-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new smartrate endpoints functions (#342)
- Loading branch information
Showing
12 changed files
with
549 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace EasyPost\Service; | ||
|
||
use EasyPost\Exception\General\EndOfPaginationException; | ||
use EasyPost\Http\Requestor; | ||
use EasyPost\Util\InternalUtil; | ||
|
||
/** | ||
* SmartRate service containing all the details of SmartRate requests. | ||
*/ | ||
class SmartRateService extends BaseService | ||
{ | ||
/** | ||
* Retrieve a recommended ship date for each carrier-service level combination via the | ||
* Smart Deliver On API, based on a specific delivery date and origin-destination postal code pair. | ||
* | ||
* @param mixed $params | ||
* @return mixed | ||
*/ | ||
public function recommendShipDate(mixed $params = null): mixed | ||
{ | ||
$response = Requestor::request($this->client, 'post', '/smartrate/deliver_on', $params); | ||
|
||
return InternalUtil::convertToEasyPostObject($this->client, $response); | ||
} | ||
|
||
/** | ||
* Retrieve the estimated delivery date of each carrier-service level combination via the | ||
* Smart Deliver By API, based on a specific ship date and origin-destination postal code pair. | ||
* | ||
* @param mixed $params | ||
* @return mixed | ||
*/ | ||
public function estimateDeliveryDate(mixed $params = null): mixed | ||
{ | ||
$response = Requestor::request($this->client, 'post', '/smartrate/deliver_by', $params); | ||
|
||
return InternalUtil::convertToEasyPostObject($this->client, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace EasyPost\Test; | ||
|
||
use EasyPost\EasyPostClient; | ||
use EasyPost\Exception\General\EndOfPaginationException; | ||
use Exception; | ||
|
||
class SmartRateTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
private static EasyPostClient $client; | ||
|
||
/** | ||
* Setup the testing environment for this file. | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
TestUtil::setupVcrTests(); | ||
self::$client = new EasyPostClient(getenv('EASYPOST_TEST_API_KEY')); | ||
} | ||
|
||
/** | ||
* Cleanup the testing environment once finished. | ||
*/ | ||
public static function tearDownAfterClass(): void | ||
{ | ||
TestUtil::teardownVcrTests(); | ||
} | ||
|
||
/** | ||
* Test that we retrieve SmartRates when provided a from/to zip and planned ship date. | ||
*/ | ||
public function testRetrieveRecommendDate(): void | ||
{ | ||
TestUtil::setupCassette('smartrate/recommendShipDate.yml'); | ||
|
||
$params = [ | ||
'from_zip' => Fixture::caAddress1()['zip'], | ||
'to_zip' => Fixture::caAddress2()['zip'], | ||
'desired_delivery_date' => Fixture::desiredDeliveryDate(), | ||
'carriers' => [Fixture::usps()], | ||
]; | ||
|
||
$rates = self::$client->smartRate->recommendShipDate($params); | ||
|
||
foreach ($rates['results'] as $entry) { | ||
$this->assertTrue( | ||
isset($entry['easypost_time_in_transit_data']), | ||
'Assertion failed: easypost_time_in_transit_data is not set.' | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Test that we retrieve SmartRates when provided a from/to zip and planned ship date. | ||
*/ | ||
public function testRetrieveEstimatedDeliveryDate(): void | ||
{ | ||
TestUtil::setupCassette('smartrate/estimatedDeliveryDate.yml'); | ||
|
||
$params = [ | ||
'from_zip' => Fixture::caAddress1()['zip'], | ||
'to_zip' => Fixture::caAddress2()['zip'], | ||
'planned_ship_date' => Fixture::plannedShipDate(), | ||
'carriers' => [Fixture::usps()], | ||
]; | ||
|
||
$rates = self::$client->smartRate->estimateDeliveryDate($params); | ||
|
||
foreach ($rates['results'] as $entry) { | ||
$this->assertTrue( | ||
isset($entry['easypost_time_in_transit_data']), | ||
'Assertion failed: easypost_time_in_transit_data is not set.' | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.