Skip to content

Commit

Permalink
Add Amazon shipping endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 committed Oct 22, 2024
1 parent ca96499 commit cea7572
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next Release

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

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

Expand Down
3 changes: 3 additions & 0 deletions easypost/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"FedexAccount",
"FedexSmartpostAccount",
]
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [
"AmazonShippingAccount",
]
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [
"UpsAccount",
"UpsMailInnovationsAccount",
Expand Down
1 change: 0 additions & 1 deletion easypost/services/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def _update_resource(
"""Update an EasyPost object via the EasyPost API."""
url = self._instance_url(class_name, id)
wrapped_params = {self._snakecase_name(class_name): params}

response = Requestor(self._client).request(method=method, url=url, params=wrapped_params, beta=beta)

return convert_to_easypost_object(response=response)
Expand Down
12 changes: 12 additions & 0 deletions easypost/services/carrier_account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)

from easypost.constant import (
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH,
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS,
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES,
MISSING_PARAMETER_ERROR,
Expand Down Expand Up @@ -35,6 +36,8 @@ def create(self, **params) -> CarrierAccount:
url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type)
if carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
wrapped_params = {"ups_oauth_registrations": params}
elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
wrapped_params = {"carrier_account_oauth_registrations": params}
else:
wrapped_params = {self._snakecase_name(self._model_class): params}

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

if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
class_name = "UpsOauthRegistrations"
elif carrier_account.get("type") in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
response = Requestor(self._client).request(
method=RequestMethod.PATCH,
url=f"/carrier_accounts/register_oauth/{id}",
params={},
)
return convert_to_easypost_object(response=response)
else:
class_name = self._model_class

Expand All @@ -77,5 +87,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option
return "/carrier_accounts/register"
elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
return "/ups_oauth_registrations"
elif carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH:
return "/carrier_accounts/register_oauth"

return "/carrier_accounts"
137 changes: 137 additions & 0 deletions tests/cassettes/test_carrier_account_create_amazon_shipping.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cea7572

Please sign in to comment.