From 7f0edb6a783d9a50f94f65c815c1280baecaac89 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 5 May 2023 19:03:44 +0200 Subject: wallet-core: refund DD37 refactoring --- packages/taler-wallet-core/src/wallet.ts | 33 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'packages/taler-wallet-core/src/wallet.ts') diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index ed174e33b..d76aa4ec9 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -48,6 +48,7 @@ import { RefreshReason, TalerError, TalerErrorCode, + TransactionType, URL, ValidateIbanResponse, WalletCoreVersion, @@ -95,6 +96,7 @@ import { codecForRetryTransactionRequest, codecForSetCoinSuspendedRequest, codecForSetWalletDeviceIdRequest, + codecForStartRefundQueryRequest, codecForSuspendTransaction, codecForTestPayArgs, codecForTransactionByIdRequest, @@ -188,13 +190,11 @@ import { } from "./operations/exchanges.js"; import { getMerchantInfo } from "./operations/merchants.js"; import { - applyRefund, - applyRefundFromPurchaseId, confirmPay, getContractTermsDetails, preparePayForUri, - prepareRefund, processPurchase, + startRefundQueryForUri, } from "./operations/pay-merchant.js"; import { checkPeerPullPaymentInitiation, @@ -233,6 +233,7 @@ import { deleteTransaction, getTransactionById, getTransactions, + parseTransactionIdentifier, resumeTransaction, retryTransaction, suspendTransaction, @@ -276,6 +277,7 @@ import { WalletCoreApiClient, WalletCoreResponseType, } from "./wallet-api-types.js"; +import { startQueryRefund } from "./operations/pay-merchant.js"; const logger = new Logger("wallet.ts"); @@ -1141,14 +1143,6 @@ async function dispatchRequestInternal( await acceptExchangeTermsOfService(ws, req.exchangeBaseUrl, req.etag); return {}; } - case WalletApiOperation.ApplyRefund: { - const req = codecForApplyRefundRequest().decode(payload); - return await applyRefund(ws, req.talerRefundUri); - } - case WalletApiOperation.ApplyRefundFromPurchaseId: { - const req = codecForApplyRefundFromPurchaseIdRequest().decode(payload); - return await applyRefundFromPurchaseId(ws, req.purchaseId); - } case WalletApiOperation.AcceptBankIntegratedWithdrawal: { const req = codecForAcceptBankIntegratedWithdrawalRequest().decode(payload); @@ -1292,9 +1286,22 @@ async function dispatchRequestInternal( const req = codecForPrepareTipRequest().decode(payload); return await prepareTip(ws, req.talerTipUri); } - case WalletApiOperation.PrepareRefund: { + case WalletApiOperation.StartRefundQueryForUri: { const req = codecForPrepareRefundRequest().decode(payload); - return await prepareRefund(ws, req.talerRefundUri); + await startRefundQueryForUri(ws, req.talerRefundUri); + return {}; + } + case WalletApiOperation.StartRefundQuery: { + const req = codecForStartRefundQueryRequest().decode(payload); + const txIdParsed = parseTransactionIdentifier(req.transactionId); + if (!txIdParsed) { + throw Error("invalid transaction ID"); + } + if (txIdParsed.tag !== TransactionType.Payment) { + throw Error("expected payment transaction ID"); + } + await startQueryRefund(ws, txIdParsed.proposalId); + return {}; } case WalletApiOperation.AcceptTip: { const req = codecForAcceptTipRequest().decode(payload); -- cgit v1.2.3