btcpayserver/BTCPayServer/Views/Stores/CheckoutExperience.cshtml
Wouter Samaey d8c1c51a21
Auto-detect language on payment page (#2552)
* Auto-detect language on payment page

based on the requst Accept-Language header, which is the language you configured in your browser/OS and this 99.99% accurate

* Update BTCPayServer/Services/LanguageService.cs

Co-authored-by: britttttk <39231115+britttttk@users.noreply.github.com>

* Update BTCPayServer/Services/LanguageService.cs

Co-authored-by: Andrew Camilleri <evilkukka@gmail.com>

* Update BTCPayServer/Services/LanguageService.cs

Co-authored-by: Andrew Camilleri <evilkukka@gmail.com>

* Update BTCPayServer/Services/LanguageService.cs

Co-authored-by: Andrew Camilleri <evilkukka@gmail.com>

* Added loop for all locales in Accept-Language sorted by weight + check if know this language

* New public method so a unit test can be created for it

* Unit test for language detection

* Fix language service when not in browser context

* fall back to default lang

* Auto-detect setting + ?lang=auto support

* Added invoice param "?lang=auto" info to docs

* Using null-coalescing assignment operator

* Reduce complexity and http dependency in language service

Co-authored-by: britttttk <39231115+britttttk@users.noreply.github.com>
Co-authored-by: Andrew Camilleri <evilkukka@gmail.com>
2021-07-27 08:17:56 +02:00

141 lines
7.6 KiB
Text

@using BTCPayServer.Payments
@model CheckoutExperienceViewModel
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewData.SetActivePageAndTitle(StoreNavPages.Checkout, "Checkout experience", Context.GetStoreData().StoreName);
}
<div class="row">
<div class="col-lg-8">
<form method="post">
@if (!ViewContext.ModelState.IsValid)
{
<div asp-validation-summary="All" class="text-danger"></div>
}
<h4 class="mb-3">Payment</h4>
@if (Model.PaymentMethods.Any())
{
<div class="form-group mb-4">
<label asp-for="DefaultPaymentMethod" class="form-label"></label>
<select asp-for="DefaultPaymentMethod" asp-items="Model.PaymentMethods" class="form-select w-auto"></select>
</div>
<div class="form-group mb-4">
<div class="form-label mb-1">Enable payment methods only when amount is …</div>
<table class="table">
@for (var index = 0; index < Model.PaymentMethodCriteria.Count; index++)
{
var criteria = Model.PaymentMethodCriteria[index];
<tr>
<td class="border-0 ps-0 align-middle">
<input type="hidden" asp-for="PaymentMethodCriteria[index].PaymentMethod"/>
@PaymentMethodId.Parse(criteria.PaymentMethod).ToPrettyString()
</td>
<td class="border-0">
<select asp-for="PaymentMethodCriteria[index].Type" class="form-select"
asp-items="@((PaymentMethodCriteriaViewModel.CriteriaType[]) Enum.GetValues(typeof(PaymentMethodCriteriaViewModel.CriteriaType))).Select(s => new SelectListItem(PaymentMethodCriteriaViewModel.ToString(s), s.ToString()))">
</select>
</td>
<td class="border-0">
<input placeholder="6.15 USD" asp-for="PaymentMethodCriteria[index].Value" class="form-control my-0" style="max-width: 20ch;"/>
</td>
</tr>
}
</table>
</div>
}
<h5 class="mb-3">General</h5>
<div class="form-check my-1">
<input asp-for="RequiresRefundEmail" type="checkbox" class="form-check-input"/>
<label asp-for="RequiresRefundEmail" class="form-check-label"></label>
</div>
<div class="form-check my-1">
<input asp-for="LazyPaymentMethods" type="checkbox" class="form-check-input" />
<label asp-for="LazyPaymentMethods" class="form-check-label"></label>
</div>
<div class="form-check my-1">
<input asp-for="RedirectAutomatically" type="checkbox" class="form-check-input" />
<label asp-for="RedirectAutomatically" class="form-check-label"></label>
</div>
<div class="form-check my-1">
<input asp-for="ShowRecommendedFee" type="checkbox" class="form-check-input"/>
<label asp-for="ShowRecommendedFee" class="form-check-label"></label>
<p class="form-text text-muted mb-0">Fee will be shown for BTC and LTC onchain payments only.</p>
</div>
<div class="form-group mt-2 mb-4">
<label asp-for="RecommendedFeeBlockTarget" class="form-label"></label>
<input asp-for="RecommendedFeeBlockTarget" class="form-control" style="width:8ch" min="1" />
<span asp-validation-for="RecommendedFeeBlockTarget" class="text-danger"></span>
</div>
<h5 class="mt-4 mb-3">Lightning</h5>
<div class="form-check my-1">
<input asp-for="LightningAmountInSatoshi" type="checkbox" class="form-check-input"/>
<label asp-for="LightningAmountInSatoshi" class="form-check-label"></label>
</div>
<div class="form-check my-1">
<input asp-for="LightningPrivateRouteHints" type="checkbox" class="form-check-input"/>
<label asp-for="LightningPrivateRouteHints" class="form-check-label"></label>
</div>
<div class="form-check my-1">
<input asp-for="OnChainWithLnInvoiceFallback" type="checkbox" class="form-check-input"/>
<label asp-for="OnChainWithLnInvoiceFallback" class="form-check-label"></label>
</div>
<h4 class="mt-5 mb-3">Appearance</h4>
<div class="form-group">
<div class="form-check">
<input asp-for="AutoDetectLanguage" type="checkbox" class="form-check-input"/>
<label asp-for="AutoDetectLanguage" class="form-check-label"></label>
<p class="form-text text-muted">Detects the language of the customer's browser with 99.9% accuracy.</p>
</div>
</div>
<div class="form-group">
<label asp-for="DefaultLang" class="form-label"></label>
<select asp-for="DefaultLang" asp-items="Model.Languages" class="form-select w-auto"></select>
</div>
<div class="form-group">
<label asp-for="HtmlTitle" class="form-label"></label>
<input asp-for="HtmlTitle" class="form-control"/>
<span asp-validation-for="HtmlTitle" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CustomLogo" class="form-label"></label>
<a href="https://docs.btcpayserver.org/Theme/#checkout-page-themes" target="_blank" rel="noreferrer noopener">
<span class="fa fa-question-circle-o text-secondary" title="More information..."></span>
</a>
<input asp-for="CustomLogo" class="form-control"/>
<span asp-validation-for="CustomLogo" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CustomCSS" class="form-label"></label>
<a href="https://docs.btcpayserver.org/Theme/#checkout-page-themes" target="_blank" rel="noreferrer noopener">
<span class="fa fa-question-circle-o text-secondary" title="More information..."></span>
</a>
<input asp-for="CustomCSS" class="form-control"/>
<span asp-validation-for="CustomCSS" class="text-danger"></span>
<p class="form-text text-muted">
Bundled Themes:
<a href="#" onclick="return setTheme(1);">Legacy</a>
| <a href="#" onclick="return setTheme(2);">Dark</a>
</p>
</div>
<button name="command" type="submit" class="btn btn-primary" value="Save">Save</button>
</form>
</div>
</div>
@section PageFootContent {
<partial name="_ValidationScriptsPartial" />
<script type="text/javascript">
function setTheme(themeChoice) {
if (themeChoice === 1) { // reserving 0 for potential clear down the road
$('#CustomCSS').val('/checkout/css/themes/legacy.css');
} else if (themeChoice === 2) {
$('#CustomCSS').val('/checkout/css/themes/dark.css');
} else {
$('#CustomCSS').val('');
}
return false;
}
</script>
}