7
7
namespace Magento \Fedex \Model ;
8
8
9
9
use Magento \Framework \App \ObjectManager ;
10
+ use Magento \Framework \DataObject ;
10
11
use Magento \Framework \Module \Dir ;
11
12
use Magento \Framework \Serialize \Serializer \Json ;
13
+ use Magento \Framework \Webapi \Soap \ClientFactory ;
12
14
use Magento \Framework \Xml \Security ;
13
15
use Magento \Quote \Model \Quote \Address \RateRequest ;
14
16
use Magento \Shipping \Model \Carrier \AbstractCarrierOnline ;
17
19
/**
18
20
* Fedex shipping implementation
19
21
*
20
- * @author Magento Core Team <core@magentocommerce.com>
21
22
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
22
23
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23
24
*/
@@ -143,6 +144,11 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
143
144
*/
144
145
private $ serializer ;
145
146
147
+ /**
148
+ * @var ClientFactory
149
+ */
150
+ private $ soapClientFactory ;
151
+
146
152
/**
147
153
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
148
154
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
@@ -164,7 +170,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
164
170
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
165
171
* @param array $data
166
172
* @param Json|null $serializer
167
- *
173
+ * @param ClientFactory|null $soapClientFactory
168
174
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
169
175
*/
170
176
public function __construct (
@@ -187,7 +193,8 @@ public function __construct(
187
193
\Magento \Framework \Module \Dir \Reader $ configReader ,
188
194
\Magento \Catalog \Model \ResourceModel \Product \CollectionFactory $ productCollectionFactory ,
189
195
array $ data = [],
190
- Json $ serializer = null
196
+ Json $ serializer = null ,
197
+ ClientFactory $ soapClientFactory = null
191
198
) {
192
199
$ this ->_storeManager = $ storeManager ;
193
200
$ this ->_productCollectionFactory = $ productCollectionFactory ;
@@ -214,6 +221,7 @@ public function __construct(
214
221
$ this ->_rateServiceWsdl = $ wsdlBasePath . 'RateService_v10.wsdl ' ;
215
222
$ this ->_trackServiceWsdl = $ wsdlBasePath . 'TrackService_v ' . self ::$ trackServiceVersion . '.wsdl ' ;
216
223
$ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
224
+ $ this ->soapClientFactory = $ soapClientFactory ?: ObjectManager::getInstance ()->get (ClientFactory::class);
217
225
}
218
226
219
227
/**
@@ -225,7 +233,7 @@ public function __construct(
225
233
*/
226
234
protected function _createSoapClient ($ wsdl , $ trace = false )
227
235
{
228
- $ client = new \ SoapClient ($ wsdl , ['trace ' => $ trace ]);
236
+ $ client = $ this -> soapClientFactory -> create ($ wsdl , ['trace ' => $ trace ]);
229
237
$ client ->__setLocation (
230
238
$ this ->getConfigFlag (
231
239
'sandbox_mode '
@@ -1263,7 +1271,7 @@ protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
1263
1271
$ countriesOfManufacture [] = $ product ->getCountryOfManufacture ();
1264
1272
}
1265
1273
1266
- $ paymentType = $ request -> getIsReturn () ? ' RECIPIENT ' : ' SENDER ' ;
1274
+ $ paymentType = $ this -> getPaymentType ( $ request ) ;
1267
1275
$ optionType = $ request ->getShippingMethod () == self ::RATE_REQUEST_SMARTPOST
1268
1276
? 'SERVICE_DEFAULT ' : $ packageParams ->getDeliveryConfirmation ();
1269
1277
$ requestClient = [
@@ -1749,4 +1757,18 @@ private function parseDate($timestamp)
1749
1757
1750
1758
return false ;
1751
1759
}
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
+ }
1752
1774
}
0 commit comments