@fantastic.dev/better-stripe 0.77.0 → 0.79.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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/client/core/accountLinks.d.ts +17 -1
- package/dist/client/core/accountLinks.d.ts.map +1 -1
- package/dist/client/core/accountLinks.js +72 -11
- package/dist/client/core/accountLinks.js.map +1 -1
- package/dist/client/core/billingPortalClient.d.ts.map +1 -1
- package/dist/client/core/billingPortalClient.js +1 -1
- package/dist/client/core/billingPortalClient.js.map +1 -1
- package/dist/client/core/billingPortalFlow.d.ts +69 -0
- package/dist/client/core/billingPortalFlow.d.ts.map +1 -0
- package/dist/client/core/billingPortalFlow.js +81 -0
- package/dist/client/core/billingPortalFlow.js.map +1 -0
- package/dist/client/core/idempotency.d.ts.map +1 -1
- package/dist/client/core/idempotency.js +4 -1
- package/dist/client/core/idempotency.js.map +1 -1
- package/dist/client/helpers.d.ts +3 -1
- package/dist/client/helpers.d.ts.map +1 -1
- package/dist/client/helpers.js +13 -2
- package/dist/client/helpers.js.map +1 -1
- package/dist/client/index.d.ts +5 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/invoiceReads.d.ts +3 -1
- package/dist/client/invoiceReads.d.ts.map +1 -1
- package/dist/client/singleAttemptHttpClient.d.ts +11 -0
- package/dist/client/singleAttemptHttpClient.d.ts.map +1 -0
- package/dist/client/singleAttemptHttpClient.js +51 -0
- package/dist/client/singleAttemptHttpClient.js.map +1 -0
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/react/workflows/Billing.d.ts.map +1 -1
- package/dist/react/workflows/Billing.js +6 -4
- package/dist/react/workflows/Billing.js.map +1 -1
- package/docs/client-api.md +123 -0
- package/package.json +1 -1
- package/src/client/core/accountLinks.test.ts +4 -4
- package/src/client/core/accountLinks.ts +120 -13
- package/src/client/core/billingPortal.test.ts +8 -6
- package/src/client/core/billingPortalClient.ts +5 -1
- package/src/client/core/billingPortalFlow.test.ts +349 -0
- package/src/client/core/billingPortalFlow.ts +98 -0
- package/src/client/core/billingPortalIdentity.test.ts +418 -0
- package/src/client/core/idempotency.ts +6 -1
- package/src/client/customer-preview.test.ts +188 -7
- package/src/client/helpers.ts +15 -1
- package/src/client/index.ts +5 -2
- package/src/client/invoiceReads.ts +1 -1
- package/src/client/singleAttemptHttpClient.test.ts +70 -0
- package/src/client/singleAttemptHttpClient.ts +58 -0
- package/src/react/workflows/Billing.tsx +15 -8
- package/src/react/workflows/BillingPortal.test.tsx +101 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { BetterStripe, type BetterStripeComponent } from "../index.js";
|
|
4
|
+
import type { RunCtx } from "../helpers.js";
|
|
5
|
+
import type {
|
|
6
|
+
BillingPortalSubscriptionUpdateFlow,
|
|
7
|
+
CreateBillingPortalSessionOptions,
|
|
8
|
+
} from "./accountLinks.js";
|
|
9
|
+
|
|
10
|
+
const ctx = {} as RunCtx;
|
|
11
|
+
const flowData = {
|
|
12
|
+
type: "subscription_update_confirm",
|
|
13
|
+
subscription_update_confirm: {
|
|
14
|
+
subscription: "sub_original",
|
|
15
|
+
items: [{ id: "si_original", price: "price_target" }],
|
|
16
|
+
},
|
|
17
|
+
after_completion: {
|
|
18
|
+
type: "redirect",
|
|
19
|
+
redirect: { return_url: "https://host.example/billing/confirmed" },
|
|
20
|
+
},
|
|
21
|
+
} satisfies BillingPortalSubscriptionUpdateFlow;
|
|
22
|
+
|
|
23
|
+
function fixture(connectedAccountId?: string) {
|
|
24
|
+
const subscription = {
|
|
25
|
+
object: "subscription",
|
|
26
|
+
id: "sub_original",
|
|
27
|
+
customer_account: "acct_customer",
|
|
28
|
+
items: {
|
|
29
|
+
has_more: false,
|
|
30
|
+
data: [{ id: "si_original", price: { id: "price_current" } }],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const retrieve = vi.fn().mockResolvedValue(subscription);
|
|
34
|
+
const create = vi
|
|
35
|
+
.fn()
|
|
36
|
+
.mockResolvedValue({ url: "https://billing.stripe.test" });
|
|
37
|
+
class Client extends BetterStripe {
|
|
38
|
+
protected stripe() {
|
|
39
|
+
return {
|
|
40
|
+
subscriptions: { retrieve },
|
|
41
|
+
billingPortal: { sessions: { create } },
|
|
42
|
+
} as unknown as Stripe;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const client = new Client({} as BetterStripeComponent);
|
|
46
|
+
const options = {
|
|
47
|
+
stripeAccountId: "acct_customer",
|
|
48
|
+
connectedAccountId,
|
|
49
|
+
configurationId: "bpc_policy",
|
|
50
|
+
returnUrl: "https://host.example/billing",
|
|
51
|
+
flowData,
|
|
52
|
+
} satisfies CreateBillingPortalSessionOptions;
|
|
53
|
+
return { client, options, subscription, retrieve, create };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("targeted Billing Portal subscription confirmation", () => {
|
|
57
|
+
it.each([undefined, "acct_connected"])(
|
|
58
|
+
"retains exact subscription/item/price and completion routing in scope %s",
|
|
59
|
+
async (connectedAccountId) => {
|
|
60
|
+
const f = fixture(connectedAccountId);
|
|
61
|
+
expect(await f.client.createBillingPortalSession(ctx, f.options)).toEqual(
|
|
62
|
+
{
|
|
63
|
+
url: "https://billing.stripe.test",
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
expect(f.retrieve.mock.calls).toEqual([
|
|
67
|
+
[
|
|
68
|
+
"sub_original",
|
|
69
|
+
{},
|
|
70
|
+
{
|
|
71
|
+
...(connectedAccountId
|
|
72
|
+
? { stripeAccount: connectedAccountId }
|
|
73
|
+
: {}),
|
|
74
|
+
maxNetworkRetries: 0,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
]);
|
|
78
|
+
const params = {
|
|
79
|
+
customer_account: "acct_customer",
|
|
80
|
+
configuration: "bpc_policy",
|
|
81
|
+
return_url: "https://host.example/billing",
|
|
82
|
+
flow_data: flowData,
|
|
83
|
+
};
|
|
84
|
+
expect(f.create.mock.calls).toEqual([
|
|
85
|
+
[
|
|
86
|
+
params,
|
|
87
|
+
{
|
|
88
|
+
...(connectedAccountId
|
|
89
|
+
? { stripeAccount: connectedAccountId }
|
|
90
|
+
: {}),
|
|
91
|
+
maxNetworkRetries: 0,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
]);
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
it.each([
|
|
99
|
+
{ id: "sub_other" },
|
|
100
|
+
{ customer_account: "acct_other" },
|
|
101
|
+
{ customer_account: null },
|
|
102
|
+
{ items: { has_more: false, data: [{ id: "si_other" }] } },
|
|
103
|
+
{
|
|
104
|
+
items: {
|
|
105
|
+
has_more: false,
|
|
106
|
+
data: [{ id: "si_original" }, { id: "si_original" }],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
])(
|
|
110
|
+
"denies mismatched or ambiguous original subscription: %j",
|
|
111
|
+
async (fields) => {
|
|
112
|
+
const f = fixture();
|
|
113
|
+
f.retrieve.mockResolvedValue({ ...f.subscription, ...fields });
|
|
114
|
+
await expect(
|
|
115
|
+
f.client.createBillingPortalSession(ctx, f.options),
|
|
116
|
+
).rejects.toThrow();
|
|
117
|
+
expect(f.create).not.toHaveBeenCalled();
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Original recovered success stub is preserved separately: the provider disallows multi-item updates.
|
|
122
|
+
it("rejects a multi-item subscription instead of silently selecting its first item", async () => {
|
|
123
|
+
const f = fixture();
|
|
124
|
+
f.retrieve.mockResolvedValue({
|
|
125
|
+
...f.subscription,
|
|
126
|
+
items: {
|
|
127
|
+
has_more: false,
|
|
128
|
+
data: [{ id: "si_unrelated" }, { id: "si_original" }],
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
await expect(
|
|
132
|
+
f.client.createBillingPortalSession(ctx, f.options),
|
|
133
|
+
).rejects.toThrow();
|
|
134
|
+
expect(f.retrieve).toHaveBeenCalledExactlyOnceWith(
|
|
135
|
+
"sub_original",
|
|
136
|
+
{},
|
|
137
|
+
{ maxNetworkRetries: 0 },
|
|
138
|
+
);
|
|
139
|
+
expect(f.create).not.toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it.each([
|
|
143
|
+
null,
|
|
144
|
+
true,
|
|
145
|
+
[],
|
|
146
|
+
"subscription_update_confirm",
|
|
147
|
+
{ ...flowData, type: "subscription_update" },
|
|
148
|
+
{
|
|
149
|
+
...flowData,
|
|
150
|
+
subscription_update_confirm: { subscription: "sub_original", items: [] },
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
...flowData,
|
|
154
|
+
subscription_update_confirm: {
|
|
155
|
+
subscription: "sub_original",
|
|
156
|
+
items: [{ id: "si_original", price: "prod_wrong" }],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
...flowData,
|
|
161
|
+
subscription_update_confirm: {
|
|
162
|
+
subscription: "sub_original",
|
|
163
|
+
items: [
|
|
164
|
+
{ id: "si_original", price: "price_target" },
|
|
165
|
+
{ id: "si_other", price: "price_other" },
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
...flowData,
|
|
171
|
+
after_completion: {
|
|
172
|
+
type: "redirect",
|
|
173
|
+
redirect: { return_url: "javascript:alert(1)" },
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{ ...flowData, unknownPolicy: true },
|
|
177
|
+
{
|
|
178
|
+
...flowData,
|
|
179
|
+
subscription_update_confirm: {
|
|
180
|
+
subscription: 42,
|
|
181
|
+
items: [{ id: "si_original", price: "price_target" }],
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
...flowData,
|
|
186
|
+
subscription_update_confirm: {
|
|
187
|
+
subscription: "sub_original",
|
|
188
|
+
items: [{ id: false, price: "price_target" }],
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
...flowData,
|
|
193
|
+
subscription_update_confirm: {
|
|
194
|
+
subscription: "sub_original",
|
|
195
|
+
items: [
|
|
196
|
+
{ id: "si_original", price: "price_target", unknownPolicy: true },
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
...flowData,
|
|
202
|
+
after_completion: { type: "redirect", redirect: { return_url: 42 } },
|
|
203
|
+
},
|
|
204
|
+
])(
|
|
205
|
+
"rejects unsupported input before provider dispatch: %j",
|
|
206
|
+
async (untrusted) => {
|
|
207
|
+
const f = fixture();
|
|
208
|
+
const options = {
|
|
209
|
+
...f.options,
|
|
210
|
+
flowData: untrusted,
|
|
211
|
+
} as CreateBillingPortalSessionOptions;
|
|
212
|
+
await expect(
|
|
213
|
+
f.client.createBillingPortalSession(ctx, options),
|
|
214
|
+
).rejects.toThrow();
|
|
215
|
+
expect(f.retrieve).not.toHaveBeenCalled();
|
|
216
|
+
expect(f.create).not.toHaveBeenCalled();
|
|
217
|
+
},
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
it.each([
|
|
221
|
+
0,
|
|
222
|
+
-1,
|
|
223
|
+
1.5,
|
|
224
|
+
"2",
|
|
225
|
+
null,
|
|
226
|
+
Number.NaN,
|
|
227
|
+
Number.POSITIVE_INFINITY,
|
|
228
|
+
Number.MAX_SAFE_INTEGER + 1,
|
|
229
|
+
])(
|
|
230
|
+
"rejects an invalid target quantity before dispatch: %j",
|
|
231
|
+
async (quantity) => {
|
|
232
|
+
const f = fixture();
|
|
233
|
+
const options = {
|
|
234
|
+
...f.options,
|
|
235
|
+
flowData: {
|
|
236
|
+
...flowData,
|
|
237
|
+
subscription_update_confirm: {
|
|
238
|
+
subscription: "sub_original",
|
|
239
|
+
items: [{ id: "si_original", price: "price_target", quantity }],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
} as CreateBillingPortalSessionOptions;
|
|
243
|
+
await expect(
|
|
244
|
+
f.client.createBillingPortalSession(ctx, options),
|
|
245
|
+
).rejects.toThrow();
|
|
246
|
+
expect(f.retrieve).not.toHaveBeenCalled();
|
|
247
|
+
expect(f.create).not.toHaveBeenCalled();
|
|
248
|
+
},
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
it.each([1, 2, Number.MAX_SAFE_INTEGER])(
|
|
252
|
+
"forwards an explicit positive integer target quantity: %j",
|
|
253
|
+
async (quantity) => {
|
|
254
|
+
const f = fixture();
|
|
255
|
+
const requested: BillingPortalSubscriptionUpdateFlow = {
|
|
256
|
+
...flowData,
|
|
257
|
+
subscription_update_confirm: {
|
|
258
|
+
subscription: "sub_original",
|
|
259
|
+
items: [{ id: "si_original", price: "price_target", quantity }],
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
await f.client.createBillingPortalSession(ctx, {
|
|
263
|
+
...f.options,
|
|
264
|
+
flowData: requested,
|
|
265
|
+
});
|
|
266
|
+
expect(f.create.mock.calls[0]?.[0].flow_data).toEqual(requested);
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
it("rejects a partial item page even when the selected item is present", async () => {
|
|
271
|
+
const f = fixture();
|
|
272
|
+
f.retrieve.mockResolvedValue({
|
|
273
|
+
...f.subscription,
|
|
274
|
+
items: { ...f.subscription.items, has_more: true },
|
|
275
|
+
});
|
|
276
|
+
await expect(
|
|
277
|
+
f.client.createBillingPortalSession(ctx, f.options),
|
|
278
|
+
).rejects.toThrow();
|
|
279
|
+
expect(f.create).not.toHaveBeenCalled();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("retains the authorized scalar snapshot while the original subscription read awaits", async () => {
|
|
283
|
+
const f = fixture("acct_connected");
|
|
284
|
+
const options: CreateBillingPortalSessionOptions = {
|
|
285
|
+
...f.options,
|
|
286
|
+
flowData: {
|
|
287
|
+
...flowData,
|
|
288
|
+
subscription_update_confirm: {
|
|
289
|
+
subscription: "sub_original",
|
|
290
|
+
items: [{ id: "si_original", price: "price_target" }],
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
let release!: (value: typeof f.subscription) => void;
|
|
295
|
+
f.retrieve.mockReturnValue(
|
|
296
|
+
new Promise((resolve) => {
|
|
297
|
+
release = resolve;
|
|
298
|
+
}),
|
|
299
|
+
);
|
|
300
|
+
const pending = f.client.createBillingPortalSession(ctx, options);
|
|
301
|
+
options.stripeAccountId = "acct_changed";
|
|
302
|
+
options.connectedAccountId = "acct_changed";
|
|
303
|
+
options.returnUrl = "https://untrusted.example/changed";
|
|
304
|
+
options.flowData!.subscription_update_confirm.items[0].price =
|
|
305
|
+
"price_changed";
|
|
306
|
+
release(f.subscription);
|
|
307
|
+
await pending;
|
|
308
|
+
expect(f.create.mock.calls).toEqual([
|
|
309
|
+
[
|
|
310
|
+
{
|
|
311
|
+
customer_account: "acct_customer",
|
|
312
|
+
configuration: "bpc_policy",
|
|
313
|
+
return_url: "https://host.example/billing",
|
|
314
|
+
flow_data: flowData,
|
|
315
|
+
},
|
|
316
|
+
{ stripeAccount: "acct_connected", maxNetworkRetries: 0 },
|
|
317
|
+
],
|
|
318
|
+
]);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("preserves ordinary configured sessions without a subscription lookup", async () => {
|
|
322
|
+
const f = fixture();
|
|
323
|
+
const { flowData: _flowData, ...ordinary } = f.options;
|
|
324
|
+
await f.client.createBillingPortalSession(ctx, ordinary);
|
|
325
|
+
expect(f.retrieve).not.toHaveBeenCalled();
|
|
326
|
+
expect(f.create.mock.calls).toEqual([
|
|
327
|
+
[
|
|
328
|
+
{
|
|
329
|
+
customer_account: ordinary.stripeAccountId,
|
|
330
|
+
return_url: ordinary.returnUrl,
|
|
331
|
+
configuration: ordinary.configurationId,
|
|
332
|
+
},
|
|
333
|
+
{ maxNetworkRetries: 0 },
|
|
334
|
+
],
|
|
335
|
+
]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("does not fall back to an account-wide session after a scoped read fails", async () => {
|
|
339
|
+
const f = fixture("acct_connected");
|
|
340
|
+
f.retrieve.mockRejectedValue(
|
|
341
|
+
new Error("Original subscription unavailable"),
|
|
342
|
+
);
|
|
343
|
+
await expect(
|
|
344
|
+
f.client.createBillingPortalSession(ctx, f.options),
|
|
345
|
+
).rejects.toThrow();
|
|
346
|
+
expect(f.retrieve).toHaveBeenCalledTimes(1);
|
|
347
|
+
expect(f.create).not.toHaveBeenCalled();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
const id = (prefix: string) =>
|
|
4
|
+
z
|
|
5
|
+
.string()
|
|
6
|
+
.max(255)
|
|
7
|
+
.regex(new RegExp(`^${prefix}_[A-Za-z0-9_]+$`));
|
|
8
|
+
const redirectUrl = z
|
|
9
|
+
.string()
|
|
10
|
+
.max(2048)
|
|
11
|
+
.url()
|
|
12
|
+
.refine((value) => {
|
|
13
|
+
const url = new URL(value);
|
|
14
|
+
return (
|
|
15
|
+
["https:", "http:"].includes(url.protocol) &&
|
|
16
|
+
!url.username &&
|
|
17
|
+
!url.password
|
|
18
|
+
);
|
|
19
|
+
}, "A public HTTP(S) redirect URL is required.");
|
|
20
|
+
const item = z
|
|
21
|
+
.object({
|
|
22
|
+
id: id("si"),
|
|
23
|
+
price: id("price"),
|
|
24
|
+
quantity: z
|
|
25
|
+
.number()
|
|
26
|
+
.int()
|
|
27
|
+
.positive()
|
|
28
|
+
.max(Number.MAX_SAFE_INTEGER)
|
|
29
|
+
.optional(),
|
|
30
|
+
})
|
|
31
|
+
.strict();
|
|
32
|
+
const flow = z
|
|
33
|
+
.object({
|
|
34
|
+
type: z.literal("subscription_update_confirm"),
|
|
35
|
+
subscription_update_confirm: z
|
|
36
|
+
.object({
|
|
37
|
+
subscription: id("sub"),
|
|
38
|
+
items: z.tuple([item]),
|
|
39
|
+
})
|
|
40
|
+
.strict(),
|
|
41
|
+
after_completion: z
|
|
42
|
+
.object({
|
|
43
|
+
type: z.literal("redirect"),
|
|
44
|
+
redirect: z.object({ return_url: redirectUrl }).strict(),
|
|
45
|
+
})
|
|
46
|
+
.strict()
|
|
47
|
+
.optional(),
|
|
48
|
+
})
|
|
49
|
+
.strict();
|
|
50
|
+
|
|
51
|
+
/** One existing subscription item; host authorization and target policy remain required. */
|
|
52
|
+
export type BillingPortalSubscriptionUpdateFlow = z.infer<typeof flow>;
|
|
53
|
+
|
|
54
|
+
// Parsing makes a bounded scalar copy before the first provider await.
|
|
55
|
+
export const billingPortalSessionOptions = z
|
|
56
|
+
.object({
|
|
57
|
+
stripeAccountId: id("acct"),
|
|
58
|
+
connectedAccountId: id("acct").optional(),
|
|
59
|
+
configurationId: id("bpc").optional(),
|
|
60
|
+
returnUrl: redirectUrl,
|
|
61
|
+
flowData: flow.optional(),
|
|
62
|
+
})
|
|
63
|
+
.strict();
|
|
64
|
+
export const targetedPortalOptions = billingPortalSessionOptions.extend({
|
|
65
|
+
flowData: flow,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export function assertTargetedPortalSubscription(
|
|
69
|
+
value: unknown,
|
|
70
|
+
options: z.infer<typeof targetedPortalOptions>,
|
|
71
|
+
): void {
|
|
72
|
+
const subscription = z
|
|
73
|
+
.object({
|
|
74
|
+
object: z.literal("subscription"),
|
|
75
|
+
id: id("sub"),
|
|
76
|
+
deleted: z.literal(false).optional(),
|
|
77
|
+
customer_account: id("acct"),
|
|
78
|
+
items: z.object({
|
|
79
|
+
has_more: z.literal(false),
|
|
80
|
+
data: z.array(z.object({ id: id("si") })).max(100),
|
|
81
|
+
}),
|
|
82
|
+
})
|
|
83
|
+
.parse(value);
|
|
84
|
+
const target = options.flowData.subscription_update_confirm;
|
|
85
|
+
if (
|
|
86
|
+
subscription.id !== target.subscription ||
|
|
87
|
+
subscription.customer_account !== options.stripeAccountId ||
|
|
88
|
+
subscription.items.data.filter((entry) => entry.id === target.items[0].id)
|
|
89
|
+
.length !== 1
|
|
90
|
+
)
|
|
91
|
+
throw new Error(
|
|
92
|
+
"The original subscription item does not belong to this customer account.",
|
|
93
|
+
);
|
|
94
|
+
if (subscription.items.data.length !== 1)
|
|
95
|
+
throw new Error(
|
|
96
|
+
"Billing Portal confirmation does not support multi-item subscriptions.",
|
|
97
|
+
);
|
|
98
|
+
}
|