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.
Passed
Push — master ( 68460a...213420 )
by Miguel
42s queued 11s
created

Transaction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCheckoutId() 0 3 1
A status() 0 25 2
A __construct() 0 10 2
A setCheckoutId() 0 3 1
1
<?php
2
3
namespace Apoca\Sibs\Brands;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\ClientException;
7
8
/**
9
 * Class Transaction
10
 *
11
 * @package Apoca\Sibs\Brands
12
 */
13
class Transaction
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $checkoutId;
19
20
    /**
21
     * @var string
22
     */
23
    protected $endpoint;
24
25
    /**
26
     * @var array
27
     */
28
    protected $clientConfig = [];
29
30
    /**
31
     * Transaction constructor.
32
     *
33
     * @param string $checkoutId
34
     */
35
    public function __construct(string $checkoutId)
36
    {
37
        $this->setCheckoutId($checkoutId);
38
39
        if (config('sibs.mode') === 'test') {
40
            $this->clientConfig = [
41
                'verify' => false,
42
            ];
43
        }
44
        $this->endpoint = config('sibs.host') . config('sibs.version') . '/';
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getCheckoutId(): string
51
    {
52
        return $this->checkoutId;
53
    }
54
55
    /**
56
     * @param mixed $checkoutId
57
     */
58
    public function setCheckoutId($checkoutId): void
59
    {
60
        $this->checkoutId = $checkoutId;
61
    }
62
63
    /**
64
     * Get status payment
65
     *
66
     * @return object
67
     */
68
    public function status(): object
69
    {
70
        $data = (object)null;
71
72
        try {
73
            $client = new Client($this->clientConfig);
74
75
            $response = $client->post($this->endpoint . "checkouts/{$this->getCheckoutId()}/payment?entityId=" . config('sibs.authentication.entityId'),
76
                [
77
                    'headers' => [
78
                        'Authorization' => config('sibs.authentication.token'),
79
                    ],
80
                ]);
81
82
            $data->status = $response->getStatusCode();
83
            $data->response = json_decode($response->getBody()->getContents());
84
85
            return $data;
86
        } catch (ClientException $e) {
87
            $response = $e->getResponse();
88
89
            $data->status = $response->getStatusCode();
90
            $data->response = json_decode($response->getBody()->getContents());
91
92
            return $data;
93
        }
94
    }
95
}
96