@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
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import workflowTest from "@convex-dev/workflow/test";
|
|
3
|
+
import type { WorkflowId } from "@convex-dev/workflow";
|
|
4
|
+
import { executionWorkflow } from "../durableExecution/runtime.js";
|
|
5
|
+
import { convexTest } from "convex-test";
|
|
6
|
+
import {
|
|
7
|
+
anyApi,
|
|
8
|
+
componentsGeneric,
|
|
9
|
+
defineSchema,
|
|
10
|
+
internalActionGeneric,
|
|
11
|
+
internalQueryGeneric,
|
|
12
|
+
internalMutationGeneric,
|
|
13
|
+
} from "convex/server";
|
|
14
|
+
import { v } from "convex/values";
|
|
15
|
+
import Stripe from "stripe";
|
|
16
|
+
import { afterEach, beforeEach, vi } from "vitest";
|
|
17
|
+
import { BetterStripe } from "../../client/index.js";
|
|
18
|
+
import { getStripeClient, type Component } from "../../client/helpers.js";
|
|
19
|
+
import { STRIPE_CUSTOMER_PREVIEW_API_VERSION as version } from "../../client/apiVersion.js";
|
|
20
|
+
import { internal } from "../_generated/api.js";
|
|
21
|
+
import { workflowRefFields } from "./workflowValidators.js";
|
|
22
|
+
import { provisioningReceipt } from "./workflowSchema.js";
|
|
23
|
+
import { schema, modules } from "../../test.js";
|
|
24
|
+
|
|
25
|
+
export const nested = componentsGeneric();
|
|
26
|
+
export const scope = { accountId: "acct_owner", scopeKey: "opaque-scope" };
|
|
27
|
+
export const stripeSubscriptionId = "sub_original";
|
|
28
|
+
export const original = {
|
|
29
|
+
customerAccount: scope.accountId,
|
|
30
|
+
stripeSubscriptionId,
|
|
31
|
+
previousPaymentMethodId: "pm_card",
|
|
32
|
+
previousPaymentMethodTypes: ["card"],
|
|
33
|
+
};
|
|
34
|
+
const phaseArgs = {
|
|
35
|
+
...{
|
|
36
|
+
accountId: v.string(),
|
|
37
|
+
scopeKey: v.string(),
|
|
38
|
+
operationId: v.string(),
|
|
39
|
+
version: v.number(),
|
|
40
|
+
},
|
|
41
|
+
stripeSubscriptionId: v.string(),
|
|
42
|
+
providerApiVersion: v.string(),
|
|
43
|
+
definitionVersion: v.string(),
|
|
44
|
+
phase: v.union(v.literal("create"), v.literal("attach"), v.literal("apply")),
|
|
45
|
+
providerKey: v.string(),
|
|
46
|
+
};
|
|
47
|
+
let requests: {
|
|
48
|
+
method: string;
|
|
49
|
+
path: string;
|
|
50
|
+
version: string | null;
|
|
51
|
+
key: string | null;
|
|
52
|
+
}[];
|
|
53
|
+
let methodOwner: string | null;
|
|
54
|
+
let unknownPhase: "create" | "attach" | null;
|
|
55
|
+
let extraFields: boolean;
|
|
56
|
+
let enabled: boolean;
|
|
57
|
+
let lostApply: boolean;
|
|
58
|
+
let checkpointFault: boolean;
|
|
59
|
+
let cancelPhase: "create" | "attach" | "apply" | null;
|
|
60
|
+
function client() {
|
|
61
|
+
const sdk = new BetterStripe(nested.betterStripe as unknown as Component, {
|
|
62
|
+
stripeApiVersion: version,
|
|
63
|
+
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
|
|
64
|
+
});
|
|
65
|
+
return sdk.balanceFundingWorkflow;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const host = {
|
|
69
|
+
prepare: internalActionGeneric({
|
|
70
|
+
args: { requestKey: v.string() },
|
|
71
|
+
returns: v.any(),
|
|
72
|
+
handler: async (ctx, { requestKey }) =>
|
|
73
|
+
client().prepare(ctx, {
|
|
74
|
+
...scope,
|
|
75
|
+
stripeSubscriptionId,
|
|
76
|
+
requestKey,
|
|
77
|
+
consent: true,
|
|
78
|
+
consentAt: 100,
|
|
79
|
+
consentReference: "original-consent",
|
|
80
|
+
providerAction: anyApi.host.provider,
|
|
81
|
+
}),
|
|
82
|
+
}),
|
|
83
|
+
provider: internalActionGeneric({
|
|
84
|
+
args: phaseArgs,
|
|
85
|
+
returns: v.any(),
|
|
86
|
+
handler: async (ctx, args) => {
|
|
87
|
+
const result = await client().executeProviderPhase(ctx, args);
|
|
88
|
+
if (cancelPhase === args.phase) {
|
|
89
|
+
cancelPhase = null;
|
|
90
|
+
await client().cancel(ctx, {
|
|
91
|
+
accountId: args.accountId,
|
|
92
|
+
scopeKey: args.scopeKey,
|
|
93
|
+
stripeSubscriptionId: args.stripeSubscriptionId,
|
|
94
|
+
operationId: args.operationId,
|
|
95
|
+
version: args.version,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (!extraFields) return result;
|
|
99
|
+
const response = result as { status: string; value?: object };
|
|
100
|
+
return {
|
|
101
|
+
...response,
|
|
102
|
+
value: {
|
|
103
|
+
...response.value,
|
|
104
|
+
rawProviderObject: "raw_provider_private_field",
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
apply: internalActionGeneric({
|
|
110
|
+
args: {
|
|
111
|
+
preparationId: v.string(),
|
|
112
|
+
enabled: v.boolean(),
|
|
113
|
+
requestKey: v.string(),
|
|
114
|
+
},
|
|
115
|
+
returns: v.any(),
|
|
116
|
+
handler: (ctx, args) =>
|
|
117
|
+
new BetterStripe(nested.betterStripe as unknown as Component, {
|
|
118
|
+
stripeApiVersion: version,
|
|
119
|
+
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
|
|
120
|
+
}).balanceFundingWorkflow.apply(ctx, {
|
|
121
|
+
...args,
|
|
122
|
+
...scope,
|
|
123
|
+
stripeSubscriptionId,
|
|
124
|
+
consent: true,
|
|
125
|
+
providerAction: anyApi.host.provider,
|
|
126
|
+
}),
|
|
127
|
+
}),
|
|
128
|
+
resume: internalActionGeneric({
|
|
129
|
+
args: { operationId: v.string(), version: v.number() },
|
|
130
|
+
returns: v.any(),
|
|
131
|
+
handler: async (ctx, args) =>
|
|
132
|
+
client().resume(ctx, { ...args, ...scope, stripeSubscriptionId }),
|
|
133
|
+
}),
|
|
134
|
+
inspect: internalActionGeneric({
|
|
135
|
+
args: { operationId: v.string(), version: v.number() },
|
|
136
|
+
returns: v.any(),
|
|
137
|
+
handler: (ctx, args) =>
|
|
138
|
+
client().inspect(ctx, { ...args, ...scope, stripeSubscriptionId }),
|
|
139
|
+
}),
|
|
140
|
+
cancel: internalActionGeneric({
|
|
141
|
+
args: { operationId: v.string(), version: v.number() },
|
|
142
|
+
returns: v.any(),
|
|
143
|
+
handler: async (ctx, args) =>
|
|
144
|
+
client().cancel(ctx, { ...args, ...scope, stripeSubscriptionId }),
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
export function setup(
|
|
148
|
+
failFinish = false,
|
|
149
|
+
failReceipt = false,
|
|
150
|
+
stopBeforeApplyRecord = false,
|
|
151
|
+
) {
|
|
152
|
+
let attempts = 0;
|
|
153
|
+
let receiptAttempts = 0;
|
|
154
|
+
const t = convexTest(defineSchema({}), {
|
|
155
|
+
"./_generated/api.ts": async () => ({}),
|
|
156
|
+
"./host.ts": async () => host,
|
|
157
|
+
});
|
|
158
|
+
t.registerComponent("betterStripe", schema, {
|
|
159
|
+
...modules,
|
|
160
|
+
...(stopBeforeApplyRecord
|
|
161
|
+
? {
|
|
162
|
+
"./component/balanceFunding/internal/workflow.ts": async () => {
|
|
163
|
+
const modulePath = "./internal/workflow.ts";
|
|
164
|
+
const actual = await import(/* @vite-ignore */ modulePath);
|
|
165
|
+
if (!checkpointFault) return actual;
|
|
166
|
+
return {
|
|
167
|
+
...actual,
|
|
168
|
+
run: executionWorkflow.define({
|
|
169
|
+
args: workflowRefFields,
|
|
170
|
+
returns: v.null(),
|
|
171
|
+
handler: async (step, args): Promise<null> => {
|
|
172
|
+
const plan = await step.runQuery(
|
|
173
|
+
internal.balanceFunding.internal.queries.plan,
|
|
174
|
+
args,
|
|
175
|
+
{ name: "plan-v1" },
|
|
176
|
+
);
|
|
177
|
+
await step.runAction(
|
|
178
|
+
internal.balanceFunding.internal.actions.bridge,
|
|
179
|
+
{ ...args, phase: "apply", providerKey: plan.applyKey },
|
|
180
|
+
{ name: "apply-provider-v1", retry: false },
|
|
181
|
+
);
|
|
182
|
+
throw new Error(
|
|
183
|
+
"controlled stop at durable provider checkpoint",
|
|
184
|
+
);
|
|
185
|
+
},
|
|
186
|
+
}),
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
: {}),
|
|
191
|
+
...(failFinish || failReceipt
|
|
192
|
+
? {
|
|
193
|
+
"./component/balanceFunding/internal/mutations.ts": async () => {
|
|
194
|
+
const modulePath = "./internal/mutations.ts";
|
|
195
|
+
const statePath = "./workflowState.ts";
|
|
196
|
+
const actual = await import(/* @vite-ignore */ modulePath);
|
|
197
|
+
const state = await import(/* @vite-ignore */ statePath);
|
|
198
|
+
return {
|
|
199
|
+
...actual,
|
|
200
|
+
recordProviderReceipt: internalMutationGeneric({
|
|
201
|
+
args: { ...phaseArgs, receipt: provisioningReceipt },
|
|
202
|
+
returns: v.null(),
|
|
203
|
+
handler: async (ctx, args) => {
|
|
204
|
+
if (
|
|
205
|
+
failReceipt &&
|
|
206
|
+
args.phase ===
|
|
207
|
+
(stopBeforeApplyRecord ? "apply" : "attach") &&
|
|
208
|
+
receiptAttempts++ < 2
|
|
209
|
+
)
|
|
210
|
+
throw new Error("controlled receipt-store outage");
|
|
211
|
+
return state.recordProviderReceiptHandler(ctx, args);
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
finishFromReceipts: internalMutationGeneric({
|
|
215
|
+
args: {
|
|
216
|
+
accountId: v.string(),
|
|
217
|
+
scopeKey: v.string(),
|
|
218
|
+
operationId: v.string(),
|
|
219
|
+
version: v.number(),
|
|
220
|
+
stripeSubscriptionId: v.string(),
|
|
221
|
+
providerApiVersion: v.string(),
|
|
222
|
+
definitionVersion: v.string(),
|
|
223
|
+
},
|
|
224
|
+
returns: v.null(),
|
|
225
|
+
handler: async (ctx, args) => {
|
|
226
|
+
if (failFinish && ++attempts === 1)
|
|
227
|
+
throw new Error("controlled receipt-finish outage");
|
|
228
|
+
return state.finishFromReceiptsHandler(ctx, args);
|
|
229
|
+
},
|
|
230
|
+
}),
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
}
|
|
234
|
+
: {}),
|
|
235
|
+
"./component/fundingWorkflowFixture.ts": async () => ({
|
|
236
|
+
status: internalQueryGeneric({
|
|
237
|
+
args: { id: v.string() },
|
|
238
|
+
returns: v.any(),
|
|
239
|
+
handler: (ctx, { id }) =>
|
|
240
|
+
executionWorkflow.status(ctx, id as WorkflowId),
|
|
241
|
+
}),
|
|
242
|
+
cleanup: internalMutationGeneric({
|
|
243
|
+
args: { id: v.string() },
|
|
244
|
+
returns: v.any(),
|
|
245
|
+
handler: (ctx, args) =>
|
|
246
|
+
executionWorkflow.cleanup(ctx, args.id as WorkflowId),
|
|
247
|
+
}),
|
|
248
|
+
history: internalQueryGeneric({
|
|
249
|
+
args: { id: v.string() },
|
|
250
|
+
returns: v.any(),
|
|
251
|
+
handler: (ctx, { id }) =>
|
|
252
|
+
executionWorkflow.listSteps(ctx, id as WorkflowId, {
|
|
253
|
+
paginationOpts: { cursor: null, numItems: 30 },
|
|
254
|
+
}),
|
|
255
|
+
}),
|
|
256
|
+
}),
|
|
257
|
+
});
|
|
258
|
+
workflowTest.register(t, "betterStripe/workflow");
|
|
259
|
+
return t;
|
|
260
|
+
}
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
vi.useFakeTimers();
|
|
263
|
+
const secret = "sk_test_funding_" + crypto.randomUUID();
|
|
264
|
+
vi.stubEnv("STRIPE_SECRET_KEY", secret);
|
|
265
|
+
requests = [];
|
|
266
|
+
methodOwner = null;
|
|
267
|
+
unknownPhase = null;
|
|
268
|
+
extraFields = false;
|
|
269
|
+
enabled = false;
|
|
270
|
+
lostApply = false;
|
|
271
|
+
checkpointFault = false;
|
|
272
|
+
cancelPhase = null;
|
|
273
|
+
const stripe = getStripeClient(secret, version);
|
|
274
|
+
(
|
|
275
|
+
stripe as unknown as {
|
|
276
|
+
_setApiField: (name: string, value: unknown) => void;
|
|
277
|
+
}
|
|
278
|
+
)._setApiField(
|
|
279
|
+
"httpClient",
|
|
280
|
+
Stripe.createFetchHttpClient(async (url, init) => {
|
|
281
|
+
const path = new URL(String(url)).pathname;
|
|
282
|
+
const method = init?.method ?? "GET";
|
|
283
|
+
const headers = new Headers(init?.headers);
|
|
284
|
+
requests.push({
|
|
285
|
+
method,
|
|
286
|
+
path,
|
|
287
|
+
version: headers.get("Stripe-Version"),
|
|
288
|
+
key: headers.get("Idempotency-Key"),
|
|
289
|
+
});
|
|
290
|
+
if (path.includes("subscriptions") && method === "POST") {
|
|
291
|
+
const body = new URLSearchParams(String(init?.body));
|
|
292
|
+
enabled = body.get("default_payment_method") === "pm_balance";
|
|
293
|
+
if (lostApply) {
|
|
294
|
+
lostApply = false;
|
|
295
|
+
throw new TypeError("private apply response");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (path.endsWith("/attach") && method === "POST")
|
|
299
|
+
methodOwner = scope.accountId;
|
|
300
|
+
if (
|
|
301
|
+
(unknownPhase === "create" &&
|
|
302
|
+
path === "/v1/payment_methods" &&
|
|
303
|
+
method === "POST") ||
|
|
304
|
+
(unknownPhase === "attach" &&
|
|
305
|
+
path.endsWith("/attach") &&
|
|
306
|
+
method === "POST")
|
|
307
|
+
) {
|
|
308
|
+
unknownPhase = null;
|
|
309
|
+
throw new TypeError("raw_provider_private_failure");
|
|
310
|
+
}
|
|
311
|
+
const body = path.includes("subscriptions")
|
|
312
|
+
? {
|
|
313
|
+
id: stripeSubscriptionId,
|
|
314
|
+
object: "subscription",
|
|
315
|
+
customer_account: scope.accountId,
|
|
316
|
+
status: "active",
|
|
317
|
+
default_payment_method: enabled ? "pm_balance" : "pm_card",
|
|
318
|
+
payment_settings: {
|
|
319
|
+
payment_method_types: [enabled ? "stripe_balance" : "card"],
|
|
320
|
+
},
|
|
321
|
+
}
|
|
322
|
+
: path.endsWith("/pm_card")
|
|
323
|
+
? {
|
|
324
|
+
id: "pm_card",
|
|
325
|
+
object: "payment_method",
|
|
326
|
+
type: "card",
|
|
327
|
+
customer_account: scope.accountId,
|
|
328
|
+
}
|
|
329
|
+
: {
|
|
330
|
+
id: "pm_balance",
|
|
331
|
+
object: "payment_method",
|
|
332
|
+
type: "stripe_balance",
|
|
333
|
+
customer_account: methodOwner,
|
|
334
|
+
};
|
|
335
|
+
return new Response(JSON.stringify(body), { status: 200 });
|
|
336
|
+
}),
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
afterEach(() => {
|
|
340
|
+
vi.useRealTimers();
|
|
341
|
+
vi.unstubAllEnvs();
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
export const fixture = {
|
|
345
|
+
set checkpointFault(value: boolean) {
|
|
346
|
+
checkpointFault = value;
|
|
347
|
+
},
|
|
348
|
+
set cancelPhase(value: "create" | "attach" | "apply" | null) {
|
|
349
|
+
cancelPhase = value;
|
|
350
|
+
},
|
|
351
|
+
get requests() {
|
|
352
|
+
return requests;
|
|
353
|
+
},
|
|
354
|
+
set unknownPhase(value: "create" | "attach" | null) {
|
|
355
|
+
unknownPhase = value;
|
|
356
|
+
},
|
|
357
|
+
set extraFields(value: boolean) {
|
|
358
|
+
extraFields = value;
|
|
359
|
+
},
|
|
360
|
+
set lostApply(value: boolean) {
|
|
361
|
+
lostApply = value;
|
|
362
|
+
},
|
|
363
|
+
get enabled() {
|
|
364
|
+
return enabled;
|
|
365
|
+
},
|
|
366
|
+
};
|