Skip to content

Commit 04cfeb9

Browse files
jchen293Justintime50
authored andcommitted
Add Amazon shipping endpoint
1 parent 03136e0 commit 04cfeb9

File tree

7 files changed

+466
-1
lines changed

7 files changed

+466
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Adds `tracking_codes` as a parameter of the `all` method on the TrackerService
1818
- Removes the deprecated `create_list` tracker endpoint function as it is no longer available via API
19+
- Routes `AmazonShippingAccount` create/update requests to the new `/register_oauth` endpoint
1920

2021
## v9.4.1 (2024-08-09)
2122

easypost/constant.py

Lines changed: 3 additions & 0 deletions
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def _update_resource(
8585
"""Update an EasyPost object via the EasyPost API."""
8686
url = self._instance_url(class_name, id)
8787
wrapped_params = {self._snakecase_name(class_name): params}
88-
8988
response = Requestor(self._client).request(method=method, url=url, params=wrapped_params, beta=beta)
9089

9190
return convert_to_easypost_object(response=response)

easypost/services/carrier_account_service.py

Lines changed: 12 additions & 0 deletions
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

@@ -54,6 +57,13 @@ def update(self, id: str, **params) -> CarrierAccount:
5457

5558
if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
5659
class_name = "UpsOauthRegistrations"
60+
elif carrier_account.get("type") in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
61+
response = Requestor(self._client).request(
62+
method=RequestMethod.PATCH,
63+
url=f"/carrier_accounts/register_oauth/{id}",
64+
params={},
65+
)
66+
return convert_to_easypost_object(response=response)
5767
else:
5868
class_name = self._model_class
5969

@@ -75,5 +85,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option
7585
return "/carrier_accounts/register"
7686
elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
7787
return "/ups_oauth_registrations"
88+
elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
89+
return "/carrier_accounts/register_oauth"
7890

7991
return "/carrier_accounts"

tests/cassettes/test_carrier_account_create_amazon_shipping.yaml

Lines changed: 137 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)