Skip to content

Commit 37d5f07

Browse files
authored
Merge pull request #362 from EasyPost/ups_endpoint
fix: endpoint used for ups create/update
2 parents b4d8f33 + 236adfd commit 37d5f07

File tree

8 files changed

+160
-242
lines changed

8 files changed

+160
-242
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v8.0.1 (2025-05-27)
4+
5+
- Corrects the endpoint used for creating/updating UPS accounts
6+
37
## v8.0.0 (2025-04-28)
48

59
See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-7x-to-80) for more details.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "easypost/easypost-php",
33
"description": "EasyPost Shipping API Client Library for PHP",
4-
"version": "8.0.0",
4+
"version": "8.0.1",
55
"keywords": [
66
"shipping",
77
"api",

lib/EasyPost/Constant/Constants.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Constants
1111
const BETA_API_VERSION = 'beta';
1212

1313
// Library constants
14-
const LIBRARY_VERSION = '8.0.0';
14+
const LIBRARY_VERSION = '8.0.1';
1515
const SUPPORT_EMAIL = '[email protected]';
1616

1717
// Validation
@@ -20,16 +20,13 @@ abstract class Constants
2020
'FedexSmartpostAccount'
2121
];
2222

23-
const UPS_OAUTH_ACCOUNT_TYPES = [
23+
const CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [
24+
'AmazonShippingAccount',
2425
'UpsAccount',
2526
'UpsMailInnovationsAccount',
2627
'UpsSurepostAccount'
2728
];
2829

29-
const CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [
30-
'AmazonShippingAccount',
31-
];
32-
3330
// Exception messages (many of these are intended to be used with `sprintf()`)
3431
const ARRAY_REQUIRED_ERROR = 'You must pass an array as the first argument to EasyPost API method calls.';
3532
const COMMUNICATION_ERROR = 'Unexpected error communicating with %s. If this problem persists please let us know at ' . self::SUPPORT_EMAIL . '. %s'; // phpcs:ignore

lib/EasyPost/Exception/Api/ApiException.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,16 @@ public function __construct(string $message = '', ?int $httpStatus = null, ?stri
3939
$this->errors = [];
4040
$this->code = null;
4141

42-
try {
43-
$this->jsonBody = isset($httpBody) ? json_decode($httpBody, true) : null;
42+
$this->jsonBody = isset($httpBody) ? json_decode($httpBody, true) : null;
4443

45-
// Set `errors` property
46-
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['errors'])) {
47-
$this->errors = $this->jsonBody['error']['errors'];
48-
}
44+
// Set `errors` property
45+
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['errors'])) {
46+
$this->errors = $this->jsonBody['error']['errors'];
47+
}
4948

50-
// Set `code` property
51-
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['code'])) {
52-
$this->code = $this->jsonBody['error']['code'];
53-
}
54-
} catch (Exception $e) { // @phpstan-ignore-line
55-
$this->jsonBody = null;
49+
// Set `code` property
50+
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['code'])) {
51+
$this->code = $this->jsonBody['error']['code'];
5652
}
5753
}
5854

lib/EasyPost/Http/Requestor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static function absoluteUrl(EasyPostClient $client, string $url = '', bo
5555
public static function utf8(mixed $value): string
5656
{
5757
if (is_string($value) && mb_detect_encoding($value, 'UTF-8', true) != 'UTF-8') {
58-
return mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
58+
return (string)mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
5959
}
6060

6161
return $value;

lib/EasyPost/Service/CarrierAccountService.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@ public function all(mixed $params = null): mixed
4343
*/
4444
public function update(string $id, mixed $params): mixed
4545
{
46-
$carrierAccount = self::retrieve($id);
47-
$carrierAccountType = $carrierAccount['type'];
48-
if (in_array($carrierAccountType, Constants::UPS_OAUTH_ACCOUNT_TYPES, true)) {
49-
$className = 'UpsOauthRegistration';
50-
$params = [self::selectTopLayerKey($carrierAccountType) => $params];
51-
} else {
52-
$className = 'CarrierAccount';
53-
$params = [self::selectTopLayerKey($carrierAccountType) => $params];
46+
if (!isset($params['carrier_account']) || !is_array($params['carrier_account'])) {
47+
$clone = $params;
48+
unset($params);
49+
$params['carrier_account'] = $clone;
5450
}
55-
return self::updateResource($className, $id, $params);
51+
52+
return self::updateResource(self::serviceModelClassName(self::class), $id, $params);
5653
}
5754

5855
/**
@@ -111,8 +108,6 @@ private function selectCarrierAccountCreationEndpoint(string $carrierAccountType
111108
{
112109
if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS, true)) {
113110
return '/carrier_accounts/register';
114-
} else if (in_array($carrierAccountType, Constants::UPS_OAUTH_ACCOUNT_TYPES, true)) {
115-
return '/ups_oauth_registrations';
116111
} else if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH, true)) {
117112
return '/carrier_accounts/register_oauth';
118113
}
@@ -128,9 +123,7 @@ private function selectCarrierAccountCreationEndpoint(string $carrierAccountType
128123
*/
129124
private function selectTopLayerKey(string $carrierAccountType): string
130125
{
131-
if (in_array($carrierAccountType, Constants::UPS_OAUTH_ACCOUNT_TYPES, true)) {
132-
return 'ups_oauth_registrations';
133-
} else if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH, true)) {
126+
if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH, true)) {
134127
return 'carrier_account_oauth_registrations';
135128
} else {
136129
return 'carrier_account';

test/cassettes/carrier_accounts/create_ups.yml

Lines changed: 56 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)