aboutsummaryrefslogtreecommitdiff
path: root/src/taleruri.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-08-31 11:49:36 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-08-31 11:49:36 +0200
commit5a7269b20db0371535669c0faa7f1814d967b5ca (patch)
treec757d7b441875b745e3d83e8a543785e7b82fc9b /src/taleruri.ts
parent5ec344290efd937fa82c0704bc7c204a0bf14c78 (diff)
cli refunds
Diffstat (limited to 'src/taleruri.ts')
-rw-r--r--src/taleruri.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/taleruri.ts b/src/taleruri.ts
index f5fc77421..bd01abb65 100644
--- a/src/taleruri.ts
+++ b/src/taleruri.ts
@@ -26,6 +26,10 @@ export interface WithdrawUriResult {
statusUrl: string;
}
+export interface RefundUriResult {
+ refundUrl: string;
+}
+
export interface TipUriResult {
tipPickupUrl: string;
tipId: string;
@@ -155,3 +159,52 @@ export function parseTipUri(s: string): TipUriResult | undefined {
merchantOrigin: new URI(tipPickupUrl).origin(),
};
}
+
+export function parseRefundUri(s: string): RefundUriResult | undefined {
+ const parsedUri = new URI(s);
+ if (parsedUri.scheme() != "taler") {
+ return undefined;
+ }
+ if (parsedUri.authority() != "refund") {
+ return undefined;
+ }
+
+ let [
+ _,
+ host,
+ maybePath,
+ maybeInstance,
+ orderId,
+ ] = parsedUri.path().split("/");
+
+ if (!host) {
+ return undefined;
+ }
+
+ if (!maybePath) {
+ return undefined;
+ }
+
+ if (!orderId) {
+ return undefined;
+ }
+
+ if (maybePath === "-") {
+ maybePath = "public/refund";
+ } else {
+ maybePath = decodeURIComponent(maybePath);
+ }
+ if (maybeInstance === "-") {
+ maybeInstance = "default";
+ }
+
+ const refundUrl = new URI(
+ "https://" + host + "/" + decodeURIComponent(maybePath),
+ )
+ .addQuery({ instance: maybeInstance, order_id: orderId })
+ .href();
+
+ return {
+ refundUrl,
+ };
+} \ No newline at end of file