Skip to content

Commit

Permalink
Merge pull request #7 from edson-nascimento/feature/drop-support-php56
Browse files Browse the repository at this point in the history
Feature drop support php56
  • Loading branch information
edson-nascimento authored Jul 13, 2022
2 parents cc0f300 + 692a34b commit 50af7c4
Show file tree
Hide file tree
Showing 25 changed files with 624 additions and 120 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run tests
on:
pull_request:
types:
- opened
- reopened
- ready_for_review

env:
PHP_EXTENSIONS: mbstring
PHP_TOOLS: composer:v2, phpunit:9.5

jobs:
run-tests:
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest

strategy:
matrix:
php-version:
- 7.4

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}
extensions: ${{ env.PHP_EXTENSIONS }}
tools: ${{ env.PHP_TOOLS }}

- name: Determine composer cache directory
id: determine-composer-cache-directory
run: echo "::set-output name=directory::$(composer config cache-dir)"

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ steps.determine-composer-cache-directory.outputs.directory }}
key: php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }}
restore-keys: php-${{ matrix.php-version }}-composer-

# TODO test direct env php with github actios
- name: Add config/env.test.php
run: echo '${{ secrets.ENV_PHP }}' > $GITHUB_WORKSPACE/config/env.test.php

- name: Install dependencies
run: composer update --no-interaction --no-progress --ignore-platform-reqs

- name: Static analysis
run: composer phpstan

- name: PHPUnit tests
run: composer phpunit

- name: Remove temp files
run: rm -f $GITHUB_WORKSPACE/auth.json, $GITHUB_WORKSPACE/config/env.test.php
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
/.project
.buildpath
composer.lock
/build
/vendor
/.idea
/tests/tmp
/tests/.phpunit.result.cache
config/env.test.php
21 changes: 20 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ Todos os passos e processos referentes à integração com o sistema de captura
Documentação oficial
* https://developers.getnet.com.br/api

#### Pré-requisitos

- PHP `>=7.4`

#### Composer

