@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
@@ -0,0 +1,263 @@
1
+ import { computeFee, isPercentOnlyFee, validateSplit } from "../core/fees.js";
2
+ import { throwStripeError } from "../errors.js";
3
+ import { stripReservedMetadata } from "../helpers.js";
4
+ import { componentRef } from "../webhooks/helpers.js";
5
+ /**
6
+ * Derive the persisted fee/routing fields (BTS-11) from the FINAL Checkout
7
+ * Session request, reading the nested `subscription_data`/`payment_intent_data`
8
+ * that will actually be sent to Stripe. Deriving from the final request (rather
9
+ * than a pre-override draft) keeps the stored row consistent when callers pass
10
+ * `sessionOverrides` that replace those nested params.
11
+ */
12
+ function deriveFeeRow(params) {
13
+ const dest = (d) => typeof d === "string"
14
+ ? d
15
+ : (d?.id ?? undefined);
16
+ if (params.mode === "subscription") {
17
+ const destination = dest(params.subscription_data?.transfer_data?.destination);
18
+ if (!destination)
19
+ return {};
20
+ const pct = params.subscription_data?.application_fee_percent;
21
+ return {
22
+ chargeType: "destination",
23
+ destinationAccountId: destination,
24
+ ...(pct !== undefined ? { applicationFeePercent: pct } : {}),
25
+ };
26
+ }
27
+ if (params.mode === "payment") {
28
+ const destination = dest(params.payment_intent_data?.transfer_data?.destination);
29
+ if (!destination)
30
+ return {};
31
+ const amt = params.payment_intent_data?.application_fee_amount;
32
+ return {
33
+ chargeType: "destination",
34
+ destinationAccountId: destination,
35
+ ...(amt !== undefined ? { applicationFeeAmount: amt } : {}),
36
+ };
37
+ }
38
+ return {};
39
+ }
40
+ /**
41
+ * Destination and separate charges use platform prices. Catalog accountId is a
42
+ * store attribution tag, not Stripe ownership (createProduct uses the platform).
43
+ * For tagged products, verify the price in the platform Stripe context before
44
+ * rejecting it. Untagged/unknown catalog entries are validated by Checkout.
45
+ */
46
+ async function assertPlatformPrice(stripe, component, ctx, stripePriceId) {
47
+ const price = (await ctx.runQuery(componentRef(component, "products/queries/getPriceByStripeId"), { stripePriceId }));
48
+ if (!price?.stripeProductId)
49
+ return;
50
+ const product = (await ctx.runQuery(componentRef(component, "products/queries/getProductByStripeId"), { stripeProductId: price.stripeProductId }));
51
+ if (product?.accountId) {
52
+ try {
53
+ await stripe.prices.retrieve(stripePriceId);
54
+ }
55
+ catch (error) {
56
+ // Only absence on the platform means the ownership check failed.
57
+ // Auth/network/rate-limit failures must not be misreported as ownership.
58
+ if (!error ||
59
+ typeof error !== "object" ||
60
+ !("code" in error) ||
61
+ error.code !== "resource_missing")
62
+ throw error;
63
+ throwStripeError("INVALID_CONFIGURATION", `Price ${stripePriceId} is unavailable on the platform account; destination charges require a platform-owned price.`);
64
+ }
65
+ }
66
+ }
67
+ // =============================================================================
68
+ // Checkout methods
69
+ // =============================================================================
70
+ export async function renderCheckoutSession(stripe, component, ctx, opts, capturedDescriptor) {
71
+ const uiMode = opts.uiMode ?? "embedded";
72
+ // Setup-mode sessions create no charge, so routing/fees are meaningless and
73
+ // would persist an unfunded `chargeType` the webhook engine can't act on.
74
+ if (opts.mode === "setup" &&
75
+ (opts.split?.length || opts.destinationAccountId || opts.feeConfig)) {
76
+ throwStripeError("INVALID_CONFIGURATION", "split/destinationAccountId/fee are not supported for setup-mode Checkout Sessions");
77
+ }
78
+ // Resolve the routing model. A `split` with >1 recipient uses separate charges
79
+ // & transfers (no application_fee; webhook engine creates the transfers); a
80
+ // single-recipient split is just a destination charge. `split` wins over
81
+ // `destinationAccountId`.
82
+ let isSeparate = false;
83
+ let destinationAccountId = opts.destinationAccountId;
84
+ if (opts.split && opts.split.length > 0) {
85
+ validateSplit(opts.split);
86
+ if (opts.split.length === 1) {
87
+ destinationAccountId = opts.split[0].destinationAccountId;
88
+ }
89
+ else {
90
+ isSeparate = true;
91
+ }
92
+ }
93
+ // Metadata markers the webhook split engine reads to create the transfers.
94
+ // For subscriptions these live on the subscription and are consumed on each
95
+ // invoice.paid; for one-time payments they live on the PaymentIntent.
96
+ const separateMeta = isSeparate
97
+ ? {
98
+ bsChargeType: "separate",
99
+ bsSplit: JSON.stringify(opts.split),
100
+ ...(opts.feeConfig
101
+ ? { bsFeeConfig: JSON.stringify(opts.feeConfig) }
102
+ : {}),
103
+ }
104
+ : {};
105
+ // Strip the reserved `bs*` namespace from caller metadata so it can't forge
106
+ // webhook instructions (e.g. trigger split transfers without routing).
107
+ const metadata = {
108
+ ...stripReservedMetadata(opts.metadata),
109
+ userId: opts.userId,
110
+ ...(opts.orgId ? { orgId: opts.orgId } : {}),
111
+ };
112
+ // Per-store statement descriptor (BTS-32). Destination charges are platform
113
+ // charges (platform = merchant of record), so buyer recognition is
114
+ // suffix-based: the store's stored suffix, else the configured platform
115
+ // default. Resolved from the component account record at session creation.
116
+ let statementDescriptorSuffix;
117
+ if (destinationAccountId && !isSeparate && opts.mode !== "setup") {
118
+ if (capturedDescriptor)
119
+ statementDescriptorSuffix = capturedDescriptor.value;
120
+ else {
121
+ const account = (await ctx.runQuery(componentRef(component, "core/queries/getAccountByStripeId"), { stripeAccountId: destinationAccountId }));
122
+ statementDescriptorSuffix =
123
+ account?.statementDescriptor ?? opts.defaultStatementDescriptorSuffix;
124
+ }
125
+ }
126
+ const sessionParams = {
127
+ mode: opts.mode,
128
+ line_items: [{ price: opts.stripePriceId, quantity: opts.quantity ?? 1 }],
129
+ metadata,
130
+ };
131
+ if (opts.mode === "subscription") {
132
+ const subscriptionData = {
133
+ metadata,
134
+ };
135
+ if (opts.trialDays) {
136
+ subscriptionData.trial_period_days = opts.trialDays;
137
+ }
138
+ if (isSeparate) {
139
+ // Separate charges & transfers: NO transfer_data / application_fee. The
140
+ // split is carried in metadata for the webhook engine to execute.
141
+ subscriptionData.metadata = { ...metadata, ...separateMeta };
142
+ }
143
+ else if (destinationAccountId) {
144
+ // Single-recipient destination charge: route funds to the seller and take
145
+ // the platform's cut. Percent-only fees map to `application_fee_percent`;
146
+ // percent+fixed/tiered fees can't be expressed that way, so flag the
147
+ // subscription for per-invoice fee computation (handled by WEBHOOK_FEE).
148
+ subscriptionData.transfer_data = { destination: destinationAccountId };
149
+ if (opts.feeConfig) {
150
+ if (isPercentOnlyFee(opts.feeConfig)) {
151
+ subscriptionData.application_fee_percent = opts.feeConfig.percent;
152
+ }
153
+ else {
154
+ subscriptionData.metadata = {
155
+ ...metadata,
156
+ bsFeeMode: "per_invoice",
157
+ bsFeeConfig: JSON.stringify(opts.feeConfig),
158
+ };
159
+ }
160
+ }
161
+ if (statementDescriptorSuffix) {
162
+ // Subscriptions can't carry a suffix directly; the invoice.created
163
+ // processor reads this marker and sets it on each invoice.
164
+ subscriptionData.metadata = {
165
+ ...(subscriptionData.metadata ?? metadata),
166
+ bsStatementDescriptor: statementDescriptorSuffix,
167
+ };
168
+ }
169
+ }
170
+ sessionParams.subscription_data = subscriptionData;
171
+ }
172
+ if (opts.mode === "payment") {
173
+ const paymentIntentData = { metadata };
174
+ if (isSeparate) {
175
+ paymentIntentData.metadata = { ...metadata, ...separateMeta };
176
+ }
177
+ else if (destinationAccountId) {
178
+ // Single-recipient destination charge for a one-time purchase. The platform
179
+ // fee is a fixed `application_fee_amount`: compute it when the amount is
180
+ // known; otherwise flag the PI with `bsFeeMode=per_charge` and the webhook
181
+ // collects it at payment_intent.succeeded via a partial reversal of the
182
+ // destination transfer, sized from the amount actually charged (BTS-60).
183
+ paymentIntentData.transfer_data = {
184
+ destination: destinationAccountId,
185
+ };
186
+ if (statementDescriptorSuffix) {
187
+ paymentIntentData.statement_descriptor_suffix =
188
+ statementDescriptorSuffix;
189
+ }
190
+ if (opts.feeConfig) {
191
+ if (opts.amount !== undefined) {
192
+ paymentIntentData.application_fee_amount = computeFee(opts.amount, opts.feeConfig).feeAmount;
193
+ }
194
+ else {
195
+ paymentIntentData.metadata = {
196
+ ...metadata,
197
+ bsFeeMode: "per_charge",
198
+ bsFeeConfig: JSON.stringify(opts.feeConfig),
199
+ };
200
+ }
201
+ }
202
+ }
203
+ sessionParams.payment_intent_data = paymentIntentData;
204
+ }
205
+ if (uiMode === "embedded" || uiMode === "custom" || uiMode === "form") {
206
+ sessionParams.ui_mode =
207
+ uiMode === "custom"
208
+ ? "elements"
209
+ : uiMode === "form"
210
+ ? "form"
211
+ : "embedded_page";
212
+ sessionParams.return_url = opts.returnUrl;
213
+ }
214
+ else {
215
+ sessionParams.success_url = `${opts.returnUrl}?session_id={CHECKOUT_SESSION_ID}`;
216
+ sessionParams.cancel_url = opts.returnUrl;
217
+ }
218
+ if (opts.accountId) {
219
+ sessionParams.customer_account = opts.accountId;
220
+ }
221
+ else if (opts.customerEmail) {
222
+ sessionParams.customer_email = opts.customerEmail;
223
+ }
224
+ // Merge overrides, then derive the persisted fee/routing row from the FINAL
225
+ // request — sessionOverrides can replace subscription_data/payment_intent_data
226
+ // wholesale, so the row must reflect what was actually sent to Stripe.
227
+ const finalSessionParams = {
228
+ ...sessionParams,
229
+ ...opts.sessionOverrides,
230
+ };
231
+ // Separate-charge sales persist the split + chargeType directly; single-recipient
232
+ // destination charges derive the row from the final transfer_data/fee.
233
+ const feeRow = isSeparate
234
+ ? { chargeType: "separate", splitRecipients: opts.split }
235
+ : deriveFeeRow(finalSessionParams);
236
+ // Both destination and separate charges run on the platform account, so the
237
+ // price must be platform-owned. Validate the FINAL request (post-overrides) so
238
+ // callers can't inject transfer_data or swap line_items to bypass the check.
239
+ const finalPriceId = finalSessionParams.line_items?.[0]?.price;
240
+ if ((isSeparate || feeRow.chargeType === "destination") &&
241
+ typeof finalPriceId === "string") {
242
+ await assertPlatformPrice(stripe, component, ctx, finalPriceId);
243
+ }
244
+ return {
245
+ version: 1,
246
+ request: finalSessionParams,
247
+ options: opts,
248
+ descriptor: { value: statementDescriptorSuffix },
249
+ routingMetadata: {
250
+ subscription: sessionParams.subscription_data?.metadata,
251
+ payment: sessionParams.payment_intent_data?.metadata,
252
+ },
253
+ row: {
254
+ userId: opts.userId,
255
+ orgId: opts.orgId,
256
+ accountId: opts.accountId,
257
+ priceId: opts.stripePriceId,
258
+ ...feeRow,
259
+ metadata,
260
+ },
261
+ };
262
+ }
263
+ //# sourceMappingURL=checkoutRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkoutRequest.js","sourceRoot":"","sources":["../../../src/client/billing/checkoutRequest.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,MAAmC;IAMvD,MAAM,IAAI,GAAG,CAAC,CAAU,EAAsB,EAAE,CAC9C,OAAO,CAAC,KAAK,QAAQ;QACnB,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,CAAE,CAAwC,EAAE,EAAE,IAAI,SAAS,CAAC,CAAC;IAEnE,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,IAAI,CACtB,MAAM,CAAC,iBAAiB,EAAE,aAAa,EAAE,WAAW,CACrD,CAAC;QACF,IAAI,CAAC,WAAW;YAAE,OAAO,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,iBAAiB,EAAE,uBAAuB,CAAC;QAC9D,OAAO;YACL,UAAU,EAAE,aAAa;YACzB,oBAAoB,EAAE,WAAW;YACjC,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7D,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,C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EAAE;QAChD,eAAe,EAAE;YACf,YAAY,EAAE,aAAa,CAAC,iBAAiB,EAAE,QAAQ;YACvD,OAAO,EAAE,aAAa,CAAC,mBAAmB,EAAE,QAAQ;SACrD;QACD,GAAG,EAAE;YACH,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,aAAa;YAC3B,GAAG,MAAM;YACT,QAAQ;SACT;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type Stripe from "stripe";
2
+ import type { Component, RunCtx } from "../helpers.js";
3
+ import { renderCheckoutSession } from "./checkoutRequest.js";
4
+ export type PreparedCheckoutSession = Awaited<ReturnType<typeof renderCheckoutSession>>;
5
+ /** Read-only preparation. Persist the whole snapshot under host-owned immutable authorization. */
6
+ export declare function prepareCheckoutSession(stripe: Stripe, component: Component, ctx: RunCtx, opts: Parameters<typeof renderCheckoutSession>[3]): Promise<PreparedCheckoutSession>;
7
+ /** Execute only a trusted server snapshot. Ownership and durable request binding belong to the host. */
8
+ export declare function executePreparedCheckoutSession(stripe: Stripe, component: Component, ctx: RunCtx, args: {
9
+ prepared: PreparedCheckoutSession;
10
+ idempotencyKey: string;
11
+ }): Promise<{
12
+ stripeSessionId: string;
13
+ clientSecret: string | undefined;
14
+ url: string | undefined;
15
+ }>;
16
+ /** Shared legacy submission. Its input has already passed the maintained renderer's safeguards. */
17
+ export declare function submitPreparedCheckout(stripe: Stripe, component: Component, ctx: RunCtx, prepared: PreparedCheckoutSession, key?: string): Promise<{
18
+ stripeSessionId: string;
19
+ clientSecret: string | undefined;
20
+ url: string | undefined;
21
+ }>;
22
+ //# sourceMappingURL=preparedCheckout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preparedCheckout.d.ts","sourceRoot":"","sources":["../../../src/client/billing/preparedCheckout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC3C,UAAU,CAAC,OAAO,qBAAqB,CAAC,CACzC,CAAC;AAmDF,kGAAkG;AAClG,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAChD,OAAO,CAAC,uBAAuB,CAAC,CAMlC;AACD,wGAAwG;AACxG,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE;;;;GAkCpE;AACD,mGAAmG;AACnG,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,uBAAuB,EACjC,GAAG,CAAC,EAAE,MAAM;;;;GAuBb"}
@@ -0,0 +1,86 @@
1
+ import { runMutationOrThrow } from "../helpers.js";
2
+ import { componentRef } from "../webhooks/helpers.js";
3
+ import { idempotencyOptions } from "../core/idempotency.js";
4
+ import { renderCheckoutSession } from "./checkoutRequest.js";
5
+ function canonical(value) {
6
+ return JSON.stringify(value, (_key, item) => {
7
+ if (typeof item === "number" && !Number.isFinite(item))
8
+ throw new Error("Checkout request must be serializable.");
9
+ if (["function", "symbol", "bigint"].includes(typeof item))
10
+ throw new Error("Checkout request must be serializable.");
11
+ if (item && typeof item === "object" && !Array.isArray(item))
12
+ return Object.fromEntries(Object.entries(item).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
13
+ return item;
14
+ });
15
+ }
16
+ function snapshot(value) {
17
+ return JSON.parse(canonical(value));
18
+ }
19
+ function validateCorrelation(prepared) {
20
+ const { request, row, options } = prepared;
21
+ const nested = request.mode === "subscription"
22
+ ? request.subscription_data?.metadata
23
+ : request.mode === "payment"
24
+ ? request.payment_intent_data?.metadata
25
+ : undefined;
26
+ if (request.mode !== options.mode ||
27
+ request.customer_account !== options.accountId ||
28
+ request.customer_email !==
29
+ (options.accountId ? undefined : options.customerEmail) ||
30
+ request.line_items?.length !== 1 ||
31
+ request.line_items[0]?.price !== options.stripePriceId ||
32
+ canonical(request.metadata) !== canonical(row.metadata) ||
33
+ (request.mode !== "setup" &&
34
+ Object.entries(row.metadata).some(([key, value]) => nested?.[key] !== value)))
35
+ throw new Error("Prepared Checkout correlation does not match.");
36
+ const generated = request.mode === "subscription"
37
+ ? prepared.routingMetadata.subscription
38
+ : prepared.routingMetadata.payment;
39
+ const reserved = new Set([...Object.keys(nested ?? {}), ...Object.keys(generated ?? {})].filter((key) => key.startsWith("bs")));
40
+ if ([...reserved].some((key) => nested?.[key] !== generated?.[key]))
41
+ throw new Error("Prepared Checkout routing metadata does not match.");
42
+ }
43
+ /** Read-only preparation. Persist the whole snapshot under host-owned immutable authorization. */
44
+ export async function prepareCheckoutSession(stripe, component, ctx, opts) {
45
+ const prepared = snapshot(await renderCheckoutSession(stripe, component, ctx, snapshot(opts)));
46
+ validateCorrelation(prepared);
47
+ return prepared;
48
+ }
49
+ /** Execute only a trusted server snapshot. Ownership and durable request binding belong to the host. */
50
+ export async function executePreparedCheckoutSession(stripe, component, ctx, args) {
51
+ const requestOptions = idempotencyOptions(args.idempotencyKey);
52
+ if (!requestOptions)
53
+ throw new Error("Prepared Checkout requires an explicit idempotency key.");
54
+ const prepared = snapshot(args.prepared);
55
+ if (prepared.version !== 1)
56
+ throw new Error("Unsupported prepared Checkout version.");
57
+ if (prepared.options.idempotencyKey !== undefined &&
58
+ prepared.options.idempotencyKey !== args.idempotencyKey)
59
+ throw new Error("Prepared Checkout idempotency key does not match.");
60
+ validateCorrelation(prepared);
61
+ const expected = snapshot(await renderCheckoutSession(stripe, component, ctx, prepared.options, prepared.descriptor));
62
+ if (canonical(prepared) !== canonical(expected))
63
+ throw new Error("Prepared Checkout request does not match its bound context.");
64
+ return submitPreparedCheckout(stripe, component, ctx, prepared, args.idempotencyKey);
65
+ }
66
+ /** Shared legacy submission. Its input has already passed the maintained renderer's safeguards. */
67
+ export async function submitPreparedCheckout(stripe, component, ctx, prepared, key) {
68
+ const options = idempotencyOptions(key);
69
+ const session = options
70
+ ? await stripe.checkout.sessions.create(prepared.request, options)
71
+ : await stripe.checkout.sessions.create(prepared.request);
72
+ await runMutationOrThrow(ctx, componentRef(component, "billing/mutations/upsertCheckoutSession"), {
73
+ ...prepared.row,
74
+ stripeSessionId: session.id,
75
+ mode: prepared.request.mode,
76
+ status: (session.status ?? "open"),
77
+ clientSecret: session.client_secret ?? undefined,
78
+ url: session.url ?? undefined,
79
+ });
80
+ return {
81
+ stripeSessionId: session.id,
82
+ clientSecret: session.client_secret ?? undefined,
83
+ url: session.url ?? undefined,
84
+ };
85
+ }
86
+ //# sourceMappingURL=preparedCheckout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preparedCheckout.js","sourceRoot":"","sources":["../../../src/client/billing/preparedCheckout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAK7D,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAa,EAAE,EAAE;QACnD,IAAI,OAAO,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.js";
3
+ import type { FeeOverride, PlatformFeeConfig } from "./types.js";
4
+ import type { CreateCheckoutSessionOptions } from "./billing/checkoutOptions.js";
5
+ import { executePreparedCheckoutSession } from "./billing/preparedCheckout.js";
6
+ /** Server-only request preparation and execution, without a browser-owned money API. */
7
+ export declare class CheckoutRequestClient {
8
+ private component;
9
+ private provider;
10
+ private resolveFee;
11
+ private descriptor?;
12
+ constructor(component: Component, provider: () => Stripe, resolveFee: (fee?: FeeOverride) => PlatformFeeConfig | undefined, descriptor?: string | undefined);
13
+ prepare(ctx: RunCtx, opts: CreateCheckoutSessionOptions): Promise<{
14
+ version: 1;
15
+ request: Stripe.Checkout.SessionCreateParams;
16
+ options: {
17
+ idempotencyKey?: string;
18
+ userId: string;
19
+ orgId?: string;
20
+ stripePriceId: string;
21
+ mode: "payment" | "subscription" | "setup";
22
+ uiMode?: "embedded" | "redirect" | "custom" | "form";
23
+ quantity?: number;
24
+ returnUrl: string;
25
+ trialDays?: number;
26
+ accountId?: string;
27
+ customerEmail?: string;
28
+ destinationAccountId?: string;
29
+ split?: import("../component/lib/fees.js").SplitRecipient[];
30
+ feeConfig?: PlatformFeeConfig;
31
+ amount?: number;
32
+ defaultStatementDescriptorSuffix?: string;
33
+ metadata?: Record<string, string>;
34
+ sessionOverrides?: Record<string, unknown>;
35
+ };
36
+ descriptor: {
37
+ value: string | undefined;
38
+ };
39
+ routingMetadata: {
40
+ subscription: Stripe.MetadataParam | undefined;
41
+ payment: Stripe.MetadataParam | undefined;
42
+ };
43
+ row: {
44
+ chargeType?: "destination";
45
+ destinationAccountId?: string;
46
+ applicationFeePercent?: number;
47
+ applicationFeeAmount?: number;
48
+ userId: string;
49
+ orgId: string | undefined;
50
+ accountId: string | undefined;
51
+ priceId: string;
52
+ metadata: {
53
+ userId: string;
54
+ orgId?: string | undefined;
55
+ };
56
+ } | {
57
+ chargeType: "separate";
58
+ splitRecipients: {
59
+ amount?: number | undefined;
60
+ destinationAccountId: string;
61
+ percent?: number | undefined;
62
+ role: "affiliate" | "other" | "store";
63
+ }[] | undefined;
64
+ userId: string;
65
+ orgId: string | undefined;
66
+ accountId: string | undefined;
67
+ priceId: string;
68
+ metadata: {
69
+ userId: string;
70
+ orgId?: string | undefined;
71
+ };
72
+ };
73
+ }>;
74
+ execute(ctx: RunCtx, args: Parameters<typeof executePreparedCheckoutSession>[3]): Promise<{
75
+ stripeSessionId: string;
76
+ clientSecret: string | undefined;
77
+ url: string | undefined;
78
+ }>;
79
+ }
80
+ //# sourceMappingURL=checkoutRequests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkoutRequests.d.ts","sourceRoot":"","sources":["../../src/client/checkoutRequests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAEL,8BAA8B,EAC/B,MAAM,+BAA+B,CAAC;AAEvC,wFAAwF;AACxF,qBAAa,qBAAqB;IAE9B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU,CAAC;IAJrB,YACU,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,MAAM,MAAM,EACtB,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,WAAW,KAAK,iBAAiB,GAAG,SAAS,EAChE,UAAU,CAAC,EAAE,MAAM,YAAA,EACzB;IACJ,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAUtD;IACD,OAAO,CACL,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC,CAAC,CAAC;;;;OAQ3D;CACF"}
@@ -0,0 +1,28 @@
1
+ import { prepareCheckoutSession, executePreparedCheckoutSession, } from "./billing/preparedCheckout.js";
2
+ /** Server-only request preparation and execution, without a browser-owned money API. */
3
+ export class CheckoutRequestClient {
4
+ component;
5
+ provider;
6
+ resolveFee;
7
+ descriptor;
8
+ constructor(component, provider, resolveFee, descriptor) {
9
+ this.component = component;
10
+ this.provider = provider;
11
+ this.resolveFee = resolveFee;
12
+ this.descriptor = descriptor;
13
+ }
14
+ prepare(ctx, opts) {
15
+ const { fee, ...rest } = opts;
16
+ return prepareCheckoutSession(this.provider(), this.component, ctx, {
17
+ ...rest,
18
+ feeConfig: opts.destinationAccountId || opts.split?.length
19
+ ? this.resolveFee(fee)
20
+ : undefined,
21
+ defaultStatementDescriptorSuffix: this.descriptor,
22
+ });
23
+ }
24
+ execute(ctx, args) {
25
+ return executePreparedCheckoutSession(this.provider(), this.component, ctx, args);
26
+ }
27
+ }
28
+ //# sourceMappingURL=checkoutRequests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkoutRequests.js","sourceRoot":"","sources":["../../src/client/checkoutRequests.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AAEvC,wFAAwF;AACxF,MAAM,OAAO,qBAAqB;IAEtB,SAAS;IACT,QAAQ;IACR,UAAU;IACV,UAAU;IAJpB,YACU,SAAoB,EACpB,QAAsB,EACtB,UAAgE,EAChE,UAAmB;yBAHnB,SAAS;wBACT,QAAQ;0BACR,UAAU;0BACV,UAAU;IACjB,CAAC;IACJ,OAAO,CAAC,GAAW,EAAE,IAAkC;QACrD,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC9B,OAAO,sBAAsB,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;YAClE,GAAG,IAAI;YACP,SAAS,EACP,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM;gBAC7C,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;gBACtB,CAAC,CAAC,SAAS;YACf,gCAAgC,EAAE,IAAI,CAAC,UAAU;SAClD,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CACL,GAAW,EACX,IAA0D;QAE1D,OAAO,8BAA8B,CACnC,IAAI,CAAC,QAAQ,EAAE,EACf,IAAI,CAAC,SAAS,EACd,GAAG,EACH,IAAI,CACL,CAAC;IACJ,CAAC;CACF"}