Skip to content

Commit

Permalink
refactor to use php7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigopedra committed Sep 5, 2020
1 parent f7d062e commit 17c3c2f
Show file tree
Hide file tree
Showing 66 changed files with 1,784 additions and 2,949 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
.DS_Store
.swp
composer.lock
phpunit.xml
build
vendor
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Baseado no repositório [https://github.com/lucasmro/ClearSale](https://github.c

## Requisitos

PHP 5.5+
PHP 7.1+

Extensões PHP

Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"RodrigoPedra\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"RodrigoPedra\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
}
Expand Down
116 changes: 58 additions & 58 deletions examples/airline-ticket-order-example.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
<?php

date_default_timezone_set( 'America/Sao_Paulo' );
date_default_timezone_set('America/Sao_Paulo');

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/logger.php';

use RodrigoPedra\ClearSaleID\Service\Analysis;
use RodrigoPedra\ClearSaleID\Service\Connector;
use RodrigoPedra\ClearSaleID\Environment\Sandbox;
use RodrigoPedra\ClearSaleID\Service\Integration;
use RodrigoPedra\ClearSaleID\Entity\Request\Item;
use RodrigoPedra\ClearSaleID\Entity\Request\Order;
use RodrigoPedra\ClearSaleID\Entity\Request\Phone;
use RodrigoPedra\ClearSaleID\Entity\Request\AbstractCustomer;
use RodrigoPedra\ClearSaleID\Entity\Request\Address;
use RodrigoPedra\ClearSaleID\Entity\Request\Payment;
use RodrigoPedra\ClearSaleID\Entity\Request\Passenger;
use RodrigoPedra\ClearSaleID\Entity\Request\Connection;
use RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint;
use RodrigoPedra\ClearSaleID\Entity\Request\AbstractCustomer;
use RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData;
use RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData;
use RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint;
use RodrigoPedra\ClearSaleID\Entity\Request\Item;
use RodrigoPedra\ClearSaleID\Entity\Request\Order;
use RodrigoPedra\ClearSaleID\Entity\Request\Passenger;
use RodrigoPedra\ClearSaleID\Entity\Request\Payment;
use RodrigoPedra\ClearSaleID\Entity\Request\Phone;
use RodrigoPedra\ClearSaleID\Environment\Sandbox;
use RodrigoPedra\ClearSaleID\Service\Analysis;
use RodrigoPedra\ClearSaleID\Service\Connector;
use RodrigoPedra\ClearSaleID\Service\Integration;

try {
// Dados da Integração com a ClearSale
$entityCode = '<CLEARSALE_ENTITY_CODE>';

// ambiente
$environment = new Sandbox( $entityCode, new ExampleLogger );
$environment->setDebug( true );
$environment = new Sandbox($entityCode, new ExampleLogger());
$environment->setDebug(true);

// serviços
$connector = new Connector( $environment );
$integration = new Integration( $connector );
$clearSale = new Analysis( $integration );
$connector = new Connector($environment);
$integration = new Integration($connector);
$clearSale = new Analysis($integration);

// Dados do Pedido
$fingerPrint = new FingerPrint( createSessionId() );
$orderId = createOrderId();
$date = new \DateTime();
$email = '[email protected]';
$totalItems = 10.0;
$totalOrder = 17.5;
$fingerPrint = new FingerPrint(createSessionId());
$orderId = createOrderId();
$date = new \DateTime();
$email = '[email protected]';
$totalItems = 10.0;
$totalOrder = 17.5;
$quantityInstallments = 1;
$ip = '127.0.0.1';
$origin = 'WEB';
$customerBillingData = createCustomerBillingData();
$ip = '127.0.0.1';
$origin = 'WEB';
$customerBillingData = createCustomerBillingData();
$customerShippingData = createCustomerShippingData();
$item = Item::create( 1, 'Adaptador USB', 10.0, 1 );
$payment = Payment::create( Payment::BOLETO_BANCARIO, new \DateTime(), 17.5 );
$item = Item::create(1, 'Adaptador USB', 10.0, 1);
$payment = Payment::create(Payment::BOLETO_BANCARIO, new \DateTime(), 17.5);

$passenger = Passenger::create( 'Fulano da Silva', Passenger::DOCUMENT_TYPE_CPF, '63165236372' );
$passenger = Passenger::create('Fulano da Silva', Passenger::DOCUMENT_TYPE_CPF, '63165236372');
$connection = createConnection();

// Criar Pedido
Expand All @@ -72,7 +72,7 @@
);

// Enviar pedido para análise
$response = $clearSale->analysis( $order );
$response = $clearSale->analysis($order);

