From bcefbeb5cfa2fde7395de21c4d8cadc776f7bb54 Mon Sep 17 00:00:00 2001 From: Hugo Henrique Date: Tue, 24 Aug 2021 09:04:47 -0300 Subject: [PATCH] Feature: Added try/catch blocks in set of token --- 1.0 | 0 composer.json | 3 +- src/PagHiper.php | 62 ++++++++++++++++++++++-------------------- tests/PagHiperTest.php | 2 -- 4 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 1.0 diff --git a/1.0 b/1.0 deleted file mode 100644 index e69de29..0000000 diff --git a/composer.json b/composer.json index cf6af2d..f1cc780 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/PagHiper.php b/src/PagHiper.php index 857c42e..1c378f3 100644 --- a/src/PagHiper.php +++ b/src/PagHiper.php @@ -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; @@ -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()); + } } diff --git a/tests/PagHiperTest.php b/tests/PagHiperTest.php index 8a13dcb..efdf883 100644 --- a/tests/PagHiperTest.php +++ b/tests/PagHiperTest.php @@ -1,7 +1,5 @@