@metamask/subscription-controller 13.0.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -1
- package/dist/SubscriptionController-method-action-types.d.ts +8 -4
- package/dist/SubscriptionController-method-action-types.d.ts.map +1 -1
- package/dist/SubscriptionController-method-action-types.js.map +1 -1
- package/dist/SubscriptionController.d.ts +8 -4
- package/dist/SubscriptionController.d.ts.map +1 -1
- package/dist/SubscriptionController.js +32 -15
- package/dist/SubscriptionController.js.map +1 -1
- package/dist/SubscriptionService-structs.d.ts +36 -36
- package/dist/SubscriptionService-structs.js +4 -4
- package/dist/SubscriptionService-structs.js.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts +2 -2
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService.js +2 -3
- package/dist/subscription-delegation/SubscriptionDelegationService.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionController.js","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAG/E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,EACL,4BAA4B,EAC5B,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,yCAAyC,GAC1C,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAmBhE,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,aAAa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C;QACf,CAAC;QAED,OAAO,CACL,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC;YACnC,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CACpC,CAAC;IACJ,CAAC;IAED,sBAAsB,CAAC,YAA0B;QAC/C,MAAM,sBAAsB,GAAG;YAC7B,GAAG,YAAY;YACf,6BAA6B;YAC7B,QAAQ,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;SACF,CAAC;QAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type {\n StateMetadata,\n ControllerStateChangeEvent,\n ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport type { GeolocationControllerGetGeolocationDataAction } from '@metamask/geolocation-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { SeedlessOnboardingControllerGetIsUserAuthenticatedAction } from '@metamask/seedless-onboarding-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport deepEqual from 'fast-deep-equal';\n\nimport {\n ACTIVE_SUBSCRIPTION_STATUSES,\n controllerName,\n DEFAULT_POLLING_INTERVAL,\n REFUND_ELIGIBLE_COUNTRIES,\n SubscriptionControllerErrorMessage,\n SubscriptionDelegationServiceErrorMessage,\n} from './constants.js';\nimport { createModuleLogger, projectLogger } from './logger.js';\nimport type { SubscriptionControllerMethodActions } from './SubscriptionController-method-action-types.js';\nimport type {\n SubscriptionServiceAssignUserToCohortAction,\n SubscriptionServiceCancelSubscriptionAction,\n SubscriptionServiceGetBillingPortalUrlAction,\n SubscriptionServiceGetBenefitsAction,\n SubscriptionServiceGetPricingAction,\n SubscriptionServiceGetSubscriptionsAction,\n SubscriptionServiceGetSubscriptionsEligibilitiesAction,\n SubscriptionServiceLinkRewardsAction,\n SubscriptionServiceStartSubscriptionWithCardAction,\n SubscriptionServiceStartSubscriptionWithCryptoAction,\n SubscriptionServiceSubmitSponsorshipIntentsAction,\n SubscriptionServiceSubmitUserEventAction,\n SubscriptionServiceUnCancelSubscriptionAction,\n SubscriptionServiceUpdatePaymentMethodCardAction,\n SubscriptionServiceUpdatePaymentMethodCryptoAction,\n} from './SubscriptionService-method-action-types.js';\nimport {\n CRYPTO_AUTH_METHODS,\n PAYMENT_TYPES,\n PRODUCT_TYPES,\n SUBSCRIPTION_STATUSES,\n} from './types.js';\nimport type {\n AssignCohortRequest,\n BillingPortalResponse,\n CryptoAuthMethod,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ProductPrice,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n SubmitSubscriptionCryptoApprovalRequest,\n SubmitUserEventRequest,\n TokenPaymentInfo,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodOpts,\n CachedLastSelectedPaymentMethod,\n CacheLastSelectedPaymentMethodRequest,\n SubmitSponsorshipIntentsMethodParams,\n RecurringInterval,\n SubscriptionStatus,\n LinkRewardsRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionResponse,\n CancelSubscriptionRequest,\n PricingCryptoPaymentMethod,\n SubscriptionBenefitsResponse,\n SubscriptionBenefitsState,\n} from './types.js';\nimport type {\n PricingResponse,\n ProductType,\n ProductEntitlements,\n StartSubscriptionRequest,\n Subscription,\n} from './types.js';\n\nconst log = createModuleLogger(projectLogger, controllerName);\n\nexport type SubscriptionControllerState = {\n customerId?: string;\n trialedProducts: ProductType[];\n subscriptions: Subscription[];\n productEntitlements?: ProductEntitlements;\n pricing?: PricingResponse;\n benefits?: SubscriptionBenefitsState;\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n /** The reward account ID if user has linked rewards to the subscription. */\n rewardAccountId?: CaipAccountId;\n /**\n * The last selected payment method for the user.\n * This is used to display the last selected payment method in the UI.\n * This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\n lastSelectedPaymentMethod?: Partial<\n Record<ProductType, CachedLastSelectedPaymentMethod>\n >;\n};\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetStateAction\n | SubscriptionControllerMethodActions;\n\ntype AllowedActions =\n | SubscriptionServiceGetPricingAction\n | SubscriptionServiceGetSubscriptionsAction\n | SubscriptionServiceGetBenefitsAction\n | SubscriptionServiceGetSubscriptionsEligibilitiesAction\n | SubscriptionServiceCancelSubscriptionAction\n | SubscriptionServiceUnCancelSubscriptionAction\n | SubscriptionServiceStartSubscriptionWithCardAction\n | SubscriptionServiceStartSubscriptionWithCryptoAction\n | SubscriptionServiceUpdatePaymentMethodCardAction\n | SubscriptionServiceUpdatePaymentMethodCryptoAction\n | SubscriptionServiceGetBillingPortalUrlAction\n | SubscriptionServiceSubmitSponsorshipIntentsAction\n | SubscriptionServiceSubmitUserEventAction\n | SubscriptionServiceAssignUserToCohortAction\n | SubscriptionServiceLinkRewardsAction\n | AuthenticationController.AuthenticationControllerPerformSignOutAction\n | SeedlessOnboardingControllerGetIsUserAuthenticatedAction\n | GeolocationControllerGetGeolocationDataAction;\n\n// Events\nexport type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerEvents =\n SubscriptionControllerStateChangeEvent;\n\ntype AllowedEvents = never;\n\n// Messenger\nexport type SubscriptionControllerMessenger = Messenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents\n>;\n\n/**\n * Subscription Controller Options.\n */\nexport type SubscriptionControllerOptions = {\n messenger: SubscriptionControllerMessenger;\n\n /**\n * Initial state to set on this controller.\n */\n state?: Partial<SubscriptionControllerState>;\n\n /**\n * Polling interval to use for the subscription controller.\n *\n * @default 5 minutes.\n */\n pollingInterval?: number;\n};\n\n/**\n * Get the default state for the Subscription Controller.\n *\n * @returns The default state for the Subscription Controller.\n */\nexport function getDefaultSubscriptionControllerState(): SubscriptionControllerState {\n return {\n subscriptions: [],\n trialedProducts: [],\n };\n}\n\n/**\n * Seedless Onboarding Controller State Metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst subscriptionControllerMetadata: StateMetadata<SubscriptionControllerState> =\n {\n subscriptions: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n productEntitlements: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSubscription: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n customerId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n rewardAccountId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n trialedProducts: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pricing: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n benefits: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSelectedPaymentMethod: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n };\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getPricing',\n 'getSubscriptions',\n 'getBenefits',\n 'getSubscriptionByProduct',\n 'isUserEligibleForTrial',\n 'getSubscriptionsEligibilities',\n 'cancelSubscription',\n 'unCancelSubscription',\n 'startSubscriptionWithCard',\n 'startSubscriptionWithCrypto',\n 'stopAllPolling',\n 'submitSubscriptionCryptoApproval',\n 'getCryptoApproveTransactionParams',\n 'updatePaymentMethod',\n 'getBillingPortalUrl',\n 'cacheLastSelectedPaymentMethod',\n 'clearLastSelectedPaymentMethod',\n 'submitSponsorshipIntents',\n 'submitUserEvent',\n 'assignUserToCohort',\n 'linkRewards',\n 'getTokenApproveAmount',\n 'getTokenMinimumBalanceAmount',\n 'clearState',\n 'triggerAccessTokenRefresh',\n] as const;\n\nexport class SubscriptionController extends StaticIntervalPollingController()<\n typeof controllerName,\n SubscriptionControllerState,\n SubscriptionControllerMessenger\n> {\n /**\n * Creates a new SubscriptionController instance.\n *\n * @param options - The options for the SubscriptionController.\n * @param options.messenger - A restricted messenger.\n * @param options.state - Initial state to set on this controller.\n * @param options.pollingInterval - The polling interval to use for the subscription controller.\n */\n constructor(options: SubscriptionControllerOptions) {\n const {\n messenger,\n state,\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n } = options;\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.setIntervalLength(pollingInterval);\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Gets the pricing information from the subscription service.\n *\n * @returns The pricing information.\n */\n async getPricing(): Promise<PricingResponse> {\n const pricing = await this.messenger.call('SubscriptionService:getPricing');\n this.update((state) => {\n state.pricing = pricing;\n });\n return pricing;\n }\n\n async getSubscriptions(): Promise<Subscription[]> {\n return await this.#getSubscriptions();\n }\n\n async #getSubscriptions({\n refreshBenefits = true,\n }: { refreshBenefits?: boolean } = {}): Promise<Subscription[]> {\n const currentSubscriptions = this.state.subscriptions;\n const currentTrialedProducts = this.state.trialedProducts;\n const currentCustomerId = this.state.customerId;\n const currentLastSubscription = this.state.lastSubscription;\n const currentRewardAccountId = this.state.rewardAccountId;\n const currentProductEntitlements = this.state.productEntitlements;\n const currentSubscriptionState: GetSubscriptionsResponse = {\n customerId: currentCustomerId,\n subscriptions: currentSubscriptions,\n trialedProducts: currentTrialedProducts,\n lastSubscription: currentLastSubscription,\n rewardAccountId: currentRewardAccountId,\n productEntitlements: currentProductEntitlements,\n };\n\n const newSubscriptionState = await this.messenger.call(\n 'SubscriptionService:getSubscriptions',\n );\n\n this.#updateSubscriptionStateIfChanged(\n currentSubscriptionState,\n newSubscriptionState,\n );\n\n await this.#refreshBenefitsIfActive(refreshBenefits);\n\n return newSubscriptionState.subscriptions;\n }\n\n /**\n * Updates the subscription state and refreshes the access token when the\n * fetched subscription state differs from the current state.\n *\n * @param currentState - The subscription state captured before the request.\n * @param newState - The subscription state returned by the service.\n */\n #updateSubscriptionStateIfChanged(\n currentState: GetSubscriptionsResponse,\n newState: GetSubscriptionsResponse,\n ): void {\n const {\n subscriptions: currentSubscriptions,\n trialedProducts: currentTrialedProducts,\n customerId: currentCustomerId,\n lastSubscription: currentLastSubscription,\n rewardAccountId: currentRewardAccountId,\n productEntitlements: currentProductEntitlements,\n } = currentState;\n const {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\n rewardAccountId: newRewardAccountId,\n productEntitlements: newProductEntitlements,\n } = newState;\n\n const areSubscriptionsEqual = this.#areSubscriptionsEqual(\n currentSubscriptions,\n newSubscriptions,\n );\n const areTrialedProductsEqual = this.#areTrialedProductsEqual(\n currentTrialedProducts,\n newTrialedProducts,\n );\n const isLastSubscriptionEqual = this.#isSubscriptionEqual(\n currentLastSubscription,\n newLastSubscription,\n );\n const areCustomerIdsEqual = currentCustomerId === newCustomerId;\n const areRewardAccountIdsEqual =\n currentRewardAccountId === newRewardAccountId;\n const areProductEntitlementsEqual = this.#areProductEntitlementsEqual(\n currentProductEntitlements,\n newProductEntitlements,\n );\n // only update the state if the subscriptions or trialed products are different\n // this prevents unnecessary state updates events, easier for the clients to handle\n\n // Only update the state if any subscription-related field changed. This\n // prevents unnecessary state change events for clients to handle.\n if (\n !areSubscriptionsEqual ||\n !isLastSubscriptionEqual ||\n !areTrialedProductsEqual ||\n !areCustomerIdsEqual ||\n !areRewardAccountIdsEqual ||\n !areProductEntitlementsEqual\n ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\n state.rewardAccountId = newRewardAccountId;\n // Omitted entitlements are an empty map so selectors fail closed\n // instead of keeping last-known paid-feature flags.\n state.productEntitlements = newProductEntitlements ?? {};\n });\n // Trigger an access token refresh to ensure the user has the latest\n // access token after a subscription state change.\n this.triggerAccessTokenRefresh();\n }\n }\n\n /**\n * Gets and stores the user's subscription benefits.\n *\n * @returns The benefits response.\n * @throws If the user is not an active Money Account Plus subscriber or is\n * not eligible for benefits.\n */\n async getBenefits(): Promise<SubscriptionBenefitsResponse> {\n this.#assertIsActiveMoneyAccountPlusSubscriber();\n\n const benefits = await this.messenger.call(\n 'SubscriptionService:getBenefits',\n );\n\n // The subscription may have become inactive while the benefits request\n // was in flight. Re-check before persisting the response so stale\n // benefits cannot be restored after entitlement ends.\n this.#assertIsActiveMoneyAccountPlusSubscriber();\n\n this.update((state) => {\n state.benefits = benefits.eligible\n ? {\n billingPeriodId: benefits.billingPeriodId,\n ...benefits.products,\n }\n : undefined;\n });\n\n if (!benefits.eligible) {\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n\n return benefits;\n }\n\n /**\n * Get the subscription by product.\n *\n * @param productType - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(productType: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((product) => product.name === productType),\n );\n }\n\n /**\n * Whether the user is eligible to start a trial for the given product.\n *\n * Shield is eligible when the user has not trialed Shield before.\n * Money Account Plus is eligible when the user has not trialed it before\n * and is authenticated with social login. Only an unlocked wallet can\n * subscribe, so `SeedlessOnboardingController:getIsUserAuthenticated` is a\n * sufficient social-login check.\n *\n * @param productType - The product to check.\n * @returns Whether the user is eligible for a trial.\n */\n async isUserEligibleForTrial(productType: ProductType): Promise<boolean> {\n if (this.state.trialedProducts.includes(productType)) {\n return false;\n }\n\n switch (productType) {\n case PRODUCT_TYPES.SHIELD:\n return true;\n case PRODUCT_TYPES.MONEY_ACCOUNT_PLUS:\n return await this.messenger.call(\n 'SeedlessOnboardingController:getIsUserAuthenticated',\n );\n default: {\n // `productType` is `never` here. A new `PRODUCT_TYPES` member fails\n // compilation until this switch handles it.\n const unexpectedProduct: never = productType;\n throw new Error(\n `Unexpected product type: ${String(unexpectedProduct)}`,\n );\n }\n }\n }\n\n /**\n * Get the subscriptions eligibilities.\n *\n * @param request - Optional request object containing user balance to check cohort eligibility.\n * @returns The subscriptions eligibilities.\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n return await this.messenger.call(\n 'SubscriptionService:getSubscriptionsEligibilities',\n request,\n );\n }\n\n async cancelSubscription(request: CancelSubscriptionRequest): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const cancelledSubscription = await this.messenger.call(\n 'SubscriptionService:cancelSubscription',\n request,\n );\n\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? { ...subscription, ...cancelledSubscription }\n : subscription,\n );\n });\n\n try {\n await this.#getSubscriptions();\n } catch (error) {\n log('Failed to refresh subscriptions after cancellation', error);\n\n // Preserve the existing best-effort benefits refresh behavior if the\n // canonical subscription refresh is unavailable.\n await this.#refreshBenefitsIfActive();\n }\n\n this.triggerAccessTokenRefresh();\n }\n\n async unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const uncancelledSubscription = await this.messenger.call(\n 'SubscriptionService:unCancelSubscription',\n {\n subscriptionId: request.subscriptionId,\n },\n );\n\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? { ...subscription, ...uncancelledSubscription }\n : subscription,\n );\n });\n\n await this.#refreshBenefitsIfActive();\n\n this.triggerAccessTokenRefresh();\n }\n\n /**\n * Starts a card-paid subscription checkout session for the requested products\n * (e.g. Shield or Money Account Plus).\n *\n * `isTrialRequested` on the request is ignored and overwritten from pricing\n * (`trialPeriodDays > 0`) and `trialedProducts`.\n *\n * `isEligibleForRefund` is sent as provided. When omitted, it is resolved\n * from geolocation (EU/EEA), or `false` if the lookup fails.\n *\n * @param request - The start subscription request.\n * @returns The checkout session response.\n */\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n // get the latest subscriptions state before computing trial eligibility\n await this.getSubscriptions();\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n const response = await this.messenger.call(\n 'SubscriptionService:startSubscriptionWithCard',\n {\n ...request,\n isTrialRequested: this.#getIsTrialRequested(\n request.products,\n request.recurringInterval,\n ),\n isEligibleForRefund: await this.#getIsEligibleForRefund(\n request.isEligibleForRefund,\n ),\n },\n );\n // note: no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet\n\n return response;\n }\n\n /**\n * Starts a crypto-paid subscription for the requested products\n * (e.g. Shield or Money Account Plus). Unlike card checkout, this\n * creates the subscription immediately, so local state is refreshed\n * afterwards.\n *\n * `isTrialRequested` on the request is ignored and overwritten from pricing\n * (`trialPeriodDays > 0`) and `trialedProducts`.\n *\n * `isEligibleForRefund` is sent as provided. When omitted, it is resolved\n * from geolocation (EU/EEA), or `false` if the lookup fails.\n *\n * @param request - The start crypto subscription request.\n * @returns The start crypto subscription response.\n * @throws If `products` is empty.\n */\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n\n // get the latest subscriptions state before computing trial eligibility\n await this.#getSubscriptions({ refreshBenefits: false });\n this.#assertIsUserNotSubscribed({ products: request.products });\n const isTrialRequested = this.#getIsTrialRequested(\n request.products,\n request.recurringInterval,\n );\n if (\n request.assertTrialEligibility &&\n request.isTrialRequested !== isTrialRequested\n ) {\n throw new Error(\n SubscriptionDelegationServiceErrorMessage.TrialEligibilityChanged,\n );\n }\n const {\n assertTrialEligibility: _assertTrialEligibility,\n ...subscriptionRequest\n } = request;\n const response = await this.messenger.call(\n 'SubscriptionService:startSubscriptionWithCrypto',\n {\n ...subscriptionRequest,\n isTrialRequested,\n isEligibleForRefund: await this.#getIsEligibleForRefund(\n request.isEligibleForRefund,\n ),\n },\n );\n\n // Crypto start creates the subscription immediately (unlike card checkout).\n await this.getSubscriptions();\n\n return response;\n }\n\n /**\n * Submits a Shield ERC-20 crypto approval transaction to start or update a\n * crypto subscription.\n *\n * This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.\n * Delegation-based products (e.g. Money Account) must call\n * `startSubscriptionWithCrypto` instead.\n *\n * @param request - The crypto approval request.\n * @param request.productType - The subscription product. Typed as\n * `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more\n * product).\n * @param request.txMeta - The transaction metadata. Must have type\n * `TransactionType.shieldSubscriptionApprove`.\n * @param request.isSponsored - Whether the transaction is sponsored.\n * @param request.rewardAccountId - The account ID of the reward subscription\n * to link.\n * @throws If `productType` is not Shield or `txMeta.type` is not\n * `shieldSubscriptionApprove`.\n * @returns void\n */\n async submitSubscriptionCryptoApproval(\n request: SubmitSubscriptionCryptoApprovalRequest,\n ): Promise<void> {\n const { productType, txMeta, isSponsored, rewardAccountId } = request;\n if (\n // Widen for the runtime guard: JS / unsound callers may still pass a\n // non-Shield product.\n (productType as ProductType) !== PRODUCT_TYPES.SHIELD ||\n txMeta.type !== TransactionType.shieldSubscriptionApprove\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.CryptoApprovalRequiresShieldApprove,\n );\n }\n\n const { chainId, rawTx } = txMeta;\n if (!chainId || !rawTx) {\n throw new Error('Chain ID or raw transaction not found');\n }\n\n const { pricing, lastSelectedPaymentMethod } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n if (!lastSelectedPaymentMethod) {\n throw new Error('Last selected payment method not found');\n }\n const lastSelectedPaymentMethodForProduct =\n lastSelectedPaymentMethod[productType];\n this.#assertIsPaymentMethodCrypto(lastSelectedPaymentMethodForProduct);\n\n const productPrice = this.#getProductPriceByProductAndPlan(\n productType,\n lastSelectedPaymentMethodForProduct.plan,\n );\n // get the latest subscriptions state before computing trial eligibility\n await this.#getSubscriptions({ refreshBenefits: false });\n const isTrialRequested = this.#getIsTrialRequested(\n [productType],\n lastSelectedPaymentMethodForProduct.plan,\n );\n const currentSubscription = this.getSubscriptionByProduct(productType);\n\n this.#assertValidSubscriptionStateForCryptoApproval({\n productType,\n });\n // if subscription exists, this transaction is for changing payment method\n const isChangePaymentMethod = Boolean(currentSubscription);\n\n if (isChangePaymentMethod) {\n await this.updatePaymentMethod({\n paymentType: PAYMENT_TYPES.byCrypto,\n subscriptionId: (currentSubscription as Subscription).id,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodForProduct.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n });\n } else {\n const params: StartCryptoSubscriptionRequest = {\n products: [productType],\n isTrialRequested,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodForProduct.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n cryptoAuthMethod: CRYPTO_AUTH_METHODS.ERC20_APPROVAL,\n isSponsored,\n useTestClock: lastSelectedPaymentMethodForProduct.useTestClock,\n rewardAccountId,\n };\n await this.startSubscriptionWithCrypto(params);\n }\n\n // update the subscriptions state after subscription created in server\n await this.#getSubscriptions({ refreshBenefits: false });\n }\n\n /**\n * Get transaction params to create crypto approve transaction for subscription payment\n *\n * @param request - The request object\n * @param request.chainId - The chain ID\n * @param request.tokenAddress - The address of the token\n * @param request.productType - The product type\n * @param request.interval - The interval\n * @returns The crypto approve transaction params\n */\n getCryptoApproveTransactionParams(\n request: GetCryptoApproveTransactionRequest,\n ): GetCryptoApproveTransactionResponse {\n const { pricing } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n const product = pricing.products.find(\n (productInfo) => productInfo.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find(\n (productPrice) => productPrice.interval === request.interval,\n );\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = this.#findCryptoPaymentMethod(\n request.productType,\n CRYPTO_AUTH_METHODS.ERC20_APPROVAL,\n );\n if (!chainsPaymentInfo) {\n throw new Error('Chains payment info not found');\n }\n const chainPaymentInfo = chainsPaymentInfo.chains?.find(\n (chain) => chain.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (token) =>\n token.address.toLowerCase() ===\n request.paymentTokenAddress.toLowerCase(),\n );\n if (!tokenPaymentInfo) {\n throw new Error('Invalid token address');\n }\n\n const tokenApproveAmount = this.getTokenApproveAmount(\n price,\n tokenPaymentInfo,\n );\n\n return {\n approveAmount: tokenApproveAmount,\n paymentAddress: chainPaymentInfo.paymentAddress,\n paymentTokenAddress: request.paymentTokenAddress,\n chainId: request.chainId,\n };\n }\n\n async updatePaymentMethod(\n opts: UpdatePaymentMethodOpts,\n ): Promise<UpdatePaymentMethodCardResponse | Subscription[]> {\n if (opts.paymentType === PAYMENT_TYPES.byCard) {\n const { paymentType, ...cardRequest } = opts;\n return await this.messenger.call(\n 'SubscriptionService:updatePaymentMethodCard',\n cardRequest,\n );\n } else if (opts.paymentType === PAYMENT_TYPES.byCrypto) {\n const { paymentType, ...cryptoRequest } = opts;\n await this.messenger.call(\n 'SubscriptionService:updatePaymentMethodCrypto',\n cryptoRequest,\n );\n return await this.getSubscriptions();\n }\n throw new Error('Invalid payment type');\n }\n\n /**\n * Gets the billing portal URL.\n *\n * @returns The billing portal URL\n */\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n return await this.messenger.call('SubscriptionService:getBillingPortalUrl');\n }\n\n /**\n * Cache the last selected payment method for a specific product.\n *\n * @param request - The request object.\n * @param request.product - The product to cache the payment method for.\n * @param request.paymentMethod - The payment method to cache.\n * @param request.paymentMethod.type - The type of the payment method.\n * @param request.paymentMethod.paymentTokenAddress - The payment token address.\n * @param request.paymentMethod.plan - The plan of the payment method.\n */\n cacheLastSelectedPaymentMethod(\n request: CacheLastSelectedPaymentMethodRequest,\n ): void {\n const { product, paymentMethod } = request;\n if (\n paymentMethod.type === PAYMENT_TYPES.byCrypto &&\n (!paymentMethod.paymentTokenAddress || !paymentMethod.paymentTokenSymbol)\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentTokenAddressAndSymbolRequiredForCrypto,\n );\n }\n\n this.update((state) => {\n state.lastSelectedPaymentMethod = {\n ...state.lastSelectedPaymentMethod,\n [product]: paymentMethod,\n };\n });\n }\n\n /**\n * Clear the last selected payment method for a specific product.\n *\n * @param product - The product to clear the payment method for.\n */\n clearLastSelectedPaymentMethod(product: ProductType): void {\n this.update((state) => {\n if (state.lastSelectedPaymentMethod) {\n const { [product]: _, ...rest } = state.lastSelectedPaymentMethod;\n state.lastSelectedPaymentMethod = rest;\n }\n });\n }\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false if the chain does not support sponsorship or the user has already trialed\n * @throws If the crypto payment method or chain is missing from pricing\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsMethodParams,\n ): Promise<boolean> {\n if (request.products.length === 0) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n const selectedPaymentMethod =\n this.state.lastSelectedPaymentMethod?.[request.products[0]];\n this.#assertIsPaymentMethodCrypto(selectedPaymentMethod);\n\n const cryptoAuthMethod =\n selectedPaymentMethod.cryptoAuthMethod ??\n CRYPTO_AUTH_METHODS.ERC20_APPROVAL;\n const isEligibleForTrialedSponsorship =\n this.#getIsEligibleForTrialedSponsorship(\n request.chainId,\n request.products,\n cryptoAuthMethod,\n );\n if (!isEligibleForTrialedSponsorship) {\n return false;\n }\n\n const { paymentTokenSymbol, plan } = selectedPaymentMethod;\n const productPrice = this.#getProductPriceByProductAndPlan(\n // we only support one product at a time for now\n request.products[0],\n plan,\n );\n const billingCycles = productPrice.minBillingCycles;\n\n await this.messenger.call('SubscriptionService:submitSponsorshipIntents', {\n ...request,\n paymentTokenSymbol,\n billingCycles,\n recurringInterval: plan,\n });\n return true;\n }\n\n /**\n * Submit a user event from the UI. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n await this.messenger.call('SubscriptionService:submitUserEvent', request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n await this.messenger.call(\n 'SubscriptionService:assignUserToCohort',\n request,\n );\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward subscription ID.\n * @param request.subscriptionId - The ID of the subscription to link rewards to.\n * @param request.rewardAccountId - The account ID of the reward subscription to link to the subscription.\n * @example { subscriptionId: '1234567890', rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns Resolves when the rewards are linked successfully.\n */\n async linkRewards(\n request: LinkRewardsRequest & { subscriptionId: string },\n ): Promise<void> {\n // assert that the user is subscribed to the subscription\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n // link rewards to the subscription\n const response = await this.messenger.call(\n 'SubscriptionService:linkRewards',\n {\n rewardAccountId: request.rewardAccountId,\n },\n );\n if (!response.success) {\n throw new Error(SubscriptionControllerErrorMessage.LinkRewardsFailed);\n }\n }\n\n async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n async #refreshBenefitsIfActive(refreshBenefits = true): Promise<void> {\n if (!this.#hasActiveMoneyAccountPlusSubscription()) {\n if (this.state.benefits) {\n this.update((state) => {\n state.benefits = undefined;\n });\n }\n return;\n }\n\n if (!refreshBenefits) {\n return;\n }\n\n try {\n await this.getBenefits();\n } catch (error) {\n log('Failed to refresh subscription benefits', error);\n }\n }\n\n /**\n * Calculate total subscription price amount (approval amount) from price info\n * e.g: $8 per month * 12 months min billing cycles = $96\n *\n * @param price - The price info\n * @returns The price amount\n */\n #getSubscriptionPriceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCycles)\n .toString();\n return amount;\n }\n\n /**\n * Calculate minimum subscription balance amount from price info\n *\n * @param price - The price info\n * @returns The balance amount\n */\n #getSubscriptionBalanceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCyclesForBalance)\n .toString();\n return amount;\n }\n\n /**\n * Calculate token approve amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token approve amount\n */\n getTokenApproveAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate?.[\n price.currency as keyof NonNullable<TokenPaymentInfo['conversionRate']>\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n // price of the product\n const priceAmount = new BigNumber(this.#getSubscriptionPriceAmount(price));\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = priceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Calculate token minimum balance amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token balance amount\n */\n getTokenMinimumBalanceAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate?.[\n price.currency as keyof NonNullable<TokenPaymentInfo['conversionRate']>\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n const balanceAmount = new BigNumber(\n this.#getSubscriptionBalanceAmount(price),\n );\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = balanceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Clears the subscription state and resets to default values.\n */\n clearState(): void {\n const defaultState = getDefaultSubscriptionControllerState();\n this.update(() => {\n return defaultState;\n });\n }\n\n /**\n * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh(): void {\n // We perform a sign out to clear the access token from the authentication\n // controller. Next time the access token is requested, a new access token\n // will be fetched.\n this.messenger.call('AuthenticationController:performSignOut');\n }\n\n #getProductPriceByProductAndPlan(\n productType: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find(\n (product) => product.name === productType,\n );\n const productPrice = productPricing?.prices.find(\n (price) => price.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertValidSubscriptionStateForCryptoApproval({\n productType,\n }: {\n productType: ProductType;\n }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => product.name === productType),\n );\n\n const isValid =\n !subscription ||\n (\n [\n SUBSCRIPTION_STATUSES.awaitingFunds,\n SUBSCRIPTION_STATUSES.pastDue,\n SUBSCRIPTION_STATUSES.unpaid,\n SUBSCRIPTION_STATUSES.paused,\n SUBSCRIPTION_STATUSES.provisional,\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n ] as SubscriptionStatus[]\n ).includes(subscription.status);\n if (!isValid) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionNotValidForCryptoApproval,\n );\n }\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => products.includes(product.name)),\n );\n\n if (\n subscription &&\n ACTIVE_SUBSCRIPTION_STATUSES.includes(subscription.status)\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserAlreadySubscribed);\n }\n }\n\n #assertIsActiveMoneyAccountPlusSubscriber(): void {\n if (!this.#hasActiveMoneyAccountPlusSubscription()) {\n if (this.state.benefits) {\n this.update((state) => {\n state.benefits = undefined;\n });\n }\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n }\n\n #assertIsUserSubscribed(request: { subscriptionId: string }): void {\n if (\n !this.state.subscriptions.find(\n (subscription) => subscription.id === request.subscriptionId,\n )\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n }\n\n /**\n * Asserts that the value is a valid crypto payment method.\n *\n * After this assert, `cryptoAuthMethod` and `useTestClock` remain optional\n * because persisted cache entries may omit them.\n *\n * @param value - The value to assert.\n * @throws an error if the value is not a valid crypto payment method.\n */\n #assertIsPaymentMethodCrypto(\n value: CachedLastSelectedPaymentMethod | undefined,\n ): asserts value is CachedLastSelectedPaymentMethod & {\n type: typeof PAYMENT_TYPES.byCrypto;\n paymentTokenAddress: Hex;\n paymentTokenSymbol: string;\n } {\n if (\n value?.type !== PAYMENT_TYPES.byCrypto ||\n !value.paymentTokenAddress ||\n !value.paymentTokenSymbol\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentMethodNotCrypto,\n );\n }\n }\n\n #hasActiveMoneyAccountPlusSubscription(): boolean {\n return this.state.subscriptions.some(\n (subscription) =>\n subscription.products.some(\n (product) => product.name === PRODUCT_TYPES.MONEY_ACCOUNT_PLUS,\n ) && ACTIVE_SUBSCRIPTION_STATUSES.includes(subscription.status),\n );\n }\n\n /**\n * Determines if the user is eligible for trialed sponsorship for the given chain and products.\n * The user is eligible if the chain supports sponsorship and the user has not trialed the provided products before.\n *\n * @param chainId - The chain ID\n * @param products - The products to check eligibility for\n * @param cryptoAuthMethod - The crypto authorization method of the selected payment method\n * @returns True if the user is eligible for trialed sponsorship, false otherwise\n */\n #getIsEligibleForTrialedSponsorship(\n chainId: Hex,\n products: ProductType[],\n cryptoAuthMethod: CryptoAuthMethod,\n ): boolean {\n const isSponsorshipSupported = this.#getChainSupportsSponsorship(\n chainId,\n products[0],\n cryptoAuthMethod,\n );\n\n // verify if the user has trialed the provided products before\n const hasTrialedBefore = this.state.trialedProducts.some((product) =>\n products.includes(product),\n );\n\n return isSponsorshipSupported && !hasTrialedBefore;\n }\n\n /**\n * Whether a trial should be requested for the given products and plan.\n * True only when every product has `trialPeriodDays > 0` and has not\n * already been trialed.\n *\n * @param products - The products to check.\n * @param plan - The recurring interval to look up pricing for.\n * @returns Whether a trial should be requested.\n */\n #getIsTrialRequested(\n products: ProductType[],\n plan: RecurringInterval,\n ): boolean {\n return products.every((productType) => {\n if (this.state.trialedProducts.includes(productType)) {\n return false;\n }\n const productPrice = this.#getProductPriceByProductAndPlan(\n productType,\n plan,\n );\n return productPrice.trialPeriodDays > 0;\n });\n }\n\n /**\n * Returns the caller-provided refund eligibility when set. Otherwise\n * resolves it from geolocation (EU/EEA), or `false` if the lookup fails.\n *\n * @param isEligibleForRefund - Caller-provided eligibility, if any.\n * @returns Whether the user is eligible for a refund.\n */\n async #getIsEligibleForRefund(\n isEligibleForRefund?: boolean,\n ): Promise<boolean> {\n if (isEligibleForRefund !== undefined) {\n return isEligibleForRefund;\n }\n\n try {\n const { country } = await this.messenger.call(\n 'GeolocationController:getGeolocationData',\n );\n return (\n country !== null && REFUND_ELIGIBLE_COUNTRIES.has(country.toUpperCase())\n );\n } catch (error) {\n log('Failed to resolve geolocation for refund eligibility', error);\n return false;\n }\n }\n\n #findCryptoPaymentMethod(\n productType: ProductType,\n cryptoAuthMethod: CryptoAuthMethod,\n ): PricingCryptoPaymentMethod | undefined {\n const matches: {\n method: PricingCryptoPaymentMethod;\n explicit: boolean;\n }[] = [];\n\n for (const paymentMethod of this.state.pricing?.paymentMethods ?? []) {\n if (paymentMethod.type !== PAYMENT_TYPES.byCrypto) {\n continue;\n }\n\n const resolved = this.#resolveCryptoPaymentMethodDefaults(paymentMethod);\n if (!resolved) {\n continue;\n }\n\n if (\n resolved.cryptoAuthMethod === cryptoAuthMethod &&\n resolved.products.includes(productType)\n ) {\n matches.push({\n method: paymentMethod,\n explicit: resolved.explicit,\n });\n }\n }\n\n if (matches.length === 0) {\n return undefined;\n }\n\n const explicitMatches = matches.filter((match) => match.explicit);\n const candidates = explicitMatches.length > 0 ? explicitMatches : matches;\n\n if (candidates.length > 1) {\n throw new Error('Multiple matching crypto payment methods found');\n }\n\n return candidates[0].method;\n }\n\n /**\n * Resolves omitted `products` / `cryptoAuthMethod` on a crypto pricing row.\n * Legacy Shield + `erc20_approval` defaults apply only when both fields are\n * absent. If `products` is present, the list must be non-empty and\n * `cryptoAuthMethod` must be explicit; otherwise the row is ignored.\n *\n * @param paymentMethod - The crypto pricing row.\n * @returns Resolved products and auth method, or `undefined` if the row is\n * incomplete.\n */\n #resolveCryptoPaymentMethodDefaults(\n paymentMethod: PricingCryptoPaymentMethod,\n ):\n | {\n products: ProductType[];\n cryptoAuthMethod: CryptoAuthMethod;\n explicit: boolean;\n }\n | undefined {\n const productsPresent = paymentMethod.products !== undefined;\n const authPresent = paymentMethod.cryptoAuthMethod !== undefined;\n\n if (!productsPresent && !authPresent) {\n return {\n products: [PRODUCT_TYPES.SHIELD],\n cryptoAuthMethod: CRYPTO_AUTH_METHODS.ERC20_APPROVAL,\n explicit: false,\n };\n }\n\n if (!paymentMethod.products?.length || !paymentMethod.cryptoAuthMethod) {\n return undefined;\n }\n\n return {\n products: paymentMethod.products,\n cryptoAuthMethod: paymentMethod.cryptoAuthMethod,\n explicit: true,\n };\n }\n\n /**\n * Whether the given chain supports sponsorship for the product and auth method.\n *\n * @param chainId - The chain ID\n * @param productType - The product type\n * @param cryptoAuthMethod - The crypto authorization method to look up\n * @returns True if the chain row has sponsorship enabled, false if it is explicitly not sponsored\n * @throws If the crypto payment method or chain row is missing from pricing\n */\n #getChainSupportsSponsorship(\n chainId: Hex,\n productType: ProductType,\n cryptoAuthMethod: CryptoAuthMethod,\n ): boolean {\n const cryptoPaymentInfo = this.#findCryptoPaymentMethod(\n productType,\n cryptoAuthMethod,\n );\n if (!cryptoPaymentInfo) {\n throw new Error('Chains payment info not found');\n }\n\n const chainPaymentInfo = cryptoPaymentInfo.chains?.find(\n (chain) => chain.chainId === chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n return Boolean(chainPaymentInfo.isSponsorshipSupported);\n }\n\n /**\n * Determines whether two trialed products arrays are equal by comparing all products in the arrays.\n *\n * @param oldTrialedProducts - The first trialed products array to compare.\n * @param newTrialedProducts - The second trialed products array to compare.\n * @returns True if the trialed products arrays are equal, false otherwise.\n */\n #areTrialedProductsEqual(\n oldTrialedProducts: ProductType[],\n newTrialedProducts: ProductType[],\n ): boolean {\n return (\n oldTrialedProducts.length === newTrialedProducts?.length &&\n oldTrialedProducts.every((product) =>\n newTrialedProducts?.includes(product),\n )\n );\n }\n\n /**\n * Compares product entitlement maps without treating object key order as a\n * change. Insertion-order-sensitive `JSON.stringify` can otherwise treat an\n * equivalent API payload as different and trigger `performSignOut`.\n *\n * @param oldProductEntitlements - Stored product entitlements.\n * @param newProductEntitlements - Freshly fetched product entitlements.\n * @returns True if the maps are equal regardless of key order.\n */\n #areProductEntitlementsEqual(\n oldProductEntitlements?: ProductEntitlements,\n newProductEntitlements?: ProductEntitlements,\n ): boolean {\n return deepEqual(\n oldProductEntitlements ?? {},\n newProductEntitlements ?? {},\n );\n }\n\n /**\n * Determines whether two subscription arrays are equal by comparing all properties\n * of each subscription in the arrays.\n *\n * @param oldSubs - The first subscription array to compare.\n * @param newSubs - The second subscription array to compare.\n * @returns True if the subscription arrays are equal, false otherwise.\n */\n #areSubscriptionsEqual(\n oldSubs: Subscription[],\n newSubs: Subscription[],\n ): boolean {\n // Check if arrays have different lengths\n if (oldSubs.length !== newSubs.length) {\n return false;\n }\n\n // Sort both arrays by id to ensure consistent comparison\n const sortedOldSubs = [...oldSubs].sort((a, b) => a.id.localeCompare(b.id));\n const sortedNewSubs = [...newSubs].sort((a, b) => a.id.localeCompare(b.id));\n\n // Check if all subscriptions are equal\n return sortedOldSubs.every((oldSub, index) => {\n const newSub = sortedNewSubs[index];\n return this.#isSubscriptionEqual(oldSub, newSub);\n });\n }\n\n #isSubscriptionEqual(oldSub?: Subscription, newSub?: Subscription): boolean {\n // not equal if one is undefined and the other is defined\n if (!oldSub || !newSub) {\n if (!oldSub && !newSub) {\n return true;\n }\n return false;\n }\n\n return (\n this.#stringifySubscription(oldSub) ===\n this.#stringifySubscription(newSub)\n );\n }\n\n #stringifySubscription(subscription: Subscription): string {\n const subsWithSortedProducts = {\n ...subscription,\n // order the products by name\n products: [...subscription.products].sort((a, b) =>\n a.name.localeCompare(b.name),\n ),\n };\n\n return JSON.stringify(subsWithSortedProducts);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SubscriptionController.js","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAG/E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,EACL,4BAA4B,EAC5B,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,yCAAyC,GAC1C,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAmBhE,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAsCpB,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;AAuF9D;;;;GAIG;AACH,MAAM,UAAU,qCAAqC;IACnD,OAAO;QACL,aAAa,EAAE,EAAE;QACjB,eAAe,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,8BAA8B,GAClC;IACE,aAAa,EAAE;QACb,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,mBAAmB,EAAE;QACnB,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QAC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AC7B,QAAQ,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;SACF,CAAC;QAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type {\n StateMetadata,\n ControllerStateChangeEvent,\n ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport type { GeolocationControllerGetGeolocationDataAction } from '@metamask/geolocation-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { SeedlessOnboardingControllerGetIsUserAuthenticatedAction } from '@metamask/seedless-onboarding-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport deepEqual from 'fast-deep-equal';\n\nimport {\n ACTIVE_SUBSCRIPTION_STATUSES,\n controllerName,\n DEFAULT_POLLING_INTERVAL,\n REFUND_ELIGIBLE_COUNTRIES,\n SubscriptionControllerErrorMessage,\n SubscriptionDelegationServiceErrorMessage,\n} from './constants.js';\nimport { createModuleLogger, projectLogger } from './logger.js';\nimport type { SubscriptionControllerMethodActions } from './SubscriptionController-method-action-types.js';\nimport type {\n SubscriptionServiceAssignUserToCohortAction,\n SubscriptionServiceCancelSubscriptionAction,\n SubscriptionServiceGetBillingPortalUrlAction,\n SubscriptionServiceGetBenefitsAction,\n SubscriptionServiceGetPricingAction,\n SubscriptionServiceGetSubscriptionsAction,\n SubscriptionServiceGetSubscriptionsEligibilitiesAction,\n SubscriptionServiceLinkRewardsAction,\n SubscriptionServiceStartSubscriptionWithCardAction,\n SubscriptionServiceStartSubscriptionWithCryptoAction,\n SubscriptionServiceSubmitSponsorshipIntentsAction,\n SubscriptionServiceSubmitUserEventAction,\n SubscriptionServiceUnCancelSubscriptionAction,\n SubscriptionServiceUpdatePaymentMethodCardAction,\n SubscriptionServiceUpdatePaymentMethodCryptoAction,\n} from './SubscriptionService-method-action-types.js';\nimport {\n CRYPTO_AUTH_METHODS,\n PAYMENT_TYPES,\n PRODUCT_TYPES,\n SUBSCRIPTION_STATUSES,\n} from './types.js';\nimport type {\n AssignCohortRequest,\n BillingPortalResponse,\n CryptoAuthMethod,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ProductPrice,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n SubmitSubscriptionCryptoApprovalRequest,\n SubmitUserEventRequest,\n TokenPaymentInfo,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodOpts,\n CachedLastSelectedPaymentMethod,\n CacheLastSelectedPaymentMethodRequest,\n SubmitSponsorshipIntentsMethodParams,\n RecurringInterval,\n SubscriptionStatus,\n LinkRewardsRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionResponse,\n CancelSubscriptionRequest,\n PricingCryptoPaymentMethod,\n SubscriptionBenefitsResponse,\n SubscriptionBenefitsState,\n} from './types.js';\nimport type {\n PricingResponse,\n ProductType,\n ProductEntitlements,\n StartSubscriptionRequest,\n Subscription,\n} from './types.js';\n\nconst log = createModuleLogger(projectLogger, controllerName);\n\nexport type SubscriptionControllerState = {\n customerId?: string;\n trialedProducts: ProductType[];\n subscriptions: Subscription[];\n productEntitlements?: ProductEntitlements;\n pricing?: PricingResponse;\n benefits?: SubscriptionBenefitsState;\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n /** The reward account ID if user has linked rewards to the subscription. */\n rewardAccountId?: CaipAccountId;\n /**\n * The last selected payment method for the user.\n * This is used to display the last selected payment method in the UI.\n * This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\n lastSelectedPaymentMethod?: Partial<\n Record<ProductType, CachedLastSelectedPaymentMethod>\n >;\n};\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetStateAction\n | SubscriptionControllerMethodActions;\n\ntype AllowedActions =\n | SubscriptionServiceGetPricingAction\n | SubscriptionServiceGetSubscriptionsAction\n | SubscriptionServiceGetBenefitsAction\n | SubscriptionServiceGetSubscriptionsEligibilitiesAction\n | SubscriptionServiceCancelSubscriptionAction\n | SubscriptionServiceUnCancelSubscriptionAction\n | SubscriptionServiceStartSubscriptionWithCardAction\n | SubscriptionServiceStartSubscriptionWithCryptoAction\n | SubscriptionServiceUpdatePaymentMethodCardAction\n | SubscriptionServiceUpdatePaymentMethodCryptoAction\n | SubscriptionServiceGetBillingPortalUrlAction\n | SubscriptionServiceSubmitSponsorshipIntentsAction\n | SubscriptionServiceSubmitUserEventAction\n | SubscriptionServiceAssignUserToCohortAction\n | SubscriptionServiceLinkRewardsAction\n | AuthenticationController.AuthenticationControllerPerformSignOutAction\n | SeedlessOnboardingControllerGetIsUserAuthenticatedAction\n | GeolocationControllerGetGeolocationDataAction;\n\n// Events\nexport type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerEvents =\n SubscriptionControllerStateChangeEvent;\n\ntype AllowedEvents = never;\n\n// Messenger\nexport type SubscriptionControllerMessenger = Messenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents\n>;\n\n/**\n * Subscription Controller Options.\n */\nexport type SubscriptionControllerOptions = {\n messenger: SubscriptionControllerMessenger;\n\n /**\n * Initial state to set on this controller.\n */\n state?: Partial<SubscriptionControllerState>;\n\n /**\n * Polling interval to use for the subscription controller.\n *\n * @default 5 minutes.\n */\n pollingInterval?: number;\n};\n\n/**\n * Get the default state for the Subscription Controller.\n *\n * @returns The default state for the Subscription Controller.\n */\nexport function getDefaultSubscriptionControllerState(): SubscriptionControllerState {\n return {\n subscriptions: [],\n trialedProducts: [],\n };\n}\n\n/**\n * Seedless Onboarding Controller State Metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst subscriptionControllerMetadata: StateMetadata<SubscriptionControllerState> =\n {\n subscriptions: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n productEntitlements: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSubscription: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n customerId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n rewardAccountId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n trialedProducts: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pricing: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n benefits: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSelectedPaymentMethod: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n };\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getPricing',\n 'getSubscriptions',\n 'getBenefits',\n 'getSubscriptionByProduct',\n 'isUserEligibleForTrial',\n 'getSubscriptionsEligibilities',\n 'cancelSubscription',\n 'unCancelSubscription',\n 'startSubscriptionWithCard',\n 'startSubscriptionWithCrypto',\n 'stopAllPolling',\n 'submitSubscriptionCryptoApproval',\n 'getCryptoApproveTransactionParams',\n 'updatePaymentMethod',\n 'getBillingPortalUrl',\n 'cacheLastSelectedPaymentMethod',\n 'clearLastSelectedPaymentMethod',\n 'submitSponsorshipIntents',\n 'submitUserEvent',\n 'assignUserToCohort',\n 'linkRewards',\n 'getTokenApproveAmount',\n 'getTokenMinimumBalanceAmount',\n 'clearState',\n 'triggerAccessTokenRefresh',\n] as const;\n\nexport class SubscriptionController extends StaticIntervalPollingController()<\n typeof controllerName,\n SubscriptionControllerState,\n SubscriptionControllerMessenger\n> {\n /**\n * Creates a new SubscriptionController instance.\n *\n * @param options - The options for the SubscriptionController.\n * @param options.messenger - A restricted messenger.\n * @param options.state - Initial state to set on this controller.\n * @param options.pollingInterval - The polling interval to use for the subscription controller.\n */\n constructor(options: SubscriptionControllerOptions) {\n const {\n messenger,\n state,\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n } = options;\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.setIntervalLength(pollingInterval);\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Gets the pricing information from the subscription service.\n *\n * @returns The pricing information.\n */\n async getPricing(): Promise<PricingResponse> {\n const pricing = await this.messenger.call('SubscriptionService:getPricing');\n this.update((state) => {\n state.pricing = pricing;\n });\n return pricing;\n }\n\n async getSubscriptions(): Promise<Subscription[]> {\n return await this.#getSubscriptions();\n }\n\n async #getSubscriptions({\n refreshBenefits = true,\n }: { refreshBenefits?: boolean } = {}): Promise<Subscription[]> {\n const currentSubscriptions = this.state.subscriptions;\n const currentTrialedProducts = this.state.trialedProducts;\n const currentCustomerId = this.state.customerId;\n const currentLastSubscription = this.state.lastSubscription;\n const currentRewardAccountId = this.state.rewardAccountId;\n const currentProductEntitlements = this.state.productEntitlements;\n const currentSubscriptionState: GetSubscriptionsResponse = {\n customerId: currentCustomerId,\n subscriptions: currentSubscriptions,\n trialedProducts: currentTrialedProducts,\n lastSubscription: currentLastSubscription,\n rewardAccountId: currentRewardAccountId,\n productEntitlements: currentProductEntitlements,\n };\n\n const newSubscriptionState = await this.messenger.call(\n 'SubscriptionService:getSubscriptions',\n );\n\n this.#updateSubscriptionStateIfChanged(\n currentSubscriptionState,\n newSubscriptionState,\n );\n\n await this.#refreshBenefitsIfActive(refreshBenefits);\n\n return newSubscriptionState.subscriptions;\n }\n\n /**\n * Updates the subscription state and refreshes the access token when the\n * fetched subscription state differs from the current state.\n *\n * @param currentState - The subscription state captured before the request.\n * @param newState - The subscription state returned by the service.\n */\n #updateSubscriptionStateIfChanged(\n currentState: GetSubscriptionsResponse,\n newState: GetSubscriptionsResponse,\n ): void {\n const {\n subscriptions: currentSubscriptions,\n trialedProducts: currentTrialedProducts,\n customerId: currentCustomerId,\n lastSubscription: currentLastSubscription,\n rewardAccountId: currentRewardAccountId,\n productEntitlements: currentProductEntitlements,\n } = currentState;\n const {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\n rewardAccountId: newRewardAccountId,\n productEntitlements: newProductEntitlements,\n } = newState;\n\n const areSubscriptionsEqual = this.#areSubscriptionsEqual(\n currentSubscriptions,\n newSubscriptions,\n );\n const areTrialedProductsEqual = this.#areTrialedProductsEqual(\n currentTrialedProducts,\n newTrialedProducts,\n );\n const isLastSubscriptionEqual = this.#isSubscriptionEqual(\n currentLastSubscription,\n newLastSubscription,\n );\n const areCustomerIdsEqual = currentCustomerId === newCustomerId;\n const areRewardAccountIdsEqual =\n currentRewardAccountId === newRewardAccountId;\n const areProductEntitlementsEqual = this.#areProductEntitlementsEqual(\n currentProductEntitlements,\n newProductEntitlements,\n );\n // only update the state if the subscriptions or trialed products are different\n // this prevents unnecessary state updates events, easier for the clients to handle\n\n // Only update the state if any subscription-related field changed. This\n // prevents unnecessary state change events for clients to handle.\n if (\n !areSubscriptionsEqual ||\n !isLastSubscriptionEqual ||\n !areTrialedProductsEqual ||\n !areCustomerIdsEqual ||\n !areRewardAccountIdsEqual ||\n !areProductEntitlementsEqual\n ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\n state.rewardAccountId = newRewardAccountId;\n // Omitted entitlements are an empty map so selectors fail closed\n // instead of keeping last-known paid-feature flags.\n state.productEntitlements = newProductEntitlements ?? {};\n });\n // Trigger an access token refresh to ensure the user has the latest\n // access token after a subscription state change.\n this.triggerAccessTokenRefresh();\n }\n }\n\n /**\n * Gets and stores the user's subscription benefits.\n *\n * @returns The benefits response.\n * @throws If the user is not an active Money Account Plus subscriber or is\n * not eligible for benefits.\n */\n async getBenefits(): Promise<SubscriptionBenefitsResponse> {\n this.#assertIsActiveMoneyAccountPlusSubscriber();\n\n const benefits = await this.messenger.call(\n 'SubscriptionService:getBenefits',\n );\n\n // The subscription may have become inactive while the benefits request\n // was in flight. Re-check before persisting the response so stale\n // benefits cannot be restored after entitlement ends.\n this.#assertIsActiveMoneyAccountPlusSubscriber();\n\n this.update((state) => {\n state.benefits = benefits.eligible\n ? {\n billingPeriodId: benefits.billingPeriodId,\n ...benefits.products,\n }\n : undefined;\n });\n\n if (!benefits.eligible) {\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n\n return benefits;\n }\n\n /**\n * Get the subscription by product.\n *\n * @param productType - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(productType: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((product) => product.name === productType),\n );\n }\n\n /**\n * Whether the user is eligible to start a trial for the given product.\n *\n * Shield is eligible when the user has not trialed Shield before.\n * Money Account Plus is eligible when the user has not trialed it before\n * and is authenticated with social login. Only an unlocked wallet can\n * subscribe, so `SeedlessOnboardingController:getIsUserAuthenticated` is a\n * sufficient social-login check.\n *\n * @param productType - The product to check.\n * @returns Whether the user is eligible for a trial.\n */\n async isUserEligibleForTrial(productType: ProductType): Promise<boolean> {\n if (this.state.trialedProducts.includes(productType)) {\n return false;\n }\n\n switch (productType) {\n case PRODUCT_TYPES.SHIELD:\n return true;\n case PRODUCT_TYPES.MONEY_ACCOUNT_PLUS:\n return await this.messenger.call(\n 'SeedlessOnboardingController:getIsUserAuthenticated',\n );\n default: {\n // `productType` is `never` here. A new `PRODUCT_TYPES` member fails\n // compilation until this switch handles it.\n const unexpectedProduct: never = productType;\n throw new Error(\n `Unexpected product type: ${String(unexpectedProduct)}`,\n );\n }\n }\n }\n\n /**\n * Get the subscriptions eligibilities.\n *\n * @param request - Optional request object containing user balance to check cohort eligibility.\n * @returns The subscriptions eligibilities.\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n return await this.messenger.call(\n 'SubscriptionService:getSubscriptionsEligibilities',\n request,\n );\n }\n\n async cancelSubscription(request: CancelSubscriptionRequest): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const cancelledSubscription = await this.messenger.call(\n 'SubscriptionService:cancelSubscription',\n request,\n );\n\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? { ...subscription, ...cancelledSubscription }\n : subscription,\n );\n });\n\n try {\n await this.#getSubscriptions();\n } catch (error) {\n log('Failed to refresh subscriptions after cancellation', error);\n\n // Preserve the existing best-effort benefits refresh behavior if the\n // canonical subscription refresh is unavailable.\n await this.#refreshBenefitsIfActive();\n }\n\n this.triggerAccessTokenRefresh();\n }\n\n async unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const uncancelledSubscription = await this.messenger.call(\n 'SubscriptionService:unCancelSubscription',\n {\n subscriptionId: request.subscriptionId,\n },\n );\n\n // Replace rather than merge: optional fields the response omits (e.g.\n // `cancelAtPeriodEnd`, `canceledAt`) must not survive from the\n // pending-cancellation state.\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? uncancelledSubscription\n : subscription,\n );\n });\n\n try {\n await this.#getSubscriptions();\n } catch (error) {\n log('Failed to refresh subscriptions after uncancellation', error);\n\n // Preserve the existing best-effort benefits refresh behavior if the\n // canonical subscription refresh is unavailable.\n await this.#refreshBenefitsIfActive();\n }\n\n this.triggerAccessTokenRefresh();\n }\n\n /**\n * Starts a card-paid subscription checkout session for the requested products\n * (e.g. Shield or Money Account Plus).\n *\n * `isTrialRequested` on the request is ignored and overwritten from\n * `isUserEligibleForTrial` and `trialPeriodDays > 0`. Shield is eligible\n * when it has not been trialed. Money Account Plus is eligible when it has\n * not been trialed and the user is authenticated with social login.\n *\n * `isEligibleForRefund` is sent as provided. When omitted, it is resolved\n * from geolocation (EU/EEA), or `false` if the lookup fails.\n *\n * @param request - The start subscription request.\n * @returns The checkout session response.\n */\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n // get the latest subscriptions state before computing trial eligibility\n await this.getSubscriptions();\n this.#assertIsUserNotSubscribed({ products: request.products });\n const isTrialRequested = await this.#getIsTrialRequested(\n request.products,\n request.recurringInterval,\n );\n\n const response = await this.messenger.call(\n 'SubscriptionService:startSubscriptionWithCard',\n {\n ...request,\n isTrialRequested,\n isEligibleForRefund: await this.#getIsEligibleForRefund(\n request.isEligibleForRefund,\n ),\n },\n );\n // note: no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet\n\n return response;\n }\n\n /**\n * Starts a crypto-paid subscription for the requested products\n * (e.g. Shield or Money Account Plus). Unlike card checkout, this\n * creates the subscription immediately, so local state is refreshed\n * afterwards.\n *\n * `isTrialRequested` on the request is ignored and overwritten from\n * `isUserEligibleForTrial` and `trialPeriodDays > 0`. Shield is eligible\n * when it has not been trialed. Money Account Plus is eligible when it has\n * not been trialed and the user is authenticated with social login.\n *\n * `isEligibleForRefund` is sent as provided. When omitted, it is resolved\n * from geolocation (EU/EEA), or `false` if the lookup fails.\n *\n * @param request - The start crypto subscription request.\n * @returns The start crypto subscription response.\n * @throws If `products` is empty.\n */\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n\n // get the latest subscriptions state before computing trial eligibility\n await this.#getSubscriptions({ refreshBenefits: false });\n this.#assertIsUserNotSubscribed({ products: request.products });\n const isTrialRequested = await this.#getIsTrialRequested(\n request.products,\n request.recurringInterval,\n );\n if (\n request.assertTrialEligibility &&\n request.isTrialRequested !== isTrialRequested\n ) {\n throw new Error(\n SubscriptionDelegationServiceErrorMessage.TrialEligibilityChanged,\n );\n }\n const {\n assertTrialEligibility: _assertTrialEligibility,\n ...subscriptionRequest\n } = request;\n const response = await this.messenger.call(\n 'SubscriptionService:startSubscriptionWithCrypto',\n {\n ...subscriptionRequest,\n isTrialRequested,\n isEligibleForRefund: await this.#getIsEligibleForRefund(\n request.isEligibleForRefund,\n ),\n },\n );\n\n // Crypto start creates the subscription immediately (unlike card checkout).\n await this.getSubscriptions();\n\n return response;\n }\n\n /**\n * Submits a Shield ERC-20 crypto approval transaction to start or update a\n * crypto subscription.\n *\n * This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.\n * Delegation-based products (e.g. Money Account) must call\n * `startSubscriptionWithCrypto` instead.\n *\n * @param request - The crypto approval request.\n * @param request.productType - The subscription product. Typed as\n * `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more\n * product).\n * @param request.txMeta - The transaction metadata. Must have type\n * `TransactionType.shieldSubscriptionApprove`.\n * @param request.isSponsored - Whether the transaction is sponsored.\n * @param request.rewardAccountId - The account ID of the reward subscription\n * to link.\n * @throws If `productType` is not Shield or `txMeta.type` is not\n * `shieldSubscriptionApprove`.\n * @returns void\n */\n async submitSubscriptionCryptoApproval(\n request: SubmitSubscriptionCryptoApprovalRequest,\n ): Promise<void> {\n const { productType, txMeta, isSponsored, rewardAccountId } = request;\n if (\n // Widen for the runtime guard: JS / unsound callers may still pass a\n // non-Shield product.\n (productType as ProductType) !== PRODUCT_TYPES.SHIELD ||\n txMeta.type !== TransactionType.shieldSubscriptionApprove\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.CryptoApprovalRequiresShieldApprove,\n );\n }\n\n const { chainId, rawTx } = txMeta;\n if (!chainId || !rawTx) {\n throw new Error('Chain ID or raw transaction not found');\n }\n\n const { pricing, lastSelectedPaymentMethod } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n if (!lastSelectedPaymentMethod) {\n throw new Error('Last selected payment method not found');\n }\n const lastSelectedPaymentMethodForProduct =\n lastSelectedPaymentMethod[productType];\n this.#assertIsPaymentMethodCrypto(lastSelectedPaymentMethodForProduct);\n\n const productPrice = this.#getProductPriceByProductAndPlan(\n productType,\n lastSelectedPaymentMethodForProduct.plan,\n );\n // get the latest subscriptions state before computing trial eligibility\n await this.#getSubscriptions({ refreshBenefits: false });\n const isTrialRequested = await this.#getIsTrialRequested(\n [productType],\n lastSelectedPaymentMethodForProduct.plan,\n );\n const currentSubscription = this.getSubscriptionByProduct(productType);\n\n this.#assertValidSubscriptionStateForCryptoApproval({\n productType,\n });\n // if subscription exists, this transaction is for changing payment method\n const isChangePaymentMethod = Boolean(currentSubscription);\n\n if (isChangePaymentMethod) {\n await this.updatePaymentMethod({\n paymentType: PAYMENT_TYPES.byCrypto,\n subscriptionId: (currentSubscription as Subscription).id,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodForProduct.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n });\n } else {\n const params: StartCryptoSubscriptionRequest = {\n products: [productType],\n isTrialRequested,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodForProduct.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n cryptoAuthMethod: CRYPTO_AUTH_METHODS.ERC20_APPROVAL,\n isSponsored,\n useTestClock: lastSelectedPaymentMethodForProduct.useTestClock,\n rewardAccountId,\n };\n await this.startSubscriptionWithCrypto(params);\n }\n\n // update the subscriptions state after subscription created in server\n await this.#getSubscriptions({ refreshBenefits: false });\n }\n\n /**\n * Get transaction params to create crypto approve transaction for subscription payment\n *\n * @param request - The request object\n * @param request.chainId - The chain ID\n * @param request.tokenAddress - The address of the token\n * @param request.productType - The product type\n * @param request.interval - The interval\n * @returns The crypto approve transaction params\n */\n getCryptoApproveTransactionParams(\n request: GetCryptoApproveTransactionRequest,\n ): GetCryptoApproveTransactionResponse {\n const { pricing } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n const product = pricing.products.find(\n (productInfo) => productInfo.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find(\n (productPrice) => productPrice.interval === request.interval,\n );\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = this.#findCryptoPaymentMethod(\n request.productType,\n CRYPTO_AUTH_METHODS.ERC20_APPROVAL,\n );\n if (!chainsPaymentInfo) {\n throw new Error('Chains payment info not found');\n }\n const chainPaymentInfo = chainsPaymentInfo.chains?.find(\n (chain) => chain.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (token) =>\n token.address.toLowerCase() ===\n request.paymentTokenAddress.toLowerCase(),\n );\n if (!tokenPaymentInfo) {\n throw new Error('Invalid token address');\n }\n\n const tokenApproveAmount = this.getTokenApproveAmount(\n price,\n tokenPaymentInfo,\n );\n\n return {\n approveAmount: tokenApproveAmount,\n paymentAddress: chainPaymentInfo.paymentAddress,\n paymentTokenAddress: request.paymentTokenAddress,\n chainId: request.chainId,\n };\n }\n\n async updatePaymentMethod(\n opts: UpdatePaymentMethodOpts,\n ): Promise<UpdatePaymentMethodCardResponse | Subscription[]> {\n if (opts.paymentType === PAYMENT_TYPES.byCard) {\n const { paymentType, ...cardRequest } = opts;\n return await this.messenger.call(\n 'SubscriptionService:updatePaymentMethodCard',\n cardRequest,\n );\n } else if (opts.paymentType === PAYMENT_TYPES.byCrypto) {\n const { paymentType, ...cryptoRequest } = opts;\n await this.messenger.call(\n 'SubscriptionService:updatePaymentMethodCrypto',\n cryptoRequest,\n );\n return await this.getSubscriptions();\n }\n throw new Error('Invalid payment type');\n }\n\n /**\n * Gets the billing portal URL.\n *\n * @returns The billing portal URL\n */\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n return await this.messenger.call('SubscriptionService:getBillingPortalUrl');\n }\n\n /**\n * Cache the last selected payment method for a specific product.\n *\n * @param request - The request object.\n * @param request.product - The product to cache the payment method for.\n * @param request.paymentMethod - The payment method to cache.\n * @param request.paymentMethod.type - The type of the payment method.\n * @param request.paymentMethod.paymentTokenAddress - The payment token address.\n * @param request.paymentMethod.plan - The plan of the payment method.\n */\n cacheLastSelectedPaymentMethod(\n request: CacheLastSelectedPaymentMethodRequest,\n ): void {\n const { product, paymentMethod } = request;\n if (\n paymentMethod.type === PAYMENT_TYPES.byCrypto &&\n (!paymentMethod.paymentTokenAddress || !paymentMethod.paymentTokenSymbol)\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentTokenAddressAndSymbolRequiredForCrypto,\n );\n }\n\n this.update((state) => {\n state.lastSelectedPaymentMethod = {\n ...state.lastSelectedPaymentMethod,\n [product]: paymentMethod,\n };\n });\n }\n\n /**\n * Clear the last selected payment method for a specific product.\n *\n * @param product - The product to clear the payment method for.\n */\n clearLastSelectedPaymentMethod(product: ProductType): void {\n this.update((state) => {\n if (state.lastSelectedPaymentMethod) {\n const { [product]: _, ...rest } = state.lastSelectedPaymentMethod;\n state.lastSelectedPaymentMethod = rest;\n }\n });\n }\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false if the chain does not support sponsorship or the user has already trialed\n * @throws If the crypto payment method or chain is missing from pricing\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsMethodParams,\n ): Promise<boolean> {\n if (request.products.length === 0) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n const selectedPaymentMethod =\n this.state.lastSelectedPaymentMethod?.[request.products[0]];\n this.#assertIsPaymentMethodCrypto(selectedPaymentMethod);\n\n const cryptoAuthMethod =\n selectedPaymentMethod.cryptoAuthMethod ??\n CRYPTO_AUTH_METHODS.ERC20_APPROVAL;\n const isEligibleForTrialedSponsorship =\n this.#getIsEligibleForTrialedSponsorship(\n request.chainId,\n request.products,\n cryptoAuthMethod,\n );\n if (!isEligibleForTrialedSponsorship) {\n return false;\n }\n\n const { paymentTokenSymbol, plan } = selectedPaymentMethod;\n const productPrice = this.#getProductPriceByProductAndPlan(\n // we only support one product at a time for now\n request.products[0],\n plan,\n );\n const billingCycles = productPrice.minBillingCycles;\n\n await this.messenger.call('SubscriptionService:submitSponsorshipIntents', {\n ...request,\n paymentTokenSymbol,\n billingCycles,\n recurringInterval: plan,\n });\n return true;\n }\n\n /**\n * Submit a user event from the UI. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n await this.messenger.call('SubscriptionService:submitUserEvent', request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n await this.messenger.call(\n 'SubscriptionService:assignUserToCohort',\n request,\n );\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward subscription ID.\n * @param request.subscriptionId - The ID of the subscription to link rewards to.\n * @param request.rewardAccountId - The account ID of the reward subscription to link to the subscription.\n * @example { subscriptionId: '1234567890', rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns Resolves when the rewards are linked successfully.\n */\n async linkRewards(\n request: LinkRewardsRequest & { subscriptionId: string },\n ): Promise<void> {\n // assert that the user is subscribed to the subscription\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n // link rewards to the subscription\n const response = await this.messenger.call(\n 'SubscriptionService:linkRewards',\n {\n rewardAccountId: request.rewardAccountId,\n },\n );\n if (!response.success) {\n throw new Error(SubscriptionControllerErrorMessage.LinkRewardsFailed);\n }\n }\n\n async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n async #refreshBenefitsIfActive(refreshBenefits = true): Promise<void> {\n if (!this.#hasActiveMoneyAccountPlusSubscription()) {\n if (this.state.benefits) {\n this.update((state) => {\n state.benefits = undefined;\n });\n }\n return;\n }\n\n if (!refreshBenefits) {\n return;\n }\n\n try {\n await this.getBenefits();\n } catch (error) {\n log('Failed to refresh subscription benefits', error);\n }\n }\n\n /**\n * Calculate total subscription price amount (approval amount) from price info\n * e.g: $8 per month * 12 months min billing cycles = $96\n *\n * @param price - The price info\n * @returns The price amount\n */\n #getSubscriptionPriceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCycles)\n .toString();\n return amount;\n }\n\n /**\n * Calculate minimum subscription balance amount from price info\n *\n * @param price - The price info\n * @returns The balance amount\n */\n #getSubscriptionBalanceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCyclesForBalance)\n .toString();\n return amount;\n }\n\n /**\n * Calculate token approve amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token approve amount\n */\n getTokenApproveAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate?.[\n price.currency as keyof NonNullable<TokenPaymentInfo['conversionRate']>\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n // price of the product\n const priceAmount = new BigNumber(this.#getSubscriptionPriceAmount(price));\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = priceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Calculate token minimum balance amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token balance amount\n */\n getTokenMinimumBalanceAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate?.[\n price.currency as keyof NonNullable<TokenPaymentInfo['conversionRate']>\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n const balanceAmount = new BigNumber(\n this.#getSubscriptionBalanceAmount(price),\n );\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = balanceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Clears the subscription state and resets to default values.\n */\n clearState(): void {\n const defaultState = getDefaultSubscriptionControllerState();\n this.update(() => {\n return defaultState;\n });\n }\n\n /**\n * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh(): void {\n // We perform a sign out to clear the access token from the authentication\n // controller. Next time the access token is requested, a new access token\n // will be fetched.\n this.messenger.call('AuthenticationController:performSignOut');\n }\n\n #getProductPriceByProductAndPlan(\n productType: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find(\n (product) => product.name === productType,\n );\n const productPrice = productPricing?.prices.find(\n (price) => price.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertValidSubscriptionStateForCryptoApproval({\n productType,\n }: {\n productType: ProductType;\n }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => product.name === productType),\n );\n\n const isValid =\n !subscription ||\n (\n [\n SUBSCRIPTION_STATUSES.awaitingFunds,\n SUBSCRIPTION_STATUSES.pastDue,\n SUBSCRIPTION_STATUSES.unpaid,\n SUBSCRIPTION_STATUSES.paused,\n SUBSCRIPTION_STATUSES.provisional,\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n ] as SubscriptionStatus[]\n ).includes(subscription.status);\n if (!isValid) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionNotValidForCryptoApproval,\n );\n }\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => products.includes(product.name)),\n );\n\n if (\n subscription &&\n ACTIVE_SUBSCRIPTION_STATUSES.includes(subscription.status)\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserAlreadySubscribed);\n }\n }\n\n #assertIsActiveMoneyAccountPlusSubscriber(): void {\n if (!this.#hasActiveMoneyAccountPlusSubscription()) {\n if (this.state.benefits) {\n this.update((state) => {\n state.benefits = undefined;\n });\n }\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n }\n\n #assertIsUserSubscribed(request: { subscriptionId: string }): void {\n if (\n !this.state.subscriptions.find(\n (subscription) => subscription.id === request.subscriptionId,\n )\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n }\n\n /**\n * Asserts that the value is a valid crypto payment method.\n *\n * After this assert, `cryptoAuthMethod` and `useTestClock` remain optional\n * because persisted cache entries may omit them.\n *\n * @param value - The value to assert.\n * @throws an error if the value is not a valid crypto payment method.\n */\n #assertIsPaymentMethodCrypto(\n value: CachedLastSelectedPaymentMethod | undefined,\n ): asserts value is CachedLastSelectedPaymentMethod & {\n type: typeof PAYMENT_TYPES.byCrypto;\n paymentTokenAddress: Hex;\n paymentTokenSymbol: string;\n } {\n if (\n value?.type !== PAYMENT_TYPES.byCrypto ||\n !value.paymentTokenAddress ||\n !value.paymentTokenSymbol\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentMethodNotCrypto,\n );\n }\n }\n\n #hasActiveMoneyAccountPlusSubscription(): boolean {\n return this.state.subscriptions.some(\n (subscription) =>\n subscription.products.some(\n (product) => product.name === PRODUCT_TYPES.MONEY_ACCOUNT_PLUS,\n ) && ACTIVE_SUBSCRIPTION_STATUSES.includes(subscription.status),\n );\n }\n\n /**\n * Determines if the user is eligible for trialed sponsorship for the given chain and products.\n * The user is eligible if the chain supports sponsorship and the user has not trialed the provided products before.\n *\n * @param chainId - The chain ID\n * @param products - The products to check eligibility for\n * @param cryptoAuthMethod - The crypto authorization method of the selected payment method\n * @returns True if the user is eligible for trialed sponsorship, false otherwise\n */\n #getIsEligibleForTrialedSponsorship(\n chainId: Hex,\n products: ProductType[],\n cryptoAuthMethod: CryptoAuthMethod,\n ): boolean {\n const isSponsorshipSupported = this.#getChainSupportsSponsorship(\n chainId,\n products[0],\n cryptoAuthMethod,\n );\n\n // verify if the user has trialed the provided products before\n const hasTrialedBefore = this.state.trialedProducts.some((product) =>\n products.includes(product),\n );\n\n return isSponsorshipSupported && !hasTrialedBefore;\n }\n\n /**\n * Whether a trial should be requested for the given products and plan.\n * True only when every product is eligible via `isUserEligibleForTrial`\n * and its price has `trialPeriodDays > 0`.\n *\n * @param products - The products to check.\n * @param plan - The recurring interval to look up pricing for.\n * @returns Whether a trial should be requested.\n */\n async #getIsTrialRequested(\n products: ProductType[],\n plan: RecurringInterval,\n ): Promise<boolean> {\n const results = await Promise.all(\n products.map(async (productType) => {\n if (!(await this.isUserEligibleForTrial(productType))) {\n return false;\n }\n\n const productPrice = this.#getProductPriceByProductAndPlan(\n productType,\n plan,\n );\n return productPrice.trialPeriodDays > 0;\n }),\n );\n\n return results.every(Boolean);\n }\n\n /**\n * Returns the caller-provided refund eligibility when set. Otherwise\n * resolves it from geolocation (EU/EEA), or `false` if the lookup fails.\n *\n * @param isEligibleForRefund - Caller-provided eligibility, if any.\n * @returns Whether the user is eligible for a refund.\n */\n async #getIsEligibleForRefund(\n isEligibleForRefund?: boolean,\n ): Promise<boolean> {\n if (isEligibleForRefund !== undefined) {\n return isEligibleForRefund;\n }\n\n try {\n const { country } = await this.messenger.call(\n 'GeolocationController:getGeolocationData',\n );\n return (\n country !== null && REFUND_ELIGIBLE_COUNTRIES.has(country.toUpperCase())\n );\n } catch (error) {\n log('Failed to resolve geolocation for refund eligibility', error);\n return false;\n }\n }\n\n #findCryptoPaymentMethod(\n productType: ProductType,\n cryptoAuthMethod: CryptoAuthMethod,\n ): PricingCryptoPaymentMethod | undefined {\n const matches: {\n method: PricingCryptoPaymentMethod;\n explicit: boolean;\n }[] = [];\n\n for (const paymentMethod of this.state.pricing?.paymentMethods ?? []) {\n if (paymentMethod.type !== PAYMENT_TYPES.byCrypto) {\n continue;\n }\n\n const resolved = this.#resolveCryptoPaymentMethodDefaults(paymentMethod);\n if (!resolved) {\n continue;\n }\n\n if (\n resolved.cryptoAuthMethod === cryptoAuthMethod &&\n resolved.products.includes(productType)\n ) {\n matches.push({\n method: paymentMethod,\n explicit: resolved.explicit,\n });\n }\n }\n\n if (matches.length === 0) {\n return undefined;\n }\n\n const explicitMatches = matches.filter((match) => match.explicit);\n const candidates = explicitMatches.length > 0 ? explicitMatches : matches;\n\n if (candidates.length > 1) {\n throw new Error('Multiple matching crypto payment methods found');\n }\n\n return candidates[0].method;\n }\n\n /**\n * Resolves omitted `products` / `cryptoAuthMethod` on a crypto pricing row.\n * Legacy Shield + `erc20_approval` defaults apply only when both fields are\n * absent. If `products` is present, the list must be non-empty and\n * `cryptoAuthMethod` must be explicit; otherwise the row is ignored.\n *\n * @param paymentMethod - The crypto pricing row.\n * @returns Resolved products and auth method, or `undefined` if the row is\n * incomplete.\n */\n #resolveCryptoPaymentMethodDefaults(\n paymentMethod: PricingCryptoPaymentMethod,\n ):\n | {\n products: ProductType[];\n cryptoAuthMethod: CryptoAuthMethod;\n explicit: boolean;\n }\n | undefined {\n const productsPresent = paymentMethod.products !== undefined;\n const authPresent = paymentMethod.cryptoAuthMethod !== undefined;\n\n if (!productsPresent && !authPresent) {\n return {\n products: [PRODUCT_TYPES.SHIELD],\n cryptoAuthMethod: CRYPTO_AUTH_METHODS.ERC20_APPROVAL,\n explicit: false,\n };\n }\n\n if (!paymentMethod.products?.length || !paymentMethod.cryptoAuthMethod) {\n return undefined;\n }\n\n return {\n products: paymentMethod.products,\n cryptoAuthMethod: paymentMethod.cryptoAuthMethod,\n explicit: true,\n };\n }\n\n /**\n * Whether the given chain supports sponsorship for the product and auth method.\n *\n * @param chainId - The chain ID\n * @param productType - The product type\n * @param cryptoAuthMethod - The crypto authorization method to look up\n * @returns True if the chain row has sponsorship enabled, false if it is explicitly not sponsored\n * @throws If the crypto payment method or chain row is missing from pricing\n */\n #getChainSupportsSponsorship(\n chainId: Hex,\n productType: ProductType,\n cryptoAuthMethod: CryptoAuthMethod,\n ): boolean {\n const cryptoPaymentInfo = this.#findCryptoPaymentMethod(\n productType,\n cryptoAuthMethod,\n );\n if (!cryptoPaymentInfo) {\n throw new Error('Chains payment info not found');\n }\n\n const chainPaymentInfo = cryptoPaymentInfo.chains?.find(\n (chain) => chain.chainId === chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n return Boolean(chainPaymentInfo.isSponsorshipSupported);\n }\n\n /**\n * Determines whether two trialed products arrays are equal by comparing all products in the arrays.\n *\n * @param oldTrialedProducts - The first trialed products array to compare.\n * @param newTrialedProducts - The second trialed products array to compare.\n * @returns True if the trialed products arrays are equal, false otherwise.\n */\n #areTrialedProductsEqual(\n oldTrialedProducts: ProductType[],\n newTrialedProducts: ProductType[],\n ): boolean {\n return (\n oldTrialedProducts.length === newTrialedProducts?.length &&\n oldTrialedProducts.every((product) =>\n newTrialedProducts?.includes(product),\n )\n );\n }\n\n /**\n * Compares product entitlement maps without treating object key order as a\n * change. Insertion-order-sensitive `JSON.stringify` can otherwise treat an\n * equivalent API payload as different and trigger `performSignOut`.\n *\n * @param oldProductEntitlements - Stored product entitlements.\n * @param newProductEntitlements - Freshly fetched product entitlements.\n * @returns True if the maps are equal regardless of key order.\n */\n #areProductEntitlementsEqual(\n oldProductEntitlements?: ProductEntitlements,\n newProductEntitlements?: ProductEntitlements,\n ): boolean {\n return deepEqual(\n oldProductEntitlements ?? {},\n newProductEntitlements ?? {},\n );\n }\n\n /**\n * Determines whether two subscription arrays are equal by comparing all properties\n * of each subscription in the arrays.\n *\n * @param oldSubs - The first subscription array to compare.\n * @param newSubs - The second subscription array to compare.\n * @returns True if the subscription arrays are equal, false otherwise.\n */\n #areSubscriptionsEqual(\n oldSubs: Subscription[],\n newSubs: Subscription[],\n ): boolean {\n // Check if arrays have different lengths\n if (oldSubs.length !== newSubs.length) {\n return false;\n }\n\n // Sort both arrays by id to ensure consistent comparison\n const sortedOldSubs = [...oldSubs].sort((a, b) => a.id.localeCompare(b.id));\n const sortedNewSubs = [...newSubs].sort((a, b) => a.id.localeCompare(b.id));\n\n // Check if all subscriptions are equal\n return sortedOldSubs.every((oldSub, index) => {\n const newSub = sortedNewSubs[index];\n return this.#isSubscriptionEqual(oldSub, newSub);\n });\n }\n\n #isSubscriptionEqual(oldSub?: Subscription, newSub?: Subscription): boolean {\n // not equal if one is undefined and the other is defined\n if (!oldSub || !newSub) {\n if (!oldSub && !newSub) {\n return true;\n }\n return false;\n }\n\n return (\n this.#stringifySubscription(oldSub) ===\n this.#stringifySubscription(newSub)\n );\n }\n\n #stringifySubscription(subscription: Subscription): string {\n const subsWithSortedProducts = {\n ...subscription,\n // order the products by name\n products: [...subscription.products].sort((a, b) =>\n a.name.localeCompare(b.name),\n ),\n };\n\n return JSON.stringify(subsWithSortedProducts);\n }\n}\n"]}
|
|
@@ -8,8 +8,8 @@ export declare const SubscriptionStruct: Struct<{
|
|
|
8
8
|
unitAmount: number;
|
|
9
9
|
unitDecimals: number;
|
|
10
10
|
}[];
|
|
11
|
-
currentPeriodStart
|
|
12
|
-
currentPeriodEnd
|
|
11
|
+
currentPeriodStart: string;
|
|
12
|
+
currentPeriodEnd: string;
|
|
13
13
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
14
14
|
status: "active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid";
|
|
15
15
|
interval: "month" | "year";
|
|
@@ -34,9 +34,9 @@ export declare const SubscriptionStruct: Struct<{
|
|
|
34
34
|
trialEnd?: string | undefined;
|
|
35
35
|
endDate?: string | undefined;
|
|
36
36
|
canceledAt?: string | undefined;
|
|
37
|
-
cancelType
|
|
37
|
+
cancelType: "allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification";
|
|
38
38
|
inactiveAt?: string | undefined;
|
|
39
|
-
isEligibleForSupport
|
|
39
|
+
isEligibleForSupport: boolean;
|
|
40
40
|
billingCycles?: number | undefined;
|
|
41
41
|
lastInvoice?: {
|
|
42
42
|
id: string;
|
|
@@ -67,8 +67,8 @@ export declare const SubscriptionStruct: Struct<{
|
|
|
67
67
|
unitAmount: Struct<number, null>;
|
|
68
68
|
unitDecimals: Struct<number, null>;
|
|
69
69
|
}>>;
|
|
70
|
-
currentPeriodStart: Struct<string
|
|
71
|
-
currentPeriodEnd: Struct<string
|
|
70
|
+
currentPeriodStart: Struct<string, null>;
|
|
71
|
+
currentPeriodEnd: Struct<string, null>;
|
|
72
72
|
cancelAtPeriodEnd: Struct<boolean | undefined, null>;
|
|
73
73
|
status: Struct<"active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid", {
|
|
74
74
|
active: "active";
|
|
@@ -107,14 +107,14 @@ export declare const SubscriptionStruct: Struct<{
|
|
|
107
107
|
trialEnd: Struct<string | undefined, null>;
|
|
108
108
|
endDate: Struct<string | undefined, null>;
|
|
109
109
|
canceledAt: Struct<string | undefined, null>;
|
|
110
|
-
cancelType: Struct<"allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification"
|
|
110
|
+
cancelType: Struct<"allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification", {
|
|
111
111
|
allowed_at_period_end: "allowed_at_period_end";
|
|
112
112
|
allowed_immediate: "allowed_immediate";
|
|
113
113
|
not_allowed: "not_allowed";
|
|
114
114
|
not_allowed_pending_verification: "not_allowed_pending_verification";
|
|
115
115
|
}>;
|
|
116
116
|
inactiveAt: Struct<string | undefined, null>;
|
|
117
|
-
isEligibleForSupport: Struct<boolean
|
|
117
|
+
isEligibleForSupport: Struct<boolean, null>;
|
|
118
118
|
billingCycles: Struct<number | undefined, null>;
|
|
119
119
|
lastInvoice: Struct<{
|
|
120
120
|
id: string;
|
|
@@ -151,8 +151,8 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
151
151
|
unitAmount: number;
|
|
152
152
|
unitDecimals: number;
|
|
153
153
|
}[];
|
|
154
|
-
currentPeriodStart
|
|
155
|
-
currentPeriodEnd
|
|
154
|
+
currentPeriodStart: string;
|
|
155
|
+
currentPeriodEnd: string;
|
|
156
156
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
157
157
|
status: "active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid";
|
|
158
158
|
interval: "month" | "year";
|
|
@@ -177,9 +177,9 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
177
177
|
trialEnd?: string | undefined;
|
|
178
178
|
endDate?: string | undefined;
|
|
179
179
|
canceledAt?: string | undefined;
|
|
180
|
-
cancelType
|
|
180
|
+
cancelType: "allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification";
|
|
181
181
|
inactiveAt?: string | undefined;
|
|
182
|
-
isEligibleForSupport
|
|
182
|
+
isEligibleForSupport: boolean;
|
|
183
183
|
billingCycles?: number | undefined;
|
|
184
184
|
lastInvoice?: {
|
|
185
185
|
id: string;
|
|
@@ -214,8 +214,8 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
214
214
|
unitAmount: number;
|
|
215
215
|
unitDecimals: number;
|
|
216
216
|
}[];
|
|
217
|
-
currentPeriodStart
|
|
218
|
-
currentPeriodEnd
|
|
217
|
+
currentPeriodStart: string;
|
|
218
|
+
currentPeriodEnd: string;
|
|
219
219
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
220
220
|
status: "active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid";
|
|
221
221
|
interval: "month" | "year";
|
|
@@ -240,9 +240,9 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
240
240
|
trialEnd?: string | undefined;
|
|
241
241
|
endDate?: string | undefined;
|
|
242
242
|
canceledAt?: string | undefined;
|
|
243
|
-
cancelType
|
|
243
|
+
cancelType: "allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification";
|
|
244
244
|
inactiveAt?: string | undefined;
|
|
245
|
-
isEligibleForSupport
|
|
245
|
+
isEligibleForSupport: boolean;
|
|
246
246
|
billingCycles?: number | undefined;
|
|
247
247
|
lastInvoice?: {
|
|
248
248
|
id: string;
|
|
@@ -262,8 +262,8 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
262
262
|
unitAmount: number;
|
|
263
263
|
unitDecimals: number;
|
|
264
264
|
}[];
|
|
265
|
-
currentPeriodStart
|
|
266
|
-
currentPeriodEnd
|
|
265
|
+
currentPeriodStart: string;
|
|
266
|
+
currentPeriodEnd: string;
|
|
267
267
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
268
268
|
status: "active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid";
|
|
269
269
|
interval: "month" | "year";
|
|
@@ -288,9 +288,9 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
288
288
|
trialEnd?: string | undefined;
|
|
289
289
|
endDate?: string | undefined;
|
|
290
290
|
canceledAt?: string | undefined;
|
|
291
|
-
cancelType
|
|
291
|
+
cancelType: "allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification";
|
|
292
292
|
inactiveAt?: string | undefined;
|
|
293
|
-
isEligibleForSupport
|
|
293
|
+
isEligibleForSupport: boolean;
|
|
294
294
|
billingCycles?: number | undefined;
|
|
295
295
|
lastInvoice?: {
|
|
296
296
|
id: string;
|
|
@@ -306,8 +306,8 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
306
306
|
unitAmount: number;
|
|
307
307
|
unitDecimals: number;
|
|
308
308
|
}[];
|
|
309
|
-
currentPeriodStart
|
|
310
|
-
currentPeriodEnd
|
|
309
|
+
currentPeriodStart: string;
|
|
310
|
+
currentPeriodEnd: string;
|
|
311
311
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
312
312
|
status: "active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid";
|
|
313
313
|
interval: "month" | "year";
|
|
@@ -332,9 +332,9 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
332
332
|
trialEnd?: string | undefined;
|
|
333
333
|
endDate?: string | undefined;
|
|
334
334
|
canceledAt?: string | undefined;
|
|
335
|
-
cancelType
|
|
335
|
+
cancelType: "allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification";
|
|
336
336
|
inactiveAt?: string | undefined;
|
|
337
|
-
isEligibleForSupport
|
|
337
|
+
isEligibleForSupport: boolean;
|
|
338
338
|
billingCycles?: number | undefined;
|
|
339
339
|
lastInvoice?: {
|
|
340
340
|
id: string;
|
|
@@ -365,8 +365,8 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
365
365
|
unitAmount: Struct<number, null>;
|
|
366
366
|
unitDecimals: Struct<number, null>;
|
|
367
367
|
}>>;
|
|
368
|
-
currentPeriodStart: Struct<string
|
|
369
|
-
currentPeriodEnd: Struct<string
|
|
368
|
+
currentPeriodStart: Struct<string, null>;
|
|
369
|
+
currentPeriodEnd: Struct<string, null>;
|
|
370
370
|
cancelAtPeriodEnd: Struct<boolean | undefined, null>;
|
|
371
371
|
status: Struct<"active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid", {
|
|
372
372
|
active: "active";
|
|
@@ -405,14 +405,14 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
405
405
|
trialEnd: Struct<string | undefined, null>;
|
|
406
406
|
endDate: Struct<string | undefined, null>;
|
|
407
407
|
canceledAt: Struct<string | undefined, null>;
|
|
408
|
-
cancelType: Struct<"allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification"
|
|
408
|
+
cancelType: Struct<"allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification", {
|
|
409
409
|
allowed_at_period_end: "allowed_at_period_end";
|
|
410
410
|
allowed_immediate: "allowed_immediate";
|
|
411
411
|
not_allowed: "not_allowed";
|
|
412
412
|
not_allowed_pending_verification: "not_allowed_pending_verification";
|
|
413
413
|
}>;
|
|
414
414
|
inactiveAt: Struct<string | undefined, null>;
|
|
415
|
-
isEligibleForSupport: Struct<boolean
|
|
415
|
+
isEligibleForSupport: Struct<boolean, null>;
|
|
416
416
|
billingCycles: Struct<number | undefined, null>;
|
|
417
417
|
lastInvoice: Struct<{
|
|
418
418
|
id: string;
|
|
@@ -505,8 +505,8 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
505
505
|
unitAmount: number;
|
|
506
506
|
unitDecimals: number;
|
|
507
507
|
}[];
|
|
508
|
-
currentPeriodStart
|
|
509
|
-
currentPeriodEnd
|
|
508
|
+
currentPeriodStart: string;
|
|
509
|
+
currentPeriodEnd: string;
|
|
510
510
|
cancelAtPeriodEnd?: boolean | undefined;
|
|
511
511
|
status: "active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid";
|
|
512
512
|
interval: "month" | "year";
|
|
@@ -531,9 +531,9 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
531
531
|
trialEnd?: string | undefined;
|
|
532
532
|
endDate?: string | undefined;
|
|
533
533
|
canceledAt?: string | undefined;
|
|
534
|
-
cancelType
|
|
534
|
+
cancelType: "allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification";
|
|
535
535
|
inactiveAt?: string | undefined;
|
|
536
|
-
isEligibleForSupport
|
|
536
|
+
isEligibleForSupport: boolean;
|
|
537
537
|
billingCycles?: number | undefined;
|
|
538
538
|
lastInvoice?: {
|
|
539
539
|
id: string;
|
|
@@ -564,8 +564,8 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
564
564
|
unitAmount: Struct<number, null>;
|
|
565
565
|
unitDecimals: Struct<number, null>;
|
|
566
566
|
}>>;
|
|
567
|
-
currentPeriodStart: Struct<string
|
|
568
|
-
currentPeriodEnd: Struct<string
|
|
567
|
+
currentPeriodStart: Struct<string, null>;
|
|
568
|
+
currentPeriodEnd: Struct<string, null>;
|
|
569
569
|
cancelAtPeriodEnd: Struct<boolean | undefined, null>;
|
|
570
570
|
status: Struct<"active" | "awaiting_funds" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "paused" | "provisional" | "trialing" | "unpaid", {
|
|
571
571
|
active: "active";
|
|
@@ -604,14 +604,14 @@ export declare const GetSubscriptionsResponseStruct: Struct<{
|
|
|
604
604
|
trialEnd: Struct<string | undefined, null>;
|
|
605
605
|
endDate: Struct<string | undefined, null>;
|
|
606
606
|
canceledAt: Struct<string | undefined, null>;
|
|
607
|
-
cancelType: Struct<"allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification"
|
|
607
|
+
cancelType: Struct<"allowed_at_period_end" | "allowed_immediate" | "not_allowed" | "not_allowed_pending_verification", {
|
|
608
608
|
allowed_at_period_end: "allowed_at_period_end";
|
|
609
609
|
allowed_immediate: "allowed_immediate";
|
|
610
610
|
not_allowed: "not_allowed";
|
|
611
611
|
not_allowed_pending_verification: "not_allowed_pending_verification";
|
|
612
612
|
}>;
|
|
613
613
|
inactiveAt: Struct<string | undefined, null>;
|
|
614
|
-
isEligibleForSupport: Struct<boolean
|
|
614
|
+
isEligibleForSupport: Struct<boolean, null>;
|
|
615
615
|
billingCycles: Struct<number | undefined, null>;
|
|
616
616
|
lastInvoice: Struct<{
|
|
617
617
|
id: string;
|