diff options
author | Florian Dold <florian@dold.me> | 2024-02-16 13:39:18 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-02-16 13:39:18 +0100 |
commit | b70f922fdd928c3ab675522dc8031371909a88ab (patch) | |
tree | 6da5c3c20223eafd8051f6daefd15d2c623c6119 /packages | |
parent | c909d6fc0657002a2e5d117e98b9685f7a04a9d4 (diff) |
wallet-core: make templateParams optional
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-util/src/wallet-types.ts | 2 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-merchant.ts | 26 |
2 files changed, 16 insertions, 12 deletions
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index b79bfe4fe..e6a66ac9d 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -1927,7 +1927,7 @@ export const codecForSharePaymentResult = (): Codec<SharePaymentResult> => export interface PreparePayTemplateRequest { talerPayTemplateUri: string; - templateParams: Record<string, string>; + templateParams?: Record<string, string>; } export const codecForPreparePayTemplateRequest = diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index fc34feb30..4b692fe69 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -1563,26 +1563,30 @@ export async function preparePayForTemplate( ws: InternalWalletState, req: PreparePayTemplateRequest, ): Promise<PreparePayResult> { - const url = parsePayTemplateUri(req.talerPayTemplateUri); + const parsedUri = parsePayTemplateUri(req.talerPayTemplateUri); const templateDetails: MerchantUsingTemplateDetails = {}; - if (!url) { + if (!parsedUri) { throw Error("invalid taler-template URI"); } + logger.trace(`parsed URI: ${j2s(parsedUri)}`); if ( - url.templateParams.amount !== undefined && - typeof url.templateParams.amount === "string" + parsedUri.templateParams.amount !== undefined && + typeof parsedUri.templateParams.amount === "string" ) { - templateDetails.amount = (req.templateParams.amount ?? - url.templateParams.amount) as AmountString | undefined; + templateDetails.amount = (req.templateParams?.amount ?? + parsedUri.templateParams.amount) as AmountString | undefined; } if ( - url.templateParams.summary !== undefined && - typeof url.templateParams.summary === "string" + parsedUri.templateParams.summary !== undefined && + typeof parsedUri.templateParams.summary === "string" ) { templateDetails.summary = - req.templateParams.summary ?? url.templateParams.summary; + req.templateParams?.summary ?? parsedUri.templateParams.summary; } - const reqUrl = new URL(`templates/${url.templateId}`, url.merchantBaseUrl); + const reqUrl = new URL( + `templates/${parsedUri.templateId}`, + parsedUri.merchantBaseUrl, + ); const httpReq = await ws.http.fetch(reqUrl.href, { method: "POST", body: templateDetails, @@ -1593,7 +1597,7 @@ export async function preparePayForTemplate( ); const payUri = stringifyPayUri({ - merchantBaseUrl: url.merchantBaseUrl, + merchantBaseUrl: parsedUri.merchantBaseUrl, orderId: resp.order_id, sessionId: "", claimToken: resp.token, |