diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-31 11:49:36 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-31 11:49:36 +0200 |
commit | 5a7269b20db0371535669c0faa7f1814d967b5ca (patch) | |
tree | c757d7b441875b745e3d83e8a543785e7b82fc9b /src/taleruri.ts | |
parent | 5ec344290efd937fa82c0704bc7c204a0bf14c78 (diff) |
cli refunds
Diffstat (limited to 'src/taleruri.ts')
-rw-r--r-- | src/taleruri.ts | 53 |
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 |