// Resultado da análise
switch ($response) {
Expand All @@ -91,10 +91,10 @@
echo 'Erro' . PHP_EOL;
}

if ($clearSale->updateOrderStatus( $orderId, Analysis::UPDATE_ORDER_STATUS_ORDER_APPROVED ) === true) {
if ($clearSale->updateOrderStatus($orderId, Analysis::UPDATE_ORDER_STATUS_ORDER_APPROVED) === true) {
echo 'Status do pedido atualizado';
}
} catch ( Exception $e ) {
} catch (Exception $e) {
echo 'ERRO', PHP_EOL, PHP_EOL;

// Erro genérico da análise
Expand All @@ -103,22 +103,22 @@

function createOrderId()
{
return sprintf( 'TEST-%s', createSessionId() );
return \sprintf('TEST-%s', createSessionId());
}

function createSessionId()
{
return md5( uniqid( rand(), true ) );
return \md5(\uniqid(\rand(), true));
}

function createCustomerBillingData()
{
$id = '1';
$id = '1';
$legalDocument = '63165236372';
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create( Phone::COMERCIAL, '11', '37288788' );
$birthDate = new \DateTime( '1980-01-01' );
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create(Phone::COMERCIAL, '11', '37288788');
$birthDate = new \DateTime('1980-01-01');

return CustomerBillingData::create(
$id,
Expand All @@ -133,11 +133,11 @@ function createCustomerBillingData()

function createCustomerShippingData()
{
$id = '1';
$id = '1';
$legalDocument = '63165236372';
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create( Phone::COMERCIAL, '11', '37288788' );
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create(Phone::COMERCIAL, '11', '37288788');

return CustomerShippingData::create(
$id,
Expand All @@ -151,27 +151,27 @@ function createCustomerShippingData()

function createAddress()
{
$street = 'Rua José de Oliveira Coutinho';
$number = 151;
$county = 'Barra Funda';
$street = 'Rua José de Oliveira Coutinho';
$number = 151;
$county = 'Barra Funda';
$country = 'Brasil';
$city = 'São Paulo';
$state = 'SP';
$zip = '01144020';
$city = 'São Paulo';
$state = 'SP';
$zip = '01144020';

return Address::create( $street, $number, $county, $country, $city, $state, $zip );
return Address::create($street, $number, $county, $country, $city, $state, $zip);
}

function createConnection()
{
$company = 'TAM';
$flightNumber = '3356';
$flightDate = new \DateTime( '2015-09-14 11:55:00' );
$class = 'Econômica';
$from = 'GRU';
$to = 'JPA';
$departureDate = new \DateTime( '2015-09-14 11:55:00' );
$arrivalDate = new \DateTime( '2015-09-14 15:33:00' );
$company = 'TAM';
$flightNumber = '3356';
$flightDate = new \DateTime('2015-09-14 11:55:00');
$class = 'Econômica';
$from = 'GRU';
$to = 'JPA';
$departureDate = new \DateTime('2015-09-14 11:55:00');
$arrivalDate = new \DateTime('2015-09-14 15:33:00');

return Connection::create(
$company,
Expand Down
96 changes: 48 additions & 48 deletions examples/ecommerce-order-example.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
<?php

date_default_timezone_set( 'America/Sao_Paulo' );
date_default_timezone_set('America/Sao_Paulo');

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/logger.php';

use RodrigoPedra\ClearSaleID\Service\Analysis;
use RodrigoPedra\ClearSaleID\Service\Connector;
use RodrigoPedra\ClearSaleID\Environment\Sandbox;
use RodrigoPedra\ClearSaleID\Service\Integration;
use RodrigoPedra\ClearSaleID\Entity\Request\Item;
use RodrigoPedra\ClearSaleID\Entity\Request\Order;
use RodrigoPedra\ClearSaleID\Entity\Request\Phone;
use RodrigoPedra\ClearSaleID\Entity\Request\Address;
use RodrigoPedra\ClearSaleID\Entity\Request\Payment;
use RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint;
use RodrigoPedra\ClearSaleID\Entity\Request\AbstractCustomer;
use RodrigoPedra\ClearSaleID\Entity\Request\Address;
use RodrigoPedra\ClearSaleID\Entity\Request\CustomerBillingData;
use RodrigoPedra\ClearSaleID\Entity\Request\CustomerShippingData;
use RodrigoPedra\ClearSaleID\Entity\Request\FingerPrint;
use RodrigoPedra\ClearSaleID\Entity\Request\Item;
use RodrigoPedra\ClearSaleID\Entity\Request\Order;
use RodrigoPedra\ClearSaleID\Entity\Request\Payment;
use RodrigoPedra\ClearSaleID\Entity\Request\Phone;
use RodrigoPedra\ClearSaleID\Environment\Sandbox;
use RodrigoPedra\ClearSaleID\Service\Analysis;
use RodrigoPedra\ClearSaleID\Service\Connector;
use RodrigoPedra\ClearSaleID\Service\Integration;

try {
// Dados da Integração com a ClearSale
$entityCode = '<CLEARSALE_ENTITY_CODE>';

// ambiente
$environment = new Sandbox( $entityCode, new ExampleLogger );
$environment->setDebug( true );
$environment = new Sandbox($entityCode, new ExampleLogger());
$environment->setDebug(true);

// serviços
$connector = new Connector( $environment );
$integration = new Integration( $connector );
$clearSale = new Analysis( $integration );
$connector = new Connector($environment);
$integration = new Integration($connector);
$clearSale = new Analysis($integration);

// Dados do Pedido
$fingerPrint = new FingerPrint( createSessionId() );
$orderId = createOrderId();
$date = new \DateTime();
$email = '[email protected]';
$totalItems = 10.0;
$totalOrder = 17.5;
$fingerPrint = new FingerPrint(createSessionId());
$orderId = createOrderId();
$date = new \DateTime();
$email = '[email protected]';
$totalItems = 10.0;
$totalOrder = 17.5;
$quantityInstallments = 1;
$ip = '127.0.0.1';
$origin = 'WEB';
$customerBillingData = createCustomerBillingData();
$ip = '127.0.0.1';
$origin = 'WEB';
$customerBillingData = createCustomerBillingData();
$customerShippingData = createCustomerShippingData();
$item = Item::create( 1, 'Adaptador USB', 10.0, 1 );
$payment = Payment::create( Payment::BOLETO_BANCARIO, new \DateTime(), 17.5 );
$item = Item::create(1, 'Adaptador USB', 10.0, 1);
$payment = Payment::create(Payment::BOLETO_BANCARIO, new \DateTime(), 17.5);

// Criar Pedido
$order = Order::createEcommerceOrder(
Expand All @@ -64,7 +64,7 @@
$item
);

$response = $clearSale->analysis( $order );
$response = $clearSale->analysis($order);

// Resultado da análise
switch ($response) {
Expand All @@ -83,10 +83,10 @@
echo 'Erro' . PHP_EOL;
}

if ($clearSale->updateOrderStatus( $orderId, Analysis::UPDATE_ORDER_STATUS_ORDER_APPROVED ) === true) {
if ($clearSale->updateOrderStatus($orderId, Analysis::UPDATE_ORDER_STATUS_ORDER_APPROVED) === true) {
echo 'Status do pedido atualizado';
}
} catch ( Exception $e ) {
} catch (Exception $e) {
echo 'ERRO', PHP_EOL, PHP_EOL;

// Erro genérico da análise
Expand All @@ -95,22 +95,22 @@

function createOrderId()
{
return sprintf( 'TEST-%s', createSessionId() );
return \sprintf('TEST-%s', createSessionId());
}

function createSessionId()
{
return md5( uniqid( rand(), true ) );
return \md5(\uniqid(\rand(), true));
}

function createCustomerBillingData()
{
$id = '1';
$id = '1';
$legalDocument = '63165236372';
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create( Phone::COMERCIAL, '11', '37288788' );
$birthDate = new \DateTime( '1980-01-01' );
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create(Phone::COMERCIAL, '11', '37288788');
$birthDate = new \DateTime('1980-01-01');

return CustomerBillingData::create(
$id,
Expand All @@ -125,11 +125,11 @@ function createCustomerBillingData()

function createCustomerShippingData()
{
$id = '1';
$id = '1';
$legalDocument = '63165236372';
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create( Phone::COMERCIAL, '11', '37288788' );
$name = 'Fulano da Silva';
$address = createAddress();
$phone = Phone::create(Phone::COMERCIAL, '11', '37288788');

return CustomerShippingData::create(
$id,
Expand All @@ -143,15 +143,15 @@ function createCustomerShippingData()

function createAddress()
{
$street = 'Rua José de Oliveira Coutinho';
$number = 151;
$county = 'Barra Funda';
$street = 'Rua José de Oliveira Coutinho';
$number = 151;
$county = 'Barra Funda';
$country = 'Brasil';
$city = 'São Paulo';
$state = 'SP';
$zip = '01144020';
$city = 'São Paulo';
$state = 'SP';
$zip = '01144020';

return Address::create( $street, $number, $county, $country, $city, $state, $zip );
return Address::create($street, $number, $county, $country, $city, $state, $zip);
}

exit;
Loading

0 comments on commit 17c3c2f

Please sign in to comment.