FLUX-SE / PayumStripe

Payum Stripe gateways (with SCA support)
MIT License
28 stars 15 forks source link

[StripeCheckoutSession] Subscription Mode enhance Async payment Status #23

Closed Prometee closed 2 years ago

Prometee commented 2 years ago

This PR aim to change the behaviour of the subscription handle by a Session to improve async payment status if you are using for example SEPA direct debit with subscriptions.

Two new webhooks are available on Stripe :

They allow us to know if a PaymentIntent has failed or succeeded when they have been created by a Stripe Checkout Session.

In case of Session mode payment, nothing change because this library will Sync the PaymentIntent inside the Session object waiting for checkout.session.completed, checkout.session.async_payment_*, payment_intent.succeeded or a payment_intent.canceled event which trigger another Sync.

In case of Session mode setup, nothing change because this library will Sync the SetupIntent inside the Session object waiting for checkout.session.completed, setup_intent.succeeded or a setup_intent.canceled event which trigger another Sync.

In case of Session mode subscription, this library will no longer Sync a Session object to a Subscription one. Instead it will keep a Session object and wait for checkout.session.completed or checkout.session.async_payment_* event. Thing is Stripe API is not changing any field of the Session object when the Session is completed, unpaid and an async payment failed (happen when checkout.session.async_payment_failed webhook is triggered), that's why this library will try to get the underlying PaymentIntent of the created Subscription (Subscription->Last Invoice->PaymentIntent) and see if it has failed or not, to finally update the Payum Payment status.

codecov[bot] commented 2 years ago

Codecov Report

Merging #23 (ada4ddc) into master (6072ba8) will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #23   +/-   ##
=========================================
  Coverage     99.74%   99.75%           
- Complexity      398      408   +10     
=========================================
  Files           105      107    +2     
  Lines          1192     1221   +29     
=========================================
+ Hits           1189     1218   +29     
  Misses            3        3           
Impacted Files Coverage Δ
.../Action/Api/WebhookEvent/AbstractPaymentAction.php 97.77% <ø> (ø)
src/Action/EmbeddableTokenTrait.php 100.00% <ø> (ø)
src/Action/NotifyAction.php 100.00% <ø> (ø)
src/Action/StatusAction.php 100.00% <ø> (ø)
src/AbstractStripeGatewayFactory.php 100.00% <100.00%> (ø)
src/Action/Api/ResolveWebhookEventAction.php 100.00% <100.00%> (ø)
src/Action/Api/Resource/AllInvoiceAction.php 100.00% <100.00%> (ø)
src/Action/StatusSessionAction.php 100.00% <100.00%> (ø)
...kEvent/CheckoutSessionAsyncPaymentFailedAction.php 100.00% <100.00%> (ø)
...ent/CheckoutSessionAsyncPaymentSucceededAction.php 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6072ba8...ada4ddc. Read the comment docs.