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

## v8.8.1 (2026-07-02)

- Uppercases all HTTP methods to correct a new Guzzle deprecation
- Removed dead code in `__set` and `__unset` of an `EasyPostObject`

## v8.8.0 (2026-06-25)

- Adds `params` to `requestPin` ensuring users can pass `easypost_details` to the call.
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.8.0",
"version": "8.8.1",
"keywords": [
"shipping",
"api",
Expand Down
2 changes: 1 addition & 1 deletion 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.8.0';
const LIBRARY_VERSION = '8.8.1';
const SUPPORT_EMAIL = 'support@easypost.com';

// Validation
Expand Down
12 changes: 4 additions & 8 deletions lib/EasyPost/EasyPostClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,11 @@ public function __get(string $serviceName)

if (array_key_exists($serviceName, $serviceClassMap)) {
return new $serviceClassMap[$serviceName]($this);
} else {
// TODO: checking for `_parent` is a hack and should be fixed when we revisit the
// (de)serialization of objects in this lib.
if ($serviceName != '_parent') {
throw new EasyPostException(
sprintf(Constants::UNDEFINED_PROPERTY_ERROR, 'EasyPostClient', $serviceName)
);
}
}

throw new EasyPostException(
sprintf(Constants::UNDEFINED_PROPERTY_ERROR, 'EasyPostClient', $serviceName)
);
}

