Просмотр исходного кода

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
M Fahru 1 год назад
Родитель
Сommit
b3c339464e

+ 14 - 0
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<RecurlyPlanCode, 'assistant'>
+}

+ 10 - 0
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

+ 30 - 0
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<PaymentProvider['service'], 'recurly'>
+    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