X
    Categories: Knowledgebase

How to show error when checkout with magento 2 (An error occurred on the server. Please try again)

  1. Go to the file : vendor/magento/module-checkout/Model/PaymentInformationManagement.php
    vendor/magento/module-checkout/Model/GuestPaymentInformationManagement.php
  2. Change function savePaymentInformationAndPlaceOrder() from
    /**
     * {@inheritDoc}
     */
    public function savePaymentInformationAndPlaceOrder(
        $cartId,
        MagentoQuoteApiDataPaymentInterface $paymentMethod,
        MagentoQuoteApiDataAddressInterface $billingAddress = null
    ) {
        $this->savePaymentInformation($cartId, $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

    /**
     * {@inheritDoc}
     */
    public function savePaymentInformationAndPlaceOrder(
        $cartId,
        MagentoQuoteApiDataPaymentInterface $paymentMethod,
        MagentoQuoteApiDataAddressInterface $billingAddress = null
    ) {
        $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
        try {
            $orderId = $this->cartManagement->placeOrder($cartId);
        } catch (Exception $e) {
            throw new CouldNotSaveException(
                $e
            );
        }
        return $orderId;
    }

Check log and see result !

Thank for reading this post, Hope it helps.

Kien Wiliam: Magento Ecommerce Developer