@fantastic.dev/better-stripe 0.81.0 → 0.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAggregate/configure.d.ts +35 -0
- package/dist/client/billing/renewalAggregate/configure.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/configure.js +96 -0
- package/dist/client/billing/renewalAggregate/configure.js.map +1 -0
- package/dist/client/billing/renewalAggregate/index.d.ts +3 -0
- package/dist/client/billing/renewalAggregate/index.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/index.js +3 -0
- package/dist/client/billing/renewalAggregate/index.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts +176 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js +112 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts +7 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.js +192 -0
- package/dist/client/billing/renewalAggregate/phases.js.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts +594 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.js +164 -0
- package/dist/client/billing/renewalAggregate/preflight.js.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.js +60 -0
- package/dist/client/billing/renewalAggregate/profile.js.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts +40 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.js +62 -0
- package/dist/client/billing/renewalAggregate/receipt.js.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts +51 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.js +87 -0
- package/dist/client/billing/renewalAggregate/shared.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts +42 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js +90 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts +136 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js +82 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js +23 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js.map +1 -0
- package/dist/client/billing/renewalAttach/couponJoins.d.ts +23 -0
- package/dist/client/billing/renewalAttach/couponJoins.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/couponJoins.js +76 -0
- package/dist/client/billing/renewalAttach/couponJoins.js.map +1 -0
- package/dist/client/billing/renewalAttach/index.d.ts +3 -0
- package/dist/client/billing/renewalAttach/index.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/index.js +3 -0
- package/dist/client/billing/renewalAttach/index.js.map +1 -0
- package/dist/client/billing/renewalAttach/reader.d.ts +141 -0
- package/dist/client/billing/renewalAttach/reader.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/reader.js +80 -0
- package/dist/client/billing/renewalAttach/reader.js.map +1 -0
- package/dist/client/billing/renewalAttach/request.d.ts +30 -0
- package/dist/client/billing/renewalAttach/request.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/request.js +39 -0
- package/dist/client/billing/renewalAttach/request.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 -5
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -3
- package/dist/client/index.js.map +1 -1
- package/dist/client/renewal.d.ts +8 -0
- package/dist/client/renewal.d.ts.map +1 -0
- package/dist/client/renewal.js +4 -0
- package/dist/client/renewal.js.map +1 -0
- package/dist/client/renewalContextClient.d.ts +130 -0
- package/dist/client/renewalContextClient.d.ts.map +1 -0
- package/dist/client/renewalContextClient.js +10 -0
- package/dist/client/renewalContextClient.js.map +1 -0
- package/dist/client/usage/observationClient.d.ts +2 -2
- package/dist/client/usage/observationClient.d.ts.map +1 -1
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- 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/renewal-context-reads.md +113 -0
- package/docs/renewal-phase-assembly.md +180 -0
- package/docs/renewal-price-replacements.md +57 -16
- 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
- package/src/client/billing/renewalAttach/couponEvidence.test.ts +104 -0
- package/src/client/billing/renewalAttach/couponJoins.ts +95 -0
- package/src/client/billing/renewalAttach/index.ts +9 -0
- package/src/client/billing/renewalAttach/reader.test.ts +409 -0
- package/src/client/billing/renewalAttach/reader.ts +131 -0
- package/src/client/billing/renewalAttach/request.ts +49 -0
- package/src/client/index.ts +3 -8
- package/src/client/renewal.ts +13 -0
- package/src/client/renewalContextClient.ts +23 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { resourceId, unsupported } from "./shared.js";
|
|
3
|
+
const customId = z.string().min(1).max(255).regex(/\S/);
|
|
4
|
+
const originalRedemptions = z
|
|
5
|
+
.array(z
|
|
6
|
+
.object({
|
|
7
|
+
id: resourceId("di"),
|
|
8
|
+
object: z.literal("discount"),
|
|
9
|
+
deleted: z.literal(false).optional(),
|
|
10
|
+
customer_account: resourceId("acct"),
|
|
11
|
+
customer: z
|
|
12
|
+
.union([
|
|
13
|
+
resourceId("cus"),
|
|
14
|
+
z
|
|
15
|
+
.object({
|
|
16
|
+
id: resourceId("cus"),
|
|
17
|
+
object: z.literal("customer"),
|
|
18
|
+
deleted: z.literal(false).optional(),
|
|
19
|
+
livemode: z.boolean().optional(),
|
|
20
|
+
customer_account: resourceId("acct").nullable().optional(),
|
|
21
|
+
})
|
|
22
|
+
.passthrough(),
|
|
23
|
+
])
|
|
24
|
+
.nullable()
|
|
25
|
+
.optional(),
|
|
26
|
+
subscription: resourceId("sub").nullable(),
|
|
27
|
+
subscription_item: resourceId("si").nullable(),
|
|
28
|
+
start: z.number().int().nonnegative(),
|
|
29
|
+
end: z.null(),
|
|
30
|
+
source: z
|
|
31
|
+
.object({
|
|
32
|
+
type: z.literal("coupon"),
|
|
33
|
+
coupon: z
|
|
34
|
+
.object({
|
|
35
|
+
id: customId,
|
|
36
|
+
object: z.literal("coupon"),
|
|
37
|
+
deleted: z.literal(false).optional(),
|
|
38
|
+
livemode: z.boolean().optional(),
|
|
39
|
+
duration: z.literal("forever"),
|
|
40
|
+
applies_to: z
|
|
41
|
+
.object({ products: z.array(customId) })
|
|
42
|
+
.strict()
|
|
43
|
+
.optional(),
|
|
44
|
+
})
|
|
45
|
+
.passthrough(),
|
|
46
|
+
})
|
|
47
|
+
.passthrough(),
|
|
48
|
+
})
|
|
49
|
+
.passthrough())
|
|
50
|
+
.max(20);
|
|
51
|
+
export function qualifySourceDiscounts(value, level, context, customerId, observedAt) {
|
|
52
|
+
const parsed = originalRedemptions.safeParse(value);
|
|
53
|
+
if (!parsed.success)
|
|
54
|
+
unsupported("incomplete_or_unsupported_discount_evidence");
|
|
55
|
+
if (!parsed.data.length)
|
|
56
|
+
unsupported("ambiguous_empty_discount_hierarchy");
|
|
57
|
+
if (new Set(parsed.data.map((discount) => discount.id)).size !==
|
|
58
|
+
parsed.data.length)
|
|
59
|
+
unsupported("duplicate_discount_redemptions");
|
|
60
|
+
for (const discount of parsed.data) {
|
|
61
|
+
const customer = discount.customer;
|
|
62
|
+
if (discount.customer_account !== context.customerAccountId ||
|
|
63
|
+
discount.start > observedAt ||
|
|
64
|
+
(typeof customer === "string" && customer !== customerId) ||
|
|
65
|
+
(typeof customer === "object" &&
|
|
66
|
+
customer !== null &&
|
|
67
|
+
(customer.id !== customerId ||
|
|
68
|
+
(customer.livemode !== undefined &&
|
|
69
|
+
customer.livemode !== context.livemode) ||
|
|
70
|
+
(customer.customer_account !== undefined &&
|
|
71
|
+
customer.customer_account !== context.customerAccountId))) ||
|
|
72
|
+
(level === "subscription" &&
|
|
73
|
+
(discount.subscription !== context.subscriptionId ||
|
|
74
|
+
discount.subscription_item !== null)) ||
|
|
75
|
+
(level === "item" &&
|
|
76
|
+
(discount.subscription_item !== context.itemId ||
|
|
77
|
+
(discount.subscription !== null &&
|
|
78
|
+
discount.subscription !== context.subscriptionId))))
|
|
79
|
+
unsupported("discount_owner_or_start_mismatch");
|
|
80
|
+
const coupon = discount.source.coupon;
|
|
81
|
+
if (coupon.livemode !== undefined && coupon.livemode !== context.livemode)
|
|
82
|
+
unsupported("discount_coupon_mode_mismatch");
|
|
83
|
+
if (coupon.applies_to &&
|
|
84
|
+
(!coupon.applies_to.products.includes(context.currentProductId) ||
|
|
85
|
+
!coupon.applies_to.products.includes(context.targetProductId)))
|
|
86
|
+
unsupported("discount_product_applicability");
|
|
87
|
+
}
|
|
88
|
+
return parsed.data;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=sourceDiscounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceDiscounts.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/sourceDiscounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACxD,MAAM,mBAAmB,GAAG,CAAC;KAC1B,KAAK,CACJ,CAAC;KACE,MAAM,CAAC;IACN,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC;IACpB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC7B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IACpC,gBAAgB,EAAE,UAAU,CAAC,MAAM,CAAC;IACpC,QAAQ,EAAE,CAAC;SACR,KAAK,CAAC;QACL,UAAU,CAAC,KAAK,CAAC;QACjB,CAAC;aACE,MAAM,CAAC;YACN,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC;YACrB,MAAM,EAAE,CAAC,CAA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YAAY,KAAK,OAAO,CAAC,cAAc;oBAC/C,QAAQ,CAAC,iBAAiB,KAAK,IAAI,CAAC,CAAC;YACzC,CAAC,KAAK,KAAK,MAAM;gBACf,CAAC,QAAQ,CAAC,iBAAiB,KAAK,OAAO,CAAC,MAAM;oBAC5C,CAAC,QAAQ,CAAC,YAAY,KAAK,IAAI;wBAC7B,QAAQ,CAAC,YAAY,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;YAEzD,WAAW,CAAC,kCAAkC,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,QAAQ;YACvE,WAAW,CAAC,+BAA+B,CAAC,CAAC;QAC/C,IACE,MAAM,CAAC,UAAU;YACjB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC;gBAC7D,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YAEhE,WAAW,CAAC,gCAAgC,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify actual original subscription/item fields before any attachment.
|
|
3
|
+
* The field projections below are validation views, not fabricated phase reads
|
|
4
|
+
* or provider acknowledgement. Their output is never dispatched or adopted.
|
|
5
|
+
*/
|
|
6
|
+
export declare function qualifyOriginalSettings(subscription: Record<string, unknown>, item: Record<string, unknown>, customer: {
|
|
7
|
+
id: string;
|
|
8
|
+
customer_account: string;
|
|
9
|
+
livemode: boolean;
|
|
10
|
+
}): {
|
|
11
|
+
context: {
|
|
12
|
+
customerAccountId: string;
|
|
13
|
+
customerId: string;
|
|
14
|
+
livemode: boolean;
|
|
15
|
+
effectiveCollectionMethod: "charge_automatically" | "send_invoice";
|
|
16
|
+
effectiveAutomaticTax: boolean;
|
|
17
|
+
effectiveInvoiceIssuer: {
|
|
18
|
+
type: "self";
|
|
19
|
+
account?: null | undefined;
|
|
20
|
+
} | {
|
|
21
|
+
type: "account";
|
|
22
|
+
account: string | {
|
|
23
|
+
[x: string]: unknown;
|
|
24
|
+
id: string;
|
|
25
|
+
object: string;
|
|
26
|
+
deleted?: false | undefined;
|
|
27
|
+
livemode?: boolean | undefined;
|
|
28
|
+
customer?: string | {
|
|
29
|
+
[x: string]: unknown;
|
|
30
|
+
id: string;
|
|
31
|
+
object: "customer";
|
|
32
|
+
deleted?: false | undefined;
|
|
33
|
+
livemode?: boolean | undefined;
|
|
34
|
+
customer_account?: string | null | undefined;
|
|
35
|
+
} | null | undefined;
|
|
36
|
+
customer_account?: string | null | undefined;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
invoice: {
|
|
41
|
+
account_tax_ids: (string | {
|
|
42
|
+
[x: string]: unknown;
|
|
43
|
+
id: string;
|
|
44
|
+
object: "tax_id";
|
|
45
|
+
deleted?: false | undefined;
|
|
46
|
+
livemode: boolean;
|
|
47
|
+
customer?: null | undefined;
|
|
48
|
+
customer_account?: null | undefined;
|
|
49
|
+
owner: {
|
|
50
|
+
type: "self";
|
|
51
|
+
customer_account: null;
|
|
52
|
+
account?: null | undefined;
|
|
53
|
+
customer?: null | undefined;
|
|
54
|
+
} | {
|
|
55
|
+
type: "account";
|
|
56
|
+
account: string | {
|
|
57
|
+
[x: string]: unknown;
|
|
58
|
+
id: string;
|
|
59
|
+
object: string;
|
|
60
|
+
deleted?: false | undefined;
|
|
61
|
+
livemode?: boolean | undefined;
|
|
62
|
+
customer?: string | {
|
|
63
|
+
[x: string]: unknown;
|
|
64
|
+
id: string;
|
|
65
|
+
object: "customer";
|
|
66
|
+
deleted?: false | undefined;
|
|
67
|
+
livemode?: boolean | undefined;
|
|
68
|
+
customer_account?: string | null | undefined;
|
|
69
|
+
} | null | undefined;
|
|
70
|
+
customer_account?: string | null | undefined;
|
|
71
|
+
};
|
|
72
|
+
customer_account: null;
|
|
73
|
+
customer?: null | undefined;
|
|
74
|
+
};
|
|
75
|
+
})[] | null;
|
|
76
|
+
custom_fields: {
|
|
77
|
+
name: string;
|
|
78
|
+
value: string;
|
|
79
|
+
}[] | null;
|
|
80
|
+
description: string | null;
|
|
81
|
+
footer: string | null;
|
|
82
|
+
issuer: {
|
|
83
|
+
type: "self";
|
|
84
|
+
account?: null | undefined;
|
|
85
|
+
} | {
|
|
86
|
+
type: "account";
|
|
87
|
+
account: string | {
|
|
88
|
+
[x: string]: unknown;
|
|
89
|
+
id: string;
|
|
90
|
+
object: string;
|
|
91
|
+
deleted?: false | undefined;
|
|
92
|
+
livemode?: boolean | undefined;
|
|
93
|
+
customer?: string | {
|
|
94
|
+
[x: string]: unknown;
|
|
95
|
+
id: string;
|
|
96
|
+
object: "customer";
|
|
97
|
+
deleted?: false | undefined;
|
|
98
|
+
livemode?: boolean | undefined;
|
|
99
|
+
customer_account?: string | null | undefined;
|
|
100
|
+
} | null | undefined;
|
|
101
|
+
customer_account?: string | null | undefined;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
automaticTax: {
|
|
106
|
+
enabled: boolean;
|
|
107
|
+
liability?: {
|
|
108
|
+
type: "self";
|
|
109
|
+
account?: null | undefined;
|
|
110
|
+
} | {
|
|
111
|
+
type: "account";
|
|
112
|
+
account: string | {
|
|
113
|
+
[x: string]: unknown;
|
|
114
|
+
id: string;
|
|
115
|
+
object: string;
|
|
116
|
+
deleted?: false | undefined;
|
|
117
|
+
livemode?: boolean | undefined;
|
|
118
|
+
customer?: string | {
|
|
119
|
+
[x: string]: unknown;
|
|
120
|
+
id: string;
|
|
121
|
+
object: "customer";
|
|
122
|
+
deleted?: false | undefined;
|
|
123
|
+
livemode?: boolean | undefined;
|
|
124
|
+
customer_account?: string | null | undefined;
|
|
125
|
+
} | null | undefined;
|
|
126
|
+
customer_account?: string | null | undefined;
|
|
127
|
+
};
|
|
128
|
+
} | null | undefined;
|
|
129
|
+
disabled_reason?: null | undefined;
|
|
130
|
+
};
|
|
131
|
+
taxLevels: {
|
|
132
|
+
subscription: string[];
|
|
133
|
+
item: string[];
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=sourceSettings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceSettings.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/sourceSettings.ts"],"names":[],"mappings":"AAcA;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiEtE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
const invoiceSchema = settingsInput.shape.settings.shape.invoice_settings
|
|
7
|
+
.unwrap()
|
|
8
|
+
.omit({ days_until_due: true })
|
|
9
|
+
.extend({
|
|
10
|
+
issuer: settingsInput.shape.context.shape.effectiveInvoiceIssuer,
|
|
11
|
+
})
|
|
12
|
+
.strict();
|
|
13
|
+
/**
|
|
14
|
+
* Classify actual original subscription/item fields before any attachment.
|
|
15
|
+
* The field projections below are validation views, not fabricated phase reads
|
|
16
|
+
* or provider acknowledgement. Their output is never dispatched or adopted.
|
|
17
|
+
*/
|
|
18
|
+
export function qualifyOriginalSettings(subscription, item, customer) {
|
|
19
|
+
const invoice = invoiceSchema.safeParse(subscription.invoice_settings);
|
|
20
|
+
if (!invoice.success)
|
|
21
|
+
unsupported("unsupported_original_invoice_settings");
|
|
22
|
+
const automaticTax = settingsInput.shape.settings.shape.automatic_tax
|
|
23
|
+
.unwrap()
|
|
24
|
+
.safeParse(subscription.automatic_tax);
|
|
25
|
+
if (!automaticTax.success)
|
|
26
|
+
unsupported("unsupported_original_automatic_tax");
|
|
27
|
+
const parsedContext = settingsInput.shape.context.safeParse({
|
|
28
|
+
customerId: customer.id,
|
|
29
|
+
customerAccountId: customer.customer_account,
|
|
30
|
+
livemode: customer.livemode,
|
|
31
|
+
effectiveCollectionMethod: subscription.collection_method,
|
|
32
|
+
effectiveAutomaticTax: automaticTax.data.enabled,
|
|
33
|
+
effectiveInvoiceIssuer: invoice.data.issuer,
|
|
34
|
+
});
|
|
35
|
+
if (!parsedContext.success)
|
|
36
|
+
unsupported("unsupported_original_billing_context");
|
|
37
|
+
const context = parsedContext.data;
|
|
38
|
+
const taxLevels = {
|
|
39
|
+
subscription: explicitTaxIds(subscription.default_tax_rates, "original_subscription"),
|
|
40
|
+
item: explicitTaxIds(item.tax_rates, "original_item"),
|
|
41
|
+
};
|
|
42
|
+
const projection = projectRenewalPhaseSettings({
|
|
43
|
+
context,
|
|
44
|
+
settings: {
|
|
45
|
+
application_fee_percent: subscription.application_fee_percent,
|
|
46
|
+
billing_thresholds: subscription.billing_thresholds,
|
|
47
|
+
collection_method: subscription.collection_method,
|
|
48
|
+
default_payment_method: subscription.default_payment_method,
|
|
49
|
+
on_behalf_of: subscription.on_behalf_of,
|
|
50
|
+
transfer_data: subscription.transfer_data,
|
|
51
|
+
automatic_tax: automaticTax.data,
|
|
52
|
+
default_tax_rates: subscription.default_tax_rates,
|
|
53
|
+
// days_until_due is a top-level Subscription field in Stripe 23.
|
|
54
|
+
invoice_settings: {
|
|
55
|
+
...invoice.data,
|
|
56
|
+
days_until_due: subscription.days_until_due,
|
|
57
|
+
},
|
|
58
|
+
description: subscription.description,
|
|
59
|
+
metadata: null,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
if (projection.status !== "projected")
|
|
63
|
+
unsupported(`unsupported_original_settings_${projection.reason}`);
|
|
64
|
+
const itemProjection = projectRenewalItemSettings({
|
|
65
|
+
effectiveAutomaticTax: context.effectiveAutomaticTax,
|
|
66
|
+
livemode: context.livemode,
|
|
67
|
+
settings: {
|
|
68
|
+
billing_thresholds: item.billing_thresholds,
|
|
69
|
+
tax_rates: item.tax_rates,
|
|
70
|
+
metadata: item.metadata,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
if (itemProjection.status !== "projected")
|
|
74
|
+
unsupported(`unsupported_original_${itemProjection.reason}`);
|
|
75
|
+
return {
|
|
76
|
+
context,
|
|
77
|
+
invoice: invoice.data,
|
|
78
|
+
automaticTax: automaticTax.data,
|
|
79
|
+
taxLevels,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=sourceSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceSettings.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/sourceSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC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c,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/D,OAAO;QACL,OAAO;QACP,OAAO,EAAE,OAAO,CAAC,IAAI;QACrB,YAAY,EAAE,YAAY,CAAC,IAAI;QAC/B,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Null/absent read hierarchies are not evidence of an explicit empty list. */
|
|
2
|
+
export declare function explicitTaxIds(value: unknown, level: string): string[];
|
|
3
|
+
export type OriginalTaxLevels = {
|
|
4
|
+
subscription: string[];
|
|
5
|
+
item: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function preserveTaxLevels(original: OriginalTaxLevels, phaseTax: unknown, phaseItemTax: unknown): void;
|
|
8
|
+
//# sourceMappingURL=taxRetention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taxRetention.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/taxRetention.ts"],"names":[],"mappings":"AAIA,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAItE;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3E,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,OAAO,QAWtB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { taxRate } from "../renewalProjection/settingsSchema.js";
|
|
3
|
+
import { equal, unsupported } from "./shared.js";
|
|
4
|
+
/** Null/absent read hierarchies are not evidence of an explicit empty list. */
|
|
5
|
+
export function explicitTaxIds(value, level) {
|
|
6
|
+
const parsed = z.array(taxRate).max(20).safeParse(value);
|
|
7
|
+
if (!parsed.success)
|
|
8
|
+
unsupported(`unproven_${level}_tax_hierarchy`);
|
|
9
|
+
return parsed.data.map((tax) => tax.id);
|
|
10
|
+
}
|
|
11
|
+
export function preserveTaxLevels(original, phaseTax, phaseItemTax) {
|
|
12
|
+
const phase = explicitTaxIds(phaseTax, "phase_default");
|
|
13
|
+
const item = explicitTaxIds(phaseItemTax, "phase_item");
|
|
14
|
+
if (!equal(original.subscription, phase))
|
|
15
|
+
unsupported("phase_default_tax_retention_mismatch");
|
|
16
|
+
// An empty item array means no item override. Its subscription/phase default
|
|
17
|
+
// applies instead. Equal current totals cannot authorize changing that level.
|
|
18
|
+
if (original.item.length > 0 !== item.length > 0)
|
|
19
|
+
unsupported("item_tax_override_level_changed");
|
|
20
|
+
if (!equal(original.item, item))
|
|
21
|
+
unsupported("item_tax_retention_mismatch");
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=taxRetention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taxRetention.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/taxRetention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjD,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,KAAc,EAAE,KAAa;IAC1D,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzD,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,WAAW,CAAC,YAAY,KAAK,gBAAgB,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC;AAID,MAAM,UAAU,iBAAiB,CAC/B,QAA2B,EAC3B,QAAiB,EACjB,YAAqB;IAErB,MAAM,KAAK,GAAG,cAAc,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC;QACtC,WAAW,CAAC,sCAAsC,CAAC,CAAC;IACtD,6EAA6E;IAC7E,8EAA8E;IAC9E,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;QAC9C,WAAW,CAAC,iCAAiC,CAAC,CAAC;IACjD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;QAAE,WAAW,CAAC,6BAA6B,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
/** Explicit bounded joins, never a fallback for failed or over-depth expansion. */
|
|
3
|
+
export declare function joinRenewalCoupons(stripe: Stripe, subscription: Record<string, unknown>, item: Record<string, unknown>, livemode: boolean, options: Stripe.RequestOptions): Promise<{
|
|
4
|
+
subscriptionDiscounts: {
|
|
5
|
+
id: string;
|
|
6
|
+
object: "discount";
|
|
7
|
+
deleted?: false | undefined;
|
|
8
|
+
source: {
|
|
9
|
+
type: "coupon";
|
|
10
|
+
coupon: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
}[];
|
|
13
|
+
itemDiscounts: {
|
|
14
|
+
id: string;
|
|
15
|
+
object: "discount";
|
|
16
|
+
deleted?: false | undefined;
|
|
17
|
+
source: {
|
|
18
|
+
type: "coupon";
|
|
19
|
+
coupon: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
}[];
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=couponJoins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"couponJoins.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalAttach/couponJoins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AA2BjC,mFAAmF;AACnF,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,MAAM,CAAC,cAAc;;;;;;;;;;;;;;;;;;;GA4D/B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { equal, object, unsupported } from "../renewalAggregate/shared.js";
|
|
3
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
4
|
+
const id = z.string().min(1).max(255).regex(/\S/);
|
|
5
|
+
const discount = z
|
|
6
|
+
.object({
|
|
7
|
+
id: z.string().regex(/^di_[A-Za-z0-9_]+$/),
|
|
8
|
+
object: z.literal("discount"),
|
|
9
|
+
deleted: z.literal(false).optional(),
|
|
10
|
+
source: z
|
|
11
|
+
.object({
|
|
12
|
+
type: z.literal("coupon"),
|
|
13
|
+
coupon: z.union([
|
|
14
|
+
id,
|
|
15
|
+
z
|
|
16
|
+
.object({
|
|
17
|
+
id,
|
|
18
|
+
object: z.literal("coupon"),
|
|
19
|
+
deleted: z.literal(false).optional(),
|
|
20
|
+
})
|
|
21
|
+
.passthrough(),
|
|
22
|
+
]),
|
|
23
|
+
})
|
|
24
|
+
.passthrough(),
|
|
25
|
+
})
|
|
26
|
+
.passthrough();
|
|
27
|
+
/** Explicit bounded joins, never a fallback for failed or over-depth expansion. */
|
|
28
|
+
export async function joinRenewalCoupons(stripe, subscription, item, livemode, options) {
|
|
29
|
+
const lists = [subscription.discounts, item.discounts].map((value) => {
|
|
30
|
+
const parsed = z.array(discount).max(20).safeParse(value);
|
|
31
|
+
if (!parsed.success)
|
|
32
|
+
unsupported("incomplete_or_unsupported_discount_evidence");
|
|
33
|
+
return parsed.data;
|
|
34
|
+
});
|
|
35
|
+
for (const list of lists)
|
|
36
|
+
for (const redemption of list) {
|
|
37
|
+
const ref = redemption.source.coupon;
|
|
38
|
+
if (typeof ref !== "string" &&
|
|
39
|
+
ref.livemode !== undefined &&
|
|
40
|
+
ref.livemode !== livemode)
|
|
41
|
+
unsupported("expanded_coupon_mode_mismatch");
|
|
42
|
+
}
|
|
43
|
+
const coupons = new Map();
|
|
44
|
+
for (const list of lists)
|
|
45
|
+
for (const redemption of list) {
|
|
46
|
+
const couponId = typeof redemption.source.coupon === "string"
|
|
47
|
+
? redemption.source.coupon
|
|
48
|
+
: redemption.source.coupon.id;
|
|
49
|
+
let coupon = coupons.get(couponId);
|
|
50
|
+
if (!coupon) {
|
|
51
|
+
coupon = object(renewalSnapshot(await stripe.coupons.retrieve(couponId, {}, options)));
|
|
52
|
+
if (coupon.id !== couponId ||
|
|
53
|
+
coupon.object !== "coupon" ||
|
|
54
|
+
coupon.deleted === true ||
|
|
55
|
+
(coupon.livemode !== undefined && coupon.livemode !== livemode))
|
|
56
|
+
unsupported("coupon_join_identity_mismatch");
|
|
57
|
+
coupons.set(couponId, coupon);
|
|
58
|
+
}
|
|
59
|
+
// A join may expand a string reference, but must never replace facts
|
|
60
|
+
// already present in a full read. Shape drift is conservatively rejected.
|
|
61
|
+
if (typeof redemption.source.coupon !== "string" &&
|
|
62
|
+
!equal(redemption.source.coupon, coupon))
|
|
63
|
+
unsupported("expanded_coupon_read_drift");
|
|
64
|
+
}
|
|
65
|
+
const joined = lists.map((list) => list.map((redemption) => {
|
|
66
|
+
const couponId = typeof redemption.source.coupon === "string"
|
|
67
|
+
? redemption.source.coupon
|
|
68
|
+
: redemption.source.coupon.id;
|
|
69
|
+
return {
|
|
70
|
+
...redemption,
|
|
71
|
+
source: { ...redemption.source, coupon: coupons.get(couponId) },
|
|
72
|
+
};
|
|
73
|
+
}));
|
|
74
|
+
return { subscriptionDiscounts: joined[0], itemDiscounts: joined[1] };
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=couponJoins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"couponJoins.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAttach/couponJoins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAClD,MAAM,QAAQ,GAAG,CAAC;KACf,MAAM,CAAC;IACN,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAC1C,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC7B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IACpC,MAAM,EAAE,CAAC;SACN,MAAM,CAAC;QACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QACzB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC;YACd,EAAE;YACF,CAAC;iBACE,MAAM,CAAC;gBACN,EAAE;gBACF,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAC3B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;aACrC,CAAC;iBACD,WAAW,EAAE;SACjB,CAAC;KACH,C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,CAAC,CACH,CAAC;IACF,OAAO,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { readRenewalPriceReplacementContext, type ReadRenewalPriceReplacementContextOptions, } from "./reader.js";
|
|
2
|
+
export { prepareRenewalScheduleAttachment, type PrepareRenewalScheduleAttachmentOptions, type PreparedRenewalScheduleAttachment, } from "./request.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalAttach/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,KAAK,yCAAyC,GAC/C,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gCAAgC,EAChC,KAAK,uCAAuC,EAC5C,KAAK,iCAAiC,GACvC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAttach/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,GAEnC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gCAAgC,GAGjC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type Stripe from "stripe";
|
|
3
|
+
declare const input: z.ZodObject<{
|
|
4
|
+
expected: z.ZodObject<{
|
|
5
|
+
customerAccountId: z.ZodString;
|
|
6
|
+
subscriptionId: z.ZodString;
|
|
7
|
+
itemId: z.ZodString;
|
|
8
|
+
currentPriceId: z.ZodString;
|
|
9
|
+
currentProductId: z.ZodString;
|
|
10
|
+
targetPriceId: z.ZodString;
|
|
11
|
+
targetProductId: z.ZodString;
|
|
12
|
+
periodStart: z.ZodNumber;
|
|
13
|
+
periodEnd: z.ZodNumber;
|
|
14
|
+
livemode: z.ZodBoolean;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
export type ReadRenewalPriceReplacementContextOptions = z.infer<typeof input>;
|
|
18
|
+
/** Fixed provider read profile. Evidence acquisition is not write qualification. */
|
|
19
|
+
export declare function readRenewalPriceReplacementContext(stripe: Stripe, options: ReadRenewalPriceReplacementContextOptions, apiVersion: string): Promise<{
|
|
20
|
+
version: 1;
|
|
21
|
+
scope: "platform";
|
|
22
|
+
apiVersion: string;
|
|
23
|
+
readProfile: "renewal-context-v1";
|
|
24
|
+
providerQualification: "required";
|
|
25
|
+
observedAt: number;
|
|
26
|
+
subscription: {
|
|
27
|
+
id: string;
|
|
28
|
+
object: "subscription";
|
|
29
|
+
customer_account: string;
|
|
30
|
+
status: "active";
|
|
31
|
+
currency: string;
|
|
32
|
+
livemode: boolean;
|
|
33
|
+
cancel_at: null;
|
|
34
|
+
cancel_at_period_end: false;
|
|
35
|
+
pause_collection: null;
|
|
36
|
+
pending_update: null;
|
|
37
|
+
default_source: null;
|
|
38
|
+
application_fee_percent: null;
|
|
39
|
+
payment_settings: {
|
|
40
|
+
payment_method_options: null;
|
|
41
|
+
payment_method_types: null;
|
|
42
|
+
save_default_payment_method: "off" | null;
|
|
43
|
+
} | null;
|
|
44
|
+
billing_schedules?: unknown[] | undefined;
|
|
45
|
+
schedule: string | {
|
|
46
|
+
[x: string]: unknown;
|
|
47
|
+
id: string;
|
|
48
|
+
object: "subscription_schedule";
|
|
49
|
+
deleted?: false | undefined;
|
|
50
|
+
} | null;
|
|
51
|
+
discounts: {
|
|
52
|
+
id: string;
|
|
53
|
+
object: "discount";
|
|
54
|
+
deleted?: false | undefined;
|
|
55
|
+
source: {
|
|
56
|
+
type: "coupon";
|
|
57
|
+
coupon: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
}[];
|
|
60
|
+
items: {
|
|
61
|
+
has_more: false;
|
|
62
|
+
data: {
|
|
63
|
+
id: string;
|
|
64
|
+
object: "subscription_item";
|
|
65
|
+
subscription: string;
|
|
66
|
+
current_period_start: number;
|
|
67
|
+
current_period_end: number;
|
|
68
|
+
quantity: number;
|
|
69
|
+
price: {
|
|
70
|
+
[x: string]: unknown;
|
|
71
|
+
id: string;
|
|
72
|
+
object: "price";
|
|
73
|
+
product: string | {
|
|
74
|
+
[x: string]: unknown;
|
|
75
|
+
id: string;
|
|
76
|
+
object: "product";
|
|
77
|
+
deleted?: false | undefined;
|
|
78
|
+
};
|
|
79
|
+
active: boolean;
|
|
80
|
+
livemode: boolean;
|
|
81
|
+
type: "recurring";
|
|
82
|
+
currency: string;
|
|
83
|
+
billing_scheme: "per_unit";
|
|
84
|
+
recurring: {
|
|
85
|
+
[x: string]: unknown;
|
|
86
|
+
interval: "day" | "month" | "week" | "year";
|
|
87
|
+
interval_count: number;
|
|
88
|
+
usage_type: "licensed";
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
discounts: {
|
|
92
|
+
id: string;
|
|
93
|
+
object: "discount";
|
|
94
|
+
deleted?: false | undefined;
|
|
95
|
+
source: {
|
|
96
|
+
type: "coupon";
|
|
97
|
+
coupon: Record<string, unknown>;
|
|
98
|
+
};
|
|
99
|
+
}[];
|
|
100
|
+
}[];
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
targetPrice: {
|
|
104
|
+
[x: string]: unknown;
|
|
105
|
+
id: string;
|
|
106
|
+
object: "price";
|
|
107
|
+
product: string | {
|
|
108
|
+
[x: string]: unknown;
|
|
109
|
+
id: string;
|
|
110
|
+
object: "product";
|
|
111
|
+
deleted?: false | undefined;
|
|
112
|
+
};
|
|
113
|
+
active: boolean;
|
|
114
|
+
livemode: boolean;
|
|
115
|
+
type: "recurring";
|
|
116
|
+
currency: string;
|
|
117
|
+
billing_scheme: "per_unit";
|
|
118
|
+
recurring: {
|
|
119
|
+
[x: string]: unknown;
|
|
120
|
+
interval: "day" | "month" | "week" | "year";
|
|
121
|
+
interval_count: number;
|
|
122
|
+
usage_type: "licensed";
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
billingCustomer: {
|
|
126
|
+
[x: string]: unknown;
|
|
127
|
+
id: string;
|
|
128
|
+
object: "customer";
|
|
129
|
+
customer_account: string;
|
|
130
|
+
livemode: boolean;
|
|
131
|
+
deleted?: false | undefined;
|
|
132
|
+
discount: {
|
|
133
|
+
[x: string]: unknown;
|
|
134
|
+
id: string;
|
|
135
|
+
object: "discount";
|
|
136
|
+
deleted?: false | undefined;
|
|
137
|
+
} | null;
|
|
138
|
+
};
|
|
139
|
+
}>;
|
|
140
|
+
export {};
|
|
141
|
+
//# sourceMappingURL=reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalAttach/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAkBjC,QAAA,MAAM,KAAK;;;;;;;;;;;;;kBAAmD,CAAC;AAC/D,MAAM,MAAM,yCAAyC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;AAe9E,oFAAoF;AACpF,wBAAsB,kCAAkC,CACtD,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,yCAAyC,EAClD,UAAU,EAAE,MAAM;aAiFP,CAAC;WACH,UAAU;;iBAEJ,oBAAoB;2BACV,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAMpC"}
|