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   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 47
ccs 16
cts 16
cp 1
rs 10
wmc 5
lcom 1
cbo 2

3 Methods

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