1
|
|
|
<?php |
2
|
|
|
namespace Omnipay\Gtpay\Message; |
3
|
|
|
|
4
|
|
|
use Omnipay\Common\Message\AbstractResponse; |
5
|
|
|
use Omnipay\Common\Message\RequestInterface; |
6
|
|
|
|
7
|
|
|
class CompletePurchaseResponse extends AbstractResponse |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
const CANCELED_GATEWAY_CODE = 'Z6'; |
11
|
|
|
|
12
|
|
|
const SUCCESS_CODE = '00'; |
13
|
|
|
|
14
|
|
|
private $isSuccessful = null; |
15
|
|
|
|
16
|
|
|
private $validator; |
17
|
|
|
|
18
|
10 |
|
public function __construct(RequestInterface $request, $data) |
19
|
|
|
{ |
20
|
10 |
|
parent::__construct($request, $data); |
21
|
10 |
|
$this->validator = new ResponseDataValidator($this); |
22
|
10 |
|
} |
23
|
|
|
|
24
|
10 |
|
public function isSuccessful() |
25
|
|
|
{ |
26
|
10 |
|
if (is_null($this->isSuccessful)) { |
27
|
10 |
|
$this->validator->validate(); |
28
|
5 |
|
$this->isSuccessful = $this->checkSuccessStatus(); |
29
|
5 |
|
if ($this->isSuccessful()) { |
30
|
4 |
|
$this->validator->successValidate(); |
31
|
|
|
} |
32
|
|
|
} |
33
|
5 |
|
return $this->isSuccessful; |
34
|
|
|
} |
35
|
|
|
|
36
|
5 |
|
private function checkSuccessStatus() |
37
|
|
|
{ |
38
|
5 |
|
return $this->hasSuccessCode($this->getCode()); |
39
|
|
|
} |
40
|
|
|
|
41
|
2 |
|
public function getTransactionReference() |
42
|
|
|
{ |
43
|
2 |
|
return isset($this->data['MerchantReference'])?$this->data['MerchantReference']:null; |
44
|
|
|
} |
45
|
|
|
|
46
|
8 |
|
public function getTransactionId() |
47
|
|
|
{ |
48
|
8 |
|
return isset($this->data['gtpay_tranx_id'])?$this->data['gtpay_tranx_id']:null; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function getMessage() |
52
|
|
|
{ |
53
|
1 |
|
if (!isset($this->data['gtpay_tranx_status_msg'])) { |
54
|
|
|
return null; |
55
|
|
|
} |
56
|
1 |
|
return isset($this->data['ResponseDescription']) |
57
|
1 |
|
?$this->data['ResponseDescription']: $this->data['gtpay_tranx_status_msg']; |
58
|
|
|
} |
59
|
|
|
|
60
|
5 |
|
public function getCode() |
61
|
|
|
{ |
62
|
5 |
|
if (!isset($this->data['gtpay_tranx_status_code'])) { |
63
|
|
|
return null; |
64
|
|
|
} |
65
|
5 |
|
return isset($this->data['ResponseCode'])?$this->data['ResponseCode']:$this->data['gtpay_tranx_status_code']; |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
public function getGatewayAmount() |
69
|
|
|
{ |
70
|
1 |
|
return isset($this->data['gtpay_tranx_amt'])? $this->data['gtpay_tranx_amt']:null; |
71
|
|
|
} |
72
|
|
|
|
73
|
8 |
|
public function getGatewayAmountInteger() |
74
|
|
|
{ |
75
|
8 |
|
return isset($this->data['gtpay_tranx_amt_small_denom'])?$this->data['gtpay_tranx_amt_small_denom']:null; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
public function getApprovedAmount() |
79
|
|
|
{ |
80
|
1 |
|
return isset($this->data['Amount'])?$this->data['Amount']:0; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get currency returned from gateway |
85
|
|
|
* @return null |
86
|
|
|
*/ |
87
|
8 |
|
public function getGatewayNumericCurrency() |
88
|
|
|
{ |
89
|
8 |
|
return isset($this->data['gtpay_tranx_curr'])?$this->data['gtpay_tranx_curr']:null; |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function formatIntegerAmount($integerAmount) |
93
|
|
|
{ |
94
|
1 |
|
return $this->getRequest()->getCurrency() |
95
|
1 |
|
.' '.number_format( |
96
|
1 |
|
$this->convertIntegerAmount($integerAmount), |
97
|
1 |
|
$this->getRequest()->getCurrencyDecimalPlaces() |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
public function convertIntegerAmount($integerAmount) |
102
|
|
|
{ |
103
|
1 |
|
return $integerAmount/$this->getCurrencyDecimalFactor(); |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function getCurrencyDecimalFactor() |
107
|
|
|
{ |
108
|
1 |
|
return pow(10, $this->getRequest()->getCurrencyDecimalPlaces()); |
109
|
|
|
} |
110
|
|
|
|
111
|
10 |
|
public function hasSuccessCode($statusCode) |
112
|
|
|
{ |
113
|
10 |
|
return ResponseDataValidator::compareStrings($statusCode, self::SUCCESS_CODE); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|