Developer forum

Forum » Development » Abort checkout

Abort checkout

Per Ljung
Reply
Hi!

I'm writing a custom checkout handler and wonder if there's possible to abort a checkout and return to the first step?

When the user has cancelled a payment I want to redirect to the state before checkout so that the products in the cart are still there to checkout again if the customer wants to do this, maybe select another payment method.

And if a payment is rejected by the the external payment provider I want to display alternatives for payment that the user can try if the first payment for some reason didn't succeed.

An also if there's an error during the payment the customer should be able to try again. Is this possible? When I''m redirected back from the payment provider the content of the cart is lost.

Best regards,
Per

Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Per

This is expected and correct behavior, that the cart is removed from the session. If you see the Checkout Handler documentation section 1.3 point 2 you'll see that after your CheckoutHandler is invoked, the order is removed from session and only exists as that object that was passed to you.

In your Redirect method you need to handle the different scenarios, success, rejection, cancellation and callback. E.g. you need to set the order complete if Success. When you've handled the different states, you need to finish by calling CheckoutDone(order). This is very important as it let's the cart know that you're done. It then looks at the state of the order and if it's not complete it downgrades the order to a cart object and puts it back into the session context. If you want the user to be redirected back to the first step in the cart then simply call RedirectToCart() after CheckoutDone(order). You could also render a template and show that and that template could contain a link that could take the user to some step in the cart.

Hope this helps :)

- Jeppe

 

You must be logged in to post in the forum