From 6cc8ca5f3ee2b1e52a0477d4e645805261b9591b Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 16 Jun 2025 13:43:30 -0600 Subject: [PATCH 1/3] chore: refactor wrapping params code into utility function --- lib/EasyPost/Service/AddressService.php | 6 +- lib/EasyPost/Service/BatchService.php | 6 +- .../Service/CarrierAccountService.php | 6 +- lib/EasyPost/Service/CustomsInfoService.php | 8 +- lib/EasyPost/Service/CustomsItemService.php | 8 +- lib/EasyPost/Service/EndShipperService.php | 14 +--- lib/EasyPost/Service/InsuranceService.php | 6 +- lib/EasyPost/Service/LumaService.php | 6 +- lib/EasyPost/Service/OrderService.php | 7 +- lib/EasyPost/Service/ParcelService.php | 8 +- lib/EasyPost/Service/PickupService.php | 6 +- .../Service/ReferralCustomerService.php | 6 +- lib/EasyPost/Service/RefundService.php | 8 +- lib/EasyPost/Service/ShipmentService.php | 15 ++-- lib/EasyPost/Service/TrackerService.php | 10 +-- lib/EasyPost/Service/UserService.php | 12 +-- lib/EasyPost/Service/WebhookService.php | 8 +- lib/EasyPost/Util/InternalUtil.php | 18 +++++ test/EasyPost/TrackerTest.php | 14 ---- .../trackers/createUnwrappedParam.yml | 81 ------------------- 20 files changed, 54 insertions(+), 199 deletions(-) delete mode 100644 test/cassettes/trackers/createUnwrappedParam.yml 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..6a71328f 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 { + // Don't use InternalUtil::wrapParams here 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 { + // Don't use InternalUtil::wrapParams here 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..12c20aee 100644 --- a/lib/EasyPost/Service/TrackerService.php +++ b/lib/EasyPost/Service/TrackerService.php @@ -52,15 +52,7 @@ public function getNextPage(mixed $trackers, ?int $pageSize = null): mixed */ public function create(mixed $params = null): mixed { - if (!is_array($params)) { - $clone = $params; - unset($params); - $params['tracker']['tracking_code'] = $clone; - } elseif (!isset($params['tracker']) || !is_array($params['tracker'])) { - $clone = $params; - unset($params); - $params['tracker'] = $clone; - } + $params = InternalUtil::wrapParams($params, 'tracker'); return self::createResource(self::serviceModelClassName(self::class), $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; + } } diff --git a/test/EasyPost/TrackerTest.php b/test/EasyPost/TrackerTest.php index d7afbfbc..82353717 100644 --- a/test/EasyPost/TrackerTest.php +++ b/test/EasyPost/TrackerTest.php @@ -45,20 +45,6 @@ public function testCreate(): void $this->assertEquals('pre_transit', $tracker->status); } - /** - * Test creating a Tracker when we don't wrap the param. - */ - public function testCreateUnwrappedParam(): void - { - TestUtil::setupCassette('trackers/createUnwrappedParam.yml'); - - $tracker = self::$client->tracker->create('EZ1000000001'); - - $this->assertInstanceOf(Tracker::class, $tracker); - $this->assertStringMatchesFormat('trk_%s', $tracker->id); - $this->assertEquals('pre_transit', $tracker->status); - } - /** * Test retrieving a Tracker. */ diff --git a/test/cassettes/trackers/createUnwrappedParam.yml b/test/cassettes/trackers/createUnwrappedParam.yml deleted file mode 100644 index eccae544..00000000 --- a/test/cassettes/trackers/createUnwrappedParam.yml +++ /dev/null @@ -1,81 +0,0 @@ - -- - request: - method: POST - url: 'https://api.easypost.com/v2/trackers' - headers: - Host: api.easypost.com - Expect: '' - Accept-Encoding: '' - Accept: application/json - Authorization: '' - Content-Type: application/json - User-Agent: '' - body: '{"tracker":{"tracking_code":"EZ1000000001"}}' - response: - status: - code: 200 - message: OK - headers: - x-frame-options: SAMEORIGIN - x-xss-protection: '1; mode=block' - x-content-type-options: nosniff - x-download-options: noopen - x-permitted-cross-domain-policies: none - referrer-policy: strict-origin-when-cross-origin - x-ep-request-uuid: e181587866bcec22e2b90438008721e0 - cache-control: 'private, no-cache, no-store' - pragma: no-cache - expires: '0' - location: /api/v2/trackers/trk_1c9f7586ac174a389f476d4bbdaff639 - content-type: 'application/json; charset=utf-8' - content-length: '1618' - x-runtime: '0.059724' - x-node: bigweb40nuq - x-version-label: easypost-202408141633-8ef9a7bcc9-master - x-backend: easypost - x-proxied: ['intlb3nuq c0f5e722d1', 'extlb2nuq b6e1b5034c'] - strict-transport-security: 'max-age=31536000; includeSubDomains; preload' - body: '{"id":"trk_1c9f7586ac174a389f476d4bbdaff639","object":"Tracker","mode":"test","tracking_code":"EZ1000000001","status":"pre_transit","status_detail":"status_update","created_at":"2024-08-14T17:38:46Z","updated_at":"2024-08-14T17:38:46Z","signed_by":null,"weight":null,"est_delivery_date":"2024-08-14T17:38:46Z","shipment_id":null,"carrier":"USPS","tracking_details":[{"object":"TrackingDetail","message":"Pre-Shipment Info Sent to USPS","description":"","status":"pre_transit","status_detail":"status_update","datetime":"2024-07-14T17:38:46Z","source":"USPS","carrier_code":"","tracking_location":{"object":"TrackingLocation","city":null,"state":null,"country":null,"zip":null}},{"object":"TrackingDetail","message":"Shipping Label Created","description":"","status":"pre_transit","status_detail":"status_update","datetime":"2024-07-15T06:15:46Z","source":"USPS","carrier_code":"","tracking_location":{"object":"TrackingLocation","city":"HOUSTON","state":"TX","country":null,"zip":"77063"}}],"carrier_detail":{"object":"CarrierDetail","service":"First-Class Package Service","container_type":null,"est_delivery_date_local":null,"est_delivery_time_local":null,"origin_location":"HOUSTON TX, 77001","origin_tracking_location":{"object":"TrackingLocation","city":"HOUSTON","state":"TX","country":null,"zip":"77063"},"destination_location":"CHARLESTON SC, 29401","destination_tracking_location":null,"guaranteed_delivery_date":null,"alternate_identifier":null,"initial_delivery_attempt":null},"finalized":true,"is_return":false,"public_url":"https:\/\/track.easypost.com\/djE6dHJrXzFjOWY3NTg2YWMxNzRhMzg5ZjQ3NmQ0YmJkYWZmNjM5"}' - curl_info: - url: 'https://api.easypost.com/v2/trackers' - content_type: 'application/json; charset=utf-8' - http_code: 200 - header_size: 754 - request_size: 350 - filetime: -1 - ssl_verify_result: 0 - redirect_count: 0 - total_time: 0.156398 - namelookup_time: 0.002097 - connect_time: 0.031247 - pretransfer_time: 0.063944 - size_upload: 44.0 - size_download: 1618.0 - speed_download: 10345.0 - speed_upload: 281.0 - download_content_length: 1618.0 - upload_content_length: 44.0 - starttransfer_time: 0.156366 - redirect_time: 0.0 - redirect_url: '' - primary_ip: 169.62.110.130 - certinfo: { } - primary_port: 443 - local_ip: 192.168.1.75 - local_port: 52863 - http_version: 2 - protocol: 2 - ssl_verifyresult: 0 - scheme: https - appconnect_time_us: 63900 - connect_time_us: 31247 - namelookup_time_us: 2097 - pretransfer_time_us: 63944 - redirect_time_us: 0 - starttransfer_time_us: 156366 - total_time_us: 156398 - effective_method: POST - capath: '' - cainfo: '' - index: 0 From 189539376c04391ad50f13a85a82ab8d20d7a356 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:11:00 -0600 Subject: [PATCH 2/3] fix: put back trackers wrapping logic --- lib/EasyPost/Service/ShipmentService.php | 4 +- lib/EasyPost/Service/TrackerService.php | 11 ++- test/EasyPost/TrackerTest.php | 14 ++++ .../trackers/createUnwrappedParam.yml | 81 +++++++++++++++++++ 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 test/cassettes/trackers/createUnwrappedParam.yml diff --git a/lib/EasyPost/Service/ShipmentService.php b/lib/EasyPost/Service/ShipmentService.php index 6a71328f..b1a4a595 100644 --- a/lib/EasyPost/Service/ShipmentService.php +++ b/lib/EasyPost/Service/ShipmentService.php @@ -142,7 +142,7 @@ public function refund(string $id, mixed $params = null): mixed */ public function label(string $id, mixed $params = null): mixed { - // Don't use InternalUtil::wrapParams here + // TODO: only accept wrapped params if (!isset($params['file_format'])) { $clone = $params; unset($params); @@ -164,7 +164,7 @@ public function label(string $id, mixed $params = null): mixed */ public function insure(string $id, mixed $params = null): mixed { - // Don't use InternalUtil::wrapParams here + // TODO: Only accept wrapped params if (!isset($params['amount'])) { $clone = $params; unset($params); diff --git a/lib/EasyPost/Service/TrackerService.php b/lib/EasyPost/Service/TrackerService.php index 12c20aee..cdd1eba0 100644 --- a/lib/EasyPost/Service/TrackerService.php +++ b/lib/EasyPost/Service/TrackerService.php @@ -52,7 +52,16 @@ public function getNextPage(mixed $trackers, ?int $pageSize = null): mixed */ public function create(mixed $params = null): mixed { - $params = InternalUtil::wrapParams($params, 'tracker'); + // TODO: only accept wrapped params + if (!is_array($params)) { + $clone = $params; + unset($params); + $params['tracker']['tracking_code'] = $clone; + } elseif (!isset($params['tracker']) || !is_array($params['tracker'])) { + $clone = $params; + unset($params); + $params['tracker'] = $clone; + } return self::createResource(self::serviceModelClassName(self::class), $params); } diff --git a/test/EasyPost/TrackerTest.php b/test/EasyPost/TrackerTest.php index 82353717..d7afbfbc 100644 --- a/test/EasyPost/TrackerTest.php +++ b/test/EasyPost/TrackerTest.php @@ -45,6 +45,20 @@ public function testCreate(): void $this->assertEquals('pre_transit', $tracker->status); } + /** + * Test creating a Tracker when we don't wrap the param. + */ + public function testCreateUnwrappedParam(): void + { + TestUtil::setupCassette('trackers/createUnwrappedParam.yml'); + + $tracker = self::$client->tracker->create('EZ1000000001'); + + $this->assertInstanceOf(Tracker::class, $tracker); + $this->assertStringMatchesFormat('trk_%s', $tracker->id); + $this->assertEquals('pre_transit', $tracker->status); + } + /** * Test retrieving a Tracker. */ diff --git a/test/cassettes/trackers/createUnwrappedParam.yml b/test/cassettes/trackers/createUnwrappedParam.yml new file mode 100644 index 00000000..6529cf7a --- /dev/null +++ b/test/cassettes/trackers/createUnwrappedParam.yml @@ -0,0 +1,81 @@ + +- + request: + method: POST + url: 'https://api.easypost.com/v2/trackers' + headers: + Host: api.easypost.com + Expect: '' + Accept-Encoding: '' + Accept: application/json + Authorization: '' + Content-Type: application/json + User-Agent: '' + body: '{"tracker":{"tracking_code":"EZ1000000001"}}' + response: + status: + code: 200 + message: OK + headers: + x-frame-options: SAMEORIGIN + x-xss-protection: '1; mode=block' + x-content-type-options: nosniff + x-download-options: noopen + x-permitted-cross-domain-policies: none + referrer-policy: strict-origin-when-cross-origin + x-ep-request-uuid: e181587866bcec22e2b90438008721e0 + cache-control: 'private, no-cache, no-store' + pragma: no-cache + expires: '0' + location: /api/v2/trackers/trk_1c9f7586ac174a389f476d4bbdaff639 + content-type: 'application/json; charset=utf-8' + content-length: '1618' + x-runtime: '0.059724' + x-node: bigweb40nuq + x-version-label: easypost-202408141633-8ef9a7bcc9-master + x-backend: easypost + x-proxied: ['intlb3nuq c0f5e722d1', 'extlb2nuq b6e1b5034c'] + strict-transport-security: 'max-age=31536000; includeSubDomains; preload' + body: '{"id":"trk_1c9f7586ac174a389f476d4bbdaff639","object":"Tracker","mode":"test","tracking_code":"EZ1000000001","status":"pre_transit","status_detail":"status_update","created_at":"2024-08-14T17:38:46Z","updated_at":"2024-08-14T17:38:46Z","signed_by":null,"weight":null,"est_delivery_date":"2024-08-14T17:38:46Z","shipment_id":null,"carrier":"USPS","tracking_details":[{"object":"TrackingDetail","message":"Pre-Shipment Info Sent to USPS","description":"","status":"pre_transit","status_detail":"status_update","datetime":"2024-07-14T17:38:46Z","source":"USPS","carrier_code":"","tracking_location":{"object":"TrackingLocation","city":null,"state":null,"country":null,"zip":null}},{"object":"TrackingDetail","message":"Shipping Label Created","description":"","status":"pre_transit","status_detail":"status_update","datetime":"2024-07-15T06:15:46Z","source":"USPS","carrier_code":"","tracking_location":{"object":"TrackingLocation","city":"HOUSTON","state":"TX","country":null,"zip":"77063"}}],"carrier_detail":{"object":"CarrierDetail","service":"First-Class Package Service","container_type":null,"est_delivery_date_local":null,"est_delivery_time_local":null,"origin_location":"HOUSTON TX, 77001","origin_tracking_location":{"object":"TrackingLocation","city":"HOUSTON","state":"TX","country":null,"zip":"77063"},"destination_location":"CHARLESTON SC, 29401","destination_tracking_location":null,"guaranteed_delivery_date":null,"alternate_identifier":null,"initial_delivery_attempt":null},"finalized":true,"is_return":false,"public_url":"https:\/\/track.easypost.com\/djE6dHJrXzFjOWY3NTg2YWMxNzRhMzg5ZjQ3NmQ0YmJkYWZmNjM5"}' + curl_info: + url: 'https://api.easypost.com/v2/trackers' + content_type: 'application/json; charset=utf-8' + http_code: 200 + header_size: 754 + request_size: 350 + filetime: -1 + ssl_verify_result: 0 + redirect_count: 0 + total_time: 0.156398 + namelookup_time: 0.002097 + connect_time: 0.031247 + pretransfer_time: 0.063944 + size_upload: 44.0 + size_download: 1618.0 + speed_download: 10345.0 + speed_upload: 281.0 + download_content_length: 1618.0 + upload_content_length: 44.0 + starttransfer_time: 0.156366 + redirect_time: 0.0 + redirect_url: '' + primary_ip: 169.62.110.130 + certinfo: { } + primary_port: 443 + local_ip: 192.168.1.75 + local_port: 52863 + http_version: 2 + protocol: 2 + ssl_verifyresult: 0 + scheme: https + appconnect_time_us: 63900 + connect_time_us: 31247 + namelookup_time_us: 2097 + pretransfer_time_us: 63944 + redirect_time_us: 0 + starttransfer_time_us: 156366 + total_time_us: 156398 + effective_method: POST + capath: '' + cainfo: '' + index: 0 \ No newline at end of file From 0f250a0fdfe93f122834d96cca87f3b51aa1cf47 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:12:56 -0600 Subject: [PATCH 3/3] chore: prep v8.2.0 for release --- CHANGELOG.md | 2 +- composer.json | 2 +- lib/EasyPost/Constant/Constants.php | 2 +- test/cassettes/trackers/createUnwrappedParam.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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/test/cassettes/trackers/createUnwrappedParam.yml b/test/cassettes/trackers/createUnwrappedParam.yml index 6529cf7a..eccae544 100644 --- a/test/cassettes/trackers/createUnwrappedParam.yml +++ b/test/cassettes/trackers/createUnwrappedParam.yml @@ -78,4 +78,4 @@ effective_method: POST capath: '' cainfo: '' - index: 0 \ No newline at end of file + index: 0