Skip to content

Commit

Permalink
Merge pull request #319 from EasyPost/remove_carbon_offset
Browse files Browse the repository at this point in the history
chore: remove the unusable carbon offset params and object
  • Loading branch information
Justintime50 authored Nov 27, 2023
2 parents 8b3b9fa + 269c197 commit 5bcbc4b
Show file tree
Hide file tree
Showing 146 changed files with 6,349 additions and 6,763 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 Major Release

- Removed `withCarbonOffset` parameter from `create`, `buy`, and `regenerateRates` functions of the Shipment service as EasyPost now offers Carbon Neutral shipments by default for free

## v6.9.1 (2023-11-20)

- Fixes a bug that globally reset the timezone to UTC instead of setting the timezone per-request (closes #310)
Expand Down
14 changes: 0 additions & 14 deletions lib/EasyPost/CarbonOffset.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/EasyPost/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* @property int $delivery_days
* @property string $delivery_date
* @property bool $delivery_date_guaranteed
* @property CarbonOffset $carbon_offset
* @property string $created_at
* @property string $updated_at
*/
Expand Down
13 changes: 3 additions & 10 deletions lib/EasyPost/Service/ShipmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,16 @@ public function getNextPage($shipments, $pageSize = null)
* Create a shipment.
*
* @param mixed $params
* @param bool $withCarbonOffset
* @return mixed
*/
public function create($params = null, $withCarbonOffset = false)
public function create($params = null)
{
if (!isset($params['shipment']) || !is_array($params['shipment'])) {
$clone = $params;
unset($params);
$params['shipment'] = $clone;
}

$params['carbon_offset'] = $withCarbonOffset;

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

Expand All @@ -84,13 +81,11 @@ public function create($params = null, $withCarbonOffset = false)
*
* @param string $id
* @param mixed $params
* @param bool $withCarbonOffset
* @return mixed
*/
public function regenerateRates($id, $params = null, $withCarbonOffset = false)
public function regenerateRates($id, $params = null)
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/rerate';
$params['carbon_offset'] = $withCarbonOffset;
$response = Requestor::request($this->client, 'post', $url, $params);

return InternalUtil::convertToEasyPostObject($this->client, $response);
Expand All @@ -117,11 +112,10 @@ public function getSmartRates($id)
*
* @param string $id
* @param mixed $params
* @param boolean $withCarbonOffset
* @param string $endShipperId
* @return mixed
*/
public function buy($id, $params = null, $withCarbonOffset = false, $endShipperId = false)
public function buy($id, $params = null, $endShipperId = false)
{
if (isset($params['id']) && (!isset($params['rate']) || !is_array($params['rate']))) {
$clone = $params;
Expand All @@ -130,7 +124,6 @@ public function buy($id, $params = null, $withCarbonOffset = false, $endShipperI
}

$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/buy';
$params['carbon_offset'] = $withCarbonOffset;

if ($endShipperId !== false) {
$params['end_shipper_id'] = $endShipperId;
Expand Down
1 change: 0 additions & 1 deletion lib/easypost.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
require_once(dirname(__FILE__) . '/EasyPost/ApiKey.php');
require_once(dirname(__FILE__) . '/EasyPost/Batch.php');
require_once(dirname(__FILE__) . '/EasyPost/Brand.php');
require_once(dirname(__FILE__) . '/EasyPost/CarbonOffset.php');
require_once(dirname(__FILE__) . '/EasyPost/CarrierAccount.php');
require_once(dirname(__FILE__) . '/EasyPost/CarrierDetail.php');
require_once(dirname(__FILE__) . '/EasyPost/CustomsInfo.php');
Expand Down
8 changes: 0 additions & 8 deletions test/EasyPost/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public function testCreateVerify()
$this->assertInstanceOf(Address::class, $address);
$this->assertStringMatchesFormat('adr_%s', $address->id);
$this->assertEquals('417 MONTGOMERY ST FL 5', $address->street1);
$this->assertEquals(
'Invalid secondary information(Apt/Suite#)',
$address->verifications->zip4->errors[0]->message
);
}

/**
Expand Down Expand Up @@ -100,10 +96,6 @@ public function testCreateVerifyArray()
$this->assertInstanceOf(Address::class, $address);
$this->assertStringMatchesFormat('adr_%s', $address->id);
$this->assertEquals('417 MONTGOMERY ST FL 5', $address->street1);
$this->assertEquals(
'Invalid secondary information(Apt/Suite#)',
$address->verifications->zip4->errors[0]->message
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/EasyPost/BetaRateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testRetrieveLowestStatelessRate()

$lowestStatelessRate = Util::getLowestStatelessRate($statelessRates);

$this->assertEquals('First', $lowestStatelessRate->service);
$this->assertEquals('GroundAdvantage', $lowestStatelessRate->service);

try {
$lowestStatelessRate = Util::getLowestStatelessRate($statelessRates, ['invalidCarrier']);
Expand Down
4 changes: 2 additions & 2 deletions test/EasyPost/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static function oneCallBuyShipment()
// USPS only does "next-day" pickups including Saturday but not Sunday or Holidays.
public static function basicPickup()
{
$pickupDate = '2022-12-09';
$pickupDate = '2023-11-24';

$pickupData = self::readFixtureData()['pickups']['basic'];
$pickupData['min_datetime'] = $pickupDate;
Expand Down Expand Up @@ -179,6 +179,6 @@ public static function rmaFormOtions()

public static function plannedShipDate()
{
return '2023-04-28';
return '2023-11-24';
}
}
15 changes: 7 additions & 8 deletions test/EasyPost/InsuranceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace EasyPost\Test;

use EasyPost\EasyPostClient;
use EasyPost\Insurance;
use EasyPost\Exception\General\EndOfPaginationException;
use EasyPost\Insurance;
use Exception;

class InsuranceTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -54,17 +54,16 @@ public function testRetrieve()
{
TestUtil::setupCassette('insurance/retrieve.yml');

$shipment = self::$client->shipment->create(Fixture::oneCallBuyShipment());

$insuranceData = Fixture::basicInsurance();
$insuranceData['tracking_code'] = $shipment->tracking_code;
$insurances = self::$client->insurance->all([
'page_size' => Fixture::pageSize(),
]);

$insurance = self::$client->insurance->create($insuranceData);
$insuranceArray = $insurances['insurances'];

$retrievedInsurance = self::$client->insurance->retrieve($insurance->id);
$retrievedInsurance = self::$client->insurance->retrieve($insuranceArray[0]['id']);

$this->assertInstanceOf(Insurance::class, $retrievedInsurance);
$this->assertEquals($insurance, $retrievedInsurance);
$this->assertEquals($insuranceArray[0], $retrievedInsurance);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/EasyPost/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ public function testLowestRate()

// Test lowest rate with no filters
$lowestRate = $order->lowestRate();
$this->assertEquals('First', $lowestRate['service']);
$this->assertEquals('5.82', $lowestRate['rate']);
$this->assertEquals('GroundAdvantage', $lowestRate['service']);
$this->assertEquals('5.93', $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('8.15', $lowestRate['rate']);
$this->assertEquals('6.95', $lowestRate['rate']);
$this->assertEquals('USPS', $lowestRate['carrier']);

// Test lowest rate with carrier filter (should error due to bad carrier)
Expand Down
4 changes: 2 additions & 2 deletions test/EasyPost/ReferralCustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public static function setUpBeforeClass(): void
$partnerUserProdApiKey = getenv('PARTNER_USER_PROD_API_KEY') !== false
? getenv('PARTNER_USER_PROD_API_KEY') : '123';
self::$client = new EasyPostClient($partnerUserProdApiKey);
self::$referralUserProdApiKey = getenv('REFERRAL_USER_PROD_API_KEY') !== false
? getenv('REFERRAL_USER_PROD_API_KEY') : '123';
self::$referralUserProdApiKey = getenv('REFERRAL_CUSTOMER_PROD_API_KEY') !== false
? getenv('REFERRAL_CUSTOMER_PROD_API_KEY') : '123';
}

/**
Expand Down
97 changes: 11 additions & 86 deletions test/EasyPost/ShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,14 @@ public function testLowestRate()

// Test lowestRate with no filters
$lowestRate = $shipment->lowestRate();
$this->assertEquals('First', $lowestRate['service']);
$this->assertEquals('5.82', $lowestRate['rate']);
$this->assertEquals('GroundAdvantage', $lowestRate['service']);
$this->assertEquals('5.93', $lowestRate['rate']);
$this->assertEquals('USPS', $lowestRate['carrier']);

// 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('8.15', $lowestRate['rate']);
$this->assertEquals('6.95', $lowestRate['rate']);
$this->assertEquals('USPS', $lowestRate['carrier']);

// Test lowestRate with carrier filter (should error due to bad carrier)
Expand All @@ -378,14 +378,14 @@ public function testLowestRateExclusions()
// Test lowest rate by excluding a carrier (this is a weak test but we cannot assume existence
// of a non-USPS carrier).
$lowestRate = $shipment->lowestRate(['!RandomCarrier']);
$this->assertEquals('First', $lowestRate['service']);
$this->assertEquals('5.82', $lowestRate['rate']);
$this->assertEquals('GroundAdvantage', $lowestRate['service']);
$this->assertEquals('5.93', $lowestRate['rate']);
$this->assertEquals('USPS', $lowestRate['carrier']);

// Test lowest rate by excluding the `Priority` service
$lowestRate = $shipment->lowestRate([], ['!Priority']);
$this->assertEquals('First', $lowestRate['service']);
$this->assertEquals('5.82', $lowestRate['rate']);
$this->assertEquals('GroundAdvantage', $lowestRate['service']);
$this->assertEquals('5.93', $lowestRate['rate']);
$this->assertEquals('USPS', $lowestRate['carrier']);
}

Expand All @@ -403,8 +403,8 @@ public function testLowestSmartRateVariations()

// Test lowestSmartRate with no filters
$lowestSmartRate = self::$client->shipment->lowestSmartRate($shipment->id, 3, 'percentile_85');
$this->assertEquals('First', $lowestSmartRate['service']);
$this->assertEquals(5.82, $lowestSmartRate['rate']);
$this->assertEquals('GroundAdvantage', $lowestSmartRate['service']);
$this->assertEquals(5.93, $lowestSmartRate['rate']);
$this->assertEquals('USPS', $lowestSmartRate['carrier']);

// Test lowestSmartRate with invalid filters (should error due to strict delivery_days)
Expand All @@ -429,8 +429,8 @@ public function testLowestSmartRateVariations()

// Test lowestSmartRate with valid filters
$lowestSmartRate = Util::getLowestSmartRate($smartRates, 3, 'percentile_85');
$this->assertEquals('First', $lowestSmartRate['service']);
$this->assertEquals(5.82, $lowestSmartRate['rate']);
$this->assertEquals('GroundAdvantage', $lowestSmartRate['service']);
$this->assertEquals(5.93, $lowestSmartRate['rate']);
$this->assertEquals('USPS', $lowestSmartRate['carrier']);

// Test lowestSmartRate with invalid filters (should error due to strict delivery_days)
Expand Down Expand Up @@ -475,81 +475,6 @@ public function testGenerateForm()
$this->assertNotNull($form->form_url);
}

/**
* Tests creating a carbon offset shipment.
*/
public function testCreateCarbonOffsetShipment()
{
TestUtil::setupCassette('shipments/createCarbonOffsetShipment.yml');

$shipment = self::$client->shipment->create(Fixture::basicShipment(), true);

$this->assertInstanceOf(Shipment::class, $shipment);

foreach ($shipment->rates as $rate) {
$this->assertNotNull($rate->carbon_offset);
}
}

/**
* Tests buying a carbon offset shipment.
*/
public function testBuyCarbonOffsetShipment()
{
TestUtil::setupCassette('shipments/buyCarbonOffsetShipment.yml');

$shipment = self::$client->shipment->create(Fixture::basicShipment());

$boughtShipment = self::$client->shipment->buy(
$shipment->id,
['rate' => $shipment->lowestRate()],
true,
);

$this->assertInstanceOf(Shipment::class, $boughtShipment);

$foundCarbonOffset = false;

foreach ($boughtShipment->fees as $fee) {
if ($fee->type == 'CarbonOffsetFee') {
$foundCarbonOffset = true;
}
}

$this->assertTrue($foundCarbonOffset);
}

/**
* Tests one call buy a carbon offset shipment.
*/
public function testOneCallBuyCarbonOffsetShipment()
{
TestUtil::setupCassette('shipments/oneCallBuyCarbonOffsetShipment.yml');

$shipment = self::$client->shipment->create(Fixture::oneCallBuyShipment(), true);

$this->assertInstanceOf(Shipment::class, $shipment);

foreach ($shipment->rates as $rate) {
$this->assertNotNull($rate->carbon_offset);
}
}

/**
* Tests rerate a shipment with carbon offset.
*/
public function testRerateShipmentWithCarbonOffset()
{
TestUtil::setupCassette('shipments/rerateCarbonOffsetShipment.yml');

$shipment = self::$client->shipment->create(Fixture::oneCallBuyShipment());

$newCarbonOffset = self::$client->shipment->regenerateRates($shipment->id, null, true);
foreach ($newCarbonOffset->rates as $rate) {
$this->assertNotNull($rate->carbon_offset);
}
}

/**
* Tests buying a shipment with an end shipper.
*/
Expand Down
Loading

0 comments on commit 5bcbc4b

Please sign in to comment.