Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./vendor/bin/pint
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
}
],
"require-dev": {
"pestphp/pest": "^3.5"
"pestphp/pest": "^3.5",
"laravel/pint": "^1.18"
},
"config": {
"allow-plugins": {
Expand All @@ -27,4 +28,4 @@
"scripts": {
"test": "vendor/bin/pest"
}
}
}
68 changes: 67 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions examples/asaas/clients.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

use PHPay\PHPay;
use PHPay\Gateways\Asaas\AsaasGateway;
use PHPay\PHPay;

require_once __DIR__ . '/../../vendor/autoload.php';

require_once __DIR__ . '/credentials.php';

$client = [
'name' => NAME,
'cpf_cnpj' => CPF_CNPJ
'name' => NAME,
'cpf_cnpj' => CPF_CNPJ,
];

/**
Expand All @@ -35,7 +36,7 @@
*/
$response = $phpay
->client()
->with(['cpfCnpj' => '09102295466',])
->with(['cpfCnpj' => '09102295466', ])
->all();

// print_r($response);
Expand Down
2 changes: 1 addition & 1 deletion examples/asaas/credentials.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
const TOKEN_ASAAS_SANDBOX = '';

/* client to testing */
const NAME = '';
const NAME = '';
const CPF_CNPJ = '';
69 changes: 69 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"preset": "psr12",
"rules": {
"group_import": true,
"single_import_per_statement": false,
"no_unused_imports": true,
"array_indentation": true,
"array_syntax": {
"syntax": "short"
},
"binary_operator_spaces": {
"default": "single_space",
"operators": {
"=": "align_single_space_minimal",
"=>": "align_single_space_minimal"
}
},
"blank_line_after_namespace": true,
"blank_line_after_opening_tag": false,
"class_attributes_separation": {
"elements": {
"property": "one"
}
},
"concat_space": {
"spacing": "one"
},
"declare_equal_normalize": {
"space": "single"
},
"elseif": false,
"encoding": true,
"indentation_type": true,
"no_useless_else": false,
"no_useless_return": true,
"ordered_imports": true,
"ternary_operator_spaces": true,
"no_extra_blank_lines": true,
"no_multiline_whitespace_around_double_arrow": true,
"multiline_whitespace_before_semicolons": true,
"no_singleline_whitespace_before_semicolons": true,
"no_spaces_around_offset": true,
"ternary_to_null_coalescing": true,
"whitespace_after_comma_in_array": true,
"trim_array_spaces": true,
"trailing_comma_in_multiline": true,
"unary_operator_spaces": true,
"blank_line_before_statement": {
"statements": [
"break",
"continue",
"declare",
"return",
"throw",
"try",
"continue",
"do",
"exit",
"for",
"foreach",
"if",
"include",
"include_once",
"require",
"require_once"
]
}
}
}
8 changes: 4 additions & 4 deletions src/Gateways/Asaas/AsaasGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Support\Facades\Http;
use PHPay\Contracts\GatewayInterface;
use PHPay\Exceptions\AsaasExceptions;
use PHPay\Gateways\Asaas\Enums\{BillingType, ClientMethods};
use PHPay\Gateways\Asaas\Enums\{BillingType};
use PHPay\Gateways\Asaas\Requests\AsaasPixRequest;
use PHPay\Gateways\Asaas\Resources\{Auth, Client};
use PHPay\Gateways\Gateway;
Expand Down Expand Up @@ -58,10 +58,10 @@ public function pix(array $pix): self|AsaasExceptions

$payment = Http::asaas()
->post('/payments', [
'customer' => $this->customerId,
'customer' => $this->customerId,
'billingType' => BillingType::PIX->value,
'value' => $amount,
'dueDate' => $due_date,
'value' => $amount,
'dueDate' => $due_date,
'description' => $description,
])->json();

Expand Down
6 changes: 3 additions & 3 deletions src/Gateways/Asaas/Enums/BillingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

enum BillingType: string
{
case UNDEFINED = 'UNDEFINED';
case BOLETO = 'BOLETO';
case UNDEFINED = 'UNDEFINED';
case BOLETO = 'BOLETO';
case CREDIT_CARD = 'CREDIT_CARD';
case PIX = 'PIX';
case PIX = 'PIX';
}
6 changes: 3 additions & 3 deletions src/Gateways/Asaas/Enums/ClientMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

