@fantastic.dev/better-stripe 0.41.0 → 0.43.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 +25 -0
- package/README.md +1 -1
- package/dist/client/balanceFundingWorkflow/client.d.ts +172 -0
- package/dist/client/balanceFundingWorkflow/client.d.ts.map +1 -0
- package/dist/client/balanceFundingWorkflow/client.js +289 -0
- package/dist/client/balanceFundingWorkflow/client.js.map +1 -0
- package/dist/client/billing/balanceFunding.d.ts +5 -0
- package/dist/client/billing/balanceFunding.d.ts.map +1 -1
- package/dist/client/billing/balanceFunding.js +30 -0
- package/dist/client/billing/balanceFunding.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +1388 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +710 -17
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +1420 -34
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +694 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/costRecovery-invoices.d.ts +3 -2
- package/dist/client/costRecovery-invoices.d.ts.map +1 -1
- package/dist/client/costRecovery-invoices.js +10 -5
- package/dist/client/costRecovery-invoices.js.map +1 -1
- package/dist/client/costRecovery.d.ts +4 -2
- package/dist/client/costRecovery.d.ts.map +1 -1
- package/dist/client/costRecovery.js +2 -2
- package/dist/client/costRecovery.js.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/processingCostReconciliation/client.d.ts +14 -0
- package/dist/client/processingCostReconciliation/client.d.ts.map +1 -0
- package/dist/client/processingCostReconciliation/client.js +35 -0
- package/dist/client/processingCostReconciliation/client.js.map +1 -0
- package/dist/client/processingCostReconciliation/contracts.d.ts +172 -0
- package/dist/client/processingCostReconciliation/contracts.d.ts.map +1 -0
- package/dist/client/processingCostReconciliation/contracts.js +55 -0
- package/dist/client/processingCostReconciliation/contracts.js.map +1 -0
- package/dist/client/processingCostReconciliation/invoiceFunding.d.ts +15 -0
- package/dist/client/processingCostReconciliation/invoiceFunding.d.ts.map +1 -0
- package/dist/client/processingCostReconciliation/invoiceFunding.js +195 -0
- package/dist/client/processingCostReconciliation/invoiceFunding.js.map +1 -0
- package/dist/client/processingCostReconciliation/provider.d.ts +9 -0
- package/dist/client/processingCostReconciliation/provider.d.ts.map +1 -0
- package/dist/client/processingCostReconciliation/provider.js +148 -0
- package/dist/client/processingCostReconciliation/provider.js.map +1 -0
- package/dist/client/settlement/processingCostHistory.d.ts +12 -0
- package/dist/client/settlement/processingCostHistory.d.ts.map +1 -0
- package/dist/client/settlement/processingCostHistory.js +20 -0
- package/dist/client/settlement/processingCostHistory.js.map +1 -0
- package/dist/client/settlement/processingCosts.d.ts +3 -0
- package/dist/client/settlement/processingCosts.d.ts.map +1 -1
- package/dist/client/settlement/processingCosts.js +27 -7
- package/dist/client/settlement/processingCosts.js.map +1 -1
- package/dist/component/_generated/api.d.ts +36 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +988 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/helpers.d.ts +42 -0
- package/dist/component/balanceFunding/helpers.d.ts.map +1 -1
- package/dist/component/balanceFunding/internal/actions.d.ts +39 -0
- package/dist/component/balanceFunding/internal/actions.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/actions.js +80 -0
- package/dist/component/balanceFunding/internal/actions.js.map +1 -0
- package/dist/component/balanceFunding/internal/mutations.d.ts +55 -0
- package/dist/component/balanceFunding/internal/mutations.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/mutations.js +54 -0
- package/dist/component/balanceFunding/internal/mutations.js.map +1 -0
- package/dist/component/balanceFunding/internal/queries.d.ts +116 -0
- package/dist/component/balanceFunding/internal/queries.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/queries.js +35 -0
- package/dist/component/balanceFunding/internal/queries.js.map +1 -0
- package/dist/component/balanceFunding/internal/workflow.d.ts +10 -0
- package/dist/component/balanceFunding/internal/workflow.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/workflow.js +31 -0
- package/dist/component/balanceFunding/internal/workflow.js.map +1 -0
- package/dist/component/balanceFunding/lifecycleHandlers.d.ts +126 -0
- package/dist/component/balanceFunding/lifecycleHandlers.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.d.ts +419 -16
- package/dist/component/balanceFunding/mutations.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.js +24 -0
- package/dist/component/balanceFunding/mutations.js.map +1 -1
- package/dist/component/balanceFunding/preparationHandlers.d.ts +42 -0
- package/dist/component/balanceFunding/preparationHandlers.d.ts.map +1 -1
- package/dist/component/balanceFunding/queries.d.ts +78 -0
- package/dist/component/balanceFunding/queries.d.ts.map +1 -1
- package/dist/component/balanceFunding/queries.js +35 -0
- package/dist/component/balanceFunding/queries.js.map +1 -1
- package/dist/component/balanceFunding/receipt.d.ts +5 -0
- package/dist/component/balanceFunding/receipt.d.ts.map +1 -0
- package/dist/component/balanceFunding/receipt.js +37 -0
- package/dist/component/balanceFunding/receipt.js.map +1 -0
- package/dist/component/balanceFunding/schema.d.ts +506 -2
- package/dist/component/balanceFunding/schema.d.ts.map +1 -1
- package/dist/component/balanceFunding/schema.js +2 -0
- package/dist/component/balanceFunding/schema.js.map +1 -1
- package/dist/component/balanceFunding/stateHandlers.d.ts +42 -0
- package/dist/component/balanceFunding/stateHandlers.d.ts.map +1 -1
- package/dist/component/balanceFunding/workflowControl.d.ts +19 -0
- package/dist/component/balanceFunding/workflowControl.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowControl.js +149 -0
- package/dist/component/balanceFunding/workflowControl.js.map +1 -0
- package/dist/component/balanceFunding/workflowSchema.d.ts +356 -0
- package/dist/component/balanceFunding/workflowSchema.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowSchema.js +48 -0
- package/dist/component/balanceFunding/workflowSchema.js.map +1 -0
- package/dist/component/balanceFunding/workflowState.d.ts +157 -0
- package/dist/component/balanceFunding/workflowState.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowState.js +194 -0
- package/dist/component/balanceFunding/workflowState.js.map +1 -0
- package/dist/component/balanceFunding/workflowValidators.d.ts +306 -0
- package/dist/component/balanceFunding/workflowValidators.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowValidators.js +27 -0
- package/dist/component/balanceFunding/workflowValidators.js.map +1 -0
- package/dist/component/earnings/triggers.d.ts +388 -2
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/adoption.d.ts +29 -0
- package/dist/component/processingCostReconciliation/adoption.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/adoption.js +58 -0
- package/dist/component/processingCostReconciliation/adoption.js.map +1 -0
- package/dist/component/processingCostReconciliation/bridge.d.ts +45 -0
- package/dist/component/processingCostReconciliation/bridge.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/bridge.js +41 -0
- package/dist/component/processingCostReconciliation/bridge.js.map +1 -0
- package/dist/component/processingCostReconciliation/helpers.d.ts +327 -0
- package/dist/component/processingCostReconciliation/helpers.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/helpers.js +39 -0
- package/dist/component/processingCostReconciliation/helpers.js.map +1 -0
- package/dist/component/processingCostReconciliation/mutations.d.ts +303 -0
- package/dist/component/processingCostReconciliation/mutations.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/mutations.js +121 -0
- package/dist/component/processingCostReconciliation/mutations.js.map +1 -0
- package/dist/component/processingCostReconciliation/queries.d.ts +422 -0
- package/dist/component/processingCostReconciliation/queries.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/queries.js +19 -0
- package/dist/component/processingCostReconciliation/queries.js.map +1 -0
- package/dist/component/processingCostReconciliation/rollback.d.ts +21 -0
- package/dist/component/processingCostReconciliation/rollback.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/rollback.js +54 -0
- package/dist/component/processingCostReconciliation/rollback.js.map +1 -0
- package/dist/component/processingCostReconciliation/schema.d.ts +2460 -0
- package/dist/component/processingCostReconciliation/schema.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/schema.js +137 -0
- package/dist/component/processingCostReconciliation/schema.js.map +1 -0
- package/dist/component/processingCostReconciliation/steps.d.ts +306 -0
- package/dist/component/processingCostReconciliation/steps.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/steps.js +149 -0
- package/dist/component/processingCostReconciliation/steps.js.map +1 -0
- package/dist/component/processingCostReconciliation/validation.d.ts +13 -0
- package/dist/component/processingCostReconciliation/validation.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/validation.js +61 -0
- package/dist/component/processingCostReconciliation/validation.js.map +1 -0
- package/dist/component/processingCostReconciliation/workflow.d.ts +105 -0
- package/dist/component/processingCostReconciliation/workflow.d.ts.map +1 -0
- package/dist/component/processingCostReconciliation/workflow.js +33 -0
- package/dist/component/processingCostReconciliation/workflow.js.map +1 -0
- package/dist/component/schema.d.ts +694 -1
- package/dist/component/schema.js +2 -0
- package/dist/component/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/client/balanceFundingWorkflow/capture.test.ts +144 -0
- package/src/client/balanceFundingWorkflow/client.ts +419 -0
- package/src/client/billing/balanceFunding.ts +50 -0
- package/src/client/costRecovery-invoices.ts +19 -4
- package/src/client/costRecovery.ts +4 -2
- package/src/client/index.ts +15 -0
- package/src/client/processingCostReconciliation/client.ts +75 -0
- package/src/client/processingCostReconciliation/contracts.ts +176 -0
- package/src/client/processingCostReconciliation/invoiceFunding.ts +270 -0
- package/src/client/processingCostReconciliation/invoiceProvider.test.ts +353 -0
- package/src/client/processingCostReconciliation/provider.test.ts +324 -0
- package/src/client/processingCostReconciliation/provider.ts +178 -0
- package/src/client/settlement/processingCostHistory.ts +31 -0
- package/src/client/settlement/processingCosts.ts +50 -15
- package/src/component/_generated/api.ts +36 -0
- package/src/component/_generated/component.ts +1094 -0
- package/src/component/balanceFunding/internal/actions.ts +107 -0
- package/src/component/balanceFunding/internal/mutations.ts +66 -0
- package/src/component/balanceFunding/internal/queries.ts +34 -0
- package/src/component/balanceFunding/internal/workflow.ts +49 -0
- package/src/component/balanceFunding/mutations.ts +34 -0
- package/src/component/balanceFunding/queries.ts +38 -0
- package/src/component/balanceFunding/receipt.ts +48 -0
- package/src/component/balanceFunding/schema.ts +2 -0
- package/src/component/balanceFunding/scopeLookup.test.ts +94 -0
- package/src/component/balanceFunding/workflow.fixtures.ts +366 -0
- package/src/component/balanceFunding/workflow.test.ts +552 -0
- package/src/component/balanceFunding/workflowControl.ts +198 -0
- package/src/component/balanceFunding/workflowSchema.ts +78 -0
- package/src/component/balanceFunding/workflowState.ts +285 -0
- package/src/component/balanceFunding/workflowValidators.ts +40 -0
- package/src/component/processingCostReconciliation/adoption.test.ts +206 -0
- package/src/component/processingCostReconciliation/adoption.ts +77 -0
- package/src/component/processingCostReconciliation/bridge.ts +50 -0
- package/src/component/processingCostReconciliation/helpers.ts +55 -0
- package/src/component/processingCostReconciliation/invoice.test.ts +152 -0
- package/src/component/processingCostReconciliation/mutations.ts +148 -0
- package/src/component/processingCostReconciliation/queries.ts +18 -0
- package/src/component/processingCostReconciliation/rollback.ts +72 -0
- package/src/component/processingCostReconciliation/schema.ts +191 -0
- package/src/component/processingCostReconciliation/state.test.ts +407 -0
- package/src/component/processingCostReconciliation/steps.ts +168 -0
- package/src/component/processingCostReconciliation/validation.ts +79 -0
- package/src/component/processingCostReconciliation/workflow.test.ts +329 -0
- package/src/component/processingCostReconciliation/workflow.ts +50 -0
- package/src/component/schema.ts +2 -0
package/dist/component/schema.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { operationsTable as processingCostReconciliationOperations } from "./processingCostReconciliation/schema.js";
|
|
1
2
|
import { operationsTable as recoveryWorkflowOperations, requestsTable as recoveryWorkflowRequests, } from "./recoveryWorkflow/schema.js";
|
|
2
3
|
import { preparationsTable as balanceFundingPreparations, operationsTable as balanceFundingOperations, requestsTable as balanceFundingRequests, } from "./balanceFunding/schema.js";
|
|
3
4
|
import { payloadsTable as operationEvidencePayloads, headersTable as operationEvidenceHeaders, } from "./operationEvidence/schema.js";
|
|
@@ -23,6 +24,7 @@ import { accountsTable } from "./core/schema";
|
|
|
23
24
|
import { pricesTable, productsTable } from "./products/schema";
|
|
24
25
|
import { webhookEventsTable } from "./webhooks/schema";
|
|
25
26
|
export default defineSchema({
|
|
27
|
+
processingCostReconciliationOperations,
|
|
26
28
|
recoveryWorkflowOperations,
|
|
27
29
|
recoveryWorkflowRequests,
|
|
28
30
|
balanceFundingPreparations,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,IAAI,0BAA0B,EAC7C,aAAa,IAAI,wBAAwB,GAC1C,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,iBAAiB,IAAI,0BAA0B,EAC/C,eAAe,IAAI,wBAAwB,EAC3C,aAAa,IAAI,sBAAsB,GACxC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,aAAa,IAAI,yBAAyB,EAC1C,YAAY,IAAI,wBAAwB,GACzC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAC;AAClG,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL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,cAAc,EAAE,WAAW;IAC3B,gBAAgB,EAAE,aAAa;IAC/B,cAAc,EAAE,WAAW;IAC3B,oBAAoB,EAAE,iBAAiB;IACvC,qBAAqB,EAAE,gBAAgB;IACvC,eAAe,EAAE,oBAAoB;IACrC,mBAAmB,EAAE,wBAAwB;IAC7C,OAAO;IACP,QAAQ,EAAE,aAAa;IACvB,eAAe,EAAE,oBAAoB;IAErC,WAAW;IACX,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,WAAW;IAEnB,UAAU;IACV,aAAa,EAAE,kBAAkB;IACjC,gBAAgB,EAAE,qBAAqB;IACvC,QAAQ,EAAE,aAAa;IAEvB,UAAU;IACV,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,YAAY;IACrB,iBAAiB,EAAE,sBAAsB;IACzC,OAAO,EAAE,YAAY;IACrB,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,cAAc;IACzB,mBAAmB,EAAE,wBAAwB;IAE7C,WAAW;IACX,aAAa,EAAE,kBAAkB;CAClC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import Stripe from "stripe";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { STRIPE_CUSTOMER_PREVIEW_API_VERSION } from "../apiVersion.js";
|
|
4
|
+
import * as funding from "../billing/balanceFunding.js";
|
|
5
|
+
|
|
6
|
+
function fixture(sdkVersion: string = STRIPE_CUSTOMER_PREVIEW_API_VERSION) {
|
|
7
|
+
const requests: { method: string; path: string; version: string | null }[] =
|
|
8
|
+
[];
|
|
9
|
+
const subscription = {
|
|
10
|
+
id: "sub_plan",
|
|
11
|
+
object: "subscription",
|
|
12
|
+
customer_account: "acct_owner",
|
|
13
|
+
status: "active",
|
|
14
|
+
default_payment_method: "pm_card",
|
|
15
|
+
payment_settings: { payment_method_types: ["card"] },
|
|
16
|
+
};
|
|
17
|
+
const method = {
|
|
18
|
+
id: "pm_card",
|
|
19
|
+
object: "payment_method",
|
|
20
|
+
type: "card",
|
|
21
|
+
customer_account: "acct_owner",
|
|
22
|
+
};
|
|
23
|
+
const stripe = new Stripe("sk_test_capture_fixture", {
|
|
24
|
+
apiVersion: sdkVersion as Stripe.LatestApiVersion,
|
|
25
|
+
maxNetworkRetries: 0,
|
|
26
|
+
httpClient: Stripe.createFetchHttpClient(async (url, init) => {
|
|
27
|
+
const path = new URL(String(url)).pathname;
|
|
28
|
+
requests.push({
|
|
29
|
+
method: init?.method ?? "GET",
|
|
30
|
+
path,
|
|
31
|
+
version: new Headers(init?.headers).get("Stripe-Version"),
|
|
32
|
+
});
|
|
33
|
+
return new Response(
|
|
34
|
+
JSON.stringify(path.includes("subscriptions") ? subscription : method),
|
|
35
|
+
{ status: 200 },
|
|
36
|
+
);
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
const capture = (
|
|
40
|
+
version = STRIPE_CUSTOMER_PREVIEW_API_VERSION,
|
|
41
|
+
consent = true,
|
|
42
|
+
) => {
|
|
43
|
+
return funding.captureBalanceFundingOriginal(stripe, version, {
|
|
44
|
+
customerAccount: "acct_owner",
|
|
45
|
+
stripeSubscriptionId: "sub_plan",
|
|
46
|
+
consent: consent as true,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
return { capture, subscription, method, requests };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
it("captures immutable original settings through read-only preview SDK calls before provisioning", async () => {
|
|
53
|
+
const s = fixture();
|
|
54
|
+
expect(await s.capture()).toEqual({
|
|
55
|
+
customerAccount: "acct_owner",
|
|
56
|
+
stripeSubscriptionId: "sub_plan",
|
|
57
|
+
previousPaymentMethodId: "pm_card",
|
|
58
|
+
previousPaymentMethodTypes: ["card"],
|
|
59
|
+
});
|
|
60
|
+
expect(s.requests).toEqual([
|
|
61
|
+
{
|
|
62
|
+
method: "GET",
|
|
63
|
+
path: "/v1/subscriptions/sub_plan",
|
|
64
|
+
version: STRIPE_CUSTOMER_PREVIEW_API_VERSION,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
method: "GET",
|
|
68
|
+
path: "/v1/payment_methods/pm_card",
|
|
69
|
+
version: STRIPE_CUSTOMER_PREVIEW_API_VERSION,
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("preserves null versus empty restoration settings", async () => {
|
|
75
|
+
for (const types of [null, []]) {
|
|
76
|
+
const s = fixture();
|
|
77
|
+
Object.assign(s.subscription, {
|
|
78
|
+
default_payment_method: null,
|
|
79
|
+
payment_settings: { payment_method_types: types },
|
|
80
|
+
});
|
|
81
|
+
expect(await s.capture()).toMatchObject({
|
|
82
|
+
previousPaymentMethodId: null,
|
|
83
|
+
previousPaymentMethodTypes: types,
|
|
84
|
+
});
|
|
85
|
+
expect(s.requests).toHaveLength(1);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("requires explicit preview configuration and consent before provider reads", async () => {
|
|
90
|
+
const s = fixture();
|
|
91
|
+
await expect(
|
|
92
|
+
s.capture(
|
|
93
|
+
"2026-02-25.clover" as typeof STRIPE_CUSTOMER_PREVIEW_API_VERSION,
|
|
94
|
+
),
|
|
95
|
+
).rejects.toThrow(/preview/i);
|
|
96
|
+
await expect(s.capture(undefined, false)).rejects.toThrow(/consent/i);
|
|
97
|
+
expect(s.requests).toHaveLength(0);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("refuses recapture when balance funding is already configured", async () => {
|
|
101
|
+
const settings = fixture();
|
|
102
|
+
settings.subscription.payment_settings.payment_method_types = [
|
|
103
|
+
"stripe_balance",
|
|
104
|
+
];
|
|
105
|
+
await expect(settings.capture()).rejects.toThrow(/persisted restoration/i);
|
|
106
|
+
const method = fixture();
|
|
107
|
+
method.method.type = "stripe_balance";
|
|
108
|
+
await expect(method.capture()).rejects.toThrow(/persisted restoration/i);
|
|
109
|
+
expect(
|
|
110
|
+
[...settings.requests, ...method.requests].every((r) => r.method === "GET"),
|
|
111
|
+
).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("rejects foreign or inactive subscriptions before any provider write", async () => {
|
|
115
|
+
const foreign = fixture();
|
|
116
|
+
foreign.subscription.customer_account = "acct_foreign";
|
|
117
|
+
await expect(foreign.capture()).rejects.toThrow(/belong/i);
|
|
118
|
+
const inactive = fixture();
|
|
119
|
+
inactive.subscription.status = "canceled";
|
|
120
|
+
await expect(inactive.capture()).rejects.toThrow(/cannot change/i);
|
|
121
|
+
expect(
|
|
122
|
+
[...foreign.requests, ...inactive.requests].every(
|
|
123
|
+
(r) => r.method === "GET",
|
|
124
|
+
),
|
|
125
|
+
).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("rejects a version argument that disagrees with the actual configured SDK", async () => {
|
|
129
|
+
const s = fixture("2026-02-25.clover");
|
|
130
|
+
await expect(s.capture()).rejects.toThrow(/preview|version/i);
|
|
131
|
+
expect(s.requests).toHaveLength(0);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("verifies the captured subscription and original payment method identities", async () => {
|
|
135
|
+
const subscription = fixture();
|
|
136
|
+
subscription.subscription.id = "sub_foreign";
|
|
137
|
+
await expect(subscription.capture()).rejects.toThrow(/identity|match/i);
|
|
138
|
+
const method = fixture();
|
|
139
|
+
method.method.id = "pm_foreign";
|
|
140
|
+
await expect(method.capture()).rejects.toThrow(/identity|match/i);
|
|
141
|
+
const owner = fixture();
|
|
142
|
+
owner.method.customer_account = "acct_foreign";
|
|
143
|
+
await expect(owner.capture()).rejects.toThrow(/belong|identity/i);
|
|
144
|
+
});
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import {
|
|
3
|
+
createFunctionHandle,
|
|
4
|
+
type FunctionReference,
|
|
5
|
+
type GenericActionCtx,
|
|
6
|
+
type GenericDataModel,
|
|
7
|
+
} from "convex/server";
|
|
8
|
+
import type { GenericId } from "convex/values";
|
|
9
|
+
import type { Component } from "../helpers.js";
|
|
10
|
+
import {
|
|
11
|
+
captureBalanceFundingOriginal,
|
|
12
|
+
getBalanceFundingCapability,
|
|
13
|
+
} from "../billing/balanceFunding.js";
|
|
14
|
+
import { resolveOwnerAccount } from "../utils/owner.js";
|
|
15
|
+
import {
|
|
16
|
+
FUNDING_WORKFLOW_VERSION,
|
|
17
|
+
type ProviderResult,
|
|
18
|
+
} from "../../component/balanceFunding/workflowSchema.js";
|
|
19
|
+
import type { FundingPhaseRef } from "../../component/balanceFunding/workflowValidators.js";
|
|
20
|
+
export type FundingProviderPhaseOptions = Omit<
|
|
21
|
+
FundingPhaseRef,
|
|
22
|
+
"operationId"
|
|
23
|
+
> & { operationId: string };
|
|
24
|
+
export type FundingProviderPhaseResult = ProviderResult;
|
|
25
|
+
type Context = Pick<
|
|
26
|
+
GenericActionCtx<GenericDataModel>,
|
|
27
|
+
"runQuery" | "runMutation"
|
|
28
|
+
>;
|
|
29
|
+
export type FundingOperationReference = {
|
|
30
|
+
accountId: string;
|
|
31
|
+
scopeKey: string;
|
|
32
|
+
stripeSubscriptionId: string;
|
|
33
|
+
operationId: string;
|
|
34
|
+
version: number;
|
|
35
|
+
};
|
|
36
|
+
export type PrepareFundingWorkflowOptions = {
|
|
37
|
+
accountId: string;
|
|
38
|
+
scopeKey: string;
|
|
39
|
+
stripeSubscriptionId: string;
|
|
40
|
+
requestKey: string;
|
|
41
|
+
consent: true;
|
|
42
|
+
consentAt: number;
|
|
43
|
+
consentReference: string;
|
|
44
|
+
providerAction: FunctionReference<"action", "public" | "internal">;
|
|
45
|
+
};
|
|
46
|
+
const uncertain = (): ProviderResult => ({
|
|
47
|
+
status: "unknown",
|
|
48
|
+
reason: "provider_outcome_unknown",
|
|
49
|
+
retryable: false,
|
|
50
|
+
});
|
|
51
|
+
export class BalanceFundingWorkflowClient {
|
|
52
|
+
constructor(
|
|
53
|
+
private readonly component: Component,
|
|
54
|
+
private readonly provider: () => Stripe,
|
|
55
|
+
private readonly apiVersion: string,
|
|
56
|
+
) {}
|
|
57
|
+
private reference(args: FundingOperationReference) {
|
|
58
|
+
return {
|
|
59
|
+
accountId: args.accountId,
|
|
60
|
+
scopeKey: args.scopeKey,
|
|
61
|
+
stripeSubscriptionId: args.stripeSubscriptionId,
|
|
62
|
+
version: args.version,
|
|
63
|
+
operationId: args.operationId as GenericId<"balanceFundingOperations">,
|
|
64
|
+
providerApiVersion: this.apiVersion,
|
|
65
|
+
definitionVersion: FUNDING_WORKFLOW_VERSION,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async prepare(ctx: Context, options: PrepareFundingWorkflowOptions) {
|
|
69
|
+
if (
|
|
70
|
+
!getBalanceFundingCapability(this.apiVersion).configured ||
|
|
71
|
+
options.consent !== true
|
|
72
|
+
)
|
|
73
|
+
return {
|
|
74
|
+
status: "rejected" as const,
|
|
75
|
+
reason: "policy_invalid" as const,
|
|
76
|
+
retryable: false as const,
|
|
77
|
+
};
|
|
78
|
+
const { providerAction, consentAt, consentReference, ...lookup } = options;
|
|
79
|
+
const query = { ...lookup, providerApiVersion: this.apiVersion };
|
|
80
|
+
const prior = await ctx.runQuery(
|
|
81
|
+
this.component.balanceFunding.queries.findPreparationOperation,
|
|
82
|
+
query,
|
|
83
|
+
);
|
|
84
|
+
let operation;
|
|
85
|
+
if (prior && "operationId" in prior) operation = prior;
|
|
86
|
+
else if (prior) return prior;
|
|
87
|
+
else {
|
|
88
|
+
const { requestKey: _requestKey, consent: _consent, ...scope } = lookup;
|
|
89
|
+
const saved = await ctx.runQuery(
|
|
90
|
+
this.component.balanceFunding.queries.readScopePreparation,
|
|
91
|
+
{ ...scope, providerApiVersion: this.apiVersion },
|
|
92
|
+
);
|
|
93
|
+
if (saved && "status" in saved) return saved;
|
|
94
|
+
const captured =
|
|
95
|
+
saved?.preparation ??
|
|
96
|
+
(await captureBalanceFundingOriginal(this.provider(), this.apiVersion, {
|
|
97
|
+
customerAccount: options.accountId,
|
|
98
|
+
stripeSubscriptionId: options.stripeSubscriptionId,
|
|
99
|
+
consent: true,
|
|
100
|
+
}));
|
|
101
|
+
const {
|
|
102
|
+
customerAccount,
|
|
103
|
+
stripeSubscriptionId,
|
|
104
|
+
previousPaymentMethodId,
|
|
105
|
+
previousPaymentMethodTypes,
|
|
106
|
+
} = captured;
|
|
107
|
+
const intent = await ctx.runMutation(
|
|
108
|
+
this.component.balanceFunding.mutations.prepare,
|
|
109
|
+
{
|
|
110
|
+
accountId: options.accountId,
|
|
111
|
+
scopeKey: options.scopeKey,
|
|
112
|
+
requestKey: options.requestKey,
|
|
113
|
+
consent: true,
|
|
114
|
+
consentAt: saved?.consentAt ?? consentAt,
|
|
115
|
+
consentReference: saved?.consentReference ?? consentReference,
|
|
116
|
+
providerApiVersion: this.apiVersion,
|
|
117
|
+
preparation: {
|
|
118
|
+
customerAccount,
|
|
119
|
+
stripeSubscriptionId,
|
|
120
|
+
previousPaymentMethodId,
|
|
121
|
+
previousPaymentMethodTypes,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
if (intent.status !== "accepted") return intent;
|
|
126
|
+
operation = intent.operation;
|
|
127
|
+
}
|
|
128
|
+
return ctx.runMutation(
|
|
129
|
+
this.component.balanceFunding.mutations.startWorkflow,
|
|
130
|
+
{
|
|
131
|
+
...this.reference({
|
|
132
|
+
...operation,
|
|
133
|
+
stripeSubscriptionId: options.stripeSubscriptionId,
|
|
134
|
+
}),
|
|
135
|
+
providerAction: await createFunctionHandle(providerAction),
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
async apply(
|
|
140
|
+
ctx: Context,
|
|
141
|
+
options: {
|
|
142
|
+
accountId: string;
|
|
143
|
+
scopeKey: string;
|
|
144
|
+
stripeSubscriptionId: string;
|
|
145
|
+
preparationId: string;
|
|
146
|
+
enabled: boolean;
|
|
147
|
+
consent?: true;
|
|
148
|
+
requestKey: string;
|
|
149
|
+
providerAction: FunctionReference<"action", "public" | "internal">;
|
|
150
|
+
},
|
|
151
|
+
) {
|
|
152
|
+
if (!getBalanceFundingCapability(this.apiVersion).configured)
|
|
153
|
+
return {
|
|
154
|
+
status: "rejected" as const,
|
|
155
|
+
reason: "policy_invalid" as const,
|
|
156
|
+
retryable: false as const,
|
|
157
|
+
};
|
|
158
|
+
const preparation = await ctx.runQuery(
|
|
159
|
+
this.component.balanceFunding.queries.readPreparation,
|
|
160
|
+
{
|
|
161
|
+
accountId: options.accountId,
|
|
162
|
+
scopeKey: options.scopeKey,
|
|
163
|
+
stripeSubscriptionId: options.stripeSubscriptionId,
|
|
164
|
+
preparationId: options.preparationId,
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
if (!preparation || preparation.providerApiVersion !== this.apiVersion)
|
|
168
|
+
return {
|
|
169
|
+
status: "conflict" as const,
|
|
170
|
+
reason: "identity_changed" as const,
|
|
171
|
+
retryable: false as const,
|
|
172
|
+
};
|
|
173
|
+
const result = await ctx.runMutation(
|
|
174
|
+
this.component.balanceFunding.mutations.begin,
|
|
175
|
+
{
|
|
176
|
+
accountId: options.accountId,
|
|
177
|
+
scopeKey: options.scopeKey,
|
|
178
|
+
preparationId: options.preparationId,
|
|
179
|
+
enabled: options.enabled,
|
|
180
|
+
...(options.consent === true ? { consent: true as const } : {}),
|
|
181
|
+
requestKey: options.requestKey,
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
if (result.status !== "accepted") return result;
|
|
185
|
+
return ctx.runMutation(
|
|
186
|
+
this.component.balanceFunding.mutations.startWorkflow,
|
|
187
|
+
{
|
|
188
|
+
...this.reference({
|
|
189
|
+
...result.operation,
|
|
190
|
+
stripeSubscriptionId: options.stripeSubscriptionId,
|
|
191
|
+
}),
|
|
192
|
+
providerAction: await createFunctionHandle(options.providerAction),
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
inspect(ctx: Context, args: FundingOperationReference) {
|
|
197
|
+
return ctx.runQuery(this.component.balanceFunding.queries.getOperation, {
|
|
198
|
+
accountId: args.accountId,
|
|
199
|
+
scopeKey: args.scopeKey,
|
|
200
|
+
operationId: args.operationId,
|
|
201
|
+
version: args.version,
|
|
202
|
+
stripeSubscriptionId: args.stripeSubscriptionId,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
resume(ctx: Context, args: FundingOperationReference) {
|
|
206
|
+
return ctx.runMutation(
|
|
207
|
+
this.component.balanceFunding.mutations.resumeWorkflow,
|
|
208
|
+
this.reference(args),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
cancel(ctx: Context, args: FundingOperationReference) {
|
|
212
|
+
return ctx.runMutation(
|
|
213
|
+
this.component.balanceFunding.mutations.cancelWorkflow,
|
|
214
|
+
this.reference(args),
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
async executeProviderPhase(
|
|
218
|
+
ctx: Context,
|
|
219
|
+
input: FundingProviderPhaseOptions,
|
|
220
|
+
): Promise<ProviderResult> {
|
|
221
|
+
const args = {
|
|
222
|
+
...input,
|
|
223
|
+
operationId: input.operationId as GenericId<"balanceFundingOperations">,
|
|
224
|
+
};
|
|
225
|
+
try {
|
|
226
|
+
const stripe = this.provider();
|
|
227
|
+
if (
|
|
228
|
+
args.providerApiVersion !== this.apiVersion ||
|
|
229
|
+
stripe.getApiField("version") !== args.providerApiVersion ||
|
|
230
|
+
!getBalanceFundingCapability(this.apiVersion).configured
|
|
231
|
+
)
|
|
232
|
+
return {
|
|
233
|
+
status: "conflict",
|
|
234
|
+
reason: "revision_changed",
|
|
235
|
+
retryable: false,
|
|
236
|
+
};
|
|
237
|
+
const claim = await ctx.runMutation(
|
|
238
|
+
this.component.balanceFunding.mutations.claimProviderPhase,
|
|
239
|
+
args,
|
|
240
|
+
);
|
|
241
|
+
if (claim.status !== "claimed") return claim;
|
|
242
|
+
const operation = await ctx.runQuery(
|
|
243
|
+
this.component.balanceFunding.queries.inspectOperation,
|
|
244
|
+
{
|
|
245
|
+
accountId: args.accountId,
|
|
246
|
+
scopeKey: args.scopeKey,
|
|
247
|
+
operationId: args.operationId,
|
|
248
|
+
version: args.version,
|
|
249
|
+
stripeSubscriptionId: args.stripeSubscriptionId,
|
|
250
|
+
},
|
|
251
|
+
);
|
|
252
|
+
if (!operation) return uncertain();
|
|
253
|
+
const saved = await ctx.runQuery(
|
|
254
|
+
this.component.balanceFunding.queries.readPreparation,
|
|
255
|
+
{
|
|
256
|
+
accountId: args.accountId,
|
|
257
|
+
scopeKey: args.scopeKey,
|
|
258
|
+
preparationId: operation.preparationId,
|
|
259
|
+
stripeSubscriptionId: args.stripeSubscriptionId,
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
if (!saved || saved.providerApiVersion !== args.providerApiVersion)
|
|
263
|
+
return uncertain();
|
|
264
|
+
const prep = saved.preparation;
|
|
265
|
+
if (args.phase === "apply") {
|
|
266
|
+
if (!prep.paymentMethodId || !saved.verified) return uncertain();
|
|
267
|
+
const method = await stripe.paymentMethods.retrieve(
|
|
268
|
+
prep.paymentMethodId,
|
|
269
|
+
);
|
|
270
|
+
if (
|
|
271
|
+
method.id !== prep.paymentMethodId ||
|
|
272
|
+
method.type !== "stripe_balance" ||
|
|
273
|
+
resolveOwnerAccount(method) !== args.accountId
|
|
274
|
+
)
|
|
275
|
+
return uncertain();
|
|
276
|
+
let sub = await stripe.subscriptions.retrieve(
|
|
277
|
+
args.stripeSubscriptionId,
|
|
278
|
+
);
|
|
279
|
+
const matches = (id: string | null, types: string[] | null) => {
|
|
280
|
+
const pm =
|
|
281
|
+
typeof sub.default_payment_method === "string"
|
|
282
|
+
? sub.default_payment_method
|
|
283
|
+
: (sub.default_payment_method?.id ?? null);
|
|
284
|
+
const actual = sub.payment_settings?.payment_method_types ?? null;
|
|
285
|
+
return (
|
|
286
|
+
pm === id &&
|
|
287
|
+
JSON.stringify(actual === null ? null : [...actual].sort()) ===
|
|
288
|
+
JSON.stringify(types === null ? null : [...types].sort())
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
const valid = () =>
|
|
292
|
+
sub.id === args.stripeSubscriptionId &&
|
|
293
|
+
sub.object === "subscription" &&
|
|
294
|
+
resolveOwnerAccount(sub) === args.accountId &&
|
|
295
|
+
["active", "trialing", "past_due"].includes(sub.status);
|
|
296
|
+
const targetMethod = operation.enabled
|
|
297
|
+
? prep.paymentMethodId
|
|
298
|
+
: prep.previousPaymentMethodId;
|
|
299
|
+
const targetTypes = operation.enabled
|
|
300
|
+
? ["stripe_balance"]
|
|
301
|
+
: prep.previousPaymentMethodTypes;
|
|
302
|
+
if (!valid()) return uncertain();
|
|
303
|
+
if (!matches(targetMethod, targetTypes)) {
|
|
304
|
+
if (
|
|
305
|
+
claim.mode !== "execute" ||
|
|
306
|
+
(!matches(
|
|
307
|
+
prep.previousPaymentMethodId,
|
|
308
|
+
prep.previousPaymentMethodTypes,
|
|
309
|
+
) &&
|
|
310
|
+
!matches(prep.paymentMethodId, ["stripe_balance"]))
|
|
311
|
+
)
|
|
312
|
+
return uncertain();
|
|
313
|
+
await stripe.subscriptions.update(
|
|
314
|
+
sub.id,
|
|
315
|
+
{
|
|
316
|
+
default_payment_method: targetMethod ?? "",
|
|
317
|
+
payment_settings: {
|
|
318
|
+
payment_method_types:
|
|
319
|
+
(targetTypes as Stripe.SubscriptionUpdateParams.PaymentSettings.PaymentMethodType[]) ??
|
|
320
|
+
"",
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
{ idempotencyKey: args.providerKey, maxNetworkRetries: 0 },
|
|
324
|
+
);
|
|
325
|
+
sub = await stripe.subscriptions.retrieve(args.stripeSubscriptionId);
|
|
326
|
+
if (!valid() || !matches(targetMethod, targetTypes))
|
|
327
|
+
return uncertain();
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
status: "ready",
|
|
331
|
+
value: {
|
|
332
|
+
phase: "apply",
|
|
333
|
+
customerAccount: args.accountId,
|
|
334
|
+
stripeSubscriptionId: args.stripeSubscriptionId,
|
|
335
|
+
providerApiVersion: args.providerApiVersion,
|
|
336
|
+
paymentMethodId: targetMethod,
|
|
337
|
+
paymentMethodTypes: targetTypes,
|
|
338
|
+
enabled: operation.enabled,
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
let paymentMethodId = claim.paymentMethodId;
|
|
343
|
+
if (args.phase === "create") {
|
|
344
|
+
const method = await stripe.paymentMethods.create(
|
|
345
|
+
{ type: "stripe_balance" },
|
|
346
|
+
{ idempotencyKey: args.providerKey, maxNetworkRetries: 0 },
|
|
347
|
+
);
|
|
348
|
+
if (
|
|
349
|
+
!method.id ||
|
|
350
|
+
method.object !== "payment_method" ||
|
|
351
|
+
method.type !== "stripe_balance" ||
|
|
352
|
+
resolveOwnerAccount(method)
|
|
353
|
+
)
|
|
354
|
+
return uncertain();
|
|
355
|
+
paymentMethodId = method.id;
|
|
356
|
+
} else {
|
|
357
|
+
if (!paymentMethodId) return uncertain();
|
|
358
|
+
let method = await stripe.paymentMethods.retrieve(paymentMethodId);
|
|
359
|
+
if (
|
|
360
|
+
method.id !== paymentMethodId ||
|
|
361
|
+
method.object !== "payment_method" ||
|
|
362
|
+
method.type !== "stripe_balance"
|
|
363
|
+
)
|
|
364
|
+
return uncertain();
|
|
365
|
+
if (!resolveOwnerAccount(method) && claim.mode === "execute") {
|
|
366
|
+
await stripe.paymentMethods.attach(
|
|
367
|
+
paymentMethodId,
|
|
368
|
+
{ customer_account: args.accountId },
|
|
369
|
+
{ idempotencyKey: args.providerKey, maxNetworkRetries: 0 },
|
|
370
|
+
);
|
|
371
|
+
method = await stripe.paymentMethods.retrieve(paymentMethodId);
|
|
372
|
+
}
|
|
373
|
+
if (
|
|
374
|
+
method.id !== paymentMethodId ||
|
|
375
|
+
resolveOwnerAccount(method) !== args.accountId
|
|
376
|
+
)
|
|
377
|
+
return uncertain();
|
|
378
|
+
const sub = await stripe.subscriptions.retrieve(
|
|
379
|
+
args.stripeSubscriptionId,
|
|
380
|
+
);
|
|
381
|
+
if (
|
|
382
|
+
sub.id !== args.stripeSubscriptionId ||
|
|
383
|
+
resolveOwnerAccount(sub) !== args.accountId ||
|
|
384
|
+
!["active", "trialing", "past_due"].includes(sub.status)
|
|
385
|
+
)
|
|
386
|
+
return uncertain();
|
|
387
|
+
const currentMethod =
|
|
388
|
+
typeof sub.default_payment_method === "string"
|
|
389
|
+
? sub.default_payment_method
|
|
390
|
+
: (sub.default_payment_method?.id ?? null);
|
|
391
|
+
const currentTypes = sub.payment_settings?.payment_method_types ?? null;
|
|
392
|
+
if (
|
|
393
|
+
currentMethod !== prep.previousPaymentMethodId ||
|
|
394
|
+
JSON.stringify(
|
|
395
|
+
currentTypes === null ? null : [...currentTypes].sort(),
|
|
396
|
+
) !==
|
|
397
|
+
JSON.stringify(
|
|
398
|
+
prep.previousPaymentMethodTypes === null
|
|
399
|
+
? null
|
|
400
|
+
: [...prep.previousPaymentMethodTypes].sort(),
|
|
401
|
+
)
|
|
402
|
+
)
|
|
403
|
+
return uncertain();
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
status: "ready",
|
|
407
|
+
value: {
|
|
408
|
+
phase: args.phase,
|
|
409
|
+
customerAccount: args.accountId,
|
|
410
|
+
stripeSubscriptionId: args.stripeSubscriptionId,
|
|
411
|
+
providerApiVersion: args.providerApiVersion,
|
|
412
|
+
paymentMethodId: paymentMethodId!,
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
} catch {
|
|
416
|
+
return uncertain();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
@@ -66,6 +66,56 @@ function methodId(sub: Stripe.Subscription) {
|
|
|
66
66
|
return typeof pm === "string" ? pm : (pm?.id ?? null);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
export type BalanceFundingOriginal = Omit<
|
|
70
|
+
BalanceFundingPreparation,
|
|
71
|
+
"paymentMethodId"
|
|
72
|
+
>;
|
|
73
|
+
|
|
74
|
+
/** Read only: persist this snapshot before provisioning any provider resource. */
|
|
75
|
+
export async function captureBalanceFundingOriginal(
|
|
76
|
+
stripe: Stripe,
|
|
77
|
+
version: string,
|
|
78
|
+
opts: BalanceFundingScope & { consent: true },
|
|
79
|
+
): Promise<BalanceFundingOriginal> {
|
|
80
|
+
if (
|
|
81
|
+
!getBalanceFundingCapability(version).configured ||
|
|
82
|
+
stripe.getApiField("version") !== version
|
|
83
|
+
)
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Balance funding capture requires matching explicit Stripe preview API configuration.",
|
|
86
|
+
);
|
|
87
|
+
if (opts.consent !== true)
|
|
88
|
+
throw new Error("Explicit consent is required for balance funding.");
|
|
89
|
+
const sub = await subscription(stripe, opts);
|
|
90
|
+
if (sub.id !== opts.stripeSubscriptionId || sub.object !== "subscription")
|
|
91
|
+
throw new Error("Captured subscription identity does not match.");
|
|
92
|
+
const previous = methodId(sub);
|
|
93
|
+
const types = sub.payment_settings?.payment_method_types ?? null;
|
|
94
|
+
if (types?.includes("stripe_balance"))
|
|
95
|
+
throw new Error(
|
|
96
|
+
"Balance funding is already configured; reuse the persisted restoration record.",
|
|
97
|
+
);
|
|
98
|
+
if (previous) {
|
|
99
|
+
const method = await stripe.paymentMethods.retrieve(previous);
|
|
100
|
+
if (method.id !== previous || method.object !== "payment_method")
|
|
101
|
+
throw new Error("Captured payment method identity does not match.");
|
|
102
|
+
if (resolveOwnerAccount(method) !== opts.customerAccount)
|
|
103
|
+
throw new Error(
|
|
104
|
+
"Original payment method does not belong to the account.",
|
|
105
|
+
);
|
|
106
|
+
if (method.type === "stripe_balance")
|
|
107
|
+
throw new Error(
|
|
108
|
+
"Balance funding is already configured; reuse the persisted restoration record.",
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
customerAccount: opts.customerAccount,
|
|
113
|
+
stripeSubscriptionId: opts.stripeSubscriptionId,
|
|
114
|
+
previousPaymentMethodId: previous,
|
|
115
|
+
previousPaymentMethodTypes: types === null ? null : [...types],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
69
119
|
/** Capture restoration settings, provision and attach; does not enable billing. */
|
|
70
120
|
export async function prepareBalanceFunding(
|
|
71
121
|
stripe: Stripe,
|