From 900ff3d9e0c40098996ba484058be8d8c89e21b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Fri, 10 Jan 2025 19:39:54 -0300 Subject: [PATCH 1/6] PHPAY-52: wip: fix webhooks example --- examples/asaas/webhook.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/asaas/webhook.php b/examples/asaas/webhook.php index 295ca78..a9999fc 100644 --- a/examples/asaas/webhook.php +++ b/examples/asaas/webhook.php @@ -1,6 +1,6 @@ webhook($webhook) ->create(); @@ -64,7 +64,7 @@ */ $phpay ->webhook() - ->find($webhook['id']); + ->find($webhookId); /** * update a webhook @@ -72,10 +72,10 @@ * @return array * @see available fields in https://docs.asaas.com/reference/atualizar-webhook-existente */ -$webhookUpdated = $phpay +$phpay ->webhook() - ->update($webhook['id'], [ - 'name' => 'Webhook de Teste Atualizado', + ->update($webhookId, [ + 'name' => 'Update webhook with PHPay is awesome', 'url' => 'https://sixtec.com.br/webhook/atualizado', ]); @@ -84,6 +84,6 @@ * * @return bool */ -$webhookDeleted = $phpay +$phpay ->webhook() - ->destroy($webhook['id']); + ->destroy($webhookId); From 38fb15b1683eb79c40098a2569684318da5958e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Fri, 10 Jan 2025 20:13:58 -0300 Subject: [PATCH 2/6] PHPAY-52: wip: resource pix adding generate key with asaas --- examples/asaas/pix.php | 24 ++++++++++ src/Contracts/GatewayInterface.php | 8 ++++ src/Gateways/Asaas/AsaasGateway.php | 12 +++++ .../Asaas/Interface/AsaasGatewayInterface.php | 9 ++++ .../Resources/Pix/Interface/PixInterface.php | 7 +++ src/Gateways/Asaas/Resources/Pix/Pix.php | 47 +++++++++++++++++++ src/Gateways/Efi/EfiGateway.php | 12 +++++ .../Efi/Interface/EfiGatewayInterface.php | 8 ++++ src/PHPay.php | 14 +++++- 9 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 examples/asaas/pix.php create mode 100644 src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php create mode 100644 src/Gateways/Asaas/Resources/Pix/Pix.php diff --git a/examples/asaas/pix.php b/examples/asaas/pix.php new file mode 100644 index 0000000..8b8d467 --- /dev/null +++ b/examples/asaas/pix.php @@ -0,0 +1,24 @@ +pix() + ->createKey(); + +print_r($pixKey); diff --git a/src/Contracts/GatewayInterface.php b/src/Contracts/GatewayInterface.php index 03396e9..69d296e 100644 --- a/src/Contracts/GatewayInterface.php +++ b/src/Contracts/GatewayInterface.php @@ -27,4 +27,12 @@ public function charge(array $charge = []): object; * @return object */ public function webhook(array $webhook = []): object; + + /** + * get resource pix from gateway. + * + * @param array $pix + * @return object + */ + public function pix(array $pix = []): object; } diff --git a/src/Gateways/Asaas/AsaasGateway.php b/src/Gateways/Asaas/AsaasGateway.php index ad813ae..26b3dad 100644 --- a/src/Gateways/Asaas/AsaasGateway.php +++ b/src/Gateways/Asaas/AsaasGateway.php @@ -6,6 +6,7 @@ use PHPay\Asaas\Interface\AsaasGatewayInterface; use PHPay\Asaas\Resources\Charge\Charge; use PHPay\Asaas\Resources\Customer\Customer; +use PHPay\Asaas\Resources\Pix\Pix; use PHPay\Asaas\Resources\Webhook\Webhook; class AsaasGateway implements AsaasGatewayInterface @@ -68,4 +69,15 @@ public function webhook(array $webhook = []): Webhook { return new Webhook($this->token, $webhook, $this->sandbox); } + + /** + * pix + * + * @param array $pix + * @return Pix + */ + public function pix(array $pix = []): Pix + { + return new Pix($this->token, $this->sandbox); + } } diff --git a/src/Gateways/Asaas/Interface/AsaasGatewayInterface.php b/src/Gateways/Asaas/Interface/AsaasGatewayInterface.php index 75a7fc2..373a522 100644 --- a/src/Gateways/Asaas/Interface/AsaasGatewayInterface.php +++ b/src/Gateways/Asaas/Interface/AsaasGatewayInterface.php @@ -4,6 +4,7 @@ use PHPay\Asaas\Resources\Charge\Charge; use PHPay\Asaas\Resources\Customer\Customer; +use PHPay\Asaas\Resources\Pix\Pix; use PHPay\Asaas\Resources\Webhook\Webhook; use PHPay\Contracts\GatewayInterface; @@ -32,4 +33,12 @@ public function charge(array $charge = []): Charge; * @return Webhook */ public function webhook(array $webhook = []): Webhook; + + /** + * get resource pix from gateway. + * + * @param array $pix + * @return Pix + */ + public function pix(array $pix = []): Pix; } diff --git a/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php b/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php new file mode 100644 index 0000000..d67e740 --- /dev/null +++ b/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php @@ -0,0 +1,7 @@ +client = $this->clientAsaasBoot(); + } + + /** + * create pix key + * + * @return string + * @return array + */ + public function createKey(): array + { + /* TODO: prepare response */ + /* TODO: adding reponse with image qrcode */ + return $this->post('pix/addressKeys', [ + 'type' => 'EVP', + ]); + } +} diff --git a/src/Gateways/Efi/EfiGateway.php b/src/Gateways/Efi/EfiGateway.php index feebe72..e62ab9d 100644 --- a/src/Gateways/Efi/EfiGateway.php +++ b/src/Gateways/Efi/EfiGateway.php @@ -6,6 +6,7 @@ use Efi\Resources\Authorization\Authorization; use Efi\Resources\Charge\Charge; use Efi\Traits\HasEfiClient; +use Exception; use GuzzleHttp\Client; use stdClass; @@ -104,4 +105,15 @@ private function authorization(): void throw new \Exception('Token not generated'); } } + + /** + * create pix + * + * @param array $pix + * @return object pix + */ + public function pix(array $pix = []): object + { + throw new Exception('Not implemented'); + } } diff --git a/src/Gateways/Efi/Interface/EfiGatewayInterface.php b/src/Gateways/Efi/Interface/EfiGatewayInterface.php index 24c6ce2..2ee2856 100644 --- a/src/Gateways/Efi/Interface/EfiGatewayInterface.php +++ b/src/Gateways/Efi/Interface/EfiGatewayInterface.php @@ -21,4 +21,12 @@ public function getToken(): array; * @return Charge charge */ public function charge(array $charge = []): Charge; + + /** + * get resource customer from gateway. + * + * @param array $pix + * @return object + */ + public function pix(array $pix = []): object; } diff --git a/src/PHPay.php b/src/PHPay.php index 8ea8d0c..3e14a96 100644 --- a/src/PHPay.php +++ b/src/PHPay.php @@ -20,11 +20,10 @@ public function __construct( /** * ATTENTION!!! ONLY EFÍ GATEWAY - * get token. * * @return array */ - public function getToken(): array + protected function getToken(): array { /** * @var EfiGatewayInterface $gateway @@ -66,4 +65,15 @@ public function webhook(array $webhook = []): object { return $this->gateway->webhook($webhook); } + + /** + * get resource pix from gateway. + * + * @param array $pix + * @return object + */ + public function pix(array $pix = []): object + { + return $this->gateway->pix($pix); + } } From 86532d3cd245f3d5fc1c94a4ec7fc7048b201ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Fri, 10 Jan 2025 21:29:07 -0300 Subject: [PATCH 3/6] PHPAY-52: wip: resource pix list keys --- examples/asaas/pix.php | 11 +++++-- src/Gateways/Asaas/Resources/Pix/Pix.php | 39 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/examples/asaas/pix.php b/examples/asaas/pix.php index 8b8d467..27ea9f1 100644 --- a/examples/asaas/pix.php +++ b/examples/asaas/pix.php @@ -17,8 +17,15 @@ * * @return string $pixKey */ -$pixKey = $phpay +$phpay ->pix() ->createKey(); -print_r($pixKey); +/** + * get all pix keys + * + * @return array $pixKeys + */ +$phpay + ->pix() + ->getAll(); diff --git a/src/Gateways/Asaas/Resources/Pix/Pix.php b/src/Gateways/Asaas/Resources/Pix/Pix.php index 4ee90ff..4c0f5db 100644 --- a/src/Gateways/Asaas/Resources/Pix/Pix.php +++ b/src/Gateways/Asaas/Resources/Pix/Pix.php @@ -18,6 +18,11 @@ class Pix implements PixInterface */ private Client $client; + /** + * @var array + */ + private array $queryParams = []; + /** * construct * @@ -30,6 +35,19 @@ public function __construct( $this->client = $this->clientAsaasBoot(); } + /** + * set query params + * + * @param array $queryParams + * @return PixInterface + */ + public function setQueryParams(array $queryParams): PixInterface + { + $this->queryParams = $queryParams; + + return $this; + } + /** * create pix key * @@ -44,4 +62,25 @@ public function createKey(): array 'type' => 'EVP', ]); } + + /** + * get all pix keys + * + * @return array + * @see params in https://docs.asaas.com/reference/list-keys + */ + public function getAll(): array + { + $params = $this->queryParams; + + if (empty($params)) { + $params = [ + 'offset' => 0, + 'limit' => 100, + 'status' => 'ACTIVE', + ]; + } + + return $this->get('pix/addressKeys', $params); + } } From 3293668f83f2f4b159d212096eb22d2bd5a3e908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Fri, 10 Jan 2025 21:31:09 -0300 Subject: [PATCH 4/6] PHPAY-52: wip: resource pix find key by id --- examples/asaas/pix.php | 14 ++++---------- src/Gateways/Asaas/Resources/Pix/Pix.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/asaas/pix.php b/examples/asaas/pix.php index 27ea9f1..2583b6e 100644 --- a/examples/asaas/pix.php +++ b/examples/asaas/pix.php @@ -12,20 +12,14 @@ */ $phpay = new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX)); -/** - * create pix key - * - * @return string $pixKey - */ $phpay ->pix() ->createKey(); -/** - * get all pix keys - * - * @return array $pixKeys - */ +$phpay + ->pix() + ->find(ID_PIX_KEY); + $phpay ->pix() ->getAll(); diff --git a/src/Gateways/Asaas/Resources/Pix/Pix.php b/src/Gateways/Asaas/Resources/Pix/Pix.php index 4c0f5db..dae5100 100644 --- a/src/Gateways/Asaas/Resources/Pix/Pix.php +++ b/src/Gateways/Asaas/Resources/Pix/Pix.php @@ -63,6 +63,17 @@ public function createKey(): array ]); } + /** + * find pix key + * + * @param string $id + * @return array + */ + public function find(string $id): array + { + return $this->get("pix/addressKeys/{$id}"); + } + /** * get all pix keys * From f4cd314e2ac200597b00d580cdd6e29291052f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Fri, 10 Jan 2025 21:46:51 -0300 Subject: [PATCH 5/6] PHPAY-52: wip: resource pix destroy key --- examples/asaas/pix.php | 4 ++ .../Resources/Pix/Interface/PixInterface.php | 38 +++++++++++++++++++ src/Gateways/Asaas/Resources/Pix/Pix.php | 11 ++++++ 3 files changed, 53 insertions(+) diff --git a/examples/asaas/pix.php b/examples/asaas/pix.php index 2583b6e..20a069e 100644 --- a/examples/asaas/pix.php +++ b/examples/asaas/pix.php @@ -23,3 +23,7 @@ $phpay ->pix() ->getAll(); + +$phpay + ->pix() + ->destroy(ID_PIX_KEY); diff --git a/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php b/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php index d67e740..14058ce 100644 --- a/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php +++ b/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php @@ -4,4 +4,42 @@ interface PixInterface { + /** + * set query params + * + * @param array $queryParams + * @return PixInterface + */ + public function setQueryParams(array $queryParams): PixInterface; + + /** + * create pix key + * + * @return array + */ + public function createKey(): array; + + /** + * find pix key + * + * @param string $id + * @return array + */ + public function find(string $id): array; + + /** + * get all pix keys + * + * @return array + * @see params in https://docs.asaas.com/reference/list-keys + */ + public function getAll(): array; + + /** + * destroy pix key + * + * @param string $id + * @return bool + */ + public function destroy(string $id): bool; } diff --git a/src/Gateways/Asaas/Resources/Pix/Pix.php b/src/Gateways/Asaas/Resources/Pix/Pix.php index dae5100..66c680a 100644 --- a/src/Gateways/Asaas/Resources/Pix/Pix.php +++ b/src/Gateways/Asaas/Resources/Pix/Pix.php @@ -94,4 +94,15 @@ public function getAll(): array return $this->get('pix/addressKeys', $params); } + + /** + * destroy pix key + * + * @param string $id + * @return bool + */ + public function destroy(string $id): bool + { + return $this->delete("pix/addressKeys/{$id}"); + } } From 43c3542801e0dfcbe8b5681e7f57adeda2c7b2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Fri, 10 Jan 2025 22:01:44 -0300 Subject: [PATCH 6/6] PHPAY-52: feat: adding manager pix keys resource --- examples/asaas/pix.php | 8 +++++++ .../Resources/Pix/Interface/PixInterface.php | 16 +++++++++++++ src/Gateways/Asaas/Resources/Pix/Pix.php | 24 ++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/examples/asaas/pix.php b/examples/asaas/pix.php index 20a069e..32d51e5 100644 --- a/examples/asaas/pix.php +++ b/examples/asaas/pix.php @@ -27,3 +27,11 @@ $phpay ->pix() ->destroy(ID_PIX_KEY); + +$phpay + ->pix() + ->staticQrCode($staticQrCodeParams); + +$phpay + ->pix() + ->destroyStaticQrCode($statiQrCodeId); diff --git a/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php b/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php index 14058ce..3a3e71b 100644 --- a/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php +++ b/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php @@ -42,4 +42,20 @@ public function getAll(): array; * @return bool */ public function destroy(string $id): bool; + + /** + * static qr code + * + * @param array $params + * @return array + */ + public function staticQrCode(array $params): array; + + /** + * destroy static qr code + * + * @param string $id + * @return bool + */ + public function destroyStaticQrCode(string $id): bool; } diff --git a/src/Gateways/Asaas/Resources/Pix/Pix.php b/src/Gateways/Asaas/Resources/Pix/Pix.php index 66c680a..b91a772 100644 --- a/src/Gateways/Asaas/Resources/Pix/Pix.php +++ b/src/Gateways/Asaas/Resources/Pix/Pix.php @@ -88,7 +88,6 @@ public function getAll(): array $params = [ 'offset' => 0, 'limit' => 100, - 'status' => 'ACTIVE', ]; } @@ -105,4 +104,27 @@ public function destroy(string $id): bool { return $this->delete("pix/addressKeys/{$id}"); } + + /** + * static qr code + * + * @param array $params + * @return array + * @see params in https://docs.asaas.com/reference/create-static-qrcode + */ + public function staticQrCode(array $params): array + { + return $this->post('pix/qrCodes/static', $params); + } + + /** + * destroy static qr code + * + * @param string $id + * @return bool + */ + public function destroyStaticQrCode(string $id): bool + { + return $this->delete("pix/qrCodes/static/{$id}"); + } }