diff options
author | Florian Dold <florian@dold.me> | 2024-08-21 19:23:48 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-08-21 19:23:48 +0200 |
commit | 0b25d5d010c2b66628035f267353bec0721e3bf0 (patch) | |
tree | 0ba998103f344cbb72a610cffed236c8f786b256 /packages/taler-wallet-core | |
parent | 5374b47792a7aad57e8f766d62b516df490ec360 (diff) |
wallet-core: fix transition out of auto-refund
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/pay-merchant.ts | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts index 726abb1e7..e0b1fad98 100644 --- a/packages/taler-wallet-core/src/pay-merchant.ts +++ b/packages/taler-wallet-core/src/pay-merchant.ts @@ -144,6 +144,7 @@ import { WalletDbReadWriteTransaction, WalletStoresV1, } from "./db.js"; +import { getScopeForAllExchanges } from "./exchanges.js"; import { DbReadWriteTransaction, StoreNames } from "./query.js"; import { calculateRefreshOutput, @@ -161,7 +162,6 @@ import { getDenomInfo, WalletExecutionContext, } from "./wallet.js"; -import { getScopeForAllExchanges } from "./exchanges.js"; /** * Logger. @@ -3228,12 +3228,9 @@ async function processPurchaseAutoRefund( purchase: PurchaseRecord, ): Promise<TaskRunResult> { const proposalId = purchase.proposalId; - logger.trace(`processing auto-refund for proposal ${proposalId}`); + const ctx = new PayMerchantTransactionContext(wex, proposalId); - const transactionId = constructTransactionIdentifier({ - tag: TransactionType.Payment, - proposalId, - }); + logger.trace(`processing auto-refund for proposal ${proposalId}`); const download = await expectProposalDownload(wex, purchase); @@ -3257,20 +3254,20 @@ async function processPurchaseAutoRefund( cur.status === RefundGroupStatus.Done || cur.status === RefundGroupStatus.Pending ) { - return Amounts.add(prev, cur.amountEffective).amount; + return Amounts.add(prev, cur.amountRaw).amount; } return prev; }, Amounts.zeroOfAmount(am)); }, ); - const refundedIsLessThanPrice = - Amounts.cmp(download.contractData.amount, totalKnownRefund) === +1; - const nothingMoreToRefund = !refundedIsLessThanPrice; + const fullyRefunded = + Amounts.cmp(download.contractData.amount, totalKnownRefund) <= 0; - const ctx = new PayMerchantTransactionContext(wex, proposalId); + // We stop with the auto-refund state when the auto-refund period + // is over or the product is already fully refunded. - if (noAutoRefundOrExpired || nothingMoreToRefund) { + if (noAutoRefundOrExpired || fullyRefunded) { const transitionInfo = await wex.db.runReadWriteTx( { storeNames: ["purchases", "transactionsMeta"] }, async (tx) => { @@ -3295,7 +3292,7 @@ async function processPurchaseAutoRefund( return { oldTxState, newTxState }; }, ); - notifyTransition(wex, transactionId, transitionInfo); + notifyTransition(wex, ctx.transactionId, transitionInfo); return TaskRunResult.finished(); } @@ -3352,7 +3349,7 @@ async function processPurchaseAutoRefund( return { oldTxState, newTxState }; }, ); - notifyTransition(wex, transactionId, transitionInfo); + notifyTransition(wex, ctx.transactionId, transitionInfo); return TaskRunResult.progress(); } |