@fantastic.dev/better-stripe 0.80.0 → 0.81.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 +6 -0
- package/README.md +1 -1
- 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/docs/renewal-preservation-mappings.md +94 -0
- package/docs/renewal-price-replacements.md +5 -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/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,150 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const id = (prefix) => z
|
|
3
|
+
.string()
|
|
4
|
+
.max(255)
|
|
5
|
+
.regex(new RegExp(`^${prefix}_[A-Za-z0-9_]+$`));
|
|
6
|
+
export const reference = (prefix, object) => z.union([
|
|
7
|
+
id(prefix),
|
|
8
|
+
z
|
|
9
|
+
.object({
|
|
10
|
+
id: id(prefix),
|
|
11
|
+
object: z.literal(object),
|
|
12
|
+
deleted: z.literal(false).optional(),
|
|
13
|
+
livemode: z.boolean().optional(),
|
|
14
|
+
customer: z
|
|
15
|
+
.union([
|
|
16
|
+
id("cus"),
|
|
17
|
+
z
|
|
18
|
+
.object({
|
|
19
|
+
id: id("cus"),
|
|
20
|
+
object: z.literal("customer"),
|
|
21
|
+
deleted: z.literal(false).optional(),
|
|
22
|
+
livemode: z.boolean().optional(),
|
|
23
|
+
customer_account: id("acct").nullable().optional(),
|
|
24
|
+
})
|
|
25
|
+
.passthrough(),
|
|
26
|
+
])
|
|
27
|
+
.nullable()
|
|
28
|
+
.optional(),
|
|
29
|
+
customer_account: id("acct").nullable().optional(),
|
|
30
|
+
})
|
|
31
|
+
.passthrough(),
|
|
32
|
+
]);
|
|
33
|
+
const account = reference("acct", "account");
|
|
34
|
+
const issuer = z.discriminatedUnion("type", [
|
|
35
|
+
z.object({ type: z.literal("self"), account: z.null().optional() }).strict(),
|
|
36
|
+
z.object({ type: z.literal("account"), account }).strict(),
|
|
37
|
+
]);
|
|
38
|
+
const invoiceTaxId = z.union([
|
|
39
|
+
id("txi"),
|
|
40
|
+
z
|
|
41
|
+
.object({
|
|
42
|
+
id: id("txi"),
|
|
43
|
+
object: z.literal("tax_id"),
|
|
44
|
+
deleted: z.literal(false).optional(),
|
|
45
|
+
livemode: z.boolean(),
|
|
46
|
+
customer: z.null().optional(),
|
|
47
|
+
customer_account: z.null().optional(),
|
|
48
|
+
owner: z.discriminatedUnion("type", [
|
|
49
|
+
z
|
|
50
|
+
.object({
|
|
51
|
+
type: z.literal("self"),
|
|
52
|
+
customer_account: z.null(),
|
|
53
|
+
account: z.null().optional(),
|
|
54
|
+
customer: z.null().optional(),
|
|
55
|
+
})
|
|
56
|
+
.strict(),
|
|
57
|
+
z
|
|
58
|
+
.object({
|
|
59
|
+
type: z.literal("account"),
|
|
60
|
+
account,
|
|
61
|
+
customer_account: z.null(),
|
|
62
|
+
customer: z.null().optional(),
|
|
63
|
+
})
|
|
64
|
+
.strict(),
|
|
65
|
+
]),
|
|
66
|
+
})
|
|
67
|
+
.passthrough(),
|
|
68
|
+
]);
|
|
69
|
+
export const taxRate = z
|
|
70
|
+
.object({
|
|
71
|
+
id: id("txr"),
|
|
72
|
+
object: z.literal("tax_rate"),
|
|
73
|
+
deleted: z.literal(false).optional(),
|
|
74
|
+
livemode: z.boolean(),
|
|
75
|
+
})
|
|
76
|
+
.passthrough();
|
|
77
|
+
const string = z.string().max(5000);
|
|
78
|
+
export const settingsInput = z
|
|
79
|
+
.object({
|
|
80
|
+
context: z
|
|
81
|
+
.object({
|
|
82
|
+
customerAccountId: id("acct"),
|
|
83
|
+
customerId: id("cus"),
|
|
84
|
+
livemode: z.boolean(),
|
|
85
|
+
effectiveCollectionMethod: z.enum([
|
|
86
|
+
"charge_automatically",
|
|
87
|
+
"send_invoice",
|
|
88
|
+
]),
|
|
89
|
+
effectiveAutomaticTax: z.boolean(),
|
|
90
|
+
effectiveInvoiceIssuer: issuer,
|
|
91
|
+
})
|
|
92
|
+
.strict(),
|
|
93
|
+
settings: z
|
|
94
|
+
.object({
|
|
95
|
+
application_fee_percent: z.null(),
|
|
96
|
+
billing_thresholds: z.null(),
|
|
97
|
+
collection_method: z
|
|
98
|
+
.enum(["charge_automatically", "send_invoice"])
|
|
99
|
+
.nullable(),
|
|
100
|
+
default_payment_method: reference("pm", "payment_method").nullable(),
|
|
101
|
+
on_behalf_of: account.nullable(),
|
|
102
|
+
transfer_data: z
|
|
103
|
+
.object({
|
|
104
|
+
destination: account,
|
|
105
|
+
amount_percent: z
|
|
106
|
+
.number()
|
|
107
|
+
.min(0)
|
|
108
|
+
.max(100)
|
|
109
|
+
.multipleOf(0.01)
|
|
110
|
+
.nullable(),
|
|
111
|
+
})
|
|
112
|
+
.strict()
|
|
113
|
+
.nullable(),
|
|
114
|
+
automatic_tax: z
|
|
115
|
+
.object({
|
|
116
|
+
enabled: z.boolean(),
|
|
117
|
+
liability: issuer.nullable().optional(),
|
|
118
|
+
disabled_reason: z.null().optional(),
|
|
119
|
+
})
|
|
120
|
+
.strict()
|
|
121
|
+
.optional(),
|
|
122
|
+
default_tax_rates: z.array(taxRate).max(20).nullable().optional(),
|
|
123
|
+
invoice_settings: z
|
|
124
|
+
.object({
|
|
125
|
+
account_tax_ids: z.array(invoiceTaxId).max(20).nullable(),
|
|
126
|
+
custom_fields: z
|
|
127
|
+
.array(z
|
|
128
|
+
.object({
|
|
129
|
+
name: z.string().max(40),
|
|
130
|
+
value: z.string().max(140),
|
|
131
|
+
})
|
|
132
|
+
.strict())
|
|
133
|
+
.max(4)
|
|
134
|
+
.nullable(),
|
|
135
|
+
days_until_due: z.number().int().nonnegative().max(3650).nullable(),
|
|
136
|
+
description: string.nullable(),
|
|
137
|
+
footer: string.nullable(),
|
|
138
|
+
issuer: issuer.nullable(),
|
|
139
|
+
})
|
|
140
|
+
.strict()
|
|
141
|
+
.nullable(),
|
|
142
|
+
description: string.nullable(),
|
|
143
|
+
metadata: z
|
|
144
|
+
.record(z.string().max(40), z.string().min(1).max(500))
|
|
145
|
+
.nullable(),
|
|
146
|
+
})
|
|
147
|
+
.strict(),
|
|
148
|
+
})
|
|
149
|
+
.strict();
|
|
150
|
+
//# sourceMappingURL=settingsSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settingsSchema.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalProjection/settingsSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,EAAE,GAAG,CAAC,MAAc,EAAE,EAAE,CAC5B,CAAC;KACE,MAAM,EAAE;KACR,GAAG,CAAC,GAAG,CAAC;KACR,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,iBAAiB,CAAC,CAAC,CAAC;AACpD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,EAAE,CAC1D,CAAC,CAAC,KAAK,CAAC;IACN,EAAE,CAAC,MAAM,CAAC;IACV,CAAC;SACE,MAAM,CAAC;QACN,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC;QACd,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QACzB,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;QACpC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAChC,QAAQ,EAAE,CAAC;aACR,KAAK,CAAC;YACL,EAAE,CAAC,KAAK,CAAC;YACT,CAAC;iBACE,MAAM,CAAC;gBACN,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC;gBACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;gBAC7B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;gBACpC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;gBAChC,gBAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;aACnD,CAAC;iBACD,WAAW,EAAE;SACjB,CAAC;aACD,QAAQ,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AAC;gBACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;gBACxB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC;aAC3B,CAAC;iBACD,MAAM,EAAE,CACZ;iBACA,GAAG,CAAC,CAAC,CAAC;iBACN,QAAQ,EAAE;YACb,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;YACnE,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE;YAC9B,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;YACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;SAC1B,CAAC;aACD,MAAM,EAAE;aACR,QAAQ,EAAE;QACb,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE;QAC9B,QAAQ,EAAE,CAAC;aACR,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;aACtD,QAAQ,EAAE;KACd,CAAC;SACD,MAAM,EAAE;CACZ,CAAC;KACD,MAAM,EAAE,CAAC"}
|
|
@@ -4,6 +4,7 @@ export declare const renewalPrice: z.ZodObject<{
|
|
|
4
4
|
object: z.ZodLiteral<"price">;
|
|
5
5
|
product: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
6
6
|
id: z.ZodString;
|
|
7
|
+
object: z.ZodLiteral<"product">;
|
|
7
8
|
deleted: z.ZodOptional<z.ZodLiteral<false>>;
|
|
8
9
|
}, z.core.$loose>]>;
|
|
9
10
|
active: z.ZodBoolean;
|
|
@@ -68,6 +69,7 @@ export declare const renewalSubscription: z.ZodObject<{
|
|
|
68
69
|
object: z.ZodLiteral<"price">;
|
|
69
70
|
product: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
70
71
|
id: z.ZodString;
|
|
72
|
+
object: z.ZodLiteral<"product">;
|
|
71
73
|
deleted: z.ZodOptional<z.ZodLiteral<false>>;
|
|
72
74
|
}, z.core.$loose>]>;
|
|
73
75
|
active: z.ZodBoolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renewalReplacementSchema.d.ts","sourceRoot":"","sources":["../../../src/client/billing/renewalReplacementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"renewalReplacementSchema.d.ts","sourceRoot":"","sources":["../../../src/client/billing/renewalReplacementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoBxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;iBAkBT,CAAC;AAEjB,eAAO,MAAM,eAAe;;;;;;;;;;;kBAc6C,CAAC;AAE1E,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6ChB,CAAC;AAEjB,yFAAyF;AACzF,MAAM,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9E,eAAO,MAAM,sBAAsB;;;;;;;;;;;iBAkBnB,CAAC;AAEjB,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;kBAQzB,CAAC"}
|
|
@@ -4,10 +4,16 @@ const id = (prefix) => z
|
|
|
4
4
|
.max(255)
|
|
5
5
|
.regex(new RegExp(`^${prefix}_[A-Za-z0-9_]+$`));
|
|
6
6
|
const integer = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
7
|
+
// Stripe allows caller-supplied product IDs, including IDs without prod_.
|
|
8
|
+
const productId = z.string().min(1).max(255).regex(/\S/);
|
|
7
9
|
const product = z.union([
|
|
8
|
-
|
|
10
|
+
productId,
|
|
9
11
|
z
|
|
10
|
-
.object({
|
|
12
|
+
.object({
|
|
13
|
+
id: productId,
|
|
14
|
+
object: z.literal("product"),
|
|
15
|
+
deleted: z.literal(false).optional(),
|
|
16
|
+
})
|
|
11
17
|
.passthrough(),
|
|
12
18
|
]);
|
|
13
19
|
export const renewalPrice = z
|
|
@@ -35,9 +41,9 @@ export const renewalExpected = z
|
|
|
35
41
|
subscriptionId: id("sub"),
|
|
36
42
|
itemId: id("si"),
|
|
37
43
|
currentPriceId: id("price"),
|
|
38
|
-
currentProductId:
|
|
44
|
+
currentProductId: productId,
|
|
39
45
|
targetPriceId: id("price"),
|
|
40
|
-
targetProductId:
|
|
46
|
+
targetProductId: productId,
|
|
41
47
|
periodStart: integer,
|
|
42
48
|
periodEnd: integer,
|
|
43
49
|
livemode: z.boolean(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renewalReplacementSchema.js","sourceRoot":"","sources":["../../../src/client/billing/renewalReplacementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,EAAE,GAAG,CAAC,MAAc,EAAE,EAAE,CAC5B,CAAC;KACE,MAAM,EAAE;KACR,GAAG,CAAC,GAAG,CAAC;KACR,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,iBAAiB,CAAC,CAAC,CAAC;AACpD,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACzE,MAAM,
|
|
1
|
+
{"version":3,"file":"renewalReplacementSchema.js","sourceRoot":"","sources":["../../../src/client/billing/renewalReplacementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,EAAE,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AC,MAAM,sBAAsB,GAAG,CAAC;KACpC,MAAM,CAAC;IACN,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC;IACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC7B,gBAAgB,EAAE,EAAE,CAAC,MAAM,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IACpC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC,IAAI,EAAE;QACR,CAAC;aACE,MAAM,CAAC;YACN,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC;YACZ,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;YAC7B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;SACrC,CAAC;aACD,WAAW,EAAE;KACjB,CAAC;CACH,CAAC;KACD,WAAW,EAAE,CAAC;AAEjB,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,CAAC;IACN,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE;IACzB,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE;IACxB,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACvC,QAAQ,EAAE,eAAe;IACzB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC;KACD,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Renewal preservation mappings
|
|
2
|
+
|
|
3
|
+
The internal renewal projection modules convert selected, bounded provider read
|
|
4
|
+
fields into explicit schedule update fields. They are not public schedule writers.
|
|
5
|
+
Every successful field projection carries `requiresProviderQualification: true`.
|
|
6
|
+
It is not permission to attach or configure a schedule, evidence of provider
|
|
7
|
+
retention, or a complete phase. See the [renewal contract](renewal-price-replacements.md).
|
|
8
|
+
|
|
9
|
+
The aggregate assembler must take these fields from the full acknowledged owned
|
|
10
|
+
schedule, bind that baseline and its unchanged defaults, and correlate original
|
|
11
|
+
subscription, customer account, item, price, quantity, period and target. It must
|
|
12
|
+
derive effective collection method, tax enablement and invoice issuer from those
|
|
13
|
+
reads and defaults. Context inputs are comparison values, not provenance flags.
|
|
14
|
+
A browser cannot supply this evidence.
|
|
15
|
+
|
|
16
|
+
## Phase settings
|
|
17
|
+
|
|
18
|
+
`projectRenewalPhaseSettings` accepts only the named phase fields below. Unknown
|
|
19
|
+
fields at this boundary reject. Expanded references must have the expected object
|
|
20
|
+
and resource ID kind and cannot be deleted. Available mode and customer facts,
|
|
21
|
+
including nested Customer facts, must agree with context. Bare IDs preserve a
|
|
22
|
+
reference from the acknowledged scoped read; they do not prove ownership or
|
|
23
|
+
resource freshness by themselves.
|
|
24
|
+
|
|
25
|
+
| Read field | Projected update field | Rule |
|
|
26
|
+
| ------------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| `application_fee_percent` | omitted | Only null supported. Nonnull, including zero, rejects for this platform flow. |
|
|
28
|
+
| `billing_thresholds` | omitted | Only null supported. Active thresholds can change the paid period. |
|
|
29
|
+
| `collection_method` | same | Null omits. Otherwise require the exact effective known method. |
|
|
30
|
+
| `default_payment_method` | ID | Null omits. Validate available customer/account/mode facts. Never translate a legacy source. |
|
|
31
|
+
| `on_behalf_of` | account ID | Null omits. No inferred routing or scope change. |
|
|
32
|
+
| `transfer_data` | destination ID, optional percentage | Null omits. Preserve numeric zero and percentages with at most two decimal places; reject extra precision without rounding. Null percentage omits that subfield. Never invent 100. |
|
|
33
|
+
| `automatic_tax` | enabled, optional liability | Absent omits. Preserve false. Null liability omits; self has no account, account liability requires its exact ID. Nonnull disabled reasons reject. Compare effective enablement with unchanged defaults. |
|
|
34
|
+
| `default_tax_rates` | ordered tax-rate IDs | Null/absent omits; empty list becomes provider Emptyable `""`. Expanded rates must match mode. Nonempty manual rates with effective automatic tax reject. |
|
|
35
|
+
| `description` | same | Null omits. Preserve strings including empty strings exactly. |
|
|
36
|
+
| `metadata` | exact string map | Null/empty map omits actions. Empty-value unset actions reject. Never derive phase actions from flattened subscription metadata. |
|
|
37
|
+
|
|
38
|
+
Invoice settings map only `account_tax_ids`, `custom_fields`, `days_until_due`,
|
|
39
|
+
`description`, `footer` and `issuer`. Null settings or null nested overrides omit.
|
|
40
|
+
Empty tax-ID/custom-field lists use `""`; nonempty lists retain order. Text retains
|
|
41
|
+
empty strings. Days require effective `send_invoice` and a bounded nonnegative
|
|
42
|
+
integer. Issuer must agree with effective issuer. Expanded invoice tax IDs require
|
|
43
|
+
self/account ownership matching that issuer. Customer/application owners, missing
|
|
44
|
+
owner evidence and deleted references reject. These identify the issuer, not the
|
|
45
|
+
buyer.
|
|
46
|
+
|
|
47
|
+
Omitting a null override relies on the unchanged default hierarchy. This mapper
|
|
48
|
+
does not establish that hierarchy or authorize replacing defaults. The assembler
|
|
49
|
+
must reject unknown or contradictory defaults. Provider parameter types alone do
|
|
50
|
+
not establish that a read-to-write mapping preserves provider behavior.
|
|
51
|
+
|
|
52
|
+
## Item settings
|
|
53
|
+
|
|
54
|
+
`projectRenewalItemSettings` maps item `tax_rates` and metadata. Thresholds must be
|
|
55
|
+
null. Null/absent tax override omits; explicit empty rates becomes `""`; nonempty
|
|
56
|
+
expanded rates map in order after mode/deletion validation. Effective automatic
|
|
57
|
+
tax rejects manual item rates, including tax inherited from schedule defaults.
|
|
58
|
+
Metadata follows the phase action rules. Item identity, price, quantity and
|
|
59
|
+
successor correlation belong to the full assembler and observer. This projection
|
|
60
|
+
does not assume item IDs survive a price transition.
|
|
61
|
+
|
|
62
|
+
## Existing discount redemptions
|
|
63
|
+
|
|
64
|
+
`projectRenewalDiscounts` emits only `{discount: existingId}`, never coupon or
|
|
65
|
+
promotion-code selectors that would redeem again. It requires a direct existing
|
|
66
|
+
subscription/item redemption, exact account/owner correlation, matching ordered
|
|
67
|
+
phase references, an expanded coupon with forever duration and null redemption
|
|
68
|
+
end, and product applicability covering original and target. Coupon and product
|
|
69
|
+
IDs may be custom nonblank identifiers. Generated resource kinds such as `di_`,
|
|
70
|
+
`sub_`, `si_` and `acct_` remain validated.
|
|
71
|
+
|
|
72
|
+
Phase references must be IDs or minimal undeleted reference objects. Full expanded
|
|
73
|
+
phase Discount objects require normalization and correlation first; contradictory
|
|
74
|
+
extra claims reject. Coupon references must agree with the expanded source.
|
|
75
|
+
|
|
76
|
+
Once/repeating duration, ancestor-owned redemption, ambiguous empty discount
|
|
77
|
+
hierarchy and missing source evidence remain unsupported. Null end alone does not
|
|
78
|
+
establish forever duration. Customer `discount: null` proves current absence only.
|
|
79
|
+
It does not distinguish historical suppression from inheritance or authorize
|
|
80
|
+
freezing future customer discounts. These required consumer contexts remain open
|
|
81
|
+
in the full contract. No invented provenance flag or host policy replaces them.
|
|
82
|
+
|
|
83
|
+
## Complete-request requirements
|
|
84
|
+
|
|
85
|
+
The full preflight/assembler still owns trial/cancellation/pending/special state,
|
|
86
|
+
original/target identity, current/future boundaries, anchor/cadence classes, full
|
|
87
|
+
receipt/default/request bindings and drift rejection. Subscription-only payment
|
|
88
|
+
or historical trial fields without phase writers are retention-verification gaps,
|
|
89
|
+
not proof Stripe discards them. An extra subscription POST, rollback or release
|
|
90
|
+
cannot hide such a gap.
|
|
91
|
+
|
|
92
|
+
Provider qualification, dispatch and observation remain separate requirements.
|
|
93
|
+
The complete flow must prove unchanged paid terms and the exact renewal outcome,
|
|
94
|
+
including supported month-end/cadence behavior, before capability acceptance.
|
|
@@ -42,6 +42,11 @@ currency. Different products and recurring cadences are represented without
|
|
|
42
42
|
inventing tier ordering or financial arithmetic. Representation does not certify
|
|
43
43
|
that a future writer supports every cadence, billing mode or setting.
|
|
44
44
|
|
|
45
|
+
Product IDs may be provider-valid custom nonblank IDs, as well as generated
|
|
46
|
+
`prod_` IDs. Original and target product selectors must still match exactly.
|
|
47
|
+
The internal [preservation mappings](renewal-preservation-mappings.md) document
|
|
48
|
+
field projection boundaries separately from complete schedule eligibility.
|
|
49
|
+
|
|
45
50
|
The subscription's actual `currency` must match both prices' default `currency`.
|
|
46
51
|
This helper does not select `currency_options` or infer an alternative amount.
|
|
47
52
|
Alternative-currency contexts need a separate explicit mapping and are rejected
|
package/package.json
CHANGED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import * as projection from "./renewalProjection/discounts.js";
|
|
3
|
+
|
|
4
|
+
const context = {
|
|
5
|
+
customerAccountId: "acct_buyer",
|
|
6
|
+
subscriptionId: "sub_original",
|
|
7
|
+
level: "subscription" as const,
|
|
8
|
+
currentProductId: "prod_original",
|
|
9
|
+
targetProductId: "prod_target",
|
|
10
|
+
};
|
|
11
|
+
function redemption() {
|
|
12
|
+
return {
|
|
13
|
+
id: "di_existing",
|
|
14
|
+
object: "discount",
|
|
15
|
+
customer_account: "acct_buyer",
|
|
16
|
+
subscription: "sub_original",
|
|
17
|
+
subscription_item: null,
|
|
18
|
+
start: 1700000000,
|
|
19
|
+
end: null,
|
|
20
|
+
source: {
|
|
21
|
+
type: "coupon",
|
|
22
|
+
coupon: {
|
|
23
|
+
id: "original-offer",
|
|
24
|
+
object: "coupon",
|
|
25
|
+
duration: "forever",
|
|
26
|
+
applies_to: { products: ["prod_original", "prod_target"] },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function input() {
|
|
32
|
+
return {
|
|
33
|
+
...context,
|
|
34
|
+
redemptions: [redemption()],
|
|
35
|
+
phaseDiscounts: [
|
|
36
|
+
{
|
|
37
|
+
discount: "di_existing",
|
|
38
|
+
coupon: "original-offer",
|
|
39
|
+
promotion_code: null,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
it("defines a pure discount projection boundary", () => {
|
|
46
|
+
expect(projection).toHaveProperty(
|
|
47
|
+
"projectRenewalDiscounts",
|
|
48
|
+
expect.any(Function),
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("reuses an existing unambiguous forever redemption without redeeming a coupon", () => {
|
|
53
|
+
const args = input();
|
|
54
|
+
const before = structuredClone(args);
|
|
55
|
+
expect(projection.projectRenewalDiscounts(args)).toEqual({
|
|
56
|
+
status: "projected",
|
|
57
|
+
discounts: [{ discount: "di_existing" }],
|
|
58
|
+
requiresProviderQualification: true,
|
|
59
|
+
});
|
|
60
|
+
expect(args).toEqual(before);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("does not reinterpret an empty phase as customer inheritance or suppression", () => {
|
|
64
|
+
expect(
|
|
65
|
+
projection.projectRenewalDiscounts({
|
|
66
|
+
...context,
|
|
67
|
+
redemptions: [],
|
|
68
|
+
phaseDiscounts: [],
|
|
69
|
+
}),
|
|
70
|
+
).toEqual({
|
|
71
|
+
status: "unsupported",
|
|
72
|
+
reason: "ambiguous_empty_discount_hierarchy",
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it.each([
|
|
77
|
+
["customer_account", "acct_foreign"],
|
|
78
|
+
["subscription", "sub_foreign"],
|
|
79
|
+
["subscription_item", "si_other"],
|
|
80
|
+
["deleted", true],
|
|
81
|
+
] as const)(
|
|
82
|
+
"rejects foreign or incomplete redemption identity %s",
|
|
83
|
+
(field, value) => {
|
|
84
|
+
const args = input();
|
|
85
|
+
expect(
|
|
86
|
+
projection.projectRenewalDiscounts({
|
|
87
|
+
...args,
|
|
88
|
+
redemptions: [{ ...redemption(), [field]: value }],
|
|
89
|
+
}).status,
|
|
90
|
+
).toBe("unsupported");
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
it.each(["once", "repeating"])(
|
|
95
|
+
"keeps unqualified %s duration visible",
|
|
96
|
+
(duration) => {
|
|
97
|
+
const args = input();
|
|
98
|
+
const discount = redemption();
|
|
99
|
+
discount.source.coupon.duration = duration;
|
|
100
|
+
expect(
|
|
101
|
+
projection.projectRenewalDiscounts({ ...args, redemptions: [discount] }),
|
|
102
|
+
).toEqual({
|
|
103
|
+
status: "unsupported",
|
|
104
|
+
reason: "discount_duration_not_qualified",
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
it("rejects cross-product applicability gaps", () => {
|
|
110
|
+
const args = input();
|
|
111
|
+
args.redemptions[0].source.coupon.applies_to.products = ["prod_original"];
|
|
112
|
+
expect(projection.projectRenewalDiscounts(args)).toEqual({
|
|
113
|
+
status: "unsupported",
|
|
114
|
+
reason: "coupon_product_applicability",
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("requires the phase to identify the same acknowledged redemption, in order", () => {
|
|
119
|
+
const args = input();
|
|
120
|
+
args.phaseDiscounts[0].discount = "di_foreign";
|
|
121
|
+
expect(projection.projectRenewalDiscounts(args)).toEqual({
|
|
122
|
+
status: "unsupported",
|
|
123
|
+
reason: "phase_redemption_mismatch",
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("never turns an unexpanded ID into invented redemption evidence", () => {
|
|
128
|
+
expect(
|
|
129
|
+
projection.projectRenewalDiscounts({
|
|
130
|
+
...input(),
|
|
131
|
+
redemptions: ["di_existing"],
|
|
132
|
+
}),
|
|
133
|
+
).toEqual({ status: "unsupported", reason: "incomplete_discount_evidence" });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it.each([
|
|
137
|
+
["id", "coupon_wrong_kind"],
|
|
138
|
+
["customer_account", "cus_wrong_kind"],
|
|
139
|
+
["subscription", "si_wrong_kind"],
|
|
140
|
+
["subscription_item", "sub_wrong_kind"],
|
|
141
|
+
["id", " "],
|
|
142
|
+
] as const)("rejects malformed redemption %s", (field, value) => {
|
|
143
|
+
const args = input();
|
|
144
|
+
const discount = { ...redemption(), [field]: value };
|
|
145
|
+
const result = projection.projectRenewalDiscounts({
|
|
146
|
+
...args,
|
|
147
|
+
customerAccountId: discount.customer_account,
|
|
148
|
+
subscriptionId: discount.subscription,
|
|
149
|
+
redemptions: [discount],
|
|
150
|
+
phaseDiscounts: [{ discount: discount.id }],
|
|
151
|
+
});
|
|
152
|
+
expect(result).toEqual({
|
|
153
|
+
status: "unsupported",
|
|
154
|
+
reason: "incomplete_discount_evidence",
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it.each(["currentProductId", "targetProductId"] as const)(
|
|
159
|
+
"rejects blank custom product identity %s",
|
|
160
|
+
(field) => {
|
|
161
|
+
const args = input();
|
|
162
|
+
args.redemptions[0].source.coupon.applies_to.products.push(" ");
|
|
163
|
+
expect(
|
|
164
|
+
projection.projectRenewalDiscounts({ ...args, [field]: " " }),
|
|
165
|
+
).toEqual({
|
|
166
|
+
status: "unsupported",
|
|
167
|
+
reason: "incomplete_discount_evidence",
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
it("preserves custom product and coupon IDs", () => {
|
|
173
|
+
const args = input();
|
|
174
|
+
args.currentProductId = "custom-original";
|
|
175
|
+
args.targetProductId = "custom-target";
|
|
176
|
+
args.redemptions[0].source.coupon.applies_to.products = [
|
|
177
|
+
args.currentProductId,
|
|
178
|
+
args.targetProductId,
|
|
179
|
+
];
|
|
180
|
+
expect(projection.projectRenewalDiscounts(args).status).toBe("projected");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it.each([
|
|
184
|
+
{ customer_account: "acct_foreign" },
|
|
185
|
+
{ subscription: "sub_foreign" },
|
|
186
|
+
{ source: { type: "coupon", coupon: { id: "foreign-offer" } } },
|
|
187
|
+
])("rejects additional expanded phase claims %j", (extra) => {
|
|
188
|
+
expect(
|
|
189
|
+
projection.projectRenewalDiscounts({
|
|
190
|
+
...input(),
|
|
191
|
+
phaseDiscounts: [
|
|
192
|
+
{
|
|
193
|
+
discount: { id: "di_existing", object: "discount", ...extra },
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
}),
|
|
197
|
+
).toEqual({ status: "unsupported", reason: "incomplete_discount_evidence" });
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("accepts a minimal phase discount reference", () => {
|
|
201
|
+
expect(
|
|
202
|
+
projection.projectRenewalDiscounts({
|
|
203
|
+
...input(),
|
|
204
|
+
phaseDiscounts: [{ discount: { id: "di_existing", object: "discount" } }],
|
|
205
|
+
}).status,
|
|
206
|
+
).toBe("projected");
|
|
207
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import * as projection from "./renewalProjection/itemSettings.js";
|
|
3
|
+
|
|
4
|
+
const input = () => ({
|
|
5
|
+
effectiveAutomaticTax: false,
|
|
6
|
+
livemode: false,
|
|
7
|
+
settings: { billing_thresholds: null, tax_rates: [], metadata: null },
|
|
8
|
+
});
|
|
9
|
+
it("preserves explicit empty item rates as a clear override", () => {
|
|
10
|
+
expect(projection.projectRenewalItemSettings(input())).toEqual({
|
|
11
|
+
status: "projected",
|
|
12
|
+
settings: { tax_rates: "" },
|
|
13
|
+
requiresProviderQualification: true,
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it("keeps absent tax overrides absent and null metadata without actions", () => {
|
|
17
|
+
expect(
|
|
18
|
+
projection.projectRenewalItemSettings({
|
|
19
|
+
...input(),
|
|
20
|
+
settings: { billing_thresholds: null, metadata: null },
|
|
21
|
+
}),
|
|
22
|
+
).toMatchObject({ status: "projected", settings: {} });
|
|
23
|
+
});
|
|
24
|
+
it("maps ordered item tax IDs and exact metadata without changing reads", () => {
|
|
25
|
+
const value = {
|
|
26
|
+
...input(),
|
|
27
|
+
settings: {
|
|
28
|
+
billing_thresholds: null,
|
|
29
|
+
tax_rates: ["first", "second"].map((name) => ({
|
|
30
|
+
id: `txr_${name}`,
|
|
31
|
+
object: "tax_rate",
|
|
32
|
+
livemode: false,
|
|
33
|
+
})),
|
|
34
|
+
metadata: { original: "kept" },
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const before = structuredClone(value);
|
|
38
|
+
expect(projection.projectRenewalItemSettings(value)).toMatchObject({
|
|
39
|
+
status: "projected",
|
|
40
|
+
settings: {
|
|
41
|
+
tax_rates: ["txr_first", "txr_second"],
|
|
42
|
+
metadata: { original: "kept" },
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
expect(value).toEqual(before);
|
|
46
|
+
});
|
|
47
|
+
it.each([
|
|
48
|
+
{ billing_thresholds: { usage_gte: 100 } },
|
|
49
|
+
{ metadata: { unset: "" } },
|
|
50
|
+
{ tax_rates: [{ id: "txr_live", object: "tax_rate", livemode: true }] },
|
|
51
|
+
{
|
|
52
|
+
tax_rates: [
|
|
53
|
+
{ id: "txr_deleted", object: "tax_rate", livemode: false, deleted: true },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{ unknown_future_setting: true },
|
|
57
|
+
])("rejects unsupported item state %j", (extra) => {
|
|
58
|
+
expect(
|
|
59
|
+
projection.projectRenewalItemSettings({
|
|
60
|
+
...input(),
|
|
61
|
+
settings: {
|
|
62
|
+
...input().settings,
|
|
63
|
+
...extra,
|
|
64
|
+
},
|
|
65
|
+
}).status,
|
|
66
|
+
).toBe("unsupported");
|
|
67
|
+
});
|
|
68
|
+
it("rejects item rates under inherited effective automatic tax", () => {
|
|
69
|
+
expect(
|
|
70
|
+
projection.projectRenewalItemSettings({
|
|
71
|
+
...input(),
|
|
72
|
+
effectiveAutomaticTax: true,
|
|
73
|
+
settings: {
|
|
74
|
+
...input().settings,
|
|
75
|
+
tax_rates: [{ id: "txr_manual", object: "tax_rate", livemode: false }],
|
|
76
|
+
},
|
|
77
|
+
}).status,
|
|
78
|
+
).toBe("unsupported");
|
|
79
|
+
});
|