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 ( 912ff7...0b7f7f )
by Lanre
05:08
created

ChargeWithToken::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 2
b 0
f 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Gbowo\Adapter\Paystack\Plugin;
4
5
use Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException;
6
use InvalidArgumentException;
7
use Gbowo\Contract\Customer\BillInterface;
8
use function GuzzleHttp\json_decode;
9
use Gbowo\Plugin\AbstractChargeWithToken;
10
11
/**
12
 * Charge a customer with the token returned from the first transaction initiated with the Paystack
13
 * @author Lanre Adelowo <[email protected]>
14
 * Class ChargeWithToken
15
 * @package Gbowo\Adapter\Paystack\Plugin
16
 */
17
class ChargeWithToken extends AbstractChargeWithToken implements BillInterface
18
{
19
20
    /**
21
     * The relative link for charging users
22
     * @var string
23
     */
24
    const TOKEN_CHARGE_RELATIVE_LINK = "/charge_token";
25
26
    const SUCCESS_MESSAGE = "Charge successful";
27
    /**
28
     * @var string
29
     */
30
    protected $baseUrl;
31
32 13
    public function __construct(string $baseUrl)
33
    {
34 13
        $this->baseUrl = $baseUrl;
35 13
    }
36
37 3
    public function handle(array $data)
38
    {
39 3
        if (!array_key_exists("token", $data)) {
40 1
            throw new InvalidArgumentException(
41 1
                "A token must be specified"
42
            );
43
        }
44
45 2
        $response = $this->chargeByToken($data);
46
47 2
        $res = json_decode($response->getBody(), true);
48
49 2
        if (strcmp($res['message'], self::SUCCESS_MESSAGE) !== 0) {
50 1
            throw new TransactionVerficationFailedException(
51 1
                "The transaction was not successful"
52
            );
53
        }
54
55 1
        return $res['data'];
56
    }
57
58 2
    public function chargeByToken($token)
59
    {
60 2
        return $this->adapter->getHttpClient()
61 2
            ->post($this->baseUrl . self::TOKEN_CHARGE_RELATIVE_LINK);
62
    }
63
}
64