vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.69k stars 1.01k forks source link

Order stuck in `PaymentAuthorized` after a failed payment #1330

Closed martijnvdbrug closed 2 years ago

martijnvdbrug commented 2 years ago

Is your feature request related to a problem? Please describe. With Mollie payments (and Stripe similar I believe), the payment flow is as follows:

  1. handler.createPayment() is called by the client.
  2. The handler constructs a redirect link and returns this to the client via public metadata
  3. The client goes to the external platform to do a payment
  4. A webhook from Mollie updates the status of the payment to status Paid

Before the handler can return the redirectLink, we need to return a payment state. The 'earliest' state we can send is Authorized, resulting in the order becoming PaymentAuthorized

However, a client can leave the external platform, for whatever reason: cancel, expire, failed payment. Whenever the user returns to the storefront, the order will be stuck in PaymentAuthorized, with no way back to AddingItems

Describe the solution you'd like The order should be able to return to AddingItems after a customer leaves the payment platform. The logical way is to keep the order in ArrangingPayment while the user is on the external platform. From there we can:

  1. transition to PaymentSettled if payment succeeds
  2. transition to AddingItems if the payment fails, expires or is canceled

Describe alternatives you've considered I currently detect any PaymentAuthorized orders and discard them on the frontend. The customer is forced to recreate the order.

Additional context image

michaelbromley commented 2 years ago

Hey @martijnvdbrug, maybe the solution to this is to re-think the payment flow slightly. The upcoming stripe plugin (#1417) does it like this:

  1. call a custom mutation createStripePaymentIntent rather than addPaymentToOrder
  2. this creates the payment intent with Stripe
  3. when the webhook returns successful, only then do we actually create a Payment (and programatically, rather than via the mutation).

This flow gets around this whole issue, since the Order has not been transitioned to PaymentAuthorized or PaymentSettled until the actual successful transaction comes back. I also feel that this conceptually maps to what is going on a bit better.

What do you think?

martijnvdbrug commented 2 years ago

That is a nice solution indeed.

Only downside I see is that the ArrangingPayment state is not used, and it's nice see how many users left after ArrangingPayments. BUT, thats not what the states are for I guess.

I think we can close this one. I opened a new issue for updating the Mollie plugin: https://github.com/vendure-ecommerce/vendure/issues/1432 I can work on this :arrow_up: