From d36d81cbbcd3282125bb569919d620a9fa590a8c Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Mon, 7 Dec 2020 23:32:11 -0300
Subject: [PATCH 1/9] Fixed what needed fixing and squished some bugs. :bug:
---
.editorconfig | 2 +-
.gitignore | 16 ++--
.php_cs.dist | 40 +++++++++
.travis.yml | 20 -----
CHANGELOG.md | 13 ++-
Instapago/Api.php | 70 +++++++--------
Instapago/Exceptions/GenericException.php | 37 ++++++++
Instapago/Validator.php | 102 +++++++++++-----------
README.md | 12 +--
composer.json | 27 ++++--
psalm.xml.dist | 16 ++++
tests/ApiTest.php | 32 +++----
12 files changed, 241 insertions(+), 146 deletions(-)
create mode 100644 .php_cs.dist
delete mode 100644 .travis.yml
create mode 100644 Instapago/Exceptions/GenericException.php
create mode 100644 psalm.xml.dist
diff --git a/.editorconfig b/.editorconfig
index 1492202..5d36dbe 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -4,7 +4,7 @@ root = true
charset = utf-8
end_of_line = lf
insert_final_newline = true
-indent_style = space
+indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
diff --git a/.gitignore b/.gitignore
index 31790fa..0296b57 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,11 @@
-composer.phar
-/vendor/
-test.php
-.DS_Store
-# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
-# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
+.idea
+.php_cs
+.php_cs.cache
+.phpunit.result.cache
+build
composer.lock
+coverage
+docs
+phpunit.xml
+psalm.xml
+vendor
diff --git a/.php_cs.dist b/.php_cs.dist
new file mode 100644
index 0000000..b68900e
--- /dev/null
+++ b/.php_cs.dist
@@ -0,0 +1,40 @@
+in([
+ __DIR__ . '/Instapago',
+ __DIR__ . '/tests',
+ ])
+ ->name('*.php')
+ ->notName('*.blade.php')
+ ->ignoreDotFiles(true)
+ ->ignoreVCS(true);
+
+return PhpCsFixer\Config::create()
+ ->setRules([
+ '@PSR2' => true,
+ 'array_syntax' => ['syntax' => 'short'],
+ 'ordered_imports' => ['sortAlgorithm' => 'alpha'],
+ 'no_unused_imports' => true,
+ 'not_operator_with_successor_space' => true,
+ 'trailing_comma_in_multiline_array' => true,
+ 'phpdoc_scalar' => true,
+ 'unary_operator_spaces' => true,
+ 'binary_operator_spaces' => true,
+ 'blank_line_before_statement' => [
+ 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
+ ],
+ 'phpdoc_single_line_var_spacing' => true,
+ 'phpdoc_var_without_name' => true,
+ 'class_attributes_separation' => [
+ 'elements' => [
+ 'method',
+ ],
+ ],
+ 'method_argument_space' => [
+ 'on_multiline' => 'ensure_fully_multiline',
+ 'keep_multiple_spaces_after_comma' => true,
+ ],
+ 'single_trait_insert_per_statement' => true,
+ ])
+ ->setFinder($finder);
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 0312e15..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-language: php
-php:
- - '7.1'
- - '7.2'
- #- hhvm
- #- nightly
-
-# Commands to be run before your environment runs.
-before_script:
- - composer self-update
- - composer install --prefer-source --no-interaction --dev
-
-# Commands you want to run that will verify your build.
-script:
- - vendor/bin/phpunit
-
-# Customize when the notification emails are sent.
-notifications:
- on_success: never
- on_failure: always
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9611f21..41ba0d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,10 +2,15 @@
> Todos los cambios significativos en la librería serán registrados en éste documento.
-Lamento haber olvidado hacer los tags correspondientes :(
+### v6.0.0
+* Se actualiza el code base
+* Se agregan mejoras a nivel general
+* Se dropea soporte a cualquier cosa menor a php 7.4
+
-###v3.0.2
-* Se actualizan las pruebas unitarias
+Lamento haber olvidado hacer los tags correspondientes :(
+### v3.0.2
+* Se actualizan las pruebas unitarias
* Se actualiza versión de php unit a la vieja estable (5.7)
### v3.0.1
@@ -46,7 +51,7 @@
### v1.0.0
### Nuevo
-* Optimizaciones generales
+* Optimizaciones generales
* Agregada una funcion para el manejo de errores (exceptions).
* Eliminado `fullPayment`
* Optimizado ` __construct` (Else is never necessary and you can simplify the code to work without else.)
diff --git a/Instapago/Api.php b/Instapago/Api.php
index ffde4e1..5706628 100644
--- a/Instapago/Api.php
+++ b/Instapago/Api.php
@@ -101,17 +101,17 @@ private function payment($type, $fields)
(new Validator())->payment()->validate($fields);
$fields = [
- 'KeyID' => $this->keyId,
- 'PublicKeyId' => $this->publicKeyId,
- 'amount' => $fields['amount'],
- 'description' => $fields['description'],
- 'cardHolder' => $fields['card_holder'],
- 'cardHolderId' => $fields['card_holder_id'],
- 'cardNumber' => $fields['card_number'],
- 'cvc' => $fields['cvc'],
+ 'KeyID' => $this->keyId,
+ 'PublicKeyId' => $this->publicKeyId,
+ 'amount' => $fields['amount'],
+ 'description' => $fields['description'],
+ 'cardHolder' => $fields['card_holder'],
+ 'cardHolderId' => $fields['card_holder_id'],
+ 'cardNumber' => $fields['card_number'],
+ 'cvc' => $fields['cvc'],
'expirationDate' => $fields['expiration'],
- 'statusId' => $type,
- 'IP' => $fields['ip'],
+ 'statusId' => $type,
+ 'IP' => $fields['ip'],
];
$obj = $this->curlTransaccion('payment', $fields, 'POST');
@@ -135,11 +135,11 @@ private function payment($type, $fields)
public function continuePayment($fields)
{
(new Validator())->release()->validate($fields);
- $fields = [
- 'KeyID' => $this->keyId, //required
- 'PublicKeyId' => $this->publicKeyId, //required
- 'id' => $fields['id'], //required
- 'amount' => $fields['amount'], //required
+ $fields = [
+ 'KeyID' => $this->keyId, //required
+ 'PublicKeyId' => $this->publicKeyId, //required
+ 'id' => $fields['id'], //required
+ 'amount' => $fields['amount'], //required
];
$obj = $this->curlTransaccion('complete', $fields, 'POST');
@@ -166,9 +166,9 @@ public function query($id_pago)
]);
$fields = [
- 'KeyID' => $this->keyId, //required
- 'PublicKeyId' => $this->publicKeyId, //required
- 'id' => $id_pago, //required
+ 'KeyID' => $this->keyId, //required
+ 'PublicKeyId' => $this->publicKeyId, //required
+ 'id' => $id_pago, //required
];
$obj = $this->curlTransaccion('payment', $fields, 'GET');
@@ -194,9 +194,9 @@ public function cancel($id_pago)
]);
$fields = [
- 'KeyID' => $this->keyId, //required
- 'PublicKeyId' => $this->publicKeyId, //required
- 'id' => $id_pago, //required
+ 'KeyID' => $this->keyId, //required
+ 'PublicKeyId' => $this->publicKeyId, //required
+ 'id' => $id_pago, //required
];
$obj = $this->curlTransaccion('payment', $fields, 'DELETE');
@@ -223,7 +223,7 @@ public function curlTransaccion($url, $fields, $method)
$args = [];
if (! in_array($method, ['GET', 'POST', 'DELETE'])) {
- throw new Exception('Not implemented yet', 1);
+ throw new Exceptions\GenericException('Not implemented yet', 1);
}
$key = ($method == 'GET') ? 'query' : 'form_params';
@@ -256,40 +256,40 @@ public function checkResponseCode($obj)
throw new Exceptions\InvalidInputException(
'Error al validar los datos enviados.'
);
- break;
+
case 401:
throw new Exceptions\AuthException(
'Error de autenticación, ha ocurrido un error con las llaves utilizadas.'
);
- break;
+
case 403:
throw new Exceptions\BankRejectException(
'Pago Rechazado por el banco.'
);
- break;
+
case 500:
throw new Exceptions\InstapagoException(
'Ha Ocurrido un error interno dentro del servidor.'
);
- break;
+
case 503:
throw new Exceptions\InstapagoException(
'Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo.'
);
- break;
+
case 201:
return [
- 'code' => $code,
- 'msg_banco' => $obj['message'],
- 'voucher' => html_entity_decode($obj['voucher']),
- 'id_pago' => $obj['id'],
- 'reference' => $obj['reference'],
+ 'code' => $code,
+ 'msg_banco' => $obj['message'],
+ 'voucher' => html_entity_decode($obj['voucher']),
+ 'id_pago' => $obj['id'],
+ 'reference' => $obj['reference'],
'original_response' => $obj,
];
- break;
+
default:
- throw new \Exception('Not implemented yet');
- break;
+ throw new Exceptions\GenericException('Not implemented yet');
+
}
}
}
diff --git a/Instapago/Exceptions/GenericException.php b/Instapago/Exceptions/GenericException.php
new file mode 100644
index 0000000..cac68b9
--- /dev/null
+++ b/Instapago/Exceptions/GenericException.php
@@ -0,0 +1,37 @@
+.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the “Software”), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author José Gómez <1josegomezr@gmail.com>
+ * @license MIT Licens
+ * @copyright 2016 José Gómez
+ */
+
+namespace Instapago\Exceptions;
+
+/**
+ * Custom GenericException.
+ */
+class GenericException extends \Exception
+{
+}
diff --git a/Instapago/Validator.php b/Instapago/Validator.php
index 9203cb2..d7acd76 100644
--- a/Instapago/Validator.php
+++ b/Instapago/Validator.php
@@ -36,64 +36,64 @@
*/
class Validator
{
- protected $validations = [];
+ protected $validations = [];
- public function payment()
- {
- $this->validations = [
- 'amount' => [FILTER_VALIDATE_FLOAT],
- 'description' => [FILTER_VALIDATE_REGEXP, '/^(.{0,140})$/'],
- 'card_holder' => [FILTER_VALIDATE_REGEXP, '/^([a-zA-ZáéíóúñÁÉÍÓÚÑ\ ]+)$/'],
- 'card_holder_id' => [FILTER_VALIDATE_REGEXP, '/^(\d{5,8})$/'],
- 'card_number' => [FILTER_VALIDATE_REGEXP, '/^(\d{16})$/'],
- 'cvc' => [FILTER_VALIDATE_INT],
- 'expiration' => [FILTER_VALIDATE_REGEXP, '/^(\d{2})\/(\d{4})$/'],
- 'ip' => [FILTER_VALIDATE_IP],
- ];
+ public function payment()
+ {
+ $this->validations = [
+ 'amount' => [FILTER_VALIDATE_FLOAT],
+ 'description' => [FILTER_VALIDATE_REGEXP, '/^(.{0,140})$/'],
+ 'card_holder' => [FILTER_VALIDATE_REGEXP, '/^([a-zA-ZáéíóúñÁÉÍÓÚÑ\ ]+)$/'],
+ 'card_holder_id' => [FILTER_VALIDATE_REGEXP, '/^(\d{5,8})$/'],
+ 'card_number' => [FILTER_VALIDATE_REGEXP, '/^(\d{16})$/'],
+ 'cvc' => [FILTER_VALIDATE_INT],
+ 'expiration' => [FILTER_VALIDATE_REGEXP, '/^(\d{2})\/(\d{4})$/'],
+ 'ip' => [FILTER_VALIDATE_IP],
+ ];
- return $this;
- }
+ return $this;
+ }
- public function release()
- {
- $this->validations = [
- 'amount' => [FILTER_VALIDATE_FLOAT],
- 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
- ];
+ public function release()
+ {
+ $this->validations = [
+ 'amount' => [FILTER_VALIDATE_FLOAT],
+ 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
+ ];
- return $this;
- }
+ return $this;
+ }
- public function query()
- {
- $this->validations = [
- 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
- ];
+ public function query()
+ {
+ $this->validations = [
+ 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
+ ];
- return $this;
- }
+ return $this;
+ }
- public function validate($fields)
- {
- foreach ($this->validations as $key => $filters) {
- if ( ! $this->_validation($fields[$key], $filters)) {
- throw new Exceptions\ValidationException("Error {$key}: {$fields[$key]}");
- }
- }
- }
+ public function validate($fields)
+ {
+ foreach ($this->validations as $key => $filters) {
+ if (! $this->_validation($fields[$key], $filters)) {
+ throw new Exceptions\ValidationException("Error {$key}: {$fields[$key]}");
+ }
+ }
+ }
- private function _validation($value, $filters)
- {
- $filter = $filters[0];
- $flags = [];
- if ($filter === FILTER_VALIDATE_REGEXP) {
- $flags = [
- 'options' => [
- 'regexp'=> $filters[1],
- ],
- ];
- }
+ private function _validation($value, $filters)
+ {
+ $filter = $filters[0];
+ $flags = [];
+ if ($filter === FILTER_VALIDATE_REGEXP) {
+ $flags = [
+ 'options' => [
+ 'regexp' => $filters[1],
+ ],
+ ];
+ }
- return filter_var($value, $filter, $flags);
- }
+ return filter_var($value, $filter, $flags);
+ }
}
diff --git a/README.md b/README.md
index 94bdbd7..b46996a 100644
--- a/README.md
+++ b/README.md
@@ -7,10 +7,7 @@
[![GitHub issues](https://img.shields.io/github/issues/abr4xas/php-instapago.svg?style=flat-square)](https://github.com/abr4xas/php-instapago/issues) [![GitHub forks](https://img.shields.io/github/forks/abr4xas/php-instapago.svg?style=flat-square)](https://github.com/abr4xas/php-instapago/network) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/abr4xas/php-instapago/master/LICENSE)
-[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/abr4xas/php-instapago/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/abr4xas/php-instapago/?branch=master)
-[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a2b75f8ad49b4a988400fc4633737f28)](https://www.codacy.com/app/abr4xas/php-instapago?utm_source=github.com&utm_medium=referral&utm_content=abr4xas/php-instapago&utm_campaign=Badge_Grade)
-[![Join the chat at https://gitter.im/abr4xas/php-instapago](https://badges.gitter.im/abr4xas/php-instapago.svg)](https://gitter.im/abr4xas/php-instapago?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-[![Build Status](https://travis-ci.org/abr4xas/php-instapago.svg?branch=master)](https://travis-ci.org/abr4xas/php-instapago)
+
## instalación
@@ -92,10 +89,13 @@ $ php -S localhost:8000
* publicKeyId = e9a5893e047b645fed12c82db877e05a
```
-## phpunit
+## tests
+
+las llaves que se usan para los test son unicamente destinadas a este propósito.
+
```
-$ phpunit --configuration="phpunit.xml.dist"
+$ composer all
```
## enlaces
diff --git a/composer.json b/composer.json
index 0254c0f..adaf9aa 100644
--- a/composer.json
+++ b/composer.json
@@ -10,16 +10,20 @@
"license": "MIT",
"authors": [
{
- "name": "abr4xas",
- "email": "me@abr4xas.org",
- "homepage": "http://abr4xas.org"
+ "name": "angel cruz",
+ "email": "angel@tepuilabs.dev",
+ "homepage": "https://angelcruz.dev",
+ "role": "Developer"
}
],
"require": {
- "guzzlehttp/guzzle": "^6.3"
+ "guzzlehttp/guzzle": "^7.2",
+ "php": "^7.4|^8.0"
},
"require-dev": {
- "phpunit/phpunit": "^7.3"
+ "friendsofphp/php-cs-fixer": "^2.16",
+ "phpunit/phpunit": "^9.3",
+ "vimeo/psalm": "^3.11"
},
"autoload": {
"psr-4": {
@@ -27,6 +31,15 @@
}
},
"scripts": {
- "test": "phpunit --verbose"
- }
+ "psalm": "vendor/bin/psalm",
+ "test": "vendor/bin/phpunit",
+ "test-coverage": "vendor/bin/phpunit --coverage-html coverage",
+ "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
+ "all" : "composer psalm && composer test && composer test-coverage && composer format"
+ },
+ "config": {
+ "sort-packages": true
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true
}
diff --git a/psalm.xml.dist b/psalm.xml.dist
new file mode 100644
index 0000000..4d7e696
--- /dev/null
+++ b/psalm.xml.dist
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
diff --git a/tests/ApiTest.php b/tests/ApiTest.php
index 5316c16..9b1e0b4 100644
--- a/tests/ApiTest.php
+++ b/tests/ApiTest.php
@@ -27,7 +27,7 @@
* @copyright 2016 Angel Cruz
*/
use Instapago\Api;
-use PHPUnit\Framework\TestCase as TestCase;
+use PHPUnit\Framework\TestCase;
class ApiTest extends TestCase
{
@@ -45,28 +45,28 @@ protected function setUp()
private function _dataPagoPrueba()
{
return [
- 'amount' => '200',
- 'description' => 'PHPUnit Test Payment',
- 'card_holder' => 'juan peñalver',
+ 'amount' => '200',
+ 'description' => 'PHPUnit Test Payment',
+ 'card_holder' => 'juan peñalver',
'card_holder_id' => '11111111',
- 'card_number' => '4111111111111111',
- 'cvc' => '123',
- 'expiration' => '12/2020',
- 'ip' => '127.0.0.1',
+ 'card_number' => '4111111111111111',
+ 'cvc' => '123',
+ 'expiration' => '12/2020',
+ 'ip' => '127.0.0.1',
];
}
private function _dataPagoPruebaError()
{
return [
- 'amount' => '200.00',
- 'description' => 'PHPUnit Test Payment',
- 'card_holder' => 'juan peñalver',
+ 'amount' => '200.00',
+ 'description' => 'PHPUnit Test Payment',
+ 'card_holder' => 'juan peñalver',
'card_holder_id' => '11111111',
- 'card_number' => '4111111111111112',
- 'cvc' => '123',
- 'expiration' => '12/2020',
- 'ip' => '127.0.0.1',
+ 'card_number' => '4111111111111112',
+ 'cvc' => '123',
+ 'expiration' => '12/2020',
+ 'ip' => '127.0.0.1',
];
}
@@ -105,7 +105,7 @@ public function testCreaPagoReserva()
public function testContinuarPago($pago)
{
$continue = $this->api->continuePayment([
- 'id' => $pago['id_pago'],
+ 'id' => $pago['id_pago'],
'amount' => '200',
]);
From 0f954e752140db25d1efff17523b6699ed29a60d Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Mon, 7 Dec 2020 23:35:40 -0300
Subject: [PATCH 2/9] Fixed what needed fixing and squished some bugs. :bug:
---
LICENSE | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LICENSE b/LICENSE
index 1862148..f5b714d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2016 ángel
+Copyright (c) 2020 ángel cruz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
From df523560e22d03013713d8072320fd8028661013 Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Sun, 13 Dec 2020 09:07:08 -0300
Subject: [PATCH 3/9] Fixed what needed fixing and squished some bugs. :bug:
---
composer.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/composer.json b/composer.json
index adaf9aa..b076c74 100644
--- a/composer.json
+++ b/composer.json
@@ -17,8 +17,8 @@
}
],
"require": {
- "guzzlehttp/guzzle": "^7.2",
- "php": "^7.4|^8.0"
+ "php": "^7.4|^8.0",
+ "guzzlehttp/guzzle": "^7.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
From 60b0e0653928f165778e1b791b28a51473b760fe Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Sun, 13 Dec 2020 10:06:47 -0300
Subject: [PATCH 4/9] ordenando el proyecto :rocket:
---
CHANGELOG.md | 1 +
LICENSE => LICENSE.md | 2 +-
README.md | 15 +-
composer.json | 16 ++-
phpunit.xml | 14 --
phpunit.xml.dist | 31 ++++
psalm.xml.dist | 2 +-
{Instapago => src}/Api.php | 17 +--
.../Exceptions/AuthException.php | 2 +-
.../Exceptions/BankRejectException.php | 2 +-
.../Exceptions/GenericException.php | 2 +-
.../Exceptions/InstapagoException.php | 2 +-
.../Exceptions/InvalidInputException.php | 2 +-
.../Exceptions/TimeoutException.php | 2 +-
.../Exceptions/ValidationException.php | 2 +-
{Instapago => src}/Validator.php | 50 +++----
tests/.gitignore | 3 -
tests/ApiTest.php | 134 ------------------
tests/ExampleTest.php | 14 ++
19 files changed, 103 insertions(+), 210 deletions(-)
rename LICENSE => LICENSE.md (95%)
delete mode 100644 phpunit.xml
create mode 100644 phpunit.xml.dist
rename {Instapago => src}/Api.php (95%)
rename {Instapago => src}/Exceptions/AuthException.php (97%)
rename {Instapago => src}/Exceptions/BankRejectException.php (97%)
rename {Instapago => src}/Exceptions/GenericException.php (97%)
rename {Instapago => src}/Exceptions/InstapagoException.php (97%)
rename {Instapago => src}/Exceptions/InvalidInputException.php (97%)
rename {Instapago => src}/Exceptions/TimeoutException.php (97%)
rename {Instapago => src}/Exceptions/ValidationException.php (97%)
rename {Instapago => src}/Validator.php (61%)
delete mode 100644 tests/.gitignore
delete mode 100644 tests/ApiTest.php
create mode 100644 tests/ExampleTest.php
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41ba0d9..10a0b02 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
> Todos los cambios significativos en la librería serán registrados en éste documento.
### v6.0.0
+### Nuevo
* Se actualiza el code base
* Se agregan mejoras a nivel general
* Se dropea soporte a cualquier cosa menor a php 7.4
diff --git a/LICENSE b/LICENSE.md
similarity index 95%
rename from LICENSE
rename to LICENSE.md
index f5b714d..0e68607 100644
--- a/LICENSE
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2020 ángel cruz
+Copyright (c) 2020 ángel cruz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index b46996a..bbaa3e9 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,9 @@
NOTA Los logos son propiedad de Instapago y Banesco, respectivamente.
-[![GitHub issues](https://img.shields.io/github/issues/abr4xas/php-instapago.svg?style=flat-square)](https://github.com/abr4xas/php-instapago/issues) [![GitHub forks](https://img.shields.io/github/forks/abr4xas/php-instapago.svg?style=flat-square)](https://github.com/abr4xas/php-instapago/network) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/abr4xas/php-instapago/master/LICENSE)
+[![Latest Version on Packagist](https://img.shields.io/packagist/v/instapago/instapago.svg?style=flat-square)](https://packagist.org/packages/instapago/instapago)
+[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/instapago/instapago/run-tests?label=tests)](https://github.com/instapago/instapago/actions?query=workflow%3Arun-tests+branch%3Amaster)
+[![Total Downloads](https://img.shields.io/packagist/dt/instapago/instapago.svg?style=flat-square)](https://packagist.org/packages/instapago/instapago)
## instalación
@@ -29,7 +31,7 @@ creamos un archivo `index.php`
require 'vendor/autoload.php';
-use \Instapago\Api;
+use \Instapago\Instapago\Api;
$paymentData = [
@@ -82,17 +84,8 @@ Podemos revisar rápidamente si todo funciona correctamente escribiendo:
$ php -S localhost:8000
```
-### llaves de pruebas
-
-```
-* keyId = 74D4A278-C3F8-4D7A-9894-FA0571D7E023
-* publicKeyId = e9a5893e047b645fed12c82db877e05a
-```
-
## tests
-las llaves que se usan para los test son unicamente destinadas a este propósito.
-
```
$ composer all
diff --git a/composer.json b/composer.json
index b076c74..2a3ce52 100644
--- a/composer.json
+++ b/composer.json
@@ -1,18 +1,17 @@
{
"name": "instapago/instapago",
- "type": "library",
"description": "Librería Instapago para PHP",
"keywords": [
- "venezuela",
"instapago",
- "banesco"
+ "instapago"
],
+ "homepage": "https://github.com/instapago/instapago",
"license": "MIT",
"authors": [
{
"name": "angel cruz",
"email": "angel@tepuilabs.dev",
- "homepage": "https://angelcruz.dev",
+ "homepage": "https://angelcruz.me",
"role": "Developer"
}
],
@@ -27,14 +26,19 @@
},
"autoload": {
"psr-4": {
- "Instapago\\": "Instapago"
+ "Instapago\\Instapago\\": "src"
+ }
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "Instapago\\Instapago\\Tests\\": "tests"
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
- "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
+ "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"all" : "composer psalm && composer test && composer test-coverage && composer format"
},
"config": {
diff --git a/phpunit.xml b/phpunit.xml
deleted file mode 100644
index dbb8711..0000000
--- a/phpunit.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- tests/
-
-
-
-
- Instapago
-
-
-
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..9c2416f
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,31 @@
+
+
+
+
+ tests
+
+
+
+
+ ./src
+
+
+
+
+
+
+
+
+
+
+
diff --git a/psalm.xml.dist b/psalm.xml.dist
index 4d7e696..c6df33e 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -8,7 +8,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
-
+
diff --git a/Instapago/Api.php b/src/Api.php
similarity index 95%
rename from Instapago/Api.php
rename to src/Api.php
index 5706628..6aa2fdd 100644
--- a/Instapago/Api.php
+++ b/src/Api.php
@@ -27,17 +27,18 @@
* @copyright 2016 Angel Cruz
*/
-namespace Instapago;
+namespace Instapago\Instapago;
use GuzzleHttp\Client as Client;
+use GuzzleHttp\Exception\ConnectException;
/**
* Clase para la pasarela de pagos Instapago.
*/
class Api
{
- protected $keyId;
- protected $publicKeyId;
+ protected string $keyId;
+ protected string $publicKeyId;
/**
* Crear un nuevo objeto de Instapago.
@@ -46,7 +47,7 @@ class Api
* @param string $publicKeyId llave publica
* Requeridas.
*/
- public function __construct($keyId, $publicKeyId)
+ public function __construct(string $keyId, string $publicKeyId)
{
if (empty($keyId) || empty($publicKeyId)) {
throw new Exceptions\InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.');
@@ -210,12 +211,12 @@ public function cancel($id_pago)
* Efectúa y retornar una respuesta a un metodo de pago.
*
* @param $url string endpoint a consultar
- * @param $fields array datos para la consulta
* @param $method string verbo http de la consulta
+ * @param (mixed|string)[] $fields datos para la consulta
*
* @return array resultados de la transaccion
*/
- public function curlTransaccion($url, $fields, $method)
+ public function curlTransaccion(string $url, array $fields, string $method)
{
$client = new Client([
'base_uri' => 'https://api.instapago.com/',
@@ -235,7 +236,7 @@ public function curlTransaccion($url, $fields, $method)
$obj = json_decode($body, true);
return $obj;
- } catch (\GuzzleHttp\Exception\ConnectException $e) {
+ } catch (ConnectException $e) {
throw new Exceptions\TimeoutException('Cannot connect to api.instapago.com');
}
}
@@ -247,7 +248,7 @@ public function curlTransaccion($url, $fields, $method)
*
* @return array datos de transaccion
*/
- public function checkResponseCode($obj)
+ public function checkResponseCode(array $obj)
{
$code = $obj['code'];
diff --git a/Instapago/Exceptions/AuthException.php b/src/Exceptions/AuthException.php
similarity index 97%
rename from Instapago/Exceptions/AuthException.php
rename to src/Exceptions/AuthException.php
index 281a61a..ca3af2f 100644
--- a/Instapago/Exceptions/AuthException.php
+++ b/src/Exceptions/AuthException.php
@@ -27,7 +27,7 @@
* @copyright 2016 José Gómez
*/
-namespace Instapago\Exceptions;
+namespace Instapago\Instapago\Exceptions;
/**
* Custom AuthException.
diff --git a/Instapago/Exceptions/BankRejectException.php b/src/Exceptions/BankRejectException.php
similarity index 97%
rename from Instapago/Exceptions/BankRejectException.php
rename to src/Exceptions/BankRejectException.php
index 3166eb9..1939634 100644
--- a/Instapago/Exceptions/BankRejectException.php
+++ b/src/Exceptions/BankRejectException.php
@@ -27,7 +27,7 @@
* @copyright 2016 José Gómez
*/
-namespace Instapago\Exceptions;
+namespace Instapago\Instapago\Exceptions;
/**
* Custom BankRejectException.
diff --git a/Instapago/Exceptions/GenericException.php b/src/Exceptions/GenericException.php
similarity index 97%
rename from Instapago/Exceptions/GenericException.php
rename to src/Exceptions/GenericException.php
index cac68b9..fe8f6de 100644
--- a/Instapago/Exceptions/GenericException.php
+++ b/src/Exceptions/GenericException.php
@@ -27,7 +27,7 @@
* @copyright 2016 José Gómez
*/
-namespace Instapago\Exceptions;
+namespace Instapago\Instapago\Exceptions;
/**
* Custom GenericException.
diff --git a/Instapago/Exceptions/InstapagoException.php b/src/Exceptions/InstapagoException.php
similarity index 97%
rename from Instapago/Exceptions/InstapagoException.php
rename to src/Exceptions/InstapagoException.php
index 926a0de..dc21afe 100644
--- a/Instapago/Exceptions/InstapagoException.php
+++ b/src/Exceptions/InstapagoException.php
@@ -27,7 +27,7 @@
* @copyright 2016 Angel Cruz
*/
-namespace Instapago\Exceptions;
+namespace Instapago\Instapago\Exceptions;
/**
* Custom InstapagoException.
diff --git a/Instapago/Exceptions/InvalidInputException.php b/src/Exceptions/InvalidInputException.php
similarity index 97%
rename from Instapago/Exceptions/InvalidInputException.php
rename to src/Exceptions/InvalidInputException.php
index 15d740c..fe1d8b0 100644
--- a/Instapago/Exceptions/InvalidInputException.php
+++ b/src/Exceptions/InvalidInputException.php
@@ -27,7 +27,7 @@
* @copyright 2016 José Gómez
*/
-namespace Instapago\Exceptions;
+namespace Instapago\Instapago\Exceptions;
/**
* Custom InvalidInputException.
diff --git a/Instapago/Exceptions/TimeoutException.php b/src/Exceptions/TimeoutException.php
similarity index 97%
rename from Instapago/Exceptions/TimeoutException.php
rename to src/Exceptions/TimeoutException.php
index 68cb3d7..d459312 100644
--- a/Instapago/Exceptions/TimeoutException.php
+++ b/src/Exceptions/TimeoutException.php
@@ -27,7 +27,7 @@
* @copyright 2016 José Gómez
*/
-namespace Instapago\Exceptions;
+namespace Instapago\Instapago\Exceptions;
/**
* Custom TimeoutException.
diff --git a/Instapago/Exceptions/ValidationException.php b/src/Exceptions/ValidationException.php
similarity index 97%
rename from Instapago/Exceptions/ValidationException.php
rename to src/Exceptions/ValidationException.php
index 609bc30..406307f 100644
--- a/Instapago/Exceptions/ValidationException.php
+++ b/src/Exceptions/ValidationException.php
@@ -27,7 +27,7 @@
* @copyright 2016 José Gómez
*/
-namespace Instapago\Exceptions;
+namespace Instapago\Instapago\Exceptions;
/**
* Custom ValidationException.
diff --git a/Instapago/Validator.php b/src/Validator.php
similarity index 61%
rename from Instapago/Validator.php
rename to src/Validator.php
index d7acd76..9a38df1 100644
--- a/Instapago/Validator.php
+++ b/src/Validator.php
@@ -27,7 +27,7 @@
* @copyright 2016 José Gómez
*/
-namespace Instapago;
+namespace Instapago\Instapago;
/**
* Validator.
@@ -36,44 +36,44 @@
*/
class Validator
{
- protected $validations = [];
+ protected array $validations = [];
- public function payment()
+ public function payment(): self
{
$this->validations = [
- 'amount' => [FILTER_VALIDATE_FLOAT],
- 'description' => [FILTER_VALIDATE_REGEXP, '/^(.{0,140})$/'],
- 'card_holder' => [FILTER_VALIDATE_REGEXP, '/^([a-zA-ZáéíóúñÁÉÍÓÚÑ\ ]+)$/'],
- 'card_holder_id' => [FILTER_VALIDATE_REGEXP, '/^(\d{5,8})$/'],
- 'card_number' => [FILTER_VALIDATE_REGEXP, '/^(\d{16})$/'],
- 'cvc' => [FILTER_VALIDATE_INT],
- 'expiration' => [FILTER_VALIDATE_REGEXP, '/^(\d{2})\/(\d{4})$/'],
- 'ip' => [FILTER_VALIDATE_IP],
- ];
+ 'amount' => [FILTER_VALIDATE_FLOAT],
+ 'description' => [FILTER_VALIDATE_REGEXP, '/^(.{0,140})$/'],
+ 'card_holder' => [FILTER_VALIDATE_REGEXP, '/^([a-zA-ZáéíóúñÁÉÍÓÚÑ\ ]+)$/'],
+ 'card_holder_id' => [FILTER_VALIDATE_REGEXP, '/^(\d{5,8})$/'],
+ 'card_number' => [FILTER_VALIDATE_REGEXP, '/^(\d{16})$/'],
+ 'cvc' => [FILTER_VALIDATE_INT],
+ 'expiration' => [FILTER_VALIDATE_REGEXP, '/^(\d{2})\/(\d{4})$/'],
+ 'ip' => [FILTER_VALIDATE_IP],
+ ];
return $this;
}
- public function release()
+ public function release(): self
{
$this->validations = [
- 'amount' => [FILTER_VALIDATE_FLOAT],
- 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
- ];
+ 'amount' => [FILTER_VALIDATE_FLOAT],
+ 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
+ ];
return $this;
}
- public function query()
+ public function query(): self
{
$this->validations = [
- 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
- ];
+ 'id' => [FILTER_VALIDATE_REGEXP, '/^([0-9a-f]{8})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{4})\-([0-9a-f]{12})$/'],
+ ];
return $this;
}
- public function validate($fields)
+ public function validate(array $fields): void
{
foreach ($this->validations as $key => $filters) {
if (! $this->_validation($fields[$key], $filters)) {
@@ -82,16 +82,16 @@ public function validate($fields)
}
}
- private function _validation($value, $filters)
+ private function _validation(array $value, array $filters): bool
{
$filter = $filters[0];
$flags = [];
if ($filter === FILTER_VALIDATE_REGEXP) {
$flags = [
- 'options' => [
- 'regexp' => $filters[1],
- ],
- ];
+ 'options' => [
+ 'regexp' => $filters[1],
+ ],
+ ];
}
return filter_var($value, $filter, $flags);
diff --git a/tests/.gitignore b/tests/.gitignore
deleted file mode 100644
index 067fa69..0000000
--- a/tests/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*
-!ApiTest.php
-!.gitignore
\ No newline at end of file
diff --git a/tests/ApiTest.php b/tests/ApiTest.php
deleted file mode 100644
index 9b1e0b4..0000000
--- a/tests/ApiTest.php
+++ /dev/null
@@ -1,134 +0,0 @@
-.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the “Software”), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @author Angel Cruz
- * @license MIT License
- * @copyright 2016 Angel Cruz
- */
-use Instapago\Api;
-use PHPUnit\Framework\TestCase;
-
-class ApiTest extends TestCase
-{
- protected $api;
- protected $pago;
-
- protected function setUp()
- {
- $this->api = new Api(
- 'D99BF283-A630-4168-9FED-6D2DA7E38DCA',
- 'e9a5893e047b645fed12c82db877e05a'
- );
- }
-
- private function _dataPagoPrueba()
- {
- return [
- 'amount' => '200',
- 'description' => 'PHPUnit Test Payment',
- 'card_holder' => 'juan peñalver',
- 'card_holder_id' => '11111111',
- 'card_number' => '4111111111111111',
- 'cvc' => '123',
- 'expiration' => '12/2020',
- 'ip' => '127.0.0.1',
- ];
- }
-
- private function _dataPagoPruebaError()
- {
- return [
- 'amount' => '200.00',
- 'description' => 'PHPUnit Test Payment',
- 'card_holder' => 'juan peñalver',
- 'card_holder_id' => '11111111',
- 'card_number' => '4111111111111112',
- 'cvc' => '123',
- 'expiration' => '12/2020',
- 'ip' => '127.0.0.1',
- ];
- }
-
- public function testBadData()
- {
- try {
- $data = $this->_dataPagoPruebaError();
- $pago = $this->api->directPayment($data);
- } catch (\Instapago\Exceptions\InvalidInputException $e) {
- $this->assertContains('Error al validar los datos enviados', $e->getMessage());
- }
- }
-
- public function testCreaPagoDirecto()
- {
- $data = $this->_dataPagoPrueba();
- $pago = $this->api->directPayment($data);
- $this->assertEquals(201, $pago['code']);
-
- return $pago;
- }
-
- public function testCreaPagoReserva()
- {
- $data = $this->_dataPagoPrueba();
- $pago = $this->api->reservePayment($data);
- $this->assertEquals(201, $pago['code']);
- $this->assertContains('pago aprobado', strtolower($pago['msg_banco']));
-
- return $pago;
- }
-
- /**
- * @depends testCreaPagoReserva
- */
- public function testContinuarPago($pago)
- {
- $continue = $this->api->continuePayment([
- 'id' => $pago['id_pago'],
- 'amount' => '200',
- ]);
-
- $this->assertContains('pago completado', strtolower($continue['msg_banco']));
- }
-
- /**
- * @depends testCreaPagoDirecto
- */
- public function testInfoPago($pago)
- {
- $info = $this->api->query($pago['id_pago']);
- $this->assertContains('autorizada', strtolower($info['msg_banco']));
- }
-
- /**
- * @depends testCreaPagoDirecto
- * En modo pruebas este método no funciona.
- * El personal de instapago asegura que en producción no hay problemas
- */
- public function testCancelPago($pago)
- {
- $info = $this->api->cancel($pago['id_pago']);
- $this->assertContains('el pago ha sido anulado', strtolower($info['msg_banco']));
- }
-}
diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php
new file mode 100644
index 0000000..08882cc
--- /dev/null
+++ b/tests/ExampleTest.php
@@ -0,0 +1,14 @@
+assertTrue(true);
+ }
+}
From 617921fdb947a01052cf8d4a5de041ec08db5824 Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Sun, 13 Dec 2020 10:09:24 -0300
Subject: [PATCH 5/9] Fix the fixes
---
.github/CONTRIBUTING.md | 55 ++++++++++++++++++++++++++++++
.github/ISSUE_TEMPLATE/config.yml | 11 ++++++
.github/workflows/php-cs-fixer.yml | 23 +++++++++++++
.github/workflows/psalm.yml | 33 ++++++++++++++++++
.github/workflows/run-tests.yml | 37 ++++++++++++++++++++
5 files changed, 159 insertions(+)
create mode 100644 .github/CONTRIBUTING.md
create mode 100644 .github/ISSUE_TEMPLATE/config.yml
create mode 100644 .github/workflows/php-cs-fixer.yml
create mode 100644 .github/workflows/psalm.yml
create mode 100644 .github/workflows/run-tests.yml
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
new file mode 100644
index 0000000..b4ae1c4
--- /dev/null
+++ b/.github/CONTRIBUTING.md
@@ -0,0 +1,55 @@
+# Contributing
+
+Contributions are **welcome** and will be fully **credited**.
+
+Please read and understand the contribution guide before creating an issue or pull request.
+
+## Etiquette
+
+This project is open source, and as such, the maintainers give their free time to build and maintain the source code
+held within. They make the code freely available in the hope that it will be of use to other developers. It would be
+extremely unfair for them to suffer abuse or anger for their hard work.
+
+Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
+world that developers are civilized and selfless people.
+
+It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
+quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
+
+## Viability
+
+When requesting or submitting new features, first consider whether it might be useful to others. Open
+source projects are used by many developers, who may have entirely different needs to your own. Think about
+whether or not your feature is likely to be used by other users of the project.
+
+## Procedure
+
+Before filing an issue:
+
+- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
+- Check to make sure your feature suggestion isn't already present within the project.
+- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
+- Check the pull requests tab to ensure that the feature isn't already in progress.
+
+Before submitting a pull request:
+
+- Check the codebase to ensure that your feature doesn't already exist.
+- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
+
+## Requirements
+
+If the project maintainer has any additional requirements, you will find them listed here.
+
+- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
+
+- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
+
+- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
+
+- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
+
+- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
+
+- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
+
+**Happy coding**!
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..32e7e1e
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,11 @@
+blank_issues_enabled: false
+contact_links:
+ - name: Ask a Question
+ url: https://github.com/instapago/instapago/discussions/new?category=q-a
+ about: Ask the community for help
+ - name: Feature Request
+ url: https://github.com/instapago/instapago/discussions/new?category=ideas
+ about: Share ideas for new features
+ - name: Bug Report
+ url: https://github.com/instapago/instapago/issues/new
+ about: Report a reproducable bug
diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml
new file mode 100644
index 0000000..4cf285f
--- /dev/null
+++ b/.github/workflows/php-cs-fixer.yml
@@ -0,0 +1,23 @@
+name: Check & fix styling
+
+on: [push]
+
+jobs:
+ php-cs-fixer:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ ref: ${{ github.head_ref }}
+
+ - name: Run PHP CS Fixer
+ uses: docker://oskarstark/php-cs-fixer-ga
+ with:
+ args: --config=.php_cs.dist --allow-risky=yes
+
+ - name: Commit changes
+ uses: stefanzweifel/git-auto-commit-action@v4
+ with:
+ commit_message: Fix styling
diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml
new file mode 100644
index 0000000..99cf0d9
--- /dev/null
+++ b/.github/workflows/psalm.yml
@@ -0,0 +1,33 @@
+name: Psalm
+
+on:
+ push:
+ paths:
+ - '**.php'
+ - 'psalm.xml.dist'
+
+jobs:
+ psalm:
+ name: psalm
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '7.4'
+ extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
+ coverage: none
+
+ - name: Cache composer dependencies
+ uses: actions/cache@v2
+ with:
+ path: vendor
+ key: composer-${{ hashFiles('composer.lock') }}
+
+ - name: Run composer install
+ run: composer install -n --prefer-dist
+
+ - name: Run psalm
+ run: ./vendor/bin/psalm --output-format=github
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
new file mode 100644
index 0000000..6f2791a
--- /dev/null
+++ b/.github/workflows/run-tests.yml
@@ -0,0 +1,37 @@
+name: Tests
+
+on: [push, pull_request]
+
+jobs:
+ test:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: true
+ matrix:
+ os: [ubuntu-latest, windows-latest]
+ php: [8.0, 7.4]
+ stability: [prefer-lowest, prefer-stable]
+
+ name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
+ coverage: none
+
+ - name: Setup problem matchers
+ run: |
+ echo "::add-matcher::${{ runner.tool_cache }}/php.json"
+ echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
+
+ - name: Install dependencies
+ run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
+
+ - name: Execute tests
+ run: vendor/bin/phpunit
From c96f4bc4802e54ce12e3fbb11c9a452f0f8ab6e2 Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Sun, 13 Dec 2020 10:10:52 -0300
Subject: [PATCH 6/9] Programming the flux capacitor
---
.github/workflows/run-tests.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
index 6f2791a..31a1cd3 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
- php: [8.0, 7.4]
+ php: [7.4]
stability: [prefer-lowest, prefer-stable]
name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
@@ -24,7 +24,7 @@ jobs:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
-
+
- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
From 7db95e003783ba5e9e528799ce88025834686cb6 Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Sun, 13 Dec 2020 10:14:44 -0300
Subject: [PATCH 7/9] Spinning up the hamster...
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index bbaa3e9..deac5ad 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/instapago/instapago.svg?style=flat-square)](https://packagist.org/packages/instapago/instapago)
-[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/instapago/instapago/run-tests?label=tests)](https://github.com/instapago/instapago/actions?query=workflow%3Arun-tests+branch%3Amaster)
+[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/instapago/instapago/run-tests?label=tests)](https://github.com/instapago/instapago/actions?query=workflow%3ATests+branch%3Amaster)
[![Total Downloads](https://img.shields.io/packagist/dt/instapago/instapago.svg?style=flat-square)](https://packagist.org/packages/instapago/instapago)
From ef46c805c54b26386f36945db024b575c90bafd6 Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Sun, 13 Dec 2020 10:29:25 -0300
Subject: [PATCH 8/9] Fixed what needed fixing and squished some bugs. :bug:
---
.php_cs.dist | 2 +-
README.md | 25 +++++++++++++++++++------
src/Api.php | 24 +++++++++++++++---------
3 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/.php_cs.dist b/.php_cs.dist
index b68900e..ac127a7 100644
--- a/.php_cs.dist
+++ b/.php_cs.dist
@@ -2,7 +2,7 @@
$finder = Symfony\Component\Finder\Finder::create()
->in([
- __DIR__ . '/Instapago',
+ __DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
diff --git a/README.md b/README.md
index deac5ad..ccdcdd4 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,15 @@ creamos un archivo `index.php`
require 'vendor/autoload.php';
use \Instapago\Instapago\Api;
+use \Instapago\Instapago\Exceptions\{
+ InstapagoException,
+ AuthException,
+ BankRejectException,
+ InvalidInputException,
+ TimeoutException,
+ ValidationException,
+ GenericException,
+};
$paymentData = [
@@ -51,27 +60,31 @@ try{
$respuesta = $api->directPayment($paymentData);
// hacer algo con $respuesta
-}catch(\Instapago\Exceptions\InstapagoException $e){
+}catch(InstapagoException $e){
echo $e->getMessage(); // manejar el error
-}catch(\Instapago\Exceptions\AuthException $e){
+}catch(AuthException $e){
echo $e->getMessage(); // manejar el error
-}catch(\Instapago\Exceptions\BankRejectException $e){
+}catch(BankRejectException $e){
echo $e->getMessage(); // manejar el error
-}catch(\Instapago\Exceptions\InvalidInputException $e){
+}catch(InvalidInputException $e){
echo $e->getMessage(); // manejar el error
-}catch(\Instapago\Exceptions\TimeoutException $e){
+}catch(TimeoutException $e){
echo $e->getMessage(); // manejar el error
-}catch(\Instapago\Exceptions\ValidationException $e){
+}catch(ValidationException $e){
+
+ echo $e->getMessage(); // manejar el error
+
+}catch(GenericException $e){
echo $e->getMessage(); // manejar el error
diff --git a/src/Api.php b/src/Api.php
index 6aa2fdd..7118d5a 100644
--- a/src/Api.php
+++ b/src/Api.php
@@ -29,6 +29,12 @@
namespace Instapago\Instapago;
+use \Instapago\Instapago\Exceptions\AuthException;
+use \Instapago\Instapago\Exceptions\BankRejectException;
+use \Instapago\Instapago\Exceptions\GenericException;
+use \Instapago\Instapago\Exceptions\InstapagoException;
+use \Instapago\Instapago\Exceptions\InvalidInputException;
+use \Instapago\Instapago\Exceptions\TimeoutException;
use GuzzleHttp\Client as Client;
use GuzzleHttp\Exception\ConnectException;
@@ -50,7 +56,7 @@ class Api
public function __construct(string $keyId, string $publicKeyId)
{
if (empty($keyId) || empty($publicKeyId)) {
- throw new Exceptions\InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.');
+ throw new InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.');
}
$this->publicKeyId = $publicKeyId;
$this->keyId = $keyId;
@@ -224,7 +230,7 @@ public function curlTransaccion(string $url, array $fields, string $method)
$args = [];
if (! in_array($method, ['GET', 'POST', 'DELETE'])) {
- throw new Exceptions\GenericException('Not implemented yet', 1);
+ throw new GenericException('Not implemented yet', 1);
}
$key = ($method == 'GET') ? 'query' : 'form_params';
@@ -237,7 +243,7 @@ public function curlTransaccion(string $url, array $fields, string $method)
return $obj;
} catch (ConnectException $e) {
- throw new Exceptions\TimeoutException('Cannot connect to api.instapago.com');
+ throw new TimeoutException('Cannot connect to api.instapago.com');
}
}
@@ -254,27 +260,27 @@ public function checkResponseCode(array $obj)
switch ($code) {
case 400:
- throw new Exceptions\InvalidInputException(
+ throw new InvalidInputException(
'Error al validar los datos enviados.'
);
case 401:
- throw new Exceptions\AuthException(
+ throw new AuthException(
'Error de autenticación, ha ocurrido un error con las llaves utilizadas.'
);
case 403:
- throw new Exceptions\BankRejectException(
+ throw new BankRejectException(
'Pago Rechazado por el banco.'
);
case 500:
- throw new Exceptions\InstapagoException(
+ throw new InstapagoException(
'Ha Ocurrido un error interno dentro del servidor.'
);
case 503:
- throw new Exceptions\InstapagoException(
+ throw new InstapagoException(
'Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo.'
);
@@ -289,7 +295,7 @@ public function checkResponseCode(array $obj)
];
default:
- throw new Exceptions\GenericException('Not implemented yet');
+ throw new GenericException('Not implemented yet');
}
}
From 553ca3b735f8eb3fb9e3645968309a434b99f06c Mon Sep 17 00:00:00 2001
From: angel cruz
Date: Sun, 13 Dec 2020 22:08:42 -0300
Subject: [PATCH 9/9] release v6.0.0 :rocket:
---
.gitignore | 1 +
CHANGELOG.md | 2 +-
README.md | 7 ++-
src/Validator.php | 2 +-
tests/ApiInstapagoTest.php | 109 +++++++++++++++++++++++++++++++++++++
tests/ExampleTest.php | 14 -----
6 files changed, 117 insertions(+), 18 deletions(-)
create mode 100644 tests/ApiInstapagoTest.php
delete mode 100644 tests/ExampleTest.php
diff --git a/.gitignore b/.gitignore
index 0296b57..f6ed20a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ docs
phpunit.xml
psalm.xml
vendor
+test.php
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10a0b02..c5e56bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@
### Nuevo
* Se actualiza el code base
* Se agregan mejoras a nivel general
-* Se dropea soporte a cualquier cosa menor a php 7.4
+* Se agregan test y funcionan correctamente :)
Lamento haber olvidado hacer los tags correspondientes :(
diff --git a/README.md b/README.md
index ccdcdd4..45bbe9a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
-![Php Instapago](help/hYNsH6B.png)
+
+
+
+
Librería Instapago para PHP
@@ -24,7 +27,7 @@ $ composer dumpautoload -o // opcional
### como usar
-creamos un archivo `index.php`
+>NOTA: Tomar en cuenta que esta nueva versión fue probada usando php7.4, no aseguro que funcione en algo menor a eso, en *teoría* debería pero no estoy seguro.
```php
api = new Api('0D22A123-3BF3-4F6B-B209-9ACBAE52D1EE', 'e8d1e67e6d9033cd03a44017c1624a39');
+ }
+
+ private function _dataPagoPrueba()
+ {
+ return [
+ 'amount' => '200',
+ 'description' => 'PHPUnit Test Payment',
+ 'card_holder' => 'juan peñalver',
+ 'card_holder_id' => '11111111',
+ 'card_number' => '4111111111111111',
+ 'cvc' => '123',
+ 'expiration' => '12/2020',
+ 'ip' => '127.0.0.1',
+ ];
+ }
+
+ private function _dataPagoPruebaError()
+ {
+ return [
+ 'amount' => '200.00',
+ 'description' => 'PHPUnit Test Payment',
+ 'card_holder' => 'juan peñalver',
+ 'card_holder_id' => '11111111',
+ 'card_number' => '4111111111111112',
+ 'cvc' => '123',
+ 'expiration' => '12/2020',
+ 'ip' => '127.0.0.1',
+ ];
+ }
+
+ /** @test */
+ public function test_data_erronea()
+ {
+ try {
+ $data = $this->_dataPagoPruebaError();
+ $pago = $this->api->directPayment($data);
+ } catch (InvalidInputException $e) {
+ $this->assertStringContainsStringIgnoringCase('Error al validar los datos enviados', $e->getMessage());
+ }
+ }
+
+ /** @test */
+ public function test_crear_pago_directo()
+ {
+ $data = $this->_dataPagoPrueba();
+ $pago = $this->api->directPayment($data);
+ $this->assertEquals(201, $pago['code']);
+
+ return $pago;
+ }
+
+ /** @test */
+ public function test_crear_pago_reserva()
+ {
+ $data = $this->_dataPagoPrueba();
+ $pago = $this->api->reservePayment($data);
+ $this->assertEquals(201, $pago['code']);
+ $this->assertStringContainsStringIgnoringCase('pago aprobado', strtolower($pago['msg_banco']));
+
+ return $pago;
+ }
+
+ /**
+ * @depends test_crear_pago_reserva
+ */
+ public function testContinuarPago($pago)
+ {
+ $continue = $this->api->continuePayment([
+ 'id' => $pago['id_pago'],
+ 'amount' => '200',
+ ]);
+
+ $this->assertStringContainsStringIgnoringCase('pago completado', strtolower($continue['msg_banco']));
+ }
+
+ /**
+ * @depends test_crear_pago_directo
+ */
+ public function test_info_pago($pago)
+ {
+ $info = $this->api->query($pago['id_pago']);
+ $this->assertStringContainsStringIgnoringCase('autorizada', strtolower($info['msg_banco']));
+ }
+
+ /**
+ * @depends test_crear_pago_directo
+ */
+ public function test_cancelar_pago($pago)
+ {
+ $info = $this->api->cancel($pago['id_pago']);
+ $this->assertStringContainsStringIgnoringCase('el pago ha sido anulado', strtolower($info['msg_banco']));
+ }
+}
diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php
deleted file mode 100644
index 08882cc..0000000
--- a/tests/ExampleTest.php
+++ /dev/null
@@ -1,14 +0,0 @@
-assertTrue(true);
- }
-}