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.

    enter image description here

    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?

    Please add the error you see in your logs file in here

    @Ankit Shah, I am facing this issue so if you found the solution for this kindly share here

    @Vigna Since last few months not getting this error. If there is error due to your custom module. So need to check `var/log` & solves issue

    ok, I will check!!!

    Is it sorted out ?

    Does anyone find a solution?

  • 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.

    after vendor / theme/ what is the following folder? Magento_Payment / templates??

    @styzzz it will be like app/design/frontend/[Vendor]/[theme]/Magento_Payment/templates/transparent/iframe.phtml

    it's working fine

    what would be the solution here

  • 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.

    Thank you very much. You saved my day!

  • 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.

  • 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 
    

    enter image description here

    enter image description here

    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
    

    enter image description here

    Sudo will probably wreck your installation file permissions

  • In my case enabling single-store mode then disabling it solved the problem.

    1. Go to Stores -> Configuration -> General Set 'Enable Single-Store Mode' to Yes.
    2. Go to System -> Cache Management and click 'Flush Magento Cache'.
    3. Go to Stores -> Configuration -> General Set 'Enable Single-Store Mode' to No.
  • 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!

    Where did you change? may i know the path? Thank You @Mukesh Ojha

    @zus I have set Merchant MD5 in authorized.net payment method. Please check if any payment method configured using MD5 then make it short

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used