From 1392dc47c6489fca1b3a4c036852873495190c36 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 10 Mar 2021 17:11:59 +0100 Subject: finish first complete end-to-end backup/sync test --- packages/taler-wallet-core/src/operations/pay.ts | 68 +++++++++++++----------- 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/pay.ts') diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts index cccbb3cac..03bf9e119 100644 --- a/packages/taler-wallet-core/src/operations/pay.ts +++ b/packages/taler-wallet-core/src/operations/pay.ts @@ -1150,36 +1150,11 @@ async function submitPay( }; } -/** - * Check if a payment for the given taler://pay/ URI is possible. - * - * If the payment is possible, the signature are already generated but not - * yet send to the merchant. - */ -export async function preparePayForUri( +export async function checkPaymentByProposalId( ws: InternalWalletState, - talerPayUri: string, + proposalId: string, + sessionId?: string, ): Promise { - const uriResult = parsePayUri(talerPayUri); - - if (!uriResult) { - throw OperationFailedError.fromCode( - TalerErrorCode.WALLET_INVALID_TALER_PAY_URI, - `invalid taler://pay URI (${talerPayUri})`, - { - talerPayUri, - }, - ); - } - - let proposalId = await startDownloadProposal( - ws, - uriResult.merchantBaseUrl, - uriResult.orderId, - uriResult.sessionId, - uriResult.claimToken, - ); - let proposal = await ws.db.get(Stores.proposals, proposalId); if (!proposal) { throw Error(`could not get proposal ${proposalId}`); @@ -1238,7 +1213,7 @@ export async function preparePayForUri( }; } - if (purchase.lastSessionId !== uriResult.sessionId) { + if (purchase.lastSessionId !== sessionId) { logger.trace( "automatically re-submitting payment with different session ID", ); @@ -1247,7 +1222,7 @@ export async function preparePayForUri( if (!p) { return; } - p.lastSessionId = uriResult.sessionId; + p.lastSessionId = sessionId; await tx.put(Stores.purchases, p); }); const r = await guardOperationException( @@ -1292,6 +1267,39 @@ export async function preparePayForUri( } } +/** + * Check if a payment for the given taler://pay/ URI is possible. + * + * If the payment is possible, the signature are already generated but not + * yet send to the merchant. + */ +export async function preparePayForUri( + ws: InternalWalletState, + talerPayUri: string, +): Promise { + const uriResult = parsePayUri(talerPayUri); + + if (!uriResult) { + throw OperationFailedError.fromCode( + TalerErrorCode.WALLET_INVALID_TALER_PAY_URI, + `invalid taler://pay URI (${talerPayUri})`, + { + talerPayUri, + }, + ); + } + + let proposalId = await startDownloadProposal( + ws, + uriResult.merchantBaseUrl, + uriResult.orderId, + uriResult.sessionId, + uriResult.claimToken, + ); + + return checkPaymentByProposalId(ws, proposalId, uriResult.sessionId); +} + /** * Generate deposit permissions for a purchase. * -- cgit v1.2.3