Enable/Disable tips and discount. Fix custom amount. (#612)

This commit is contained in:
Mario Dian 2019-02-25 14:11:03 +08:00 committed by Nicolas Dorier
parent dd52075ff1
commit 1e7a2ffe97
7 changed files with 64 additions and 0 deletions

View File

@ -55,12 +55,16 @@ namespace BTCPayServer.Controllers
" custom: true"; " custom: true";
EnableShoppingCart = false; EnableShoppingCart = false;
ShowCustomAmount = true; ShowCustomAmount = true;
ShowDiscount = true;
EnableTips = true;
} }
public string Title { get; set; } public string Title { get; set; }
public string Currency { get; set; } public string Currency { get; set; }
public string Template { get; set; } public string Template { get; set; }
public bool EnableShoppingCart { get; set; } public bool EnableShoppingCart { get; set; }
public bool ShowCustomAmount { get; set; } public bool ShowCustomAmount { get; set; }
public bool ShowDiscount { get; set; }
public bool EnableTips { get; set; }
public const string BUTTON_TEXT_DEF = "Buy for {0}"; public const string BUTTON_TEXT_DEF = "Buy for {0}";
public string ButtonText { get; set; } = BUTTON_TEXT_DEF; public string ButtonText { get; set; } = BUTTON_TEXT_DEF;
@ -89,6 +93,8 @@ namespace BTCPayServer.Controllers
Title = settings.Title, Title = settings.Title,
EnableShoppingCart = settings.EnableShoppingCart, EnableShoppingCart = settings.EnableShoppingCart,
ShowCustomAmount = settings.ShowCustomAmount, ShowCustomAmount = settings.ShowCustomAmount,
ShowDiscount = settings.ShowDiscount,
EnableTips = settings.EnableTips,
Currency = settings.Currency, Currency = settings.Currency,
Template = settings.Template, Template = settings.Template,
ButtonText = settings.ButtonText ?? PointOfSaleSettings.BUTTON_TEXT_DEF, ButtonText = settings.ButtonText ?? PointOfSaleSettings.BUTTON_TEXT_DEF,
@ -160,6 +166,8 @@ namespace BTCPayServer.Controllers
Title = vm.Title, Title = vm.Title,
EnableShoppingCart = vm.EnableShoppingCart, EnableShoppingCart = vm.EnableShoppingCart,
ShowCustomAmount = vm.ShowCustomAmount, ShowCustomAmount = vm.ShowCustomAmount,
ShowDiscount = vm.ShowDiscount,
EnableTips = vm.EnableTips,
Currency = vm.Currency.ToUpperInvariant(), Currency = vm.Currency.ToUpperInvariant(),
Template = vm.Template, Template = vm.Template,
ButtonText = vm.ButtonText, ButtonText = vm.ButtonText,

View File

@ -62,6 +62,8 @@ namespace BTCPayServer.Controllers
Step = step.ToString(CultureInfo.InvariantCulture), Step = step.ToString(CultureInfo.InvariantCulture),
EnableShoppingCart = settings.EnableShoppingCart, EnableShoppingCart = settings.EnableShoppingCart,
ShowCustomAmount = settings.ShowCustomAmount, ShowCustomAmount = settings.ShowCustomAmount,
ShowDiscount = settings.ShowDiscount,
EnableTips = settings.EnableTips,
CurrencyCode = settings.Currency, CurrencyCode = settings.Currency,
CurrencySymbol = numberFormatInfo.CurrencySymbol, CurrencySymbol = numberFormatInfo.CurrencySymbol,
CurrencyInfo = new ViewPointOfSaleViewModel.CurrencyInfoData() CurrencyInfo = new ViewPointOfSaleViewModel.CurrencyInfoData()

View File

@ -17,6 +17,10 @@ namespace BTCPayServer.Models.AppViewModels
public bool EnableShoppingCart { get; set; } public bool EnableShoppingCart { get; set; }
[Display(Name = "User can input custom amount")] [Display(Name = "User can input custom amount")]
public bool ShowCustomAmount { get; set; } public bool ShowCustomAmount { get; set; }
[Display(Name = "User can input discount in %")]
public bool ShowDiscount { get; set; }
[Display(Name = "Enable tips")]
public bool EnableTips { get; set; }
public string Example1 { get; internal set; } public string Example1 { get; internal set; }
public string Example2 { get; internal set; } public string Example2 { get; internal set; }
public string ExampleCallback { get; internal set; } public string ExampleCallback { get; internal set; }

View File

@ -36,6 +36,8 @@ namespace BTCPayServer.Models.AppViewModels
public bool EnableShoppingCart { get; set; } public bool EnableShoppingCart { get; set; }
public bool ShowCustomAmount { get; set; } public bool ShowCustomAmount { get; set; }
public bool ShowDiscount { get; set; }
public bool EnableTips { get; set; }
public string Step { get; set; } public string Step { get; set; }
public string Title { get; set; } public string Title { get; set; }
public Item[] Items { get; set; } public Item[] Items { get; set; }

View File

