2021-11-05 04:16:54 +01:00
|
|
|
using System;
|
2021-10-25 08:18:02 +02:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2022-12-04 13:23:59 +01:00
|
|
|
using System.Threading;
|
2021-10-25 08:18:02 +02:00
|
|
|
using System.Threading.Tasks;
|
2021-10-29 10:27:33 +02:00
|
|
|
using BTCPayServer.Abstractions.Constants;
|
|
|
|
using BTCPayServer.Abstractions.Extensions;
|
|
|
|
using BTCPayServer.Abstractions.Models;
|
|
|
|
using BTCPayServer.Client;
|
2021-10-25 08:18:02 +02:00
|
|
|
using BTCPayServer.Client.Models;
|
|
|
|
using BTCPayServer.Controllers;
|
|
|
|
using BTCPayServer.Data;
|
2022-06-28 16:02:17 +02:00
|
|
|
using BTCPayServer.Data.Payouts.LightningLike;
|
2021-10-25 08:18:02 +02:00
|
|
|
using BTCPayServer.Events;
|
2022-06-28 16:02:17 +02:00
|
|
|
using BTCPayServer.HostedServices;
|
2021-10-25 08:18:02 +02:00
|
|
|
using BTCPayServer.Lightning;
|
|
|
|
using BTCPayServer.Models.AppViewModels;
|
|
|
|
using BTCPayServer.Payments;
|
|
|
|
using BTCPayServer.Payments.Lightning;
|
2022-07-18 20:51:53 +02:00
|
|
|
using BTCPayServer.Plugins.PointOfSale.Models;
|
2022-12-04 13:23:59 +01:00
|
|
|
using BTCPayServer.Services;
|
2021-10-25 08:18:02 +02:00
|
|
|
using BTCPayServer.Services.Apps;
|
|
|
|
using BTCPayServer.Services.Invoices;
|
2021-10-29 11:01:16 +02:00
|
|
|
using BTCPayServer.Services.Rates;
|
2021-10-25 08:18:02 +02:00
|
|
|
using BTCPayServer.Services.Stores;
|
|
|
|
using LNURL;
|
2021-10-29 10:27:33 +02:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-10-25 08:18:02 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-12-31 08:59:02 +01:00
|
|
|
using Microsoft.AspNetCore.Routing;
|
2021-10-25 08:18:02 +02:00
|
|
|
using NBitcoin;
|
|
|
|
using NBitcoin.Crypto;
|
|
|
|
using Newtonsoft.Json;
|
2022-11-15 10:40:57 +01:00
|
|
|
using MarkPayoutRequest = BTCPayServer.HostedServices.MarkPayoutRequest;
|
2021-10-25 08:18:02 +02:00
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
{
|
|
|
|
[Route("~/{cryptoCode}/[controller]/")]
|
2022-01-07 04:32:00 +01:00
|
|
|
[Route("~/{cryptoCode}/lnurl/")]
|
|
|
|
public class UILNURLController : Controller
|
2021-10-25 08:18:02 +02:00
|
|
|
{
|
|
|
|
private readonly InvoiceRepository _invoiceRepository;
|
|
|
|
private readonly EventAggregator _eventAggregator;
|
|
|
|
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
|
|
|
|
private readonly LightningLikePaymentHandler _lightningLikePaymentHandler;
|
|
|
|
private readonly StoreRepository _storeRepository;
|
|
|
|
private readonly AppService _appService;
|
2022-04-19 09:58:31 +02:00
|
|
|
|
2022-01-07 04:32:00 +01:00
|
|
|
private readonly UIInvoiceController _invoiceController;
|
2021-10-29 10:27:33 +02:00
|
|
|
private readonly LinkGenerator _linkGenerator;
|
2022-04-19 09:58:31 +02:00
|
|
|
private readonly LightningAddressService _lightningAddressService;
|
2022-06-28 16:02:17 +02:00
|
|
|
private readonly LightningLikePayoutHandler _lightningLikePayoutHandler;
|
|
|
|
private readonly PullPaymentHostedService _pullPaymentHostedService;
|
2022-12-04 13:23:59 +01:00
|
|
|
private readonly BTCPayNetworkJsonSerializerSettings _btcPayNetworkJsonSerializerSettings;
|
2021-10-25 08:18:02 +02:00
|
|
|
|
2022-01-07 04:32:00 +01:00
|
|
|
public UILNURLController(InvoiceRepository invoiceRepository,
|
2021-10-25 08:18:02 +02:00
|
|
|
EventAggregator eventAggregator,
|
|
|
|
BTCPayNetworkProvider btcPayNetworkProvider,
|
|
|
|
LightningLikePaymentHandler lightningLikePaymentHandler,
|
|
|
|
StoreRepository storeRepository,
|
|
|
|
AppService appService,
|
2022-01-07 04:32:00 +01:00
|
|
|
UIInvoiceController invoiceController,
|
2022-04-19 09:58:31 +02:00
|
|
|
LinkGenerator linkGenerator,
|
2022-06-28 16:02:17 +02:00
|
|
|
LightningAddressService lightningAddressService,
|
|
|
|
LightningLikePayoutHandler lightningLikePayoutHandler,
|
2022-12-04 13:23:59 +01:00
|
|
|
PullPaymentHostedService pullPaymentHostedService,
|
|
|
|
BTCPayNetworkJsonSerializerSettings btcPayNetworkJsonSerializerSettings)
|
2021-10-25 08:18:02 +02:00
|
|
|
{
|
|
|
|
_invoiceRepository = invoiceRepository;
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
_btcPayNetworkProvider = btcPayNetworkProvider;
|
|
|
|
_lightningLikePaymentHandler = lightningLikePaymentHandler;
|
|
|
|
_storeRepository = storeRepository;
|
|
|
|
_appService = appService;
|
|
|
|
_invoiceController = invoiceController;
|
2021-10-29 10:27:33 +02:00
|
|
|
_linkGenerator = linkGenerator;
|
2022-04-19 09:58:31 +02:00
|
|
|
_lightningAddressService = lightningAddressService;
|
2022-06-28 16:02:17 +02:00
|
|
|
_lightningLikePayoutHandler = lightningLikePayoutHandler;
|
|
|
|
_pullPaymentHostedService = pullPaymentHostedService;
|
2022-12-04 13:23:59 +01:00
|
|
|
_btcPayNetworkJsonSerializerSettings = btcPayNetworkJsonSerializerSettings;
|
2021-10-25 08:18:02 +02:00
|
|
|
}
|
2021-10-29 10:27:33 +02:00
|
|
|
|
|
|
|
|
2022-06-28 16:02:17 +02:00
|
|
|
[HttpGet("withdraw/pp/{pullPaymentId}")]
|
2022-12-04 13:23:59 +01:00
|
|
|
public async Task<IActionResult> GetLNURLForPullPayment(string cryptoCode, string pullPaymentId, string pr, CancellationToken cancellationToken)
|
2022-06-28 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
var network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode);
|
|
|
|
if (network is null || !network.SupportLightning)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var pmi = new PaymentMethodId(cryptoCode, PaymentTypes.LightningLike);
|
|
|
|
var pp = await _pullPaymentHostedService.GetPullPayment(pullPaymentId, true);
|
|
|
|
if (!pp.IsRunning() || !pp.IsSupported(pmi))
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var blob = pp.GetBlob();
|
|
|
|
if (!blob.Currency.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var progress = _pullPaymentHostedService.CalculatePullPaymentProgress(pp, DateTimeOffset.UtcNow);
|
|
|
|
|
|
|
|
var remaining = progress.Limit - progress.Completed - progress.Awaiting;
|
|
|
|
var request = new LNURLWithdrawRequest()
|
|
|
|
{
|
|
|
|
MaxWithdrawable = LightMoney.FromUnit(remaining, LightMoneyUnit.BTC),
|
|
|
|
K1 = pullPaymentId,
|
|
|
|
BalanceCheck = new Uri(Request.GetCurrentUrl()),
|
|
|
|
CurrentBalance = LightMoney.FromUnit(remaining, LightMoneyUnit.BTC),
|
|
|
|
MinWithdrawable =
|
|
|
|
LightMoney.FromUnit(
|
|
|
|
Math.Min(await _lightningLikePayoutHandler.GetMinimumPayoutAmount(pmi, null), remaining),
|
|
|
|
LightMoneyUnit.BTC),
|
|
|
|
Tag = "withdrawRequest",
|
|
|
|
Callback = new Uri(Request.GetCurrentUrl()),
|
|
|
|
};
|
|
|
|
if (pr is null)
|
|
|
|
{
|
|
|
|
return Ok(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BOLT11PaymentRequest.TryParse(pr, out var result, network.NBitcoinNetwork) || result is null)
|
|
|
|
{
|
|
|
|
return BadRequest(new LNUrlStatusResponse {Status = "ERROR", Reason = "Pr was not a valid BOLT11"});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.MinimumAmount < request.MinWithdrawable || result.MinimumAmount > request.MaxWithdrawable)
|
|
|
|
return BadRequest(new LNUrlStatusResponse {Status = "ERROR", Reason = "Pr was not within bounds"});
|
|
|
|
var store = await _storeRepository.FindStore(pp.StoreId);
|
|
|
|
var pm = store!.GetSupportedPaymentMethods(_btcPayNetworkProvider)
|
|
|
|
.OfType<LightningSupportedPaymentMethod>()
|
|
|
|
.FirstOrDefault(method => method.PaymentId == pmi);
|
|
|
|
if (pm is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var claimResponse = await _pullPaymentHostedService.Claim(new ClaimRequest()
|
|
|
|
{
|
|
|
|
Destination = new BoltInvoiceClaimDestination(pr, result),
|
|
|
|
PaymentMethodId = pmi,
|
|
|
|
PullPaymentId = pullPaymentId,
|
|
|
|
StoreId = pp.StoreId,
|
|
|
|
Value = result.MinimumAmount.ToDecimal(LightMoneyUnit.BTC)
|
|
|
|
});
|
|
|
|
|
|
|
|
if (claimResponse.Result != ClaimRequest.ClaimResult.Ok)
|
|
|
|
return BadRequest(new LNUrlStatusResponse {Status = "ERROR", Reason = "Pr could not be paid"});
|
|
|
|
switch (claimResponse.PayoutData.State)
|
|
|
|
{
|
|
|
|
case PayoutState.AwaitingPayment:
|
|
|
|
{
|
|
|
|
var client =
|
|
|
|
_lightningLikePaymentHandler.CreateLightningClient(pm, network);
|
2022-12-04 13:23:59 +01:00
|
|
|
var payResult = await UILightningLikePayoutController.TrypayBolt(client,
|
|
|
|
claimResponse.PayoutData.GetBlob(_btcPayNetworkJsonSerializerSettings),
|
|
|
|
claimResponse.PayoutData, result, pmi, cancellationToken);
|
|
|
|
|
2022-06-28 16:02:17 +02:00
|
|
|
switch (payResult.Result)
|
|
|
|
{
|
|
|
|
case PayResult.Ok:
|
2022-12-04 13:23:59 +01:00
|
|
|
case PayResult.Unknown:
|
2022-11-15 10:40:57 +01:00
|
|
|
await _pullPaymentHostedService.MarkPaid(new MarkPayoutRequest()
|
2022-06-28 16:02:17 +02:00
|
|
|
{
|
2022-12-04 13:23:59 +01:00
|
|
|
PayoutId = claimResponse.PayoutData.Id,
|
|
|
|
State = claimResponse.PayoutData.State,
|
|
|
|
Proof = claimResponse.PayoutData.GetProofBlobJson()
|
2022-06-28 16:02:17 +02:00
|
|
|
});
|
|
|
|
|
2022-12-04 13:23:59 +01:00
|
|
|
return Ok(new LNUrlStatusResponse
|
|
|
|
{
|
|
|
|
Status = "OK",
|
|
|
|
Reason = payResult.Message
|
|
|
|
});
|
|
|
|
case PayResult.CouldNotFindRoute:
|
|
|
|
case PayResult.Error:
|
2022-06-28 16:02:17 +02:00
|
|
|
default:
|
|
|
|
await _pullPaymentHostedService.Cancel(
|
|
|
|
new PullPaymentHostedService.CancelRequest(new string[]
|
|
|
|
{
|
|
|
|
claimResponse.PayoutData.Id
|
2022-11-15 10:40:57 +01:00
|
|
|
}, null));
|
2022-06-28 16:02:17 +02:00
|
|
|
|
|
|
|
return Ok(new LNUrlStatusResponse
|
|
|
|
{
|
|
|
|
Status = "ERROR",
|
2022-12-04 13:23:59 +01:00
|
|
|
Reason = payResult.Message
|
2022-06-28 16:02:17 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case PayoutState.AwaitingApproval:
|
|
|
|
return Ok(new LNUrlStatusResponse
|
|
|
|
{
|
|
|
|
Status = "OK",
|
|
|
|
Reason =
|
|
|
|
"The payment request has been recorded, but still needs to be approved before execution."
|
|
|
|
});
|
|
|
|
case PayoutState.InProgress:
|
|
|
|
case PayoutState.Completed:
|
|
|
|
return Ok(new LNUrlStatusResponse {Status = "OK"});
|
|
|
|
case PayoutState.Cancelled:
|
|
|
|
return BadRequest(new LNUrlStatusResponse {Status = "ERROR", Reason = "Pr could not be paid"});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(request);
|
|
|
|
}
|
2021-10-29 10:27:33 +02:00
|
|
|
[HttpGet("pay/app/{appId}/{itemCode}")]
|
|
|
|
public async Task<IActionResult> GetLNURLForApp(string cryptoCode, string appId, string itemCode = null)
|
|
|
|
{
|
|
|
|
var network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode);
|
|
|
|
if (network is null || !network.SupportLightning)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var app = await _appService.GetApp(appId, null, true);
|
|
|
|
if (app is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var store = app.StoreData;
|
|
|
|
if (store is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
2022-04-19 09:58:31 +02:00
|
|
|
|
2021-10-29 10:27:33 +02:00
|
|
|
if (string.IsNullOrEmpty(itemCode))
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var pmi = new PaymentMethodId(cryptoCode, PaymentTypes.LNURLPay);
|
|
|
|
var lnpmi = new PaymentMethodId(cryptoCode, PaymentTypes.LightningLike);
|
|
|
|
var methods = store.GetSupportedPaymentMethods(_btcPayNetworkProvider);
|
|
|
|
var lnUrlMethod =
|
|
|
|
methods.FirstOrDefault(method => method.PaymentId == pmi) as LNURLPaySupportedPaymentMethod;
|
|
|
|
var lnMethod = methods.FirstOrDefault(method => method.PaymentId == lnpmi);
|
|
|
|
if (lnUrlMethod is null || lnMethod is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
ViewPointOfSaleViewModel.Item[] items = null;
|
2021-10-29 10:27:33 +02:00
|
|
|
string currencyCode = null;
|
|
|
|
switch (app.AppType)
|
|
|
|
{
|
|
|
|
case nameof(AppType.Crowdfund):
|
|
|
|
var cfS = app.GetSettings<CrowdfundSettings>();
|
|
|
|
currencyCode = cfS.TargetCurrency;
|
|
|
|
items = _appService.Parse(cfS.PerksTemplate, cfS.TargetCurrency);
|
|
|
|
break;
|
|
|
|
case nameof(AppType.PointOfSale):
|
2022-02-27 06:19:02 +01:00
|
|
|
var posS = app.GetSettings<PointOfSaleSettings>();
|
2021-10-29 10:27:33 +02:00
|
|
|
currencyCode = posS.Currency;
|
|
|
|
items = _appService.Parse(posS.Template, posS.Currency);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var item = items.FirstOrDefault(item1 =>
|
|
|
|
item1.Id.Equals(itemCode, StringComparison.InvariantCultureIgnoreCase));
|
|
|
|
if (item is null ||
|
|
|
|
item.Inventory <= 0 ||
|
|
|
|
(item.PaymentMethods?.Any() is true &&
|
|
|
|
item.PaymentMethods?.Any(s => PaymentMethodId.Parse(s) == pmi) is false))
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
return await GetLNURL(cryptoCode, app.StoreDataId, currencyCode, null, null,
|
2022-04-24 13:36:10 +02:00
|
|
|
() => (null, app, item, new List<string> {AppService.GetAppInternalTag(appId)}, item.Price.Value, true));
|
2021-10-29 10:27:33 +02:00
|
|
|
}
|
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
public class EditLightningAddressVM
|
|
|
|
{
|
|
|
|
public class EditLightningAddressItem : LightningAddressSettings.LightningAddressItem
|
|
|
|
{
|
|
|
|
[Required]
|
|
|
|
[RegularExpression("[a-zA-Z0-9-_]+")]
|
|
|
|
public string Username { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public EditLightningAddressItem Add { get; set; }
|
2022-04-19 09:58:31 +02:00
|
|
|
public List<EditLightningAddressItem> Items { get; set; } = new();
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public class LightningAddressSettings
|
|
|
|
{
|
|
|
|
public class LightningAddressItem
|
|
|
|
{
|
|
|
|
public string StoreId { get; set; }
|
2022-04-19 09:58:31 +02:00
|
|
|
[Display(Name = "Invoice currency")] public string CurrencyCode { get; set; }
|
2021-12-31 08:59:02 +01:00
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
[Display(Name = "Min sats")]
|
|
|
|
[Range(1, double.PositiveInfinity)]
|
|
|
|
public decimal? Min { get; set; }
|
2021-12-31 08:59:02 +01:00
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
[Display(Name = "Max sats")]
|
|
|
|
[Range(1, double.PositiveInfinity)]
|
|
|
|
public decimal? Max { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConcurrentDictionary<string, LightningAddressItem> Items { get; set; } =
|
|
|
|
new ConcurrentDictionary<string, LightningAddressItem>();
|
|
|
|
|
|
|
|
public ConcurrentDictionary<string, string[]> StoreToItemMap { get; set; } =
|
|
|
|
new ConcurrentDictionary<string, string[]>();
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("~/.well-known/lnurlp/{username}")]
|
|
|
|
public async Task<IActionResult> ResolveLightningAddress(string username)
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
var lightningAddressSettings = await _lightningAddressService.ResolveByAddress(username);
|
|
|
|
if (lightningAddressSettings is null)
|
2021-10-29 11:01:16 +02:00
|
|
|
{
|
2021-11-05 04:16:54 +01:00
|
|
|
return NotFound("Unknown username");
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 09:58:31 +02:00
|
|
|
var blob = lightningAddressSettings.Blob.GetBlob<LightningAddressDataBlob>();
|
|
|
|
return await GetLNURL("BTC", lightningAddressSettings.StoreDataId, blob.CurrencyCode, blob.Min, blob.Max,
|
2022-04-24 13:36:10 +02:00
|
|
|
() => (username, null, null, null, null, true));
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
2021-10-29 10:27:33 +02:00
|
|
|
|
|
|
|
[HttpGet("pay")]
|
|
|
|
public async Task<IActionResult> GetLNURL(string cryptoCode, string storeId, string currencyCode = null,
|
|
|
|
decimal? min = null, decimal? max = null,
|
2022-04-24 13:36:10 +02:00
|
|
|
Func<(string username, AppData app, ViewPointOfSaleViewModel.Item item, List<string> additionalTags, decimal? invoiceAmount, bool? anyoneCanInvoice)>
|
2021-10-29 10:27:33 +02:00
|
|
|
internalDetails = null)
|
|
|
|
{
|
|
|
|
var network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode);
|
|
|
|
if (network is null || !network.SupportLightning)
|
|
|
|
{
|
2021-11-05 04:16:54 +01:00
|
|
|
return NotFound("This network does not support Lightning");
|
2021-10-29 10:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var store = await _storeRepository.FindStore(storeId);
|
|
|
|
if (store is null)
|
|
|
|
{
|
2021-11-05 04:16:54 +01:00
|
|
|
return NotFound("Store not found");
|
2021-10-29 10:27:33 +02:00
|
|
|
}
|
|
|
|
|
2022-07-06 14:14:55 +02:00
|
|
|
var storeBlob = store.GetStoreBlob();
|
|
|
|
currencyCode ??= storeBlob.DefaultCurrency ?? cryptoCode;
|
2021-10-29 10:27:33 +02:00
|
|
|
var pmi = new PaymentMethodId(cryptoCode, PaymentTypes.LNURLPay);
|
|
|
|
var lnpmi = new PaymentMethodId(cryptoCode, PaymentTypes.LightningLike);
|
|
|
|
var methods = store.GetSupportedPaymentMethods(_btcPayNetworkProvider);
|
|
|
|
var lnUrlMethod =
|
|
|
|
methods.FirstOrDefault(method => method.PaymentId == pmi) as LNURLPaySupportedPaymentMethod;
|
|
|
|
var lnMethod = methods.FirstOrDefault(method => method.PaymentId == lnpmi);
|
|
|
|
if (lnUrlMethod is null || lnMethod is null)
|
|
|
|
{
|
2021-11-05 04:16:54 +01:00
|
|
|
return NotFound("LNURL or Lightning payment method not found");
|
2021-10-29 10:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var blob = store.GetStoreBlob();
|
|
|
|
if (blob.GetExcludedPaymentMethods().Match(pmi) || blob.GetExcludedPaymentMethods().Match(lnpmi))
|
|
|
|
{
|
2021-11-05 04:16:54 +01:00
|
|
|
return NotFound("LNURL or Lightning payment method disabled");
|
2021-10-29 10:27:33 +02:00
|
|
|
}
|
|
|
|
|
2022-04-24 13:36:10 +02:00
|
|
|
(string username, AppData app, ViewPointOfSaleViewModel.Item item, List<string> additionalTags, decimal? invoiceAmount, bool? anyoneCanInvoice) =
|
|
|
|
(internalDetails ?? (() => (null, null, null, null, null, null)))();
|
2021-10-29 10:27:33 +02:00
|
|
|
|
|
|
|
if ((anyoneCanInvoice ?? blob.AnyoneCanInvoice) is false)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2022-02-21 05:21:33 +01:00
|
|
|
var lnAddress = username is null ? null : $"{username}@{Request.Host}";
|
2022-04-24 13:36:10 +02:00
|
|
|
List<string[]> lnurlMetadata = new();
|
2021-10-29 10:27:33 +02:00
|
|
|
|
2022-06-28 07:05:02 +02:00
|
|
|
var redirectUrl = app?.AppType switch
|
|
|
|
{
|
|
|
|
nameof(AppType.PointOfSale) => app.GetSettings<PointOfSaleSettings>().RedirectUrl ??
|
|
|
|
HttpContext.Request.GetAbsoluteUri($"/apps/{app.Id}/pos"),
|
|
|
|
_ => null
|
|
|
|
};
|
2022-04-24 13:36:10 +02:00
|
|
|
var invoiceRequest = new CreateInvoiceRequest
|
|
|
|
{
|
|
|
|
Amount = invoiceAmount,
|
|
|
|
Checkout = new InvoiceDataBase.CheckoutOptions
|
2021-10-29 10:27:33 +02:00
|
|
|
{
|
2022-04-24 13:36:10 +02:00
|
|
|
PaymentMethods = new[] { pmi.ToStringNormalized() },
|
|
|
|
Expiration = blob.InvoiceExpiration < TimeSpan.FromMinutes(2)
|
|
|
|
? blob.InvoiceExpiration
|
2022-06-28 07:05:02 +02:00
|
|
|
: TimeSpan.FromMinutes(2),
|
|
|
|
RedirectURL = redirectUrl
|
2022-04-24 13:36:10 +02:00
|
|
|
},
|
|
|
|
Currency = currencyCode,
|
|
|
|
Type = invoiceAmount is null ? InvoiceType.TopUp : InvoiceType.Standard,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
{
|
|
|
|
invoiceRequest.Metadata =
|
|
|
|
new InvoiceMetadata
|
2021-10-29 10:27:33 +02:00
|
|
|
{
|
2022-04-24 13:36:10 +02:00
|
|
|
ItemCode = item.Id,
|
|
|
|
ItemDesc = item.Description,
|
2022-06-28 07:05:02 +02:00
|
|
|
OrderId = AppService.GetAppOrderId(app)
|
2022-04-24 13:36:10 +02:00
|
|
|
}.ToJObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
var i = await _invoiceController.CreateInvoiceCoreRaw(invoiceRequest, store, Request.GetAbsoluteRoot(), additionalTags);
|
2021-10-29 10:27:33 +02:00
|
|
|
if (i.Type != InvoiceType.TopUp)
|
|
|
|
{
|
|
|
|
min = i.GetPaymentMethod(pmi).Calculate().Due.ToDecimal(MoneyUnit.Satoshi);
|
2022-09-12 19:05:37 +02:00
|
|
|
max = item?.Price?.Type == ViewPointOfSaleViewModel.Item.ItemPrice.ItemPriceType.Minimum ? null : min;
|
2021-10-29 10:27:33 +02:00
|
|
|
}
|
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
if (!string.IsNullOrEmpty(username))
|
|
|
|
{
|
|
|
|
var pm = i.GetPaymentMethod(pmi);
|
|
|
|
var paymentMethodDetails = (LNURLPayPaymentMethodDetails)pm.GetPaymentMethodDetails();
|
|
|
|
paymentMethodDetails.ConsumedLightningAddress = lnAddress;
|
|
|
|
pm.SetPaymentMethodDetails(paymentMethodDetails);
|
|
|
|
await _invoiceRepository.UpdateInvoicePaymentMethod(i.Id, pm);
|
|
|
|
}
|
2022-04-24 13:36:10 +02:00
|
|
|
|
|
|
|
var description = blob.LightningDescriptionTemplate
|
|
|
|
.Replace("{StoreName}", store.StoreName ?? "", StringComparison.OrdinalIgnoreCase)
|
|
|
|
.Replace("{ItemDescription}", i.Metadata.ItemDesc ?? "", StringComparison.OrdinalIgnoreCase)
|
|
|
|
.Replace("{OrderId}", i.Metadata.OrderId ?? "", StringComparison.OrdinalIgnoreCase);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2022-04-24 13:36:10 +02:00
|
|
|
lnurlMetadata.Add(new[] {"text/plain", description});
|
2021-10-29 11:01:16 +02:00
|
|
|
if (!string.IsNullOrEmpty(username))
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
lnurlMetadata.Add(new[] {"text/identifier", lnAddress});
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
2021-10-29 10:27:33 +02:00
|
|
|
return Ok(new LNURLPayRequest
|
|
|
|
{
|
|
|
|
Tag = "payRequest",
|
|
|
|
MinSendable = new LightMoney(min ?? 1m, LightMoneyUnit.Satoshi),
|
|
|
|
MaxSendable =
|
|
|
|
max is null
|
|
|
|
? LightMoney.FromUnit(6.12m, LightMoneyUnit.BTC)
|
|
|
|
: new LightMoney(max.Value, LightMoneyUnit.Satoshi),
|
|
|
|
CommentAllowed = lnUrlMethod.LUD12Enabled ? 2000 : 0,
|
|
|
|
Metadata = JsonConvert.SerializeObject(lnurlMetadata),
|
|
|
|
Callback = new Uri(_linkGenerator.GetUriByAction(
|
|
|
|
action: nameof(GetLNURLForInvoice),
|
2022-01-07 04:32:00 +01:00
|
|
|
controller: "UILNURL",
|
2022-04-19 09:58:31 +02:00
|
|
|
values: new {cryptoCode, invoiceId = i.Id}, Request.Scheme, Request.Host, Request.PathBase))
|
2021-10-29 10:27:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-25 08:18:02 +02:00
|
|
|
[HttpGet("pay/i/{invoiceId}")]
|
|
|
|
public async Task<IActionResult> GetLNURLForInvoice(string invoiceId, string cryptoCode,
|
|
|
|
[FromQuery] long? amount = null, string comment = null)
|
|
|
|
{
|
|
|
|
var network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode);
|
|
|
|
if (network is null || !network.SupportLightning)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
2022-04-19 09:58:31 +02:00
|
|
|
|
2022-02-21 05:27:02 +01:00
|
|
|
if (comment is not null)
|
2022-02-21 05:47:00 +01:00
|
|
|
comment = comment.Truncate(2000);
|
2021-10-25 08:18:02 +02:00
|
|
|
|
|
|
|
var pmi = new PaymentMethodId(cryptoCode, PaymentTypes.LNURLPay);
|
|
|
|
var i = await _invoiceRepository.GetInvoice(invoiceId, true);
|
2022-04-24 13:36:10 +02:00
|
|
|
|
|
|
|
var store = await _storeRepository.FindStore(i.StoreId);
|
|
|
|
if (store is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2021-10-25 08:18:02 +02:00
|
|
|
if (i.Status == InvoiceStatusLegacy.New)
|
|
|
|
{
|
|
|
|
var isTopup = i.IsUnsetTopUp();
|
|
|
|
var lnurlSupportedPaymentMethod =
|
|
|
|
i.GetSupportedPaymentMethod<LNURLPaySupportedPaymentMethod>(pmi).FirstOrDefault();
|
2022-07-06 15:09:05 +02:00
|
|
|
if (lnurlSupportedPaymentMethod is null)
|
2021-10-25 08:18:02 +02:00
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var lightningPaymentMethod = i.GetPaymentMethod(pmi);
|
|
|
|
var accounting = lightningPaymentMethod.Calculate();
|
|
|
|
var paymentMethodDetails =
|
|
|
|
lightningPaymentMethod.GetPaymentMethodDetails() as LNURLPayPaymentMethodDetails;
|
|
|
|
if (paymentMethodDetails.LightningSupportedPaymentMethod is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var min = new LightMoney(isTopup ? 1m : accounting.Due.ToUnit(MoneyUnit.Satoshi),
|
|
|
|
LightMoneyUnit.Satoshi);
|
|
|
|
var max = isTopup ? LightMoney.FromUnit(6.12m, LightMoneyUnit.BTC) : min;
|
|
|
|
|
2022-04-24 13:36:10 +02:00
|
|
|
List<string[]> lnurlMetadata = new();
|
|
|
|
|
|
|
|
var blob = store.GetStoreBlob();
|
|
|
|
var description = blob.LightningDescriptionTemplate
|
|
|
|
.Replace("{StoreName}", store.StoreName ?? "", StringComparison.OrdinalIgnoreCase)
|
|
|
|
.Replace("{ItemDescription}", i.Metadata.ItemDesc ?? "", StringComparison.OrdinalIgnoreCase)
|
|
|
|
.Replace("{OrderId}", i.Metadata.OrderId ?? "", StringComparison.OrdinalIgnoreCase);
|
2021-10-25 08:18:02 +02:00
|
|
|
|
2022-04-24 13:36:10 +02:00
|
|
|
lnurlMetadata.Add(new[] {"text/plain", description});
|
2021-10-29 11:01:16 +02:00
|
|
|
if (!string.IsNullOrEmpty(paymentMethodDetails.ConsumedLightningAddress))
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
lnurlMetadata.Add(new[] {"text/identifier", paymentMethodDetails.ConsumedLightningAddress});
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
2021-10-25 08:18:02 +02:00
|
|
|
|
|
|
|
var metadata = JsonConvert.SerializeObject(lnurlMetadata);
|
|
|
|
if (amount.HasValue && (amount < min || amount > max))
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
return BadRequest(new LNUrlStatusResponse {Status = "ERROR", Reason = "Amount is out of bounds."});
|
2021-10-25 08:18:02 +02:00
|
|
|
}
|
|
|
|
|
2022-07-06 14:14:55 +02:00
|
|
|
LNURLPayRequest.LNURLPayRequestCallbackResponse.ILNURLPayRequestSuccessAction successAction = null;
|
|
|
|
|
|
|
|
if ((i.ReceiptOptions?.Enabled ??blob.ReceiptOptions.Enabled ) is true)
|
|
|
|
{
|
|
|
|
successAction =
|
|
|
|
new LNURLPayRequest.LNURLPayRequestCallbackResponse.LNURLPayRequestSuccessActionUrl()
|
|
|
|
{
|
|
|
|
Tag = "url",
|
|
|
|
Description = "Thank you for your purchase. Here is your receipt",
|
|
|
|
Url = _linkGenerator.GetUriByAction(HttpContext, "InvoiceReceipt", "UIInvoice", new { invoiceId})
|
|
|
|
};
|
|
|
|
}
|
2022-08-12 20:10:44 +02:00
|
|
|
|
|
|
|
if (amount is null)
|
|
|
|
{
|
|
|
|
return Ok(new LNURLPayRequest
|
|
|
|
{
|
|
|
|
Tag = "payRequest",
|
|
|
|
MinSendable = min,
|
|
|
|
MaxSendable = max,
|
|
|
|
CommentAllowed = lnurlSupportedPaymentMethod.LUD12Enabled ? 2000 : 0,
|
|
|
|
Metadata = metadata,
|
|
|
|
Callback = new Uri(Request.GetCurrentUrl())
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(paymentMethodDetails.BOLT11) || paymentMethodDetails.GeneratedBoltAmount != amount)
|
2021-10-25 08:18:02 +02:00
|
|
|
{
|
|
|
|
var client =
|
|
|
|
_lightningLikePaymentHandler.CreateLightningClient(
|
|
|
|
paymentMethodDetails.LightningSupportedPaymentMethod, network);
|
|
|
|
if (!string.IsNullOrEmpty(paymentMethodDetails.BOLT11))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
await client.CancelInvoice(paymentMethodDetails.InvoiceId);
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
//not a fully supported option
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LightningInvoice invoice;
|
|
|
|
try
|
|
|
|
{
|
2022-08-25 10:40:06 +02:00
|
|
|
var expiry = i.ExpirationTime.ToUniversalTime() - DateTimeOffset.UtcNow;
|
2022-12-13 10:56:33 +01:00
|
|
|
var param = new CreateInvoiceParams(amount.Value, metadata, expiry)
|
2022-08-25 10:40:06 +02:00
|
|
|
{
|
2022-12-13 10:56:33 +01:00
|
|
|
PrivateRouteHints = blob.LightningPrivateRouteHints,
|
|
|
|
DescriptionHashOnly = true
|
2022-08-25 10:40:06 +02:00
|
|
|
};
|
|
|
|
invoice = await client.CreateInvoice(param);
|
2021-10-25 08:18:02 +02:00
|
|
|
if (!BOLT11PaymentRequest.Parse(invoice.BOLT11, network.NBitcoinNetwork)
|
2022-04-19 09:58:31 +02:00
|
|
|
.VerifyDescriptionHash(metadata))
|
2021-10-25 08:18:02 +02:00
|
|
|
{
|
|
|
|
return BadRequest(new LNUrlStatusResponse
|
|
|
|
{
|
|
|
|
Status = "ERROR",
|
|
|
|
Reason = "Lightning node could not generate invoice with a VALID description hash"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
catch (Exception)
|
2021-10-25 08:18:02 +02:00
|
|
|
{
|
|
|
|
return BadRequest(new LNUrlStatusResponse
|
|
|
|
{
|
|
|
|
Status = "ERROR",
|
|
|
|
Reason = "Lightning node could not generate invoice with description hash"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
paymentMethodDetails.BOLT11 = invoice.BOLT11;
|
|
|
|
paymentMethodDetails.InvoiceId = invoice.Id;
|
|
|
|
paymentMethodDetails.GeneratedBoltAmount = new LightMoney(amount.Value);
|
|
|
|
if (lnurlSupportedPaymentMethod.LUD12Enabled)
|
|
|
|
{
|
|
|
|
paymentMethodDetails.ProvidedComment = comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
lightningPaymentMethod.SetPaymentMethodDetails(paymentMethodDetails);
|
|
|
|
await _invoiceRepository.UpdateInvoicePaymentMethod(invoiceId, lightningPaymentMethod);
|
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-25 08:18:02 +02:00
|
|
|
_eventAggregator.Publish(new InvoiceNewPaymentDetailsEvent(invoiceId,
|
|
|
|
paymentMethodDetails, pmi));
|
|
|
|
return Ok(new LNURLPayRequest.LNURLPayRequestCallbackResponse
|
|
|
|
{
|
2022-07-06 14:14:55 +02:00
|
|
|
Disposable = true, Routes = Array.Empty<string>(), Pr = paymentMethodDetails.BOLT11,
|
|
|
|
SuccessAction = successAction
|
2021-10-25 08:18:02 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-12 20:10:44 +02:00
|
|
|
if (paymentMethodDetails.GeneratedBoltAmount == amount)
|
2021-10-25 08:18:02 +02:00
|
|
|
{
|
|
|
|
if (lnurlSupportedPaymentMethod.LUD12Enabled && paymentMethodDetails.ProvidedComment != comment)
|
|
|
|
{
|
|
|
|
paymentMethodDetails.ProvidedComment = comment;
|
|
|
|
lightningPaymentMethod.SetPaymentMethodDetails(paymentMethodDetails);
|
|
|
|
await _invoiceRepository.UpdateInvoicePaymentMethod(invoiceId, lightningPaymentMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(new LNURLPayRequest.LNURLPayRequestCallbackResponse
|
|
|
|
{
|
2022-07-06 14:14:55 +02:00
|
|
|
Disposable = true, Routes = Array.Empty<string>(), Pr = paymentMethodDetails.BOLT11,
|
|
|
|
SuccessAction = successAction
|
2021-10-25 08:18:02 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BadRequest(new LNUrlStatusResponse
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
Status = "ERROR", Reason = "Invoice not in a valid payable state"
|
2021-10-25 08:18:02 +02:00
|
|
|
});
|
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
|
|
|
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
2022-05-04 19:40:23 +02:00
|
|
|
[HttpGet("~/stores/{storeId}/plugins/lightning-address")]
|
2021-10-29 11:01:16 +02:00
|
|
|
public async Task<IActionResult> EditLightningAddress(string storeId)
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
if (ControllerContext.HttpContext.GetStoreData().GetEnabledPaymentIds(_btcPayNetworkProvider)
|
|
|
|
.All(id => id.PaymentType != LNURLPayPaymentType.Instance))
|
2021-10-29 11:01:16 +02:00
|
|
|
{
|
|
|
|
TempData.SetStatusMessageModel(new StatusMessageModel
|
|
|
|
{
|
|
|
|
Message = "LNURL is required for lightning addresses but has not yet been enabled.",
|
|
|
|
Severity = StatusMessageModel.StatusSeverity.Error
|
|
|
|
});
|
2022-04-19 09:58:31 +02:00
|
|
|
return RedirectToAction(nameof(UIStoresController.GeneralSettings), "UIStores", new {storeId});
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 09:58:31 +02:00
|
|
|
var addresses =
|
|
|
|
await _lightningAddressService.Get(new LightningAddressQuery() {StoreIds = new[] {storeId}});
|
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
return View(new EditLightningAddressVM
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
Items = addresses.Select(s =>
|
|
|
|
{
|
|
|
|
var blob = s.Blob.GetBlob<LightningAddressDataBlob>();
|
|
|
|
return new EditLightningAddressVM.EditLightningAddressItem
|
|
|
|
{
|
|
|
|
Max = blob.Max,
|
|
|
|
Min = blob.Min,
|
|
|
|
CurrencyCode = blob.CurrencyCode,
|
|
|
|
StoreId = storeId,
|
|
|
|
Username = s.Username,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
).ToList()
|
2021-10-29 11:01:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-19 09:58:31 +02:00
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
|
|
|
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
2022-05-04 19:40:23 +02:00
|
|
|
[HttpPost("~/stores/{storeId}/plugins/lightning-address")]
|
2021-10-29 11:01:16 +02:00
|
|
|
public async Task<IActionResult> EditLightningAddress(string storeId, [FromForm] EditLightningAddressVM vm,
|
|
|
|
string command, [FromServices] CurrencyNameTable currencyNameTable)
|
|
|
|
{
|
|
|
|
if (command == "add")
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
if (!string.IsNullOrEmpty(vm.Add.CurrencyCode) &&
|
|
|
|
currencyNameTable.GetCurrencyData(vm.Add.CurrencyCode, false) is null)
|
2021-10-29 11:01:16 +02:00
|
|
|
{
|
|
|
|
vm.AddModelError(addressVm => addressVm.Add.CurrencyCode, "Currency is invalid", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
{
|
|
|
|
return View(vm);
|
|
|
|
}
|
2022-04-19 09:58:31 +02:00
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2022-04-19 09:58:31 +02:00
|
|
|
if (await _lightningAddressService.Set(new LightningAddressData()
|
|
|
|
{
|
|
|
|
StoreDataId = storeId,
|
|
|
|
Username = vm.Add.Username,
|
|
|
|
Blob = new LightningAddressDataBlob()
|
|
|
|
{
|
|
|
|
Max = vm.Add.Max, Min = vm.Add.Min, CurrencyCode = vm.Add.CurrencyCode
|
|
|
|
}.SerializeBlob()
|
|
|
|
}))
|
2021-10-29 11:01:16 +02:00
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
TempData.SetStatusMessageModel(new StatusMessageModel
|
|
|
|
{
|
|
|
|
Severity = StatusMessageModel.StatusSeverity.Success,
|
|
|
|
Message = "Lightning address added successfully."
|
|
|
|
});
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
vm.AddModelError(addressVm => addressVm.Add.Username, "Username is already taken", this);
|
|
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
{
|
|
|
|
return View(vm);
|
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
return RedirectToAction("EditLightningAddress");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command.StartsWith("remove", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
2022-04-19 09:58:31 +02:00
|
|
|
var index = command.Substring(command.IndexOf(":", StringComparison.InvariantCultureIgnoreCase) + 1);
|
|
|
|
if (await _lightningAddressService.Remove(index, storeId))
|
2021-10-29 11:01:16 +02:00
|
|
|
{
|
|
|
|
TempData.SetStatusMessageModel(new StatusMessageModel
|
|
|
|
{
|
|
|
|
Severity = StatusMessageModel.StatusSeverity.Success,
|
2022-04-19 09:58:31 +02:00
|
|
|
Message = $"Lightning address {index} removed successfully."
|
2021-10-29 11:01:16 +02:00
|
|
|
});
|
2022-04-19 09:58:31 +02:00
|
|
|
return RedirectToAction("EditLightningAddress");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vm.AddModelError(addressVm => addressVm.Add.Username, "Username could not be removed", this);
|
|
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
{
|
|
|
|
return View(vm);
|
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-19 09:58:31 +02:00
|
|
|
|
|
|
|
return View(vm);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
|
|
|
}
|
2021-10-25 08:18:02 +02:00
|
|
|
}
|
|
|
|
}
|