1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\BPOINT\Message; |
4
|
|
|
|
5
|
|
|
use Omnipay\Common\Http\ClientInterface; |
6
|
|
|
use Omnipay\Common\Message\AbstractRequest; |
7
|
|
|
use Omnipay\Common\Message\NotificationInterface; |
8
|
|
|
use Omnipay\Common\Message\RequestInterface; |
9
|
|
|
use Omnipay\Common\Message\ResponseInterface; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request as HttpRequest; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Accept an incoming notification (a webhook) |
14
|
|
|
* |
15
|
|
|
* @see https://www.bpoint.com.au/developers/v3/#!#webhooks |
16
|
|
|
*/ |
17
|
|
|
class WebhookNotification extends AbstractRequest implements NotificationInterface, ResponseInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* The data contained in the response. |
21
|
|
|
* |
22
|
|
|
* @var mixed |
23
|
|
|
*/ |
24
|
|
|
protected $data; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
|
|
public function __construct(ClientInterface $httpClient, HttpRequest $httpRequest) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($httpClient, $httpRequest); |
32
|
|
|
// fetch POST stream directly |
33
|
|
|
$this->data = json_decode($httpRequest->getContent(), true); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* ResponseInterface implemented so that we can return self here for any legacy support that uses send() |
38
|
|
|
*/ |
39
|
|
|
public function sendData($data) |
40
|
|
|
{ |
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the authorisation code if available. |
46
|
|
|
* |
47
|
|
|
* @return null|string |
48
|
|
|
*/ |
49
|
|
|
public function getTransactionReference() |
50
|
|
|
{ |
51
|
|
|
return isset($this->data['AuthoriseId']) ? $this->data['AuthoriseId'] : null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Was the transaction successful? |
56
|
|
|
* |
57
|
|
|
* @return string Transaction status, one of {@link NotificationInterface::STATUS_COMPLETED}, |
58
|
|
|
* {@link NotificationInterface::STATUS_PENDING}, or {@link NotificationInterface::STATUS_FAILED}. |
59
|
|
|
*/ |
60
|
|
|
public function getTransactionStatus() |
61
|
|
|
{ |
62
|
|
|
if (!isset($this->data['ResponseCode'])) { |
63
|
|
|
return NotificationInterface::STATUS_FAILED; |
64
|
|
|
} |
65
|
|
|
if ($this->data['ResponseCode'] == '0') { |
66
|
|
|
return NotificationInterface::STATUS_COMPLETED; |
67
|
|
|
} |
68
|
|
|
if ($this->data['ResponseCode'] == 'P') { |
69
|
|
|
return NotificationInterface::STATUS_PENDING; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// last resort, assume failure |
73
|
|
|
return NotificationInterface::STATUS_FAILED; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the merchant response message if available. |
78
|
|
|
* |
79
|
|
|
* @return null|string |
80
|
|
|
*/ |
81
|
|
|
public function getMessage() |
82
|
|
|
{ |
83
|
|
|
return isset($this->data['ResponseText']) ? $this->data['ResponseText'] : null; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getData() |
87
|
|
|
{ |
88
|
|
|
return $this->data; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the original request which generated this response |
93
|
|
|
* |
94
|
|
|
* @return RequestInterface |
95
|
|
|
*/ |
96
|
|
|
public function getRequest() |
97
|
|
|
{ |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Is the response successful? |
103
|
|
|
* |
104
|
|
|
* @return boolean |
105
|
|
|
*/ |
106
|
|
|
public function isSuccessful() |
107
|
|
|
{ |
108
|
|
|
return $this->getTransactionStatus() == NotificationInterface::STATUS_COMPLETED; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Does the response require a redirect? |
113
|
|
|
* |
114
|
|
|
* @return boolean |
115
|
|
|
*/ |
116
|
|
|
public function isRedirect() |
117
|
|
|
{ |
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Is the transaction cancelled by the user? |
123
|
|
|
* |
124
|
|
|
* @return boolean |
125
|
|
|
*/ |
126
|
|
|
public function isCancelled() |
127
|
|
|
{ |
128
|
|
|
return isset($this->data['ResponseCode']) && $this->data['ResponseCode'] == 'C'; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Response code |
133
|
|
|
* |
134
|
|
|
* @return null|string A response code from the payment gateway |
135
|
|
|
*/ |
136
|
|
|
public function getCode() |
137
|
|
|
{ |
138
|
|
|
return isset($this->data['ResponseCode']) ? $this->data['ResponseCode'] : null; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get the card type if available. |
143
|
|
|
* |
144
|
|
|
* @return null|string |
145
|
|
|
*/ |
146
|
|
|
public function getCardType() |
147
|
|
|
{ |
148
|
|
|
return isset($this->data['CardType']) ? $this->data['CardType'] : null; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|