In Drupal Commerce, I need a way to send a user back to their checkout page if the payment gateway responds back with an error.

Right now it kind of bombs out and just tosses a nasty error message to the user and the cart and its contents are "gone", since Drupal marks the Commerce order as complete.

I've tried adding in my custom error handler function something like: commerce_order_status_update($order, 'checkout_review'); or commerce_order_status_update($order, 'cart');

But in both cases, the order does remain however some weird things happen, such as if you try to go to /cart you get a cart empty message as well as the shipping information gets dropped.

I'm beginning to think I'm not following the best practice for returning a user properly to their cart following an error in the checkout process.

  • What's a NAK? The best Google can give me is a sodium-potassium alloy, which I suspect isn't what you're going for... – Clive Sep 28 '15 at 13:04
  • Sorry, a negative-acknowledge character. Basically if the payment gateway comes back with an error of any kind. The error is not important per se. Rather, I'm more interested in having Drupal see the error and then send the user either back to the cart or checkout page. – Matt Sep 28 '15 at 13:08
  • It depends - what's your method for retrieving the response from the payment processor, and at what point in the process do you do that? Or is the response instigated by the processor at the other end (IPN style)? – Clive Sep 28 '15 at 13:11
  • Right now I am using hook_commerce_checkout_complete to detect when the order is complete on the Drupal side and interpret the payment gateway's response. api.drupalcommerce.org/api/Drupal%20Commerce/… – Matt Sep 28 '15 at 13:14
  • 1
    It's based on the status of the order - you set the workflow up for that using rules. Your custom code for contacting the payment processor is in a custom Commerce payment processor module, right? Like commerce_paypal etc? You're not just trying to run some arbitrary PHP code at some point in the process? Payment processor modules are a fully-fledged thing with rules and constraints that integrate with the rest of the Commerce workflow - if you haven't written that type of module, that's why you're having problems. If you have, just update the question with the code from the relevant hooks – Clive Sep 28 '15 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.