From b3c339464eed19e9ce4e7fd1319fa2971425a6d2 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Mon, 7 Jul 2025 07:02:05 -0700 Subject: [PATCH] Merge pull request #25911 from overleaf/mf-stripe-payment-page-form-submit-event [web] Simulate `payment-page-form-submit` event for Stripe subscription GitOrigin-RevId: 8cfa1a2d91aaea4314a4a40f3256bade50507084 --- services/web/types/stripe/metadata.ts | 14 +++++++++ services/web/types/stripe/webhook-event.ts | 10 +++++++ .../web/types/subscription/analytics-event.ts | 30 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 services/web/types/stripe/metadata.ts create mode 100644 services/web/types/subscription/analytics-event.ts diff --git a/services/web/types/stripe/metadata.ts b/services/web/types/stripe/metadata.ts new file mode 100644 index 0000000000..17861d3d16 --- /dev/null +++ b/services/web/types/stripe/metadata.ts @@ -0,0 +1,14 @@ +import Stripe from 'stripe' +import { RecurlyPlanCode } from '../subscription/plan' + +type MetadataPlanCode = Exclude< + RecurlyPlanCode, + | 'professional_free_trial_7_days' + | 'student_free_trial_7_days' + | 'collaborator_free_trial_7_days' +> + +export type ProductMetadata = Stripe.Metadata & { + planCode: MetadataPlanCode + addOnCode?: Extract +} diff --git a/services/web/types/stripe/webhook-event.ts b/services/web/types/stripe/webhook-event.ts index f6e36b8b0a..c0c182e047 100644 --- a/services/web/types/stripe/webhook-event.ts +++ b/services/web/types/stripe/webhook-event.ts @@ -53,6 +53,15 @@ export type InvoicePaidWebhookEvent = { data: { object: Stripe.Invoice } + request: Stripe.Event.Request +} + +export type PaymentIntentPaymentFailedWebhookEvent = { + type: 'payment_intent.payment_failed' + data: { + object: Stripe.PaymentIntent + } + request: Stripe.Event.Request } export type CustomerSubscriptionWebhookEvent = @@ -63,3 +72,4 @@ export type CustomerSubscriptionWebhookEvent = export type WebhookEvent = | CustomerSubscriptionWebhookEvent | InvoicePaidWebhookEvent + | PaymentIntentPaymentFailedWebhookEvent diff --git a/services/web/types/subscription/analytics-event.ts b/services/web/types/subscription/analytics-event.ts new file mode 100644 index 0000000000..8633884a7d --- /dev/null +++ b/services/web/types/subscription/analytics-event.ts @@ -0,0 +1,30 @@ +import { CurrencyCode } from './currency' +import { PaymentProvider } from './dashboard/subscription' + +type PaymentPageFormSubmitEventBaseSegmentation = { + currencyCode: CurrencyCode + plan_code?: string + coupon_code: string + isPaypal: boolean + upgradeType: 'standalone' + referrer?: string +} + +type PaymentPageFormSubmitEventStripeSegmentation = + PaymentPageFormSubmitEventBaseSegmentation & { + payment_provider: Exclude + stripe_price_id: string + stripe_price_lookup_key: string + } + +type PaymentPageFormSubmitEventRecurlySegmentation = + PaymentPageFormSubmitEventBaseSegmentation & { + payment_provider: Exclude< + PaymentProvider['service'], + 'stripe-us' | 'stripe-uk' + > + } + +export type PaymentPageFormSubmitEventSegmentation = + | PaymentPageFormSubmitEventStripeSegmentation + | PaymentPageFormSubmitEventRecurlySegmentation