Skip to content

Commit

Permalink
Otimizações
Browse files Browse the repository at this point in the history
- Updated comments
- Removed "pt_en" from files name (all files are now in English)
- Simplified response() method in Notification
- Simplified cancel() method in Billet
- Minor improvements
  • Loading branch information
Pedro committed Sep 28, 2018
1 parent 570b175 commit de3b120
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 61 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ Você pode obter a lista de dados que você pode enviar no seguinte link: [https
use WebMaster\PagHiper\PagHiper;

$pagHiper = new PagHiper();
$transaction = $pagHiper->billet()->cancel([
'transaction_id' => 'JKP03X9KN0RELVLH',
]);
$transaction = $pagHiper->billet()->cancel('JKP03X9KN0RELVLH');
```

**Para obter informações do pagamento via retorno automático:**
Expand All @@ -70,10 +68,7 @@ $transaction = $pagHiper->billet()->cancel([
use WebMaster\PagHiper\PagHiper;

$pagHiper = new PagHiper();
$transaction = $pagHiper->notification()->response([
'notification_id' => $_POST['notification_id'],
'transaction_id' => $_POST['idTransacao']
]);
$transaction = $pagHiper->notification()->response($_POST['notification_id'], $_POST['idTransacao']);
```

**Para obter a lista de suas contas bancárias:**
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Interfaces/BankAccountsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface BankAccountsInterface
{
/**
* Lista as contas bancárias para saque via API.
* Retrieves a list of bank accounts.
*
* @return void
*/
Expand Down
22 changes: 22 additions & 0 deletions src/Core/Interfaces/BilletInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace WebMaster\PagHiper\Core\Interfaces;

interface BilletInterface
{
/**
* Create a new billet.
*
* @param array $data Billet data. Full list of all available data can be found at: https://dev.paghiper.com/reference#gerar-boleto
* @return void
*/
public function create(array $data);

/**
* Cancels a billet.
*
* @param string $transactionId Transaction ID to cancel.
* @return boolean
*/
public function cancel(string $transactionId);
}
24 changes: 0 additions & 24 deletions src/Core/Interfaces/BoletoInterface.php

This file was deleted.

6 changes: 4 additions & 2 deletions src/Core/Interfaces/NotificationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
interface NotificationInterface
{
/**
* Pega a resposta da notificação (retorno automático) do PagHiper.
* Get notification's response.
*
* @param string $notificationId
* @param string $transactionId
* @return void
*/
public function response(array $data);
public function response(string $notificationId = '', string $transactionId = '');
}
11 changes: 6 additions & 5 deletions src/Core/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class Request
protected $response;

/**
* Envia uma requisição para a API do PagHiper
* Send a request to PagHiper's API.
*
* @param string $endpoint Recurso da API (exemplo: /transaction/create/)
* @param array $params Parâmetros necessários para o endpoint. https://dev.paghiper.com/reference
* @param string $endpoint API resource (exemplo: /transaction/create/)
* @param array $params Resource params. Can be found at: https://dev.paghiper.com/reference
*/
public function __construct(string $endpoint = '', array $params = [])
{
Expand All @@ -34,12 +34,13 @@ public function __construct(string $endpoint = '', array $params = [])
],
]);

// Acrescenta o token e apiKey
// Add token and apiKey
$params = array_merge([
'token' => $credentials::TOKEN,
'apiKey' => $credentials::API_KEY,
], $params);

// Send the request
$request = $client->request('POST', $endpoint, [
'json' => $params,
]);
Expand All @@ -50,7 +51,7 @@ public function __construct(string $endpoint = '', array $params = [])
}

