wallet-core: fix payment abort state machine
This commit is contained in:
parent
1c89f43a04
commit
f3d4ff4e3a
@ -1161,6 +1161,8 @@ export enum PurchaseStatus {
|
||||
Done = 54,
|
||||
|
||||
FailedAbort = 55,
|
||||
|
||||
AbortedRefunded = 56,
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,7 +2566,16 @@ async function storeRefunds(
|
||||
logger.warn("purchase group not found anymore");
|
||||
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;
|
||||
}
|
||||
|
||||
@ -2686,8 +2702,12 @@ async function storeRefunds(
|
||||
|
||||
const oldTxState = computePayMerchantTransactionState(myPurchase);
|
||||
if (numPendingItemsTotal === 0) {
|
||||
if (isAborting) {
|
||||
myPurchase.purchaseStatus = PurchaseStatus.AbortedRefunded;
|
||||
} else {
|
||||
myPurchase.purchaseStatus = PurchaseStatus.Done;
|
||||
}
|
||||
}
|
||||
await tx.purchases.put(myPurchase);
|
||||
const newTxState = computePayMerchantTransactionState(myPurchase);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user