Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
commit-message:
# Prefix all commit messages with "chore: "
prefix: 'chore'
schedule:
interval: 'monthly'
open-pull-requests-limit: 10
52 changes: 52 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Run lint and tests
on:
pull_request:
types:
- opened
- reopened
- ready_for_review
workflow_dispatch:

env:
PHP_VERSION: 8.3
PHP_EXTENSIONS: mbstring
PHP_TOOLS: composer:v2, phpunit:11

permissions:
id-token: write
contents: read

jobs:
run-tests:
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: composer update --no-interaction --no-progress

- name: Static analysis
run: composer phpstan

- name: Run unit tests
run: composer test:unit
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
composer.lock
vendor
.idea
/.settings/
/.project
/.buildpath
/.vscode
/cache
37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SDK API-3.0 PHP
* [x] Com autorização na primeira recorrência.
* [x] Com autorização a partir da primeira recorrência.
* [x] Pagamentos por cartão de débito.
* [x] Pagamentos por pix.
* [x] Pagamentos por boleto.
* [x] Pagamentos por transferência eletrônica.
* [x] Cancelamento de autorização.
Expand All @@ -21,28 +22,33 @@ Por envolver a interface de usuário da aplicação, o SDK funciona apenas como

## Dependências

* PHP >= 5.6
* PHP >= 8.3

## Instalando o SDK

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

```json
"require": {
"developercielo/api-3.0-php": "^1.0"
"developercielo/api-3.0-php": "^2.0.0"
}
```

Com a dependência adicionada ao `composer.json`, basta executar:
Adicionar o `repositories` no `composer.json`

```
composer install
```json
"repositories": [
{
"type": "vcs",
"url": "https://github.com/edson-nascimento/API-3.0-PHP"
}
],
```

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

```
composer require "developercielo/api-3.0-php"
composer update
```

## Produtos e Bandeiras suportadas e suas constantes
Expand Down Expand Up @@ -424,6 +430,23 @@ try {
}
```

### Criando uma venda com PIX

```php
<?php
// ...
$sale = new Sale('123');

$customer = $sale->customer('Fulano de Tal');

$payment = $sale->payment(15700);
$payment->pix();
$payment->setCapture(true);

$sale = (new CieloEcommerce($merchant, $environment))->createSale($sale);
// ...
```

### Tokenizando um cartão

```php
Expand Down
41 changes: 31 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
{
"autoload": {
"psr-0": {
"Cielo": "src"
}
},
"name": "developercielo/api-3.0-php",
"description": "Integração com a API 3.0 da Cielo",
"license": "MIT",
"type": "library",
"require": {
"php": ">=5.6",
"php": "^8.2",
"ext-curl": "*",
"ext-json": "*",
"psr/log":"^1.1"
"psr/log": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^11.1.2",
"phpstan/phpstan": "^1.10.67",
"kint-php/kint": "^5.1.0"
},
"autoload": {
"psr-0": {
"Cielo": "src"
}
},
"autoload-dev": {
"psr-4": {
"TestApp\\": "tests/"
}
},
"suggest": {
"monolog/monolog": "Allows more advanced logging of the application flow"
},
"homepage": "https://github.com/DeveloperCielo/API-3.0-PHP"
}
"homepage": "https://github.com/DeveloperCielo/API-3.0-PHP",
"scripts": {
"phpstan": "phpstan analyse -c phpstan.neon",
"phpunit": "phpunit --configuration phpunit.xml --testdox --exclude-group payment",
"test": [
"@phpstan",
"@phpunit"
],
"test:unit": "phpunit tests/Unit --configuration phpunit.xml --testdox",
"test:e2e": "phpunit tests/E2E --configuration phpunit.xml --testdox"
},
"license": "MIT",
"minimum-stability": "stable"
}
17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parameters:
level: 5
phpVersion: 80300
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
reportMaybesInPropertyPhpDocTypes: true
checkExplicitMixedMissingReturn: true
reportMaybesInMethodSignatures: true
reportStaticMethodSignatures: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkDynamicProperties: true
reportAlwaysTrueInLastCondition: true
paths:
- ./
excludePaths:
- ./vendor/*
ignoreErrors:
23 changes: 23 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
backupGlobals="false"
cacheResult="false"
cacheDirectory="cache/phpunit"
backupStaticProperties="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
5 changes: 1 addition & 4 deletions src/Cielo/API30/Ecommerce/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ class Address implements CieloSerializable

private $district;

/**
* @return array
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return get_object_vars($this);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Cielo/API30/Ecommerce/CieloEcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ class CieloEcommerce
* requests will be send
*
* @param Merchant $merchant
* The merchant credentials
* @param Environment environment
* The environment: {@link Environment::production()} or
* {@link Environment::sandbox()}
* @param Environment $environment
* @param LoggerInterface|null $logger
*/
public function __construct(Merchant $merchant, Environment $environment = null, LoggerInterface $logger = null)
Expand Down Expand Up @@ -117,7 +114,7 @@ public function getRecurrentPayment($recurrentPaymentId)
* @param integer $amount
* Order value in cents
*
* @return Sale The Sale with authorization, tid, etc. returned by Cielo.
* @return \Cielo\API30\Ecommerce\Payment
*
* @throws \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Cielo/API30/Ecommerce/CieloSerializable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface CieloSerializable extends \JsonSerializable
/**
* @param \stdClass $data
*
* @return mixed
* @return void
*/
public function populate(\stdClass $data);
}
5 changes: 1 addition & 4 deletions src/Cielo/API30/Ecommerce/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public function populate(\stdClass $data)
$this->customerName = isset($data->CustomerName) ? $data->CustomerName : null;
}

/**
* @return array
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return get_object_vars($this);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Cielo/API30/Ecommerce/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public function __construct($name = null)
$this->setName($name);
}

/**
* @return array
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return get_object_vars($this);
}
Expand Down
Loading