add composer.json
```
"edson-nascimento/getnet-php": "^1.0"
"edson-nascimento/getnet-php": "^2.0"
```
ou execute
```
Expand Down Expand Up @@ -270,6 +274,7 @@ $response->getStatus();
|DENIED|Negada|
|AUTHORIZED|Autorizada pelo emissor|
|CONFIRMED|Confirmada ou Capturada|
|WAITING|Aguardando pagamento pix|

### Cartões para testes

Expand Down Expand Up @@ -306,4 +311,18 @@ $response->getStatus();
|authorizeCancel|Cancela a transação|
|boleto|Gera boleto|

### Instalar e configurar ambiente para desenvolvimento/alterações

- Clone o repositório
- Instale as dependências rodando `composer install` na raiz do projeto
- Na pasta `config` crie um arquivo `config/env.test.php` baseado no `config/env.test.php.txt`
- Adicione suas credenciais do sandbox da getnet no `config/env.test.php`
- **Rodar testes**
- `composer test`
- `composer test:unit`
- `composer test:e2e`
- `composer phpstan`




70 changes: 46 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
{
"name": "edson-nascimento/getnet-php",
"description": "SDK php para integração com a API Getnet",
"minimum-stability": "stable",
"license": "MIT",
"type": "library",
"require": {
"php": ">=5.6.0"
},
"autoload": {
"psr-4": {
"Getnet\\": "src//Getnet"
}
},
"authors": [
{
"name": "Bruno Paz",
"email": "brunopaz@azpay.com.br"
"name":"edson-nascimento/getnet-php",
"description":"SDK php para integração com a API Getnet",
"minimum-stability":"stable",
"license":"MIT",
"type":"library",
"require":{
"php": ">=7.4"
},
{
"name": "Edson Nascimento",
"email": "edson27bn@gmail.com"
}
],
"homepage": "https://github.com/edson-nascimento/getnet-php"
}
"require-dev":{
"phpunit/phpunit":"^9",
"phpstan/phpstan":"^1.8.0",
"kint-php/kint":"^3.3",
"monolog/monolog":"*"
},
"autoload":{
"psr-4":{
"Getnet\\":"src//Getnet"
}
},
"autoload-dev":{
"psr-4":{
"Tests\\": "tests"
}
},
"scripts":{
"phpstan":"phpstan analyse -c phpstan.neon",
"phpunit":"phpunit --configuration phpunit.xml --testdox",
"test":[
"@phpstan",
"@phpunit"
],
"test:unit":"phpunit --configuration phpunit.xml --testdox --exclude e2e",
"test:e2e":"phpunit --configuration phpunit.xml --testdox --group e2e",
"test:coverage":"phpunit --configuration phpunit.xml --coverage-clover build/logs/clover.xml --coverage-html build/coverage"
},
"authors":[
{
"name":"Bruno Paz",
"email":"brunopaz@azpay.com.br"
},
{
"name":"Edson Nascimento",
"email":"edson27bn@gmail.com"
}
],
"homepage":"https://github.com/edson-nascimento/getnet-php"
}
24 changes: 24 additions & 0 deletions config/bootstrap.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
use Getnet\API\Getnet;
use Getnet\API\Environment;

$ROOTDIR = dirname(__DIR__);

require_once $ROOTDIR . '/vendor/autoload.php';

// for local development copy config/env.test.php.txt to config/env.test.php and add your credentials
require_once $ROOTDIR . '/config/env.test.php';

/**
*
* @return Getnet
* @throws Exception
*/
function getnetServiceTest()
{
$getnet = new Getnet(getenv('GETNET_CLIENT_ID'), getenv('GETNET_CLIENT_SECRET'), Environment::sandbox());

$getnet->setSellerId(getenv('GETNET_SELLER_ID'));

return $getnet;
}
8 changes: 8 additions & 0 deletions config/env.test.php.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
$client_id = "xxxx";
$seller_id = "xxxx";
$client_secret = "xxxx";

putenv("GETNET_CLIENT_ID=$client_id");
putenv("GETNET_SELLER_ID=$seller_id");
putenv("GETNET_CLIENT_SECRET=$client_secret");
19 changes: 3 additions & 16 deletions tests/Authorize.php → examples/Authorize.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
<?php
use Getnet\API\Getnet;
use Getnet\API\Transaction;
use Getnet\API\Environment;
use Getnet\API\Token;
use Getnet\API\Credit;
use Getnet\API\Customer;
use Getnet\API\Card;
use Getnet\API\Order;


session_start();
include "../vendor/autoload.php";


$client_id = "3a666a8c-6d97-4eb0-a62c-77e3758c3425";
$client_secret = "f52a2358-70e6-4baa-b77f-9f0eeb7c8706";
$seller_id = "c695b415-6f2e-4475-a221-3c005258a450";
$environment = Environment::sandbox();

//Opicional, passar chave se você quiser guardar o token do auth na sessão para não precisar buscar a cada trasação, só quando expira
$keySession = null;
require_once '../config/bootstrap.test.php';

//Autenticação da API
$getnet = new Getnet($client_id, $client_secret, $environment, $keySession);
$getnet = getnetServiceTest();

//Cria a transação
$transaction = new Transaction();
$transaction->setSellerId($seller_id);
$transaction->setSellerId($getnet->getSellerId());
$transaction->setCurrency("BRL");
$transaction->setAmount(27.50);

Expand Down
19 changes: 3 additions & 16 deletions tests/AuthorizePosterior.php → examples/AuthorizePosterior.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
<?php
use Getnet\API\Getnet;
use Getnet\API\Transaction;
use Getnet\API\Environment;
use Getnet\API\Token;
use Getnet\API\Credit;
use Getnet\API\Customer;
use Getnet\API\Card;
use Getnet\API\Order;


session_start();
include "../vendor/autoload.php";


$client_id = "3a666a8c-6d97-4eb0-a62c-77e3758c3425";
$client_secret = "f52a2358-70e6-4baa-b77f-9f0eeb7c8706";
$seller_id = "c695b415-6f2e-4475-a221-3c005258a450";
$environment = Environment::sandbox();

//Opicional, passar chave se você quiser guardar o token do auth na sessão para não precisar buscar a cada trasação, só quando expira
$keySession = null;
require_once '../config/bootstrap.test.php';

//Autenticação da API
$getnet = new Getnet($client_id, $client_secret, $environment, $keySession);
$getnet = getnetServiceTest();

//Cria a transação
$transaction = new Transaction();
$transaction->setSellerId($seller_id);
$transaction->setSellerId($getnet->getSellerId());
$transaction->setCurrency("BRL");
$transaction->setAmount(45.90);

Expand Down
17 changes: 3 additions & 14 deletions tests/Boleto.php → examples/Boleto.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
<?php
use Getnet\API\Getnet;
use Getnet\API\Transaction;
use Getnet\API\Environment;
use Getnet\API\Customer;
use Getnet\API\Boleto;
use Getnet\API\Order;


session_start();
include "../vendor/autoload.php";


$client_id = "3a666a8c-6d97-4eb0-a62c-77e3758c3425";
$client_secret = "f52a2358-70e6-4baa-b77f-9f0eeb7c8706";
$seller_id = "c695b415-6f2e-4475-a221-3c005258a450";
$environment = Environment::sandbox();

//Opicional, passar chave se você quiser guardar o token do auth na sessão para não precisar buscar a cada trasação, só quando expira
$keySession = null;
require_once '../config/bootstrap.test.php';

//Autenticação da API
$getnet = new Getnet($client_id, $client_secret, $environment, $keySession);
$getnet = getnetServiceTest();

//Cria a transação
$transaction = new Transaction();
$transaction->setSellerId($seller_id);
$transaction->setSellerId($getnet->getSellerId());
$transaction->setCurrency("BRL");
$transaction->setAmount(75.50);

Expand Down
17 changes: 3 additions & 14 deletions tests/Debit.php → examples/Debit.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
<?php
use Getnet\API\Getnet;
use Getnet\API\Transaction;
use Getnet\API\Environment;
use Getnet\API\Token;
use Getnet\API\Customer;
use Getnet\API\Card;
use Getnet\API\Order;


session_start();
include "../vendor/autoload.php";


$client_id = "3a666a8c-6d97-4eb0-a62c-77e3758c3425";
$client_secret = "f52a2358-70e6-4baa-b77f-9f0eeb7c8706";
$seller_id = "c695b415-6f2e-4475-a221-3c005258a450";
$environment = Environment::sandbox();

//Opicional, passar chave se você quiser guardar o token do auth na sessão para não precisar buscar a cada trasação, só quando expira
$keySession = null;
require_once '../config/bootstrap.test.php';

//Autenticação da API
$getnet = new Getnet($client_id, $client_secret, $environment, $keySession);
$getnet = getnetServiceTest();

//Cria a transação
$transaction = new Transaction();
$transaction->setSellerId($seller_id);
$transaction->setSellerId($getnet->getSellerId());
$transaction->setCurrency("BRL");
$transaction->setAmount(33.33);

Expand Down
18 changes: 18 additions & 0 deletions examples/Pix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
use Getnet\API\PixTransaction;

require_once '../config/bootstrap.test.php';

//Autenticação da API
$getnet = getnetServiceTest();

//Cria a transação
$transaction = new PixTransaction(75.50);
$transaction->setCurrency("BRL");
$transaction->setOrderId('DEV-1608748980');
$transaction->setCustomerId('12345');


$response = $getnet->pix($transaction);

var_dump($response);
Loading

0 comments on commit 50af7c4

Please sign in to comment.