|
| 1 | +using System.Threading.Tasks; |
| 2 | +using EasyPost.Exceptions.API; |
| 3 | +using EasyPost.Models.API; |
| 4 | +using EasyPost.Models.API.Beta; |
| 5 | +using EasyPost.Tests._Utilities; |
| 6 | +using EasyPost.Tests._Utilities.Attributes; |
| 7 | +using EasyPost.Utilities.Internal.Attributes; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace EasyPost.Tests.BetaFeaturesTests.ServicesTests.Beta |
| 11 | +{ |
| 12 | + public class ReferralServiceTests : UnitTest |
| 13 | + { |
| 14 | + public ReferralServiceTests() : base("beta_referral_service_with_parameters", TestUtils.ApiKey.Referral) |
| 15 | + { |
| 16 | + } |
| 17 | + |
| 18 | + #region Tests |
| 19 | + |
| 20 | + #region Test CRUD Operations |
| 21 | + |
| 22 | + [Fact] |
| 23 | + [CrudOperations.Create] |
| 24 | + [Testing.Function] |
| 25 | + public async Task TestAddPaymentMethod() |
| 26 | + { |
| 27 | + UseVCR("add_payment_method"); |
| 28 | + |
| 29 | + try |
| 30 | + { |
| 31 | + BetaFeatures.Parameters.ReferralCustomers.AddPaymentMethod parameters = new() |
| 32 | + { |
| 33 | + StripeCustomerId = "cus_123", |
| 34 | + PaymentMethodReference = "ba_123", |
| 35 | + }; |
| 36 | + |
| 37 | + PaymentMethod _ = await Client.Beta.Referral.AddPaymentMethod(parameters); |
| 38 | + } |
| 39 | + catch (InvalidRequestError e) |
| 40 | + { |
| 41 | + // the data we're sending is invalid, we expect an error to be thrown |
| 42 | + Assert.Equal(422, e.StatusCode); |
| 43 | + Assert.Equal("BILLING.INVALID_PAYMENT_GATEWAY_REFERENCE", e.Code); |
| 44 | + Assert.Equal("Invalid Payment Gateway Reference.", e.Message); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + [CrudOperations.Update] |
| 50 | + [Testing.Function] |
| 51 | + public async Task TestRefundByAmount() |
| 52 | + { |
| 53 | + UseVCR("refund_by_amount"); |
| 54 | + |
| 55 | + try |
| 56 | + { |
| 57 | + BetaFeatures.Parameters.ReferralCustomers.RefundByAmount parameters = new() |
| 58 | + { |
| 59 | + Amount = 2000, |
| 60 | + }; |
| 61 | + |
| 62 | + PaymentRefund _ = await Client.Beta.Referral.RefundByAmount(parameters); |
| 63 | + } |
| 64 | + catch (InvalidRequestError e) |
| 65 | + { |
| 66 | + // the data we're sending is invalid, we expect an error to be thrown |
| 67 | + Assert.Equal(422, e.StatusCode); |
| 68 | + Assert.Equal("TRANSACTION.AMOUNT_INVALID", e.Code); |
| 69 | + Assert.Equal("Refund amount is invalid. Please use a valid amount or escalate to finance.", e.Message); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + [Fact] |
| 74 | + [CrudOperations.Update] |
| 75 | + [Testing.Function] |
| 76 | + public async Task TestRefundByPaymentLog() |
| 77 | + { |
| 78 | + UseVCR("refund_by_payment_log"); |
| 79 | + |
| 80 | + try |
| 81 | + { |
| 82 | + BetaFeatures.Parameters.ReferralCustomers.RefundByPaymentLog parameters = new() |
| 83 | + { |
| 84 | + PaymentLogId = "paylog_123", |
| 85 | + }; |
| 86 | + |
| 87 | + PaymentRefund _ = await Client.Beta.Referral.RefundByPaymentLog(parameters); |
| 88 | + } |
| 89 | + catch (InvalidRequestError e) |
| 90 | + { |
| 91 | + // the data we're sending is invalid, we expect an error to be thrown |
| 92 | + Assert.Equal(422, e.StatusCode); |
| 93 | + Assert.Equal("TRANSACTION.DOES_NOT_EXIST", e.Code); |
| 94 | + Assert.Equal("We could not find a transaction with that id.", e.Message); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + #endregion |
| 99 | + |
| 100 | + #endregion |
| 101 | + } |
| 102 | +} |
0 commit comments