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?
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.')
with this
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.
If the magento version is > 2.4 then check service elasticsearch is in running state.
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.
The solution that worked for me, was to change the generic "An Error Occured on the Server", to "Credit Card Declined. Please check credit card details and billing address". . .
To do this, you need to edit
/app/design/frontend/THEME/VENDOR/Magento_Payment/templates/transparent/iframe.phtml
edit line:
message: $t('An error occurred on the server. Please try to place the order again.')
You can find a copy of iframe.html in vendor/magento and move it to your theme to make this change.
It is possible to display the real error by editing the model files based on the error ajax call
Edit the function savePaymentInformationAndPlaceOrder in
vendor/magento/module-checkout/Model/PaymentInformationManagement.php
or for Guest orders in
vendor/magento/module-checkout/Model/GuestPaymentInformationManagement.php
Change the function from:
public function savePaymentInformationAndPlaceOrder(
$cartId,
$email,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
$this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);
try {
$orderId = $this->cartManagement->placeOrder($cartId);
} catch (\Exception $e) {
throw new CouldNotSaveException(
__('An error occurred on the server. Please try to place the order again.'),
$e
);
}
return $orderId;
}
to:
public function savePaymentInformationAndPlaceOrder(
$cartId,
$email,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
$this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);
try {
$orderId = $this->cartManagement->placeOrder($cartId);
} catch (\Exception $e) {
throw new CouldNotSaveException(
__($e->getMessage()),
$e
);
}
return $orderId;
}
Now you get the actual error and you should find the full exception in the exception.log file
Thanks :)
This means that an exception was thrown somewhere in your application, execution was terminated and the exception was handled. I believe the exception is being thrown in vendor/magento/module-checkout/Model/PaymentInformationManagement.php
.
If you inspect the response of the rest call in your network tab you will see that there was a json object returned that should have a stack trace of where the error was generated. If you want the actual error to display, you can update this exception handling to output $e->getMessage()
instead of the generic display message or inject the Psr/logger and log it out to your log directory.
The best way for you to prevent this is to track down what is throwing an exception and resolve the exception.
We have also seen this same error when a person's credit card fails. A very generic error.
In our case since we sell overseas... it is usually the card holder needs to call their bank and just let them know it is a legitimate payment transaction they are trying to submit.
In my case enabling single-store mode then disabling it solved the problem.
This is occurs due your third party extension or your own custom module syntax error present in module files.
If you want to see the actual error in your code, you can run the command on terminal.
sudo php bin/magento setup:di:compile
In my case syntax error mention by red circle in above snapshot (semicolon is not use in array).
I have replaced semicolon to comma.
Note : After remove syntax error again run command.
sudo php bin/magento setup:di:compile
Now clear cache.
Note : If above solution is not working, the disable your custom or third party extension
sudo php bin/magento --clear-static-content module:disable Module_Name
I got same issue and it was a silly md5 hash code mistake. Please use shorter md5 code. I was using too long md5 string so it wasn't working after make it shorter it is working perfectly!
If you are upgrading to version 2.4.4 from older version, this error is likely due to deprecated functionality in external modules that are not detected while compiling. I had this issue. Check log files for deprecated functionality errors.
In my case problem was in State/Province/Region field in address. After filling this field the order was placed correctly.
Solution:
or
var/log
& solves issue