diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-30 17:27:59 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-30 17:27:59 +0200 |
commit | 5ec344290efd937fa82c0704bc7c204a0bf14c78 (patch) | |
tree | 7d9594180bbc7b5fa2b4a8dbe24272e7a82301f3 /src/taleruri.ts | |
parent | defbf625bdef0f8a666b72b8ce99de5e01af6b91 (diff) | |
download | wallet-core-5ec344290efd937fa82c0704bc7c204a0bf14c78.tar.xz |
support for tipping protocol changes
Diffstat (limited to 'src/taleruri.ts')
-rw-r--r-- | src/taleruri.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/taleruri.ts b/src/taleruri.ts index fa305d1de..f5fc77421 100644 --- a/src/taleruri.ts +++ b/src/taleruri.ts @@ -26,6 +26,13 @@ export interface WithdrawUriResult { statusUrl: string; } +export interface TipUriResult { + tipPickupUrl: string; + tipId: string; + merchantInstance: string; + merchantOrigin: string; +} + export function parseWithdrawUri(s: string): WithdrawUriResult | undefined { const parsedUri = new URI(s); if (parsedUri.scheme() !== "taler") { @@ -104,3 +111,47 @@ export function parsePayUri(s: string): PayUriResult | undefined { sessionId: maybeSessionid, }; } + +export function parseTipUri(s: string): TipUriResult | undefined { + const parsedUri = new URI(s); + if (parsedUri.scheme() != "taler") { + return undefined; + } + if (parsedUri.authority() != "tip") { + return undefined; + } + + let [_, host, maybePath, maybeInstance, tipId] = parsedUri.path().split("/"); + + if (!host) { + return undefined; + } + + if (!maybePath) { + return undefined; + } + + if (!tipId) { + return undefined; + } + + if (maybePath === "-") { + maybePath = "public/tip-pickup"; + } else { + maybePath = decodeURIComponent(maybePath); + } + if (maybeInstance === "-") { + maybeInstance = "default"; + } + + const tipPickupUrl = new URI( + "https://" + host + "/" + decodeURIComponent(maybePath), + ).href(); + + return { + tipPickupUrl, + tipId: tipId, + merchantInstance: maybeInstance, + merchantOrigin: new URI(tipPickupUrl).origin(), + }; +} |