1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP version 5.4 and 7 |
4
|
|
|
* |
5
|
|
|
* @package Payever\ThirdParty |
6
|
|
|
* @author Hennadii.Shymanskyi <[email protected]> |
7
|
|
|
* @copyright 2017-2019 payever GmbH |
8
|
|
|
* @license MIT <https://opensource.org/licenses/MIT> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Payever\ExternalIntegration\ThirdParty\Action; |
12
|
|
|
|
13
|
|
|
use Payever\ExternalIntegration\Inventory\Http\RequestEntity\InventoryChangedRequestEntity; |
14
|
|
|
use Payever\ExternalIntegration\Products\Http\RequestEntity\ProductRemovedRequestEntity; |
15
|
|
|
use Payever\ExternalIntegration\Products\Http\RequestEntity\ProductRequestEntity; |
16
|
|
|
|
17
|
|
|
class BidirectionalActionProcessor |
18
|
|
|
{ |
19
|
|
|
/** @var InwardActionProcessor */ |
20
|
|
|
private $inwardActionProcessor; |
21
|
|
|
|
22
|
|
|
/** @var OutwardActionProcessor */ |
23
|
|
|
private $outwardActionProcessor; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
InwardActionProcessor $inwardActionProcessor, |
27
|
|
|
OutwardActionProcessor $outwardActionProcessor |
28
|
|
|
) { |
29
|
|
|
$this->inwardActionProcessor = $inwardActionProcessor; |
30
|
|
|
$this->outwardActionProcessor = $outwardActionProcessor; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Do the job of processing payever third-party action request |
35
|
|
|
* |
36
|
|
|
* @param string $action - action name {@see ActionEnum} |
37
|
|
|
* @param array|string|null $payload - user can pass payload directly if it's coming from custom source |
38
|
|
|
* |
39
|
|
|
* @throws \Exception - bubbles up anything thrown inside |
40
|
|
|
*/ |
41
|
|
|
public function processInwardAction($action, $payload = null) |
42
|
|
|
{ |
43
|
|
|
$this->inwardActionProcessor->process($action, $payload); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $action - {@see ActionEnum} |
48
|
|
|
* @param InventoryChangedRequestEntity|ProductRequestEntity|ProductRemovedRequestEntity|array|string $payload |
49
|
|
|
* |
50
|
|
|
* @throws \RuntimeException - when given action is unknown |
51
|
|
|
* @throws \Exception - bubbles up anything thrown by API |
52
|
|
|
*/ |
53
|
|
|
public function processOutwardAction($action, $payload) |
54
|
|
|
{ |
55
|
|
|
$this->outwardActionProcessor->process($action, $payload); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|