diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-06 23:08:35 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-06 23:08:35 +0530 |
commit | 5698d609efd715668e24c22e20fed9d952723852 (patch) | |
tree | 10523570956cdb6ca266bcc267591eecf416ed63 /contrib | |
parent | b4fd96d263b0c71cc6b13a46c477cd96fe0af186 (diff) | |
download | merchant-5698d609efd715668e24c22e20fed9d952723852.tar.gz merchant-5698d609efd715668e24c22e20fed9d952723852.tar.bz2 merchant-5698d609efd715668e24c22e20fed9d952723852.zip |
parse taler pay URI into order page URL
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/request_payment.en.must | 232 |
1 files changed, 231 insertions, 1 deletions
diff --git a/contrib/request_payment.en.must b/contrib/request_payment.en.must index a2e615ef..c4beed59 100644 --- a/contrib/request_payment.en.must +++ b/contrib/request_payment.en.must @@ -89,8 +89,238 @@ body { </head> <body> + +<script> +{{! + Auto-generated from https://git.taler.net/wallet-core.git with the command: + + $ rollup packages/taler-wallet-core/lib/util/taleruri.js --name "taleruri" --file out.js --format umd +}} + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = global || self, factory(global.taleruri = {})); +}(this, (function (exports) { 'use strict'; + + /* + This file is part of GNU Taler + (C) 2020 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + // @ts-ignore + const _URL = globalThis.URL; + if (!_URL) { + throw Error("FATAL: URL not available"); + } + // @ts-ignore + const _URLSearchParams = globalThis.URLSearchParams; + if (!_URLSearchParams) { + throw Error("FATAL: URLSearchParams not available"); + } + const URLSearchParams = _URLSearchParams; + + /* + This file is part of GNU Taler + (C) 2019-2020 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + /** + * Parse a taler[+http]://withdraw URI. + * Return undefined if not passed a valid URI. + */ + function parseWithdrawUri(s) { + const pi = parseProtoInfo(s, "withdraw"); + if (!pi) { + return undefined; + } + const parts = pi.rest.split("/"); + if (parts.length < 2) { + return undefined; + } + const host = parts[0].toLowerCase(); + const pathSegments = parts.slice(1, parts.length - 1); + const withdrawId = parts[parts.length - 1]; + const p = [host, ...pathSegments].join("/"); + return { + bankIntegrationApiBaseUrl: `${pi.innerProto}://${p}/`, + withdrawalOperationId: withdrawId, + }; + } + /** + * Classify a taler:// URI. + */ + function classifyTalerUri(s) { + const sl = s.toLowerCase(); + if (sl.startsWith("taler://pay/")) { + return "taler-pay" /* TalerPay */; + } + if (sl.startsWith("taler+http://pay/")) { + return "taler-pay" /* TalerPay */; + } + if (sl.startsWith("taler://tip/")) { + return "taler-tip" /* TalerTip */; + } + if (sl.startsWith("taler+http://tip/")) { + return "taler-tip" /* TalerTip */; + } + if (sl.startsWith("taler://refund/")) { + return "taler-refund" /* TalerRefund */; + } + if (sl.startsWith("taler+http://refund/")) { + return "taler-refund" /* TalerRefund */; + } + if (sl.startsWith("taler://withdraw/")) { + return "taler-withdraw" /* TalerWithdraw */; + } + if (sl.startsWith("taler://notify-reserve/")) { + return "taler-notify-reserve" /* TalerNotifyReserve */; + } + return "unknown" /* Unknown */; + } + function parseProtoInfo(s, action) { + const pfxPlain = `taler://${action}/`; + const pfxHttp = `taler+http://${action}/`; + if (s.toLowerCase().startsWith(pfxPlain)) { + return { + innerProto: "https", + rest: s.substring(pfxPlain.length), + }; + } + else if (s.toLowerCase().startsWith(pfxHttp)) { + return { + innerProto: "http", + rest: s.substring(pfxHttp.length), + }; + } + else { + return undefined; + } + } + /** + * Parse a taler[+http]://pay URI. + * Return undefined if not passed a valid URI. + */ + function parsePayUri(s) { + var _a, _b; + const pi = parseProtoInfo(s, "pay"); + if (!pi) { + return undefined; + } + const c = pi === null || pi === void 0 ? void 0 : pi.rest.split("?"); + const q = new URLSearchParams((_a = c[1]) !== null && _a !== void 0 ? _a : ""); + const claimToken = (_b = q.get("c")) !== null && _b !== void 0 ? _b : undefined; + const parts = c[0].split("/"); + if (parts.length < 3) { + return undefined; + } + const host = parts[0].toLowerCase(); + const sessionId = parts[parts.length - 1]; + const orderId = parts[parts.length - 2]; + const pathSegments = parts.slice(1, parts.length - 2); + const p = [host, ...pathSegments].join("/"); + const merchantBaseUrl = `${pi.innerProto}://${p}/`; + return { + merchantBaseUrl, + orderId, + sessionId: sessionId, + claimToken, + }; + } + /** + * Parse a taler[+http]://tip URI. + * Return undefined if not passed a valid URI. + */ + function parseTipUri(s) { + const pi = parseProtoInfo(s, "tip"); + if (!pi) { + return undefined; + } + const c = pi === null || pi === void 0 ? void 0 : pi.rest.split("?"); + const parts = c[0].split("/"); + if (parts.length < 2) { + return undefined; + } + const host = parts[0].toLowerCase(); + const tipId = parts[parts.length - 1]; + const pathSegments = parts.slice(1, parts.length - 1); + const p = [host, ...pathSegments].join("/"); + const merchantBaseUrl = `${pi.innerProto}://${p}/`; + return { + merchantBaseUrl, + merchantTipId: tipId, + }; + } + /** + * Parse a taler[+http]://refund URI. + * Return undefined if not passed a valid URI. + */ + function parseRefundUri(s) { + const pi = parseProtoInfo(s, "refund"); + if (!pi) { + return undefined; + } + const c = pi === null || pi === void 0 ? void 0 : pi.rest.split("?"); + const parts = c[0].split("/"); + if (parts.length < 2) { + return undefined; + } + const host = parts[0].toLowerCase(); + const orderId = parts[parts.length - 1]; + const pathSegments = parts.slice(1, parts.length - 1); + const p = [host, ...pathSegments].join("/"); + const merchantBaseUrl = `${pi.innerProto}://${p}/`; + return { + merchantBaseUrl, + orderId, + }; + } + + exports.classifyTalerUri = classifyTalerUri; + exports.parsePayUri = parsePayUri; + exports.parseRefundUri = parseRefundUri; + exports.parseTipUri = parseTipUri; + exports.parseWithdrawUri = parseWithdrawUri; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); +</script> + <script> - let checkUrl = FIXME-#6457_dold_pay_uri_to_URL("{{taler_pay_uri}}"); + function pay_uri_to_order_url(uri) { + let parsed = taleruri.parsePayUri(uri); + if (!parsed) { + throw Error("could not parse Taler pay URI"); + } + let url = parsed.merchantBaseUrl + "orders/" + parsed.orderId; + if (parsed.claimToken) { + url = url + "?token=" + parsed.claimToken; + } + return url; + } + + let checkUrl = pay_uri_to_order_url("{{taler_pay_uri}}"); let delayMs = 500; function check() { let req = new XMLHttpRequest(); |