taler-typescript-core

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

commit 3613f5d020ac6c59c50c569b0a7aa88ee76bee1a
parent 43398c91ee3a04943c989b666c3eebac8b035f0a
Author: Florian Dold <florian@dold.me>
Date:   Wed, 30 Oct 2024 11:28:23 +0100

wallet-core: always returns scopes in preparePay

Diffstat:
Mpackages/taler-util/src/types-taler-wallet.ts | 34+++++++++++++++++++++++++++++++---
Mpackages/taler-wallet-core/src/pay-merchant.ts | 22+++++++++++++++++++---
2 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -849,6 +849,7 @@ export const codecForPreparePayResultInsufficientBalance = "status", codecForConstString(PreparePayResultType.InsufficientBalance), ) + .property("scopes", codecForList(codecForScopeInfo())) .property( "balanceDetails", codecForPayMerchantInsufficientBalanceDetails(), @@ -864,6 +865,7 @@ export const codecForPreparePayResultAlreadyConfirmed = ) .property("amountEffective", codecOptional(codecForAmountString())) .property("amountRaw", codecForAmountString()) + .property("scopes", codecForList(codecForScopeInfo())) .property("paid", codecForBoolean()) .property("talerUri", codecForString()) .property("contractTerms", codecForAny()) @@ -935,29 +937,55 @@ export interface PreparePayResultPaymentPossible { export interface PreparePayResultInsufficientBalance { status: PreparePayResultType.InsufficientBalance; transactionId: TransactionIdStr; + /** - * @deprecated use transactionId + * Scopes involved in this transaction. + * + * For the insufficient balance response, contains scopes + * of *possible* payment providers. */ - proposalId: string; + scopes: ScopeInfo[]; + contractTerms: MerchantContractTerms; + amountRaw: AmountString; + talerUri: string; + balanceDetails: PaymentInsufficientBalanceDetails; + + /** + * @deprecated use transactionId + */ + proposalId: string; } export interface PreparePayResultAlreadyConfirmed { status: PreparePayResultType.AlreadyConfirmed; + transactionId: TransactionIdStr; + contractTerms: MerchantContractTerms; + paid: boolean; + amountRaw: AmountString; + amountEffective: AmountString | undefined; + + /** + * Scopes involved in this transaction. + */ + scopes: ScopeInfo[]; + contractTermsHash: string; + + talerUri: string; + /** * @deprecated use transactionId */ proposalId: string; - talerUri: string; } export interface BankWithdrawDetails { diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts @@ -1621,6 +1621,10 @@ async function checkPaymentByProposalId( let coins: SelectedProspectiveCoin[] | undefined = undefined; + const allowedExchangeUrls = contractData.allowedExchanges.map( + (x) => x.exchangeBaseUrl, + ); + switch (res.type) { case "failure": { logger.info("not allowing payment, insufficient coins"); @@ -1629,12 +1633,16 @@ async function checkPaymentByProposalId( res.insufficientBalanceDetails, )}`, ); + let scopes = await wex.db.runAllStoresReadOnlyTx({}, async (tx) => { + return getScopeForAllExchanges(tx, allowedExchangeUrls); + }); return { status: PreparePayResultType.InsufficientBalance, contractTerms: d.contractTermsRaw, proposalId: proposal.proposalId, transactionId, amountRaw: Amounts.stringify(d.contractData.amount), + scopes, talerUri, balanceDetails: res.insufficientBalanceDetails, }; @@ -1653,9 +1661,7 @@ async function checkPaymentByProposalId( logger.trace("costInfo", totalCost); logger.trace("coinsForPayment", res); - const exchanges = new Set<string>(); - - coins.map((x) => exchanges.add(x.exchangeBaseUrl)); + const exchanges = new Set<string>(coins.map((x) => x.exchangeBaseUrl)); const scopes = await wex.db.runAllStoresReadOnlyTx({}, async (tx) => { return await getScopeForAllExchanges(tx, [...exchanges]); @@ -1674,6 +1680,13 @@ async function checkPaymentByProposalId( }; } + const scopes = await wex.db.runAllStoresReadOnlyTx({}, async (tx) => { + let exchangeUrls = contractData.allowedExchanges.map( + (x) => x.exchangeBaseUrl, + ); + return await getScopeForAllExchanges(tx, exchangeUrls); + }); + if ( purchase.purchaseStatus === PurchaseStatus.Done || purchase.purchaseStatus === PurchaseStatus.PendingPayingReplay @@ -1715,6 +1728,7 @@ async function checkPaymentByProposalId( amountEffective: purchase.payInfo ? Amounts.stringify(purchase.payInfo.totalPayCost) : undefined, + scopes, transactionId, proposalId, talerUri, @@ -1730,6 +1744,7 @@ async function checkPaymentByProposalId( amountEffective: purchase.payInfo ? Amounts.stringify(purchase.payInfo.totalPayCost) : undefined, + scopes, transactionId, proposalId, talerUri, @@ -1747,6 +1762,7 @@ async function checkPaymentByProposalId( ? Amounts.stringify(purchase.payInfo.totalPayCost) : undefined, ...(paid ? { nextUrl: download.contractData.orderId } : {}), + scopes, transactionId, proposalId, talerUri,