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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v8.0.1 (2025-05-27)

- Corrects the endpoint used for creating/updating UPS accounts

## v8.0.0 (2025-04-28)

See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-7x-to-80) for more details.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "easypost/easypost-php",
"description": "EasyPost Shipping API Client Library for PHP",
"version": "8.0.0",
"version": "8.0.1",
"keywords": [
"shipping",
"api",
Expand Down
9 changes: 3 additions & 6 deletions lib/EasyPost/Constant/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class Constants
const BETA_API_VERSION = 'beta';

// Library constants
const LIBRARY_VERSION = '8.0.0';
const LIBRARY_VERSION = '8.0.1';
const SUPPORT_EMAIL = '[email protected]';

// Validation
Expand All @@ -20,16 +20,13 @@ abstract class Constants
'FedexSmartpostAccount'
];

const UPS_OAUTH_ACCOUNT_TYPES = [
const CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [
'AmazonShippingAccount',
'UpsAccount',
'UpsMailInnovationsAccount',
'UpsSurepostAccount'
];

const CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = [
'AmazonShippingAccount',
];

// Exception messages (many of these are intended to be used with `sprintf()`)
const ARRAY_REQUIRED_ERROR = 'You must pass an array as the first argument to EasyPost API method calls.';
const COMMUNICATION_ERROR = 'Unexpected error communicating with %s. If this problem persists please let us know at ' . self::SUPPORT_EMAIL . '. %s'; // phpcs:ignore
Expand Down
20 changes: 8 additions & 12 deletions lib/EasyPost/Exception/Api/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,16 @@ public function __construct(string $message = '', ?int $httpStatus = null, ?stri
$this->errors = [];
$this->code = null;

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

// Set `errors` property
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['errors'])) {
$this->errors = $this->jsonBody['error']['errors'];
}
// Set `errors` property
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['errors'])) {
$this->errors = $this->jsonBody['error']['errors'];
}

// Set `code` property
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['code'])) {
$this->code = $this->jsonBody['error']['code'];
}
} catch (Exception $e) { // @phpstan-ignore-line
$this->jsonBody = null;
// Set `code` property
if (isset($this->jsonBody) && !empty($this->jsonBody['error']['code'])) {
$this->code = $this->jsonBody['error']['code'];
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Http/Requestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static function absoluteUrl(EasyPostClient $client, string $url = '', bo
public static function utf8(mixed $value): string
{
if (is_string($value) && mb_detect_encoding($value, 'UTF-8', true) != 'UTF-8') {
return mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
return (string)mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
}

return $value;
Expand Down
21 changes: 7 additions & 14 deletions lib/EasyPost/Service/CarrierAccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,13 @@ public function all(mixed $params = null): mixed
*/
public function update(string $id, mixed $params): mixed
{
$carrierAccount = self::retrieve($id);
$carrierAccountType = $carrierAccount['type'];
if (in_array($carrierAccountType, Constants::UPS_OAUTH_ACCOUNT_TYPES, true)) {
$className = 'UpsOauthRegistration';
$params = [self::selectTopLayerKey($carrierAccountType) => $params];
} else {
$className = 'CarrierAccount';
$params = [self::selectTopLayerKey($carrierAccountType) => $params];
if (!isset($params['carrier_account']) || !is_array($params['carrier_account'])) {
$clone = $params;
unset($params);
$params['carrier_account'] = $clone;
}
return self::updateResource($className, $id, $params);

return self::updateResource(self::serviceModelClassName(self::class), $id, $params);
}

/**
Expand Down Expand Up @@ -111,8 +108,6 @@ private function selectCarrierAccountCreationEndpoint(string $carrierAccountType
{
if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS, true)) {
return '/carrier_accounts/register';
} else if (in_array($carrierAccountType, Constants::UPS_OAUTH_ACCOUNT_TYPES, true)) {
return '/ups_oauth_registrations';
} else if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH, true)) {
return '/carrier_accounts/register_oauth';
}
Expand All @@ -128,9 +123,7 @@ private function selectCarrierAccountCreationEndpoint(string $carrierAccountType
*/
private function selectTopLayerKey(string $carrierAccountType): string
{
if (in_array($carrierAccountType, Constants::UPS_OAUTH_ACCOUNT_TYPES, true)) {
return 'ups_oauth_registrations';
} else if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH, true)) {
if (in_array($carrierAccountType, Constants::CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH, true)) {
return 'carrier_account_oauth_registrations';
} else {
return 'carrier_account';
Expand Down
110 changes: 56 additions & 54 deletions test/cassettes/carrier_accounts/create_ups.yml

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

Loading
Loading