diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..1d6664c
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+# EditorConfig is awesome: https://editorconfig.org/
+
+# top-most EditorConfig file
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = false
+insert_final_newline = true
+
+[*.php]
+indent_size = 4
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..366dd18
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,24 @@
+version: 2
+updates:
+ - package-ecosystem: 'github-actions'
+ directory: '/'
+ commit-message:
+ prefix: 'chore'
+ schedule:
+ interval: 'monthly'
+ open-pull-requests-limit: 10
+ labels: ['dependencies']
+
+ - package-ecosystem: 'composer'
+ directory: '/'
+ commit-message:
+ prefix: 'chore'
+ schedule:
+ interval: 'monthly'
+ open-pull-requests-limit: 10
+ groups:
+ all-dependencies:
+ patterns: ['*']
+ update-types: ['minor', 'patch', 'major']
+ labels: ['dependencies']
+ versioning-strategy: 'increase'
diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml
new file mode 100644
index 0000000..835f898
--- /dev/null
+++ b/.github/workflows/pull_request.yml
@@ -0,0 +1,58 @@
+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
+ REDE_PV: ${{ secrets.REDE_PV }}
+ REDE_TOKEN: ${{ secrets.REDE_TOKEN }}
+ REDE_DEBUG: ${{ vars.REDE_DEBUG }}
+
+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: PHP Coding Standards Fixer
+ run: composer format:check
+
+ - name: Run PHPUnit
+ run: composer phpunit
diff --git a/.gitignore b/.gitignore
index 0010aca..d87aa4a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,15 @@
+/vendor/*
+/config/app.php
+/tmp/*
+/.env
+/test.php
+/teste.php
+error_log
+.phpunit.cache/*
+.vscode/settings.json
+.php-cs-fixer.cache
+cghooks.lock
.idea
-vendor/*
composer.lock
-
.phpunit.result.cache
-.php-cs-fixer.cache
+env.test.php
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
new file mode 100644
index 0000000..5cb93b4
--- /dev/null
+++ b/.php-cs-fixer.php
@@ -0,0 +1,28 @@
+in(__DIR__)
+ ->name('*.php')
+ ->ignoreDotFiles(true)
+ ->ignoreVCS(true);
+
+return (new PhpCsFixer\Config())
+ ->setParallelConfig(\PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
+ ->setRiskyAllowed(false)
+ ->setRules([
+ '@PSR12' => true, // Aplicar o padrão PSR-12
+ '@Symfony' => true, // Aplicar o padrão Symfony
+ 'fully_qualified_strict_types' => false, // Garantir namespaces completos
+ 'array_syntax' => ['syntax' => 'short'], // Usar a sintaxe curta para arrays []
+ 'binary_operator_spaces' => ['default' => 'single_space'],
+ 'concat_space' => ['spacing' => 'one'],
+ 'increment_style' => ['style' => 'post'],
+ 'class_attributes_separation' => true,
+ ])
+ ->setIndent(' ')
+ ->setLineEnding("\n")
+ ->setFinder($finder);
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..82e1ad0
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,17 @@
+{
+ "recommendations": [
+ "editorconfig.editorconfig",
+ "dbaeumer.vscode-eslint",
+ "esbenp.prettier-vscode",
+ "streetsidesoftware.code-spell-checker",
+ "streetsidesoftware.code-spell-checker-portuguese",
+ "usernamehw.errorlens",
+ "eamodio.gitlens",
+ "seatonjiang.gitmoji-vscode",
+ "devsense.phptools-vscode",
+ "phproberto.vscode-php-getters-setters",
+ "mehedidracula.php-namespace-resolver",
+ "junstyle.php-cs-fixer",
+ ],
+ "unwantedRecommendations": []
+}
diff --git a/.vscode/settings.example.json b/.vscode/settings.example.json
new file mode 100644
index 0000000..365b4b6
--- /dev/null
+++ b/.vscode/settings.example.json
@@ -0,0 +1,35 @@
+{
+ "files.eol": "\n",
+ "eslint.run": "onSave",
+ "editor.tabSize": 2,
+ "php-cs-fixer.executablePath": "${workspaceFolder}/vendor/bin/php-cs-fixer",
+ "[php]": {
+ "editor.defaultFormatter": "junstyle.php-cs-fixer",
+ "editor.formatOnSave": false,
+ "editor.tabSize": 4,
+ "editor.insertSpaces": true,
+ "editor.trimAutoWhitespace": true,
+ "editor.bracketPairColorization.enabled": true
+ },
+ "php.format.codeStyle": "PSR-12",
+ "php.debug.port": 9000,
+ "editor.rulers": [
+ 150
+ ],
+ "files.insertFinalNewline": true,
+ "javascript.suggest.autoImports": true,
+ "typescript.suggest.autoImports": true,
+ "editor.codeActionsOnSave": {
+ "source.fixAll.eslint": "explicit",
+ "source.organizeImports": "explicit"
+ },
+ "eslint.format.enable": true,
+ "scss.validate": false,
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
+ "[json]": {
+ "editor.defaultFormatter": "vscode.json-language-features"
+ },
+ "[jsonc]": {
+ "editor.defaultFormatter": "vscode.json-language-features"
+ }
+}
diff --git a/README.md b/README.md
index 5c8038c..28d148c 100644
--- a/README.md
+++ b/README.md
@@ -2,23 +2,23 @@
SDK de integração eRede
-# Funcionalidades
+## Funcionalidades
Este SDK possui as seguintes funcionalidades:
-* Autorização
-* Captura
-* Consultas
-* Cancelamento
-* 3DS2
-* Zero dollar
-* iata
-* MCC dinâmico.
-# Instalação
+- Autorização
+- Captura
+- Consultas
+- Cancelamento
+- 3DS2
+- Zero dollar
+- iata
+- MCC dinâmico.
+- PIX
## Dependências
-* PHP >= 8.1
+- PHP >= 8.1
## Instalando o SDK
@@ -26,53 +26,46 @@ Se já possui um arquivo `composer.json`, basta adicionar a seguinte dependênci
```json
{
-"require": {
+ "require": {
"developersrede/erede-php": "*"
+ }
}
-}
-
```
Com a dependência adicionada ao `composer.json`, basta executar:
-```
+```bash
composer install
```
Alternativamente, você pode executar diretamente em seu terminal:
-```
+```bash
composer require "developersrede/erede-php"
```
-# Testes
+## Comandos
+
+- Rodar todos os testes e PHPStan `composer test`
+- Rodar todos os testes `composer phpunit`
+- Testes unitários `composer test:unit`
+- Testes integração `composer test:e2e`
+- PHPStan `composer phpstan`
+- PHP-CS-Fixer verify `composer format:check`
+- PHP-CS-Fixer fix `composer format:fix`
+
+## Testes
O SDK utiliza PHPUnit com TestDox para os testes. Para executá-los em ambiente local, você precisa exportar
as variáveis de ambiente `REDE_PV` e `REDE_TOKEN` com suas credenciais da API. Feito isso, basta rodar:
-```
+```bash
export REDE_PV=1234
export REDE_TOKEN=5678
-
-./tests
-```
-
-Os testes também podem ser executados através de um container com a configuração ideal para o projeto. Para isso, basta
-fazer:
-
-```
-docker build . -t erede-docker
-docker run -e REDE_PV='1234' -e REDE_TOKEN='5678' erede-docker
-```
-````
-Caso necessário, o SDK possui a possibilidade de logs de depuração que podem ser utilizados ao executar os testes. Para isso,
-basta exportar a variável de ambiente `REDE_DEBUG` com o valor 1:
-
-```
-export REDE_DEBUG=1
+export REDE_DEBUG=0
```
-# Utilizando
+Ou copie o arquivo `tests/config/env.test.php.example` para `tests/config/env.test.php` e adicione as suas credenciais
## Autorizando uma transação
@@ -130,6 +123,7 @@ if ($transaction->getReturnCode() == '00') {
```
## Adiciona configuração de parcelamento
+
```php
debitCard(
// Configura o 3dSecure para autenticação
$transaction->threeDSecure(
new Device(
- ColorDepth: 1,
- DeviceType3ds: 'BROWSER',
- JavaEnabled: false,
- Language: 'BR',
- ScreenHeight: 500,
- ScreenWidth: 500,
- TimeZoneOffset: 3
+ colorDepth: 1,
+ deviceType3ds: 'BROWSER',
+ javaEnabled: false,
+ language: 'BR',
+ screenHeight: 500,
+ screenWidth: 500,
+ timeZoneOffset: 3
)
);
$transaction->addUrl('https://redirecturl.com/3ds/success', Url::THREE_D_SECURE_SUCCESS);
@@ -369,3 +363,20 @@ if ($transaction->getReturnCode() == '220') {
printf("Redirecione o cliente para \"%s\" para autenticação\n", $transaction->getThreeDSecure()->getUrl());
}
```
+
+## Transação com PIX
+
+```php
+createQrCode(new \DateTimeImmutable('+ 1 hour'));
+
+$transaction = (new eRede($store))->create($transaction);
+
+if ($transaction->getReturnCode() == '00') {
+ printf(
+ "Transação criada com sucesso; tid=%s, qrCodeData=%s, qrCodeImage=%s\n",
+ $transaction->getTid(), $transaction->getQrCode()->getQrCodeData(), $transaction->getQrCode()->getQrCodeImage()
+ );
+}
+```
diff --git a/composer.json b/composer.json
index b573d70..240abbd 100644
--- a/composer.json
+++ b/composer.json
@@ -6,24 +6,59 @@
"license": "MIT",
"type": "library",
"require": {
- "php": "^8.1",
+ "php": "^8.2",
"ext-curl": "*",
"ext-json": "*",
- "psr/log": "*",
- "monolog/monolog": "*"
+ "psr/log": ">=3.0.2",
+ "monolog/monolog": ">=3.8"
},
"require-dev": {
- "phpunit/phpunit": "^9.5.0",
- "friendsofphp/php-cs-fixer": "^v3.11.0",
- "phpstan/phpstan": "^1.8.6",
- "squizlabs/php_codesniffer": "^3.7",
- "sebastian/phpcpd": "^6.0.0"
+ "phpunit/phpunit": "^11.4.3",
+ "phpstan/phpstan": "^1.12.10",
+ "kint-php/kint": "^5.1.1",
+ "monolog/monolog": "^3.8.0",
+ "friendsofphp/php-cs-fixer": "^3.64",
+ "brainmaestro/composer-git-hooks": "^3.0"
},
"autoload": {
"psr-4": {
"Rede\\": "src/Rede"
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "Rede\\Tests\\": "tests/"
+ }
+ },
+ "scripts": {
+ "start": "php -S localhost:8879 -t .",
+ "format:check": "php-cs-fixer fix --dry-run --stop-on-violation",
+ "format:fix": "php-cs-fixer fix",
+ "phpstan": "phpstan analyse -c phpstan.neon --xdebug",
+ "phpunit": "phpunit --configuration phpunit.xml --testdox",
+ "test": [
+ "@phpstan",
+ "@phpunit"
+ ],
+ "test:unit": "phpunit tests/Unit --configuration phpunit.xml --testdox",
+ "test:e2e": "phpunit tests/E2E --configuration phpunit.xml --testdox",
+ "test:coverage": "phpunit --configuration phpunit.xml --coverage-clover build/logs/clover.xml --coverage-html build/coverage",
+ "post-install-cmd": "cghooks add --ignore-lock",
+ "post-update-cmd": "cghooks update"
+ },
+ "extra": {
+ "hooks": {
+ "config": {
+ "stop-on-failure": [
+ "pre-push",
+ "pre-commit"
+ ]
+ },
+ "pre-commit": [
+ "composer format:check"
+ ]
+ }
+ },
"authors": [
{
"name": "João Batista Neto",
diff --git a/phpstan.neon b/phpstan.neon
index 1163c0e..a16d06a 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,5 +1,6 @@
parameters:
- level: 8
- paths:
- - src
- - test
+ level: 8
+ paths:
+ - ./
+ excludePaths:
+ - ./vendor/*
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..8707778
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,37 @@
+
+
+
+
+ tests
+
+
+
+ .
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Rede/Additional.php b/src/Rede/Additional.php
index 0308bfc..ddc9e8d 100644
--- a/src/Rede/Additional.php
+++ b/src/Rede/Additional.php
@@ -7,51 +7,37 @@ class Additional implements RedeSerializable
use SerializeTrait;
use CreateTrait;
- /**
- * @var int|null
- */
private ?int $gateway = null;
- /**
- * @var int|null
- */
private ?int $module = null;
- /**
- * @return int|null
- */
public function getGateway(): ?int
{
return $this->gateway;
}
/**
- * @param int $gateway
- *
* @return $this
*/
public function setGateway(int $gateway): static
{
$this->gateway = $gateway;
+
return $this;
}
- /**
- * @return int|null
- */
public function getModule(): ?int
{
return $this->module;
}
/**
- * @param int $module
- *
* @return $this
*/
public function setModule(int $module): static
{
$this->module = $module;
+
return $this;
}
}
diff --git a/src/Rede/Address.php b/src/Rede/Address.php
index 03a9447..094a3c6 100644
--- a/src/Rede/Address.php
+++ b/src/Rede/Address.php
@@ -7,218 +7,169 @@ class Address implements RedeSerializable
use SerializeTrait;
public const BILLING = 1;
+
public const SHIPPING = 2;
+
public const BOTH = 3;
public const APARTMENT = 1;
+
public const HOUSE = 2;
+
public const COMMERCIAL = 3;
+
public const OTHER = 4;
- /**
- * @var string|null
- */
private ?string $address = null;
- /**
- * @var string|null
- */
private ?string $addresseeName = null;
- /**
- * @var string|null
- */
private ?string $city = null;
- /**
- * @var string|null
- */
private ?string $complement = null;
- /**
- * @var string|null
- */
private ?string $neighbourhood = null;
- /**
- * @var string|null
- */
private ?string $number = null;
- /**
- * @var string|null
- */
private ?string $state = null;
- /**
- * @var int|null
- */
private ?int $type = null;
- /**
- * @var string|null
- */
private ?string $zipCode = null;
- /**
- * @return string|null
- */
public function getAddress(): ?string
{
return $this->address;
}
/**
- * @param string|null $address
* @return $this
*/
public function setAddress(?string $address): static
{
$this->address = $address;
+
return $this;
}
- /**
- * @return string|null
- */
public function getAddresseeName(): ?string
{
return $this->addresseeName;
}
/**
- * @param string|null $addresseeName
* @return $this
*/
public function setAddresseeName(?string $addresseeName): static
{
$this->addresseeName = $addresseeName;
+
return $this;
}
- /**
- * @return string|null
- */
public function getCity(): ?string
{
return $this->city;
}
/**
- * @param string|null $city
* @return $this
*/
public function setCity(?string $city): static
{
$this->city = $city;
+
return $this;
}
- /**
- * @return string|null
- */
public function getComplement(): ?string
{
return $this->complement;
}
/**
- * @param string|null $complement
* @return $this
*/
public function setComplement(?string $complement): static
{
$this->complement = $complement;
+
return $this;
}
- /**
- * @return string|null
- */
public function getNeighbourhood(): ?string
{
return $this->neighbourhood;
}
/**
- * @param string|null $neighbourhood
* @return $this
*/
public function setNeighbourhood(?string $neighbourhood): static
{
$this->neighbourhood = $neighbourhood;
+
return $this;
}
- /**
- * @return string|null
- */
public function getNumber(): ?string
{
return $this->number;
}
/**
- * @param string|null $number
* @return $this
*/
public function setNumber(?string $number): static
{
$this->number = $number;
+
return $this;
}
- /**
- * @return string|null
- */
public function getState(): ?string
{
return $this->state;
}
/**
- * @param string|null $state
* @return $this
*/
public function setState(?string $state): static
{
$this->state = $state;
+
return $this;
}
- /**
- * @return int|null
- */
public function getType(): ?int
{
return $this->type;
}
/**
- * @param int|null $type
* @return $this
*/
public function setType(?int $type): static
{
$this->type = $type;
+
return $this;
}
- /**
- * @return string|null
- */
public function getZipCode(): ?string
{
return $this->zipCode;
}
/**
- * @param string|null $zipCode
* @return $this
*/
public function setZipCode(?string $zipCode): static
{
$this->zipCode = $zipCode;
+
return $this;
}
}
diff --git a/src/Rede/Authorization.php b/src/Rede/Authorization.php
index fb604f9..49ca073 100644
--- a/src/Rede/Authorization.php
+++ b/src/Rede/Authorization.php
@@ -2,400 +2,296 @@
namespace Rede;
-use DateTime;
-
class Authorization
{
use CreateTrait;
- /**
- * @var string|null
- */
private ?string $affiliation = null;
- /**
- * @var int|null
- */
private ?int $amount = null;
- /**
- * @var string|null
- */
private ?string $authorizationCode = null;
- /**
- * @var string|null
- */
private ?string $cardBin = null;
- /**
- * @var string|null
- */
private ?string $cardHolderName = null;
- /**
- * @var DateTime|null
- */
- private ?DateTime $dateTime = null;
+ private ?\DateTime $dateTime = null;
- /**
- * @var int|null
- */
private ?int $installments = null;
- /**
- * @var string|null
- */
private ?string $kind = null;
- /**
- * @var string|null
- */
private ?string $last4 = null;
- /**
- * @var string|null
- */
private ?string $nsu = null;
- /**
- * @var string|null
- */
private ?string $origin = null;
- /**
- * @var string|null
- */
private ?string $reference = null;
- /**
- * @var string|null
- */
private ?string $returnCode = null;
- /**
- * @var string|null
- */
private ?string $returnMessage = null;
- /**
- * @var string|null
- */
private ?string $status = null;
- /**
- * @var string|null
- */
private ?string $subscription = null;
- /**
- * @var string|null
- */
private ?string $tid = null;
- /**
- * @return string|null
- */
public function getAffiliation(): ?string
{
return $this->affiliation;
}
/**
- * @param string|null $affiliation
* @return $this
*/
public function setAffiliation(?string $affiliation): static
{
$this->affiliation = $affiliation;
+
return $this;
}
- /**
- * @return int|null
- */
public function getAmount(): ?int
{
return $this->amount;
}
/**
- * @param int|null $amount
* @return $this
*/
public function setAmount(?int $amount): static
{
$this->amount = $amount;
+
return $this;
}
- /**
- * @return string|null
- */
public function getAuthorizationCode(): ?string
{
return $this->authorizationCode;
}
/**
- * @param string|null $authorizationCode
* @return $this
*/
public function setAuthorizationCode(?string $authorizationCode): static
{
$this->authorizationCode = $authorizationCode;
+
return $this;
}
- /**
- * @return string|null
- */
public function getCardBin(): ?string
{
return $this->cardBin;
}
/**
- * @param string|null $cardBin
* @return $this
*/
public function setCardBin(?string $cardBin): static
{
$this->cardBin = $cardBin;
+
return $this;
}
- /**
- * @return string|null
- */
public function getCardHolderName(): ?string
{
return $this->cardHolderName;
}
/**
- * @param string|null $cardHolderName
* @return $this
*/
public function setCardHolderName(?string $cardHolderName): static
{
$this->cardHolderName = $cardHolderName;
+
return $this;
}
- /**
- * @return DateTime|null
- */
- public function getDateTime(): ?DateTime
+ public function getDateTime(): ?\DateTime
{
return $this->dateTime;
}
/**
- * @param DateTime|null $dateTime
* @return $this
*/
- public function setDateTime(?DateTime $dateTime): static
+ public function setDateTime(?\DateTime $dateTime): static
{
$this->dateTime = $dateTime;
+
return $this;
}
- /**
- * @return int|null
- */
public function getInstallments(): ?int
{
return $this->installments;
}
/**
- * @param int|null $installments
* @return $this
*/
public function setInstallments(?int $installments): static
{
$this->installments = $installments;
+
return $this;
}
- /**
- * @return string|null
- */
public function getKind(): ?string
{
return $this->kind;
}
/**
- * @param string|null $kind
* @return $this
*/
public function setKind(?string $kind): static
{
$this->kind = $kind;
+
return $this;
}
- /**
- * @return string|null
- */
public function getLast4(): ?string
{
return $this->last4;
}
/**
- * @param string|null $last4
* @return $this
*/
public function setLast4(?string $last4): static
{
$this->last4 = $last4;
+
return $this;
}
- /**
- * @return string|null
- */
public function getNsu(): ?string
{
return $this->nsu;
}
/**
- * @param string|null $nsu
* @return $this
*/
public function setNsu(?string $nsu): static
{
$this->nsu = $nsu;
+
return $this;
}
- /**
- * @return string|null
- */
public function getOrigin(): ?string
{
return $this->origin;
}
/**
- * @param string|null $origin
* @return $this
*/
public function setOrigin(?string $origin): static
{
$this->origin = $origin;
+
return $this;
}
- /**
- * @return string|null
- */
public function getReference(): ?string
{
return $this->reference;
}
/**
- * @param string|null $reference
* @return $this
*/
public function setReference(?string $reference): static
{
$this->reference = $reference;
+
return $this;
}
- /**
- * @return string|null
- */
public function getReturnCode(): ?string
{
return $this->returnCode;
}
/**
- * @param string|null $returnCode
* @return $this
*/
public function setReturnCode(?string $returnCode): static
{
$this->returnCode = $returnCode;
+
return $this;
}
- /**
- * @return string|null
- */
public function getReturnMessage(): ?string
{
return $this->returnMessage;
}
/**
- * @param string|null $returnMessage
* @return $this
*/
public function setReturnMessage(?string $returnMessage): static
{
$this->returnMessage = $returnMessage;
+
return $this;
}
- /**
- * @return string|null
- */
public function getStatus(): ?string
{
return $this->status;
}
/**
- * @param string|null $status
* @return $this
*/
public function setStatus(?string $status): static
{
$this->status = $status;
+
return $this;
}
- /**
- * @return string|null
- */
public function getSubscription(): ?string
{
return $this->subscription;
}
/**
- * @param string|null $subscription
* @return $this
*/
public function setSubscription(?string $subscription): static
{
$this->subscription = $subscription;
+
return $this;
}
- /**
- * @return string|null
- */
public function getTid(): ?string
{
return $this->tid;
}
/**
- * @param string|null $tid
* @return $this
*/
public function setTid(?string $tid): static
{
$this->tid = $tid;
+
return $this;
}
}
diff --git a/src/Rede/Brand.php b/src/Rede/Brand.php
index 29a97af..f64dbb2 100644
--- a/src/Rede/Brand.php
+++ b/src/Rede/Brand.php
@@ -6,71 +6,45 @@ class Brand
{
use CreateTrait;
- /**
- * @var string|null
- */
private ?string $name = null;
- /**
- * @var string|null
- */
private ?string $returnCode = null;
- /**
- * @var string|null
- */
+
private ?string $returnMessage = null;
- /**
- * @return string|null
- */
public function getName(): ?string
{
return $this->name;
}
- /**
- * @param string|null $name
- * @return Brand
- */
public function setName(?string $name): Brand
{
$this->name = $name;
+
return $this;
}
- /**
- * @return string|null
- */
public function getReturnCode(): ?string
{
return $this->returnCode;
}
- /**
- * @param string|null $returnCode
- * @return Brand
- */
public function setReturnCode(?string $returnCode): Brand
{
$this->returnCode = $returnCode;
+
return $this;
}
- /**
- * @return string|null
- */
public function getReturnMessage(): ?string
{
return $this->returnMessage;
}
- /**
- * @param string|null $returnMessage
- * @return Brand
- */
public function setReturnMessage(?string $returnMessage): Brand
{
$this->returnMessage = $returnMessage;
+
return $this;
}
}
diff --git a/src/Rede/Capture.php b/src/Rede/Capture.php
index e6895c5..fd4ba95 100644
--- a/src/Rede/Capture.php
+++ b/src/Rede/Capture.php
@@ -2,78 +2,49 @@
namespace Rede;
-use DateTime;
-
class Capture
{
use CreateTrait;
- /**
- * @var int|null
- */
private ?int $amount = null;
- /**
- * @var DateTime|null
- */
- private ?DateTime $dateTime = null;
+ private ?\DateTime $dateTime = null;
- /**
- * @var string|null
- */
private ?string $nsu = null;
- /**
- * @return int|null
- */
public function getAmount(): ?int
{
return $this->amount;
}
- /**
- * @param int|null $amount
- * @return Capture
- */
public function setAmount(?int $amount): Capture
{
$this->amount = $amount;
+
return $this;
}
- /**
- * @return DateTime|null
- */
- public function getDateTime(): ?DateTime
+ public function getDateTime(): ?\DateTime
{
return $this->dateTime;
}
- /**
- * @param DateTime|null $dateTime
- * @return Capture
- */
- public function setDateTime(?DateTime $dateTime): Capture
+ public function setDateTime(?\DateTime $dateTime): Capture
{
$this->dateTime = $dateTime;
+
return $this;
}
- /**
- * @return string|null
- */
public function getNsu(): ?string
{
return $this->nsu;
}
- /**
- * @param string|null $nsu
- * @return Capture
- */
public function setNsu(?string $nsu): Capture
{
$this->nsu = $nsu;
+
return $this;
}
}
diff --git a/src/Rede/Cart.php b/src/Rede/Cart.php
index b738a33..d70c7bf 100644
--- a/src/Rede/Cart.php
+++ b/src/Rede/Cart.php
@@ -6,19 +6,10 @@ class Cart implements RedeSerializable
{
use SerializeTrait;
- /**
- * @var Address|null
- */
private ?Address $billing = null;
- /**
- * @var Consumer|null
- */
private ?Consumer $consumer = null;
- /**
- * @var Iata|null
- */
private ?Iata $iata = null;
/**
@@ -31,11 +22,6 @@ class Cart implements RedeSerializable
*/
private array $shipping = [];
- /**
- * @param int $type
- *
- * @return Address
- */
public function address(int $type = Address::BOTH): Address
{
$address = new Address();
@@ -52,8 +38,6 @@ public function address(int $type = Address::BOTH): Address
}
/**
- * @param Item $item
- *
* @return $this
*/
public function addItem(Item $item): static
@@ -64,8 +48,6 @@ public function addItem(Item $item): static
}
/**
- * @param Address $shippingAddress
- *
* @return $this
*/
public function addShippingAddress(Address $shippingAddress): static
@@ -76,8 +58,6 @@ public function addShippingAddress(Address $shippingAddress): static
}
/**
- * @param Address $shippingAddress
- *
* @return $this
*/
public function setShippingAddress(Address $shippingAddress): static
@@ -88,8 +68,6 @@ public function setShippingAddress(Address $shippingAddress): static
}
/**
- * @param Address $billingAddress
- *
* @return $this
*/
public function setBillingAddress(Address $billingAddress): static
@@ -99,13 +77,6 @@ public function setBillingAddress(Address $billingAddress): static
return $this;
}
- /**
- * @param string $name
- * @param string $email
- * @param string $cpf
- *
- * @return Consumer
- */
public function consumer(string $name, string $email, string $cpf): Consumer
{
$consumer = new Consumer($name, $email, $cpf);
@@ -116,20 +87,17 @@ public function consumer(string $name, string $email, string $cpf): Consumer
}
/**
- * @param Flight $flight
- *
* @return $this
*/
public function setFlight(Flight $flight): static
{
$this->iata = new Iata();
$this->iata->setFlight($flight);
+
return $this;
}
/**
- * @param Iata $iata
- *
* @return $this
*/
public function setIata(Iata $iata): static
@@ -147,29 +115,20 @@ public function getShippingAddresses(): array
return $this->shipping;
}
- /**
- * @return Address|null
- */
public function getBilling(): ?Address
{
return $this->billing;
}
- /**
- * @return Consumer|null
- */
public function getConsumer(): ?Consumer
{
return $this->consumer;
}
- /**
- * @param Consumer $consumer
- * @return Cart
- */
public function setConsumer(Consumer $consumer): Cart
{
$this->consumer = $consumer;
+
return $this;
}
diff --git a/src/Rede/Consumer.php b/src/Rede/Consumer.php
index f54a807..9c7e58d 100644
--- a/src/Rede/Consumer.php
+++ b/src/Rede/Consumer.php
@@ -2,14 +2,12 @@
namespace Rede;
-use ArrayIterator;
-use stdClass;
-
class Consumer implements RedeSerializable
{
use SerializeTrait;
public const MALE = 'M';
+
public const FEMALE = 'F';
/**
@@ -17,36 +15,23 @@ class Consumer implements RedeSerializable
*/
private array $documents = [];
- /**
- * @var string|null
- */
private ?string $gender = null;
- /**
- * @var Phone|null
- */
private ?Phone $phone = null;
/**
* Consumer constructor.
- *
- * @param string $name
- * @param string $email
- * @param string $cpf
*/
public function __construct(private string $name, private string $email, private string $cpf)
{
}
/**
- * @param string $type
- * @param string $number
- *
* @return $this
*/
public function addDocument(string $type, string $number): static
{
- $document = new stdClass();
+ $document = new \stdClass();
$document->type = $type;
$document->number = $number;
@@ -56,102 +41,73 @@ public function addDocument(string $type, string $number): static
}
/**
- * @return ArrayIterator
+ * @return \ArrayIterator
*/
- public function getDocumentsIterator(): ArrayIterator
+ public function getDocumentsIterator(): \ArrayIterator
{
- return new ArrayIterator($this->documents);
+ return new \ArrayIterator($this->documents);
}
- /**
- * @return string|null
- */
public function getGender(): ?string
{
return $this->gender;
}
- /**
- * @param string $gender
- * @return Consumer
- */
public function setGender(string $gender): Consumer
{
$this->gender = $gender;
+
return $this;
}
- /**
- * @return Phone|null
- */
public function getPhone(): ?Phone
{
return $this->phone;
}
/**
- * @param string $ddd
- * @param string $number
- * @param int $type
* @return $this
*/
public function setPhone(string $ddd, string $number, int $type = Phone::CELLPHONE): static
{
$this->phone = new Phone($ddd, $number, $type);
+
return $this;
}
- /**
- * @return string
- */
public function getName(): string
{
return $this->name;
}
- /**
- * @param string $name
- * @return Consumer
- */
public function setName(string $name): Consumer
{
$this->name = $name;
+
return $this;
}
- /**
- * @return string
- */
public function getEmail(): string
{
return $this->email;
}
- /**
- * @param string $email
- * @return Consumer
- */
public function setEmail(string $email): Consumer
{
$this->email = $email;
+
return $this;
}
- /**
- * @return string
- */
public function getCpf(): string
{
return $this->cpf;
}
- /**
- * @param string $cpf
- * @return Consumer
- */
public function setCpf(string $cpf): Consumer
{
$this->cpf = $cpf;
+
return $this;
}
}
diff --git a/src/Rede/CreateTrait.php b/src/Rede/CreateTrait.php
index 517b3c4..396cbf6 100644
--- a/src/Rede/CreateTrait.php
+++ b/src/Rede/CreateTrait.php
@@ -2,33 +2,26 @@
namespace Rede;
-use DateTime;
-use Exception;
-
trait CreateTrait
{
/**
- * @param object $data
- *
- * @return object
- * @throws Exception
+ * @throws \Exception
*/
- public static function create(object $data): object
+ public function populate(object $body): static
{
- $object = new self();
- $dataKeys = get_object_vars($data);
- $objectKeys = get_object_vars($object);
+ $bodyKeys = get_object_vars($body);
+ $dateTimeProps = ['requestDateTime', 'dateTime', 'refundDateTime', 'dateTimeExpiration', 'expirationQrCode'];
- foreach ($dataKeys as $property => $value) {
- if (array_key_exists($property, $objectKeys)) {
- if ($property == 'requestDateTime' || $property == 'dateTime' || $property == 'refundDateTime') {
- $value = new DateTime($value);
+ foreach ($bodyKeys as $property => $value) {
+ if (property_exists($this, $property) && null !== $value) {
+ if (in_array($property, $dateTimeProps) && is_string($value)) {
+ $value = new \DateTime($value);
}
- $object->{$property} = $value;
+ $this->{$property} = $value;
}
}
- return $object;
+ return $this;
}
}
diff --git a/src/Rede/Device.php b/src/Rede/Device.php
index 99f8e7e..c9d4655 100644
--- a/src/Rede/Device.php
+++ b/src/Rede/Device.php
@@ -7,149 +7,119 @@ class Device implements RedeSerializable
use CreateTrait;
use SerializeTrait;
- /**
- * @param string|int|null $ColorDepth
- * @param string|null $DeviceType3ds
- * @param bool|null $JavaEnabled
- * @param string $Language
- * @param int|null $ScreenHeight
- * @param int|null $ScreenWidth
- * @param int|null $TimeZoneOffset
- */
public function __construct(
- private string|int|null $ColorDepth = null,
- private ?string $DeviceType3ds = null,
- private ?bool $JavaEnabled = null,
- private string $Language = 'BR',
- private ?int $ScreenHeight = null,
- private ?int $ScreenWidth = null,
- private ?int $TimeZoneOffset = 3,
+ private string|int|null $colorDepth = null,
+ private ?string $deviceType3ds = null,
+ private ?bool $javaEnabled = null,
+ private string $language = 'BR',
+ private ?int $screenHeight = null,
+ private ?int $screenWidth = null,
+ private ?int $timeZoneOffset = 3,
) {
}
- /**
- * @return string|null
- */
- public function getColorDepth(): ?string
+ public function getColorDepth(): string|int|null
{
- return $this->ColorDepth;
+ return $this->colorDepth;
}
/**
- * @param string $ColorDepth
* @return $this
*/
- public function setColorDepth(string $ColorDepth): static
+ public function setColorDepth(string $colorDepth): static
{
- $this->ColorDepth = $ColorDepth;
+ $this->colorDepth = $colorDepth;
+
return $this;
}
- /**
- * @return string|null
- */
public function getDeviceType3ds(): ?string
{
- return $this->DeviceType3ds;
+ return $this->deviceType3ds;
}
/**
- * @param string $DeviceType3ds
* @return $this
*/
- public function setDeviceType3ds(string $DeviceType3ds): static
+ public function setDeviceType3ds(string $deviceType3ds): static
{
- $this->DeviceType3ds = $DeviceType3ds;
+ $this->deviceType3ds = $deviceType3ds;
+
return $this;
}
- /**
- * @return bool|null
- */
public function getJavaEnabled(): ?bool
{
- return $this->JavaEnabled;
+ return $this->javaEnabled;
}
/**
- * @param bool $JavaEnabled
* @return $this
*/
public function setJavaEnabled(bool $JavaEnabled = true): static
{
- $this->JavaEnabled = $JavaEnabled;
+ $this->javaEnabled = $JavaEnabled;
+
return $this;
}
- /**
- * @return string
- */
public function getLanguage(): string
{
- return $this->Language;
+ return $this->language;
}
/**
- * @param string $Language
* @return $this
*/
- public function setLanguage(string $Language): static
+ public function setLanguage(string $language): static
{
- $this->Language = $Language;
+ $this->language = $language;
+
return $this;
}
- /**
- * @return int|null
- */
public function getScreenHeight(): ?int
{
- return $this->ScreenHeight;
+ return $this->screenHeight;
}
/**
- * @param int $ScreenHeight
* @return $this
*/
- public function setScreenHeight(int $ScreenHeight): static
+ public function setScreenHeight(int $screenHeight): static
{
- $this->ScreenHeight = $ScreenHeight;
+ $this->screenHeight = $screenHeight;
+
return $this;
}
- /**
- * @return int|null
- */
public function getScreenWidth(): ?int
{
- return $this->ScreenWidth;
+ return $this->screenWidth;
}
/**
- * @param int $ScreenWidth
* @return $this
*/
- public function setScreenWidth(int $ScreenWidth): static
+ public function setScreenWidth(int $screenWidth): static
{
- $this->ScreenWidth = $ScreenWidth;
+ $this->screenWidth = $screenWidth;
+
return $this;
}
- /**
- * @return int|null
- */
public function getTimeZoneOffset(): ?int
{
- return $this->TimeZoneOffset;
+ return $this->timeZoneOffset;
}
/**
- * @param int $TimeZoneOffset
* @return $this
*/
- public function setTimeZoneOffset(int $TimeZoneOffset): static
+ public function setTimeZoneOffset(int $timeZoneOffset): static
{
- $this->TimeZoneOffset = $TimeZoneOffset;
+ $this->timeZoneOffset = $timeZoneOffset;
+
return $this;
}
}
diff --git a/src/Rede/Environment.php b/src/Rede/Environment.php
index 97694a7..542376d 100644
--- a/src/Rede/Environment.php
+++ b/src/Rede/Environment.php
@@ -2,33 +2,22 @@
namespace Rede;
-use stdClass;
-
class Environment implements RedeSerializable
{
public const PRODUCTION = 'https://api.userede.com.br/erede';
+
public const SANDBOX = 'https://api.userede.com.br/desenvolvedores';
+
public const VERSION = 'v1';
- /**
- * @var string|null
- */
private ?string $ip = null;
- /**
- * @var string|null
- */
private ?string $sessionId = null;
- /**
- * @var string
- */
private string $endpoint;
/**
- * Creates an environment with its base url and version
- *
- * @param string $baseUrl
+ * Creates an environment with its base url and version.
*/
private function __construct(string $baseUrl)
{
@@ -52,8 +41,6 @@ public static function sandbox(): Environment
}
/**
- * @param string $service
- *
* @return string Gets the environment endpoint
*/
public function getEndpoint(string $service): string
@@ -61,51 +48,42 @@ public function getEndpoint(string $service): string
return $this->endpoint . $service;
}
- /**
- * @return string|null
- */
public function getIp(): ?string
{
return $this->ip;
}
/**
- * @param string $ip
- *
* @return $this
*/
public function setIp(string $ip): static
{
$this->ip = $ip;
+
return $this;
}
- /**
- * @return string|null
- */
public function getSessionId(): ?string
{
return $this->sessionId;
}
/**
- * @param string $sessionId
- *
* @return $this
*/
public function setSessionId(string $sessionId): static
{
$this->sessionId = $sessionId;
+
return $this;
}
/**
- * @return mixed
* @noinspection PhpMixedReturnTypeCanBeReducedInspection
*/
public function jsonSerialize(): mixed
{
- $consumer = new stdClass();
+ $consumer = new \stdClass();
$consumer->ip = $this->ip;
$consumer->sessionId = $this->sessionId;
diff --git a/src/Rede/Exception/RedeException.php b/src/Rede/Exception/RedeException.php
index 41d6f3e..005b696 100644
--- a/src/Rede/Exception/RedeException.php
+++ b/src/Rede/Exception/RedeException.php
@@ -2,8 +2,6 @@
namespace Rede\Exception;
-use RuntimeException;
-
-class RedeException extends RuntimeException
+class RedeException extends \RuntimeException
{
}
diff --git a/src/Rede/Flight.php b/src/Rede/Flight.php
index 09768cf..2ccccda 100644
--- a/src/Rede/Flight.php
+++ b/src/Rede/Flight.php
@@ -15,60 +15,48 @@ public function __construct(private string $number, private string $from, privat
{
}
- /**
- * @return string
- */
public function getDate(): string
{
return $this->date;
}
/**
- * @param string $date
- *
* @return $this
*/
public function setDate(string $date): static
{
$this->date = $date;
+
return $this;
}
- /**
- * @return string
- */
public function getFrom(): string
{
return $this->from;
}
/**
- * @param string $from
- *
* @return $this
*/
public function setFrom(string $from): static
{
$this->from = $from;
+
return $this;
}
- /**
- * @return string
- */
public function getNumber(): string
{
return $this->number;
}
/**
- * @param string $number
- *
* @return $this
*/
public function setNumber(string $number): static
{
$this->number = $number;
+
return $this;
}
@@ -81,20 +69,17 @@ public function getPassenger(): array
}
/**
- * @param Passenger $passenger
- *
* @return $this
*/
public function setPassenger(Passenger $passenger): static
{
$this->passenger = [];
$this->addPassenger($passenger);
+
return $this;
}
/**
- * @param Passenger $passenger
- *
* @return $this
*/
public function addPassenger(Passenger $passenger): static
@@ -104,22 +89,18 @@ public function addPassenger(Passenger $passenger): static
return $this;
}
- /**
- * @return string
- */
public function getTo(): string
{
return $this->to;
}
/**
- * @param string $to
- *
* @return $this
*/
public function setTo(string $to): static
{
$this->to = $to;
+
return $this;
}
}
diff --git a/src/Rede/Iata.php b/src/Rede/Iata.php
index 5ae2df6..32f5895 100644
--- a/src/Rede/Iata.php
+++ b/src/Rede/Iata.php
@@ -2,20 +2,12 @@
namespace Rede;
-use ArrayIterator;
-
class Iata implements RedeSerializable
{
use SerializeTrait;
- /**
- * @var string|null
- */
private ?string $code = null;
- /**
- * @var string|null
- */
private ?string $departureTax = null;
/**
@@ -23,55 +15,45 @@ class Iata implements RedeSerializable
*/
private array $flight = [];
- /**
- * @return string|null
- */
public function getCode(): ?string
{
return $this->code;
}
/**
- * @param string $code
- *
* @return $this
*/
public function setCode(string $code): static
{
$this->code = $code;
+
return $this;
}
- /**
- * @return string|null
- */
public function getDepartureTax(): ?string
{
return $this->departureTax;
}
/**
- * @param string $departureTax
- *
* @return $this
*/
public function setDepartureTax(string $departureTax): static
{
$this->departureTax = $departureTax;
+
return $this;
}
/**
- * @return ArrayIterator
+ * @return \ArrayIterator
*/
- public function getFlightIterator(): ArrayIterator
+ public function getFlightIterator(): \ArrayIterator
{
- return new ArrayIterator($this->flight);
+ return new \ArrayIterator($this->flight);
}
/**
- * @param Flight $flight
- *
* @return $this
*/
public function setFlight(Flight $flight): static
@@ -83,8 +65,6 @@ public function setFlight(Flight $flight): static
}
/**
- * @param Flight $flight
- *
* @return $this
*/
public function addFlight(Flight $flight): static
diff --git a/src/Rede/Item.php b/src/Rede/Item.php
index f1444cb..08f4a8a 100644
--- a/src/Rede/Item.php
+++ b/src/Rede/Item.php
@@ -7,195 +7,147 @@ class Item implements RedeSerializable
use SerializeTrait;
public const PHYSICAL = 1;
+
public const DIGITAL = 2;
+
public const SERVICE = 3;
+
public const AIRLINE = 4;
- /**
- * @var int|null
- */
private ?int $amount = null;
- /**
- * @var string|null
- */
private ?string $description = null;
- /**
- * @var int|null
- */
private ?int $discount = null;
- /**
- * @var int|null
- */
private ?int $freight = null;
- /**
- * @var string|null
- */
private ?string $shippingType = null;
/**
* Item constructor.
- *
- * @param string $id
- * @param int $quantity
- * @param int $type
*/
public function __construct(private string $id, private int $quantity, private int $type = Item::PHYSICAL)
{
}
- /**
- * @return int|null
- */
public function getAmount(): ?int
{
return $this->amount;
}
/**
- * @param int $amount
- *
* @return $this
*/
public function setAmount(int $amount): static
{
$this->amount = $amount;
+
return $this;
}
- /**
- * @return string|null
- */
public function getDescription(): ?string
{
return $this->description;
}
/**
- * @param string $description
- *
* @return $this
*/
public function setDescription(string $description): static
{
$this->description = $description;
+
return $this;
}
- /**
- * @return int|null
- */
public function getDiscount(): ?int
{
return $this->discount;
}
/**
- * @param int $discount
- *
* @return $this
*/
public function setDiscount(int $discount): static
{
$this->discount = $discount;
+
return $this;
}
- /**
- * @return int|null
- */
public function getFreight(): ?int
{
return $this->freight;
}
/**
- * @param int $freight
- *
* @return $this
*/
public function setFreight(int $freight): static
{
$this->freight = $freight;
+
return $this;
}
- /**
- * @return string|null
- */
public function getId(): ?string
{
return $this->id;
}
/**
- * @param string $id
- *
* @return $this
*/
public function setId(string $id): static
{
$this->id = $id;
+
return $this;
}
- /**
- * @return int|null
- */
public function getQuantity(): ?int
{
return $this->quantity;
}
/**
- * @param int $quantity
- *
* @return $this
*/
public function setQuantity(int $quantity): static
{
$this->quantity = $quantity;
+
return $this;
}
- /**
- * @return string|null
- */
public function getShippingType(): ?string
{
return $this->shippingType;
}
/**
- * @param string $shippingType
- *
* @return $this
*/
public function setShippingType(string $shippingType): static
{
$this->shippingType = $shippingType;
+
return $this;
}
- /**
- * @return int|null
- */
public function getType(): ?int
{
return $this->type;
}
/**
- * @param int $type
- *
* @return $this
*/
public function setType(int $type): static
{
$this->type = $type;
+
return $this;
}
}
diff --git a/src/Rede/Passenger.php b/src/Rede/Passenger.php
index 1d7cc6f..39ca9ac 100644
--- a/src/Rede/Passenger.php
+++ b/src/Rede/Passenger.php
@@ -6,84 +6,69 @@ class Passenger implements RedeSerializable
{
use SerializeTrait;
- /**
- * @var Phone|null
- */
private ?Phone $phone = null;
public function __construct(private string $name, private string $email, private string $ticket)
{
}
- /**
- * @return Phone|null
- */
public function getPhone(): ?Phone
{
return $this->phone;
}
/**
- * @param Phone $phone
* @return $this
*/
public function setPhone(Phone $phone): static
{
$this->phone = $phone;
+
return $this;
}
- /**
- * @return string
- */
public function getName(): string
{
return $this->name;
}
/**
- * @param string $name
* @return $this
*/
public function setName(string $name): static
{
$this->name = $name;
+
return $this;
}
- /**
- * @return string
- */
public function getEmail(): string
{
return $this->email;
}
/**
- * @param string $email
* @return $this
*/
public function setEmail(string $email): static
{
$this->email = $email;
+
return $this;
}
- /**
- * @return string
- */
public function getTicket(): string
{
return $this->ticket;
}
/**
- * @param string $ticket
* @return $this
*/
public function setTicket(string $ticket): static
{
$this->ticket = $ticket;
+
return $this;
}
}
diff --git a/src/Rede/Phone.php b/src/Rede/Phone.php
index 93ce21f..3a08826 100644
--- a/src/Rede/Phone.php
+++ b/src/Rede/Phone.php
@@ -7,72 +7,62 @@ class Phone implements RedeSerializable
use SerializeTrait;
public const CELLPHONE = 1;
+
public const HOME = 2;
+
public const WORK = 3;
+
public const OTHER = 4;
/**
* Phone constructor.
- *
- * @param string $ddd
- * @param string $number
- * @param int $type
*/
public function __construct(private string $ddd, private string $number, private int $type = Phone::CELLPHONE)
{
}
- /**
- * @return string
- */
public function getDdd(): string
{
return $this->ddd;
}
/**
- * @param string $ddd
* @return $this
*/
public function setDdd(string $ddd): static
{
$this->ddd = $ddd;
+
return $this;
}
- /**
- * @return string
- */
public function getNumber(): string
{
return $this->number;
}
/**
- * @param string $number
* @return $this
*/
public function setNumber(string $number): static
{
$this->number = $number;
+
return $this;
}
- /**
- * @return int
- */
public function getType(): int
{
return $this->type;
}
/**
- * @param int $type
* @return $this
*/
public function setType(int $type): static
{
$this->type = $type;
+
return $this;
}
}
diff --git a/src/Rede/QrCode.php b/src/Rede/QrCode.php
new file mode 100644
index 0000000..b320e00
--- /dev/null
+++ b/src/Rede/QrCode.php
@@ -0,0 +1,118 @@
+
+ */
+ public function jsonSerialize(): array
+ {
+ return [
+ 'dateTimeExpiration' => $this->getDateTimeExpiration()?->format('c') ?: null,
+ ];
+ }
+
+ public function getDateTimeExpiration(): ?\DateTimeInterface
+ {
+ return $this->dateTimeExpiration;
+ }
+
+ public function setDateTimeExpiration(\DateTimeInterface $dateTimeExpiration): static
+ {
+ $this->dateTimeExpiration = $dateTimeExpiration;
+
+ return $this;
+ }
+
+ public function getDateTime(): ?\DateTimeInterface
+ {
+ return $this->dateTime;
+ }
+
+ public function getExpirationQrCode(): ?\DateTimeInterface
+ {
+ return $this->expirationQrCode;
+ }
+
+ public function getQrCodeImage(): ?string
+ {
+ return $this->qrCodeImage;
+ }
+
+ public function getQrCodeData(): ?string
+ {
+ return $this->qrCodeData;
+ }
+
+ public function getReturnCode(): ?string
+ {
+ return $this->returnCode;
+ }
+
+ public function getReturnMessage(): ?string
+ {
+ return $this->returnMessage;
+ }
+
+ public function getAffiliation(): int|string|null
+ {
+ return $this->affiliation;
+ }
+
+ public function getKind(): ?string
+ {
+ return $this->kind;
+ }
+
+ public function getReference(): ?string
+ {
+ return $this->reference;
+ }
+
+ public function getAmount(): int|string|null
+ {
+ return $this->amount;
+ }
+
+ public function getTid(): ?string
+ {
+ return $this->tid;
+ }
+
+ public function getStatus(): ?string
+ {
+ return $this->status;
+ }
+}
diff --git a/src/Rede/RedeSerializable.php b/src/Rede/RedeSerializable.php
index 44b6af6..909ca5d 100644
--- a/src/Rede/RedeSerializable.php
+++ b/src/Rede/RedeSerializable.php
@@ -2,8 +2,6 @@
namespace Rede;
-use JsonSerializable;
-
-interface RedeSerializable extends JsonSerializable
+interface RedeSerializable extends \JsonSerializable
{
}
diff --git a/src/Rede/RedeUnserializable.php b/src/Rede/RedeUnserializable.php
index 34a1245..0ef20f8 100644
--- a/src/Rede/RedeUnserializable.php
+++ b/src/Rede/RedeUnserializable.php
@@ -5,8 +5,6 @@
interface RedeUnserializable
{
/**
- * @param string $serialized
- *
* @return $this
*/
public function jsonUnserialize(string $serialized): static;
diff --git a/src/Rede/Refund.php b/src/Rede/Refund.php
index 6b2b37b..9d8924f 100644
--- a/src/Rede/Refund.php
+++ b/src/Rede/Refund.php
@@ -2,107 +2,77 @@
namespace Rede;
-use DateTime;
-use Exception;
-
class Refund
{
use CreateTrait;
- /**
- * @var int|null
- */
private ?int $amount = null;
- /**
- * @var DateTime|null
- */
- private ?DateTime $refundDateTime = null;
+ private ?\DateTime $refundDateTime = null;
- /**
- * @var string|null
- */
private ?string $refundId = null;
- /**
- * @var string|null
- */
private ?string $status = null;
- /**
- * @return int|null
- */
public function getAmount(): ?int
{
return $this->amount;
}
/**
- * @param int $amount
- *
* @return $this
*/
public function setAmount(int $amount): static
{
$this->amount = $amount;
+
return $this;
}
- /**
- * @return DateTime|null
- */
- public function getRefundDateTime(): ?DateTime
+ public function getRefundDateTime(): ?\DateTime
{
return $this->refundDateTime;
}
/**
- * @param string $refundDateTime
- *
* @return $this
- * @throws Exception
+ *
+ * @throws \Exception
*/
public function setRefundDateTime(string $refundDateTime): static
{
- $this->refundDateTime = new DateTime($refundDateTime);
+ $this->refundDateTime = new \DateTime($refundDateTime);
+
return $this;
}
- /**
- * @return string|null
- */
public function getRefundId(): ?string
{
return $this->refundId;
}
/**
- * @param string $refundId
- *
* @return $this
*/
public function setRefundId(string $refundId): static
{
$this->refundId = $refundId;
+
return $this;
}
- /**
- * @return string|null
- */
public function getStatus(): ?string
{
return $this->status;
}
/**
- * @param string $status
- *
* @return $this
*/
public function setStatus(string $status): static
{
$this->status = $status;
+
return $this;
}
}
diff --git a/src/Rede/SerializeTrait.php b/src/Rede/SerializeTrait.php
index c306ff5..b81a80e 100644
--- a/src/Rede/SerializeTrait.php
+++ b/src/Rede/SerializeTrait.php
@@ -10,7 +10,7 @@ trait SerializeTrait
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this), function ($value) {
- return $value !== null;
+ return null !== $value;
});
}
}
diff --git a/src/Rede/Service/AbstractService.php b/src/Rede/Service/AbstractService.php
index 0a9af10..297660b 100644
--- a/src/Rede/Service/AbstractService.php
+++ b/src/Rede/Service/AbstractService.php
@@ -2,45 +2,32 @@
namespace Rede\Service;
-use CurlHandle;
-use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Rede\eRede;
use Rede\Exception\RedeException;
use Rede\Store;
use Rede\Transaction;
-use RuntimeException;
abstract class AbstractService
{
public const GET = 'GET';
+
public const POST = 'POST';
+
public const PUT = 'PUT';
- /**
- * @var string|null
- */
private ?string $platform = null;
- /**
- * @var string|null
- */
private ?string $platformVersion = null;
/**
* AbstractService constructor.
- *
- * @param Store $store
- * @param LoggerInterface|null $logger
*/
public function __construct(protected Store $store, protected ?LoggerInterface $logger = null)
{
}
/**
- * @param string|null $platform
- * @param string|null $platformVersion
- *
* @return $this
*/
public function platform(?string $platform, ?string $platformVersion): static
@@ -52,19 +39,14 @@ public function platform(?string $platform, ?string $platformVersion): static
}
/**
- * @return Transaction
- * @throws InvalidArgumentException
- * @throws RuntimeException
+ * @throws \InvalidArgumentException
+ * @throws \RuntimeException
* @throws RedeException
*/
abstract public function execute(): Transaction;
/**
- * @param string $body
- * @param string $method
- *
- * @return Transaction
- * @throws RuntimeException
+ * @throws \RuntimeException
*/
protected function sendRequest(string $body = '', string $method = 'GET'): Transaction
{
@@ -76,13 +58,13 @@ protected function sendRequest(string $body = '', string $method = 'GET'): Trans
$userAgent
),
'Accept: application/json',
- 'Transaction-Response: brand-return-opened'
+ 'Transaction-Response: brand-return-opened',
];
$curl = curl_init($this->store->getEnvironment()->getEndpoint($this->getService()));
- if (!$curl instanceof CurlHandle) {
- throw new RuntimeException('Was not possible to create a curl instance.');
+ if (!$curl instanceof \CurlHandle) {
+ throw new \RuntimeException('Was not possible to create a curl instance.');
}
curl_setopt(
@@ -104,7 +86,7 @@ protected function sendRequest(string $body = '', string $method = 'GET'): Trans
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
}
- if ($body !== '') {
+ if ('' !== $body) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$headers[] = 'Content-Type: application/json; charset=utf8';
@@ -141,11 +123,11 @@ protected function sendRequest(string $body = '', string $method = 'GET'): Trans
$this->dumpHttpInfo($httpInfo);
if (curl_errno($curl)) {
- throw new RuntimeException(sprintf('Curl error[%s]: %s', curl_errno($curl), curl_error($curl)));
+ throw new \RuntimeException(sprintf('Curl error[%s]: %s', curl_errno($curl), curl_error($curl)));
}
if (!is_string($response)) {
- throw new RuntimeException('Error obtaining a response from the API');
+ throw new \RuntimeException('Error obtaining a response from the API');
}
curl_close($curl);
@@ -155,8 +137,6 @@ protected function sendRequest(string $body = '', string $method = 'GET'): Trans
/**
* Gets the User-Agent string.
- *
- * @return string
*/
private function getUserAgent(): string
{
@@ -195,10 +175,10 @@ private function getUserAgent(): string
abstract protected function getService(): string;
/**
- * Dumps the httpInfo log
+ * Dumps the httpInfo log.
+ *
+ * @param array $httpInfo the http info
*
- * @param array $httpInfo The http info.
- * @return void
* @noinspection PhpPluralMixedCanBeReplacedWithArrayInspection
*/
private function dumpHttpInfo(array $httpInfo): void
@@ -219,8 +199,6 @@ private function dumpHttpInfo(array $httpInfo): void
/**
* @param string $response Parses the HTTP response from Rede
* @param int $statusCode The HTTP status code
- *
- * @return Transaction
*/
abstract protected function parseResponse(string $response, int $statusCode): Transaction;
}
diff --git a/src/Rede/Service/AbstractTransactionsService.php b/src/Rede/Service/AbstractTransactionsService.php
index 457a9c7..17c3b26 100644
--- a/src/Rede/Service/AbstractTransactionsService.php
+++ b/src/Rede/Service/AbstractTransactionsService.php
@@ -2,34 +2,21 @@
namespace Rede\Service;
-use Exception;
-use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Rede\Exception\RedeException;
use Rede\Store;
use Rede\Transaction;
-use RuntimeException;
abstract class AbstractTransactionsService extends AbstractService
{
- /**
- * @var ?Transaction
- */
protected ?Transaction $transaction;
- /**
- * @var string
- */
private string $tid;
/**
* AbstractTransactionsService constructor.
- *
- * @param Store $store
- * @param Transaction|null $transaction
- * @param LoggerInterface|null $logger
*/
- public function __construct(Store $store, Transaction $transaction = null, LoggerInterface $logger = null)
+ public function __construct(Store $store, ?Transaction $transaction = null, ?LoggerInterface $logger = null)
{
parent::__construct($store, $logger);
@@ -37,9 +24,8 @@ public function __construct(Store $store, Transaction $transaction = null, Logge
}
/**
- * @return Transaction
- * @throws InvalidArgumentException
- * @throws RuntimeException
+ * @throws \InvalidArgumentException
+ * @throws \RuntimeException
* @throws RedeException
*/
public function execute(): Transaction
@@ -47,32 +33,28 @@ public function execute(): Transaction
$json = json_encode($this->transaction);
if (!is_string($json)) {
- throw new RuntimeException('Problem converting the Transaction object to json');
+ throw new \RuntimeException('Problem converting the Transaction object to json');
}
return $this->sendRequest($json, AbstractService::POST);
}
- /**
- * @return string
- */
public function getTid(): string
{
return $this->tid;
}
/**
- * @param string $tid
* @return $this
*/
public function setTid(string $tid): static
{
$this->tid = $tid;
+
return $this;
}
/**
- * @return string
* @see AbstractService::getService()
*/
protected function getService(): string
@@ -81,35 +63,28 @@ protected function getService(): string
}
/**
- * @param string $response
- * @param int $statusCode
- *
- * @return Transaction
* @throws RedeException
- * @throws InvalidArgumentException
- * @throws Exception
+ * @throws \InvalidArgumentException
+ * @throws \Exception
+ *
* @see AbstractService::parseResponse()
*/
protected function parseResponse(string $response, int $statusCode): Transaction
{
$previous = null;
- if ($this->transaction === null) {
+ if (null === $this->transaction) {
$this->transaction = new Transaction();
}
try {
$this->transaction->jsonUnserialize($response);
- } catch (InvalidArgumentException $e) {
+ } catch (\InvalidArgumentException $e) {
$previous = $e;
}
if ($statusCode >= 400) {
- throw new RedeException(
- $this->transaction->getReturnMessage() ?? 'Error on getting the content from the API',
- (int)$this->transaction->getReturnCode(),
- $previous
- );
+ throw new RedeException($this->transaction->getReturnMessage() ?? 'Error on getting the content from the API', (int) $this->transaction->getReturnCode(), $previous);
}
return $this->transaction;
diff --git a/src/Rede/Service/CancelTransactionService.php b/src/Rede/Service/CancelTransactionService.php
index b35dbce..4af3ceb 100644
--- a/src/Rede/Service/CancelTransactionService.php
+++ b/src/Rede/Service/CancelTransactionService.php
@@ -2,17 +2,12 @@
namespace Rede\Service;
-use RuntimeException;
-
class CancelTransactionService extends AbstractTransactionsService
{
- /**
- * @return string
- */
protected function getService(): string
{
- if ($this->transaction === null) {
- throw new RuntimeException('Transaction was not defined yet');
+ if (null === $this->transaction) {
+ throw new \RuntimeException('Transaction was not defined yet');
}
return sprintf('%s/%s/refunds', parent::getService(), $this->transaction->getTid());
diff --git a/src/Rede/Service/CaptureTransactionService.php b/src/Rede/Service/CaptureTransactionService.php
index e35eac1..1070af5 100644
--- a/src/Rede/Service/CaptureTransactionService.php
+++ b/src/Rede/Service/CaptureTransactionService.php
@@ -2,17 +2,14 @@
namespace Rede\Service;
-use InvalidArgumentException;
use Rede\Exception\RedeException;
use Rede\Transaction;
-use RuntimeException;
class CaptureTransactionService extends AbstractTransactionsService
{
/**
- * @return Transaction
- * @throws InvalidArgumentException
- * @throws RuntimeException
+ * @throws \InvalidArgumentException
+ * @throws \RuntimeException
* @throws RedeException
*/
public function execute(): Transaction
@@ -20,19 +17,16 @@ public function execute(): Transaction
$json = json_encode($this->transaction);
if (!is_string($json)) {
- throw new RuntimeException('Problem converting the Transaction object to json');
+ throw new \RuntimeException('Problem converting the Transaction object to json');
}
return $this->sendRequest($json, AbstractService::PUT);
}
- /**
- * @return string
- */
protected function getService(): string
{
- if ($this->transaction === null) {
- throw new RuntimeException('Transaction was not defined yet');
+ if (null === $this->transaction) {
+ throw new \RuntimeException('Transaction was not defined yet');
}
return sprintf('%s/%s', parent::getService(), $this->transaction->getTid());
diff --git a/src/Rede/Service/GetTransactionService.php b/src/Rede/Service/GetTransactionService.php
index 0a2ab31..b50180b 100644
--- a/src/Rede/Service/GetTransactionService.php
+++ b/src/Rede/Service/GetTransactionService.php
@@ -2,27 +2,18 @@
namespace Rede\Service;
-use InvalidArgumentException;
use Rede\Exception\RedeException;
use Rede\Transaction;
-use RuntimeException;
class GetTransactionService extends AbstractTransactionsService
{
- /**
- * @var ?string
- */
private ?string $reference = null;
- /**
- * @var bool
- */
private bool $refund = false;
/**
- * @return Transaction
- * @throws InvalidArgumentException
- * @throws RuntimeException
+ * @throws \InvalidArgumentException
+ * @throws \RuntimeException
* @throws RedeException
*/
public function execute(): Transaction
@@ -31,19 +22,16 @@ public function execute(): Transaction
}
/**
- * @param string $reference
- *
* @return $this
*/
public function setReference(string $reference): static
{
$this->reference = $reference;
+
return $this;
}
/**
- * @param bool $refund
- *
* @return $this
*/
public function setRefund(bool $refund = true): static
@@ -53,12 +41,9 @@ public function setRefund(bool $refund = true): static
return $this;
}
- /**
- * @return string
- */
protected function getService(): string
{
- if ($this->reference !== null) {
+ if (null !== $this->reference) {
return sprintf('%s?reference=%s', parent::getService(), $this->reference);
}
diff --git a/src/Rede/Store.php b/src/Rede/Store.php
index ef56f19..37ee466 100644
--- a/src/Rede/Store.php
+++ b/src/Rede/Store.php
@@ -6,76 +6,61 @@ class Store
{
/**
* Which environment will this store used for?
- * @var Environment
*/
private Environment $environment;
/**
* Creates a store.
*
- * @param string $filiation
- * @param string $token
- * @param Environment|null $environment if none provided, production will be used.
+ * @param Environment|null $environment if none provided, production will be used
*/
public function __construct(private string $filiation, private string $token, ?Environment $environment = null)
{
$this->environment = $environment ?? Environment::production();
}
- /**
- * @return Environment
- */
public function getEnvironment(): Environment
{
return $this->environment;
}
/**
- * @param Environment $environment
- *
* @return $this
*/
public function setEnvironment(Environment $environment): static
{
$this->environment = $environment;
+
return $this;
}
- /**
- * @return string
- */
public function getFiliation(): string
{
return $this->filiation;
}
/**
- * @param string $filiation
- *
* @return $this
*/
public function setFiliation(string $filiation): static
{
$this->filiation = $filiation;
+
return $this;
}
- /**
- * @return string
- */
public function getToken(): string
{
return $this->token;
}
/**
- * @param string $token
- *
* @return $this
*/
public function setToken(string $token): static
{
$this->token = $token;
+
return $this;
}
}
diff --git a/src/Rede/SubMerchant.php b/src/Rede/SubMerchant.php
index c42f920..d4b9a26 100644
--- a/src/Rede/SubMerchant.php
+++ b/src/Rede/SubMerchant.php
@@ -6,66 +6,53 @@ class SubMerchant
{
/**
* SubMerchant constructor.
- *
- * @param string $mcc
- * @param string $city
- * @param string $country
*/
public function __construct(private string $mcc, private string $city, private string $country)
{
}
- /**
- * @return string
- */
public function getMcc(): string
{
return $this->mcc;
}
/**
- * @param string $mcc
* @return $this
*/
public function setMcc(string $mcc): static
{
$this->mcc = $mcc;
+
return $this;
}
- /**
- * @return string
- */
public function getCity(): string
{
return $this->city;
}
/**
- * @param string $city
* @return $this
*/
public function setCity(string $city): static
{
$this->city = $city;
+
return $this;
}
- /**
- * @return string
- */
public function getCountry(): string
{
return $this->country;
}
/**
- * @param string $country
* @return $this
*/
public function setCountry(string $country): static
{
$this->country = $country;
+
return $this;
}
}
diff --git a/src/Rede/ThreeDSecure.php b/src/Rede/ThreeDSecure.php
index 0db16da..afe0ab4 100644
--- a/src/Rede/ThreeDSecure.php
+++ b/src/Rede/ThreeDSecure.php
@@ -10,81 +10,52 @@ class ThreeDSecure implements RedeSerializable
public const DATA_ONLY = 'DATA_ONLY';
public const CONTINUE_ON_FAILURE = 'continue';
+
public const DECLINE_ON_FAILURE = 'decline';
public const MPI_REDE = 'mpi_rede';
+
public const MPI_THIRD_PARTY = 'mpi_third_party';
- /**
- * @var string|null
- */
private ?string $cavv = null;
- /**
- * @var string|null
- */
private ?string $eci = null;
- /**
- * @var string|null
- */
private ?string $url = null;
- /**
- * @var string|null
- */
private ?string $xid = null;
- /**
- * @var int
- */
private int $threeDIndicator = 2;
- /**
- * @var string|null
- */
- private ?string $DirectoryServerTransactionId = null;
+ private ?string $directoryServerTransactionId = null;
+
+ private ?string $ipAddress = null;
- /**
- * @var string
- */
private string $userAgent;
- /**
- * @var bool
- */
private bool $embedded;
- /**
- * @var string|null
- */
private ?string $returnCode = null;
- /**
- * @var string|null
- */
private ?string $returnMessage = null;
- /**
- * @var string|null
- */
private ?string $challengePreference = null;
/**
* ThreeDSecure constructor.
*
- * @param Device|null $Device User device data.
- * @param string $onFailure What to do in case of failure.
- * @param string $mpi The MPI is from Rede or third party.
- * @param string|null $userAgent The user' user-agent.
+ * @param Device|null $device user device data
+ * @param string $onFailure what to do in case of failure
+ * @param string $mpi the MPI is from Rede or third party
+ * @param string|null $userAgent the user' user-agent
*/
public function __construct(
- private readonly ?Device $Device = null,
+ private readonly ?Device $device = null,
private string $onFailure = self::DECLINE_ON_FAILURE,
string $mpi = ThreeDSecure::MPI_REDE,
- string $userAgent = null
+ ?string $userAgent = null,
) {
- if ($userAgent === null) {
+ if (null === $userAgent) {
$userAgent = eRede::USER_AGENT;
if (isset($_SERVER['HTTP_USER_AGENT'])) {
@@ -92,50 +63,36 @@ public function __construct(
}
}
- $this->embedded = $mpi === ThreeDSecure::MPI_REDE;
+ $this->embedded = ThreeDSecure::MPI_REDE === $mpi;
$this->userAgent = $userAgent;
}
- /**
- * @return string|null
- */
public function getReturnCode(): ?string
{
return $this->returnCode;
}
- /**
- * @return string|null
- */
public function getReturnMessage(): ?string
{
return $this->returnMessage;
}
- /**
- * @return Device
- */
- public function getDevice(): Device
+ public function getDevice(): ?Device
{
- return $this->Device;
+ return $this->device;
}
- /**
- * @return int
- */
public function getThreeDIndicator(): int
{
return $this->threeDIndicator;
}
/**
- * @param int $threeDIndicator
- *
* @return $this
*/
public function setThreeDIndicator(int $threeDIndicator): static
{
- /**
+ /*
* Support for 3DS 1 will be discontinued.
*/
if ($threeDIndicator < 2) {
@@ -150,173 +107,147 @@ public function setThreeDIndicator(int $threeDIndicator): static
return $this;
}
- /**
- * @return string|null
- */
public function getDirectoryServerTransactionId(): ?string
{
- return $this->DirectoryServerTransactionId;
+ return $this->directoryServerTransactionId;
}
/**
- * @param string $DirectoryServerTransactionId
- *
* @return $this
*/
- public function setDirectoryServerTransactionId(string $DirectoryServerTransactionId): static
+ public function setDirectoryServerTransactionId(string $directoryServerTransactionId): static
{
- $this->DirectoryServerTransactionId = $DirectoryServerTransactionId;
+ $this->directoryServerTransactionId = $directoryServerTransactionId;
+
return $this;
}
- /**
- * @return string|null
- */
public function getCavv(): ?string
{
return $this->cavv;
}
/**
- * @param string $cavv
- *
* @return $this
*/
public function setCavv(string $cavv): static
{
$this->cavv = $cavv;
+
return $this;
}
- /**
- * @return string|null
- */
public function getEci(): ?string
{
return $this->eci;
}
/**
- * @param string $eci
- *
* @return $this
*/
public function setEci(string $eci): static
{
$this->eci = $eci;
+
return $this;
}
- /**
- * @return string
- */
public function getOnFailure(): string
{
return $this->onFailure;
}
/**
- * @param string $onFailure
- *
* @return $this
*/
public function setOnFailure(string $onFailure): static
{
$this->onFailure = $onFailure;
+
return $this;
}
- /**
- * @return string|null
- */
public function getUrl(): ?string
{
return $this->url;
}
/**
- * @param string $url
- *
* @return $this
*/
public function setUrl(string $url): static
{
$this->url = $url;
+
+ return $this;
+ }
+
+ public function getIpAddress(): ?string
+ {
+ return $this->ipAddress;
+ }
+
+ public function setIpAddress(string $ipAddress): static
+ {
+ $this->ipAddress = $ipAddress;
+
return $this;
}
- /**
- * @return string|null
- */
public function getUserAgent(): ?string
{
return $this->userAgent;
}
/**
- * @param string $userAgent
- *
* @return $this
*/
public function setUserAgent(string $userAgent): static
{
$this->userAgent = $userAgent;
+
return $this;
}
- /**
- * @return string|null
- */
public function getXid(): ?string
{
return $this->xid;
}
/**
- * @param string $xid
- *
* @return $this
*/
public function setXid(string $xid): static
{
$this->xid = $xid;
+
return $this;
}
- /**
- * @return bool
- */
public function isEmbedded(): bool
{
return $this->embedded;
}
/**
- * @param bool $embedded
- *
* @return $this
*/
public function setEmbedded(bool $embedded): static
{
$this->embedded = $embedded;
+
return $this;
}
- /**
- * @return string|null
- */
public function getChallengePreference(): ?string
{
return $this->challengePreference;
}
- /**
- * @param string|null $challengePreference
- * @return ThreeDSecure
- */
public function setChallengePreference(?string $challengePreference): ThreeDSecure
{
$this->challengePreference = $challengePreference;
+
return $this;
}
}
diff --git a/src/Rede/Transaction.php b/src/Rede/Transaction.php
index 8e8c5b2..2cff921 100644
--- a/src/Rede/Transaction.php
+++ b/src/Rede/Transaction.php
@@ -2,133 +2,64 @@
namespace Rede;
-use ArrayIterator;
-use DateTime;
-use Exception;
-use InvalidArgumentException;
-
class Transaction implements RedeSerializable, RedeUnserializable
{
public const CREDIT = 'credit';
+
public const DEBIT = 'debit';
+ public const PIX = 'Pix';
+
public const ORIGIN_EREDE = 1;
+
public const ORIGIN_VISA_CHECKOUT = 4;
+
public const ORIGIN_MASTERPASS = 6;
- /**
- * @var Additional|null
- */
private ?Additional $additional = null;
- /**
- * @var Authorization|null
- */
private ?Authorization $authorization = null;
- /**
- * @var string|null
- */
private ?string $authorizationCode = null;
- /**
- * @var int|null
- */
private ?int $brandTid = null;
- /**
- * @var Brand|null
- */
private ?Brand $brand = null;
- /**
- * @var string|null
- */
private ?string $cancelId = null;
- /**
- * @var bool|Capture|null
- */
private bool|Capture|null $capture = null;
- /**
- * @var string|null
- */
private ?string $cardBin = null;
- /**
- * @var string|null
- */
private ?string $cardHolderName = null;
- /**
- * @var string|null
- */
private ?string $cardNumber = null;
- /**
- * @var Cart|null
- */
private ?Cart $cart = null;
- /**
- * @var DateTime|null
- */
- private ?DateTime $dateTime = null;
+ private ?\DateTime $dateTime = null;
- /**
- * @var int|null
- */
private ?int $distributorAffiliation = null;
- /**
- * @var int|string|null
- */
private int|string|null $expirationMonth = null;
- /**
- * @var int|string|null
- */
private int|string|null $expirationYear = null;
- /**
- * @var Iata|null
- */
private ?Iata $iata = null;
- /**
- * @var int|null
- */
private ?int $installments = null;
- /**
- * @var string|null
- */
private ?string $kind = null;
- /**
- * @var string|null
- */
private ?string $last4 = null;
- /**
- * @var string|null
- */
private ?string $nsu = null;
- /**
- * @var int|null
- */
private ?int $origin = null;
- /**
- * @var DateTime|null
- */
- private ?DateTime $refundDateTime = null;
+ private ?\DateTime $refundDateTime = null;
- /**
- * @var string|null
- */
private ?string $refundId = null;
/**
@@ -136,49 +67,22 @@ class Transaction implements RedeSerializable, RedeUnserializable
*/
private array $refunds = [];
- /**
- * @var DateTime|null
- */
- private ?DateTime $requestDateTime = null;
+ private ?\DateTime $requestDateTime = null;
- /**
- * @var string|null
- */
private ?string $returnCode = null;
- /**
- * @var string|null
- */
private ?string $returnMessage = null;
- /**
- * @var string|null
- */
private ?string $securityCode = null;
- /**
- * @var string|null
- */
private ?string $softDescriptor = null;
- /**
- * @var int|null
- */
private ?int $storageCard = null;
- /**
- * @var bool
- */
private ?bool $subscription = null;
- /**
- * @var ThreeDSecure|null
- */
private ?ThreeDSecure $threeDSecure = null;
- /**
- * @var string|null
- */
private ?string $tid = null;
/**
@@ -186,38 +90,25 @@ class Transaction implements RedeSerializable, RedeUnserializable
*/
private array $urls = [];
- /**
- * @var SubMerchant|null
- */
private ?SubMerchant $subMerchant = null;
- /**
- * @var string|null
- */
private ?string $paymentFacilitatorID = null;
- /**
- * @var int|null
- */
private ?int $amount = null;
+ private ?QrCode $qrCode = null;
+
/**
* Transaction constructor.
- *
- * @param int|float|null $amount
- * @param string|null $reference
*/
public function __construct(int|float|null $amount = null, private ?string $reference = null)
{
- if ($amount !== null) {
+ if (null !== $amount) {
$this->setAmount($amount);
}
}
/**
- * @param string $url
- * @param string $kind
- *
* @return $this
*/
public function addUrl(string $url, string $kind = Url::CALLBACK): static
@@ -228,20 +119,17 @@ public function addUrl(string $url, string $kind = Url::CALLBACK): static
}
/**
- * @param int|null $gateway
- * @param int|null $module
- *
* @return $this
*/
public function additional(?int $gateway = null, ?int $module = null): static
{
$this->additional = new Additional();
- if ($gateway !== null) {
+ if (null !== $gateway) {
$this->additional->setGateway($gateway);
}
- if ($module !== null) {
+ if (null !== $module) {
$this->additional->setModule($module);
}
@@ -249,12 +137,6 @@ public function additional(?int $gateway = null, ?int $module = null): static
}
/**
- * @param string $cardNumber
- * @param string $cardCvv
- * @param int|string $expirationMonth
- * @param int|string $expirationYear
- * @param string $holderName
- *
* @return $this this transaction
*/
public function creditCard(
@@ -262,7 +144,7 @@ public function creditCard(
string $cardCvv,
int|string $expirationMonth,
int|string $expirationYear,
- string $holderName
+ string $holderName,
): static {
return $this->setCard(
$cardNumber,
@@ -275,13 +157,6 @@ public function creditCard(
}
/**
- * @param string $cardNumber
- * @param string $securityCode
- * @param int|string $expirationMonth
- * @param int|string $expirationYear
- * @param string $cardHolderName
- * @param string $kind
- *
* @return $this this transaction
*/
public function setCard(
@@ -290,7 +165,7 @@ public function setCard(
int|string $expirationMonth,
int|string $expirationYear,
string $cardHolderName,
- string $kind
+ string $kind,
): static {
$this->setCardNumber($cardNumber);
$this->setSecurityCode($securityCode);
@@ -303,12 +178,6 @@ public function setCard(
}
/**
- * @param string $cardNumber
- * @param string $cardCvv
- * @param int|string $expirationMonth
- * @param int|string $expirationYear
- * @param string $holderName
- *
* @return $this this transaction
*/
public function debitCard(
@@ -316,7 +185,7 @@ public function debitCard(
string $cardCvv,
int|string $expirationMonth,
int|string $expirationYear,
- string $holderName
+ string $holderName,
): static {
$this->capture();
@@ -331,23 +200,22 @@ public function debitCard(
}
/**
- * @param bool $capture
- *
* @return $this
*/
public function capture(bool $capture = true): static
{
- if (!$capture && $this->kind === Transaction::DEBIT) {
- throw new InvalidArgumentException('Debit transactions will always be captured');
+ if (!$capture && Transaction::DEBIT === $this->kind) {
+ throw new \InvalidArgumentException('Debit transactions will always be captured');
}
$this->capture = $capture;
+
return $this;
}
/**
- * @return mixed
* @see \JsonSerializable::jsonSerialize()
+ *
* @noinspection PhpMixedReturnTypeCanBeReducedInspection
*/
public function jsonSerialize(): mixed
@@ -377,9 +245,10 @@ public function jsonSerialize(): mixed
'origin' => $this->origin,
'distributorAffiliation' => $this->distributorAffiliation,
'storageCard' => $this->storageCard,
- 'urls' => $this->urls,
+ 'urls' => $this->urls ?: null,
'iata' => $this->iata,
- 'additional' => $this->additional
+ 'additional' => $this->additional,
+ 'qrCode' => $this->qrCode,
],
function ($value) {
return !is_null($value);
@@ -387,199 +256,168 @@ function ($value) {
);
}
- /**
- * @return int|null
- */
+ public function getQrCode(): ?QrCode
+ {
+ return $this->qrCode;
+ }
+
+ public function setQrCode(QrCode $qrCode): static
+ {
+ $this->qrCode = $qrCode;
+
+ return $this;
+ }
+
+ public function createQrCode(\DateTimeInterface $dateTimeExpiration): static
+ {
+ $this->qrCode = new QrCode();
+ $this->qrCode->setDateTimeExpiration($dateTimeExpiration);
+ $this->setKind(Transaction::PIX);
+
+ return $this;
+ }
+
public function getAmount(): ?int
{
return $this->amount;
}
/**
- * @param int|float $amount
- *
* @return $this
*/
public function setAmount(int|float $amount): static
{
- $this->amount = (int)round($amount * 100);
+ $this->amount = (int) round($amount * 100);
+
return $this;
}
- /**
- * @return Authorization|null
- */
public function getAuthorization(): ?Authorization
{
return $this->authorization;
}
- /**
- * @return string|null
- */
public function getAuthorizationCode(): ?string
{
return $this->authorizationCode;
}
- /**
- * @return string|null
- */
public function getCancelId(): ?string
{
return $this->cancelId;
}
- /**
- * @return bool|Capture|null
- */
public function getCapture(): bool|Capture|null
{
return $this->capture;
}
- /**
- * @return string|null
- */
public function getCardBin(): ?string
{
return $this->cardBin;
}
- /**
- * @return string|null
- */
public function getCardHolderName(): ?string
{
return $this->cardHolderName;
}
/**
- * @param string $cardHolderName
- *
* @return $this
*/
public function setCardHolderName(string $cardHolderName): static
{
$this->cardHolderName = $cardHolderName;
+
return $this;
}
- /**
- * @return string|null
- */
public function getCardNumber(): ?string
{
return $this->cardNumber;
}
/**
- * @param string $cardNumber
- *
* @return $this
*/
public function setCardNumber(string $cardNumber): static
{
$this->cardNumber = $cardNumber;
+
return $this;
}
- /**
- * @return Cart|null
- */
public function getCart(): ?Cart
{
return $this->cart;
}
/**
- * @param Cart $cart
- *
* @return $this
*/
public function setCart(Cart $cart): static
{
$this->cart = $cart;
+
return $this;
}
- /**
- * @return DateTime|null
- */
- public function getDateTime(): ?DateTime
+ public function getDateTime(): ?\DateTime
{
return $this->dateTime;
}
- /**
- * @return int|null
- */
public function getDistributorAffiliation(): ?int
{
return $this->distributorAffiliation;
}
/**
- * @param int $distributorAffiliation
- *
* @return $this
*/
public function setDistributorAffiliation(int $distributorAffiliation): static
{
$this->distributorAffiliation = $distributorAffiliation;
+
return $this;
}
- /**
- * @return int|string|null
- */
public function getExpirationMonth(): int|string|null
{
return $this->expirationMonth;
}
/**
- * @param int|string $expirationMonth
- *
* @return $this
*/
public function setExpirationMonth(int|string $expirationMonth): static
{
$this->expirationMonth = $expirationMonth;
+
return $this;
}
- /**
- * @return int|string|null
- */
public function getExpirationYear(): int|string|null
{
return $this->expirationYear;
}
/**
- * @param int|string $expirationYear
- *
* @return $this
*/
public function setExpirationYear(int|string $expirationYear): static
{
$this->expirationYear = $expirationYear;
+
return $this;
}
- /**
- * @return Iata|null
- */
public function getIata(): ?Iata
{
return $this->iata;
}
/**
- * @param string $code
- * @param string $departureTax
- *
* @return $this
*/
public function setIata(string $code, string $departureTax): static
@@ -591,109 +429,81 @@ public function setIata(string $code, string $departureTax): static
return $this;
}
- /**
- * @return int|null
- */
public function getInstallments(): ?int
{
return $this->installments;
}
/**
- * @param int $installments
- *
* @return $this
*/
public function setInstallments(int $installments): static
{
$this->installments = $installments;
+
return $this;
}
- /**
- * @return string|null
- */
public function getKind(): ?string
{
return $this->kind;
}
/**
- * @param string $kind
- *
* @return $this
*/
public function setKind(string $kind): static
{
$this->kind = $kind;
+
return $this;
}
- /**
- * @return string|null
- */
public function getLast4(): ?string
{
return $this->last4;
}
- /**
- * @return string|null
- */
public function getNsu(): ?string
{
return $this->nsu;
}
- /**
- * @return int|null
- */
public function getOrigin(): ?int
{
return $this->origin;
}
/**
- * @param int $origin
- *
* @return $this
*/
public function setOrigin(int $origin): static
{
$this->origin = $origin;
+
return $this;
}
- /**
- * @return string|null
- */
public function getReference(): ?string
{
return $this->reference;
}
/**
- * @param string $reference
- *
* @return $this
*/
public function setReference(string $reference): static
{
$this->reference = $reference;
+
return $this;
}
- /**
- * @return DateTime|null
- */
- public function getRefundDateTime(): ?DateTime
+ public function getRefundDateTime(): ?\DateTime
{
return $this->refundDateTime;
}
- /**
- * @return string|null
- */
public function getRefundId(): ?string
{
return $this->refundId;
@@ -707,91 +517,67 @@ public function getRefunds(): array
return $this->refunds;
}
- /**
- * @return DateTime|null
- */
- public function getRequestDateTime(): ?DateTime
+ public function getRequestDateTime(): ?\DateTime
{
return $this->requestDateTime;
}
- /**
- * @return string|null
- */
public function getReturnCode(): ?string
{
return $this->returnCode;
}
- /**
- * @return string|null
- */
public function getReturnMessage(): ?string
{
return $this->returnMessage;
}
- /**
- * @return string|null
- */
public function getSecurityCode(): ?string
{
return $this->securityCode;
}
/**
- * @param string $securityCode
- *
* @return $this
*/
public function setSecurityCode(string $securityCode): static
{
$this->securityCode = $securityCode;
+
return $this;
}
- /**
- * @return string|null
- */
public function getSoftDescriptor(): ?string
{
return $this->softDescriptor;
}
/**
- * @param string $softDescriptor
- *
* @return $this
*/
public function setSoftDescriptor(string $softDescriptor): static
{
$this->softDescriptor = $softDescriptor;
+
return $this;
}
- /**
- * @return int|null
- */
public function getStorageCard(): ?int
{
return $this->storageCard;
}
/**
- * @param int $storageCard
- *
* @return $this
*/
public function setStorageCard(int $storageCard): static
{
$this->storageCard = $storageCard;
+
return $this;
}
/**
- * @param string $code
- * @param string $departureTax
- *
* @return $this
*/
public function iata(string $code, string $departureTax): static
@@ -799,65 +585,50 @@ public function iata(string $code, string $departureTax): static
return $this->setIata($code, $departureTax);
}
- /**
- * @return bool
- */
public function isSubscription(): bool
{
return $this->subscription ?? false;
}
/**
- * @param bool $subscription
- *
* @return $this
*/
public function setSubscription(bool $subscription): static
{
$this->subscription = $subscription;
+
return $this;
}
- /**
- * @return ThreeDSecure
- */
public function getThreeDSecure(): ThreeDSecure
{
return $this->threeDSecure ?? new ThreeDSecure();
}
- /**
- * @return string|null
- */
public function getTid(): ?string
{
return $this->tid;
}
/**
- * @param string $tid
- *
* @return $this
*/
public function setTid(string $tid): static
{
$this->tid = $tid;
+
return $this;
}
/**
- * @return ArrayIterator
+ * @return \ArrayIterator
*/
- public function getUrlsIterator(): ArrayIterator
+ public function getUrlsIterator(): \ArrayIterator
{
- return new ArrayIterator($this->urls);
+ return new \ArrayIterator($this->urls);
}
/**
- * @param string $softDescriptor
- * @param string $paymentFacilitatorID
- * @param SubMerchant $subMerchant
- *
* @return $this
*/
public function mcc(string $softDescriptor, string $paymentFacilitatorID, SubMerchant $subMerchant): static
@@ -869,52 +640,37 @@ public function mcc(string $softDescriptor, string $paymentFacilitatorID, SubMer
return $this;
}
- /**
- * @return SubMerchant|null
- */
public function getSubMerchant(): ?SubMerchant
{
return $this->subMerchant;
}
/**
- * @param SubMerchant $subMerchant
- *
* @return $this
*/
public function setSubMerchant(SubMerchant $subMerchant): static
{
$this->subMerchant = $subMerchant;
+
return $this;
}
- /**
- * @return string|null
- */
public function getPaymentFacilitatorID(): ?string
{
return $this->paymentFacilitatorID;
}
/**
- * @param string $paymentFacilitatorID
- *
* @return $this
*/
public function setPaymentFacilitatorID(string $paymentFacilitatorID): static
{
$this->paymentFacilitatorID = $paymentFacilitatorID;
+
return $this;
}
/**
- * @param Device $device
- * @param string $onFailure
- * @param string $mpi
- * @param string $directoryServerTransactionId
- * @param string|null $userAgent
- * @param int $threeDIndicator
- *
* @return $this
*/
public function threeDSecure(
@@ -923,7 +679,7 @@ public function threeDSecure(
string $mpi = ThreeDSecure::MPI_REDE,
string $directoryServerTransactionId = '',
?string $userAgent = null,
- int $threeDIndicator = 2
+ int $threeDIndicator = 2,
): static {
$threeDSecure = new ThreeDSecure($device, $onFailure, $mpi, $userAgent);
$threeDSecure->setThreeDIndicator($threeDIndicator);
@@ -934,60 +690,50 @@ public function threeDSecure(
return $this;
}
- /**
- * @return int|null
- */
public function getBrandTid(): ?int
{
return $this->brandTid;
}
/**
- * @param int $brandTid
- *
* @return $this
*/
public function setBrandTid(int $brandTid): static
{
$this->brandTid = $brandTid;
+
return $this;
}
- /**
- * @return Brand|null
- */
public function getBrand(): ?Brand
{
return $this->brand;
}
/**
- * @param Brand $brand
- *
* @return $this
*/
public function setBrand(Brand $brand): static
{
$this->brand = $brand;
+
return $this;
}
/**
- * @param string $serialized
- *
* @return $this
- * @throws Exception
+ *
+ * @throws \Exception
*/
public function jsonUnserialize(string $serialized): static
{
$properties = json_decode($serialized);
-
- if (json_last_error() !== JSON_ERROR_NONE) {
- throw new InvalidArgumentException(sprintf('JSON: %s', json_last_error_msg()));
+ if (JSON_ERROR_NONE !== json_last_error()) {
+ throw new \InvalidArgumentException(sprintf('JSON: %s', json_last_error_msg()));
}
foreach (get_object_vars($properties) as $property => $value) {
- if ($property == 'links') {
+ if ('links' == $property) {
continue;
}
@@ -1000,6 +746,7 @@ public function jsonUnserialize(string $serialized): static
'threeDSecure' => $this->unserializeThreeDSecure($property, $value),
'requestDateTime', 'dateTime', 'refundDateTime' => $this->unserializeRequestDateTime($property, $value),
'brand' => $this->unserializeBrand($property, $value),
+ 'qrCodeResponse' => $this->unserializeQrCode($property, $value),
default => $this->{$property} = $value,
};
}
@@ -1008,35 +755,22 @@ public function jsonUnserialize(string $serialized): static
}
/**
- * @param string $property
- * @param mixed $value
- * @return void
- * @throws Exception
+ * @throws \Exception
*/
private function unserializeRefunds(string $property, mixed $value): void
{
- if ($property === 'refunds' && is_array($value)) {
+ if ('refunds' === $property && is_array($value)) {
$this->refunds = [];
foreach ($value as $refundValue) {
- /**
- * @var Refund $refund
- */
- $refund = Refund::create($refundValue);
-
- $this->refunds[] = $refund;
+ $this->refunds[] = (new Refund())->populate($refundValue);
}
}
}
- /**
- * @param string $property
- * @param mixed $value
- * @return void
- */
private function unserializeUrls(string $property, mixed $value): void
{
- if ($property === 'urls' && is_array($value)) {
+ if ('urls' === $property && is_array($value)) {
$this->urls = [];
foreach ($value as $urlValue) {
@@ -1046,107 +780,74 @@ private function unserializeUrls(string $property, mixed $value): void
}
/**
- * @param string $property
- * @param mixed $value
- * @return void
- * @throws Exception
+ * @throws \Exception
*/
private function unserializeCapture(string $property, mixed $value): void
{
- if ($property === 'capture' && is_object($value)) {
- /**
- * @var Capture $capture
- */
- $capture = Capture::create($value);
-
- $this->capture = $capture;
+ if ('capture' === $property && is_object($value)) {
+ $this->capture = (new Capture())->populate($value);
}
}
/**
- * @param string $property
- * @param mixed $value
- * @return void
- * @throws Exception
+ * @throws \Exception
*/
private function unserializeAuthorization(string $property, mixed $value): void
{
- if ($property == 'authorization' && is_object($value)) {
- /**
- * @var Authorization $authorization
- */
- $authorization = Authorization::create($value);
-
- $this->authorization = $authorization;
+ if ('authorization' == $property && is_object($value)) {
+ $this->authorization = (new Authorization())->populate($value);
}
}
/**
- * @param string $property
- * @param mixed $value
- * @return void
- * @throws Exception
+ * @throws \Exception
*/
private function unserializeAdditional(string $property, mixed $value): void
{
- if ($property == 'additional' && is_object($value)) {
- /**
- * @var Additional $additional
- */
- $additional = Additional::create($value);
-
- $this->additional = $additional;
+ if ('additional' == $property && is_object($value)) {
+ $this->additional = (new Additional())->populate($value);
}
}
/**
- * @param string $property
- * @param mixed $value
- * @return void
- * @throws Exception
+ * @throws \Exception
*/
private function unserializeThreeDSecure(string $property, mixed $value): void
{
- if ($property == 'threeDSecure' && is_object($value)) {
- /**
- * @var ThreeDSecure $threeDSecure
- */
- $threeDSecure = ThreeDSecure::create($value);
-
- $this->threeDSecure = $threeDSecure;
+ if ('threeDSecure' == $property && is_object($value)) {
+ $this->threeDSecure = (new ThreeDSecure())->populate($value);
}
}
/**
- * @param string $property
- * @param mixed $value
- * @return void
- * @throws Exception
+ * @throws \Exception
*/
private function unserializeRequestDateTime(string $property, mixed $value): void
{
- if ($property == 'requestDateTime' || $property == 'dateTime' || $property == 'refundDateTime') {
- $value = new DateTime($value);
+ if ('requestDateTime' == $property || 'dateTime' == $property || 'refundDateTime' == $property) {
+ $value = new \DateTime($value);
}
$this->{$property} = $value;
}
/**
- * @param string $property
- * @param mixed $value
- * @return void
- * @throws Exception
+ * @throws \Exception
*/
private function unserializeBrand(string $property, mixed $value): void
{
- if ($property == 'brand') {
- /**
- * @var Brand $brand
- */
- $brand = Brand::create($value);
+ if ('brand' == $property) {
+ $this->brand = (new Brand())->populate($value);
+ }
+ }
- $this->brand = $brand;
+ /**
+ * @throws \Exception
+ */
+ private function unserializeQrCode(string $property, mixed $value): void
+ {
+ if (('qrCodeResponse' === $property) && is_object($value)) {
+ $this->qrCode = (new QrCode())->populate($value);
}
}
}
diff --git a/src/Rede/Url.php b/src/Rede/Url.php
index ae6896b..07c95ee 100644
--- a/src/Rede/Url.php
+++ b/src/Rede/Url.php
@@ -7,46 +7,42 @@ class Url implements RedeSerializable
use SerializeTrait;
public const CALLBACK = 'callback';
+
public const THREE_D_SECURE_FAILURE = 'threeDSecureFailure';
+
public const THREE_D_SECURE_SUCCESS = 'threeDSecureSuccess';
public function __construct(private string $url, private string $kind = Url::CALLBACK)
{
}
- /**
- * @return string
- */
public function getUrl(): string
{
return $this->url;
}
/**
- * @param string $url
* @return $this
*/
public function setUrl(string $url): static
{
$this->url = $url;
+
return $this;
}
- /**
- * @return string
- */
public function getKind(): string
{
return $this->kind;
}
/**
- * @param string $kind
* @return $this
*/
public function setKind(string $kind): static
{
$this->kind = $kind;
+
return $this;
}
}
diff --git a/src/Rede/eRede.php b/src/Rede/eRede.php
index 990c35b..e58702f 100644
--- a/src/Rede/eRede.php
+++ b/src/Rede/eRede.php
@@ -9,37 +9,26 @@
use Rede\Service\GetTransactionService;
/**
- * phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
+ * phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps.
*/
class eRede
{
public const VERSION = '6.1.0';
+
public const USER_AGENT = 'eRede/' . eRede::VERSION . ' (PHP %s; Store %s; %s %s) %s';
- /**
- * @var string|null
- */
private ?string $platform = null;
- /**
- * @var string|null
- */
private ?string $platformVersion = null;
/**
* eRede constructor.
- *
- * @param Store $store
- * @param LoggerInterface|null $logger
*/
public function __construct(private readonly Store $store, private readonly ?LoggerInterface $logger = null)
{
}
/**
- * @param Transaction $transaction
- *
- * @return Transaction
* @see eRede::create()
*/
public function authorize(Transaction $transaction): Transaction
@@ -47,11 +36,6 @@ public function authorize(Transaction $transaction): Transaction
return $this->create($transaction);
}
- /**
- * @param Transaction $transaction
- *
- * @return Transaction
- */
public function create(Transaction $transaction): Transaction
{
$service = new CreateTransactionService($this->store, $transaction, $this->logger);
@@ -61,9 +45,6 @@ public function create(Transaction $transaction): Transaction
}
/**
- * @param string $platform
- * @param string $platformVersion
- *
* @return $this
*/
public function platform(string $platform, string $platformVersion): static
@@ -74,11 +55,6 @@ public function platform(string $platform, string $platformVersion): static
return $this;
}
- /**
- * @param Transaction $transaction
- *
- * @return Transaction
- */
public function cancel(Transaction $transaction): Transaction
{
$service = new CancelTransactionService($this->store, $transaction, $this->logger);
@@ -88,9 +64,6 @@ public function cancel(Transaction $transaction): Transaction
}
/**
- * @param string $tid
- *
- * @return Transaction
* @see eRede::get()
*/
public function getById(string $tid): Transaction
@@ -98,11 +71,6 @@ public function getById(string $tid): Transaction
return $this->get($tid);
}
- /**
- * @param string $tid
- *
- * @return Transaction
- */
public function get(string $tid): Transaction
{
$service = new GetTransactionService(store: $this->store, logger: $this->logger);
@@ -112,11 +80,6 @@ public function get(string $tid): Transaction
return $service->execute();
}
- /**
- * @param string $reference
- *
- * @return Transaction
- */
public function getByReference(string $reference): Transaction
{
$service = new GetTransactionService(store: $this->store, logger: $this->logger);
@@ -126,11 +89,6 @@ public function getByReference(string $reference): Transaction
return $service->execute();
}
- /**
- * @param string $tid
- *
- * @return Transaction
- */
public function getRefunds(string $tid): Transaction
{
$service = new GetTransactionService(
@@ -144,15 +102,10 @@ public function getRefunds(string $tid): Transaction
return $service->execute();
}
- /**
- * @param Transaction $transaction
- *
- * @return Transaction
- */
public function zero(Transaction $transaction): Transaction
{
$amount = (int) $transaction->getAmount();
- $capture = (bool)$transaction->getCapture();
+ $capture = (bool) $transaction->getCapture();
$transaction->setAmount(0);
$transaction->capture();
@@ -165,11 +118,6 @@ public function zero(Transaction $transaction): Transaction
return $transaction;
}
- /**
- * @param Transaction $transaction
- *
- * @return Transaction
- */
public function capture(Transaction $transaction): Transaction
{
$service = new CaptureTransactionService($this->store, $transaction, $this->logger);
diff --git a/tests b/tests
deleted file mode 100755
index a713056..0000000
--- a/tests
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-if [[ ! -d vendor ]]; then
- echo "Vendor dir not found; running composer install"
- composer install
-fi
-
-if [[ ! -v REDE_PV ]] || [[ ! -v REDE_TOKEN ]]; then
- echo "You need to define the environment variables REDE_PV AND REDE_TOKEN to continue"
- exit 1
-fi
-
-./vendor/bin/phpcs --ignore=vendor --standard=PSR12 src test
-./vendor/bin/phpstan
-./vendor/bin/phpcpd src tests\n
-./vendor/bin/phpunit --testdox --colors='always' test
diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php
new file mode 100644
index 0000000..c46d75f
--- /dev/null
+++ b/tests/BaseTestCase.php
@@ -0,0 +1,26 @@
+logger = new Logger('eRede SDK Test');
+ $this->logger->pushHandler(new StreamHandler('php://stdout', $debug ? Level::Debug : Level::Error));
+
+ $this->store = new Store($filiation, $token, Environment::sandbox());
+ }
+
+ protected function generateReferenceNumber(): string
+ {
+ return 'pedido' . (time() + self::$sequence++);
+ }
+
+ protected function createERede(): eRede
+ {
+ if (null === $this->store) {
+ throw new \RuntimeException('Store cant be null');
+ }
+
+ return new eRede($this->store, $this->logger);
+ }
+}
diff --git a/test/Rede/eRedeTest.php b/tests/E2E/ERedeIntegrationTest.php
similarity index 64%
rename from test/Rede/eRedeTest.php
rename to tests/E2E/ERedeIntegrationTest.php
index a355577..c9b3181 100644
--- a/test/Rede/eRedeTest.php
+++ b/tests/E2E/ERedeIntegrationTest.php
@@ -1,66 +1,24 @@
logger = new Logger('eRede SDK Test');
- $this->logger->pushHandler(new StreamHandler('php://stdout', $debug ? Level::Debug : Level::Error));
+namespace Rede\Tests\E2E;
- $this->store = new Store($filiation, $token, Environment::sandbox());
- }
-
- private function generateReferenceNumber(): string
- {
- return 'pedido' . (time() + eRedeTest::$sequence++);
- }
+use PHPUnit\Framework\Attributes\Depends;
+use Rede\Device;
+use Rede\QrCode;
+use Rede\SubMerchant;
+use Rede\ThreeDSecure;
+use Rede\Transaction;
+use Rede\Url;
+class ERedeIntegrationTest extends BaseIntegrationTestCase
+{
public function testShouldAuthorizeACreditcardTransaction(): void
{
- $transaction = (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->capture(false);
@@ -71,11 +29,11 @@ public function testShouldAuthorizeACreditcardTransaction(): void
public function testShouldAuthorizeAndCaptureACreditcardTransaction(): void
{
- $transaction = (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->capture();
@@ -86,11 +44,11 @@ public function testShouldAuthorizeAndCaptureACreditcardTransaction(): void
public function testShouldAuthorizeACreditcardTransactionWithInstallments(): void
{
- $transaction = (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->setInstallments(3);
@@ -101,11 +59,11 @@ public function testShouldAuthorizeACreditcardTransactionWithInstallments(): voi
public function testShouldAuthorizeACreditcardTransactionWithSoftdescriptor(): void
{
- $transaction = (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->setSoftDescriptor('Loja X');
@@ -116,11 +74,11 @@ public function testShouldAuthorizeACreditcardTransactionWithSoftdescriptor(): v
public function testShouldAuthorizeACreditcardTransactionWithAdditionalGatewayAndModuleInformation(): void
{
- $transaction = (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->additional(1234, 56);
@@ -129,16 +87,13 @@ public function testShouldAuthorizeACreditcardTransactionWithAdditionalGatewayAn
$this->assertEquals('00', $transaction->getReturnCode());
}
- /**
- * @testdox Should authorize a credit card transaction with dynamic MCC
- */
public function testShouldAuthorizeACreditcardTransactionWithDynamicMCC(): void
{
- $transaction = (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->mcc(
'LOJADOZE',
@@ -155,16 +110,13 @@ public function testShouldAuthorizeACreditcardTransactionWithDynamicMCC(): void
$this->assertEquals('00', $transaction->getReturnCode());
}
- /**
- * @testdox Should authorize a credit card transaction with IATA
- */
public function testShouldAuthorizeACreditcardTransactionWithIATA(): void
{
- $transaction = (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->iata('101010', '250');
@@ -179,7 +131,7 @@ public function testShouldAuthorizeAZeroDolarCreditcardTransaction(): void
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->setSoftDescriptor('Loja X');
@@ -191,22 +143,22 @@ public function testShouldAuthorizeAZeroDolarCreditcardTransaction(): void
public function testShouldCreateADebitcardTransactionWithAuthentication(): void
{
$transaction = (new Transaction(25, $this->generateReferenceNumber()))->debitCard(
- '5277696455399733',
+ '4514166653413658',
'123',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
);
$transaction->threeDSecure(
new Device(
- ColorDepth: 1,
- DeviceType3ds: 'BROWSER',
- JavaEnabled: false,
- Language: 'BR',
- ScreenHeight: 500,
- ScreenWidth: 500,
- TimeZoneOffset: 3
+ colorDepth: 1,
+ deviceType3ds: 'BROWSER',
+ javaEnabled: false,
+ language: 'BR',
+ screenHeight: 500,
+ screenWidth: 500,
+ timeZoneOffset: 3
),
ThreeDSecure::DECLINE_ON_FAILURE
);
@@ -219,7 +171,7 @@ public function testShouldCreateADebitcardTransactionWithAuthentication(): void
$this->assertContains($returnCode, ['220', '201']);
- if ($returnCode === '220') {
+ if ('220' === $returnCode) {
$this->assertNotEmpty($transaction->getThreeDSecure()->getUrl());
printf("\tURL de autenticação: %s\n", $transaction->getThreeDSecure()->getUrl());
@@ -230,11 +182,11 @@ public function testShouldCaptureATransaction(): void
{
// First we create a new transaction
$authorizedTransaction = $this->createERede()->create(
- (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
'12',
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->capture(false)
);
@@ -256,24 +208,21 @@ public function testShouldCancelATransaction(): void
// Then we capture the authorized transaction
$canceledTransaction = $this->createERede()
- ->cancel((new Transaction(20.99))
- ->setTid((string)$authorizedTransaction->getTid()));
+ ->cancel((new Transaction(200.99))
+ ->setTid((string) $authorizedTransaction->getTid()));
$this->assertEquals('359', $canceledTransaction->getReturnCode());
}
- /**
- * @testdox Should consult a transaction by its TID
- */
public function testShouldConsultATransactionByItsTID(): void
{
// First we create a new transaction
$authorizedTransaction = $this->createAnAuthorizedTransaction();
- $contultedTransaction = $this->createERede()->get((string)$authorizedTransaction->getTid());
+ $contultedTransaction = $this->createERede()->get((string) $authorizedTransaction->getTid());
$authorization = $contultedTransaction->getAuthorization();
- if ($authorization === null) {
- throw new RuntimeException('Something happened with the authorized transaction');
+ if (null === $authorization) {
+ throw new \RuntimeException('Something happened with the authorized transaction');
}
$this->assertEquals($authorizedTransaction->getTid(), $authorization->getTid());
@@ -283,11 +232,11 @@ public function testShouldConsultATransactionByReference(): void
{
// First we create a new transaction
$authorizedTransaction = $this->createAnAuthorizedTransaction();
- $contultedTransaction = $this->createERede()->getByReference((string)$authorizedTransaction->getReference());
+ $contultedTransaction = $this->createERede()->getByReference((string) $authorizedTransaction->getReference());
$authorization = $contultedTransaction->getAuthorization();
- if ($authorization === null) {
- throw new RuntimeException('Something happened with the authorized transaction');
+ if (null === $authorization) {
+ throw new \RuntimeException('Something happened with the authorized transaction');
}
$this->assertEquals($authorizedTransaction->getReference(), $authorization->getReference());
@@ -302,13 +251,13 @@ public function testShouldConsultTheTransactionRefunds(): void
// Them we cancel the authorized transaction
$canceledTransaction = $this->createERede()
- ->cancel((new Transaction(20.99))
- ->setTid((string)$authorizedTransaction->getTid()));
+ ->cancel((new Transaction(200.99))
+ ->setTid((string) $authorizedTransaction->getTid()));
$this->assertEquals('359', $canceledTransaction->getReturnCode());
// Now we can consult the refunds
- $refundedTransactions = $this->createERede()->getRefunds((string)$authorizedTransaction->getTid());
+ $refundedTransactions = $this->createERede()->getRefunds((string) $authorizedTransaction->getTid());
$this->assertCount(1, $refundedTransactions->getRefunds());
@@ -317,31 +266,45 @@ public function testShouldConsultTheTransactionRefunds(): void
}
}
- /**
- * @return Transaction
- */
private function createAnAuthorizedTransaction(): Transaction
{
return $this->createERede()->create(
- (new Transaction(20.99, $this->generateReferenceNumber()))->creditCard(
+ (new Transaction(200.99, $this->generateReferenceNumber()))->creditCard(
'5448280000000007',
'235',
12,
- (int)date('Y') + 1,
+ (int) date('Y') + 1,
'John Snow'
)->capture()
);
}
- /**
- * @return eRede
- */
- private function createERede(): eRede
+ public function testShouldCreatePixTransaction(): Transaction
{
- if ($this->store === null || $this->logger === null) {
- throw new RuntimeException('Store cant be null');
- }
+ $transaction = (new Transaction(200.99, $this->generateReferenceNumber()))->createQrCode(new \DateTimeImmutable('+ 1 hour'));
- return new eRede($this->store, $this->logger);
+ $transaction = $this->createERede()->create($transaction);
+
+ $this->assertEquals('00', $transaction->getReturnCode());
+ $this->assertInstanceOf(QrCode::class, $transaction->getQrCode());
+ $this->assertNotEmpty($transaction->getQrCode()->getDateTimeExpiration());
+ $this->assertNotEmpty($transaction->getQrCode()->getQrCodeImage());
+ $this->assertNotEmpty($transaction->getQrCode()->getQrCodeData());
+
+ return $transaction;
+ }
+
+ #[Depends('testShouldCreatePixTransaction')]
+ public function testShouldGetPixTransaction(Transaction $tr): Transaction
+ {
+ $transaction = $this->createERede()->get($tr->getTid() ?? '');
+ $this->assertInstanceOf(QrCode::class, $transaction->getQrCode());
+ $this->assertNotEmpty($transaction->getQrCode()->getQrCodeImage());
+ $this->assertNotEmpty($transaction->getQrCode()->getQrCodeData());
+ $this->assertNotEmpty($transaction->getQrCode()->getExpirationQrCode());
+ $this->assertSame('Pending', $transaction->getQrCode()->getStatus());
+ $this->assertSame(20099, $transaction->getQrCode()->getAmount());
+
+ return $transaction;
}
}
diff --git a/tests/Unit/QrCodeUnitTest.php b/tests/Unit/QrCodeUnitTest.php
new file mode 100644
index 0000000..725d5f5
--- /dev/null
+++ b/tests/Unit/QrCodeUnitTest.php
@@ -0,0 +1,41 @@
+dateTimeExpiration = '2024-11-12T15:00:09-03:00';
+ // Campos que retornam apenas na consulta
+ $body->dateTime = '2024-11-12T14:39:09-03:00';
+ $body->returnCode = '00';
+ $body->returnMessage = 'Success.';
+ $body->affiliation = 38421438;
+ $body->kind = 'Pix';
+ $body->reference = '6733a0d967616';
+ $body->amount = 9959;
+ $body->tid = '40012411121539096004';
+ $body->status = 'Pending';
+ $body->expirationQrCode = '2024-11-12T15:00:09-03:00';
+ $body->qrCodeData = '123';
+ $body->qrCodeImage = '456';
+ $body->origin = 1;
+ $body->txId = 'REZ12345600384214382411121539095NP';
+
+ $qrCode = (new QrCode())->populate($body);
+
+ $this->assertSame('Pending', $qrCode->getStatus());
+ $this->assertSame(9959, $qrCode->getAmount());
+ $this->assertSame('123', $qrCode->getQrCodeData());
+ $this->assertSame('456', $qrCode->getQrCodeImage());
+ $this->assertSame('40012411121539096004', $qrCode->getTid());
+ $this->assertSame('2024-11-12T15:00:09-03:00', $qrCode->getDateTimeExpiration()?->format('c'));
+ $this->assertSame('2024-11-12T15:00:09-03:00', $qrCode->getExpirationQrCode()?->format('c'));
+ $this->assertSame('2024-11-12T14:39:09-03:00', $qrCode->getDateTime()?->format('c'));
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..147fb5a
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,8 @@
+