commit 89b60325e863184e1aac472b5063096be3a37506 parent f277308be93405178fed4bd3b7de3ff60e37596d Author: Florian Dold <dold@taler.net> Date: Fri, 27 Nov 2026 16:30:04 +0100 wallet-core: return from confirmPay before the merchant responds Return the transaction ID once confirmation is recorded. Callers that need the payment outcome observe the transaction, and standalone CLI commands keep their wallet running through the first attempt. Issue: https://bugs.taler.net/n/9812 Diffstat:
44 files changed, 224 insertions(+), 410 deletions(-)
diff --git a/packages/taler-harness/src/harness/environments.ts b/packages/taler-harness/src/harness/environments.ts @@ -32,7 +32,6 @@ import { AmountString, assertUnreachable, Configuration, - ConfirmPayResultType, decodeCrock, Duration, encodeCrock, @@ -801,13 +800,11 @@ export async function makeTestPaymentV2( orderStatus.taler_pay_uri, ); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts @@ -30,6 +30,7 @@ import { Amounts, BasicAuth, BasicOrTokenAuth, + ConfirmPayRequest, ConfigSources, Configuration, CoreApiResponse, @@ -60,6 +61,8 @@ import { TokenAuth, Transaction, TransactionIdStr, + TransactionMajorState, + TransactionMinorState, WalletNotification, assertUnreachable, codecForAccountKycRedirects, @@ -3638,6 +3641,49 @@ export class WalletClient { return getClientFromRemoteWallet(this.remoteWallet); } + /** Confirm and wait until the merchant payment succeeds, including orders in auto-refund monitoring. */ + async confirmPayAndWait(request: ConfirmPayRequest): Promise<void> { + const { transactionId } = await this.call( + WalletApiOperation.ConfirmPay, + request, + ); + const result = await this.call(WalletApiOperation.WaitTransactionState, { + transactionId, + txState: [ + { major: TransactionMajorState.Done }, + { + major: TransactionMajorState.Finalizing, + minor: TransactionMinorState.AutoRefund, + }, + ], + bailStates: "nonpending", + bailOnError: true, + }); + if (result.matched !== "target") { + const tx = await this.getTx(transactionId); + throw Error( + `payment ${transactionId} did not succeed: ${j2s(tx.failReason ?? tx.abortReason ?? tx.error ?? tx.txState)}`, + ); + } + } + + async waitForPaymentRetry(transactionId: TransactionIdStr): Promise<void> { + const result = await this.call(WalletApiOperation.WaitTransactionState, { + transactionId, + txState: { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.SubmitPayment, + }, + requireError: true, + bailStates: "nonpending", + }); + if (result.matched !== "target") { + throw Error( + `payment ${transactionId} reached ${j2s(result.txState)} before retrying`, + ); + } + } + async getTx(id: TransactionIdStr): Promise<Transaction> { return this.call(WalletApiOperation.GetTransactionById, { transactionId: id, diff --git a/packages/taler-harness/src/integrationtests/test-donau-keychange.ts b/packages/taler-harness/src/integrationtests/test-donau-keychange.ts @@ -19,7 +19,6 @@ */ import { AmountString, - ConfirmPayResultType, DonauHttpClient, j2s, MerchantContractOutputType, @@ -208,16 +207,14 @@ export async function runDonauKeychangeTest(t: GlobalTestState) { // t.assertAmountEquals(outTok.amount, "TESTKUDOS:5"); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + // The donau's keys changed under the merchant, and both sides refresh + // them, so the payment goes through. + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, useDonau: true, }); - // The donau's keys changed under the merchant, and both sides refresh - // them, so the payment goes through. - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Merchant should still be running and not crash! orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-donau-minus-t.ts b/packages/taler-harness/src/integrationtests/test-donau-minus-t.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, DonauHttpClient, j2s, MerchantContractOutputType, @@ -166,14 +165,12 @@ export async function runDonauMinusTTest(t: GlobalTestState) { // t.assertAmountEquals(outTok.amount, "TESTKUDOS:5"); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, useDonau: true, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-donau-multi.ts b/packages/taler-harness/src/integrationtests/test-donau-multi.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, DonauHttpClient, Duration, j2s, @@ -229,14 +228,12 @@ export async function runDonauMultiTest(t: GlobalTestState) { // t.assertAmountEquals(outTok.amount, "TESTKUDOS:5"); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, useDonau: true, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-donau.ts b/packages/taler-harness/src/integrationtests/test-donau.ts @@ -19,7 +19,6 @@ */ import { AmountString, - ConfirmPayResultType, DonauHttpClient, j2s, MerchantContractOutputType, @@ -202,14 +201,12 @@ export async function runDonauTest(t: GlobalTestState) { // t.assertAmountEquals(outTok.amount, "TESTKUDOS:5"); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, useDonau: true, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts b/packages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts @@ -16,7 +16,6 @@ import { AbsoluteTime, - ConfirmPayResultType, Duration, j2s, succeedOrThrow, @@ -141,13 +140,11 @@ export async function runMerchantDepositLargeTest(t: GlobalTestState) { console.log(`wire transfer deadline in ${diff.d_ms}ms`); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts @@ -19,8 +19,6 @@ */ import { codecForMerchantOrderStatusUnpaid, - ConfirmPayResultType, - j2s, succeedOrThrow, TalerErrorCode, TalerMerchantInstanceHttpClient, @@ -308,22 +306,19 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) { choiceIndex: 0, }); - t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Pending); - - console.log(j2s(confirmPayRes.lastError)); - - // Merchant should not accept the payment! - // Something is clearly wrong, as the exchange now announces - // its own base URL and something is wrong. + await walletClient.call(WalletApiOperation.WaitTransactionState, { + transactionId: confirmPayRes.transactionId, + txState: "nonpending", + }); + // The merchant's rejection is the payment failure reason. Recovery can + // encounter a separate error while trying to abort the deposit. + const { failReason } = await walletClient.getTx(confirmPayRes.transactionId); t.assertDeepEqual( - confirmPayRes.lastError?.code, + failReason?.code, TalerErrorCode.MERCHANT_GENERIC_EXCHANGE_UNTRUSTED, ); - t.assertDeepEqual( - (confirmPayRes.lastError as any).detail, - faultyExchange.baseUrl, - ); + t.assertDeepEqual(failReason?.detail, faultyExchange.baseUrl); } runMerchantExchangeConfusionTest.suites = ["merchant"]; diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts b/packages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, Duration, HttpStatusCode, MerchantAuthMethod, @@ -366,11 +365,10 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { t.assertDeepEqual(again.transactionId, preparePayResult.transactionId); } - const confirmResp = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertDeepEqual(confirmResp.type, ConfirmPayResultType.Done); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts b/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, @@ -173,13 +172,11 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) { const proposalTransactionId = preparePayResp.transactionId; - const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.call(WalletApiOperation.ConfirmPay, { transactionId: proposalTransactionId, choiceIndex: 0, }); - t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); - publicOrderStatusResp = await publicOrderStatusPromise; t.assertDeepEqual(publicOrderStatusResp.status, 200); codecForMerchantOrderStatusPaid().decode(await publicOrderStatusResp.json()); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-payto-reuse.ts b/packages/taler-harness/src/integrationtests/test-merchant-payto-reuse.ts @@ -20,7 +20,6 @@ import { AccessToken, Configuration, - ConfirmPayResultType, encodeCrock, getRandomBytes, succeedOrThrow, @@ -212,13 +211,11 @@ export async function runMerchantPaytoReuseTest(t: GlobalTestState) { }, }); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( @@ -266,13 +263,11 @@ export async function runMerchantPaytoReuseTest(t: GlobalTestState) { }, }); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts b/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts @@ -76,7 +76,7 @@ async function testRefundApi( minor: TransactionMinorState.Proposed, }, }); - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-sessions.ts b/packages/taler-harness/src/integrationtests/test-merchant-sessions.ts @@ -12,7 +12,6 @@ */ import { - ConfirmPayResultType, HttpStatusCode, succeedOrThrow, TalerMerchantInstanceHttpClient, @@ -133,11 +132,10 @@ export async function runMerchantSessionsTest(t: GlobalTestState) { t.assertTrue(wrongFulfillment.type === "fail"); t.assertDeepEqual(wrongFulfillment.response.status, HttpStatusCode.NotFound); - const confirmPay = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.call(WalletApiOperation.ConfirmPay, { transactionId: preparePay.transactionId, choiceIndex: 0, }); - t.assertTrue(confirmPay.type === ConfirmPayResultType.Done); const paidSession = succeedOrThrow(await paidSessionPromise); t.assertDeepEqual(paidSession.paid, true); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts @@ -9,7 +9,6 @@ import { AccessToken, - ConfirmPayResultType, encodeCrock, getRandomBytes, succeedOrThrow, @@ -136,11 +135,10 @@ async function testPublicOrderScenario( await getJson(t, correctHashUrl, 402); await getJson(t, orderUrl(), useClaimToken ? 202 : 402); - const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResp.transactionId, choiceIndex: 0, }); - t.assertDeepEqual(confirmPayRes.type, ConfirmPayResultType.Done); await getJson(t, orderUrl(), useClaimToken ? 202 : 200); await getJson(t, wrongHashUrl, 403); @@ -153,11 +151,23 @@ async function testPublicOrderScenario( }); t.assertDeepEqual(paidHtmlResp.status, 200); - const confirmPayWithSession = await walletClient.call( - WalletApiOperation.ConfirmPay, - { transactionId: preparePayResp.transactionId, sessionId }, + const replay = await walletClient.call(WalletApiOperation.ConfirmPay, { + transactionId: preparePayResp.transactionId, + sessionId, + }); + t.assertDeepEqual(replay, { + type: "pending", + transactionId: preparePayResp.transactionId, + }); + const paidSession = succeedOrThrow( + await merchantClient.getOrderIdForSessionAndUrl( + sessionId, + paidBody.fulfillment_url, + { timeout: 10_000 }, + ), ); - t.assertDeepEqual(confirmPayWithSession.type, ConfirmPayResultType.Done); + t.assertDeepEqual(paidSession.paid, true); + t.assertDeepEqual(paidSession.order_id, orderId); const alreadyPaidOrder = succeedOrThrow(await createOrder()); const alreadyPaidUrl = () => { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-webui-simple.ts b/packages/taler-harness/src/integrationtests/test-merchant-webui-simple.ts @@ -508,7 +508,7 @@ async function testOrdersFlowAndPayment( await saveScreenshot("08d-order-claimed-detail"); // 3. Confirm pay with wallet -> Order transitions to PAID - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: prepareRes.transactionId, choiceIndex: 0, }); @@ -586,7 +586,7 @@ async function testRefundFlow( }, }); - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: prepareRes.transactionId, choiceIndex: 0, }); diff --git a/packages/taler-harness/src/integrationtests/test-multiexchange.ts b/packages/taler-harness/src/integrationtests/test-multiexchange.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, Duration, openPromise, RefreshReason, @@ -397,7 +396,7 @@ export async function runMultiExchangeTest(t: GlobalTestState) { choiceIndex: 0, }, ); - t.assertDeepEqual(confirmAbortPay.type, ConfirmPayResultType.Pending); + await walletClient.waitForPaymentRetry(confirmAbortPay.transactionId); observeDepositedCoinConflict = true; holdSecondExchangeMelt = true; diff --git a/packages/taler-harness/src/integrationtests/test-otp.ts b/packages/taler-harness/src/integrationtests/test-otp.ts @@ -58,7 +58,6 @@ import { generateConfirmationChallenge, parseChallengeConfirmationAlgorithm, verifyChallengeConfirmation, - ConfirmPayResultType, Duration, TalerMerchantInstanceHttpClient, TemplateType, @@ -137,13 +136,11 @@ async function runOtpAlgorithmTest(t: GlobalTestState, algorithm: number) { // Pay for it - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertTrue(r2.type === ConfirmPayResultType.Done); - const transaction = await walletClient.call( WalletApiOperation.GetTransactionById, { diff --git a/packages/taler-harness/src/integrationtests/test-pay-paid.ts b/packages/taler-harness/src/integrationtests/test-pay-paid.ts @@ -19,7 +19,6 @@ */ import { Duration, - ConfirmPayResultType, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, @@ -162,13 +161,11 @@ export async function runPayPaidTest(t: GlobalTestState) { await publicOrderStatusResp.json(), ); - const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: proposalTransactionId, choiceIndex: 0, }); - t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); - publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl); console.log(await publicOrderStatusResp.json()); diff --git a/packages/taler-harness/src/integrationtests/test-payment-abort.ts b/packages/taler-harness/src/integrationtests/test-payment-abort.ts @@ -19,7 +19,6 @@ */ import { Duration, - ConfirmPayResultType, Amounts, TalerErrorCode, TalerErrorDetail, @@ -170,8 +169,8 @@ export async function runPaymentAbortTest(t: GlobalTestState) { }, ); - // Can't have succeeded yet, but network error results in "pending" state. - t.assertDeepEqual(confirmPayResp.type, ConfirmPayResultType.Pending); + // Abort after the first unsuccessful submission. + await walletClient.waitForPaymentRetry(confirmPayResp.transactionId); const txns = await walletClient.call(WalletApiOperation.GetTransactions, { sort: "stable-ascending", diff --git a/packages/taler-harness/src/integrationtests/test-payment-claim.ts b/packages/taler-harness/src/integrationtests/test-payment-claim.ts @@ -231,7 +231,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) { t.assertDeepEqual(holderTx.txState.major, TransactionMajorState.Dialog); }); - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-multiple.ts b/packages/taler-harness/src/integrationtests/test-payment-multiple.ts @@ -199,7 +199,7 @@ export async function runPaymentMultipleTest(t: GlobalTestState) { }, }); - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: r1.transactionId, choiceIndex: 0, }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-order-gone.ts b/packages/taler-harness/src/integrationtests/test-payment-order-gone.ts @@ -19,7 +19,6 @@ */ import { AmountString, - ConfirmPayResultType, succeedOrThrow, TalerMerchantInstanceHttpClient, TransactionMajorState, @@ -113,11 +112,10 @@ export async function runPaymentOrderGoneTest(t: GlobalTestState) { minor: TransactionMinorState.Proposed, }, }); - const confirmResp = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: prep.transactionId, choiceIndex: 0, }); - t.assertTrue(confirmResp.type === ConfirmPayResultType.Done); succeedOrThrow( await merchantClient.deleteOrder( diff --git a/packages/taler-harness/src/integrationtests/test-payment-template.ts b/packages/taler-harness/src/integrationtests/test-payment-template.ts @@ -21,7 +21,6 @@ import { Amounts, AmountString, CheckPayTemplateReponse, - ConfirmPayResultType, Duration, TalerMerchantInstanceHttpClient, TemplateType, @@ -157,13 +156,11 @@ export async function runPaymentTemplateTest(t: GlobalTestState) { // Pay for it - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertTrue(r2.type === ConfirmPayResultType.Done); - // Check if payment was successful. const orderStatus = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-payment-transient.ts b/packages/taler-harness/src/integrationtests/test-payment-transient.ts @@ -19,7 +19,7 @@ */ import { Duration, - ConfirmPayResultType, + openPromise, TalerErrorCode, TalerErrorDetail, TalerMerchantInstanceHttpClient, @@ -150,6 +150,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) { let injectFault = true; let numFaultResponses = 0; + const allowPayResponse = openPromise<void>(); faultyMerchant.faultProxy.addFault({ async modifyResponse(ctx: FaultInjectionResponseContext) { @@ -159,6 +160,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) { if (!url.pathname.endsWith("/pay")) { return; } + await allowPayResponse.promise; if (!injectFault) { console.log("not injecting pay fault"); return; @@ -182,9 +184,17 @@ export async function runPaymentTransientTest(t: GlobalTestState) { }, ); - console.log(confirmPayResp); + // The first merchant reply is still held when confirmation returns. + const submitted = await walletClient.getTx(proposalTransactionId); + allowPayResponse.resolve(); + t.assertDeepEqual(confirmPayResp, { + type: "pending", + transactionId: proposalTransactionId, + }); + t.assertDeepEqual(submitted.txState.major, TransactionMajorState.Pending); + t.assertDeepEqual(submitted.error, undefined); - t.assertTrue(confirmPayResp.type === ConfirmPayResultType.Pending); + await walletClient.waitForPaymentRetry(confirmPayResp.transactionId); t.assertTrue(numFaultResponses > 0); // Stop injecting faults diff --git a/packages/taler-harness/src/integrationtests/test-payment-unclaim.ts b/packages/taler-harness/src/integrationtests/test-payment-unclaim.ts @@ -8,7 +8,6 @@ */ import { AmountString, - ConfirmPayResultType, Result, succeedOrThrow, TalerMerchantInstanceHttpClient, @@ -165,11 +164,10 @@ export async function runPaymentUnclaimTest(t: GlobalTestState) { }, }); - const paid = await secondWallet.call(WalletApiOperation.ConfirmPay, { + await secondWallet.call(WalletApiOperation.ConfirmPay, { transactionId: secondPrepared.transactionId, choiceIndex: 0, }); - t.assertTrue(paid.type === ConfirmPayResultType.Done); await firstWallet.call(WalletApiOperation.TestingWaitTransactionState, { transactionId: firstPrepared.transactionId, txState: { diff --git a/packages/taler-harness/src/integrationtests/test-paywall-flow.ts b/packages/taler-harness/src/integrationtests/test-paywall-flow.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, @@ -149,12 +148,10 @@ export async function runPaywallFlowTest(t: GlobalTestState) { await publicOrderStatusResp.json(), ); - const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: proposalTransactionId, choiceIndex: 0, }); - - t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href); console.log(await publicOrderStatusResp.json()); diff --git a/packages/taler-harness/src/integrationtests/test-repurchase.ts b/packages/taler-harness/src/integrationtests/test-repurchase.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, j2s, succeedOrThrow, TalerMerchantApi, @@ -129,14 +128,10 @@ export async function runRepurchaseTest(t: GlobalTestState) { }, }); - const confirmPayResp = await walletClient.call( - WalletApiOperation.ConfirmPay, - { - transactionId: preparePayOneResult.transactionId, - choiceIndex: 0, - }, - ); - t.assertTrue(confirmPayResp.type === ConfirmPayResultType.Done); + await walletClient.confirmPayAndWait({ + transactionId: preparePayOneResult.transactionId, + choiceIndex: 0, + }); const orderTwoResp = succeedOrThrow( await merchantClient.createOrder(merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts b/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts @@ -268,7 +268,7 @@ export async function runWalletTokensTest(t: GlobalTestState) { }, }); - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex, }); @@ -356,7 +356,7 @@ export async function runWalletTokensTest(t: GlobalTestState) { } } - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex, }); @@ -578,7 +578,7 @@ export async function runWalletTokensTest(t: GlobalTestState) { }, }); - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex, }); @@ -656,7 +656,7 @@ export async function runWalletTokensTest(t: GlobalTestState) { } } - await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex, }); diff --git a/packages/taler-harness/src/integrationtests/test-wire-metadata.ts b/packages/taler-harness/src/integrationtests/test-wire-metadata.ts @@ -18,7 +18,6 @@ * Imports. */ import { - ConfirmPayResultType, Duration, j2s, LoginTokenScope, @@ -249,13 +248,11 @@ export async function runWireMetadataTest(t: GlobalTestState) { }, }); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { + await walletClient.confirmPayAndWait({ transactionId: preparePayResult.transactionId, choiceIndex: 0, }); - t.assertDeepEqual(r2.type, ConfirmPayResultType.Done); - // Check if payment was successful. orderStatus = succeedOrThrow( diff --git a/packages/taler-util/src/types-taler-wallet.test.ts b/packages/taler-util/src/types-taler-wallet.test.ts @@ -18,12 +18,23 @@ import assert from "node:assert"; import { test } from "node:test"; import { + codecForConfirmPayRequest, codecForListWithdrawalExchangeCandidatesRequest, codecForTestingWaitTransactionRequest, codecForWaitTransactionStateRequest, matchTransactionState, } from "./types-taler-wallet.js"; +test("payment confirmation ignores the former noWait option from older clients", () => { + const codec = codecForConfirmPayRequest(); + const request = { transactionId: "txn:payment:test", choiceIndex: 0 }; + const expected = codec.decode(request); + assert.ok(!("noWait" in expected)); + for (const noWait of [true, false]) { + assert.deepStrictEqual(codec.decode({ ...request, noWait }), expected); + } +}); + test("withdrawal exchange candidates support selection flags", () => { const codec = codecForListWithdrawalExchangeCandidatesRequest(); assert.deepStrictEqual( diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -97,7 +97,6 @@ import { } from "./types-taler-exchange.js"; import { MerchantContractTerms, - MerchantContractTermsV0, MerchantContractTermsV1, MerchantInfo, TokenEnvelope, @@ -852,23 +851,13 @@ export interface CoinDumpJson { } export enum ConfirmPayResultType { - Done = "done", Pending = "pending", } -/** - * Result for confirmPay - */ -export interface ConfirmPayResultDone { - type: ConfirmPayResultType.Done; - contractTerms: MerchantContractTermsV0; - transactionId: TransactionIdStr; -} - +/** Payment confirmation was accepted. Observe the transaction for its outcome. */ export interface ConfirmPayResultPending { type: ConfirmPayResultType.Pending; transactionId: TransactionIdStr; - lastError?: TalerErrorDetail | undefined; } export const codecForTalerErrorDetail = (): Codec<TalerErrorDetail> => @@ -878,7 +867,7 @@ export const codecForTalerErrorDetail = (): Codec<TalerErrorDetail> => .property("hint", codecOptional(codecForString())) .build("TalerErrorDetail"); -export type ConfirmPayResult = ConfirmPayResultDone | ConfirmPayResultPending; +export type ConfirmPayResult = ConfirmPayResultPending; export enum InsufficientBalanceHint { /** @@ -3129,15 +3118,6 @@ export interface ConfirmPayRequest { * Only applies to v1 orders. */ choiceIndex?: number; - - /** - * Do not wait for the first payment success or error - * before returning a response. Instead, status will - * be communicated via notifications. - * - * Will become the default in future versions. - */ - noWait?: boolean; } export const codecForConfirmPayRequest = (): Codec<ConfirmPayRequest> => @@ -3149,7 +3129,7 @@ export const codecForConfirmPayRequest = (): Codec<ConfirmPayRequest> => .property("forcedTokenSel", codecOptional(codecForBoolean())) .property("choiceIndex", codecOptional(codecForNumber())) .property("useDonau", codecOptional(codecForBoolean())) - .property("noWait", codecOptional(codecForBoolean())) + .deprecatedProperty("noWait") .build("ConfirmPay"); export interface ListDiscountsRequest { diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts @@ -1759,6 +1759,18 @@ async function settleTos( return ok; } +// A standalone CLI shuts its local wallet down when the command returns. +async function waitForPaymentAttempt( + ctx: WalletContext, + transactionId: TransactionIdStr, +): Promise<void> { + await ctx.client.call(WalletApiOperation.WaitTransactionState, { + transactionId, + txState: "nonpending", + bailOnError: true, + }); +} + /** * Pick a contract choice and pay, asking whoever is there to ask. */ @@ -2064,6 +2076,9 @@ async function runContinueTx( if (!result.performed) { return 0; } + if (!a.wait && cont.kind === ContinuationKind.ConfirmPayment) { + await waitForPaymentAttempt(ctx, transactionId); + } return await waitForCreatedTx(ctx, transactionId, a); }); } @@ -4231,6 +4246,7 @@ advancedCli transactionId, sessionId: args.payConfirm.sessionIdOverride, }); + await waitForPaymentAttempt(wallet, transactionId); }), ); }); diff --git a/packages/taler-wallet-core/src/dev-experiments.ts b/packages/taler-wallet-core/src/dev-experiments.ts @@ -142,9 +142,6 @@ export interface DevExperimentState { blockClaimResponse?: boolean; - /** Migration test for confirmPay */ - flagConfirmPayNoWait?: boolean; - tc?: { dropRequestProbability?: number; dropResponseProbability?: number; @@ -608,10 +605,6 @@ export async function applyDevExperiment( overrides.set(scopeKey, urls); return; } - case "flag-confirm-pay-no-wait": { - wex.ws.devExperimentState.flagConfirmPayNoWait = getValFlag(parsedUri); - return; - } case "fake-chf-bban": { wex.ws.devExperimentState.fakeChfBban = getValFlag(parsedUri); return; diff --git a/packages/taler-wallet-core/src/pay-merchant.test.ts b/packages/taler-wallet-core/src/pay-merchant.test.ts @@ -110,7 +110,6 @@ import { getPayMerchantResumeTransition, getPayMerchantSuspendTransition, getRefundTotals, - isPaymentSessionComplete, isSharedPurchase, isStableMerchantPayFailure, isTransientRefundStatus, @@ -284,7 +283,7 @@ test("merchant confirmation binds the reviewed wallet debit before spending", as const wex = { ws: { devExperimentState: {}, config: { testing: {} } }, runWalletDbTx: runner.runReadWriteTx.bind(runner), - taskScheduler: { resetTask() {}, startShepherdTask() {} }, + taskScheduler: { resetTask() {} }, } as unknown as WalletExecutionContext; const transactionId = "txn:payment:reviewed-debit"; const load = () => @@ -294,7 +293,6 @@ test("merchant confirmation binds the reviewed wallet debit before spending", as confirmPay(wex, { transactionId, expectedAmountEffective, - noWait: true, }), (cause: unknown) => cause instanceof TalerError && @@ -306,12 +304,16 @@ test("merchant confirmation binds the reviewed wallet debit before spending", as assert.equal(stored?.payInfo, undefined); assert.equal(stored?.purchaseStatus, PurchaseStatus.DialogProposed); } - await confirmPay(wex, { + const result = await confirmPay(wex, { transactionId, expectedAmountEffective: "TESTKUDOS:0.00", - noWait: true, }); - assert.equal((await load())?.payInfo?.totalPayCost, "TESTKUDOS:0"); + assert.deepEqual(result, { type: "pending", transactionId }); + assert.equal((await load())?.purchaseStatus, PurchaseStatus.PendingPaying); + const beforeRepeat = await load(); + assert.equal(beforeRepeat?.payInfo?.totalPayCost, "TESTKUDOS:0"); + assert.deepEqual(await confirmPay(wex, { transactionId }), result); + assert.deepEqual(await load(), beforeRepeat); } finally { await runner.close(); } @@ -2628,25 +2630,6 @@ test("claimed contract terms are bound to the requested order and nonce", () => ); }); -test("payment replay waits for the requested session to finish", () => { - const purchase = { - timestampFirstSuccessfulPay: 1, - lastSessionId: "new-session", - purchaseStatus: PurchaseStatus.PendingPayingReplay, - } as Pick< - WalletPurchase, - "timestampFirstSuccessfulPay" | "lastSessionId" | "purchaseStatus" - >; - - assert.strictEqual(isPaymentSessionComplete(purchase, "new-session"), false); - purchase.purchaseStatus = PurchaseStatus.Done; - assert.strictEqual(isPaymentSessionComplete(purchase, "new-session"), true); - assert.strictEqual( - isPaymentSessionComplete(purchase, "other-session"), - false, - ); -}); - test("a concurrent session request is retained for replay", () => { const purchase = { lastSessionId: "first-session", diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts @@ -129,7 +129,6 @@ import { constructTaskIdentifier, DbRetryInfo, genericWaitForState, - genericWaitForStateVal, getGenericRecordHandle, LookupFullTransactionOpts, PendingTaskType, @@ -3091,138 +3090,6 @@ export async function generateDepositPermissions( } } -/** - * Wait until either: - * a) the payment succeeded (if provided under the {@param waitSessionId}), or - * b) the attempt to pay failed (merchant unavailable, etc.) - */ -async function waitPaymentResult( - wex: WalletExecutionContext, - proposalId: string, - waitSessionId?: string, -): Promise<ConfirmPayResult> { - const ctx = new PayMerchantTransactionContext(wex, proposalId); - wex.taskScheduler.startShepherdTask(ctx.taskId); - - logger.info(`waiting for payment result on ${ctx.transactionId}`); - - return await genericWaitForStateVal<ConfirmPayResult>(wex, { - filterNotification(notif) { - return ( - notif.type === NotificationType.TransactionStateTransition && - notif.transactionId === ctx.transactionId - ); - }, - async checkState() { - const txRes = await ctx.wex.runWalletDbTx(async (tx) => { - const purchase = await tx.getPurchase(ctx.proposalId); - const retryRecord = await tx.getOperationRetry(ctx.taskId); - return { purchase, retryRecord }; - }); - - if (!txRes.purchase) { - throw Error("purchase gone"); - } - - const purchase = txRes.purchase; - - logger.info( - `purchase is in state ${PurchaseStatus[purchase.purchaseStatus]}`, - ); - - const d = await expectProposalDownload(ctx.wex, purchase); - - if (isPaymentSessionComplete(txRes.purchase, waitSessionId)) { - return { - type: ConfirmPayResultType.Done, - contractTerms: d.contractTermsRaw, - transactionId: ctx.transactionId, - }; - } - - if ( - (purchase.purchaseStatus === PurchaseStatus.SuspendedPaying || - purchase.purchaseStatus === PurchaseStatus.SuspendedPayingReplay) && - txRes.retryRecord?.lastError - ) { - return { - type: ConfirmPayResultType.Pending, - lastError: txRes.retryRecord.lastError, - transactionId: ctx.transactionId, - }; - } - - if (txRes.retryRecord && txRes.retryRecord.retryInfo.retryCounter > 0) { - logger.info( - `stopping waiting for payment result, got retry record: ${j2s( - txRes.retryRecord, - )}`, - ); - return { - type: ConfirmPayResultType.Pending, - lastError: txRes.retryRecord.lastError, - transactionId: ctx.transactionId, - }; - } - - if ( - isUnsuccessfulTransaction(computePayMerchantTransactionState(purchase)) - ) { - // The payment gave up instead of going through. Reporting it as done - // would tell the caller that the purchase succeeded, so it is - // reported like a payment that has not happened (yet), with whatever - // reason the transaction recorded for giving up. - return { - type: ConfirmPayResultType.Pending, - lastError: purchase.failReason ?? purchase.abortReason, - transactionId: ctx.transactionId, - }; - } - - if (txRes.purchase.purchaseStatus >= PurchaseStatus.Done) { - if (waitSessionId !== undefined) { - // A terminal payment only proves the session recorded with its - // authenticated /pay or /paid response. A concurrent caller that - // requested another session must not be told that session is done. - return { - type: ConfirmPayResultType.Pending, - transactionId: ctx.transactionId, - }; - } - return { - type: ConfirmPayResultType.Done, - contractTerms: d.contractTermsRaw, - transactionId: ctx.transactionId, - }; - } - - return undefined; - }, - }); -} - -export function isPaymentSessionComplete( - purchase: Pick< - WalletPurchase, - "timestampFirstSuccessfulPay" | "lastSessionId" | "purchaseStatus" - >, - waitSessionId?: string, -): boolean { - if (!purchase.timestampFirstSuccessfulPay) { - return false; - } - if (waitSessionId == null) { - return true; - } - if (purchase.lastSessionId !== waitSessionId) { - return false; - } - return ![ - PurchaseStatus.PendingPayingReplay, - PurchaseStatus.SuspendedPayingReplay, - ].includes(purchase.purchaseStatus); -} - export async function getChoicesForPayment( wex: WalletExecutionContext, transactionId: string, @@ -3545,11 +3412,9 @@ export async function confirmPay( forcedCoinSel?: ForcedCoinSel; choiceIndex?: number; useDonau?: boolean; - noWait?: boolean; }, ): Promise<ConfirmPayResult> { - const { transactionId, sessionIdOverride, forcedCoinSel } = args; - let { choiceIndex } = args; + const { transactionId, sessionIdOverride, forcedCoinSel, choiceIndex } = args; const parsedTx = parseTransactionIdentifier(transactionId); if (parsedTx?.tag !== TransactionType.Payment) { @@ -3580,45 +3445,35 @@ export async function confirmPay( ); } - const existingPurchase = await wex.runWalletDbTx(async (tx) => { + const alreadyConfirmed = await wex.runWalletDbTx(async (tx) => { const purchase = await tx.getPurchase(proposalId); + if (!purchase?.payInfo) { + return false; + } + if (choiceIndex !== undefined && choiceIndex !== purchase.choiceIndex) { + throw TalerError.fromDetail( + TalerErrorCode.WALLET_CORE_API_BAD_REQUEST, + { parameter: "choiceIndex" }, + "the choice index of an existing purchase cannot be changed", + ); + } if ( - purchase?.payInfo && sessionIdOverride !== undefined && applyPaySessionRequest(purchase, sessionIdOverride) ) { await tx.upsertPurchase(purchase); await ctx.updateTransactionMeta(tx); } - return purchase; + return true; }); - if (existingPurchase && existingPurchase.payInfo) { - if ( - choiceIndex !== undefined && - choiceIndex !== existingPurchase.choiceIndex - ) { - throw TalerError.fromDetail( - TalerErrorCode.WALLET_CORE_API_BAD_REQUEST, - { parameter: "choiceIndex" }, - "the choice index of an existing purchase cannot be changed", - ); - } - + if (alreadyConfirmed) { logger.trace("confirmPay: submitting payment for existing purchase"); - const ctx = new PayMerchantTransactionContext( - wex, - existingPurchase.proposalId, - ); await wex.taskScheduler.resetTask(ctx.taskId); - if (args.noWait) { - return { - type: ConfirmPayResultType.Pending, - transactionId: transactionId as TransactionIdStr, - lastError: undefined, - }; - } - return waitPaymentResult(wex, proposalId, sessionIdOverride); + return { + type: ConfirmPayResultType.Pending, + transactionId: ctx.transactionId, + }; } logger.trace("confirmPay: purchase record does not exist yet"); @@ -3640,20 +3495,14 @@ export async function confirmPay( const currency = Amounts.currencyOf(amountRaw); if (contractTerms.version === MerchantContractVersion.V1) { - const choicePersistence = await wex.runWalletDbTx(async (tx) => { + await wex.runWalletDbTx(async (tx) => { const [p, h] = await ctx.getRecordHandle(tx); if (!p) { throw makeTransactionNotFoundError(transactionId); } + // The confirmation transaction below also handles a concurrent confirmation. if (p.payInfo) { - if (p.choiceIndex !== choiceIndex) { - throw TalerError.fromDetail( - TalerErrorCode.WALLET_CORE_API_BAD_REQUEST, - { parameter: "choiceIndex" }, - "the choice index of an existing purchase cannot be changed", - ); - } - return "already-confirmed" as const; + return; } switch (p.purchaseStatus) { case PurchaseStatus.DialogShared: @@ -3679,20 +3528,7 @@ export async function confirmPay( await h.update(p, "select-payment-choice", BalanceEffect.None, { detailsChanged, }); - return "selected" as const; }); - - if (choicePersistence === "already-confirmed") { - await wex.taskScheduler.resetTask(ctx.taskId); - if (args.noWait) { - return { - type: ConfirmPayResultType.Pending, - transactionId: transactionId as TransactionIdStr, - lastError: undefined, - }; - } - return waitPaymentResult(wex, proposalId, sessionIdOverride); - } } const sessionId = sessionIdOverride ?? proposedPaymentSession(proposal); @@ -3701,7 +3537,7 @@ export async function confirmPay( `recording payment on ${proposal.orderId} with session ID ${sessionId}`, ); - const paymentPrepared = await wex.runWalletDbTx(async (tx) => { + await wex.runWalletDbTx(async (tx) => { const [p, h] = await ctx.getRecordHandle(tx); if (!p) { throw makeTransactionNotFoundError(transactionId); @@ -3717,10 +3553,13 @@ export async function confirmPay( "the selected payment choice changed while confirming", ); } - if (sessionId !== undefined && applyPaySessionRequest(p, sessionId)) { + if ( + sessionIdOverride !== undefined && + applyPaySessionRequest(p, sessionIdOverride) + ) { await h.update(p, "confirm-pay-session-replay", BalanceEffect.None); } - return false; + return; } switch (p.purchaseStatus) { case PurchaseStatus.DialogShared: @@ -3879,7 +3718,7 @@ export async function confirmPay( if (p.payInfo.payCoinSelection) { const sel = p.payInfo.payCoinSelection; await spendCoins(wex, tx, { - transactionId: transactionId as TransactionIdStr, + transactionId: ctx.transactionId, coinPubs: sel.coinPubs, contributions: sel.coinContributions.map((x) => Amounts.parseOrThrow(x), @@ -3887,35 +3726,14 @@ export async function confirmPay( refreshReason: RefreshReason.PayMerchant, }); } - return true; }); - if (!paymentPrepared) { - await wex.taskScheduler.resetTask(ctx.taskId); - if (args.noWait) { - return { - type: ConfirmPayResultType.Pending, - transactionId: transactionId as TransactionIdStr, - lastError: undefined, - }; - } - return waitPaymentResult(wex, proposalId, sessionIdOverride); - } - - // In case we're sharing the payment and we're long-polling + // Wake the purchase task even if it was long-polling for a shared payment. await wex.taskScheduler.resetTask(ctx.taskId); - - if (args.noWait) { - wex.taskScheduler.startShepherdTask(ctx.taskId); - return { - type: ConfirmPayResultType.Pending, - transactionId: transactionId as TransactionIdStr, - lastError: undefined, - }; - } - - // Wait until we have completed the first attempt to pay. - return waitPaymentResult(wex, proposalId); + return { + type: ConfirmPayResultType.Pending, + transactionId: ctx.transactionId, + }; } export async function processPurchase( diff --git a/packages/taler-wallet-core/src/requests.ts b/packages/taler-wallet-core/src/requests.ts @@ -1471,7 +1471,6 @@ async function handleConfirmPay( forcedCoinSel: undefined, sessionIdOverride: req.sessionId, useDonau: req.useDonau, - noWait: req.noWait ?? wex.ws.devExperimentState.flagConfirmPayNoWait, }); } diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts @@ -33,7 +33,6 @@ import { checkLogicInvariant, CheckPaymentResponse, ChoiceSelectionDetailType, - ConfirmPayResultType, Duration, encodeCrock, getRandomBytes, @@ -328,6 +327,23 @@ async function checkPayment( ); } +async function waitForTestPayment( + wex: WalletExecutionContext, + transactionId: TransactionIdStr, +): Promise<void> { + const result = await waitTransactionState(wex, { + transactionId, + txState: { major: TransactionMajorState.Done }, + bailStates: "nonpending", + bailOnError: true, + }); + if (result.matched !== "target") { + throw Error( + `payment ${transactionId} did not succeed: ${j2s(result.txState)}`, + ); + } +} + interface MakePaymentResult { orderId: string; paymentTransactionId: string; @@ -389,7 +405,7 @@ async function makePayment( choiceIndex: 0, }); - logger.trace("confirmPayResult", confirmPayResult); + await waitForTestPayment(wex, confirmPayResult.transactionId); paymentStatus = await checkPayment(wex, merchant, orderResp.orderId); @@ -1135,9 +1151,7 @@ export async function testPay( choiceIndex: 0, forcedCoinSel: args.forcedCoinSel, }); - if (r.type != ConfirmPayResultType.Done) { - throw Error("payment not done"); - } + await waitForTestPayment(wex, r.transactionId); const purchase = await wex.runWalletDbTx(async (tx) => { const parsedTx = parseTransactionIdentifier(r.transactionId); checkLogicInvariant(parsedTx?.tag === TransactionType.Payment); diff --git a/packages/taler-wallet-core/src/versions.ts b/packages/taler-wallet-core/src/versions.ts @@ -52,7 +52,7 @@ export const WALLET_BANK_CONVERSION_API_PROTOCOL_VERSION = "2:0:0"; /** * Libtool version of the wallet-core API. */ -export const WALLET_CORE_API_PROTOCOL_VERSION = "13:0:1"; +export const WALLET_CORE_API_PROTOCOL_VERSION = "14:0:0"; /** * Libtool rules: diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -999,8 +999,9 @@ export type CheckPayForTemplateOp = { }; /** - * Confirm a payment that was previously prepared with - * {@link PreparePayForUriV2Op} + * Confirm a payment prepared with {@link PreparePayForUriV2Op}. The call + * returns after recording confirmation. Observe the transaction or use + * {@link WaitTransactionStateOp} for its outcome. */ export type ConfirmPayOp = { op: WalletApiOperation.ConfirmPay; diff --git a/packages/wallet-webui/src/routes/payment-model.ts b/packages/wallet-webui/src/routes/payment-model.ts @@ -52,7 +52,6 @@ export function paymentConfirmationRequest( sessionId?: string, ): ConfirmPayRequest { return { - noWait: true, ...(sessionId === undefined ? {} : { sessionId }), transactionId, choiceIndex, diff --git a/packages/wallet-webui/src/testing/demo-wallet.ts b/packages/wallet-webui/src/testing/demo-wallet.ts @@ -1399,9 +1399,8 @@ export class DemoWalletConnection implements WalletConnection { this.emitTransaction(transaction, oldMajor); } return { - type: ConfirmPayResultType.Done, + type: ConfirmPayResultType.Pending, transactionId: transaction.transactionId, - contractTerms: paymentTerms(), } as never; } case WalletApiOperation.CheckPeerPushDebitV2: @@ -1692,7 +1691,7 @@ export class DemoWalletConnection implements WalletConnection { walletCoreVersion: { implementationSemver: "demo", implementationGitHash: "demo", - version: "13:0:1", + version: "14:0:0", }, frontendInfo: request.frontendInfo, database: { backend: "indexeddb", recordCounts: {} }, diff --git a/packages/wallet-webui/test/demo-wallet.test.ts b/packages/wallet-webui/test/demo-wallet.test.ts @@ -81,7 +81,6 @@ test("demo payment mutates balance and emits production notifications", async () transactionId: prepared.value.transactionId, choiceIndex: 0, expectedAmountEffective: "CHF:5.10", - noWait: true, }, ); assert.ok(Result.isOk(confirmed)); diff --git a/packages/wallet-webui/test/payment-model.test.ts b/packages/wallet-webui/test/payment-model.test.ts @@ -83,7 +83,7 @@ test("the QR keeps the released order's credentials and this tab's session", () ); }); -test("payment confirmation always returns immediately", () => { +test("payment confirmation includes the selected choice and reviewed debit", () => { assert.deepEqual( paymentConfirmationRequest( "txn:payment:test" as TransactionIdStr, @@ -94,7 +94,6 @@ test("payment confirmation always returns immediately", () => { { transactionId: "txn:payment:test", choiceIndex: 1, - noWait: true, }, ); assert.deepEqual( @@ -123,7 +122,6 @@ test("payment confirmation always returns immediately", () => { expectedAmountEffective: "CHF:5.25", forcedTokenSel: true, useDonau: true, - noWait: true, }, ); }); diff --git a/packages/wallet-webui/test/transaction-observation-routes.test.tsx b/packages/wallet-webui/test/transaction-observation-routes.test.tsx @@ -1025,7 +1025,10 @@ test("checkout keeps a submitted payment in progress past its deadline", async ( assert.ok(h.view.getByRole("button", { name: "Paying…" })); assert.equal(h.view.queryByText("Payment deadline passed"), null); h.paymentRequests[0].resolve( - Result.of({ type: ConfirmPayResultType.Done }), + Result.of({ + type: ConfirmPayResultType.Pending, + transactionId: h.transactionId, + }), ); } finally { await h.close(); @@ -1415,7 +1418,6 @@ for (const route of ["payment-review", "payment-review-details"] as const) { transactionId: h.transactionId, choiceIndex: 0, expectedAmountEffective: "CHF:5.1", - noWait: true, }); const initial = h.readySnapshot; assert.ok(initial.type === TransactionType.Payment); @@ -1428,14 +1430,11 @@ for (const route of ["payment-review", "payment-review-details"] as const) { payment: null, confirmation: { unavailableReasons: ["not-proposed"] }, }; - // Deliberately return a different URL: navigation must use the snapshot. const reply = { tag: "ok", value: { - type: ConfirmPayResultType.Done, - contractTerms: { - fulfillment_url: "https://merchant.example/response-fulfillment", - }, + type: ConfirmPayResultType.Pending, + transactionId: h.transactionId, }, }; if (order === "response-first") {