From 22e0e112e1efb1c65dd45d1b74761b700ffd321d Mon Sep 17 00:00:00 2001 From: ArielMejiaDev Date: Sun, 21 Feb 2021 18:34:03 -0600 Subject: [PATCH] Adding new methods response & isSuccessful on payment object --- .idea/PagaloGT.iml | 15 +++++++++++++++ .idea/php.xml | 20 ++++++++++++++++++++ .idea/phpunit.xml | 10 ++++++++++ .idea/vcs.xml | 6 ++++++ .idea/workspace.xml | 35 ++++++++++++++++++++++++++++++++++- composer.json | 8 ++++---- src/PagaloGT.php | 22 +++++++++++++++++++--- 7 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 .idea/phpunit.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/PagaloGT.iml b/.idea/PagaloGT.iml index 3ba18b3..d91c7dd 100644 --- a/.idea/PagaloGT.iml +++ b/.idea/PagaloGT.iml @@ -90,6 +90,21 @@ + + + + + + + + + + + + + + + diff --git a/.idea/php.xml b/.idea/php.xml index bca27f6..fe5aafc 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -87,7 +87,27 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml new file mode 100644 index 0000000..4f8104c --- /dev/null +++ b/.idea/phpunit.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c942269..f70788d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,13 @@ - + + + + + + + + + @@ -98,6 +107,21 @@ + + + + + + + + + + + + + + + @@ -107,11 +131,19 @@ + + + + + + + + @@ -125,6 +157,7 @@ + diff --git a/composer.json b/composer.json index 16dfebe..d782bcc 100755 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ } ], "require": { - "php": "^7.1", - "illuminate/support": "^8.0" + "php": "^7.1|^8.0", + "illuminate/support": "^7.0|^8.0" }, "require-dev": { - "orchestra/testbench": "^6.0", - "phpunit/phpunit": "^8.0" + "orchestra/testbench": "^5.0|^6.0", + "phpunit/phpunit": "^8.0|^9.0" }, "autoload": { "psr-4": { diff --git a/src/PagaloGT.php b/src/PagaloGT.php index a1c9d4f..79b884c 100755 --- a/src/PagaloGT.php +++ b/src/PagaloGT.php @@ -2,6 +2,7 @@ namespace ArielMejiaDev\PagaloGT; +use Illuminate\Http\Client\Response; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; @@ -17,8 +18,7 @@ class PagaloGT const APPROVE_REASON_CODE = 100; const APPROVE_DECISION = "ACCEPT"; - private $responseDecision; - private $responseReasonCode; + protected $response; public function __construct() { @@ -114,6 +114,21 @@ public function setRetry($times, $sleep) return Http::retry($this->retryTimes, $this->retrySleep)->post($this->url, $data); } + public function isSuccessful() + { + return isset($this->response->json()['decision']) && + $this->response->json()['decision'] === self::APPROVE_DECISION && + $this->response->json()['reasonCode'] === self::APPROVE_REASON_CODE; + } + + /** + * @return Response + */ + public function response(): Response + { + return $this->response; + } + public function pay() { $data = [ @@ -123,6 +138,7 @@ public function pay() 'tarjetaPagalo' => json_encode($this->card), ]; - return Http::post($this->url, $data); + $this->response = Http::post($this->url, $data); + return $this; } }