Skip to content

Commit

Permalink
Adding new methods response & isSuccessful on payment object
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielMejiaDev committed Feb 22, 2021
1 parent 1941113 commit 22e0e11
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 8 deletions.
15 changes: 15 additions & 0 deletions .idea/PagaloGT.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
22 changes: 19 additions & 3 deletions src/PagaloGT.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ArielMejiaDev\PagaloGT;

use Illuminate\Http\Client\Response;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;

Expand All @@ -17,8 +18,7 @@ class PagaloGT

const APPROVE_REASON_CODE = 100;
const APPROVE_DECISION = "ACCEPT";
private $responseDecision;
private $responseReasonCode;
protected $response;

public function __construct()
{
Expand Down Expand Up @@ -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 = [
Expand All @@ -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;
}
}

0 comments on commit 22e0e11

Please sign in to comment.