diff options
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(), + }; +} |