codephix /
asaas-sdk
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace CodePhix\Asaas; |
||||
| 4 | |||||
| 5 | class Connection { |
||||
| 6 | public $http; |
||||
| 7 | public $api_key; |
||||
| 8 | public $api_status; |
||||
| 9 | public $base_url; |
||||
| 10 | public $headers; |
||||
| 11 | |||||
| 12 | public function __construct($token, $status) { |
||||
| 13 | |||||
| 14 | if($status == 'producao'){ |
||||
| 15 | $this->api_status = false; |
||||
| 16 | }elseif($status == 'homologacao'){ |
||||
| 17 | $this->api_status = 1; |
||||
| 18 | }else{ |
||||
| 19 | die('Tipo de homologação invalida'); |
||||
|
0 ignored issues
–
show
|
|||||
| 20 | } |
||||
| 21 | $this->api_key = $token; |
||||
| 22 | //$this->api_status = PAYMENT['asaas']['status']; |
||||
| 23 | $this->base_url = "https://" . (($this->api_status) ? 'sandbox' : 'www'); |
||||
| 24 | |||||
| 25 | return $this; |
||||
| 26 | } |
||||
| 27 | |||||
| 28 | |||||
| 29 | public function get($url, $option = false, $custom = false ) |
||||
| 30 | { |
||||
| 31 | |||||
| 32 | $ch = curl_init(); |
||||
| 33 | curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url.$option); |
||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 34 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
||||
| 35 | curl_setopt($ch, CURLOPT_HEADER, FALSE); |
||||
| 36 | |||||
| 37 | if(!empty($custom)){ |
||||
| 38 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $custom); |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
||||
| 42 | "Content-Type: application/json", |
||||
| 43 | "access_token: ".$this->api_key |
||||
| 44 | )); |
||||
| 45 | |||||
| 46 | $response = curl_exec($ch); |
||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 47 | curl_close($ch); |
||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 48 | $response = json_decode($response); |
||||
| 49 | |||||
| 50 | //$response = $this->http->request('GET', $this->base_url . $url); |
||||
| 51 | |||||
| 52 | return $response; |
||||
| 53 | } |
||||
| 54 | |||||
| 55 | public function post($url, $params) |
||||
| 56 | { |
||||
| 57 | $params = json_encode($params); |
||||
| 58 | $ch = curl_init(); |
||||
| 59 | |||||
| 60 | curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url); |
||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 61 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
||||
| 62 | curl_setopt($ch, CURLOPT_HEADER, FALSE); |
||||
| 63 | |||||
| 64 | curl_setopt($ch, CURLOPT_POST, TRUE); |
||||
| 65 | |||||
| 66 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params); |
||||
| 67 | |||||
| 68 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
||||
| 69 | "Content-Type: application/json", |
||||
| 70 | "access_token: ".$this->api_key |
||||
| 71 | )); |
||||
| 72 | |||||
| 73 | $response = curl_exec($ch); |
||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 74 | curl_close($ch); |
||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 75 | $response = json_decode($response); |
||||
| 76 | |||||
| 77 | return $response; |
||||
| 78 | |||||
| 79 | } |
||||
| 80 | |||||
| 81 | } |
||||
| 82 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.