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 Answer 1


There are many ways to achieve your goal.

For example, you can try with Plugin:


<?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"/>

Your Plugin:

public function beforeSavePaymentInformationAndPlaceOrder(
    PaymentInformationManagementInterface $subject,
    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
    Commented Jan 10, 2020 at 8:20

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.