1 | <?php |
||
2 | |||
3 | namespace Omnipay\WindcaveHpp\Message; |
||
4 | |||
5 | use Omnipay\Common\Exception\InvalidRequestException; |
||
6 | use Omnipay\Common\Http\ClientInterface; |
||
7 | use Omnipay\Common\Message\AbstractRequest; |
||
8 | use Omnipay\Common\Message\NotificationInterface; |
||
9 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
||
10 | |||
11 | class AcceptNotification extends PurchaseRequest implements NotificationInterface { |
||
12 | protected $data; |
||
13 | |||
14 | protected $transaction; |
||
15 | |||
16 | public function getData() { |
||
17 | return $this->data; |
||
18 | } |
||
19 | |||
20 | public function sendData($data) { |
||
21 | $sessionId = $this->httpRequest->query->get('sessionId') ?? $this->httpRequest->request->get('sessionId') ?? ''; |
||
22 | |||
23 | if (empty($sessionId)) { |
||
24 | throw new InvalidRequestException('Session id is required'); |
||
25 | } |
||
26 | |||
27 | $headers = [ |
||
28 | 'Accept' => 'application/json', |
||
29 | 'Content-Type' => 'application/json', |
||
30 | 'Authorization' => 'Basic ' . $this->getAuthorization() |
||
31 | ]; |
||
32 | |||
33 | try { |
||
34 | $httpResponse = $this->httpClient->request('GET', $this->getEndpoint('sessions/' . $sessionId), $headers); |
||
35 | } |
||
36 | catch (\Exception $exception) { |
||
37 | throw new InvalidRequestException($exception->getMessage()); |
||
38 | } |
||
39 | |||
40 | $transactionData = json_decode($httpResponse->getBody()->getContents(), true); |
||
41 | |||
42 | $this->data = $transactionData; |
||
43 | $this->transaction = $transactionData['transactions'][0] ?? []; |
||
44 | |||
45 | return $this; |
||
0 ignored issues
–
show
|
|||
46 | } |
||
47 | |||
48 | public function getTransaction() { |
||
49 | return $this->transaction; |
||
50 | } |
||
51 | |||
52 | public function getTransactionReference() { |
||
53 | return $this->getTransaction()['id'] ?? ''; |
||
54 | } |
||
55 | |||
56 | public function getTransactionStatus() { |
||
57 | if ($this->getTransaction() && $this->getAuthorised() && $this->getResponseText() === 'APPROVED') { |
||
58 | return static::STATUS_COMPLETED; |
||
59 | } |
||
60 | |||
61 | return static::STATUS_FAILED; |
||
62 | } |
||
63 | |||
64 | public function getAuthorised() { |
||
65 | return $this->getTransaction()['authorised'] ?? false; |
||
66 | } |
||
67 | |||
68 | public function getResponseText() { |
||
69 | return strtoupper($this->getTransaction()['responseText']) ?? ''; |
||
70 | } |
||
71 | |||
72 | public function getMessage() { |
||
73 | return $this->getResponseText() ?? ''; |
||
74 | } |
||
75 | } |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: