Skip to content

Commit

Permalink
PHPAY-52: asaas pix manager keys resource (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolucasdev authored Jan 11, 2025
2 parents f1c88eb + 43c3542 commit f802401
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 10 deletions.
37 changes: 37 additions & 0 deletions examples/asaas/pix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

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

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

require_once __DIR__ . '/credentials.php';

/**
* @var AsaasGateway $phpay
*/
$phpay = new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX));

$phpay
->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);
16 changes: 8 additions & 8 deletions examples/asaas/webhook.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

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

require_once __DIR__ . '/../../vendor/autoload.php';
Expand Down Expand Up @@ -44,7 +44,7 @@
* @return array
* @see available fields in https://docs.asaas.com/reference/criar-novo-webhook
*/
$webhook = $phpay
$phpay
->webhook($webhook)
->create();

Expand All @@ -64,18 +64,18 @@
*/
$phpay
->webhook()
->find($webhook['id']);
->find($webhookId);

/**
* update a webhook
*
* @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',
]);

Expand All @@ -84,6 +84,6 @@
*
* @return bool
*/
$webhookDeleted = $phpay
$phpay
->webhook()
->destroy($webhook['id']);
->destroy($webhookId);
8 changes: 8 additions & 0 deletions src/Contracts/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<mixed> $pix
* @return object
*/
public function pix(array $pix = []): object;
}
12 changes: 12 additions & 0 deletions src/Gateways/Asaas/AsaasGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,4 +69,15 @@ public function webhook(array $webhook = []): Webhook
{
return new Webhook($this->token, $webhook, $this->sandbox);
}

/**
* pix
*
* @param array<mixed> $pix
* @return Pix
*/
public function pix(array $pix = []): Pix
{
return new Pix($this->token, $this->sandbox);
}
}
9 changes: 9 additions & 0 deletions src/Gateways/Asaas/Interface/AsaasGatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<mixed> $pix
* @return Pix
*/
public function pix(array $pix = []): Pix;
}
61 changes: 61 additions & 0 deletions src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace PHPay\Asaas\Resources\Pix\Interface;

interface PixInterface
{
/**
* set query params
*
* @param array<mixed> $queryParams
* @return PixInterface
*/
public function setQueryParams(array $queryParams): PixInterface;

/**
* create pix key
*
* @return array<mixed>
*/
public function createKey(): array;

/**
* find pix key
*
* @param string $id
* @return array<mixed>
*/
public function find(string $id): array;

/**
* get all pix keys
*
* @return array<mixed>
* @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<mixed> $params
* @return array<mixed>
*/
public function staticQrCode(array $params): array;

/**
* destroy static qr code
*
* @param string $id
* @return bool
*/
public function destroyStaticQrCode(string $id): bool;
}
130 changes: 130 additions & 0 deletions src/Gateways/Asaas/Resources/Pix/Pix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace PHPay\Asaas\Resources\Pix;

use GuzzleHttp\Client;
use PHPay\Asaas\Resources\Pix\Interface\PixInterface;
use PHPay\Asaas\Traits\HasAsaasClient;

class Pix implements PixInterface
{
/**
* trait asaas client
*/
use HasAsaasClient;

/**
* client guzzle
*/
private Client $client;

/**
* @var array<mixed>
*/
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<mixed> $queryParams
* @return PixInterface
*/
public function setQueryParams(array $queryParams): PixInterface
{
$this->queryParams = $queryParams;

return $this;
}

/**
* create pix key
*
* @return string
* @return array<mixed>
*/
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<mixed>
*/
public function find(string $id): array
{
return $this->get("pix/addressKeys/{$id}");
}

/**
* get all pix keys
*
* @return array<mixed>
* @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<mixed> $params
* @return array<mixed>
* @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}");
}
}
12 changes: 12 additions & 0 deletions src/Gateways/Efi/EfiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -104,4 +105,15 @@ private function authorization(): void
throw new \Exception('Token not generated');
}
}

/**
* create pix
*
* @param array<string> $pix
* @return object pix
*/
public function pix(array $pix = []): object
{
throw new Exception('Not implemented');
}
}
8 changes: 8 additions & 0 deletions src/Gateways/Efi/Interface/EfiGatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ public function getToken(): array;
* @return Charge charge
*/
public function charge(array $charge = []): Charge;

/**
* get resource customer from gateway.
*
* @param array<mixed> $pix
* @return object
*/
public function pix(array $pix = []): object;
}
Loading

0 comments on commit f802401

Please sign in to comment.