Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `BetaReferralCustomerService.create_bank_account_client_secret`
- `ReferralCustomerService.add_credit_card_from_stripe`
- `ReferralCustomerService.add_bank_account_from_stripe`
- Routes `AmazonShippingAccount` create requests to the new `/register_oauth` endpoint
- Fixes the payload wrapping for updating a webhook
- Removes deprecated `user.all_api_keys` and `user.api_keys`, use `api_key.all` and `api_key.retrieve_api_keys_for_user` respectively
- Bumps all dev dependencies
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
5 changes: 5 additions & 0 deletions easypost/services/carrier_account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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 @@ -33,6 +34,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 Down Expand Up @@ -75,5 +78,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"
134 changes: 134 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.

16 changes: 16 additions & 0 deletions tests/test_carrier_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,19 @@ def test_carrier_account_update_ups(prod_client):
prod_client.carrier_account.delete(
updated_carrier_account.id
) # Delete the carrier account once it's done being tested.


@pytest.mark.vcr()
def test_carrier_account_create_amazon_shipping(prod_client):
"""Test registering an Amazon Shipping Carrier Account which uses a different URL and schema."""
params = {
"type": "AmazonShippingAccount",
}

carrier_account = prod_client.carrier_account.create(**params)

assert isinstance(carrier_account, CarrierAccount)
assert str.startswith(carrier_account.id, "ca_")
assert carrier_account.type == "AmazonShippingAccount"

prod_client.carrier_account.delete(carrier_account.id) # Delete the carrier account once it's done being tested.