In my Magento2 instance, I created a Plugin interceptor for run custom validation before process the payment. Works for all payment methods but PayPal Express or PayPal Standard.

di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Quote\Api\CartManagementInterface">
        <plugin name="myvalidation_before_order_place" type="Myvendor\Myvalidation\Plugin\MyvalidationBeforePlaceOrder" sortOrder="1" disabled="false" />
    </type>
</config>

MyvalidationBeforePlaceOrder.php

class MyvalidationBeforePlaceOrder
{
    public function __construct(
        // my construct
    ) {
        // my construct
    }

    public function beforePlaceOrder(CartManagementInterface $subject, $cartId, PaymentInterface $paymentMethod = null)
    {
        // my custom validation logic
        throw new PaymentException(__('TEST'));
    }
}

Looks like Magento2 PayPal module ignore Magento\Quote\Api\CartManagementInterface

Ideally, when customer click on "Place Order" button in checkout, Myvalidation script should be executed and then the payment processed (in the case of PayPal, execute Myvalidation then redirect to PayPal website). Any suggestion of which interceptor should I use?

有帮助吗?

解决方案

For Paypal Express, Create Plugin on Magento\Paypal\Model\Express\Checkout::place

or you need to create plugin on Magento\Quote\Model\QuoteManagement::submit

许可以下: CC-BY-SA归因
scroll top