1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodePhix\Asaas; |
4
|
|
|
|
5
|
|
|
class Connection { |
6
|
|
|
|
7
|
|
|
public $http; |
8
|
|
|
public $api_key; |
9
|
|
|
public $api_key_live; |
10
|
|
|
public $api_status; |
11
|
|
|
public $base_url; |
12
|
|
|
public $headers; |
13
|
|
|
|
14
|
|
|
public function __construct() { |
15
|
|
|
$this->api_key = PAYMENT['asaas']['chave']; |
|
|
|
|
16
|
|
|
$this->api_key_live = PAYMENT['asaas']['chavelivre']; |
17
|
|
|
$this->api_status = PAYMENT['asaas']['status']; |
18
|
|
|
$this->base_url = "https://" . ((PAYMENT['asaas']['status']) ? 'sandbox' : 'www'); |
19
|
|
|
return $this; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
public function get($url, $option = false, $custom = false ) |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
$ch = curl_init(); |
27
|
|
|
curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url."?".$option); |
|
|
|
|
28
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
29
|
|
|
curl_setopt($ch, CURLOPT_HEADER, FALSE); |
30
|
|
|
|
31
|
|
|
if(!empty($custom)){ |
32
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $custom); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
36
|
|
|
"Content-Type: application/json", |
37
|
|
|
"access_token: ".(($this->api_status == 1) ? $this->api_key_live : $this->api_key) |
38
|
|
|
)); |
39
|
|
|
|
40
|
|
|
$response = curl_exec($ch); |
|
|
|
|
41
|
|
|
curl_close($ch); |
|
|
|
|
42
|
|
|
$response = json_decode($response); |
43
|
|
|
|
44
|
|
|
//$response = $this->http->request('GET', $this->base_url . $url); |
45
|
|
|
|
46
|
|
|
return $response; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function post($url, $params) |
50
|
|
|
{ |
51
|
|
|
$params = json_encode($params); |
52
|
|
|
$ch = curl_init(); |
53
|
|
|
|
54
|
|
|
curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url); |
|
|
|
|
55
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
56
|
|
|
curl_setopt($ch, CURLOPT_HEADER, FALSE); |
57
|
|
|
|
58
|
|
|
curl_setopt($ch, CURLOPT_POST, TRUE); |
59
|
|
|
|
60
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); |
61
|
|
|
|
62
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
63
|
|
|
"Content-Type: application/json", |
64
|
|
|
"access_token: ".(($this->api_status == 1) ? $this->api_key_live : $this->api_key) |
65
|
|
|
)); |
66
|
|
|
|
67
|
|
|
$response = curl_exec($ch); |
|
|
|
|
68
|
|
|
curl_close($ch); |
|
|
|
|
69
|
|
|
$response = json_decode($response); |
70
|
|
|
|
71
|
|
|
return $response; |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |