Skip to content

Commit

Permalink
fix stripe customer.subscription.deleted-webhook (calcom#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Sep 28, 2021
1 parent e684824 commit f8a4f81
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ee/pages/api/integrations/stripepayment/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ type WebhookHandler = (event: Stripe.Event) => Promise<void>;
const webhookHandlers: Record<string, WebhookHandler | undefined> = {
"payment_intent.succeeded": handlePaymentSuccess,
"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;
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({
Expand Down

0 comments on commit f8a4f81

Please sign in to comment.