@funnelfox/payments-sdk 0.1.2-beta.7 → 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 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,17 +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(`/stripe/purchase${query}`, {
88
- price_id: params.priceId,
89
- managed: params.managed,
90
- customer_id: params.customerId,
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
- ...params.upgrade && { upgrade: params.upgrade }
97
- });
116
+ const data = await this.post(
117
+ `/stripe/purchase${query}`,
118
+ buildStripeCheckoutSessionBody(params)
119
+ );
98
120
  if (!data.client_secret) {
99
121
  throw new CheckoutError("Backend returned no client_secret");
100
122
  }
@@ -265,5 +287,6 @@ async function initCheckout(options) {
265
287
  // Annotate the CommonJS export names for ESM import in node:
266
288
  0 && (module.exports = {
267
289
  CheckoutError,
290
+ buildStripeCheckoutSessionBody,
268
291
  initCheckout
269
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,10 @@ interface StripeConfig {
27
33
  allowPromoCodes?: boolean;
28
34
  /** Pre-apply a specific coupon/discount code to the checkout session */
29
35
  coupon?: string;
30
- /** Free trial period in days before billing starts */
31
- trialPeriodDays?: number;
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;
32
40
  /** When true, treats this as a subscription upgrade — requires customerId to be set */
33
41
  upgrade?: boolean;
34
42
  }
@@ -113,4 +121,9 @@ declare class CheckoutError extends Error {
113
121
  constructor(message: string);
114
122
  }
115
123
 
116
- export { type CheckoutCallbacks, type CheckoutCancelEvent, type CheckoutCompleteEvent, CheckoutError, type CheckoutErrorEvent, type CheckoutInstance, type FastSpringConfig, type PaymentMethodType, type PaymentProvider, type ProviderConfigMap, type ProviderName, type RenderOptions, type StripeConfig, initCheckout };
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,10 @@ interface StripeConfig {
27
33
  allowPromoCodes?: boolean;
28
34
  /** Pre-apply a specific coupon/discount code to the checkout session */
29
35
  coupon?: string;
30
- /** Free trial period in days before billing starts */
31
- trialPeriodDays?: number;
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;
32
40
  /** When true, treats this as a subscription upgrade — requires customerId to be set */
33
41
  upgrade?: boolean;
34
42
  }
@@ -113,4 +121,9 @@ declare class CheckoutError extends Error {
113
121
  constructor(message: string);
114
122
  }
115
123
 
116
- export { type CheckoutCallbacks, type CheckoutCancelEvent, type CheckoutCompleteEvent, CheckoutError, type CheckoutErrorEvent, type CheckoutInstance, type FastSpringConfig, type PaymentMethodType, type PaymentProvider, type ProviderConfigMap, type ProviderName, type RenderOptions, type StripeConfig, initCheckout };
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,17 +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(`/stripe/purchase${query}`, {
61
- price_id: params.priceId,
62
- managed: params.managed,
63
- customer_id: params.customerId,
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
- ...params.upgrade && { upgrade: params.upgrade }
70
- });
88
+ const data = await this.post(
89
+ `/stripe/purchase${query}`,
90
+ buildStripeCheckoutSessionBody(params)
91
+ );
71
92
  if (!data.client_secret) {
72
93
  throw new CheckoutError("Backend returned no client_secret");
73
94
  }
@@ -237,5 +258,6 @@ async function initCheckout(options) {
237
258
  }
238
259
  export {
239
260
  CheckoutError,
261
+ buildStripeCheckoutSessionBody,
240
262
  initCheckout
241
263
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelfox/payments-sdk",
3
- "version": "0.1.2-beta.7",
3
+ "version": "0.1.2-beta.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",