diff --git a/examples/asaas/pix.php b/examples/asaas/pix.php new file mode 100644 index 0000000..32d51e5 --- /dev/null +++ b/examples/asaas/pix.php @@ -0,0 +1,37 @@ +pix() + ->createKey(); + +$phpay + ->pix() + ->find(ID_PIX_KEY); + +$phpay + ->pix() + ->getAll(); + +$phpay + ->pix() + ->destroy(ID_PIX_KEY); + +$phpay + ->pix() + ->staticQrCode($staticQrCodeParams); + +$phpay + ->pix() + ->destroyStaticQrCode($statiQrCodeId); 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); 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..3a3e71b --- /dev/null +++ b/src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php @@ -0,0 +1,61 @@ + $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; + + /** + * 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 new file mode 100644 index 0000000..b91a772 --- /dev/null +++ b/src/Gateways/Asaas/Resources/Pix/Pix.php @@ -0,0 +1,130 @@ + + */ + private array $queryParams = []; + + /** + * construct + * + * @param string $token + */ + public function __construct( + private string $token, + private bool $sandbox = true, + ) { + $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 + * + * @return string + * @return array + */ + public function createKey(): array + { + /* TODO: prepare response */ + /* TODO: adding reponse with image qrcode */ + return $this->post('pix/addressKeys', [ + 'type' => 'EVP', + ]); + } + + /** + * find pix key + * + * @param string $id + * @return array + */ + public function find(string $id): array + { + return $this->get("pix/addressKeys/{$id}"); + } + + /** + * 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, + ]; + } + + 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}"); + } + + /** + * 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}"); + } +} 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); + } }