diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/taleruri-test.ts | 15 | ||||
-rw-r--r-- | src/util/taleruri.ts | 17 |
2 files changed, 23 insertions, 9 deletions
diff --git a/src/util/taleruri-test.ts b/src/util/taleruri-test.ts index de4a90697..052581a91 100644 --- a/src/util/taleruri-test.ts +++ b/src/util/taleruri-test.ts @@ -96,7 +96,7 @@ test("taler pay url parsing: complex path prefix", t => { t.is(r1.sessionId, undefined); }); -test("taler pay url parsing: complex path prefix and instance", t => { +test("taler pay uri parsing: complex path prefix and instance", t => { const url1 = "taler://pay/example.com/mypfx%2Fpublic/foo/myorder"; const r1 = parsePayUri(url1); if (!r1) { @@ -107,7 +107,18 @@ test("taler pay url parsing: complex path prefix and instance", t => { t.is(r1.orderId, "myorder"); }); -test("taler pay url parsing: non-https #1", t => { +test("taler refund uri parsing: non-https #1", t => { + const url1 = "taler://refund/example.com/-/-/myorder?insecure=1"; + const r1 = parseRefundUri(url1); + if (!r1) { + t.fail(); + return; + } + t.is(r1.merchantBaseUrl, "http://example.com/public/"); + t.is(r1.orderId, "myorder") +}); + +test("taler pay uri parsing: non-https #1", t => { const url1 = "taler://pay/example.com/-/-/myorder?insecure=1"; const r1 = parsePayUri(url1); if (!r1) { diff --git a/src/util/taleruri.ts b/src/util/taleruri.ts index 1b4e4352b..8ad79669f 100644 --- a/src/util/taleruri.ts +++ b/src/util/taleruri.ts @@ -95,13 +95,12 @@ export function classifyTalerUri(s: string): TalerUriType { return TalerUriType.TalerNotifyReserve; } return TalerUriType.Unknown; - } export function getOrderDownloadUrl(merchantBaseUrl: string, orderId: string) { const u = new URL("proposal", merchantBaseUrl); u.searchParams.set("order_id", orderId); - return u.href + return u.href; } export function parsePayUri(s: string): PayUriResult | undefined { @@ -208,7 +207,7 @@ export function parseRefundUri(s: string): RefundUriResult | undefined { return undefined; } - const path = s.slice(pfx.length); + const [path, search] = s.slice(pfx.length).split("?"); let [host, maybePath, maybeInstance, orderId] = path.split("/"); @@ -236,10 +235,14 @@ export function parseRefundUri(s: string): RefundUriResult | undefined { maybeInstancePath = `instances/${maybeInstance}/`; } - const merchantBaseUrl = "https://" + host + - "/" + - maybePath + - maybeInstancePath + let protocol = "https"; + const searchParams = new URLSearchParams(search); + if (searchParams.get("insecure") === "1") { + protocol = "http"; + } + + const merchantBaseUrl = + `${protocol}://${host}/` + maybePath + maybeInstancePath; return { merchantBaseUrl, |