-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyberssl_api.class.php
338 lines (299 loc) · 7.63 KB
/
cyberssl_api.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?php
/**
* CyberSSL API
*
* @version 1.15
**/
/*Hack for old php versions to use boolval() */
if(!function_exists('boolval')) {
function boolval($val) {
return (bool) $val;
}
}
class CyberSSL_api
{
protected $api_url;
protected $token;
public $response_success;
public $response;
public $error_code;
public $error_message;
/**
* CyberSSL_api constructor.
*
* @param $api_type
*/
public function __construct($api_type)
{
if ($api_type == "production") {
$this->api_url = 'https://api.cyberssl.com/v1/';
}
if ($api_type == "sandbox") {
$this->api_url = 'https://api.cyberssl.com/sandbox/v1/';
}
}
/**
* @param $api_key
*
* @return boolean
*/
public function auth($api_key)
{
$this->call( 'auth', "GET", array(
'apikey' => $api_key
) );
if ($this->response["success"]) {
$this->token = $this->response["token"];
}
return $this->response["success"];
}
/**
* @return mixed
*/
public function list_products()
{
$this->call( 'list_products', "GET", array(
'token' => $this->token
) );
if ($this->response_success) {
return $this->response["ssl_products"];
}
return false;
}
/**
* @param $product_id
*
* @return array|boolean
*/
public function get_ssl_product_details($product_id)
{
$this->call( 'get_ssl_product_details', "GET", array(
'product_id' => $product_id,
'token' => $this->token
) );
if ($this->response_success) {
return $this->response["product"];
}
return false;
}
/**
* @return array,bool
*/
public function my_ssl_orders()
{
$this->call( 'my_orders', "GET", array(
'token' => $this->token
) );
if ($this->response_success) {
return $this->response["ssl_orders"];
}
return false;
}
/**
* @param $array
*
* @return boolean
*/
public function add_ssl_order($array)
{
return $this->call( 'add_ssl_order', "POST", array_merge( array(
'token' => $this->token
), $array ) );
}
/**
* @param $array
*
* @return boolean
*/
public function validate_csr($array)
{
return $this->call( 'validate_csr', "POST", array_merge( array(
'token' => $this->token
), $array ) );
}
/**
* @param $array
*
* @return array|boolean
*/
public function get_dv_options_csr($array)
{
$this->call( 'get_dv_options_csr', "POST", array_merge( array(
'token' => $this->token
), $array ) );
if ($this->response_success) {
return $this->response["dv_options"];
}
return false;
}
/**
* @param $array
*
* @return boolean
*/
public function reissue_ssl_order($array)
{
return $this->call( 'reissue_ssl_order', "POST", array_merge( array(
'token' => $this->token
), $array ) );
}
/**
* @param $array
*
* @return boolean
*/
public function activate_ssl_order($array)
{
return $this->call( 'activate_ssl_order', "POST", array_merge( array(
'token' => $this->token
), $array ) );
}
/**
* @return array|boolean
*/
public function get_ssl_web_soft()
{
$this->call( 'get_ssl_web_soft', "GET", array(
'token' => $this->token,
) );
if ($this->response_success) {
return $this->response["webservers"];
}
return false;
}
/**
* @param $array
*
* @return array|bool
*/
public function get_dv_options($array)
{
$this->call( 'get_dv_options', "GET", array_merge( array(
'token' => $this->token
), $array ) );
if ($this->response_success) {
return $this->response["dv_options"];
}
return false;
}
/**
* @param $array
*
* @return boolean
*/
public function change_dv_method($array)
{
return $this->call( 'change_dv_method', "POST", array_merge( array(
'token' => $this->token
), $array ) );
}
/**
* @param $order_id
*
* @return array|bool
*/
public function order_status($order_id)
{
$this->call( 'order_status', "GET", array(
'token' => $this->token,
'order_id' => $order_id,
) );
if ($this->response_success) {
return $this->response["order"];
}
return false;
}
/**
* @param $array
*
* @return float|bool
*/
public function get_ssl_product_price($array)
{
$this->call( 'get_ssl_product_price', "GET", array_merge( array(
'token' => $this->token
), $array ) );
if ($this->response_success) {
return floatval($this->response["amount"]);
}
return false;
}
/**
* @param $array
*
* @return boolean
*/
public function order_extra_domains($array)
{
return $this->call( 'order_extra_domains', "POST", array_merge( array(
'token' => $this->token
), $array ) );
}
/**
* @return bool|float
*/
public function get_balance()
{
$this->call( 'get_balance', "GET", array(
'token' => $this->token
) );
if ($this->response_success) {
return floatval($this->response["balance"]);
}
return false;
}
/**
* @param $order_id
*
* @return boolean
*/
public function resend_dv_email($order_id)
{
return $this->call( 'resend_dv_email', "GET", array(
'token' => $this->token,
'order_id' => $order_id
) );
}
/**
* @param $uri
* @param $data_type
* @param array $data
*
* @return boolean
*/
protected function call($uri, $data_type, $data = array())
{
$url = $this->api_url . $uri;
if (!empty ($data) && $data_type == "GET") {
foreach ($data as $key => $value) {
$url .= (strpos( $url, '?' ) !== false ? '&' : '?') . urlencode( $key ) . '=' . rawurlencode( $value );
}
}
$post = !empty ($data) && ($data_type == 'POST') ? true : false;
$c = curl_init( $url );
if ($post) {
curl_setopt( $c, CURLOPT_POST, true );
}
if (!empty ($data) && ($data_type == 'POST')) {
$queryData = http_build_query( $data );
curl_setopt( $c, CURLOPT_POSTFIELDS, $queryData );
}
curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $c, CURLOPT_TIMEOUT, 60 );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, true );
$result = curl_exec( $c );
//$status = curl_getinfo( $c, CURLINFO_HTTP_CODE );
curl_close( $c );
$result_decode = json_decode( $result, true );
$this->response_success = boolval($result_decode["success"]);
if (@$result_decode["error_code"]) {
$this->error_code = $result_decode["error_code"];
}
if (@$result_decode["error_message"]) {
$this->error_message = $result_decode["error_message"];
}
$this->response = $result_decode;
return boolval($this->response["success"]);
}
}