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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG

## Next Release
## v8.2.0 (2025-06-18)

- Adds the following functions
- `shipment.createAndBuyLuma`
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.1.0",
"version": "8.2.0",
"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.0.1';
const LIBRARY_VERSION = '8.2.0';
const SUPPORT_EMAIL = 'support@easypost.com';

// Validation
Expand Down
6 changes: 1 addition & 5 deletions lib/EasyPost/Service/AddressService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ public function create(mixed $params = null): mixed
*/
public function createAndVerify(mixed $params = null): mixed
{
if (!isset($params['address']) || !is_array($params['address'])) {
$clone = $params;
unset($params);
$params['address'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'address');

$url = self::classUrl(self::serviceModelClassName(self::class));
$response = Requestor::request($this->client, 'post', $url . '/create_and_verify', $params);
Expand Down
6 changes: 1 addition & 5 deletions lib/EasyPost/Service/BatchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public function all(mixed $params = null): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['batch']) || !is_array($params['batch'])) {
$clone = $params;
unset($params);
$params['batch'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'batch');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/EasyPost/Service/CarrierAccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public function all(mixed $params = null): mixed
*/
public function update(string $id, mixed $params): mixed
{
if (!isset($params['carrier_account']) || !is_array($params['carrier_account'])) {
$clone = $params;
unset($params);
$params['carrier_account'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'carrier_account');

return self::updateResource(self::serviceModelClassName(self::class), $id, $params);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/EasyPost/Service/CustomsInfoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EasyPost\Service;

use EasyPost\Util\InternalUtil;

/**
* CustomsInfo service containing all the logic to make API calls.
*/
Expand All @@ -26,11 +28,7 @@ public function retrieve(string $id): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['customs_info']) || !is_array($params['customs_info'])) {
$clone = $params;
unset($params);
$params['customs_info'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'customs_info');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/EasyPost/Service/CustomsItemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EasyPost\Service;

use EasyPost\Util\InternalUtil;

/**
* CustomsItem service containing all the logic to make API calls.
*/
Expand All @@ -26,11 +28,7 @@ public function retrieve(string $id): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['customs_item']) || !is_array($params['customs_item'])) {
$clone = $params;
unset($params);
$params['customs_item'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'customs_item');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
14 changes: 4 additions & 10 deletions lib/EasyPost/Service/EndShipperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EasyPost\Service;

use EasyPost\Util\InternalUtil;

/**
* EndShipper service containing all the logic to make API calls.
*/
Expand All @@ -15,11 +17,7 @@ class EndShipperService extends BaseService
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['address']) || !is_array($params['address'])) {
$clone = $params;
unset($params);
$params['address'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'address');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down Expand Up @@ -55,11 +53,7 @@ public function all(mixed $params = null): mixed
*/
public function update(string $id, mixed $params): mixed
{
if (!isset($params['address']) || !is_array($params['address'])) {
$clone = $params;
unset($params);
$params['address'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'address');

return self::updateResource(self::serviceModelClassName(self::class), $id, $params, 'put');
}
Expand Down
6 changes: 1 addition & 5 deletions lib/EasyPost/Service/InsuranceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public function getNextPage(mixed $insurances, ?int $pageSize = null): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['insurance']) || !is_array($params['insurance'])) {
$clone = $params;
unset($params);
$params['insurance'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'insurance');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/EasyPost/Service/LumaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ class LumaService extends BaseService
*/
public function getPromise(array $params): mixed
{
if (!isset($params['shipment']) || !is_array($params['shipment'])) {
$clone = $params;
unset($params);
$params['shipment'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'shipment');

$url = '/luma/promise';
$response = Requestor::request($this->client, 'post', $url, $params);
Expand Down
7 changes: 2 additions & 5 deletions lib/EasyPost/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public function retrieve(string $id): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['order']) || !is_array($params['order'])) {
$clone = $params;
unset($params);
$params['order'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'order');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down Expand Up @@ -63,6 +59,7 @@ public function getRates(string $id, mixed $params = null): mixed
*/
public function buy(string $id, mixed $params = null): mixed
{
// Don't use InternalUtil::wrapParams here
if ($params instanceof Rate) {
$clone = $params;
unset($params);
Expand Down
8 changes: 3 additions & 5 deletions lib/EasyPost/Service/ParcelService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EasyPost\Service;

use EasyPost\Util\InternalUtil;

/**
* Parcel service containing all the logic to make API calls.
*/
Expand All @@ -26,11 +28,7 @@ public function retrieve(string $id): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['parcel']) || !is_array($params['parcel'])) {
$clone = $params;
unset($params);
$params['parcel'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'parcel');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/EasyPost/Service/PickupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public function getNextPage(mixed $pickups, ?int $pageSize = null): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['pickup']) || !is_array($params['pickup'])) {
$clone = $params;
unset($params);
$params['pickup'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'pickup');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/EasyPost/Service/ReferralCustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ public function getNextPage(mixed $referrals, ?int $pageSize = null): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['user']) || !is_array($params['user'])) {
$clone = $params;
unset($params);
$params['user'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'user');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/EasyPost/Service/RefundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EasyPost\Service;

use EasyPost\Util\InternalUtil;

/**
* Refund service containing all the logic to make API calls.
*/
Expand Down Expand Up @@ -49,11 +51,7 @@ public function getNextPage(mixed $refunds, ?int $pageSize = null): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['refund']) || !is_array($params['refund'])) {
$clone = $params;
unset($params);
$params['refund'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'refund');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
15 changes: 5 additions & 10 deletions lib/EasyPost/Service/ShipmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ public function getNextPage(mixed $shipments, ?int $pageSize = null): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['shipment']) || !is_array($params['shipment'])) {
$clone = $params;
unset($params);
$params['shipment'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'shipment');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down Expand Up @@ -104,6 +100,7 @@ public function getSmartRates(string $id): array
*/
public function buy(string $id, mixed $params = null, string|bool $endShipperId = false)
{
// Don't use InternalUtil::wrapParams here
if (isset($params['id']) && (!isset($params['rate']) || !is_array($params['rate']))) {
$clone = $params;
unset($params);
Expand Down Expand Up @@ -145,6 +142,7 @@ public function refund(string $id, mixed $params = null): mixed
*/
public function label(string $id, mixed $params = null): mixed
{
// TODO: only accept wrapped params
if (!isset($params['file_format'])) {
$clone = $params;
unset($params);
Expand All @@ -166,6 +164,7 @@ public function label(string $id, mixed $params = null): mixed
*/
public function insure(string $id, mixed $params = null): mixed
{
// TODO: Only accept wrapped params
if (!isset($params['amount'])) {
$clone = $params;
unset($params);
Expand Down Expand Up @@ -263,11 +262,7 @@ public function recommendShipDate(string $id, string $desiredDeliveryDate): mixe
*/
public function createAndBuyLuma(array $params): mixed
{
if (!isset($params['shipment']) || !is_array($params['shipment'])) {
$clone = $params;
unset($params);
$params['shipment'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'shipment');

$url = self::classUrl(self::serviceModelClassName(self::class)) . '/luma';
$response = Requestor::request($this->client, 'post', $url, $params);
Expand Down
1 change: 1 addition & 0 deletions lib/EasyPost/Service/TrackerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function getNextPage(mixed $trackers, ?int $pageSize = null): mixed
*/
public function create(mixed $params = null): mixed
{
// TODO: only accept wrapped params
if (!is_array($params)) {
$clone = $params;
unset($params);
Expand Down
12 changes: 2 additions & 10 deletions lib/EasyPost/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ public function retrieve(string $id): mixed
*/
public function update(string $id, mixed $params): mixed
{
if (!isset($params['user']) || !is_array($params['user'])) {
$clone = $params;
unset($params);
$params['user'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'user');

return $this->updateResource(self::serviceModelClassName(self::class), $id, $params);
}
Expand All @@ -48,11 +44,7 @@ public function update(string $id, mixed $params): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['user']) || !is_array($params['user'])) {
$clone = $params;
unset($params);
$params['user'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'user');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/EasyPost/Service/WebhookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace EasyPost\Service;

use EasyPost\Util\InternalUtil;

/**
* Webhook service containing all the logic to make API calls.
*/
Expand Down Expand Up @@ -61,11 +63,7 @@ public function update(string $id, mixed $params = null): mixed
*/
public function create(mixed $params = null): mixed
{
if (!isset($params['webhook']) || !is_array($params['webhook'])) {
$clone = $params;
unset($params);
$params['webhook'] = $clone;
}
$params = InternalUtil::wrapParams($params, 'webhook');

return self::createResource(self::serviceModelClassName(self::class), $params);
}
Expand Down
18 changes: 18 additions & 0 deletions lib/EasyPost/Util/InternalUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,22 @@ public static function getLowestObjectRate(

return $lowestRate;
}

/**
* Wraps the params in a key.
*
* @param mixed $params
* @param string $keyName
* @return mixed
*/
public static function wrapParams(mixed $params, string $keyName): mixed
{
if (!isset($params[$keyName]) || !is_array($params[$keyName])) {
$clone = $params;
unset($params);
$params[$keyName] = $clone;
}

return $params;
}
}
Loading