-
-
Notifications
You must be signed in to change notification settings - Fork 969
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
improve one-time payment webhook logic #375
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understood correctly, we want to give users access when we are sure that payment succeeded. That's why we introduced a new hook payment_intent.succeeded
.
I've left some comments.
try { | ||
const metadata = returnMetadataByMode({ mode, priceId }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const metadata = returnMetadataByMode({ mode, priceId }); | |
const paymentIntentData = getPaymentIntentData({ mode, priceId }); |
Related to the suggested fn rename below.
default: | ||
assertUnreachable(plan.effect); | ||
} | ||
const { subscriptionPlan } = getPlanEffectDetailsById(planId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it feels like we are implicitly saying: we only want to update the subscriptionPlan
value for subscription
plans by not using the numOfCreditsPurchased
value here. Can we be explicit about it? Something like:
if (plan.effect.kind === 'credits') {
return;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👍
Description
Fixes #371
Adds a new webhook event handler for
payment_intent.succeeded
. One-time payment products (i.e. "credits"), characterized by Stripe as having thepayment
mode (not thesubscription
mode), do not send aninvoice.paid
event (although subscriptions do), so we have to confirm payment and handle it better than just using thecheckout.session.completed
event, which can be sent even in the case that a payment fails.Contributor Checklist