mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Fix: Bitpay's API rate route wasn't backward for some queries (#5671)
This commit is contained in:
parent
bd196ad963
commit
cd8ef0c1ff
2 changed files with 21 additions and 9 deletions
|
@ -1147,6 +1147,14 @@ namespace BTCPayServer.Tests
|
|||
bitpay = new Bitpay(k, tester.PayTester.ServerUri);
|
||||
Assert.True(bitpay.TestAccess(Facade.Merchant));
|
||||
Assert.True(bitpay.TestAccess(Facade.PointOfSale));
|
||||
HttpClient client = new HttpClient();
|
||||
var token = (await bitpay.GetAccessTokenAsync(Facade.Merchant)).Value;
|
||||
var getRates = tester.PayTester.ServerUri.AbsoluteUri + $"rates/?cryptoCode=BTC&token={token}";
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, getRates);
|
||||
req.Headers.Add("x-signature", NBitpayClient.Extensions.BitIdExtensions.GetBitIDSignature(k, getRates, null));
|
||||
req.Headers.Add("x-identity", k.PubKey.ToHex());
|
||||
var resp = await client.SendAsync(req);
|
||||
resp.EnsureSuccessStatusCode();
|
||||
|
||||
// Can generate API Key
|
||||
var repo = tester.PayTester.GetService<TokenRepository>();
|
||||
|
@ -1167,7 +1175,6 @@ namespace BTCPayServer.Tests
|
|||
apiKey = apiKey2;
|
||||
|
||||
// Can create an invoice with this new API Key
|
||||
HttpClient client = new HttpClient();
|
||||
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post,
|
||||
tester.PayTester.ServerUri.AbsoluteUri + "invoices");
|
||||
message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic",
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace BTCPayServer.Controllers
|
|||
[Route("rates/{baseCurrency}")]
|
||||
[HttpGet]
|
||||
[BitpayAPIConstraint]
|
||||
public async Task<IActionResult> GetBaseCurrencyRates(string baseCurrency, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetBaseCurrencyRates(string baseCurrency, string cryptoCode = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var supportedMethods = CurrentStore.GetSupportedPaymentMethods(_networkProvider);
|
||||
|
||||
|
@ -57,16 +57,16 @@ namespace BTCPayServer.Controllers
|
|||
|
||||
var currencypairs = BuildCurrencyPairs(currencyCodes, baseCurrency);
|
||||
|
||||
var result = await GetRates2(currencypairs, null, cancellationToken);
|
||||
var result = await GetRates2(currencypairs, null, cryptoCode, cancellationToken);
|
||||
var rates = (result as JsonResult)?.Value as Rate[];
|
||||
return rates == null ? result : Json(new DataWrapper<Rate[]>(rates));
|
||||
}
|
||||
|
||||
[HttpGet("rates/{baseCurrency}/{currency}")]
|
||||
[BitpayAPIConstraint]
|
||||
public async Task<IActionResult> GetCurrencyPairRate(string baseCurrency, string currency, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetCurrencyPairRate(string baseCurrency, string currency, string cryptoCode = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = await GetRates2($"{baseCurrency}_{currency}", null, cancellationToken);
|
||||
var result = await GetRates2($"{baseCurrency}_{currency}", null, cryptoCode, cancellationToken);
|
||||
return (result as JsonResult)?.Value is not Rate[] rates
|
||||
? result
|
||||
: Json(new DataWrapper<Rate>(rates.First()));
|
||||
|
@ -74,9 +74,9 @@ namespace BTCPayServer.Controllers
|
|||
|
||||
[HttpGet("rates")]
|
||||
[BitpayAPIConstraint]
|
||||
public async Task<IActionResult> GetRates(string currencyPairs, string storeId = null, CancellationToken cancellationToken = default)
|
||||
public async Task<IActionResult> GetRates(string currencyPairs, string storeId = null, string cryptoCode = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = await GetRates2(currencyPairs, storeId, cancellationToken);
|
||||
var result = await GetRates2(currencyPairs, storeId, cryptoCode, cancellationToken);
|
||||
return (result as JsonResult)?.Value is not Rate[] rates
|
||||
? result
|
||||
: Json(new DataWrapper<Rate[]>(rates));
|
||||
|
@ -84,7 +84,7 @@ namespace BTCPayServer.Controllers
|
|||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("api/rates")]
|
||||
public async Task<IActionResult> GetRates2(string currencyPairs, string storeId, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetRates2(string currencyPairs, string storeId, string cryptoCode = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var store = CurrentStore ?? await _storeRepo.FindStore(storeId);
|
||||
if (store == null)
|
||||
|
@ -95,7 +95,12 @@ namespace BTCPayServer.Controllers
|
|||
}
|
||||
if (currencyPairs == null)
|
||||
{
|
||||
currencyPairs = store.GetStoreBlob().GetDefaultCurrencyPairString();
|
||||
var blob = store.GetStoreBlob();
|
||||
currencyPairs = blob.GetDefaultCurrencyPairString();
|
||||
if (string.IsNullOrEmpty(currencyPairs) && !string.IsNullOrWhiteSpace(cryptoCode))
|
||||
{
|
||||
currencyPairs = $"{blob.DefaultCurrency}_{cryptoCode}".ToUpperInvariant();
|
||||
}
|
||||
if (string.IsNullOrEmpty(currencyPairs))
|
||||
{
|
||||
var result = Json(new BitpayErrorsModel() { Error = "You need to setup the default currency pairs in 'Store Settings / Rates' or specify 'currencyPairs' query parameter (eg. BTC_USD,LTC_CAD)." });
|
||||
|
|
Loading…
Add table
Reference in a new issue