77namespace Magento \Fedex \Model ;
88
99use Magento \Framework \App \ObjectManager ;
10+ use Magento \Framework \DataObject ;
1011use Magento \Framework \Module \Dir ;
1112use Magento \Framework \Serialize \Serializer \Json ;
13+ use Magento \Framework \Webapi \Soap \ClientFactory ;
1214use Magento \Framework \Xml \Security ;
1315use Magento \Quote \Model \Quote \Address \RateRequest ;
1416use Magento \Shipping \Model \Carrier \AbstractCarrierOnline ;
1719/**
1820 * Fedex shipping implementation
1921 *
20- * @author Magento Core Team <[email protected] > 2122 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2223 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2324 */
@@ -143,6 +144,11 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
143144 */
144145 private $ serializer ;
145146
147+ /**
148+ * @var ClientFactory
149+ */
150+ private $ soapClientFactory ;
151+
146152 /**
147153 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
148154 * @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
@@ -164,7 +170,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
164170 * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
165171 * @param array $data
166172 * @param Json|null $serializer
167- *
173+ * @param ClientFactory|null $soapClientFactory
168174 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
169175 */
170176 public function __construct (
@@ -187,7 +193,8 @@ public function __construct(
187193 \Magento \Framework \Module \Dir \Reader $ configReader ,
188194 \Magento \Catalog \Model \ResourceModel \Product \CollectionFactory $ productCollectionFactory ,
189195 array $ data = [],
190- Json $ serializer = null
196+ Json $ serializer = null ,
197+ ClientFactory $ soapClientFactory = null
191198 ) {
192199 $ this ->_storeManager = $ storeManager ;
193200 $ this ->_productCollectionFactory = $ productCollectionFactory ;
@@ -214,6 +221,7 @@ public function __construct(
214221 $ this ->_rateServiceWsdl = $ wsdlBasePath . 'RateService_v10.wsdl ' ;
215222 $ this ->_trackServiceWsdl = $ wsdlBasePath . 'TrackService_v ' . self ::$ trackServiceVersion . '.wsdl ' ;
216223 $ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
224+ $ this ->soapClientFactory = $ soapClientFactory ?: ObjectManager::getInstance ()->get (ClientFactory::class);
217225 }
218226
219227 /**
@@ -225,7 +233,7 @@ public function __construct(
225233 */
226234 protected function _createSoapClient ($ wsdl , $ trace = false )
227235 {
228- $ client = new \ SoapClient ($ wsdl , ['trace ' => $ trace ]);
236+ $ client = $ this -> soapClientFactory -> create ($ wsdl , ['trace ' => $ trace ]);
229237 $ client ->__setLocation (
230238 $ this ->getConfigFlag (
231239 'sandbox_mode '
@@ -1263,7 +1271,7 @@ protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
12631271 $ countriesOfManufacture [] = $ product ->getCountryOfManufacture ();
12641272 }
12651273
1266- $ paymentType = $ request -> getIsReturn () ? ' RECIPIENT ' : ' SENDER ' ;
1274+ $ paymentType = $ this -> getPaymentType ( $ request ) ;
12671275 $ optionType = $ request ->getShippingMethod () == self ::RATE_REQUEST_SMARTPOST
12681276 ? 'SERVICE_DEFAULT ' : $ packageParams ->getDeliveryConfirmation ();
12691277 $ requestClient = [
@@ -1749,4 +1757,18 @@ private function parseDate($timestamp)
17491757
17501758 return false ;
17511759 }
1760+
1761+ /**
1762+ * Defines payment type by request.
1763+ * Two values are available: RECIPIENT or SENDER.
1764+ *
1765+ * @param DataObject $request
1766+ * @return string
1767+ */
1768+ private function getPaymentType (DataObject $ request ): string
1769+ {
1770+ return $ request ->getIsReturn () && $ request ->getShippingMethod () !== self ::RATE_REQUEST_SMARTPOST
1771+ ? 'RECIPIENT '
1772+ : 'SENDER ' ;
1773+ }
17521774}
0 commit comments