0

I am working on a custom extension where I need to call an observer when any payment method is selected from the available payment method list on the frontend checkout page.

Unfortunately, I didn't find one, but it seems that I rather need to subscribe to quote.paymentMethod.

Can anyone tell me if there is an event for this that could be observed or should I subscribe to quote.paymentMethod?

PS. I need to recalculate the totals/save the quote once a payment method is selected.

1 Answer 1

1

1)The Magento\Checkout\Model\PaymentInformationManagement class implements savePaymentInformationAndPlaceOrder() method from the Magento\Checkout\Api\PaymentInformationManagementInterface interface. There is also similar to the PaymentInformationManagement class, the Magento\Checkout\Model\GuestPaymentInformationManagement class responsible for guest checkout.

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.