Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practice payment flow with edge cases per provider #360

Closed
havard024 opened this issue Jul 8, 2023 · 4 comments
Closed

Best practice payment flow with edge cases per provider #360

havard024 opened this issue Jul 8, 2023 · 4 comments
Assignees

Comments

@havard024
Copy link

Hi,

I recently started using this project and I was wondering if you have any thoughts on adding examples on best practice / full payment flow with edge cases for eg an ecommerce site? eg is it out of scope of this project or something you would accept contributions to eg update documentation and / or add examples per provider.

I belive this issue #328 was looking for something similar.

For example, when implementing a payment flow with stripe using PaymentIntents (I believe this is using the changes API), they recommend to reuse a payment intent instead of creating a new if the user never completed a checkout.

The reuse of payment intent also applies if a user adds / removes products, there stripe recommends to update the existing payment intent if one has been created.

When using the stripe checkout flow I don't think this is needed, you would just create a new checkout session. Though they do have functionality to expire a session https://stripe.com/docs/api/checkout/sessions/expire

The use of the the above cases is to prevent duplicate payments.

Stripe has some more documentation on idempotent requests to prevent duplicate requests which could result in duplicate payment intents / checkout sessions: https://stripe.com/docs/api/idempotent_requests

I understand that each provider might have their own mechanisms to handle, but it's not something that changes over time, thus each provider could document a best practice payment flow or some example flows for specific use cases.

Looking forwards to hear your thoughts on this 💡

@mariofix
Copy link
Member

mariofix commented Jul 8, 2023

Hi @havard024 Thanks for your question, we're in the process of updating the provider for Stripe (payments.stripe.StripeProviderV3),
One of the main change is the use of Checkout Sessions, it handles by default the Creation using the API, and Payment Confirmation, Expiration, and Refund of each payment using Webhooks.

By using Checkout Sessions in my projects I got rid of the problem you're describing, but I'll make some more tests to see if the idempotency key is needed regardless.

@mariofix mariofix self-assigned this Jul 8, 2023
@havard024
Copy link
Author

Hi @mariofix thanks for the quick response.

From my experience, the idempotency key helps for cases where client application are able to send two requests to server to create a session. eg a user clicks on a button twice, it can be fixed by disabled the button client side.

I've tried the StripeProviderV3 already and it works like a charm, I believe creating a session for each payment / checkout solves the majority of cases. Looking forward to see finished product!

@mariofix
Copy link
Member

mariofix commented Aug 4, 2023

Hey @havard024 they are enabled by default 😃 Automatic Retries

@havard024
Copy link
Author

Hey @havard024 they are enabled by default 😃 Automatic Retries

Well that makes the job at lot easier 😄 Thanks for looking into it!

@mariofix mariofix closed this as completed Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants