Skip to content

Commit cea7572

Browse files
committed
Add Amazon shipping endpoint
1 parent ca96499 commit cea7572

7 files changed

+466
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next Release
44

55
- Removes the deprecated `create_list` tracker endpoint function as it is no longer available via API
6+
- Routes `AmazonShippingAccount` create/update requests to the new `/register_oauth` endpoint
67

78
## v9.4.1 (2024-08-09)
89

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/base_service.py

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def _update_resource(
7777
"""Update an EasyPost object via the EasyPost API."""
7878
url = self._instance_url(class_name, id)
7979
wrapped_params = {self._snakecase_name(class_name): params}
80-
8180
response = Requestor(self._client).request(method=method, url=url, params=wrapped_params, beta=beta)
8281

8382
return convert_to_easypost_object(response=response)

easypost/services/carrier_account_service.py

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
)
77

88
from easypost.constant import (
9+
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH,
910
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS,
1011
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES,
1112
MISSING_PARAMETER_ERROR,
@@ -35,6 +36,8 @@ def create(self, **params) -> CarrierAccount:
3536
url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type)
3637
if carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
3738
wrapped_params = {"ups_oauth_registrations": params}
39+
elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
40+
wrapped_params = {"carrier_account_oauth_registrations": params}
3841
else:
3942
wrapped_params = {self._snakecase_name(self._model_class): params}
4043

@@ -56,6 +59,13 @@ def update(self, id: str, **params) -> CarrierAccount:
5659

5760
if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
5861
class_name = "UpsOauthRegistrations"
62+
elif carrier_account.get("type") in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
63+
response = Requestor(self._client).request(
64+
method=RequestMethod.PATCH,
65+
url=f"/carrier_accounts/register_oauth/{id}",
66+
params={},
67+
)
68+
return convert_to_easypost_object(response=response)
5969
else:
6070
class_name = self._model_class
6171

@@ -77,5 +87,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option
7787
return "/carrier_accounts/register"
7888
elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
7989
return "/ups_oauth_registrations"
90+
elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
91+
return "/carrier_accounts/register_oauth"
8092

8193
return "/carrier_accounts"

tests/cassettes/test_carrier_account_create_amazon_shipping.yaml

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

0 commit comments

Comments
 (0)