Magento – Magento 2.1.1 An error occured on the server please try again at checkout

developer-modemagento2payment-gatewaypayment-methods

for a while we've been getting an error when checking out with Braintree using a sandbox account. we simply get the error

'An error has occurred on the server, please try again"

The error occurs when hitting the checkout button

I've tried removing the table prefix and running the SQL fix but the error still persists. There is nothing incorrect in the Braintree configuration as the dummy payments are being sent and verified in the sandbox account & our host confirms there are no server errors causing it so it must be a Mage issue.

We're at a point now where we are totally flumuxed on the issue…

Best Answer

To know the exact reason why it is happening so, please open below file: vendor/magento/module-checkout/Model/PaymentInformationManagement.php

than comment out the try, catch and put code to place order directly as below:

Replace below function

public function savePaymentInformationAndPlaceOrder(
    $cartId,
    \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
    \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
    $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
    try {
        $orderId = $this->cartManagement->placeOrder($cartId);
    } catch (\Exception $e) {
        //var_dump($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,
    \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
    \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
    $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
    //try {
        $orderId = $this->cartManagement->placeOrder($cartId);
    /*} catch (\Exception $e) {
        //var_dump($e);
        throw new CouldNotSaveException(
            __('An error occurred on the server. Please try to place the order again.'),
            $e
        );
    }*/
    return $orderId;
}

Now, try to place order again. You will be able to see the detailed error in log file or may be in console.

Related Topic