SubscriptionController Actions
31 actions registered.
SubscriptionController:assignUserToCohort
Package: @metamask/subscription-controller
Assign user to a cohort.
Parameters:
| Name | Description |
|---|---|
request | Request object containing the cohort to assign the user to. |
Handler signature:
(request: AssignCohortRequest) => Promise<void>
SubscriptionController:cacheLastSelectedPaymentMethod
Package: @metamask/subscription-controller
Cache the last selected payment method for a specific product.
Parameters:
| Name | Description |
|---|---|
request | The request object. |
request.product | The product to cache the payment method for. |
request.paymentMethod | The payment method to cache. |
request.paymentMethod.type | The type of the payment method. |
request.paymentMethod.paymentTokenAddress | The payment token address. |
request.paymentMethod.plan | The plan of the payment method. |
Handler signature:
(request: CacheLastSelectedPaymentMethodRequest) => void
SubscriptionController:cancelSubscription
Package: @metamask/subscription-controller
Handler signature:
(request: CancelSubscriptionRequest) => Promise<void>
SubscriptionController:clearLastSelectedPaymentMethod
Package: @metamask/subscription-controller
Clear the last selected payment method for a specific product.
Parameters:
| Name | Description |
|---|---|
product | The product to clear the payment method for. |
Handler signature:
(product: ProductType) => void
SubscriptionController:clearState
Package: @metamask/subscription-controller
Clears the subscription state and resets to default values.
Handler signature:
() => void
SubscriptionController:getBenefits
Package: @metamask/subscription-controller
Gets and stores the user's subscription benefits.
An ineligible response is a normal result. Persisted benefits are cleared
and the response is returned so callers can branch on eligible. That
includes a provisional subscription whose benefits are not ready yet,
which is distinct from having no active Money Account Plus subscription.
Returns: The benefits response, including when eligible is false.
Handler signature:
() => Promise<SubscriptionBenefitsResponse>
SubscriptionController:getBillingPortalUrl
Package: @metamask/subscription-controller
Gets the billing portal URL.
Returns: The billing portal URL
Handler signature:
() => Promise<BillingPortalResponse>
SubscriptionController:getCryptoApproveTransactionParams
Package: @metamask/subscription-controller
Get transaction params to create crypto approve transaction for subscription payment
Parameters:
| Name | Description |
|---|---|
request | The request object |
request.chainId | The chain ID |
request.tokenAddress | The address of the token |
request.productType | The product type |
request.interval | The interval |
Returns: The crypto approve transaction params
Handler signature:
(request: GetCryptoApproveTransactionRequest) => GetCryptoApproveTransactionResponse
SubscriptionController:getPricing
Package: @metamask/subscription-controller
Gets the pricing information from the subscription service.
Returns: The pricing information.
Handler signature:
() => Promise<PricingResponse>
SubscriptionController:getState
Package: @metamask/subscription-controller
Handler signature:
() => SubscriptionControllerState
SubscriptionController:getSubscriptionByProduct
Package: @metamask/subscription-controller
Get the subscription by product.
Parameters:
| Name | Description |
|---|---|
productType | The product type. |
Returns: The subscription.
Handler signature:
(productType: ProductType) => Subscription | undefined
SubscriptionController:getSubscriptions
Package: @metamask/subscription-controller
Handler signature:
() => Promise<Subscription[]>
SubscriptionController:getSubscriptionsEligibilities
Package: @metamask/subscription-controller
Get the subscriptions eligibilities.
Parameters:
| Name | Description |
|---|---|
request | Optional request object containing user balance to check cohort eligibility. |
Returns: The subscriptions eligibilities.
Handler signature:
(request?: GetSubscriptionsEligibilitiesRequest) => Promise<SubscriptionEligibility[]>
SubscriptionController:getTokenApproveAmount
Package: @metamask/subscription-controller
Calculate token approve amount from price info
Parameters:
| Name | Description |
|---|---|
price | The price info |
tokenPaymentInfo | The token price info |
Returns: The token approve amount
Handler signature:
(price: ProductPrice, tokenPaymentInfo: TokenPaymentInfo) => string
SubscriptionController:getTokenMinimumBalanceAmount
Package: @metamask/subscription-controller
Calculate token minimum balance amount from price info
Parameters:
| Name | Description |
|---|---|
price | The price info |
tokenPaymentInfo | The token price info |
Returns: The token balance amount
Handler signature:
(price: ProductPrice, tokenPaymentInfo: TokenPaymentInfo) => string
SubscriptionController:isUserEligibleForTrial
Package: @metamask/subscription-controller
Whether the user is eligible to start a trial for the given product.
Shield is eligible when the user has not trialed Shield before.
Money Account Plus is eligible when the user has not trialed it before
and is authenticated with social login. Only an unlocked wallet can
subscribe, so SeedlessOnboardingController:getIsUserAuthenticated is a
sufficient social-login check.
Parameters:
| Name | Description |
|---|---|
productType | The product to check. |
Returns: Whether the user is eligible for a trial.
Handler signature:
(productType: ProductType) => Promise<boolean>
SubscriptionController:linkRewards
Package: @metamask/subscription-controller
Link rewards to a subscription.
Parameters:
| Name | Description |
|---|---|
request | Request object containing the reward subscription ID. |
request.subscriptionId | The ID of the subscription to link rewards to. |
request.rewardAccountId | The account ID of the reward subscription to link to the subscription. |
Returns: Resolves when the rewards are linked successfully.
Handler signature:
(request: LinkRewardsRequest & {
subscriptionId: string;
}) => Promise<void>
SubscriptionController:registerAddress
Source: app/core/Engine/types.ts:677
Declared structurally to match PerpsControllerAllowedActions, which lists
this action so clients that do expose it can serve it. Our
SubscriptionController does not, so nothing delegates it and
RewardsIntegrationService keeps using its injected subscription
dependency. Remove once @metamask/subscription-controller exposes the
action itself.
Handler signature:
(caipAccountId: string) => Promise<void>
SubscriptionController:retryCryptoCharge
Package: @metamask/subscription-controller
Retries a failed crypto charge with the stored payment method: verifies the payment method of a paused subscription, otherwise pays the last invoice. The charged subscription from the response replaces the one in the refreshed subscriptions.
Parameters:
| Name | Description |
|---|---|
request | The retry request. |
request.subscriptionId | The subscription to retry. |
Returns: The refreshed subscriptions.
Handler signature:
(request: {
subscriptionId: string;
}) => Promise<Subscription[]>
SubscriptionController:setChargeRetryInProgress
Package: @metamask/subscription-controller
Sets whether SubscriptionDelegationService is retrying a stuck Money
Account Plus charge.
Parameters:
| Name | Description |
|---|---|
isChargeRetryInProgress | Whether the charge retry is in progress. |
Handler signature:
(isChargeRetryInProgress: boolean) => void
SubscriptionController:startPolling
Package: @metamask/subscription-controller
Handler signature:
SubscriptionController['startPolling']
SubscriptionController:startSubscriptionWithCard
Package: @metamask/subscription-controller
Starts a card-paid subscription checkout session for the requested products (e.g. Shield or Money Account Plus).
isTrialRequested on the request is ignored and overwritten from
isUserEligibleForTrial and trialPeriodDays > 0. Shield is eligible
when it has not been trialed. Money Account Plus is eligible when it has
not been trialed and the user is authenticated with social login.
isEligibleForRefund is sent as provided. When omitted, it is resolved
from geolocation (EU/EEA), or false if the lookup fails.
Parameters:
| Name | Description |
|---|---|
request | The start subscription request. |
Returns: The checkout session response.
Handler signature:
(request: StartSubscriptionRequest) => Promise<StartSubscriptionResponse>
SubscriptionController:startSubscriptionWithCrypto
Package: @metamask/subscription-controller
Starts a crypto-paid subscription for the requested products (e.g. Shield or Money Account Plus). Unlike card checkout, this creates the subscription immediately, so local state is refreshed afterwards.
isTrialRequested on the request is ignored and overwritten from
isUserEligibleForTrial and trialPeriodDays > 0. Shield is eligible
when it has not been trialed. Money Account Plus is eligible when it has
not been trialed and the user is authenticated with social login.
isEligibleForRefund is sent as provided. When omitted, it is resolved
from geolocation (EU/EEA), or false if the lookup fails.
Parameters:
| Name | Description |
|---|---|
request | The start crypto subscription request. |
Returns: The start crypto subscription response.
Handler signature:
(request: StartCryptoSubscriptionRequest) => Promise<StartCryptoSubscriptionResponse>
SubscriptionController:stopAllPolling
Package: @metamask/subscription-controller
Handler signature:
SubscriptionController['stopAllPolling']
SubscriptionController:stopPollingByPollingToken
Package: @metamask/subscription-controller
Handler signature:
SubscriptionController['stopPollingByPollingToken']
SubscriptionController:submitSponsorshipIntents
Package: @metamask/subscription-controller
Submit sponsorship intents to the Subscription Service backend.
This is intended to be used together with the crypto subscription flow. When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.
Parameters:
| Name | Description |
|---|---|
request | Request object containing the address and products. |
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
Handler signature:
(request: SubmitSponsorshipIntentsMethodParams) => Promise<boolean>
SubscriptionController:submitSubscriptionCryptoApproval
Package: @metamask/subscription-controller
Submits a Shield ERC-20 crypto approval transaction to start or update a crypto subscription.
This handler is Shield / TransactionType.shieldSubscriptionApprove only.
Delegation-based products (e.g. Money Account) must call
startSubscriptionWithCrypto instead.
Parameters:
| Name | Description |
|---|---|
request | The crypto approval request. |
request.productType | The subscription product. Typed as typeof PRODUCT_TYPES.SHIELD only at the moment (future might support more product). |
request.txMeta | The transaction metadata. Must have type TransactionType.shieldSubscriptionApprove. |
request.isSponsored | Whether the transaction is sponsored. |
request.rewardAccountId | The account ID of the reward subscription to link. |
Returns: void
Handler signature:
(request: SubmitSubscriptionCryptoApprovalRequest) => Promise<void>
SubscriptionController:submitUserEvent
Package: @metamask/subscription-controller
Submit a user event from the UI. (e.g. shield modal viewed)
Parameters:
| Name | Description |
|---|---|
request | Request object containing the event to submit. |
Handler signature:
(request: SubmitUserEventRequest) => Promise<void>
SubscriptionController:triggerAccessTokenRefresh
Package: @metamask/subscription-controller
Triggers an access token refresh.
Handler signature:
() => void
SubscriptionController:unCancelSubscription
Package: @metamask/subscription-controller
Handler signature:
(request: {
subscriptionId: string;
}) => Promise<void>
SubscriptionController:updatePaymentMethod
Package: @metamask/subscription-controller
Handler signature:
(opts: UpdatePaymentMethodOpts) => Promise<UpdatePaymentMethodCardResponse | Subscription[]>