Magento2 – Guest Checkout Credit Card Messages
With a lot of security improvement with Magento2, one that we found a bit confusing was that when a guest customer checks out and has an issue with their credit card, a generic popup error message appears that says “Unable to place order. An error occurred on the server. Please try to place the order again.”
That error, makes it seem like there is something wrong with the actual website itself, often prompting calls to customer service by somewhat irritated customers saying “Your website is broken”, when in fact its actually a credit card issue instead.
What should be an optional setting the Magento code to display error messages to the customer (actually, there is in the payment processor plugin, but Magento is refusing to honor them), we now have to craft our own “hook” into Magento’s payment processor.
The first is to create a plugin and calls that that extends the “\Magento\Checkout\Model\GuestPaymentInformationManagement” class.
In our “savePaymentInformationAndPlaceOrder”, we utilize the same mechanisms as the default class, but we catch the exception and store our own custom error.
The second part is to create and/or extend any classes that modify the Index portion of your “Magento\Checkout\Controller\Cart\Index”.
We just have a simple paymentErrror check that grabs the message and pushes it into Magento’s message manager.
So, in all, while its a bit excessive, adding a custom error message to a Magento2 store is not really that difficult.
Our message that we present to the Guest customer does not reveal any information that a nefarious user could use to try and “Game” the credit card system (ie: number is invalid/date is invalid/name is invalid/etc). A generic “Error Processing Credit Card. Please try again, or try another credit card”, will however, prevent a lot of calls going to your main store telling you that the website is broken.