77 private static $weightPrecision = 10;
160 \
Magento\Framework\
App\Config\ScopeConfigInterface $scopeConfig,
161 \
Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
162 \Psr\Log\LoggerInterface
$logger,
164 \
Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory,
165 \
Magento\Shipping\Model\Rate\ResultFactory $rateFactory,
166 \
Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory,
167 \
Magento\Shipping\Model\Tracking\ResultFactory $trackFactory,
168 \
Magento\Shipping\Model\Tracking\
Result\ErrorFactory $trackErrorFactory,
169 \
Magento\Shipping\Model\Tracking\
Result\StatusFactory $trackStatusFactory,
170 \
Magento\Directory\Model\RegionFactory $regionFactory,
171 \
Magento\Directory\Model\CountryFactory $countryFactory,
172 \
Magento\Directory\Model\CurrencyFactory $currencyFactory,
173 \
Magento\Directory\Helper\Data $directoryData,
175 CarrierHelper $carrierHelper,
177 \
Magento\Framework\HTTP\ZendClientFactory $httpClientFactory,
180 $this->_carrierHelper = $carrierHelper;
181 $this->_productCollectionFactory = $productCollectionFactory;
182 $this->_httpClientFactory = $httpClientFactory;
235 $r = new \Magento\Framework\DataObject();
238 $r->setService(
$request->getLimitMethod());
240 $r->setService(
'ALL');
244 $userId =
$request->getUspsUserid();
248 $r->setUserId($userId);
251 $container =
$request->getUspsContainer();
255 $r->setContainer($container);
269 $r->setGirth($girth);
276 $r->setHeight($height);
283 $r->setLength($length);
290 $r->setWidth($width);
292 if (
$request->getUspsMachinable()) {
293 $machinable =
$request->getUspsMachinable();
297 $r->setMachinable($machinable);
300 $r->setOrigPostal(
$request->getOrigPostcode());
303 $this->_scopeConfig->getValue(
304 \
Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_ZIP,
305 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
312 $r->setOrigCountryId(
$request->getOrigCountryId());
314 $r->setOrigCountryId(
315 $this->_scopeConfig->getValue(
316 \
Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID,
317 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
324 $destCountry =
$request->getDestCountryId();
329 $r->setDestCountryId($destCountry);
336 $r->setDestPostal(
$request->getDestPostcode());
340 $r->setWeightPounds(floor($weight));
341 $ounces = ($weight - floor($weight)) * self::OUNCES_POUND;
342 $r->setWeightOunces(sprintf(
'%.' . self::$weightPrecision .
'f', $ounces));
344 $r->setFreeMethodWeight(
$request->getFreeMethodWeight());
347 $r->setValue(
$request->getPackageValue());
348 $r->setValueWithDiscount(
$request->getPackageValueWithDiscount());
350 $r->setBaseSubtotalInclTax(
$request->getBaseSubtotalInclTax());
397 $r->setWeightPounds(floor($weight));
398 $ounces = ($weight - floor($weight)) * self::OUNCES_POUND;
399 $r->setWeightOunces(sprintf(
'%.' . self::$weightPrecision .
'f', $ounces));
400 $r->setService($freeMethod);
424 $xml = $this->_xmlElFactory->create(
425 [
'data' =>
'<?xml version="1.0" encoding="UTF-8"?><RateV4Request/>']
427 $xml->addAttribute(
'USERID', $r->getUserId());
429 $xml->addChild(
'Revision',
'2');
431 $package = $xml->addChild(
'Package');
432 $package->addAttribute(
'ID', 0);
438 if (strpos($r->getContainer(),
'FLAT RATE ENVELOPE') !==
false ||
439 strpos($r->getContainer(),
'FLAT RATE BOX') !==
false 444 $package->addChild(
'Service',
$service);
447 if ($r->getService() ==
'FIRST CLASS' || $r->getService() ==
'FIRST CLASS HFP COMMERCIAL') {
448 $package->addChild(
'FirstClassMailType',
'PARCEL');
450 $package->addChild(
'ZipOrigination', $r->getOrigPostal());
452 $package->addChild(
'ZipDestination', substr($r->getDestPostal(), 0, 5));
453 $package->addChild(
'Pounds', $r->getWeightPounds());
454 $package->addChild(
'Ounces', $r->getWeightOunces());
456 $package->addChild(
'Container', $r->getContainer());
457 $package->addChild(
'Size', $r->getSize());
458 if ($r->getSize() ==
'LARGE') {
459 $package->addChild(
'Width', $r->getWidth());
460 $package->addChild(
'Length', $r->getLength());
461 $package->addChild(
'Height', $r->getHeight());
462 if ($r->getContainer() ==
'NONRECTANGULAR' || $r->getContainer() ==
'VARIABLE') {
463 $package->addChild(
'Girth', $r->getGirth());
466 $package->addChild(
'Machinable', $r->getMachinable());
470 $xml = $this->_xmlElFactory->create(
471 [
'data' =>
'<?xml version = "1.0" encoding = "UTF-8"?><IntlRateV2Request/>']
473 $xml->addAttribute(
'USERID', $r->getUserId());
475 $xml->addChild(
'Revision',
'2');
477 $package = $xml->addChild(
'Package');
478 $package->addAttribute(
'ID', 0);
479 $package->addChild(
'Pounds', $r->getWeightPounds());
480 $package->addChild(
'Ounces', $r->getWeightOunces());
481 $package->addChild(
'MailType',
'All');
482 $package->addChild(
'ValueOfContents', $r->getValue());
483 $package->addChild(
'Country', $r->getDestCountryName());
484 $package->addChild(
'Container', $r->getContainer());
485 $package->addChild(
'Size', $r->getSize());
486 $width = $length = $height = $girth =
'';
487 if ($r->getSize() ==
'LARGE') {
488 $width = $r->getWidth();
489 $length = $r->getLength();
490 $height = $r->getHeight();
491 if ($r->getContainer() ==
'NONRECTANGULAR') {
492 $girth = $r->getGirth();
495 $package->addChild(
'Width', $width);
496 $package->addChild(
'Length', $length);
497 $package->addChild(
'Height', $height);
498 $package->addChild(
'Girth', $girth);
500 $package->addChild(
'OriginZip', $r->getOrigPostal());
501 $package->addChild(
'AcceptanceDateTime', date(
'c'));
502 $package->addChild(
'DestinationPostalCode', $r->getDestPostal());
509 if ($responseBody ===
null) {
516 $client = $this->_httpClientFactory->create();
517 $client->setUri(
$url);
518 $client->setConfig([
'maxredirects' => 0,
'timeout' => 30]);
519 $client->setParameterGet(
'API', $api);
520 $client->setParameterGet(
'XML',
$request);
524 $debugData[
'result'] = $responseBody;
526 }
catch (\Exception $e) {
527 $debugData[
'result'] = [
'error' => $e->getMessage(),
'code' => $e->getCode()];
530 $this->
_debug($debugData);
551 if (strpos(trim(
$response),
'<?xml') === 0) {
552 if (strpos(
$response,
'<?xml version="1.0"?>') !==
false) {
554 '<?xml version="1.0"?>',
555 '<?xml version="1.0" encoding="ISO-8859-1"?>',
561 if (is_object($xml)) {
562 $allowedMethods = explode(
',', $this->
getConfigData(
'allowed_methods'));
563 $serviceCodeToActualNameMap = [];
568 if (is_object($xml->Package) && is_object($xml->Package->Postage)) {
569 foreach ($xml->Package->Postage as $postage) {
571 $_serviceCode = $this->
getCode(
'method_to_code', $serviceName);
572 $serviceCode = $_serviceCode ? $_serviceCode : (string)$postage->attributes()->CLASSID;
573 $serviceCodeToActualNameMap[$serviceCode] = $serviceName;
574 if (in_array($serviceCode, $allowedMethods)) {
575 $costArr[$serviceCode] = (string)$postage->Rate;
576 $priceArr[$serviceCode] = $this->getMethodPrice(
577 (
string)$postage->Rate,
588 if (is_object($xml->Package) && is_object($xml->Package->Service)) {
589 foreach ($xml->Package->Service as
$service) {
591 $serviceCode =
'INT_' . (string)
$service->attributes()->ID;
592 $serviceCodeToActualNameMap[$serviceCode] = $serviceName;
593 if (!$this->isServiceAvailable(
$service)) {
596 if (in_array($serviceCode, $allowedMethods)) {
597 $costArr[$serviceCode] = (string)
$service->Postage;
598 $priceArr[$serviceCode] = $this->getMethodPrice(
611 $result = $this->_rateFactory->create();
612 if (empty($priceArr)) {
613 $error = $this->_rateErrorFactory->create();
614 $error->setCarrier(
'usps');
616 $error->setErrorMessage($this->
getConfigData(
'specificerrmsg'));
620 $rate = $this->_rateMethodFactory->create();
621 $rate->setCarrier(
'usps');
624 $rate->setMethodTitle(
626 $serviceCodeToActualNameMap[
$method]
653 '0_FCLE' =>
__(
'First-Class Mail Large Envelope'),
654 '0_FCL' =>
__(
'First-Class Mail Letter'),
655 '0_FCP' =>
__(
'First-Class Package Service - Retail'),
656 '0_FCPC' =>
__(
'First-Class Mail Postcards'),
657 '1' =>
__(
'Priority Mail'),
658 '2' =>
__(
'Priority Mail Express Hold For Pickup'),
659 '3' =>
__(
'Priority Mail Express'),
660 '4' =>
__(
'Retail Ground'),
661 '6' =>
__(
'Media Mail'),
662 '7' =>
__(
'Library Mail'),
663 '13' =>
__(
'Priority Mail Express Flat Rate Envelope'),
664 '15' =>
__(
'First-Class Mail Large Postcards'),
665 '16' =>
__(
'Priority Mail Flat Rate Envelope'),
666 '17' =>
__(
'Priority Mail Medium Flat Rate Box'),
667 '22' =>
__(
'Priority Mail Large Flat Rate Box'),
668 '23' =>
__(
'Priority Mail Express Sunday/Holiday Delivery'),
669 '25' =>
__(
'Priority Mail Express Sunday/Holiday Delivery Flat Rate Envelope'),
670 '27' =>
__(
'Priority Mail Express Flat Rate Envelope Hold For Pickup'),
671 '28' =>
__(
'Priority Mail Small Flat Rate Box'),
672 '29' =>
__(
'Priority Mail Padded Flat Rate Envelope'),
673 '30' =>
__(
'Priority Mail Express Legal Flat Rate Envelope'),
674 '31' =>
__(
'Priority Mail Express Legal Flat Rate Envelope Hold For Pickup'),
675 '32' =>
__(
'Priority Mail Express Sunday/Holiday Delivery Legal Flat Rate Envelope'),
676 '33' =>
__(
'Priority Mail Hold For Pickup'),
677 '34' =>
__(
'Priority Mail Large Flat Rate Box Hold For Pickup'),
678 '35' =>
__(
'Priority Mail Medium Flat Rate Box Hold For Pickup'),
679 '36' =>
__(
'Priority Mail Small Flat Rate Box Hold For Pickup'),
680 '37' =>
__(
'Priority Mail Flat Rate Envelope Hold For Pickup'),
681 '38' =>
__(
'Priority Mail Gift Card Flat Rate Envelope'),
682 '39' =>
__(
'Priority Mail Gift Card Flat Rate Envelope Hold For Pickup'),
683 '40' =>
__(
'Priority Mail Window Flat Rate Envelope'),
684 '41' =>
__(
'Priority Mail Window Flat Rate Envelope Hold For Pickup'),
685 '42' =>
__(
'Priority Mail Small Flat Rate Envelope'),
686 '43' =>
__(
'Priority Mail Small Flat Rate Envelope Hold For Pickup'),
687 '44' =>
__(
'Priority Mail Legal Flat Rate Envelope'),
688 '45' =>
__(
'Priority Mail Legal Flat Rate Envelope Hold For Pickup'),
689 '46' =>
__(
'Priority Mail Padded Flat Rate Envelope Hold For Pickup'),
690 '47' =>
__(
'Priority Mail Regional Rate Box A'),
691 '48' =>
__(
'Priority Mail Regional Rate Box A Hold For Pickup'),
692 '49' =>
__(
'Priority Mail Regional Rate Box B'),
693 '50' =>
__(
'Priority Mail Regional Rate Box B Hold For Pickup'),
694 '53' =>
__(
'First-Class Package Service Hold For Pickup'),
695 '57' =>
__(
'Priority Mail Express Sunday/Holiday Delivery Flat Rate Boxes'),
696 '58' =>
__(
'Priority Mail Regional Rate Box C'),
697 '59' =>
__(
'Priority Mail Regional Rate Box C Hold For Pickup'),
698 '61' =>
__(
'First-Class Package Service'),
699 '62' =>
__(
'Priority Mail Express Padded Flat Rate Envelope'),
700 '63' =>
__(
'Priority Mail Express Padded Flat Rate Envelope Hold For Pickup'),
701 '64' =>
__(
'Priority Mail Express Sunday/Holiday Delivery Padded Flat Rate Envelope'),
702 'INT_1' =>
__(
'Priority Mail Express International'),
703 'INT_2' =>
__(
'Priority Mail International'),
704 'INT_4' =>
__(
'Global Express Guaranteed (GXG)'),
705 'INT_5' =>
__(
'Global Express Guaranteed Document'),
706 'INT_6' =>
__(
'Global Express Guaranteed Non-Document Rectangular'),
707 'INT_7' =>
__(
'Global Express Guaranteed Non-Document Non-Rectangular'),
708 'INT_8' =>
__(
'Priority Mail International Flat Rate Envelope'),
709 'INT_9' =>
__(
'Priority Mail International Medium Flat Rate Box'),
710 'INT_10' =>
__(
'Priority Mail Express International Flat Rate Envelope'),
711 'INT_11' =>
__(
'Priority Mail International Large Flat Rate Box'),
712 'INT_12' =>
__(
'USPS GXG Envelopes'),
713 'INT_13' =>
__(
'First-Class Mail International Letter'),
714 'INT_14' =>
__(
'First-Class Mail International Large Envelope'),
715 'INT_15' =>
__(
'First-Class Package International Service'),
716 'INT_16' =>
__(
'Priority Mail International Small Flat Rate Box'),
717 'INT_17' =>
__(
'Priority Mail Express International Legal Flat Rate Envelope'),
718 'INT_18' =>
__(
'Priority Mail International Gift Card Flat Rate Envelope'),
719 'INT_19' =>
__(
'Priority Mail International Window Flat Rate Envelope'),
720 'INT_20' =>
__(
'Priority Mail International Small Flat Rate Envelope'),
721 'INT_21' =>
__(
'First-Class Mail International Postcard'),
722 'INT_22' =>
__(
'Priority Mail International Legal Flat Rate Envelope'),
723 'INT_23' =>
__(
'Priority Mail International Padded Flat Rate Envelope'),
724 'INT_24' =>
__(
'Priority Mail International DVD Flat Rate priced box'),
725 'INT_25' =>
__(
'Priority Mail International Large Video Flat Rate priced box'),
726 'INT_27' =>
__(
'Priority Mail Express International Padded Flat Rate Envelope'),
728 'service_to_code' => [
729 '0_FCLE' =>
'First Class',
730 '0_FCL' =>
'First Class',
731 '0_FCP' =>
'First Class',
732 '0_FCPC' =>
'First Class',
734 '2' =>
'Priority Express',
735 '3' =>
'Priority Express',
736 '4' =>
'Retail Ground',
739 '13' =>
'Priority Express',
740 '15' =>
'First Class',
744 '23' =>
'Priority Express',
745 '25' =>
'Priority Express',
746 '27' =>
'Priority Express',
749 '30' =>
'Priority Express',
750 '31' =>
'Priority Express',
751 '32' =>
'Priority Express',
770 '53' =>
'First Class',
771 '57' =>
'Priority Express',
774 '61' =>
'First Class',
775 '62' =>
'Priority Express',
776 '63' =>
'Priority Express',
777 '64' =>
'Priority Express',
778 'INT_1' =>
'Priority Express',
779 'INT_2' =>
'Priority',
780 'INT_4' =>
'Priority Express',
781 'INT_5' =>
'Priority Express',
782 'INT_6' =>
'Priority Express',
783 'INT_7' =>
'Priority Express',
784 'INT_8' =>
'Priority',
785 'INT_9' =>
'Priority',
786 'INT_10' =>
'Priority Express',
787 'INT_11' =>
'Priority',
788 'INT_12' =>
'Priority Express',
789 'INT_13' =>
'First Class',
790 'INT_14' =>
'First Class',
791 'INT_15' =>
'First Class',
792 'INT_16' =>
'Priority',
793 'INT_17' =>
'Priority',
794 'INT_18' =>
'Priority',
795 'INT_19' =>
'Priority',
796 'INT_20' =>
'Priority',
797 'INT_21' =>
'First Class',
798 'INT_22' =>
'Priority',
799 'INT_23' =>
'Priority',
800 'INT_24' =>
'Priority',
801 'INT_25' =>
'Priority',
802 'INT_27' =>
'Priority Express',
804 'method_to_code' => [
805 'First-Class Mail Large Envelope' =>
'0_FCLE',
806 'First-Class Mail Letter' =>
'0_FCL',
807 'First-Class Package Service - Retail' =>
'0_FCP',
809 'first_class_mail_type' => [
'LETTER' =>
__(
'Letter'),
'FLAT' =>
__(
'Flat'),
'PARCEL' =>
__(
'Parcel')],
811 'VARIABLE' =>
__(
'Variable'),
812 'SM FLAT RATE BOX' =>
__(
'Small Flat-Rate Box'),
813 'MD FLAT RATE BOX' =>
__(
'Medium Flat-Rate Box'),
814 'LG FLAT RATE BOX' =>
__(
'Large Flat-Rate Box'),
815 'FLAT RATE ENVELOPE' =>
__(
'Flat-Rate Envelope'),
816 'SM FLAT RATE ENVELOPE' =>
__(
'Small Flat-Rate Envelope'),
817 'WINDOW FLAT RATE ENVELOPE' =>
__(
'Window Flat-Rate Envelope'),
818 'GIFT CARD FLAT RATE ENVELOPE' =>
__(
'Gift Card Flat-Rate Envelope'),
819 'LEGAL FLAT RATE ENVELOPE' =>
__(
'Legal Flat-Rate Envelope'),
820 'PADDED FLAT RATE ENVELOPE' =>
__(
'Padded Flat-Rate Envelope'),
821 'RECTANGULAR' =>
__(
'Rectangular'),
822 'NONRECTANGULAR' =>
__(
'Non-rectangular'),
824 'containers_filter' => [
826 'containers' => [
'VARIABLE'],
830 '13',
'27',
'16',
'22',
'17',
'28',
'2',
'3',
'1',
'33',
'34',
'35',
831 '36',
'37',
'42',
'43',
'53',
'4',
'6',
'15',
'23',
'25',
'57' 836 'INT_10',
'INT_8',
'INT_11',
'INT_9',
'INT_16',
'INT_20',
'INT_4',
837 'INT_12',
'INT_1',
'INT_2',
'INT_13',
'INT_14',
'INT_15' 843 'containers' => [
'SM FLAT RATE BOX'],
846 'method' => [
'28',
'57'],
849 'method' => [
'INT_16',
'INT_24'],
854 'containers' => [
'MD FLAT RATE BOX'],
857 'method' => [
'17',
'57'],
860 'method' => [
'INT_9',
'INT_24'],
865 'containers' => [
'LG FLAT RATE BOX'],
868 'method' => [
'22',
'57'],
871 'method' => [
'INT_11',
'INT_24',
'INT_25'],
876 'containers' => [
'SM FLAT RATE ENVELOPE'],
879 'method' => [
'42',
'43'],
882 'method' => [
'INT_20'],
887 'containers' => [
'WINDOW FLAT RATE ENVELOPE'],
890 'method' => [
'40',
'41'],
893 'method' => [
'INT_19'],
898 'containers' => [
'GIFT CARD FLAT RATE ENVELOPE'],
901 'method' => [
'38',
'39'],
904 'method' => [
'INT_18'],
909 'containers' => [
'PADDED FLAT RATE ENVELOPE'],
912 'method' => [
'62',
'63',
'64',
'46',
'29'],
915 'method' => [
'INT_27',
'INT_23'],
920 'containers' => [
'LEGAL FLAT RATE ENVELOPE'],
923 'method' => [
'44',
'45',
'30',
'31',
'32'],
926 'method' => [
'INT_17',
'INT_22'],
931 'containers' => [
'FLAT RATE ENVELOPE'],
934 'method' => [
'16',
'13',
'27',
'16',
'15',
'37',
'42',
'43',
'25',
'62'],
938 'INT_10',
'INT_8',
'INT_14',
'INT_20',
'INT_17',
'INT_18',
'INT_19',
'INT_22',
'INT_27' 944 'containers' => [
'RECTANGULAR'],
947 'method' => [
'3',
'1',
'4',
'6',
'7',
'61'],
950 'method' => [
'INT_12',
'INT_1',
'INT_2',
'INT_15'],
955 'containers' => [
'NONRECTANGULAR'],
958 'method' => [
'3',
'1',
'4',
'6',
'7'],
961 'method' => [
'INT_4',
'INT_1',
'INT_2',
'INT_15'],
966 'size' => [
'REGULAR' =>
__(
'Regular'),
'LARGE' =>
__(
'Large')],
967 'machinable' => [
'true' =>
__(
'Yes'),
'false' =>
__(
'No')],
968 'delivery_confirmation_types' => [
'True' =>
__(
'Not Required'),
'False' =>
__(
'Required')],
971 if (!isset($codes[
$type])) {
974 return $codes[
$type];
994 if (!is_array($trackings)) {
995 $trackings = [$trackings];
1010 $r = new \Magento\Framework\DataObject();
1013 $r->setUserId($userId);
1015 $this->_rawTrackRequest = $r;
1026 $r = $this->_rawTrackRequest;
1028 foreach ($trackings as $tracking) {
1029 $xml = $this->_xmlElFactory->create(
1030 [
'data' =>
'<?xml version = "1.0" encoding = "UTF-8"?><TrackRequest/>']
1032 $xml->addAttribute(
'USERID', $r->getUserId());
1034 $trackid = $xml->addChild(
'TrackID');
1035 $trackid->addAttribute(
'ID', $tracking);
1046 $client = $this->_httpClientFactory->create();
1047 $client->setUri(
$url);
1048 $client->setConfig([
'maxredirects' => 0,
'timeout' => 30]);
1049 $client->setParameterGet(
'API', $api);
1050 $client->setParameterGet(
'XML',
$request);
1053 $debugData[
'result'] = $responseBody;
1054 }
catch (\Exception $e) {
1055 $debugData[
'result'] = [
'error' => $e->getMessage(),
'code' => $e->getCode()];
1059 $this->
_debug($debugData);
1075 $errorTitle =
__(
'For some reason we can\'t retrieve tracking info right now.');
1078 if (strpos(trim(
$response),
'<?xml') === 0) {
1080 if (is_object($xml)) {
1081 if (isset($xml->Number) && isset($xml->Description) && (
string)$xml->Description !=
'') {
1082 $errorTitle = (string)$xml->Description;
1083 }
elseif (isset($xml->TrackInfo)
1084 && isset($xml->TrackInfo->Error)
1085 && isset($xml->TrackInfo->Error->Description)
1086 && (
string)$xml->TrackInfo->Error->Description !=
'' 1088 $errorTitle = (string)$xml->TrackInfo->Error->Description;
1091 'Sorry, something went wrong. Please try again or contact us and we\'ll try to help.' 1095 if (isset($xml->TrackInfo) && isset($xml->TrackInfo->TrackSummary)) {
1096 $resultArr[
'tracksummary'] = (string)$xml->TrackInfo->TrackSummary;
1102 if (!$this->_result) {
1103 $this->_result = $this->_trackFactory->create();
1105 $defaults = $this->getDefaults();
1108 $tracking = $this->_trackStatusFactory->create();
1109 $tracking->setCarrier(
'usps');
1111 $tracking->setTracking($trackingvalue);
1112 $tracking->setTrackSummary($resultArr[
'tracksummary']);
1113 $this->_result->append($tracking);
1115 $error = $this->_trackErrorFactory->create();
1116 $error->setCarrier(
'usps');
1118 $error->setTracking($trackingvalue);
1119 $error->setErrorMessage($errorTitle);
1120 $this->_result->append($error);
1132 if ($this->_result instanceof \
Magento\Shipping\Model\Tracking\
Result) {
1133 if ($trackings = $this->_result->getAllTrackings()) {
1134 foreach ($trackings as $tracking) {
1135 if (
$data = $tracking->getAllData()) {
1136 if (!empty(
$data[
'track_summary'])) {
1137 $statuses .=
__(
$data[
'track_summary']);
1139 $statuses .=
__(
'Empty response');
1145 if (empty($statuses)) {
1146 $statuses =
__(
'Empty response');
1159 $allowed = explode(
',', $this->
getConfigData(
'allowed_methods'));
1161 foreach ($allowed as $k) {
1162 $arr[$k] = $this->
getCode(
'method', $k);
1180 'AE' =>
'United Arab Emirates',
1181 'AF' =>
'Afghanistan',
1182 'AG' =>
'Antigua and Barbuda',
1186 'AN' =>
'Netherlands Antilles',
1188 'AR' =>
'Argentina',
1190 'AU' =>
'Australia',
1192 'AX' =>
'Aland Island (Finland)',
1193 'AZ' =>
'Azerbaijan',
1194 'BA' =>
'Bosnia-Herzegovina',
1196 'BD' =>
'Bangladesh',
1198 'BF' =>
'Burkina Faso',
1204 'BN' =>
'Brunei Darussalam',
1213 'CC' =>
'Cocos Island (Australia)',
1214 'CD' =>
'Congo, Democratic Republic of the',
1215 'CF' =>
'Central African Republic',
1216 'CG' =>
'Congo, Republic of the',
1217 'CH' =>
'Switzerland',
1218 'CI' =>
'Ivory Coast (Cote d Ivoire)',
1219 'CK' =>
'Cook Islands (New Zealand)',
1224 'CR' =>
'Costa Rica',
1226 'CV' =>
'Cape Verde',
1227 'CX' =>
'Christmas Island (Australia)',
1229 'CZ' =>
'Czech Republic',
1234 'DO' =>
'Dominican Republic',
1244 'FK' =>
'Falkland Islands',
1245 'FM' =>
'Micronesia, Federated States of',
1246 'FO' =>
'Faroe Islands',
1249 'GB' =>
'Great Britain and Northern Ireland',
1251 'GE' =>
'Georgia, Republic of',
1252 'GF' =>
'French Guiana',
1254 'GI' =>
'Gibraltar',
1255 'GL' =>
'Greenland',
1258 'GP' =>
'Guadeloupe',
1259 'GQ' =>
'Equatorial Guinea',
1261 'GS' =>
'South Georgia (Falkland Islands)',
1262 'GT' =>
'Guatemala',
1263 'GW' =>
'Guinea-Bissau',
1265 'HK' =>
'Hong Kong',
1270 'ID' =>
'Indonesia',
1282 'KG' =>
'Kyrgyzstan',
1286 'KN' =>
'Saint Kitts (Saint Christopher and Nevis)',
1287 'KP' =>
'North Korea (Korea, Democratic People\'s Republic of)',
1288 'KR' =>
'South Korea (Korea, Republic of)',
1290 'KY' =>
'Cayman Islands',
1291 'KZ' =>
'Kazakhstan',
1294 'LC' =>
'Saint Lucia',
1295 'LI' =>
'Liechtenstein',
1296 'LK' =>
'Sri Lanka',
1299 'LT' =>
'Lithuania',
1300 'LU' =>
'Luxembourg',
1304 'MC' =>
'Monaco (France)',
1306 'MG' =>
'Madagascar',
1307 'MK' =>
'Macedonia, Republic of',
1312 'MQ' =>
'Martinique',
1313 'MR' =>
'Mauritania',
1314 'MS' =>
'Montserrat',
1316 'MU' =>
'Mauritius',
1321 'MZ' =>
'Mozambique',
1323 'NC' =>
'New Caledonia',
1326 'NI' =>
'Nicaragua',
1327 'NL' =>
'Netherlands',
1331 'NZ' =>
'New Zealand',
1335 'PF' =>
'French Polynesia',
1336 'PG' =>
'Papua New Guinea',
1337 'PH' =>
'Philippines',
1340 'PM' =>
'Saint Pierre and Miquelon',
1341 'PN' =>
'Pitcairn Island',
1350 'SA' =>
'Saudi Arabia',
1351 'SB' =>
'Solomon Islands',
1352 'SC' =>
'Seychelles',
1355 'SG' =>
'Singapore',
1356 'SH' =>
'Saint Helena',
1358 'SK' =>
'Slovak Republic',
1359 'SL' =>
'Sierra Leone',
1360 'SM' =>
'San Marino',
1364 'ST' =>
'Sao Tome and Principe',
1365 'SV' =>
'El Salvador',
1366 'SY' =>
'Syrian Arab Republic',
1367 'SZ' =>
'Swaziland',
1368 'TC' =>
'Turks and Caicos Islands',
1372 'TJ' =>
'Tajikistan',
1373 'TK' =>
'Tokelau (Union Group) (Western Samoa)',
1374 'TL' =>
'East Timor (Timor-Leste, Democratic Republic of)',
1375 'TM' =>
'Turkmenistan',
1379 'TT' =>
'Trinidad and Tobago',
1386 'UZ' =>
'Uzbekistan',
1387 'VA' =>
'Vatican City',
1388 'VC' =>
'Saint Vincent and the Grenadines',
1389 'VE' =>
'Venezuela',
1390 'VG' =>
'British Virgin Islands',
1393 'WF' =>
'Wallis and Futuna Islands',
1394 'WS' =>
'Western Samoa',
1396 'YT' =>
'Mayotte (France)',
1397 'ZA' =>
'South Africa',
1400 'US' =>
'United States',
1403 if (isset($countries[$countryId])) {
1404 return $countries[$countryId];
1418 $name = (string)preg_replace(
1419 [
'~<[^/!][^>]+>.*</[^>]+>~sU',
'~<!--.*-->~isU',
'~<[^>]+>~is'],
1421 html_entity_decode(
$name)
1440 $packageParams =
$request->getPackageParams();
1442 $packageWeight =
$request->getPackageWeight();
1444 $packageWeight = round(
1445 $this->_carrierHelper->convertMeasureWeight(
1446 (
float)
$request->getPackageWeight(),
1447 $packageParams->getWeightUnits(),
1453 list($fromZip5, $fromZip4) = $this->
_parseZip($request->getShipperAddressPostalCode());
1454 list($toZip5, $toZip4) = $this->
_parseZip($request->getRecipientAddressPostalCode(),
true);
1456 $rootNode =
'ExpressMailLabelRequest';
1458 $xmlWrap = $this->_xmlElFactory->create([
'data' =>
'<?xml version = "1.0" encoding = "UTF-8"?><wrap/>']);
1459 $xml = $xmlWrap->addChild($rootNode);
1460 $xml->addAttribute(
'USERID', $this->
getConfigData(
'userid'));
1461 $xml->addAttribute(
'PASSWORD', $this->
getConfigData(
'password'));
1462 $xml->addChild(
'Option');
1463 $xml->addChild(
'Revision');
1464 $xml->addChild(
'EMCAAccount');
1465 $xml->addChild(
'EMCAPassword');
1466 $xml->addChild(
'ImageParameters');
1467 $xml->addChild(
'FromFirstName',
$request->getShipperContactPersonFirstName());
1468 $xml->addChild(
'FromLastName',
$request->getShipperContactPersonLastName());
1469 $xml->addChild(
'FromFirm',
$request->getShipperContactCompanyName());
1470 $xml->addChild(
'FromAddress1',
$request->getShipperAddressStreet2());
1471 $xml->addChild(
'FromAddress2',
$request->getShipperAddressStreet1());
1472 $xml->addChild(
'FromCity',
$request->getShipperAddressCity());
1473 $xml->addChild(
'FromState',
$request->getShipperAddressStateOrProvinceCode());
1474 $xml->addChild(
'FromZip5', $fromZip5);
1475 $xml->addChild(
'FromZip4', $fromZip4);
1476 $xml->addChild(
'FromPhone',
$request->getShipperContactPhoneNumber());
1477 $xml->addChild(
'ToFirstName',
$request->getRecipientContactPersonFirstName());
1478 $xml->addChild(
'ToLastName',
$request->getRecipientContactPersonLastName());
1479 $xml->addChild(
'ToFirm',
$request->getRecipientContactCompanyName());
1480 $xml->addChild(
'ToAddress1',
$request->getRecipientAddressStreet2());
1481 $xml->addChild(
'ToAddress2',
$request->getRecipientAddressStreet1());
1482 $xml->addChild(
'ToCity',
$request->getRecipientAddressCity());
1483 $xml->addChild(
'ToState',
$request->getRecipientAddressStateOrProvinceCode());
1484 $xml->addChild(
'ToZip5', $toZip5);
1485 $xml->addChild(
'ToZip4', $toZip4);
1486 $xml->addChild(
'ToPhone',
$request->getRecipientContactPhoneNumber());
1487 $xml->addChild(
'WeightInOunces', $packageWeight);
1488 $xml->addChild(
'WaiverOfSignature', $packageParams->getDeliveryConfirmation());
1489 $xml->addChild(
'POZipCode');
1490 $xml->addChild(
'ImageType',
'PDF');
1492 $xml = $xmlWrap->{$rootNode}->asXML();
1510 switch ($serviceType) {
1513 $serviceType =
'Priority';
1517 $serviceType =
'First Class';
1520 case 'Standard Post':
1521 case 'Retail Ground':
1522 $serviceType =
'Retail Ground';
1526 $serviceType =
'Media Mail';
1530 $serviceType =
'Library Mail';
1533 throw new \Exception(
__(
'Service type does not match'));
1535 $packageParams =
$request->getPackageParams();
1536 $packageWeight =
$request->getPackageWeight();
1538 $packageWeight = round(
1539 $this->_carrierHelper->convertMeasureWeight(
1540 (
float)
$request->getPackageWeight(),
1541 $packageParams->getWeightUnits(),
1547 list($fromZip5, $fromZip4) = $this->_parseZip(
$request->getShipperAddressPostalCode());
1548 list($toZip5, $toZip4) = $this->_parseZip(
$request->getRecipientAddressPostalCode(),
true);
1550 if ($this->getConfigData(
'mode')) {
1551 $rootNode =
'SignatureConfirmationV3.0Request';
1553 $rootNode =
'SigConfirmCertifyV3.0Request';
1556 $xmlWrap = $this->_xmlElFactory->create([
'data' =>
'<?xml version = "1.0" encoding = "UTF-8"?><wrap/>']);
1557 $xml = $xmlWrap->addChild($rootNode);
1558 $xml->addAttribute(
'USERID', $this->getConfigData(
'userid'));
1559 $xml->addChild(
'Option', 1);
1560 $xml->addChild(
'ImageParameters');
1561 $xml->addChild(
'FromName',
$request->getShipperContactPersonName());
1562 $xml->addChild(
'FromFirm',
$request->getShipperContactCompanyName());
1563 $xml->addChild(
'FromAddress1',
$request->getShipperAddressStreet2());
1564 $xml->addChild(
'FromAddress2',
$request->getShipperAddressStreet1());
1565 $xml->addChild(
'FromCity',
$request->getShipperAddressCity());
1566 $xml->addChild(
'FromState',
$request->getShipperAddressStateOrProvinceCode());
1567 $xml->addChild(
'FromZip5', $fromZip5);
1568 $xml->addChild(
'FromZip4', $fromZip4);
1569 $xml->addChild(
'ToName',
$request->getRecipientContactPersonName());
1570 $xml->addChild(
'ToFirm',
$request->getRecipientContactCompanyName());
1571 $xml->addChild(
'ToAddress1',
$request->getRecipientAddressStreet2());
1572 $xml->addChild(
'ToAddress2',
$request->getRecipientAddressStreet1());
1573 $xml->addChild(
'ToCity',
$request->getRecipientAddressCity());
1574 $xml->addChild(
'ToState',
$request->getRecipientAddressStateOrProvinceCode());
1575 $xml->addChild(
'ToZip5', $toZip5);
1576 $xml->addChild(
'ToZip4', $toZip4);
1577 $xml->addChild(
'WeightInOunces', $packageWeight);
1578 $xml->addChild(
'ServiceType', $serviceType);
1579 $xml->addChild(
'WaiverOfSignature', $packageParams->getDeliveryConfirmation());
1580 $xml->addChild(
'ImageType',
'PDF');
1582 $xml = $xmlWrap->{$rootNode}->asXML();
1595 $weightInOunces = ceil($weightInPounds * self::OUNCES_POUND);
1596 $pounds = floor($weightInOunces / self::OUNCES_POUND);
1597 $ounces = $weightInOunces % self::OUNCES_POUND;
1599 return [$pounds, $ounces];
1617 $packageParams =
$request->getPackageParams();
1618 $height = $packageParams->getHeight();
1619 $width = $packageParams->getWidth();
1620 $length = $packageParams->getLength();
1621 $girth = $packageParams->getGirth();
1622 $packageWeight =
$request->getPackageWeight();
1624 $packageWeight = $this->_carrierHelper->convertMeasureWeight(
1625 (
float)
$request->getPackageWeight(),
1626 $packageParams->getWeightUnits(),
1632 $this->_carrierHelper->convertMeasureDimension(
1633 (
float)$packageParams->getLength(),
1634 $packageParams->getDimensionUnits(),
1639 $this->_carrierHelper->convertMeasureDimension(
1640 (
float)$packageParams->getWidth(),
1641 $packageParams->getDimensionUnits(),
1646 $this->_carrierHelper->convertMeasureDimension(
1647 (
float)$packageParams->getHeight(),
1648 $packageParams->getDimensionUnits(),
1655 $this->_carrierHelper->convertMeasureDimension(
1656 (
float)$packageParams->getGirth(),
1657 $packageParams->getGirthDimensionUnits(),
1663 $container =
$request->getPackagingType();
1664 switch ($container) {
1666 $container =
'VARIABLE';
1668 case 'FLAT RATE ENVELOPE':
1669 $container =
'FLATRATEENV';
1671 case 'FLAT RATE BOX':
1672 $container =
'FLATRATEBOX';
1675 $container =
'RECTANGULAR';
1677 case 'NONRECTANGULAR':
1678 $container =
'NONRECTANGULAR';
1681 $container =
'VARIABLE';
1684 list($fromZip5, $fromZip4) = $this->_parseZip(
$request->getShipperAddressPostalCode());
1687 $xmlWrap = $this->_xmlElFactory->create([
'data' =>
'<?xml version = "1.0" encoding = "UTF-8"?><wrap/>']);
1692 $rootNode =
'PriorityMailIntlRequest';
1693 $xml = $xmlWrap->addChild($rootNode);
1697 $rootNode =
'FirstClassMailIntlRequest';
1698 $xml = $xmlWrap->addChild($rootNode);
1701 $rootNode =
'ExpressMailIntlRequest';
1702 $xml = $xmlWrap->addChild($rootNode);
1706 $xml->addAttribute(
'USERID', $this->getConfigData(
'userid'));
1707 $xml->addAttribute(
'PASSWORD', $this->getConfigData(
'password'));
1708 $xml->addChild(
'Option');
1709 $xml->addChild(
'Revision', self::DEFAULT_REVISION);
1710 $xml->addChild(
'ImageParameters');
1711 $xml->addChild(
'FromFirstName',
$request->getShipperContactPersonFirstName());
1712 $xml->addChild(
'FromLastName',
$request->getShipperContactPersonLastName());
1713 $xml->addChild(
'FromFirm',
$request->getShipperContactCompanyName());
1714 $xml->addChild(
'FromAddress1',
$request->getShipperAddressStreet2());
1715 $xml->addChild(
'FromAddress2',
$request->getShipperAddressStreet1());
1716 $xml->addChild(
'FromCity',
$request->getShipperAddressCity());
1717 $xml->addChild(
'FromState',
$request->getShipperAddressStateOrProvinceCode());
1718 $xml->addChild(
'FromZip5', $fromZip5);
1719 $xml->addChild(
'FromZip4', $fromZip4);
1720 $xml->addChild(
'FromPhone',
$request->getShipperContactPhoneNumber());
1721 if (
$method !=
'FirstClass') {
1722 if (
$request->getReferenceData()) {
1723 $referenceData =
$request->getReferenceData() .
' P' .
$request->getPackageId();
1725 $referenceData =
$request->getOrderShipment()->getOrder()->getIncrementId() .
1729 $xml->addChild(
'FromCustomsReference',
'Order #' . $referenceData);
1731 $xml->addChild(
'ToFirstName',
$request->getRecipientContactPersonFirstName());
1732 $xml->addChild(
'ToLastName',
$request->getRecipientContactPersonLastName());
1733 $xml->addChild(
'ToFirm',
$request->getRecipientContactCompanyName());
1734 $xml->addChild(
'ToAddress1',
$request->getRecipientAddressStreet1());
1735 $xml->addChild(
'ToAddress2',
$request->getRecipientAddressStreet2());
1736 $xml->addChild(
'ToCity',
$request->getRecipientAddressCity());
1737 $xml->addChild(
'ToProvince',
$request->getRecipientAddressStateOrProvinceCode());
1738 $xml->addChild(
'ToCountry', $this->_getCountryName(
$request->getRecipientAddressCountryCode()));
1739 $xml->addChild(
'ToPostalCode',
$request->getRecipientAddressPostalCode());
1740 $xml->addChild(
'ToPOBoxFlag',
'N');
1741 $xml->addChild(
'ToPhone',
$request->getRecipientContactPhoneNumber());
1742 $xml->addChild(
'ToFax');
1743 $xml->addChild(
'ToEmail');
1744 if (
$method !=
'FirstClass') {
1745 $xml->addChild(
'NonDeliveryOption',
'Return');
1747 if (
$method ==
'FirstClass') {
1749 $xml->addChild(
'FirstClassMailType',
'LETTER');
1752 $xml->addChild(
'FirstClassMailType',
'FLAT');
1754 $xml->addChild(
'FirstClassMailType',
'PARCEL');
1758 if (
$method !=
'FirstClass') {
1759 $xml->addChild(
'Container', $container);
1761 $shippingContents = $xml->addChild(
'ShippingContents');
1762 $packageItems =
$request->getPackageItems();
1764 $countriesOfManufacture = [];
1766 foreach ($packageItems as $itemShipment) {
1767 $item = new \Magento\Framework\DataObject();
1768 $item->setData($itemShipment);
1774 )->addFieldToFilter(
1777 )->addAttributeToSelect(
1778 'country_of_manufacture' 1781 $countriesOfManufacture[
$product->getId()] =
$product->getCountryOfManufacture();
1784 $packagePoundsWeight = $packageOuncesWeight = 0;
1786 foreach ($packageItems as $itemShipment) {
1787 $item = new \Magento\Framework\DataObject();
1788 $item->setData($itemShipment);
1790 $itemWeight =
$item->getWeight() *
$item->getQty();
1792 $itemWeight = $this->_carrierHelper->convertMeasureWeight(
1794 $packageParams->getWeightUnits(),
1798 if (!empty($countriesOfManufacture[
$item->getProductId()])) {
1799 $countryOfManufacture = $this->_getCountryName($countriesOfManufacture[
$item->getProductId()]);
1801 $countryOfManufacture =
'';
1803 $itemDetail = $shippingContents->addChild(
'ItemDetail');
1804 $itemDetail->addChild(
'Description',
$item->getName());
1805 $ceiledQty = ceil(
$item->getQty());
1806 if ($ceiledQty < 1) {
1809 $individualItemWeight = $itemWeight / $ceiledQty;
1810 $itemDetail->addChild(
'Quantity', $ceiledQty);
1811 $itemDetail->addChild(
'Value', sprintf(
'%.2F',
$item->getCustomsValue() *
$item->getQty()));
1812 list($individualPoundsWeight, $individualOuncesWeight) = $this->_convertPoundOunces($individualItemWeight);
1813 $itemDetail->addChild(
'NetPounds', $individualPoundsWeight);
1814 $itemDetail->addChild(
'NetOunces', sprintf(
'%.2F', $individualOuncesWeight));
1815 $itemDetail->addChild(
'HSTariffNumber', 0);
1816 $itemDetail->addChild(
'CountryOfOrigin', $countryOfManufacture);
1818 list($itemPoundsWeight, $itemOuncesWeight) = $this->_convertPoundOunces($itemWeight);
1819 $packagePoundsWeight += $itemPoundsWeight;
1820 $packageOuncesWeight += $itemOuncesWeight;
1822 $additionalPackagePoundsWeight = floor($packageOuncesWeight / self::OUNCES_POUND);
1823 $packagePoundsWeight += $additionalPackagePoundsWeight;
1824 $packageOuncesWeight -= $additionalPackagePoundsWeight * self::OUNCES_POUND;
1825 if ($packagePoundsWeight + $packageOuncesWeight / self::OUNCES_POUND < $packageWeight) {
1826 list($packagePoundsWeight, $packageOuncesWeight) = $this->_convertPoundOunces($packageWeight);
1829 $xml->addChild(
'GrossPounds', $packagePoundsWeight);
1830 $xml->addChild(
'GrossOunces', $packageOuncesWeight);
1831 if ($packageParams->getContentType() ==
'OTHER' && $packageParams->getContentTypeOther() !=
null) {
1832 $xml->addChild(
'ContentType', $packageParams->getContentType());
1833 $xml->addChild(
'ContentTypeOther ', $packageParams->getContentTypeOther());
1835 $xml->addChild(
'ContentType', $packageParams->getContentType());
1838 $xml->addChild(
'Agreement',
'y');
1839 $xml->addChild(
'ImageType',
'PDF');
1840 $xml->addChild(
'ImageLayout',
'ALLINONEFILE');
1841 if (
$method ==
'FirstClass') {
1842 $xml->addChild(
'Container', $container);
1845 if ($packageParams->getSize()) {
1846 $xml->addChild(
'Size', $packageParams->getSize());
1849 $xml->addChild(
'Length', $length);
1850 $xml->addChild(
'Width', $width);
1851 $xml->addChild(
'Height', $height);
1853 $xml->addChild(
'Girth', $girth);
1856 $xml = $xmlWrap->{$rootNode}->asXML();
1872 $this->_prepareShipmentRequest(
$request);
1873 $result = new \Magento\Framework\DataObject();
1874 $service = $this->getCode(
'service_to_code',
$request->getShippingMethod());
1875 $recipientUSCountry = $this->_isUSCountry(
$request->getRecipientAddressCountryCode());
1877 if ($recipientUSCountry &&
$service ==
'Priority Express') {
1878 $requestXml = $this->_formUsExpressShipmentRequest(
$request);
1879 $api =
'ExpressMailLabel';
1881 if ($recipientUSCountry) {
1882 $requestXml = $this->_formUsSignatureConfirmationShipmentRequest(
$request,
$service);
1883 if ($this->getConfigData(
'mode')) {
1884 $api =
'SignatureConfirmationV3';
1886 $api =
'SignatureConfirmationCertifyV3';
1890 $requestXml = $this->_formIntlShipmentRequest(
$request);
1891 $api =
'FirstClassMailIntl';
1894 $requestXml = $this->_formIntlShipmentRequest(
$request);
1895 $api =
'PriorityMailIntl';
1897 $requestXml = $this->_formIntlShipmentRequest(
$request);
1898 $api =
'ExpressMailIntl';
1904 $debugData = [
'request' => $this->filterDebugData($requestXml)];
1905 $url = $this->getConfigData(
'gateway_secure_url');
1907 $url = $this->_defaultGatewayUrl;
1909 $client = $this->_httpClientFactory->create();
1910 $client->setUri(
$url);
1911 $client->setConfig([
'maxredirects' => 0,
'timeout' => 30]);
1912 $client->setParameterGet(
'API', $api);
1913 $client->setParameterGet(
'XML', $requestXml);
1914 $response = $client->request()->getBody();
1920 $debugData[
'result'] = [
1925 $this->_debug($debugData);
1926 $result->setErrors($debugData[
'result'][
'error']);
1928 if ($recipientUSCountry &&
$service ==
'Priority Express') {
1929 $labelContent = base64_decode((
string)
$response->EMLabel);
1930 $trackingNumber = (string)
$response->EMConfirmationNumber;
1931 }
elseif ($recipientUSCountry) {
1932 $labelContent = base64_decode((
string)
$response->SignatureConfirmationLabel);
1933 $trackingNumber = (string)
$response->SignatureConfirmationNumber;
1935 $labelContent = base64_decode((
string)
$response->LabelImage);
1936 $trackingNumber = (string)
$response->BarcodeNumber;
1938 $result->setShippingLabelContent($labelContent);
1939 $result->setTrackingNumber($trackingNumber);
1945 $this->_debug($debugData);
1959 return $this->_getAllowedContainers();
1962 return $this->_isUSCountry(
$params->getCountryRecipient()) ? [] : $this->_getAllowedContainers(
$params);
1972 return $this->getCode(
'container');
1982 return $this->getCode(
'containers_filter');
1996 $countryRecipient =
$params->getCountryRecipient();
1997 if ($this->_isUSCountry($countryRecipient)) {
1998 return $this->getCode(
'delivery_confirmation_types');
2013 return $this->_isUSCountry($countyDest)
2014 && $this->getDataHelper()->displayGirthValue($carrierMethodCode) ?
false :
true;
2025 $countryShipper =
$params->getCountryShipper();
2026 $countryRecipient =
$params->getCountryRecipient();
2028 if ($countryShipper == self::USA_COUNTRY_ID && $countryRecipient != self::USA_COUNTRY_ID) {
2030 'MERCHANDISE' =>
__(
'Merchandise'),
2031 'SAMPLE' =>
__(
'Sample'),
2032 'GIFT' =>
__(
'Gift'),
2033 'DOCUMENTS' =>
__(
'Documents'),
2034 'RETURN' =>
__(
'Return'),
2035 'OTHER' =>
__(
'Other')
2049 protected function _parseZip($zipString, $returnFull =
false)
2053 $zip = [$zipString];
2054 if (preg_match(
'/[\\d\\w]{5}\\-[\\d\\w]{4}/', $zipString) != 0) {
2055 $zip = explode(
'-', $zipString);
2059 if (strlen($zip[
$i]) == 5) {
2065 if (empty($zip5) && empty($zip4) && $returnFull) {
2069 return [$zip5, $zip4];
2078 private function isServiceAvailable(\SimpleXMLElement
$service)
2081 if (empty(
$service->ExtraServices->children()->count())) {
2085 foreach (
$service->ExtraServices->children() as $child) {
2086 if (filter_var($child->Available, FILTER_VALIDATE_BOOLEAN)) {
2109 protected function filterDebugData(
$data)
2112 $xml = new \SimpleXMLElement(
$data);
2116 if (in_array((
string) $key, $this->_debugReplacePrivateDataKeys)) {
2120 $data = $xml->asXML();
2121 }
catch (\Exception $e) {
2133 private function getDataHelper()
2135 if (!$this->dataHelper) {
2136 $this->dataHelper = ObjectManager::getInstance()->get(DataHelper::class);
2139 return $this->dataHelper;
elseif(isset( $params[ 'redirect_parent']))
_formUsSignatureConfirmationShipmentRequest(\Magento\Framework\DataObject $request, $serviceType)
_filterServiceName($name)
collectRates(RateRequest $request)
getTotalNumOfBoxes($weight)
getContainerTypes(\Magento\Framework\DataObject $params=null)
const CONTAINER_RECTANGULAR
setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $request)
getDeliveryConfirmationTypes(\Magento\Framework\DataObject $params=null)
_getXmlTracking($trackings)
_formIntlShipmentRequest(\Magento\Framework\DataObject $request)
$_productCollectionFactory
_parseXmlResponse($response)
getContainerTypesFilter()
const CONTAINER_NONRECTANGULAR
_getCachedQuotes($requestParams)
const CONTAINER_FLAT_RATE_ENVELOPE
_doShipmentRequest(\Magento\Framework\DataObject $request)
_parseXmlTrackingResponse($trackingvalue, $response)
_setCachedQuotes($requestParams, $response)
getContentTypes(\Magento\Framework\DataObject $params)
parseXml($xmlContent, $customSimplexml='SimpleXMLElement')
_getCountryName($countryId)
_convertPoundOunces($weightInPounds)
_parseZip($zipString, $returnFull=false)
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, Security $xmlSecurity, \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, CarrierHelper $carrierHelper, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory, array $data=[])
_formUsExpressShipmentRequest(\Magento\Framework\DataObject $request)
_setFreeMethodRequest($freeMethod)
_updateFreeMethodQuote($request)
$_debugReplacePrivateDataKeys
const CONTAINER_FLAT_RATE_BOX
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
$_customizableContainerTypes
isShippingLabelsAvailable()
isGirthAllowed($countyDest=null, $carrierMethodCode=null)
if(!isset($_GET['name'])) $name