|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omnipay\Paysera\Message; |
|
4
|
|
|
|
|
5
|
|
|
use Omnipay\Common\Message\AbstractResponse; |
|
6
|
|
|
use Omnipay\Common\Message\RequestInterface; |
|
7
|
|
|
use Omnipay\Common\Message\NotificationInterface; |
|
8
|
|
|
use Omnipay\Common\Exception\InvalidResponseException; |
|
9
|
|
|
|
|
10
|
|
|
class AcceptNotificationResponse extends AbstractResponse implements NotificationInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Create an instance of Accept Notification response. |
|
14
|
|
|
* |
|
15
|
|
|
* @param \Omnipay\Common\Message\RequestInterface $request |
|
16
|
|
|
* @param array $data |
|
17
|
|
|
* @return void |
|
|
|
|
|
|
18
|
|
|
* |
|
19
|
|
|
* @throws \Omnipay\Common\Exception\InvalidResponseException |
|
20
|
|
|
*/ |
|
21
|
4 |
|
public function __construct(RequestInterface $request, $data) |
|
22
|
|
|
{ |
|
23
|
4 |
|
parent::__construct($request, $data); |
|
24
|
|
|
|
|
25
|
4 |
|
if ($this->hasUnsupportedType()) { |
|
26
|
1 |
|
throw new InvalidResponseException('Only macro/EMA payment callbacks are accepted'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
3 |
|
if ($this->isSuccessful()) { |
|
30
|
1 |
|
echo 'OK'; |
|
31
|
|
|
} |
|
32
|
3 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Determine the response has unsupported type. |
|
36
|
|
|
* |
|
37
|
|
|
* @return bool |
|
38
|
|
|
*/ |
|
39
|
4 |
|
protected function hasUnsupportedType() |
|
40
|
|
|
{ |
|
41
|
4 |
|
return ! in_array($this->getDataValueOrNull('type'), ['macro', 'EMA']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function getTransactionReference() |
|
48
|
|
|
{ |
|
49
|
1 |
|
return $this->getDataValueOrNull('orderid'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
3 |
|
public function getTransactionStatus() |
|
56
|
|
|
{ |
|
57
|
3 |
|
switch ($this->getCode()) { |
|
58
|
3 |
|
case '0': |
|
59
|
1 |
|
return NotificationInterface::STATUS_FAILED; |
|
60
|
2 |
|
case '1': |
|
61
|
1 |
|
return NotificationInterface::STATUS_COMPLETED; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
return NotificationInterface::STATUS_PENDING; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function getMessage() |
|
71
|
|
|
{ |
|
72
|
1 |
|
return $this->getDataValueOrNull('paytext'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Determine test mode is on. |
|
77
|
|
|
* |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function isTestMode() |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->getDataValueOrNull('test') !== '0'; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
3 |
|
public function isSuccessful() |
|
89
|
|
|
{ |
|
90
|
3 |
|
return $this->getCode() === '1'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* {@inheritdoc} |
|
95
|
|
|
*/ |
|
96
|
3 |
|
public function getCode() |
|
97
|
|
|
{ |
|
98
|
3 |
|
return $this->getDataValueOrNull('status'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Return the value from data or null. |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $name |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
4 |
|
protected function getDataValueOrNull($name) |
|
108
|
|
|
{ |
|
109
|
4 |
|
return isset($this->data[$name]) ? $this->data[$name] : null; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.