diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-merchant.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-merchant.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index 5d58f4c2f..a81311702 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -30,11 +30,13 @@ import { AbsoluteTime, AmountJson, Amounts, + AmountString, codecForAbortResponse, codecForMerchantContractTerms, codecForMerchantOrderRefundPickupResponse, codecForMerchantOrderStatusPaid, codecForMerchantPayResponse, + codecForMerchantPostOrderResponse, codecForProposal, CoinDepositPermission, CoinRefreshRequest, @@ -53,12 +55,15 @@ import { MerchantCoinRefundStatus, MerchantContractTerms, MerchantPayResponse, + MerchantUsingTemplateDetails, NotificationType, + parsePayTemplateUri, parsePayUri, parseTalerUri, PayCoinSelection, PreparePayResult, PreparePayResultType, + PreparePayTemplateRequest, randomBytes, RefreshReason, SharePaymentResult, @@ -1209,6 +1214,49 @@ export async function preparePayForUri( return checkPaymentByProposalId(ws, proposalId, uriResult.sessionId); } +export async function preparePayForTemplate( + ws: InternalWalletState, + req: PreparePayTemplateRequest, +): Promise<PreparePayResult> { + const url = parsePayTemplateUri(req.talerPayTemplateUri); + const templateDetails: MerchantUsingTemplateDetails = {}; + if (!url) { + throw Error("invalid taler-template URI"); + } + if ( + url.templateParams.amount !== undefined && + typeof url.templateParams.amount === "string" + ) { + templateDetails.amount = (req.templateParams.amount ?? + url.templateParams.amount) as AmountString | undefined; + } + if ( + url.templateParams.summary !== undefined && + typeof url.templateParams.summary === "string" + ) { + templateDetails.summary = + req.templateParams.summary ?? url.templateParams.summary; + } + const reqUrl = new URL(`templates/${url.templateId}`, url.merchantBaseUrl); + const httpReq = await ws.http.fetch(reqUrl.href, { + method: "POST", + body: templateDetails, + }); + const resp = await readSuccessResponseJsonOrThrow( + httpReq, + codecForMerchantPostOrderResponse(), + ); + + const payUri = stringifyPayUri({ + merchantBaseUrl: url.merchantBaseUrl, + orderId: resp.order_id, + sessionId: "", + claimToken: resp.token, + }); + + return await preparePayForUri(ws, payUri); +} + /** * Generate deposit permissions for a purchase. * |