Skip to content

Commit 1895393

Browse files
committed
fix: put back trackers wrapping logic
1 parent 6cc8ca5 commit 1895393

File tree

4 files changed

+107
-3
lines changed

4 files changed

+107
-3
lines changed

lib/EasyPost/Service/ShipmentService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function refund(string $id, mixed $params = null): mixed
142142
*/
143143
public function label(string $id, mixed $params = null): mixed
144144
{
145-
// Don't use InternalUtil::wrapParams here
145+
// TODO: only accept wrapped params
146146
if (!isset($params['file_format'])) {
147147
$clone = $params;
148148
unset($params);
@@ -164,7 +164,7 @@ public function label(string $id, mixed $params = null): mixed
164164
*/
165165
public function insure(string $id, mixed $params = null): mixed
166166
{
167-
// Don't use InternalUtil::wrapParams here
167+
// TODO: Only accept wrapped params
168168
if (!isset($params['amount'])) {
169169
$clone = $params;
170170
unset($params);

lib/EasyPost/Service/TrackerService.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ public function getNextPage(mixed $trackers, ?int $pageSize = null): mixed
5252
*/
5353
public function create(mixed $params = null): mixed
5454
{
55-
$params = InternalUtil::wrapParams($params, 'tracker');
55+
// TODO: only accept wrapped params
56+
if (!is_array($params)) {
57+
$clone = $params;
58+
unset($params);
59+
$params['tracker']['tracking_code'] = $clone;
60+
} elseif (!isset($params['tracker']) || !is_array($params['tracker'])) {
61+
$clone = $params;
62+
unset($params);
63+
$params['tracker'] = $clone;
64+
}
5665

5766
return self::createResource(self::serviceModelClassName(self::class), $params);
5867
}

test/EasyPost/TrackerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ public function testCreate(): void
4545
$this->assertEquals('pre_transit', $tracker->status);
4646
}
4747

48+
/**
49+
* Test creating a Tracker when we don't wrap the param.
50+
*/
51+
public function testCreateUnwrappedParam(): void
52+
{
53+
TestUtil::setupCassette('trackers/createUnwrappedParam.yml');
54+
55+
$tracker = self::$client->tracker->create('EZ1000000001');
56+
57+
$this->assertInstanceOf(Tracker::class, $tracker);
58+
$this->assertStringMatchesFormat('trk_%s', $tracker->id);
59+
$this->assertEquals('pre_transit', $tracker->status);
60+
}
61+
4862
/**
4963
* Test retrieving a Tracker.
5064
*/

test/cassettes/trackers/createUnwrappedParam.yml

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)