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.

Checkout   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 163
rs 10
c 0
b 0
f 0
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptionalParameters() 0 3 1
A getAmount() 0 3 1
A setOptionalParameters() 0 3 1
A setAmount() 0 3 1
A getCurrency() 0 3 1
A setCurrency() 0 3 1
A __construct() 0 13 2
A setPaymentType() 0 3 1
A getPaymentType() 0 3 1
A pay() 0 41 3
1
<?php
2
3
namespace Apoca\Sibs\Brands;
4
5
use Apoca\Sibs\Contracts\PaymentInterface;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\ClientException;
8
9
/**
10
 * Class Checkout
11
 *
12
 * @package Apoca\Sibs\Brands
13
 */
14
class Checkout implements PaymentInterface
15
{
16
    /**
17
     * @var float
18
     */
19
    protected $amount;
20
21
    /**
22
     * @var string
23
     */
24
    protected $currency;
25
26
    /**
27
     * @var string
28
     */
29
    protected $paymentType = 'DB';
30
31
    /**
32
     * @var string
33
     */
34
    protected $endpoint;
35
36
    /**
37
     * @var array
38
     */
39
    protected $clientConfig = [];
40
41
    /**
42
     * @var array
43
     */
44
    protected $optionalParameters = [];
45
46
    /**
47
     * Checkout constructor.
48
     *
49
     * @param float  $amount
50
     * @param string $currency
51
     * @param string $paymentType
52
     * @param array  $optionalParameters
53
     */
54
    public function __construct(float $amount, string $currency, string $paymentType, array $optionalParameters)
55
    {
56
        $this->setAmount($amount);
57
        $this->setCurrency($currency);
58
        $this->setPaymentType($paymentType);
59
        $this->setOptionalParameters($optionalParameters);
60
61
        if (config('sibs.mode') === 'test') {
62
            $this->clientConfig = [
63
                'verify' => false,
64
            ];
65
        }
66
        $this->endpoint = config('sibs.host') . config('sibs.version') . '/';
67
    }
68
69
    /**
70
     * @return array
71
     */
72
    public function getOptionalParameters(): array
73
    {
74
        return $this->optionalParameters;
75
    }
76
77
    /**
78
     * @param array $optionalParameters
79
     */
80
    public function setOptionalParameters(array $optionalParameters): void
81
    {
82
        $this->optionalParameters = $optionalParameters;
83
    }
84
85
    /**
86
     * @return float
87
     */
88
    public function getAmount(): float
89
    {
90
        return $this->amount;
91
    }
92
93
    /**
94
     * @param float $amount
95
     */
96
    public function setAmount(float $amount): void
97
    {
98
        $this->amount = $amount;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getCurrency(): string
105
    {
106
        return $this->currency;
107
    }
108
109
    /**
110
     * @param string $currency
111
     */
112
    public function setCurrency(string $currency): void
113
    {
114
        $this->currency = $currency;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getPaymentType(): string
121
    {
122
        return $this->paymentType;
123
    }
124
125
    /**
126
     * @param string $paymentType
127
     */
128
    public function setPaymentType(string $paymentType): void
129
    {
130
        $this->paymentType = $paymentType;
131
    }
132
133
    /**
134
     * @return object
135
     */
136
    public function pay(): object
137
    {
138
        $data = (object)null;
139
140
        try {
141
            $client = new Client($this->clientConfig);
142
143
            $payload = [
144
                'entityId' => config('sibs.authentication.entityId'),
145
                'amount' => number_format($this->amount, 2),
146
                'currency' => $this->currency,
147
                'paymentType' => $this->paymentType,
148
            ];
149
            if (config('sibs.mode') === 'test') {
150
                $payload = array_merge($payload,
151
                    [
152
                        'customParameters[SIBS_ENV]' => 'QLY',
153
                        'testMode' => 'EXTERNAL',
154
                    ]);
155
            }
156
157
            $response = $client->post($this->endpoint . 'checkouts', [
158
                'headers' => [
159
                    'Content-Type' => 'application/x-www-form-urlencoded',
160
                    'Content-Length' => ob_get_length(),
161
                    'Authorization' => config('sibs.authentication.token'),
162
                ],
163
                'form_params' => array_merge($payload, $this->getOptionalParameters()),
164
            ]);
165
166
            $data->status = $response->getStatusCode();
167
            $data->response = json_decode($response->getBody()->getContents(), false);
168
169
            return $data;
170
        } catch (ClientException $e) {
171
            $response = $e->getResponse();
172
173
            $data->status = $response->getStatusCode();
174
            $data->response = json_decode($response->getBody()->getContents(), false);
175
176
            return $data;
177
        }
178
    }
179
}
180