@funnelfox/payments-sdk 0.1.2-beta.6 → 0.1.2-beta.8
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/dist/index.cjs +34 -10
- package/dist/index.d.cts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +33 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CheckoutError: () => CheckoutError,
|
|
24
|
+
buildStripeCheckoutSessionBody: () => buildStripeCheckoutSessionBody,
|
|
24
25
|
initCheckout: () => initCheckout
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -36,6 +37,34 @@ var CheckoutError = class extends Error {
|
|
|
36
37
|
// src/providers/stripe/index.ts
|
|
37
38
|
var import_stripe_js = require("@stripe/stripe-js");
|
|
38
39
|
|
|
40
|
+
// src/providers/stripe/helpers.ts
|
|
41
|
+
function buildStripeCheckoutSessionBody(params) {
|
|
42
|
+
return {
|
|
43
|
+
price_id: params.priceId,
|
|
44
|
+
managed: params.managed,
|
|
45
|
+
customer_id: params.customerId,
|
|
46
|
+
customer: params.customer,
|
|
47
|
+
return_url: params.returnUrl,
|
|
48
|
+
...params.allowPromoCodes && { allow_promotion_codes: params.allowPromoCodes },
|
|
49
|
+
...params.coupon && { coupon: params.coupon },
|
|
50
|
+
...params.customPriceValue !== void 0 && {
|
|
51
|
+
metadata: {
|
|
52
|
+
custom_price_value: params.customPriceValue
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
...params.trial?.periodDays && {
|
|
56
|
+
trial: {
|
|
57
|
+
period_days: params.trial.periodDays,
|
|
58
|
+
...params.trial.priceId ? {
|
|
59
|
+
price_id: params.trial.priceId,
|
|
60
|
+
flow: "modern"
|
|
61
|
+
} : {}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
...params.upgrade && { upgrade: params.upgrade }
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
39
68
|
// src/http.ts
|
|
40
69
|
var HttpService = class {
|
|
41
70
|
constructor(baseUrl, headers = {}) {
|
|
@@ -84,16 +113,10 @@ var StripeCheckoutService = class extends HttpService {
|
|
|
84
113
|
}
|
|
85
114
|
async createCheckoutSession(params) {
|
|
86
115
|
const query = `?account=${encodeURIComponent(params.accountId)}`;
|
|
87
|
-
const data = await this.post(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
customer: params.customer,
|
|
92
|
-
return_url: params.returnUrl,
|
|
93
|
-
...params.allowPromoCodes && { allow_promotion_codes: params.allowPromoCodes },
|
|
94
|
-
...params.coupon && { coupon: params.coupon },
|
|
95
|
-
...params.trialPeriodDays && { trial: { period_days: params.trialPeriodDays } }
|
|
96
|
-
});
|
|
116
|
+
const data = await this.post(
|
|
117
|
+
`/stripe/purchase${query}`,
|
|
118
|
+
buildStripeCheckoutSessionBody(params)
|
|
119
|
+
);
|
|
97
120
|
if (!data.client_secret) {
|
|
98
121
|
throw new CheckoutError("Backend returned no client_secret");
|
|
99
122
|
}
|
|
@@ -264,5 +287,6 @@ async function initCheckout(options) {
|
|
|
264
287
|
// Annotate the CommonJS export names for ESM import in node:
|
|
265
288
|
0 && (module.exports = {
|
|
266
289
|
CheckoutError,
|
|
290
|
+
buildStripeCheckoutSessionBody,
|
|
267
291
|
initCheckout
|
|
268
292
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,12 @@ interface StripeCustomer {
|
|
|
8
8
|
postal_code?: string;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
interface StripeCheckoutTrial {
|
|
12
|
+
/** Subscription free/paid trial length in days. */
|
|
13
|
+
periodDays: number;
|
|
14
|
+
/** Optional one-time price for a paid trial. When omitted, the trial period is free of charge. */
|
|
15
|
+
priceId?: string;
|
|
16
|
+
}
|
|
11
17
|
interface StripeConfig {
|
|
12
18
|
/** Stripe publishable key (pk_test_... or pk_live_...) */
|
|
13
19
|
publishableKey: string;
|
|
@@ -27,8 +33,12 @@ interface StripeConfig {
|
|
|
27
33
|
allowPromoCodes?: boolean;
|
|
28
34
|
/** Pre-apply a specific coupon/discount code to the checkout session */
|
|
29
35
|
coupon?: string;
|
|
30
|
-
/**
|
|
31
|
-
|
|
36
|
+
/** Optional declared amount for variable or custom pricing, retained for reporting and reconciliation. */
|
|
37
|
+
customPriceValue?: number | null;
|
|
38
|
+
/** Optional trial configuration for the subscription, including duration and paid-trial pricing when applicable. */
|
|
39
|
+
trial?: StripeCheckoutTrial;
|
|
40
|
+
/** When true, treats this as a subscription upgrade — requires customerId to be set */
|
|
41
|
+
upgrade?: boolean;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
interface FastSpringConfig {
|
|
@@ -111,4 +121,9 @@ declare class CheckoutError extends Error {
|
|
|
111
121
|
constructor(message: string);
|
|
112
122
|
}
|
|
113
123
|
|
|
114
|
-
|
|
124
|
+
type CreateCheckoutSessionParams = Pick<StripeConfig, 'priceId' | 'managed' | 'accountId' | 'customerId' | 'customer' | 'allowPromoCodes' | 'coupon' | 'customPriceValue' | 'trial' | 'upgrade'> & {
|
|
125
|
+
returnUrl: string;
|
|
126
|
+
};
|
|
127
|
+
declare function buildStripeCheckoutSessionBody(params: CreateCheckoutSessionParams): Record<string, unknown>;
|
|
128
|
+
|
|
129
|
+
export { type CheckoutCallbacks, type CheckoutCancelEvent, type CheckoutCompleteEvent, CheckoutError, type CheckoutErrorEvent, type CheckoutInstance, type CreateCheckoutSessionParams, type FastSpringConfig, type PaymentMethodType, type PaymentProvider, type ProviderConfigMap, type ProviderName, type RenderOptions, type StripeCheckoutTrial, type StripeConfig, buildStripeCheckoutSessionBody, initCheckout };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ interface StripeCustomer {
|
|
|
8
8
|
postal_code?: string;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
interface StripeCheckoutTrial {
|
|
12
|
+
/** Subscription free/paid trial length in days. */
|
|
13
|
+
periodDays: number;
|
|
14
|
+
/** Optional one-time price for a paid trial. When omitted, the trial period is free of charge. */
|
|
15
|
+
priceId?: string;
|
|
16
|
+
}
|
|
11
17
|
interface StripeConfig {
|
|
12
18
|
/** Stripe publishable key (pk_test_... or pk_live_...) */
|
|
13
19
|
publishableKey: string;
|
|
@@ -27,8 +33,12 @@ interface StripeConfig {
|
|
|
27
33
|
allowPromoCodes?: boolean;
|
|
28
34
|
/** Pre-apply a specific coupon/discount code to the checkout session */
|
|
29
35
|
coupon?: string;
|
|
30
|
-
/**
|
|
31
|
-
|
|
36
|
+
/** Optional declared amount for variable or custom pricing, retained for reporting and reconciliation. */
|
|
37
|
+
customPriceValue?: number | null;
|
|
38
|
+
/** Optional trial configuration for the subscription, including duration and paid-trial pricing when applicable. */
|
|
39
|
+
trial?: StripeCheckoutTrial;
|
|
40
|
+
/** When true, treats this as a subscription upgrade — requires customerId to be set */
|
|
41
|
+
upgrade?: boolean;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
interface FastSpringConfig {
|
|
@@ -111,4 +121,9 @@ declare class CheckoutError extends Error {
|
|
|
111
121
|
constructor(message: string);
|
|
112
122
|
}
|
|
113
123
|
|
|
114
|
-
|
|
124
|
+
type CreateCheckoutSessionParams = Pick<StripeConfig, 'priceId' | 'managed' | 'accountId' | 'customerId' | 'customer' | 'allowPromoCodes' | 'coupon' | 'customPriceValue' | 'trial' | 'upgrade'> & {
|
|
125
|
+
returnUrl: string;
|
|
126
|
+
};
|
|
127
|
+
declare function buildStripeCheckoutSessionBody(params: CreateCheckoutSessionParams): Record<string, unknown>;
|
|
128
|
+
|
|
129
|
+
export { type CheckoutCallbacks, type CheckoutCancelEvent, type CheckoutCompleteEvent, CheckoutError, type CheckoutErrorEvent, type CheckoutInstance, type CreateCheckoutSessionParams, type FastSpringConfig, type PaymentMethodType, type PaymentProvider, type ProviderConfigMap, type ProviderName, type RenderOptions, type StripeCheckoutTrial, type StripeConfig, buildStripeCheckoutSessionBody, initCheckout };
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,34 @@ var CheckoutError = class extends Error {
|
|
|
9
9
|
// src/providers/stripe/index.ts
|
|
10
10
|
import { loadStripe } from "@stripe/stripe-js";
|
|
11
11
|
|
|
12
|
+
// src/providers/stripe/helpers.ts
|
|
13
|
+
function buildStripeCheckoutSessionBody(params) {
|
|
14
|
+
return {
|
|
15
|
+
price_id: params.priceId,
|
|
16
|
+
managed: params.managed,
|
|
17
|
+
customer_id: params.customerId,
|
|
18
|
+
customer: params.customer,
|
|
19
|
+
return_url: params.returnUrl,
|
|
20
|
+
...params.allowPromoCodes && { allow_promotion_codes: params.allowPromoCodes },
|
|
21
|
+
...params.coupon && { coupon: params.coupon },
|
|
22
|
+
...params.customPriceValue !== void 0 && {
|
|
23
|
+
metadata: {
|
|
24
|
+
custom_price_value: params.customPriceValue
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
...params.trial?.periodDays && {
|
|
28
|
+
trial: {
|
|
29
|
+
period_days: params.trial.periodDays,
|
|
30
|
+
...params.trial.priceId ? {
|
|
31
|
+
price_id: params.trial.priceId,
|
|
32
|
+
flow: "modern"
|
|
33
|
+
} : {}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
...params.upgrade && { upgrade: params.upgrade }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
12
40
|
// src/http.ts
|
|
13
41
|
var HttpService = class {
|
|
14
42
|
constructor(baseUrl, headers = {}) {
|
|
@@ -57,16 +85,10 @@ var StripeCheckoutService = class extends HttpService {
|
|
|
57
85
|
}
|
|
58
86
|
async createCheckoutSession(params) {
|
|
59
87
|
const query = `?account=${encodeURIComponent(params.accountId)}`;
|
|
60
|
-
const data = await this.post(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
customer: params.customer,
|
|
65
|
-
return_url: params.returnUrl,
|
|
66
|
-
...params.allowPromoCodes && { allow_promotion_codes: params.allowPromoCodes },
|
|
67
|
-
...params.coupon && { coupon: params.coupon },
|
|
68
|
-
...params.trialPeriodDays && { trial: { period_days: params.trialPeriodDays } }
|
|
69
|
-
});
|
|
88
|
+
const data = await this.post(
|
|
89
|
+
`/stripe/purchase${query}`,
|
|
90
|
+
buildStripeCheckoutSessionBody(params)
|
|
91
|
+
);
|
|
70
92
|
if (!data.client_secret) {
|
|
71
93
|
throw new CheckoutError("Backend returned no client_secret");
|
|
72
94
|
}
|
|
@@ -236,5 +258,6 @@ async function initCheckout(options) {
|
|
|
236
258
|
}
|
|
237
259
|
export {
|
|
238
260
|
CheckoutError,
|
|
261
|
+
buildStripeCheckoutSessionBody,
|
|
239
262
|
initCheckout
|
|
240
263
|
};
|