1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace BitBag\SyliusDhl24PlShippingExportPlugin\Api; |
||
6 | |||
7 | use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
||
8 | |||
9 | class ShippingLabelFetcher implements ShippingLabelFetcherInterface |
||
10 | { |
||
11 | /** @var WebClientInterface */ |
||
12 | private $webClient; |
||
13 | |||
14 | /** @var SoapClientInterface */ |
||
15 | private $soapClient; |
||
16 | |||
17 | /** @var string */ |
||
18 | private $response; |
||
19 | |||
20 | private FlashBagInterface $flashBag; |
||
21 | |||
22 | public function __construct(FlashBagInterface $flashBag, WebClientInterface $webClient, SoapClientInterface $soapClient) |
||
23 | { |
||
24 | $this->flashBag = $flashBag; |
||
25 | $this->webClient = $webClient; |
||
26 | $this->soapClient = $soapClient; |
||
27 | } |
||
28 | |||
29 | public function createShipment($shippingGateway, $shipment): void |
||
30 | { |
||
31 | try { |
||
32 | $this->webClient->setShippingGateway($shippingGateway); |
||
33 | $this->webClient->setShipment($shipment); |
||
34 | $requestData = $this->webClient->getRequestData(); |
||
35 | |||
36 | $this->response = $this->soapClient->createShipment($requestData, $shippingGateway->getConfigValue('wsdl')); |
||
37 | } catch (\SoapFault $exception) { |
||
38 | $this->flashBag->add( |
||
39 | 'error', |
||
40 | sprintf( |
||
41 | 'DHL24 Web Service for #%s order: %s', |
||
42 | $shipment->getOrder()->getNumber(), |
||
43 | $exception->getMessage() |
||
44 | ) |
||
45 | ); |
||
46 | |||
47 | return; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | public function getLabelContent(): ?string |
||
52 | { |
||
53 | if (!isset($this->response->createShipmentResult)) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
54 | return ''; |
||
55 | } |
||
56 | |||
57 | $this->flashBag->add('success', 'bitbag.ui.shipment_data_has_been_exported'); // Add success notification |
||
58 | |||
59 | return base64_decode($this->response->createShipmentResult->label->labelContent); |
||
60 | } |
||
61 | } |
||
62 |