diff --git a/CHANGELOG.md b/CHANGELOG.md index e3681187..a71ac9bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/easypost/constant.py b/easypost/constant.py index 9659e779..066a239a 100644 --- a/easypost/constant.py +++ b/easypost/constant.py @@ -36,6 +36,9 @@ "FedexAccount", "FedexSmartpostAccount", ] +_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [ + "AmazonShippingAccount", +] _UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [ "UpsAccount", "UpsMailInnovationsAccount", diff --git a/easypost/services/carrier_account_service.py b/easypost/services/carrier_account_service.py index 56258a9f..5708b35c 100644 --- a/easypost/services/carrier_account_service.py +++ b/easypost/services/carrier_account_service.py @@ -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, @@ -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} @@ -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" diff --git a/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml b/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml new file mode 100644 index 00000000..eae66012 --- /dev/null +++ b/tests/cassettes/test_carrier_account_create_amazon_shipping.yaml @@ -0,0 +1,134 @@ +interactions: +- request: + body: '{"carrier_account_oauth_registrations": {"type": "AmazonShippingAccount"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '74' + Content-Type: + - application/json + authorization: + - + user-agent: + - + method: POST + uri: https://api.easypost.com/v2/carrier_accounts/register_oauth + response: + body: + string: '{"id": "ca_18bfc1a27cc349cfbf219cf0e754f917", "object": "CarrierAccount", + "type": "AmazonShippingAccount", "clone": false, "created_at": "2025-04-10T19:12:34Z", + "updated_at": "2025-04-10T19:12:34Z", "description": null, "reference": null, + "billing_type": "carrier", "readable": "Amazon Shipping", "logo": null, "fields": + [], "credentials": {}, "test_credentials": {}}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '1448' + content-type: + - application/json; charset=utf-8 + expires: + - '0' + pragma: + - no-cache + referrer-policy: + - strict-origin-when-cross-origin + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-backend: + - easypost + x-content-type-options: + - nosniff + x-download-options: + - noopen + x-ep-request-uuid: + - 028443c067f81822e2bbac9c00135101 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb54nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb3nuq 284c5d344a + - extlb1nuq 99aac35317 + x-runtime: + - '0.225842' + x-version-label: + - easypost-202504101604-e81adf64e4-master + x-xss-protection: + - 1; mode=block + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + authorization: + - + user-agent: + - + method: DELETE + uri: https://api.easypost.com/v2/carrier_accounts/ca_18bfc1a27cc349cfbf219cf0e754f917 + response: + body: + string: '{}' + headers: + cache-control: + - private, no-cache, no-store + content-length: + - '2' + content-type: + - application/json; charset=utf-8 + expires: + - '0' + pragma: + - no-cache + referrer-policy: + - strict-origin-when-cross-origin + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-backend: + - easypost + x-content-type-options: + - nosniff + x-download-options: + - noopen + x-ep-request-uuid: + - 028443c067f81822e2bbac9c00135164 + x-frame-options: + - SAMEORIGIN + x-node: + - bigweb35nuq + x-permitted-cross-domain-policies: + - none + x-proxied: + - intlb4nuq 284c5d344a + - extlb1nuq 99aac35317 + x-runtime: + - '0.056642' + x-version-label: + - easypost-202504101604-e81adf64e4-master + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_carrier_account.py b/tests/test_carrier_account.py index 72e1a698..57554394 100644 --- a/tests/test_carrier_account.py +++ b/tests/test_carrier_account.py @@ -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.