1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UAPAY; |
4
|
|
|
|
5
|
|
|
use UAPAY\Log as Log; |
6
|
|
|
use UAPAY\Exception; |
7
|
|
|
|
8
|
|
|
class Callback extends Response |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $id; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $orderId; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
protected $number; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
protected $amount; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $createdAt; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor |
37
|
|
|
* |
38
|
|
|
* @param array $jwt_options array of options |
39
|
|
|
*/ |
40
|
|
|
public function __construct($jwt_options=null) |
41
|
|
|
{ |
42
|
|
|
parent::__construct($this->get_http_raw_post_data(), $jwt_options); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get data from the body of the http request |
47
|
|
|
* |
48
|
|
|
* - with the appropriate configuration of php.ini they can be found |
49
|
|
|
* in the global variable $HTTP_RAW_POST_DATA |
50
|
|
|
* |
51
|
|
|
* - but it's easier just to read the data from the php://input stream, |
52
|
|
|
* which does not depend on the php.ini directives and allows you to read |
53
|
|
|
* raw data from the request body |
54
|
|
|
* |
55
|
|
|
* @return string Http raw post data |
56
|
|
|
* |
57
|
|
|
*/ |
58
|
|
|
protected function get_http_raw_post_data() |
59
|
|
|
{ |
60
|
|
|
Log::instance()->add('callback request from ' . $_SERVER['REMOTE_ADDR']); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$raw_request = file_get_contents('php://input'); |
63
|
|
|
|
64
|
|
|
Log::instance()->debug('got: '); |
|
|
|
|
65
|
|
|
Log::instance()->debug($raw_request); |
66
|
|
|
Log::instance()->debug(' '); |
67
|
|
|
|
68
|
|
|
return $raw_request; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Handle decoded JSON |
73
|
|
|
* |
74
|
|
|
* @throws Exception\JSON |
75
|
|
|
*/ |
76
|
|
|
protected function json_handle() |
77
|
|
|
{ |
78
|
|
|
if (isset($this->json['error'])) |
79
|
|
|
{ |
80
|
|
|
throw new Exception\JSON('json callback contain an error message!'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ($this->jwt['using'] === true) |
84
|
|
|
{ |
85
|
|
|
if ( ! isset($this->json['token'])) |
86
|
|
|
{ |
87
|
|
|
throw new Exception\JSON('json does not contain the token field!'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->json = $this->token_decode($this->json['token']); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->status = $this->json_value('status'); |
94
|
|
|
$this->id = $this->json_value('id'); |
95
|
|
|
$this->orderId = $this->json_value('orderId'); |
96
|
|
|
$this->number = $this->json_value('number'); |
97
|
|
|
$this->amount = $this->json_value('amount'); |
98
|
|
|
$this->createdAt = $this->json_value('createdAt'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get value from JSON |
103
|
|
|
* |
104
|
|
|
* @param string $name |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
protected function json_value($name) |
108
|
|
|
{ |
109
|
|
|
if (!isset($this->json[$name])) |
110
|
|
|
{ |
111
|
|
|
throw new Exception\JSON('invalid json callback!'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this->json[$name]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get id |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function id() |
123
|
|
|
{ |
124
|
|
|
return $this->id; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get order id |
129
|
|
|
* |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function orderId() |
133
|
|
|
{ |
134
|
|
|
return $this->orderId; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get number of paymnet |
139
|
|
|
* |
140
|
|
|
* @return int |
141
|
|
|
*/ |
142
|
|
|
public function number() |
143
|
|
|
{ |
144
|
|
|
return $this->number; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get amount |
149
|
|
|
* |
150
|
|
|
* @return int |
151
|
|
|
*/ |
152
|
|
|
public function amount() |
153
|
|
|
{ |
154
|
|
|
return $this->amount; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Get createdAt |
159
|
|
|
* |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function createdAt() |
163
|
|
|
{ |
164
|
|
|
return $this->createdAt; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Get jsons array |
169
|
|
|
* |
170
|
|
|
* @return array |
171
|
|
|
*/ |
172
|
|
|
public function json() |
173
|
|
|
{ |
174
|
|
|
return $this->json; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|