|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PTS\Paysera\Action; |
|
4
|
|
|
|
|
5
|
|
|
use Payum\Core\Action\ActionInterface; |
|
6
|
|
|
use Payum\Core\ApiAwareInterface; |
|
7
|
|
|
use Payum\Core\ApiAwareTrait; |
|
8
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
|
9
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
|
10
|
|
|
use Payum\Core\GatewayAwareInterface; |
|
11
|
|
|
use Payum\Core\GatewayAwareTrait; |
|
12
|
|
|
use Payum\Core\Reply\HttpResponse; |
|
13
|
|
|
use Payum\Core\Request\GetHttpRequest; |
|
14
|
|
|
use Payum\Core\Request\Notify; |
|
15
|
|
|
use PTS\Paysera\Api; |
|
16
|
|
|
use PTS\Paysera\MockedApi; |
|
17
|
|
|
|
|
18
|
|
|
class NotifyAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use ApiAwareTrait; |
|
21
|
|
|
|
|
22
|
|
|
use GatewayAwareTrait; |
|
23
|
|
|
|
|
24
|
25 |
|
public function __construct($mocked = false) |
|
25
|
|
|
{ |
|
26
|
25 |
|
$mocked ? $this->apiClass = MockedApi::class : $this->apiClass = Api::class; |
|
27
|
25 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param mixed $request |
|
31
|
|
|
* @throws \WebToPayException |
|
32
|
|
|
*/ |
|
33
|
7 |
|
public function execute($request) |
|
34
|
|
|
{ |
|
35
|
7 |
|
RequestNotSupportedException::assertSupports($this, $request); |
|
36
|
|
|
|
|
37
|
1 |
|
$model = ArrayObject::ensureArrayObject($request->getModel()); |
|
38
|
|
|
|
|
39
|
1 |
|
$this->gateway->execute($httpRequest = new GetHttpRequest()); |
|
40
|
|
|
|
|
41
|
1 |
|
$response = $this->api->doNotify($httpRequest->method === 'POST' ? $httpRequest->request : $httpRequest->query); |
|
42
|
|
|
|
|
43
|
1 |
|
if (!$response) { |
|
44
|
1 |
|
throw new \WebToPayException('Wrong parameters'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
switch ($response['status']) { |
|
48
|
|
|
case '0': |
|
49
|
|
|
$model['status'] = 'FAILED'; |
|
50
|
|
|
break; |
|
51
|
|
|
case '1': |
|
52
|
|
|
$model['status'] = 'COMPLETED'; |
|
53
|
|
|
break; |
|
54
|
|
|
case '2': |
|
55
|
|
|
$model['status'] = 'NOT_EXECUTED'; |
|
56
|
|
|
break; |
|
57
|
|
|
} |
|
58
|
|
|
throw new HttpResponse('OK'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritDoc} |
|
63
|
|
|
*/ |
|
64
|
15 |
|
public function supports($request) |
|
65
|
|
|
{ |
|
66
|
|
|
return |
|
67
|
15 |
|
$request instanceof Notify && |
|
68
|
15 |
|
$request->getModel() instanceof \ArrayAccess; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|