wallet-core: fix payment abort state machine

This commit is contained in:
Florian Dold 2023-06-05 10:29:04 +02:00
parent 1c89f43a04
commit f3d4ff4e3a
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 25 additions and 3 deletions

View File

@ -1161,6 +1161,8 @@ export enum PurchaseStatus {
Done = 54, Done = 54,
FailedAbort = 55, FailedAbort = 55,
AbortedRefunded = 56,
} }
/** /**

View File

@ -1505,6 +1505,7 @@ export async function processPurchase(
case PurchaseStatus.DialogProposed: case PurchaseStatus.DialogProposed:
case PurchaseStatus.AbortedProposalRefused: case PurchaseStatus.AbortedProposalRefused:
case PurchaseStatus.AbortedIncompletePayment: case PurchaseStatus.AbortedIncompletePayment:
case PurchaseStatus.AbortedRefunded:
case PurchaseStatus.SuspendedAbortingWithRefund: case PurchaseStatus.SuspendedAbortingWithRefund:
case PurchaseStatus.SuspendedDownloadingProposal: case PurchaseStatus.SuspendedDownloadingProposal:
case PurchaseStatus.SuspendedPaying: case PurchaseStatus.SuspendedPaying:
@ -2038,6 +2039,10 @@ export function computePayMerchantTransactionState(
major: TransactionMajorState.Failed, major: TransactionMajorState.Failed,
minor: TransactionMinorState.Refused, minor: TransactionMinorState.Refused,
}; };
case PurchaseStatus.AbortedRefunded:
return {
major: TransactionMajorState.Aborted,
};
case PurchaseStatus.Done: case PurchaseStatus.Done:
return { return {
major: TransactionMajorState.Done, major: TransactionMajorState.Done,
@ -2113,6 +2118,8 @@ export function computePayMerchantTransactionActions(
// Final States // Final States
case PurchaseStatus.AbortedProposalRefused: case PurchaseStatus.AbortedProposalRefused:
return [TransactionAction.Delete]; return [TransactionAction.Delete];
case PurchaseStatus.AbortedRefunded:
return [TransactionAction.Delete];
case PurchaseStatus.Done: case PurchaseStatus.Done:
return [TransactionAction.Delete]; return [TransactionAction.Delete];
case PurchaseStatus.RepurchaseDetected: case PurchaseStatus.RepurchaseDetected:
@ -2559,7 +2566,16 @@ async function storeRefunds(
logger.warn("purchase group not found anymore"); logger.warn("purchase group not found anymore");
return; return;
} }
if (myPurchase.purchaseStatus !== PurchaseStatus.PendingAcceptRefund) { 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; return;
} }
@ -2686,8 +2702,12 @@ async function storeRefunds(
const oldTxState = computePayMerchantTransactionState(myPurchase); const oldTxState = computePayMerchantTransactionState(myPurchase);
if (numPendingItemsTotal === 0) { if (numPendingItemsTotal === 0) {
if (isAborting) {
myPurchase.purchaseStatus = PurchaseStatus.AbortedRefunded;
} else {
myPurchase.purchaseStatus = PurchaseStatus.Done; myPurchase.purchaseStatus = PurchaseStatus.Done;
} }
}
await tx.purchases.put(myPurchase); await tx.purchases.put(myPurchase);
const newTxState = computePayMerchantTransactionState(myPurchase); const newTxState = computePayMerchantTransactionState(myPurchase);