mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-06 15:44:26 +01:00
init bitpay rates api
This commit is contained in:
@@ -31,6 +31,74 @@ namespace BTCPayServer.Controllers
|
||||
_CurrencyNameTable = currencyNameTable ?? throw new ArgumentNullException(nameof(currencyNameTable));
|
||||
}
|
||||
|
||||
[Route("rates/{baseCurrency}/{currency}")]
|
||||
[HttpGet]
|
||||
[BitpayAPIConstraint]
|
||||
public async Task<IActionResult> GetCurrencyPairRate(string baseCurrency, string currency, string storeId)
|
||||
{
|
||||
storeId = storeId ?? this.HttpContext.GetStoreData()?.Id;
|
||||
var result = await GetRates2($"{baseCurrency}_{currency}", storeId);
|
||||
var rates = (result as JsonResult)?.Value as Rate[];
|
||||
if (rates == null)
|
||||
return result;
|
||||
return Json(new DataWrapper<Rate>(rates.First()));
|
||||
}
|
||||
|
||||
|
||||
[Route("rates")]
|
||||
[HttpGet]
|
||||
[BitpayAPIConstraint]
|
||||
public async Task<IActionResult> GetRates()
|
||||
{
|
||||
var store = this.HttpContext.GetStoreData();
|
||||
var currencypairs = "";
|
||||
var supportedMethods = store.GetSupportedPaymentMethods(_NetworkProvider);
|
||||
|
||||
foreach (var supportedPaymentMethod in supportedMethods)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(currencypairs))
|
||||
{
|
||||
currencypairs += ",";
|
||||
}
|
||||
|
||||
currencypairs += supportedPaymentMethod.CryptoCode + "_USD,";
|
||||
currencypairs += supportedPaymentMethod.CryptoCode + "_EUR";
|
||||
}
|
||||
var result = await GetRates2(currencypairs, store.Id);
|
||||
var rates = (result as JsonResult)?.Value as Rate[];
|
||||
if (rates == null)
|
||||
return result;
|
||||
return Json(new DataWrapper<Rate>(rates.First()));
|
||||
}
|
||||
|
||||
[Route("rates/{baseCurrency}")]
|
||||
[HttpGet]
|
||||
[BitpayAPIConstraint]
|
||||
public async Task<IActionResult> GetRates(string baseCurrency)
|
||||
{
|
||||
var store = this.HttpContext.GetStoreData();
|
||||
var currencypairs = "";
|
||||
var supportedMethods = store.GetSupportedPaymentMethods(_NetworkProvider);
|
||||
|
||||
currencypairs += baseCurrency + "_USD,";
|
||||
currencypairs += baseCurrency + "_EUR";
|
||||
foreach (var supportedPaymentMethod in supportedMethods)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(currencypairs))
|
||||
{
|
||||
currencypairs += ",";
|
||||
}
|
||||
|
||||
currencypairs += baseCurrency + "_ " +supportedPaymentMethod.CryptoCode +",";
|
||||
currencypairs += baseCurrency + "_ " + supportedPaymentMethod.CryptoCode;
|
||||
}
|
||||
var result = await GetRates2(currencypairs, store.Id);
|
||||
var rates = (result as JsonResult)?.Value as Rate[];
|
||||
if (rates == null)
|
||||
return result;
|
||||
return Json(new DataWrapper<Rate>(rates.First()));
|
||||
}
|
||||
|
||||
[Route("rates")]
|
||||
[HttpGet]
|
||||
[BitpayAPIConstraint]
|
||||
@@ -44,6 +112,7 @@ namespace BTCPayServer.Controllers
|
||||
return Json(new DataWrapper<Rate[]>(rates));
|
||||
}
|
||||
|
||||
|
||||
[Route("api/rates")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetRates2(string currencyPairs, string storeId)
|
||||
|
||||
@@ -32,8 +32,9 @@ namespace BTCPayServer
|
||||
|
||||
public BTCPayNetwork Network { get { return this._Network; } }
|
||||
|
||||
public DerivationStrategyBase DerivationStrategyBase { get { return this._DerivationStrategy; } }
|
||||
public DerivationStrategyBase DerivationStrategyBase => this._DerivationStrategy;
|
||||
|
||||
public string CryptoCode => Network.CryptoCode;
|
||||
public PaymentMethodId PaymentId => new PaymentMethodId(Network.CryptoCode, PaymentTypes.BTCLike);
|
||||
|
||||
public override string ToString()
|
||||
|
||||
@@ -202,7 +202,8 @@ namespace BTCPayServer.HostedServices
|
||||
PaymentSubtotals = dto.PaymentSubtotals,
|
||||
PaymentTotals = dto.PaymentTotals,
|
||||
AmountPaid = dto.AmountPaid,
|
||||
ExchangeRates = dto.ExchangeRates
|
||||
ExchangeRates = dto.ExchangeRates,
|
||||
|
||||
};
|
||||
|
||||
// We keep backward compatibility with bitpay by passing BTC info to the notification
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace BTCPayServer.Payments
|
||||
/// </summary>
|
||||
public interface ISupportedPaymentMethod
|
||||
{
|
||||
string CryptoCode { get;}
|
||||
PaymentMethodId PaymentId { get; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user