@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.
Files changed (103) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAggregate/configure.d.ts +35 -0
  4. package/dist/client/billing/renewalAggregate/configure.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAggregate/configure.js +96 -0
  6. package/dist/client/billing/renewalAggregate/configure.js.map +1 -0
  7. package/dist/client/billing/renewalAggregate/index.d.ts +3 -0
  8. package/dist/client/billing/renewalAggregate/index.d.ts.map +1 -0
  9. package/dist/client/billing/renewalAggregate/index.js +3 -0
  10. package/dist/client/billing/renewalAggregate/index.js.map +1 -0
  11. package/dist/client/billing/renewalAggregate/phaseContext.d.ts +176 -0
  12. package/dist/client/billing/renewalAggregate/phaseContext.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAggregate/phaseContext.js +112 -0
  14. package/dist/client/billing/renewalAggregate/phaseContext.js.map +1 -0
  15. package/dist/client/billing/renewalAggregate/phases.d.ts +7 -0
  16. package/dist/client/billing/renewalAggregate/phases.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAggregate/phases.js +192 -0
  18. package/dist/client/billing/renewalAggregate/phases.js.map +1 -0
  19. package/dist/client/billing/renewalAggregate/preflight.d.ts +594 -0
  20. package/dist/client/billing/renewalAggregate/preflight.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAggregate/preflight.js +164 -0
  22. package/dist/client/billing/renewalAggregate/preflight.js.map +1 -0
  23. package/dist/client/billing/renewalAggregate/profile.d.ts +8 -0
  24. package/dist/client/billing/renewalAggregate/profile.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAggregate/profile.js +60 -0
  26. package/dist/client/billing/renewalAggregate/profile.js.map +1 -0
  27. package/dist/client/billing/renewalAggregate/receipt.d.ts +40 -0
  28. package/dist/client/billing/renewalAggregate/receipt.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAggregate/receipt.js +62 -0
  30. package/dist/client/billing/renewalAggregate/receipt.js.map +1 -0
  31. package/dist/client/billing/renewalAggregate/shared.d.ts +51 -0
  32. package/dist/client/billing/renewalAggregate/shared.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAggregate/shared.js +87 -0
  34. package/dist/client/billing/renewalAggregate/shared.js.map +1 -0
  35. package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts +42 -0
  36. package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAggregate/sourceDiscounts.js +90 -0
  38. package/dist/client/billing/renewalAggregate/sourceDiscounts.js.map +1 -0
  39. package/dist/client/billing/renewalAggregate/sourceSettings.d.ts +136 -0
  40. package/dist/client/billing/renewalAggregate/sourceSettings.d.ts.map +1 -0
  41. package/dist/client/billing/renewalAggregate/sourceSettings.js +82 -0
  42. package/dist/client/billing/renewalAggregate/sourceSettings.js.map +1 -0
  43. package/dist/client/billing/renewalAggregate/taxRetention.d.ts +8 -0
  44. package/dist/client/billing/renewalAggregate/taxRetention.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAggregate/taxRetention.js +23 -0
  46. package/dist/client/billing/renewalAggregate/taxRetention.js.map +1 -0
  47. package/dist/client/billing/renewalPriceReplacement.d.ts +2 -0
  48. package/dist/client/billing/renewalPriceReplacement.d.ts.map +1 -1
  49. package/dist/client/billing/renewalProjection/discounts.d.ts +20 -0
  50. package/dist/client/billing/renewalProjection/discounts.d.ts.map +1 -0
  51. package/dist/client/billing/renewalProjection/discounts.js +121 -0
  52. package/dist/client/billing/renewalProjection/discounts.js.map +1 -0
  53. package/dist/client/billing/renewalProjection/itemSettings.d.ts +14 -0
  54. package/dist/client/billing/renewalProjection/itemSettings.d.ts.map +1 -0
  55. package/dist/client/billing/renewalProjection/itemSettings.js +41 -0
  56. package/dist/client/billing/renewalProjection/itemSettings.js.map +1 -0
  57. package/dist/client/billing/renewalProjection/settings.d.ts +18 -0
  58. package/dist/client/billing/renewalProjection/settings.d.ts.map +1 -0
  59. package/dist/client/billing/renewalProjection/settings.js +132 -0
  60. package/dist/client/billing/renewalProjection/settings.js.map +1 -0
  61. package/dist/client/billing/renewalProjection/settingsSchema.d.ts +200 -0
  62. package/dist/client/billing/renewalProjection/settingsSchema.d.ts.map +1 -0
  63. package/dist/client/billing/renewalProjection/settingsSchema.js +150 -0
  64. package/dist/client/billing/renewalProjection/settingsSchema.js.map +1 -0
  65. package/dist/client/billing/renewalReplacementSchema.d.ts +2 -0
  66. package/dist/client/billing/renewalReplacementSchema.d.ts.map +1 -1
  67. package/dist/client/billing/renewalReplacementSchema.js +10 -4
  68. package/dist/client/billing/renewalReplacementSchema.js.map +1 -1
  69. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  70. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  71. package/dist/component/balanceFunding/mutations.d.ts +43 -43
  72. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  73. package/dist/component/payoutRelease/queries.d.ts +2 -2
  74. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  75. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  76. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  77. package/docs/renewal-phase-assembly.md +180 -0
  78. package/docs/renewal-preservation-mappings.md +94 -0
  79. package/docs/renewal-price-replacements.md +7 -0
  80. package/package.json +1 -1
  81. package/src/client/billing/renewal-discount-projection.test.ts +207 -0
  82. package/src/client/billing/renewal-item-settings-projection.test.ts +79 -0
  83. package/src/client/billing/renewal-price-replacement.test.ts +46 -0
  84. package/src/client/billing/renewal-settings-projection.test.ts +300 -0
  85. package/src/client/billing/renewalAggregate/configure.test.ts +372 -0
  86. package/src/client/billing/renewalAggregate/configure.ts +164 -0
  87. package/src/client/billing/renewalAggregate/index.ts +2 -0
  88. package/src/client/billing/renewalAggregate/phaseContext.ts +144 -0
  89. package/src/client/billing/renewalAggregate/phases.ts +247 -0
  90. package/src/client/billing/renewalAggregate/preflight.test.ts +233 -0
  91. package/src/client/billing/renewalAggregate/preflight.ts +211 -0
  92. package/src/client/billing/renewalAggregate/profile.ts +76 -0
  93. package/src/client/billing/renewalAggregate/receipt.ts +76 -0
  94. package/src/client/billing/renewalAggregate/shared.ts +106 -0
  95. package/src/client/billing/renewalAggregate/sourceAndTaxRetention.test.ts +247 -0
  96. package/src/client/billing/renewalAggregate/sourceDiscounts.ts +112 -0
  97. package/src/client/billing/renewalAggregate/sourceSettings.ts +88 -0
  98. package/src/client/billing/renewalAggregate/taxRetention.ts +28 -0
  99. package/src/client/billing/renewalProjection/discounts.ts +152 -0
  100. package/src/client/billing/renewalProjection/itemSettings.ts +55 -0
  101. package/src/client/billing/renewalProjection/settings.ts +163 -0
  102. package/src/client/billing/renewalProjection/settingsSchema.ts +154 -0
  103. package/src/client/billing/renewalReplacementSchema.ts +10 -4
