Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Amazon shipping endpoint #353

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Release

- Routes `AmazonShippingAccount` create/update requests to the new `/register_oauth` endpoint

## v9.5.0 (2024-10-24)

- Adds `tracking_codes` as a parameter of the `all` method on the TrackerService
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 = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: do we know if other carriers will reuse this same endpoint? Otherwise this name may be too generic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know; there could be a carrier that uses this endpoint in the future. This name is similar to what we have for FedEx _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS

"AmazonShippingAccount",
]
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [
"UpsAccount",
"UpsMailInnovationsAccount",
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={"carrier_account_oauth_registrations": 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
Loading