@proxy-checkout/stripe-server-js 0.1.0-prx-146.162.1 → 0.1.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/README.md +15 -113
- package/dist/cjs/errors.d.cts +1 -68
- package/dist/cjs/errors.d.ts +1 -68
- package/dist/cjs/errors.js +1 -86
- package/dist/cjs/index.d.cts +4 -10
- package/dist/cjs/index.d.ts +4 -10
- package/dist/cjs/index.js +1 -24
- package/dist/cjs/metadata.d.cts +2 -26
- package/dist/cjs/metadata.d.ts +2 -26
- package/dist/cjs/metadata.js +3 -73
- package/dist/cjs/open-checkout.d.cts +0 -21
- package/dist/cjs/open-checkout.d.ts +0 -21
- package/dist/cjs/open-checkout.js +38 -310
- package/dist/cjs/sync-checkout-cart.d.cts +3 -3
- package/dist/cjs/sync-checkout-cart.d.ts +3 -3
- package/dist/cjs/sync-checkout-cart.js +22 -92
- package/dist/cjs/types.d.cts +0 -199
- package/dist/cjs/types.d.ts +0 -199
- package/dist/cjs/version.d.cts +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/errors.d.ts +1 -68
- package/dist/esm/errors.js +0 -80
- package/dist/esm/index.d.ts +4 -10
- package/dist/esm/index.js +2 -7
- package/dist/esm/metadata.d.ts +2 -26
- package/dist/esm/metadata.js +2 -69
- package/dist/esm/open-checkout.d.ts +0 -21
- package/dist/esm/open-checkout.js +40 -312
- package/dist/esm/sync-checkout-cart.d.ts +3 -3
- package/dist/esm/sync-checkout-cart.js +23 -93
- package/dist/esm/types.d.ts +0 -199
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +3 -3
- package/dist/cjs/acquisition.d.cts +0 -189
- package/dist/cjs/acquisition.d.ts +0 -189
- package/dist/cjs/acquisition.js +0 -789
- package/dist/cjs/compatibility.d.cts +0 -66
- package/dist/cjs/compatibility.d.ts +0 -66
- package/dist/cjs/compatibility.js +0 -174
- package/dist/cjs/open-payment-intent.d.cts +0 -35
- package/dist/cjs/open-payment-intent.d.ts +0 -35
- package/dist/cjs/open-payment-intent.js +0 -157
- package/dist/cjs/open-setup-intent.d.cts +0 -49
- package/dist/cjs/open-setup-intent.d.ts +0 -49
- package/dist/cjs/open-setup-intent.js +0 -157
- package/dist/cjs/open-subscription.d.cts +0 -75
- package/dist/cjs/open-subscription.d.ts +0 -75
- package/dist/cjs/open-subscription.js +0 -307
- package/dist/cjs/subscription-params.d.cts +0 -33
- package/dist/cjs/subscription-params.d.ts +0 -33
- package/dist/cjs/subscription-params.js +0 -237
- package/dist/esm/acquisition.d.ts +0 -189
- package/dist/esm/acquisition.js +0 -763
- package/dist/esm/compatibility.d.ts +0 -66
- package/dist/esm/compatibility.js +0 -168
- package/dist/esm/open-payment-intent.d.ts +0 -35
- package/dist/esm/open-payment-intent.js +0 -154
- package/dist/esm/open-setup-intent.d.ts +0 -49
- package/dist/esm/open-setup-intent.js +0 -153
- package/dist/esm/open-subscription.d.ts +0 -75
- package/dist/esm/open-subscription.js +0 -304
- package/dist/esm/subscription-params.d.ts +0 -33
- package/dist/esm/subscription-params.js +0 -232
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.openSetupIntent = openSetupIntent;
|
|
4
|
-
exports.directSetupProviderOptionsFingerprint = directSetupProviderOptionsFingerprint;
|
|
5
|
-
const acquisition_js_1 = require("./acquisition.js");
|
|
6
|
-
const compatibility_js_1 = require("./compatibility.js");
|
|
7
|
-
const errors_js_1 = require("./errors.js");
|
|
8
|
-
const subscription_params_js_1 = require("./subscription-params.js");
|
|
9
|
-
async function openSetupIntent(options) {
|
|
10
|
-
(0, compatibility_js_1.assertStripePathCompatibility)("subscription.direct_setup_intent", options.compatibility);
|
|
11
|
-
assertStripeId(options.customerId, "cus_", "customerId");
|
|
12
|
-
(0, acquisition_js_1.assertNoConnectRequestOptions)(options.stripeRequestOptions);
|
|
13
|
-
const opened = await (0, acquisition_js_1.openSharedAcquisitionSession)({
|
|
14
|
-
cartSchema: options.cartSchema,
|
|
15
|
-
getCartBuyerReference: options.getCartBuyerReference,
|
|
16
|
-
proxy: options.proxy,
|
|
17
|
-
proxySessionId: options.proxySessionId,
|
|
18
|
-
requestId: options.requestId,
|
|
19
|
-
});
|
|
20
|
-
if (opened.outcome !== "active")
|
|
21
|
-
return opened;
|
|
22
|
-
const builderInput = {
|
|
23
|
-
cart: opened.cart,
|
|
24
|
-
proxySession: opened.proxySession,
|
|
25
|
-
stripe: options.stripe,
|
|
26
|
-
};
|
|
27
|
-
const setupIntentParams = (await options.buildSetupIntentParams?.(builderInput)) ?? {};
|
|
28
|
-
const subscriptionParams = await options.buildSubscriptionParams(builderInput);
|
|
29
|
-
(0, subscription_params_js_1.assertAllowedSetupIntentParams)(setupIntentParams);
|
|
30
|
-
(0, subscription_params_js_1.validateSubscriptionParams)(subscriptionParams);
|
|
31
|
-
(0, acquisition_js_1.assertMerchantDoesNotSetAcquisitionMetadata)(setupIntentParams.metadata, "setupIntentParams.metadata");
|
|
32
|
-
(0, acquisition_js_1.assertMerchantDoesNotSetAcquisitionMetadata)(subscriptionParams.metadata, "subscriptionParams.metadata");
|
|
33
|
-
const providerOptionsFingerprint = directSetupProviderOptionsFingerprint({
|
|
34
|
-
customerId: options.customerId,
|
|
35
|
-
initialInvoiceActionShape: options.initialInvoiceActionShape,
|
|
36
|
-
setupIntentParams,
|
|
37
|
-
subscriptionParams,
|
|
38
|
-
});
|
|
39
|
-
let reservation;
|
|
40
|
-
try {
|
|
41
|
-
reservation = await (0, acquisition_js_1.reserveDirectSubscriptionAcquisition)({
|
|
42
|
-
directSubscriptionSource: "setup_intent",
|
|
43
|
-
providerOptionsFingerprint,
|
|
44
|
-
proxy: options.proxy,
|
|
45
|
-
proxySessionId: options.proxySessionId,
|
|
46
|
-
requestId: options.requestId,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
catch (cause) {
|
|
50
|
-
const proxySession = await (0, acquisition_js_1.terminalAfterAcquisitionFailure)({
|
|
51
|
-
cause,
|
|
52
|
-
proxy: options.proxy,
|
|
53
|
-
proxySessionId: options.proxySessionId,
|
|
54
|
-
requestId: options.requestId,
|
|
55
|
-
});
|
|
56
|
-
return (0, acquisition_js_1.terminalAcquisitionResult)(proxySession, opened.cart);
|
|
57
|
-
}
|
|
58
|
-
(0, acquisition_js_1.assertDirectSubscriptionReservation)(reservation, "setup_intent", options.proxySessionId, providerOptionsFingerprint);
|
|
59
|
-
const expectedMetadata = (0, acquisition_js_1.acquisitionMetadata)(reservation);
|
|
60
|
-
const replayed = await (0, acquisition_js_1.createOrRecoverStripeAcquisitionObject)({
|
|
61
|
-
acquisition: reservation.acquisitionAttempt,
|
|
62
|
-
objectType: "setup_intent",
|
|
63
|
-
proxy: options.proxy,
|
|
64
|
-
proxySessionId: options.proxySessionId,
|
|
65
|
-
requestId: options.requestId,
|
|
66
|
-
role: "setup_intent",
|
|
67
|
-
create: async () => {
|
|
68
|
-
const setupIdempotencyKey = reservation.stripe.idempotencyKeys.setupIntent;
|
|
69
|
-
if (!setupIdempotencyKey) {
|
|
70
|
-
throw new errors_js_1.StripeResponseShapeError("Proxy direct SetupIntent reservation omitted its setup_intent idempotency key.", "stripe.idempotencyKeys.setupIntent");
|
|
71
|
-
}
|
|
72
|
-
return (await options.stripe.setupIntents.create({
|
|
73
|
-
...setupIntentParams,
|
|
74
|
-
customer: options.customerId,
|
|
75
|
-
metadata: (0, acquisition_js_1.mergeAcquisitionMetadata)(setupIntentParams.metadata, expectedMetadata),
|
|
76
|
-
}, (0, acquisition_js_1.stripeRequestOptions)(options.stripeRequestOptions, setupIdempotencyKey)));
|
|
77
|
-
},
|
|
78
|
-
retrieve: async (id) => (await options.stripe.setupIntents.retrieve(id, undefined, options.stripeRequestOptions)),
|
|
79
|
-
});
|
|
80
|
-
const setupIntent = replayed.object;
|
|
81
|
-
assertSetupIntent(setupIntent, {
|
|
82
|
-
customerId: options.customerId,
|
|
83
|
-
expectedMetadata,
|
|
84
|
-
expectedSetupIntentId: replayed.acquisition.providerSetupIntentId,
|
|
85
|
-
});
|
|
86
|
-
if (!replayed.alreadyAttached) {
|
|
87
|
-
await (0, acquisition_js_1.attachAcquisitionObject)({
|
|
88
|
-
acquisitionAttempt: replayed.acquisition,
|
|
89
|
-
objectId: setupIntent.id,
|
|
90
|
-
objectType: "setup_intent",
|
|
91
|
-
providerCustomerId: options.customerId,
|
|
92
|
-
proxy: options.proxy,
|
|
93
|
-
proxySessionId: options.proxySessionId,
|
|
94
|
-
requestId: options.requestId,
|
|
95
|
-
role: "setup_intent",
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
acquisitionAttemptId: reservation.acquisitionAttempt.id,
|
|
100
|
-
cart: opened.cart,
|
|
101
|
-
clientSecret: requireClientSecret(setupIntent),
|
|
102
|
-
outcome: "ready",
|
|
103
|
-
proxySession: opened.proxySession,
|
|
104
|
-
proxySessionId: options.proxySessionId,
|
|
105
|
-
setupIntent,
|
|
106
|
-
setupIntentId: setupIntent.id,
|
|
107
|
-
status: requireSetupIntentStatus(setupIntent),
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function directSetupProviderOptionsFingerprint(input) {
|
|
111
|
-
return (0, acquisition_js_1.fingerprintStripeProviderOptions)("direct_subscription", {
|
|
112
|
-
direct_subscription_source: "setup_intent",
|
|
113
|
-
initial_invoice_action_shape: input.initialInvoiceActionShape,
|
|
114
|
-
setup_intent: { ...input.setupIntentParams, customer: input.customerId },
|
|
115
|
-
subscription: { ...input.subscriptionParams, customer: input.customerId },
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
function assertSetupIntent(setupIntent, input) {
|
|
119
|
-
assertStripeId(setupIntent.id, "seti_", "setupIntent.id");
|
|
120
|
-
if (input.expectedSetupIntentId !== null && setupIntent.id !== input.expectedSetupIntentId) {
|
|
121
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe returned SetupIntent ${setupIntent.id} while retrieving ${input.expectedSetupIntentId}.`, { code: "acquisition_mismatch", field: "setupIntent.id" });
|
|
122
|
-
}
|
|
123
|
-
(0, acquisition_js_1.assertAcquisitionMetadata)(setupIntent.metadata, input.expectedMetadata, "Stripe SetupIntent");
|
|
124
|
-
const customerId = (0, acquisition_js_1.requireStripeObjectId)(setupIntent.customer, "cus_", "setupIntent.customer");
|
|
125
|
-
if (customerId !== input.customerId) {
|
|
126
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe SetupIntent ${setupIntent.id} Customer does not match the shared billing Customer.`, { code: "customer_payment_method_mismatch", field: "setupIntent.customer" });
|
|
127
|
-
}
|
|
128
|
-
requireSetupIntentStatus(setupIntent);
|
|
129
|
-
}
|
|
130
|
-
function requireSetupIntentStatus(setupIntent) {
|
|
131
|
-
const supported = new Set([
|
|
132
|
-
"canceled",
|
|
133
|
-
"processing",
|
|
134
|
-
"requires_action",
|
|
135
|
-
"requires_confirmation",
|
|
136
|
-
"requires_payment_method",
|
|
137
|
-
"succeeded",
|
|
138
|
-
]);
|
|
139
|
-
if (typeof setupIntent.status !== "string" || !supported.has(setupIntent.status)) {
|
|
140
|
-
throw new errors_js_1.StripeResponseShapeError(`Stripe SetupIntent ${setupIntent.id} returned an unsupported status shape.`, "setupIntent.status");
|
|
141
|
-
}
|
|
142
|
-
return setupIntent.status;
|
|
143
|
-
}
|
|
144
|
-
function requireClientSecret(setupIntent) {
|
|
145
|
-
if (typeof setupIntent.client_secret !== "string" || setupIntent.client_secret.length === 0) {
|
|
146
|
-
throw new errors_js_1.StripeResponseShapeError(`Stripe SetupIntent ${setupIntent.id} did not return presentation material.`, "setupIntent.client_secret");
|
|
147
|
-
}
|
|
148
|
-
return setupIntent.client_secret;
|
|
149
|
-
}
|
|
150
|
-
function assertStripeId(value, prefix, field) {
|
|
151
|
-
if (!value.startsWith(prefix) || value.length <= prefix.length) {
|
|
152
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe ${field} is invalid.`, {
|
|
153
|
-
code: "provider_response_invalid",
|
|
154
|
-
field,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { PayerOpenedResult, ProxyCartValidator } from "@proxy-checkout/server-js";
|
|
2
|
-
import { type SharedAcquisitionTerminal, type StripeAcquisitionProxyClient } from "./acquisition.js";
|
|
3
|
-
import { type StripeCompatibilityDescriptor } from "./compatibility.js";
|
|
4
|
-
import { type ValidateFixedSubscriptionPrice } from "./subscription-params.js";
|
|
5
|
-
import type { StripeDirectSubscriptionClientLike, StripeInvoiceLike, StripeRequestOptionsWithoutIdempotencyLike, StripeSetupIntentCreateParams, StripeSetupSubscriptionClientLike, StripeSubscriptionCreateParams, StripeSubscriptionLike } from "./types.js";
|
|
6
|
-
export type InitialInvoiceAction = {
|
|
7
|
-
readonly invoiceId: string | null;
|
|
8
|
-
readonly kind: "none";
|
|
9
|
-
} | {
|
|
10
|
-
readonly clientSecret: string;
|
|
11
|
-
readonly invoiceId: string;
|
|
12
|
-
readonly kind: "client_secret";
|
|
13
|
-
readonly paymentIntentId: string | null;
|
|
14
|
-
};
|
|
15
|
-
export interface OpenSubscriptionBuilderInput<TStripe extends StripeDirectSubscriptionClientLike, TCart> {
|
|
16
|
-
readonly cart: TCart;
|
|
17
|
-
readonly proxySession: PayerOpenedResult;
|
|
18
|
-
readonly stripe: TStripe;
|
|
19
|
-
}
|
|
20
|
-
interface OpenSubscriptionBaseOptions<TStripe extends StripeDirectSubscriptionClientLike, TCart> {
|
|
21
|
-
readonly buildSubscriptionParams: (input: OpenSubscriptionBuilderInput<TStripe, TCart>) => Promise<StripeSubscriptionCreateParams> | StripeSubscriptionCreateParams;
|
|
22
|
-
readonly cartSchema?: ProxyCartValidator<TCart>;
|
|
23
|
-
readonly compatibility?: StripeCompatibilityDescriptor;
|
|
24
|
-
readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
|
|
25
|
-
/** Must match the merchant's pinned Stripe API generation; no shape fallback is attempted. */
|
|
26
|
-
readonly initialInvoiceActionShape: "confirmation_secret" | "legacy_payment_intent";
|
|
27
|
-
readonly proxy: StripeAcquisitionProxyClient;
|
|
28
|
-
readonly proxySessionId: string;
|
|
29
|
-
readonly requestId?: string;
|
|
30
|
-
readonly stripe: TStripe;
|
|
31
|
-
readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
|
|
32
|
-
/** Merchant cart/quote attestation for discounts or additional fixed-price checks. */
|
|
33
|
-
readonly validateFixedPrice?: ValidateFixedSubscriptionPrice<TCart>;
|
|
34
|
-
}
|
|
35
|
-
interface OpenSubscriptionFromSetupIntent<TStripe extends StripeSetupSubscriptionClientLike, TCart> {
|
|
36
|
-
readonly fromSavedPaymentMethod?: never;
|
|
37
|
-
readonly fromSetupIntent: {
|
|
38
|
-
readonly acquisitionAttemptId: string;
|
|
39
|
-
readonly buildSetupIntentParams?: (input: OpenSubscriptionBuilderInput<TStripe, TCart>) => Promise<StripeSetupIntentCreateParams> | StripeSetupIntentCreateParams;
|
|
40
|
-
readonly setupIntentId: string;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
interface OpenSubscriptionFromSavedPaymentMethod {
|
|
44
|
-
/**
|
|
45
|
-
* This branch is shareable only for an authorized purchase/shared billing
|
|
46
|
-
* account, never one invited viewer's private saved method.
|
|
47
|
-
*/
|
|
48
|
-
readonly fromSavedPaymentMethod: {
|
|
49
|
-
readonly customerId: string;
|
|
50
|
-
readonly paymentMethodId: string;
|
|
51
|
-
};
|
|
52
|
-
readonly fromSetupIntent?: never;
|
|
53
|
-
}
|
|
54
|
-
export type OpenSubscriptionOptions<TStripe extends StripeDirectSubscriptionClientLike, TCart = unknown> = OpenSubscriptionBaseOptions<TStripe, TCart> & (TStripe extends StripeSetupSubscriptionClientLike ? OpenSubscriptionFromSetupIntent<TStripe, TCart> | OpenSubscriptionFromSavedPaymentMethod : OpenSubscriptionFromSavedPaymentMethod);
|
|
55
|
-
export interface OpenSubscriptionReadyResult<TCart, TSubscription extends StripeSubscriptionLike> {
|
|
56
|
-
readonly acquisitionAttemptId: string;
|
|
57
|
-
readonly cart: TCart;
|
|
58
|
-
readonly initialInvoiceAction: InitialInvoiceAction;
|
|
59
|
-
readonly outcome: "ready";
|
|
60
|
-
readonly proxySession: PayerOpenedResult;
|
|
61
|
-
readonly proxySessionId: string;
|
|
62
|
-
readonly status: string;
|
|
63
|
-
readonly subscription: TSubscription;
|
|
64
|
-
readonly subscriptionId: string;
|
|
65
|
-
}
|
|
66
|
-
export type OpenSubscriptionResponse<TCart, TSubscription extends StripeSubscriptionLike> = OpenSubscriptionReadyResult<TCart, TSubscription> | SharedAcquisitionTerminal<TCart>;
|
|
67
|
-
export declare function openSubscription<TStripe extends StripeDirectSubscriptionClientLike, TCart = unknown, TSubscription extends StripeSubscriptionLike = StripeSubscriptionLike>(options: OpenSubscriptionOptions<TStripe, TCart>): Promise<OpenSubscriptionResponse<TCart, TSubscription>>;
|
|
68
|
-
export type LegacyInitialInvoiceLike = StripeInvoiceLike & {
|
|
69
|
-
readonly payment_intent?: {
|
|
70
|
-
readonly client_secret?: string | null;
|
|
71
|
-
readonly id: string;
|
|
72
|
-
readonly status?: string;
|
|
73
|
-
} | null;
|
|
74
|
-
};
|
|
75
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { PayerOpenedResult, ProxyCartValidator } from "@proxy-checkout/server-js";
|
|
2
|
-
import { type SharedAcquisitionTerminal, type StripeAcquisitionProxyClient } from "./acquisition.js";
|
|
3
|
-
import { type StripeCompatibilityDescriptor } from "./compatibility.js";
|
|
4
|
-
import { type ValidateFixedSubscriptionPrice } from "./subscription-params.js";
|
|
5
|
-
import type { StripeDirectSubscriptionClientLike, StripeInvoiceLike, StripeRequestOptionsWithoutIdempotencyLike, StripeSetupIntentCreateParams, StripeSetupSubscriptionClientLike, StripeSubscriptionCreateParams, StripeSubscriptionLike } from "./types.js";
|
|
6
|
-
export type InitialInvoiceAction = {
|
|
7
|
-
readonly invoiceId: string | null;
|
|
8
|
-
readonly kind: "none";
|
|
9
|
-
} | {
|
|
10
|
-
readonly clientSecret: string;
|
|
11
|
-
readonly invoiceId: string;
|
|
12
|
-
readonly kind: "client_secret";
|
|
13
|
-
readonly paymentIntentId: string | null;
|
|
14
|
-
};
|
|
15
|
-
export interface OpenSubscriptionBuilderInput<TStripe extends StripeDirectSubscriptionClientLike, TCart> {
|
|
16
|
-
readonly cart: TCart;
|
|
17
|
-
readonly proxySession: PayerOpenedResult;
|
|
18
|
-
readonly stripe: TStripe;
|
|
19
|
-
}
|
|
20
|
-
interface OpenSubscriptionBaseOptions<TStripe extends StripeDirectSubscriptionClientLike, TCart> {
|
|
21
|
-
readonly buildSubscriptionParams: (input: OpenSubscriptionBuilderInput<TStripe, TCart>) => Promise<StripeSubscriptionCreateParams> | StripeSubscriptionCreateParams;
|
|
22
|
-
readonly cartSchema?: ProxyCartValidator<TCart>;
|
|
23
|
-
readonly compatibility?: StripeCompatibilityDescriptor;
|
|
24
|
-
readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
|
|
25
|
-
/** Must match the merchant's pinned Stripe API generation; no shape fallback is attempted. */
|
|
26
|
-
readonly initialInvoiceActionShape: "confirmation_secret" | "legacy_payment_intent";
|
|
27
|
-
readonly proxy: StripeAcquisitionProxyClient;
|
|
28
|
-
readonly proxySessionId: string;
|
|
29
|
-
readonly requestId?: string;
|
|
30
|
-
readonly stripe: TStripe;
|
|
31
|
-
readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
|
|
32
|
-
/** Merchant cart/quote attestation for discounts or additional fixed-price checks. */
|
|
33
|
-
readonly validateFixedPrice?: ValidateFixedSubscriptionPrice<TCart>;
|
|
34
|
-
}
|
|
35
|
-
interface OpenSubscriptionFromSetupIntent<TStripe extends StripeSetupSubscriptionClientLike, TCart> {
|
|
36
|
-
readonly fromSavedPaymentMethod?: never;
|
|
37
|
-
readonly fromSetupIntent: {
|
|
38
|
-
readonly acquisitionAttemptId: string;
|
|
39
|
-
readonly buildSetupIntentParams?: (input: OpenSubscriptionBuilderInput<TStripe, TCart>) => Promise<StripeSetupIntentCreateParams> | StripeSetupIntentCreateParams;
|
|
40
|
-
readonly setupIntentId: string;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
interface OpenSubscriptionFromSavedPaymentMethod {
|
|
44
|
-
/**
|
|
45
|
-
* This branch is shareable only for an authorized purchase/shared billing
|
|
46
|
-
* account, never one invited viewer's private saved method.
|
|
47
|
-
*/
|
|
48
|
-
readonly fromSavedPaymentMethod: {
|
|
49
|
-
readonly customerId: string;
|
|
50
|
-
readonly paymentMethodId: string;
|
|
51
|
-
};
|
|
52
|
-
readonly fromSetupIntent?: never;
|
|
53
|
-
}
|
|
54
|
-
export type OpenSubscriptionOptions<TStripe extends StripeDirectSubscriptionClientLike, TCart = unknown> = OpenSubscriptionBaseOptions<TStripe, TCart> & (TStripe extends StripeSetupSubscriptionClientLike ? OpenSubscriptionFromSetupIntent<TStripe, TCart> | OpenSubscriptionFromSavedPaymentMethod : OpenSubscriptionFromSavedPaymentMethod);
|
|
55
|
-
export interface OpenSubscriptionReadyResult<TCart, TSubscription extends StripeSubscriptionLike> {
|
|
56
|
-
readonly acquisitionAttemptId: string;
|
|
57
|
-
readonly cart: TCart;
|
|
58
|
-
readonly initialInvoiceAction: InitialInvoiceAction;
|
|
59
|
-
readonly outcome: "ready";
|
|
60
|
-
readonly proxySession: PayerOpenedResult;
|
|
61
|
-
readonly proxySessionId: string;
|
|
62
|
-
readonly status: string;
|
|
63
|
-
readonly subscription: TSubscription;
|
|
64
|
-
readonly subscriptionId: string;
|
|
65
|
-
}
|
|
66
|
-
export type OpenSubscriptionResponse<TCart, TSubscription extends StripeSubscriptionLike> = OpenSubscriptionReadyResult<TCart, TSubscription> | SharedAcquisitionTerminal<TCart>;
|
|
67
|
-
export declare function openSubscription<TStripe extends StripeDirectSubscriptionClientLike, TCart = unknown, TSubscription extends StripeSubscriptionLike = StripeSubscriptionLike>(options: OpenSubscriptionOptions<TStripe, TCart>): Promise<OpenSubscriptionResponse<TCart, TSubscription>>;
|
|
68
|
-
export type LegacyInitialInvoiceLike = StripeInvoiceLike & {
|
|
69
|
-
readonly payment_intent?: {
|
|
70
|
-
readonly client_secret?: string | null;
|
|
71
|
-
readonly id: string;
|
|
72
|
-
readonly status?: string;
|
|
73
|
-
} | null;
|
|
74
|
-
};
|
|
75
|
-
export {};
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.openSubscription = openSubscription;
|
|
4
|
-
const acquisition_js_1 = require("./acquisition.js");
|
|
5
|
-
const compatibility_js_1 = require("./compatibility.js");
|
|
6
|
-
const errors_js_1 = require("./errors.js");
|
|
7
|
-
const open_setup_intent_js_1 = require("./open-setup-intent.js");
|
|
8
|
-
const subscription_params_js_1 = require("./subscription-params.js");
|
|
9
|
-
async function openSubscription(options) {
|
|
10
|
-
(0, acquisition_js_1.assertNoConnectRequestOptions)(options.stripeRequestOptions);
|
|
11
|
-
(0, compatibility_js_1.assertStripePathCompatibility)(options.fromSetupIntent === undefined
|
|
12
|
-
? "subscription.direct_saved_payment_method"
|
|
13
|
-
: "subscription.direct_setup_intent", options.compatibility);
|
|
14
|
-
const opened = await (0, acquisition_js_1.openSharedAcquisitionSession)({
|
|
15
|
-
cartSchema: options.cartSchema,
|
|
16
|
-
getCartBuyerReference: options.getCartBuyerReference,
|
|
17
|
-
proxy: options.proxy,
|
|
18
|
-
proxySessionId: options.proxySessionId,
|
|
19
|
-
requestId: options.requestId,
|
|
20
|
-
});
|
|
21
|
-
if (opened.outcome !== "active")
|
|
22
|
-
return opened;
|
|
23
|
-
const builderInput = {
|
|
24
|
-
cart: opened.cart,
|
|
25
|
-
proxySession: opened.proxySession,
|
|
26
|
-
stripe: options.stripe,
|
|
27
|
-
};
|
|
28
|
-
const subscriptionParams = await options.buildSubscriptionParams(builderInput);
|
|
29
|
-
const items = (0, subscription_params_js_1.validateSubscriptionParams)(subscriptionParams);
|
|
30
|
-
(0, acquisition_js_1.assertMerchantDoesNotSetAcquisitionMetadata)(subscriptionParams.metadata, "subscriptionParams.metadata");
|
|
31
|
-
const validateFixedPrices = () => (0, subscription_params_js_1.retrieveAndValidateSubscriptionPrices)({
|
|
32
|
-
cart: opened.cart,
|
|
33
|
-
items,
|
|
34
|
-
params: subscriptionParams,
|
|
35
|
-
proxySession: opened.proxySession,
|
|
36
|
-
stripe: options.stripe,
|
|
37
|
-
stripeRequestOptions: options.stripeRequestOptions,
|
|
38
|
-
validateFixedPrice: options.validateFixedPrice,
|
|
39
|
-
});
|
|
40
|
-
let customerId;
|
|
41
|
-
let paymentMethodId;
|
|
42
|
-
let providerOptionsFingerprint;
|
|
43
|
-
let reservation;
|
|
44
|
-
if (options.fromSetupIntent !== undefined) {
|
|
45
|
-
assertStripeId(options.fromSetupIntent.setupIntentId, "seti_", "fromSetupIntent.setupIntentId");
|
|
46
|
-
const setupStripe = requireSetupSubscriptionClient(options.stripe);
|
|
47
|
-
const setupIntentParams = (await options.fromSetupIntent.buildSetupIntentParams?.({
|
|
48
|
-
...builderInput,
|
|
49
|
-
stripe: setupStripe,
|
|
50
|
-
})) ?? {};
|
|
51
|
-
(0, subscription_params_js_1.assertAllowedSetupIntentParams)(setupIntentParams);
|
|
52
|
-
(0, acquisition_js_1.assertMerchantDoesNotSetAcquisitionMetadata)(setupIntentParams.metadata, "setupIntentParams.metadata");
|
|
53
|
-
const setupIntent = await setupStripe.setupIntents.retrieve(options.fromSetupIntent.setupIntentId, undefined, options.stripeRequestOptions);
|
|
54
|
-
if (setupIntent.id !== options.fromSetupIntent.setupIntentId) {
|
|
55
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe returned SetupIntent ${setupIntent.id} while retrieving ${options.fromSetupIntent.setupIntentId}.`, { code: "acquisition_mismatch", field: "setupIntent.id" });
|
|
56
|
-
}
|
|
57
|
-
const expectedMetadata = {
|
|
58
|
-
proxy_acquisition_attempt_id: options.fromSetupIntent.acquisitionAttemptId,
|
|
59
|
-
proxy_contract_version: "2",
|
|
60
|
-
proxy_integration_path: "direct_subscription",
|
|
61
|
-
proxy_session_id: options.proxySessionId,
|
|
62
|
-
};
|
|
63
|
-
(0, acquisition_js_1.assertAcquisitionMetadata)(setupIntent.metadata, expectedMetadata, "Stripe SetupIntent");
|
|
64
|
-
if (setupIntent.status !== "succeeded") {
|
|
65
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe SetupIntent ${setupIntent.id} must succeed before creating a Subscription.`, { code: "setup_intent_not_succeeded", field: "setupIntent.status" });
|
|
66
|
-
}
|
|
67
|
-
customerId = (0, acquisition_js_1.requireStripeObjectId)(setupIntent.customer, "cus_", "setupIntent.customer");
|
|
68
|
-
paymentMethodId = (0, acquisition_js_1.requireStripeObjectId)(setupIntent.payment_method, "pm_", "setupIntent.payment_method");
|
|
69
|
-
await assertPaymentMethodCustomer({
|
|
70
|
-
customerId,
|
|
71
|
-
paymentMethodId,
|
|
72
|
-
stripe: options.stripe,
|
|
73
|
-
stripeRequestOptions: options.stripeRequestOptions,
|
|
74
|
-
});
|
|
75
|
-
await validateFixedPrices();
|
|
76
|
-
providerOptionsFingerprint = (0, open_setup_intent_js_1.directSetupProviderOptionsFingerprint)({
|
|
77
|
-
customerId,
|
|
78
|
-
initialInvoiceActionShape: options.initialInvoiceActionShape,
|
|
79
|
-
setupIntentParams,
|
|
80
|
-
subscriptionParams,
|
|
81
|
-
});
|
|
82
|
-
try {
|
|
83
|
-
reservation = await (0, acquisition_js_1.recoverSetupIntentReservation)({
|
|
84
|
-
acquisitionAttemptId: options.fromSetupIntent.acquisitionAttemptId,
|
|
85
|
-
providerOptionsFingerprint,
|
|
86
|
-
proxy: options.proxy,
|
|
87
|
-
proxySessionId: options.proxySessionId,
|
|
88
|
-
requestId: options.requestId,
|
|
89
|
-
setupIntentId: options.fromSetupIntent.setupIntentId,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
catch (cause) {
|
|
93
|
-
const proxySession = await (0, acquisition_js_1.terminalAfterAcquisitionFailure)({
|
|
94
|
-
cause,
|
|
95
|
-
proxy: options.proxy,
|
|
96
|
-
proxySessionId: options.proxySessionId,
|
|
97
|
-
requestId: options.requestId,
|
|
98
|
-
});
|
|
99
|
-
return (0, acquisition_js_1.terminalAcquisitionResult)(proxySession, opened.cart);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
customerId = options.fromSavedPaymentMethod.customerId;
|
|
104
|
-
paymentMethodId = options.fromSavedPaymentMethod.paymentMethodId;
|
|
105
|
-
assertStripeId(customerId, "cus_", "fromSavedPaymentMethod.customerId");
|
|
106
|
-
assertStripeId(paymentMethodId, "pm_", "fromSavedPaymentMethod.paymentMethodId");
|
|
107
|
-
await assertPaymentMethodCustomer({
|
|
108
|
-
customerId,
|
|
109
|
-
paymentMethodId,
|
|
110
|
-
stripe: options.stripe,
|
|
111
|
-
stripeRequestOptions: options.stripeRequestOptions,
|
|
112
|
-
});
|
|
113
|
-
await validateFixedPrices();
|
|
114
|
-
providerOptionsFingerprint = (0, acquisition_js_1.fingerprintStripeProviderOptions)("direct_subscription", {
|
|
115
|
-
direct_subscription_source: "saved_payment_method",
|
|
116
|
-
initial_invoice_action_shape: options.initialInvoiceActionShape,
|
|
117
|
-
subscription: {
|
|
118
|
-
...subscriptionParams,
|
|
119
|
-
customer: customerId,
|
|
120
|
-
default_payment_method: paymentMethodId,
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
try {
|
|
124
|
-
reservation = await (0, acquisition_js_1.reserveDirectSubscriptionAcquisition)({
|
|
125
|
-
directSubscriptionSource: "saved_payment_method",
|
|
126
|
-
providerOptionsFingerprint,
|
|
127
|
-
proxy: options.proxy,
|
|
128
|
-
proxySessionId: options.proxySessionId,
|
|
129
|
-
requestId: options.requestId,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
catch (cause) {
|
|
133
|
-
const proxySession = await (0, acquisition_js_1.terminalAfterAcquisitionFailure)({
|
|
134
|
-
cause,
|
|
135
|
-
proxy: options.proxy,
|
|
136
|
-
proxySessionId: options.proxySessionId,
|
|
137
|
-
requestId: options.requestId,
|
|
138
|
-
});
|
|
139
|
-
return (0, acquisition_js_1.terminalAcquisitionResult)(proxySession, opened.cart);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const source = options.fromSetupIntent ? "setup_intent" : "saved_payment_method";
|
|
143
|
-
(0, acquisition_js_1.assertDirectSubscriptionReservation)(reservation, source, options.proxySessionId, providerOptionsFingerprint);
|
|
144
|
-
const expectedMetadata = (0, acquisition_js_1.acquisitionMetadata)(reservation);
|
|
145
|
-
const expansion = initialInvoiceExpansion(options.initialInvoiceActionShape);
|
|
146
|
-
const replayed = await (0, acquisition_js_1.createOrRecoverStripeAcquisitionObject)({
|
|
147
|
-
acquisition: reservation.acquisitionAttempt,
|
|
148
|
-
objectType: "subscription",
|
|
149
|
-
proxy: options.proxy,
|
|
150
|
-
proxySessionId: options.proxySessionId,
|
|
151
|
-
requestId: options.requestId,
|
|
152
|
-
role: "root",
|
|
153
|
-
create: async () => (await options.stripe.subscriptions.create({
|
|
154
|
-
...subscriptionParams,
|
|
155
|
-
collection_method: "charge_automatically",
|
|
156
|
-
customer: customerId,
|
|
157
|
-
default_payment_method: paymentMethodId,
|
|
158
|
-
expand: uniqueStrings([...(subscriptionParams.expand ?? []), ...expansion]),
|
|
159
|
-
metadata: (0, acquisition_js_1.mergeAcquisitionMetadata)(subscriptionParams.metadata, expectedMetadata),
|
|
160
|
-
payment_behavior: "default_incomplete",
|
|
161
|
-
}, (0, acquisition_js_1.stripeRequestOptions)(options.stripeRequestOptions, reservation.stripe.idempotencyKeys.root))),
|
|
162
|
-
retrieve: async (id) => (await options.stripe.subscriptions.retrieve(id, { expand: expansion }, options.stripeRequestOptions)),
|
|
163
|
-
});
|
|
164
|
-
const subscription = replayed.object;
|
|
165
|
-
assertSubscriptionResponse(subscription, {
|
|
166
|
-
customerId,
|
|
167
|
-
expectedMetadata,
|
|
168
|
-
expectedSubscriptionId: replayed.acquisition.providerRootObjectId,
|
|
169
|
-
paymentMethodId,
|
|
170
|
-
});
|
|
171
|
-
if (!replayed.alreadyAttached) {
|
|
172
|
-
await (0, acquisition_js_1.attachAcquisitionObject)({
|
|
173
|
-
acquisitionAttempt: replayed.acquisition,
|
|
174
|
-
objectId: subscription.id,
|
|
175
|
-
objectType: "subscription",
|
|
176
|
-
providerCustomerId: customerId,
|
|
177
|
-
proxy: options.proxy,
|
|
178
|
-
proxySessionId: options.proxySessionId,
|
|
179
|
-
requestId: options.requestId,
|
|
180
|
-
role: "root",
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
acquisitionAttemptId: reservation.acquisitionAttempt.id,
|
|
185
|
-
cart: opened.cart,
|
|
186
|
-
initialInvoiceAction: readInitialInvoiceAction(subscription),
|
|
187
|
-
outcome: "ready",
|
|
188
|
-
proxySession: opened.proxySession,
|
|
189
|
-
proxySessionId: options.proxySessionId,
|
|
190
|
-
status: requireSubscriptionStatus(subscription),
|
|
191
|
-
subscription,
|
|
192
|
-
subscriptionId: subscription.id,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
function initialInvoiceExpansion(shape) {
|
|
196
|
-
return shape === "confirmation_secret"
|
|
197
|
-
? ["latest_invoice.confirmation_secret"]
|
|
198
|
-
: ["latest_invoice.payment_intent"];
|
|
199
|
-
}
|
|
200
|
-
function readInitialInvoiceAction(subscription) {
|
|
201
|
-
const latestInvoice = subscription.latest_invoice;
|
|
202
|
-
if (latestInvoice === null || latestInvoice === undefined) {
|
|
203
|
-
if (subscription.status === "active" || subscription.status === "trialing") {
|
|
204
|
-
return { invoiceId: null, kind: "none" };
|
|
205
|
-
}
|
|
206
|
-
throw new errors_js_1.StripeResponseShapeError(`Stripe Subscription ${subscription.id} did not return an expanded initial Invoice.`, "subscription.latest_invoice");
|
|
207
|
-
}
|
|
208
|
-
if (typeof latestInvoice === "string") {
|
|
209
|
-
throw new errors_js_1.StripeResponseShapeError(`Stripe Subscription ${subscription.id} initial Invoice was not expanded.`, "subscription.latest_invoice");
|
|
210
|
-
}
|
|
211
|
-
assertStripeId(latestInvoice.id, "in_", "subscription.latest_invoice.id");
|
|
212
|
-
const confirmationSecret = latestInvoice.confirmation_secret;
|
|
213
|
-
if (confirmationSecret &&
|
|
214
|
-
typeof confirmationSecret.client_secret === "string" &&
|
|
215
|
-
confirmationSecret.client_secret.length > 0) {
|
|
216
|
-
if (confirmationSecret.type !== undefined && confirmationSecret.type !== "payment_intent") {
|
|
217
|
-
throw new errors_js_1.StripeResponseShapeError(`Stripe Invoice ${latestInvoice.id} returned an unsupported confirmation secret type.`, "subscription.latest_invoice.confirmation_secret.type");
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
clientSecret: confirmationSecret.client_secret,
|
|
221
|
-
invoiceId: latestInvoice.id,
|
|
222
|
-
kind: "client_secret",
|
|
223
|
-
paymentIntentId: null,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
const paymentIntent = latestInvoice.payment_intent;
|
|
227
|
-
if (typeof paymentIntent === "object" &&
|
|
228
|
-
paymentIntent !== null &&
|
|
229
|
-
typeof paymentIntent.client_secret === "string" &&
|
|
230
|
-
paymentIntent.client_secret.length > 0) {
|
|
231
|
-
return {
|
|
232
|
-
clientSecret: paymentIntent.client_secret,
|
|
233
|
-
invoiceId: latestInvoice.id,
|
|
234
|
-
kind: "client_secret",
|
|
235
|
-
paymentIntentId: (0, acquisition_js_1.requireStripeObjectId)(paymentIntent, "pi_", "subscription.latest_invoice.payment_intent"),
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
if (latestInvoice.amount_due === 0 ||
|
|
239
|
-
latestInvoice.status === "paid" ||
|
|
240
|
-
latestInvoice.status === "void" ||
|
|
241
|
-
subscription.status === "active" ||
|
|
242
|
-
subscription.status === "trialing" ||
|
|
243
|
-
(typeof paymentIntent === "object" &&
|
|
244
|
-
paymentIntent !== null &&
|
|
245
|
-
(paymentIntent.status === "processing" || paymentIntent.status === "succeeded"))) {
|
|
246
|
-
return { invoiceId: latestInvoice.id, kind: "none" };
|
|
247
|
-
}
|
|
248
|
-
throw new errors_js_1.StripeResponseShapeError(`Stripe Subscription ${subscription.id} initial Invoice requires action but did not return a client secret.`, "subscription.latest_invoice");
|
|
249
|
-
}
|
|
250
|
-
async function assertPaymentMethodCustomer(input) {
|
|
251
|
-
const paymentMethod = await input.stripe.paymentMethods.retrieve(input.paymentMethodId, undefined, input.stripeRequestOptions);
|
|
252
|
-
if (paymentMethod.id !== input.paymentMethodId) {
|
|
253
|
-
throw new errors_js_1.ProxyStripeAcquisitionError("Stripe returned a different PaymentMethod than the one requested by the merchant.", { code: "customer_payment_method_mismatch", field: "paymentMethod.id" });
|
|
254
|
-
}
|
|
255
|
-
const attachedCustomerId = (0, acquisition_js_1.requireStripeObjectId)(paymentMethod.customer, "cus_", "paymentMethod.customer");
|
|
256
|
-
if (attachedCustomerId !== input.customerId) {
|
|
257
|
-
throw new errors_js_1.ProxyStripeAcquisitionError("Stripe PaymentMethod is not attached to the authorized shared billing Customer.", { code: "customer_payment_method_mismatch", field: "paymentMethod.customer" });
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function requireSetupSubscriptionClient(stripe) {
|
|
261
|
-
if (!("setupIntents" in stripe) ||
|
|
262
|
-
typeof stripe.setupIntents?.retrieve !==
|
|
263
|
-
"function") {
|
|
264
|
-
throw new errors_js_1.ProxyStripeAcquisitionError("The fromSetupIntent branch requires a merchant Stripe client with setupIntents.retrieve.", { code: "provider_response_invalid", field: "stripe.setupIntents.retrieve" });
|
|
265
|
-
}
|
|
266
|
-
return stripe;
|
|
267
|
-
}
|
|
268
|
-
function assertSubscriptionResponse(subscription, input) {
|
|
269
|
-
assertStripeId(subscription.id, "sub_", "subscription.id");
|
|
270
|
-
if (input.expectedSubscriptionId !== null && subscription.id !== input.expectedSubscriptionId) {
|
|
271
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe returned Subscription ${subscription.id} while retrieving ${input.expectedSubscriptionId}.`, { code: "acquisition_mismatch", field: "subscription.id" });
|
|
272
|
-
}
|
|
273
|
-
(0, acquisition_js_1.assertAcquisitionMetadata)(subscription.metadata, input.expectedMetadata, "Stripe Subscription");
|
|
274
|
-
const customerId = (0, acquisition_js_1.requireStripeObjectId)(subscription.customer, "cus_", "subscription.customer");
|
|
275
|
-
const paymentMethodId = (0, acquisition_js_1.requireStripeObjectId)(subscription.default_payment_method, "pm_", "subscription.default_payment_method");
|
|
276
|
-
if (customerId !== input.customerId || paymentMethodId !== input.paymentMethodId) {
|
|
277
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe Subscription ${subscription.id} billing identity does not match the verified Customer and PaymentMethod.`, { code: "customer_payment_method_mismatch", field: "subscription.default_payment_method" });
|
|
278
|
-
}
|
|
279
|
-
requireSubscriptionStatus(subscription);
|
|
280
|
-
}
|
|
281
|
-
function requireSubscriptionStatus(subscription) {
|
|
282
|
-
const supported = new Set([
|
|
283
|
-
"active",
|
|
284
|
-
"canceled",
|
|
285
|
-
"incomplete",
|
|
286
|
-
"incomplete_expired",
|
|
287
|
-
"past_due",
|
|
288
|
-
"paused",
|
|
289
|
-
"trialing",
|
|
290
|
-
"unpaid",
|
|
291
|
-
]);
|
|
292
|
-
if (typeof subscription.status !== "string" || !supported.has(subscription.status)) {
|
|
293
|
-
throw new errors_js_1.StripeResponseShapeError(`Stripe Subscription ${subscription.id} returned an unsupported status shape.`, "subscription.status");
|
|
294
|
-
}
|
|
295
|
-
return subscription.status;
|
|
296
|
-
}
|
|
297
|
-
function uniqueStrings(values) {
|
|
298
|
-
return [...new Set(values)];
|
|
299
|
-
}
|
|
300
|
-
function assertStripeId(value, prefix, field) {
|
|
301
|
-
if (!value.startsWith(prefix) || value.length <= prefix.length) {
|
|
302
|
-
throw new errors_js_1.ProxyStripeAcquisitionError(`Stripe ${field} is invalid.`, {
|
|
303
|
-
code: "provider_response_invalid",
|
|
304
|
-
field,
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { PayerOpenedResult } from "@proxy-checkout/server-js";
|
|
2
|
-
import type { StripeDirectSubscriptionClientLike, StripePriceLike, StripeRequestOptionsWithoutIdempotencyLike, StripeSetupIntentCreateParams, StripeSubscriptionCreateParams } from "./types.js";
|
|
3
|
-
export interface ValidatedSubscriptionItem {
|
|
4
|
-
readonly priceId: string;
|
|
5
|
-
readonly quantity: number;
|
|
6
|
-
}
|
|
7
|
-
export interface VerifiedSubscriptionPriceItem extends ValidatedSubscriptionItem {
|
|
8
|
-
readonly price: StripePriceLike;
|
|
9
|
-
readonly unitAmountMinor: number;
|
|
10
|
-
}
|
|
11
|
-
export interface ValidateFixedSubscriptionPriceInput<TCart> {
|
|
12
|
-
readonly baseRecurringSubtotalMinor: number;
|
|
13
|
-
readonly cart: TCart;
|
|
14
|
-
readonly currency: string;
|
|
15
|
-
readonly items: readonly VerifiedSubscriptionPriceItem[];
|
|
16
|
-
readonly proxySession: PayerOpenedResult;
|
|
17
|
-
}
|
|
18
|
-
export type ValidateFixedSubscriptionPrice<TCart> = (input: ValidateFixedSubscriptionPriceInput<TCart>) => {
|
|
19
|
-
readonly expectedInitialInvoiceAmountMinor: number;
|
|
20
|
-
} | Promise<{
|
|
21
|
-
readonly expectedInitialInvoiceAmountMinor: number;
|
|
22
|
-
}>;
|
|
23
|
-
export declare function assertAllowedSetupIntentParams(params: StripeSetupIntentCreateParams): void;
|
|
24
|
-
export declare function validateSubscriptionParams(params: StripeSubscriptionCreateParams): readonly ValidatedSubscriptionItem[];
|
|
25
|
-
export declare function retrieveAndValidateSubscriptionPrices<TCart>(input: {
|
|
26
|
-
cart: TCart;
|
|
27
|
-
items: readonly ValidatedSubscriptionItem[];
|
|
28
|
-
params: StripeSubscriptionCreateParams;
|
|
29
|
-
proxySession: PayerOpenedResult;
|
|
30
|
-
stripe: StripeDirectSubscriptionClientLike;
|
|
31
|
-
stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
|
|
32
|
-
validateFixedPrice?: ValidateFixedSubscriptionPrice<TCart>;
|
|
33
|
-
}): Promise<readonly VerifiedSubscriptionPriceItem[]>;
|