GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8bb018...93d08f )
by Lanre
02:25
created

GetPaymentData::verifyTransaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Gbowo\Adapter\Paystack\Plugin;
4
5
use Gbowo\Adapter\Paystack\Traits\VerifyHttpStatusResponseCode;
6
use function strcmp;
7
use function GuzzleHttp\json_decode;
8
use Gbowo\Plugin\AbstractGetPaymentData;
9
use Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException;
10
11
class GetPaymentData extends AbstractGetPaymentData
12
{
13
14
    use VerifyHttpStatusResponseCode;
15
16
    const VERIFIED_TRANSACTION = 'Verification successful';
17
18
    const INVALID_TRANSACTION = "Invalid transaction reference";
19
20
    const TRANSACTION_VERIFICATION = '/transaction/verify/';
21
22
    protected $baseUrl;
23
24
    public function __construct(string $baseUrl)
25
    {
26
        $this->baseUrl = $baseUrl;
27
    }
28
29
    /**
30
     * @param string $reference
31
     * @return mixed
32
     * @throws \Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException
33
     */
34 4
    public function handle(string $reference) : array
35
    {
36 4
        $link = $this->baseUrl . self::TRANSACTION_VERIFICATION . $reference;
37
38 4
        $response = $this->verifyTransaction($link);
39
40 4
        $this->verifyResponse($response);
41
42 3
        $result = json_decode($response->getBody(), true);
43
44 3
        $validated = false;
45
46 3
        if (strcmp($result['message'], self::VERIFIED_TRANSACTION) === 0) {
47 2
            $validated = true;
48
        }
49
50 3
        if (false === $validated) {
51 1
            throw new TransactionVerficationFailedException(self::INVALID_TRANSACTION);
52
        }
53
54 2
        return $result["data"];
55
    }
56
57
    /**
58
     * @param string $link
59
     * @return \Psr\Http\Message\ResponseInterface
60
     */
61 4
    protected function verifyTransaction(string $link)
62
    {
63 4
        return $this->adapter->getHttpClient()
64 4
            ->get($link);
65
    }
66
}
67