Skip to content

Commit

Permalink
Merge pull request #348 from EasyPost/webhook_fixtures
Browse files Browse the repository at this point in the history
fix: webhook fixture, addCreditCard params
  • Loading branch information
Justintime50 authored Aug 16, 2024
2 parents 7ab2a17 + feee9f4 commit b469f50
Show file tree
Hide file tree
Showing 152 changed files with 7,436 additions and 7,127 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Release

- Fixes an issue with how query params were sent when using the `addCreditCard` function

## v7.4.1 (2024-08-09)

- Fix parameters for retrieving next page of child users
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 44 files
+13 −16 .github/workflows/ci.yml
+4 −2 Makefile
+21 −0 official/docs/csharp/current/claims/cancel.cs
+43 −0 official/docs/csharp/current/claims/create.cs
+27 −0 official/docs/csharp/current/claims/list.cs
+21 −0 official/docs/csharp/current/claims/retrieve.cs
+2 −0 official/docs/curl/current/claims/cancel.sh
+13 −0 official/docs/curl/current/claims/create.sh
+2 −0 official/docs/curl/current/claims/list.sh
+2 −0 official/docs/curl/current/claims/retrieve.sh
+15 −0 official/docs/golang/current/claims/cancel.go
+25 −0 official/docs/golang/current/claims/create.go
+19 −0 official/docs/golang/current/claims/list.go
+15 −0 official/docs/golang/current/claims/retrieve.go
+15 −0 official/docs/java/current/claims/cancel.java
+30 −0 official/docs/java/current/claims/create.java
+20 −0 official/docs/java/current/claims/list.java
+15 −0 official/docs/java/current/claims/retrieve.java
+9 −0 official/docs/node/current/claims/cancel.js
+18 −0 official/docs/node/current/claims/create.js
+11 −0 official/docs/node/current/claims/list.js
+9 −0 official/docs/node/current/claims/retrieve.js
+7 −0 official/docs/php/current/claims/cancel.php
+19 −0 official/docs/php/current/claims/create.php
+9 −0 official/docs/php/current/claims/list.php
+7 −0 official/docs/php/current/claims/retrieve.php
+7 −0 official/docs/python/current/claims/cancel.py
+16 −0 official/docs/python/current/claims/create.py
+7 −0 official/docs/python/current/claims/list.py
+7 −0 official/docs/python/current/claims/retrieve.py
+40 −0 official/docs/responses/claim/claim-cancel.json
+35 −0 official/docs/responses/claim/claim-create.json
+185 −0 official/docs/responses/claim/claim-list.json
+35 −0 official/docs/responses/claim/claim-retrieve.json
+7 −0 official/docs/ruby/current/claim/cancel.rb
+19 −0 official/docs/ruby/current/claim/create.rb
+9 −0 official/docs/ruby/current/claim/list.rb
+7 −0 official/docs/ruby/current/claim/retrieve.rb
+3 −1 official/fixtures/client-library-fixtures.json
+1 −1 official/fixtures/event-body.json
+23 −0 official/guides/create-carrier-curls/ontracv3.sh
+13 −0 official/guides/create-carrier-curls/quick.sh
+17 −14 official/guides/errors-guide/golang/catch-error.go
+1 −1 style_guides/golang/.golangci.yml
35 changes: 0 additions & 35 deletions lib/EasyPost/Http/Requestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,41 +91,6 @@ private static function encodeObjects(mixed $data): array|string
}
}

/**
* URL Encodes data for GET requests.
*
* @param mixed $arr
* @param string|null $prefix
* @return string
*/
public static function urlEncode(mixed $arr, ?string $prefix = null): string
{
if (!is_array($arr)) {
return $arr;
}

$r = [];
foreach ($arr as $k => $v) {
if (is_null($v)) {
continue;
}

if (isset($prefix)) {
$k = $prefix . '[' . $k . ']';
} else {
$k = $prefix . '[]';
}

if (is_array($v)) {
$r[] = self::urlEncode($v, $k);
} else {
$r[] = urlencode($k) . '=' . urlencode($v);
}
}

return implode('&', $r);
}

