@openlup/platform 0.20.0 → 0.22.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 +272 -278
- package/README.md +195 -6
- package/dist/composition/composeBundle.d.ts +13 -0
- package/dist/composition/composeBundle.js +4 -0
- package/dist/composition/fulfillmentContribution.d.ts +21 -0
- package/dist/composition/fulfillmentContribution.js +19 -0
- package/dist/composition/index.d.ts +1 -0
- package/dist/composition/index.js +2 -0
- package/dist/fulfillment/adapterConformance.d.ts +3 -0
- package/dist/fulfillment/adapterConformance.js +223 -0
- package/dist/fulfillment/bindings.d.ts +3 -0
- package/dist/fulfillment/bindings.js +29 -0
- package/dist/fulfillment/commerceFulfillmentHandlers.d.ts +29 -0
- package/dist/fulfillment/commerceFulfillmentHandlers.js +184 -0
- package/dist/fulfillment/commerceFulfillmentReadModel.d.ts +86 -0
- package/dist/fulfillment/commerceFulfillmentReadModel.js +131 -0
- package/dist/fulfillment/contracts/alignment.d.ts +25 -0
- package/dist/fulfillment/contracts/alignment.js +1 -0
- package/dist/fulfillment/contracts/bindings.d.ts +51 -0
- package/dist/fulfillment/contracts/bindings.js +1 -0
- package/dist/fulfillment/contracts/capabilities.d.ts +29 -0
- package/dist/fulfillment/contracts/capabilities.js +1 -0
- package/dist/fulfillment/contracts/conformance.d.ts +93 -0
- package/dist/fulfillment/contracts/conformance.js +1 -0
- package/dist/fulfillment/contracts/customerAlignment.d.ts +6 -0
- package/dist/fulfillment/contracts/customerAlignment.js +1 -0
- package/dist/fulfillment/contracts/dispatch.d.ts +105 -0
- package/dist/fulfillment/contracts/dispatch.js +1 -0
- package/dist/fulfillment/contracts/index.d.ts +18 -0
- package/dist/fulfillment/contracts/index.js +1 -0
- package/dist/fulfillment/contracts/label.d.ts +35 -0
- package/dist/fulfillment/contracts/label.js +1 -0
- package/dist/fulfillment/contracts/nativeUnsupported.d.ts +6 -0
- package/dist/fulfillment/contracts/nativeUnsupported.js +1 -0
- package/dist/fulfillment/contracts/observation.d.ts +52 -0
- package/dist/fulfillment/contracts/observation.js +1 -0
- package/dist/fulfillment/contracts/operator.d.ts +64 -0
- package/dist/fulfillment/contracts/operator.js +1 -0
- package/dist/fulfillment/contracts/read.d.ts +110 -0
- package/dist/fulfillment/contracts/read.js +1 -0
- package/dist/fulfillment/contracts/readback.d.ts +38 -0
- package/dist/fulfillment/contracts/readback.js +1 -0
- package/dist/fulfillment/contracts/replacement.d.ts +34 -0
- package/dist/fulfillment/contracts/replacement.js +1 -0
- package/dist/fulfillment/contracts/store.d.ts +86 -0
- package/dist/fulfillment/contracts/store.js +1 -0
- package/dist/fulfillment/contracts/sync.d.ts +170 -0
- package/dist/fulfillment/contracts/sync.js +1 -0
- package/dist/fulfillment/currentFulfillmentParcel.d.ts +2 -0
- package/dist/fulfillment/currentFulfillmentParcel.js +1 -0
- package/dist/fulfillment/delayReadModel.d.ts +11 -0
- package/dist/fulfillment/delayReadModel.js +45 -0
- package/dist/fulfillment/deliveryAlignmentReadModel.d.ts +4 -0
- package/dist/fulfillment/deliveryAlignmentReadModel.js +12 -0
- package/dist/fulfillment/dispatchProjection.d.ts +7 -0
- package/dist/fulfillment/dispatchProjection.js +18 -0
- package/dist/fulfillment/fulfillmentObservationEffects.d.ts +66 -0
- package/dist/fulfillment/fulfillmentObservationEffects.js +36 -0
- package/dist/fulfillment/handlerSchemas.d.ts +647 -0
- package/dist/fulfillment/handlerSchemas.js +213 -0
- package/dist/fulfillment/handlerSupport.d.ts +33 -0
- package/dist/fulfillment/handlerSupport.js +25 -0
- package/dist/fulfillment/index.d.ts +37 -0
- package/dist/fulfillment/index.js +37 -0
- package/dist/fulfillment/labelLifecycle.d.ts +24 -0
- package/dist/fulfillment/labelLifecycle.js +9 -0
- package/dist/fulfillment/lowStockEvidenceHandler.d.ts +36 -0
- package/dist/fulfillment/lowStockEvidenceHandler.js +46 -0
- package/dist/fulfillment/migrations.d.ts +27 -0
- package/dist/fulfillment/migrations.js +8 -0
- package/dist/fulfillment/nativeUnsupported.d.ts +10 -0
- package/dist/fulfillment/nativeUnsupported.js +18 -0
- package/dist/fulfillment/normalizedFulfillmentFacts.d.ts +2 -0
- package/dist/fulfillment/normalizedFulfillmentFacts.js +1 -0
- package/dist/fulfillment/observationProjection.d.ts +11 -0
- package/dist/fulfillment/observationProjection.js +37 -0
- package/dist/fulfillment/omnipack/capabilities.d.ts +3 -0
- package/dist/fulfillment/omnipack/capabilities.js +16 -0
- package/dist/fulfillment/omnipack/client.d.ts +37 -0
- package/dist/fulfillment/omnipack/client.js +162 -0
- package/dist/fulfillment/omnipack/index.d.ts +52 -0
- package/dist/fulfillment/omnipack/index.js +349 -0
- package/dist/fulfillment/omnipack/mappers.d.ts +73 -0
- package/dist/fulfillment/omnipack/mappers.js +177 -0
- package/dist/fulfillment/omnipack/observation.d.ts +21 -0
- package/dist/fulfillment/omnipack/observation.js +57 -0
- package/dist/fulfillment/omnipack/omnipackDispatchPayload.d.ts +36 -0
- package/dist/fulfillment/omnipack/omnipackDispatchPayload.js +63 -0
- package/dist/fulfillment/omnipack/omnipackOutboundOrderPayload.d.ts +83 -0
- package/dist/fulfillment/omnipack/omnipackOutboundOrderPayload.js +113 -0
- package/dist/fulfillment/omnipack/omnipackProductPackPayload.d.ts +11 -0
- package/dist/fulfillment/omnipack/omnipackProductPackPayload.js +38 -0
- package/dist/fulfillment/omnipack/omnipackProductPayload.d.ts +18 -0
- package/dist/fulfillment/omnipack/omnipackProductPayload.js +51 -0
- package/dist/fulfillment/omnipack/omnipackReconciliationPayload.d.ts +1 -0
- package/dist/fulfillment/omnipack/omnipackReconciliationPayload.js +3 -0
- package/dist/fulfillment/omnipack/omnipackStatusVocabulary.d.ts +4 -0
- package/dist/fulfillment/omnipack/omnipackStatusVocabulary.js +87 -0
- package/dist/fulfillment/omnipack/omnipackWebhookPayload.d.ts +9 -0
- package/dist/fulfillment/omnipack/omnipackWebhookPayload.js +76 -0
- package/dist/fulfillment/omnipack/productSyncMappers.d.ts +18 -0
- package/dist/fulfillment/omnipack/productSyncMappers.js +43 -0
- package/dist/fulfillment/omnipack/providerError.d.ts +25 -0
- package/dist/fulfillment/omnipack/providerError.js +47 -0
- package/dist/fulfillment/omnipack/trackingReferences.d.ts +16 -0
- package/dist/fulfillment/omnipack/trackingReferences.js +52 -0
- package/dist/fulfillment/paidFulfillmentRecovery.d.ts +67 -0
- package/dist/fulfillment/paidFulfillmentRecovery.js +154 -0
- package/dist/fulfillment/paidHandoff.d.ts +27 -0
- package/dist/fulfillment/paidHandoff.js +86 -0
- package/dist/fulfillment/paidHandoffPorts.d.ts +24 -0
- package/dist/fulfillment/paidHandoffPorts.js +3 -0
- package/dist/fulfillment/postgresDeliveryAlignment.d.ts +4 -0
- package/dist/fulfillment/postgresDeliveryAlignment.js +12 -0
- package/dist/fulfillment/postgresDispatchStore.d.ts +16 -0
- package/dist/fulfillment/postgresDispatchStore.js +44 -0
- package/dist/fulfillment/postgresEvidenceReadPort.d.ts +25 -0
- package/dist/fulfillment/postgresEvidenceReadPort.js +45 -0
- package/dist/fulfillment/postgresPaidFulfillmentRecovery.d.ts +25 -0
- package/dist/fulfillment/postgresPaidFulfillmentRecovery.js +26 -0
- package/dist/fulfillment/postgresPaidHandoffStore.d.ts +4 -0
- package/dist/fulfillment/postgresPaidHandoffStore.js +10 -0
- package/dist/fulfillment/postgresShipmentSpine.d.ts +63 -0
- package/dist/fulfillment/postgresShipmentSpine.js +232 -0
- package/dist/fulfillment/postgresStockSyncPort.d.ts +8 -0
- package/dist/fulfillment/postgresStockSyncPort.js +63 -0
- package/dist/fulfillment/productReconciliationEvidenceHandler.d.ts +36 -0
- package/dist/fulfillment/productReconciliationEvidenceHandler.js +50 -0
- package/dist/fulfillment/providerCapabilities.d.ts +9 -0
- package/dist/fulfillment/providerCapabilities.js +17 -0
- package/dist/fulfillment/providerCommandLedger.d.ts +143 -0
- package/dist/fulfillment/providerCommandLedger.js +14 -0
- package/dist/fulfillment/providerDispatchAcceptance.d.ts +26 -0
- package/dist/fulfillment/providerDispatchAcceptance.js +23 -0
- package/dist/fulfillment/providerDispatchError.d.ts +6 -0
- package/dist/fulfillment/providerDispatchError.js +5 -0
- package/dist/fulfillment/providerDispatchWorker.d.ts +31 -0
- package/dist/fulfillment/providerDispatchWorker.js +172 -0
- package/dist/fulfillment/providerProductSyncWorker.d.ts +28 -0
- package/dist/fulfillment/providerProductSyncWorker.js +122 -0
- package/dist/fulfillment/providerReconciliationError.d.ts +9 -0
- package/dist/fulfillment/providerReconciliationError.js +17 -0
- package/dist/fulfillment/providerReconciliationTerminalSkip.d.ts +2 -0
- package/dist/fulfillment/providerReconciliationTerminalSkip.js +6 -0
- package/dist/fulfillment/providerReconciliationTimestamp.d.ts +1 -0
- package/dist/fulfillment/providerReconciliationTimestamp.js +27 -0
- package/dist/fulfillment/providerReconciliationWorker.d.ts +82 -0
- package/dist/fulfillment/providerReconciliationWorker.js +151 -0
- package/dist/fulfillment/providerStockAvailability.d.ts +13 -0
- package/dist/fulfillment/providerStockAvailability.js +51 -0
- package/dist/fulfillment/providerStockSyncWorker.d.ts +37 -0
- package/dist/fulfillment/providerStockSyncWorker.js +186 -0
- package/dist/fulfillment/providerTrackingReferences.d.ts +15 -0
- package/dist/fulfillment/providerTrackingReferences.js +23 -0
- package/dist/fulfillment/replacementRefusals.d.ts +5 -0
- package/dist/fulfillment/replacementRefusals.js +38 -0
- package/dist/fulfillment/replacementShipmentHandler.d.ts +5 -0
- package/dist/fulfillment/replacementShipmentHandler.js +46 -0
- package/dist/fulfillment/schemaCapabilities.d.ts +13 -0
- package/dist/fulfillment/schemaCapabilities.js +7 -0
- package/dist/fulfillment/shipmentsOverviewHandler.d.ts +16 -0
- package/dist/fulfillment/shipmentsOverviewHandler.js +54 -0
- package/dist/fulfillment/statusMap.d.ts +2 -0
- package/dist/fulfillment/statusMap.js +1 -0
- package/dist/fulfillment/trackingProgress.d.ts +1 -0
- package/dist/fulfillment/trackingProgress.js +1 -0
- package/dist/fulfillment/verifiedIngress.d.ts +52 -0
- package/dist/fulfillment/verifiedIngress.js +66 -0
- package/dist/payments/adapterConformance.d.ts +8 -0
- package/dist/payments/adapterConformance.js +109 -0
- package/dist/payments/bindings.d.ts +3 -0
- package/dist/payments/bindings.js +17 -0
- package/dist/payments/checkoutActivePaymentActionResolver.d.ts +7 -0
- package/dist/payments/checkoutActivePaymentActionResolver.js +77 -0
- package/dist/payments/checkoutRecoveryPaymentResolver.d.ts +8 -0
- package/dist/payments/checkoutRecoveryPaymentResolver.js +87 -0
- package/dist/payments/contracts/adapter.d.ts +113 -0
- package/dist/payments/contracts/adapter.js +1 -0
- package/dist/payments/contracts/conformance.d.ts +155 -0
- package/dist/payments/contracts/conformance.js +1 -0
- package/dist/payments/contracts/evidence.d.ts +157 -0
- package/dist/payments/contracts/evidence.js +1 -0
- package/dist/payments/contracts/index.d.ts +10 -0
- package/dist/payments/contracts/index.js +1 -0
- package/dist/payments/contracts/preparedAttempt.d.ts +69 -0
- package/dist/payments/contracts/preparedAttempt.js +1 -0
- package/dist/payments/contracts/reconciliation.d.ts +303 -0
- package/dist/payments/contracts/reconciliation.js +1 -0
- package/dist/payments/contracts/repair.d.ts +92 -0
- package/dist/payments/contracts/repair.js +1 -0
- package/dist/payments/contracts/truth.d.ts +92 -0
- package/dist/payments/contracts/truth.js +1 -0
- package/dist/payments/eventConformanceRunner.d.ts +12 -0
- package/dist/payments/eventConformanceRunner.js +125 -0
- package/dist/payments/index.d.ts +16 -0
- package/dist/payments/index.js +16 -0
- package/dist/payments/paymentAttemptSilenceWindow.d.ts +10 -0
- package/dist/payments/paymentAttemptSilenceWindow.js +19 -0
- package/dist/payments/paymentMethodLifecycle.d.ts +11 -0
- package/dist/payments/paymentMethodLifecycle.js +37 -0
- package/dist/payments/paymentProviderReconciliationAbsenceReopen.d.ts +7 -0
- package/dist/payments/paymentProviderReconciliationAbsenceReopen.js +100 -0
- package/dist/payments/paymentProviderReconciliationEvidence.d.ts +36 -0
- package/dist/payments/paymentProviderReconciliationEvidence.js +91 -0
- package/dist/payments/paymentProviderReconciliationWorker.d.ts +4 -0
- package/dist/payments/paymentProviderReconciliationWorker.js +245 -0
- package/dist/payments/paymentTruth.d.ts +8 -0
- package/dist/payments/paymentTruth.js +125 -0
- package/dist/payments/paymentVerifyNowHandler.d.ts +27 -0
- package/dist/payments/paymentVerifyNowHandler.js +70 -0
- package/dist/payments/paymentVerifyNowService.d.ts +23 -0
- package/dist/payments/paymentVerifyNowService.js +93 -0
- package/dist/payments/paymentWebhookPostProcessing.d.ts +22 -0
- package/dist/payments/paymentWebhookPostProcessing.js +15 -0
- package/dist/payments/postgresPaymentTruth.d.ts +10 -0
- package/dist/payments/postgresPaymentTruth.js +126 -0
- package/dist/payments/preparedAttempt.d.ts +6 -0
- package/dist/payments/preparedAttempt.js +70 -0
- package/dist/payments/preparedAttemptFinalization.d.ts +5 -0
- package/dist/payments/preparedAttemptFinalization.js +12 -0
- package/dist/payments/schemaCapabilities.d.ts +10 -0
- package/dist/payments/schemaCapabilities.js +10 -0
- package/dist/payments/sql.d.ts +20 -0
- package/dist/payments/sql.js +6 -0
- package/dist/payments/stripe/classifyDecline.d.ts +46 -0
- package/dist/payments/stripe/classifyDecline.js +58 -0
- package/dist/payments/stripe/declineFailureHints.d.ts +46 -0
- package/dist/payments/stripe/declineFailureHints.js +87 -0
- package/dist/payments/stripe/donorContracts.d.ts +120 -0
- package/dist/payments/stripe/donorContracts.js +1 -0
- package/dist/payments/stripe/executionDecline.d.ts +53 -0
- package/dist/payments/stripe/executionDecline.js +107 -0
- package/dist/payments/stripe/index.d.ts +41 -0
- package/dist/payments/stripe/index.js +264 -0
- package/dist/payments/stripe/intentMapper.d.ts +26 -0
- package/dist/payments/stripe/intentMapper.js +51 -0
- package/dist/payments/stripe/methodFacts.d.ts +10 -0
- package/dist/payments/stripe/methodFacts.js +12 -0
- package/dist/payments/stripe/paymentFailureEvidence.d.ts +26 -0
- package/dist/payments/stripe/paymentFailureEvidence.js +33 -0
- package/dist/payments/stripe/stripeFailureEvidence.d.ts +41 -0
- package/dist/payments/stripe/stripeFailureEvidence.js +82 -0
- package/dist/payments/stripe/stripeIntentConfirmationEvidence.d.ts +28 -0
- package/dist/payments/stripe/stripeIntentConfirmationEvidence.js +32 -0
- package/dist/payments/stripe/stripePaymentReconciliationProvider.d.ts +35 -0
- package/dist/payments/stripe/stripePaymentReconciliationProvider.js +222 -0
- package/dist/payments/stripe/stripeRefundEvidence.d.ts +8 -0
- package/dist/payments/stripe/stripeRefundEvidence.js +17 -0
- package/dist/payments/stripe/stripeSandboxPaymentExecutionAdapter.d.ts +45 -0
- package/dist/payments/stripe/stripeSandboxPaymentExecutionAdapter.js +220 -0
- package/dist/payments/stripe/stripeWebhookNormalizer.d.ts +14 -0
- package/dist/payments/stripe/stripeWebhookNormalizer.js +243 -0
- package/dist/payments/stripe/webhookSignature.d.ts +14 -0
- package/dist/payments/stripe/webhookSignature.js +43 -0
- package/dist/payments/tpay/blikRecurringMapper.d.ts +37 -0
- package/dist/payments/tpay/blikRecurringMapper.js +24 -0
- package/dist/payments/tpay/capabilities.d.ts +3 -0
- package/dist/payments/tpay/capabilities.js +18 -0
- package/dist/payments/tpay/classifyDecline.d.ts +46 -0
- package/dist/payments/tpay/classifyDecline.js +58 -0
- package/dist/payments/tpay/declineFailureHints.d.ts +72 -0
- package/dist/payments/tpay/declineFailureHints.js +37 -0
- package/dist/payments/tpay/donorContracts.d.ts +140 -0
- package/dist/payments/tpay/donorContracts.js +1 -0
- package/dist/payments/tpay/index.d.ts +73 -0
- package/dist/payments/tpay/index.js +294 -0
- package/dist/payments/tpay/paymentFailureEvidence.d.ts +26 -0
- package/dist/payments/tpay/paymentFailureEvidence.js +33 -0
- package/dist/payments/tpay/preparedProviderAttempt.d.ts +22 -0
- package/dist/payments/tpay/preparedProviderAttempt.js +24 -0
- package/dist/payments/tpay/providerAttemptFailureDiagnostic.d.ts +3 -0
- package/dist/payments/tpay/providerAttemptFailureDiagnostic.js +95 -0
- package/dist/payments/tpay/tpayCreateTransactionInput.d.ts +25 -0
- package/dist/payments/tpay/tpayCreateTransactionInput.js +128 -0
- package/dist/payments/tpay/tpayDeclineEvidence.d.ts +126 -0
- package/dist/payments/tpay/tpayDeclineEvidence.js +177 -0
- package/dist/payments/tpay/tpayDispatchFailure.d.ts +60 -0
- package/dist/payments/tpay/tpayDispatchFailure.js +121 -0
- package/dist/payments/tpay/tpayFailureEvidence.d.ts +20 -0
- package/dist/payments/tpay/tpayFailureEvidence.js +61 -0
- package/dist/payments/tpay/tpayHttpClient.d.ts +52 -0
- package/dist/payments/tpay/tpayHttpClient.js +185 -0
- package/dist/payments/tpay/tpayHttpFailure.d.ts +57 -0
- package/dist/payments/tpay/tpayHttpFailure.js +143 -0
- package/dist/payments/tpay/tpayPaymentExecutionAdapter.d.ts +20 -0
- package/dist/payments/tpay/tpayPaymentExecutionAdapter.js +249 -0
- package/dist/payments/tpay/tpayPaymentReconciliationProvider.d.ts +5 -0
- package/dist/payments/tpay/tpayPaymentReconciliationProvider.js +244 -0
- package/dist/payments/tpay/tpayTransactionPayload.d.ts +120 -0
- package/dist/payments/tpay/tpayTransactionPayload.js +96 -0
- package/dist/payments/tpay/wallClockTime.d.ts +31 -0
- package/dist/payments/tpay/wallClockTime.js +57 -0
- package/dist/payments/tpay/webhookJwsVerifier.d.ts +17 -0
- package/dist/payments/tpay/webhookJwsVerifier.js +51 -0
- package/dist/payments/tpay/webhookNormalizer.d.ts +54 -0
- package/dist/payments/tpay/webhookNormalizer.js +200 -0
- package/dist/payments/verifiedEvidenceProjection.d.ts +12 -0
- package/dist/payments/verifiedEvidenceProjection.js +166 -0
- package/dist/payments/verifiedIngress.d.ts +119 -0
- package/dist/payments/verifiedIngress.js +220 -0
- package/package.json +37 -2
- package/release-gates.json +105 -3
- package/sql/20260808210000_fulfillment_shipment_rail.sql +810 -0
- package/sql/20260810180000_payment_settlement_rail.sql +574 -0
- package/sql/20260815150000_payment_truth_reconciliation.sql +479 -0
- package/sql/20260819150000_fulfillment_shipment_sequence.sql +98 -0
- package/sql/20260826100000_late_payment_shifts_the_subscription_cycle.sql +215 -0
- package/sql/20261022080000_fulfillment_command_ledger.sql +786 -0
- package/sql/20261022090000_fulfillment_delivery_alignment.sql +1106 -0
- package/src/composition/composeBundle.ts +13 -0
- package/src/composition/fulfillmentContribution.ts +28 -0
- package/src/composition/index.ts +2 -0
- package/src/fulfillment/adapterConformance.ts +195 -0
- package/src/fulfillment/bindings.ts +26 -0
- package/src/fulfillment/commerceFulfillmentHandlers.ts +263 -0
- package/src/fulfillment/commerceFulfillmentReadModel.ts +257 -0
- package/src/fulfillment/contracts/alignment.ts +13 -0
- package/src/fulfillment/contracts/bindings.ts +30 -0
- package/src/fulfillment/contracts/capabilities.ts +15 -0
- package/src/fulfillment/contracts/conformance.ts +61 -0
- package/src/fulfillment/contracts/customerAlignment.ts +4 -0
- package/src/fulfillment/contracts/dispatch.ts +58 -0
- package/src/fulfillment/contracts/index.ts +18 -0
- package/src/fulfillment/contracts/label.ts +9 -0
- package/src/fulfillment/contracts/nativeUnsupported.ts +6 -0
- package/src/fulfillment/contracts/observation.ts +18 -0
- package/src/fulfillment/contracts/operator.ts +31 -0
- package/src/fulfillment/contracts/read.ts +42 -0
- package/src/fulfillment/contracts/readback.ts +11 -0
- package/src/fulfillment/contracts/replacement.ts +15 -0
- package/src/fulfillment/contracts/store.ts +26 -0
- package/src/fulfillment/contracts/sync.ts +61 -0
- package/src/fulfillment/currentFulfillmentParcel.ts +2 -0
- package/src/fulfillment/delayReadModel.ts +60 -0
- package/src/fulfillment/deliveryAlignmentReadModel.ts +15 -0
- package/src/fulfillment/dispatchProjection.ts +20 -0
- package/src/fulfillment/fulfillmentObservationEffects.ts +86 -0
- package/src/fulfillment/handlerSchemas.ts +255 -0
- package/src/fulfillment/handlerSupport.ts +25 -0
- package/src/fulfillment/index.ts +38 -0
- package/src/fulfillment/labelLifecycle.ts +11 -0
- package/src/fulfillment/lowStockEvidenceHandler.ts +60 -0
- package/src/fulfillment/migrations.ts +8 -0
- package/src/fulfillment/nativeUnsupported.ts +23 -0
- package/src/fulfillment/normalizedFulfillmentFacts.ts +2 -0
- package/src/fulfillment/observationProjection.ts +41 -0
- package/src/fulfillment/omnipack/capabilities.ts +18 -0
- package/src/fulfillment/omnipack/client.ts +258 -0
- package/src/fulfillment/omnipack/index.ts +312 -0
- package/src/fulfillment/omnipack/mappers.ts +261 -0
- package/src/fulfillment/omnipack/observation.ts +61 -0
- package/src/fulfillment/omnipack/omnipackDispatchPayload.ts +93 -0
- package/src/fulfillment/omnipack/omnipackOutboundOrderPayload.ts +194 -0
- package/src/fulfillment/omnipack/omnipackProductPackPayload.ts +47 -0
- package/src/fulfillment/omnipack/omnipackProductPayload.ts +67 -0
- package/src/fulfillment/omnipack/omnipackReconciliationPayload.ts +7 -0
- package/src/fulfillment/omnipack/omnipackStatusVocabulary.ts +103 -0
- package/src/fulfillment/omnipack/omnipackWebhookPayload.ts +73 -0
- package/src/fulfillment/omnipack/productSyncMappers.ts +74 -0
- package/src/fulfillment/omnipack/providerError.ts +64 -0
- package/src/fulfillment/omnipack/trackingReferences.ts +77 -0
- package/src/fulfillment/paidFulfillmentRecovery.ts +252 -0
- package/src/fulfillment/paidHandoff.ts +122 -0
- package/src/fulfillment/paidHandoffPorts.ts +21 -0
- package/src/fulfillment/postgresDeliveryAlignment.ts +14 -0
- package/src/fulfillment/postgresDispatchStore.ts +55 -0
- package/src/fulfillment/postgresEvidenceReadPort.ts +59 -0
- package/src/fulfillment/postgresPaidFulfillmentRecovery.ts +29 -0
- package/src/fulfillment/postgresPaidHandoffStore.ts +11 -0
- package/src/fulfillment/postgresShipmentSpine.ts +321 -0
- package/src/fulfillment/postgresStockSyncPort.ts +65 -0
- package/src/fulfillment/productReconciliationEvidenceHandler.ts +64 -0
- package/src/fulfillment/providerCapabilities.ts +18 -0
- package/src/fulfillment/providerCommandLedger.ts +53 -0
- package/src/fulfillment/providerDispatchAcceptance.ts +31 -0
- package/src/fulfillment/providerDispatchError.ts +7 -0
- package/src/fulfillment/providerDispatchWorker.ts +131 -0
- package/src/fulfillment/providerProductSyncWorker.ts +154 -0
- package/src/fulfillment/providerReconciliationError.ts +20 -0
- package/src/fulfillment/providerReconciliationTerminalSkip.ts +8 -0
- package/src/fulfillment/providerReconciliationTimestamp.ts +34 -0
- package/src/fulfillment/providerReconciliationWorker.ts +150 -0
- package/src/fulfillment/providerStockAvailability.ts +60 -0
- package/src/fulfillment/providerStockSyncWorker.ts +222 -0
- package/src/fulfillment/providerTrackingReferences.ts +31 -0
- package/src/fulfillment/replacementRefusals.ts +43 -0
- package/src/fulfillment/replacementShipmentHandler.ts +47 -0
- package/src/fulfillment/schemaCapabilities.ts +7 -0
- package/src/fulfillment/shipmentsOverviewHandler.ts +73 -0
- package/src/fulfillment/statusMap.ts +2 -0
- package/src/fulfillment/trackingProgress.ts +1 -0
- package/src/fulfillment/verifiedIngress.ts +80 -0
- package/src/payments/adapterConformance.ts +118 -0
- package/src/payments/bindings.ts +17 -0
- package/src/payments/checkoutActivePaymentActionResolver.ts +97 -0
- package/src/payments/checkoutRecoveryPaymentResolver.ts +108 -0
- package/src/payments/contracts/adapter.ts +96 -0
- package/src/payments/contracts/conformance.ts +171 -0
- package/src/payments/contracts/evidence.ts +142 -0
- package/src/payments/contracts/index.ts +54 -0
- package/src/payments/contracts/preparedAttempt.ts +86 -0
- package/src/payments/contracts/reconciliation.ts +296 -0
- package/src/payments/contracts/repair.ts +95 -0
- package/src/payments/contracts/truth.ts +108 -0
- package/src/payments/eventConformanceRunner.ts +149 -0
- package/src/payments/index.ts +21 -0
- package/src/payments/paymentAttemptSilenceWindow.ts +26 -0
- package/src/payments/paymentMethodLifecycle.ts +50 -0
- package/src/payments/paymentProviderReconciliationAbsenceReopen.ts +130 -0
- package/src/payments/paymentProviderReconciliationEvidence.ts +117 -0
- package/src/payments/paymentProviderReconciliationWorker.ts +291 -0
- package/src/payments/paymentTruth.ts +131 -0
- package/src/payments/paymentVerifyNowHandler.ts +94 -0
- package/src/payments/paymentVerifyNowService.ts +125 -0
- package/src/payments/paymentWebhookPostProcessing.ts +36 -0
- package/src/payments/postgresPaymentTruth.ts +149 -0
- package/src/payments/preparedAttempt.ts +90 -0
- package/src/payments/preparedAttemptFinalization.ts +13 -0
- package/src/payments/schemaCapabilities.ts +10 -0
- package/src/payments/sql.ts +6 -0
- package/src/payments/stripe/classifyDecline.ts +62 -0
- package/src/payments/stripe/declineFailureHints.ts +89 -0
- package/src/payments/stripe/donorContracts.ts +87 -0
- package/src/payments/stripe/executionDecline.ts +126 -0
- package/src/payments/stripe/index.ts +265 -0
- package/src/payments/stripe/intentMapper.ts +58 -0
- package/src/payments/stripe/methodFacts.ts +21 -0
- package/src/payments/stripe/paymentFailureEvidence.ts +58 -0
- package/src/payments/stripe/stripeFailureEvidence.ts +115 -0
- package/src/payments/stripe/stripeIntentConfirmationEvidence.ts +34 -0
- package/src/payments/stripe/stripePaymentReconciliationProvider.ts +263 -0
- package/src/payments/stripe/stripeRefundEvidence.ts +19 -0
- package/src/payments/stripe/stripeSandboxPaymentExecutionAdapter.ts +283 -0
- package/src/payments/stripe/stripeWebhookNormalizer.ts +277 -0
- package/src/payments/stripe/webhookSignature.ts +55 -0
- package/src/payments/tpay/blikRecurringMapper.ts +42 -0
- package/src/payments/tpay/capabilities.ts +21 -0
- package/src/payments/tpay/classifyDecline.ts +62 -0
- package/src/payments/tpay/declineFailureHints.ts +90 -0
- package/src/payments/tpay/donorContracts.ts +104 -0
- package/src/payments/tpay/index.ts +293 -0
- package/src/payments/tpay/paymentFailureEvidence.ts +58 -0
- package/src/payments/tpay/preparedProviderAttempt.ts +38 -0
- package/src/payments/tpay/providerAttemptFailureDiagnostic.ts +99 -0
- package/src/payments/tpay/tpayCreateTransactionInput.ts +158 -0
- package/src/payments/tpay/tpayDeclineEvidence.ts +233 -0
- package/src/payments/tpay/tpayDispatchFailure.ts +186 -0
- package/src/payments/tpay/tpayFailureEvidence.ts +75 -0
- package/src/payments/tpay/tpayHttpClient.ts +290 -0
- package/src/payments/tpay/tpayHttpFailure.ts +186 -0
- package/src/payments/tpay/tpayPaymentExecutionAdapter.ts +297 -0
- package/src/payments/tpay/tpayPaymentReconciliationProvider.ts +285 -0
- package/src/payments/tpay/tpayTransactionPayload.ts +207 -0
- package/src/payments/tpay/wallClockTime.ts +57 -0
- package/src/payments/tpay/webhookJwsVerifier.ts +82 -0
- package/src/payments/tpay/webhookNormalizer.ts +279 -0
- package/src/payments/verifiedEvidenceProjection.ts +179 -0
- package/src/payments/verifiedIngress.ts +317 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PaymentMoney, PaymentRefundObservation, PaymentVerifyNormalizePort, RefundEvidencePolicy,
|
|
3
|
+
VerifiedMethodEvidence, VerifiedPaymentEvidence,
|
|
4
|
+
} from "./contracts/evidence.js";
|
|
5
|
+
import type { ProviderWebhookWithMethodLifecycle } from "./paymentMethodLifecycle.js";
|
|
6
|
+
import type { ProviderPaymentWebhookKind } from "./verifiedIngress.js";
|
|
7
|
+
|
|
8
|
+
/** New boundary module: verified adapter envelopes into the unchanged donor carrier.
|
|
9
|
+
* Original bytes go only to verification. Store adapter-redacted audit facts plus
|
|
10
|
+
* nested normalized evidence; typed facts override overlapping reader keys.
|
|
11
|
+
* Neither audit shape nor receipt time changes adapter identity/fingerprint.
|
|
12
|
+
* Incomplete refunds are ingested and acknowledged, but require-evidence prevents apply.
|
|
13
|
+
*/
|
|
14
|
+
export function projectVerifiedEvidence(
|
|
15
|
+
evidence: VerifiedPaymentEvidence | VerifiedMethodEvidence,
|
|
16
|
+
input: Parameters<PaymentVerifyNormalizePort["verifyAndNormalize"]>[0],
|
|
17
|
+
policy: RefundEvidencePolicy,
|
|
18
|
+
methodOwner?: { clientId: string; subscriptionId?: string | null },
|
|
19
|
+
): ProviderWebhookWithMethodLifecycle {
|
|
20
|
+
const payload = auditPayload(evidence);
|
|
21
|
+
const base = {
|
|
22
|
+
provider: evidence.provider, providerEventId: evidence.providerEventId,
|
|
23
|
+
occurredAt: input.receivedAt, rawPayload: payload,
|
|
24
|
+
paymentIntentId: evidence.intentRef,
|
|
25
|
+
};
|
|
26
|
+
switch (evidence.kind) {
|
|
27
|
+
case "money": {
|
|
28
|
+
// The donor treats absent money as unasserted and skips parity checks.
|
|
29
|
+
// Settling adapter evidence must instead use its existing mismatch refusal.
|
|
30
|
+
if ((evidence.outcome === "succeeded" || evidence.outcome === "refunded" || evidence.outcome === "disputed")
|
|
31
|
+
&& (evidence.money === null || !Number.isSafeInteger(evidence.money.amountMinor)
|
|
32
|
+
|| evidence.money.amountMinor <= 0 || !evidence.money.currency.trim())) {
|
|
33
|
+
throw new Error("payment_control_result_amount_mismatch");
|
|
34
|
+
}
|
|
35
|
+
const reversal = evidence.refund;
|
|
36
|
+
const refundKind = evidence.outcome === "refunded"
|
|
37
|
+
? (reversal ? projectRefund(reversal, evidence) : null) ?? (policy === "legacy-assume-full" ? "full" : null)
|
|
38
|
+
: undefined;
|
|
39
|
+
return {
|
|
40
|
+
...base, eventType: moneyEvent(evidence.outcome, refundKind ? reversal : undefined),
|
|
41
|
+
providerPaymentId: evidence.providerPaymentRef, paymentAttemptId: evidence.attemptRef,
|
|
42
|
+
amountMinor: evidence.money?.amountMinor ?? null, currency: evidence.money?.currency ?? null,
|
|
43
|
+
refundKind,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
case "method":
|
|
47
|
+
return {
|
|
48
|
+
...base, eventType: methodEvent(evidence.outcome),
|
|
49
|
+
// Pinned donor normalizer :59 calls resolveLinkagePaymentId :146–154:
|
|
50
|
+
// setup/method objects use their own object id as the carrier reference.
|
|
51
|
+
providerPaymentId: evidence.setupRef ?? evidence.methodRef,
|
|
52
|
+
methodLifecycle: lifecycle(evidence.methodLifecycle),
|
|
53
|
+
...(evidence.reusableMethod && methodOwner ? { reusableMethod: {
|
|
54
|
+
clientId: methodOwner.clientId, subscriptionId: methodOwner.subscriptionId,
|
|
55
|
+
providerCustomerRef: evidence.reusableMethod.providerCustomerRef,
|
|
56
|
+
providerMethodRef: evidence.reusableMethod.providerMethodRef,
|
|
57
|
+
providerMandateRef: evidence.reusableMethod.providerMandateRef,
|
|
58
|
+
methodKind: evidence.reusableMethod.methodKind, status: evidence.reusableMethod.status,
|
|
59
|
+
} } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return assertNever(evidence);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function moneyEvent(outcome: VerifiedPaymentEvidence["outcome"], refund: PaymentRefundObservation | undefined): ProviderPaymentWebhookKind {
|
|
66
|
+
switch (outcome) {
|
|
67
|
+
case "succeeded": return "payment.succeeded";
|
|
68
|
+
case "failed": return "payment.failed";
|
|
69
|
+
case "pending": return "payment.requires_action";
|
|
70
|
+
case "refunded": return refund?.kind === "full-reversal" && refund.reason === "chargeback" ? "payment.disputed" : "payment.refunded";
|
|
71
|
+
case "disputed": return "payment.disputed";
|
|
72
|
+
}
|
|
73
|
+
return assertNever(outcome);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function methodEvent(outcome: VerifiedMethodEvidence["outcome"]): ProviderPaymentWebhookKind {
|
|
77
|
+
switch (outcome) {
|
|
78
|
+
case "registered": case "updated": return "setup.succeeded";
|
|
79
|
+
case "revoked": case "expired": case "suspended": case "failed": return "setup.failed";
|
|
80
|
+
case "requires-action": return "setup.requires_action";
|
|
81
|
+
}
|
|
82
|
+
return assertNever(outcome);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function projectRefund(refund: PaymentRefundObservation, evidence: VerifiedPaymentEvidence): "full" | "partial" | null {
|
|
86
|
+
const original = refund.originalPaymentMoney;
|
|
87
|
+
if (!refund.operationId?.trim() || !evidence.providerPaymentRef.trim()
|
|
88
|
+
|| !Number.isSafeInteger(original?.amountMinor) || original.amountMinor <= 0
|
|
89
|
+
|| !original.currency?.trim() || !evidence.money
|
|
90
|
+
|| evidence.money.amountMinor !== original.amountMinor || evidence.money.currency !== original.currency) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
switch (refund.kind) {
|
|
94
|
+
case "full-reversal": return "full";
|
|
95
|
+
case "cumulative-snapshot": case "event-delta": {
|
|
96
|
+
const money = refund.refundedMoney;
|
|
97
|
+
if (!Number.isSafeInteger(money?.amountMinor) || money.amountMinor <= 0
|
|
98
|
+
|| money.amountMinor > original.amountMinor || money.currency !== original.currency) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return money.amountMinor < original.amountMinor ? "partial" : "full";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return assertNever(refund);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function assertNever(value: never): never {
|
|
108
|
+
throw new Error(`payment_evidence_unmapped:${String(value)}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function auditPayload(evidence: VerifiedPaymentEvidence | VerifiedMethodEvidence): Record<string, unknown> {
|
|
112
|
+
// Explicit typed fields only: unknown envelope properties never enter storage.
|
|
113
|
+
const normalized = {
|
|
114
|
+
provider: evidence.provider, providerEventId: evidence.providerEventId,
|
|
115
|
+
fingerprint: evidence.fingerprint,
|
|
116
|
+
providerOccurredAt: evidence.providerOccurredAt, kind: evidence.kind,
|
|
117
|
+
intentRef: evidence.intentRef, outcome: evidence.outcome,
|
|
118
|
+
...(evidence.kind === "money" ? {
|
|
119
|
+
providerPaymentRef: evidence.providerPaymentRef, attemptRef: evidence.attemptRef,
|
|
120
|
+
money: evidence.money && money(evidence.money),
|
|
121
|
+
refusal: evidence.refusal && { code: evidence.refusal.code,
|
|
122
|
+
hints: [...evidence.refusal.hints], adviceCode: evidence.refusal.adviceCode },
|
|
123
|
+
refund: evidence.refund && refund(evidence.refund),
|
|
124
|
+
} : {
|
|
125
|
+
methodRef: evidence.methodRef, setupRef: evidence.setupRef,
|
|
126
|
+
methodLifecycle: lifecycle(evidence.methodLifecycle),
|
|
127
|
+
reusableMethod: evidence.reusableMethod && {
|
|
128
|
+
providerCustomerRef: evidence.reusableMethod.providerCustomerRef,
|
|
129
|
+
providerMethodRef: evidence.reusableMethod.providerMethodRef,
|
|
130
|
+
providerMandateRef: evidence.reusableMethod.providerMandateRef,
|
|
131
|
+
methodKind: evidence.reusableMethod.methodKind, status: evidence.reusableMethod.status,
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
};
|
|
135
|
+
const payload: Record<string, unknown> = { ...evidence.providerAuditPayload };
|
|
136
|
+
if (evidence.kind === "money") {
|
|
137
|
+
// Host readers use the provider object reference and original payment money.
|
|
138
|
+
payload.providerPaymentId = evidence.providerPaymentRef;
|
|
139
|
+
payload.amountMinor = evidence.money?.amountMinor ?? null;
|
|
140
|
+
payload.currency = evidence.money?.currency ?? null;
|
|
141
|
+
// Snapshot reader namespaces are adapter-owned. Their charge identity has no
|
|
142
|
+
// typed home; their cumulative amount must come from the typed observation.
|
|
143
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
144
|
+
if (value && typeof value === "object" && !Array.isArray(value) && "chargeId" in value) {
|
|
145
|
+
payload[key] = { ...value, amountRefundedMinor: evidence.refund?.kind === "cumulative-snapshot"
|
|
146
|
+
? evidence.refund.refundedMoney?.amountMinor ?? null : null };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const failure = payload.failureEvidence;
|
|
150
|
+
if (failure && typeof failure === "object" && !Array.isArray(failure)) {
|
|
151
|
+
payload.failureEvidence = { ...failure, providerPaymentId: evidence.providerPaymentRef,
|
|
152
|
+
code: evidence.refusal?.code ?? null, adviceCode: evidence.refusal?.adviceCode ?? null };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
payload.openlupEvidence = normalized;
|
|
156
|
+
return payload;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function money(value: PaymentMoney) {
|
|
160
|
+
return { amountMinor: value.amountMinor, currency: value.currency };
|
|
161
|
+
}
|
|
162
|
+
function refund(value: PaymentRefundObservation) {
|
|
163
|
+
const base = { operationId: value.operationId, originalPaymentMoney: value.originalPaymentMoney && money(value.originalPaymentMoney) };
|
|
164
|
+
switch (value.kind) {
|
|
165
|
+
case "full-reversal": return { ...base, kind: value.kind, reason: value.reason };
|
|
166
|
+
case "cumulative-snapshot": case "event-delta":
|
|
167
|
+
return { ...base, kind: value.kind, refundedMoney: value.refundedMoney && money(value.refundedMoney) };
|
|
168
|
+
}
|
|
169
|
+
return assertNever(value);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function lifecycle(value: VerifiedMethodEvidence["methodLifecycle"]): VerifiedMethodEvidence["methodLifecycle"] {
|
|
173
|
+
return value && { kind: value.kind, providerKind: value.providerKind,
|
|
174
|
+
providerMethodRef: value.providerMethodRef, providerEventId: value.providerEventId,
|
|
175
|
+
occurredAt: value.occurredAt, replacement: value.replacement && {
|
|
176
|
+
schemeLabel: value.replacement.schemeLabel, lastDigits: value.replacement.lastDigits,
|
|
177
|
+
expiresAt: value.replacement.expiresAt,
|
|
178
|
+
} };
|
|
179
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import type { PaymentIngressPort, PaymentVerifyNormalizePort, RefundEvidencePolicy, VerifiedMethodEvidence } from "./contracts/evidence.js";
|
|
2
|
+
import { projectVerifiedEvidence } from "./verifiedEvidenceProjection.js";
|
|
3
|
+
const PAYMENT_WEBHOOK_EVENT_TYPES = [
|
|
4
|
+
"payment.succeeded",
|
|
5
|
+
"payment.failed",
|
|
6
|
+
"payment.refunded",
|
|
7
|
+
"payment.requires_action",
|
|
8
|
+
"payment.disputed",
|
|
9
|
+
"setup.succeeded",
|
|
10
|
+
"setup.failed",
|
|
11
|
+
"setup.requires_action",
|
|
12
|
+
] as const;
|
|
13
|
+
type PaymentWebhookEventType = (typeof PAYMENT_WEBHOOK_EVENT_TYPES)[number];
|
|
14
|
+
export type ProviderPaymentWebhookKind = PaymentWebhookEventType;
|
|
15
|
+
|
|
16
|
+
export interface NormalizedProviderPaymentWebhook {
|
|
17
|
+
provider: string;
|
|
18
|
+
providerEventId: string;
|
|
19
|
+
eventType: ProviderPaymentWebhookKind;
|
|
20
|
+
providerPaymentId: string;
|
|
21
|
+
paymentIntentId?: string | null;
|
|
22
|
+
paymentAttemptId?: string | null;
|
|
23
|
+
amountMinor?: number | null;
|
|
24
|
+
currency?: string | null;
|
|
25
|
+
occurredAt: string;
|
|
26
|
+
|
|
27
|
+
refundKind?: "full" | "partial" | null;
|
|
28
|
+
rawPayload: Record<string, unknown>;
|
|
29
|
+
reusableMethod?: {
|
|
30
|
+
clientId: string;
|
|
31
|
+
subscriptionId?: string | null;
|
|
32
|
+
providerCustomerRef?: string | null;
|
|
33
|
+
providerMethodRef: string;
|
|
34
|
+
providerMandateRef?: string | null;
|
|
35
|
+
methodKind: string;
|
|
36
|
+
status: "pending_verification" | "active" | "inactive" | "expired" | "revoked";
|
|
37
|
+
consentSnapshot?: Record<string, unknown>;
|
|
38
|
+
} | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PaymentWebhookControlPort {
|
|
42
|
+
ingestPaymentEvent(input: NormalizedProviderPaymentWebhook): Promise<{
|
|
43
|
+
paymentEventId: string;
|
|
44
|
+
paymentIntentId: string | null;
|
|
45
|
+
paymentAttemptId: string | null;
|
|
46
|
+
replayed: boolean; occurredAt?: string; // Durable instant for application and post-processing.
|
|
47
|
+
}>;
|
|
48
|
+
applyPaymentResult?(input: {
|
|
49
|
+
idempotencyKey: string;
|
|
50
|
+
paymentIntentId: string;
|
|
51
|
+
paymentEventId: string;
|
|
52
|
+
resultStatus: "succeeded" | "failed" | "refunded" | "partially_refunded" | "disputed";
|
|
53
|
+
occurredAt: string;
|
|
54
|
+
failureReason: string | null;
|
|
55
|
+
}): Promise<{ replayed: boolean }>;
|
|
56
|
+
|
|
57
|
+
confirmSubscriptionActivation?(input: {
|
|
58
|
+
idempotencyKey: string;
|
|
59
|
+
paymentIntentId: string;
|
|
60
|
+
occurredAt: string;
|
|
61
|
+
methodRef: string | null;
|
|
62
|
+
methodKind: string | null;
|
|
63
|
+
}): Promise<{ confirmed: boolean; status: string | null }>;
|
|
64
|
+
recoverPaidSubscriptionActivationWithCard?(input: {
|
|
65
|
+
idempotencyKey: string;
|
|
66
|
+
subscriptionId: string;
|
|
67
|
+
paymentMethodRef: string;
|
|
68
|
+
occurredAt: string;
|
|
69
|
+
}): Promise<{ recovered: boolean; replayed: boolean; reason: string | null }>;
|
|
70
|
+
/**
|
|
71
|
+
* Closes the ledger row of a `setup.*` event once the full setup pipeline
|
|
72
|
+
* resolved. Setup events carry no money result, so applyPaymentResult (the
|
|
73
|
+
* only other processed_at writer) never runs for them.
|
|
74
|
+
*/
|
|
75
|
+
markSetupEventProcessed?(input: { paymentEventId: string }): Promise<{ updated: boolean }>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface PaymentWebhookMethodRefPort {
|
|
79
|
+
upsertFromWebhook(input: NormalizedProviderPaymentWebhook): Promise<{ replayed: boolean }>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type PaymentWebhookAfterProcessed = (input: {
|
|
83
|
+
event: NormalizedProviderPaymentWebhook;
|
|
84
|
+
ingested: {
|
|
85
|
+
paymentEventId: string;
|
|
86
|
+
paymentIntentId: string | null;
|
|
87
|
+
paymentAttemptId: string | null;
|
|
88
|
+
replayed: boolean;
|
|
89
|
+
};
|
|
90
|
+
resultStatus: "succeeded" | "failed" | "refunded" | "partially_refunded" | "disputed" | null;
|
|
91
|
+
}) => Promise<void>;
|
|
92
|
+
|
|
93
|
+
export interface PaymentWebhookProcessingPorts {
|
|
94
|
+
paymentControlPort: PaymentWebhookControlPort;
|
|
95
|
+
methodRefPort?: PaymentWebhookMethodRefPort;
|
|
96
|
+
afterProcessed?: PaymentWebhookAfterProcessed;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
type IngressResponse = Awaited<ReturnType<PaymentIngressPort["receive"]>>;
|
|
101
|
+
type OperationalEventRecorder = (event: { name: string; domain: string; surface: string; details: Record<string, unknown> }) => void;
|
|
102
|
+
|
|
103
|
+
/** Verified ingress boundary; persistence and transport response writing belong to the host. */
|
|
104
|
+
export function createVerifiedPaymentIngress({
|
|
105
|
+
provider, verifyPort, paymentControlPort, methodRefPort, afterProcessed, createPorts, resolveMethodOwner,
|
|
106
|
+
refundEvidencePolicy = "require-evidence", operationalEvents = () => {},
|
|
107
|
+
}: {
|
|
108
|
+
provider: string;
|
|
109
|
+
verifyPort: PaymentVerifyNormalizePort;
|
|
110
|
+
paymentControlPort: PaymentWebhookControlPort;
|
|
111
|
+
methodRefPort?: PaymentWebhookMethodRefPort;
|
|
112
|
+
afterProcessed?: PaymentWebhookAfterProcessed;
|
|
113
|
+
createPorts?: (event: NormalizedProviderPaymentWebhook) => PaymentWebhookProcessingPorts | Promise<PaymentWebhookProcessingPorts>;
|
|
114
|
+
/** Host-owned identity; adapter metadata cannot supply client/subscription authority. */
|
|
115
|
+
resolveMethodOwner?: (evidence: VerifiedMethodEvidence) => Promise<{ clientId: string; subscriptionId?: string | null } | null>;
|
|
116
|
+
refundEvidencePolicy?: RefundEvidencePolicy;
|
|
117
|
+
operationalEvents?: OperationalEventRecorder;
|
|
118
|
+
}): PaymentIngressPort {
|
|
119
|
+
return { async receive(input) {
|
|
120
|
+
let evidence;
|
|
121
|
+
try { evidence = await verifyPort.verifyAndNormalize(input); }
|
|
122
|
+
catch { return { status: 400, data: { error: "Invalid provider webhook signature" } }; }
|
|
123
|
+
if (evidence.kind === "refusal") {
|
|
124
|
+
return evidence.reason === "unsupported-event"
|
|
125
|
+
? { status: 200, data: { provider, acknowledged: true, skipped: "unsupported_event" } }
|
|
126
|
+
: { status: 400, data: { error: "Invalid provider webhook signature" } };
|
|
127
|
+
}
|
|
128
|
+
const verifiedEvidence = evidence;
|
|
129
|
+
let event: NormalizedProviderPaymentWebhook | undefined;
|
|
130
|
+
const res: IngressResponse = { status: 503, data: {} };
|
|
131
|
+
const sendSuccess = (target: IngressResponse, data: Record<string, unknown>) => { target.status = 200; target.data = data; };
|
|
132
|
+
const sendBffError = (target: IngressResponse, code: string, error: string) => {
|
|
133
|
+
target.status = code === "BAD_REQUEST" ? 400 : code === "CONFLICT" ? 409 : 503;
|
|
134
|
+
target.data = { error };
|
|
135
|
+
};
|
|
136
|
+
await processEvent();
|
|
137
|
+
return res;
|
|
138
|
+
async function processEvent(): Promise<void> {
|
|
139
|
+
try {
|
|
140
|
+
try { event = projectVerifiedEvidence(verifiedEvidence, input, refundEvidencePolicy); }
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (error instanceof Error && error.message === "payment_control_result_amount_mismatch") throw error;
|
|
143
|
+
sendBffError(res, "BAD_REQUEST", "Invalid provider webhook evidence");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (event.provider !== provider) {
|
|
147
|
+
sendBffError(res, "BAD_REQUEST", "Provider webhook route mismatch");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (verifiedEvidence.kind === "method" && verifiedEvidence.reusableMethod && resolveMethodOwner) {
|
|
152
|
+
const owner = await resolveMethodOwner(verifiedEvidence);
|
|
153
|
+
event = projectVerifiedEvidence(verifiedEvidence, input, refundEvidencePolicy, owner ?? undefined);
|
|
154
|
+
}
|
|
155
|
+
const ports = createPorts
|
|
156
|
+
? await createPorts(event)
|
|
157
|
+
: { paymentControlPort: paymentControlPort as PaymentWebhookControlPort, methodRefPort, afterProcessed };
|
|
158
|
+
if (!ports.paymentControlPort) throw new Error("Provider webhook port unavailable");
|
|
159
|
+
const ingested = await ports.paymentControlPort.ingestPaymentEvent(event); if (ingested.occurredAt) event = { ...event, occurredAt: ingested.occurredAt };
|
|
160
|
+
const resultStatus = mapResultStatus(event, refundEvidencePolicy);
|
|
161
|
+
if (resultStatus && ingested.paymentIntentId && ports.paymentControlPort.applyPaymentResult) {
|
|
162
|
+
await ports.paymentControlPort.applyPaymentResult({
|
|
163
|
+
idempotencyKey: `provider-webhook:${provider}:${event.providerEventId}:apply`,
|
|
164
|
+
paymentIntentId: ingested.paymentIntentId,
|
|
165
|
+
paymentEventId: ingested.paymentEventId,
|
|
166
|
+
resultStatus,
|
|
167
|
+
occurredAt: event.occurredAt,
|
|
168
|
+
failureReason: event.eventType === "payment.failed" ? "provider_webhook_failed" : null,
|
|
169
|
+
});
|
|
170
|
+
} else if (isMoneyMoved(resultStatus) && !ingested.paymentIntentId && !ingested.replayed) {
|
|
171
|
+
// Operator policy: payments should only originate at the storefront
|
|
172
|
+
// checkout. A money-moved provider event (succeeded / refunded /
|
|
173
|
+
// disputed) that matched no local intent is an out-of-band payment
|
|
174
|
+
// (provider panel payment-link, dashboard link/invoice, wallet, card
|
|
175
|
+
// terminal). It is recorded in inbound_provider_events and ACKed, but
|
|
176
|
+
// there is no order to settle, invoice, or fulfill — the safe no-op above
|
|
177
|
+
// is intentional and preserved. Emit a vendor-neutral, non-paging
|
|
178
|
+
// reconciliation signal so the money is never silently lost.
|
|
179
|
+
// Fires once per unique provider event (`!replayed`): the ingest RPC is
|
|
180
|
+
// idempotent on (provider, provider_event_id), so PSP re-delivery is a
|
|
181
|
+
// natural throttle.
|
|
182
|
+
operationalEvents({
|
|
183
|
+
name: "provider_payment_unmatched_out_of_band",
|
|
184
|
+
domain: "payment",
|
|
185
|
+
surface: "webhook",
|
|
186
|
+
details: {
|
|
187
|
+
provider,
|
|
188
|
+
providerPaymentId: event.providerPaymentId,
|
|
189
|
+
eventType: event.eventType,
|
|
190
|
+
resultStatus,
|
|
191
|
+
amountMinor: event.amountMinor ?? null,
|
|
192
|
+
currency: event.currency ?? null,
|
|
193
|
+
occurredAt: event.occurredAt,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (ports.methodRefPort) {
|
|
198
|
+
await ports.methodRefPort.upsertFromWebhook(event);
|
|
199
|
+
}
|
|
200
|
+
if (ports.afterProcessed) {
|
|
201
|
+
await ports.afterProcessed({ event, ingested, resultStatus });
|
|
202
|
+
}
|
|
203
|
+
// Reached only when every setup mutation above resolved (a throw 5xx's →
|
|
204
|
+
// provider redelivers into a still-'received' row). Runs on replays too,
|
|
205
|
+
// so redelivery self-heals rows stuck from before this closer existed.
|
|
206
|
+
if (resultStatus === null && event.eventType.startsWith("setup.") && ports.paymentControlPort.markSetupEventProcessed) {
|
|
207
|
+
await ports.paymentControlPort.markSetupEventProcessed({ paymentEventId: ingested.paymentEventId });
|
|
208
|
+
}
|
|
209
|
+
sendSuccess(res, {
|
|
210
|
+
provider,
|
|
211
|
+
providerEventId: event.providerEventId,
|
|
212
|
+
paymentEventId: ingested.paymentEventId,
|
|
213
|
+
replayed: ingested.replayed,
|
|
214
|
+
});
|
|
215
|
+
} catch (error) {
|
|
216
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
217
|
+
// A genuine idempotency conflict (same key, different payload) is a client
|
|
218
|
+
// 409, not a transient 5xx — a 503 would make the provider retry a request
|
|
219
|
+
// that can never succeed. The method-ref RPC raises this on a fingerprint
|
|
220
|
+
// mismatch (SQLSTATE 23505).
|
|
221
|
+
if (/payment_method_ref_idempotency_conflict|commerce_idempotency_conflict|\b23505\b/.test(message)) {
|
|
222
|
+
sendBffError(res, "CONFLICT", "Webhook idempotency conflict");
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
// A `succeeded` result that arrives AFTER the provisional-subscription
|
|
226
|
+
// sweep has already terminalized the intent (cancelled/refunded/…) is
|
|
227
|
+
// rejected by `apply_result` with `payment_control_result_terminal_intent`
|
|
228
|
+
// (ERRCODE 22023). The money question is already settled from the control
|
|
229
|
+
// plane's perspective, so this is a "no work left to do" outcome, not a
|
|
230
|
+
// transient upstream failure — ACK 200 so the provider stops
|
|
231
|
+
// retrying for days (retry-storm / charge-without-fulfillment risk). We
|
|
232
|
+
// match the RPC's exception text specifically, NOT the bare 22023 code,
|
|
233
|
+
// because 22023 is also raised for genuine mismatches (amount / currency /
|
|
234
|
+
// intent-not-found) that must still surface as 503.
|
|
235
|
+
if (event && /payment_control_result_terminal_intent/.test(message)) {
|
|
236
|
+
operationalEvents({
|
|
237
|
+
name: "provider_payment_result_after_terminal_intent",
|
|
238
|
+
domain: "payment",
|
|
239
|
+
surface: "webhook",
|
|
240
|
+
details: {
|
|
241
|
+
provider,
|
|
242
|
+
providerEventId: event.providerEventId,
|
|
243
|
+
providerPaymentId: event.providerPaymentId,
|
|
244
|
+
eventType: event.eventType,
|
|
245
|
+
occurredAt: event.occurredAt,
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
sendSuccess(res, {
|
|
249
|
+
provider,
|
|
250
|
+
providerEventId: event.providerEventId,
|
|
251
|
+
acknowledged: true,
|
|
252
|
+
skipped: "result_terminal_intent",
|
|
253
|
+
});
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
// The event cannot be attributed to the intent's exact active attempt:
|
|
257
|
+
// either it named another attempt (the slow-webhook shape and possible
|
|
258
|
+
// double charge) or ingest could not correlate it at all. Neither answer
|
|
259
|
+
// changes on redelivery, so ACK 200 instead of creating an endless retry
|
|
260
|
+
// loop. The durable inbound event and this reason route operator recovery.
|
|
261
|
+
// Match named reasons only, never the shared 22023 SQLSTATE.
|
|
262
|
+
if (event && /payment_control_result_attempt_(?:mismatch|unresolved)/.test(message)) {
|
|
263
|
+
const reason = message.includes("payment_control_result_attempt_unresolved")
|
|
264
|
+
? "attempt_unresolved"
|
|
265
|
+
: "attempt_mismatch";
|
|
266
|
+
operationalEvents({
|
|
267
|
+
name: "provider_payment_result_attempt_mismatch",
|
|
268
|
+
domain: "payment",
|
|
269
|
+
surface: "webhook",
|
|
270
|
+
// `providerPaymentId`, not `providerEventId`, is the operator's handle:
|
|
271
|
+
// the detail allowlist carries the former and drops the latter, and it
|
|
272
|
+
// is the value `ingest_event` correlated the attempt from.
|
|
273
|
+
details: {
|
|
274
|
+
provider,
|
|
275
|
+
providerPaymentId: event.providerPaymentId,
|
|
276
|
+
eventType: event.eventType,
|
|
277
|
+
resultStatus: mapResultStatus(event, refundEvidencePolicy),
|
|
278
|
+
occurredAt: event.occurredAt,
|
|
279
|
+
reason,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
sendSuccess(res, {
|
|
283
|
+
provider,
|
|
284
|
+
providerEventId: event.providerEventId,
|
|
285
|
+
acknowledged: true,
|
|
286
|
+
skipped: "result_attempt_mismatch",
|
|
287
|
+
});
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
sendBffError(res, "UPSTREAM_UNAVAILABLE", "Provider webhook processing failed");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function mapResultStatus(
|
|
297
|
+
event: NormalizedProviderPaymentWebhook,
|
|
298
|
+
refundEvidencePolicy: RefundEvidencePolicy,
|
|
299
|
+
): "succeeded" | "failed" | "refunded" | "partially_refunded" | "disputed" | null {
|
|
300
|
+
if (event.eventType === "payment.succeeded") return "succeeded";
|
|
301
|
+
if (event.eventType === "payment.failed") return "failed";
|
|
302
|
+
if (event.eventType === "payment.refunded") {
|
|
303
|
+
if (refundEvidencePolicy === "require-evidence" && (event.refundKind == null || !event.providerPaymentId.trim() || !Number.isSafeInteger(event.amountMinor) || (event.amountMinor ?? 0) <= 0 || !event.currency?.trim())) return null;
|
|
304
|
+
return event.refundKind === "partial" ? "partially_refunded" : "refunded";
|
|
305
|
+
}
|
|
306
|
+
if (event.eventType === "payment.disputed") return "disputed";
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// "Money moved" for reconciliation purposes: a settled charge, a refund, or a
|
|
311
|
+
// chargeback/dispute. `failed` (no money moved) and `null` (setup / non-money
|
|
312
|
+
// events) are excluded — an unmatched failed/setup event needs no reconciliation.
|
|
313
|
+
function isMoneyMoved(
|
|
314
|
+
resultStatus: "succeeded" | "failed" | "refunded" | "partially_refunded" | "disputed" | null,
|
|
315
|
+
): boolean {
|
|
316
|
+
return resultStatus !== null && resultStatus !== "failed";
|
|
317
|
+
}
|