1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of PHP CS Fixer. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* Dariusz Rumiński <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This source file is subject to the MIT license that is bundled |
10
|
|
|
* with this source code in the file LICENSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Etrias\PaazlConnector\Services; |
14
|
|
|
|
15
|
|
|
use DateTime; |
16
|
|
|
use Etrias\PaazlConnector\Client\PaazlClientInterface; |
17
|
|
|
use Etrias\PaazlConnector\SoapTypes\BatchStatusRequest; |
18
|
|
|
use Etrias\PaazlConnector\SoapTypes\CloseBatchRequest; |
19
|
|
|
use Etrias\PaazlConnector\SoapTypes\ListOpenBatchesRequest; |
20
|
|
|
use Etrias\PaazlConnector\SoapTypes\OpenBatchRequest; |
21
|
|
|
|
22
|
|
|
class BatchService implements BatchServiceInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var PaazlClientInterface |
26
|
|
|
*/ |
27
|
|
|
protected $client; |
28
|
|
|
/** |
29
|
|
|
* @var SecurityServiceInterface |
30
|
|
|
*/ |
31
|
|
|
protected $security; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* DocumentService constructor. |
35
|
|
|
* |
36
|
|
|
* @param PaazlClientInterface $client |
37
|
|
|
* @param SecurityServiceInterface $security |
38
|
|
|
*/ |
39
|
|
|
public function __construct(PaazlClientInterface $client, SecurityServiceInterface $security) |
40
|
|
|
{ |
41
|
|
|
$this->security = $security; |
42
|
|
|
$this->client = $client; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function openBatch( |
49
|
|
|
$distributor = null, |
50
|
|
|
$shippingOption = null, |
51
|
|
|
$country = null, |
52
|
|
|
$targetWebShop = null |
53
|
|
|
) { |
54
|
|
|
$today = new DateTime(); |
55
|
|
|
$hashInput = implode('', [ |
56
|
|
|
$distributor, |
57
|
|
|
$shippingOption, |
58
|
|
|
$country, |
59
|
|
|
$today->format('Ymd'), |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
$request = new OpenBatchRequest( |
63
|
|
|
$this->security->getHash($hashInput), |
64
|
|
|
$this->client->getWebShopId(), |
65
|
|
|
$targetWebShop, |
66
|
|
|
$distributor, |
67
|
|
|
$shippingOption, |
68
|
|
|
$country |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
return $this->client->openBatch($request); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function closeBatch($batchId, $targetWebShop = null) |
78
|
|
|
{ |
79
|
|
|
$request = new CloseBatchRequest( |
80
|
|
|
$this->security->getHash($batchId), |
81
|
|
|
$this->client->getWebShopId(), |
82
|
|
|
$targetWebShop, |
83
|
|
|
$batchId |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
return $this->client->closeBatch($request); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function getBatchStatus($batchId, $targetWebShop = null) |
93
|
|
|
{ |
94
|
|
|
$request = new BatchStatusRequest( |
95
|
|
|
$this->security->getHash($batchId), |
96
|
|
|
$this->client->getWebShopId(), |
97
|
|
|
$targetWebShop, |
98
|
|
|
$batchId |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
return $this->client->batchStatus($request); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
|
public function listOpenBatches($targetWebShop = null) |
108
|
|
|
{ |
109
|
|
|
$today = new DateTime(); |
110
|
|
|
$request = new ListOpenBatchesRequest( |
111
|
|
|
$this->security->getHash($today->format('Ymd')), |
112
|
|
|
$this->client->getWebShopId(), |
113
|
|
|
$targetWebShop |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
return $this->client->listOpenBatches($request); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|