taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 0b25d5d010c2b66628035f267353bec0721e3bf0
parent 5374b47792a7aad57e8f766d62b516df490ec360
Author: Florian Dold <florian@dold.me>
Date:   Wed, 21 Aug 2024 19:23:48 +0200

wallet-core: fix transition out of auto-refund

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-refund-auto.ts | 20+++++++++++---------
Mpackages/taler-wallet-core/src/pay-merchant.ts | 25+++++++++++--------------
2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-refund-auto.ts b/packages/taler-harness/src/integrationtests/test-refund-auto.ts @@ -62,12 +62,12 @@ export async function runRefundAutoTest(t: GlobalTestState) { summary: "Buy me!", amount: "TESTKUDOS:5", fulfillment_url: "taler://fulfillment-success/thx", - auto_refund: { - d_us: 3000 * 1000, - }, + auto_refund: Duration.toTalerProtocolDuration( + Duration.fromSpec({ minutes: 5 }), + ), }, refund_delay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 5 }), + Duration.fromSpec({ minutes: 10 }), ), }); @@ -104,6 +104,8 @@ export async function runRefundAutoTest(t: GlobalTestState) { console.log(ref); + t.logStep("gave-refund"); + // The wallet should now automatically pick up the refund. await walletClient.call( WalletApiOperation.TestingWaitTransactionsFinal, @@ -133,12 +135,12 @@ export async function runRefundAutoTest(t: GlobalTestState) { summary: "Buy me!", amount: "TESTKUDOS:5", fulfillment_url: "taler://fulfillment-success/thx", - auto_refund: { - d_us: 3000 * 1000, - }, + auto_refund: Duration.toTalerProtocolDuration( + Duration.fromSpec({ minutes: 5 }), + ), }, refund_delay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 5 }), + Duration.fromSpec({ minutes: 10 }), ), }); @@ -175,7 +177,7 @@ export async function runRefundAutoTest(t: GlobalTestState) { }); // Only time-travel the wallet await walletClient.call(WalletApiOperation.TestingSetTimetravel, { - offsetMs: 5000, + offsetMs: 10 * 60 * 1000, }); await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { transactionId: r1.transactionId, diff --git 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(); }