@fantastic.dev/better-stripe 0.31.0 → 0.33.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 +13 -0
- package/README.md +7 -1
- package/dist/client/billing/checkoutPages.d.ts +26 -0
- package/dist/client/billing/checkoutPages.d.ts.map +1 -0
- package/dist/client/billing/checkoutPages.js +111 -0
- package/dist/client/billing/checkoutPages.js.map +1 -0
- package/dist/client/billing/invoicePaymentPages.d.ts +28 -0
- package/dist/client/billing/invoicePaymentPages.d.ts.map +1 -0
- package/dist/client/billing/invoicePaymentPages.js +124 -0
- package/dist/client/billing/invoicePaymentPages.js.map +1 -0
- package/dist/client/connect/refundContext.d.ts +6 -0
- package/dist/client/connect/refundContext.d.ts.map +1 -0
- package/dist/client/connect/refundContext.js +109 -0
- package/dist/client/connect/refundContext.js.map +1 -0
- package/dist/client/connect/refundContextHistory.d.ts +20 -0
- package/dist/client/connect/refundContextHistory.d.ts.map +1 -0
- package/dist/client/connect/refundContextHistory.js +55 -0
- package/dist/client/connect/refundContextHistory.js.map +1 -0
- package/dist/client/connect/refundContextTypes.d.ts +39 -0
- package/dist/client/connect/refundContextTypes.d.ts.map +1 -0
- package/dist/client/connect/refundContextTypes.js +15 -0
- package/dist/client/connect/refundContextTypes.js.map +1 -0
- package/dist/client/connect/refundTarget.d.ts +14 -0
- package/dist/client/connect/refundTarget.d.ts.map +1 -0
- package/dist/client/connect/refundTarget.js +17 -0
- package/dist/client/connect/refundTarget.js.map +1 -0
- package/dist/client/connect/refunds.d.ts +17 -1
- package/dist/client/connect/refunds.d.ts.map +1 -1
- package/dist/client/connect/refunds.js +7 -17
- package/dist/client/connect/refunds.js.map +1 -1
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -7
- package/dist/client/index.js.map +1 -1
- package/dist/client/invoiceReads.d.ts +20 -0
- package/dist/client/invoiceReads.d.ts.map +1 -0
- package/dist/client/invoiceReads.js +25 -0
- package/dist/client/invoiceReads.js.map +1 -0
- package/docs/checkout-session-pages.md +71 -0
- package/docs/invoice-payment-pages.md +43 -0
- package/docs/read-contracts.md +44 -0
- package/docs/refund-context.md +84 -0
- package/package.json +5 -2
- package/src/client/billing/checkoutPages.test.ts +251 -0
- package/src/client/billing/checkoutPages.ts +135 -0
- package/src/client/billing/invoicePaymentPages.test.ts +354 -0
- package/src/client/billing/invoicePaymentPages.ts +165 -0
- package/src/client/connect/refundContext.ts +140 -0
- package/src/client/connect/refundContextHistory.ts +84 -0
- package/src/client/connect/refundContextTypes.ts +56 -0
- package/src/client/connect/refundTarget.ts +39 -0
- package/src/client/connect/refunds.test.ts +72 -0
- package/src/client/connect/refunds.ts +8 -22
- package/src/client/index.ts +16 -12
- package/src/client/invoiceReads.ts +45 -0
- package/src/client/refund-context-shapes.test.ts +127 -0
- package/src/client/refund-context.test.ts +404 -0
package/CHANGELOG.md
CHANGED
|
@@ -26,6 +26,19 @@
|
|
|
26
26
|
- Remove internal tracker references from public documentation and add a
|
|
27
27
|
regression check that prevents their reintroduction.
|
|
28
28
|
|
|
29
|
+
## [0.33.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.32.0...v0.33.0) (2026-10-16)
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
- **billing:** expose bounded authorized refund context ([6f4f264](https://github.com/FantasticDevHQ/better-stripe/commit/6f4f264658d48c478165a4e3f3aaa83e6a6cf94b))
|
|
34
|
+
- **billing:** expose bounded buyer Checkout session pages ([f6cb1a6](https://github.com/FantasticDevHQ/better-stripe/commit/f6cb1a64139235ee65f907c3577e4aac75cff96c))
|
|
35
|
+
|
|
36
|
+
## [0.32.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.31.0...v0.32.0) (2026-10-16)
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
- **billing:** expose verified invoice payment references ([dc1245c](https://github.com/FantasticDevHQ/better-stripe/commit/dc1245c686aa924c0920ae5a6cbd1b3fba895713))
|
|
41
|
+
|
|
29
42
|
## [0.31.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.30.3...v0.31.0) (2026-10-16)
|
|
30
43
|
|
|
31
44
|
### Features
|
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ claim execution are completed.
|
|
|
70
70
|
|
|
71
71
|
## Status
|
|
72
72
|
|
|
73
|
-
**Version**: `0.
|
|
73
|
+
**Version**: `0.33.0` <!-- x-release-please-version --> (pre-1.0). API may change between minor versions until 1.0.
|
|
74
74
|
|
|
75
75
|
Used in production by its authors. Webhook pipeline is covered by unit tests and a live E2E harness (`npm run e2e:webhooks`) that fires real Stripe-signed events and asserts the ledger.
|
|
76
76
|
|
|
@@ -1754,6 +1754,12 @@ See the [read contract guide](docs/read-contracts.md) for reactive product, pric
|
|
|
1754
1754
|
cursors, exact currency summaries, legacy backfill, payout failure details, and
|
|
1755
1755
|
published-version adoption requirements.
|
|
1756
1756
|
|
|
1757
|
+
For buyer purchase-history discovery, use the public invoice and
|
|
1758
|
+
[Checkout-session page readers](docs/checkout-session-pages.md). Checkout pages
|
|
1759
|
+
also reveal open/asynchronous sessions with no invoice. They preserve raw
|
|
1760
|
+
references and require host authorization, continuation checkpoints and
|
|
1761
|
+
historical reconciliation; they do not attest complete history or award credit.
|
|
1762
|
+
|
|
1757
1763
|
Custom recipient payout minimums are waived during the final day before the verified holding deadline. Provider limits and all financial checks still apply. See [settlement and deadline handling](docs/settlement.md) for worker cadence, retries and expiry limitations.
|
|
1758
1764
|
|
|
1759
1765
|
Holding-expiry recovery remains visible and retryable after schedule restoration. The package preserves unresolved provider balances and payout claims, and prevents reset or custom reactivation from erasing them. See [expiry recovery](docs/settlement.md) for operator handling.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const optionsSchema: z.ZodObject<{
|
|
4
|
+
customerAccount: z.ZodString;
|
|
5
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
6
|
+
complete: "complete";
|
|
7
|
+
expired: "expired";
|
|
8
|
+
open: "open";
|
|
9
|
+
}>>;
|
|
10
|
+
created: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
gte: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
lte: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
}, z.core.$strict>>;
|
|
14
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
export type CheckoutSessionPageOptions = z.input<typeof optionsSchema>;
|
|
18
|
+
export type ProviderCheckoutSessionPage = {
|
|
19
|
+
page: Stripe.Checkout.Session[];
|
|
20
|
+
hasMore: boolean;
|
|
21
|
+
continueCursor: string | null;
|
|
22
|
+
};
|
|
23
|
+
/** Provider discovery only. Hosts authorize buyers and reconcile mutable history and gaps. */
|
|
24
|
+
export declare function getCheckoutSessionPageFromStripe(stripe: Stripe, input: CheckoutSessionPageOptions): Promise<ProviderCheckoutSessionPage>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=checkoutPages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkoutPages.d.ts","sourceRoot":"","sources":["../../../src/client/billing/checkoutPages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,QAAA,MAAM,aAAa;;;;;;;;;;;;;kBAKR,CAAC;AAsBZ,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACvE,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AA0BF,8FAA8F;AAC9F,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,2BAA2B,CAAC,CAuDtC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const time = z.number().int().nonnegative().safe();
|
|
3
|
+
const scopeSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
customerAccount: z
|
|
6
|
+
.string()
|
|
7
|
+
.max(128)
|
|
8
|
+
.regex(/^acct_[A-Za-z0-9_]+$/),
|
|
9
|
+
status: z.enum(["open", "complete", "expired"]).optional(),
|
|
10
|
+
created: z
|
|
11
|
+
.object({ gte: time.optional(), lte: time.optional() })
|
|
12
|
+
.strict()
|
|
13
|
+
.optional(),
|
|
14
|
+
})
|
|
15
|
+
.strict();
|
|
16
|
+
const optionsSchema = scopeSchema
|
|
17
|
+
.extend({
|
|
18
|
+
limit: z.number().int().min(1).max(100).default(25),
|
|
19
|
+
cursor: z.string().min(1).max(2048).nullable().optional(),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
const sessionId = z
|
|
23
|
+
.string()
|
|
24
|
+
.max(128)
|
|
25
|
+
.regex(/^cs_[A-Za-z0-9_]+$/);
|
|
26
|
+
const cursorSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
version: z.literal(1),
|
|
29
|
+
scope: scopeSchema,
|
|
30
|
+
after: sessionId,
|
|
31
|
+
})
|
|
32
|
+
.strict();
|
|
33
|
+
const identitySchema = z
|
|
34
|
+
.object({
|
|
35
|
+
id: sessionId,
|
|
36
|
+
object: z.literal("checkout.session"),
|
|
37
|
+
customer_account: z.string(),
|
|
38
|
+
customer: z.null().optional(),
|
|
39
|
+
created: time,
|
|
40
|
+
})
|
|
41
|
+
.passthrough();
|
|
42
|
+
function encodeCursor(scope, after) {
|
|
43
|
+
return btoa(JSON.stringify({ version: 1, scope, after }))
|
|
44
|
+
.replaceAll("+", "-")
|
|
45
|
+
.replaceAll("/", "_")
|
|
46
|
+
.replace(/=+$/, "");
|
|
47
|
+
}
|
|
48
|
+
function decodeCursor(cursor, scope) {
|
|
49
|
+
try {
|
|
50
|
+
if (!/^[A-Za-z0-9_-]+$/.test(cursor))
|
|
51
|
+
throw new Error();
|
|
52
|
+
const parsed = cursorSchema.parse(JSON.parse(atob(cursor.replaceAll("-", "+").replaceAll("_", "/"))));
|
|
53
|
+
if (JSON.stringify(parsed.scope) !== JSON.stringify(scope) ||
|
|
54
|
+
encodeCursor(parsed.scope, parsed.after) !== cursor)
|
|
55
|
+
throw new Error();
|
|
56
|
+
return parsed.after;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw new Error("Invalid Checkout page cursor or scope");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Provider discovery only. Hosts authorize buyers and reconcile mutable history and gaps. */
|
|
63
|
+
export async function getCheckoutSessionPageFromStripe(stripe, input) {
|
|
64
|
+
const { limit, cursor, ...scope } = optionsSchema.parse(input);
|
|
65
|
+
if (scope.created?.gte !== undefined &&
|
|
66
|
+
scope.created.lte !== undefined &&
|
|
67
|
+
scope.created.gte > scope.created.lte)
|
|
68
|
+
throw new Error("Invalid Checkout page time window");
|
|
69
|
+
if (scope.created &&
|
|
70
|
+
scope.created.gte === undefined &&
|
|
71
|
+
scope.created.lte === undefined)
|
|
72
|
+
delete scope.created;
|
|
73
|
+
const after = cursor ? decodeCursor(cursor, scope) : undefined;
|
|
74
|
+
const response = await stripe.checkout.sessions.list({
|
|
75
|
+
customer_account: scope.customerAccount,
|
|
76
|
+
limit,
|
|
77
|
+
...(scope.status ? { status: scope.status } : {}),
|
|
78
|
+
...(scope.created ? { created: scope.created } : {}),
|
|
79
|
+
...(after ? { starting_after: after } : {}),
|
|
80
|
+
});
|
|
81
|
+
if (!Array.isArray(response.data) ||
|
|
82
|
+
typeof response.has_more !== "boolean" ||
|
|
83
|
+
response.data.length > limit)
|
|
84
|
+
throw new Error("Invalid provider Checkout page");
|
|
85
|
+
const seen = new Set();
|
|
86
|
+
for (const row of response.data) {
|
|
87
|
+
const parsed = identitySchema.safeParse(row);
|
|
88
|
+
if (!parsed.success ||
|
|
89
|
+
parsed.data.customer_account !== scope.customerAccount ||
|
|
90
|
+
(scope.status !== undefined && row.status !== scope.status) ||
|
|
91
|
+
(scope.created?.gte !== undefined &&
|
|
92
|
+
parsed.data.created < scope.created.gte) ||
|
|
93
|
+
(scope.created?.lte !== undefined &&
|
|
94
|
+
parsed.data.created > scope.created.lte))
|
|
95
|
+
throw new Error("Invalid provider Checkout page buyer scope or identity");
|
|
96
|
+
if (seen.has(row.id))
|
|
97
|
+
throw new Error("Duplicate provider Checkout page entry");
|
|
98
|
+
if (row.id === after)
|
|
99
|
+
throw new Error("Provider Checkout page has no advancing continuation");
|
|
100
|
+
seen.add(row.id);
|
|
101
|
+
}
|
|
102
|
+
const last = response.data[response.data.length - 1]?.id;
|
|
103
|
+
if (response.has_more && !last)
|
|
104
|
+
throw new Error("Provider Checkout page has no advancing continuation");
|
|
105
|
+
return {
|
|
106
|
+
page: response.data,
|
|
107
|
+
hasMore: response.has_more,
|
|
108
|
+
continueCursor: response.has_more ? encodeCursor(scope, last) : null,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=checkoutPages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkoutPages.js","sourceRoot":"","sources":["../../../src/client/billing/checkoutPages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;AACnD,MAAM,WAAW,GAAG,CAAC;KAClB,MAAM,CAAC;I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I,CAAC,IAAI;QAC5B,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,OAAO,EAAE,QAAQ,CAAC,QAAQ;QAC1B,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,IAAK,CAAC,CAAC,CAAC,CAAC,IAAI;KACtE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const optionsSchema: z.ZodObject<{
|
|
4
|
+
stripeInvoiceId: z.ZodString;
|
|
5
|
+
customerAccount: z.ZodString;
|
|
6
|
+
stripeSubscriptionId: z.ZodString;
|
|
7
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export type InvoicePaymentPageOptions = z.input<typeof optionsSchema>;
|
|
11
|
+
export type ProviderInvoicePaymentPage = {
|
|
12
|
+
scope: {
|
|
13
|
+
stripeInvoiceId: string;
|
|
14
|
+
customerAccount: string;
|
|
15
|
+
stripeSubscriptionId: string;
|
|
16
|
+
};
|
|
17
|
+
page: {
|
|
18
|
+
invoicePayment: Stripe.InvoicePayment;
|
|
19
|
+
paymentIntentId: string | null;
|
|
20
|
+
referenceStatus: "payment_intent" | "unsupported" | "unavailable";
|
|
21
|
+
}[];
|
|
22
|
+
hasMore: boolean;
|
|
23
|
+
continueCursor: string | null;
|
|
24
|
+
};
|
|
25
|
+
/** Canonical provider references only. The host authorizes scope and separately verifies refund eligibility. */
|
|
26
|
+
export declare function getInvoicePaymentPageFromStripe(stripe: Stripe, input: InvoicePaymentPageOptions): Promise<ProviderInvoicePaymentPage>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=invoicePaymentPages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoicePaymentPages.d.ts","sourceRoot":"","sources":["../../../src/client/billing/invoicePaymentPages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkBxB,QAAA,MAAM,aAAa;;;;;;kBAKR,CAAC;AAWZ,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACtE,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE;QACL,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,MAAM,CAAC;QACxB,oBAAoB,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,IAAI,EAAE;QACJ,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC;QACtC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,eAAe,EAAE,gBAAgB,GAAG,aAAa,GAAG,aAAa,CAAC;KACnE,EAAE,CAAC;IACJ,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAiEF,gHAAgH;AAChH,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,0BAA0B,CAAC,CA8CrC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const scopeSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
stripeInvoiceId: z
|
|
5
|
+
.string()
|
|
6
|
+
.max(128)
|
|
7
|
+
.regex(/^in_[A-Za-z0-9_]+$/),
|
|
8
|
+
customerAccount: z
|
|
9
|
+
.string()
|
|
10
|
+
.max(128)
|
|
11
|
+
.regex(/^acct_[A-Za-z0-9_]+$/),
|
|
12
|
+
stripeSubscriptionId: z
|
|
13
|
+
.string()
|
|
14
|
+
.max(128)
|
|
15
|
+
.regex(/^sub_[A-Za-z0-9_]+$/),
|
|
16
|
+
})
|
|
17
|
+
.strict();
|
|
18
|
+
const optionsSchema = scopeSchema
|
|
19
|
+
.extend({
|
|
20
|
+
limit: z.number().int().min(1).max(100).default(25),
|
|
21
|
+
cursor: z.string().min(1).max(2048).nullable().optional(),
|
|
22
|
+
})
|
|
23
|
+
.strict();
|
|
24
|
+
const cursorSchema = z
|
|
25
|
+
.object({
|
|
26
|
+
version: z.literal(1),
|
|
27
|
+
scope: scopeSchema,
|
|
28
|
+
after: z
|
|
29
|
+
.string()
|
|
30
|
+
.max(128)
|
|
31
|
+
.regex(/^inpay_[A-Za-z0-9_]+$/),
|
|
32
|
+
})
|
|
33
|
+
.strict();
|
|
34
|
+
/** Bind a continuation to the verified invoice, buyer and subscription selectors. */
|
|
35
|
+
function encodeCursor(scope, after) {
|
|
36
|
+
return btoa(JSON.stringify({ version: 1, scope, after }))
|
|
37
|
+
.replaceAll("+", "-")
|
|
38
|
+
.replaceAll("/", "_")
|
|
39
|
+
.replace(/=+$/, "");
|
|
40
|
+
}
|
|
41
|
+
/** Reject malformed continuations and accidental cross-scope reuse before provider reads. */
|
|
42
|
+
function decodeCursor(cursor, scope) {
|
|
43
|
+
try {
|
|
44
|
+
if (!/^[A-Za-z0-9_-]+$/.test(cursor))
|
|
45
|
+
throw new Error();
|
|
46
|
+
const value = cursorSchema.parse(JSON.parse(atob(cursor.replaceAll("-", "+").replaceAll("_", "/"))));
|
|
47
|
+
if (JSON.stringify(value.scope) !== JSON.stringify(scope) ||
|
|
48
|
+
encodeCursor(value.scope, value.after) !== cursor)
|
|
49
|
+
throw new Error();
|
|
50
|
+
return value.after;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw new Error("Invalid invoice payment page cursor or scope");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Normalize provider references without inferring missing identifiers. */
|
|
57
|
+
function referenceId(value) {
|
|
58
|
+
return typeof value === "string" ? value : value?.id;
|
|
59
|
+
}
|
|
60
|
+
/** Keep financial evidence exact; reject units that JavaScript cannot safely represent. */
|
|
61
|
+
function assertRepresentableUnits(row) {
|
|
62
|
+
const amounts = [
|
|
63
|
+
row.amount_requested,
|
|
64
|
+
...(row.amount_paid === null ? [] : [row.amount_paid]),
|
|
65
|
+
];
|
|
66
|
+
if (amounts.some((amount) => !Number.isSafeInteger(amount) || amount < 0) ||
|
|
67
|
+
!/^[a-z]{3}$/.test(row.currency)) {
|
|
68
|
+
throw new Error("Invalid provider invoice payment units or currency");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Retain unsupported rows while distinguishing canonical and unavailable references. */
|
|
72
|
+
function paymentReference(invoicePayment) {
|
|
73
|
+
assertRepresentableUnits(invoicePayment);
|
|
74
|
+
const type = invoicePayment.payment.type;
|
|
75
|
+
const id = type === "payment_intent"
|
|
76
|
+
? referenceId(invoicePayment.payment.payment_intent)
|
|
77
|
+
: undefined;
|
|
78
|
+
const paymentIntentId = id && /^pi_[A-Za-z0-9_]+$/.test(id) ? id : null;
|
|
79
|
+
return {
|
|
80
|
+
invoicePayment,
|
|
81
|
+
paymentIntentId,
|
|
82
|
+
referenceStatus: type !== "payment_intent"
|
|
83
|
+
? "unsupported"
|
|
84
|
+
: paymentIntentId
|
|
85
|
+
? "payment_intent"
|
|
86
|
+
: "unavailable",
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Canonical provider references only. The host authorizes scope and separately verifies refund eligibility. */
|
|
90
|
+
export async function getInvoicePaymentPageFromStripe(stripe, input) {
|
|
91
|
+
const { limit, cursor, ...scope } = optionsSchema.parse(input);
|
|
92
|
+
const after = cursor ? decodeCursor(cursor, scope) : undefined;
|
|
93
|
+
const invoice = await stripe.invoices.retrieve(scope.stripeInvoiceId);
|
|
94
|
+
const parent = invoice.parent;
|
|
95
|
+
if (invoice.id !== scope.stripeInvoiceId ||
|
|
96
|
+
invoice.customer_account !== scope.customerAccount ||
|
|
97
|
+
parent?.type !== "subscription_details" ||
|
|
98
|
+
referenceId(parent.subscription_details?.subscription) !==
|
|
99
|
+
scope.stripeSubscriptionId) {
|
|
100
|
+
throw new Error("Invalid provider invoice payment buyer or subscription scope");
|
|
101
|
+
}
|
|
102
|
+
const response = await stripe.invoicePayments.list({
|
|
103
|
+
invoice: scope.stripeInvoiceId,
|
|
104
|
+
limit,
|
|
105
|
+
...(after ? { starting_after: after } : {}),
|
|
106
|
+
});
|
|
107
|
+
if (response.data.length > limit ||
|
|
108
|
+
new Set(response.data.map((row) => row.id)).size !== response.data.length ||
|
|
109
|
+
response.data.some((row) => row.id === after ||
|
|
110
|
+
referenceId(row.invoice) !== scope.stripeInvoiceId ||
|
|
111
|
+
!/^inpay_[A-Za-z0-9_]+$/.test(row.id))) {
|
|
112
|
+
throw new Error("Invalid provider invoice payment page scope or continuation");
|
|
113
|
+
}
|
|
114
|
+
const last = response.data[response.data.length - 1]?.id;
|
|
115
|
+
if (response.has_more && (!last || last === after))
|
|
116
|
+
throw new Error("Provider invoice payment page has no advancing continuation");
|
|
117
|
+
return {
|
|
118
|
+
scope,
|
|
119
|
+
page: response.data.map(paymentReference),
|
|
120
|
+
hasMore: response.has_more,
|
|
121
|
+
continueCursor: response.has_more ? encodeCursor(scope, last) : null,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=invoicePaymentPages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoicePaymentPages.js","sourceRoot":"","sources":["../../../src/client/billing/invoicePaymentPages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,GAAG,CAAC;KAClB,MAAM,CAAC;IACN,eAAe,EAAE,CAAC;SACf,MAAM,EAAE;SACR,GAAG,CAAC,GAAG,CAAC;SACR,KAAK,CAAC,oBAAoB,CAAC;IAC9B,eAAe,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I,KAAK,CACb,6DAA6D,CAC9D,CAAC;IACJ,OAAO;QACL,KAAK;QACL,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC;QACzC,OAAO,EAAE,QAAQ,CAAC,QAAQ;QAC1B,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,IAAK,CAAC,CAAC,CAAC,CAAC,IAAI;KACtE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
3
|
+
import { type RefundContextOptions, type RefundContext } from "./refundContextTypes.js";
|
|
4
|
+
/** Observes one authorized original payment; hosts still own community scope and creation-time revalidation. */
|
|
5
|
+
export declare function getRefundContext(stripe: Stripe, component: Component, ctx: RunCtx, input: RefundContextOptions): Promise<RefundContext>;
|
|
6
|
+
//# sourceMappingURL=refundContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refundContext.d.ts","sourceRoot":"","sources":["../../../src/client/connect/refundContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAUvD,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAEnB,MAAM,yBAAyB,CAAC;AAiCjC,gHAAgH;AAChH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAoFxB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { componentRef } from "../webhooks/helpers.js";
|
|
2
|
+
import { assertRefundAuthorized } from "./refunds.js";
|
|
3
|
+
import { readRefundPayment, readRefundCharge, refundObjectId, } from "./refundTarget.js";
|
|
4
|
+
import { readRefundHistory } from "./refundContextHistory.js";
|
|
5
|
+
import { refundContextOptionsSchema, } from "./refundContextTypes.js";
|
|
6
|
+
const unavailable = (reason) => ({ status: "unavailable", reason });
|
|
7
|
+
function amountsAgree(payment, charge) {
|
|
8
|
+
const amounts = [
|
|
9
|
+
payment.amount,
|
|
10
|
+
payment.amount_received,
|
|
11
|
+
charge.amount,
|
|
12
|
+
charge.amount_captured,
|
|
13
|
+
charge.amount_refunded,
|
|
14
|
+
];
|
|
15
|
+
return (amounts.every((n) => Number.isSafeInteger(n) && n >= 0) &&
|
|
16
|
+
charge.amount_captured === payment.amount_received &&
|
|
17
|
+
charge.amount_captured <= charge.amount &&
|
|
18
|
+
charge.amount_captured <= payment.amount &&
|
|
19
|
+
charge.amount_refunded <= charge.amount_captured);
|
|
20
|
+
}
|
|
21
|
+
function canonicalCustomer(value) {
|
|
22
|
+
if (value === null)
|
|
23
|
+
return true;
|
|
24
|
+
if (typeof value === "string")
|
|
25
|
+
return /^cus_[A-Za-z0-9_]+$/.test(value);
|
|
26
|
+
return Boolean(value &&
|
|
27
|
+
value.object === "customer" &&
|
|
28
|
+
typeof value.id === "string" &&
|
|
29
|
+
/^cus_[A-Za-z0-9_]+$/.test(value.id));
|
|
30
|
+
}
|
|
31
|
+
/** Observes one authorized original payment; hosts still own community scope and creation-time revalidation. */
|
|
32
|
+
export async function getRefundContext(stripe, component, ctx, input) {
|
|
33
|
+
const opts = refundContextOptionsSchema.parse(input);
|
|
34
|
+
const original = (await assertRefundAuthorized(stripe, component, ctx, opts)) ??
|
|
35
|
+
(await ctx.runQuery(componentRef(component, "connect/queries/getPaymentByStripeId"), { stripePaymentIntentId: opts.stripePaymentIntentId }));
|
|
36
|
+
if (!original)
|
|
37
|
+
return unavailable("payment_unavailable");
|
|
38
|
+
if (original.stripePaymentIntentId !== opts.stripePaymentIntentId)
|
|
39
|
+
return unavailable("payment_scope_mismatch");
|
|
40
|
+
const buyer = original.accountId;
|
|
41
|
+
if (!buyer || !/^acct_[A-Za-z0-9_]+$/.test(buyer))
|
|
42
|
+
return unavailable("buyer_unavailable");
|
|
43
|
+
const payment = await readRefundPayment(stripe, opts);
|
|
44
|
+
if (!payment ||
|
|
45
|
+
payment.object !== "payment_intent" ||
|
|
46
|
+
payment.id !== opts.stripePaymentIntentId)
|
|
47
|
+
return unavailable("payment_scope_mismatch");
|
|
48
|
+
if (!canonicalCustomer(payment.customer))
|
|
49
|
+
return unavailable("buyer_mismatch");
|
|
50
|
+
if (payment.customer_account !== buyer)
|
|
51
|
+
return unavailable("buyer_mismatch");
|
|
52
|
+
if (payment.status !== "succeeded")
|
|
53
|
+
return unavailable("payment_not_succeeded");
|
|
54
|
+
if (!/^[a-z]{3}$/.test(payment.currency) ||
|
|
55
|
+
payment.currency !== original.currency)
|
|
56
|
+
return unavailable("currency_mismatch");
|
|
57
|
+
const chargeId = refundObjectId(payment.latest_charge);
|
|
58
|
+
if (!chargeId || !/^ch_[A-Za-z0-9_]+$/.test(chargeId))
|
|
59
|
+
return unavailable("charge_unavailable");
|
|
60
|
+
const charge = await readRefundCharge(stripe, opts, payment);
|
|
61
|
+
if (!charge ||
|
|
62
|
+
charge.id !== chargeId ||
|
|
63
|
+
refundObjectId(charge.payment_intent) !== payment.id)
|
|
64
|
+
return unavailable("charge_scope_mismatch");
|
|
65
|
+
if (charge.object !== "charge" ||
|
|
66
|
+
charge.status !== "succeeded" ||
|
|
67
|
+
typeof charge.paid !== "boolean" ||
|
|
68
|
+
typeof charge.captured !== "boolean" ||
|
|
69
|
+
typeof charge.disputed !== "boolean" ||
|
|
70
|
+
typeof charge.refunded !== "boolean")
|
|
71
|
+
return unavailable("charge_scope_mismatch");
|
|
72
|
+
if (!canonicalCustomer(charge.customer))
|
|
73
|
+
return unavailable("buyer_mismatch");
|
|
74
|
+
if (refundObjectId(charge.customer) !== refundObjectId(payment.customer))
|
|
75
|
+
return unavailable("buyer_mismatch");
|
|
76
|
+
if (charge.currency !== payment.currency)
|
|
77
|
+
return unavailable("currency_mismatch");
|
|
78
|
+
if (!amountsAgree(payment, charge))
|
|
79
|
+
return unavailable("amount_unavailable");
|
|
80
|
+
if (!charge.paid || !charge.captured || charge.amount_captured === 0)
|
|
81
|
+
return unavailable("charge_not_captured");
|
|
82
|
+
if (charge.disputed)
|
|
83
|
+
return unavailable("charge_disputed");
|
|
84
|
+
const history = await readRefundHistory(stripe, {
|
|
85
|
+
paymentIntentId: payment.id,
|
|
86
|
+
chargeId: charge.id,
|
|
87
|
+
currency: payment.currency,
|
|
88
|
+
capturedAmount: charge.amount_captured,
|
|
89
|
+
maxRefundPages: opts.maxRefundPages,
|
|
90
|
+
stripeAccountId: opts.stripeAccountId,
|
|
91
|
+
});
|
|
92
|
+
if (history.status !== "complete")
|
|
93
|
+
return history;
|
|
94
|
+
if (history.refundedAmount !== charge.amount_refunded ||
|
|
95
|
+
charge.refunded !== (history.refundedAmount === charge.amount_captured))
|
|
96
|
+
return unavailable("refund_counter_mismatch");
|
|
97
|
+
return {
|
|
98
|
+
status: "ready",
|
|
99
|
+
stripePaymentIntentId: payment.id,
|
|
100
|
+
stripeChargeId: charge.id,
|
|
101
|
+
customerAccount: buyer,
|
|
102
|
+
currency: payment.currency,
|
|
103
|
+
capturedAmount: charge.amount_captured,
|
|
104
|
+
refundedAmount: history.refundedAmount,
|
|
105
|
+
remainingRefundableAmount: charge.amount_captured - history.refundedAmount,
|
|
106
|
+
observedAt: Date.now(),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=refundContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refundContext.js","sourceRoot":"","sources":["../../../src/client/connect/refundContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,iB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cAAc;QAC1E,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import type { RefundContextUnavailableReason } from "./refundContextTypes.js";
|
|
3
|
+
type HistoryResult = {
|
|
4
|
+
status: "complete";
|
|
5
|
+
refundedAmount: number;
|
|
6
|
+
} | {
|
|
7
|
+
status: "unavailable";
|
|
8
|
+
reason: RefundContextUnavailableReason;
|
|
9
|
+
};
|
|
10
|
+
/** All bounded pages must agree with the captured charge; loaded previews cannot establish a remainder. */
|
|
11
|
+
export declare function readRefundHistory(stripe: Stripe, opts: {
|
|
12
|
+
paymentIntentId: string;
|
|
13
|
+
chargeId: string;
|
|
14
|
+
currency: string;
|
|
15
|
+
capturedAmount: number;
|
|
16
|
+
maxRefundPages: number;
|
|
17
|
+
stripeAccountId?: string;
|
|
18
|
+
}): Promise<HistoryResult>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=refundContextHistory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refundContextHistory.d.ts","sourceRoot":"","sources":["../../../src/client/connect/refundContextHistory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAE9E,KAAK,aAAa,GACd;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,8BAA8B,CAAA;CAAE,CAAC;AAKtE,2GAA2G;AAC3G,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;IACJ,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GACA,OAAO,CAAC,aAAa,CAAC,CA6DxB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { refundObjectId } from "./refundTarget.js";
|
|
2
|
+
const unavailable = (reason) => ({ status: "unavailable", reason });
|
|
3
|
+
/** All bounded pages must agree with the captured charge; loaded previews cannot establish a remainder. */
|
|
4
|
+
export async function readRefundHistory(stripe, opts) {
|
|
5
|
+
let refundedAmount = 0;
|
|
6
|
+
let cursor;
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
for (let count = 0; count < opts.maxRefundPages; count++) {
|
|
9
|
+
const page = await stripe.refunds.list({
|
|
10
|
+
payment_intent: opts.paymentIntentId,
|
|
11
|
+
limit: 100,
|
|
12
|
+
...(cursor ? { starting_after: cursor } : {}),
|
|
13
|
+
}, opts.stripeAccountId
|
|
14
|
+
? { stripeAccount: opts.stripeAccountId }
|
|
15
|
+
: undefined);
|
|
16
|
+
if (!page ||
|
|
17
|
+
page.object !== "list" ||
|
|
18
|
+
!Array.isArray(page.data) ||
|
|
19
|
+
page.data.length > 100 ||
|
|
20
|
+
typeof page.has_more !== "boolean" ||
|
|
21
|
+
(page.has_more && !page.data.length))
|
|
22
|
+
return unavailable("refund_history_incomplete");
|
|
23
|
+
for (const refund of page.data) {
|
|
24
|
+
if (!refund ||
|
|
25
|
+
refund.object !== "refund" ||
|
|
26
|
+
typeof refund.id !== "string" ||
|
|
27
|
+
!/^re_[A-Za-z0-9_]+$/.test(refund.id) ||
|
|
28
|
+
seen.has(refund.id))
|
|
29
|
+
return unavailable("refund_history_incomplete");
|
|
30
|
+
seen.add(refund.id);
|
|
31
|
+
if (refundObjectId(refund.charge) !== opts.chargeId ||
|
|
32
|
+
refundObjectId(refund.payment_intent) !== opts.paymentIntentId ||
|
|
33
|
+
refund.currency !== opts.currency ||
|
|
34
|
+
!Number.isSafeInteger(refund.amount) ||
|
|
35
|
+
refund.amount < 0)
|
|
36
|
+
return unavailable("refund_scope_mismatch");
|
|
37
|
+
if (refund.status === "pending" || refund.status === "requires_action")
|
|
38
|
+
return unavailable("refund_pending");
|
|
39
|
+
if (refund.status !== "succeeded" &&
|
|
40
|
+
refund.status !== "failed" &&
|
|
41
|
+
refund.status !== "canceled")
|
|
42
|
+
return unavailable("refund_state_unknown");
|
|
43
|
+
if (refund.status === "succeeded")
|
|
44
|
+
refundedAmount += refund.amount;
|
|
45
|
+
if (!Number.isSafeInteger(refundedAmount) ||
|
|
46
|
+
refundedAmount > opts.capturedAmount)
|
|
47
|
+
return unavailable("refund_counter_mismatch");
|
|
48
|
+
}
|
|
49
|
+
if (!page.has_more)
|
|
50
|
+
return { status: "complete", refundedAmount };
|
|
51
|
+
cursor = page.data[page.data.length - 1].id;
|
|
52
|
+
}
|
|
53
|
+
return unavailable("refund_history_incomplete");
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=refundContextHistory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refundContextHistory.js","sourceRoot":"","sources":["../../../src/client/connect/refundContextHistory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAMnD,MAAM,WAAW,GAAG,CAClB,MAAsC,EACvB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC;AAExD,2GAA2G;AAC3G,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,IAOC;IAED,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,IAAI,MAA0B,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,G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K,IAAI,CAAC,QAAQ;gBACjC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC;gBACpC,MAAM,CAAC,MAAM,GAAG,CAAC;gBAEjB,OAAO,WAAW,CAAC,uBAAuB,CAAC,CAAC;YAC9C,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,iBAAiB;gBACpE,OAAO,WAAW,CAAC,gBAAgB,CAAC,CAAC;YACvC,IACE,MAAM,CAAC,MAAM,KAAK,WAAW;gBAC7B,MAAM,CAAC,MAAM,KAAK,QAAQ;gBAC1B,MAAM,CAAC,MAAM,KAAK,UAAU;gBAE5B,OAAO,WAAW,CAAC,sBAAsB,CAAC,CAAC;YAC7C,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW;gBAAE,cAAc,IAAI,MAAM,CAAC,MAAM,CAAC;YACnE,IACE,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC;gBACrC,cAAc,GAAG,IAAI,CAAC,cAAc;gBAEpC,OAAO,WAAW,CAAC,yBAAyB,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;QAClE,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO,WAAW,CAAC,2BAA2B,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { RefundActor } from "./refundActor.js";
|
|
3
|
+
/** New observations require an explicit actor; legacy createRefund omission is not inherited. */
|
|
4
|
+
export declare const refundContextOptionsSchema: z.ZodObject<{
|
|
5
|
+
stripePaymentIntentId: z.ZodString;
|
|
6
|
+
actor: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
7
|
+
type: z.ZodLiteral<"admin">;
|
|
8
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
9
|
+
type: z.ZodLiteral<"seller">;
|
|
10
|
+
accountId: z.ZodString;
|
|
11
|
+
}, z.core.$strict>], "type">;
|
|
12
|
+
stripeAccountId: z.ZodOptional<z.ZodString>;
|
|
13
|
+
maxRefundPages: z.ZodDefault<z.ZodNumber>;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
export type RefundContextOptions = {
|
|
16
|
+
stripePaymentIntentId: string;
|
|
17
|
+
actor: RefundActor;
|
|
18
|
+
/** Server-owned provider request scope, distinct from the buyer and merchant accounts. */
|
|
19
|
+
stripeAccountId?: string;
|
|
20
|
+
/** Complete bounded history or unavailable, never a partial refund balance. Default 5, maximum 10. */
|
|
21
|
+
maxRefundPages?: number;
|
|
22
|
+
};
|
|
23
|
+
export type RefundContextUnavailableReason = "payment_unavailable" | "buyer_unavailable" | "payment_scope_mismatch" | "payment_not_succeeded" | "charge_unavailable" | "charge_scope_mismatch" | "buyer_mismatch" | "currency_mismatch" | "amount_unavailable" | "charge_not_captured" | "charge_disputed" | "refund_pending" | "refund_state_unknown" | "refund_history_incomplete" | "refund_scope_mismatch" | "refund_counter_mismatch";
|
|
24
|
+
export type RefundContext = {
|
|
25
|
+
status: "unavailable";
|
|
26
|
+
reason: RefundContextUnavailableReason;
|
|
27
|
+
} | {
|
|
28
|
+
status: "ready";
|
|
29
|
+
stripePaymentIntentId: string;
|
|
30
|
+
stripeChargeId: string;
|
|
31
|
+
customerAccount: string;
|
|
32
|
+
currency: string;
|
|
33
|
+
capturedAmount: number;
|
|
34
|
+
refundedAmount: number;
|
|
35
|
+
remainingRefundableAmount: number;
|
|
36
|
+
/** Milliseconds; an observation, not a reservation or immutable snapshot. */
|
|
37
|
+
observedAt: number;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=refundContextTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refundContextTypes.d.ts","sourceRoot":"","sources":["../../../src/client/connect/refundContextTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,iGAAiG;AACjG,eAAO,MAAM,0BAA0B;;;;;;;;;;kBAU5B,CAAC;AAEZ,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,0FAA0F;IAC1F,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,MAAM,MAAM,8BAA8B,GACtC,qBAAqB,GACrB,mBAAmB,GACnB,wBAAwB,GACxB,uBAAuB,GACvB,oBAAoB,GACpB,uBAAuB,GACvB,gBAAgB,GAChB,mBAAmB,GACnB,oBAAoB,GACpB,qBAAqB,GACrB,iBAAiB,GACjB,gBAAgB,GAChB,sBAAsB,GACtB,2BAA2B,GAC3B,uBAAuB,GACvB,yBAAyB,CAAC;AAC9B,MAAM,MAAM,aAAa,GACrB;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,8BAA8B,CAAA;CAAE,GACjE;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,yBAAyB,EAAE,MAAM,CAAC;IAClC,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|