Skip to main content

SubscriptionController Actions

31 actions registered.

NameDeprecated
assignUserToCohort
cacheLastSelectedPaymentMethod
cancelSubscription
clearLastSelectedPaymentMethod
clearState
getBenefits
getBillingPortalUrl
getCryptoApproveTransactionParams
getPricing
getState
getSubscriptionByProduct
getSubscriptions
getSubscriptionsEligibilities
getTokenApproveAmount
getTokenMinimumBalanceAmount
isUserEligibleForTrial
linkRewards
registerAddress
retryCryptoCharge
setChargeRetryInProgress
startPolling
startSubscriptionWithCard
startSubscriptionWithCrypto
stopAllPolling
stopPollingByPollingToken
submitSponsorshipIntents
submitSubscriptionCryptoApproval
submitUserEvent
triggerAccessTokenRefresh
unCancelSubscription
updatePaymentMethod

SubscriptionController:assignUserToCohort​

Package: @metamask/subscription-controller

Assign user to a cohort.

Parameters:

NameDescription
requestRequest 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:

NameDescription
requestThe request object.
request.productThe product to cache the payment method for.
request.paymentMethodThe payment method to cache.
request.paymentMethod.typeThe type of the payment method.
request.paymentMethod.paymentTokenAddressThe payment token address.
request.paymentMethod.planThe 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:

NameDescription
productThe 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:

NameDescription
requestThe request object
request.chainIdThe chain ID
request.tokenAddressThe address of the token
request.productTypeThe product type
request.intervalThe 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:

NameDescription
productTypeThe 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:

NameDescription
requestOptional 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:

NameDescription
priceThe price info
tokenPaymentInfoThe 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:

NameDescription
priceThe price info
tokenPaymentInfoThe 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:

NameDescription
productTypeThe 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:

NameDescription
requestRequest object containing the reward subscription ID.
request.subscriptionIdThe ID of the subscription to link rewards to.
request.rewardAccountIdThe 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:

NameDescription
requestThe retry request.
request.subscriptionIdThe 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:

NameDescription
isChargeRetryInProgressWhether 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:

NameDescription
requestThe 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:

NameDescription
requestThe 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:

NameDescription
requestRequest 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:

NameDescription
requestThe crypto approval request.
request.productTypeThe subscription product. Typed as typeof PRODUCT_TYPES.SHIELD only at the moment (future might support more product).
request.txMetaThe transaction metadata. Must have type TransactionType.shieldSubscriptionApprove.
request.isSponsoredWhether the transaction is sponsored.
request.rewardAccountIdThe 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:

NameDescription
requestRequest 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[]>