0

I am verifying the phone number through OTP in Magento 2 one page checkout. when the user clicks the place order button before the phone number gets verified, I need to show a validation message to verify the phone number.

I have created the OTP verification module for the phone number based on the below link: How to add custom button under the phone number field in one page checkout in Magento 2?

1

There are many ways to achieve your goal.

For example, you can try with Plugin:

app/code/Vendor/Checkout/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Checkout\Api\PaymentInformationManagementInterface">
        <plugin name="verify_phone_validation" type="Vendor\Checkout\Plugin\Payment\VerifyPhoneValidation"/>
    </type>
</config>

Your Plugin:

public function beforeSavePaymentInformationAndPlaceOrder(
    PaymentInformationManagementInterface $subject,
    $cartId,
    PaymentInterface $paymentMethod,
    AddressInterface $billingAddress = null
) {
    //Your custom logic

    if ($customer->isVerifiedPhone()) {
                throw new CouldNotSaveException(
                    __(
                        "The order wasn't placed. "
                        . "You need to verify the phone number before placing order"
                    )
                );
    }
}
  • when is the plugin gets called?.when click on place order button? – Arul Jan 10 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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