Skip to content

Commit 46e2e5c

Browse files
Merge pull request #3 from edson-nascimento/feature/add-suporte-php8
feat: atualizar projeto para PHP8
2 parents 35ac19d + 356e26a commit 46e2e5c

21 files changed

+248
-63
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: 'github-actions'
4+
directory: '/'
5+
commit-message:
6+
# Prefix all commit messages with "chore: "
7+
prefix: 'chore'
8+
schedule:
9+
interval: 'monthly'
10+
open-pull-requests-limit: 10

.github/workflows/pull_request.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Run lint and tests
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- reopened
7+
- ready_for_review
8+
workflow_dispatch:
9+
10+
env:
11+
PHP_VERSION: 8.3
12+
PHP_EXTENSIONS: mbstring
13+
PHP_TOOLS: composer:v2, phpunit:11
14+
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
jobs:
20+
run-tests:
21+
if: ${{ !github.event.pull_request.draft }}
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Install PHP ${{ env.PHP_VERSION }}
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
coverage: none
30+
php-version: ${{ env.PHP_VERSION }}
31+
extensions: ${{ env.PHP_EXTENSIONS }}
32+
tools: ${{ env.PHP_TOOLS }}
33+
34+
- name: Get Composer Cache Directory
35+
id: composer-cache
36+
run: |
37+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
38+
- uses: actions/cache@v4
39+
with:
40+
path: ${{ steps.composer-cache.outputs.dir }}
41+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
42+
restore-keys: |
43+
${{ runner.os }}-composer-
44+
45+
- name: Install dependencies
46+
run: composer update --no-interaction --no-progress
47+
48+
- name: Static analysis
49+
run: composer phpstan
50+
51+
- name: Run unit tests
52+
run: composer test:unit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor
55
/.project
66
/.buildpath
77
/.vscode
8+
/cache

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SDK API-3.0 PHP
99
* [x] Com autorização na primeira recorrência.
1010
* [x] Com autorização a partir da primeira recorrência.
1111
* [x] Pagamentos por cartão de débito.
12+
* [x] Pagamentos por pix.
1213
* [x] Pagamentos por boleto.
1314
* [x] Pagamentos por transferência eletrônica.
1415
* [x] Cancelamento de autorização.
@@ -21,28 +22,33 @@ Por envolver a interface de usuário da aplicação, o SDK funciona apenas como
2122

2223
## Dependências
2324

24-
* PHP >= 5.6
25+
* PHP >= 8.3
2526

2627
## Instalando o SDK
2728

2829
Se já possui um arquivo `composer.json`, basta adicionar a seguinte dependência ao seu projeto:
2930

3031
```json
3132
"require": {
32-
"developercielo/api-3.0-php": "^1.0"
33+
"developercielo/api-3.0-php": "^2.0.0"
3334
}
3435
```
3536

36-
Com a dependência adicionada ao `composer.json`, basta executar:
37+
Adicionar o `repositories` no `composer.json`
3738

38-
```
39-
composer install
39+
```json
40+
"repositories": [
41+
{
42+
"type": "vcs",
43+
"url": "https://github.com/edson-nascimento/API-3.0-PHP"
44+
}
45+
],
4046
```
4147

42-
Alternativamente, você pode executar diretamente em seu terminal:
48+
Com a dependência adicionada ao `composer.json`, basta executar:
4349

4450
```
45-
composer require "developercielo/api-3.0-php"
51+
composer update
4652
```
4753

4854
## Produtos e Bandeiras suportadas e suas constantes
@@ -424,6 +430,23 @@ try {
424430
}
425431
```
426432

433+
### Criando uma venda com PIX
434+
435+
```php
436+
<?php
437+
// ...
438+
$sale = new Sale('123');
439+
440+
$customer = $sale->customer('Fulano de Tal');
441+
442+
$payment = $sale->payment(15700);
443+
$payment->pix();
444+
$payment->setCapture(true);
445+
446+
$sale = (new CieloEcommerce($merchant, $environment))->createSale($sale);
447+
// ...
448+
```
449+
427450
### Tokenizando um cartão
428451

