Skip to content

Commit

Permalink
Make Checkout V2 the default
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Apr 4, 2023
1 parent 1b672a1 commit 977b405
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 42 deletions.
12 changes: 4 additions & 8 deletions BTCPayServer.Tests/Checkoutv2Tests.cs
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Client.Models;
using BTCPayServer.Payments;
using BTCPayServer.Tests.Logging;
using BTCPayServer.Views.Stores;
Expand Down Expand Up @@ -32,7 +33,6 @@ public async Task CanConfigureCheckout()
s.GoToRegister();
s.RegisterNewUser(true);
s.CreateNewStore();
s.EnableCheckoutV2();
s.AddLightningNode();
// Use non-legacy derivation scheme
s.AddDerivationScheme("BTC", "tpubDD79XF4pzhmPSJ9AyUay9YbXAeD1c6nkUqC32pnKARJH6Ja5hGUfGc76V82ahXpsKqN6UcSGXMkzR34aZq4W23C6DAdZFaVrzWqzj24F8BC");
Expand Down Expand Up @@ -179,8 +179,7 @@ public async Task CanConfigureCheckout()
await s.Server.ExplorerNode.GenerateAsync(1);

// Fake Pay
s.Driver.FindElement(By.Id("FakePayAmount")).FillIn(amountFraction);
s.Driver.FindElement(By.Id("FakePay")).Click();
s.PayInvoice();
TestUtils.Eventually(() =>
{
Assert.Contains("Created transaction",
Expand All @@ -192,9 +191,7 @@ public async Task CanConfigureCheckout()
});

// Pay full amount
var amountDue = s.Driver.FindElement(By.Id("AmountDue")).GetAttribute("data-amount-due");
s.Driver.FindElement(By.Id("FakePayAmount")).FillIn(amountDue);
s.Driver.FindElement(By.Id("FakePay")).Click();
s.PayInvoice();

// Processing
TestUtils.Eventually(() =>
Expand All @@ -207,7 +204,7 @@ public async Task CanConfigureCheckout()
});

