diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-28 02:49:27 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-28 02:49:27 +0200 |
commit | 1390175a9afc53948dd1d6f8a2f88e51c1bf53cc (patch) | |
tree | 1e65581f11354ec61532dbbf3174e9bd26b515c4 /src/taleruri.ts | |
parent | 70c0a557f9c89a2a0006f74bd8b361b62660bde2 (diff) |
rudimentary taler://withdraw support
Diffstat (limited to 'src/taleruri.ts')
-rw-r--r-- | src/taleruri.ts | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/taleruri.ts b/src/taleruri.ts index fa3b09c31..fa305d1de 100644 --- a/src/taleruri.ts +++ b/src/taleruri.ts @@ -15,12 +15,39 @@ */ import URI = require("urijs"); +import { string } from "prop-types"; export interface PayUriResult { downloadUrl: string; sessionId?: string; } +export interface WithdrawUriResult { + statusUrl: string; +} + +export function parseWithdrawUri(s: string): WithdrawUriResult | undefined { + const parsedUri = new URI(s); + if (parsedUri.scheme() !== "taler") { + return undefined; + } + if (parsedUri.authority() != "withdraw") { + return undefined; + } + + let [host, path, withdrawId] = parsedUri.segmentCoded(); + + if (path === "-") { + path = "/api/withdraw-operation"; + } + + return { + statusUrl: new URI({ protocol: "https", hostname: host, path: path }) + .segmentCoded(withdrawId) + .href(), + }; +} + export function parsePayUri(s: string): PayUriResult | undefined { const parsedUri = new URI(s); if (parsedUri.scheme() === "http" || parsedUri.scheme() === "https") { @@ -68,10 +95,12 @@ export function parsePayUri(s: string): PayUriResult | undefined { const downloadUrl = new URI( "https://" + host + "/" + decodeURIComponent(maybePath), - ).addQuery({ instance: maybeInstance, order_id: orderId }).href(); + ) + .addQuery({ instance: maybeInstance, order_id: orderId }) + .href(); return { downloadUrl, sessionId: maybeSessionid, - } + }; } |