@fantastic.dev/better-stripe 0.34.0 → 0.37.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 +260 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +664 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +332 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +664 -2
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +332 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/refundCommandEvidence.d.ts +14 -0
- package/dist/client/connect/refundCommandEvidence.d.ts.map +1 -0
- package/dist/client/connect/refundCommandEvidence.js +20 -0
- package/dist/client/connect/refundCommandEvidence.js.map +1 -0
- package/dist/client/connect/refundCommandNormalization.d.ts +11 -0
- package/dist/client/connect/refundCommandNormalization.d.ts.map +1 -0
- package/dist/client/connect/refundCommandNormalization.js +12 -0
- package/dist/client/connect/refundCommandNormalization.js.map +1 -0
- package/dist/client/financialObservations.d.ts +42 -0
- package/dist/client/financialObservations.d.ts.map +1 -0
- package/dist/client/financialObservations.js +58 -0
- package/dist/client/financialObservations.js.map +1 -0
- package/dist/client/financialOwnership.d.ts +52 -0
- package/dist/client/financialOwnership.d.ts.map +1 -0
- package/dist/client/financialOwnership.js +72 -0
- package/dist/client/financialOwnership.js.map +1 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/observationPagination.d.ts +10 -0
- package/dist/client/observationPagination.d.ts.map +1 -0
- package/dist/client/observationPagination.js +12 -0
- package/dist/client/observationPagination.js.map +1 -0
- package/dist/client/operationEvidence.d.ts +37 -0
- package/dist/client/operationEvidence.d.ts.map +1 -0
- package/dist/client/operationEvidence.js +44 -0
- package/dist/client/operationEvidence.js.map +1 -0
- package/dist/client/publicTypes.d.ts +6 -0
- package/dist/client/publicTypes.d.ts.map +1 -1
- package/dist/client/readContracts.d.ts +31 -0
- package/dist/client/readContracts.d.ts.map +1 -1
- package/dist/client/readContracts.js +14 -0
- package/dist/client/readContracts.js.map +1 -1
- package/dist/client/transferObservations.d.ts +59 -0
- package/dist/client/transferObservations.d.ts.map +1 -0
- package/dist/client/transferObservations.js +82 -0
- package/dist/client/transferObservations.js.map +1 -0
- package/dist/component/_generated/component.d.ts +687 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/affiliateRecovery/mutations.d.ts.map +1 -1
- package/dist/component/affiliateRecovery/mutations.js +4 -1
- package/dist/component/affiliateRecovery/mutations.js.map +1 -1
- package/dist/component/connect/mutations.d.ts.map +1 -1
- package/dist/component/connect/mutations.js +18 -2
- package/dist/component/connect/mutations.js.map +1 -1
- package/dist/component/connect/queries.d.ts +8 -0
- package/dist/component/connect/queries.d.ts.map +1 -1
- package/dist/component/connect/reversalClaims.d.ts.map +1 -1
- package/dist/component/connect/reversalClaims.js +7 -1
- package/dist/component/connect/reversalClaims.js.map +1 -1
- package/dist/component/connect/reversalReceipts.d.ts.map +1 -1
- package/dist/component/connect/reversalReceipts.js +2 -0
- package/dist/component/connect/reversalReceipts.js.map +1 -1
- package/dist/component/connect/schema.d.ts +11 -1
- package/dist/component/connect/schema.d.ts.map +1 -1
- package/dist/component/connect/schema.js +9 -1
- package/dist/component/connect/schema.js.map +1 -1
- package/dist/component/connect/validators.d.ts +9 -1
- package/dist/component/connect/validators.d.ts.map +1 -1
- package/dist/component/connect/validators.js +2 -0
- package/dist/component/connect/validators.js.map +1 -1
- package/dist/component/earnings/pairedAdjustment.d.ts +12 -0
- package/dist/component/earnings/pairedAdjustment.d.ts.map +1 -0
- package/dist/component/earnings/pairedAdjustment.js +46 -0
- package/dist/component/earnings/pairedAdjustment.js.map +1 -0
- package/dist/component/earnings/triggers.d.ts +546 -2
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/earnings/triggers.js +17 -3
- package/dist/component/earnings/triggers.js.map +1 -1
- package/dist/component/financialObservations/continuation.d.ts +7 -0
- package/dist/component/financialObservations/continuation.d.ts.map +1 -0
- package/dist/component/financialObservations/continuation.js +131 -0
- package/dist/component/financialObservations/continuation.js.map +1 -0
- package/dist/component/financialObservations/generations.d.ts +6 -0
- package/dist/component/financialObservations/generations.d.ts.map +1 -0
- package/dist/component/financialObservations/generations.js +46 -0
- package/dist/component/financialObservations/generations.js.map +1 -0
- package/dist/component/financialObservations/mutations.d.ts +62 -0
- package/dist/component/financialObservations/mutations.d.ts.map +1 -0
- package/dist/component/financialObservations/mutations.js +69 -0
- package/dist/component/financialObservations/mutations.js.map +1 -0
- package/dist/component/financialObservations/queries.d.ts +307 -0
- package/dist/component/financialObservations/queries.d.ts.map +1 -0
- package/dist/component/financialObservations/queries.js +219 -0
- package/dist/component/financialObservations/queries.js.map +1 -0
- package/dist/component/financialObservations/schema.d.ts +182 -0
- package/dist/component/financialObservations/schema.d.ts.map +1 -0
- package/dist/component/financialObservations/schema.js +53 -0
- package/dist/component/financialObservations/schema.js.map +1 -0
- package/dist/component/financialObservations/settlement.d.ts +7 -0
- package/dist/component/financialObservations/settlement.d.ts.map +1 -0
- package/dist/component/financialObservations/settlement.js +118 -0
- package/dist/component/financialObservations/settlement.js.map +1 -0
- package/dist/component/financialObservations/settlementHelpers.d.ts +46 -0
- package/dist/component/financialObservations/settlementHelpers.d.ts.map +1 -0
- package/dist/component/financialObservations/settlementHelpers.js +70 -0
- package/dist/component/financialObservations/settlementHelpers.js.map +1 -0
- package/dist/component/financialObservations/transferBatches.d.ts +12 -0
- package/dist/component/financialObservations/transferBatches.d.ts.map +1 -0
- package/dist/component/financialObservations/transferBatches.js +76 -0
- package/dist/component/financialObservations/transferBatches.js.map +1 -0
- package/dist/component/financialObservations/transferContinuation.d.ts +5 -0
- package/dist/component/financialObservations/transferContinuation.d.ts.map +1 -0
- package/dist/component/financialObservations/transferContinuation.js +35 -0
- package/dist/component/financialObservations/transferContinuation.js.map +1 -0
- package/dist/component/financialObservations/transferContinuationState.d.ts +8 -0
- package/dist/component/financialObservations/transferContinuationState.d.ts.map +1 -0
- package/dist/component/financialObservations/transferContinuationState.js +69 -0
- package/dist/component/financialObservations/transferContinuationState.js.map +1 -0
- package/dist/component/financialObservations/transferContinuationSteps.d.ts +5 -0
- package/dist/component/financialObservations/transferContinuationSteps.d.ts.map +1 -0
- package/dist/component/financialObservations/transferContinuationSteps.js +174 -0
- package/dist/component/financialObservations/transferContinuationSteps.js.map +1 -0
- package/dist/component/financialObservations/transferHelpers.d.ts +18 -0
- package/dist/component/financialObservations/transferHelpers.d.ts.map +1 -0
- package/dist/component/financialObservations/transferHelpers.js +37 -0
- package/dist/component/financialObservations/transferHelpers.js.map +1 -0
- package/dist/component/financialObservations/transferReferenceSchema.d.ts +56 -0
- package/dist/component/financialObservations/transferReferenceSchema.d.ts.map +1 -0
- package/dist/component/financialObservations/transferReferenceSchema.js +21 -0
- package/dist/component/financialObservations/transferReferenceSchema.js.map +1 -0
- package/dist/component/financialObservations/transferSchema.d.ts +237 -0
- package/dist/component/financialObservations/transferSchema.d.ts.map +1 -0
- package/dist/component/financialObservations/transferSchema.js +65 -0
- package/dist/component/financialObservations/transferSchema.js.map +1 -0
- package/dist/component/financialObservations/transfers.d.ts +7 -0
- package/dist/component/financialObservations/transfers.d.ts.map +1 -0
- package/dist/component/financialObservations/transfers.js +79 -0
- package/dist/component/financialObservations/transfers.js.map +1 -0
- package/dist/component/financialOwnership/helpers.d.ts +37 -0
- package/dist/component/financialOwnership/helpers.d.ts.map +1 -0
- package/dist/component/financialOwnership/helpers.js +76 -0
- package/dist/component/financialOwnership/helpers.js.map +1 -0
- package/dist/component/financialOwnership/mutations.d.ts +28 -0
- package/dist/component/financialOwnership/mutations.d.ts.map +1 -0
- package/dist/component/financialOwnership/mutations.js +74 -0
- package/dist/component/financialOwnership/mutations.js.map +1 -0
- package/dist/component/financialOwnership/queries.d.ts +57 -0
- package/dist/component/financialOwnership/queries.d.ts.map +1 -0
- package/dist/component/financialOwnership/queries.js +50 -0
- package/dist/component/financialOwnership/queries.js.map +1 -0
- package/dist/component/financialOwnership/schema.d.ts +140 -0
- package/dist/component/financialOwnership/schema.d.ts.map +1 -0
- package/dist/component/financialOwnership/schema.js +35 -0
- package/dist/component/financialOwnership/schema.js.map +1 -0
- package/dist/component/operationEvidence/canonical.d.ts +4 -0
- package/dist/component/operationEvidence/canonical.d.ts.map +1 -0
- package/dist/component/operationEvidence/canonical.js +8 -0
- package/dist/component/operationEvidence/canonical.js.map +1 -0
- package/dist/component/operationEvidence/helpers.d.ts +87 -0
- package/dist/component/operationEvidence/helpers.d.ts.map +1 -0
- package/dist/component/operationEvidence/helpers.js +49 -0
- package/dist/component/operationEvidence/helpers.js.map +1 -0
- package/dist/component/operationEvidence/maintenance.d.ts +88 -0
- package/dist/component/operationEvidence/maintenance.d.ts.map +1 -0
- package/dist/component/operationEvidence/maintenance.js +59 -0
- package/dist/component/operationEvidence/maintenance.js.map +1 -0
- package/dist/component/operationEvidence/mutations.d.ts +97 -0
- package/dist/component/operationEvidence/mutations.d.ts.map +1 -0
- package/dist/component/operationEvidence/mutations.js +14 -0
- package/dist/component/operationEvidence/mutations.js.map +1 -0
- package/dist/component/operationEvidence/queries.d.ts +205 -0
- package/dist/component/operationEvidence/queries.d.ts.map +1 -0
- package/dist/component/operationEvidence/queries.js +75 -0
- package/dist/component/operationEvidence/queries.js.map +1 -0
- package/dist/component/operationEvidence/schema.d.ts +536 -0
- package/dist/component/operationEvidence/schema.d.ts.map +1 -0
- package/dist/component/operationEvidence/schema.js +53 -0
- package/dist/component/operationEvidence/schema.js.map +1 -0
- package/dist/component/refundHistory/commandBinding.d.ts +17 -0
- package/dist/component/refundHistory/commandBinding.d.ts.map +1 -0
- package/dist/component/refundHistory/commandBinding.js +41 -0
- package/dist/component/refundHistory/commandBinding.js.map +1 -0
- package/dist/component/refundHistory/commandEvidence.d.ts +50 -0
- package/dist/component/refundHistory/commandEvidence.d.ts.map +1 -0
- package/dist/component/refundHistory/commandEvidence.js +58 -0
- package/dist/component/refundHistory/commandEvidence.js.map +1 -0
- package/dist/component/refundHistory/commandEvidenceValidator.d.ts +89 -0
- package/dist/component/refundHistory/commandEvidenceValidator.d.ts.map +1 -0
- package/dist/component/refundHistory/commandEvidenceValidator.js +8 -0
- package/dist/component/refundHistory/commandEvidenceValidator.js.map +1 -0
- package/dist/component/refundHistory/commandFields.d.ts +8 -0
- package/dist/component/refundHistory/commandFields.d.ts.map +1 -0
- package/dist/component/refundHistory/commandFields.js +9 -0
- package/dist/component/refundHistory/commandFields.js.map +1 -0
- package/dist/component/refundHistory/mutations.d.ts +8 -0
- package/dist/component/refundHistory/mutations.d.ts.map +1 -0
- package/dist/component/refundHistory/mutations.js +25 -0
- package/dist/component/refundHistory/mutations.js.map +1 -0
- package/dist/component/refundHistory/originalSeller.d.ts +5 -0
- package/dist/component/refundHistory/originalSeller.d.ts.map +1 -0
- package/dist/component/refundHistory/originalSeller.js +35 -0
- package/dist/component/refundHistory/originalSeller.js.map +1 -0
- package/dist/component/refundHistory/queries.d.ts +51 -0
- package/dist/component/refundHistory/queries.d.ts.map +1 -1
- package/dist/component/refundHistory/queries.js +14 -0
- package/dist/component/refundHistory/queries.js.map +1 -1
- package/dist/component/schema.d.ts +332 -1
- package/dist/component/schema.js +15 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/settlement/mutations.d.ts.map +1 -1
- package/dist/component/settlement/mutations.js +5 -1
- package/dist/component/settlement/mutations.js.map +1 -1
- package/dist/shared/refundCommandScope.d.ts +10 -0
- package/dist/shared/refundCommandScope.d.ts.map +1 -0
- package/dist/shared/refundCommandScope.js +9 -0
- package/dist/shared/refundCommandScope.js.map +1 -0
- package/docs/financial-observations.md +244 -0
- package/docs/financial-ownership.md +54 -0
- package/docs/refund-command-evidence.md +55 -0
- package/package.json +5 -2
- package/src/client/connect/refundCommandEvidence.ts +41 -0
- package/src/client/connect/refundCommandNormalization.ts +28 -0
- package/src/client/financialObservations.test.ts +109 -0
- package/src/client/financialObservations.ts +106 -0
- package/src/client/financialOwnership.test.ts +80 -0
- package/src/client/financialOwnership.ts +116 -0
- package/src/client/index.ts +2 -2
- package/src/client/observationPagination.ts +11 -0
- package/src/client/operationEvidence.test.ts +110 -0
- package/src/client/operationEvidence.ts +92 -0
- package/src/client/publicTypes.ts +45 -0
- package/src/client/readContracts.ts +25 -0
- package/src/client/refund-command-evidence.test.ts +68 -0
- package/src/client/refund-command-normalization.test.ts +61 -0
- package/src/client/transferContinuation.test.ts +94 -0
- package/src/client/transferObservations.test.ts +98 -0
- package/src/client/transferObservations.ts +180 -0
- package/src/component/_generated/api.ts +54 -0
- package/src/component/_generated/component.ts +797 -0
- package/src/component/affiliateRecovery/mutations.ts +10 -1
- package/src/component/connect/mutations.ts +29 -2
- package/src/component/connect/reversalClaims.ts +19 -1
- package/src/component/connect/reversalReceipts.ts +2 -0
- package/src/component/connect/schema.ts +9 -1
- package/src/component/connect/validators.ts +2 -0
- package/src/component/core/reset.test.ts +8 -1
- package/src/component/earnings/earnings-totals.test.ts +14 -10
- package/src/component/earnings/paired-adjustment.test.ts +258 -0
- package/src/component/earnings/pairedAdjustment.ts +77 -0
- package/src/component/earnings/triggers.ts +23 -11
- package/src/component/financialObservations/continuation.test.ts +445 -0
- package/src/component/financialObservations/continuation.ts +159 -0
- package/src/component/financialObservations/generations.ts +53 -0
- package/src/component/financialObservations/mutations.ts +75 -0
- package/src/component/financialObservations/observation-boundaries.test.ts +466 -0
- package/src/component/financialObservations/queries.ts +246 -0
- package/src/component/financialObservations/schema.ts +68 -0
- package/src/component/financialObservations/settlement-observations.test.ts +86 -0
- package/src/component/financialObservations/settlement.ts +142 -0
- package/src/component/financialObservations/settlementHelpers.ts +92 -0
- package/src/component/financialObservations/transfer-batches.test.ts +61 -0
- package/src/component/financialObservations/transfer-boundaries.test.ts +116 -0
- package/src/component/financialObservations/transfer-continuation-guards.test.ts +428 -0
- package/src/component/financialObservations/transfer-continuation.test.ts +154 -0
- package/src/component/financialObservations/transfer-observations.test.ts +212 -0
- package/src/component/financialObservations/transfer-overflow.test.ts +181 -0
- package/src/component/financialObservations/transfer-writers.test.ts +162 -0
- package/src/component/financialObservations/transferBatches.ts +96 -0
- package/src/component/financialObservations/transferContinuation.ts +53 -0
- package/src/component/financialObservations/transferContinuationState.ts +85 -0
- package/src/component/financialObservations/transferContinuationSteps.ts +232 -0
- package/src/component/financialObservations/transferHelpers.ts +38 -0
- package/src/component/financialObservations/transferReferenceSchema.ts +20 -0
- package/src/component/financialObservations/transferSchema.ts +74 -0
- package/src/component/financialObservations/transfers.ts +99 -0
- package/src/component/financialOwnership/financial-ownership.test.ts +102 -0
- package/src/component/financialOwnership/helpers.ts +98 -0
- package/src/component/financialOwnership/mutations.ts +83 -0
- package/src/component/financialOwnership/ownership-boundaries.test.ts +308 -0
- package/src/component/financialOwnership/queries.ts +65 -0
- package/src/component/financialOwnership/schema.ts +35 -0
- package/src/component/operationEvidence/canonical.ts +10 -0
- package/src/component/operationEvidence/helpers.ts +65 -0
- package/src/component/operationEvidence/integrity.test.ts +257 -0
- package/src/component/operationEvidence/maintenance.test.ts +152 -0
- package/src/component/operationEvidence/maintenance.ts +89 -0
- package/src/component/operationEvidence/mutations.ts +14 -0
- package/src/component/operationEvidence/queries.ts +108 -0
- package/src/component/operationEvidence/reads.test.ts +140 -0
- package/src/component/operationEvidence/schema.ts +62 -0
- package/src/component/refundHistory/command-evidence.test.ts +288 -0
- package/src/component/refundHistory/command-normalization-resource.test.ts +77 -0
- package/src/component/refundHistory/command-normalization.test.ts +229 -0
- package/src/component/refundHistory/command-provenance.test.ts +59 -0
- package/src/component/refundHistory/commandBinding.ts +54 -0
- package/src/component/refundHistory/commandEvidence.ts +76 -0
- package/src/component/refundHistory/commandEvidenceValidator.ts +18 -0
- package/src/component/refundHistory/commandFields.ts +9 -0
- package/src/component/refundHistory/mutations.ts +33 -0
- package/src/component/refundHistory/original-seller-boundaries.test.ts +138 -0
- package/src/component/refundHistory/original-seller.test.ts +175 -0
- package/src/component/refundHistory/originalSeller.ts +48 -0
- package/src/component/refundHistory/queries.ts +15 -0
- package/src/component/schema.ts +28 -0
- package/src/component/settlement/mutations.ts +5 -1
- package/src/shared/refundCommandScope.ts +19 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { api } from "../_generated/api.js";
|
|
4
|
+
import { schema, modules } from "../../test.js";
|
|
5
|
+
|
|
6
|
+
const scope = {
|
|
7
|
+
commandKey: "dojo-refund:original_store_gap:v1",
|
|
8
|
+
accountId: "acct_original_store",
|
|
9
|
+
stripePaymentIntentId: "pi_original_split",
|
|
10
|
+
stripeChargeId: "ch_original_split",
|
|
11
|
+
currency: "usd",
|
|
12
|
+
};
|
|
13
|
+
const refund = {
|
|
14
|
+
stripeRefundId: "re_original_split",
|
|
15
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
16
|
+
stripeChargeId: scope.stripeChargeId,
|
|
17
|
+
amount: 50,
|
|
18
|
+
currency: "usd",
|
|
19
|
+
status: "pending" as const,
|
|
20
|
+
metadata: { betterStripeRefundCommand: scope.commandKey },
|
|
21
|
+
};
|
|
22
|
+
const payment = {
|
|
23
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
24
|
+
userId: "original_buyer",
|
|
25
|
+
accountId: "acct_original_buyer",
|
|
26
|
+
amount: 1000,
|
|
27
|
+
currency: "usd",
|
|
28
|
+
status: "succeeded" as const,
|
|
29
|
+
chargeType: "separate" as const,
|
|
30
|
+
splitRecipients: [
|
|
31
|
+
{
|
|
32
|
+
destinationAccountId: scope.accountId,
|
|
33
|
+
role: "store" as const,
|
|
34
|
+
amount: 700,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
destinationAccountId: "acct_affiliate",
|
|
38
|
+
role: "affiliate" as const,
|
|
39
|
+
amount: 300,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
const read = api.refundHistory.queries.getRefundCommandEvidence;
|
|
44
|
+
|
|
45
|
+
const allocation = {
|
|
46
|
+
sourceChargeId: scope.stripeChargeId,
|
|
47
|
+
paymentIntentId: scope.stripePaymentIntentId,
|
|
48
|
+
currency: scope.currency,
|
|
49
|
+
gross: 1000,
|
|
50
|
+
processingFee: 0,
|
|
51
|
+
platformNet: 0,
|
|
52
|
+
transfers: payment.splitRecipients,
|
|
53
|
+
};
|
|
54
|
+
it.each([false, true])(
|
|
55
|
+
"qualifies immutable original separate store, refund first=%s, without rewriting history",
|
|
56
|
+
async (isRefundFirst) => {
|
|
57
|
+
const t = convexTest(schema, modules);
|
|
58
|
+
if (isRefundFirst)
|
|
59
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
60
|
+
await t.mutation(api.connect.mutations.upsertPayment, payment);
|
|
61
|
+
await t.mutation(
|
|
62
|
+
api.settlement.mutations.reserveSettlementAllocation,
|
|
63
|
+
allocation,
|
|
64
|
+
);
|
|
65
|
+
if (!isRefundFirst)
|
|
66
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
67
|
+
const before = await t.run((ctx) => ctx.db.query("refunds").take(2));
|
|
68
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
69
|
+
status: "observed",
|
|
70
|
+
refund: { ...refund, accountId: scope.accountId },
|
|
71
|
+
});
|
|
72
|
+
expect(await t.run((ctx) => ctx.db.query("refunds").take(2))).toEqual(
|
|
73
|
+
before,
|
|
74
|
+
);
|
|
75
|
+
expect(before[0]?.accountId).toBeUndefined();
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
it("keeps original allocation authority after normal SAME-PI store reassignment and reserve replay", async () => {
|
|
79
|
+
const t = convexTest(schema, modules);
|
|
80
|
+
await t.mutation(api.connect.mutations.upsertPayment, payment);
|
|
81
|
+
const original = await t.mutation(
|
|
82
|
+
api.settlement.mutations.reserveSettlementAllocation,
|
|
83
|
+
allocation,
|
|
84
|
+
);
|
|
85
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
86
|
+
const changed = [
|
|
87
|
+
{
|
|
88
|
+
destinationAccountId: "acct_replacement",
|
|
89
|
+
role: "store" as const,
|
|
90
|
+
amount: 700,
|
|
91
|
+
},
|
|
92
|
+
payment.splitRecipients[1]!,
|
|
93
|
+
];
|
|
94
|
+
await t.mutation(api.connect.mutations.upsertPayment, {
|
|
95
|
+
...payment,
|
|
96
|
+
splitRecipients: changed,
|
|
97
|
+
});
|
|
98
|
+
expect(
|
|
99
|
+
await t.mutation(api.settlement.mutations.reserveSettlementAllocation, {
|
|
100
|
+
...allocation,
|
|
101
|
+
transfers: changed,
|
|
102
|
+
}),
|
|
103
|
+
).toEqual(original);
|
|
104
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
105
|
+
status: "observed",
|
|
106
|
+
refund: { accountId: scope.accountId },
|
|
107
|
+
});
|
|
108
|
+
expect(
|
|
109
|
+
await t.query(read, { ...scope, accountId: "acct_replacement" }),
|
|
110
|
+
).toMatchObject({ status: "unavailable" });
|
|
111
|
+
expect(
|
|
112
|
+
await t.query(read, { ...scope, accountId: "acct_affiliate" }),
|
|
113
|
+
).toMatchObject({ status: "unavailable" });
|
|
114
|
+
});
|
|
115
|
+
it.each([false, true])(
|
|
116
|
+
"holds payment-only ownerless legacy provenance, destination=%s",
|
|
117
|
+
async (isDestination) => {
|
|
118
|
+
const t = convexTest(schema, modules);
|
|
119
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
120
|
+
// Late raw history has no immutable capture allocation and no receipt owner.
|
|
121
|
+
await t.run((ctx) =>
|
|
122
|
+
ctx.db.insert(
|
|
123
|
+
"payments",
|
|
124
|
+
isDestination
|
|
125
|
+
? {
|
|
126
|
+
...payment,
|
|
127
|
+
chargeType: "destination",
|
|
128
|
+
splitRecipients: undefined,
|
|
129
|
+
destinationAccountId: scope.accountId,
|
|
130
|
+
}
|
|
131
|
+
: payment,
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
135
|
+
status: "unavailable",
|
|
136
|
+
reason: "scope_mismatch",
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
it("retains persisted destination-account parity", async () => {
|
|
141
|
+
const t = convexTest(schema, modules);
|
|
142
|
+
await t.mutation(api.connect.mutations.upsertPayment, {
|
|
143
|
+
...payment,
|
|
144
|
+
chargeType: "destination",
|
|
145
|
+
splitRecipients: [],
|
|
146
|
+
destinationAccountId: scope.accountId,
|
|
147
|
+
});
|
|
148
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
149
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
150
|
+
status: "observed",
|
|
151
|
+
refund: { accountId: scope.accountId },
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
it.each(["acct_foreign", ""])(
|
|
155
|
+
"never hides persisted conflicting account %s",
|
|
156
|
+
async (accountId) => {
|
|
157
|
+
const t = convexTest(schema, modules);
|
|
158
|
+
await t.mutation(
|
|
159
|
+
api.settlement.mutations.reserveSettlementAllocation,
|
|
160
|
+
allocation,
|
|
161
|
+
);
|
|
162
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
163
|
+
...refund,
|
|
164
|
+
accountId,
|
|
165
|
+
});
|
|
166
|
+
const before = await t.run((ctx) => ctx.db.query("refunds").take(1));
|
|
167
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
168
|
+
status: "unavailable",
|
|
169
|
+
reason: "scope_mismatch",
|
|
170
|
+
});
|
|
171
|
+
expect(await t.run((ctx) => ctx.db.query("refunds").take(1))).toEqual(
|
|
172
|
+
before,
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { QueryCtx } from "../_generated/server.js";
|
|
2
|
+
import type { Doc } from "../_generated/dataModel.js";
|
|
3
|
+
import type { RefundCommandScope } from "../../shared/refundCommandScope.js";
|
|
4
|
+
|
|
5
|
+
const account = (value: string) => /^acct_[A-Za-z0-9_]{1,128}$/.test(value);
|
|
6
|
+
|
|
7
|
+
/** Immutable allocation routing only. Observation does not authorize a refund. */
|
|
8
|
+
function seller(allocation: Doc<"settlementAllocations">): string | undefined {
|
|
9
|
+
const destinations = new Set<string>();
|
|
10
|
+
let store: string | undefined;
|
|
11
|
+
for (const recipient of allocation.transfers) {
|
|
12
|
+
if (
|
|
13
|
+
!account(recipient.destinationAccountId) ||
|
|
14
|
+
destinations.has(recipient.destinationAccountId) ||
|
|
15
|
+
!Number.isSafeInteger(recipient.amount) ||
|
|
16
|
+
recipient.amount < 0
|
|
17
|
+
)
|
|
18
|
+
return undefined;
|
|
19
|
+
destinations.add(recipient.destinationAccountId);
|
|
20
|
+
if (recipient.role === "store") {
|
|
21
|
+
if (store !== undefined) return undefined;
|
|
22
|
+
store = recipient.destinationAccountId;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return store;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** At most two exact-charge allocations; mutable payments never establish original ownership. */
|
|
29
|
+
export async function originalRefundSeller(
|
|
30
|
+
ctx: QueryCtx,
|
|
31
|
+
scope: RefundCommandScope,
|
|
32
|
+
): Promise<string | undefined> {
|
|
33
|
+
const allocations = await ctx.db
|
|
34
|
+
.query("settlementAllocations")
|
|
35
|
+
.withIndex("by_source_charge", (q) =>
|
|
36
|
+
q.eq("sourceChargeId", scope.stripeChargeId),
|
|
37
|
+
)
|
|
38
|
+
.take(2);
|
|
39
|
+
const allocation = allocations[0];
|
|
40
|
+
if (
|
|
41
|
+
allocations.length !== 1 ||
|
|
42
|
+
!allocation ||
|
|
43
|
+
allocation.paymentIntentId !== scope.stripePaymentIntentId ||
|
|
44
|
+
allocation.currency !== scope.currency
|
|
45
|
+
)
|
|
46
|
+
return undefined;
|
|
47
|
+
return seller(allocation);
|
|
48
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { refundCommandEvidenceValidator } from "./commandEvidenceValidator.js";
|
|
2
|
+
import { readRefundCommandEvidence } from "./commandEvidence.js";
|
|
1
3
|
import {
|
|
2
4
|
paginationOptsValidator,
|
|
3
5
|
paginationResultValidator,
|
|
@@ -97,3 +99,16 @@ function scopedRefunds(
|
|
|
97
99
|
return refunds.withIndex("by_status", (q) => q.eq("status", status));
|
|
98
100
|
return refunds;
|
|
99
101
|
}
|
|
102
|
+
|
|
103
|
+
/** Exact command evidence is read-only and never authorizes a provider retry. */
|
|
104
|
+
export const getRefundCommandEvidence = query({
|
|
105
|
+
args: {
|
|
106
|
+
commandKey: v.string(),
|
|
107
|
+
accountId: v.string(),
|
|
108
|
+
stripePaymentIntentId: v.string(),
|
|
109
|
+
stripeChargeId: v.string(),
|
|
110
|
+
currency: v.string(),
|
|
111
|
+
},
|
|
112
|
+
returns: refundCommandEvidenceValidator,
|
|
113
|
+
handler: readRefundCommandEvidence,
|
|
114
|
+
});
|
package/src/component/schema.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
payloadsTable as operationEvidencePayloads,
|
|
3
|
+
headersTable as operationEvidenceHeaders,
|
|
4
|
+
} from "./operationEvidence/schema.js";
|
|
5
|
+
import { transferBatchReferencesTable } from "./financialObservations/transferReferenceSchema.js";
|
|
6
|
+
import {
|
|
7
|
+
transferObservationsTable,
|
|
8
|
+
transferBatchesTable,
|
|
9
|
+
} from "./financialObservations/transferSchema.js";
|
|
10
|
+
import {
|
|
11
|
+
sourceObservationsTable,
|
|
12
|
+
sourceLegsTable,
|
|
13
|
+
observationGenerationsTable,
|
|
14
|
+
} from "./financialObservations/schema.js";
|
|
15
|
+
import {
|
|
16
|
+
ownershipTable,
|
|
17
|
+
generationsTable,
|
|
18
|
+
} from "./financialOwnership/schema.js";
|
|
1
19
|
import { accountClosuresTable } from "./accountClosure/schema.js";
|
|
2
20
|
import { jobsTable as payoutWorkerJobsTable } from "./payoutWorker/schema.js";
|
|
3
21
|
import {
|
|
@@ -60,6 +78,16 @@ import { pricesTable, productsTable } from "./products/schema";
|
|
|
60
78
|
import { webhookEventsTable } from "./webhooks/schema";
|
|
61
79
|
|
|
62
80
|
export default defineSchema({
|
|
81
|
+
operationEvidencePayloads,
|
|
82
|
+
operationEvidenceHeaders,
|
|
83
|
+
financialTransferObservations: transferObservationsTable,
|
|
84
|
+
financialTransferBatches: transferBatchesTable,
|
|
85
|
+
financialTransferBatchReferences: transferBatchReferencesTable,
|
|
86
|
+
financialSourceObservations: sourceObservationsTable,
|
|
87
|
+
financialSourceLegs: sourceLegsTable,
|
|
88
|
+
financialObservationGenerations: observationGenerationsTable,
|
|
89
|
+
financialOwnership: ownershipTable,
|
|
90
|
+
financialOwnershipGenerations: generationsTable,
|
|
63
91
|
payoutWorkerJobs: payoutWorkerJobsTable,
|
|
64
92
|
payoutFinancialRevisions: financialRevisionsTable,
|
|
65
93
|
payoutRiskEvents: riskEventsTable,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { observeSettlementAllocation } from "../financialObservations/settlement.js";
|
|
1
2
|
import { paginator } from "convex-helpers/server/pagination";
|
|
2
3
|
import schema from "../schema.js";
|
|
3
4
|
import { updateObligation } from "../affiliateRecovery/accounting.js";
|
|
@@ -28,6 +29,7 @@ export const reserveSettlementAllocation = mutation({
|
|
|
28
29
|
existing.sourceInvoiceId !== args.sourceInvoiceId
|
|
29
30
|
)
|
|
30
31
|
throw new Error("Settlement source identity cannot change.");
|
|
32
|
+
await observeSettlementAllocation(ctx, existing);
|
|
31
33
|
return existing;
|
|
32
34
|
}
|
|
33
35
|
const adjustment = args.adjustmentAmount ?? 0;
|
|
@@ -59,7 +61,9 @@ export const reserveSettlementAllocation = mutation({
|
|
|
59
61
|
"Settlement allocation must reconcile in integer currency units with unique recipient legs.",
|
|
60
62
|
);
|
|
61
63
|
const id = await ctx.db.insert("settlementAllocations", args);
|
|
62
|
-
|
|
64
|
+
const stored = (await ctx.db.get("settlementAllocations", id))!;
|
|
65
|
+
await observeSettlementAllocation(ctx, stored);
|
|
66
|
+
return stored;
|
|
63
67
|
},
|
|
64
68
|
});
|
|
65
69
|
export const claimCommissionInvoice = mutation({
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Canonical server-owned selectors. Shape validation is not host authorization or currency support. */
|
|
2
|
+
export type RefundCommandScope = {
|
|
3
|
+
commandKey: string;
|
|
4
|
+
accountId: string;
|
|
5
|
+
stripePaymentIntentId: string;
|
|
6
|
+
stripeChargeId: string;
|
|
7
|
+
currency: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function assertRefundCommandScope(input: RefundCommandScope): void {
|
|
11
|
+
if (
|
|
12
|
+
!/^[A-Za-z0-9:_-]{16,200}$/.test(input.commandKey) ||
|
|
13
|
+
!/^acct_[A-Za-z0-9_]{1,128}$/.test(input.accountId) ||
|
|
14
|
+
!/^pi_[A-Za-z0-9_]{1,252}$/.test(input.stripePaymentIntentId) ||
|
|
15
|
+
!/^ch_[A-Za-z0-9_]{1,252}$/.test(input.stripeChargeId) ||
|
|
16
|
+
!/^[a-z]{3}$/.test(input.currency)
|
|
17
|
+
)
|
|
18
|
+
throw new Error("Invalid refund command selectors");
|
|
19
|
+
}
|