mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
125 lines
5.2 KiB
Plaintext
125 lines
5.2 KiB
Plaintext
@using BTCPayServer.Plugins.SideShift
|
|
@using BTCPayServer.Payments
|
|
@inject BTCPayServer.Security.ContentSecurityPolicies csp
|
|
@inject SideShiftService SideShiftService
|
|
@model BTCPayServer.Models.InvoicingModels.PaymentModel
|
|
@{
|
|
var settings = await SideShiftService.GetSideShiftForInvoice(Model.InvoiceId, Model.StoreId);
|
|
var preferredTargetPaymentMethodId = "";
|
|
if(!PaymentMethodId.TryParse(settings?.PreferredTargetPaymentMethodId, out var preferredPMI))
|
|
{
|
|
preferredTargetPaymentMethodId = null;
|
|
}
|
|
else
|
|
{
|
|
preferredTargetPaymentMethodId = Model.AvailableCryptos.FirstOrDefault(crypto =>
|
|
crypto.PaymentMethodId == settings.PreferredTargetPaymentMethodId ||
|
|
(crypto.CryptoCode == preferredPMI.CryptoCode && crypto.PaymentMethodId.EndsWith(LNURLPayPaymentType.Instance.GetId()) || crypto.PaymentMethodId.EndsWith(LightningPaymentType.Instance.GetId())))?.PaymentMethodId;
|
|
}
|
|
}
|
|
@if (settings?.Enabled is true)
|
|
{
|
|
csp.Add("script-src", "https://sideshift.ai");
|
|
csp.Add("script-src", "*.sideshift.ai");
|
|
|
|
<template id="side-shift-checkout-template">
|
|
<div class="payment-box">
|
|
<p v-html="content"></p>
|
|
<button type="button" v-on:click="openDialog" class="btn btn-primary rounded-pill w-100">{{$t("Pay with SideShift")}}</button>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
Vue.component("SideShiftCheckout", {
|
|
template: "#side-shift-checkout-template",
|
|
props: ["model"],
|
|
data: function() {
|
|
return {
|
|
explicitId: "",
|
|
preferredToCurrency: @Json.Serialize(preferredTargetPaymentMethodId),
|
|
}
|
|
},
|
|
async created () {
|
|
const self = this;
|
|
setInterval(function() {
|
|
if ( self.explicitId === window.ssExplicitId) {
|
|
return;
|
|
}
|
|
self.explicitId = window.ssExplicitId;
|
|
},200)
|
|
|
|
if(this.preferredToCurrency && this.model.paymentMethodId !== this.preferredToCurrency){
|
|
if (this.model.onChainWithLnInvoiceFallback && this.model.paymentMethodId === "BTC"){
|
|
return;
|
|
}
|
|
this.$parent.paymentMethodId = this.preferredToCurrency;
|
|
await this.$parent.fetchData();
|
|
this.$parent.paymentMethodId = "SideShift";
|
|
}
|
|
|
|
},
|
|
computed: {
|
|
lightning () {
|
|
if (!this.model.onChainWithLnInvoiceFallback || this.model.paymentMethodId !== "BTC"){
|
|
return null;
|
|
}
|
|
const index = this.model.invoiceBitcoinUrl.indexOf("lightning=");
|
|
if (index === -1){
|
|
return null;
|
|
}
|
|
return this.model.invoiceBitcoinUrl.slice(index + "lightning=".length);
|
|
},
|
|
content () {
|
|
return this.$i18n.i18next.t("conversion_body", this.model).replace(/\n/ig, '<br>');
|
|
},
|
|
currency () {
|
|
return this.model.paymentMethodId;
|
|
},
|
|
settleMethodId () {
|
|
|
|
const toCurrency = this.currency.toLowerCase();
|
|
|
|
if (toCurrency === "lbtc") {
|
|
return 'liquid';
|
|
} else if (toCurrency === "usdt") {
|
|
return "usdtla";
|
|
} else if (toCurrency.endsWith('lightninglike') || toCurrency.endsWith('lnurlpay') || this.lightning) {
|
|
return "ln";
|
|
} else {
|
|
return toCurrency.replace('_btclike', '').replace('_monerolike', '').replace('_zcashlike', '').toLowerCase();
|
|
}
|
|
},
|
|
type () {
|
|
return this.model.isUnsetTopUp
|
|
? undefined
|
|
: 'fixed';
|
|
},
|
|
amountDue () {
|
|
return this.model.isUnsetTopUp
|
|
? undefined
|
|
: this.model.btcDue * (1 + (@settings.AmountMarkupPercentage / 100));
|
|
}
|
|
},
|
|
methods: {
|
|
openDialog () {
|
|
window.__SIDESHIFT__ = {
|
|
parentAffiliateId: "qg0OrfHJV",
|
|
defaultDepositMethodId: this.explicitId || undefined,
|
|
defaultSettleMethodId: this.settleMethodId,
|
|
settleAddress: this.lightning || this.model.btcAddress,
|
|
settleAmount: this.amountDue,
|
|
type: this.type
|
|
};
|
|
console.log(window.__SIDESHIFT__);
|
|
window.sideshift.show();
|
|
}
|
|
},
|
|
watch: {
|
|
explicitId (val) {
|
|
this.openDialog();
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
<script src="https://sideshift.ai/static/js/main.js" defer></script>
|
|
}
|