mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
[Greenfield] Fix create/update payment requests expiry field and allow null currency field (Fix #3222) (#3284)
This commit is contained in:
@@ -12,7 +12,8 @@ namespace BTCPayServer.Client.Models
|
|||||||
[JsonProperty(ItemConverterType = typeof(NumericStringJsonConverter))]
|
[JsonProperty(ItemConverterType = typeof(NumericStringJsonConverter))]
|
||||||
public decimal Amount { get; set; }
|
public decimal Amount { get; set; }
|
||||||
public string Currency { get; set; }
|
public string Currency { get; set; }
|
||||||
public DateTime? ExpiryDate { get; set; }
|
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
|
||||||
|
public DateTimeOffset? ExpiryDate { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|||||||
@@ -912,7 +912,7 @@ namespace BTCPayServer.Tests
|
|||||||
//create payment request
|
//create payment request
|
||||||
|
|
||||||
//validation errors
|
//validation errors
|
||||||
await AssertValidationError(new[] { "Amount", "Currency" }, async () =>
|
await AssertValidationError(new[] { "Amount" }, async () =>
|
||||||
{
|
{
|
||||||
await client.CreatePaymentRequest(user.StoreId, new CreatePaymentRequestRequest() { Title = "A" });
|
await client.CreatePaymentRequest(user.StoreId, new CreatePaymentRequestRequest() { Title = "A" });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
{
|
{
|
||||||
return validationResult;
|
return validationResult;
|
||||||
}
|
}
|
||||||
|
request.Currency ??= StoreData.GetStoreBlob().DefaultCurrency;
|
||||||
var pr = new PaymentRequestData()
|
var pr = new PaymentRequestData()
|
||||||
{
|
{
|
||||||
StoreDataId = storeId,
|
StoreDataId = storeId,
|
||||||
@@ -95,7 +95,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
pr = await _paymentRequestRepository.CreateOrUpdatePaymentRequest(pr);
|
pr = await _paymentRequestRepository.CreateOrUpdatePaymentRequest(pr);
|
||||||
return Ok(FromModel(pr));
|
return Ok(FromModel(pr));
|
||||||
}
|
}
|
||||||
|
public Data.StoreData StoreData => HttpContext.GetStoreData();
|
||||||
[HttpPut("~/api/v1/stores/{storeId}/payment-requests/{paymentRequestId}")]
|
[HttpPut("~/api/v1/stores/{storeId}/payment-requests/{paymentRequestId}")]
|
||||||
[Authorize(Policy = Policies.CanModifyPaymentRequests,
|
[Authorize(Policy = Policies.CanModifyPaymentRequests,
|
||||||
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||||
@@ -107,7 +107,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
{
|
{
|
||||||
return validationResult;
|
return validationResult;
|
||||||
}
|
}
|
||||||
|
request.Currency ??= StoreData.GetStoreBlob().DefaultCurrency;
|
||||||
var pr = await _paymentRequestRepository.FindPaymentRequests(
|
var pr = await _paymentRequestRepository.FindPaymentRequests(
|
||||||
new PaymentRequestQuery() { StoreId = storeId, Ids = new[] { paymentRequestId } });
|
new PaymentRequestQuery() { StoreId = storeId, Ids = new[] { paymentRequestId } });
|
||||||
if (pr.Total == 0)
|
if (pr.Total == 0)
|
||||||
@@ -130,10 +130,11 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
ModelState.AddModelError(nameof(data.Amount), "Please provide an amount greater than 0");
|
ModelState.AddModelError(nameof(data.Amount), "Please provide an amount greater than 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(data.Currency) ||
|
if (!string.IsNullOrEmpty(data.Currency) &&
|
||||||
_currencyNameTable.GetCurrencyData(data.Currency, false) == null)
|
_currencyNameTable.GetCurrencyData(data.Currency, false) == null)
|
||||||
ModelState.AddModelError(nameof(data.Currency), "Invalid currency");
|
ModelState.AddModelError(nameof(data.Currency), "Invalid currency");
|
||||||
|
if (string.IsNullOrEmpty(data.Currency))
|
||||||
|
data.Currency = null;
|
||||||
if (string.IsNullOrEmpty(data.Title))
|
if (string.IsNullOrEmpty(data.Title))
|
||||||
ModelState.AddModelError(nameof(data.Title), "Title is required");
|
ModelState.AddModelError(nameof(data.Title), "Title is required");
|
||||||
|
|
||||||
|
|||||||
@@ -97,10 +97,11 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpPost("/stores/{storeId}/payment-requests/edit/{payReqId?}")]
|
[HttpPost("/stores/{storeId}/payment-requests/edit/{payReqId?}")]
|
||||||
public async Task<IActionResult> EditPaymentRequest(string payReqId, UpdatePaymentRequestViewModel viewModel)
|
public async Task<IActionResult> EditPaymentRequest(string payReqId, UpdatePaymentRequestViewModel viewModel)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(viewModel.Currency) ||
|
if (!string.IsNullOrEmpty(viewModel.Currency) &&
|
||||||
_Currencies.GetCurrencyData(viewModel.Currency, false) == null)
|
_Currencies.GetCurrencyData(viewModel.Currency, false) == null)
|
||||||
ModelState.AddModelError(nameof(viewModel.Currency), "Invalid currency");
|
ModelState.AddModelError(nameof(viewModel.Currency), "Invalid currency");
|
||||||
|
if (string.IsNullOrEmpty(viewModel.Currency))
|
||||||
|
viewModel.Currency = null;
|
||||||
var store = GetCurrentStore();
|
var store = GetCurrentStore();
|
||||||
var paymentRequest = GetCurrentPaymentRequest();
|
var paymentRequest = GetCurrentPaymentRequest();
|
||||||
if (paymentRequest == null && !string.IsNullOrEmpty(payReqId))
|
if (paymentRequest == null && !string.IsNullOrEmpty(payReqId))
|
||||||
@@ -128,7 +129,7 @@ namespace BTCPayServer.Controllers
|
|||||||
blob.Description = viewModel.Description;
|
blob.Description = viewModel.Description;
|
||||||
blob.Amount = viewModel.Amount;
|
blob.Amount = viewModel.Amount;
|
||||||
blob.ExpiryDate = viewModel.ExpiryDate?.ToUniversalTime();
|
blob.ExpiryDate = viewModel.ExpiryDate?.ToUniversalTime();
|
||||||
blob.Currency = viewModel.Currency;
|
blob.Currency = viewModel.Currency ?? store.GetStoreBlob().DefaultCurrency;
|
||||||
blob.EmbeddedCSS = viewModel.EmbeddedCSS;
|
blob.EmbeddedCSS = viewModel.EmbeddedCSS;
|
||||||
blob.CustomCSSLink = viewModel.CustomCSSLink;
|
blob.CustomCSSLink = viewModel.CustomCSSLink;
|
||||||
blob.AllowCustomPaymentAmounts = viewModel.AllowCustomPaymentAmounts;
|
blob.AllowCustomPaymentAmounts = viewModel.AllowCustomPaymentAmounts;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace BTCPayServer.Models.PaymentRequestViewModels
|
|||||||
Amount = blob.Amount;
|
Amount = blob.Amount;
|
||||||
Currency = blob.Currency;
|
Currency = blob.Currency;
|
||||||
Description = blob.Description;
|
Description = blob.Description;
|
||||||
ExpiryDate = blob.ExpiryDate;
|
ExpiryDate = blob.ExpiryDate?.UtcDateTime;
|
||||||
Email = blob.Email;
|
Email = blob.Email;
|
||||||
CustomCSSLink = blob.CustomCSSLink;
|
CustomCSSLink = blob.CustomCSSLink;
|
||||||
EmbeddedCSS = blob.EmbeddedCSS;
|
EmbeddedCSS = blob.EmbeddedCSS;
|
||||||
@@ -88,7 +88,7 @@ namespace BTCPayServer.Models.PaymentRequestViewModels
|
|||||||
Amount = blob.Amount;
|
Amount = blob.Amount;
|
||||||
Currency = blob.Currency;
|
Currency = blob.Currency;
|
||||||
Description = blob.Description;
|
Description = blob.Description;
|
||||||
ExpiryDate = blob.ExpiryDate;
|
ExpiryDate = blob.ExpiryDate?.UtcDateTime;
|
||||||
Email = blob.Email;
|
Email = blob.Email;
|
||||||
EmbeddedCSS = blob.EmbeddedCSS;
|
EmbeddedCSS = blob.EmbeddedCSS;
|
||||||
CustomCSSLink = blob.CustomCSSLink;
|
CustomCSSLink = blob.CustomCSSLink;
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ namespace BTCPayServer.PaymentRequest
|
|||||||
{
|
{
|
||||||
QueueExpiryTask(
|
QueueExpiryTask(
|
||||||
updated.PaymentRequestId,
|
updated.PaymentRequestId,
|
||||||
expiry.Value,
|
expiry.Value.UtcDateTime,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@
|
|||||||
<span asp-validation-for="Amount" class="text-danger"></span>
|
<span asp-validation-for="Amount" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="Currency" class="form-label" data-required></label>
|
<label asp-for="Currency" class="form-label"></label>
|
||||||
<input asp-for="Currency" class="form-control" required />
|
<input asp-for="Currency" class="form-control" />
|
||||||
<span asp-validation-for="Currency" class="text-danger"></span>
|
<span asp-validation-for="Currency" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user