Problem/Motivation

Currently, the Amazon payment method does not take into consideration discounts or coupons that might have been added after the user has begun the Checkout process. For example,

Prerequisites:
- Billing address pane on Checkout page
- Payment pane on Review page
- Do not require payments at checkout, and show a message

  1. Create a new Gift Card that covers your order total.
  2. Choose Amazon Pay at the cart page
  3. Apply the coupon at Checkout
  4. Proceed to the Payment/Review page

In this example, the Amazon Billing Page will appear. This is because the Amazon Pay method puts a payment method callback into a hook_form_alter() implementation. The result is that, even if Rules are configured to not show the Amazon Pay method if an order is not free, the message "Payment is not required for your order" appears as well as the wallet widget.

I should note that this used to work better, but I believe some recent changes to how discounts are calculated has surfaced this issue (possibly a regression). However it still seems weird that the LPA module would still return a form despite Rules evaluating to FALSE.

Proposed resolution

Verify that the order total is greater than zero before returning a pane form.

User interface changes

None

API changes

Minor condition added

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torgosPizza created an issue. See original summary.

torgosPizza’s picture

Title: Do not show Amazon Pay payment method for free orders. » Do not return Amazon Pay payment method form if an order has a $0 total
FileSize
1 KB

Updating the title a bit, and here's a patch.

mglaman’s picture

+++ b/commerce_amazon_lpa.module
@@ -472,6 +472,14 @@ function commerce_amazon_lpa_form_alter(&$form, &$form_state, $form_id) {
+    // Exit if the order is actually free.
+    $order_total = $order_wrapper->commerce_order_total->value();

Should we run this first, commerce_order_calculate_total? Or I suppose it is already calculated when entering checkout.

Anybody’s picture

Does someone know if a similar logic is already implemented in other modules like commerce_paypal where we could have a look for #3?
I'm also unsure.

Another concept could be to detach commerce_amazon_lpa with a rule if total is zero? I guess that should already work?