Преглед изворни кода

Merge pull request #28388 from overleaf/ls-set-and-use-user-id-on-customer-object

Set and use userId on customer object

GitOrigin-RevId: 44749df8135154348fbf099db3c680d3d3212ff3
Liangjun Song пре 11 месеци
родитељ
комит
aaeacb52b7

+ 3 - 0
services/web/app/src/Features/Subscription/PaymentProviderEntities.js

@@ -650,11 +650,14 @@ class PaymentProviderAccount {
    * @param {string} props.code
    * @param {string} props.email
    * @param {boolean} [props.hasPastDueInvoice]
+   * @param {object} [props.metadata]
+   * @param {string} [props.metadata.userId]
    */
   constructor(props) {
     this.code = props.code
     this.email = props.email
     this.hasPastDueInvoice = props.hasPastDueInvoice ?? false
+    this.metadata = props.metadata ?? {}
   }
 }
 

+ 24 - 0
services/web/types/stripe/webhook-event.ts

@@ -7,6 +7,7 @@ export type CustomerSubscriptionUpdatedWebhookEvent = {
       metadata: {
         adminUserId?: string
       }
+      customer: string
     }
     // https://docs.stripe.com/api/events/object?api-version=2025-04-30.basil#event_object-data-previous_attributes
     previous_attributes: {
@@ -35,6 +36,7 @@ export type CustomerSubscriptionCreatedWebhookEvent = {
       metadata: {
         adminUserId?: string
       }
+      customer: string
     }
   }
 }
@@ -46,6 +48,7 @@ export type CustomerSubscriptionsDeletedWebhookEvent = {
       metadata: {
         adminUserId?: string
       }
+      customer: string
     }
   }
 }
@@ -90,6 +93,25 @@ export type InvoiceOverdueWebhookEvent = {
   request: Stripe.Event.Request
 }
 
+export type CheckoutSessionCompletedWebhookEvent = {
+  type: 'checkout.session.completed'
+  data: {
+    object: Stripe.Checkout.Session & {
+      metadata: {
+        userId?: string
+      }
+    }
+  }
+  request: Stripe.Event.Request
+}
+
+export type CustomerCreatedWebhookEvent = {
+  type: 'customer.created'
+  data: {
+    object: Stripe.Customer
+  }
+}
+
 export type CustomerSubscriptionWebhookEvent =
   | CustomerSubscriptionUpdatedWebhookEvent
   | CustomerSubscriptionCreatedWebhookEvent
@@ -101,3 +123,5 @@ export type WebhookEvent =
   | InvoiceVoidedWebhookEvent
   | PaymentIntentPaymentFailedWebhookEvent
   | InvoiceOverdueWebhookEvent
+  | CheckoutSessionCompletedWebhookEvent
+  | CustomerCreatedWebhookEvent