fix stripe `customer.subscription.deleted`-webhook (#811)

pull/813/head^2
Alex Johansson 2021-09-28 20:48:45 +01:00 committed by GitHub
parent e684824c79
commit f8a4f81991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -102,13 +102,13 @@ type WebhookHandler = (event: Stripe.Event) => Promise<void>;
const webhookHandlers: Record<string, WebhookHandler | undefined> = { const webhookHandlers: Record<string, WebhookHandler | undefined> = {
"payment_intent.succeeded": handlePaymentSuccess, "payment_intent.succeeded": handlePaymentSuccess,
"customer.subscription.deleted": async (event) => { "customer.subscription.deleted": async (event) => {
const data = event.data as Stripe.Subscription; const object = event.data.object as Stripe.Subscription;
const customerId = typeof data.customer === "string" ? data.customer : data.customer.id; const customerId = typeof object.customer === "string" ? object.customer : object.customer.id;
const customer = (await stripe.customers.retrieve(customerId)) as Stripe.Customer; const customer = (await stripe.customers.retrieve(customerId)) as Stripe.Customer;
if (typeof customer.email !== "string") { if (typeof customer.email !== "string") {
throw new Error(`Couldn't find customer email for ${data.customer}`); throw new Error(`Couldn't find customer email for ${customerId}`);
} }
await prisma.user.update({ await prisma.user.update({