9
9
namespace Magento \Fedex \Model ;
10
10
11
11
use Magento \Framework \App \ObjectManager ;
12
+ use Magento \Framework \DataObject ;
12
13
use Magento \Framework \Module \Dir ;
13
14
use Magento \Framework \Serialize \Serializer \Json ;
15
+ use Magento \Framework \Webapi \Soap \ClientFactory ;
14
16
use Magento \Framework \Xml \Security ;
15
17
use Magento \Quote \Model \Quote \Address \RateRequest ;
16
18
use Magento \Shipping \Model \Carrier \AbstractCarrierOnline ;
19
21
/**
20
22
* Fedex shipping implementation
21
23
*
22
- * @author Magento Core Team <core@magentocommerce.com>
23
24
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
24
25
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25
26
*/
@@ -145,6 +146,11 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
145
146
*/
146
147
private $ serializer ;
147
148
149
+ /**
150
+ * @var ClientFactory
151
+ */
152
+ private $ soapClientFactory ;
153
+
148
154
/**
149
155
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
150
156
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
@@ -166,7 +172,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
166
172
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
167
173
* @param array $data
168
174
* @param Json|null $serializer
169
- *
175
+ * @param ClientFactory|null $soapClientFactory
170
176
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
171
177
*/
172
178
public function __construct (
@@ -189,7 +195,8 @@ public function __construct(
189
195
\Magento \Framework \Module \Dir \Reader $ configReader ,
190
196
\Magento \Catalog \Model \ResourceModel \Product \CollectionFactory $ productCollectionFactory ,
191
197
array $ data = [],
192
- Json $ serializer = null
198
+ Json $ serializer = null ,
199
+ ClientFactory $ soapClientFactory = null
193
200
) {
194
201
$ this ->_storeManager = $ storeManager ;
195
202
$ this ->_productCollectionFactory = $ productCollectionFactory ;
@@ -216,6 +223,7 @@ public function __construct(
216
223
$ this ->_rateServiceWsdl = $ wsdlBasePath . 'RateService_v10.wsdl ' ;
217
224
$ this ->_trackServiceWsdl = $ wsdlBasePath . 'TrackService_v ' . self ::$ trackServiceVersion . '.wsdl ' ;
218
225
$ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
226
+ $ this ->soapClientFactory = $ soapClientFactory ?: ObjectManager::getInstance ()->get (ClientFactory::class);
219
227
}
220
228
221
229
/**
@@ -227,7 +235,7 @@ public function __construct(
227
235
*/
228
236
protected function _createSoapClient ($ wsdl , $ trace = false )
229
237
{
230
- $ client = new \ SoapClient ($ wsdl , ['trace ' => $ trace ]);
238
+ $ client = $ this -> soapClientFactory -> create ($ wsdl , ['trace ' => $ trace ]);
231
239
$ client ->__setLocation (
232
240
$ this ->getConfigFlag (
233
241
'sandbox_mode '
@@ -1264,7 +1272,7 @@ protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
1264
1272
$ countriesOfManufacture [] = $ product ->getCountryOfManufacture ();
1265
1273
}
1266
1274
1267
- $ paymentType = $ request -> getIsReturn () ? ' RECIPIENT ' : ' SENDER ' ;
1275
+ $ paymentType = $ this -> getPaymentType ( $ request ) ;
1268
1276
$ optionType = $ request ->getShippingMethod () == self ::RATE_REQUEST_SMARTPOST
1269
1277
? 'SERVICE_DEFAULT ' : $ packageParams ->getDeliveryConfirmation ();
1270
1278
$ requestClient = [
@@ -1750,4 +1758,18 @@ private function parseDate($timestamp)
1750
1758
1751
1759
return false ;
1752
1760
}
1761
+
1762
+ /**
1763
+ * Defines payment type by request.
1764
+ * Two values are available: RECIPIENT or SENDER.
1765
+ *
1766
+ * @param DataObject $request
1767
+ * @return string
1768
+ */
1769
+ private function getPaymentType (DataObject $ request ): string
1770
+ {
1771
+ return $ request ->getIsReturn () && $ request ->getShippingMethod () !== self ::RATE_REQUEST_SMARTPOST
1772
+ ? 'RECIPIENT '
1773
+ : 'SENDER ' ;
1774
+ }
1753
1775
}
0 commit comments