mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Add ability to select default payment method for invoice through UI
This commit is contained in:
committed by
Andrew Camilleri
parent
bb6a188883
commit
809340e629
@@ -476,7 +476,7 @@ namespace BTCPayServer.Controllers
|
|||||||
bool isDefaultPaymentId = false;
|
bool isDefaultPaymentId = false;
|
||||||
if (paymentMethodId is null)
|
if (paymentMethodId is null)
|
||||||
{
|
{
|
||||||
paymentMethodId = store.GetDefaultPaymentId(_NetworkProvider);
|
paymentMethodId = _InvoiceRepository.GetDefaultPaymentId(store.GetEnabledPaymentIds(_NetworkProvider), invoice) ?? store.GetDefaultPaymentId(_NetworkProvider);
|
||||||
isDefaultPaymentId = true;
|
isDefaultPaymentId = true;
|
||||||
}
|
}
|
||||||
BTCPayNetworkBase network = _NetworkProvider.GetNetwork<BTCPayNetworkBase>(paymentMethodId.CryptoCode);
|
BTCPayNetworkBase network = _NetworkProvider.GetNetwork<BTCPayNetworkBase>(paymentMethodId.CryptoCode);
|
||||||
@@ -854,7 +854,8 @@ namespace BTCPayServer.Controllers
|
|||||||
SupportedTransactionCurrencies = model.SupportedTransactionCurrencies?.ToDictionary(s => s, s => new InvoiceSupportedTransactionCurrency()
|
SupportedTransactionCurrencies = model.SupportedTransactionCurrencies?.ToDictionary(s => s, s => new InvoiceSupportedTransactionCurrency()
|
||||||
{
|
{
|
||||||
Enabled = true
|
Enabled = true
|
||||||
})
|
}),
|
||||||
|
DefaultPaymentMethod = model.DefaultPaymentMethod,
|
||||||
}, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken);
|
}, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken);
|
||||||
|
|
||||||
TempData[WellKnownTempData.SuccessMessage] = $"Invoice {result.Data.Id} just created!";
|
TempData[WellKnownTempData.SuccessMessage] = $"Invoice {result.Data.Id} just created!";
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ namespace BTCPayServer.Controllers
|
|||||||
excludeFilter = PaymentFilter.Where(p => !supportedTransactionCurrencies.Contains(p));
|
excludeFilter = PaymentFilter.Where(p => !supportedTransactionCurrencies.Contains(p));
|
||||||
}
|
}
|
||||||
entity.PaymentTolerance = storeBlob.PaymentTolerance;
|
entity.PaymentTolerance = storeBlob.PaymentTolerance;
|
||||||
|
entity.DefaultPaymentMethod = invoice.DefaultPaymentMethod;
|
||||||
return await CreateInvoiceCoreRaw(entity, store, excludeFilter, null, cancellationToken);
|
return await CreateInvoiceCoreRaw(entity, store, excludeFilter, null, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NBitpayClient;
|
using NBitpayClient;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Models
|
namespace BTCPayServer.Models
|
||||||
{
|
{
|
||||||
@@ -52,6 +51,8 @@ namespace BTCPayServer.Models
|
|||||||
public string Currency { get; set; }
|
public string Currency { get; set; }
|
||||||
[JsonProperty(PropertyName = "price", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
[JsonProperty(PropertyName = "price", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
public decimal? Price { get; set; }
|
public decimal? Price { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "defaultPaymentMethod", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
|
public string DefaultPaymentMethod { get; set; }
|
||||||
[JsonProperty(PropertyName = "notificationEmail", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
[JsonProperty(PropertyName = "notificationEmail", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
public string NotificationEmail { get; set; }
|
public string NotificationEmail { get; set; }
|
||||||
[JsonConverter(typeof(DateTimeJsonConverter))]
|
[JsonConverter(typeof(DateTimeJsonConverter))]
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Display(Name = "Default payment method on checkout")]
|
||||||
|
public string DefaultPaymentMethod
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
[DisplayName("POS Data")]
|
[DisplayName("POS Data")]
|
||||||
public string PosData
|
public string PosData
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
|
|
||||||
public decimal Price { get; set; }
|
public decimal Price { get; set; }
|
||||||
public string Currency { get; set; }
|
public string Currency { get; set; }
|
||||||
|
public string DefaultPaymentMethod { get; set; }
|
||||||
|
|
||||||
[JsonExtensionData]
|
[JsonExtensionData]
|
||||||
public IDictionary<string, JToken> AdditionalData { get; set; }
|
public IDictionary<string, JToken> AdditionalData { get; set; }
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
{
|
{
|
||||||
public static class InvoiceExtensions
|
public static class InvoiceExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
public static async Task ActivateInvoicePaymentMethod(this InvoiceRepository invoiceRepository,
|
public static async Task ActivateInvoicePaymentMethod(this InvoiceRepository invoiceRepository,
|
||||||
EventAggregator eventAggregator, BTCPayNetworkProvider btcPayNetworkProvider, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
|
EventAggregator eventAggregator, BTCPayNetworkProvider btcPayNetworkProvider, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
|
||||||
StoreData store,InvoiceEntity invoice, PaymentMethodId paymentMethodId)
|
StoreData store,InvoiceEntity invoice, PaymentMethodId paymentMethodId)
|
||||||
{
|
{
|
||||||
@@ -49,5 +49,18 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PaymentMethodId GetDefaultPaymentId(
|
||||||
|
this InvoiceRepository invoiceRepository,
|
||||||
|
PaymentMethodId[] paymentMethodIds,
|
||||||
|
InvoiceEntity invoice
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PaymentMethodId.TryParse(invoice.DefaultPaymentMethod, out var defaultPaymentId);
|
||||||
|
var chosen = paymentMethodIds.FirstOrDefault(f => f == defaultPaymentId) ??
|
||||||
|
paymentMethodIds.FirstOrDefault(f => f.CryptoCode == defaultPaymentId?.CryptoCode) ??
|
||||||
|
paymentMethodIds.FirstOrDefault();
|
||||||
|
return chosen;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,11 @@
|
|||||||
<select asp-for="SupportedTransactionCurrencies" asp-items="Model.AvailablePaymentMethods" class="form-select" multiple="multiple"></select>
|
<select asp-for="SupportedTransactionCurrencies" asp-items="Model.AvailablePaymentMethods" class="form-select" multiple="multiple"></select>
|
||||||
<span asp-validation-for="SupportedTransactionCurrencies" class="text-danger"></span>
|
<span asp-validation-for="SupportedTransactionCurrencies" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="DefaultPaymentMethod" class="form-label"></label>
|
||||||
|
<select asp-for="DefaultPaymentMethod" asp-items="Model.AvailablePaymentMethods" class="form-select"></select>
|
||||||
|
<span asp-validation-for="DefaultPaymentMethod" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="submit" value="Create" class="btn btn-primary" id="Create" />
|
<input type="submit" value="Create" class="btn btn-primary" id="Create" />
|
||||||
<a asp-action="ListInvoices" class="text-muted ms-3">Back to list</a>
|
<a asp-action="ListInvoices" class="text-muted ms-3">Back to list</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user