Skip to content

Commit b469f50

Browse files
authored
Merge pull request #348 from EasyPost/webhook_fixtures
fix: webhook fixture, addCreditCard params
2 parents 7ab2a17 + feee9f4 commit b469f50

File tree

152 files changed

+7436
-7127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+7436
-7127
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Fixes an issue with how query params were sent when using the `addCreditCard` function
6+
37
## v7.4.1 (2024-08-09)
48

59
- Fix parameters for retrieving next page of child users

examples

Submodule examples updated 44 files

lib/EasyPost/Http/Requestor.php

-35
Original file line numberDiff line numberDiff line change
@@ -91,41 +91,6 @@ private static function encodeObjects(mixed $data): array|string
9191
}
9292
}
9393

94-
/**
95-
* URL Encodes data for GET requests.
96-
*
97-
* @param mixed $arr
98-
* @param string|null $prefix
99-
* @return string
100-
*/
101-
public static function urlEncode(mixed $arr, ?string $prefix = null): string
102-
{
103-
if (!is_array($arr)) {
104-
return $arr;
105-
}
106-
107-
$r = [];
108-
foreach ($arr as $k => $v) {
109-
if (is_null($v)) {
110-
continue;
111-
}
112-
113-
if (isset($prefix)) {
114-
$k = $prefix . '[' . $k . ']';
115-
} else {
116-
$k = $prefix . '[]';
117-
}
118-
119-
if (is_array($v)) {
120-
$r[] = self::urlEncode($v, $k);
121-
} else {
122-
$r[] = urlencode($k) . '=' . urlencode($v);
123-
}
124-
}
125-
126-
return implode('&', $r);
127-
}
128-
12994
/**
13095
* Make a request to the EasyPost API.
13196
*

lib/EasyPost/Service/ReferralCustomerService.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ private function createStripeToken(
162162
]
163163
];
164164

165-
$formEncodedParams = Requestor::urlEncode($creditCardDetails);
166-
$url = "https://api.stripe.com/v1/tokens?$formEncodedParams";
165+
$url = 'https://api.stripe.com/v1/tokens';
167166

168167
$guzzleClient = new Client();
169168

169+
$requestOptions['query'] = $creditCardDetails;
170170
$requestOptions['headers'] = $headers;
171171
$requestOptions['http_errors'] = false;
172172

test/EasyPost/BetaReferralCustomerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testAddPaymentMethod(): void
4444
'primary'
4545
);
4646
} catch (ApiException $error) {
47-
$this->assertEquals('Invalid Payment Gateway Reference.', $error->getMessage());
47+
$this->assertEquals('Invalid connect integration.', $error->getMessage());
4848
}
4949
}
5050

test/EasyPost/Fixture.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ public static function reportDate(): string
5555
return '2022-04-09';
5656
}
5757

58-
public static function webhookUrl(): string
59-
{
60-
return self::readFixtureData()['webhook_url'];
61-
}
62-
6358
/**
6459
* @return array<mixed>
6560
*/
@@ -156,7 +151,7 @@ public static function oneCallBuyShipment(): array
156151
*/
157152
public static function basicPickup(): array
158153
{
159-
$pickupDate = '2023-11-24';
154+
$pickupDate = '2024-08-18';
160155

161156
$pickupData = self::readFixtureData()['pickups']['basic'];
162157
$pickupData['min_datetime'] = $pickupDate;
@@ -206,7 +201,25 @@ public static function eventBytes(): mixed
206201
$eventBytesFilepath = file("$currentDir/examples/official/fixtures/event-body.json");
207202
$data = $eventBytesFilepath[0];
208203

209-
return mb_convert_encoding(json_encode(json_decode($data, true)), 'UTF-8', mb_list_encodings());
204+
return mb_convert_encoding(json_encode(
205+
json_decode($data, true),
206+
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
207+
), 'UTF-8');
208+
}
209+
210+
public static function webhookHmacSignature(): string
211+
{
212+
return self::readFixtureData()['webhook_hmac_signature'];
213+
}
214+
215+
public static function webhookSecret(): string
216+
{
217+
return self::readFixtureData()['webhook_secret'];
218+
}
219+
220+
public static function webhookUrl(): string
221+
{
222+
return self::readFixtureData()['webhook_url'];
210223
}
211224

212225
/**
@@ -234,15 +247,15 @@ public static function rmaFormOtions(): array
234247
*/
235248
public static function plannedShipDate(): string
236249
{
237-
return '2024-07-16';
250+
return '2024-08-16';
238251
}
239252

240253
/**
241254
* @return string
242255
*/
243256
public static function desiredDeliveryDate(): string
244257
{
245-
return '2024-07-16';
258+
return '2024-08-18';
246259
}
247260

248261
/**

test/EasyPost/OrderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ public function testLowestRate(): void
128128
// Test lowest rate with no filters
129129
$lowestRate = $order->lowestRate();
130130
$this->assertEquals('GroundAdvantage', $lowestRate['service']);
131-
$this->assertEquals('11.33', $lowestRate['rate']);
131+
$this->assertEquals('11.40', $lowestRate['rate']);
132132
$this->assertEquals('USPS', $lowestRate['carrier']);
133133

134134
// Test lowest rate with service filter (this rate is higher than the lowest but should filter)
135135
$lowestRate = $order->lowestRate([], ['Priority']);
136136
$this->assertEquals('Priority', $lowestRate['service']);
137-
$this->assertEquals('13.79', $lowestRate['rate']);
137+
$this->assertEquals('14.48', $lowestRate['rate']);
138138
$this->assertEquals('USPS', $lowestRate['carrier']);
139139

140140
// Test lowest rate with carrier filter (should error due to bad carrier)

test/EasyPost/ReferralCustomerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testReferralAddCreditCard(): void
132132
Fixture::creditCardDetails()['cvc']
133133
);
134134

135-
$this->assertStringMatchesFormat('card_%s', $creditCard->id);
135+
$this->assertStringMatchesFormat('pm_%s', $creditCard->id);
136136
$this->assertEquals('6170', $creditCard->last4);
137137
}
138138
}

test/EasyPost/ShipmentTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public function testLowestRate(): void
356356
// Test lowestRate with service filter (this rate is higher than the lowest but should filter)
357357
$lowestRate = $shipment->lowestRate([], ['Priority']);
358358
$this->assertEquals('Priority', $lowestRate['service']);
359-
$this->assertEquals('6.95', $lowestRate['rate']);
359+
$this->assertEquals('6.90', $lowestRate['rate']);
360360
$this->assertEquals('USPS', $lowestRate['carrier']);
361361

362362
// Test lowestRate with carrier filter (should error due to bad carrier)

test/EasyPost/WebhookTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,14 @@ public function testDelete(): void
129129
*/
130130
public function testValidateWebhook(): void
131131
{
132-
$webhookSecret = 'sécret';
133-
$expectedHmacSignature = 'hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115a46b';
134132
$headers = [
135-
'X-Hmac-Signature' => $expectedHmacSignature
133+
'X-Hmac-Signature' => Fixture::webhookHmacSignature()
136134
];
137135

138-
$webhookBody = Util::validateWebhook(Fixture::eventBytes(), $headers, $webhookSecret);
136+
$webhookBody = Util::validateWebhook(Fixture::eventBytes(), $headers, Fixture::webhookSecret());
139137

140-
$this->assertEquals('batch.created', $webhookBody->description);
138+
$this->assertEquals('tracker.updated', $webhookBody->description);
139+
$this->assertEquals(614.4, $webhookBody->result->weight); // Ensure we convert floats properly
141140
}
142141

143142
/**

test/cassettes/addresses/all.yml

+27-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)