Can set LazyPaymentMethod at the invoice creation level

This commit is contained in:
nicolas.dorier
2023-04-24 23:58:58 +09:00
parent d8698181f4
commit bee18d1cfb
5 changed files with 10 additions and 12 deletions

View File

@@ -86,6 +86,7 @@ namespace BTCPayServer.Client.Models
public bool? RequiresRefundEmail { get; set; } = null; public bool? RequiresRefundEmail { get; set; } = null;
public string DefaultLanguage { get; set; } public string DefaultLanguage { get; set; }
public CheckoutType? CheckoutType { get; set; } public CheckoutType? CheckoutType { get; set; }
public bool? LazyPaymentMethods { get; set; }
} }
} }
public class InvoiceData : InvoiceDataBase public class InvoiceData : InvoiceDataBase

View File

@@ -248,6 +248,7 @@ namespace BTCPayServer.Controllers
entity.RedirectAutomatically = invoice.Checkout.RedirectAutomatically ?? storeBlob.RedirectAutomatically; entity.RedirectAutomatically = invoice.Checkout.RedirectAutomatically ?? storeBlob.RedirectAutomatically;
entity.CheckoutType = invoice.Checkout.CheckoutType; entity.CheckoutType = invoice.Checkout.CheckoutType;
entity.RequiresRefundEmail = invoice.Checkout.RequiresRefundEmail; entity.RequiresRefundEmail = invoice.Checkout.RequiresRefundEmail;
entity.LazyPaymentMethods = invoice.Checkout.LazyPaymentMethods ?? storeBlob.LazyPaymentMethods;
IPaymentFilter? excludeFilter = null; IPaymentFilter? excludeFilter = null;
if (invoice.Checkout.PaymentMethods != null) if (invoice.Checkout.PaymentMethods != null)
{ {
@@ -460,7 +461,7 @@ namespace BTCPayServer.Controllers
var storeBlob = store.GetStoreBlob(); var storeBlob = store.GetStoreBlob();
// Checkout v2 does not show a payment method switch for Bitcoin-only + BIP21, so exclude that case // Checkout v2 does not show a payment method switch for Bitcoin-only + BIP21, so exclude that case
var preparePayment = storeBlob.LazyPaymentMethods && !storeBlob.OnChainWithLnInvoiceFallback var preparePayment = entity.LazyPaymentMethods && !storeBlob.OnChainWithLnInvoiceFallback
? null ? null
: handler.PreparePayment(supportedPaymentMethod, store, network); : handler.PreparePayment(supportedPaymentMethod, store, network);
var rate = await fetchingByCurrencyPair[new CurrencyPair(network.CryptoCode, entity.Currency)]; var rate = await fetchingByCurrencyPair[new CurrencyPair(network.CryptoCode, entity.Currency)];

View File

@@ -447,19 +447,9 @@ namespace BTCPayServer
try try
{ {
createInvoice.Checkout ??= new InvoiceDataBase.CheckoutOptions(); createInvoice.Checkout ??= new InvoiceDataBase.CheckoutOptions();
createInvoice.Checkout.LazyPaymentMethods = false;
createInvoice.Checkout.PaymentMethods = new[] { pmi.ToStringNormalized() }; createInvoice.Checkout.PaymentMethods = new[] { pmi.ToStringNormalized() };
i = await _invoiceController.CreateInvoiceCoreRaw(createInvoice, store, Request.GetAbsoluteRoot(), additionalTags); i = await _invoiceController.CreateInvoiceCoreRaw(createInvoice, store, Request.GetAbsoluteRoot(), additionalTags);
var pm = i.GetPaymentMethod(pmi);
if (pm is null)
return NotFound("LNUrl is enabled, but the invoice couldn't use it. Check the invoice's events for more information.");
// If LNUrl isn't activated, make sure it is
var pmd = pm.GetPaymentMethodDetails();
if (!pmd.Activated)
{
if (!await _invoiceActivator.ActivateInvoicePaymentMethod(pmi, i, store))
return NotFound("Unable to activate LNURL. Check the invoice's events for more information.");
i = await _invoiceRepository.GetInvoice(i.Id);
}
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -461,6 +461,7 @@ namespace BTCPayServer.Services.Invoices
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public CheckoutType? CheckoutType { get; set; } public CheckoutType? CheckoutType { get; set; }
public bool LazyPaymentMethods { get; set; }
public bool IsExpired() public bool IsExpired()
{ {

View File

@@ -1173,6 +1173,11 @@
"nullable": true, "nullable": true,
"description": "Default payment type for the invoice (e.g., BTC, BTC-LightningNetwork). Default payment method set for the store is used if this parameter is not specified." "description": "Default payment type for the invoice (e.g., BTC, BTC-LightningNetwork). Default payment method set for the store is used if this parameter is not specified."
}, },
"lazyPaymentMethods": {
"type": "boolean",
"nullable": true,
"description": "If true, payment methods are enabled individually upon user interaction in the invoice. Default to store's settings'"
},
"expirationMinutes": { "expirationMinutes": {
"nullable": true, "nullable": true,
"description": "The number of minutes after which an invoice becomes expired. Defaults to the store's settings. (The default store settings is 15)", "description": "The number of minutes after which an invoice becomes expired. Defaults to the store's settings. (The default store settings is 15)",