@fantastic.dev/better-stripe 0.79.1 → 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 +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalPriceReplacement.d.ts +133 -0
- package/dist/client/billing/renewalPriceReplacement.d.ts.map +1 -0
- package/dist/client/billing/renewalPriceReplacement.js +90 -0
- package/dist/client/billing/renewalPriceReplacement.js.map +1 -0
- 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 +126 -0
- package/dist/client/billing/renewalReplacementSchema.d.ts.map +1 -0
- package/dist/client/billing/renewalReplacementSchema.js +127 -0
- package/dist/client/billing/renewalReplacementSchema.js.map +1 -0
- package/dist/client/billing/renewalReplacementSnapshot.d.ts +3 -0
- package/dist/client/billing/renewalReplacementSnapshot.d.ts.map +1 -0
- package/dist/client/billing/renewalReplacementSnapshot.js +69 -0
- package/dist/client/billing/renewalReplacementSnapshot.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/usage/observationClient.d.ts +2 -2
- package/dist/client/usage/observationClient.d.ts.map +1 -1
- 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/docs/client-api.md +5 -0
- package/docs/renewal-preservation-mappings.md +94 -0
- package/docs/renewal-price-replacements.md +191 -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 +503 -0
- package/src/client/billing/renewal-settings-projection.test.ts +300 -0
- package/src/client/billing/renewalPriceReplacement.ts +127 -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 +135 -0
- package/src/client/billing/renewalReplacementSnapshot.ts +85 -0
- package/src/client/index.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -26,6 +26,18 @@
|
|
|
26
26
|
- Remove internal tracker references from public documentation and add a
|
|
27
27
|
regression check that prevents their reintroduction.
|
|
28
28
|
|
|
29
|
+
## [0.81.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.80.0...v0.81.0) (2026-10-27)
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
- **billing:** project preserved renewal billing settings ([349d56e](https://github.com/FantasticDevHQ/better-stripe/commit/349d56e3c001da239958762f6dbcb06d613ccade))
|
|
34
|
+
|
|
35
|
+
## [0.80.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.79.1...v0.80.0) (2026-10-27)
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
- **billing:** prepare bound renewal replacement snapshots ([#394](https://github.com/FantasticDevHQ/better-stripe/issues/394)) ([42514b7](https://github.com/FantasticDevHQ/better-stripe/commit/42514b7c045bc845e4e96549eb5d0af75a762b0b))
|
|
40
|
+
|
|
29
41
|
## [0.79.1](https://github.com/FantasticDevHQ/better-stripe/compare/v0.79.0...v0.79.1) (2026-10-26)
|
|
30
42
|
|
|
31
43
|
### Maintenance
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ billing, and Connect marketplaces. It provides checkout, subscriptions, webhook
|
|
|
5
5
|
syncing, marketplace fees and splits, payouts, refunds, and disputes, with React
|
|
6
6
|
hooks and headless UI components.
|
|
7
7
|
|
|
8
|
-
**Version**: `0.
|
|
8
|
+
**Version**: `0.81.0` <!-- x-release-please-version --> (pre-1.0). API may change between minor versions until 1.0.
|
|
9
9
|
|
|
10
10
|
Connect platforms use the default GA API version. Non-Connect merchants using
|
|
11
11
|
customer-only Accounts v2 need preview access and an explicit preview version.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type RenewalPriceReplacementExpected } from "./renewalReplacementSchema.js";
|
|
2
|
+
export type PrepareRenewalPriceReplacementOptions = {
|
|
3
|
+
subscription: unknown;
|
|
4
|
+
targetPrice: unknown;
|
|
5
|
+
billingCustomer?: unknown;
|
|
6
|
+
expected: RenewalPriceReplacementExpected;
|
|
7
|
+
key: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Pure read qualification, not write authorization or proof of preservation.
|
|
11
|
+
* Supply fresh full provider reads on the trusted server. Persist the result
|
|
12
|
+
* under host-owned immutable authorization before any later dispatch.
|
|
13
|
+
*/
|
|
14
|
+
export declare function prepareRenewalPriceReplacement(options: PrepareRenewalPriceReplacementOptions): {
|
|
15
|
+
version: 1;
|
|
16
|
+
scope: "platform";
|
|
17
|
+
expected: {
|
|
18
|
+
customerAccountId: string;
|
|
19
|
+
subscriptionId: string;
|
|
20
|
+
itemId: string;
|
|
21
|
+
currentPriceId: string;
|
|
22
|
+
currentProductId: string;
|
|
23
|
+
targetPriceId: string;
|
|
24
|
+
targetProductId: string;
|
|
25
|
+
periodStart: number;
|
|
26
|
+
periodEnd: number;
|
|
27
|
+
livemode: boolean;
|
|
28
|
+
};
|
|
29
|
+
quantity: number;
|
|
30
|
+
providerSnapshot: {
|
|
31
|
+
subscription: {
|
|
32
|
+
[x: string]: unknown;
|
|
33
|
+
id: string;
|
|
34
|
+
object: "subscription";
|
|
35
|
+
customer_account: string;
|
|
36
|
+
status: "active";
|
|
37
|
+
currency: string;
|
|
38
|
+
livemode: boolean;
|
|
39
|
+
schedule: null;
|
|
40
|
+
cancel_at: null;
|
|
41
|
+
cancel_at_period_end: false;
|
|
42
|
+
pause_collection: null;
|
|
43
|
+
pending_update: null;
|
|
44
|
+
default_source: null;
|
|
45
|
+
application_fee_percent: null;
|
|
46
|
+
payment_settings: {
|
|
47
|
+
payment_method_options: null;
|
|
48
|
+
payment_method_types: null;
|
|
49
|
+
save_default_payment_method: "off" | null;
|
|
50
|
+
} | null;
|
|
51
|
+
billing_schedules?: unknown[] | undefined;
|
|
52
|
+
items: {
|
|
53
|
+
[x: string]: unknown;
|
|
54
|
+
has_more: false;
|
|
55
|
+
data: [{
|
|
56
|
+
[x: string]: unknown;
|
|
57
|
+
id: string;
|
|
58
|
+
object: "subscription_item";
|
|
59
|
+
subscription: string;
|
|
60
|
+
current_period_start: number;
|
|
61
|
+
current_period_end: number;
|
|
62
|
+
quantity: number;
|
|
63
|
+
price: {
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
id: string;
|
|
66
|
+
object: "price";
|
|
67
|
+
product: string | {
|
|
68
|
+
[x: string]: unknown;
|
|
69
|
+
id: string;
|
|
70
|
+
object: "product";
|
|
71
|
+
deleted?: false | undefined;
|
|
72
|
+
};
|
|
73
|
+
active: boolean;
|
|
74
|
+
livemode: boolean;
|
|
75
|
+
type: "recurring";
|
|
76
|
+
currency: string;
|
|
77
|
+
billing_scheme: "per_unit";
|
|
78
|
+
recurring: {
|
|
79
|
+
[x: string]: unknown;
|
|
80
|
+
interval: "day" | "month" | "week" | "year";
|
|
81
|
+
interval_count: number;
|
|
82
|
+
usage_type: "licensed";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
}];
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
targetPrice: {
|
|
89
|
+
[x: string]: unknown;
|
|
90
|
+
id: string;
|
|
91
|
+
object: "price";
|
|
92
|
+
product: string | {
|
|
93
|
+
[x: string]: unknown;
|
|
94
|
+
id: string;
|
|
95
|
+
object: "product";
|
|
96
|
+
deleted?: false | undefined;
|
|
97
|
+
};
|
|
98
|
+
active: boolean;
|
|
99
|
+
livemode: boolean;
|
|
100
|
+
type: "recurring";
|
|
101
|
+
currency: string;
|
|
102
|
+
billing_scheme: "per_unit";
|
|
103
|
+
recurring: {
|
|
104
|
+
[x: string]: unknown;
|
|
105
|
+
interval: "day" | "month" | "week" | "year";
|
|
106
|
+
interval_count: number;
|
|
107
|
+
usage_type: "licensed";
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
billingCustomer?: {
|
|
111
|
+
[x: string]: unknown;
|
|
112
|
+
id: string;
|
|
113
|
+
object: "customer";
|
|
114
|
+
customer_account: string;
|
|
115
|
+
livemode: boolean;
|
|
116
|
+
deleted?: false | undefined;
|
|
117
|
+
discount: {
|
|
118
|
+
[x: string]: unknown;
|
|
119
|
+
id: string;
|
|
120
|
+
object: "discount";
|
|
121
|
+
deleted?: false | undefined;
|
|
122
|
+
} | null;
|
|
123
|
+
} | undefined;
|
|
124
|
+
};
|
|
125
|
+
status: "prepared";
|
|
126
|
+
preservation: "requires_schedule_validation";
|
|
127
|
+
requestIdentity: {
|
|
128
|
+
key: string;
|
|
129
|
+
binding: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export type PreparedRenewalPriceReplacement = ReturnType<typeof prepareRenewalPriceReplacement>;
|
|
133
|
+
//# sourceMappingURL=renewalPriceReplacement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renewalPriceReplacement.d.ts","sourceRoot":"","sources":["../../../src/client/billing/renewalPriceReplacement.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,+BAA+B,EACrC,MAAM,+BAA+B,CAAC;AAGvC,MAAM,MAAM,qCAAqC,GAAG;IAClD,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,+BAA+B,CAAC;IAC1C,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,qCAAqC;aAkFnC,CAAC;WACH,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAOT,UAAU;kBACJ,8BAA8B;;;;;EAM/C;AAED,MAAM,MAAM,+BAA+B,GAAG,UAAU,CACtD,OAAO,8BAA8B,CACtC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { idempotencyOptions } from "../core/idempotency.js";
|
|
2
|
+
import { renewalExpected, renewalBillingCustomer, renewalPreparationInput, renewalPrice, renewalSubscription, } from "./renewalReplacementSchema.js";
|
|
3
|
+
import { renewalSnapshot } from "./renewalReplacementSnapshot.js";
|
|
4
|
+
/**
|
|
5
|
+
* Pure read qualification, not write authorization or proof of preservation.
|
|
6
|
+
* Supply fresh full provider reads on the trusted server. Persist the result
|
|
7
|
+
* under host-owned immutable authorization before any later dispatch.
|
|
8
|
+
*/
|
|
9
|
+
export function prepareRenewalPriceReplacement(options) {
|
|
10
|
+
const args = renewalPreparationInput.parse(renewalSnapshot(options));
|
|
11
|
+
const key = idempotencyOptions(args.key)?.idempotencyKey;
|
|
12
|
+
if (!key)
|
|
13
|
+
throw new Error("Renewal preparation requires an explicit key.");
|
|
14
|
+
const expected = renewalExpected.parse(args.expected);
|
|
15
|
+
const source = renewalSnapshot({
|
|
16
|
+
subscription: args.subscription,
|
|
17
|
+
targetPrice: args.targetPrice,
|
|
18
|
+
});
|
|
19
|
+
const subscription = renewalSubscription.parse(source.subscription);
|
|
20
|
+
const targetPrice = renewalPrice.parse(source.targetPrice);
|
|
21
|
+
const billingCustomer = args.billingCustomer === undefined
|
|
22
|
+
? undefined
|
|
23
|
+
: renewalBillingCustomer.parse(args.billingCustomer);
|
|
24
|
+
if (billingCustomer !== undefined) {
|
|
25
|
+
const reference = subscription.customer;
|
|
26
|
+
const referenceId = typeof reference === "string"
|
|
27
|
+
? reference
|
|
28
|
+
: typeof reference === "object" &&
|
|
29
|
+
reference !== null &&
|
|
30
|
+
"id" in reference &&
|
|
31
|
+
"object" in reference &&
|
|
32
|
+
reference.object === "customer" &&
|
|
33
|
+
!("deleted" in reference && reference.deleted === true)
|
|
34
|
+
? reference.id
|
|
35
|
+
: undefined;
|
|
36
|
+
if (referenceId !== billingCustomer.id ||
|
|
37
|
+
billingCustomer.customer_account !== expected.customerAccountId ||
|
|
38
|
+
billingCustomer.livemode !== expected.livemode)
|
|
39
|
+
throw new Error("Billing customer evidence does not match the original subscription account.");
|
|
40
|
+
}
|
|
41
|
+
const item = subscription.items.data[0];
|
|
42
|
+
const current = item.price;
|
|
43
|
+
const productId = (p) => typeof p === "string" ? p : p.id;
|
|
44
|
+
if (subscription.id !== expected.subscriptionId ||
|
|
45
|
+
subscription.customer_account !== expected.customerAccountId ||
|
|
46
|
+
item.subscription !== expected.subscriptionId ||
|
|
47
|
+
item.id !== expected.itemId ||
|
|
48
|
+
current.id !== expected.currentPriceId ||
|
|
49
|
+
productId(current.product) !== expected.currentProductId ||
|
|
50
|
+
targetPrice.id !== expected.targetPriceId ||
|
|
51
|
+
productId(targetPrice.product) !== expected.targetProductId ||
|
|
52
|
+
item.current_period_start !== expected.periodStart ||
|
|
53
|
+
item.current_period_end !== expected.periodEnd ||
|
|
54
|
+
[subscription.livemode, current.livemode, targetPrice.livemode].some((mode) => mode !== expected.livemode))
|
|
55
|
+
throw new Error("Renewal replacement does not match the authorized original and target.");
|
|
56
|
+
if (!targetPrice.active ||
|
|
57
|
+
current.id === targetPrice.id ||
|
|
58
|
+
subscription.currency !== current.currency ||
|
|
59
|
+
current.currency !== targetPrice.currency)
|
|
60
|
+
throw new Error("The target must be a different active recurring price in the original subscription currency; alternative currency_options require separate validation.");
|
|
61
|
+
for (const field of [
|
|
62
|
+
"pending_invoice_item_interval",
|
|
63
|
+
"pending_setup_intent",
|
|
64
|
+
"pause_schedules",
|
|
65
|
+
])
|
|
66
|
+
if (subscription[field] != null)
|
|
67
|
+
throw new Error(`Renewal replacement does not support ${field}.`);
|
|
68
|
+
const providerSnapshot = renewalSnapshot({
|
|
69
|
+
subscription,
|
|
70
|
+
targetPrice,
|
|
71
|
+
...(billingCustomer === undefined ? {} : { billingCustomer }),
|
|
72
|
+
});
|
|
73
|
+
const bound = {
|
|
74
|
+
version: 1,
|
|
75
|
+
scope: "platform",
|
|
76
|
+
expected,
|
|
77
|
+
quantity: item.quantity,
|
|
78
|
+
providerSnapshot,
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
...bound,
|
|
82
|
+
status: "prepared",
|
|
83
|
+
preservation: "requires_schedule_validation",
|
|
84
|
+
requestIdentity: {
|
|
85
|
+
key,
|
|
86
|
+
binding: `renewal:v1:${JSON.stringify(renewalSnapshot(bound))}`,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=renewalPriceReplacement.js.map
|
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B;QAC3B,YAAY,EAAE,8BAAuC;QACrD,eAAe,EAAE;YACf,GAAG;YACH,OAAO,EAAE,cAAc,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE;SAChE;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type Reason = "incomplete_discount_evidence" | "ambiguous_empty_discount_hierarchy" | "discount_not_owned_at_level" | "discount_duration_not_qualified" | "coupon_product_applicability" | "phase_redemption_mismatch" | "duplicate_redemptions";
|
|
2
|
+
export type RenewalDiscountProjection = {
|
|
3
|
+
status: "unsupported";
|
|
4
|
+
reason: Reason;
|
|
5
|
+
} | {
|
|
6
|
+
status: "projected";
|
|
7
|
+
discounts: {
|
|
8
|
+
discount: string;
|
|
9
|
+
}[];
|
|
10
|
+
requiresProviderQualification: true;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Project only a direct, unambiguous existing forever redemption. Ancestor-owned
|
|
14
|
+
* redemptions are unsupported. Phase references must be IDs or minimal reference
|
|
15
|
+
* objects; full expanded objects require separate normalization and correlation.
|
|
16
|
+
* This field projection requires provider qualification before writer eligibility.
|
|
17
|
+
*/
|
|
18
|
+
export declare function projectRenewalDiscounts(input: unknown): RenewalDiscountProjection;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=discounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discounts.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalProjection/discounts.ts"],"names":[],"mappings":"AAqEA,KAAK,MAAM,GACP,8BAA8B,GAC9B,oCAAoC,GACpC,6BAA6B,GAC7B,iCAAiC,GACjC,8BAA8B,GAC9B,2BAA2B,GAC3B,uBAAuB,CAAC;AAC5B,MAAM,MAAM,yBAAyB,GACjC;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzC;IACE,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAClC,6BAA6B,EAAE,IAAI,CAAC;CACrC,CAAC;AAEN;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,GACb,yBAAyB,CA0D3B"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
3
|
+
// Coupons and products may have caller-supplied IDs. Do not require a prefix.
|
|
4
|
+
const id = z.string().min(1).max(255).regex(/\S/);
|
|
5
|
+
const resourceId = (prefix) => z
|
|
6
|
+
.string()
|
|
7
|
+
.max(255)
|
|
8
|
+
.regex(new RegExp(`^${prefix}_[A-Za-z0-9_]+$`));
|
|
9
|
+
const coupon = z
|
|
10
|
+
.object({
|
|
11
|
+
id,
|
|
12
|
+
object: z.literal("coupon"),
|
|
13
|
+
deleted: z.literal(false).optional(),
|
|
14
|
+
duration: z.enum(["once", "repeating", "forever"]),
|
|
15
|
+
applies_to: z
|
|
16
|
+
.object({ products: z.array(id) })
|
|
17
|
+
.strict()
|
|
18
|
+
.optional(),
|
|
19
|
+
})
|
|
20
|
+
.passthrough();
|
|
21
|
+
const redemption = z
|
|
22
|
+
.object({
|
|
23
|
+
id: resourceId("di"),
|
|
24
|
+
object: z.literal("discount"),
|
|
25
|
+
deleted: z.literal(false).optional(),
|
|
26
|
+
customer_account: resourceId("acct"),
|
|
27
|
+
subscription: resourceId("sub").nullable(),
|
|
28
|
+
subscription_item: resourceId("si").nullable(),
|
|
29
|
+
start: z.number().int().nonnegative(),
|
|
30
|
+
end: z.number().int().nonnegative().nullable(),
|
|
31
|
+
source: z.object({ type: z.literal("coupon"), coupon }).passthrough(),
|
|
32
|
+
})
|
|
33
|
+
.passthrough();
|
|
34
|
+
const reference = (object, identity = id) => z.union([
|
|
35
|
+
identity,
|
|
36
|
+
z
|
|
37
|
+
.object({
|
|
38
|
+
id: identity,
|
|
39
|
+
object: z.literal(object),
|
|
40
|
+
deleted: z.literal(false).optional(),
|
|
41
|
+
})
|
|
42
|
+
.strict(),
|
|
43
|
+
]);
|
|
44
|
+
const inputSchema = z
|
|
45
|
+
.object({
|
|
46
|
+
customerAccountId: resourceId("acct"),
|
|
47
|
+
subscriptionId: resourceId("sub"),
|
|
48
|
+
level: z.enum(["subscription", "subscription_item"]),
|
|
49
|
+
itemId: resourceId("si").optional(),
|
|
50
|
+
currentProductId: id,
|
|
51
|
+
targetProductId: id,
|
|
52
|
+
redemptions: z.array(redemption).max(20),
|
|
53
|
+
phaseDiscounts: z
|
|
54
|
+
.array(z
|
|
55
|
+
.object({
|
|
56
|
+
discount: reference("discount", resourceId("di")),
|
|
57
|
+
coupon: reference("coupon").nullable().optional(),
|
|
58
|
+
promotion_code: z.null().optional(),
|
|
59
|
+
})
|
|
60
|
+
.passthrough())
|
|
61
|
+
.max(20),
|
|
62
|
+
})
|
|
63
|
+
.strict();
|
|
64
|
+
/**
|
|
65
|
+
* Project only a direct, unambiguous existing forever redemption. Ancestor-owned
|
|
66
|
+
* redemptions are unsupported. Phase references must be IDs or minimal reference
|
|
67
|
+
* objects; full expanded objects require separate normalization and correlation.
|
|
68
|
+
* This field projection requires provider qualification before writer eligibility.
|
|
69
|
+
*/
|
|
70
|
+
export function projectRenewalDiscounts(input) {
|
|
71
|
+
let parsed;
|
|
72
|
+
try {
|
|
73
|
+
parsed = inputSchema.safeParse(renewalSnapshot(input));
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return { status: "unsupported", reason: "incomplete_discount_evidence" };
|
|
77
|
+
}
|
|
78
|
+
if (!parsed.success)
|
|
79
|
+
return { status: "unsupported", reason: "incomplete_discount_evidence" };
|
|
80
|
+
const args = parsed.data;
|
|
81
|
+
const unsupported = (reason) => ({
|
|
82
|
+
status: "unsupported",
|
|
83
|
+
reason,
|
|
84
|
+
});
|
|
85
|
+
if (args.redemptions.length === 0 && args.phaseDiscounts.length === 0)
|
|
86
|
+
return unsupported("ambiguous_empty_discount_hierarchy");
|
|
87
|
+
if (args.redemptions.length !== args.phaseDiscounts.length)
|
|
88
|
+
return unsupported("phase_redemption_mismatch");
|
|
89
|
+
if (new Set(args.redemptions.map((v) => v.id)).size !== args.redemptions.length)
|
|
90
|
+
return unsupported("duplicate_redemptions");
|
|
91
|
+
const refId = (value) => typeof value === "string" ? value : value.id;
|
|
92
|
+
for (const [index, value] of args.redemptions.entries()) {
|
|
93
|
+
if (value.customer_account !== args.customerAccountId ||
|
|
94
|
+
(args.level === "subscription" &&
|
|
95
|
+
(value.subscription !== args.subscriptionId ||
|
|
96
|
+
value.subscription_item !== null)) ||
|
|
97
|
+
(args.level === "subscription_item" &&
|
|
98
|
+
(!args.itemId ||
|
|
99
|
+
value.subscription_item !== args.itemId ||
|
|
100
|
+
(value.subscription !== null &&
|
|
101
|
+
value.subscription !== args.subscriptionId))))
|
|
102
|
+
return unsupported("discount_not_owned_at_level");
|
|
103
|
+
if (value.source.coupon.duration !== "forever" || value.end !== null)
|
|
104
|
+
return unsupported("discount_duration_not_qualified");
|
|
105
|
+
const products = value.source.coupon.applies_to?.products;
|
|
106
|
+
if (products &&
|
|
107
|
+
(!products.includes(args.currentProductId) ||
|
|
108
|
+
!products.includes(args.targetProductId)))
|
|
109
|
+
return unsupported("coupon_product_applicability");
|
|
110
|
+
const phase = args.phaseDiscounts[index];
|
|
111
|
+
if (refId(phase.discount) !== value.id ||
|
|
112
|
+
(phase.coupon != null && refId(phase.coupon) !== value.source.coupon.id))
|
|
113
|
+
return unsupported("phase_redemption_mismatch");
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
status: "projected",
|
|
117
|
+
discounts: args.redemptions.map(({ id: discount }) => ({ discount })),
|
|
118
|
+
requiresProviderQualification: true,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=discounts.js.map
|
|
@@ -0,0 +1 @@
|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AAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC;gBACxC,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAE3C,OAAO,WAAW,CAAC,8BAA8B,CAAC,CAAC;QACrD,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAE,CAAC;QAC1C,IACE,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,EAAE;YAClC,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAExE,OAAO,WAAW,CAAC,2BAA2B,CAAC,CAAC;IACpD,CAAC;IACD,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrE,6BAA6B,EAAE,IAAI;KACpC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
type Settings = Pick<Stripe.SubscriptionScheduleUpdateParams.Phase.Item, "tax_rates" | "metadata">;
|
|
3
|
+
type Result = {
|
|
4
|
+
status: "unsupported";
|
|
5
|
+
reason: string;
|
|
6
|
+
} | {
|
|
7
|
+
status: "projected";
|
|
8
|
+
settings: Settings;
|
|
9
|
+
requiresProviderQualification: true;
|
|
10
|
+
};
|
|
11
|
+
/** Field projection only. The assembler must derive effective tax from defaults. */
|
|
12
|
+
export declare function projectRenewalItemSettings(input: unknown): Result;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=itemSettings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemSettings.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalProjection/itemSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAoBjC,KAAK,QAAQ,GAAG,IAAI,CAClB,MAAM,CAAC,gCAAgC,CAAC,KAAK,CAAC,IAAI,EAClD,WAAW,GAAG,UAAU,CACzB,CAAC;AACF,KAAK,MAAM,GACP;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzC;IACE,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,6BAA6B,EAAE,IAAI,CAAC;CACrC,CAAC;AAEN,oFAAoF;AACpF,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAqBjE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
3
|
+
import { taxRate } from "./settingsSchema.js";
|
|
4
|
+
const inputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
effectiveAutomaticTax: z.boolean(),
|
|
7
|
+
livemode: z.boolean(),
|
|
8
|
+
settings: z
|
|
9
|
+
.object({
|
|
10
|
+
billing_thresholds: z.null(),
|
|
11
|
+
tax_rates: z.array(taxRate).max(20).nullable().optional(),
|
|
12
|
+
metadata: z
|
|
13
|
+
.record(z.string().max(40), z.string().min(1).max(500))
|
|
14
|
+
.nullable(),
|
|
15
|
+
})
|
|
16
|
+
.strict(),
|
|
17
|
+
})
|
|
18
|
+
.strict();
|
|
19
|
+
/** Field projection only. The assembler must derive effective tax from defaults. */
|
|
20
|
+
export function projectRenewalItemSettings(input) {
|
|
21
|
+
let args;
|
|
22
|
+
try {
|
|
23
|
+
args = inputSchema.parse(renewalSnapshot(input));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return { status: "unsupported", reason: "unsupported_item_settings" };
|
|
27
|
+
}
|
|
28
|
+
const { settings: source } = args;
|
|
29
|
+
if ((args.effectiveAutomaticTax && source.tax_rates?.length) ||
|
|
30
|
+
source.tax_rates?.some((tax) => tax.livemode !== args.livemode))
|
|
31
|
+
return { status: "unsupported", reason: "incompatible_item_tax" };
|
|
32
|
+
const settings = {};
|
|
33
|
+
if (source.tax_rates != null)
|
|
34
|
+
settings.tax_rates = source.tax_rates.length
|
|
35
|
+
? source.tax_rates.map((tax) => tax.id)
|
|
36
|
+
: "";
|
|
37
|
+
if (source.metadata !== null && Object.keys(source.metadata).length)
|
|
38
|
+
settings.metadata = source.metadata;
|
|
39
|
+
return { status: "projected", settings, requiresProviderQualification: true };
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=itemSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemSettings.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalProjection/itemSettings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,MAAM,WAAW,GAAG,CAAC;KAClB,MAAM,CAAC;IACN,qBAAqB,EAAE,CAAC,CAAC,OAAO,EAAE;IAClC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,QAAQ,EAAE,CAAC;SACR,MAAM,CAAC;QACN,kBAAkB,EAAE,CAAC,CAAC,IAAI,EAAE;QAC5B,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;QACzD,QAAQ,EAAE,CAAC;aACR,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,G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AAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,6BAA6B,EAAE,IAAI,EAAE,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
type Settings = Pick<Stripe.SubscriptionScheduleUpdateParams.Phase, "collection_method" | "default_payment_method" | "on_behalf_of" | "transfer_data" | "automatic_tax" | "default_tax_rates" | "invoice_settings" | "description" | "metadata">;
|
|
3
|
+
type Result = {
|
|
4
|
+
status: "unsupported";
|
|
5
|
+
reason: string;
|
|
6
|
+
} | {
|
|
7
|
+
status: "projected";
|
|
8
|
+
settings: Settings;
|
|
9
|
+
requiresProviderQualification: true;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Map only the named fields of a provider phase. The aggregate assembler must
|
|
13
|
+
* correlate context with its full acknowledged schedule and unchanged defaults.
|
|
14
|
+
* A projection is neither a complete phase nor evidence of provider retention.
|
|
15
|
+
*/
|
|
16
|
+
export declare function projectRenewalPhaseSettings(input: unknown): Result;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalProjection/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAKjC,KAAK,QAAQ,GAAG,IAAI,CAClB,MAAM,CAAC,gCAAgC,CAAC,KAAK,EAC3C,mBAAmB,GACnB,wBAAwB,GACxB,cAAc,GACd,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,kBAAkB,GAClB,aAAa,GACb,UAAU,CACb,CAAC;AACF,KAAK,MAAM,GACP;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzC;IACE,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,6BAA6B,EAAE,IAAI,CAAC;CACrC,CAAC;AAIN;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkIlE"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
2
|
+
import { settingsInput } from "./settingsSchema.js";
|
|
3
|
+
const identity = (ref) => (typeof ref === "string" ? ref : ref.id);
|
|
4
|
+
/**
|
|
5
|
+
* Map only the named fields of a provider phase. The aggregate assembler must
|
|
6
|
+
* correlate context with its full acknowledged schedule and unchanged defaults.
|
|
7
|
+
* A projection is neither a complete phase nor evidence of provider retention.
|
|
8
|
+
*/
|
|
9
|
+
export function projectRenewalPhaseSettings(input) {
|
|
10
|
+
let args;
|
|
11
|
+
try {
|
|
12
|
+
args = settingsInput.parse(renewalSnapshot(input));
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return { status: "unsupported", reason: "unsupported_phase_settings" };
|
|
16
|
+
}
|
|
17
|
+
const { settings: source, context } = args;
|
|
18
|
+
const failure = (reason) => ({
|
|
19
|
+
status: "unsupported",
|
|
20
|
+
reason,
|
|
21
|
+
});
|
|
22
|
+
const referenceMatches = (ref) => {
|
|
23
|
+
if (ref == null || typeof ref === "string")
|
|
24
|
+
return true;
|
|
25
|
+
const customer = ref.customer;
|
|
26
|
+
if (typeof customer === "object" &&
|
|
27
|
+
customer !== null &&
|
|
28
|
+
((customer.livemode !== undefined &&
|
|
29
|
+
customer.livemode !== context.livemode) ||
|
|
30
|
+
(customer.customer_account !== undefined &&
|
|
31
|
+
customer.customer_account !== context.customerAccountId)))
|
|
32
|
+
return false;
|
|
33
|
+
return ((ref.livemode === undefined || ref.livemode === context.livemode) &&
|
|
34
|
+
(ref.customer_account == null ||
|
|
35
|
+
ref.customer_account === context.customerAccountId) &&
|
|
36
|
+
(customer == null || identity(customer) === context.customerId));
|
|
37
|
+
};
|
|
38
|
+
const references = [
|
|
39
|
+
source.default_payment_method,
|
|
40
|
+
source.on_behalf_of,
|
|
41
|
+
source.transfer_data?.destination,
|
|
42
|
+
...(source.invoice_settings?.account_tax_ids ?? []),
|
|
43
|
+
...(source.default_tax_rates ?? []),
|
|
44
|
+
source.automatic_tax?.liability?.account,
|
|
45
|
+
source.invoice_settings?.issuer?.account,
|
|
46
|
+
];
|
|
47
|
+
if (!references.every(referenceMatches))
|
|
48
|
+
return failure("foreign_setting_reference");
|
|
49
|
+
const issuerIdentity = (issuer) => issuer.type === "self" ? "self" : identity(issuer.account);
|
|
50
|
+
if (source.invoice_settings?.issuer != null &&
|
|
51
|
+
issuerIdentity(source.invoice_settings.issuer) !==
|
|
52
|
+
issuerIdentity(context.effectiveInvoiceIssuer))
|
|
53
|
+
return failure("invoice_issuer_mismatch");
|
|
54
|
+
for (const taxId of source.invoice_settings?.account_tax_ids ?? []) {
|
|
55
|
+
if (typeof taxId === "string")
|
|
56
|
+
continue;
|
|
57
|
+
const owner = taxId.owner;
|
|
58
|
+
if (issuerIdentity(owner) !==
|
|
59
|
+
issuerIdentity(context.effectiveInvoiceIssuer) ||
|
|
60
|
+
(owner.type === "account" && !referenceMatches(owner.account)))
|
|
61
|
+
return failure("foreign_invoice_tax_owner");
|
|
62
|
+
}
|
|
63
|
+
if (source.collection_method != null &&
|
|
64
|
+
source.collection_method !== context.effectiveCollectionMethod)
|
|
65
|
+
return failure("collection_method_mismatch");
|
|
66
|
+
if (source.automatic_tax !== undefined &&
|
|
67
|
+
source.automatic_tax.enabled !== context.effectiveAutomaticTax)
|
|
68
|
+
return failure("automatic_tax_mismatch");
|
|
69
|
+
if (context.effectiveAutomaticTax && source.default_tax_rates?.length)
|
|
70
|
+
return failure("automatic_and_manual_tax");
|
|
71
|
+
const out = {};
|
|
72
|
+
if (source.collection_method !== null)
|
|
73
|
+
out.collection_method = source.collection_method;
|
|
74
|
+
if (source.default_payment_method !== null)
|
|
75
|
+
out.default_payment_method = identity(source.default_payment_method);
|
|
76
|
+
if (source.on_behalf_of !== null)
|
|
77
|
+
out.on_behalf_of = identity(source.on_behalf_of);
|
|
78
|
+
if (source.transfer_data !== null) {
|
|
79
|
+
out.transfer_data = {
|
|
80
|
+
destination: identity(source.transfer_data.destination),
|
|
81
|
+
};
|
|
82
|
+
if (source.transfer_data.amount_percent !== null)
|
|
83
|
+
out.transfer_data.amount_percent = source.transfer_data.amount_percent;
|
|
84
|
+
}
|
|
85
|
+
const mapIssuer = (issuer) => issuer?.type === "account"
|
|
86
|
+
? { type: "account", account: identity(issuer.account) }
|
|
87
|
+
: { type: "self" };
|
|
88
|
+
if (source.automatic_tax !== undefined) {
|
|
89
|
+
out.automatic_tax = { enabled: source.automatic_tax.enabled };
|
|
90
|
+
if (source.automatic_tax.liability != null)
|
|
91
|
+
out.automatic_tax.liability = mapIssuer(source.automatic_tax.liability);
|
|
92
|
+
}
|
|
93
|
+
if (source.default_tax_rates != null)
|
|
94
|
+
out.default_tax_rates = source.default_tax_rates.length
|
|
95
|
+
? source.default_tax_rates.map(identity)
|
|
96
|
+
: "";
|
|
97
|
+
const invoice = source.invoice_settings;
|
|
98
|
+
if (invoice !== null) {
|
|
99
|
+
const mapped = {};
|
|
100
|
+
if (invoice.account_tax_ids !== null)
|
|
101
|
+
mapped.account_tax_ids = invoice.account_tax_ids.length
|
|
102
|
+
? invoice.account_tax_ids.map(identity)
|
|
103
|
+
: "";
|
|
104
|
+
if (invoice.custom_fields !== null)
|
|
105
|
+
mapped.custom_fields = invoice.custom_fields.length
|
|
106
|
+
? invoice.custom_fields.map(({ name, value }) => ({ name, value }))
|
|
107
|
+
: "";
|
|
108
|
+
if (invoice.issuer !== null)
|
|
109
|
+
mapped.issuer = mapIssuer(invoice.issuer);
|
|
110
|
+
if (invoice.days_until_due !== null) {
|
|
111
|
+
if (context.effectiveCollectionMethod !== "send_invoice")
|
|
112
|
+
return failure("incompatible_invoice_due_days");
|
|
113
|
+
mapped.days_until_due = invoice.days_until_due;
|
|
114
|
+
}
|
|
115
|
+
if (invoice.description !== null)
|
|
116
|
+
mapped.description = invoice.description;
|
|
117
|
+
if (invoice.footer !== null)
|
|
118
|
+
mapped.footer = invoice.footer;
|
|
119
|
+
if (Object.keys(mapped).length)
|
|
120
|
+
out.invoice_settings = mapped;
|
|
121
|
+
}
|
|
122
|
+
if (source.description !== null)
|
|
123
|
+
out.description = source.description;
|
|
124
|
+
if (source.metadata !== null && Object.keys(source.metadata).length)
|
|
125
|
+
out.metadata = source.metadata;
|
|
126
|
+
return {
|
|
127
|
+
status: "projected",
|
|
128
|
+
settings: out,
|
|
129
|
+
requiresProviderQualification: true,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=settings.js.map
|