Skip to content

Commit 3eff963

Browse files
authored
Merge pull request #353 from EasyPost/amazon_shipping
Add Amazon shipping endpoint
2 parents 03136e0 + 861290d commit 3eff963

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `BetaReferralCustomerService.create_bank_account_client_secret`
99
- `ReferralCustomerService.add_credit_card_from_stripe`
1010
- `ReferralCustomerService.add_bank_account_from_stripe`
11+
- Routes `AmazonShippingAccount` create requests to the new `/register_oauth` endpoint
1112
- Fixes the payload wrapping for updating a webhook
1213
- Removes deprecated `user.all_api_keys` and `user.api_keys`, use `api_key.all` and `api_key.retrieve_api_keys_for_user` respectively
1314
- Bumps all dev dependencies

easypost/constant.py

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"FedexAccount",
3737
"FedexSmartpostAccount",
3838
]
39+
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [
40+
"AmazonShippingAccount",
41+
]
3942
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [
4043
"UpsAccount",
4144
"UpsMailInnovationsAccount",

easypost/services/carrier_account_service.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
)
55

66
from easypost.constant import (
7+
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH,
78
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS,
89
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES,
910
MISSING_PARAMETER_ERROR,
@@ -33,6 +34,8 @@ def create(self, **params) -> CarrierAccount:
3334
url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type)
3435
if carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
3536
wrapped_params = {"ups_oauth_registrations": params}
37+
elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
38+
wrapped_params = {"carrier_account_oauth_registrations": params}
3639
else:
3740
wrapped_params = {self._snakecase_name(self._model_class): params}
3841

@@ -75,5 +78,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option
7578
return "/carrier_accounts/register"
7679
elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
7780
return "/ups_oauth_registrations"
81+
elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
82+
return "/carrier_accounts/register_oauth"
7883

7984
return "/carrier_accounts"

tests/cassettes/test_carrier_account_create_amazon_shipping.yaml

+134
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_carrier_account.py

+16
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,19 @@ def test_carrier_account_update_ups(prod_client):
131131
prod_client.carrier_account.delete(
132132
updated_carrier_account.id
133133
) # Delete the carrier account once it's done being tested.
134+
135+
136+
@pytest.mark.vcr()
137+
def test_carrier_account_create_amazon_shipping(prod_client):
138+
"""Test registering an Amazon Shipping Carrier Account which uses a different URL and schema."""
139+
params = {
140+
"type": "AmazonShippingAccount",
141+
}
142+
143+
carrier_account = prod_client.carrier_account.create(**params)
144+
145+
assert isinstance(carrier_account, CarrierAccount)
146+
assert str.startswith(carrier_account.id, "ca_")
147+
assert carrier_account.type == "AmazonShippingAccount"
148+
149+
prod_client.carrier_account.delete(carrier_account.id) # Delete the carrier account once it's done being tested.

0 commit comments

Comments
 (0)