Skip to content

Commit 474c71a

Browse files
committed
feat: new billing functions for referral customer
1 parent 50fbe12 commit 474c71a

18 files changed

+477
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
- Minimum .NET Framework is now v4.7.2
66
- Adds custom webhook headers when creating/updating a webhook
7+
- Adds the following functions to assist ReferralCustomer in adding credit cards and bank accounts:
8+
- `Beta.ReferralCustomer.CreateCreditCardClientSecret`
9+
- `Beta.ReferralCustomer.CreateBankAccountClientSecret`
10+
- `ReferralCustomer.AddCreditCardFromStripe`
11+
- `ReferralCustomer.AddBankAccountFromStripe`
712
- Adds `MerchantId` as Shipment option (closes #592)
813
- Remove previously-marked obsolete parameter, functions and classes:
914
- `EasyPost.Models.API.DeliveryDateForZipPairEstimate.EasyPostTimeInTransitData` property (use `EasyPost.Models.API.DeliveryDateForZipPairEstimate.TimeInTransitDetails` instead)

EasyPost.Tests/Fixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ internal static Dictionary<string, object> BasicPickup
107107

108108
internal static string ReportDate => "2022-04-12";
109109

110-
internal static string ReportIdPrefix => "shprep_";
111-
112110
internal static string ReportType => GetFixtureStructure().ReportTypes.Shipment;
113111

114112
internal static Dictionary<string, object> RmaFormOptions => GetFixtureStructure().FormOptions.Rma;
@@ -130,6 +128,8 @@ internal static string UspsCarrierAccountId
130128

131129
internal static string UspsService => GetFixtureStructure().ServiceNames.Usps.FirstService;
132130

131+
internal static Billing Billing => GetFixtureStructure().Billing;
132+
133133
private static FixtureStructure GetFixtureStructure()
134134
{
135135
string fixtureData = ReadFixtureData();

EasyPost.Tests/FixtureData.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class FixtureStructure
1313
[JsonProperty("addresses")]
1414
public Addresses Addresses { get; set; }
1515

16+
[JsonProperty("billing")]
17+
public Billing Billing { get; set; }
18+
1619
[JsonProperty("carrier_accounts")]
1720
public CarrierAccounts CarrierAccounts { get; set; }
1821

@@ -86,6 +89,25 @@ public class Addresses
8689
#endregion
8790
}
8891

92+
public class Billing
93+
{
94+
#region JSON Properties
95+
96+
[JsonProperty("payment_method_id")]
97+
public string PaymentMethodId { get; set; }
98+
99+
[JsonProperty("financial_connections_id")]
100+
public string FinancialConnectionsId { get; set; }
101+
102+
[JsonProperty("mandate_data")]
103+
public Dictionary<string, object> MandateData { get; set; }
104+
105+
[JsonProperty("priority")]
106+
public string Priority { get; set; }
107+
108+
#endregion
109+
}
110+
89111
public class CarrierAccounts
90112
{
91113
#region JSON Properties

EasyPost.Tests/ServicesTests/Beta/ReferralServiceTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ public async Task TestRefundByPaymentLog()
7979
}
8080
}
8181

82+
[Fact]
83+
[CrudOperations.Create]
84+
[Testing.Function]
85+
public async Task TestCreateCreditCardClientSecret()
86+
{
87+
UseVCR("create_credit_card_client_secret");
88+
89+
StripeClientSecret response = await Client.Beta.ReferralCustomer.CreateCreditCardClientSecret();
90+
91+
Assert.StartsWith("seti_", response.ClientSecret);
92+
}
93+
94+
[Fact]
95+
[CrudOperations.Create]
96+
[Testing.Function]
97+
public async Task TestCreateBankAccountClientSecret()
98+
{
99+
UseVCR("create_bank_account_client_secret");
100+
101+
StripeClientSecret response = await Client.Beta.ReferralCustomer.CreateBankAccountClientSecret();
102+
103+
Assert.StartsWith("fcsess_client_secret_", response.ClientSecret);
104+
}
105+
82106
#endregion
83107

84108
#endregion

EasyPost.Tests/ServicesTests/ReferralCustomerServiceTest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,46 @@ public async Task TestUpdateReferralEmail()
310310
Assert.Null(possibleException);
311311
}
312312

313+
[Fact]
314+
[Testing.Exception]
315+
public async Task TestAddCreditCardFromStripe()
316+
{
317+
UseVCR("add_credit_card_from_stripe");
318+
319+
NotFoundError exception = await Assert.ThrowsAsync<NotFoundError>(async () =>
320+
{
321+
await Client.ReferralCustomer.AddCreditCardFromStripe(
322+
ReferralCustomerKey,
323+
Fixtures.Billing.PaymentMethodId,
324+
PaymentMethod.Priority.Primary
325+
);
326+
});
327+
328+
Assert.Equal("Stripe::PaymentMethod does not exist for the specified reference_id", exception.Message);
329+
}
330+
331+
[Fact]
332+
[Testing.Exception]
333+
public async Task TestAddBankAccountFromStripe()
334+
{
335+
UseVCR("add_bank_account_from_stripe");
336+
337+
InvalidRequestError exception = await Assert.ThrowsAsync<InvalidRequestError>(async () =>
338+
{
339+
await Client.ReferralCustomer.AddBankAccountFromStripe(
340+
ReferralCustomerKey,
341+
Fixtures.Billing.FinancialConnectionsId,
342+
Fixtures.Billing.MandateData,
343+
PaymentMethod.Priority.Primary
344+
);
345+
});
346+
347+
Assert.Equal(
348+
"account_holder_name must be present when creating a Financial Connections payment method",
349+
exception.Message
350+
);
351+
}
352+
313353
#endregion
314354

315355
#endregion

EasyPost.Tests/ServicesTests/ReportServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public async Task TestCreate()
3333
});
3434

3535
Assert.IsType<Report>(report);
36-
Assert.StartsWith(Fixtures.ReportIdPrefix, report.Id);
36+
Assert.StartsWith("shprep_", report.Id);
3737
}
3838

3939
[Fact]

EasyPost.Tests/ServicesTests/WithParameters/ReportServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task TestCreate()
3838
Report report = await Client.Report.Create(parameters);
3939

4040
Assert.IsType<Report>(report);
41-
Assert.StartsWith(Fixtures.ReportIdPrefix, report.Id);
41+
Assert.StartsWith("shprep_", report.Id);
4242
}
4343

4444
[Fact]

EasyPost.Tests/cassettes/net/beta_referral_service/create_bank_account_client_secret.json

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EasyPost.Tests/cassettes/net/beta_referral_service/create_credit_card_client_secret.json

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EasyPost.Tests/cassettes/net/referral_customer_service/add_bank_account_from_stripe.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)