Skip to content

Hot to create plugin for savePaymentInformationAndPlaceOrder method

This method is calling at checkout step but with plugin using after method it’s not calling, core method is calling.

etc/di.xml

<type name="MagentoCheckoutModelPaymentInformationManagement">
        <plugin name="k365_payemnt_management_plugin" type="K365CheckoutPluginModelPaymentInfoManagement" />
    </type>

PaymentInfoManagement.php

<?php
namespace K365CheckoutPluginModel;

use MagentoCheckoutModelPaymentInformationManagement;

class PaymentInfoManagement
{
    
public function afterSavePaymentInformationAndPlaceOrder(
    PaymentInformationManagement $subject, $result,
    $cartId,
    MagentoQuoteApiDataPaymentInterface $paymentMethod,
    MagentoQuoteApiDataAddressInterface $billingAddress = null
) {
    $this->getLogger()->critical(
            '******calllllllllllllllllllllll ' );

    $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
    try {
        $orderId = $this->cartManagement->placeOrder($cartId);
    } catch (MagentoFrameworkExceptionLocalizedException $e) {
        $this->getLogger()->critical(
            '******Placing an order with quote_id ' . $cartId . ' is failed: ' . $e->getMessage()
        );
        throw new CouldNotSaveException(
            __('*******'.$e->getMessage()),
            $e
        );
    } catch (Exception $e) {
        $this->getLogger()->critical($e);
        throw new CouldNotSaveException(
            __('*******A server error stopped your order from being placed. Please try to place your order again.'),
            $e
        );
    }
    return $result;
}

}

Thanks….