429452
```php

composer.json

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
{
2-
"autoload": {
3-
"psr-0": {
4-
"Cielo": "src"
5-
}
6-
},
72
"name": "developercielo/api-3.0-php",
83
"description": "Integração com a API 3.0 da Cielo",
9-
"license": "MIT",
104
"type": "library",
115
"require": {
12-
"php": ">=5.6",
6+
"php": "^8.2",
137
"ext-curl": "*",
148
"ext-json": "*",
15-
"psr/log":"^1.1"
9+
"psr/log": "^1.1"
10+
},
11+
"require-dev": {
12+
"phpunit/phpunit": "^11.1.2",
13+
"phpstan/phpstan": "^1.10.67",
14+
"kint-php/kint": "^5.1.0"
15+
},
16+
"autoload": {
17+
"psr-0": {
18+
"Cielo": "src"
19+
}
20+
},
21+
"autoload-dev": {
22+
"psr-4": {
23+
"TestApp\\": "tests/"
24+
}
1625
},
1726
"suggest": {
1827
"monolog/monolog": "Allows more advanced logging of the application flow"
1928
},
20-
"homepage": "https://github.com/DeveloperCielo/API-3.0-PHP"
21-
}
29+
"homepage": "https://github.com/DeveloperCielo/API-3.0-PHP",
30+
"scripts": {
31+
"phpstan": "phpstan analyse -c phpstan.neon",
32+
"phpunit": "phpunit --configuration phpunit.xml --testdox --exclude-group payment",
33+
"test": [
34+
"@phpstan",
35+
"@phpunit"
36+
],
37+
"test:unit": "phpunit tests/Unit --configuration phpunit.xml --testdox",
38+
"test:e2e": "phpunit tests/E2E --configuration phpunit.xml --testdox"
39+
},
40+
"license": "MIT",
41+
"minimum-stability": "stable"
42+
}

phpstan.neon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
parameters:
2+
level: 5
3+
phpVersion: 80300
4+
checkFunctionNameCase: true
5+
checkInternalClassCaseSensitivity: true
6+
reportMaybesInPropertyPhpDocTypes: true
7+
checkExplicitMixedMissingReturn: true
8+
reportMaybesInMethodSignatures: true
9+
reportStaticMethodSignatures: true
10+
checkTooWideReturnTypesInProtectedAndPublicMethods: true
11+
checkDynamicProperties: true
12+
reportAlwaysTrueInLastCondition: true
13+
paths:
14+
- ./
15+
excludePaths:
16+
- ./vendor/*
17+
ignoreErrors:

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
backupGlobals="false"
8+
cacheResult="false"
9+
cacheDirectory="cache/phpunit"
10+
backupStaticProperties="false"
11+
displayDetailsOnIncompleteTests="true"
12+
displayDetailsOnSkippedTests="true"
13+
displayDetailsOnTestsThatTriggerDeprecations="true"
14+
displayDetailsOnTestsThatTriggerErrors="true"
15+
displayDetailsOnTestsThatTriggerNotices="true"
16+
displayDetailsOnTestsThatTriggerWarnings="true"
17+
>
18+
<testsuites>
19+
<testsuite name="Tests">
20+
<directory suffix="Test.php">tests</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

src/Cielo/API30/Ecommerce/Address.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ class Address implements CieloSerializable
2626

2727
private $district;
2828

29-
/**
30-
* @return array
31-
*/
32-
public function jsonSerialize()
29+
public function jsonSerialize(): mixed
3330
{
3431
return get_object_vars($this);
3532
}

src/Cielo/API30/Ecommerce/CieloEcommerce.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class CieloEcommerce
2727
* requests will be send
2828
*
2929
* @param Merchant $merchant
30-
* The merchant credentials
31-
* @param Environment environment
32-
* The environment: {@link Environment::production()} or
33-
* {@link Environment::sandbox()}
30+
* @param Environment $environment
3431
* @param LoggerInterface|null $logger
3532
*/
3633
public function __construct(Merchant $merchant, Environment $environment = null, LoggerInterface $logger = null)
@@ -117,7 +114,7 @@ public function getRecurrentPayment($recurrentPaymentId)
117114
* @param integer $amount
118115
* Order value in cents
119116
*
120-
* @return Sale The Sale with authorization, tid, etc. returned by Cielo.
117+
* @return \Cielo\API30\Ecommerce\Payment
121118
*
122119
* @throws \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong.
123120
*

src/Cielo/API30/Ecommerce/CieloSerializable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface CieloSerializable extends \JsonSerializable
1212
/**
1313
* @param \stdClass $data
1414
*
15-
* @return mixed
15+
* @return void
1616
*/
1717
public function populate(\stdClass $data);
1818
}

src/Cielo/API30/Ecommerce/CreditCard.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ public function populate(\stdClass $data)
111111
$this->customerName = isset($data->CustomerName) ? $data->CustomerName : null;
112112
}
113113

114-
/**
115-
* @return array
116-
*/
117-
public function jsonSerialize()
114+
public function jsonSerialize(): mixed
118115
{
119116
return get_object_vars($this);
120117
}

src/Cielo/API30/Ecommerce/Customer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public function __construct($name = null)
3434
$this->setName($name);
3535
}
3636

37-
/**
38-
* @return array
39-
*/
40-
public function jsonSerialize()
37+
public function jsonSerialize(): mixed
4138
{
4239
return get_object_vars($this);
4340
}

src/Cielo/API30/Ecommerce/Payment.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ public function populate(\stdClass $data)
208208
$this->qrCodeString = isset($data->QrCodeString) ? $data->QrCodeString : null;
209209
}
210210

211-
/**
212-
* @return array
213-
*/
214-
public function jsonSerialize()
211+
public function jsonSerialize(): mixed
215212
{
216213
return get_object_vars($this);
217214
}
@@ -284,6 +281,7 @@ public function recurrentPayment($authorizeNow = true)
284281
public function pix()
285282
{
286283
$this->setType(self::PAYMENTTYPE_PIX);
284+
$this->setCapture(true);
287285

288286
return $this;
289287
}

src/Cielo/API30/Ecommerce/RecurrentPayment.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ public function populate(\stdClass $data)
9797
$this->status = isset($data->Status) ? $data->Status : null;
9898
}
9999

100-
/**
101-
* @return array
102-
*/
103-
public function jsonSerialize()
100+
public function jsonSerialize(): mixed
104101
{
105102
return get_object_vars($this);
106103
}

src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(Merchant $merchant, Environment $environment, Logger
3434
/**
3535
* @param $sale
3636
*
37-
* @return null
37+
* @return Sale
3838
* @throws \Cielo\API30\Ecommerce\Request\CieloRequestException
3939
* @throws \RuntimeException
4040
*/

src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(Merchant $merchant, Environment $environment, Logger
3434
/**
3535
* @param $recurrentPaymentId
3636
*
37-
* @return null
37+
* @return RecurrentPayment
3838
* @throws \Cielo\API30\Ecommerce\Request\CieloRequestException
3939
* @throws \RuntimeException
4040
*/

src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(Merchant $merchant, Environment $environment, Logger
3434
/**
3535
* @param $paymentId
3636
*
37-
* @return null
37+
* @return Sale
3838
* @throws \Cielo\API30\Ecommerce\Request\CieloRequestException
3939
* @throws \RuntimeException
4040
*/

0 commit comments

Comments
 (0)