diff --git a/CHANGELOG.md b/CHANGELOG.md index 96c9a74b..fc2d330b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `apiKey.delete` - `apiKey.enable` - `apiKey.disable` +- Adds `tracker.delete` function ## v8.4.0 (2025-11-24) diff --git a/lib/EasyPost/Service/TrackerService.php b/lib/EasyPost/Service/TrackerService.php index 80cd8e7a..052c9260 100644 --- a/lib/EasyPost/Service/TrackerService.php +++ b/lib/EasyPost/Service/TrackerService.php @@ -78,4 +78,15 @@ public function retrieveBatch(mixed $params = null): mixed return InternalUtil::convertToEasyPostObject($this->client, $response); } + + /** + * Delete a tracker. + * + * @param string $id + * @return void + */ + public function delete(string $id): void + { + $this->deleteResource(self::serviceModelClassName(self::class), $id); + } } diff --git a/test/EasyPost/TrackerTest.php b/test/EasyPost/TrackerTest.php index 45a97e44..1a703487 100644 --- a/test/EasyPost/TrackerTest.php +++ b/test/EasyPost/TrackerTest.php @@ -138,4 +138,21 @@ public function testRetrieveBatch(): void $this->assertContainsOnlyInstancesOf(Tracker::class, $trackers['trackers']); } + + /** + * Test deleting a Tracker. + */ + public function testDelete(): void + { + TestUtil::setupCassette('trackers/delete.yml'); + + $tracker = self::$client->tracker->create([ + 'tracking_code' => 'EZ1000000001', + ]); + + // Nothing gets returned here, simply ensure no error gets raised + self::$client->tracker->delete($tracker->id); + + $this->expectNotToPerformAssertions(); + } } diff --git a/test/cassettes/trackers/delete.yml b/test/cassettes/trackers/delete.yml new file mode 100644 index 00000000..369daa3d --- /dev/null +++ b/test/cassettes/trackers/delete.yml @@ -0,0 +1,171 @@ + +- + 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: 7dd2312b69824471e7897e420037d078 + cache-control: 'private, no-cache, no-store' + pragma: no-cache + expires: '0' + location: /api/v2/trackers/trk_bcdaf057b53541a3b0702a9115a04d0c + content-type: 'application/json; charset=utf-8' + content-length: '1691' + x-runtime: '0.063843' + x-node: bigweb35nuq + x-version-label: easypost-202602022215-5a5c93c546-master + x-backend: easypost + x-proxied: ['intlb3nuq 5f0235a1ab', 'extlb2nuq cbbd141214'] + strict-transport-security: 'max-age=31536000; includeSubDomains; preload' + body: '{"id":"trk_bcdaf057b53541a3b0702a9115a04d0c","object":"Tracker","mode":"test","tracking_code":"EZ1000000001","status":"pre_transit","status_detail":"status_update","created_at":"2025-11-05T22:45:06Z","updated_at":"2025-11-05T22:45:06Z","signed_by":null,"weight":null,"est_delivery_date":"2025-11-05T22:45:06Z","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":"2025-10-05T22:45:06Z","source":"USPS","carrier_code":"","tracking_location":{"object":"TrackingLocation","city":null,"state":null,"country":null,"zip":null},"est_delivery_date":null},{"object":"TrackingDetail","message":"Shipping Label Created","description":"","status":"pre_transit","status_detail":"status_update","datetime":"2025-10-06T11:22:06Z","source":"USPS","carrier_code":"","tracking_location":{"object":"TrackingLocation","city":"HOUSTON","state":"TX","country":null,"zip":"77063"},"est_delivery_date":null}],"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},"delivery_evidence":[],"finalized":true,"is_return":false,"public_url":"https:\/\/track.easypost.com\/djE6dHJrX2JjZGFmMDU3YjUzNTQxYTNiMDcwMmE5MTE1YTA0ZDBj"}' + curl_info: + url: 'https://api.easypost.com/v2/trackers' + content_type: 'application/json; charset=utf-8' + http_code: 200 + header_size: 754 + request_size: 349 + filetime: -1 + ssl_verify_result: 0 + redirect_count: 0 + total_time: 0.291998 + namelookup_time: 0.003092 + connect_time: 0.073117 + pretransfer_time: 0.154808 + size_upload: 44.0 + size_download: 1691.0 + speed_download: 5791.0 + speed_upload: 150.0 + download_content_length: 1691.0 + upload_content_length: 44.0 + starttransfer_time: 0.291968 + redirect_time: 0.0 + redirect_url: 'https://api.easypost.com/api/v2/trackers/trk_bcdaf057b53541a3b0702a9115a04d0c' + primary_ip: 169.62.110.130 + certinfo: { } + primary_port: 443 + local_ip: 10.130.6.10 + local_port: 55704 + http_version: 2 + protocol: 2 + ssl_verifyresult: 0 + scheme: https + appconnect_time_us: 154735 + queue_time_us: 16 + connect_time_us: 73117 + namelookup_time_us: 3092 + pretransfer_time_us: 154808 + redirect_time_us: 0 + starttransfer_time_us: 291968 + posttransfer_time_us: 154807 + total_time_us: 291998 + effective_method: POST + capath: '' + cainfo: '' + used_proxy: 0 + httpauth_used: 0 + proxyauth_used: 0 + conn_id: 0 + index: 0 +- + request: + method: DELETE + url: 'https://api.easypost.com/v2/trackers/trk_bcdaf057b53541a3b0702a9115a04d0c' + headers: + Host: api.easypost.com + Accept-Encoding: '' + Accept: application/json + Authorization: '' + Content-Type: application/json + User-Agent: '' + 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: 7dd2313269824471e7897e460037d0cc + cache-control: 'private, no-cache, no-store' + pragma: no-cache + expires: '0' + content-type: 'application/json; charset=utf-8' + content-length: '16' + x-runtime: '0.035649' + x-node: bigweb43nuq + x-version-label: easypost-202602022215-5a5c93c546-master + x-backend: easypost + x-canary: direct + x-proxied: ['intlb3nuq 5f0235a1ab', 'extlb2nuq cbbd141214'] + strict-transport-security: 'max-age=31536000; includeSubDomains; preload' + body: '{"success":true}' + curl_info: + url: 'https://api.easypost.com/v2/trackers/trk_bcdaf057b53541a3b0702a9115a04d0c' + content_type: 'application/json; charset=utf-8' + http_code: 200 + header_size: 705 + request_size: 324 + filetime: -1 + ssl_verify_result: 0 + redirect_count: 0 + total_time: 0.257695 + namelookup_time: 0.002345 + connect_time: 0.074825 + pretransfer_time: 0.147748 + size_upload: 0.0 + size_download: 16.0 + speed_download: 62.0 + speed_upload: 0.0 + download_content_length: 16.0 + upload_content_length: 0.0 + starttransfer_time: 0.257679 + redirect_time: 0.0 + redirect_url: '' + primary_ip: 169.62.110.130 + certinfo: { } + primary_port: 443 + local_ip: 10.130.6.10 + local_port: 55708 + http_version: 2 + protocol: 2 + ssl_verifyresult: 0 + scheme: https + appconnect_time_us: 147720 + queue_time_us: 17 + connect_time_us: 74825 + namelookup_time_us: 2345 + pretransfer_time_us: 147748 + redirect_time_us: 0 + starttransfer_time_us: 257679 + posttransfer_time_us: 147748 + total_time_us: 257695 + effective_method: DELETE + capath: '' + cainfo: '' + used_proxy: 0 + httpauth_used: 0 + proxyauth_used: 0 + conn_id: 0 + index: 0