aboutsummaryrefslogtreecommitdiff
path: root/src/taleruri.ts
diff options
context:
space:
mode:
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