@fantastic.dev/better-stripe 0.24.0 → 0.25.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.
Files changed (147) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +7 -1
  3. package/dist/client/billing/checkout.d.ts +3 -43
  4. package/dist/client/billing/checkout.d.ts.map +1 -1
  5. package/dist/client/billing/checkout.js +5 -260
  6. package/dist/client/billing/checkout.js.map +1 -1
  7. package/dist/client/billing/checkoutRequest.d.ts +129 -0
  8. package/dist/client/billing/checkoutRequest.d.ts.map +1 -0
  9. package/dist/client/billing/checkoutRequest.js +263 -0
  10. package/dist/client/billing/checkoutRequest.js.map +1 -0
  11. package/dist/client/billing/preparedCheckout.d.ts +22 -0
  12. package/dist/client/billing/preparedCheckout.d.ts.map +1 -0
  13. package/dist/client/billing/preparedCheckout.js +86 -0
  14. package/dist/client/billing/preparedCheckout.js.map +1 -0
  15. package/dist/client/checkoutRequests.d.ts +80 -0
  16. package/dist/client/checkoutRequests.d.ts.map +1 -0
  17. package/dist/client/checkoutRequests.js +28 -0
  18. package/dist/client/checkoutRequests.js.map +1 -0
  19. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +464 -0
  20. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  21. package/dist/client/connect/payoutCollection.d.ts +21 -0
  22. package/dist/client/connect/payoutCollection.d.ts.map +1 -0
  23. package/dist/client/connect/payoutCollection.js +47 -0
  24. package/dist/client/connect/payoutCollection.js.map +1 -0
  25. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +1805 -0
  26. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -0
  27. package/dist/client/connect/payoutExecutionTestHelpers.js +194 -0
  28. package/dist/client/connect/payoutExecutionTestHelpers.js.map +1 -0
  29. package/dist/client/connect/payoutSyncTestHelpers.d.ts +232 -0
  30. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  31. package/dist/client/connect/payoutWorker.d.ts +48 -0
  32. package/dist/client/connect/payoutWorker.d.ts.map +1 -0
  33. package/dist/client/connect/payoutWorker.js +78 -0
  34. package/dist/client/connect/payoutWorker.js.map +1 -0
  35. package/dist/client/index.d.ts +4 -11
  36. package/dist/client/index.d.ts.map +1 -1
  37. package/dist/client/index.js +4 -9
  38. package/dist/client/index.js.map +1 -1
  39. package/dist/client/payoutPolicy.d.ts +67 -0
  40. package/dist/client/payoutPolicy.d.ts.map +1 -1
  41. package/dist/client/payoutPolicy.js +10 -0
  42. package/dist/client/payoutPolicy.js.map +1 -1
  43. package/dist/client/readContracts.d.ts +11 -1
  44. package/dist/client/readContracts.d.ts.map +1 -1
  45. package/dist/client/readContracts.js +10 -0
  46. package/dist/client/readContracts.js.map +1 -1
  47. package/dist/component/_generated/component.d.ts +293 -0
  48. package/dist/component/_generated/component.d.ts.map +1 -1
  49. package/dist/component/core/mutations.d.ts.map +1 -1
  50. package/dist/component/core/mutations.js +2 -0
  51. package/dist/component/core/mutations.js.map +1 -1
  52. package/dist/component/core/resetSafety.d.ts +4 -0
  53. package/dist/component/core/resetSafety.d.ts.map +1 -0
  54. package/dist/component/core/resetSafety.js +54 -0
  55. package/dist/component/core/resetSafety.js.map +1 -0
  56. package/dist/component/earnings/triggers.d.ts +418 -0
  57. package/dist/component/earnings/triggers.d.ts.map +1 -1
  58. package/dist/component/earnings/triggers.js +2 -0
  59. package/dist/component/earnings/triggers.js.map +1 -1
  60. package/dist/component/payoutPolicy/schema.d.ts +2 -0
  61. package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
  62. package/dist/component/payoutPolicy/schema.js +3 -1
  63. package/dist/component/payoutPolicy/schema.js.map +1 -1
  64. package/dist/component/payoutRelease/mutations.js +1 -1
  65. package/dist/component/payoutRelease/schema.d.ts +1 -0
  66. package/dist/component/payoutRelease/schema.d.ts.map +1 -1
  67. package/dist/component/payoutRelease/schema.js +1 -0
  68. package/dist/component/payoutRelease/schema.js.map +1 -1
  69. package/dist/component/payoutSnapshots/localState.d.ts +89 -0
  70. package/dist/component/payoutSnapshots/localState.d.ts.map +1 -0
  71. package/dist/component/payoutSnapshots/localState.js +186 -0
  72. package/dist/component/payoutSnapshots/localState.js.map +1 -0
  73. package/dist/component/payoutSnapshots/mutations.d.ts +108 -0
  74. package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -0
  75. package/dist/component/payoutSnapshots/mutations.js +263 -0
  76. package/dist/component/payoutSnapshots/mutations.js.map +1 -0
  77. package/dist/component/payoutSnapshots/revisions.d.ts +12 -0
  78. package/dist/component/payoutSnapshots/revisions.d.ts.map +1 -0
  79. package/dist/component/payoutSnapshots/revisions.js +173 -0
  80. package/dist/component/payoutSnapshots/revisions.js.map +1 -0
  81. package/dist/component/payoutSnapshots/schema.d.ts +285 -0
  82. package/dist/component/payoutSnapshots/schema.d.ts.map +1 -0
  83. package/dist/component/payoutSnapshots/schema.js +108 -0
  84. package/dist/component/payoutSnapshots/schema.js.map +1 -0
  85. package/dist/component/payoutSnapshots/scope.d.ts +7 -0
  86. package/dist/component/payoutSnapshots/scope.d.ts.map +1 -0
  87. package/dist/component/payoutSnapshots/scope.js +8 -0
  88. package/dist/component/payoutSnapshots/scope.js.map +1 -0
  89. package/dist/component/payoutWorker/helpers.d.ts +30 -0
  90. package/dist/component/payoutWorker/helpers.d.ts.map +1 -0
  91. package/dist/component/payoutWorker/helpers.js +21 -0
  92. package/dist/component/payoutWorker/helpers.js.map +1 -0
  93. package/dist/component/payoutWorker/mutations.d.ts +68 -0
  94. package/dist/component/payoutWorker/mutations.d.ts.map +1 -0
  95. package/dist/component/payoutWorker/mutations.js +161 -0
  96. package/dist/component/payoutWorker/mutations.js.map +1 -0
  97. package/dist/component/payoutWorker/queries.d.ts +123 -0
  98. package/dist/component/payoutWorker/queries.d.ts.map +1 -0
  99. package/dist/component/payoutWorker/queries.js +61 -0
  100. package/dist/component/payoutWorker/queries.js.map +1 -0
  101. package/dist/component/payoutWorker/schema.d.ts +91 -0
  102. package/dist/component/payoutWorker/schema.d.ts.map +1 -0
  103. package/dist/component/payoutWorker/schema.js +27 -0
  104. package/dist/component/payoutWorker/schema.js.map +1 -0
  105. package/dist/component/schema.d.ts +232 -0
  106. package/dist/component/schema.js +10 -0
  107. package/dist/component/schema.js.map +1 -1
  108. package/docs/read-contracts.md +48 -0
  109. package/docs/settlement.md +128 -1
  110. package/package.json +1 -1
  111. package/src/client/billing/checkout.ts +11 -359
  112. package/src/client/billing/checkoutRequest.ts +362 -0
  113. package/src/client/billing/prepared-checkout.test.ts +430 -0
  114. package/src/client/billing/preparedCheckout.ts +143 -0
  115. package/src/client/checkoutRequests.ts +40 -0
  116. package/src/client/connect/payoutCollection.test.ts +74 -0
  117. package/src/client/connect/payoutCollection.ts +82 -0
  118. package/src/client/connect/payoutExecution.test.ts +1 -211
  119. package/src/client/connect/payoutExecutionTestHelpers.ts +213 -0
  120. package/src/client/connect/payoutWorker.test.ts +145 -0
  121. package/src/client/connect/payoutWorker.ts +144 -0
  122. package/src/client/index.ts +10 -21
  123. package/src/client/payoutPolicy.ts +26 -1
  124. package/src/client/readContracts.ts +23 -0
  125. package/src/component/_generated/api.ts +16 -0
  126. package/src/component/_generated/component.ts +361 -0
  127. package/src/component/core/mutations.ts +2 -0
  128. package/src/component/core/resetSafety.ts +67 -0
  129. package/src/component/earnings/triggers.ts +2 -0
  130. package/src/component/payout-reset-safety.test.ts +148 -0
  131. package/src/component/payout-revisions.test.ts +125 -0
  132. package/src/component/payout-snapshots.test.ts +395 -0
  133. package/src/component/payout-worker.test.ts +165 -0
  134. package/src/component/payoutPolicy/schema.ts +3 -1
  135. package/src/component/payoutRelease/mutations.ts +1 -1
  136. package/src/component/payoutRelease/schema.ts +1 -0
  137. package/src/component/payoutSnapshots/localState.ts +238 -0
  138. package/src/component/payoutSnapshots/mutations.ts +275 -0
  139. package/src/component/payoutSnapshots/revisions.ts +247 -0
  140. package/src/component/payoutSnapshots/schema.ts +125 -0
  141. package/src/component/payoutSnapshots/scope.ts +7 -0
  142. package/src/component/payoutWorker/helpers.ts +30 -0
  143. package/src/component/payoutWorker/mutations.ts +181 -0
  144. package/src/component/payoutWorker/queries.ts +64 -0
  145. package/src/component/payoutWorker/schema.ts +26 -0
  146. package/src/component/public.test.ts +2 -2
  147. package/src/component/schema.ts +18 -0
