use stringify taler util
This commit is contained in:
parent
9f776d3fb0
commit
ef148b1501
@ -34,6 +34,7 @@ import { useBackendContext } from "../../../../context/backend.js";
|
|||||||
import { useConfigContext } from "../../../../context/config.js";
|
import { useConfigContext } from "../../../../context/config.js";
|
||||||
import { useInstanceContext } from "../../../../context/instance.js";
|
import { useInstanceContext } from "../../../../context/instance.js";
|
||||||
import { MerchantBackend } from "../../../../declaration.js";
|
import { MerchantBackend } from "../../../../declaration.js";
|
||||||
|
import { stringifyPayTemplateUri } from "@gnu-taler/taler-util";
|
||||||
|
|
||||||
type Entity = MerchantBackend.Template.UsingTemplateDetails;
|
type Entity = MerchantBackend.Template.UsingTemplateDetails;
|
||||||
|
|
||||||
@ -64,28 +65,29 @@ export function QrPage({ template, id: templateId, onBack }: Props): VNode {
|
|||||||
const fixedAmount = !!template.template_contract.amount;
|
const fixedAmount = !!template.template_contract.amount;
|
||||||
const fixedSummary = !!template.template_contract.summary;
|
const fixedSummary = !!template.template_contract.summary;
|
||||||
|
|
||||||
const params = new URLSearchParams();
|
const templateParams: Record<string, string> = {}
|
||||||
if (!fixedAmount) {
|
if (!fixedAmount) {
|
||||||
if (state.amount) {
|
if (state.amount) {
|
||||||
params.append("amount", state.amount);
|
templateParams.amount = state.amount
|
||||||
} else {
|
} else {
|
||||||
params.append("amount", config.currency);
|
templateParams.amount = config.currency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fixedSummary) {
|
if (!fixedSummary) {
|
||||||
params.append("summary", state.summary ?? "");
|
templateParams.summary = state.summary ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
const paramsStr = fixedAmount && fixedSummary ? "" : "?" + params.toString();
|
const merchantBaseUrl = new URL(backendUrl).href;
|
||||||
const merchantURL = new URL(backendUrl);
|
|
||||||
|
|
||||||
const talerProto =
|
const payTemplateUri = stringifyPayTemplateUri({
|
||||||
merchantURL.protocol === "http:" ? "taler+http:" : "taler:";
|
merchantBaseUrl,
|
||||||
|
templateId,
|
||||||
const payTemplateUri = `${talerProto}//pay-template/${merchantURL.hostname}/${templateId}${paramsStr}`;
|
templateParams
|
||||||
|
})
|
||||||
|
|
||||||
const issuer = encodeURIComponent(
|
const issuer = encodeURIComponent(
|
||||||
`${new URL(backendUrl).hostname}/${instanceId}`,
|
`${new URL(backendUrl).host}/${instanceId}`,
|
||||||
);
|
);
|
||||||
const oauthUri = !template.pos_algorithm
|
const oauthUri = !template.pos_algorithm
|
||||||
? undefined
|
? undefined
|
||||||
|
Loading…
Reference in New Issue
Block a user