/**
* Pega a resposta do PagHiper
* Get PagHiper's response.
*
* @return void
*/
Expand Down
1 change: 0 additions & 1 deletion src/PagHiper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class PagHiper
{
protected $request;
protected $billet;
protected $bank;
protected $notification;
Expand Down
11 changes: 9 additions & 2 deletions src/v1/Bank/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
namespace WebMaster\PagHiper\v1\Bank;

use WebMaster\PagHiper\Core\Request\Request;
use WebMaster\PagHiper\Core\Exceptions\PagHiperException;
use WebMaster\PagHiper\Core\Interfaces\BankAccountsInterface;

class Accounts implements BankAccountsInterface
{
protected $accountsUri = '/bank_accounts/list/';

/**
* Lista as contas bancárias para saque via API.
* Retrieves a list of bank accounts.
*
* @return void
*/
public function accounts()
{
$bankAccounts = new Request($this->accountsUri);

return $bankAccounts->getResponse()['bank_account_list_request'];
$response = $bankAccounts->getResponse()['bank_account_list_request'];

if ($response['result'] === 'reject') {
throw new PagHiperException($response['response_message'], $response['http_code']);
}

return $response;
}
}
36 changes: 20 additions & 16 deletions src/v1/Payment/Billet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

use GuzzleHttp\Client;
use WebMaster\PagHiper\Core\Request\Request;
use WebMaster\PagHiper\Core\Interfaces\BoletoInterface;
use WebMaster\PagHiper\Core\Interfaces\BilletInterface;
use WebMaster\PagHiper\Core\Configuration\Configuration;
use WebMaster\PagHiper\Core\Exceptions\PagHiperException;

class Billet implements BoletoInterface
class Billet implements BilletInterface
{
protected $createUri = '/transaction/create/';
protected $cancelUri = '/transaction/cancel/';

/**
* Realiza a emissão do boleto
*
* @param array $data Dados para geração do boleto. Os dados necessários para gerar o boleto
* podem ser encontrados em: https://dev.paghiper.com/reference#gerar-boleto
* @return void
*/
* Create a new billet.
*
* @param array $data Billet data. Full list of all available data can be found at: https://dev.paghiper.com/reference#gerar-boleto
* @return void
*/
public function create(array $data)
{
$request = new Request($this->createUri, $data);
Expand All @@ -34,21 +33,26 @@ public function create(array $data)
}

/**
* Efetua o cancelamento boleto.
* Cancels a billet.
*
* @param array $data Dados para cancelamento do boleto. Os dados para cancelar o boleto podem ser encontrados em:
* https://dev.paghiper.com/reference#boleto
* @param string $transactionId Transaction ID to cancel.
* @return boolean
*/
public function cancel(array $data)
public function cancel(string $transactionId)
{
// Define o status da transação com 'canceled'
$data = array_merge([
$data = [
'transaction_id' => $transactionId,
'status' => 'canceled'
], $data);
];

$request = new Request($this->cancelUri, $data);

return $request->getResponse()['cancellation_request'];
$response = $request->getResponse()['cancellation_request'];

if ($response['result'] === 'reject') {
throw new PagHiperException($response['response_message'], $response['http_code']);
}

return $response;
}
}
21 changes: 18 additions & 3 deletions src/v1/Payment/Notification/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@
namespace WebMaster\PagHiper\v1\Payment\Notification;

use WebMaster\PagHiper\Core\Request\Request;
use WebMaster\PagHiper\Core\Exceptions\PagHiperException;
use WebMaster\PagHiper\Core\Interfaces\NotificationInterface;

class Notification implements NotificationInterface
{
protected $notificationUri = '/transaction/notification/';

public function response(array $data)
/**
* Get notification's response.
*
* @return void
*/
public function response(string $notificationId = '', string $transactionId = '')
{
$notification = new Request($this->notificationUri, $data);
$notification = new Request($this->notificationUri, [
'notification_id' => $notificationId,
'transaction_id' => $transactionId
]);

return $notification->getResponse()['status_request'];
$response = $notification->getResponse()['status_request'];

if ($response['result'] === 'reject') {
throw new PagHiperException($response['response_message'], $response['http_code']);
}

return $response;
}
}

0 comments on commit de3b120

Please sign in to comment.