1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

switch to official bitpay light library

This commit is contained in:
Kyle Spearrin
2019-12-19 10:27:06 -05:00
parent 665e78ec1c
commit e2d65e5b08
6 changed files with 27 additions and 33 deletions

View File

@ -23,6 +23,7 @@
<ItemGroup>
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.3.101.38" />
<PackageReference Include="AWSSDK.SQS" Version="3.3.102" />
<PackageReference Include="BitPay.Light" Version="1.0.1907" />
<PackageReference Include="Handlebars.Net" Version="1.10.1" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.7.0" />
<PackageReference Include="MailKit" Version="2.3.0" />
@ -37,7 +38,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.2.0" />
<PackageReference Include="NBitpayClient" Version="1.0.0.34" />
<PackageReference Include="Npgsql" Version="4.0.9" />
<PackageReference Include="Quartz" Version="3.0.7" />
<PackageReference Include="Serilog.AspNetCore" Version="3.0.0" />

View File

@ -197,7 +197,7 @@ namespace Bit.Core
public class BitPaySettings
{
public bool Production { get; set; }
public string Base58Secret { get; set; }
public string Token { get; set; }
public string NotificationUrl { get; set; }
}

View File

@ -15,20 +15,19 @@ namespace Bit.Core.Models.Api
public string Name { get; set; }
public string Email { get; set; }
public NBitpayClient.Invoice ToBitpayClientInvoice(GlobalSettings globalSettings)
public BitPayLight.Models.Invoice.Invoice ToBitpayInvoice(GlobalSettings globalSettings)
{
var inv = new NBitpayClient.Invoice
var inv = new BitPayLight.Models.Invoice.Invoice
{
Price = Amount.Value,
Price = Convert.ToDouble(Amount.Value),
Currency = "USD",
RedirectURL = ReturnUrl,
BuyerEmail = Email,
Buyer = new NBitpayClient.Buyer
RedirectUrl = ReturnUrl,
Buyer = new BitPayLight.Models.Invoice.Buyer
{
email = Email,
Email = Email,
Name = Name
},
NotificationURL = globalSettings.BitPay.NotificationUrl,
NotificationUrl = globalSettings.BitPay.NotificationUrl,
FullNotifications = true,
ExtendedNotifications = true
};

View File

@ -5,32 +5,25 @@ namespace Bit.Core.Utilities
{
public class BitPayClient
{
private readonly NBitpayClient.Bitpay _bpClient;
private readonly BitPayLight.BitPay _bpClient;
public BitPayClient(GlobalSettings globalSettings)
{
if(CoreHelpers.SettingHasValue(globalSettings.BitPay.Base58Secret))
if(CoreHelpers.SettingHasValue(globalSettings.BitPay.Token))
{
var btcSecret = new NBitcoin.BitcoinSecret(globalSettings.BitPay.Base58Secret,
globalSettings.BitPay.Production ? null : NBitcoin.Network.TestNet);
_bpClient = new NBitpayClient.Bitpay(btcSecret.PrivateKey,
new Uri(globalSettings.BitPay.Production ? "https://bitpay.com/" : "https://test.bitpay.com/"));
_bpClient = new BitPayLight.BitPay(globalSettings.BitPay.Token,
globalSettings.BitPay.Production ? BitPayLight.Env.Prod : BitPayLight.Env.Test);
}
}
public Task<bool> TestAccessAsync()
public Task<BitPayLight.Models.Invoice.Invoice> GetInvoiceAsync(string id)
{
return _bpClient.TestAccessAsync(NBitpayClient.Facade.Merchant);
return _bpClient.GetInvoice(id);
}
public Task<NBitpayClient.Invoice> GetInvoiceAsync(string id)
public Task<BitPayLight.Models.Invoice.Invoice> CreateInvoiceAsync(BitPayLight.Models.Invoice.Invoice invoice)
{
return _bpClient.GetInvoiceAsync(id);
}
public Task<NBitpayClient.Invoice> CreateInvoiceAsync(NBitpayClient.Invoice invoice)
{
return _bpClient.CreateInvoiceAsync(invoice);
return _bpClient.CreateInvoice(invoice);
}
}
}