@ -57,6 +57,14 @@
<label asp-for="ShowCustomAmount"></label> <label asp-for="ShowCustomAmount"></label>
<input asp-for="ShowCustomAmount" type="checkbox" class="form-check" /> <input asp-for="ShowCustomAmount" type="checkbox" class="form-check" />
</div> </div>
<div class="form-group">
<label asp-for="ShowDiscount"></label>
<input asp-for="ShowDiscount" type="checkbox" class="form-check" />
</div>
<div class="form-group">
<label asp-for="EnableTips"></label>
<input asp-for="EnableTips" type="checkbox" class="form-check" />
</div>
<div class="form-group"> <div class="form-group">
<label asp-for="ButtonText" class="control-label"></label>* <label asp-for="ButtonText" class="control-label"></label>*
<input asp-for="ButtonText" class="form-control" /> <input asp-for="ButtonText" class="form-control" />

View File

@ -93,6 +93,8 @@
</div> </div>
</td> </td>
</tr> </tr>
@if (Model.ShowDiscount)
{
<tr> <tr>
<td colspan="5" class="border-top-0"> <td colspan="5" class="border-top-0">
<div class="input-group"> <div class="input-group">
@ -106,9 +108,12 @@
</div> </div>
</td> </td>
</tr> </tr>
}
</script> </script>
<script id="template-cart-tip" type="text/template"> <script id="template-cart-tip" type="text/template">
@if (Model.EnableTips)
{
<tr class="h5"> <tr class="h5">
<td colspan="5" class="border-top-0 pt-4">@Model.CustomTipText</td> <td colspan="5" class="border-top-0 pt-4">@Model.CustomTipText</td>
</tr> </tr>
@ -135,6 +140,7 @@
</div> </div>
</td> </td>
</tr> </tr>
}
</script> </script>
<script id="template-cart-total" type="text/template"> <script id="template-cart-total" type="text/template">
@ -170,18 +176,24 @@
<span class="js-cart-summary-products text-nowrap"></span> <span class="js-cart-summary-products text-nowrap"></span>
</td> </td>
</tr> </tr>
@if (Model.ShowDiscount)
{
<tr class="h6"> <tr class="h6">
<td class="border-0 pb-y">Discount</td> <td class="border-0 pb-y">Discount</td>
<td align="right" class="border-0 pb-y"> <td align="right" class="border-0 pb-y">
<span class="js-cart-summary-discount text-nowrap"></span> <span class="js-cart-summary-discount text-nowrap"></span>
</td> </td>
</tr> </tr>
}
@if (Model.EnableTips)
{
<tr class="h6"> <tr class="h6">
<td class="border-top-0 pt-0">Tip</td> <td class="border-top-0 pt-0">Tip</td>
<td align="right" class="border-top-0 pt-0"> <td align="right" class="border-top-0 pt-0">
<span class="js-cart-summary-tip text-nowrap"></span> <span class="js-cart-summary-tip text-nowrap"></span>
</td> </td>
</tr> </tr>
}
<tr class="h3 table-light"> <tr class="h3 table-light">
<td>Total</td> <td>Total</td>
<td align="right"> <td align="right">

View File

@ -25,6 +25,10 @@ function Cart() {
} }
Cart.prototype.setCustomAmount = function(amount) { Cart.prototype.setCustomAmount = function(amount) {
if (!srvModel.showCustomAmount) {
return 0;
}
this.customAmount = this.toNumber(amount); this.customAmount = this.toNumber(amount);
if (this.customAmount > 0) { if (this.customAmount > 0) {
@ -36,10 +40,18 @@ Cart.prototype.setCustomAmount = function(amount) {
} }
Cart.prototype.getCustomAmount = function() { Cart.prototype.getCustomAmount = function() {
if (!srvModel.showCustomAmount) {
return 0;
}
return this.toCents(this.customAmount); return this.toCents(this.customAmount);
} }
Cart.prototype.setTip = function(amount) { Cart.prototype.setTip = function(amount) {
if (!srvModel.enableTips) {
return 0;
}
this.tip = this.toNumber(amount); this.tip = this.toNumber(amount);
if (this.tip > 0) { if (this.tip > 0) {
@ -51,10 +63,18 @@ Cart.prototype.setTip = function(amount) {
} }
Cart.prototype.getTip = function() { Cart.prototype.getTip = function() {
if (!srvModel.enableTips) {
return 0;
}
return this.toCents(this.tip); return this.toCents(this.tip);
} }
Cart.prototype.setDiscount = function(amount) { Cart.prototype.setDiscount = function(amount) {
if (!srvModel.showDiscount) {
return 0;
}
this.discount = this.toNumber(amount); this.discount = this.toNumber(amount);
if (this.discount > 0) { if (this.discount > 0) {
@ -66,10 +86,18 @@ Cart.prototype.setDiscount = function(amount) {
} }
Cart.prototype.getDiscount = function() { Cart.prototype.getDiscount = function() {
if (!srvModel.showDiscount) {
return 0;
}
return this.toCents(this.discount); return this.toCents(this.discount);
} }
Cart.prototype.getDiscountAmount = function(amount) { Cart.prototype.getDiscountAmount = function(amount) {
if (!srvModel.showDiscount) {
return 0;
}
return this.percentage(amount, this.getDiscount()); return this.percentage(amount, this.getDiscount());
} }