Skip to content

Commit e8039c5

Browse files
authored
Merge pull request #615 from EasyPost/amazon_account
feat: route Amazon account to correct endpoint
2 parents 772808f + 7bdb546 commit e8039c5

File tree

8 files changed

+222
-2
lines changed

8 files changed

+222
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `ReferralCustomer.AddCreditCardFromStripe`
1111
- `ReferralCustomer.AddBankAccountFromStripe`
1212
- Adds `MerchantId` as Shipment option (closes #592)
13+
- Routes `AmazonShippingAccount` to the correct endpoint on create
1314
- Fixes error parsing
1415
- Allows for alternative format of `errors` field (previously we deserialized the `errors` field into a list of `Error` objects; however, sometimes the errors are simply a list of strings. This change make the `errors` field a list of `objects` allowing for either the new `FieldError` object or a list of strings. Users will need to check for the type of error returned and handle appropriately)
1516
- Removed the unused `Error` model

EasyPost.Integration/Basics.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public void UserCanConstructParameterSets()
108108
var carrierAccountCreateFedExParameters = new EasyPost.Parameters.CarrierAccount.CreateFedEx();
109109
var carrierAccountCreateFedExSmartPostParameters = new EasyPost.Parameters.CarrierAccount.CreateFedExSmartPost();
110110
var carrierAccountCreateUpsParameters = new EasyPost.Parameters.CarrierAccount.CreateUps();
111+
var carrierAccountCreateOauthParameters = new EasyPost.Parameters.CarrierAccount.CreateOauth();
111112
var carrierAccountUpdateParameters = new EasyPost.Parameters.CarrierAccount.Update();
112113
var carrierMetadataRetrieveParameters = new EasyPost.Parameters.CarrierMetadata.Retrieve();
113114
var claimCreateParameters = new EasyPost.Parameters.Claim.Create();

EasyPost.Tests/ServicesTests/CarrierAccountServiceTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public async Task TestCreate()
4747

4848
Assert.IsType<CarrierAccount>(carrierAccount);
4949
Assert.StartsWith("ca_", carrierAccount.Id);
50+
Assert.Equal("DhlEcsAccount", carrierAccount.Type);
5051
}
5152

5253
[Fact]
@@ -73,6 +74,26 @@ public async Task TestCreateWithCustomWorkflow()
7374
}
7475
}
7576

77+
[Fact]
78+
[CrudOperations.Create]
79+
[Testing.Parameters]
80+
public async Task TestCreateOauth()
81+
{
82+
UseVCR("create_with_oauth");
83+
84+
EasyPost.Parameters.CarrierAccount.CreateOauth parameters = new()
85+
{
86+
Type = CarrierAccountType.AmazonShippingAccount.Name,
87+
};
88+
89+
CarrierAccount carrierAccount = await Client.CarrierAccount.Create(parameters);
90+
CleanUpAfterTest(carrierAccount.Id);
91+
92+
Assert.IsType<CarrierAccount>(carrierAccount);
93+
Assert.StartsWith("ca_", carrierAccount.Id);
94+
Assert.Equal("AmazonShippingAccount", carrierAccount.Type);
95+
}
96+
7697
[Fact]
7798
[CrudOperations.Read]
7899
[Testing.Function]

EasyPost.Tests/cassettes/net/carrier_account_service/create_with_oauth.json

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

EasyPost/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public static class CarrierAccounts
134134
CarrierAccountType.Ups.Name,
135135
CarrierAccountType.UpsMailInnovations.Name,
136136
CarrierAccountType.UpsSurePost.Name,
137+
CarrierAccountType.AmazonShippingAccount.Name,
137138
};
138139

139140
/// <summary>
@@ -154,6 +155,7 @@ internal static string DeriveCreateEndpoint(string carrierType)
154155
{
155156
{ new List<string> { CarrierAccountType.FedEx.Name, CarrierAccountType.FedExSmartPost.Name }.Contains(carrierType), () => endpoint = CustomCreateEndpoint },
156157
{ new List<string> { CarrierAccountType.Ups.Name, CarrierAccountType.UpsMailInnovations.Name, CarrierAccountType.UpsSurePost.Name }.Contains(carrierType), () => endpoint = UpsOAuthCreateEndpoint },
158+
{ new List<string> { CarrierAccountType.AmazonShippingAccount.Name, }.Contains(carrierType), () => endpoint = OauthCreateEndpoint },
157159
{ SwitchCaseScenario.Default, () => endpoint = StandardCreateEndpoint },
158160
};
159161

