btcpayserver/BTCPayServer/wwwroot/checkout/coinswitch.html

94 lines
3 KiB
HTML
Raw Normal View History

2018-12-11 12:47:38 +01:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CoinSwitch</title>
<script>
2018-12-18 20:00:30 +01:00
var script = document.createElement('script'),
head = document.head || document.getElementsByTagName('head')[0];
2019-01-03 15:31:56 +01:00
script.src = 'https://files.coinswitch.co/public/js/cs_switch.js';
2018-12-18 20:00:30 +01:00
head.insertBefore(script, head.firstChild);
2018-12-18 19:01:58 +01:00
script.addEventListener('load', function () {
2018-12-11 12:47:38 +01:00
var qs = (function (a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=', 2);
if (p.length == 1)
b[p[0]] = "";
else
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
var merchantId = qs["merchant_id"];
var toCurrencyDue = qs["toCurrencyDue"];
var toCurrencyAddress = qs["toCurrencyAddress"];
var toCurrency = qs["toCurrency"];
2018-12-20 14:33:31 +01:00
var mode = qs["mode"];
document.body.classList.add(mode);
var orderId = null;
2018-12-18 19:01:58 +01:00
var payment = new Coinswitch(merchantId);
if(window.localStorage){
orderId= window.localStorage.getItem(toCurrencyAddress);
}
2018-12-18 19:01:58 +01:00
var config = {
2018-12-20 14:33:31 +01:00
to_currency: toCurrency.toLowerCase(),
2018-12-18 19:01:58 +01:00
to_currency_address: toCurrencyAddress,
to_amount: parseFloat(toCurrencyDue),
state: orderId
2018-12-18 19:01:58 +01:00
};
payment.on('Exchange:Ready', function(){
waitForCoinSwitch();
2019-05-07 16:09:26 +02:00
});
payment.on("Exchange:Complete", function () {
if(window.localStorage){
window.localStorage.removeItem(toCurrencyAddress);
}
window.close();
});
payment.on("Exchange:Initiated", function(orderId) {
if(window.localStorage){
window.localStorage.setItem(toCurrencyAddress,orderId);
}
});
payment.on("Exchange:Closed", function () {
window.close();
window.postMessage("popup-closed", "*");
});
2018-12-18 19:01:58 +01:00
2018-12-18 20:00:30 +01:00
function waitForCoinSwitch() {
if (typeof payment.open !== "function") {
2018-12-18 19:01:58 +01:00
setTimeout(waitForCoinSwitch, 1000);
return;
}
2019-05-07 16:09:26 +02:00
payment.open(config);
2018-12-18 19:01:58 +01:00
}
});
2018-12-11 12:47:38 +01:00
</script>
2018-12-18 20:00:30 +01:00
<style>
2018-12-20 14:33:31 +01:00
body.popup #CoinSwitchPayment .cs-pay {
2018-12-18 20:00:30 +01:00
height: 100%;
}
2018-12-20 14:33:31 +01:00
body.popup #CoinSwitchPayment .cs-pay__main {
2018-12-18 20:00:30 +01:00
width: 100%;
2018-12-20 14:33:31 +01:00
min-height: 90vh;
2018-12-18 20:00:30 +01:00
padding-bottom: 20px;
}
2018-12-20 14:33:31 +01:00
body.popup #CoinSwitchPayment .cs-pay__dismiss-row {
2018-12-18 20:00:30 +01:00
display: none;
}
2018-12-20 14:33:31 +01:00
2018-12-18 20:00:30 +01:00
</style>
2018-12-11 12:47:38 +01:00
</head>
<body>
</body>
</html>