Magento 2: An error occurred on the server. Please try to place the order again
When user want to checkout sometimes i got below message.
After correction of Billing & Shipping Address Sometimes user able to place order some times not.
Due to this customer not able to order.
What will be the perfect solution for this?
If the magento version is > 2.4 then check service elasticsearch is in running state.
You may echo the actual error message on this file: vendor/magento/module-payment/view/frontend/templates/transparent/iframe.phtml if you did not extend the file yet or if you did you may edit this on app/design/[vendor]/[theme]/ go to line 42 and replace this
message: $t('An error occurred on the server. Please try to place the order again.')
message: $t('<?php echo $params['error_msg'];?>')
In my case, when the customer purchased using Credit card via Payapal Gateway I was able to trace the error message on this file vendor/magento/module-paypal/Model/Payflow/Service/Response/Validator/ResponseValidator.php
The payment was actualy declined with the response code ESPONSE_CODE_FRAUDSERVICE_FILTER but magento will display the default error message instead of showing Fraud Error message.
Please go to vendor/magento/module-checkout/Model/PaymentInformationManagement.php Functions: savePaymentInformationAndPlaceOrder() Change line 85 and 90 with follow code:
throw new CouldNotSaveException( __($e->getMessage()), $e );
After that, please try to checkout and you can see the error message.