aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-30 17:28:09 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-30 17:28:14 +0530
commitb51932cc85287a04dca13cbb3e4d12c5b98e9c47 (patch)
tree2af698817f7d5501ff7c39922a89cd619237f974 /src/util
parent78718d35343adfe36a4511a06662b626f4bf4957 (diff)
support claim tokensv0.7.1-dev.15
Diffstat (limited to 'src/util')
-rw-r--r--src/util/taleruri-test.ts11
-rw-r--r--src/util/taleruri.ts4
2 files changed, 15 insertions, 0 deletions
diff --git a/src/util/taleruri-test.ts b/src/util/taleruri-test.ts
index 314a981fd..44edbe1c1 100644
--- a/src/util/taleruri-test.ts
+++ b/src/util/taleruri-test.ts
@@ -63,6 +63,17 @@ test("taler pay url parsing: instance", (t) => {
t.is(r1.orderId, "myorder");
});
+test("taler pay url parsing (claim token)", (t) => {
+ const url1 = "taler://pay/example.com/instances/myinst/myorder/?c=ASDF";
+ const r1 = parsePayUri(url1);
+ if (!r1) {
+ t.fail();
+ return;
+ }
+ t.is(r1.merchantBaseUrl, "https://example.com/instances/myinst/");
+ t.is(r1.orderId, "myorder");
+ t.is(r1.claimToken, "ASDF");
+});
test("taler refund uri parsing: non-https #1", (t) => {
const url1 = "taler+http://refund/example.com/myorder";
diff --git a/src/util/taleruri.ts b/src/util/taleruri.ts
index fd2cca6ce..c26c4a5db 100644
--- a/src/util/taleruri.ts
+++ b/src/util/taleruri.ts
@@ -18,6 +18,7 @@ export interface PayUriResult {
merchantBaseUrl: string;
orderId: string;
sessionId: string;
+ claimToken: string | undefined;
}
export interface WithdrawUriResult {
@@ -136,6 +137,8 @@ export function parsePayUri(s: string): PayUriResult | undefined {
return undefined;
}
const c = pi?.rest.split("?");
+ const q = new URLSearchParams(c[1] ?? "");
+ const claimToken = q.get("c") ?? undefined;
const parts = c[0].split("/");
if (parts.length < 3) {
return undefined;
@@ -151,6 +154,7 @@ export function parsePayUri(s: string): PayUriResult | undefined {
merchantBaseUrl,
orderId,
sessionId: sessionId,
+ claimToken,
};
}