@funnelfox/payments-sdk 0.1.2-beta.7 → 0.1.2-beta.9

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,35 @@ 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
+ ...params.walletFirst && { wallet_first: params.walletFirst }
66
+ };
67
+ }
68
+
39
69
  // src/http.ts
40
70
  var HttpService = class {
41
71
  constructor(baseUrl, headers = {}) {
@@ -84,17 +114,10 @@ var StripeCheckoutService = class extends HttpService {
84
114
  }
85
115
  async createCheckoutSession(params) {
86
116
  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
- });
117
+ const data = await this.post(
118
+ `/stripe/purchase${query}`,
119
+ buildStripeCheckoutSessionBody(params)
120
+ );
98
121
  if (!data.client_secret) {
99
122
  throw new CheckoutError("Backend returned no client_secret");
100
123
  }
@@ -265,5 +288,6 @@ async function initCheckout(options) {
265
288
  // Annotate the CommonJS export names for ESM import in node:
266
289
  0 && (module.exports = {
267
290
  CheckoutError,
291
+ buildStripeCheckoutSessionBody,
268
292
  initCheckout
269
293
  });
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,10 +33,14 @@ 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;
42
+ /** When true, surfaces Apple Pay / Google Pay as the primary payment option (Wallet-First mode) */
43
+ walletFirst?: boolean;
34
44
  }
35
45
 
36
46
  interface FastSpringConfig {
@@ -113,4 +123,9 @@ declare class CheckoutError extends Error {
113
123
  constructor(message: string);
114
124
  }
115
125
 
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 };
126
+ type CreateCheckoutSessionParams = Omit<StripeConfig, 'publishableKey' | 'returnUrl'> & {
127
+ returnUrl: string;
128
+ };
129
+ declare function buildStripeCheckoutSessionBody(params: CreateCheckoutSessionParams): Record<string, unknown>;
130
+
131
+ 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,10 +33,14 @@ 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;
42
+ /** When true, surfaces Apple Pay / Google Pay as the primary payment option (Wallet-First mode) */
43
+ walletFirst?: boolean;
34
44
  }
35
45
 
36
46
  interface FastSpringConfig {
@@ -113,4 +123,9 @@ declare class CheckoutError extends Error {
113
123
  constructor(message: string);
114
124
  }
115
125
 
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 };
126
+ type CreateCheckoutSessionParams = Omit<StripeConfig, 'publishableKey' | 'returnUrl'> & {
127
+ returnUrl: string;
128
+ };
129
+ declare function buildStripeCheckoutSessionBody(params: CreateCheckoutSessionParams): Record<string, unknown>;
130
+
131
+ 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,35 @@ 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
+ ...params.walletFirst && { wallet_first: params.walletFirst }
38
+ };
39
+ }
40
+
12
41
  // src/http.ts
13
42
  var HttpService = class {
14
43
  constructor(baseUrl, headers = {}) {
@@ -57,17 +86,10 @@ var StripeCheckoutService = class extends HttpService {
57
86
  }
58
87
  async createCheckoutSession(params) {
59
88
  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
- });
89
+ const data = await this.post(
90
+ `/stripe/purchase${query}`,
91
+ buildStripeCheckoutSessionBody(params)
92
+ );
71
93
  if (!data.client_secret) {
72
94
  throw new CheckoutError("Backend returned no client_secret");
73
95
  }
@@ -237,5 +259,6 @@ async function initCheckout(options) {
237
259
  }
238
260
  export {
239
261
  CheckoutError,
262
+ buildStripeCheckoutSessionBody,
240
263
  initCheckout
241
264
  };
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.9",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",