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 ( 6e92a7...c1e021 )
by Miguel
02:10 queued 10s
created

PaymentWithMBWay::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Apoca\Sibs\Brands;
4
5
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\ClientException;
8
9
/**
10
 * Class PaymentWithMBWay
11
 *
12
 * @package Apoca\Sibs\Brands
13
 */
14
class PaymentWithMBWay extends Payment
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $accountId;
20
21
    /**
22
     * @var string
23
     */
24
    protected $endpoint;
25
26
    /**
27
     * @var array
28
     */
29
    protected $clientConfig = [];
30
31
    /**
32
     * PaymentWithMBWay constructor.
33
     *
34
     * @param float  $amount
35
     * @param string $currency
36
     * @param string $brand
37
     * @param string $type
38
     * @param string $accountId
39
     */
40
    public function __construct(
41
        float $amount,
42
        string $currency,
43
        string $brand,
44
        string $type,
45
        string $accountId
46
    ) {
47
        parent::__construct($amount, $currency, $brand, $type);
48
        $this->accountId = $accountId;
49
        $this->endpoint = config('sibs.host') . config('sibs.version') . '/';
50
    }
51
52
    /**
53
     * Execute the payment
54
     *
55
     * @return object
56
     */
57
    public function pay()
58
    {
59
        $data = (object)null;
60
61
        try {
62
            $client = new Client($this->clientConfig);
63
64
            $payload = [
65
                'entityId' => config('sibs.authentication.entityId'),
66
                'amount' => number_format($this->amount, 2),
67
                'currency' => $this->currency,
68
                'paymentBrand' => $this->brand,
69
                'paymentType' => $this->type,
70
                'virtualAccount.accountId' => $this->accountId,
71
            ];
72
            if (config('sibs.mode') === 'test') {
73
                $payload = array_merge($payload,
74
                    [
75
                        'customParameters[SIBS_ENV]' => 'QLY',
76
                        'testMode' => 'EXTERNAL',
77
                    ]);
78
            }
79
            $response = $client->post($this->endpoint . 'payments', [
80
                'headers' => [
81
                    'Authorization' => config('sibs.authentication.token'),
82
                ],
83
                'form_params' => $payload,
84
            ]);
85
86
            $data->status = $response->getStatusCode();
87
            $data->response = json_decode($response->getBody()->getContents());
88
89
            return $data;
90
        } catch (ClientException $e) {
91
            $response = $e->getResponse();
92
93
            $data->status = $response->getStatusCode();
94
            $data->response = json_decode($response->getBody()->getContents());
95
96
            return $data;
97
        }
98
    }
99
}