-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebitoorapi.class.php
More file actions
55 lines (48 loc) · 1.67 KB
/
Copy pathdebitoorapi.class.php
File metadata and controls
55 lines (48 loc) · 1.67 KB
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
<?php
// Debitoor API Helper
// Code by Daniel Roizer - http://thatblogger.co
// v2.0
class DebitoorApiHelper {
public static function createApiCall($url, $method, $headers, $data = array()){
// Append URL
$url = apiURL . $url . "?access_token=" . token;
if($method == 'PUT'){
$headers[] = 'X-HTTP-Method-Override: PUT';
}
if($method == 'GET' && $data != NULL){
$url_append = $url . "&";
foreach($data as $key => $val){
$url_append .= $key . "=" . $val . "&";
}
$url = substr($url_append, 0, -1);
}
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
switch($method){
case 'GET':
break;
case 'POST':
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
break;
case 'PUT':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
break;
case 'DELETE':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
break;
}
$response = curl_exec($handle);
$uncoded = json_decode($response, true);
if($uncoded['code'] == "unAuthorized" || $uncoded['code'] == "system"){
return false;
}else{
return $uncoded;
}
}
}