Skip to content

Commit

Permalink
feat: integrated with Customer List on ASAAS PHP Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
icarojobs committed Feb 20, 2024
1 parent 7a30a6b commit 6d4f934
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
16 changes: 16 additions & 0 deletions app/Services/AsaasPhp/Concerns/AsaasClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Services\AsaasPhp\Concerns;

trait AsaasClient
{
public function __construct(
protected ?string $environment = null,
protected ?string $token = null,
protected ?string $url = null,
) {
$this->environment = app()->isLocal() ? 'sandbox' : 'production';
$this->token = config("asaas.{$this->environment}.token");
$this->url = config("asaas.{$this->environment}.url");
}
}
11 changes: 6 additions & 5 deletions app/Services/AsaasPhp/Customer/CustomerList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace App\Services\AsaasPhp\Customer;

use App\Services\AsaasPhp\Concerns\AsaasClient;
use Illuminate\Support\Facades\Http;

class CustomerList
{
public static function list(): array
{
$environment = app()->isLocal() ? 'sandbox' : 'production';
use AsaasClient;

public function list(): array
{
try {
return Http::withToken(config("{$environment}.token"))
->get(config("{$environment}.url") . "/customers")
return Http::withHeader('access_token', $this->token)
->get("{$this->url}/customers")
->throw()
->json();
} catch (\Exception $exception) {
Expand Down
2 changes: 1 addition & 1 deletion routes/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Support\Facades\Artisan;

Artisan::command('play', function () {
$customers = App\Services\AsaasPhp\Customer\CustomerList::list();
$customers = (new App\Services\AsaasPhp\Customer\CustomerList)->list();

dd($customers);
});

0 comments on commit 6d4f934

Please sign in to comment.