/**
* Make a request to the EasyPost API.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/EasyPost/Service/ReferralCustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ private function createStripeToken(
]
];

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

$guzzleClient = new Client();

$requestOptions['query'] = $creditCardDetails;
$requestOptions['headers'] = $headers;
$requestOptions['http_errors'] = false;

Expand Down
2 changes: 1 addition & 1 deletion test/EasyPost/BetaReferralCustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testAddPaymentMethod(): void
'primary'
);
} catch (ApiException $error) {
$this->assertEquals('Invalid Payment Gateway Reference.', $error->getMessage());
$this->assertEquals('Invalid connect integration.', $error->getMessage());
}
}

Expand Down
31 changes: 22 additions & 9 deletions test/EasyPost/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public static function reportDate(): string
return '2022-04-09';
}

public static function webhookUrl(): string
{
return self::readFixtureData()['webhook_url'];
}

/**
* @return array<mixed>
*/
Expand Down Expand Up @@ -156,7 +151,7 @@ public static function oneCallBuyShipment(): array
*/
public static function basicPickup(): array
{
$pickupDate = '2023-11-24';
$pickupDate = '2024-08-18';

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

return mb_convert_encoding(json_encode(json_decode($data, true)), 'UTF-8', mb_list_encodings());
return mb_convert_encoding(json_encode(
json_decode($data, true),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
), 'UTF-8');
}

public static function webhookHmacSignature(): string
{
return self::readFixtureData()['webhook_hmac_signature'];
}

public static function webhookSecret(): string
{
return self::readFixtureData()['webhook_secret'];
}

public static function webhookUrl(): string
{
return self::readFixtureData()['webhook_url'];
}

/**
Expand Down Expand Up @@ -234,15 +247,15 @@ public static function rmaFormOtions(): array
*/
public static function plannedShipDate(): string
{
return '2024-07-16';
return '2024-08-16';
}

/**
* @return string
*/
public static function desiredDeliveryDate(): string
{
return '2024-07-16';
return '2024-08-18';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/EasyPost/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ public function testLowestRate(): void
// Test lowest rate with no filters
$lowestRate = $order->lowestRate();
$this->assertEquals('GroundAdvantage', $lowestRate['service']);
$this->assertEquals('11.33', $lowestRate['rate']);
$this->assertEquals('11.40', $lowestRate['rate']);
$this->assertEquals('USPS', $lowestRate['carrier']);

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

// Test lowest rate with carrier filter (should error due to bad carrier)
Expand Down
2 changes: 1 addition & 1 deletion test/EasyPost/ReferralCustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testReferralAddCreditCard(): void
Fixture::creditCardDetails()['cvc']
);

$this->assertStringMatchesFormat('card_%s', $creditCard->id);
$this->assertStringMatchesFormat('pm_%s', $creditCard->id);
$this->assertEquals('6170', $creditCard->last4);
}
}
2 changes: 1 addition & 1 deletion test/EasyPost/ShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function testLowestRate(): void
// Test lowestRate with service filter (this rate is higher than the lowest but should filter)
$lowestRate = $shipment->lowestRate([], ['Priority']);
$this->assertEquals('Priority', $lowestRate['service']);
$this->assertEquals('6.95', $lowestRate['rate']);
$this->assertEquals('6.90', $lowestRate['rate']);
$this->assertEquals('USPS', $lowestRate['carrier']);

// Test lowestRate with carrier filter (should error due to bad carrier)
Expand Down
9 changes: 4 additions & 5 deletions test/EasyPost/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ public function testDelete(): void
*/
public function testValidateWebhook(): void
{
$webhookSecret = 'sécret';
$expectedHmacSignature = 'hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115a46b';
$headers = [
'X-Hmac-Signature' => $expectedHmacSignature
'X-Hmac-Signature' => Fixture::webhookHmacSignature()
];

$webhookBody = Util::validateWebhook(Fixture::eventBytes(), $headers, $webhookSecret);
$webhookBody = Util::validateWebhook(Fixture::eventBytes(), $headers, Fixture::webhookSecret());

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

/**
Expand Down
53 changes: 27 additions & 26 deletions test/cassettes/addresses/all.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b469f50

Please sign in to comment.