From 1390175a9afc53948dd1d6f8a2f88e51c1bf53cc Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 28 Aug 2019 02:49:27 +0200 Subject: rudimentary taler://withdraw support --- src/taleruri.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/taleruri.ts') 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, - } + }; } -- cgit v1.2.3