@fantastic.dev/better-stripe 0.80.0 → 0.82.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/billing/renewalAggregate/configure.d.ts +35 -0
- package/dist/client/billing/renewalAggregate/configure.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/configure.js +96 -0
- package/dist/client/billing/renewalAggregate/configure.js.map +1 -0
- package/dist/client/billing/renewalAggregate/index.d.ts +3 -0
- package/dist/client/billing/renewalAggregate/index.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/index.js +3 -0
- package/dist/client/billing/renewalAggregate/index.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts +176 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js +112 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts +7 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.js +192 -0
- package/dist/client/billing/renewalAggregate/phases.js.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts +594 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.js +164 -0
- package/dist/client/billing/renewalAggregate/preflight.js.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.js +60 -0
- package/dist/client/billing/renewalAggregate/profile.js.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts +40 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.js +62 -0
- package/dist/client/billing/renewalAggregate/receipt.js.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts +51 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.js +87 -0
- package/dist/client/billing/renewalAggregate/shared.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts +42 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js +90 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts +136 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js +82 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js +23 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js.map +1 -0
- package/dist/client/billing/renewalPriceReplacement.d.ts +2 -0
- package/dist/client/billing/renewalPriceReplacement.d.ts.map +1 -1
- package/dist/client/billing/renewalProjection/discounts.d.ts +20 -0
- package/dist/client/billing/renewalProjection/discounts.d.ts.map +1 -0
- package/dist/client/billing/renewalProjection/discounts.js +121 -0
- package/dist/client/billing/renewalProjection/discounts.js.map +1 -0
- package/dist/client/billing/renewalProjection/itemSettings.d.ts +14 -0
- package/dist/client/billing/renewalProjection/itemSettings.d.ts.map +1 -0
- package/dist/client/billing/renewalProjection/itemSettings.js +41 -0
- package/dist/client/billing/renewalProjection/itemSettings.js.map +1 -0
- package/dist/client/billing/renewalProjection/settings.d.ts +18 -0
- package/dist/client/billing/renewalProjection/settings.d.ts.map +1 -0
- package/dist/client/billing/renewalProjection/settings.js +132 -0
- package/dist/client/billing/renewalProjection/settings.js.map +1 -0
- package/dist/client/billing/renewalProjection/settingsSchema.d.ts +200 -0
- package/dist/client/billing/renewalProjection/settingsSchema.d.ts.map +1 -0
- package/dist/client/billing/renewalProjection/settingsSchema.js +150 -0
- package/dist/client/billing/renewalProjection/settingsSchema.js.map +1 -0
- package/dist/client/billing/renewalReplacementSchema.d.ts +2 -0
- package/dist/client/billing/renewalReplacementSchema.d.ts.map +1 -1
- package/dist/client/billing/renewalReplacementSchema.js +10 -4
- package/dist/client/billing/renewalReplacementSchema.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- 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/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-phase-assembly.md +180 -0
- package/docs/renewal-preservation-mappings.md +94 -0
- package/docs/renewal-price-replacements.md +7 -0
- package/package.json +1 -1
- package/src/client/billing/renewal-discount-projection.test.ts +207 -0
- package/src/client/billing/renewal-item-settings-projection.test.ts +79 -0
- package/src/client/billing/renewal-price-replacement.test.ts +46 -0
- package/src/client/billing/renewal-settings-projection.test.ts +300 -0
- package/src/client/billing/renewalAggregate/configure.test.ts +372 -0
- package/src/client/billing/renewalAggregate/configure.ts +164 -0
- package/src/client/billing/renewalAggregate/index.ts +2 -0
- package/src/client/billing/renewalAggregate/phaseContext.ts +144 -0
- package/src/client/billing/renewalAggregate/phases.ts +247 -0
- package/src/client/billing/renewalAggregate/preflight.test.ts +233 -0
- package/src/client/billing/renewalAggregate/preflight.ts +211 -0
- package/src/client/billing/renewalAggregate/profile.ts +76 -0
- package/src/client/billing/renewalAggregate/receipt.ts +76 -0
- package/src/client/billing/renewalAggregate/shared.ts +106 -0
- package/src/client/billing/renewalAggregate/sourceAndTaxRetention.test.ts +247 -0
- package/src/client/billing/renewalAggregate/sourceDiscounts.ts +112 -0
- package/src/client/billing/renewalAggregate/sourceSettings.ts +88 -0
- package/src/client/billing/renewalAggregate/taxRetention.ts +28 -0
- package/src/client/billing/renewalProjection/discounts.ts +152 -0
- package/src/client/billing/renewalProjection/itemSettings.ts +55 -0
- package/src/client/billing/renewalProjection/settings.ts +163 -0
- package/src/client/billing/renewalProjection/settingsSchema.ts +154 -0
- package/src/client/billing/renewalReplacementSchema.ts +10 -4
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import * as projection from "./renewalProjection/settings.js";
|
|
3
|
+
|
|
4
|
+
const context = {
|
|
5
|
+
customerAccountId: "acct_buyer",
|
|
6
|
+
customerId: "cus_buyer",
|
|
7
|
+
livemode: false,
|
|
8
|
+
effectiveCollectionMethod: "charge_automatically",
|
|
9
|
+
effectiveAutomaticTax: false,
|
|
10
|
+
effectiveInvoiceIssuer: { type: "self" },
|
|
11
|
+
};
|
|
12
|
+
function settings() {
|
|
13
|
+
return {
|
|
14
|
+
application_fee_percent: null,
|
|
15
|
+
billing_thresholds: null,
|
|
16
|
+
collection_method: null,
|
|
17
|
+
default_payment_method: null,
|
|
18
|
+
on_behalf_of: null,
|
|
19
|
+
transfer_data: null,
|
|
20
|
+
automatic_tax: { enabled: false, liability: null, disabled_reason: null },
|
|
21
|
+
default_tax_rates: [],
|
|
22
|
+
invoice_settings: {
|
|
23
|
+
account_tax_ids: null,
|
|
24
|
+
custom_fields: null,
|
|
25
|
+
days_until_due: null,
|
|
26
|
+
description: null,
|
|
27
|
+
footer: null,
|
|
28
|
+
issuer: null,
|
|
29
|
+
},
|
|
30
|
+
description: null,
|
|
31
|
+
metadata: null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const project = (value: unknown) =>
|
|
35
|
+
projection.projectRenewalPhaseSettings({
|
|
36
|
+
context,
|
|
37
|
+
settings: value,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("maps disabled tax and explicit empty rates without inventing null writes", () => {
|
|
41
|
+
expect(project(settings())).toEqual({
|
|
42
|
+
status: "projected",
|
|
43
|
+
settings: { automatic_tax: { enabled: false }, default_tax_rates: "" },
|
|
44
|
+
requiresProviderQualification: true,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("maps exact routing, descriptions and nonempty metadata without mutating reads", () => {
|
|
49
|
+
const value = {
|
|
50
|
+
...settings(),
|
|
51
|
+
on_behalf_of: { id: "acct_issuer", object: "account" },
|
|
52
|
+
transfer_data: { destination: "acct_destination", amount_percent: 0 },
|
|
53
|
+
description: "",
|
|
54
|
+
metadata: { original: "retained" },
|
|
55
|
+
};
|
|
56
|
+
const before = structuredClone(value);
|
|
57
|
+
expect(project(value)).toMatchObject({
|
|
58
|
+
status: "projected",
|
|
59
|
+
settings: {
|
|
60
|
+
on_behalf_of: "acct_issuer",
|
|
61
|
+
transfer_data: { destination: "acct_destination", amount_percent: 0 },
|
|
62
|
+
description: "",
|
|
63
|
+
metadata: { original: "retained" },
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
expect(value).toEqual(before);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("omits a null transfer percentage rather than fabricating full-transfer values", () => {
|
|
70
|
+
expect(
|
|
71
|
+
project({
|
|
72
|
+
...settings(),
|
|
73
|
+
transfer_data: {
|
|
74
|
+
destination: "acct_destination",
|
|
75
|
+
amount_percent: null,
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
).toMatchObject({
|
|
79
|
+
status: "projected",
|
|
80
|
+
settings: {
|
|
81
|
+
transfer_data: { destination: "acct_destination" },
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it.each([
|
|
87
|
+
[0, "projected"],
|
|
88
|
+
[0.01, "projected"],
|
|
89
|
+
[0.29, "projected"],
|
|
90
|
+
[99.99, "projected"],
|
|
91
|
+
[100, "projected"],
|
|
92
|
+
[0.001, "unsupported"],
|
|
93
|
+
[1.234, "unsupported"],
|
|
94
|
+
] as const)(
|
|
95
|
+
"qualifies exact transfer percentage precision %s",
|
|
96
|
+
(amount_percent, status) => {
|
|
97
|
+
expect(
|
|
98
|
+
project({
|
|
99
|
+
...settings(),
|
|
100
|
+
transfer_data: {
|
|
101
|
+
destination: "acct_destination",
|
|
102
|
+
amount_percent,
|
|
103
|
+
},
|
|
104
|
+
}).status,
|
|
105
|
+
).toBe(status);
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
it.each([
|
|
110
|
+
{ application_fee_percent: 0 },
|
|
111
|
+
{ billing_thresholds: { amount_gte: 100 } },
|
|
112
|
+
{ collection_method: "future_mode" },
|
|
113
|
+
{ on_behalf_of: { id: "acct_issuer", object: "account", deleted: true } },
|
|
114
|
+
{
|
|
115
|
+
default_payment_method: {
|
|
116
|
+
id: "pm_existing",
|
|
117
|
+
object: "payment_method",
|
|
118
|
+
customer: "cus_foreign",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
automatic_tax: {
|
|
123
|
+
enabled: false,
|
|
124
|
+
disabled_reason: "requires_location_inputs",
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
automatic_tax: {
|
|
129
|
+
enabled: true,
|
|
130
|
+
liability: { type: "account", account: null },
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{ metadata: { remove: "" } },
|
|
134
|
+
{ future_setting: true },
|
|
135
|
+
])("rejects incomplete or unqualified settings %j", (extra) => {
|
|
136
|
+
expect(project({ ...settings(), ...extra }).status).toBe("unsupported");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("rejects manual tax alongside enabled automatic tax", () => {
|
|
140
|
+
expect(
|
|
141
|
+
project({
|
|
142
|
+
...settings(),
|
|
143
|
+
automatic_tax: { enabled: true },
|
|
144
|
+
default_tax_rates: [
|
|
145
|
+
{ id: "txr_existing", object: "tax_rate", livemode: false },
|
|
146
|
+
],
|
|
147
|
+
}).status,
|
|
148
|
+
).toBe("unsupported");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("rejects manual tax inherited alongside automatic tax from unchanged defaults", () => {
|
|
152
|
+
const value = settings();
|
|
153
|
+
const { automatic_tax: _, ...rest } = value;
|
|
154
|
+
expect(
|
|
155
|
+
projection.projectRenewalPhaseSettings({
|
|
156
|
+
context: { ...context, effectiveAutomaticTax: true },
|
|
157
|
+
settings: {
|
|
158
|
+
...rest,
|
|
159
|
+
default_tax_rates: [
|
|
160
|
+
{ id: "txr_existing", object: "tax_rate", livemode: false },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
}).status,
|
|
164
|
+
).toBe("unsupported");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("maps account tax liability and preserves invoice tax IDs in order", () => {
|
|
168
|
+
const value = settings();
|
|
169
|
+
expect(
|
|
170
|
+
projection.projectRenewalPhaseSettings({
|
|
171
|
+
context: { ...context, effectiveAutomaticTax: true },
|
|
172
|
+
settings: {
|
|
173
|
+
...value,
|
|
174
|
+
automatic_tax: {
|
|
175
|
+
enabled: true,
|
|
176
|
+
liability: { type: "account", account: "acct_liable" },
|
|
177
|
+
},
|
|
178
|
+
invoice_settings: {
|
|
179
|
+
...value.invoice_settings,
|
|
180
|
+
account_tax_ids: [
|
|
181
|
+
{
|
|
182
|
+
id: "txi_first",
|
|
183
|
+
object: "tax_id",
|
|
184
|
+
livemode: false,
|
|
185
|
+
customer: null,
|
|
186
|
+
customer_account: null,
|
|
187
|
+
owner: { type: "self", customer_account: null },
|
|
188
|
+
},
|
|
189
|
+
"txi_second",
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
}),
|
|
194
|
+
).toMatchObject({
|
|
195
|
+
status: "projected",
|
|
196
|
+
settings: {
|
|
197
|
+
automatic_tax: {
|
|
198
|
+
enabled: true,
|
|
199
|
+
liability: { type: "account", account: "acct_liable" },
|
|
200
|
+
},
|
|
201
|
+
invoice_settings: { account_tax_ids: ["txi_first", "txi_second"] },
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("rejects a tax reference from the wrong mode", () => {
|
|
207
|
+
expect(
|
|
208
|
+
project({
|
|
209
|
+
...settings(),
|
|
210
|
+
default_tax_rates: [
|
|
211
|
+
{ id: "txr_live", object: "tax_rate", livemode: true },
|
|
212
|
+
],
|
|
213
|
+
}).status,
|
|
214
|
+
).toBe("unsupported");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it.each([{ livemode: true }, { customer_account: "acct_foreign" }])(
|
|
218
|
+
"rejects contradictory nested payment-method customer facts %j",
|
|
219
|
+
(extra) => {
|
|
220
|
+
expect(
|
|
221
|
+
project({
|
|
222
|
+
...settings(),
|
|
223
|
+
default_payment_method: {
|
|
224
|
+
id: "pm_existing",
|
|
225
|
+
object: "payment_method",
|
|
226
|
+
livemode: false,
|
|
227
|
+
customer: { id: "cus_buyer", object: "customer", ...extra },
|
|
228
|
+
},
|
|
229
|
+
}).status,
|
|
230
|
+
).toBe("unsupported");
|
|
231
|
+
},
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
it.each([
|
|
235
|
+
undefined,
|
|
236
|
+
{ type: "account", account: "acct_foreign", customer_account: null },
|
|
237
|
+
{ type: "customer", customer: "cus_buyer", customer_account: "acct_buyer" },
|
|
238
|
+
])("rejects unqualified invoice tax ownership %j", (owner) => {
|
|
239
|
+
const value = settings();
|
|
240
|
+
const tax = {
|
|
241
|
+
id: "txi_existing",
|
|
242
|
+
object: "tax_id",
|
|
243
|
+
livemode: false,
|
|
244
|
+
...(owner === undefined ? {} : { owner }),
|
|
245
|
+
};
|
|
246
|
+
expect(
|
|
247
|
+
project({
|
|
248
|
+
...value,
|
|
249
|
+
invoice_settings: {
|
|
250
|
+
...value.invoice_settings,
|
|
251
|
+
account_tax_ids: [tax],
|
|
252
|
+
},
|
|
253
|
+
}).status,
|
|
254
|
+
).toBe("unsupported");
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("maps invoice Emptyables, an explicit issuer and zero-day send_invoice terms", () => {
|
|
258
|
+
expect(
|
|
259
|
+
projection.projectRenewalPhaseSettings({
|
|
260
|
+
context: { ...context, effectiveCollectionMethod: "send_invoice" },
|
|
261
|
+
settings: {
|
|
262
|
+
...settings(),
|
|
263
|
+
collection_method: "send_invoice",
|
|
264
|
+
invoice_settings: {
|
|
265
|
+
account_tax_ids: [],
|
|
266
|
+
custom_fields: [],
|
|
267
|
+
days_until_due: 0,
|
|
268
|
+
description: "",
|
|
269
|
+
footer: "original footer",
|
|
270
|
+
issuer: { type: "self" },
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
}),
|
|
274
|
+
).toMatchObject({
|
|
275
|
+
status: "projected",
|
|
276
|
+
settings: {
|
|
277
|
+
invoice_settings: {
|
|
278
|
+
account_tax_ids: "",
|
|
279
|
+
custom_fields: "",
|
|
280
|
+
days_until_due: 0,
|
|
281
|
+
description: "",
|
|
282
|
+
footer: "original footer",
|
|
283
|
+
issuer: { type: "self" },
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("rejects due days for charge_automatically", () => {
|
|
290
|
+
const value = settings();
|
|
291
|
+
expect(
|
|
292
|
+
project({
|
|
293
|
+
...value,
|
|
294
|
+
invoice_settings: {
|
|
295
|
+
...value.invoice_settings,
|
|
296
|
+
days_until_due: 3,
|
|
297
|
+
},
|
|
298
|
+
}).status,
|
|
299
|
+
).toBe("unsupported");
|
|
300
|
+
});
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import { projectRenewalConfiguration } from "./index.js";
|
|
3
|
+
import { alter, fixture } from "../../../../tests/renewalAggregate/fixtures.js";
|
|
4
|
+
|
|
5
|
+
it("projects the exact current paid phase and target phase without default writes", () => {
|
|
6
|
+
const f = fixture();
|
|
7
|
+
const before = structuredClone(f.configureInput);
|
|
8
|
+
const result = projectRenewalConfiguration(f.configureInput);
|
|
9
|
+
expect(result).toMatchObject({
|
|
10
|
+
version: 1,
|
|
11
|
+
stage: "configure",
|
|
12
|
+
scope: "platform",
|
|
13
|
+
status: "projected_configure_request",
|
|
14
|
+
providerQualification: "required",
|
|
15
|
+
apiVersion: "2026-09-30.endive",
|
|
16
|
+
scheduleId: "sub_sched_owned",
|
|
17
|
+
attachReceiptBinding: f.attachReceipt.binding,
|
|
18
|
+
baselineBinding: expect.any(String),
|
|
19
|
+
defaultSettingsBinding: expect.any(String),
|
|
20
|
+
firstDispatchedAt: f.configureInput.firstDispatchedAt,
|
|
21
|
+
requestIdentity: {
|
|
22
|
+
key: "renewal:configure-original",
|
|
23
|
+
binding: expect.any(String),
|
|
24
|
+
},
|
|
25
|
+
payload: {
|
|
26
|
+
end_behavior: "release",
|
|
27
|
+
proration_behavior: "none",
|
|
28
|
+
phases: [
|
|
29
|
+
{
|
|
30
|
+
start_date: f.prepared.expected.periodStart,
|
|
31
|
+
end_date: f.prepared.expected.periodEnd,
|
|
32
|
+
currency: "usd",
|
|
33
|
+
items: [
|
|
34
|
+
{
|
|
35
|
+
price: "price_original",
|
|
36
|
+
quantity: 3,
|
|
37
|
+
tax_rates: "",
|
|
38
|
+
discounts: [{ discount: "di_item" }],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
default_tax_rates: "",
|
|
42
|
+
discounts: [{ discount: "di_subscription" }],
|
|
43
|
+
proration_behavior: "create_prorations",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
start_date: f.prepared.expected.periodEnd,
|
|
47
|
+
duration: { interval: "month", interval_count: 1 },
|
|
48
|
+
billing_cycle_anchor: "automatic",
|
|
49
|
+
currency: "usd",
|
|
50
|
+
items: [
|
|
51
|
+
{
|
|
52
|
+
price: "price_target",
|
|
53
|
+
quantity: 3,
|
|
54
|
+
tax_rates: "",
|
|
55
|
+
discounts: [{ discount: "di_item" }],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
default_tax_rates: "",
|
|
59
|
+
discounts: [{ discount: "di_subscription" }],
|
|
60
|
+
proration_behavior: "none",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
expect(result).not.toHaveProperty("payload.default_settings");
|
|
66
|
+
expect(result).not.toHaveProperty("payload.phases.1.end_date");
|
|
67
|
+
expect(result).not.toHaveProperty("payload.phases.0.items.0.plan");
|
|
68
|
+
expect(result).not.toHaveProperty("payload.phases.1.items.0.id");
|
|
69
|
+
for (const phase of [0, 1]) {
|
|
70
|
+
expect(result).not.toHaveProperty(
|
|
71
|
+
`payload.phases.${phase}.discounts.0.coupon`,
|
|
72
|
+
);
|
|
73
|
+
expect(result).not.toHaveProperty(
|
|
74
|
+
`payload.phases.${phase}.discounts.0.promotion_code`,
|
|
75
|
+
);
|
|
76
|
+
expect(result).not.toHaveProperty(
|
|
77
|
+
`payload.phases.${phase}.items.0.discounts.0.coupon`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
expect(f.configureInput).toEqual(before);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it.each(["none", "always_invoice", "create_prorations"])(
|
|
84
|
+
"preserves acknowledged current phase proration mode %s",
|
|
85
|
+
(proration_behavior) => {
|
|
86
|
+
expect(
|
|
87
|
+
projectRenewalConfiguration(
|
|
88
|
+
fixture({ phase: { proration_behavior } }).configureInput,
|
|
89
|
+
),
|
|
90
|
+
).toMatchObject({
|
|
91
|
+
status: "projected_configure_request",
|
|
92
|
+
payload: {
|
|
93
|
+
proration_behavior: "none",
|
|
94
|
+
phases: [{ proration_behavior }, { proration_behavior: "none" }],
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
it("binds the explicit configure key without reusing the attach key", () => {
|
|
101
|
+
const f = fixture();
|
|
102
|
+
const first = projectRenewalConfiguration(f.configureInput);
|
|
103
|
+
const second = projectRenewalConfiguration({
|
|
104
|
+
...f.configureInput,
|
|
105
|
+
configureKey: "renewal:configure-other",
|
|
106
|
+
});
|
|
107
|
+
expect(first).toMatchObject({ status: "projected_configure_request" });
|
|
108
|
+
expect(second).toMatchObject({ status: "projected_configure_request" });
|
|
109
|
+
if (
|
|
110
|
+
first.status !== "projected_configure_request" ||
|
|
111
|
+
second.status !== "projected_configure_request"
|
|
112
|
+
)
|
|
113
|
+
return;
|
|
114
|
+
expect(first.payload).toEqual(second.payload);
|
|
115
|
+
expect(first.requestIdentity.binding).not.toBe(
|
|
116
|
+
second.requestIdentity.binding,
|
|
117
|
+
);
|
|
118
|
+
expect(
|
|
119
|
+
projectRenewalConfiguration({
|
|
120
|
+
...f.configureInput,
|
|
121
|
+
configureKey: f.attachRequest.requestIdentity.key,
|
|
122
|
+
}).status,
|
|
123
|
+
).not.toBe("projected_configure_request");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("uses the provider-verified renewal and a changed-cadence phase-start anchor", () => {
|
|
127
|
+
const f = fixture({ targetInterval: "year" });
|
|
128
|
+
const result = projectRenewalConfiguration(f.configureInput);
|
|
129
|
+
expect(result).toMatchObject({
|
|
130
|
+
status: "projected_configure_request",
|
|
131
|
+
profile: { cadence: "changed" },
|
|
132
|
+
providerQualification: "required",
|
|
133
|
+
payload: {
|
|
134
|
+
phases: [
|
|
135
|
+
expect.any(Object),
|
|
136
|
+
{
|
|
137
|
+
start_date: f.prepared.expected.periodEnd,
|
|
138
|
+
duration: { interval: "year", interval_count: 1 },
|
|
139
|
+
billing_cycle_anchor: "phase_start",
|
|
140
|
+
proration_behavior: "none",
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("validates the actual post-attach association instead of pretending schedule is null", () => {
|
|
148
|
+
const input = fixture().configureInput;
|
|
149
|
+
expect(projectRenewalConfiguration(input).status).toBe(
|
|
150
|
+
"projected_configure_request",
|
|
151
|
+
);
|
|
152
|
+
const result = projectRenewalConfiguration(
|
|
153
|
+
alter(input, ["freshSubscription", "schedule"], null),
|
|
154
|
+
);
|
|
155
|
+
expect(result).toMatchObject({
|
|
156
|
+
status: "conflict",
|
|
157
|
+
reason: expect.stringMatching(/schedule|association/i),
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it.each(
|
|
162
|
+
[
|
|
163
|
+
["request", "payload", "from_subscription"],
|
|
164
|
+
["providerSnapshot", "default_settings", "description"],
|
|
165
|
+
["binding"],
|
|
166
|
+
].map((path) => ({ path })),
|
|
167
|
+
)("rejects altered retained acknowledgement at %j", ({ path }) => {
|
|
168
|
+
const next = alter(
|
|
169
|
+
fixture().configureInput,
|
|
170
|
+
["attachReceipt", ...path],
|
|
171
|
+
"forged",
|
|
172
|
+
);
|
|
173
|
+
expect(projectRenewalConfiguration(next)).toMatchObject({
|
|
174
|
+
status: "conflict",
|
|
175
|
+
reason: expect.stringMatching(/binding|receipt|acknowledg/i),
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it.each(
|
|
180
|
+
[
|
|
181
|
+
["default_settings", "description"],
|
|
182
|
+
["phases", 0, "items", 0, "quantity"],
|
|
183
|
+
["current_phase", "end_date"],
|
|
184
|
+
].map((path) => ({ path })),
|
|
185
|
+
)("rejects fresh acknowledged-baseline drift at %j", ({ path }) => {
|
|
186
|
+
const result = projectRenewalConfiguration(
|
|
187
|
+
alter(
|
|
188
|
+
fixture().configureInput,
|
|
189
|
+
["schedule", ...path],
|
|
190
|
+
path[path.length - 1] === "description" ? "changed" : 999,
|
|
191
|
+
),
|
|
192
|
+
);
|
|
193
|
+
expect(result).toMatchObject({
|
|
194
|
+
status: "conflict",
|
|
195
|
+
reason: expect.stringMatching(/baseline|default|drift|period|phase/i),
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("does not adopt unrelated extra future phases or release them as a workaround", () => {
|
|
200
|
+
const f = fixture();
|
|
201
|
+
const result = projectRenewalConfiguration(
|
|
202
|
+
alter(
|
|
203
|
+
f.configureInput,
|
|
204
|
+
["schedule", "phases"],
|
|
205
|
+
[
|
|
206
|
+
...f.schedule.phases,
|
|
207
|
+
{
|
|
208
|
+
...f.schedule.phases[0],
|
|
209
|
+
start_date: f.prepared.expected.periodEnd,
|
|
210
|
+
end_date: f.prepared.expected.periodEnd + 100,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
),
|
|
214
|
+
);
|
|
215
|
+
expect(result.status).toBe("conflict");
|
|
216
|
+
expect(result).not.toHaveProperty("payload");
|
|
217
|
+
expect(result).not.toHaveProperty("releaseRequest");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("keeps an acknowledged schedule partial when a paid-term mapping is unsupported", () => {
|
|
221
|
+
const f = fixture({
|
|
222
|
+
phase: { add_invoice_items: [{ price: "price_extra" }] },
|
|
223
|
+
});
|
|
224
|
+
expect(projectRenewalConfiguration(f.configureInput)).toMatchObject({
|
|
225
|
+
status: "attached_unconfigured",
|
|
226
|
+
scheduleId: "sub_sched_owned",
|
|
227
|
+
reason: expect.stringMatching(/invoice|unsupported|mapping/i),
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("rejects unknown defaults even though the request would leave defaults untouched", () => {
|
|
232
|
+
const f = fixture({ defaults: { future_unmapped_setting: true } });
|
|
233
|
+
expect(projectRenewalConfiguration(f.configureInput)).toMatchObject({
|
|
234
|
+
status: "attached_unconfigured",
|
|
235
|
+
reason: expect.stringMatching(/default|unsupported|unknown/i),
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("rejects resetting a current phase-start anchor away from the original anchor", () => {
|
|
240
|
+
const f = fixture({
|
|
241
|
+
subscription: { billing_cycle_anchor: 1765756800 },
|
|
242
|
+
phase: { billing_cycle_anchor: "phase_start" },
|
|
243
|
+
});
|
|
244
|
+
expect(projectRenewalConfiguration(f.configureInput)).toMatchObject({
|
|
245
|
+
status: "attached_unconfigured",
|
|
246
|
+
reason: expect.stringMatching(/anchor/i),
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("copies only acknowledged metadata actions that already match current terms", () => {
|
|
251
|
+
const f = fixture({
|
|
252
|
+
subscription: {
|
|
253
|
+
metadata: {
|
|
254
|
+
keep: "original",
|
|
255
|
+
unrelated: "do-not-turn-into-a-phase-action",
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
phase: { metadata: { keep: "original" } },
|
|
259
|
+
phaseItem: { metadata: { seat: "retained" } },
|
|
260
|
+
});
|
|
261
|
+
const result = projectRenewalConfiguration(f.configureInput);
|
|
262
|
+
expect(result).toMatchObject({
|
|
263
|
+
status: "projected_configure_request",
|
|
264
|
+
payload: {
|
|
265
|
+
phases: [
|
|
266
|
+
expect.any(Object),
|
|
267
|
+
{
|
|
268
|
+
metadata: { keep: "original" },
|
|
269
|
+
items: [{ metadata: { seat: "retained" } }],
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
expect(result).not.toHaveProperty("payload.phases.1.metadata.unrelated");
|
|
275
|
+
const conflict = fixture({ phase: { metadata: { keep: "overwrite" } } });
|
|
276
|
+
const rejected = projectRenewalConfiguration(conflict.configureInput);
|
|
277
|
+
expect(rejected.status).not.toBe("projected_configure_request");
|
|
278
|
+
expect(rejected).toHaveProperty(
|
|
279
|
+
"reason",
|
|
280
|
+
expect.stringMatching(/metadata|conflict/i),
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("rejects manual phase rates under effective automatic tax inherited from defaults", () => {
|
|
285
|
+
const automatic = { enabled: true, liability: null, disabled_reason: null };
|
|
286
|
+
const f = fixture({
|
|
287
|
+
subscription: { automatic_tax: automatic },
|
|
288
|
+
defaults: { automatic_tax: automatic },
|
|
289
|
+
phase: {
|
|
290
|
+
default_tax_rates: [
|
|
291
|
+
{ id: "txr_manual", object: "tax_rate", livemode: false },
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
expect(projectRenewalConfiguration(f.configureInput)).toMatchObject({
|
|
296
|
+
status: "attached_unconfigured",
|
|
297
|
+
reason: expect.stringMatching(/tax/i),
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("rejects a future first-dispatch time instead of resetting retained time", () => {
|
|
302
|
+
const f = fixture();
|
|
303
|
+
const result = projectRenewalConfiguration({
|
|
304
|
+
...f.configureInput,
|
|
305
|
+
firstDispatchedAt: f.configureInput.observedAt + 1,
|
|
306
|
+
});
|
|
307
|
+
expect(result.status).not.toBe("projected_configure_request");
|
|
308
|
+
expect(result).toHaveProperty(
|
|
309
|
+
"reason",
|
|
310
|
+
expect.stringMatching(/time|dispatch/i),
|
|
311
|
+
);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it.each([
|
|
315
|
+
{ price: { id: "price_original", object: "price", livemode: true } },
|
|
316
|
+
{
|
|
317
|
+
price: {
|
|
318
|
+
id: "price_original",
|
|
319
|
+
object: "price",
|
|
320
|
+
product: "foreign-product",
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
{ plan: { id: "price_original", object: "plan", livemode: true } },
|
|
324
|
+
])("rejects contradictory expanded phase price/plan facts %j", (phaseItem) => {
|
|
325
|
+
const f = fixture({ phaseItem });
|
|
326
|
+
expect(projectRenewalConfiguration(f.configureInput).status).not.toBe(
|
|
327
|
+
"projected_configure_request",
|
|
328
|
+
);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("rejects an inherited tax liability that contradicts the original effective liability", () => {
|
|
332
|
+
const f = fixture({
|
|
333
|
+
subscription: {
|
|
334
|
+
automatic_tax: {
|
|
335
|
+
enabled: true,
|
|
336
|
+
liability: { type: "self" },
|
|
337
|
+
disabled_reason: null,
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
defaults: {
|
|
341
|
+
automatic_tax: {
|
|
342
|
+
enabled: true,
|
|
343
|
+
liability: { type: "account", account: "acct_other" },
|
|
344
|
+
disabled_reason: null,
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
expect(projectRenewalConfiguration(f.configureInput).status).not.toBe(
|
|
349
|
+
"projected_configure_request",
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("rejects invoice tax IDs that contradict the current subscription's invoice settings", () => {
|
|
354
|
+
const base = fixture();
|
|
355
|
+
const f = fixture({
|
|
356
|
+
subscription: {
|
|
357
|
+
invoice_settings: {
|
|
358
|
+
...base.subscription.invoice_settings,
|
|
359
|
+
account_tax_ids: ["txi_original"],
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
defaults: {
|
|
363
|
+
invoice_settings: {
|
|
364
|
+
...base.schedule.default_settings.invoice_settings,
|
|
365
|
+
account_tax_ids: ["txi_other"],
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
expect(projectRenewalConfiguration(f.configureInput).status).not.toBe(
|
|
370
|
+
"projected_configure_request",
|
|
371
|
+
);
|
|
372
|
+
});
|