@fantastic.dev/better-stripe 0.81.0 → 0.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAggregate/configure.d.ts +35 -0
- package/dist/client/billing/renewalAggregate/configure.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/configure.js +96 -0
- package/dist/client/billing/renewalAggregate/configure.js.map +1 -0
- package/dist/client/billing/renewalAggregate/index.d.ts +3 -0
- package/dist/client/billing/renewalAggregate/index.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/index.js +3 -0
- package/dist/client/billing/renewalAggregate/index.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts +176 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js +112 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts +7 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.js +192 -0
- package/dist/client/billing/renewalAggregate/phases.js.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts +594 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.js +164 -0
- package/dist/client/billing/renewalAggregate/preflight.js.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.js +60 -0
- package/dist/client/billing/renewalAggregate/profile.js.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts +40 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.js +62 -0
- package/dist/client/billing/renewalAggregate/receipt.js.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts +51 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.js +87 -0
- package/dist/client/billing/renewalAggregate/shared.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts +42 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js +90 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts +136 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js +82 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js +23 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-phase-assembly.md +180 -0
- package/docs/renewal-price-replacements.md +2 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAggregate/configure.test.ts +372 -0
- package/src/client/billing/renewalAggregate/configure.ts +164 -0
- package/src/client/billing/renewalAggregate/index.ts +2 -0
- package/src/client/billing/renewalAggregate/phaseContext.ts +144 -0
- package/src/client/billing/renewalAggregate/phases.ts +247 -0
- package/src/client/billing/renewalAggregate/preflight.test.ts +233 -0
- package/src/client/billing/renewalAggregate/preflight.ts +211 -0
- package/src/client/billing/renewalAggregate/profile.ts +76 -0
- package/src/client/billing/renewalAggregate/receipt.ts +76 -0
- package/src/client/billing/renewalAggregate/shared.ts +106 -0
- package/src/client/billing/renewalAggregate/sourceAndTaxRetention.test.ts +247 -0
- package/src/client/billing/renewalAggregate/sourceDiscounts.ts +112 -0
- package/src/client/billing/renewalAggregate/sourceSettings.ts +88 -0
- package/src/client/billing/renewalAggregate/taxRetention.ts +28 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { settingsInput } from "../renewalProjection/settingsSchema.js";
|
|
2
|
+
import { projectRenewalPhaseSettings } from "../renewalProjection/settings.js";
|
|
3
|
+
import { projectRenewalItemSettings } from "../renewalProjection/itemSettings.js";
|
|
4
|
+
import { explicitTaxIds } from "./taxRetention.js";
|
|
5
|
+
import { unsupported } from "./shared.js";
|
|
6
|
+
|
|
7
|
+
const invoiceSchema = settingsInput.shape.settings.shape.invoice_settings
|
|
8
|
+
.unwrap()
|
|
9
|
+
.omit({ days_until_due: true })
|
|
10
|
+
.extend({
|
|
11
|
+
issuer: settingsInput.shape.context.shape.effectiveInvoiceIssuer,
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Classify actual original subscription/item fields before any attachment.
|
|
17
|
+
* The field projections below are validation views, not fabricated phase reads
|
|
18
|
+
* or provider acknowledgement. Their output is never dispatched or adopted.
|
|
19
|
+
*/
|
|
20
|
+
export function qualifyOriginalSettings(
|
|
21
|
+
subscription: Record<string, unknown>,
|
|
22
|
+
item: Record<string, unknown>,
|
|
23
|
+
customer: { id: string; customer_account: string; livemode: boolean },
|
|
24
|
+
) {
|
|
25
|
+
const invoice = invoiceSchema.safeParse(subscription.invoice_settings);
|
|
26
|
+
if (!invoice.success) unsupported("unsupported_original_invoice_settings");
|
|
27
|
+
const automaticTax = settingsInput.shape.settings.shape.automatic_tax
|
|
28
|
+
.unwrap()
|
|
29
|
+
.safeParse(subscription.automatic_tax);
|
|
30
|
+
if (!automaticTax.success) unsupported("unsupported_original_automatic_tax");
|
|
31
|
+
const parsedContext = settingsInput.shape.context.safeParse({
|
|
32
|
+
customerId: customer.id,
|
|
33
|
+
customerAccountId: customer.customer_account,
|
|
34
|
+
livemode: customer.livemode,
|
|
35
|
+
effectiveCollectionMethod: subscription.collection_method,
|
|
36
|
+
effectiveAutomaticTax: automaticTax.data.enabled,
|
|
37
|
+
effectiveInvoiceIssuer: invoice.data.issuer,
|
|
38
|
+
});
|
|
39
|
+
if (!parsedContext.success)
|
|
40
|
+
unsupported("unsupported_original_billing_context");
|
|
41
|
+
const context = parsedContext.data;
|
|
42
|
+
const taxLevels = {
|
|
43
|
+
subscription: explicitTaxIds(
|
|
44
|
+
subscription.default_tax_rates,
|
|
45
|
+
"original_subscription",
|
|
46
|
+
),
|
|
47
|
+
item: explicitTaxIds(item.tax_rates, "original_item"),
|
|
48
|
+
};
|
|
49
|
+
const projection = projectRenewalPhaseSettings({
|
|
50
|
+
context,
|
|
51
|
+
settings: {
|
|
52
|
+
application_fee_percent: subscription.application_fee_percent,
|
|
53
|
+
billing_thresholds: subscription.billing_thresholds,
|
|
54
|
+
collection_method: subscription.collection_method,
|
|
55
|
+
default_payment_method: subscription.default_payment_method,
|
|
56
|
+
on_behalf_of: subscription.on_behalf_of,
|
|
57
|
+
transfer_data: subscription.transfer_data,
|
|
58
|
+
automatic_tax: automaticTax.data,
|
|
59
|
+
default_tax_rates: subscription.default_tax_rates,
|
|
60
|
+
// days_until_due is a top-level Subscription field in Stripe 23.
|
|
61
|
+
invoice_settings: {
|
|
62
|
+
...invoice.data,
|
|
63
|
+
days_until_due: subscription.days_until_due,
|
|
64
|
+
},
|
|
65
|
+
description: subscription.description,
|
|
66
|
+
metadata: null,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
if (projection.status !== "projected")
|
|
70
|
+
unsupported(`unsupported_original_settings_${projection.reason}`);
|
|
71
|
+
const itemProjection = projectRenewalItemSettings({
|
|
72
|
+
effectiveAutomaticTax: context.effectiveAutomaticTax,
|
|
73
|
+
livemode: context.livemode,
|
|
74
|
+
settings: {
|
|
75
|
+
billing_thresholds: item.billing_thresholds,
|
|
76
|
+
tax_rates: item.tax_rates,
|
|
77
|
+
metadata: item.metadata,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
if (itemProjection.status !== "projected")
|
|
81
|
+
unsupported(`unsupported_original_${itemProjection.reason}`);
|
|
82
|
+
return {
|
|
83
|
+
context,
|
|
84
|
+
invoice: invoice.data,
|
|
85
|
+
automaticTax: automaticTax.data,
|
|
86
|
+
taxLevels,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { taxRate } from "../renewalProjection/settingsSchema.js";
|
|
3
|
+
import { equal, unsupported } from "./shared.js";
|
|
4
|
+
|
|
5
|
+
/** Null/absent read hierarchies are not evidence of an explicit empty list. */
|
|
6
|
+
export function explicitTaxIds(value: unknown, level: string): string[] {
|
|
7
|
+
const parsed = z.array(taxRate).max(20).safeParse(value);
|
|
8
|
+
if (!parsed.success) unsupported(`unproven_${level}_tax_hierarchy`);
|
|
9
|
+
return parsed.data.map((tax) => tax.id);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type OriginalTaxLevels = { subscription: string[]; item: string[] };
|
|
13
|
+
|
|
14
|
+
export function preserveTaxLevels(
|
|
15
|
+
original: OriginalTaxLevels,
|
|
16
|
+
phaseTax: unknown,
|
|
17
|
+
phaseItemTax: unknown,
|
|
18
|
+
) {
|
|
19
|
+
const phase = explicitTaxIds(phaseTax, "phase_default");
|
|
20
|
+
const item = explicitTaxIds(phaseItemTax, "phase_item");
|
|
21
|
+
if (!equal(original.subscription, phase))
|
|
22
|
+
unsupported("phase_default_tax_retention_mismatch");
|
|
23
|
+
// An empty item array means no item override. Its subscription/phase default
|
|
24
|
+
// applies instead. Equal current totals cannot authorize changing that level.
|
|
25
|
+
if (original.item.length > 0 !== item.length > 0)
|
|
26
|
+
unsupported("item_tax_override_level_changed");
|
|
27
|
+
if (!equal(original.item, item)) unsupported("item_tax_retention_mismatch");
|
|
28
|
+
}
|