2

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?

1 Answer 1

2

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

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

1
  • thanks Amit, QuoteManagement::submit is perfect cause cover all payment methods with just one interceptor
    – Davebra
    Commented Jan 3, 2020 at 4:11

Your Answer

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

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