enum ClientMethods: string
{
case ALL = 'all';
case FIND = 'find';
case STORE = 'store';
case ALL = 'all';
case FIND = 'find';
case STORE = 'store';
case UPDATE = 'update';
case DELETE = 'delete';
}
6 changes: 3 additions & 3 deletions src/Gateways/Asaas/Requests/AsaasClientRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class AsaasClientRequest
*/
public static function validate(array $client): void
{
if (! isset($client['name'])) {
if (!isset($client['name'])) {
throw new \InvalidArgumentException(self::messages()->name);
}

if (! isset($client['cpf_cnpj'])) {
if (!isset($client['cpf_cnpj'])) {
throw new \InvalidArgumentException(self::messages()->cpf_cnpj);
}
}
Expand All @@ -31,7 +31,7 @@ public static function validate(array $client): void
public function messages(): stdClass
{
return (object) [
'name' => 'Asaas: Nome do cliente é obrigatório para o Asaas',
'name' => 'Asaas: Nome do cliente é obrigatório para o Asaas',
'cpf_cnpj' => 'Asaas: CPF/CNPJ do cliente é obrigatório para o Asaas',
];
}
Expand Down
12 changes: 6 additions & 6 deletions src/Gateways/Asaas/Requests/AsaasPixRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class AsaasPixRequest
{
public static function validate(array $pix): void
{
if (! isset($pix['description'])) {
if (!isset($pix['description'])) {
throw new \InvalidArgumentException(self::messages()->description);
}

if (! isset($pix['amount'])) {
if (!isset($pix['amount'])) {
throw new \InvalidArgumentException(self::messages()->amount);
}

if (! isset($pix['due_date'])) {
if (!isset($pix['due_date'])) {
throw new \InvalidArgumentException(self::messages()->due_date->required);
}

Expand All @@ -29,10 +29,10 @@ public static function messages(): stdClass
{
return (object) [
'description' => 'Asaas: Descrição do pagamento é obrigatório para o Asaas',
'amount' => 'Asaas: Valor do pagamento é obrigatório para o Asaas',
'due_date' => (object) [
'amount' => 'Asaas: Valor do pagamento é obrigatório para o Asaas',
'due_date' => (object) [
'required' => 'Asaas: Data de vencimento do pagamento é obrigatório para o Asaas',
'date' => 'Asaas: Data de vencimento do pagamento não pode ser menor que a data atual',
'date' => 'Asaas: Data de vencimento do pagamento não pode ser menor que a data atual',
],
];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Gateways/Asaas/Resources/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPay\Gateways\Asaas\Resources;

use Illuminate\Support\Facades\Http;
use PHPay\Exceptions\AsaasExceptions;

final class Auth
{
Expand All @@ -24,7 +23,7 @@ public function __construct(string $token, bool $sandbox)
->baseUrl($baseUrl)
->withHeaders([
'content-type' => 'application/json',
'user-agent' => 'payhub',
'user-agent' => 'payhub',
'access_token' => $token,
]);
});
Expand Down
6 changes: 3 additions & 3 deletions src/Gateways/Asaas/Resources/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Client implements ClientInterface
*/
public function __construct(array $client, Gateway $gateway)
{
$this->client = $client;
$this->client = $client;
$this->gateway = $gateway;
}

Expand Down Expand Up @@ -110,13 +110,13 @@ public function store(): string|AsaasExceptions

$client = self::find($cpf_cnpj);

if (! empty($client)) {
if (!empty($client)) {
return $client[0]['id'];
}

$client = Http::asaas()
->post(env('ASSAS_CLIENTS'), [
'name' => $name,
'name' => $name,
'cpfCnpj' => $cpf_cnpj,
])->json();

Expand Down
3 changes: 1 addition & 2 deletions src/PHPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use Dotenv\Dotenv;
use Illuminate\Container\Container;
use Illuminate\Http\Client\Factory;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\{Facade, Http};
use PHPay\Gateways\Asaas\AsaasGateway;
use PHPay\Gateways\Gateway;

Expand Down
6 changes: 4 additions & 2 deletions tests/Feature/PayhubTest.php → tests/Feature/PHPayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use PHPay\PHPay;

test('instance payhub class', function () {
$payhub = new PHPay('token');
$token = '';

expect($payhub)
$phpay = PHPay::asaas($token);

expect($phpay)
->toBeInstanceOf(PHPay::class);
});