Skip to content

Instantly share code, notes, and snippets.

@malkafly
Created April 19, 2021 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkafly/556593ce5e8932d252c8510a3bb6cc6a to your computer and use it in GitHub Desktop.
Save malkafly/556593ce5e8932d252c8510a3bb6cc6a to your computer and use it in GitHub Desktop.
Iugu com Laravel
<?php
namespace App\Helpers;
use Auth;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
class Iugu
{
protected $headers;
public function __construct()
{
$this->headers = [
'Authorization' => 'Basic '.base64_encode(env('IUGU_APIKEY') . ':'),
'Accept' => 'application/json',
'Accept-Charset' => 'utf-8',
'User-Agent' => 'Painel da Loja Library',
'Accept-Language' => 'pt-br;q=0.9,pt-BR'
];
}
public function updateCustomer($id, $data) {
$response = Http::withHeaders($this->headers)->put('https://api.iugu.com/v1/customers/' . $id, $data);
return $response->json();
}
public function createCustomer($data) {
$response = Http::withHeaders($this->headers)->post('https://api.iugu.com/v1/customers/', $data);
return $response->json();
}
public function getCustomer($id) {
$response = Http::withHeaders($this->headers)->get('https://api.iugu.com/v1/customers/' . $id);
return $response->json();
}
public function getInvoices($id) {
$response = Http::withHeaders($this->headers)->get('https://api.iugu.com/v1/invoices?customer_id=' . $id);
return $response->json();
}
public function getSubscription($id) {
$response = Http::withHeaders($this->headers)->get('https://api.iugu.com/v1/subscriptions/' . $id);
return $response->json();
}
public function createSubscription($customer_id, $plan_identifier) {
$response = Http::withHeaders($this->headers)->post('https://api.iugu.com/v1/subscriptions', [
'customer_id' => $customer_id,
'plan_identifier' => $plan_identifier
]);
return $response->json();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment