diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac3b892..5af478e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,7 @@ jobs: build-and-test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: dotnet-version: [ '6.0', '7.0', '8.0' ] @@ -16,7 +17,7 @@ jobs: with: dotnet-version: ${{ matrix.dotnet-version }} - name: Install dependencies - run: dotnet restore + run: dotnet restore -p:TargetFramework=net${{ matrix.dotnet-version }} - name: Build run: dotnet build --no-restore -f net${{ matrix.dotnet-version }} - name: Test diff --git a/BitPay/Client.cs b/BitPay/Client.cs index a9f46d6..3d44734 100644 --- a/BitPay/Client.cs +++ b/BitPay/Client.cs @@ -316,11 +316,15 @@ public async Task CancelInvoiceByGuid(string refundGuid) /// Request a webhook to be resent. /// /// Invoice ID. + /// + /// The resource token for the invoiceId. + /// This token can be retrieved from the Bitpay's invoice object. + /// /// Status of request /// - public async Task RequestInvoiceWebhookToBeResent(string invoiceId) + public async Task RequestInvoiceWebhookToBeResent(string invoiceId, string invoiceToken) { - return await CreateInvoiceClient().RequestInvoiceWebhookToBeResent(invoiceId).ConfigureAwait(false); + return await CreateInvoiceClient().RequestInvoiceWebhookToBeResent(invoiceId, invoiceToken).ConfigureAwait(false); } /// @@ -420,12 +424,16 @@ public async Task UpdateRefundByGuid(string refundGuid, string status) /// Send a refund notification /// /// A BitPay refundId + /// + /// The resource token for the refundId. + /// This token can be retrieved from the Bitpay's refund object. + /// /// An updated Refund Object /// RefundCreationException RefundCreationException class /// BitPayException BitPayException class - public async Task SendRefundNotification(string refundId) + public async Task SendRefundNotification(string refundId, string refundToken) { - return await CreateRefundClient().SendRefundNotification(refundId).ConfigureAwait(false); + return await CreateRefundClient().SendRefundNotification(refundId, refundToken).ConfigureAwait(false); } /// diff --git a/BitPay/Clients/InvoiceClient.cs b/BitPay/Clients/InvoiceClient.cs index 1c7bf95..59d9cf4 100644 --- a/BitPay/Clients/InvoiceClient.cs +++ b/BitPay/Clients/InvoiceClient.cs @@ -310,13 +310,17 @@ public async Task CancelInvoiceByGuid(string guidId, bool forceCancel = /// Request a webhook to be resent. /// /// Invoice ID. + /// + /// The resource token for the invoiceId. + /// This token can be retrieved from the Bitpay's invoice object. + /// /// Status of request /// BitPayGenericException class /// BitPayApiException class - public async Task RequestInvoiceWebhookToBeResent(string invoiceId) + public async Task RequestInvoiceWebhookToBeResent(string invoiceId, string invoiceToken) { var parameters = ResourceClientUtil.InitParams(); - parameters.Add("token", _accessTokens.GetAccessToken((Facade.Merchant))); + parameters.Add("token", invoiceToken); string json = null!; @@ -407,4 +411,4 @@ public async Task PayInvoice(string invoiceId, string status) return invoice; } } -} \ No newline at end of file +} diff --git a/BitPay/Clients/RefundClient.cs b/BitPay/Clients/RefundClient.cs index a6abbed..8ffcb09 100644 --- a/BitPay/Clients/RefundClient.cs +++ b/BitPay/Clients/RefundClient.cs @@ -302,13 +302,17 @@ public async Task CancelByGuid(string refundGuid) /// Send a refund notification /// /// A BitPay refundId + /// + /// The resource token for the refundId. + /// This token can be retrieved from the Bitpay's refund object. + /// /// An updated Refund Object /// BitPayGenericException class /// BitPayApiException class - public async Task SendRefundNotification(string refundId) + public async Task SendRefundNotification(string refundId, string refundToken) { var parameters = ResourceClientUtil.InitParams(); - parameters.Add("token", _accessTokens.GetAccessToken(Facade.Merchant)); + parameters.Add("token", refundToken); string json; @@ -342,4 +346,4 @@ public async Task SendRefundNotification(string refundId) } } } -} \ No newline at end of file +} diff --git a/BitPay/Exceptions/BitPayApiException.cs b/BitPay/Exceptions/BitPayApiException.cs index 67233ea..0b09626 100644 --- a/BitPay/Exceptions/BitPayApiException.cs +++ b/BitPay/Exceptions/BitPayApiException.cs @@ -30,5 +30,9 @@ public string? Code return _code; } } + + protected BitPayApiException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } -} \ No newline at end of file +} diff --git a/BitPay/Exceptions/BitPayException.cs b/BitPay/Exceptions/BitPayException.cs index a05c55f..5ef4976 100644 --- a/BitPay/Exceptions/BitPayException.cs +++ b/BitPay/Exceptions/BitPayException.cs @@ -15,5 +15,9 @@ public class BitPayException : Exception public BitPayException(string message) : base(message) { } + + protected BitPayException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } -} \ No newline at end of file +} diff --git a/BitPay/Exceptions/BitPayGenericException.cs b/BitPay/Exceptions/BitPayGenericException.cs index f5e65c6..2a048af 100644 --- a/BitPay/Exceptions/BitPayGenericException.cs +++ b/BitPay/Exceptions/BitPayGenericException.cs @@ -15,5 +15,9 @@ public class BitPayGenericException : BitPayException public BitPayGenericException(string message) : base(message) { } + + protected BitPayGenericException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } -} \ No newline at end of file +} diff --git a/BitPay/Exceptions/BitPayValidationException.cs b/BitPay/Exceptions/BitPayValidationException.cs index 7c3913e..34cfd7f 100644 --- a/BitPay/Exceptions/BitPayValidationException.cs +++ b/BitPay/Exceptions/BitPayValidationException.cs @@ -15,5 +15,9 @@ public class BitPayValidationException : BitPayGenericException public BitPayValidationException(string message) : base(message) { } + + protected BitPayValidationException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } -} \ No newline at end of file +} diff --git a/BitPay/Models/Invoice/RecipientStatus.cs b/BitPay/Models/Invoice/RecipientStatus.cs index 534b57c..2a0c6c3 100644 --- a/BitPay/Models/Invoice/RecipientStatus.cs +++ b/BitPay/Models/Invoice/RecipientStatus.cs @@ -3,7 +3,7 @@ namespace BitPay.Models.Invoice { - public class RecipientStatus + public static class RecipientStatus { public const string Active = "active"; public const string Invited = "invited"; @@ -12,4 +12,4 @@ public class RecipientStatus public const string Unverified = "unverified"; public const string Verified = "verified"; } -} \ No newline at end of file +} diff --git a/BitPay/Models/Invoice/Refund.cs b/BitPay/Models/Invoice/Refund.cs index 3ef396d..e81d444 100644 --- a/BitPay/Models/Invoice/Refund.cs +++ b/BitPay/Models/Invoice/Refund.cs @@ -27,6 +27,9 @@ public class Refund [JsonProperty(PropertyName = "guid")] public string? ResourceGuid { get; set; } + [JsonProperty(PropertyName = "token")] + public string? Token { get; set; } + [JsonProperty(PropertyName = "refundAddress")] public string? RefundAddress { get; set; } diff --git a/BitPayFunctionalTest/BitPayFunctionalTest.cs b/BitPayFunctionalTest/BitPayFunctionalTest.cs index d79cb06..cabf93c 100644 --- a/BitPayFunctionalTest/BitPayFunctionalTest.cs +++ b/BitPayFunctionalTest/BitPayFunctionalTest.cs @@ -146,6 +146,7 @@ public async Task it_should_test_refunds_requests() var refundToCreateRequest = new Refund(invoiceId: invoiceId, amount: 10.0M); var refund = await _client.CreateRefund(refundToCreateRequest); var refundId = refund.Id!; + var refundToken = refund.Token!; var retrieveRefund = await _client.GetRefund(refundId); Assert.Equal(refundId, retrieveRefund.Id); @@ -158,7 +159,7 @@ public async Task it_should_test_refunds_requests() Assert.NotEmpty(retrieveRefundByInvoiceId); retrieveRefundByInvoiceId.Exists(refundByInvoice => refundByInvoice.Invoice == invoiceId); - var refundNotification = await _client.SendRefundNotification(refundId); + var refundNotification = await _client.SendRefundNotification(refundId, refundToken); Assert.True(refundNotification); var cancelRefund = await _client.CancelRefund(refundId); @@ -480,4 +481,4 @@ private static string GetBitPayUnitTestPath() return bitPayUnitTestPath; } } -} \ No newline at end of file +} diff --git a/BitPayUnitTest/ClientTest.cs b/BitPayUnitTest/ClientTest.cs index 82bac98..27c56e6 100644 --- a/BitPayUnitTest/ClientTest.cs +++ b/BitPayUnitTest/ClientTest.cs @@ -7,6 +7,7 @@ using BitPay; using BitPay.Clients; using BitPay.Exceptions; +using BitPay.Models; using BitPay.Models.Bill; using BitPay.Models.Invoice; using BitPay.Models.Payout; @@ -14,6 +15,8 @@ using Moq; +using Newtonsoft.Json; + using Environment = BitPay.Environment; using SystemEnvironment = System.Environment; @@ -826,11 +829,15 @@ public void it_should_cancel_invoice_by_guid() [Fact] public void it_should_request_invoice_webhook_to_be_resent() { + var invoiceToken = "cM78LHk17Q8fktDE6QLBBFfvH1QKBhRkHibTLcxhgzsu3VDRvSyu3CGi17DuwYxhT";var responseObject = new + { + token = invoiceToken + }; // given HttpContent response = new StringContent(File.ReadAllText(GetJsonResponsePath() + "invoiceWebhookResponse.json")); _bitPayClient.Setup(b => b.Post( "invoices/Hpqc63wvE1ZjzeeH4kEycF/notifications", - "{\"token\":\"merchantToken\"}", + JsonConvert.SerializeObject(responseObject), false )).ReturnsAsync(new HttpResponseMessage { @@ -841,7 +848,7 @@ public void it_should_request_invoice_webhook_to_be_resent() }); // when - var result = GetTestedClassAsMerchant().RequestInvoiceWebhookToBeResent("Hpqc63wvE1ZjzeeH4kEycF").Result; + var result = GetTestedClassAsMerchant().RequestInvoiceWebhookToBeResent("Hpqc63wvE1ZjzeeH4kEycF", invoiceToken).Result; // then Assert.True(result); @@ -1665,11 +1672,16 @@ public void it_should_update_refund_by_guid() [Fact] public void it_should_send_refund_notification() { + var refundToken = "cM78LHk17Q8fktDE6QLBBFfvH1QKBhRkHibTLcxhgzsu3VDRvSyu3CGi17DuwYxhT"; + var responseObject = new + { + token = refundToken + }; // given HttpContent response = new StringContent(File.ReadAllText(GetJsonResponsePath() + "sendRefundNotificationResponse.json")); _bitPayClient.Setup(b => b.Post( "refunds/WoE46gSLkJQS48RJEiNw3L/notifications", - "{\"token\":\"merchantToken\"}", + JsonConvert.SerializeObject(responseObject), true )).ReturnsAsync(new HttpResponseMessage { @@ -1679,7 +1691,7 @@ public void it_should_send_refund_notification() }); // when - var result = GetTestedClassAsMerchant().SendRefundNotification("WoE46gSLkJQS48RJEiNw3L").Result; + var result = GetTestedClassAsMerchant().SendRefundNotification("WoE46gSLkJQS48RJEiNw3L", refundToken).Result; // then Assert.True(result);