Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Next Release

- Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint
- Starting `2024-08-05`, UPS accounts will require a new payload to register or update. See [UPS OAuth 2.0 Update](https://support.easypost.com/hc/en-us/articles/26635027512717-UPS-OAuth-2-0-Update?utm_medium=email&_hsenc=p2ANqtz-96MmFtWICOzy9sKRbbcZSiMovZSrY3MSX1_bgY9N3f9yLVfWQdLhjAGq-SmNcOnDIS6GYhZ0OApjDBrGkKyLLMx1z6_TFOVp6-wllhEFQINrkuRuc&_hsmi=313130292&utm_content=313130292&utm_source=hs_email) for more details

## v9.2.0 (2024-04-10)

- Fix payment method funding and deletion failures due to undetermined payment method type
Expand Down
4 changes: 4 additions & 0 deletions easypost/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS = [
"FedexAccount",
"FedexSmartpostAccount",
]
_UPS_OATH_CARRIER_ACCOUNT_TYPES = [
"UpsAccount",
"UpsMailInnovationsAccount",
"UpsSurepostAccount",
]
_FILTERS_KEY = "filters"
17 changes: 15 additions & 2 deletions easypost/services/carrier_account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from easypost.constant import (
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS,
_UPS_OATH_CARRIER_ACCOUNT_TYPES,
MISSING_PARAMETER_ERROR,
)
from easypost.easypost_object import convert_to_easypost_object
Expand All @@ -32,7 +33,10 @@ def create(self, **params) -> CarrierAccount:
raise MissingParameterError(MISSING_PARAMETER_ERROR.format("type"))

url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type)
wrapped_params = {self._snakecase_name(self._model_class): params}
if carrier_account_type in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
wrapped_params = {"ups_oauth_registrations": params}
else:
wrapped_params = {self._snakecase_name(self._model_class): params}

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

Expand All @@ -48,7 +52,14 @@ def retrieve(self, id: str) -> CarrierAccount:

def update(self, id: str, **params) -> CarrierAccount:
"""Update a CarrierAccount."""
return self._update_resource(self._model_class, id, **params)
carrier_account = self.retrieve(id)

if carrier_account.get("type") in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
class_name = "UpsOauthRegistrations"
else:
class_name = self._model_class

return self._update_resource(class_name, id, **params)

def delete(self, id: str) -> None:
"""Delete a CarrierAccount."""
Expand All @@ -64,5 +75,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option
"""Determines which API endpoint to use for the creation call."""
if carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS:
return "/carrier_accounts/register"
elif carrier_account_type in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
return "/ups_oauth_registrations"

return "/carrier_accounts"
69 changes: 69 additions & 0 deletions tests/cassettes/test_carrier_account_create_ups.yaml

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

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

Loading