Skip to content

Instantly share code, notes, and snippets.

@vitorvargasdev
Created May 17, 2020 14:55
Show Gist options
  • Save vitorvargasdev/9f101bcffa5a14793cf4de52578237c5 to your computer and use it in GitHub Desktop.
Save vitorvargasdev/9f101bcffa5a14793cf4de52578237c5 to your computer and use it in GitHub Desktop.
<?php
namespace App\Domains\Asaas;
use GuzzleHttp\Client;
class Connection
{
private $base_url;
private $api;
private $api_key;
private $mode;
public function __construct()
{
$this->api_key = env('ASAAS_API_KEY');
$this->mode = env('ASAAS_MODE');
$this->api = new Client([
'headers' => [
'Content-Type' => 'application/json',
'access_token' => $this->api_key
]
]);
if ($this->mode === 'sandbox') {
$this->base_url = 'https://sandbox.asaas.com/api/v3/';
}
if ($this->mode === 'production') {
$this->base_url = 'https://www.asaas.com/api/v3/';
}
}
public function get($url)
{
$response = $this->api->get($this->base_url . $url);
return $response->getBody()->getContents();
}
public function post($url, $params)
{
$response = $this->api->post($this->base_url . $url, $params);
return [
'code' => $response->getStatusCode(),
'response' => $response->getBody()->getContents()
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment