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

ChargeWithToken::chargeByToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
ccs 4
cts 4
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 GuzzleHttp\json_decode;
7
use function GuzzleHttp\json_encode;
8
use Gbowo\Plugin\AbstractChargeWithToken;
9
use Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException;
10
11
class ChargeWithToken extends AbstractChargeWithToken
12
{
13
14
    use VerifyHttpStatusResponseCode;
15
16
    /**
17
     * The relative link for charging users
18
     * @var string
19
     */
20
    const TOKEN_CHARGE_RELATIVE_LINK = "/transaction/charge_authorization";
21
22
    const SUCCESS_MESSAGE = "Successful";
23
    /**
24
     * @var string
25
     */
26
    protected $baseUrl;
27
28 29
    public function __construct(string $baseUrl)
29
    {
30 29
        $this->baseUrl = $baseUrl;
31 29
    }
32
33 3
    public function handle(array $args) : array
34
    {
35 3
        $response = $this->chargeByToken($args);
36
37 3
        $this->verifyResponse($response);
38
39 2
        $res = json_decode($response->getBody(), true);
40
41 2
        if (strcmp($res['data']['gateway_response'], self::SUCCESS_MESSAGE) !== 0) {
42 1
            throw new TransactionVerficationFailedException(
43 1
                "The transaction was not successful"
44
            );
45
        }
46
47 1
        return $res['data'];
48
    }
49
50 3
    public function chargeByToken($data)
51
    {
52 3
        return $this->adapter->getHttpClient()
53 3
            ->post($this->baseUrl . self::TOKEN_CHARGE_RELATIVE_LINK, [
54 3
                'body' => json_encode($data)
55
            ]);
56
    }
57
}
58