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   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 22 3
A verifyTransaction() 0 5 1
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