Unify checkout v1 behaviour with v2

This commit is contained in:
Dennis Reimann 2023-04-25 11:20:10 +02:00
parent 03b793d7e2
commit 8de55cef31
No known key found for this signature in database
GPG Key ID: 5009E1797F03F8D0
5 changed files with 15 additions and 21 deletions

View File

@ -164,7 +164,7 @@ namespace BTCPayServer.Tests
var invoiceId = s.CreateInvoice(defaultPaymentMethod: "BTC_LightningLike");
s.GoToInvoiceCheckout(invoiceId);
Assert.Equal("Bitcoin (Lightning) (BTC)", s.Driver.FindElement(By.ClassName("payment__currencies")).Text);
Assert.Equal("Bitcoin (Lightning)", s.Driver.FindElement(By.ClassName("payment__currencies")).Text);
s.Driver.Quit();
}
@ -187,7 +187,7 @@ namespace BTCPayServer.Tests
var invoiceId = s.CreateInvoice(10, "USD", "a@g.com");
s.GoToInvoiceCheckout(invoiceId);
Assert.Contains("sats", s.Driver.FindElement(By.ClassName("payment__currencies_noborder")).Text);
Assert.Contains("sats", s.Driver.FindElement(By.ClassName("buyerTotalLine")).Text);
}
[Fact(Timeout = TestTimeout)]

View File

@ -671,7 +671,7 @@ namespace BTCPayServer.Controllers
var displayedPaymentMethods = invoice.GetPaymentMethods().Select(p => p.GetId()).ToList();
// Exclude Lightning if OnChainWithLnInvoiceFallback is active and we have both payment methods
if (storeBlob is { CheckoutType: CheckoutType.V2, OnChainWithLnInvoiceFallback: true } &&
if (storeBlob is { OnChainWithLnInvoiceFallback: true } &&
displayedPaymentMethods.Contains(btcId))
{
displayedPaymentMethods.Remove(lnId);
@ -787,11 +787,13 @@ namespace BTCPayServer.Controllers
Request.Host,
Request.PathBase) : null;
var isAltcoinsBuild = false;
#if ALTCOINS
isAltcoinsBuild = true,
#endif
var model = new PaymentModel
{
#if ALTCOINS
AltcoinsBuild = true,
#endif
Activated = paymentMethodDetails.Activated,
CryptoCode = network.CryptoCode,
RootPath = Request.PathBase.Value.WithTrailingSlash(),
@ -856,12 +858,15 @@ namespace BTCPayServer.Controllers
{
var availableCryptoPaymentMethodId = kv.GetId();
var availableCryptoHandler = _paymentMethodHandlerDictionary[availableCryptoPaymentMethodId];
var pmName = availableCryptoHandler.GetPaymentMethodName(availableCryptoPaymentMethodId);
return new PaymentModel.AvailableCrypto
{
Displayed = displayedPaymentMethods.Contains(kv.GetId()),
PaymentMethodId = kv.GetId().ToString(),
CryptoCode = kv.Network?.CryptoCode ?? kv.GetId().CryptoCode,
PaymentMethodName = availableCryptoHandler.GetPaymentMethodName(availableCryptoPaymentMethodId),
PaymentMethodName = isAltcoinsBuild
? pmName
: pmName.Replace("Bitcoin (", "").Replace(")", "").Replace("Lightning ", ""),
IsLightning =
kv.GetId().PaymentType == PaymentTypes.LightningLike,
CryptoImage = Request.GetRelativePathOrAbsolute(availableCryptoHandler.GetCryptoImage(availableCryptoPaymentMethodId)),

View File

@ -78,7 +78,6 @@ namespace BTCPayServer.Models.InvoicingModels
public bool Activated { get; set; }
public string InvoiceCurrency { get; set; }
public string ReceiptLink { get; set; }
public bool AltcoinsBuild { get; set; }
public CheckoutType CheckoutType { get; set; }
public int? RequiredConfirmations { get; set; }
public long? ReceivedConfirmations { get; set; }

View File

@ -52,8 +52,7 @@
<div class="paywithRowRight cursorPointer" v-on:click="openPaymentMethodDialog">
<span class="payment__currencies " v-show="!changingCurrencies">
<img v-bind:src="srvModel.cryptoImage" />
<span>{{srvModel.paymentMethodName}} ({{srvModel.cryptoCode}})</span>
<span v-show="srvModel.isLightning">&#9889;</span>
<span>{{srvModel.paymentMethodName}}</span>
<span class="clickable_indicator fa fa-angle-right"></span>
</span>
</div>
@ -65,8 +64,6 @@
<a href="@crypto.Link" class="payment-method" data-payment-method="@crypto.PaymentMethodId" rel="noreferrer noopener">
<img alt="@crypto.PaymentMethodName" src="@crypto.CryptoImage" asp-append-version="true" />
@crypto.PaymentMethodName
@(crypto.IsLightning ? Html.Raw("&#9889;") : null)
<span>@crypto.CryptoCode</span>
</a>
</li>
}
@ -77,7 +74,7 @@
{
<div class="payment__currencies_noborder">
<img v-bind:src="srvModel.cryptoImage" />
<span>{{srvModel.paymentMethodName}} ({{srvModel.cryptoCode}})</span>
<span>{{srvModel.paymentMethodName}}</span>
<span v-show="srvModel.isLightning">&#9889;</span>
</div>
}

View File

@ -15,13 +15,6 @@
var displayedPaymentMethods = Model.AvailableCryptos.Where(c => c.Displayed).ToList();
}
@functions {
private string PaymentMethodName(PaymentModel.AvailableCrypto pm)
{
return Model.AltcoinsBuild
? pm.PaymentMethodName
: pm.PaymentMethodName.Replace("Bitcoin (", "").Replace(")", "").Replace("Lightning ", "");
}
private string ToJsValue(object value)
{
return Safe.Json(value).ToString()?.Replace("\"", "'");
@ -96,7 +89,7 @@
class="btcpay-pill m-0 payment-method"
:class="{ active: pmId === @ToJsValue(crypto.PaymentMethodId) }"
v-on:click.prevent="changePaymentMethod(@ToJsValue(crypto.PaymentMethodId))">
@PaymentMethodName(crypto)
@crypto.PaymentMethodName
</a>
}
@await Component.InvokeAsync("UiExtensionPoint", new { location = "checkout-payment-method", model = Model })