Skip to content

Commit ce4b900

Browse files
committed
AC-9030::Fedex API Upgrade - Fix PhpUnit and Static tests for Rate API
1 parent 1978e29 commit ce4b900

File tree

3 files changed

+152
-31
lines changed

3 files changed

+152
-31
lines changed

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Dissemination of this information or reproduction of this material
1616
* is strictly forbidden unless prior written permission is obtained
1717
* from Adobe.
18-
*************************************************************************
18+
* ************************************************************************
1919
*/
2020

2121
namespace Magento\Fedex\Model;
@@ -541,7 +541,7 @@ protected function _formRateRequest($purpose) : array
541541
protected function _doRatesRequest($purpose) : mixed
542542
{
543543
$response = null;
544-
$accessToken = $this->_getAccessToken($tracking = null);
544+
$accessToken = $this->_getAccessToken(null);
545545
if (empty($accessToken)) {
546546
return null;
547547
}
@@ -565,8 +565,8 @@ protected function _doRatesRequest($purpose) : mixed
565565
$curlClient->setOptions([CURLOPT_ENCODING => 'gzip,deflate,sdch']);
566566
$curlClient->post($url, $requestString);
567567
$response = $curlClient->getBody();
568-
$debugData['result'] = $response;
569568
$response = $this->serializer->unserialize($response);
569+
$debugData['result'] = $response;
570570
$this->_setCachedQuotes($requestString, $response);
571571
} catch (\Exception $e) {
572572
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
@@ -722,7 +722,8 @@ protected function _getRateAmountOriginBased($rate) : null|float
722722
foreach ($rate['ratedShipmentDetails'] as $ratedShipmentDetail) {
723723
$netAmount = (string)$ratedShipmentDetail['totalNetCharge'];
724724
$currencyCode = (string)$ratedShipmentDetail['shipmentRateDetail']['currency'];
725-
$rateType = (string)$ratedShipmentDetail['rateType'];
725+
$rateType = (string)reset($ratedShipmentDetail['ratedPackages'])
726+
['packageRateDetail']['rateType'];
726727
$rateTypeAmounts[$rateType] = $netAmount;
727728
}
728729

app/code/Magento/Fedex/Model/Source/PickupType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Dissemination of this information or reproduction of this material
1616
* is strictly forbidden unless prior written permission is obtained
1717
* from Adobe.
18-
*************************************************************************
18+
* ************************************************************************
1919
*/
2020

2121
namespace Magento\Fedex\Model\Source;

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 146 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Dissemination of this information or reproduction of this material
1616
* is strictly forbidden unless prior written permission is obtained
1717
* from Adobe.
18-
*************************************************************************
18+
* ************************************************************************
1919
*/
2020
declare(strict_types=1);
2121

@@ -307,33 +307,14 @@ public function testCollectRatesRateAmountOriginBased(
307307
$currencyCode,
308308
$baseCurrencyCode,
309309
$rateType,
310-
$expected,
311-
$callNum = 1
310+
$expected
312311
) {
313312
$this->scope->expects($this->any())
314313
->method('isSetFlag')
315314
->willReturn(true);
316315

317-
// @codingStandardsIgnoreStart
318-
$netAmount = new \stdClass();
319-
$netAmount->Amount = $amount;
320-
$netAmount->Currency = $currencyCode;
321-
322-
$totalNetCharge = new \stdClass();
323-
$totalNetCharge->TotalNetCharge = $netAmount;
324-
$totalNetCharge->RateType = $rateType;
325-
326-
$ratedShipmentDetail = new \stdClass();
327-
$ratedShipmentDetail->ShipmentRateDetail = $totalNetCharge;
328-
329-
$rate = new \stdClass();
330-
$rate->ServiceType = 'ServiceType';
331-
$rate->RatedShipmentDetails = [$ratedShipmentDetail];
332-
333-
$response = new \stdClass();
334-
$response->HighestSeverity = 'SUCCESS';
335-
$response->RateReplyDetails = $rate;
336-
// @codingStandardsIgnoreEnd
316+
$accessTokenResponse = $this->getAccessToken();
317+
$rateResponse = $this->getRateResponse($amount);
337318

338319
$this->serializer->method('serialize')
339320
->willReturn('CollectRateString' . $amount);
@@ -372,9 +353,12 @@ public function testCollectRatesRateAmountOriginBased(
372353
$request->method('getBaseCurrency')
373354
->willReturn($baseCurrency);
374355

375-
$this->soapClient->expects($this->exactly($callNum))
376-
->method('getRates')
377-
->willReturn($response);
356+
$this->curlFactory->expects($this->any())->method('create')->willReturn($this->curlClient);
357+
$this->curlClient->expects($this->any())->method('getBody')->willReturnSelf();
358+
359+
$this->serializer
360+
->method('unserialize')
361+
->willReturnOnConsecutiveCalls($accessTokenResponse, $rateResponse);
378362

379363
$allRates1 = $this->carrier->collectRates($request)->getAllRates();
380364
foreach ($allRates1 as $rate) {
@@ -644,6 +628,142 @@ public function getTrackResponse($shipTimeStamp, $expectedDate, $expectedTime) :
644628
return json_decode($trackResponse, true);
645629
}
646630

631+
/**
632+
* Expected Rate Response
633+
*
634+
* @param string $amount
635+
* @return array
636+
*/
637+
public function getRateResponse($amount) : array
638+
{
639+
$rateResponse = '{"transactionId":"9eb0f436-8bb1-4200-b951-ae10442489f3","output":{"alerts":[{"code":
640+
"ORIGIN.STATEORPROVINCECODE.CHANGED","message":"The origin state/province code has been changed.",
641+
"alertType":"NOTE"},{"code":"DESTINATION.STATEORPROVINCECODE.CHANGED","message":
642+
"The destination state/province code has been changed.","alertType":"NOTE"}],"rateReplyDetails":
643+
[{"serviceType":"FIRST_OVERNIGHT","serviceName":"FedEx First Overnight®","packagingType":"YOUR_PACKAGING",
644+
"ratedShipmentDetails":[{"rateType":"LIST","ratedWeightMethod":"ACTUAL","totalDiscounts":0.0,"totalBaseCharge"
645+
:276.19,"totalNetCharge":290.0,"totalNetFedExCharge":290.0,"shipmentRateDetail":{"rateZone":"05",
646+
"dimDivisor":0,"fuelSurchargePercent":5.0,"totalSurcharges":13.81,"totalFreightDiscount":0.0,"surCharges":
647+
[{"type":"FUEL","description":"Fuel Surcharge","amount":13.81}],"pricingCode":"PACKAGE","totalBillingWeight":
648+
{"units":"KG","value":10.0},"currency":"USD","rateScale":"12"},"ratedPackages":[{"groupNumber":0,
649+
"effectiveNetDiscount":0.0,"packageRateDetail":{"rateType":"PAYOR_LIST_PACKAGE","ratedWeightMethod":"ACTUAL",
650+
"baseCharge":276.19,"netFreight":276.19,"totalSurcharges":13.81,"netFedExCharge":290.0,"totalTaxes":0.0,
651+
"netCharge":290.0,"totalRebates":0.0,"billingWeight":{"units":"KG","value":10.0},"totalFreightDiscounts":0.0,
652+
"surcharges":[{"type":"FUEL","description":"Fuel Surcharge","amount":13.81}],"currency":"USD"}}],
653+
"currency":"USD"}],"operationalDetail":{"ineligibleForMoneyBackGuarantee":false,"astraDescription":"1ST OVR",
654+
"airportId":"ELP","serviceCode":"06"},"signatureOptionType":"SERVICE_DEFAULT","serviceDescription":
655+
{"serviceId":"EP1000000006","serviceType":"FIRST_OVERNIGHT","code":"06","names":[{"type":"long",
656+
"encoding":"utf-8","value":"FedEx First Overnight®"},{"type":"long","encoding":"ascii","value":
657+
"FedEx First Overnight"},{"type":"medium","encoding":"utf-8","value":"FedEx First Overnight®"},
658+
{"type":"medium","encoding":"ascii","value":"FedEx First Overnight"},{"type":"short","encoding":
659+
"utf-8","value":"FO"},{"type":"short","encoding":"ascii","value":"FO"},{"type":"abbrv","encoding":"ascii",
660+
"value":"FO"}],"serviceCategory":"parcel","description":"First Overnight","astraDescription":"1ST OVR"}},
661+
{"serviceType":"PRIORITY_OVERNIGHT","serviceName":"FedEx Priority Overnight®","packagingType":"YOUR_PACKAGING",
662+
"ratedShipmentDetails":[{"rateType":"LIST","ratedWeightMethod":"ACTUAL","totalDiscounts":0.0,
663+
"totalBaseCharge":245.19,"totalNetCharge":257.45,"totalNetFedExCharge":257.45,"shipmentRateDetail":
664+
{"rateZone":"05","dimDivisor":0,"fuelSurchargePercent":5.0,"totalSurcharges":12.26,"totalFreightDiscount":0.0,
665+
"surCharges":[{"type":"FUEL","description":"Fuel Surcharge","amount":12.26}],"pricingCode":"PACKAGE",
666+
"totalBillingWeight":{"units":"KG","value":10.0},"currency":"USD","rateScale":"1552"},"ratedPackages":
667+
[{"groupNumber":0,"effectiveNetDiscount":0.0,"packageRateDetail":{"rateType":"PAYOR_LIST_PACKAGE",
668+
"ratedWeightMethod":"ACTUAL","baseCharge":245.19,"netFreight":245.19,"totalSurcharges":12.26,"netFedExCharge":
669+
257.45,"totalTaxes":0.0,"netCharge":257.45,"totalRebates":0.0,"billingWeight":{"units":"KG","value":10.0},
670+
"totalFreightDiscounts":0.0,"surcharges":[{"type":"FUEL","description":"Fuel Surcharge","amount":12.26}],
671+
"currency":"USD"}}],"currency":"USD"}],"operationalDetail":{"ineligibleForMoneyBackGuarantee":false,
672+
"astraDescription":"P1","airportId":"ELP","serviceCode":"01"},"signatureOptionType":"SERVICE_DEFAULT",
673+
"serviceDescription":{"serviceId":"EP1000000002","serviceType":"PRIORITY_OVERNIGHT","code":"01",
674+
"names":[{"type":"long","encoding":"utf-8","value":"FedEx Priority Overnight®"},{"type":"long",
675+
"encoding":"ascii","value":"FedEx Priority Overnight"},{"type":"medium","encoding":"utf-8","value":
676+
"FedEx Priority Overnight®"},{"type":"medium","encoding":"ascii","value":"FedEx Priority Overnight"},
677+
{"type":"short","encoding":"utf-8","value":"P-1"},{"type":"short","encoding":"ascii","value":"P-1"},
678+
{"type":"abbrv","encoding":"ascii","value":"PO"}],"serviceCategory":"parcel","description":
679+
"Priority Overnight","astraDescription":"P1"}},{"serviceType":"STANDARD_OVERNIGHT","serviceName":
680+
"FedEx Standard Overnight®","packagingType":"YOUR_PACKAGING","ratedShipmentDetails":[{"rateType":"LIST",
681+
"ratedWeightMethod":"ACTUAL","totalDiscounts":0.0,"totalBaseCharge":235.26,"totalNetCharge":247.02,
682+
"totalNetFedExCharge":247.02,"shipmentRateDetail":{"rateZone":"05","dimDivisor":0,"fuelSurchargePercent":5.0,
683+
"totalSurcharges":11.76,"totalFreightDiscount":0.0,"surCharges":[{"type":"FUEL","description":"Fuel Surcharge",
684+
"amount":11.76}],"pricingCode":"PACKAGE","totalBillingWeight":{"units":"KG","value":10.0},"currency":"USD",
685+
"rateScale":"1349"},"ratedPackages":[{"groupNumber":0,"effectiveNetDiscount":0.0,"packageRateDetail":
686+
{"rateType":"PAYOR_LIST_PACKAGE","ratedWeightMethod":"ACTUAL","baseCharge":235.26,"netFreight":235.26,
687+
"totalSurcharges":11.76,"netFedExCharge":247.02,"totalTaxes":0.0,"netCharge":247.02,"totalRebates":0.0,
688+
"billingWeight":{"units":"KG","value":10.0},"totalFreightDiscounts":0.0,"surcharges":[{"type":"FUEL",
689+
"description":"Fuel Surcharge","amount":11.76}],"currency":"USD"}}],"currency":"USD"}],"operationalDetail":
690+
{"ineligibleForMoneyBackGuarantee":false,"astraDescription":"STD OVR","airportId":"ELP","serviceCode":"05"},
691+
"signatureOptionType":"SERVICE_DEFAULT","serviceDescription":{"serviceId":"EP1000000005","serviceType":
692+
"STANDARD_OVERNIGHT","code":"05","names":[{"type":"long","encoding":"utf-8","value":"FedEx Standard Overnight®"}
693+
,{"type":"long","encoding":"ascii","value":"FedEx Standard Overnight"},{"type":"medium","encoding":"utf-8",
694+
"value":"FedEx Standard Overnight®"},{"type":"medium","encoding":"ascii","value":"FedEx Standard Overnight"},
695+
{"type":"short","encoding":"utf-8","value":"SOS"},{"type":"short","encoding":"ascii","value":"SOS"},{"type":
696+
"abbrv","encoding":"ascii","value":"SO"}],"serviceCategory":"parcel","description":"Standard Overnight",
697+
"astraDescription":"STD OVR"}},{"serviceType":"FEDEX_2_DAY_AM","serviceName":"FedEx 2Day® AM","packagingType":
698+
"YOUR_PACKAGING","ratedShipmentDetails":[{"rateType":"LIST","ratedWeightMethod":"ACTUAL","totalDiscounts":0.0,
699+
"totalBaseCharge":142.78,"totalNetCharge":149.92,"totalNetFedExCharge":149.92,"shipmentRateDetail":{"rateZone":
700+
"05","dimDivisor":0,"fuelSurchargePercent":5.0,"totalSurcharges":7.14,"totalFreightDiscount":0.0,"surCharges":
701+
[{"type":"FUEL","description":"Fuel Surcharge","amount":7.14}],"pricingCode":"PACKAGE","totalBillingWeight":
702+
{"units":"KG","value":10.0},"currency":"USD","rateScale":"10"},"ratedPackages":[{"groupNumber":0,
703+
"effectiveNetDiscount":0.0,"packageRateDetail":{"rateType":"PAYOR_LIST_PACKAGE","ratedWeightMethod":"ACTUAL",
704+
"baseCharge":142.78,"netFreight":142.78,"totalSurcharges":7.14,"netFedExCharge":149.92,"totalTaxes":0.0,
705+
"netCharge":149.92,"totalRebates":0.0,"billingWeight":{"units":"KG","value":10.0},"totalFreightDiscounts":0.0,
706+
"surcharges":[{"type":"FUEL","description":"Fuel Surcharge","amount":7.14}],"currency":"USD"}}],"currency":
707+
"USD"}],"operationalDetail":{"ineligibleForMoneyBackGuarantee":false,"astraDescription":"2DAY AM","airportId":
708+
"ELP","serviceCode":"49"},"signatureOptionType":"SERVICE_DEFAULT","serviceDescription":{"serviceId":
709+
"EP1000000023","serviceType":"FEDEX_2_DAY_AM","code":"49","names":[{"type":"long","encoding":"utf-8","value":
710+
"FedEx 2Day® AM"},{"type":"long","encoding":"ascii","value":"FedEx 2Day AM"},{"type":"medium","encoding":
711+
"utf-8","value":"FedEx 2Day® AM"},{"type":"medium","encoding":"ascii","value":"FedEx 2Day AM"},{"type":"short",
712+
"encoding":"utf-8","value":"E2AM"},{"type":"short","encoding":"ascii","value":"E2AM"},{"type":"abbrv",
713+
"encoding":"ascii","value":"TA"}],"serviceCategory":"parcel","description":"2DAY AM","astraDescription":
714+
"2DAY AM"}},{"serviceType":"FEDEX_2_DAY","serviceName":"FedEx 2Day®","packagingType":"YOUR_PACKAGING",
715+
"ratedShipmentDetails":[{"rateType":"LIST","ratedWeightMethod":"ACTUAL","totalDiscounts":0.0,"totalBaseCharge":
716+
116.68,"totalNetCharge":122.51,"totalNetFedExCharge":122.51,"shipmentRateDetail":{"rateZone":"05","dimDivisor":
717+
0,"fuelSurchargePercent":5.0,"totalSurcharges":5.83,"totalFreightDiscount":0.0,"surCharges":[{"type":"FUEL",
718+
"description":"Fuel Surcharge","amount":5.83}],"pricingCode":"PACKAGE","totalBillingWeight":{"units":"KG",
719+
"value":10.0},"currency":"USD","rateScale":"6046"},"ratedPackages":[{"groupNumber":0,"effectiveNetDiscount":0.0,
720+
"packageRateDetail":{"rateType":"PAYOR_LIST_PACKAGE","ratedWeightMethod":"ACTUAL","baseCharge":116.68,
721+
"netFreight":116.68,"totalSurcharges":5.83,"netFedExCharge":122.51,"totalTaxes":0.0,"netCharge":122.51,
722+
"totalRebates":0.0,"billingWeight":{"units":"KG","value":10.0},"totalFreightDiscounts":0.0,"surcharges":
723+
[{"type":"FUEL","description":"Fuel Surcharge","amount":5.83}],"currency":"USD"}}],"currency":"USD"}],
724+
"operationalDetail":{"ineligibleForMoneyBackGuarantee":false,"astraDescription":"E2","airportId":"ELP",
725+
"serviceCode":"03"},"signatureOptionType":"SERVICE_DEFAULT","serviceDescription":{"serviceId":"EP1000000003",
726+
"serviceType":"FEDEX_2_DAY","code":"03","names":[{"type":"long","encoding":"utf-8","value":"FedEx 2Day®"},
727+
{"type":"long","encoding":"ascii","value":"FedEx 2Day"},{"type":"medium","encoding":"utf-8","value":
728+
"FedEx 2Day®"},{"type":"medium","encoding":"ascii","value":"FedEx 2Day"},{"type":"short","encoding":"utf-8",
729+
"value":"P-2"},{"type":"short","encoding":"ascii","value":"P-2"},{"type":"abbrv","encoding":"ascii","value":
730+
"ES"}],"serviceCategory":"parcel","description":"2Day","astraDescription":"E2"}},{"serviceType":
731+
"FEDEX_EXPRESS_SAVER","serviceName":"FedEx Express Saver®","packagingType":"YOUR_PACKAGING",
732+
"ratedShipmentDetails":[{"rateType":"LIST","ratedWeightMethod":"ACTUAL","totalDiscounts":0.0,"totalBaseCharge"
733+
:90.25,"totalNetCharge":94.76,"totalNetFedExCharge":94.76,"shipmentRateDetail":{"rateZone":"05","dimDivisor":0,
734+
"fuelSurchargePercent":5.0,"totalSurcharges":4.51,"totalFreightDiscount":0.0,"surCharges":[{"type":"FUEL",
735+
"description":"Fuel Surcharge","amount":4.51}],"pricingCode":"PACKAGE","totalBillingWeight":{"units":"KG",
736+
"value":10.0},"currency":"USD","rateScale":"7173"},"ratedPackages":[{"groupNumber":0,"effectiveNetDiscount":0.0,
737+
"packageRateDetail":{"rateType":"PAYOR_LIST_PACKAGE","ratedWeightMethod":"ACTUAL","baseCharge":90.25,
738+
"netFreight":90.25,"totalSurcharges":4.51,"netFedExCharge":94.76,"totalTaxes":0.0,"netCharge":94.76,
739+
"totalRebates":0.0,"billingWeight":{"units":"KG","value":10.0},"totalFreightDiscounts":0.0,"surcharges":
740+
[{"type":"FUEL","description":"Fuel Surcharge","amount":4.51}],"currency":"USD"}}],"currency":"USD"}],
741+
"operationalDetail":{"ineligibleForMoneyBackGuarantee":false,"astraDescription":"XS","airportId":"ELP",
742+
"serviceCode":"20"},"signatureOptionType":"SERVICE_DEFAULT","serviceDescription":{"serviceId":"EP1000000013",
743+
"serviceType":"FEDEX_EXPRESS_SAVER","code":"20","names":[{"type":"long","encoding":"utf-8","value":
744+
"FedEx Express Saver®"},{"type":"long","encoding":"ascii","value":"FedEx Express Saver"},{"type":"medium",
745+
"encoding":"utf-8","value":"FedEx Express Saver®"},{"type":"medium","encoding":"ascii","value":
746+
"FedEx Express Saver"}],"serviceCategory":"parcel","description":"Express Saver","astraDescription":"XS"}},
747+
{"serviceType":"ServiceType","serviceName":"FedEx Ground®","packagingType":"YOUR_PACKAGING",
748+
"ratedShipmentDetails":[{"rateType":"LIST","ratedWeightMethod":"ACTUAL","totalDiscounts":0.0,"totalBaseCharge":
749+
24.26,"totalNetCharge":'.$amount.',"totalNetFedExCharge":28.75,"shipmentRateDetail":{"rateZone":"5","dimDivisor"
750+
:0,"fuelSurchargePercent":18.5,"totalSurcharges":4.49,"totalFreightDiscount":0.0,"surCharges":[{"type":"FUEL",
751+
"description":"Fuel Surcharge","level":"PACKAGE","amount":4.49}],"totalBillingWeight":{"units":"LB","value":
752+
23.0},"currency":"USD"},"ratedPackages":[{"groupNumber":0,"effectiveNetDiscount":0.0,"packageRateDetail":
753+
{"rateType":"PAYOR_LIST_PACKAGE","ratedWeightMethod":"ACTUAL","baseCharge":24.26,"netFreight":24.26,
754+
"totalSurcharges":4.49,"netFedExCharge":28.75,"totalTaxes":0.0,"netCharge":28.75,"totalRebates":0.0,
755+
"billingWeight":{"units":"KG","value":10.43},"totalFreightDiscounts":0.0,"surcharges":[{"type":"FUEL",
756+
"description":"Fuel Surcharge","level":"PACKAGE","amount":4.49}],"currency":"USD"}}],"currency":"USD"}],
757+
"operationalDetail":{"ineligibleForMoneyBackGuarantee":false,"astraDescription":"FXG","airportId":"ELP",
758+
"serviceCode":"92"},"signatureOptionType":"SERVICE_DEFAULT","serviceDescription":{"serviceId":"EP1000000134",
759+
"serviceType":"FEDEX_GROUND","code":"92","names":[{"type":"long","encoding":"utf-8","value":"FedEx Ground®"},
760+
{"type":"long","encoding":"ascii","value":"FedEx Ground"},{"type":"medium","encoding":"utf-8","value":"Ground®"}
761+
,{"type":"medium","encoding":"ascii","value":"Ground"},{"type":"short","encoding":"utf-8","value":"FG"},
762+
{"type":"short","encoding":"ascii","value":"FG"},{"type":"abbrv","encoding":"ascii","value":"SG"}],
763+
"description":"FedEx Ground","astraDescription":"FXG"}}],"quoteDate":"2023-07-13","encoded":false}}';
764+
return json_decode($rateResponse, true);
765+
}
766+
647767
/**
648768
* get Access Token for Rest API
649769
*/

0 commit comments

Comments
 (0)