@metamask/subscription-controller 7.0.0 → 8.0.1
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 +49 -1
- package/dist/SubscriptionController-method-action-types.cjs.map +1 -1
- package/dist/SubscriptionController-method-action-types.d.cts +55 -18
- package/dist/SubscriptionController-method-action-types.d.cts.map +1 -1
- package/dist/SubscriptionController-method-action-types.d.mts +55 -18
- package/dist/SubscriptionController-method-action-types.d.mts.map +1 -1
- package/dist/SubscriptionController-method-action-types.mjs.map +1 -1
- package/dist/SubscriptionController.cjs +165 -45
- package/dist/SubscriptionController.cjs.map +1 -1
- package/dist/SubscriptionController.d.cts +55 -19
- package/dist/SubscriptionController.d.cts.map +1 -1
- package/dist/SubscriptionController.d.mts +55 -19
- package/dist/SubscriptionController.d.mts.map +1 -1
- package/dist/SubscriptionController.mjs +166 -46
- package/dist/SubscriptionController.mjs.map +1 -1
- package/dist/SubscriptionService-method-action-types.cjs.map +1 -1
- package/dist/SubscriptionService-method-action-types.d.cts +5 -1
- package/dist/SubscriptionService-method-action-types.d.cts.map +1 -1
- package/dist/SubscriptionService-method-action-types.d.mts +5 -1
- package/dist/SubscriptionService-method-action-types.d.mts.map +1 -1
- package/dist/SubscriptionService-method-action-types.mjs.map +1 -1
- package/dist/SubscriptionService-structs.cjs +35 -12
- package/dist/SubscriptionService-structs.cjs.map +1 -1
- package/dist/SubscriptionService-structs.d.cts +185 -237
- package/dist/SubscriptionService-structs.d.cts.map +1 -1
- package/dist/SubscriptionService-structs.d.mts +185 -237
- package/dist/SubscriptionService-structs.d.mts.map +1 -1
- package/dist/SubscriptionService-structs.mjs +37 -14
- package/dist/SubscriptionService-structs.mjs.map +1 -1
- package/dist/SubscriptionService.cjs +25 -3
- package/dist/SubscriptionService.cjs.map +1 -1
- package/dist/SubscriptionService.d.cts +5 -1
- package/dist/SubscriptionService.d.cts.map +1 -1
- package/dist/SubscriptionService.d.mts +5 -1
- package/dist/SubscriptionService.d.mts.map +1 -1
- package/dist/SubscriptionService.mjs +25 -3
- package/dist/SubscriptionService.mjs.map +1 -1
- package/dist/constants.cjs +2 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +2 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +27 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +171 -10
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +171 -10
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +26 -0
- package/dist/types.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ControllerStateChangeEvent, ControllerGetStateAction } from "@metamask/base-controller";
|
|
2
2
|
import type { Messenger } from "@metamask/messenger";
|
|
3
3
|
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
|
4
|
-
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
5
4
|
import type { CaipAccountId } from "@metamask/utils";
|
|
6
5
|
import { controllerName } from "./constants.cjs";
|
|
7
6
|
import type { SubscriptionControllerMethodActions } from "./SubscriptionController-method-action-types.cjs";
|
|
8
7
|
import type { SubscriptionServiceAssignUserToCohortAction, SubscriptionServiceCancelSubscriptionAction, SubscriptionServiceGetBillingPortalUrlAction, SubscriptionServiceGetPricingAction, SubscriptionServiceGetSubscriptionsAction, SubscriptionServiceGetSubscriptionsEligibilitiesAction, SubscriptionServiceLinkRewardsAction, SubscriptionServiceStartSubscriptionWithCardAction, SubscriptionServiceStartSubscriptionWithCryptoAction, SubscriptionServiceSubmitSponsorshipIntentsAction, SubscriptionServiceSubmitUserEventAction, SubscriptionServiceUnCancelSubscriptionAction, SubscriptionServiceUpdatePaymentMethodCardAction, SubscriptionServiceUpdatePaymentMethodCryptoAction } from "./SubscriptionService-method-action-types.cjs";
|
|
9
|
-
import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.cjs";
|
|
8
|
+
import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitSubscriptionCryptoApprovalRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, CacheLastSelectedPaymentMethodRequest, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.cjs";
|
|
10
9
|
import type { PricingResponse, ProductType, StartSubscriptionRequest, Subscription } from "./types.cjs";
|
|
11
10
|
export type SubscriptionControllerState = {
|
|
12
11
|
customerId?: string;
|
|
@@ -22,7 +21,7 @@ export type SubscriptionControllerState = {
|
|
|
22
21
|
* This is used to display the last selected payment method in the UI.
|
|
23
22
|
* This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)
|
|
24
23
|
*/
|
|
25
|
-
lastSelectedPaymentMethod?: Record<ProductType, CachedLastSelectedPaymentMethod
|
|
24
|
+
lastSelectedPaymentMethod?: Partial<Record<ProductType, CachedLastSelectedPaymentMethod>>;
|
|
26
25
|
};
|
|
27
26
|
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
|
28
27
|
export type SubscriptionControllerActions = SubscriptionControllerGetStateAction | SubscriptionControllerMethodActions;
|
|
@@ -54,8 +53,8 @@ export type SubscriptionControllerOptions = {
|
|
|
54
53
|
*/
|
|
55
54
|
export declare function getDefaultSubscriptionControllerState(): SubscriptionControllerState;
|
|
56
55
|
declare const SubscriptionController_base: (abstract new (...args: any[]) => {
|
|
57
|
-
readonly "__#
|
|
58
|
-
"__#
|
|
56
|
+
readonly "__#6@#intervalIds": Record<string, NodeJS.Timeout>;
|
|
57
|
+
"__#6@#intervalLength": number | undefined;
|
|
59
58
|
setIntervalLength(intervalLength: number): void;
|
|
60
59
|
getIntervalLength(): number | undefined;
|
|
61
60
|
_startPolling(input: import("@metamask/utils").Json): void;
|
|
@@ -104,17 +103,53 @@ export declare class SubscriptionController extends SubscriptionController_base<
|
|
|
104
103
|
unCancelSubscription(request: {
|
|
105
104
|
subscriptionId: string;
|
|
106
105
|
}): Promise<void>;
|
|
107
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Starts a card-paid subscription checkout session for the requested products
|
|
108
|
+
* (e.g. Shield or Money Account Plus).
|
|
109
|
+
*
|
|
110
|
+
* `isTrialRequested` on the request is ignored and overwritten from pricing
|
|
111
|
+
* (`trialPeriodDays > 0`) and `trialedProducts`.
|
|
112
|
+
*
|
|
113
|
+
* @param request - The start subscription request.
|
|
114
|
+
* @returns The checkout session response.
|
|
115
|
+
*/
|
|
116
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
|
117
|
+
/**
|
|
118
|
+
* Starts a crypto-paid subscription for the requested products
|
|
119
|
+
* (e.g. Shield or Money Account Plus). Unlike card checkout, this
|
|
120
|
+
* creates the subscription immediately, so local state is refreshed
|
|
121
|
+
* afterwards.
|
|
122
|
+
*
|
|
123
|
+
* `isTrialRequested` on the request is ignored and overwritten from pricing
|
|
124
|
+
* (`trialPeriodDays > 0`) and `trialedProducts`.
|
|
125
|
+
*
|
|
126
|
+
* @param request - The start crypto subscription request.
|
|
127
|
+
* @returns The start crypto subscription response.
|
|
128
|
+
* @throws If `products` is empty.
|
|
129
|
+
*/
|
|
108
130
|
startSubscriptionWithCrypto(request: StartCryptoSubscriptionRequest): Promise<StartCryptoSubscriptionResponse>;
|
|
109
131
|
/**
|
|
110
|
-
*
|
|
132
|
+
* Submits a Shield ERC-20 crypto approval transaction to start or update a
|
|
133
|
+
* crypto subscription.
|
|
134
|
+
*
|
|
135
|
+
* This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.
|
|
136
|
+
* Delegation-based products (e.g. Money Account) must call
|
|
137
|
+
* `startSubscriptionWithCrypto` instead.
|
|
111
138
|
*
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
114
|
-
*
|
|
139
|
+
* @param request - The crypto approval request.
|
|
140
|
+
* @param request.productType - The subscription product. Typed as
|
|
141
|
+
* `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more
|
|
142
|
+
* product).
|
|
143
|
+
* @param request.txMeta - The transaction metadata. Must have type
|
|
144
|
+
* `TransactionType.shieldSubscriptionApprove`.
|
|
145
|
+
* @param request.isSponsored - Whether the transaction is sponsored.
|
|
146
|
+
* @param request.rewardAccountId - The account ID of the reward subscription
|
|
147
|
+
* to link.
|
|
148
|
+
* @throws If `productType` is not Shield or `txMeta.type` is not
|
|
149
|
+
* `shieldSubscriptionApprove`.
|
|
115
150
|
* @returns void
|
|
116
151
|
*/
|
|
117
|
-
|
|
152
|
+
submitSubscriptionCryptoApproval(request: SubmitSubscriptionCryptoApprovalRequest): Promise<void>;
|
|
118
153
|
/**
|
|
119
154
|
* Get transaction params to create crypto approve transaction for subscription payment
|
|
120
155
|
*
|
|
@@ -136,14 +171,14 @@ export declare class SubscriptionController extends SubscriptionController_base<
|
|
|
136
171
|
/**
|
|
137
172
|
* Cache the last selected payment method for a specific product.
|
|
138
173
|
*
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
-
* @param paymentMethod
|
|
142
|
-
* @param paymentMethod.
|
|
143
|
-
* @param paymentMethod.
|
|
144
|
-
* @param paymentMethod.
|
|
174
|
+
* @param request - The request object.
|
|
175
|
+
* @param request.product - The product to cache the payment method for.
|
|
176
|
+
* @param request.paymentMethod - The payment method to cache.
|
|
177
|
+
* @param request.paymentMethod.type - The type of the payment method.
|
|
178
|
+
* @param request.paymentMethod.paymentTokenAddress - The payment token address.
|
|
179
|
+
* @param request.paymentMethod.plan - The plan of the payment method.
|
|
145
180
|
*/
|
|
146
|
-
cacheLastSelectedPaymentMethod(
|
|
181
|
+
cacheLastSelectedPaymentMethod(request: CacheLastSelectedPaymentMethodRequest): void;
|
|
147
182
|
/**
|
|
148
183
|
* Clear the last selected payment method for a specific product.
|
|
149
184
|
*
|
|
@@ -163,7 +198,8 @@ export declare class SubscriptionController extends SubscriptionController_base<
|
|
|
163
198
|
* recurringInterval: RecurringInterval.Month,
|
|
164
199
|
* billingCycles: 1,
|
|
165
200
|
* }
|
|
166
|
-
* @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false
|
|
201
|
+
* @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
|
|
202
|
+
* @throws If the crypto payment method or chain is missing from pricing
|
|
167
203
|
*/
|
|
168
204
|
submitSponsorshipIntents(request: SubmitSponsorshipIntentsMethodParams): Promise<boolean>;
|
|
169
205
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionController.d.cts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;
|
|
1
|
+
{"version":3,"file":"SubscriptionController.d.cts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,KAAK,EAAE,aAAa,EAAO,wBAAwB;AAG1D,OAAO,EAEL,cAAc,EAGf,wBAAuB;AACxB,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAwD;AAC3G,OAAO,KAAK,EACV,2CAA2C,EAC3C,2CAA2C,EAC3C,4CAA4C,EAC5C,mCAAmC,EACnC,yCAAyC,EACzC,sDAAsD,EACtD,oCAAoC,EACpC,kDAAkD,EAClD,oDAAoD,EACpD,iDAAiD,EACjD,wCAAwC,EACxC,6CAA6C,EAC7C,gDAAgD,EAChD,kDAAkD,EACnD,sDAAqD;AAOtD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EAErB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,uCAAuC,EACvC,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,qCAAqC,EACrC,oCAAoC,EAGpC,kBAAkB,EAClB,+BAA+B,EAC/B,yBAAyB,EACzB,yBAAyB,EAE1B,oBAAmB;AACpB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,wBAAwB,EACxB,YAAY,EACb,oBAAmB;AAEpB,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,WAAW,EAAE,CAAC;IAC/B,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,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AA8B,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAU1D;;;;;;;;;;;;;;;OAeG;IACG,wBAAwB,CAC5B,OAAO,EAAE,oCAAoC,GAC5C,OAAO,CAAC,OAAO,CAAC;IA2CnB;;;;;OAKG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrE;;;;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrE;;;;;;;;OAQG;IACG,WAAW,CACf,OAAO,EAAE,kBAAkB,GAAG;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,GACvD,OAAO,CAAC,IAAI,CAAC;IAgBV,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCnC;;;;;;OAMG;IACH,qBAAqB,CACnB,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAkBT;;;;;;OAMG;IACH,4BAA4B,CAC1B,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAmBT;;OAEG;IACH,UAAU,IAAI,IAAI;IAOlB;;OAEG;IACH,yBAAyB,IAAI,IAAI;CAwVlC"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ControllerStateChangeEvent, ControllerGetStateAction } from "@metamask/base-controller";
|
|
2
2
|
import type { Messenger } from "@metamask/messenger";
|
|
3
3
|
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
|
4
|
-
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
5
4
|
import type { CaipAccountId } from "@metamask/utils";
|
|
6
5
|
import { controllerName } from "./constants.mjs";
|
|
7
6
|
import type { SubscriptionControllerMethodActions } from "./SubscriptionController-method-action-types.mjs";
|
|
8
7
|
import type { SubscriptionServiceAssignUserToCohortAction, SubscriptionServiceCancelSubscriptionAction, SubscriptionServiceGetBillingPortalUrlAction, SubscriptionServiceGetPricingAction, SubscriptionServiceGetSubscriptionsAction, SubscriptionServiceGetSubscriptionsEligibilitiesAction, SubscriptionServiceLinkRewardsAction, SubscriptionServiceStartSubscriptionWithCardAction, SubscriptionServiceStartSubscriptionWithCryptoAction, SubscriptionServiceSubmitSponsorshipIntentsAction, SubscriptionServiceSubmitUserEventAction, SubscriptionServiceUnCancelSubscriptionAction, SubscriptionServiceUpdatePaymentMethodCardAction, SubscriptionServiceUpdatePaymentMethodCryptoAction } from "./SubscriptionService-method-action-types.mjs";
|
|
9
|
-
import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.mjs";
|
|
8
|
+
import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitSubscriptionCryptoApprovalRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, CacheLastSelectedPaymentMethodRequest, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.mjs";
|
|
10
9
|
import type { PricingResponse, ProductType, StartSubscriptionRequest, Subscription } from "./types.mjs";
|
|
11
10
|
export type SubscriptionControllerState = {
|
|
12
11
|
customerId?: string;
|
|
@@ -22,7 +21,7 @@ export type SubscriptionControllerState = {
|
|
|
22
21
|
* This is used to display the last selected payment method in the UI.
|
|
23
22
|
* This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)
|
|
24
23
|
*/
|
|
25
|
-
lastSelectedPaymentMethod?: Record<ProductType, CachedLastSelectedPaymentMethod
|
|
24
|
+
lastSelectedPaymentMethod?: Partial<Record<ProductType, CachedLastSelectedPaymentMethod>>;
|
|
26
25
|
};
|
|
27
26
|
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
|
28
27
|
export type SubscriptionControllerActions = SubscriptionControllerGetStateAction | SubscriptionControllerMethodActions;
|
|
@@ -54,8 +53,8 @@ export type SubscriptionControllerOptions = {
|
|
|
54
53
|
*/
|
|
55
54
|
export declare function getDefaultSubscriptionControllerState(): SubscriptionControllerState;
|
|
56
55
|
declare const SubscriptionController_base: (abstract new (...args: any[]) => {
|
|
57
|
-
readonly "__#
|
|
58
|
-
"__#
|
|
56
|
+
readonly "__#6@#intervalIds": Record<string, NodeJS.Timeout>;
|
|
57
|
+
"__#6@#intervalLength": number | undefined;
|
|
59
58
|
setIntervalLength(intervalLength: number): void;
|
|
60
59
|
getIntervalLength(): number | undefined;
|
|
61
60
|
_startPolling(input: import("@metamask/utils").Json): void;
|
|
@@ -104,17 +103,53 @@ export declare class SubscriptionController extends SubscriptionController_base<
|
|
|
104
103
|
unCancelSubscription(request: {
|
|
105
104
|
subscriptionId: string;
|
|
106
105
|
}): Promise<void>;
|
|
107
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Starts a card-paid subscription checkout session for the requested products
|
|
108
|
+
* (e.g. Shield or Money Account Plus).
|
|
109
|
+
*
|
|
110
|
+
* `isTrialRequested` on the request is ignored and overwritten from pricing
|
|
111
|
+
* (`trialPeriodDays > 0`) and `trialedProducts`.
|
|
112
|
+
*
|
|
113
|
+
* @param request - The start subscription request.
|
|
114
|
+
* @returns The checkout session response.
|
|
115
|
+
*/
|
|
116
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
|
117
|
+
/**
|
|
118
|
+
* Starts a crypto-paid subscription for the requested products
|
|
119
|
+
* (e.g. Shield or Money Account Plus). Unlike card checkout, this
|
|
120
|
+
* creates the subscription immediately, so local state is refreshed
|
|
121
|
+
* afterwards.
|
|
122
|
+
*
|
|
123
|
+
* `isTrialRequested` on the request is ignored and overwritten from pricing
|
|
124
|
+
* (`trialPeriodDays > 0`) and `trialedProducts`.
|
|
125
|
+
*
|
|
126
|
+
* @param request - The start crypto subscription request.
|
|
127
|
+
* @returns The start crypto subscription response.
|
|
128
|
+
* @throws If `products` is empty.
|
|
129
|
+
*/
|
|
108
130
|
startSubscriptionWithCrypto(request: StartCryptoSubscriptionRequest): Promise<StartCryptoSubscriptionResponse>;
|
|
109
131
|
/**
|
|
110
|
-
*
|
|
132
|
+
* Submits a Shield ERC-20 crypto approval transaction to start or update a
|
|
133
|
+
* crypto subscription.
|
|
134
|
+
*
|
|
135
|
+
* This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.
|
|
136
|
+
* Delegation-based products (e.g. Money Account) must call
|
|
137
|
+
* `startSubscriptionWithCrypto` instead.
|
|
111
138
|
*
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
114
|
-
*
|
|
139
|
+
* @param request - The crypto approval request.
|
|
140
|
+
* @param request.productType - The subscription product. Typed as
|
|
141
|
+
* `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more
|
|
142
|
+
* product).
|
|
143
|
+
* @param request.txMeta - The transaction metadata. Must have type
|
|
144
|
+
* `TransactionType.shieldSubscriptionApprove`.
|
|
145
|
+
* @param request.isSponsored - Whether the transaction is sponsored.
|
|
146
|
+
* @param request.rewardAccountId - The account ID of the reward subscription
|
|
147
|
+
* to link.
|
|
148
|
+
* @throws If `productType` is not Shield or `txMeta.type` is not
|
|
149
|
+
* `shieldSubscriptionApprove`.
|
|
115
150
|
* @returns void
|
|
116
151
|
*/
|
|
117
|
-
|
|
152
|
+
submitSubscriptionCryptoApproval(request: SubmitSubscriptionCryptoApprovalRequest): Promise<void>;
|
|
118
153
|
/**
|
|
119
154
|
* Get transaction params to create crypto approve transaction for subscription payment
|
|
120
155
|
*
|
|
@@ -136,14 +171,14 @@ export declare class SubscriptionController extends SubscriptionController_base<
|
|
|
136
171
|
/**
|
|
137
172
|
* Cache the last selected payment method for a specific product.
|
|
138
173
|
*
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
-
* @param paymentMethod
|
|
142
|
-
* @param paymentMethod.
|
|
143
|
-
* @param paymentMethod.
|
|
144
|
-
* @param paymentMethod.
|
|
174
|
+
* @param request - The request object.
|
|
175
|
+
* @param request.product - The product to cache the payment method for.
|
|
176
|
+
* @param request.paymentMethod - The payment method to cache.
|
|
177
|
+
* @param request.paymentMethod.type - The type of the payment method.
|
|
178
|
+
* @param request.paymentMethod.paymentTokenAddress - The payment token address.
|
|
179
|
+
* @param request.paymentMethod.plan - The plan of the payment method.
|
|
145
180
|
*/
|
|
146
|
-
cacheLastSelectedPaymentMethod(
|
|
181
|
+
cacheLastSelectedPaymentMethod(request: CacheLastSelectedPaymentMethodRequest): void;
|
|
147
182
|
/**
|
|
148
183
|
* Clear the last selected payment method for a specific product.
|
|
149
184
|
*
|
|
@@ -163,7 +198,8 @@ export declare class SubscriptionController extends SubscriptionController_base<
|
|
|
163
198
|
* recurringInterval: RecurringInterval.Month,
|
|
164
199
|
* billingCycles: 1,
|
|
165
200
|
* }
|
|
166
|
-
* @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false
|
|
201
|
+
* @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
|
|
202
|
+
* @throws If the crypto payment method or chain is missing from pricing
|
|
167
203
|
*/
|
|
168
204
|
submitSponsorshipIntents(request: SubmitSponsorshipIntentsMethodParams): Promise<boolean>;
|
|
169
205
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionController.d.mts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;
|
|
1
|
+
{"version":3,"file":"SubscriptionController.d.mts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,KAAK,EAAE,aAAa,EAAO,wBAAwB;AAG1D,OAAO,EAEL,cAAc,EAGf,wBAAuB;AACxB,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAwD;AAC3G,OAAO,KAAK,EACV,2CAA2C,EAC3C,2CAA2C,EAC3C,4CAA4C,EAC5C,mCAAmC,EACnC,yCAAyC,EACzC,sDAAsD,EACtD,oCAAoC,EACpC,kDAAkD,EAClD,oDAAoD,EACpD,iDAAiD,EACjD,wCAAwC,EACxC,6CAA6C,EAC7C,gDAAgD,EAChD,kDAAkD,EACnD,sDAAqD;AAOtD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EAErB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,uCAAuC,EACvC,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,qCAAqC,EACrC,oCAAoC,EAGpC,kBAAkB,EAClB,+BAA+B,EAC/B,yBAAyB,EACzB,yBAAyB,EAE1B,oBAAmB;AACpB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,wBAAwB,EACxB,YAAY,EACb,oBAAmB;AAEpB,MAAM,MAAM,2BAA2B,GAAG;IACxC,U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