From 8017918063ff515059b015263d2ad30ed39ea220 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Thu, 15 May 2025 08:11:51 -0700 Subject: [PATCH] Merge pull request #25490 from overleaf/mf-send-subscription-cancelled-and-reactivated-event-stripe-subscription [web] Send analytics events and user properties for cancelled and reactivated event in Stripe subscription GitOrigin-RevId: 07a4e6395be334c90910b5d421624c4daa703d3b --- services/web/types/stripe/webhook-event.ts | 38 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/services/web/types/stripe/webhook-event.ts b/services/web/types/stripe/webhook-event.ts index c15f53feea..72264abe46 100644 --- a/services/web/types/stripe/webhook-event.ts +++ b/services/web/types/stripe/webhook-event.ts @@ -1,12 +1,22 @@ import Stripe from 'stripe' -type StripeWebhookEventType = - | 'customer.subscription.created' - | 'customer.subscription.updated' - | 'customer.subscription.deleted' +export type CustomerSubscriptionUpdatedWebhookEvent = { + type: 'customer.subscription.updated' + data: { + object: Stripe.Subscription & { + metadata: { + adminUserId?: string + } + } + // https://docs.stripe.com/api/events/object?api-version=2025-04-30.basil#event_object-data-previous_attributes + previous_attributes: { + cancel_at_period_end?: boolean // will only be present if the subscription was cancelled or reactivated + } + } +} -export type CustomerSubscriptionWebhookEvent = { - type: StripeWebhookEventType +export type CustomerSubscriptionCreatedWebhookEvent = { + type: 'customer.subscription.created' data: { object: Stripe.Subscription & { metadata: { @@ -15,3 +25,19 @@ export type CustomerSubscriptionWebhookEvent = { } } } + +export type CustomerSubscriptionsDeletedWebhookEvent = { + type: 'customer.subscription.deleted' + data: { + object: Stripe.Subscription & { + metadata: { + adminUserId?: string + } + } + } +} + +export type CustomerSubscriptionWebhookEvent = + | CustomerSubscriptionUpdatedWebhookEvent + | CustomerSubscriptionCreatedWebhookEvent + | CustomerSubscriptionsDeletedWebhookEvent