mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 01:43:50 +01:00
[Greenfield] Select default payoutMethodId if none are selected in the Refund route (#6315)
This commit is contained in:
parent
77fba4aee3
commit
7b6a115adc
@ -51,6 +51,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
private readonly Dictionary<PaymentMethodId, IPaymentLinkExtension> _paymentLinkExtensions;
|
||||
private readonly PayoutMethodHandlerDictionary _payoutHandlers;
|
||||
private readonly PaymentMethodHandlerDictionary _handlers;
|
||||
private readonly BTCPayNetworkProvider _networkProvider;
|
||||
private readonly DefaultRulesCollection _defaultRules;
|
||||
|
||||
public LanguageService LanguageService { get; }
|
||||
@ -65,6 +66,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
Dictionary<PaymentMethodId, IPaymentLinkExtension> paymentLinkExtensions,
|
||||
PayoutMethodHandlerDictionary payoutHandlers,
|
||||
PaymentMethodHandlerDictionary handlers,
|
||||
BTCPayNetworkProvider networkProvider,
|
||||
DefaultRulesCollection defaultRules)
|
||||
{
|
||||
_invoiceController = invoiceController;
|
||||
@ -79,6 +81,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
_paymentLinkExtensions = paymentLinkExtensions;
|
||||
_payoutHandlers = payoutHandlers;
|
||||
_handlers = handlers;
|
||||
_networkProvider = networkProvider;
|
||||
_defaultRules = defaultRules;
|
||||
LanguageService = languageService;
|
||||
}
|
||||
@ -338,6 +341,9 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
}
|
||||
PaymentPrompt? paymentPrompt = null;
|
||||
PayoutMethodId? payoutMethodId = null;
|
||||
if (request.PayoutMethodId is null)
|
||||
request.PayoutMethodId = invoice.GetDefaultPaymentMethodId(store, _networkProvider)?.ToString();
|
||||
|
||||
if (request.PayoutMethodId is not null && PayoutMethodId.TryParse(request.PayoutMethodId, out payoutMethodId))
|
||||
{
|
||||
var supported = _payoutHandlers.GetSupportedPayoutMethods(store);
|
||||
|
@ -764,34 +764,7 @@ namespace BTCPayServer.Controllers
|
||||
paymentMethodId = null;
|
||||
if (paymentMethodId is null)
|
||||
{
|
||||
PaymentMethodId? invoicePaymentId = invoice.DefaultPaymentMethod;
|
||||
PaymentMethodId? storePaymentId = store.GetDefaultPaymentId();
|
||||
if (invoicePaymentId is not null)
|
||||
{
|
||||
if (displayedPaymentMethods.Contains(invoicePaymentId))
|
||||
paymentMethodId = invoicePaymentId;
|
||||
}
|
||||
if (paymentMethodId is null && storePaymentId is not null)
|
||||
{
|
||||
if (displayedPaymentMethods.Contains(storePaymentId))
|
||||
paymentMethodId = storePaymentId;
|
||||
}
|
||||
if (paymentMethodId is null && invoicePaymentId is not null)
|
||||
{
|
||||
paymentMethodId = invoicePaymentId.FindNearest(displayedPaymentMethods);
|
||||
}
|
||||
if (paymentMethodId is null && storePaymentId is not null)
|
||||
{
|
||||
paymentMethodId = storePaymentId.FindNearest(displayedPaymentMethods);
|
||||
}
|
||||
if (paymentMethodId is null)
|
||||
{
|
||||
var defaultBTC = PaymentTypes.CHAIN.GetPaymentMethodId(_NetworkProvider.DefaultNetwork.CryptoCode);
|
||||
var defaultLNURLPay = PaymentTypes.LNURL.GetPaymentMethodId(_NetworkProvider.DefaultNetwork.CryptoCode);
|
||||
paymentMethodId = displayedPaymentMethods.FirstOrDefault(e => e == defaultBTC) ??
|
||||
displayedPaymentMethods.FirstOrDefault(e => e == defaultLNURLPay) ??
|
||||
displayedPaymentMethods.FirstOrDefault();
|
||||
}
|
||||
paymentMethodId = invoice.GetDefaultPaymentMethodId(store, _NetworkProvider, displayedPaymentMethods);
|
||||
isDefaultPaymentId = true;
|
||||
}
|
||||
if (paymentMethodId is null)
|
||||
|
@ -371,6 +371,45 @@ namespace BTCPayServer.Services.Invoices
|
||||
get;
|
||||
set;
|
||||
} = new Dictionary<string, decimal>();
|
||||
|
||||
#nullable enable
|
||||
public PaymentMethodId? GetDefaultPaymentMethodId(Data.StoreData store, BTCPayNetworkProvider networkProvider, HashSet<PaymentMethodId>? authorized = null)
|
||||
{
|
||||
PaymentMethodId? paymentMethodId = null;
|
||||
PaymentMethodId? invoicePaymentId = DefaultPaymentMethod;
|
||||
PaymentMethodId? storePaymentId = store.GetDefaultPaymentId();
|
||||
authorized ??= GetPaymentPrompts().Select(p => p.PaymentMethodId).ToHashSet();
|
||||
if (invoicePaymentId is not null)
|
||||
{
|
||||
if (authorized.Contains(invoicePaymentId))
|
||||
paymentMethodId = invoicePaymentId;
|
||||
}
|
||||
if (paymentMethodId is null && storePaymentId is not null)
|
||||
{
|
||||
if (authorized.Contains(storePaymentId))
|
||||
paymentMethodId = storePaymentId;
|
||||
}
|
||||
if (paymentMethodId is null && invoicePaymentId is not null)
|
||||
{
|
||||
paymentMethodId = invoicePaymentId.FindNearest(authorized);
|
||||
}
|
||||
if (paymentMethodId is null && storePaymentId is not null)
|
||||
{
|
||||
paymentMethodId = storePaymentId.FindNearest(authorized);
|
||||
}
|
||||
if (paymentMethodId is null)
|
||||
{
|
||||
var defaultBTC = PaymentTypes.CHAIN.GetPaymentMethodId(networkProvider.DefaultNetwork.CryptoCode);
|
||||
var defaultLNURLPay = PaymentTypes.LNURL.GetPaymentMethodId(networkProvider.DefaultNetwork.CryptoCode);
|
||||
paymentMethodId = authorized.FirstOrDefault(e => e == defaultBTC) ??
|
||||
authorized.FirstOrDefault(e => e == defaultLNURLPay) ??
|
||||
authorized.FirstOrDefault();
|
||||
}
|
||||
|
||||
return paymentMethodId;
|
||||
}
|
||||
#nullable restore
|
||||
|
||||
public void UpdateTotals()
|
||||
{
|
||||
PaidAmount = new Amounts()
|
||||
|
Loading…
Reference in New Issue
Block a user