/**
Expand Down
28 changes: 0 additions & 28 deletions lib/EasyPost/EasyPostObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ public function __construct(mixed $parent = null, mixed $name = null)
public function __set(string $k, mixed $v): void
{
$this->_values[$k] = $v;

$i = 0;
$current = $this;
$param = [$k => $v];

// TODO: Rework this when we fix (de)serialization
// @phpstan-ignore-next-line
while (true && $i < 99) {
if (!is_null($current->_parent)) {
$param = [$current->_name => $param];
$current = $current->_parent;
}
$i++;
}
}

/**
Expand All @@ -81,20 +67,6 @@ public function __unset(string $k): void
{
if (!in_array($k, $this->_immutableValues)) {
unset($this->_values[$k]);

$i = 0;
$current = $this;
$param = [$k => null];

// TODO: Rework this when we fix (de)serialization
// @phpstan-ignore-next-line
while (true && $i < 99) {
if (!is_null($current->_parent)) {
$param = [$current->_name => $param];
$current = $current->_parent;
}
$i++;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/EasyPost/Http/HttpMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace EasyPost\Http;

enum HttpMethod: string
{
case GET = 'GET';
case POST = 'POST';
case PUT = 'PUT';
case PATCH = 'PATCH';
case DELETE = 'DELETE';
}
15 changes: 10 additions & 5 deletions lib/EasyPost/Http/Requestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ private static function encodeObjects(mixed $data): array|string
* Make a request to the EasyPost API.
*
* @param EasyPostClient $client
* @param string $method
* @param HttpMethod|string $method
* @param string $url
* @param mixed $params
* @param bool $beta
* @return mixed
*/
public static function request(
EasyPostClient $client,
string $method,
HttpMethod|string $method,
string $url,
mixed $params = null,
bool $beta = false
Expand All @@ -118,7 +118,7 @@ public static function request(
* Internal logic required to make a request to the EasyPost API.
*
* @param EasyPostClient $client
* @param string $method
* @param HttpMethod|string $method
* @param string $url
* @param mixed $params
* @param bool $beta
Expand All @@ -128,17 +128,22 @@ public static function request(
*/
private static function requestRaw(
EasyPostClient $client,
string $method,
HttpMethod|string $method,
string $url,
mixed $params,
bool $beta = false
): array {
if ($method instanceof HttpMethod) {
$method = $method->value;
} else {
$method = strtoupper($method);
}
$absoluteUrl = self::absoluteUrl($client, $url, $beta);
$requestOptions = [
'http_errors' => false, // we set this false here so we can do our own error handling
'timeout' => $client->getTimeout(),
];
if (in_array(strtolower($method), ['get', 'delete'])) {
if (in_array($method, [HttpMethod::GET->value, HttpMethod::DELETE->value])) {
$requestOptions['query'] = $params;
} else {
$params = self::encodeObjects($params);
Expand Down
10 changes: 8 additions & 2 deletions lib/EasyPost/Service/AddressService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasyPost\Service;

use EasyPost\Http\HttpMethod;
use EasyPost\Http\Requestor;
use EasyPost\Util\InternalUtil;

Expand Down Expand Up @@ -96,7 +97,12 @@ public function createAndVerify(mixed $params = null): mixed
$wrappedParams['address'] = $params;

$url = self::classUrl(self::serviceModelClassName(self::class));
$response = Requestor::request($this->client, 'post', $url . '/create_and_verify', $wrappedParams);
$response = Requestor::request(
$this->client,
HttpMethod::POST,
$url . '/create_and_verify',
$wrappedParams
);

return InternalUtil::convertToEasyPostObject($this->client, $response['address']);
}
Expand All @@ -110,7 +116,7 @@ public function createAndVerify(mixed $params = null): mixed
public function verify(string $id): mixed
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/verify';
$response = Requestor::request($this->client, 'get', $url, null);
$response = Requestor::request($this->client, HttpMethod::GET, $url, null);

return InternalUtil::convertToEasyPostObject($this->client, $response['address']);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/EasyPost/Service/ApiKeyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasyPost\Service;

use EasyPost\Http\HttpMethod;
use EasyPost\Constant\Constants;
use EasyPost\Exception\General\FilteringException;
use EasyPost\Http\Requestor;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function retrieveApiKeysForUser(string $id): mixed
*/
public function all(): mixed
{
$response = Requestor::request($this->client, 'get', '/api_keys');
$response = Requestor::request($this->client, HttpMethod::GET, '/api_keys');

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand Down Expand Up @@ -82,7 +83,7 @@ public function delete(string $id): void
*/
public function enable(string $id): mixed
{
$response = Requestor::request($this->client, 'post', "/api_keys/{$id}/enable");
$response = Requestor::request($this->client, HttpMethod::POST, "/api_keys/{$id}/enable");

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -95,7 +96,7 @@ public function enable(string $id): mixed
*/
public function disable(string $id): mixed
{
$response = Requestor::request($this->client, 'post', "/api_keys/{$id}/disable");
$response = Requestor::request($this->client, HttpMethod::POST, "/api_keys/{$id}/disable");

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/EasyPost/Service/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasyPost\Service;

use EasyPost\Http\HttpMethod;
use EasyPost\Constant\Constants;
use EasyPost\EasyPostClient;
use EasyPost\Exception\General\EndOfPaginationException;
Expand Down Expand Up @@ -118,7 +119,7 @@ protected function retrieveResource(string $class, string $id, bool $beta = fals
{
$url = $this->instanceUrl($class, $id);

$response = Requestor::request($this->client, 'get', $url, null, $beta);
$response = Requestor::request($this->client, HttpMethod::GET, $url, null, $beta);

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -135,7 +136,7 @@ protected function allResources(string $class, mixed $params = null, bool $beta
{
self::validate($params);
$url = self::classUrl($class);
$response = Requestor::request($this->client, 'get', $url, $params, $beta);
$response = Requestor::request($this->client, HttpMethod::GET, $url, $params, $beta);
if (isset($params)) {
$response['_params'] = $params;
}
Expand Down Expand Up @@ -196,7 +197,7 @@ protected function createResource(string $class, mixed $params = null, bool $bet
{
self::validate($params);
$url = self::classUrl($class);
$response = Requestor::request($this->client, 'post', $url, $params, $beta);
$response = Requestor::request($this->client, HttpMethod::POST, $url, $params, $beta);

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -215,7 +216,7 @@ protected function deleteResource(string $class, string $id, mixed $params = nul
self::validate();
$url = $this->instanceUrl($class, $id);

Requestor::request($this->client, 'delete', $url, $params, $beta);
Requestor::request($this->client, HttpMethod::DELETE, $url, $params, $beta);
}

/**
Expand All @@ -224,15 +225,15 @@ protected function deleteResource(string $class, string $id, mixed $params = nul
* @param string $class
* @param string $id
* @param mixed $params
* @param string $method
* @param HttpMethod|string $method
* @param bool $beta
* @return mixed
*/
protected function updateResource(
string $class,
string $id,
mixed $params = null,
string $method = 'patch',
HttpMethod|string $method = HttpMethod::PATCH,
bool $beta = false
): mixed {
self::validate();
Expand Down
11 changes: 6 additions & 5 deletions lib/EasyPost/Service/BatchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasyPost\Service;

use EasyPost\Http\HttpMethod;
use EasyPost\Http\Requestor;
use EasyPost\Util\InternalUtil;

Expand Down Expand Up @@ -55,7 +56,7 @@ public function create(mixed $params = null): mixed
public function buy(string $id, mixed $params = null): mixed
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/buy';
$response = Requestor::request($this->client, 'post', $url, $params);
$response = Requestor::request($this->client, HttpMethod::POST, $url, $params);

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -70,7 +71,7 @@ public function buy(string $id, mixed $params = null): mixed
public function label(string $id, mixed $params = null): mixed
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/label';
$response = Requestor::request($this->client, 'post', $url, $params);
$response = Requestor::request($this->client, HttpMethod::POST, $url, $params);

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -85,7 +86,7 @@ public function label(string $id, mixed $params = null): mixed
public function removeShipments(string $id, mixed $params = null): mixed
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/remove_shipments';
$response = Requestor::request($this->client, 'post', $url, $params);
$response = Requestor::request($this->client, HttpMethod::POST, $url, $params);

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -100,7 +101,7 @@ public function removeShipments(string $id, mixed $params = null): mixed
public function addShipments(string $id, mixed $params = null): mixed
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/add_shipments';
$response = Requestor::request($this->client, 'post', $url, $params);
$response = Requestor::request($this->client, HttpMethod::POST, $url, $params);

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -115,7 +116,7 @@ public function addShipments(string $id, mixed $params = null): mixed
public function createScanForm(string $id, mixed $params = null): mixed
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/scan_form';
$response = Requestor::request($this->client, 'post', $url, $params);
$response = Requestor::request($this->client, HttpMethod::POST, $url, $params);

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/EasyPost/Service/BetaRateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasyPost\Service;

use EasyPost\Http\HttpMethod;
use EasyPost\Http\Requestor;
use EasyPost\Util\InternalUtil;

Expand All @@ -22,7 +23,7 @@ public function retrieveStatelessRates(mixed $params): mixed
'shipment' => $params,
];

$response = Requestor::request($this->client, 'post', '/rates', $wrappedParams, true);
$response = Requestor::request($this->client, HttpMethod::POST, '/rates', $wrappedParams, true);

return InternalUtil::convertToEasyPostObject($this->client, $response['rates']);
}
Expand Down
Loading
Loading