@@ -186,6 +188,7 @@ internal static string DeriveUpdateEndpoint(string carrierType, string id)
186188
internal const string UpsOAuthCreateEndpoint = "ups_oauth_registrations";
187189
internal const string StandardUpdateEndpoint = "carrier_accounts/{0}";
188190
internal const string UpsOAuthUpdateEndpoint = "ups_oauth_registrations/{0}";
191+
internal const string OauthCreateEndpoint = "carrier_accounts/register_oauth";
189192
}
190193
}
191194
}

EasyPost/Models/API/CarrierAccountType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public class CarrierAccountType : ValueEnum
3333
/// </summary>
3434
public static readonly CarrierAccountType UpsSurePost = new CarrierAccountType(61, "UpsSurepostAccount");
3535

36+
/// <summary>
37+
/// Represents an Amazon carrier account.
38+
/// </summary>
39+
public static readonly CarrierAccountType AmazonShippingAccount = new CarrierAccountType(62, "AmazonShippingAccount");
40+
3641
/// <summary>
3742
/// Initializes a new instance of the <see cref="CarrierAccountType"/> class.
3843
/// </summary>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
3+
using EasyPost.Utilities.Internal.Attributes;
4+
using EasyPost.Utilities.Internal.Extensions;
5+
6+
namespace EasyPost.Parameters.CarrierAccount
7+
{
8+
/// <summary>
9+
/// <a href="https://docs.easypost.com/docs/carrier-accounts#create-a-carrieraccount">Parameters</a> for <see cref="EasyPost.Services.CarrierAccountService.Create(ACreate, System.Threading.CancellationToken)"/> API calls.
10+
/// </summary>
11+
[ExcludeFromCodeCoverage]
12+
public class CreateOauth : ACreate
13+
{
14+
#region Request Parameters
15+
16+
/// <summary>
17+
/// Description for the new <see cref="Models.API.CarrierAccount"/>.
18+
/// </summary>
19+
[TopLevelRequestParameter(Necessity.Optional, "carrier_account_oauth_registrations", "description")]
20+
public string? Description { get; set; }
21+
22+
/// <summary>
23+
/// Reference name for the new <see cref="Models.API.CarrierAccount"/>.
24+
/// </summary>
25+
[TopLevelRequestParameter(Necessity.Optional, "carrier_account_oauth_registrations", "reference")]
26+
public string? Reference { get; set; }
27+
28+
/// <inheritdoc/>
29+
[TopLevelRequestParameter(Necessity.Required, "carrier_account_oauth_registrations", "type")]
30+
public override string? Type { get; set; }
31+
32+
#endregion
33+
34+
/// <inheritdoc cref="EasyPost.Parameters.CarrierAccount.ACreate.Endpoint"/>
35+
internal override string Endpoint => Constants.CarrierAccounts.OauthCreateEndpoint;
36+
37+
/// <inheritdoc />
38+
public override Dictionary<string, object> ToDictionary()
39+
{
40+
Dictionary<string, object> dictionary = base.ToDictionary();
41+
42+
dictionary!.AddOrUpdate(Type, "type"); // Need to add "type" top-level (added sub-level by serialization)
43+
44+
return dictionary;
45+
}
46+
}
47+
}

EasyPost/Services/CarrierAccountService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ internal CarrierAccountService(EasyPostClient client)
2828

2929
#region CRUD Operations
3030

31-
// TODO: Use ID or whole object as parameter?
32-
3331
/// <summary>
3432
/// Create a <see cref="CarrierAccount"/>.
3533
/// <a href="https://docs.easypost.com/docs/carrier-accounts#create-a-carrieraccount">Related API documentation</a>.

0 commit comments

Comments
 (0)