-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPAY-52: asaas pix manager keys resource (#53)
- Loading branch information
Showing
10 changed files
with
297 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Gateways/Asaas/Resources/Pix/Interface/PixInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.