Well, this was a challenge to explain succinctly in the title.

I have a few payment method rules (i.e., rules reacting to the event "Select available payment methods for an order"). I've added conditions to these rules that they should only react if the order total is greater than 0. However, this is problematic in the following scenario:

  1. User begins checkout process with a $100 item in the cart.
  2. User chooses appropriate payment method, then proceeds to the /checkout/%/payment page to enter payment details.
  3. User realizes she forgot to enter the coupon code for her $100 coupon, and goes back to the first checkout page to enter it. (In my checkout setup, this is allowed.)
  4. She enters her coupon code, bringing her order total to $0.00.
  5. She then proceeds to the /checkout/%/review page, where there are no longer any payment methods listed. (This is to be expected, given the Rules configuration I mentioned.)
  6. She clicks "Continue to next step" at the bottom, only to be taken to the /checkout/%/payment page to enter payment details, as in #2 above.

The reason for this is that, after the user chose a payment method in step 2, that payment method was attached to the order via the $order->data property. Once she returned to the first checkout page and entered her coupon (so that her order total was now $0.00), the payment methods were hidden from her, but the payment method she'd chosen earlier was still attached. Thus, when continuing from the Review page, she was still prompted for payment details.

I'm not sure that this is a bug, or a task, or what. It seems like a bug, but perhaps I need to simply handle it differently. (For example, I could remove the "greater than 0" condition from the payment method rules, install the "Free payment method" module, and have it be selected by default if the order total is 0...? I'm not sure that selecting a method by default is possible with Rules, but I'll look into it...)

Anyway, thoughts on how to solve this?

Comments

rszrama’s picture

Hard to say; I'm not sure we have a good event to clear out that variable, but it seems reasonable to expect the payment checkout pane to clear it if the checkout pane is submitted with no options available. So it seems like at your step #6 we just need to ensure our payment checkout pane callback is being called (I believe it should) and remove the selected payment method from $order->data.

jessepinho’s picture

Yeah, I feel like it should be called; however, it appears the entire pane is skipped if no payment methods are available.

rszrama’s picture

Actually, it simply displays an empty form array, but the validate callback will still get called. So at the top of commerce_payment_pane_checkout_form_validate() and the _submit() function, you can see the if statement checking to make sure there was a payment method on the form. In the submit callback, we should just add an else that removes the item from $order->data and it should be good to go.

rszrama’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Clarified steps.