mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Use the store's default currency when creating entities (#3585)
* Use default currency for new pull payments Closes #3582. * Pull payment: Improve create form * Use default currency for new invoices Closes #3581. * Clean up old invoice form code * Use default currency for new payment requests * Test fixes
This commit is contained in:
@@ -189,6 +189,7 @@ namespace BTCPayServer.Tests
|
|||||||
(await apiKeyRepo.GetKey(accessToken)).GetBlob().Permissions);
|
(await apiKeyRepo.GetKey(accessToken)).GetBlob().Permissions);
|
||||||
|
|
||||||
//let's test the app identifier system
|
//let's test the app identifier system
|
||||||
|
TestLogs.LogInformation("Checking app identifier system");
|
||||||
authUrl = BTCPayServerClient.GenerateAuthorizeUri(s.ServerUri,
|
authUrl = BTCPayServerClient.GenerateAuthorizeUri(s.ServerUri,
|
||||||
new[] { Policies.CanModifyStoreSettings, Policies.CanModifyServerSettings }, false, true, (appidentifier, new Uri(callbackUrl))).ToString();
|
new[] { Policies.CanModifyStoreSettings, Policies.CanModifyServerSettings }, false, true, (appidentifier, new Uri(callbackUrl))).ToString();
|
||||||
|
|
||||||
|
|||||||
@@ -751,7 +751,12 @@ namespace BTCPayServer.Tests
|
|||||||
s.Driver.FindElement(By.Id("CreatePaymentRequest")).Click();
|
s.Driver.FindElement(By.Id("CreatePaymentRequest")).Click();
|
||||||
s.Driver.FindElement(By.Id("Title")).SendKeys("Pay123");
|
s.Driver.FindElement(By.Id("Title")).SendKeys("Pay123");
|
||||||
s.Driver.FindElement(By.Id("Amount")).SendKeys("700");
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("700");
|
||||||
s.Driver.FindElement(By.Id("Currency")).SendKeys("BTC");
|
|
||||||
|
var currencyInput = s.Driver.FindElement(By.Id("Currency"));
|
||||||
|
Assert.Equal("USD", currencyInput.GetAttribute("value"));
|
||||||
|
currencyInput.Clear();
|
||||||
|
currencyInput.SendKeys("BTC");
|
||||||
|
|
||||||
s.Driver.FindElement(By.Id("SaveButton")).Click();
|
s.Driver.FindElement(By.Id("SaveButton")).Click();
|
||||||
s.Driver.FindElement(By.Id("ViewPaymentRequest")).Click();
|
s.Driver.FindElement(By.Id("ViewPaymentRequest")).Click();
|
||||||
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
||||||
@@ -1615,6 +1620,12 @@ namespace BTCPayServer.Tests
|
|||||||
s.Driver.FindElement(By.Id("Name")).SendKeys("PP1");
|
s.Driver.FindElement(By.Id("Name")).SendKeys("PP1");
|
||||||
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");
|
||||||
|
|
||||||
|
var currencyInput = s.Driver.FindElement(By.Id("Currency"));
|
||||||
|
Assert.Equal("USD", currencyInput.GetAttribute("value"));
|
||||||
|
currencyInput.Clear();
|
||||||
|
currencyInput.SendKeys("BTC");
|
||||||
|
|
||||||
s.Driver.FindElement(By.Id("Create")).Click();
|
s.Driver.FindElement(By.Id("Create")).Click();
|
||||||
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);
|
||||||
|
|||||||
@@ -914,18 +914,6 @@ namespace BTCPayServer.Controllers
|
|||||||
[BitpayAPIConstraint(false)]
|
[BitpayAPIConstraint(false)]
|
||||||
public async Task<IActionResult> CreateInvoice(InvoicesModel? model = null)
|
public async Task<IActionResult> CreateInvoice(InvoicesModel? model = null)
|
||||||
{
|
{
|
||||||
var stores = new SelectList(
|
|
||||||
await _StoreRepository.GetStoresByUserId(GetUserId()),
|
|
||||||
nameof(StoreData.Id),
|
|
||||||
nameof(StoreData.StoreName),
|
|
||||||
new SearchString(model?.SearchTerm).GetFilterArray("storeid")?.ToArray().FirstOrDefault()
|
|
||||||
);
|
|
||||||
if (!stores.Any())
|
|
||||||
{
|
|
||||||
TempData[WellKnownTempData.ErrorMessage] = "You need to create at least one store before creating a transaction";
|
|
||||||
return RedirectToAction(nameof(UIHomeController.Index), "UIHome");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (model?.StoreId != null)
|
if (model?.StoreId != null)
|
||||||
{
|
{
|
||||||
var store = await _StoreRepository.FindStore(model.StoreId, GetUserId());
|
var store = await _StoreRepository.FindStore(model.StoreId, GetUserId());
|
||||||
@@ -944,11 +932,16 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
HttpContext.SetStoreData(store);
|
HttpContext.SetStoreData(store);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempData[WellKnownTempData.ErrorMessage] = "You need to select a store before creating an invoice.";
|
||||||
|
return RedirectToAction(nameof(UIHomeController.Index), "UIHome");
|
||||||
|
}
|
||||||
|
|
||||||
var vm = new CreateInvoiceModel
|
var vm = new CreateInvoiceModel
|
||||||
{
|
{
|
||||||
Stores = stores,
|
StoreId = model.StoreId,
|
||||||
StoreId = model?.StoreId,
|
Currency = HttpContext.GetStoreData()?.GetStoreBlob().DefaultCurrency,
|
||||||
AvailablePaymentMethods = GetPaymentMethodsSelectList()
|
AvailablePaymentMethods = GetPaymentMethodsSelectList()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -961,8 +954,6 @@ namespace BTCPayServer.Controllers
|
|||||||
[BitpayAPIConstraint(false)]
|
[BitpayAPIConstraint(false)]
|
||||||
public async Task<IActionResult> CreateInvoice(CreateInvoiceModel model, CancellationToken cancellationToken)
|
public async Task<IActionResult> CreateInvoice(CreateInvoiceModel model, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var stores = await _StoreRepository.GetStoresByUserId(GetUserId());
|
|
||||||
model.Stores = new SelectList(stores, nameof(StoreData.Id), nameof(StoreData.StoreName), model.StoreId);
|
|
||||||
model.AvailablePaymentMethods = GetPaymentMethodsSelectList();
|
model.AvailablePaymentMethods = GetPaymentMethodsSelectList();
|
||||||
var store = HttpContext.GetStoreData();
|
var store = HttpContext.GetStoreData();
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|||||||
@@ -89,10 +89,14 @@ namespace BTCPayServer.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(nameof(EditPaymentRequest), new UpdatePaymentRequestViewModel(paymentRequest)
|
var vm = new UpdatePaymentRequestViewModel(paymentRequest)
|
||||||
{
|
{
|
||||||
StoreId = store.Id
|
StoreId = store.Id
|
||||||
});
|
};
|
||||||
|
|
||||||
|
vm.Currency ??= store.GetStoreBlob().DefaultCurrency;
|
||||||
|
|
||||||
|
return View(nameof(EditPaymentRequest), vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("/stores/{storeId}/payment-requests/edit/{payReqId?}")]
|
[HttpPost("/stores/{storeId}/payment-requests/edit/{payReqId?}")]
|
||||||
|
|||||||
@@ -76,10 +76,11 @@ namespace BTCPayServer.Controllers
|
|||||||
});
|
});
|
||||||
return RedirectToAction(nameof(UIStoresController.GeneralSettings), "UIStores", new { storeId });
|
return RedirectToAction(nameof(UIStoresController.GeneralSettings), "UIStores", new { storeId });
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(new NewPullPaymentModel
|
return View(new NewPullPaymentModel
|
||||||
{
|
{
|
||||||
Name = "",
|
Name = "",
|
||||||
Currency = "BTC",
|
Currency = CurrentStore.GetStoreBlob().DefaultCurrency,
|
||||||
CustomCSSLink = "",
|
CustomCSSLink = "",
|
||||||
EmbeddedCSS = "",
|
EmbeddedCSS = "",
|
||||||
PaymentMethodItems = paymentMethods.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString(), true))
|
PaymentMethodItems = paymentMethods.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString(), true))
|
||||||
|
|||||||
@@ -64,12 +64,6 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DisplayName("Store")]
|
|
||||||
public SelectList Stores
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
|
|
||||||
[DisplayName("Supported Transaction Currencies")]
|
[DisplayName("Supported Transaction Currencies")]
|
||||||
public List<string> SupportedTransactionCurrencies
|
public List<string> SupportedTransactionCurrencies
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<form asp-action="CreateInvoice" method="post" id="create-invoice-form">
|
<form asp-action="CreateInvoice" method="post" id="create-invoice-form">
|
||||||
<div class="sticky-header-setup"></div>
|
<div class="sticky-header-setup"></div>
|
||||||
<div class="sticky-header d-flex align-items-center justify-content-between">
|
<div class="sticky-header d-flex align-items-center justify-content-between">
|
||||||
@@ -42,16 +41,6 @@
|
|||||||
{
|
{
|
||||||
<input type="hidden" asp-for="StoreId" />
|
<input type="hidden" asp-for="StoreId" />
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Stores" class="form-label"></label>
|
|
||||||
<select asp-for="StoreId" asp-items="Model.Stores" class="form-select"></select>
|
|
||||||
<span asp-validation-for="StoreId" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h4 class="mt-5 mb-4">Invoice Details</h4>
|
|
||||||
}
|
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<div class="form-group flex-fill me-4">
|
<div class="form-group flex-fill me-4">
|
||||||
<label asp-for="Amount" class="form-label"></label>
|
<label asp-for="Amount" class="form-label"></label>
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-8">
|
<div class="form-group col-8">
|
||||||
<label asp-for="Amount" class="form-label"></label>
|
<label asp-for="Amount" class="form-label" data-required></label>
|
||||||
<input inputmode="decimal" asp-for="Amount" class="form-control"/>
|
<input asp-for="Amount" class="form-control" inputmode="decimal" />
|
||||||
<span asp-validation-for="Amount" class="text-danger"></span>
|
<span asp-validation-for="Amount" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-4">
|
<div class="form-group col-4">
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
<span asp-validation-for="Description" class="text-danger"></span>
|
<span asp-validation-for="Description" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h5 class="mt-4 mb-2">Additional Options</h5>
|
<h4 class="mt-5 mb-2">Additional Options</h4>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="accordion" id="additional">
|
<div class="accordion" id="additional">
|
||||||
<div class="accordion-item">
|
<div class="accordion-item">
|
||||||
|
|||||||
Reference in New Issue
Block a user