We are using the latest version of Commerce and the latest version of Commerce Braintree, with hosted fields. We have created our own BillingInformation pane that rearranges some fields on that pane, and a custom PaymentProcess pane, which extended the default pane and added some logging to the try/catches in buildPaneForm. Otherwise, the code in our PaymentProcess pane remains identical, and the functionality is the same.

Our checkout flow is set up so that each checkout pane sits on its own step: there is a Billing Information step, a Review step, a Payment Process step, and an Order Complete step. Each one has only one pane in it, and I bet you can guess which ones. ;-)

During checkout, if you submit a payment that fails, the order locks correctly, but the redirectToPreviousStep() method prevents the unlocking from happening. The user can still see their order in the sidebar but the basket disappears.

I was pointed in the direction of commerce_checkout_commerce_order_presave(), which is what locks and unlocks the order. To all intents and purposes it seems like this should work, but indeed, if the user is redirected away from the payment step and back to their previous step, the order does not become unlocked.

This seems to be due to the redirectToPreviousStep() method returning a NeedsRedirectException, which is interruptive and causes the redirect to happen immediately, as far as I can tell.

It seems like moving the locking and unlocking functionality to the PaymentProcess buildPaneForm method resolves this problem; the order locks and unlocks correctly and the user never sees any kind of problem with their basket.

Will shortly add a patch for this. Happy to be told that my assumptions are incorrect, but this seems to be working for us right now.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sophie.SK created an issue. See original summary.

Sophie.SK’s picture

Patch attached. I couldn't find any tests that ran on this particular functionality.

bojanz’s picture

Assigned: Unassigned » bojanz
Status: Active » Needs review

Problem confirmed. PaymentProcess and the redirect in PaymentGatewayForm (the form element) don't unlock the order.

These two will require different fixes, so let's fix PaymentProcess here, and fix PaymentGatewayForm in #2958309: The order is not unlocked when an exception is thrown in the payment offsite-form.

We're missing lots of test coverage:
1) For locking at checkout
2) For unlocking at checkout when an error is caught in PaymentProcess
3) For redirect POST payment gateways with JS disabled.

Also related: #2958310: The customer should always be sent to the "payment" checkout step if the order is locked.

Status: Needs review » Needs work

The last submitted patch, 2: checkout_locking_bug-2946909-2.patch, failed testing. View results

  • bojanz committed 4250f83 on 8.x-2.x
    Issue #2946909 by Sophie.SK, bojanz: When a payment gateway error occurs...
bojanz’s picture

Status: Needs work » Fixed

First fix is in!

Status: Fixed » Closed (fixed)

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