Problem/Motivation

Facing a fatal error use case with the order checkout process, when the Accept Hosted payment gateway is configured. The checkout "Review" page is failing to load with the error: "Drupal\commerce_payment\Exception\InvalidResponseException: Unable to get payment page request token. in Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway\AcceptHosted->getPaymentPageRequestToken() (line 1026 of /{PATH}/web/modules/contrib/commerce_authnet/src/Plugin/Commerce/PaymentGateway/AcceptHosted.php).", along-with Accept Hosted request response error: "Received response with code Error from Authorize.net: E00031: The amount is required.".

This happens when an Accept Hosted payment page token request is sent with the invoice amount as zero or negative value.

Steps to reproduce

  • Create a promotion coupon for 100% off on order subtotal. In case you've configured shipping methods and reproducing with a shippable order item, Create another promotion coupon for 100% off on shipping amount too.
  • Add an order item to the cart and checkout.
  • Fill the order information fields and make sure payment method selected is Accept Hosted.
  • Ensure the order summary having positive order amount.
  • Continue to review.
  • You'll see the Accept Hosted payment page on the review page. Now, click on "Go back" link (below the "Payment" pane) or navigate to previous step of checkout.
  • Now, you're back on "Order information" page.
  • Apply promotion coupons using "Coupon code" input field, and make sure the order total will become zero by applying discount coupons for both order subtotal and shipping amount.
  • Once coupon(s) applied successfully, you'll notice that order total is now $0.00 but the Payment information still holds the Payment method as Accept hosted even when there is no need to charge the customer now!
  • Submit the checkout form by clicking "Continue to review".
  • This action will lead to a WSOD with PHP error as "Drupal\commerce_payment\Exception\InvalidResponseException: Unable to get payment page request token. in Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway\AcceptHosted->getPaymentPageRequestToken() (line 1026 of modules/contrib/commerce_authnet/src/Plugin/Commerce/PaymentGateway/AcceptHosted.php)."

The "transactionType" and "amount" are the required fields when building a token request for Accept Hosted payment page. the "transactionType" value derived from the Checkout Flows configuration "Transaction mode" setting, which is absolute to either "AUTH_CAPTURE" or "AUTH_ONLY". But the "amount" field value is totally dependent on the order state at the time of review. The initial checkout (without coupon application) has a positive order total amount to charge from the customer, which made payment process eligible to kick-in, but when the checkout process stepped back and customer applied the coupons and made the order total to $0.00, the payment fields are still attached with the order object, and on next step triggered the token generation request.

Proposed resolution

If coupons were applied on the cart before the checkout begins, the payment fields will never get introduced in the checkout process if order total is value to zero. But since, Coupons are still allowed to apply after checkout begins, we must make sure that at any step of the checkout if the order total is manipulated to zero by promotions or any custom order adjustments. The payment dependencies should get eliminated from the checkout process and vice-versa, to avoid fatal error situation with order checkout.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vipin.j created an issue. See original summary.

vipin.j’s picture

Status: Active » Needs review
vipin.j’s picture

The patch compatible for 2.x release.

vmarchuk’s picture

I don't think hiding the iframe is enough. It would probably be worth showing a message that the customer should choose a different payment method (+ hide the Pay button).

damienmckenna’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs review » Needs work

The patch in #4 needs to be turned into an MR.

vmarchuk’s picture

Status: Needs work » Needs review