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
|
|
|
{ |
18
|
|
|
return $this->data; |
19
|
|
|
} |
20
|
|
|
public function sendData($data) |
21
|
|
|
{ |
22
|
|
|
$sessionId = $this->httpRequest->query->get('sessionId') ?? $this->httpRequest->request->get('sessionId') ?? ''; |
23
|
|
|
|
24
|
|
|
if ( empty($sessionId) ) { |
25
|
|
|
throw new InvalidRequestException('Session id is required'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$headers = [ |
29
|
|
|
'Accept' => 'application/json', |
30
|
|
|
'Content-Type' => 'application/json', |
31
|
|
|
'Authorization' => 'Basic ' . $this->getAuthorization() |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
try { |
35
|
|
|
$httpResponse = $this->httpClient->request('GET', $this->getEndpoint('sessions/' . $sessionId), $headers); |
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; |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getTransaction() |
49
|
|
|
{ |
50
|
|
|
return $this->transaction; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getTransactionReference() |
54
|
|
|
{ |
55
|
|
|
return $this->getTransaction()['id'] ?? ''; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getTransactionStatus() |
59
|
|
|
{ |
60
|
|
|
if ( $this->getTransaction() && $this->getAuthorised() && $this->getResponseText() === 'APPROVED' ) { |
61
|
|
|
return static::STATUS_COMPLETED; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return static::STATUS_FAILED; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getAuthorised() |
68
|
|
|
{ |
69
|
|
|
return $this->getTransaction()['authorised'] ?? false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getResponseText() |
73
|
|
|
{ |
74
|
|
|
return strtoupper($this->getTransaction()['responseText']) ?? ''; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getMessage() |
78
|
|
|
{ |
79
|
|
|
return $this->getResponseText() ?? ''; |
80
|
|
|
} |
81
|
|
|
} |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: