1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cakasim\Payone\Sdk\Notification; |
6
|
|
|
|
7
|
|
|
use Cakasim\Payone\Sdk\AbstractService; |
8
|
|
|
use Cakasim\Payone\Sdk\Notification\Handler\HandlerInterface; |
9
|
|
|
use Cakasim\Payone\Sdk\Notification\Handler\HandlerManagerInterface; |
10
|
|
|
use Cakasim\Payone\Sdk\Notification\Processor\ProcessorExceptionInterface; |
11
|
|
|
use Cakasim\Payone\Sdk\Notification\Processor\ProcessorInterface; |
12
|
|
|
use Psr\Container\ContainerInterface; |
13
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The notification service. |
17
|
|
|
* |
18
|
|
|
* @author Fabian Böttcher <[email protected]> |
19
|
|
|
* @since 0.1.0 |
20
|
|
|
*/ |
21
|
|
|
class Service extends AbstractService |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var ProcessorInterface The notification processor. |
25
|
|
|
*/ |
26
|
|
|
protected $processor; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var HandlerManagerInterface The notification handler manager. |
30
|
|
|
*/ |
31
|
|
|
protected $handlerManager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructs the notification service. |
35
|
|
|
* |
36
|
|
|
* @param ProcessorInterface $processor The notification processor. |
37
|
|
|
* @param HandlerManagerInterface $handlerManager The notification handler manager. |
38
|
|
|
* @inheritDoc |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
ContainerInterface $container, |
42
|
|
|
ProcessorInterface $processor, |
43
|
|
|
HandlerManagerInterface $handlerManager |
44
|
|
|
) { |
45
|
|
|
parent::__construct($container); |
46
|
|
|
$this->processor = $processor; |
47
|
|
|
$this->handlerManager = $handlerManager; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Processes an inbound HTTP request as PAYONE notification message. |
52
|
|
|
* |
53
|
|
|
* @param ServerRequestInterface $request The inbound HTTP request. |
54
|
|
|
* @throws ProcessorExceptionInterface If processing fails. |
55
|
|
|
*/ |
56
|
|
|
public function processRequest(ServerRequestInterface $request): void |
57
|
|
|
{ |
58
|
|
|
$this->processor->processRequest($request); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Registers a notification message handler. |
63
|
|
|
* |
64
|
|
|
* @param HandlerInterface $handler The handler to register. |
65
|
|
|
*/ |
66
|
|
|
public function registerHandler(HandlerInterface $handler): void |
67
|
|
|
{ |
68
|
|
|
$this->handlerManager->registerHandler($handler); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|