summaryrefslogtreecommitdiff
path: root/src/taleruri.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/taleruri.ts')
-rw-r--r--src/taleruri.ts33
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,
- }
+ };
}