Skip to content

Commit

Permalink
#v3.3.2003.0-rc - Mayor security updates (#70)
Browse files Browse the repository at this point in the history
- Sub-version upgrade
- Invoice properties deprecation
- Facade POS removed
- API frame headers added
- Tests updated
- Assembly added
  • Loading branch information
Antonio Buedo committed Mar 24, 2020
1 parent c4b0e35 commit 0eca079
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 111 deletions.
Binary file added Assemblies/BitPay.Net.Lib_3.3.2003.zip
Binary file not shown.
106 changes: 71 additions & 35 deletions BitPay/BitPay.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions BitPay/BitPay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<TargetFrameworks>net452;net46;net461;net462;net47;net471;net472;netstandard2.0;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2</TargetFrameworks>
<LangVersion>latest</LangVersion>
<!-- version numbers will be updated by build -->
<AssemblyVersion>3.2.2001.0</AssemblyVersion>
<FileVersion>3.2.2001</FileVersion>
<VersionPrefix>3.2.2001</VersionPrefix>
<Version>3.2.2001</Version>
<AssemblyVersion>3.3.2003.0</AssemblyVersion>
<FileVersion>3.3.2003</FileVersion>
<VersionPrefix>3.3.2003</VersionPrefix>
<Version>3.3.2003</Version>
<Authors>Antonio Buedo</Authors>
<Company>BitPay Inc.</Company>
<Owners>BitPay, Inc.</Owners>
Expand Down
5 changes: 3 additions & 2 deletions BitPay/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ public class Env
public const string TestUrl = "https://test.bitpay.com/";
public const string ProdUrl = "https://bitpay.com/";
public const string BitpayApiVersion = "2.0.0";
public const string BitpayPluginInfo = "BitPay_DotNet_Client_v3.2.2001";
public const string BitpayPluginInfo = "BitPay_DotNet_Client_v3.3.2003";
public const string BitpayApiFrame = "custom";
public const string BitpayApiFrameVersion = "1.0.0";
public class Tokens
{
public string POS { get; set; }
public string Merchant { get; set; }
public string Payout { get; set; }
}
Expand Down
1 change: 0 additions & 1 deletion BitPay/Facades.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace BitPaySDK
{
public static class Facade
{
public const string PointOfSale = "pos";
public const string Merchant = "merchant";
public const string Payroll = "payroll";
}
Expand Down
100 changes: 67 additions & 33 deletions BitPay/Models/Invoice/Invoice.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using BitPaySDK.Exceptions;
using Newtonsoft.Json;

Expand Down Expand Up @@ -27,17 +28,14 @@ public Invoice(double price, string currency)
// API fields
//

[JsonProperty(PropertyName = "guid")]
public string Guid { get; set; }
[JsonProperty(PropertyName = "guid")] public string Guid { get; set; }

[JsonProperty(PropertyName = "token")]
public string Token { get; set; }
[JsonProperty(PropertyName = "token")] public string Token { get; set; }

// Required fields
//

[JsonProperty(PropertyName = "price")]
public double Price { get; set; }
[JsonProperty(PropertyName = "price")] public double Price { get; set; }

[JsonProperty(PropertyName = "currency")]
public string Currency
Expand Down Expand Up @@ -93,12 +91,11 @@ public string Currency

[JsonProperty(PropertyName = "acceptanceWindow")]
public long AcceptanceWindow { get; set; }

// Buyer data
//

[JsonProperty(PropertyName = "buyer")]
public Buyer Buyer { get; set; }
[JsonProperty(PropertyName = "buyer")] public Buyer Buyer { get; set; }

// Response fields
//
Expand All @@ -108,57 +105,94 @@ public string Currency
public string Url { get; set; }

public string Status { get; set; }

public string LowFeeDetected { get; set; }

public long InvoiceTime { get; set; }

public long ExpirationTime { get; set; }

public long CurrentTime { get; set; }

public int TargetConfirmations { get; set; }

public List<InvoiceTransaction> Transactions { get; set; }

public string ExceptionStatus { get; set; }

public dynamic RefundAddresses {

public dynamic RefundAddresses
{
get => _refundAddresses;
set => _refundAddresses = JsonConvert.DeserializeObject(value.ToString(Formatting.None));
}

public string RefundAddressRequestPending { get; set; }

public string BuyerProvidedEmail { get; set; }

public InvoiceBuyerProvidedInfo BuyerProvidedInfo { get; set; }

public SupportedTransactionCurrencies SupportedTransactionCurrencies { get; set; }

public Shopper Shopper { get; set; }

public MinerFees MinerFees { get; set; }

public string TransactionCurrency { get; set; }

public string BillId { get; set; }

public RefundInfo RefundInfo { get; set; }

public PaymentCodes PaymentCodes { get; set; }
private PaymentCodes _paymentCodes = null; //TODO remove on version 4.0

[Obsolete("PaymentCodes will be deprecated on version 4.0", false)]
public PaymentCodes PaymentCodes
{
get => _paymentCodes;
set => _paymentCodes = null;
}

private PaymentTotal _paymentSubtotals = null; //TODO remove on version 4.0

[Obsolete("PaymentSubtotals will be deprecated on version 4.0", false)]
public PaymentTotal PaymentSubtotals
{
get => _paymentSubtotals;
set => _paymentSubtotals = null;
}

private PaymentTotal _paymentTotals = null; //TODO remove on version 4.0

public PaymentTotal PaymentSubtotals { get; set; }
[Obsolete("PaymentTotals will be deprecated on version 4.0", false)]
public PaymentTotal PaymentTotals
{
get => _paymentTotals;
set => _paymentTotals = null;
}

public PaymentTotal PaymentTotals { get; set; }
private PaymentTotal _paymentDisplayTotals = null; //TODO remove on version 4.0

public PaymentTotal PaymentDisplayTotals { get; set; }
[Obsolete("PaymentDisplayTotals will be deprecated on version 4.0", false)]
public PaymentTotal PaymentDisplayTotals
{
get => _paymentDisplayTotals;
set => _paymentDisplayTotals = null;
}

public PaymentTotal PaymentDisplaySubTotals { get; set; }
private PaymentTotal _paymentDisplaySubTotals = null; //TODO remove on version 4.0

[Obsolete("PaymentDisplaySubTotals will be deprecated on version 4.0", false)]
public PaymentTotal PaymentDisplaySubTotals
{
get => _paymentDisplaySubTotals;
set => _paymentDisplaySubTotals = null;
}

public double AmountPaid { get; set; }

public dynamic ExchangeRates {
public dynamic ExchangeRates
{
get => _exchangeRates;
set => _exchangeRates = JsonConvert.DeserializeObject(value.ToString(Formatting.None));
}
Expand Down Expand Up @@ -222,7 +256,7 @@ public bool ShouldSerializePaymentCurrencies()
{
return (PaymentCurrencies != null);
}

public bool ShouldSerializeBuyer()
{
return (Buyer != null);
Expand Down Expand Up @@ -312,7 +346,7 @@ public bool ShouldSerializeMinerFees()
{
return false;
}

public bool ShouldSerializeTransactionCurrency()
{
return !string.IsNullOrEmpty(TransactionCurrency);
Expand All @@ -333,6 +367,11 @@ public bool ShouldSerializePaymentCodes()
return false;
}

public bool ShouldIgnorePaymentCodes()
{
return true;
}

public bool ShouldSerializeTargetConfirmations()
{
return false;
Expand Down Expand Up @@ -367,10 +406,5 @@ public bool ShouldSerializeBuyerProvidedInfo()
{
return false;
}

public bool ShouldSerializeFlags()
{
return false;
}
}
}
5 changes: 4 additions & 1 deletion BitPay/Models/Invoice/PaymentCode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace BitPaySDK.Models.Invoice
using System;

namespace BitPaySDK.Models.Invoice
{
[Obsolete("PaymentCode will be deprecated on version 4.0", false)] //TODO remove on version 4.0
public class PaymentCode
{
public string Bip72b { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion BitPay/Models/Invoice/PaymentCodes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace BitPaySDK.Models.Invoice
using System;

namespace BitPaySDK.Models.Invoice
{
[Obsolete("PaymentCodes will be deprecated on version 4.0", false)] //TODO remove on version 4.0
public class PaymentCodes
{
public PaymentCode Btc { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion BitPay/Models/Invoice/PaymentTotal.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace BitPaySDK.Models.Invoice
using System;

namespace BitPaySDK.Models.Invoice
{
[Obsolete("PaymentTotal will be deprecated on version 4.0", false)] //TODO remove on version 4.0
public class PaymentTotal
{
public double Btc { get; set; }
Expand Down
14 changes: 0 additions & 14 deletions BitPayUnitTest/BitPayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ public class BitPayTest {
// Initialize the BitPay object to be used in the following tests
_bitpay = new BitPay(configuration);

// If the client doesn't have a POS token yet, fetch one.
// For the Merchant and Payroll Facades, see below, in their corresponding tests
if (!_bitpay.tokenExist(Facade.PointOfSale)) {
_bitpay.AuthorizeClient(PairingCode);
}

// ledgers require the Merchant Facade
if (!_bitpay.tokenExist(Facade.Merchant)) {
// get a pairing code for the merchant facade for this client
Expand Down Expand Up @@ -112,14 +106,6 @@ public class BitPayTest {
Assert.AreEqual(InvoiceStatus.New, basicInvoice.Status, "Status is incorrect");
}

[TestMethod]
public async Task TestShouldGetInvoiceBtcPrice() {
// create an invoice and make sure we receive values for the Bitcoin Cash and Bitcoin fields, respectively
var basicInvoice = await _bitpay.CreateInvoice(new Invoice(10.0, Currency.USD));
Assert.IsNotNull(basicInvoice.PaymentSubtotals.Btc, "Invoice created with PaymentSubtotals.Btc=NULL");
Assert.IsNotNull(basicInvoice.PaymentSubtotals.Bch, "Invoice created with PaymentSubtotals.Bch=NULL");
}

[TestMethod]
public async Task TestShouldCreateInvoiceOneTenthBtc() {
// create an invoice and make sure we receive the correct price value back (under 1 BTC)
Expand Down
22 changes: 3 additions & 19 deletions BitPayXUnitTest/BitPayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Tests()
{
// JSON minified with the BitPay configuration as in the required configuration file
// and parsed into a IConfiguration object
var json = "{\"BitPayConfiguration\":{\"Environment\":\"Test\",\"EnvConfig\":{\"Test\":{\"ClientDescription\":\"Net_test\",\"ApiUrl\":\"https://test.bitpay.com/\",\"ApiVersion\":\"2.0.0\",\"PrivateKeyPath\":\"bitpay_private_test.key\",\"ApiTokens\":{\"pos\":\"AvJdGrEqTW9HVsJit9zabAnrJabqaQDhWHRacHYgfgxK\",\"merchant\":\"CE2WRSEEt9FgXvXboxNFA4YdQyyDJmgVAo752TGA7eUj\",\"payroll\":\"9pJ7fzW1GGeuDQfj32aNATCDnyY6YAacVMcDrs7HHUNo\"}},\"Prod\":{\"ClientDescription\":\"\",\"ApiUrl\":\"https://bitpay.com/\",\"ApiVersion\":\"2.0.0\",\"PrivateKeyPath\":\"\",\"ApiTokens\":{\"pos\":\"\",\"merchant\":\"\",\"payroll\":\"\"}}}}}";
var json = "{\"BitPayConfiguration\":{\"Environment\":\"Test\",\"EnvConfig\":{\"Test\":{\"PrivateKeyPath\":\"bitpay_private_test.key\",\"ApiTokens\":{\"merchant\":\"CE2WRSEEt9FgXvXboxNFA4YdQyyDJmgVAo752TGA7eUj\",\"payroll\":\"9pJ7fzW1GGeuDQfj32aNATCDnyY6YAacVMcDrs7HHUNo\"}},\"Prod\":{\"PrivateKeyPath\":\"\",\"ApiTokens\":{\"merchant\":\"\",\"payroll\":\"\"}}}}}";
var memoryJsonFile = new MemoryFileInfo("config.json", Encoding.UTF8.GetBytes(json), DateTimeOffset.Now);
var memoryFileProvider = new MockFileProvider(memoryJsonFile);

Expand All @@ -52,25 +52,18 @@ public Tests()

// Initialize the BitPay object to be used in the following tests
// Initialize with IConfiguration object
// _bitpay = new BitPay(configuration);
_bitpay = new BitPay(configuration);

// Initialize with separate variables
_bitpay = new BitPay(
Env.Test,
"bitpay_private_test.key",
new Env.Tokens(){
POS = "AvJdGrEqTW9HVsJit9zabAnrJabqaQDhWHRacHYgfgxK",
Merchant = "CE2WRSEEt9FgXvXboxNFA4YdQyyDJmgVAo752TGA7eUj",
Payout = "9pJ7fzW1GGeuDQfj32aNATCDnyY6YAacVMcDrs7HHUNo"
}
);

// If the client doesn't have a POS token yet, fetch one.
// For the Merchant and Payroll Facades, see below, in their corresponding tests
if (!_bitpay.tokenExist(Facade.PointOfSale)) {
_bitpay.AuthorizeClient(PairingCode);
}

// ledgers require the Merchant Facade
if (!_bitpay.tokenExist(Facade.Merchant)) {
// get a pairing code for the merchant facade for this client
Expand Down Expand Up @@ -104,7 +97,7 @@ public Tests()
public async Task TestShouldGetInvoiceId()
{
// create an invoice and make sure we receive an id - which means it has been successfully submitted
var invoice = new Invoice(30.0, Currency.EUR);
var invoice = new Invoice(30.0, Currency.USD);
var basicInvoice = await _bitpay.CreateInvoice(invoice);
Assert.NotNull(basicInvoice.Id);
}
Expand Down Expand Up @@ -156,15 +149,6 @@ public async Task testShouldCreateInvoiceETH()
Assert.Equal(InvoiceStatus.New, basicInvoice.Status);
}

[Fact]
public async Task TestShouldGetInvoiceBtcPrice() {
// create an invoice and make sure we receive values for the Bitcoin Cash and Bitcoin fields, respectively
var basicInvoice = await _bitpay.CreateInvoice(new Invoice(10.0, Currency.USD));
Assert.NotNull(basicInvoice.PaymentSubtotals.Btc);
Assert.NotNull(basicInvoice.PaymentSubtotals.Bch);
Assert.NotNull(basicInvoice.PaymentSubtotals.Eth);
}

[Fact]
public async Task TestShouldCreateInvoiceOneTenthBtc() {
// create an invoice and make sure we receive the correct price value back (under 1 BTC)
Expand Down

0 comments on commit 0eca079

Please sign in to comment.