preloder

Checkout Payment Improvements in the Magento 2.1.9 release

Prev Next

In my previous blog How to Show Payment Errors on the Checkout Payment Page in Magento 2 post, I communicated the importance of custom payment messages. Customers expect to see clear messages provided by the Magento 2 in case of exceptional situations. Especially when it comes to payments.

The Magento\Checkout module is responsible for passing error messages when order save operation was not successful. Magento 2.1.0-2.1.8 releases were providing a general message in case payment transaction has been failed. Even though, a clear error message is returned back from Payment Service Provider to Magento.

Starting from Magento 2.1.9 release the Magento\Checkout module has been improved. Both guest and logged in scenarios (as we know we have 2 different implementations for logged in customers and guests) are now passing custom errors messages.

The Magento\Checkout\Model\PaymentInformationManagement::savePaymentInformationAndPlaceOrder() and Magento\Checkout\Model\GuestPaymentInformationManagement::savePaymentInformationAndPlaceOrder() methods throw CouldNotSaveException exceptions with the original exception message.

    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 (\Magento\Framework\Exception\LocalizedException $e) {
            throw new CouldNotSaveException(
                __($e->getMessage()),
                $e
            );
        } catch (\Exception $e) {
            $this->getLogger()->critical($e);
            throw new CouldNotSaveException(
                __('An error occurred on the server. Please try to place the order again.'),
                $e
            );
        }

        return $orderId;
    }

This change is a big achievement towards decreasing number of customer queries due to a general “An error occurred on the server. Please try to place the order again.” message. Also, it reduces a couple of extra classes in a custom payment module.

For the websites based on Magento 2.1.0-2.1.8 versions, I recommend updating Magento to the latest Magento 2.1 or better Magento 2.2 version to get all the security and conversion improvements.

Additional Information

More about Magento 2.1.9 changes you can read in the Release Notes.

Also, don’t forget to check Magento 2.2 Release Information.

Max Pronko is an international Magento Expert, development consultant, motivational speaker and Magento award-winning developer. He is known for the educational development programs for organizations of all sizes and has positively affected thousands of people and organizations worldwide.

Posted on Sep 16, 2017

The Devletter

Subscribe to my Magento 2 tips and tutorials content.
Every week I send an interesting email directly to your inbox

Related Posts