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

[web] Add audit log entry for billing-details-updated

GitOrigin-RevId: dd0079e4043d3a6ee64bd511b242d7f5649036ca
Simon Gardner 8 месяцев назад
Родитель
Сommit
43c263b419

+ 14 - 0
services/web/app/src/Features/Helpers/StringHelper.mjs

@@ -15,6 +15,20 @@ const JSON_ESCAPE = {
   '\u2029': '\\u2029',
 }
 
+/**
+ * Converts a snake_case string into a user friendly string with each word capitalized.
+ * @param {string} snakecaseStr
+ * @returns {string}
+ */
+export function wordifySnakecase(snakecaseStr) {
+  return snakecaseStr
+    .split('_')
+    .map(word => {
+      return word.charAt(0).toUpperCase() + word.slice(1)
+    })
+    .join(' ')
+}
+
 export default StringHelper = {
   // stringifies and escapes a json object for use in a script. This ensures that &, < and > characters are escaped,
   // along with quotes. This ensures that the string can be safely rendered into HTML. See rationale at:

+ 14 - 0
services/web/app/src/Features/Subscription/SubscriptionLocator.mjs

@@ -106,6 +106,20 @@ const SubscriptionLocator = {
     )
   },
 
+  async getUniqueManagedSubscriptionUserAssociation(userId) {
+    return await Subscription.findOne(
+      {
+        managedUsersEnabled: true,
+        $or: [
+          { member_ids: userId },
+          { manager_ids: userId },
+          { admin_id: userId },
+        ],
+      },
+      { _id: 1 }
+    )
+  },
+
   async getGroupsWithEmailInvite(email) {
     return await Subscription.find({ invited_emails: email }).exec()
   },

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

@@ -114,6 +114,21 @@ export interface CustomerCreatedWebhookEvent extends Stripe.EventBase {
   }
 }
 
+export interface CustomerUpdatedWebhookEvent extends Stripe.EventBase {
+  type: 'customer.updated'
+  data: {
+    object: Stripe.Customer
+    previous_attributes?: {
+      invoice_settings?: {
+        default_payment_method?: string
+      }
+      address?: Stripe.Address
+      name?: string
+      email?: string
+    }
+  }
+}
+
 export type CustomerSubscriptionWebhookEvent =
   | CustomerSubscriptionUpdatedWebhookEvent
   | CustomerSubscriptionCreatedWebhookEvent
@@ -127,3 +142,4 @@ export type WebhookEvent =
   | SetupIntentSetupFailedWebhookEvent
   | InvoiceOverdueWebhookEvent
   | CustomerCreatedWebhookEvent
+  | CustomerUpdatedWebhookEvent