Skip to content

Commit

Permalink
Merge pull request #5 from ProfessorJamesBach/main
Browse files Browse the repository at this point in the history
Feature: Added try/catch blocks in set of token
  • Loading branch information
Interstation authored Aug 24, 2021
2 parents 30e3536 + bcefbeb commit 480618d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
Empty file removed 1.0
Empty file.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Controlador de Gera\u0000\u0000o de Boletos da Plataforma PagHiper",
"type": "library",
"require":{
"php": ">=7.4"
"php": ">=7.4",
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
Expand Down
62 changes: 33 additions & 29 deletions src/PagHiper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class PagHiper
private Bool $perDayInterest = false;
private String $latePaymentFine = '';
private String $typeBankSlip = 'boletoA4';
private array $items;
private array $items = [];
private String $notificationUrl = 'http://www.seusite.com/api/notify/paghiper';
private String $token = "{}";
private String $orderId;
private ?String $orderId;
private String $notificationId;
private String $transactionId;

Expand Down Expand Up @@ -131,33 +131,37 @@ public function gerarBoleto()

public function setToken()
{
$json = [
"apiKey" => $this::API_KEY,
"order_id" => $this->getOrderId(),
"payer_email" => $this->getPayerEmail(),
"payer_name" => $this->getPayerName(),
"payer_cpf_cnpj" => $this->getPayerCpfCnpj(),
"payer_phone" => $this->getPayerName(),
"payer_street" => $this->getPayerStreet(),
"payer_number" => $this->getPayerNumber(),
"payer_complement" => $this->getPayerComplement(),
"payer_district" => $this->getPayerDistrict(),
"payer_city" => $this->getPayerCity(),
"payer_state" => $this->getPayerState(),
"payer_zip_code" => $this->getPayerZipCode(),
"notification_url" => $this->getNotificationUrl(),
"discount_cents" => $this->getDiscountCents(),
"shipping_price_cents" => $this->getShippingPriceCents(),
"shipping_methods" => $this->getShippingMethods(),
"fixed_description" => $this->getFixedDescription(),
"type_bank_slip" => $this->getTypeBankSlip(),
"days_due_date" => $this->getDaysDueDate(),
"late_payment_fine" => $this->getLatePaymentFine(),
"per_day_interest" => $this->getPerDayInterest(),
"items" => $this->getItems()
];
$this->token = json_encode($json, JSON_UNESCAPED_SLASHES);
return $this;
try {
$json = [
"apiKey" => $this::API_KEY,
"order_id" => $this->getOrderId(),
"payer_email" => $this->getPayerEmail(),
"payer_name" => $this->getPayerName(),
"payer_cpf_cnpj" => $this->getPayerCpfCnpj(),
"payer_phone" => $this->getPayerName(),
"payer_street" => $this->getPayerStreet(),
"payer_number" => $this->getPayerNumber(),
"payer_complement" => $this->getPayerComplement(),
"payer_district" => $this->getPayerDistrict(),
"payer_city" => $this->getPayerCity(),
"payer_state" => $this->getPayerState(),
"payer_zip_code" => $this->getPayerZipCode(),
"notification_url" => $this->getNotificationUrl(),
"discount_cents" => $this->getDiscountCents(),
"shipping_price_cents" => $this->getShippingPriceCents(),
"shipping_methods" => $this->getShippingMethods(),
"fixed_description" => $this->getFixedDescription(),
"type_bank_slip" => $this->getTypeBankSlip(),
"days_due_date" => $this->getDaysDueDate(),
"late_payment_fine" => $this->getLatePaymentFine(),
"per_day_interest" => $this->getPerDayInterest(),
"items" => $this->getItems()
];
$this->token = json_encode($json, JSON_UNESCAPED_SLASHES);
return $this;
} catch (\Exception $exception) {
throw new \Error($exception->getMessage());
}
}


Expand Down
2 changes: 0 additions & 2 deletions tests/PagHiperTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php namespace Interstation\PagHiper\Tests;

require \dirname(__DIR__).'/vendor/autoload.php';

class PagHiperTest extends \PHPUnit\Framework\TestCase {

protected function assertPreConditions() : void{
Expand Down

0 comments on commit 480618d

Please sign in to comment.