mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
bringin mainnet
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.JsonConverters;
|
||||
using NBitcoin;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
@@ -20,18 +21,38 @@ public class BringinClient
|
||||
private HttpClient HttpClient { get; set; }
|
||||
|
||||
|
||||
public static HttpClient CreateClient(IHttpClientFactory httpClientFactory, string? apiKey = null)
|
||||
public static Uri GetDashboardUri(Network network)
|
||||
{
|
||||
if (network.ChainName == ChainName.Mainnet)
|
||||
{
|
||||
return new Uri("https://app.bringin.xyz");
|
||||
}
|
||||
|
||||
return new Uri("https://dev-app.bringin.xyz");
|
||||
}
|
||||
|
||||
public static Uri GetApiUrl(Network network)
|
||||
{
|
||||
if (network.ChainName == ChainName.Mainnet)
|
||||
{
|
||||
return new Uri("https://api.bringin.xyz");
|
||||
}
|
||||
|
||||
return new Uri("https://dev.bringin.xyz");
|
||||
}
|
||||
|
||||
|
||||
public static HttpClient CreateClient(Network network, IHttpClientFactory httpClientFactory, string? apiKey = null)
|
||||
{
|
||||
var httpClient = httpClientFactory.CreateClient("bringin");
|
||||
httpClient.BaseAddress = new Uri("https://dev.bringin.xyz");
|
||||
if(apiKey != null)
|
||||
httpClient.BaseAddress = GetApiUrl(network);
|
||||
if (apiKey != null)
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("api-key", apiKey);
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public static async Task<Uri> OnboardUri(HttpClient httpClient, Uri callback)
|
||||
public static async Task<Uri> OnboardUri(HttpClient httpClient, Uri callback, Network network)
|
||||
{
|
||||
|
||||
var content = new StringContent(JsonConvert.SerializeObject(new
|
||||
{
|
||||
callback
|
||||
@@ -39,9 +60,7 @@ public class BringinClient
|
||||
var response = await httpClient.PostAsync($"/api/v0/application/btcpay/signup-url", content);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
if (response.IsSuccessStatusCode) return new Uri(JObject.Parse(responseContent)["signupURL"].ToString());
|
||||
return new Uri("https://dev-app.bringin.xyz");
|
||||
var error = JObject.Parse(responseContent).ToObject<BringinErrorResponse>();
|
||||
throw new BringinException(error);
|
||||
return GetDashboardUri(network);
|
||||
}
|
||||
|
||||
public async Task<string> GetUserId()
|
||||
@@ -87,6 +106,7 @@ public class BringinClient
|
||||
var balance = JObject.Parse(responseContent).ToObject<BalanceResponse>();
|
||||
return balance.Balance / 100m; //response is in cents
|
||||
}
|
||||
|
||||
var error = JObject.Parse(responseContent).ToObject<BringinErrorResponse>();
|
||||
throw new BringinException(error);
|
||||
}
|
||||
@@ -95,10 +115,7 @@ public class BringinClient
|
||||
{
|
||||
[JsonProperty("balance")]
|
||||
[JsonConverter(typeof(NumericStringJsonConverter))]
|
||||
public decimal Balance {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public decimal Balance { get; set; }
|
||||
}
|
||||
//
|
||||
// public class GetOrderResponse
|
||||
@@ -130,28 +147,25 @@ public class BringinClient
|
||||
|
||||
public class CreateOrderResponse
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
[JsonProperty("id")] public string Id { get; set; }
|
||||
|
||||
[JsonProperty("amount")]
|
||||
[JsonConverter(typeof(NumericStringJsonConverter))]
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
[JsonProperty("invoice")]
|
||||
public string Invoice { get; set; }
|
||||
[JsonProperty("invoice")] public string Invoice { get; set; }
|
||||
|
||||
[JsonProperty("expiresAt")]
|
||||
public long Expiry { get; set; }
|
||||
[JsonProperty("expiresAt")] public long Expiry { get; set; }
|
||||
}
|
||||
|
||||
public class CreateOrderRequest
|
||||
{ [JsonProperty("sourceAmount")]
|
||||
{
|
||||
[JsonProperty("sourceAmount")]
|
||||
[JsonConverter(typeof(NumericStringJsonConverter))]
|
||||
public decimal SourceAmount { get; set; }
|
||||
|
||||
[JsonProperty("ipAddress")] public string IP { get; set; }
|
||||
[JsonProperty("paymentMethod")]
|
||||
public string PaymentMethod { get; set; }
|
||||
[JsonProperty("paymentMethod")] public string PaymentMethod { get; set; }
|
||||
}
|
||||
|
||||
public class RateResponse
|
||||
|
||||
@@ -15,11 +15,13 @@ public class BringinController : Controller
|
||||
{
|
||||
private readonly BringinService _bringinService;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
|
||||
|
||||
public BringinController(BringinService bringinService, IHttpClientFactory httpClientFactory)
|
||||
public BringinController(BringinService bringinService, IHttpClientFactory httpClientFactory, BTCPayNetworkProvider btcPayNetworkProvider)
|
||||
{
|
||||
_bringinService = bringinService;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_btcPayNetworkProvider = btcPayNetworkProvider;
|
||||
}
|
||||
|
||||
[HttpGet("onboard")]
|
||||
@@ -35,8 +37,9 @@ public class BringinController : Controller
|
||||
storeId
|
||||
}, Request.Scheme);
|
||||
|
||||
var httpClient = BringinClient.CreateClient(_httpClientFactory);
|
||||
var onboardUri = await BringinClient.OnboardUri(httpClient, new Uri(callbackUri));
|
||||
var network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>("BTC").NBitcoinNetwork;
|
||||
var httpClient = BringinClient.CreateClient(network,_httpClientFactory);
|
||||
var onboardUri = await BringinClient.OnboardUri(httpClient, new Uri(callbackUri), network);
|
||||
return Redirect(onboardUri.ToString());
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ public class BringinService : EventHostedServiceBase
|
||||
private ConcurrentDictionary<string, BringinStoreSettings> _settings;
|
||||
private readonly AsyncKeyedLocker<string> _storeLocker = new();
|
||||
|
||||
public BringinService(EventAggregator eventAggregator, ILogger<BringinService> logger,
|
||||
public BringinService(EventAggregator eventAggregator,
|
||||
ILogger<BringinService> logger,
|
||||
StoreRepository storeRepository,
|
||||
PullPaymentHostedService pullPaymentHostedService,
|
||||
BTCPayNetworkJsonSerializerSettings btcPayNetworkJsonSerializerSettings,
|
||||
@@ -199,7 +200,9 @@ public class BringinService : EventHostedServiceBase
|
||||
|
||||
try
|
||||
{
|
||||
var bringinClient = bringinStoreSetting.CreateClient(_httpClientFactory);
|
||||
|
||||
var network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>("BTC");
|
||||
var bringinClient = bringinStoreSetting.CreateClient(_httpClientFactory,network.NBitcoinNetwork);
|
||||
|
||||
var thresholdAmount = methodSetting.Value.Threshold;
|
||||
if (methodSetting.Value.FiatThreshold)
|
||||
@@ -245,7 +248,8 @@ public class BringinService : EventHostedServiceBase
|
||||
|
||||
}
|
||||
var settings = _settings[storeId];
|
||||
var bringinClient = settings.CreateClient(_httpClientFactory);
|
||||
|
||||
var bringinClient = settings.CreateClient(_httpClientFactory, _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>(paymentMethodId.CryptoCode).NBitcoinNetwork);
|
||||
|
||||
|
||||
var host = await Dns.GetHostEntryAsync(Dns.GetHostName(), CancellationToken.None);
|
||||
@@ -462,9 +466,9 @@ public class BringinService : EventHostedServiceBase
|
||||
public List<string> PendingPayouts { get; set; } = new();
|
||||
}
|
||||
|
||||
public BringinClient CreateClient(IHttpClientFactory httpClientFactory)
|
||||
public BringinClient CreateClient(IHttpClientFactory httpClientFactory, Network network)
|
||||
{
|
||||
var httpClient = BringinClient.CreateClient(httpClientFactory, ApiKey);
|
||||
var httpClient = BringinClient.CreateClient(network, httpClientFactory, ApiKey);
|
||||
return new BringinClient(ApiKey, httpClient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,8 @@
|
||||
return;
|
||||
try
|
||||
{
|
||||
var userId = await _settings.CreateClient(HttpClientFactory).GetUserId();
|
||||
var network = BTCPayNetworkProvider.GetNetwork<BTCPayNetwork>("BTC");
|
||||
var userId = await _settings.CreateClient(HttpClientFactory, network.NBitcoinNetwork).GetUserId();
|
||||
ApiKeyError = string.IsNullOrEmpty(userId);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -182,7 +183,9 @@
|
||||
{
|
||||
if (_settings?.ApiKey is null || EditMode)
|
||||
return;
|
||||
var client = _settings.CreateClient(HttpClientFactory);
|
||||
|
||||
var network = BTCPayNetworkProvider.GetNetwork<BTCPayNetwork>("BTC");
|
||||
var client = _settings.CreateClient(HttpClientFactory, network.NBitcoinNetwork);
|
||||
LastFiatBalance = await client.GetFiatBalance();
|
||||
LastFiatRate = (await client.GetRate()).BringinPrice;
|
||||
LastDataFetch = DateTimeOffset.UtcNow;
|
||||
|
||||
Reference in New Issue
Block a user