@@ -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,13 @@ 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
+ The internal [phase assembly contract](renewal-phase-assembly.md) describes
50
+ preflight, acknowledged baselines and non-dispatchable configuration candidates.
51
+
45
52
  The subscription's actual `currency` must match both prices' default `currency`.
46
53
  This helper does not select `currency_options` or infer an alternative amount.
47
54
  Alternative-currency contexts need a separate explicit mapping and are rejected
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fantastic.dev/better-stripe",
3
- "version": "0.80.0",
3
+ "version": "0.82.0",
4
4
  "description": "Convex component for Stripe Accounts v2, subscriptions, metered billing and Connect marketplaces, with React workflows.",
5
5
  "keywords": [
6
6
  "stripe",
@@ -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
+ });
@@ -13,6 +13,22 @@ const expected = {
13
13
  periodEnd: 1702592000,
14
14
  livemode: false,
15
15
  };
16
+
17
+ it.each(["current", "target"] as const)(
18
+ "accepts provider-valid custom %s product IDs",
19
+ (which) => {
20
+ const args = structuredClone(input());
21
+ if (which === "current") {
22
+ args.expected.currentProductId = "custom-original-catalog-item";
23
+ args.subscription.items.data[0].price.product =
24
+ args.expected.currentProductId;
25
+ } else {
26
+ args.expected.targetProductId = "custom-target-catalog-item";
27
+ args.targetPrice.product = args.expected.targetProductId;
28
+ }
29
+ expect(sdk.prepareRenewalPriceReplacement(args).status).toBe("prepared");
30
+ },
31
+ );
16
32
  function price(id = "price_original", product = "prod_original") {
17
33
  return {
18
34
  id,
@@ -70,6 +86,36 @@ function input() {
70
86
  };
71
87
  }
72
88
 
89
+ it("accepts an undeleted expanded custom product reference", () => {
90
+ const args = structuredClone(input());
91
+ args.expected.targetProductId = "custom-target";
92
+ expect(
93
+ sdk.prepareRenewalPriceReplacement({
94
+ ...args,
95
+ targetPrice: {
96
+ ...args.targetPrice,
97
+ product: { id: "custom-target", object: "product" },
98
+ },
99
+ }).status,
100
+ ).toBe("prepared");
101
+ });
102
+
103
+ it.each(["coupon", "customer"])(
104
+ "rejects a wrong expanded product object %s",
105
+ (object) => {
106
+ const args = input();
107
+ expect(() =>
108
+ sdk.prepareRenewalPriceReplacement({
109
+ ...args,
110
+ targetPrice: {
111
+ ...args.targetPrice,
112
+ product: { id: args.expected.targetProductId, object },
113
+ },
114
+ }),
115
+ ).toThrow();
116
+ },
117
+ );
118
+
73
119
  it("exports read-only renewal preparation without exposing a schedule writer", () => {
74
120
  expect(sdk).toHaveProperty(
75
121
  "prepareRenewalPriceReplacement",