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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 2
A __construct() 0 4 1
A chargeByToken() 0 7 1
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