From f3d4ff4e3a44141ad387ef68a9083b01bf1c818a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 5 Jun 2023 10:29:04 +0200 Subject: [PATCH] wallet-core: fix payment abort state machine --- packages/taler-wallet-core/src/db.ts | 2 ++ .../src/operations/pay-merchant.ts | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index afc7e2bf8..0e5d1c100 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1161,6 +1161,8 @@ export enum PurchaseStatus { Done = 54, FailedAbort = 55, + + AbortedRefunded = 56, } /** diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index 0097f5bcc..c3f288ff7 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -1505,6 +1505,7 @@ export async function processPurchase( case PurchaseStatus.DialogProposed: case PurchaseStatus.AbortedProposalRefused: case PurchaseStatus.AbortedIncompletePayment: + case PurchaseStatus.AbortedRefunded: case PurchaseStatus.SuspendedAbortingWithRefund: case PurchaseStatus.SuspendedDownloadingProposal: case PurchaseStatus.SuspendedPaying: @@ -2038,6 +2039,10 @@ export function computePayMerchantTransactionState( major: TransactionMajorState.Failed, minor: TransactionMinorState.Refused, }; + case PurchaseStatus.AbortedRefunded: + return { + major: TransactionMajorState.Aborted, + }; case PurchaseStatus.Done: return { major: TransactionMajorState.Done, @@ -2113,6 +2118,8 @@ export function computePayMerchantTransactionActions( // Final States case PurchaseStatus.AbortedProposalRefused: return [TransactionAction.Delete]; + case PurchaseStatus.AbortedRefunded: + return [TransactionAction.Delete]; case PurchaseStatus.Done: return [TransactionAction.Delete]; case PurchaseStatus.RepurchaseDetected: @@ -2559,8 +2566,17 @@ async function storeRefunds( logger.warn("purchase group not found anymore"); return; } - if (myPurchase.purchaseStatus !== PurchaseStatus.PendingAcceptRefund) { - return; + let isAborting: boolean; + switch (myPurchase.purchaseStatus) { + case PurchaseStatus.PendingAcceptRefund: + isAborting = false; + break; + case PurchaseStatus.AbortingWithRefund: + isAborting = true; + break; + default: + logger.warn("wrong state, not accepting refund"); + return; } let newGroup: RefundGroupRecord | undefined = undefined; @@ -2686,7 +2702,11 @@ async function storeRefunds( const oldTxState = computePayMerchantTransactionState(myPurchase); if (numPendingItemsTotal === 0) { - myPurchase.purchaseStatus = PurchaseStatus.Done; + if (isAborting) { + myPurchase.purchaseStatus = PurchaseStatus.AbortedRefunded; + } else { + myPurchase.purchaseStatus = PurchaseStatus.Done; + } } await tx.purchases.put(myPurchase); const newTxState = computePayMerchantTransactionState(myPurchase);