Magento 2 Checkout Debuggen

Sometimes you get an error in the checkout but you have no clue what the actual error is because you don’t get a good message and you can’t find it in the log files. The only thing you will see is An Error Occurred On The Server. Please Try To Place The Order Again.

No longer need to manually update the model files with Mage2 Module Experius ExceptionDebugger!

https://github.com/experius/Magento-2-Module-Experius-ExceptionDebugger

 

Manually Debug Checkout without ExceptionDebugger

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

See another article about adding a Custom Field to the Billing Address in the checkout