coinswitch integration

This commit is contained in:
Kukks 2018-12-18 19:01:58 +01:00
parent c00c95efcf
commit 2b4603a234
9 changed files with 61 additions and 16 deletions

View file

@ -317,6 +317,7 @@ namespace BTCPayServer.Controllers
ChangellyAmountDue = changellyAmountDue,
CoinSwitchEnabled = coinswitch != null,
CoinSwitchMerchantId = coinswitch?.MerchantId,
CoinSwitchMode = coinswitch?.Mode,
StoreId = store.Id,
AvailableCryptos = invoice.GetPaymentMethods(_NetworkProvider)
.Where(i => i.Network != null)

View file

@ -27,6 +27,7 @@ namespace BTCPayServer.Controllers
if (existing == null) return;
vm.MerchantId = existing.MerchantId;
vm.Enabled = existing.Enabled;
vm.Mode = existing.Mode;
}
[HttpPost]
@ -48,7 +49,8 @@ namespace BTCPayServer.Controllers
var coinSwitchSettings = new CoinSwitchSettings()
{
MerchantId = vm.MerchantId,
Enabled = vm.Enabled
Enabled = vm.Enabled,
Mode = vm.Mode
};
switch (command)

View file

@ -63,6 +63,7 @@ namespace BTCPayServer.Models.InvoicingModels
public decimal? ChangellyAmountDue { get; set; }
public bool CoinSwitchEnabled { get; set; }
public string CoinSwitchMode { get; set; }
public string CoinSwitchMerchantId { get; set; }
}
}

View file

@ -1,4 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using BTCPayServer.Payments.CoinSwitch;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace BTCPayServer.Models.StoreViewModels
{
@ -7,6 +10,15 @@ namespace BTCPayServer.Models.StoreViewModels
public string MerchantId { get; set; }
public bool Enabled { get; set; }
[Display(Name = "Mode, Choose how to show CoinSwitch")]
public string Mode { get; set; } = "popup";
public List<SelectListItem> Modes { get; } = new List<SelectListItem>
{
new SelectListItem { Value = "popup", Text = "Open in a popup" },
new SelectListItem { Value = "inline", Text = "Embed inside Checkout UI " },
};
public string StatusMessage { get; set; }
}
}

View file

@ -3,7 +3,7 @@ namespace BTCPayServer.Payments.CoinSwitch
public class CoinSwitchSettings
{
public string MerchantId { get; set; }
public string Mode { get; set; }
public bool Enabled { get; set; }
public bool IsConfigured()

View file

@ -292,12 +292,15 @@
{
<coinswitch inline-template
v-if="!srvModel.changellyEnabled || selectedThirdPartyProcessor === 'coinswitch'"
:mode="srvModel.coinSwitchMode"
:merchant-id="srvModel.changellyMerchantId"
:to-currency="srvModel.paymentMethodId"
:to-currency-due="srvModel.btcDue"
:autoload="selectedThirdPartyProcessor === 'coinswitch'"
:to-currency-address="srvModel.btcAddress">
<a v-on:click="openDialog($event)" :href="url" class="action-button" v-show="url">
<iframe v-if="mode === 'inline'" :url="url" v-show="url">a</iframe>
<a v-else-if="mode === 'popup'"
v-on:click="openDialog($event)" :href="url" class="action-button" v-show="url">
{{$t("Pay with CoinSwitch")}}
</a>
</coinswitch>
@ -307,7 +310,8 @@
<changelly inline-template
v-if="!srvModel.coinSwitchEnabled || selectedThirdPartyProcessor === 'changelly'"
:merchant-id="srvModel.changellyMerchantId"
:merchant-id="srvModel.
"
:store-id="srvModel.storeId"
:to-currency="srvModel.paymentMethodId"
:to-currency-due="srvModel.changellyAmountDue"

View file

@ -26,6 +26,11 @@
<label asp-for="Enabled"></label>
<input asp-for="Enabled" type="checkbox" class="form-check"/>
</div>
<div class="form-group">
<label asp-for="Mode"></label>
<select asp-for="Mode" asp-items="Model.Modes" >
</select>
</div>
<button name="command" type="submit" value="save" class="btn btn-primary">Submit</button>
</form>
</div>

View file

@ -33,8 +33,11 @@
<!--});-->
<!--</script>-->
<script id="cs_js" async src="https://files.coinswitch.co/public/js/cs_switch.js"></script>
<script>
window.onload = function () {
var script = document.querySelector('#cs_js');
// window.onload = function () {
script.addEventListener('load', function () {
var qs = (function (a) {
if (a == "") return {};
var b = {};
@ -48,21 +51,38 @@
return b;
})(window.location.search.substr(1).split('&'));
debugger;
var merchantId = qs["merchant_id"];
var toCurrencyDue = qs["toCurrencyDue"];
var toCurrencyAddress = qs["toCurrencyAddress"];
var toCurrency = qs["toCurrency"];
var url = "https://coinswitch.co/widget?widget_id=c0f2b60c&to=" + toCurrency + "&amount=" + toCurrencyDue + "&to_address=" + toCurrencyAddress;
document.getElementById("widget").src = url;
}
var payment = new Coinswitch(merchantId);
var config = {
to_currency: toCurrency,
to_currency_address: toCurrencyAddress,
to_amount: toCurrencyDue
};
waitForCoinSwitch();
function waitForCoinSwitch(){
if(typeof payment.open !== "function"){
setTimeout(waitForCoinSwitch, 1000);
return;
}
payment.open(config);
payment.on("Exchange:Complete", function () {
window.close();
});
payment.on("Exchange:Closed", function () {
window.close();
})
}
});
// }
</script>
</head>
<body>
<iframe id="widget" style="left:0; top:0; width: 100%; height:100%; position: absolute;"
frameborder="0" scrolling="auto" style="overflow-y: hidden;border: 1px solid #ff7f50;border-top: none;">Can't
load widget
</iframe>
sdasd
</body>
</html>

View file

@ -1,6 +1,6 @@
var CoinSwitchComponent =
{
props: ["toCurrency", "toCurrencyDue", "toCurrencyAddress", "merchantId", "autoload"],
props: ["toCurrency", "toCurrencyDue", "toCurrencyAddress", "merchantId", "autoload", "mode"],
data: function () {
},
computed: {
@ -31,8 +31,8 @@
}
},
mounted: function () {
if(this.autoload){
if(this.autoload && this.mode === 'popup'){
this.openDialog();
}
},
}
};