mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Fix: Form in Payment Requests was not setting its values to the invoices metadata (#4907)
This commit is contained in:
parent
c3c8cc21ff
commit
39b76c08de
4 changed files with 24 additions and 18 deletions
|
@ -116,8 +116,11 @@ namespace BTCPayServer.Tests
|
|||
|
||||
s.Driver.FindElement(By.Name("buyerEmail")).SendKeys("aa@aa.com");
|
||||
s.Driver.FindElement(By.CssSelector("input[type='submit']")).Click();
|
||||
invoiceId = s.Driver.Url.Split('/').Last();
|
||||
s.Driver.Navigate().GoToUrl(editUrl);
|
||||
Assert.Contains("aa@aa.com", s.Driver.PageSource);
|
||||
var invoice = await s.Server.PayTester.GetService<InvoiceRepository>().GetInvoice(invoiceId);
|
||||
Assert.Equal("aa@aa.com", invoice.Metadata.BuyerEmail);
|
||||
|
||||
//Custom Forms
|
||||
s.GoToStore(StoreNavPages.Forms);
|
||||
|
|
|
@ -124,7 +124,8 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||
|
||||
try
|
||||
{
|
||||
var invoice = await _invoiceController.CreatePaymentRequestInvoice(pr, amount, this.StoreData, Request, cancellationToken);
|
||||
var prData = await _paymentRequestRepository.FindPaymentRequest(pr.Id, null);
|
||||
var invoice = await _invoiceController.CreatePaymentRequestInvoice(prData, amount, pr.AmountDue, this.StoreData, Request, cancellationToken);
|
||||
return Ok(GreenfieldInvoiceController.ToModel(invoice, _linkGenerator, Request));
|
||||
}
|
||||
catch (BitpayHttpException e)
|
||||
|
|
|
@ -187,33 +187,35 @@ namespace BTCPayServer.Controllers
|
|||
return await CreateInvoiceCoreRaw(entity, store, excludeFilter, null, cancellationToken, entityManipulator);
|
||||
}
|
||||
|
||||
internal async Task<InvoiceEntity> CreatePaymentRequestInvoice(ViewPaymentRequestViewModel pr, decimal? amount, StoreData storeData, HttpRequest request, CancellationToken cancellationToken)
|
||||
internal async Task<InvoiceEntity> CreatePaymentRequestInvoice(Data.PaymentRequestData prData, decimal? amount, decimal amountDue, StoreData storeData, HttpRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (pr.AllowCustomPaymentAmounts && amount != null)
|
||||
amount = Math.Min(pr.AmountDue, amount.Value);
|
||||
var id = prData.Id;
|
||||
var prBlob = prData.GetBlob();
|
||||
if (prBlob.AllowCustomPaymentAmounts && amount != null)
|
||||
amount = Math.Min(amountDue, amount.Value);
|
||||
else
|
||||
amount = pr.AmountDue;
|
||||
var redirectUrl = _linkGenerator.PaymentRequestLink(pr.Id, request.Scheme, request.Host, request.PathBase);
|
||||
amount = amountDue;
|
||||
var redirectUrl = _linkGenerator.PaymentRequestLink(id, request.Scheme, request.Host, request.PathBase);
|
||||
|
||||
var invoiceMetadata =
|
||||
new InvoiceMetadata
|
||||
{
|
||||
OrderId = PaymentRequestRepository.GetOrderIdForPaymentRequest(pr.Id),
|
||||
PaymentRequestId = pr.Id,
|
||||
BuyerEmail = pr.Email
|
||||
};
|
||||
JObject invoiceMetadata = prData.GetBlob()?.FormResponse is JObject formResponse ? formResponse : new JObject();
|
||||
invoiceMetadata.Merge(new InvoiceMetadata
|
||||
{
|
||||
OrderId = PaymentRequestRepository.GetOrderIdForPaymentRequest(id),
|
||||
PaymentRequestId = id,
|
||||
BuyerEmail = string.IsNullOrEmpty(prBlob.Email) ? null : prBlob.Email
|
||||
}.ToJObject(), new JsonMergeSettings() { MergeNullValueHandling = MergeNullValueHandling.Ignore });
|
||||
|
||||
var invoiceRequest =
|
||||
new CreateInvoiceRequest
|
||||
{
|
||||
Metadata = invoiceMetadata.ToJObject(),
|
||||
Currency = pr.Currency,
|
||||
Metadata = invoiceMetadata,
|
||||
Currency = prBlob.Currency,
|
||||
Amount = amount,
|
||||
Checkout = { RedirectURL = redirectUrl },
|
||||
Receipt = new InvoiceDataBase.ReceiptOptions { Enabled = false }
|
||||
};
|
||||
|
||||
var additionalTags = new List<string> { PaymentRequestRepository.GetInternalTag(pr.Id) };
|
||||
var additionalTags = new List<string> { PaymentRequestRepository.GetInternalTag(id) };
|
||||
return await CreateInvoiceCoreRaw(invoiceRequest, storeData, request.GetAbsoluteRoot(), additionalTags, cancellationToken);
|
||||
}
|
||||
|
||||
|
|
|
@ -277,7 +277,6 @@ namespace BTCPayServer.Controllers
|
|||
|
||||
return BadRequest("Payment Request cannot be paid as it has been archived");
|
||||
}
|
||||
|
||||
if (!result.FormSubmitted && !string.IsNullOrEmpty(result.FormId))
|
||||
{
|
||||
var formData = await FormDataService.GetForm(result.FormId);
|
||||
|
@ -322,7 +321,8 @@ namespace BTCPayServer.Controllers
|
|||
try
|
||||
{
|
||||
var store = await _storeRepository.FindStore(result.StoreId);
|
||||
var newInvoice = await _InvoiceController.CreatePaymentRequestInvoice(result, amount, store, Request, cancellationToken);
|
||||
var prData = await _PaymentRequestRepository.FindPaymentRequest(result.Id, null);
|
||||
var newInvoice = await _InvoiceController.CreatePaymentRequestInvoice(prData, amount, result.AmountDue, store, Request, cancellationToken);
|
||||
if (redirectToInvoice)
|
||||
{
|
||||
return RedirectToAction("Checkout", "UIInvoice", new { invoiceId = newInvoice.Id });
|
||||
|
|
Loading…
Add table
Reference in a new issue