From 0e34bcb6e4ff8ccc9d143306a673a82e1385ecb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Sun, 1 Dec 2024 17:39:10 -0300 Subject: [PATCH 1/2] PAYH-4: feat: get notifications client --- examples/asaas/clients.php | 12 ++++++--- src/Gateways/Asaas/Resources/Client.php | 25 +++++++++++++------ .../Resources/Interfaces/ClientInterface.php | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/asaas/clients.php b/examples/asaas/clients.php index 8de41e0..ffa2245 100644 --- a/examples/asaas/clients.php +++ b/examples/asaas/clients.php @@ -67,12 +67,18 @@ /** * restore cliente no asaas - * - * @param array $client - * @return bool */ $response = $payhub ->client() ->restore('cus_000006376400'); // print_r($response); + +/** + * notifications cliente no asaas + */ +$response = $payhub + ->client() + ->notifications('cus_000006376400'); + +print_r($response); diff --git a/src/Gateways/Asaas/Resources/Client.php b/src/Gateways/Asaas/Resources/Client.php index d5fa9ea..0e6aec6 100644 --- a/src/Gateways/Asaas/Resources/Client.php +++ b/src/Gateways/Asaas/Resources/Client.php @@ -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) { @@ -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; + } } diff --git a/src/Gateways/Asaas/Resources/Interfaces/ClientInterface.php b/src/Gateways/Asaas/Resources/Interfaces/ClientInterface.php index 721cc90..76de092 100644 --- a/src/Gateways/Asaas/Resources/Interfaces/ClientInterface.php +++ b/src/Gateways/Asaas/Resources/Interfaces/ClientInterface.php @@ -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; } From 2eae9d586a413895b009ab31ec9d42b55a234919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Mon, 2 Dec 2024 18:23:32 -0300 Subject: [PATCH 2/2] PAYH-4: refactor: rename lib --- composer.json | 6 ++-- examples/asaas/clients.php | 26 +++++++--------- src/Contracts/GatewayInterface.php | 2 +- src/Exceptions/AsaasExceptions.php | 2 +- src/Gateways/Asaas/AsaasGateway.php | 31 +++++-------------- src/Gateways/Asaas/Enums/BillingType.php | 2 +- src/Gateways/Asaas/Enums/ClientMethods.php | 2 +- .../Asaas/Requests/AsaasClientRequest.php | 2 +- .../Asaas/Requests/AsaasPixRequest.php | 2 +- src/Gateways/Asaas/Resources/Auth.php | 4 +-- src/Gateways/Asaas/Resources/Client.php | 10 +++--- .../Resources/Interfaces/ClientInterface.php | 4 +-- src/Gateways/Gateway.php | 2 +- src/{Payhub.php => PHPay.php} | 9 +++--- tests/Feature/PayhubTest.php | 6 ++-- 15 files changed, 45 insertions(+), 65 deletions(-) rename src/{Payhub.php => PHPay.php} (92%) diff --git a/composer.json b/composer.json index 8084fa9..d3b375f 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "mariolucasdev/payhub", + "name": "mariolucasdev/phpay", "type": "library", "autoload": { "psr-4": { - "Payhub\\": "src/" + "PHPay\\": "src/" } }, "authors": [ @@ -27,4 +27,4 @@ "scripts": { "test": "vendor/bin/pest" } -} +} \ No newline at end of file diff --git a/examples/asaas/clients.php b/examples/asaas/clients.php index ffa2245..cc9bf31 100644 --- a/examples/asaas/clients.php +++ b/examples/asaas/clients.php @@ -1,7 +1,7 @@ - * @param bool $sandbox + * initialize phpay * * @return AsaasGateway */ -$payhub = Payhub::asaas(TOKEN_ASAAS_SANDBOX); +$phpay = PHPay::asaas(TOKEN_ASAAS_SANDBOX); /** * store asaas cliente @@ -27,7 +24,7 @@ * @param array $client * @return string cliente id asaas */ -$payhub +$phpay ->client($client) ->store(); @@ -36,7 +33,7 @@ * * @return array clients */ -$response = $payhub +$response = $phpay ->client() ->with(['cpfCnpj' => '09102295466',]) ->all(); @@ -49,7 +46,7 @@ * @param array $client * @return array client */ -$response = $payhub +$response = $phpay ->client() ->with(['cpfCnpj' => '09102295466']) ->get(); @@ -62,13 +59,14 @@ * @param array $client * @return bool */ -$payhub->client($client) +$phpay + ->client($client) ->delete(); /** * restore cliente no asaas */ -$response = $payhub +$response = $phpay ->client() ->restore('cus_000006376400'); @@ -77,8 +75,8 @@ /** * notifications cliente no asaas */ -$response = $payhub +$response = $phpay ->client() ->notifications('cus_000006376400'); -print_r($response); +// print_r($response); diff --git a/src/Contracts/GatewayInterface.php b/src/Contracts/GatewayInterface.php index 5c27138..46d8d2d 100644 --- a/src/Contracts/GatewayInterface.php +++ b/src/Contracts/GatewayInterface.php @@ -1,6 +1,6 @@ customerId = (new Client())::$method($client); - // } catch (\Exception $e) { - // return (new AsaasExceptions())($e->getMessage()); - // } - - // return $this; - // } /** * generate pix diff --git a/src/Gateways/Asaas/Enums/BillingType.php b/src/Gateways/Asaas/Enums/BillingType.php index 30d5888..52d8507 100644 --- a/src/Gateways/Asaas/Enums/BillingType.php +++ b/src/Gateways/Asaas/Enums/BillingType.php @@ -1,6 +1,6 @@ toBeInstanceOf(Payhub::class); + ->toBeInstanceOf(PHPay::class); });