package/CHANGELOG.md CHANGED
@@ -26,6 +26,13 @@
26
26
  - Remove internal tracker references from public documentation and add a
27
27
  regression check that prevents their reintroduction.
28
28
 
29
+ ## [0.25.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.24.0...v0.25.0) (2026-10-15)
30
+
31
+ ### Features
32
+
33
+ - **checkout:** expose immutable prepared request execution ([#199](https://github.com/FantasticDevHQ/better-stripe/issues/199)) ([a73454b](https://github.com/FantasticDevHQ/better-stripe/commit/a73454b3027613c5920be79e152610448c9ac70c))
34
+ - **payouts:** collect ledger pages and schedule durable payout attempts ([#198](https://github.com/FantasticDevHQ/better-stripe/issues/198)) ([0ed1b2f](https://github.com/FantasticDevHQ/better-stripe/commit/0ed1b2f23ab34301d226fa65fe0c63e093f4f9e1))
35
+
29
36
  ## [0.24.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.23.2...v0.24.0) (2026-10-15)
30
37
 
31
38
  ### Features
package/README.md CHANGED
@@ -48,14 +48,20 @@ provider outcome, and books its net payout fees once.
48
48
  The [combined release API](docs/settlement.md#combined-recipient-release) verifies
49
49
  complete source and payout history, reserves mature unpaid funds, and creates an
50
50
  idempotent bank payout. Install a host job to invoke it and expire due policies.
51
+ The [automatic worker](docs/settlement.md#automatic-recipient-worker) provides
52
+ durable attempt IDs, retry leases, recovery discovery and the next attempt time.
53
+ The example installs its five-minute cron in `example/convex/crons.ts`.
51
54
  [Historical imports and explicit funded activation](docs/settlement.md#historical-import-and-funded-activation)
52
55
  verify old payouts, source ownership and holding age before enabling a custom
53
56
  schedule. Larger histories and unallocated money still require reconciliation;
54
57
  schedule controls alone do not enforce a minimum.
58
+ [Resumable local collections and reset safeguards](docs/settlement.md#resumable-local-collections)
59
+ provide bounded ledger inspection while provider-history continuation and scalable
60
+ claim execution are completed.
55
61
 
56
62
  ## Status
57
63
 
58
- **Version**: `0.24.0` <!-- x-release-please-version --> (pre-1.0). API may change between minor versions until 1.0.
64
+ **Version**: `0.25.0` <!-- x-release-please-version --> (pre-1.0). API may change between minor versions until 1.0.
59
65
 
60
66
  Used in production by its authors. Webhook pipeline is covered by unit tests and a live E2E harness (`npm run e2e:webhooks`) that fires real Stripe-signed events and asserts the ledger.
61
67
 
@@ -1,48 +1,8 @@
1
+ import { renderCheckoutSession } from "./checkoutRequest.js";
1
2
  import type Stripe from "stripe";
2
- import type { SplitRecipient } from "../../component/lib/fees.js";
3
3
  import type { Component, RunCtx } from "../helpers.js";
4
- import type { PlatformFeeConfig, StripeComponentCheckoutSession } from "../types.js";
5
- export declare function createCheckoutSession(stripe: Stripe, component: Component, ctx: RunCtx, opts: {
6
- idempotencyKey?: string;
7
- userId: string;
8
- orgId?: string;
9
- stripePriceId: string;
10
- mode: "payment" | "subscription" | "setup";
11
- uiMode?: "embedded" | "redirect" | "custom" | "form";
12
- quantity?: number;
13
- returnUrl: string;
14
- trialDays?: number;
15
- accountId?: string;
16
- customerEmail?: string;
17
- /**
18
- * The seller/recipient connected account funds are routed to (destination
19
- * charge). Fees only apply when this is set.
20
- */
21
- destinationAccountId?: string;
22
- /**
23
- * Multiple recipients for one sale (store + affiliate[s]). With >1 recipient
24
- * this routes via separate charges & transfers (no `application_fee`); the
25
- * transfers are created by the webhook engine. A single-recipient split is
26
- * treated as a destination charge. Takes precedence over `destinationAccountId`.
27
- */
28
- split?: SplitRecipient[];
29
- /** Resolved platform fee config (the caller resolves override → default). */
30
- feeConfig?: PlatformFeeConfig;
31
- /**
32
- * Charge total in minor units (one-time payment mode). When known, the
33
- * fixed `application_fee_amount` is computed up front; otherwise the fee is
34
- * deferred to the webhook.
35
- */
36
- amount?: number;
37
- /**
38
- * Platform-default statement-descriptor suffix (BTS-32), used when the
39
- * destination account record carries no per-store suffix. The caller
40
- * (BetterStripe) passes its validated configured default.
41
- */
42
- defaultStatementDescriptorSuffix?: string;
43
- metadata?: Record<string, string>;
44
- sessionOverrides?: Record<string, unknown>;
45
- }): Promise<{
4
+ import type { StripeComponentCheckoutSession } from "../types.js";
5
+ export declare function createCheckoutSession(stripe: Stripe, component: Component, ctx: RunCtx, opts: Parameters<typeof renderCheckoutSession>[3]): Promise<{
46
6
  stripeSessionId: string;
47
7
  clientSecret: string | undefined;
48
8
  url: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../../src/client/billing/checkout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAGlE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,KAAK,EACV,iBAAiB,EACjB,8BAA8B,EAC/B,MAAM,aAAa,CAAC;AAgGrB,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IACJ,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,SAAS,GAAG,cAAc,GAAG,OAAO,CAAC;IAC3C,MAAM,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;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AAO,CAAC,8BAA8B,GAAG,IAAI,CAAC,CAKhD;AAED,wBAAsB,0BAA0B,CAC9C,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACxC,OAAO,CAAC,8BAA8B,EAAE,CAAC,CAK3C;AAED,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IACJ,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,SAAS,GAAG,cAAc,GAAG,OAAO,CAAC;IAC3C,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,iBAQF;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,qDAMF"}
@@ -1,265 +1,10 @@
1
- import { idempotencyOptions } from "../core/idempotency.js";
2
- import { computeFee, isPercentOnlyFee, validateSplit } from "../core/fees.js";
3
- import { throwStripeError } from "../errors.js";
4
- import { runMutationOrThrow, stripReservedMetadata } from "../helpers.js";
1
+ import { renderCheckoutSession } from "./checkoutRequest.js";
2
+ import { submitPreparedCheckout } from "./preparedCheckout.js";
3
+ import { runMutationOrThrow } from "../helpers.js";
5
4
  import { componentRef } from "../webhooks/helpers.js";
6
- /**
7
- * Derive the persisted fee/routing fields (BTS-11) from the FINAL Checkout
8
- * Session request, reading the nested `subscription_data`/`payment_intent_data`
9
- * that will actually be sent to Stripe. Deriving from the final request (rather
10
- * than a pre-override draft) keeps the stored row consistent when callers pass
11
- * `sessionOverrides` that replace those nested params.
12
- */
13
- function deriveFeeRow(params) {
14
- const dest = (d) => typeof d === "string"
15
- ? d
16
- : (d?.id ?? undefined);
17
- if (params.mode === "subscription") {
18
- const destination = dest(params.subscription_data?.transfer_data?.destination);
19
- if (!destination)
20
- return {};
21
- const pct = params.subscription_data?.application_fee_percent;
22
- return {
23
- chargeType: "destination",
24
- destinationAccountId: destination,
25
- ...(pct !== undefined ? { applicationFeePercent: pct } : {}),
26
- };
27
- }
28
- if (params.mode === "payment") {
29
- const destination = dest(params.payment_intent_data?.transfer_data?.destination);
30
- if (!destination)
31
- return {};
32
- const amt = params.payment_intent_data?.application_fee_amount;
33
- return {
34
- chargeType: "destination",
35
- destinationAccountId: destination,
36
- ...(amt !== undefined ? { applicationFeeAmount: amt } : {}),
37
- };
38
- }
39
- return {};
40
- }
41
- /**
42
- * Destination and separate charges use platform prices. Catalog accountId is a
43
- * store attribution tag, not Stripe ownership (createProduct uses the platform).
44
- * For tagged products, verify the price in the platform Stripe context before
45
- * rejecting it. Untagged/unknown catalog entries are validated by Checkout.
46
- */
47
- async function assertPlatformPrice(stripe, component, ctx, stripePriceId) {
48
- const price = (await ctx.runQuery(componentRef(component, "products/queries/getPriceByStripeId"), { stripePriceId }));
49
- if (!price?.stripeProductId)
50
- return;
51
- const product = (await ctx.runQuery(componentRef(component, "products/queries/getProductByStripeId"), { stripeProductId: price.stripeProductId }));
52
- if (product?.accountId) {
53
- try {
54
- await stripe.prices.retrieve(stripePriceId);
55
- }
56
- catch (error) {
57
- // Only absence on the platform means the ownership check failed.
58
- // Auth/network/rate-limit failures must not be misreported as ownership.
59
- if (!error ||
60
- typeof error !== "object" ||
61
- !("code" in error) ||
62
- error.code !== "resource_missing")
63
- throw error;
64
- throwStripeError("INVALID_CONFIGURATION", `Price ${stripePriceId} is unavailable on the platform account; destination charges require a platform-owned price.`);
65
- }
66
- }
67
- }
68
- // =============================================================================
69
- // Checkout methods
70
- // =============================================================================
71
5
  export async function createCheckoutSession(stripe, component, ctx, opts) {
72
- const uiMode = opts.uiMode ?? "embedded";
73
- // Setup-mode sessions create no charge, so routing/fees are meaningless and
74
- // would persist an unfunded `chargeType` the webhook engine can't act on.
75
- if (opts.mode === "setup" &&
76
- (opts.split?.length || opts.destinationAccountId || opts.feeConfig)) {
77
- throwStripeError("INVALID_CONFIGURATION", "split/destinationAccountId/fee are not supported for setup-mode Checkout Sessions");
78
- }
79
- // Resolve the routing model. A `split` with >1 recipient uses separate charges
80
- // & transfers (no application_fee; webhook engine creates the transfers); a
81
- // single-recipient split is just a destination charge. `split` wins over
82
- // `destinationAccountId`.
83
- let isSeparate = false;
84
- let destinationAccountId = opts.destinationAccountId;
85
- if (opts.split && opts.split.length > 0) {
86
- validateSplit(opts.split);
87
- if (opts.split.length === 1) {
88
- destinationAccountId = opts.split[0].destinationAccountId;
89
- }
90
- else {
91
- isSeparate = true;
92
- }
93
- }
94
- // Metadata markers the webhook split engine reads to create the transfers.
95
- // For subscriptions these live on the subscription and are consumed on each
96
- // invoice.paid; for one-time payments they live on the PaymentIntent.
97
- const separateMeta = isSeparate
98
- ? {
99
- bsChargeType: "separate",
100
- bsSplit: JSON.stringify(opts.split),
101
- ...(opts.feeConfig
102
- ? { bsFeeConfig: JSON.stringify(opts.feeConfig) }
103
- : {}),
104
- }
105
- : {};
106
- // Strip the reserved `bs*` namespace from caller metadata so it can't forge
107
- // webhook instructions (e.g. trigger split transfers without routing).
108
- const metadata = {
109
- ...stripReservedMetadata(opts.metadata),
110
- userId: opts.userId,
111
- ...(opts.orgId ? { orgId: opts.orgId } : {}),
112
- };
113
- // Per-store statement descriptor (BTS-32). Destination charges are platform
114
- // charges (platform = merchant of record), so buyer recognition is
115
- // suffix-based: the store's stored suffix, else the configured platform
116
- // default. Resolved from the component account record at session creation.
117
- let statementDescriptorSuffix;
118
- if (destinationAccountId && !isSeparate && opts.mode !== "setup") {
119
- const account = (await ctx.runQuery(componentRef(component, "core/queries/getAccountByStripeId"), { stripeAccountId: destinationAccountId }));
120
- statementDescriptorSuffix =
121
- account?.statementDescriptor ?? opts.defaultStatementDescriptorSuffix;
122
- }
123
- const sessionParams = {
124
- mode: opts.mode,
125
- line_items: [{ price: opts.stripePriceId, quantity: opts.quantity ?? 1 }],
126
- metadata,
127
- };
128
- if (opts.mode === "subscription") {
129
- const subscriptionData = {
130
- metadata,
131
- };
132
- if (opts.trialDays) {
133
- subscriptionData.trial_period_days = opts.trialDays;
134
- }
135
- if (isSeparate) {
136
- // Separate charges & transfers: NO transfer_data / application_fee. The
137
- // split is carried in metadata for the webhook engine to execute.
138
- subscriptionData.metadata = { ...metadata, ...separateMeta };
139
- }
140
- else if (destinationAccountId) {
141
- // Single-recipient destination charge: route funds to the seller and take
142
- // the platform's cut. Percent-only fees map to `application_fee_percent`;
143
- // percent+fixed/tiered fees can't be expressed that way, so flag the
144
- // subscription for per-invoice fee computation (handled by WEBHOOK_FEE).
145
- subscriptionData.transfer_data = { destination: destinationAccountId };
146
- if (opts.feeConfig) {
147
- if (isPercentOnlyFee(opts.feeConfig)) {
148
- subscriptionData.application_fee_percent = opts.feeConfig.percent;
149
- }
150
- else {
151
- subscriptionData.metadata = {
152
- ...metadata,
153
- bsFeeMode: "per_invoice",
154
- bsFeeConfig: JSON.stringify(opts.feeConfig),
155
- };
156
- }
157
- }
158
- if (statementDescriptorSuffix) {
159
- // Subscriptions can't carry a suffix directly; the invoice.created
160
- // processor reads this marker and sets it on each invoice.
161
- subscriptionData.metadata = {
162
- ...(subscriptionData.metadata ?? metadata),
163
- bsStatementDescriptor: statementDescriptorSuffix,
164
- };
165
- }
166
- }
167
- sessionParams.subscription_data = subscriptionData;
168
- }
169
- if (opts.mode === "payment") {
170
- const paymentIntentData = { metadata };
171
- if (isSeparate) {
172
- paymentIntentData.metadata = { ...metadata, ...separateMeta };
173
- }
174
- else if (destinationAccountId) {
175
- // Single-recipient destination charge for a one-time purchase. The platform
176
- // fee is a fixed `application_fee_amount`: compute it when the amount is
177
- // known; otherwise flag the PI with `bsFeeMode=per_charge` and the webhook
178
- // collects it at payment_intent.succeeded via a partial reversal of the
179
- // destination transfer, sized from the amount actually charged (BTS-60).
180
- paymentIntentData.transfer_data = {
181
- destination: destinationAccountId,
182
- };
183
- if (statementDescriptorSuffix) {
184
- paymentIntentData.statement_descriptor_suffix =
185
- statementDescriptorSuffix;
186
- }
187
- if (opts.feeConfig) {
188
- if (opts.amount !== undefined) {
189
- paymentIntentData.application_fee_amount = computeFee(opts.amount, opts.feeConfig).feeAmount;
190
- }
191
- else {
192
- paymentIntentData.metadata = {
193
- ...metadata,
194
- bsFeeMode: "per_charge",
195
- bsFeeConfig: JSON.stringify(opts.feeConfig),
196
- };
197
- }
198
- }
199
- }
200
- sessionParams.payment_intent_data = paymentIntentData;
201
- }
202
- if (uiMode === "embedded" || uiMode === "custom" || uiMode === "form") {
203
- sessionParams.ui_mode =
204
- uiMode === "custom"
205
- ? "elements"
206
- : uiMode === "form"
207
- ? "form"
208
- : "embedded_page";
209
- sessionParams.return_url = opts.returnUrl;
210
- }
211
- else {
212
- sessionParams.success_url = `${opts.returnUrl}?session_id={CHECKOUT_SESSION_ID}`;
213
- sessionParams.cancel_url = opts.returnUrl;
214
- }
215
- if (opts.accountId) {
216
- sessionParams.customer_account = opts.accountId;
217
- }
218
- else if (opts.customerEmail) {
219
- sessionParams.customer_email = opts.customerEmail;
220
- }
221
- // Merge overrides, then derive the persisted fee/routing row from the FINAL
222
- // request — sessionOverrides can replace subscription_data/payment_intent_data
223
- // wholesale, so the row must reflect what was actually sent to Stripe.
224
- const finalSessionParams = {
225
- ...sessionParams,
226
- ...opts.sessionOverrides,
227
- };
228
- // Separate-charge sales persist the split + chargeType directly; single-recipient
229
- // destination charges derive the row from the final transfer_data/fee.
230
- const feeRow = isSeparate
231
- ? { chargeType: "separate", splitRecipients: opts.split }
232
- : deriveFeeRow(finalSessionParams);
233
- // Both destination and separate charges run on the platform account, so the
234
- // price must be platform-owned. Validate the FINAL request (post-overrides) so
235
- // callers can't inject transfer_data or swap line_items to bypass the check.
236
- const finalPriceId = finalSessionParams.line_items?.[0]?.price;
237
- if ((isSeparate || feeRow.chargeType === "destination") &&
238
- typeof finalPriceId === "string") {
239
- await assertPlatformPrice(stripe, component, ctx, finalPriceId);
240
- }
241
- const requestOptions = idempotencyOptions(opts.idempotencyKey);
242
- const session = requestOptions
243
- ? await stripe.checkout.sessions.create(finalSessionParams, requestOptions)
244
- : await stripe.checkout.sessions.create(finalSessionParams);
245
- await runMutationOrThrow(ctx, componentRef(component, "billing/mutations/upsertCheckoutSession"), {
246
- stripeSessionId: session.id,
247
- userId: opts.userId,
248
- orgId: opts.orgId,
249
- accountId: opts.accountId,
250
- mode: finalSessionParams.mode,
251
- status: (session.status ?? "open"),
252
- clientSecret: session.client_secret ?? undefined,
253
- url: session.url ?? undefined,
254
- priceId: opts.stripePriceId,
255
- ...feeRow,
256
- metadata,
257
- });
258
- return {
259
- stripeSessionId: session.id,
260
- clientSecret: session.client_secret ?? undefined,
261
- url: session.url ?? undefined,
262
- };
6
+ const prepared = await renderCheckoutSession(stripe, component, ctx, opts);
7
+ return submitPreparedCheckout(stripe, component, ctx, prepared, opts.idempotencyKey);
263
8
  }
264
9
  export async function getCheckoutSession(component, ctx, opts) {
265
10
  return (await ctx.runQuery(componentRef(component, "billing/queries/getCheckoutSession"), opts));
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../../src/client/billing/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,MA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SAAS,EAAE,8CAA8C,CAAC,EACvE,IAAI,CACL,CAA0C,CAAC;AAC9C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,SAAoB,EACpB,GAAW,EACX,IAAyC;IAEzC,OAAO,CAAC,MAAM,GAAG,CAAC,QAAQ,CACxB,YAAY,CAAC,SAAS,EAAE,4CAA4C,CAAC,EACrE,IAAI,CACL,CAAqC,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,SAAoB,EACpB,GAAW,EACX,IAWC;IAED,MAAM,kBAAkB,CACtB,GAAG,EACH,YAAY,CAAC,SAAS,EAAE,yCAAyC,CAAC,EAClE,IAAI,CACL,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,MAAc,EACd,IAAY,EACZ,IAGC;IAED,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE;QAC1E,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACxB,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,129 @@
1
+ import type Stripe from "stripe";
2
+ import type { SplitRecipient } from "../../component/lib/fees.js";
3
+ import type { Component, RunCtx } from "../helpers.js";
4
+ import type { PlatformFeeConfig } from "../types.js";
5
+ export declare function renderCheckoutSession(stripe: Stripe, component: Component, ctx: RunCtx, opts: {
6
+ idempotencyKey?: string;
7
+ userId: string;
8
+ orgId?: string;
9
+ stripePriceId: string;
10
+ mode: "payment" | "subscription" | "setup";
11
+ uiMode?: "embedded" | "redirect" | "custom" | "form";
12
+ quantity?: number;
13
+ returnUrl: string;
14
+ trialDays?: number;
15
+ accountId?: string;
16
+ customerEmail?: string;
17
+ /**
18
+ * The seller/recipient connected account funds are routed to (destination
19
+ * charge). Fees only apply when this is set.
20
+ */
21
+ destinationAccountId?: string;
22
+ /**
23
+ * Multiple recipients for one sale (store + affiliate[s]). With >1 recipient
24
+ * this routes via separate charges & transfers (no `application_fee`); the
25
+ * transfers are created by the webhook engine. A single-recipient split is
26
+ * treated as a destination charge. Takes precedence over `destinationAccountId`.
27
+ */
28
+ split?: SplitRecipient[];
29
+ /** Resolved platform fee config (the caller resolves override → default). */
30
+ feeConfig?: PlatformFeeConfig;
31
+ /**
32
+ * Charge total in minor units (one-time payment mode). When known, the
33
+ * fixed `application_fee_amount` is computed up front; otherwise the fee is
34
+ * deferred to the webhook.
35
+ */
36
+ amount?: number;
37
+ /**
38
+ * Platform-default statement-descriptor suffix (BTS-32), used when the
39
+ * destination account record carries no per-store suffix. The caller
40
+ * (BetterStripe) passes its validated configured default.
41
+ */
42
+ defaultStatementDescriptorSuffix?: string;
43
+ metadata?: Record<string, string>;
44
+ sessionOverrides?: Record<string, unknown>;
45
+ }, capturedDescriptor?: {
46
+ value?: string;
47
+ }): Promise<{
48
+ version: 1;
49
+ request: Stripe.Checkout.SessionCreateParams;
50
+ options: {
51
+ idempotencyKey?: string;
52
+ userId: string;
53
+ orgId?: string;
54
+ stripePriceId: string;
55
+ mode: "payment" | "subscription" | "setup";
56
+ uiMode?: "embedded" | "redirect" | "custom" | "form";
57
+ quantity?: number;
58
+ returnUrl: string;
59
+ trialDays?: number;
60
+ accountId?: string;
61
+ customerEmail?: string;
62
+ /**
63
+ * The seller/recipient connected account funds are routed to (destination
64
+ * charge). Fees only apply when this is set.
65
+ */
66
+ destinationAccountId?: string;
67
+ /**
68
+ * Multiple recipients for one sale (store + affiliate[s]). With >1 recipient
69
+ * this routes via separate charges & transfers (no `application_fee`); the
70
+ * transfers are created by the webhook engine. A single-recipient split is
71
+ * treated as a destination charge. Takes precedence over `destinationAccountId`.
72
+ */
73
+ split?: SplitRecipient[];
74
+ /** Resolved platform fee config (the caller resolves override → default). */
75
+ feeConfig?: PlatformFeeConfig;
76
+ /**
77
+ * Charge total in minor units (one-time payment mode). When known, the
78
+ * fixed `application_fee_amount` is computed up front; otherwise the fee is
79
+ * deferred to the webhook.
80
+ */
81
+ amount?: number;
82
+ /**
83
+ * Platform-default statement-descriptor suffix (BTS-32), used when the
84
+ * destination account record carries no per-store suffix. The caller
85
+ * (BetterStripe) passes its validated configured default.
86
+ */
87
+ defaultStatementDescriptorSuffix?: string;
88
+ metadata?: Record<string, string>;
89
+ sessionOverrides?: Record<string, unknown>;
90
+ };
91
+ descriptor: {
92
+ value: string | undefined;
93
+ };
94
+ routingMetadata: {
95
+ subscription: Stripe.MetadataParam | undefined;
96
+ payment: Stripe.MetadataParam | undefined;
97
+ };
98
+ row: {
99
+ chargeType?: "destination";
100
+ destinationAccountId?: string;
101
+ applicationFeePercent?: number;
102
+ applicationFeeAmount?: number;
103
+ userId: string;
104
+ orgId: string | undefined;
105
+ accountId: string | undefined;
106
+ priceId: string;
107
+ metadata: {
108
+ userId: string;
109
+ orgId?: string | undefined;
110
+ };
111
+ } | {
112
+ chargeType: "separate";
113
+ splitRecipients: {
114
+ amount?: number | undefined;
115
+ destinationAccountId: string;
116
+ percent?: number | undefined;
117
+ role: "affiliate" | "other" | "store";
118
+ }[] | undefined;
119
+ userId: string;
120
+ orgId: string | undefined;
121
+ accountId: string | undefined;
122
+ priceId: string;
123
+ metadata: {
124
+ userId: string;
125
+ orgId?: string | undefined;
126
+ };
127
+ };
128
+ }>;
129
+ //# sourceMappingURL=checkoutRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkoutRequest.d.ts","sourceRoot":"","sources":["../../../src/client/billing/checkoutRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAGlE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA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