// Mine
s.Driver.FindElement(By.Id("Mine")).Click();
s.MineBlockOnInvoiceCheckout();
TestUtils.Eventually(() =>
{
Assert.Contains("Mined 1 block",
Expand Down Expand Up @@ -412,7 +409,6 @@ public async Task CanUseCheckoutAsModal()
s.GoToRegister();
s.RegisterNewUser();
s.CreateNewStore();
s.EnableCheckoutV2();
s.GoToStore();
s.AddDerivationScheme();
var invoiceId = s.CreateInvoice(0.001m, "BTC", "a@x.com");
Expand Down
18 changes: 13 additions & 5 deletions BTCPayServer.Tests/SeleniumTester.cs
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Abstractions.Models;
using BTCPayServer.Client.Models;
using BTCPayServer.Lightning;
using BTCPayServer.Lightning.CLightning;
using BTCPayServer.Views.Manage;
Expand Down Expand Up @@ -94,6 +95,7 @@ public void PayInvoice(bool mine = false, decimal? amount= null)
Driver.FindElement(By.Id("test-payment-amount")).Clear();
Driver.FindElement(By.Id("test-payment-amount")).SendKeys(amount.ToString());
}
Driver.WaitUntilAvailable(By.Id("FakePayment"));
Driver.FindElement(By.Id("FakePayment")).Click();
if (mine)
{
Expand Down Expand Up @@ -193,13 +195,19 @@ public TestAccount AsTestAccount()
StoreId = storeId;
return (name, storeId);
}

public void EnableCheckoutV2(bool bip21 = false)
public void EnableCheckout(CheckoutType checkoutType, bool bip21 = false)
{
GoToStore(StoreNavPages.CheckoutAppearance);
Driver.SetCheckbox(By.Id("UseNewCheckout"), true);
Driver.WaitForElement(By.Id("OnChainWithLnInvoiceFallback"));
Driver.SetCheckbox(By.Id("OnChainWithLnInvoiceFallback"), bip21);
if (checkoutType == CheckoutType.V2)
{
Driver.SetCheckbox(By.Id("UseClassicCheckout"), false);
Driver.WaitForElement(By.Id("OnChainWithLnInvoiceFallback"));
Driver.SetCheckbox(By.Id("OnChainWithLnInvoiceFallback"), bip21);
}
else
{
Driver.SetCheckbox(By.Id("UseClassicCheckout"), true);
}
Driver.FindElement(By.Id("Save")).SendKeys(Keys.Enter);
Assert.Contains("Store successfully updated", FindAlertMessage().Text);
Assert.True(Driver.FindElement(By.Id("UseNewCheckout")).Selected);
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer/Controllers/UIInvoiceController.UI.cs
Expand Up @@ -1157,7 +1157,7 @@ public async Task<IActionResult> CreateInvoice(InvoicesModel? model = null)
{
StoreId = model.StoreId,
Currency = storeBlob?.DefaultCurrency,
UseNewCheckout = storeBlob?.CheckoutType is CheckoutType.V2,
CheckoutType = storeBlob?.CheckoutType ?? CheckoutType.V2,
AvailablePaymentMethods = GetPaymentMethodsSelectList()
};

Expand All @@ -1172,7 +1172,7 @@ public async Task<IActionResult> CreateInvoice(CreateInvoiceModel model, Cancell
{
var store = HttpContext.GetStoreData();
var storeBlob = store.GetStoreBlob();
model.UseNewCheckout = storeBlob.CheckoutType == CheckoutType.V2;
model.CheckoutType = storeBlob.CheckoutType;
model.AvailablePaymentMethods = GetPaymentMethodsSelectList();

if (!ModelState.IsValid)
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer/Controllers/UIStoresController.cs
Expand Up @@ -385,7 +385,7 @@ public IActionResult CheckoutAppearance()
};
}).ToList();

vm.UseNewCheckout = storeBlob.CheckoutType == Client.Models.CheckoutType.V2;
vm.UseClassicCheckout = storeBlob.CheckoutType == Client.Models.CheckoutType.V1;
vm.CelebratePayment = storeBlob.CelebratePayment;
vm.OnChainWithLnInvoiceFallback = storeBlob.OnChainWithLnInvoiceFallback;
vm.ShowPayInWalletButton = storeBlob.ShowPayInWalletButton;
Expand Down Expand Up @@ -509,7 +509,7 @@ public async Task<IActionResult> CheckoutAppearance(CheckoutAppearanceViewModel

blob.ShowPayInWalletButton = model.ShowPayInWalletButton;
blob.ShowStoreHeader = model.ShowStoreHeader;
blob.CheckoutType = model.UseNewCheckout ? Client.Models.CheckoutType.V2 : Client.Models.CheckoutType.V1;
blob.CheckoutType = model.UseClassicCheckout ? Client.Models.CheckoutType.V1 : Client.Models.CheckoutType.V2;
blob.CelebratePayment = model.CelebratePayment;
blob.OnChainWithLnInvoiceFallback = model.OnChainWithLnInvoiceFallback;
blob.LightningAmountInSatoshi = model.LightningAmountInSatoshi;
Expand Down
3 changes: 3 additions & 0 deletions BTCPayServer/Data/StoreBlob.cs
Expand Up @@ -33,12 +33,15 @@ public StoreBlob()
RecommendedFeeBlockTarget = 1;
PaymentMethodCriteria = new List<PaymentMethodCriteria>();
ReceiptOptions = InvoiceDataBase.ReceiptOptions.CreateDefault();
CheckoutType = CheckoutType.V2;
}

[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public NetworkFeeMode NetworkFeeMode { get; set; }

[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
[DefaultValue(CheckoutType.V1)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public CheckoutType CheckoutType { get; set; }
public bool RequiresRefundEmail { get; set; }
public bool LightningAmountInSatoshi { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using BTCPayServer.Client.Models;
using BTCPayServer.Services.Apps;
using BTCPayServer.Validation;
using Microsoft.AspNetCore.Mvc.Rendering;
Expand Down Expand Up @@ -89,6 +90,6 @@ public RequiresRefundEmail RequiresRefundEmail
get; set;
}

public bool UseNewCheckout { get; set; }
public CheckoutType CheckoutType { get; set; }
}
}
Expand Up @@ -38,8 +38,8 @@ public void SetLanguages(LanguageService langService, string defaultLang)
[Display(Name = "Default payment method on checkout")]
public string DefaultPaymentMethod { get; set; }

[Display(Name = "Use the new checkout")]
public bool UseNewCheckout { get; set; }
[Display(Name = "Use the classic checkout")]
public bool UseClassicCheckout { get; set; }

[Display(Name = "Celebrate payment with confetti")]
public bool CelebratePayment { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions BTCPayServer/Views/UIInvoice/Checkout-Cheating.cshtml
Expand Up @@ -10,13 +10,13 @@
<form id="test-payment" :action="`/i/${invoiceId}/test-payment`" method="post" v-on:submit.prevent="handleFormSubmit($event, 'paying')" v-if="displayPayment">
<input name="CryptoCode" type="hidden" :value="cryptoCode">
<input name="PaymentMethodId" type="hidden" :value="paymentMethodId">
<label for="FakePayAmount" class="control-label form-label">Fake a {{cryptoCode}} payment for testing</label>
<label for="test-payment-amount" class="control-label form-label">Fake a {{cryptoCode}} payment for testing</label>
<div class="d-flex gap-2 mb-2">
<div class="input-group">
<input id="FakePayAmount" name="Amount" type="number" :step="isSats ? '1' : '0.00000001'" min="0" class="form-control" placeholder="Amount" v-model="amountRemaining" :disabled="paying || paymentMethodId === 'BTC_LightningLike'"/>
<input id="test-payment-amount" name="Amount" type="number" :step="isSats ? '1' : '0.00000001'" min="0" class="form-control" placeholder="Amount" v-model="amountRemaining" :disabled="paying || paymentMethodId === 'BTC_LightningLike'" />
<div id="test-payment-crypto-code" class="input-group-addon input-group-text" v-text="cryptoCode"></div>
</div>
<button class="btn btn-secondary flex-shrink-0 px-3 w-100px" type="submit" :disabled="paying" id="FakePay">Pay</button>
<button class="btn btn-secondary flex-shrink-0 px-3 w-100px" type="submit" :disabled="paying" id="FakePayment">Pay</button>
</div>
</form>
<form id="mine-block" :action="`/i/${invoiceId}/mine-blocks`" method="post" v-on:submit.prevent="handleFormSubmit($event, 'mining')" v-if="displayMine">
Expand All @@ -26,7 +26,7 @@
<input id="BlockCount" name="BlockCount" type="number" step="1" min="1" class="form-control" value="1"/>
<div class="input-group-addon input-group-text">blocks</div>
</div>
<button class="btn btn-secondary flex-shrink-0 px-3 w-100px" type="submit" :disabled="mining" id="Mine">Mine</button>
<button class="btn btn-secondary flex-shrink-0 px-3 w-100px" type="submit" :disabled="mining" id="mine-block">Mine</button>
</div>
</form>
<form id="expire-invoice" :action="`/i/${invoiceId}/expire`" method="post" v-on:submit.prevent="handleFormSubmit($event, 'expiring')" v-if="displayExpire">
Expand Down
27 changes: 9 additions & 18 deletions BTCPayServer/Views/UIStores/CheckoutAppearance.cshtml
Expand Up @@ -19,14 +19,14 @@
: ''
});
delegate('click', '#Presets_InStore', e => {
$("#UseNewCheckout").prop('checked', true);
$("#NewCheckoutSettings").addClass('show');
$("#UseClassicCheckout").prop('checked', false);
$("#CheckoutV2Settings").addClass('show');
$("#ShowPayInWalletButton").prop('checked', false);
$("#ShowStoreHeader").prop('checked', false);
});
delegate('click', '#Presets_Online', e => {
$("#UseNewCheckout").prop('checked', false);
$("#NewCheckoutSettings").removeClass('show');
$("#UseClassicCheckout").prop('checked', false);
$("#CheckoutV2Settings").addClass('show');
$("#ShowPayInWalletButton").prop('checked', true);
$("#ShowStoreHeader").prop('checked', true);
});
Expand Down Expand Up @@ -94,21 +94,12 @@
</h3>

<div class="d-flex align-items-center mb-3">
<input asp-for="UseNewCheckout" type="checkbox" class="btcpay-toggle me-3" data-bs-toggle="collapse" data-bs-target=".checkout-settings" aria-expanded="@(Model.UseNewCheckout)" aria-controls="NewCheckoutSettings" />
<div>
<label asp-for="UseNewCheckout" class="d-flex align-items-center form-label">
Use the new checkout
<span class="badge bg-warning ms-2">Experimental</span>
</label>
<span asp-validation-for="UseNewCheckout" class="text-danger"></span>
<div class="form-text">
Since v1.7.0 a new version of the checkout is available. Note: For now, the new version is English-only.<br />
We are still collecting <a href="https://github.com/btcpayserver/btcpayserver/discussions/4308" target="_blank" rel="noreferrer noopener">feedback</a> and offer this as an opt-in feature.
</div>
</div>
<input asp-for="UseClassicCheckout" type="checkbox" class="btcpay-toggle me-3" data-bs-toggle="collapse" data-bs-target=".checkout-settings" aria-expanded="@(Model.UseClassicCheckout)" aria-controls="CheckoutV2Settings" />
<label asp-for="UseClassicCheckout" class="form-label mb-0"></label>
<span asp-validation-for="UseClassicCheckout" class="text-danger"></span>
</div>

<div class="checkout-settings collapse @(Model.UseNewCheckout ? "show" : "")" id="NewCheckoutSettings">
<div class="checkout-settings collapse @(Model.UseClassicCheckout ? "" : "show")" id="CheckoutV2Settings">
<div class="form-group">
<label asp-for="DisplayExpirationTimer" class="form-label"></label>
<div class="input-group">
Expand Down Expand Up @@ -141,7 +132,7 @@
<input asp-for="LightningAmountInSatoshi" type="checkbox" class="form-check-input" />
<label asp-for="LightningAmountInSatoshi" class="form-check-label"></label>
</div>
<div class="checkout-settings collapse @(Model.UseNewCheckout ? "" : "show")" id="OldCheckoutSettings">
<div class="checkout-settings collapse @(Model.UseClassicCheckout ? "" : "show")" id="OldCheckoutSettings">
<div class="form-check">
<input asp-for="RequiresRefundEmail" type="checkbox" class="form-check-input" />
<label asp-for="RequiresRefundEmail" class="form-check-label"></label>
Expand Down

0 comments on commit 977b405

Please sign in to comment.