@openlup/platform 0.22.0 → 0.24.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 +440 -158
- package/README.md +141 -589
- package/dist/fulfillment/adapterConformance.js +1 -1
- package/dist/fulfillment/bindings.js +1 -1
- package/dist/fulfillment/contracts/conformance.d.ts +3 -1
- package/dist/fulfillment/contracts/dispatch.d.ts +45 -3
- package/dist/fulfillment/contracts/index.d.ts +3 -3
- package/dist/fulfillment/contracts/observation.d.ts +21 -1
- package/dist/fulfillment/contracts/readback.d.ts +21 -0
- package/dist/fulfillment/contracts/store.d.ts +3 -0
- package/dist/fulfillment/contracts/sync.d.ts +58 -2
- package/dist/fulfillment/dispatchProjection.d.ts +20 -1
- package/dist/fulfillment/dispatchProjection.js +97 -6
- package/dist/fulfillment/index.d.ts +3 -2
- package/dist/fulfillment/index.js +2 -2
- package/dist/fulfillment/migrations.d.ts +5 -0
- package/dist/fulfillment/migrations.js +1 -0
- package/dist/fulfillment/observationProjection.d.ts +24 -3
- package/dist/fulfillment/observationProjection.js +65 -12
- package/dist/fulfillment/omnipack/client.d.ts +3 -1
- package/dist/fulfillment/omnipack/client.js +31 -13
- package/dist/fulfillment/omnipack/index.d.ts +4 -1
- package/dist/fulfillment/omnipack/index.js +107 -45
- package/dist/fulfillment/omnipack/mappers.d.ts +7 -1
- package/dist/fulfillment/omnipack/mappers.js +24 -2
- package/dist/fulfillment/omnipack/observation.d.ts +11 -4
- package/dist/fulfillment/omnipack/observation.js +44 -29
- package/dist/fulfillment/omnipack/reconciliation.d.ts +15 -0
- package/dist/fulfillment/omnipack/reconciliation.js +55 -0
- package/dist/fulfillment/postgresDispatchStore.js +1 -1
- package/dist/fulfillment/postgresShipmentSpine.d.ts +8 -1
- package/dist/fulfillment/postgresShipmentSpine.js +17 -3
- package/dist/fulfillment/postgresStockSyncPort.js +6 -3
- package/dist/fulfillment/providerDispatchAcceptance.d.ts +1 -0
- package/dist/fulfillment/providerDispatchAcceptance.js +8 -2
- package/dist/fulfillment/providerDispatchWorker.d.ts +51 -0
- package/dist/fulfillment/providerDispatchWorker.js +65 -20
- package/dist/fulfillment/providerReconciliationWorker.d.ts +27 -19
- package/dist/fulfillment/providerReconciliationWorker.js +75 -19
- package/dist/fulfillment/providerStockSyncWorker.d.ts +5 -1
- package/dist/fulfillment/providerStockSyncWorker.js +229 -120
- package/dist/fulfillment/providerTrackingReferences.d.ts +3 -2
- package/dist/fulfillment/verifiedIngress.d.ts +38 -11
- package/dist/fulfillment/verifiedIngress.js +36 -8
- package/dist/invoicing/accountingCanonicalProviderLines.d.ts +5 -0
- package/dist/invoicing/accountingCanonicalProviderLines.js +104 -0
- package/dist/invoicing/accountingLineAllocation.d.ts +2 -0
- package/dist/invoicing/accountingLineAllocation.js +69 -0
- package/dist/invoicing/adapterConformance.d.ts +42 -0
- package/dist/invoicing/adapterConformance.js +296 -0
- package/dist/invoicing/artifacts.d.ts +7 -0
- package/dist/invoicing/artifacts.js +20 -0
- package/dist/invoicing/bindings.d.ts +46 -0
- package/dist/invoicing/bindings.js +69 -0
- package/dist/invoicing/capabilities.d.ts +11 -0
- package/dist/invoicing/capabilities.js +10 -0
- package/dist/invoicing/channelPolicy.d.ts +28 -0
- package/dist/invoicing/channelPolicy.js +27 -0
- package/dist/invoicing/continuity.d.ts +12 -0
- package/dist/invoicing/continuity.js +18 -0
- package/dist/invoicing/contracts/capabilities.d.ts +40 -0
- package/dist/invoicing/contracts/capabilities.js +1 -0
- package/dist/invoicing/contracts/companyLookup.d.ts +49 -0
- package/dist/invoicing/contracts/companyLookup.js +1 -0
- package/dist/invoicing/contracts/delivery.d.ts +74 -0
- package/dist/invoicing/contracts/delivery.js +1 -0
- package/dist/invoicing/contracts/facts.d.ts +110 -0
- package/dist/invoicing/contracts/facts.js +1 -0
- package/dist/invoicing/contracts/host.d.ts +245 -0
- package/dist/invoicing/contracts/host.js +1 -0
- package/dist/invoicing/contracts/index.d.ts +16 -0
- package/dist/invoicing/contracts/index.js +1 -0
- package/dist/invoicing/contracts/provider.d.ts +126 -0
- package/dist/invoicing/contracts/provider.js +1 -0
- package/dist/invoicing/contracts/settlement.d.ts +66 -0
- package/dist/invoicing/contracts/settlement.js +1 -0
- package/dist/invoicing/contracts/store.d.ts +277 -0
- package/dist/invoicing/contracts/store.js +1 -0
- package/dist/invoicing/contribution.d.ts +21 -0
- package/dist/invoicing/contribution.js +19 -0
- package/dist/invoicing/correction.d.ts +42 -0
- package/dist/invoicing/correction.js +44 -0
- package/dist/invoicing/delivery.d.ts +85 -0
- package/dist/invoicing/delivery.js +79 -0
- package/dist/invoicing/documentHistory.d.ts +50 -0
- package/dist/invoicing/documentHistory.js +213 -0
- package/dist/invoicing/documentSync.d.ts +24 -0
- package/dist/invoicing/documentSync.js +26 -0
- package/dist/invoicing/dutyCollector.d.ts +15 -0
- package/dist/invoicing/dutyCollector.js +35 -0
- package/dist/invoicing/fulfillmentTrigger.d.ts +56 -0
- package/dist/invoicing/fulfillmentTrigger.js +90 -0
- package/dist/invoicing/handoff.d.ts +37 -0
- package/dist/invoicing/handoff.js +62 -0
- package/dist/invoicing/index.d.ts +39 -0
- package/dist/invoicing/index.js +37 -0
- package/dist/invoicing/issue.d.ts +39 -0
- package/dist/invoicing/issue.js +55 -0
- package/dist/invoicing/migrations.d.ts +48 -0
- package/dist/invoicing/migrations.js +25 -0
- package/dist/invoicing/nativeUnsupported.d.ts +9 -0
- package/dist/invoicing/nativeUnsupported.js +22 -0
- package/dist/invoicing/paymentReadback.d.ts +20 -0
- package/dist/invoicing/paymentReadback.js +47 -0
- package/dist/invoicing/postgresInvoiceStore.d.ts +55 -0
- package/dist/invoicing/postgresInvoiceStore.js +344 -0
- package/dist/invoicing/readModel.d.ts +74 -0
- package/dist/invoicing/readModel.js +90 -0
- package/dist/invoicing/readback.d.ts +4 -0
- package/dist/invoicing/readback.js +30 -0
- package/dist/invoicing/reversal.d.ts +37 -0
- package/dist/invoicing/reversal.js +28 -0
- package/dist/invoicing/sellerRevision.d.ts +19 -0
- package/dist/invoicing/sellerRevision.js +14 -0
- package/dist/invoicing/settlementSync.d.ts +18 -0
- package/dist/invoicing/settlementSync.js +32 -0
- package/dist/invoicing/snapshot.d.ts +52 -0
- package/dist/invoicing/snapshot.js +141 -0
- package/dist/subscriptions/automaticRenewal.d.ts +44 -0
- package/dist/subscriptions/automaticRenewal.js +81 -0
- package/dist/subscriptions/automaticRenewalExecution.d.ts +21 -0
- package/dist/subscriptions/automaticRenewalExecution.js +44 -0
- package/dist/subscriptions/contracts/commands.d.ts +115 -0
- package/dist/subscriptions/contracts/commands.js +1 -0
- package/dist/subscriptions/contracts/dunning.d.ts +133 -0
- package/dist/subscriptions/contracts/dunning.js +1 -0
- package/dist/subscriptions/contracts/index.d.ts +6 -0
- package/dist/subscriptions/contracts/index.js +1 -0
- package/dist/subscriptions/contracts/messages.d.ts +43 -0
- package/dist/subscriptions/contracts/messages.js +1 -0
- package/dist/subscriptions/contracts/renewal.d.ts +533 -0
- package/dist/subscriptions/contracts/renewal.js +1 -0
- package/dist/subscriptions/contracts/stockWait.d.ts +73 -0
- package/dist/subscriptions/contracts/stockWait.js +1 -0
- package/dist/subscriptions/index.d.ts +39 -0
- package/dist/subscriptions/index.js +17 -0
- package/dist/subscriptions/paymentOutcomes.d.ts +8 -0
- package/dist/subscriptions/paymentOutcomes.js +27 -0
- package/dist/subscriptions/postgresRenewalStore.d.ts +20 -0
- package/dist/subscriptions/postgresRenewalStore.js +61 -0
- package/dist/subscriptions/postgresRetryStore.d.ts +78 -0
- package/dist/subscriptions/postgresRetryStore.js +142 -0
- package/dist/subscriptions/renewalCycleFailureMechanism.d.ts +34 -0
- package/dist/subscriptions/renewalCycleFailureMechanism.js +79 -0
- package/dist/subscriptions/renewalCycleMechanism.d.ts +46 -0
- package/dist/subscriptions/renewalCycleMechanism.js +157 -0
- package/dist/subscriptions/renewalCycleRefusalMechanism.d.ts +41 -0
- package/dist/subscriptions/renewalCycleRefusalMechanism.js +160 -0
- package/dist/subscriptions/renewalIdentity.d.ts +3 -0
- package/dist/subscriptions/renewalIdentity.js +4 -0
- package/package.json +23 -3
- package/release-gates.json +74 -7
- package/sql/20260809210000_accounting_document_rail.sql +889 -0
- package/sql/20260811150000_accounting_payout_rail.sql +333 -0
- package/sql/20260812130000_accounting_document_lifecycle_rail.sql +460 -0
- package/sql/20261022160000_subscription_retry_lifecycle.sql +328 -0
- package/sql/20261022165000_fulfillment_stock_evidence_replay_reopen.sql +30 -0
- package/sql/20261022190000_invoicing_durable_duties.sql +494 -0
- package/sql/20261022191000_invoicing_document_effects.sql +249 -0
- package/sql/20261022192000_invoicing_payment_decoupling.sql +144 -0
- package/sql/20261022195000_invoicing_seller_revision.sql +65 -0
- package/src/fulfillment/adapterConformance.ts +1 -1
- package/src/fulfillment/bindings.ts +1 -1
- package/src/fulfillment/contracts/conformance.ts +3 -1
- package/src/fulfillment/contracts/dispatch.ts +24 -5
- package/src/fulfillment/contracts/index.ts +3 -3
- package/src/fulfillment/contracts/observation.ts +11 -3
- package/src/fulfillment/contracts/readback.ts +13 -0
- package/src/fulfillment/contracts/store.ts +1 -0
- package/src/fulfillment/contracts/sync.ts +13 -2
- package/src/fulfillment/dispatchProjection.ts +94 -7
- package/src/fulfillment/index.ts +3 -2
- package/src/fulfillment/migrations.ts +1 -0
- package/src/fulfillment/observationProjection.ts +64 -13
- package/src/fulfillment/omnipack/client.ts +32 -13
- package/src/fulfillment/omnipack/index.ts +99 -39
- package/src/fulfillment/omnipack/mappers.ts +23 -2
- package/src/fulfillment/omnipack/observation.ts +45 -27
- package/src/fulfillment/omnipack/reconciliation.ts +56 -0
- package/src/fulfillment/postgresDispatchStore.ts +1 -1
- package/src/fulfillment/postgresShipmentSpine.ts +21 -4
- package/src/fulfillment/postgresStockSyncPort.ts +6 -3
- package/src/fulfillment/providerDispatchAcceptance.ts +9 -3
- package/src/fulfillment/providerDispatchWorker.ts +61 -20
- package/src/fulfillment/providerReconciliationWorker.ts +81 -25
- package/src/fulfillment/providerStockSyncWorker.ts +222 -126
- package/src/fulfillment/providerTrackingReferences.ts +3 -2
- package/src/fulfillment/verifiedIngress.ts +44 -11
- package/src/invoicing/accountingCanonicalProviderLines.ts +134 -0
- package/src/invoicing/accountingLineAllocation.ts +69 -0
- package/src/invoicing/adapterConformance.ts +249 -0
- package/src/invoicing/artifacts.ts +19 -0
- package/src/invoicing/bindings.ts +80 -0
- package/src/invoicing/capabilities.ts +9 -0
- package/src/invoicing/channelPolicy.ts +50 -0
- package/src/invoicing/continuity.ts +15 -0
- package/src/invoicing/contracts/capabilities.ts +15 -0
- package/src/invoicing/contracts/companyLookup.ts +13 -0
- package/src/invoicing/contracts/delivery.ts +24 -0
- package/src/invoicing/contracts/facts.ts +71 -0
- package/src/invoicing/contracts/host.ts +84 -0
- package/src/invoicing/contracts/index.ts +16 -0
- package/src/invoicing/contracts/provider.ts +78 -0
- package/src/invoicing/contracts/settlement.ts +39 -0
- package/src/invoicing/contracts/store.ts +102 -0
- package/src/invoicing/contribution.ts +28 -0
- package/src/invoicing/correction.ts +56 -0
- package/src/invoicing/delivery.ts +122 -0
- package/src/invoicing/documentHistory.ts +301 -0
- package/src/invoicing/documentSync.ts +51 -0
- package/src/invoicing/dutyCollector.ts +31 -0
- package/src/invoicing/fulfillmentTrigger.ts +144 -0
- package/src/invoicing/handoff.ts +71 -0
- package/src/invoicing/index.ts +39 -0
- package/src/invoicing/issue.ts +64 -0
- package/src/invoicing/migrations.ts +25 -0
- package/src/invoicing/nativeUnsupported.ts +24 -0
- package/src/invoicing/paymentReadback.ts +70 -0
- package/src/invoicing/postgresInvoiceStore.ts +334 -0
- package/src/invoicing/readModel.ts +80 -0
- package/src/invoicing/readback.ts +26 -0
- package/src/invoicing/reversal.ts +34 -0
- package/src/invoicing/sellerRevision.ts +20 -0
- package/src/invoicing/settlementSync.ts +37 -0
- package/src/invoicing/snapshot.ts +192 -0
- package/src/subscriptions/automaticRenewal.ts +87 -0
- package/src/subscriptions/automaticRenewalExecution.ts +39 -0
- package/src/subscriptions/contracts/commands.ts +46 -0
- package/src/subscriptions/contracts/dunning.ts +48 -0
- package/src/subscriptions/contracts/index.ts +6 -0
- package/src/subscriptions/contracts/messages.ts +18 -0
- package/src/subscriptions/contracts/renewal.ts +325 -0
- package/src/subscriptions/contracts/stockWait.ts +34 -0
- package/src/subscriptions/index.ts +24 -0
- package/src/subscriptions/paymentOutcomes.ts +23 -0
- package/src/subscriptions/postgresRenewalStore.ts +76 -0
- package/src/subscriptions/postgresRetryStore.ts +174 -0
- package/src/subscriptions/renewalCycleFailureMechanism.ts +119 -0
- package/src/subscriptions/renewalCycleMechanism.ts +225 -0
- package/src/subscriptions/renewalCycleRefusalMechanism.ts +215 -0
- package/src/subscriptions/renewalIdentity.ts +5 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { PaymentAttemptStatus, PaymentExecutionProviderDecline, ProviderAttemptIdentity } from "@openlup/core/payment";
|
|
2
|
+
import type {
|
|
3
|
+
HostedRenewalDue, SubscriptionRenewalChargeResult, SubscriptionCycleSnapshotResult,
|
|
4
|
+
SubscriptionCycleOrderResult, RenewalIntentResult, RenewalPreflightDeps,
|
|
5
|
+
RenewalFailureDeps, RenewalOutcomeContext, RenewalReplayContext, FailurePropagationResult,
|
|
6
|
+
} from "./contracts/renewal.js";
|
|
7
|
+
import { propagateRenewalFailure, type RenewalFailurePolicy } from "./renewalCycleFailureMechanism.js";
|
|
8
|
+
|
|
9
|
+
export interface RenewalPreflightPolicy<D extends HostedRenewalDue, CI, IR extends RenewalIntentResult> {
|
|
10
|
+
isOperatorOnly(reason: string): boolean;
|
|
11
|
+
logOperatorBlock(fields: { subscriptionId: string; providerKind: string; reason: string }): void;
|
|
12
|
+
readTotal(snapshot: Record<string, unknown>): number | null;
|
|
13
|
+
cycleKey(due: D): string;
|
|
14
|
+
executionKey(cycleKey: string, retry: number, sequence: number): string;
|
|
15
|
+
intentInput(due: D, key: string, snapshots: SubscriptionCycleSnapshotResult, order: SubscriptionCycleOrderResult, total: number, reason: string): CI;
|
|
16
|
+
identity(due: D, key: string, intent: IR, order: SubscriptionCycleOrderResult, total: number): ProviderAttemptIdentity;
|
|
17
|
+
normalizedProvider(provider: string): string;
|
|
18
|
+
failed(due: D, cycleId: string | null, cycleNumber: number | null, orderId: string | null, intentId: string | null, reason: string, propagation?: FailurePropagationResult): SubscriptionRenewalChargeResult;
|
|
19
|
+
invalidTotalsReason: string;
|
|
20
|
+
defaultNow(): string;
|
|
21
|
+
failure: RenewalFailurePolicy;
|
|
22
|
+
}
|
|
23
|
+
export interface RenewalOutcomePolicy {
|
|
24
|
+
declineReason(decline: PaymentExecutionProviderDecline): string;
|
|
25
|
+
classifyDecline(decline: PaymentExecutionProviderDecline): { failureClass: string; decidedBy: string };
|
|
26
|
+
scaReason: string;
|
|
27
|
+
defaultNow(): string;
|
|
28
|
+
failure: RenewalFailurePolicy;
|
|
29
|
+
}
|
|
30
|
+
export interface RenewalReplayPolicy extends Pick<RenewalOutcomePolicy, "scaReason" | "defaultNow" | "failure"> {
|
|
31
|
+
unacknowledgedReason(status: PaymentAttemptStatus): string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Alternate preflight owns its full order/intent/failure chain, without reservation or dispatch. */
|
|
35
|
+
export async function recordRenewalPreflightBlock<D extends HostedRenewalDue, CI,
|
|
36
|
+
IR extends RenewalIntentResult, M extends string | null | undefined>(
|
|
37
|
+
deps: RenewalPreflightDeps<CI, IR, M>, due: D, reason: string,
|
|
38
|
+
policy: RenewalPreflightPolicy<D, CI, IR>,
|
|
39
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
40
|
+
if (policy.isOperatorOnly(reason)) {
|
|
41
|
+
policy.logOperatorBlock({ subscriptionId: due.subscriptionId, providerKind: due.providerKind, reason });
|
|
42
|
+
return policy.failed(due, null, null, null, null, reason);
|
|
43
|
+
}
|
|
44
|
+
const snapshots = await deps.persistence.buildCycleSnapshots({
|
|
45
|
+
subscriptionId: due.subscriptionId,
|
|
46
|
+
scheduledAt: due.nextCycleAt,
|
|
47
|
+
});
|
|
48
|
+
const totalGrossMinor = policy.readTotal(snapshots.orderSnapshot);
|
|
49
|
+
if (totalGrossMinor === null) {
|
|
50
|
+
return policy.failed(due, null, snapshots.cycleNumber, null, null, policy.invalidTotalsReason);
|
|
51
|
+
}
|
|
52
|
+
const cycleKey = policy.cycleKey(due);
|
|
53
|
+
const cycleOrder = await deps.persistence.createCycleOrder({
|
|
54
|
+
idempotencyKey: cycleKey,
|
|
55
|
+
subscriptionId: due.subscriptionId,
|
|
56
|
+
cycleNumber: snapshots.cycleNumber,
|
|
57
|
+
scheduledAt: due.nextCycleAt,
|
|
58
|
+
templateSnapshot: snapshots.templateSnapshot,
|
|
59
|
+
pricingSnapshot: snapshots.pricingSnapshot,
|
|
60
|
+
orderSnapshot: snapshots.orderSnapshot,
|
|
61
|
+
});
|
|
62
|
+
const intent = await deps.paymentPort.createIntent(policy.intentInput(due, cycleKey, snapshots, cycleOrder, totalGrossMinor, reason));
|
|
63
|
+
const executionKey = policy.executionKey(
|
|
64
|
+
cycleKey, snapshots.retryAttempt, snapshots.providerAttemptSequence,
|
|
65
|
+
);
|
|
66
|
+
const attempt = policy.identity(due, executionKey, intent, cycleOrder, totalGrossMinor);
|
|
67
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
68
|
+
kind: "preflight_block",
|
|
69
|
+
executionIdempotencyKey: executionKey,
|
|
70
|
+
providerIdempotencyKey: attempt.providerIdempotencyKey,
|
|
71
|
+
providerRequestFingerprint: attempt.providerRequestFingerprint,
|
|
72
|
+
paymentIntentId: intent.paymentIntentId,
|
|
73
|
+
cycleId: cycleOrder.cycleId,
|
|
74
|
+
subscriptionId: due.subscriptionId,
|
|
75
|
+
orderUuid: cycleOrder.orderUuid,
|
|
76
|
+
providerKind: policy.normalizedProvider(due.providerKind),
|
|
77
|
+
failureReason: reason,
|
|
78
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
79
|
+
}, policy.failure);
|
|
80
|
+
return policy.failed(
|
|
81
|
+
due,
|
|
82
|
+
cycleOrder.cycleId,
|
|
83
|
+
snapshots.cycleNumber,
|
|
84
|
+
cycleOrder.orderUuid,
|
|
85
|
+
intent.paymentIntentId,
|
|
86
|
+
reason,
|
|
87
|
+
propagation,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function declinedRenewalOutcome<D extends HostedRenewalDue>(
|
|
92
|
+
deps: RenewalFailureDeps, due: D, context: RenewalOutcomeContext & { decline: PaymentExecutionProviderDecline }, policy: RenewalOutcomePolicy,
|
|
93
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
94
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
95
|
+
kind: "provider_declined",
|
|
96
|
+
executionIdempotencyKey: context.executionIdempotencyKey,
|
|
97
|
+
providerIdempotencyKey: context.attemptIdentity.providerIdempotencyKey,
|
|
98
|
+
providerRequestFingerprint: context.attemptIdentity.providerRequestFingerprint,
|
|
99
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
100
|
+
cycleId: context.cycleOrder.cycleId,
|
|
101
|
+
subscriptionId: due.subscriptionId,
|
|
102
|
+
orderUuid: context.cycleOrder.orderUuid,
|
|
103
|
+
providerKind: due.providerKind,
|
|
104
|
+
failureReason: policy.declineReason(context.decline),
|
|
105
|
+
failureClassification: policy.classifyDecline(context.decline),
|
|
106
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
107
|
+
attemptAlreadyPrepared: true,
|
|
108
|
+
}, policy.failure);
|
|
109
|
+
return {
|
|
110
|
+
subscriptionId: due.subscriptionId,
|
|
111
|
+
outcome: "failed",
|
|
112
|
+
cycleId: context.cycleOrder.cycleId,
|
|
113
|
+
cycleNumber: context.snapshots.cycleNumber,
|
|
114
|
+
orderId: context.cycleOrder.orderUuid,
|
|
115
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
116
|
+
attemptStatus: "failed",
|
|
117
|
+
replayed: context.cycleOrder.replayed || context.intent.replayed,
|
|
118
|
+
dunningCaseId: propagation.dunningCaseId,
|
|
119
|
+
retryAttempt: propagation.retryAttempt,
|
|
120
|
+
applyReplayed: propagation.applyReplayed,
|
|
121
|
+
dunningPropagationFailed: propagation.dunningPropagationFailed,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export async function requiresActionRenewalOutcome<D extends HostedRenewalDue>(
|
|
125
|
+
deps: RenewalFailureDeps, due: D, context: RenewalOutcomeContext, policy: RenewalOutcomePolicy,
|
|
126
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
127
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
128
|
+
kind: "off_session_requires_action",
|
|
129
|
+
executionIdempotencyKey: context.executionIdempotencyKey,
|
|
130
|
+
providerIdempotencyKey: context.attemptIdentity.providerIdempotencyKey,
|
|
131
|
+
providerRequestFingerprint: context.attemptIdentity.providerRequestFingerprint,
|
|
132
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
133
|
+
cycleId: context.cycleOrder.cycleId,
|
|
134
|
+
subscriptionId: due.subscriptionId,
|
|
135
|
+
orderUuid: context.cycleOrder.orderUuid,
|
|
136
|
+
providerKind: due.providerKind,
|
|
137
|
+
failureReason: policy.scaReason,
|
|
138
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
139
|
+
attemptAlreadyPrepared: true,
|
|
140
|
+
}, policy.failure);
|
|
141
|
+
return {
|
|
142
|
+
subscriptionId: due.subscriptionId,
|
|
143
|
+
outcome: "requires_action",
|
|
144
|
+
cycleId: context.cycleOrder.cycleId,
|
|
145
|
+
cycleNumber: context.snapshots.cycleNumber,
|
|
146
|
+
orderId: context.cycleOrder.orderUuid,
|
|
147
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
148
|
+
attemptStatus: context.finalizedAttempt.status,
|
|
149
|
+
replayed: context.cycleOrder.replayed || context.intent.replayed,
|
|
150
|
+
dunningCaseId: propagation.dunningCaseId,
|
|
151
|
+
retryAttempt: propagation.retryAttempt,
|
|
152
|
+
applyReplayed: propagation.applyReplayed,
|
|
153
|
+
dunningPropagationFailed: propagation.dunningPropagationFailed,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function replayRenewalAttempt<D extends HostedRenewalDue>(
|
|
158
|
+
deps: RenewalFailureDeps, due: D, ctx: RenewalReplayContext,
|
|
159
|
+
status: PaymentAttemptStatus, policy: RenewalReplayPolicy,
|
|
160
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
161
|
+
if (status === "requires_action") {
|
|
162
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
163
|
+
kind: "off_session_requires_action",
|
|
164
|
+
executionIdempotencyKey: ctx.executionIdempotencyKey,
|
|
165
|
+
providerIdempotencyKey: ctx.providerIdempotencyKey,
|
|
166
|
+
providerRequestFingerprint: ctx.providerRequestFingerprint,
|
|
167
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
168
|
+
cycleId: ctx.cycleId,
|
|
169
|
+
subscriptionId: due.subscriptionId,
|
|
170
|
+
orderUuid: ctx.orderId,
|
|
171
|
+
providerKind: ctx.providerKind,
|
|
172
|
+
failureReason: policy.scaReason,
|
|
173
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
174
|
+
attemptAlreadyPrepared: true,
|
|
175
|
+
}, policy.failure);
|
|
176
|
+
return {
|
|
177
|
+
subscriptionId: due.subscriptionId,
|
|
178
|
+
outcome: "requires_action",
|
|
179
|
+
cycleId: ctx.cycleId,
|
|
180
|
+
cycleNumber: ctx.cycleNumber,
|
|
181
|
+
orderId: ctx.orderId,
|
|
182
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
183
|
+
attemptStatus: status,
|
|
184
|
+
replayed: true,
|
|
185
|
+
dunningCaseId: propagation.dunningCaseId,
|
|
186
|
+
retryAttempt: propagation.retryAttempt,
|
|
187
|
+
applyReplayed: propagation.applyReplayed,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (status === "sent_to_provider" || status === "processing") {
|
|
191
|
+
return {
|
|
192
|
+
subscriptionId: due.subscriptionId,
|
|
193
|
+
outcome: "charged",
|
|
194
|
+
cycleId: ctx.cycleId,
|
|
195
|
+
cycleNumber: ctx.cycleNumber,
|
|
196
|
+
orderId: ctx.orderId,
|
|
197
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
198
|
+
attemptStatus: status,
|
|
199
|
+
replayed: true,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
subscriptionId: due.subscriptionId,
|
|
204
|
+
outcome: "failed",
|
|
205
|
+
cycleId: ctx.cycleId,
|
|
206
|
+
cycleNumber: ctx.cycleNumber,
|
|
207
|
+
orderId: ctx.orderId,
|
|
208
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
209
|
+
attemptStatus: status,
|
|
210
|
+
replayed: true,
|
|
211
|
+
dunningCaseId: null,
|
|
212
|
+
retryAttempt: null,
|
|
213
|
+
reason: policy.unacknowledgedReason(status),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RenewalIdentity, RenewalSchedule } from "./contracts/renewal.js";
|
|
2
|
+
/** The host's existing dialect owns every byte; no normalization or new prefix. */
|
|
3
|
+
export function renewalIdentity(schedule: RenewalSchedule, keys: (schedule: RenewalSchedule) => RenewalIdentity): RenewalIdentity {
|
|
4
|
+
return keys(schedule);
|
|
5
|
+
}
|