|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omnipay\EpsomAdelante\Message; |
|
4
|
|
|
|
|
5
|
|
|
use Omnipay\Common\Message\AbstractResponse; |
|
6
|
|
|
use Omnipay\Common\Message\RequestInterface; |
|
7
|
|
|
use Omnipay\Common\Exception\InvalidResponseException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Epsom connector to Adelante Complete Purchase Response |
|
11
|
|
|
* |
|
12
|
|
|
* @todo Add more invalid response checks to the constructor for other fields dependent on 'errorstatus' |
|
13
|
|
|
*/ |
|
14
|
|
|
class CompletePurchaseResponse extends AbstractResponse |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritDoc} |
|
18
|
|
|
* |
|
19
|
|
|
* @throws InvalidResponseException If error status is missing |
|
20
|
|
|
*/ |
|
21
|
9 |
|
public function __construct(RequestInterface $request, $data) |
|
22
|
|
|
{ |
|
23
|
9 |
|
parent::__construct($request, $data); |
|
24
|
|
|
|
|
25
|
9 |
|
if (!isset($data['errorstatus']) || '' === $data['errorstatus']) { |
|
26
|
1 |
|
throw new InvalidResponseException('Invalid response from payment gateway'); |
|
27
|
|
|
} |
|
28
|
8 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Is the response an error? |
|
32
|
|
|
* |
|
33
|
|
|
* @return boolean |
|
34
|
|
|
*/ |
|
35
|
8 |
|
protected function isError() |
|
36
|
|
|
{ |
|
37
|
8 |
|
return empty($this->data['errorstatus']); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Is the response successful? |
|
42
|
|
|
* |
|
43
|
|
|
* @return boolean |
|
44
|
|
|
*/ |
|
45
|
8 |
|
public function isSuccessful() |
|
46
|
|
|
{ |
|
47
|
8 |
|
return !$this->isError() && !empty($this->data['authstatus']); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the authorisation code if available. |
|
52
|
|
|
* |
|
53
|
|
|
* @return null|string |
|
54
|
|
|
*/ |
|
55
|
3 |
|
public function getTransactionReference() |
|
56
|
|
|
{ |
|
57
|
3 |
|
return isset($this->data['authcode']) ? $this->data['authcode'] : null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritDoc} |
|
62
|
|
|
*/ |
|
63
|
4 |
|
public function getTransactionId() |
|
64
|
|
|
{ |
|
65
|
4 |
|
return isset($this->data['iasorderno']) ? $this->data['iasorderno'] : null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the merchant response message if available. |
|
70
|
|
|
* |
|
71
|
|
|
* @return null|string |
|
72
|
|
|
*/ |
|
73
|
8 |
|
public function getMessage() |
|
74
|
|
|
{ |
|
75
|
8 |
|
if ($this->isError()) { |
|
76
|
4 |
|
if (!empty($this->data['errordescription'])) { |
|
77
|
2 |
|
return $this->data['errordescription']; |
|
78
|
|
|
} |
|
79
|
2 |
|
if (!empty($this->data['errorcode'])) { |
|
80
|
1 |
|
return $this->data['errorcode']; |
|
81
|
|
|
} |
|
82
|
1 |
|
} |
|
83
|
|
|
|
|
84
|
5 |
|
return null; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the card type used if available. |
|
89
|
|
|
* |
|
90
|
|
|
* @return null|string |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function getCardType() |
|
93
|
|
|
{ |
|
94
|
1 |
|
return isset($this->data['cardtype']) ? $this->data['cardtype'] : null; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get the amount paid in the transaction if available. |
|
99
|
|
|
* |
|
100
|
|
|
* The amount paid if given is the integer value in pence e.g. '1000' for £10.00 |
|
101
|
|
|
* |
|
102
|
|
|
* @return null|string The floating point value |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function getAmountPaid() |
|
105
|
|
|
{ |
|
106
|
1 |
|
return isset($this->data['amountpaid']) ? number_format($this->data['amountpaid'] / 100, 2) : null; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|