Test LNUrl Pay payment method information, add doc

This commit is contained in:
nicolas.dorier
2022-02-21 13:21:33 +09:00
parent 48393c3765
commit 557594e34d
9 changed files with 51 additions and 20 deletions

View File

@@ -35,7 +35,7 @@ namespace BTCPayServer.Client.Models
public string PaymentMethod { get; set; } public string PaymentMethod { get; set; }
public string CryptoCode { get; set; } public string CryptoCode { get; set; }
public Dictionary<string, JObject> AdditionalData { get; set; } public JObject AdditionalData { get; set; }
public class Payment public class Payment
{ {

View File

@@ -145,8 +145,15 @@ namespace BTCPayServer.Tests
Driver.FindElement(By.Id("IsAdmin")).Click(); Driver.FindElement(By.Id("IsAdmin")).Click();
Driver.FindElement(By.Id("RegisterButton")).Click(); Driver.FindElement(By.Id("RegisterButton")).Click();
Driver.AssertNoError(); Driver.AssertNoError();
CreatedUser = usr;
return usr; return usr;
} }
string CreatedUser;
public TestAccount AsTestAccount()
{
return new TestAccount(Server) { RegisterDetails = new Models.AccountViewModels.RegisterViewModel() { Password = "123456", Email = CreatedUser } };
}
public (string storeName, string storeId) CreateNewStore(bool keepId = true) public (string storeName, string storeId) CreateNewStore(bool keepId = true)
{ {

View File

@@ -1467,6 +1467,8 @@ namespace BTCPayServer.Tests
s.GoToLightningSettings(); s.GoToLightningSettings();
// LNURL is true by default // LNURL is true by default
Assert.True(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected); Assert.True(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected);
s.Driver.SetCheckbox(By.Name("LUD12Enabled"), true);
s.Driver.FindElement(By.Id("save")).Click();
// Topup Invoice test // Topup Invoice test
var i = s.CreateInvoice(storeId, null, cryptoCode); var i = s.CreateInvoice(storeId, null, cryptoCode);
@@ -1479,13 +1481,13 @@ namespace BTCPayServer.Tests
Assert.Equal(1m, fetchedReuqest.MinSendable.ToDecimal(LightMoneyUnit.Satoshi)); Assert.Equal(1m, fetchedReuqest.MinSendable.ToDecimal(LightMoneyUnit.Satoshi));
Assert.NotEqual(1m, fetchedReuqest.MaxSendable.ToDecimal(LightMoneyUnit.Satoshi)); Assert.NotEqual(1m, fetchedReuqest.MaxSendable.ToDecimal(LightMoneyUnit.Satoshi));
var lnurlResponse = await fetchedReuqest.SendRequest(new LightMoney(0.000001m, LightMoneyUnit.BTC), var lnurlResponse = await fetchedReuqest.SendRequest(new LightMoney(0.000001m, LightMoneyUnit.BTC),
network, new HttpClient()); network, new HttpClient(), comment: "lol");
Assert.Equal(new LightMoney(0.000001m, LightMoneyUnit.BTC), Assert.Equal(new LightMoney(0.000001m, LightMoneyUnit.BTC),
lnurlResponse.GetPaymentRequest(network).MinimumAmount); lnurlResponse.GetPaymentRequest(network).MinimumAmount);
var lnurlResponse2 = await fetchedReuqest.SendRequest(new LightMoney(0.000002m, LightMoneyUnit.BTC), var lnurlResponse2 = await fetchedReuqest.SendRequest(new LightMoney(0.000002m, LightMoneyUnit.BTC),
network, new HttpClient()); network, new HttpClient(), comment: "lol2");
Assert.Equal(new LightMoney(0.000002m, LightMoneyUnit.BTC), lnurlResponse2.GetPaymentRequest(network).MinimumAmount); Assert.Equal(new LightMoney(0.000002m, LightMoneyUnit.BTC), lnurlResponse2.GetPaymentRequest(network).MinimumAmount);
await Assert.ThrowsAnyAsync<LightningRPCException>(async () => await Assert.ThrowsAnyAsync<LightningRPCException>(async () =>
{ {
@@ -1499,7 +1501,11 @@ namespace BTCPayServer.Tests
var inv = await s.Server.PayTester.InvoiceRepository.GetInvoice(i); var inv = await s.Server.PayTester.InvoiceRepository.GetInvoice(i);
Assert.Equal(InvoiceStatusLegacy.Complete, inv.Status); Assert.Equal(InvoiceStatusLegacy.Complete, inv.Status);
}); });
var greenfield = await s.AsTestAccount().CreateClient();
var paymentMethods = await greenfield.GetInvoicePaymentMethods(s.StoreId, i);
Assert.Single(paymentMethods, p => {
return p.AdditionalData["providedComment"].Value<string>() == "lol2";
});
// Standard invoice test // Standard invoice test
s.GoToStore(storeId); s.GoToStore(storeId);
s.GoToLightningSettings(); s.GoToLightningSettings();
@@ -1608,6 +1614,7 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id("Amount")).Clear(); s.Driver.FindElement(By.Id("Amount")).Clear();
s.Driver.FindElement(By.Id("Amount")).SendKeys("0.0000001"); s.Driver.FindElement(By.Id("Amount")).SendKeys("0.0000001");
s.Driver.FindElement(By.Id("Create")).Click(); s.Driver.FindElement(By.Id("Create")).Click();
s.Driver.TakeScreenshot().SaveAsFile(@"C:\Users\NicolasDorier\AppData\Local\Temp\1279276918\wfew.png");
s.Driver.FindElement(By.LinkText("View")).Click(); s.Driver.FindElement(By.LinkText("View")).Click();
s.Driver.FindElement(By.Id("Destination")).SendKeys(lnurl); s.Driver.FindElement(By.Id("Destination")).SendKeys(lnurl);

View File

@@ -241,7 +241,7 @@ namespace BTCPayServer
return NotFound(); return NotFound();
} }
var lnAddress = username is null ? null : $"{username}@{Request.Host.ToString()}"; var lnAddress = username is null ? null : $"{username}@{Request.Host}";
List<string[]> lnurlMetadata = new List<string[]>(); List<string[]> lnurlMetadata = new List<string[]>();
var i = await _invoiceController.CreateInvoiceCoreRaw( var i = await _invoiceController.CreateInvoiceCoreRaw(

View File

@@ -96,7 +96,7 @@ namespace BTCPayServer.HostedServices
throw new ArgumentException("Amount out of bound", nameof(create)); throw new ArgumentException("Amount out of bound", nameof(create));
using var ctx = this._dbContextFactory.CreateContext(); using var ctx = this._dbContextFactory.CreateContext();
var o = new Data.PullPaymentData(); var o = new Data.PullPaymentData();
o.StartDate = create.StartsAt is DateTimeOffset date ? date : DateTimeOffset.UtcNow; o.StartDate = create.StartsAt is DateTimeOffset date ? date : DateTimeOffset.UtcNow - TimeSpan.FromSeconds(1.0);
o.EndDate = create.ExpiresAt is DateTimeOffset date2 ? new DateTimeOffset?(date2) : null; o.EndDate = create.ExpiresAt is DateTimeOffset date2 ? new DateTimeOffset?(date2) : null;
o.Period = create.Period is TimeSpan period ? (long?)period.TotalSeconds : null; o.Period = create.Period is TimeSpan period ? (long?)period.TotalSeconds : null;
o.Id = Encoders.Base58.EncodeData(RandomUtils.GetBytes(20)); o.Id = Encoders.Base58.EncodeData(RandomUtils.GetBytes(20));

View File

@@ -22,6 +22,6 @@ namespace BTCPayServer.Payments
bool Activated { get; set; } bool Activated { get; set; }
virtual string GetAdditionalDataPartialName() => null; virtual string GetAdditionalDataPartialName() => null;
virtual Dictionary<string,JObject> GetAdditionalData() => new(); virtual JObject GetAdditionalData() => new();
} }
} }

