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.

PaymentWithMBWay   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A pay() 0 40 3
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
     * @param array  $optionalParameters
40
     */
41
    public function __construct(
42
        float $amount,
43
        string $currency,
44
        string $brand,
45
        string $type,
46
        string $accountId,
47
        array $optionalParameters
48
    ) {
49
        parent::__construct($amount, $currency, $brand, $type, $optionalParameters);
50
        $this->accountId = $accountId;
51
        $this->endpoint = config('sibs.host') . config('sibs.version') . '/';
52
    }
53
54
    /**
55
     * Execute the payment
56
     *
57
     * @return object
58
     */
59
    public function pay()
60
    {
61
        $data = (object)null;
62
63
        try {
64
            $client = new Client($this->clientConfig);
65
66
            $payload = [
67
                'entityId' => config('sibs.authentication.entityId'),
68
                'amount' => number_format($this->amount, 2, '.', ''),
69
                'currency' => $this->currency,
70
                'paymentBrand' => $this->brand,
71
                'paymentType' => $this->type,
72
                'virtualAccount.accountId' => $this->accountId,
73
            ];
74
            if (config('sibs.mode') === 'test') {
75
                $payload = array_merge($payload,
76
                    [
77
                        'customParameters[SIBS_ENV]' => 'QLY',
78
                        'testMode' => 'EXTERNAL',
79
                    ]);
80
            }
81
            $response = $client->post($this->endpoint . 'payments', [
82
                'headers' => [
83
                    'Authorization' => config('sibs.authentication.token'),
84
                ],
85
                'form_params' => array_merge($payload, $this->getOptionalParameters()),
86
            ]);
87
88
            $data->status = $response->getStatusCode();
89
            $data->response = json_decode($response->getBody()->getContents(), false);
90
91
            return $data;
92
        } catch (ClientException $e) {
93
            $response = $e->getResponse();
94
95
            $data->status = $response->getStatusCode();
96
            $data->response = json_decode($response->getBody()->getContents(), false);
97
98
            return $data;
99
        }
100
    }
101
}