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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "mariolucasdev/payhub",
"name": "mariolucasdev/phpay",
"type": "library",
"autoload": {
"psr-4": {
"Payhub\\": "src/"
"PHPay\\": "src/"
}
},
"authors": [
Expand All @@ -27,4 +27,4 @@
"scripts": {
"test": "vendor/bin/pest"
}
}
}
34 changes: 19 additions & 15 deletions examples/asaas/clients.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

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

require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/credentials.php';
Expand All @@ -12,22 +12,19 @@
];

/**
* initialize payhub
*
* @param array $credentials <token>
* @param bool $sandbox
* initialize phpay
*
* @return AsaasGateway
*/
$payhub = Payhub::asaas(TOKEN_ASAAS_SANDBOX);
$phpay = PHPay::asaas(TOKEN_ASAAS_SANDBOX);

/**
* store asaas cliente
*
* @param array $client <name, cpf_cnpj>
* @return string cliente id asaas
*/
$payhub
$phpay
->client($client)
->store();

Expand All @@ -36,7 +33,7 @@
*
* @return array clients
*/
$response = $payhub
$response = $phpay
->client()
->with(['cpfCnpj' => '09102295466',])
->all();
Expand All @@ -49,7 +46,7 @@
* @param array $client <cpf_cnpj>
* @return array client
*/
$response = $payhub
$response = $phpay
->client()
->with(['cpfCnpj' => '09102295466'])
->get();
Expand All @@ -62,17 +59,24 @@
* @param array $client <cpf_cnpj>
* @return bool
*/
$payhub->client($client)
$phpay
->client($client)
->delete();

/**
* restore cliente no asaas
*
* @param array $client <cpf_cnpj>
* @return bool
*/
$response = $payhub
$response = $phpay
->client()
->restore('cus_000006376400');

// print_r($response);

/**
* notifications cliente no asaas
*/
$response = $phpay
->client()
->notifications('cus_000006376400');

// print_r($response);
2 changes: 1 addition & 1 deletion src/Contracts/GatewayInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Payhub\Contracts;
namespace PHPay\Contracts;

interface GatewayInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/AsaasExceptions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Payhub\Exceptions;
namespace PHPay\Exceptions;

use Exception;

Expand Down
31 changes: 7 additions & 24 deletions src/Gateways/Asaas/AsaasGateway.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Payhub\Gateways\Asaas;
namespace PHPay\Gateways\Asaas;

use Illuminate\Support\Facades\Http;
use Payhub\Contracts\GatewayInterface;
use Payhub\Exceptions\AsaasExceptions;
use Payhub\Gateways\Asaas\Enums\{BillingType, ClientMethods};
use Payhub\Gateways\Asaas\Requests\AsaasPixRequest;
use Payhub\Gateways\Asaas\Resources\{Auth, Client};
use Payhub\Gateways\Gateway;
use PHPay\Contracts\GatewayInterface;
use PHPay\Exceptions\AsaasExceptions;
use PHPay\Gateways\Asaas\Enums\{BillingType, ClientMethods};
use PHPay\Gateways\Asaas\Requests\AsaasPixRequest;
use PHPay\Gateways\Asaas\Resources\{Auth, Client};
use PHPay\Gateways\Gateway;

class AsaasGateway extends Gateway implements GatewayInterface
{
Expand Down Expand Up @@ -43,23 +43,6 @@ public function client(array $client = []): Client
{
return new Client($client, $this);
}
// {
// if (! ClientMethods::tryFrom($method)) {
// return (new AsaasExceptions())('Method not found');
// }

// if (! method_exists(Client::class, $method)) {
// return (new AsaasExceptions())('Method not found');
// }

// try {
// $this->customerId = (new Client())::$method($client);
// } catch (\Exception $e) {
// return (new AsaasExceptions())($e->getMessage());
// }

// return $this;
// }

/**
* generate pix
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Asaas/Enums/BillingType.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Payhub\Gateways\Asaas\Enums;
namespace PHPay\Gateways\Asaas\Enums;

enum BillingType: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Asaas/Enums/ClientMethods.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Payhub\Gateways\Asaas\Enums;
namespace PHPay\Gateways\Asaas\Enums;

enum ClientMethods: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Asaas/Requests/AsaasClientRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Payhub\Gateways\Asaas\Requests;
namespace PHPay\Gateways\Asaas\Requests;

use stdClass;

Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Asaas/Requests/AsaasPixRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Payhub\Gateways\Asaas\Requests;
namespace PHPay\Gateways\Asaas\Requests;

use stdClass;

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/Asaas/Resources/Auth.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Payhub\Gateways\Asaas\Resources;
namespace PHPay\Gateways\Asaas\Resources;

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

final class Auth
{
Expand Down
35 changes: 23 additions & 12 deletions src/Gateways/Asaas/Resources/Client.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Payhub\Gateways\Asaas\Resources;
namespace PHPay\Gateways\Asaas\Resources;

use Illuminate\Support\Facades\Http;
use Payhub\Exceptions\AsaasExceptions;
use Payhub\Gateways\Asaas\Requests\AsaasClientRequest;
use Payhub\Gateways\Asaas\Resources\Interfaces\ClientInterface;
use Payhub\Gateways\Gateway;
use PHPay\Exceptions\AsaasExceptions;
use PHPay\Gateways\Asaas\Requests\AsaasClientRequest;
use PHPay\Gateways\Asaas\Resources\Interfaces\ClientInterface;
use PHPay\Gateways\Gateway;

final class Client implements ClientInterface
{
Expand Down Expand Up @@ -174,13 +174,9 @@ public function restore(string $id): bool
->post(str_replace('{id}', $id, env('ASSAS_CLIENTS_RESTORE')))
->json();

print_r($client);

die();

// if ($client['restored']) {
// return true;
// }
if ($client) {
return true;
}

return false;
} catch (\Exception $e) {
Expand All @@ -189,4 +185,19 @@ public function restore(string $id): bool
return false;
}
}

/**
* get client notifications
*
* @param string $id
* @return array
*/
public function notifications(string $id): ?array
{
$notifications = Http::asaas()
->get(str_replace('{id}', $id, env('ASSAS_CLIENTS_NOTIFICATIONS')))
->json();

return $notifications;
}
}
5 changes: 3 additions & 2 deletions src/Gateways/Asaas/Resources/Interfaces/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Payhub\Gateways\Asaas\Resources\Interfaces;
namespace PHPay\Gateways\Asaas\Resources\Interfaces;

use Payhub\Exceptions\AsaasExceptions;
use PHPay\Exceptions\AsaasExceptions;

interface ClientInterface
{
Expand All @@ -13,4 +13,5 @@ public function with(array $filters): self;
public function store(): string|AsaasExceptions;
public function delete(): bool;
public function restore(string $id): bool;
public function notifications(string $id): ?array;
}
2 changes: 1 addition & 1 deletion src/Gateways/Gateway.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Payhub\Gateways;
namespace PHPay\Gateways;

abstract class Gateway
{
Expand Down
9 changes: 4 additions & 5 deletions src/Payhub.php → src/PHPay.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php

namespace Payhub;
namespace PHPay;

use Dotenv\Dotenv;
use Exception;
use Illuminate\Container\Container;
use Illuminate\Http\Client\Factory;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Http;
use Payhub\Gateways\Asaas\AsaasGateway;
use Payhub\Gateways\Gateway;
use PHPay\Gateways\Asaas\AsaasGateway;
use PHPay\Gateways\Gateway;

class Payhub
class PHPay
{
/**
* @var Gateway
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/PayhubTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use Payhub\Payhub;
use PHPay\PHPay;

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

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