View File

@@ -35,19 +35,13 @@ namespace BTCPayServer.Payments
return "LNURL/AdditionalPaymentMethodDetails"; return "LNURL/AdditionalPaymentMethodDetails";
} }
public override Dictionary<string, JObject> GetAdditionalData() public override JObject GetAdditionalData()
{ {
var result = base.GetAdditionalData(); var result = base.GetAdditionalData();
if (!string.IsNullOrEmpty(ProvidedComment)) if (!string.IsNullOrEmpty(ProvidedComment))
{ result.Add("providedComment", new JValue(ProvidedComment));
result.TryAdd(nameof(ProvidedComment), new JObject(ProvidedComment));
}
if (!string.IsNullOrEmpty(ConsumedLightningAddress)) if (!string.IsNullOrEmpty(ConsumedLightningAddress))
{ result.Add("consumedLightningAddress", new JValue(ConsumedLightningAddress));
result.TryAdd(nameof(ConsumedLightningAddress), new JObject(ConsumedLightningAddress));
}
return result; return result;
} }
} }

View File

@@ -43,7 +43,7 @@ namespace BTCPayServer.Payments.Lightning
return null; return null;
} }
public virtual Dictionary<string, JObject> GetAdditionalData() public virtual JObject GetAdditionalData()
{ {
return new(); return new();
} }

View File

@@ -1142,8 +1142,31 @@
"description": "If the payment method is activated (when lazy payments option is enabled" "description": "If the payment method is activated (when lazy payments option is enabled"
}, },
"additionalData": { "additionalData": {
"description": "Additional data provided by the payment method.",
"anyOf": [
{
"type": "object", "type": "object",
"description": "Additional data provided by the payment method." "description": "LNURL Pay information",
"properties": {
"providedComment": {
"type": "string",
"nullable": true,
"description": "The provided comment to a LNUrl payment with comments enabled",
"example": "Thank you!"
},
"consumedLightningAddress": {
"type": "string",
"nullable": true,
"description": "The consumed lightning address of a LN Address payment",
"example": "customer@example.com"
}
}
},
{
"type": "object",
"description": "No additional information"
}
]
} }
} }
}, },