23
23
use Magento \Framework \App \ObjectManager ;
24
24
use Magento \Framework \DataObject ;
25
25
use Magento \Framework \Exception \LocalizedException ;
26
+ use Magento \Framework \HTTP \Client \CurlFactory ;
26
27
use Magento \Framework \Measure \Length ;
27
28
use Magento \Framework \Measure \Weight ;
28
29
use Magento \Framework \Serialize \Serializer \Json ;
30
+ use Magento \Framework \Url \DecoderInterface ;
29
31
use Magento \Framework \Xml \Security ;
30
32
use Magento \Quote \Model \Quote \Address \RateRequest ;
31
33
use Magento \Shipping \Model \Carrier \AbstractCarrier ;
32
34
use Magento \Shipping \Model \Carrier \AbstractCarrierOnline ;
33
35
use Magento \Shipping \Model \Rate \Result ;
34
- use Magento \Framework \HTTP \Client \CurlFactory ;
35
- use Magento \Framework \Url \DecoderInterface ;
36
36
37
37
/**
38
38
* Fedex shipping implementation
@@ -100,7 +100,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
100
100
public const SHIPMENT_CANCEL_END_POINT = '/ship/v1/shipments/cancel ' ;
101
101
102
102
/**
103
- * REST end point of Tracking API
103
+ * Authentication Grant Type for REST end point
104
104
*
105
105
* @var string
106
106
*/
@@ -164,7 +164,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
164
164
* @var string[]
165
165
*/
166
166
protected $ _debugReplacePrivateDataKeys = [
167
- 'Key ' , 'Password ' , ' MeterNumber ' ,
167
+ 'client_id ' , 'client_secret ' ,
168
168
];
169
169
170
170
/**
@@ -390,12 +390,12 @@ public function getResult()
390
390
* @param string $purpose
391
391
* @return array
392
392
*/
393
- protected function _formRateRequest ($ purpose ) : array
393
+ protected function _formRateRequest ($ purpose ): array
394
394
{
395
395
$ r = $ this ->_rawRequest ;
396
396
$ ratesRequest = [
397
397
'accountNumber ' => [
398
- 'value ' => $ r ->getAccount ()
398
+ 'value ' => $ r ->getAccount ()
399
399
],
400
400
'requestedShipment ' => [
401
401
'pickupType ' => $ this ->getConfigData ('pickup_type ' ),
@@ -472,7 +472,7 @@ protected function _formRateRequest($purpose) : array
472
472
* @param string $purpose
473
473
* @return mixed
474
474
*/
475
- protected function _doRatesRequest ($ purpose ) : mixed
475
+ protected function _doRatesRequest ($ purpose ): mixed
476
476
{
477
477
$ response = null ;
478
478
$ accessToken = $ this ->_getAccessToken ();
@@ -531,11 +531,11 @@ protected function _getQuotes()
531
531
* @return Result
532
532
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
533
533
*/
534
- protected function _prepareRateResponse ($ response ) : Result
534
+ protected function _prepareRateResponse ($ response ): Result
535
535
{
536
536
$ costArr = [];
537
537
$ priceArr = [];
538
- $ errorTitle = 'For some reason we can \'t retrieve tracking info right now. ' ;
538
+ $ errorTitle = __ ( 'For some reason we can \'t retrieve tracking info right now. ' ) ;
539
539
540
540
if (is_array ($ response )) {
541
541
if (!empty ($ response ['errors ' ])) {
@@ -625,7 +625,7 @@ protected function _getPerorderPrice($cost, $handlingType, $handlingFee)
625
625
* @param \stdClass $rate
626
626
* @return null|float
627
627
*/
628
- protected function _getRateAmountOriginBased ($ rate ) : null |float
628
+ protected function _getRateAmountOriginBased ($ rate ): null |float
629
629
{
630
630
$ amount = null ;
631
631
$ currencyCode = '' ;
@@ -650,7 +650,7 @@ protected function _getRateAmountOriginBased($rate) : null|float
650
650
}
651
651
}
652
652
653
- if ($ amount === null ) {
653
+ if ($ amount === null && ! empty ( $ rate [ ' ratedShipmentDetails ' ][ 0 ][ ' totalNetCharge ' ]) ) {
654
654
$ amount = (string )$ rate ['ratedShipmentDetails ' ][0 ]['totalNetCharge ' ];
655
655
}
656
656
@@ -712,7 +712,7 @@ protected function _setFreeMethodRequest($freeMethod)
712
712
* @return \Magento\Framework\Phrase|array|false
713
713
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
714
714
*/
715
- public function getCode ($ type , $ code = '' ) : \Magento \Framework \Phrase |array |false
715
+ public function getCode ($ type , $ code = '' ): \Magento \Framework \Phrase |array |false
716
716
{
717
717
$ codes = [
718
718
'method ' => [
@@ -911,7 +911,7 @@ public function getCurrencyCode()
911
911
* @param string|string[] $trackings
912
912
* @return \Magento\Shipping\Model\Tracking\Result|null
913
913
*/
914
- public function getTracking ($ trackings ) : \Magento \Shipping \Model \Tracking \Result | null
914
+ public function getTracking ($ trackings ): \Magento \Shipping \Model \Tracking \Result | null
915
915
{
916
916
if (!is_array ($ trackings )) {
917
917
$ trackings = [$ trackings ];
@@ -930,7 +930,7 @@ public function getTracking($trackings) : \Magento\Shipping\Model\Tracking\Resul
930
930
* @param string|null $endpoint
931
931
* @return string
932
932
*/
933
- protected function _getUrl ($ endpoint = null ) : string
933
+ protected function _getUrl ($ endpoint = null ): string
934
934
{
935
935
$ url = $ this ->getConfigFlag ('sandbox_mode ' ) ? $ this ->getConfigData ('sandbox_webservices_url ' )
936
936
: $ this ->getConfigData ('production_webservices_url ' );
@@ -942,13 +942,13 @@ protected function _getUrl($endpoint = null) : string
942
942
*
943
943
* @return string|null
944
944
*/
945
- protected function _getAccessToken () : string | null
945
+ protected function _getAccessToken (): string | null
946
946
{
947
947
$ apiKey = $ this ->getConfigData ('api_key ' ) ?? null ;
948
948
$ secretKey = $ this ->getConfigData ('secret_key ' ) ?? null ;
949
949
950
950
if (!$ apiKey || !$ secretKey ) {
951
- $ this ->_debug ('Authentication keys are missing. ' );
951
+ $ this ->_debug (__ ( 'Authentication keys are missing. ' ) );
952
952
return null ;
953
953
}
954
954
@@ -979,7 +979,7 @@ protected function _getAccessToken() : string | null
979
979
* @param string|null $accessToken
980
980
* @return array|bool
981
981
*/
982
- protected function sendRequest ($ endpoint , $ request , $ accessToken = null ) : array |bool
982
+ protected function sendRequest ($ endpoint , $ request , $ accessToken = null ): array |bool
983
983
{
984
984
if ($ accessToken ) {
985
985
$ headers = [
@@ -1018,7 +1018,7 @@ protected function sendRequest($endpoint, $request, $accessToken = null) : array
1018
1018
* @param string $tracking
1019
1019
* @return void
1020
1020
*/
1021
- protected function _getTrackingInformation ($ tracking ) : void
1021
+ protected function _getTrackingInformation ($ tracking ): void
1022
1022
{
1023
1023
$ accessToken = $ this ->_getAccessToken ();
1024
1024
if (!empty ($ accessToken )) {
@@ -1062,7 +1062,7 @@ protected function _getTrackingInformation($tracking) : void
1062
1062
* @param array $response
1063
1063
* @return void
1064
1064
*/
1065
- protected function _parseTrackingResponse ($ trackingValue , $ response ) : void
1065
+ protected function _parseTrackingResponse ($ trackingValue , $ response ): void
1066
1066
{
1067
1067
if (!is_array ($ response ) || empty ($ response ['output ' ])) {
1068
1068
$ this ->_debug ($ response );
@@ -1339,7 +1339,7 @@ protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
1339
1339
* @param \Magento\Framework\DataObject $request
1340
1340
* @return \Magento\Framework\DataObject
1341
1341
*/
1342
- protected function _doShipmentRequest (\Magento \Framework \DataObject $ request ) : \Magento \Framework \DataObject
1342
+ protected function _doShipmentRequest (\Magento \Framework \DataObject $ request ): \Magento \Framework \DataObject
1343
1343
{
1344
1344
$ this ->_prepareShipmentRequest ($ request );
1345
1345
$ result = new \Magento \Framework \DataObject ();
@@ -1394,7 +1394,7 @@ protected function _doShipmentRequest(\Magento\Framework\DataObject $request) :
1394
1394
* @param array $pieceResponses
1395
1395
* @return string
1396
1396
*/
1397
- private function getTrackingNumber ($ pieceResponses ) : string
1397
+ private function getTrackingNumber ($ pieceResponses ): string
1398
1398
{
1399
1399
return reset ($ pieceResponses )['trackingNumber ' ];
1400
1400
}
@@ -1405,7 +1405,7 @@ private function getTrackingNumber($pieceResponses) : string
1405
1405
* @param array|object $pieceResponses
1406
1406
* @return string
1407
1407
*/
1408
- private function getPackagingLabel ($ pieceResponses ) : string
1408
+ private function getPackagingLabel ($ pieceResponses ): string
1409
1409
{
1410
1410
return reset (reset ($ pieceResponses )['packageDocuments ' ])['encodedLabel ' ];
1411
1411
}
@@ -1421,7 +1421,7 @@ public function rollBack($data): bool
1421
1421
{
1422
1422
$ accessToken = $ this ->_getAccessToken ();
1423
1423
if (empty ($ accessToken )) {
1424
- $ this ->_debug ('Authorization Error. No Access Token found with given credentials. ' );
1424
+ $ this ->_debug (__ ( 'Authorization Error. No Access Token found with given credentials. ' ) );
1425
1425
return false ;
1426
1426
}
1427
1427
@@ -1548,7 +1548,7 @@ protected function filterDebugData($data)
1548
1548
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
1549
1549
* @SuppressWarnings(PHPMD.NPathComplexity)
1550
1550
*/
1551
- private function processTrackingDetails ($ trackInfo ) : array
1551
+ private function processTrackingDetails ($ trackInfo ): array
1552
1552
{
1553
1553
$ result = [
1554
1554
'shippeddate ' => null ,
@@ -1637,7 +1637,7 @@ private function processTrackingDetails($trackInfo) : array
1637
1637
* @param array $trackInfo
1638
1638
* @return \Datetime|null
1639
1639
*/
1640
- private function getDeliveryDateTime ($ trackInfo ) : \Datetime | null
1640
+ private function getDeliveryDateTime ($ trackInfo ): \Datetime | null
1641
1641
{
1642
1642
$ timestamp = null ;
1643
1643
if (!empty ($ trackInfo ['dateAndTimes ' ]) && is_array ($ trackInfo ['dateAndTimes ' ])) {
@@ -1661,7 +1661,7 @@ private function getDeliveryDateTime($trackInfo) : \Datetime | null
1661
1661
* @param array $address
1662
1662
* @return \Magento\Framework\Phrase|string
1663
1663
*/
1664
- private function getDeliveryAddress ($ address ) : \Magento \Framework \Phrase | string
1664
+ private function getDeliveryAddress ($ address ): \Magento \Framework \Phrase | string
1665
1665
{
1666
1666
$ details = [];
1667
1667
@@ -1688,7 +1688,7 @@ private function getDeliveryAddress($address) : \Magento\Framework\Phrase | stri
1688
1688
* @param array $events
1689
1689
* @return array
1690
1690
*/
1691
- private function processTrackDetailsEvents (array $ events ) : array
1691
+ private function processTrackDetailsEvents (array $ events ): array
1692
1692
{
1693
1693
$ result = [];
1694
1694
foreach ($ events as $ event ) {
0 commit comments