@fantastic.dev/better-stripe 0.45.2 → 0.47.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 +36 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +46 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +39 -16
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +78 -32
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +23 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/refundSync.d.ts +32 -0
- package/dist/client/connect/refundSync.d.ts.map +1 -0
- package/dist/client/connect/refundSync.js +61 -0
- package/dist/client/connect/refundSync.js.map +1 -0
- package/dist/client/connect/refundSyncValidation.d.ts +16 -0
- package/dist/client/connect/refundSyncValidation.d.ts.map +1 -0
- package/dist/client/connect/refundSyncValidation.js +87 -0
- package/dist/client/connect/refundSyncValidation.js.map +1 -0
- package/dist/client/index.d.ts +54 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +10 -3
- package/dist/client/index.js.map +1 -1
- package/dist/client/types/triggers.d.ts +3 -2
- package/dist/client/types/triggers.d.ts.map +1 -1
- package/dist/client/webhooks/helpers.d.ts.map +1 -1
- package/dist/client/webhooks/helpers.js +1 -0
- package/dist/client/webhooks/helpers.js.map +1 -1
- package/dist/client/webhooks/refundReconciliation.d.ts +10 -0
- package/dist/client/webhooks/refundReconciliation.d.ts.map +1 -0
- package/dist/client/webhooks/refundReconciliation.js +41 -0
- package/dist/client/webhooks/refundReconciliation.js.map +1 -0
- package/dist/client/webhooks/refundReconciliationValidators.d.ts +68 -0
- package/dist/client/webhooks/refundReconciliationValidators.d.ts.map +1 -0
- package/dist/client/webhooks/refundReconciliationValidators.js +11 -0
- package/dist/client/webhooks/refundReconciliationValidators.js.map +1 -0
- package/dist/component/_generated/api.d.ts +12 -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 +67 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.d.ts +27 -27
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/connect/mutations.d.ts.map +1 -1
- package/dist/component/connect/mutations.js +2 -53
- package/dist/component/connect/mutations.js.map +1 -1
- package/dist/component/connect/refundWrites.d.ts +6 -0
- package/dist/component/connect/refundWrites.d.ts.map +1 -0
- package/dist/component/connect/refundWrites.js +56 -0
- package/dist/component/connect/refundWrites.js.map +1 -0
- package/dist/component/earnings/triggers.d.ts +46 -0
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/refundHistory/originalSeller.d.ts +1 -1
- package/dist/component/refundHistory/originalSeller.d.ts.map +1 -1
- package/dist/component/refundHistory/originalSeller.js.map +1 -1
- package/dist/component/refundSync/helpers.d.ts +43 -0
- package/dist/component/refundSync/helpers.d.ts.map +1 -0
- package/dist/component/refundSync/helpers.js +71 -0
- package/dist/component/refundSync/helpers.js.map +1 -0
- package/dist/component/refundSync/mutations.d.ts +56 -0
- package/dist/component/refundSync/mutations.d.ts.map +1 -0
- package/dist/component/refundSync/mutations.js +113 -0
- package/dist/component/refundSync/mutations.js.map +1 -0
- package/dist/component/refundSync/queries.d.ts +12 -0
- package/dist/component/refundSync/queries.d.ts.map +1 -0
- package/dist/component/refundSync/queries.js +10 -0
- package/dist/component/refundSync/queries.js.map +1 -0
- package/dist/component/refundSync/routing.d.ts +8 -0
- package/dist/component/refundSync/routing.d.ts.map +1 -0
- package/dist/component/refundSync/routing.js +42 -0
- package/dist/component/refundSync/routing.js.map +1 -0
- package/dist/component/refundSync/schema.d.ts +25 -0
- package/dist/component/refundSync/schema.d.ts.map +1 -0
- package/dist/component/refundSync/schema.js +15 -0
- package/dist/component/refundSync/schema.js.map +1 -0
- package/dist/component/refundSync/validators.d.ts +164 -0
- package/dist/component/refundSync/validators.d.ts.map +1 -0
- package/dist/component/refundSync/validators.js +32 -0
- package/dist/component/refundSync/validators.js.map +1 -0
- package/dist/component/schema.d.ts +23 -0
- package/dist/component/schema.js +2 -0
- package/dist/component/schema.js.map +1 -1
- package/docs/refund-context.md +82 -0
- package/package.json +1 -1
- package/src/client/connect/refundSync.test.ts +239 -0
- package/src/client/connect/refundSync.transport.test.ts +396 -0
- package/src/client/connect/refundSync.ts +125 -0
- package/src/client/connect/refundSyncValidation.ts +120 -0
- package/src/client/index.ts +34 -6
- package/src/client/types/triggers.ts +3 -1
- package/src/client/webhooks/helpers.ts +1 -0
- package/src/client/webhooks/refund-reconciliation.test.ts +320 -0
- package/src/client/webhooks/refundReconciliation.ts +80 -0
- package/src/client/webhooks/refundReconciliationValidators.ts +15 -0
- package/src/component/_generated/api.ts +12 -0
- package/src/component/_generated/component.ts +100 -0
- package/src/component/connect/mutations.ts +2 -67
- package/src/component/connect/refundWrites.ts +76 -0
- package/src/component/refundHistory/originalSeller.ts +4 -1
- package/src/component/refundSync/helpers.ts +99 -0
- package/src/component/refundSync/mutations.ts +131 -0
- package/src/component/refundSync/queries.ts +10 -0
- package/src/component/refundSync/refund-sync.test.ts +255 -0
- package/src/component/refundSync/routing.ts +55 -0
- package/src/component/refundSync/schema.ts +19 -0
- package/src/component/refundSync/validators.ts +35 -0
- package/src/component/schema.ts +2 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Infer } from "convex/values";
|
|
2
|
+
import type { QueryCtx, MutationCtx } from "../_generated/server.js";
|
|
3
|
+
import { originalRefundSeller } from "../refundHistory/originalSeller.js";
|
|
4
|
+
import { refundById } from "./helpers.js";
|
|
5
|
+
import type { routingInput, routingResult } from "./validators.js";
|
|
6
|
+
|
|
7
|
+
/** Unknown attribution cannot silently inherit a mutable payment's current destination. */
|
|
8
|
+
export async function refundRouting(
|
|
9
|
+
ctx: QueryCtx | MutationCtx,
|
|
10
|
+
input: { [K in keyof typeof routingInput]: Infer<(typeof routingInput)[K]> },
|
|
11
|
+
): Promise<Infer<typeof routingResult>> {
|
|
12
|
+
const existing = await refundById(ctx, input.stripeRefundId);
|
|
13
|
+
const allocations = await ctx.db
|
|
14
|
+
.query("settlementAllocations")
|
|
15
|
+
.withIndex("by_source_charge", (q) =>
|
|
16
|
+
q.eq("sourceChargeId", input.stripeChargeId),
|
|
17
|
+
)
|
|
18
|
+
.take(2);
|
|
19
|
+
const merchant = await originalRefundSeller(ctx, input);
|
|
20
|
+
const payments = await ctx.db
|
|
21
|
+
.query("payments")
|
|
22
|
+
.withIndex("by_stripe_payment_intent_id", (q) =>
|
|
23
|
+
q.eq("stripePaymentIntentId", input.stripePaymentIntentId),
|
|
24
|
+
)
|
|
25
|
+
.take(2);
|
|
26
|
+
if (
|
|
27
|
+
payments.length > 1 ||
|
|
28
|
+
(payments[0] !== undefined && payments[0].currency !== input.currency) ||
|
|
29
|
+
(allocations.length > 0 && !merchant) ||
|
|
30
|
+
(existing?.accountId !== undefined &&
|
|
31
|
+
!/^acct_[A-Za-z0-9_]{1,250}$/.test(existing.accountId)) ||
|
|
32
|
+
(merchant &&
|
|
33
|
+
existing?.accountId !== undefined &&
|
|
34
|
+
merchant !== existing.accountId)
|
|
35
|
+
)
|
|
36
|
+
return {
|
|
37
|
+
status: "held",
|
|
38
|
+
merchantAccount: null,
|
|
39
|
+
requiresChargeProof: false,
|
|
40
|
+
};
|
|
41
|
+
if (merchant)
|
|
42
|
+
return {
|
|
43
|
+
status: "known",
|
|
44
|
+
merchantAccount: merchant,
|
|
45
|
+
requiresChargeProof: false,
|
|
46
|
+
};
|
|
47
|
+
const payment = payments[0];
|
|
48
|
+
const fallback = payment?.destinationAccountId;
|
|
49
|
+
return {
|
|
50
|
+
status: "unknown",
|
|
51
|
+
merchantAccount: null,
|
|
52
|
+
requiresChargeProof:
|
|
53
|
+
existing?.accountId !== undefined || fallback !== undefined,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
|
|
4
|
+
/** Observation claims only; refunds and payment aggregates remain in existing tables. */
|
|
5
|
+
export const claimsTable = defineTable({
|
|
6
|
+
stripeRefundId: v.string(),
|
|
7
|
+
requestedContext: v.string(),
|
|
8
|
+
generation: v.number(),
|
|
9
|
+
status: v.union(
|
|
10
|
+
v.literal("pending"),
|
|
11
|
+
v.literal("accepted"),
|
|
12
|
+
v.literal("unknown"),
|
|
13
|
+
),
|
|
14
|
+
startedAt: v.number(),
|
|
15
|
+
acceptedContext: v.optional(v.string()),
|
|
16
|
+
acceptedGeneration: v.optional(v.number()),
|
|
17
|
+
acceptedAt: v.optional(v.number()),
|
|
18
|
+
acceptedFingerprint: v.optional(v.string()),
|
|
19
|
+
}).index("by_stripe_refund_id", ["stripeRefundId"]);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { refundFields, refundDocValidator } from "../connect/validators.js";
|
|
3
|
+
|
|
4
|
+
export const identity = { stripeRefundId: v.string(), apiContext: v.string() };
|
|
5
|
+
export const snapshot = v.object({
|
|
6
|
+
...refundFields,
|
|
7
|
+
stripePaymentIntentId: v.string(),
|
|
8
|
+
stripeChargeId: v.string(),
|
|
9
|
+
metadata: v.optional(v.record(v.string(), v.string())),
|
|
10
|
+
});
|
|
11
|
+
export const prepared = {
|
|
12
|
+
...identity,
|
|
13
|
+
generation: v.number(),
|
|
14
|
+
refund: snapshot,
|
|
15
|
+
};
|
|
16
|
+
export const result = v.union(
|
|
17
|
+
v.object({
|
|
18
|
+
status: v.literal("accepted"),
|
|
19
|
+
generation: v.number(),
|
|
20
|
+
changed: v.boolean(),
|
|
21
|
+
refund: refundDocValidator,
|
|
22
|
+
}),
|
|
23
|
+
v.object({ status: v.literal("superseded"), generation: v.number() }),
|
|
24
|
+
);
|
|
25
|
+
export const routingInput = {
|
|
26
|
+
stripeRefundId: v.string(),
|
|
27
|
+
stripePaymentIntentId: v.string(),
|
|
28
|
+
stripeChargeId: v.string(),
|
|
29
|
+
currency: v.string(),
|
|
30
|
+
};
|
|
31
|
+
export const routingResult = v.object({
|
|
32
|
+
status: v.union(v.literal("known"), v.literal("unknown"), v.literal("held")),
|
|
33
|
+
merchantAccount: v.union(v.string(), v.null()),
|
|
34
|
+
requiresChargeProof: v.boolean(),
|
|
35
|
+
});
|
package/src/component/schema.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { claimsTable as refundSyncClaimsTable } from "./refundSync/schema.js";
|
|
1
2
|
import { operationsTable as processingCostReconciliationOperations } from "./processingCostReconciliation/schema.js";
|
|
2
3
|
import {
|
|
3
4
|
operationsTable as recoveryWorkflowOperations,
|
|
@@ -88,6 +89,7 @@ import { pricesTable, productsTable } from "./products/schema";
|
|
|
88
89
|
import { webhookEventsTable } from "./webhooks/schema";
|
|
89
90
|
|
|
90
91
|
export default defineSchema({
|
|
92
|
+
refundSyncClaims: refundSyncClaimsTable,
|
|
91
93
|
processingCostReconciliationOperations,
|
|
92
94
|
recoveryWorkflowOperations,
|
|
93
95
|
recoveryWorkflowRequests,
|