PaymentInstrumentClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BPCI\SumUp\Customer\PaymentInstrument;
4
5
use BPCI\SumUp\ContextInterface;
6
use BPCI\SumUp\Customer\CustomerInterface;
7
use BPCI\SumUp\OAuth\AccessToken;
8
use BPCI\SumUp\SumUpClientInterface;
9
use BPCI\SumUp\Traits\Client;
10
use BPCI\SumUp\Traits\ClientInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
14
class PaymentInstrumentClient implements PaymentInstrumentClientInterface, ClientInterface
15
{
16
    use Client;
17
18
    protected $context;
19
    protected $options = [];
20
    protected $token;
21
    /**
22
     * @var CustomerInterface
23
     */
24
    protected $customer;
25
    /**
26
     * @var ResponseInterface
27
     */
28
    protected $lastResponse;
29
30
    /**
31
     * CheckoutClientInterface constructor.
32
     * @param ContextInterface $context
33
     * @param array $options
34
     */
35 2
    public function __construct(ContextInterface $context, ?array $options = [])
36
    {
37 2
        $this->context = $context;
38 2
        $this->options = $options;
39 2
    }
40
41 2
    static function getScopes(): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
42
    {
43
        return [
44 2
            'payment_instruments'
45
        ];
46
    }
47
48
    /**
49
     * @param PaymentInstrumentInterface $object
50
     * @param string|null $type
51
     * @return mixed
52
     */
53 1
    static function getBody($object, string $type = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
54
    {
55 1
        return null;
56
    }
57
58
	/**
59
     * Retrieve a paymentInstrument from server and fill the $paymentInstrument Object with response.
60
	 *
61
	 */
62 1
    public function get(): array
63
    {
64 1
        $response = [];
65 1
        if ($this->request('get')) {
66 1
            $response = \GuzzleHttp\json_decode(
67 1
                $this->lastResponse->getBody(),
68 1
                true
69
            );
70
        };
71
72 1
        return $response;
73
	}
74
75
	/**
76
     * Delete an paymentInstrument from server.
77
	 *
78
     * @param PaymentInstrumentInterface $paymentInstrument
79
     * @return bool
80
	 */
81 1
    public function disable(PaymentInstrumentInterface $paymentInstrument):?bool
82
    {
83 1
        $uri = $this->getEndPoint().'/'.$paymentInstrument->getToken();
84
85 1
        return $this->request('delete', $paymentInstrument, $uri);
86
	}
87
88
    /**
89
     * @return string
90
     */
91 2
    public function getEndPoint(): string
92
    {
93 2
        return 'customers/'.$this->customer->getCustomerId().'/payment-instruments';
94
    }
95
96
	/**
97
	 * Return last response of client
98
	 * @return ResponseInterface
99
	 */
100 2
    public function getLastResponse(): ResponseInterface
101
	{
102 2
        return $this->lastResponse;
103
	}
104
105
    /**
106
     * @param ResponseInterface $response
107
     * @return SumUpClientInterface
108
     */
109 2
    public function setLastResponse(ResponseInterface $response): SumUpClientInterface
110
    {
111 2
        $this->lastResponse = $response;
112
113 2
        return $this;
114
    }
115
116
    /**
117
     * return the context used to created the client.
118
     * @return ContextInterface
119
     */
120 2
    public function getContext(): ContextInterface
121
    {
122 2
        return $this->context;
123
    }
124
125
    /**
126
     * @return array
127
     */
128 2
    public function getOptions(): array
129
    {
130 2
        return $this->options??[];
131
    }
132
133
    /**
134
     * @return AccessToken
135
     */
136 2
    public function getToken():? AccessToken
137
    {
138 2
        return $this->token;
139
    }
140
141
    /**
142
     * @param AccessToken $token
143
     * @return SumUpClientInterface
144
     */
145 2
    public function setToken(AccessToken $token): SumUpClientInterface
146
    {
147 2
        $this->token = $token;
148
149 2
        return $this;
150
    }
151
152
    /**
153
     * @return CustomerInterface
154
     */
155
    public function getCustomer(): CustomerInterface
156
    {
157
        return $this->customer;
158
    }
159
160
    /**
161
     * @param CustomerInterface $customer
162
     * @return PaymentInstrumentClientInterface
163
     */
164 2
    public function setCustomer(CustomerInterface $customer): PaymentInstrumentClientInterface
165
    {
166 2
        $this->customer = $customer;
167
168 2
        return $this;
169
    }
170
}
171