2019-02-21 22:43:37 -05:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Utilities
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BitPayClient
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly NBitpayClient.Bitpay _bpClient;
|
|
|
|
|
|
|
|
|
|
|
|
public BitPayClient(GlobalSettings globalSettings)
|
|
|
|
|
|
{
|
2019-03-19 23:32:54 -04:00
|
|
|
|
if(CoreHelpers.SettingHasValue(globalSettings.BitPay.Base58Secret))
|
|
|
|
|
|
{
|
|
|
|
|
|
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/"));
|
|
|
|
|
|
}
|
2019-02-21 22:43:37 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> TestAccessAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _bpClient.TestAccessAsync(NBitpayClient.Facade.Merchant);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<NBitpayClient.Invoice> GetInvoiceAsync(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _bpClient.GetInvoiceAsync(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<NBitpayClient.Invoice> CreateInvoiceAsync(NBitpayClient.Invoice invoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _bpClient.CreateInvoiceAsync(invoice);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|