diff --git a/CHANGELOG.md b/CHANGELOG.md index ab9d7976..633bdeb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## Next Release +## v8.2.0 (2025-06-18) - Adds the following functions - `shipment.createAndBuyLuma` diff --git a/composer.json b/composer.json index e1ce70b0..620f0f0d 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/lib/EasyPost/Constant/Constants.php b/lib/EasyPost/Constant/Constants.php index a2bed2b9..aae196d6 100644 --- a/lib/EasyPost/Constant/Constants.php +++ b/lib/EasyPost/Constant/Constants.php @@ -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 diff --git a/lib/EasyPost/Service/AddressService.php b/lib/EasyPost/Service/AddressService.php index f089446b..351ddec9 100644 --- a/lib/EasyPost/Service/AddressService.php +++ b/lib/EasyPost/Service/AddressService.php @@ -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); diff --git a/lib/EasyPost/Service/BatchService.php b/lib/EasyPost/Service/BatchService.php index 7730f133..62f0edbc 100644 --- a/lib/EasyPost/Service/BatchService.php +++ b/lib/EasyPost/Service/BatchService.php @@ -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); } diff --git a/lib/EasyPost/Service/CarrierAccountService.php b/lib/EasyPost/Service/CarrierAccountService.php index 6483585a..efed6346 100644 --- a/lib/EasyPost/Service/CarrierAccountService.php +++ b/lib/EasyPost/Service/CarrierAccountService.php @@ -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); } diff --git a/lib/EasyPost/Service/CustomsInfoService.php b/lib/EasyPost/Service/CustomsInfoService.php index 11286823..fcd57878 100644 --- a/lib/EasyPost/Service/CustomsInfoService.php +++ b/lib/EasyPost/Service/CustomsInfoService.php @@ -2,6 +2,8 @@ namespace EasyPost\Service; +use EasyPost\Util\InternalUtil; + /** * CustomsInfo service containing all the logic to make API calls. */ @@ -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); } diff --git a/lib/EasyPost/Service/CustomsItemService.php b/lib/EasyPost/Service/CustomsItemService.php index cdab8d22..71bb862e 100644 --- a/lib/EasyPost/Service/CustomsItemService.php +++ b/lib/EasyPost/Service/CustomsItemService.php @@ -2,6 +2,8 @@ namespace EasyPost\Service; +use EasyPost\Util\InternalUtil; + /** * CustomsItem service containing all the logic to make API calls. */ @@ -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); } diff --git a/lib/EasyPost/Service/EndShipperService.php b/lib/EasyPost/Service/EndShipperService.php index 7f139249..b47e0d19 100644 --- a/lib/EasyPost/Service/EndShipperService.php +++ b/lib/EasyPost/Service/EndShipperService.php @@ -2,6 +2,8 @@ namespace EasyPost\Service; +use EasyPost\Util\InternalUtil; + /** * EndShipper service containing all the logic to make API calls. */ @@ -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); } @@ -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'); } diff --git a/lib/EasyPost/Service/InsuranceService.php b/lib/EasyPost/Service/InsuranceService.php index 469a09b2..555e8319 100644 --- a/lib/EasyPost/Service/InsuranceService.php +++ b/lib/EasyPost/Service/InsuranceService.php @@ -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); } diff --git a/lib/EasyPost/Service/LumaService.php b/lib/EasyPost/Service/LumaService.php index edc51749..0e12fa0c 100644 --- a/lib/EasyPost/Service/LumaService.php +++ b/lib/EasyPost/Service/LumaService.php @@ -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); diff --git a/lib/EasyPost/Service/OrderService.php b/lib/EasyPost/Service/OrderService.php index 1e212306..fb6d92a8 100644 --- a/lib/EasyPost/Service/OrderService.php +++ b/lib/EasyPost/Service/OrderService.php @@ -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); } @@ -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); diff --git a/lib/EasyPost/Service/ParcelService.php b/lib/EasyPost/Service/ParcelService.php index 68563331..070a635f 100644 --- a/lib/EasyPost/Service/ParcelService.php +++ b/lib/EasyPost/Service/ParcelService.php @@ -2,6 +2,8 @@ namespace EasyPost\Service; +use EasyPost\Util\InternalUtil; + /** * Parcel service containing all the logic to make API calls. */ @@ -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); } diff --git a/lib/EasyPost/Service/PickupService.php b/lib/EasyPost/Service/PickupService.php index 5d5415e5..3c91315c 100644 --- a/lib/EasyPost/Service/PickupService.php +++ b/lib/EasyPost/Service/PickupService.php @@ -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); } diff --git a/lib/EasyPost/Service/ReferralCustomerService.php b/lib/EasyPost/Service/ReferralCustomerService.php index 56cefdaf..44be0954 100644 --- a/lib/EasyPost/Service/ReferralCustomerService.php +++ b/lib/EasyPost/Service/ReferralCustomerService.php @@ -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); } diff --git a/lib/EasyPost/Service/RefundService.php b/lib/EasyPost/Service/RefundService.php index 419763d2..6f564b79 100644 --- a/lib/EasyPost/Service/RefundService.php +++ b/lib/EasyPost/Service/RefundService.php @@ -2,6 +2,8 @@ namespace EasyPost\Service; +use EasyPost\Util\InternalUtil; + /** * Refund service containing all the logic to make API calls. */ @@ -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); } diff --git a/lib/EasyPost/Service/ShipmentService.php b/lib/EasyPost/Service/ShipmentService.php index 08536c41..b1a4a595 100644 --- a/lib/EasyPost/Service/ShipmentService.php +++ b/lib/EasyPost/Service/ShipmentService.php @@ -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); } @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/lib/EasyPost/Service/TrackerService.php b/lib/EasyPost/Service/TrackerService.php index 90f4d1a3..cdd1eba0 100644 --- a/lib/EasyPost/Service/TrackerService.php +++ b/lib/EasyPost/Service/TrackerService.php @@ -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); diff --git a/lib/EasyPost/Service/UserService.php b/lib/EasyPost/Service/UserService.php index 87a2afb1..a3302ff0 100644 --- a/lib/EasyPost/Service/UserService.php +++ b/lib/EasyPost/Service/UserService.php @@ -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); } @@ -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); } diff --git a/lib/EasyPost/Service/WebhookService.php b/lib/EasyPost/Service/WebhookService.php index b84d5faa..a9edc293 100644 --- a/lib/EasyPost/Service/WebhookService.php +++ b/lib/EasyPost/Service/WebhookService.php @@ -2,6 +2,8 @@ namespace EasyPost\Service; +use EasyPost\Util\InternalUtil; + /** * Webhook service containing all the logic to make API calls. */ @@ -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); } diff --git a/lib/EasyPost/Util/InternalUtil.php b/lib/EasyPost/Util/InternalUtil.php index ac5d8b65..63aaa6c8 100644 --- a/lib/EasyPost/Util/InternalUtil.php +++ b/lib/EasyPost/Util/InternalUtil.php @@ -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; + } }