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 GuzzleHttp\Psr7\Response; |
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class PaymentInstrumentClient implements PaymentInstrumentClientInterface, ClientInterface |
16
|
|
|
{ |
17
|
|
|
use Client; |
18
|
|
|
|
19
|
|
|
protected $context; |
20
|
|
|
protected $options = []; |
21
|
|
|
protected $token; |
22
|
|
|
/** |
23
|
|
|
* @var CustomerInterface |
24
|
|
|
*/ |
25
|
|
|
protected $customer; |
26
|
|
|
/** |
27
|
|
|
* @var Response |
28
|
|
|
*/ |
29
|
|
|
protected $lastResponse; |
30
|
|
|
|
31
|
2 |
|
static function getScopes(): array |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
2 |
|
'payment_instruments' |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Retrieve a paymentInstrument from server and fill the $paymentInstrument Object with response. |
40
|
|
|
* |
41
|
|
|
*/ |
42
|
1 |
|
public function get(): array |
43
|
|
|
{ |
44
|
1 |
|
$response = []; |
45
|
1 |
|
if ($this->request('get')) { |
46
|
1 |
|
$response = \GuzzleHttp\json_decode( |
47
|
1 |
|
$this->lastResponse->getBody(), |
48
|
1 |
|
true |
49
|
|
|
); |
50
|
|
|
}; |
51
|
|
|
|
52
|
1 |
|
return $response; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Delete an paymentInstrument from server. |
57
|
|
|
* |
58
|
|
|
* @param PaymentInstrumentInterface $paymentInstrument |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
1 |
|
public function disable(PaymentInstrumentInterface $paymentInstrument):?bool |
62
|
|
|
{ |
63
|
1 |
|
$uri = self::getEndPoint().'/'.$paymentInstrument->getToken(); |
|
|
|
|
64
|
|
|
|
65
|
1 |
|
return $this->request('delete', $paymentInstrument, $uri); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* CheckoutClientInterface constructor. |
70
|
|
|
* @param ContextInterface $context |
71
|
|
|
* @param array $options |
72
|
|
|
*/ |
73
|
2 |
|
public function __construct(ContextInterface $context, ?array $options = []) |
74
|
|
|
{ |
75
|
2 |
|
$this->context = $context; |
76
|
2 |
|
$this->options = $options; |
77
|
2 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Return last response of client |
81
|
|
|
* @return ResponseInterface |
82
|
|
|
*/ |
83
|
2 |
|
function getLastResponse(): ResponseInterface |
|
|
|
|
84
|
|
|
{ |
85
|
2 |
|
return $this->lastResponse; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* return the context used to created the client. |
90
|
|
|
* @return ContextInterface |
91
|
|
|
*/ |
92
|
2 |
|
function getContext(): ContextInterface |
|
|
|
|
93
|
|
|
{ |
94
|
2 |
|
return $this->context; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param PaymentInstrumentInterface $object |
99
|
|
|
* @param string|null $type |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
1 |
|
static function getBody($object, string $type = null) |
|
|
|
|
103
|
|
|
{ |
104
|
1 |
|
return null; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param ResponseInterface $response |
109
|
|
|
* @return SumUpClientInterface |
110
|
|
|
*/ |
111
|
2 |
|
function setLastResponse(ResponseInterface $response): SumUpClientInterface |
|
|
|
|
112
|
|
|
{ |
113
|
2 |
|
$this->lastResponse = $response; |
|
|
|
|
114
|
|
|
|
115
|
2 |
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
2 |
|
function getOptions(): array |
|
|
|
|
122
|
|
|
{ |
123
|
2 |
|
return $this->options; |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
2 |
|
function getEndPoint(): string |
|
|
|
|
130
|
|
|
{ |
131
|
2 |
|
return 'customers/'.$this->customer->getCustomerId().'/payment-instruments'; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param AccessToken $token |
136
|
|
|
* @return SumUpClientInterface |
137
|
|
|
*/ |
138
|
2 |
|
function setToken(AccessToken $token): SumUpClientInterface |
|
|
|
|
139
|
|
|
{ |
140
|
2 |
|
$this->token = $token; |
141
|
|
|
|
142
|
2 |
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return AccessToken |
147
|
|
|
*/ |
148
|
2 |
|
function getToken():? AccessToken |
|
|
|
|
149
|
|
|
{ |
150
|
2 |
|
return $this->token; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param CustomerInterface $customer |
155
|
|
|
* @return PaymentInstrumentClientInterface |
156
|
|
|
*/ |
157
|
2 |
|
public function setCustomer(CustomerInterface $customer): PaymentInstrumentClientInterface |
158
|
|
|
{ |
159
|
2 |
|
$this->customer = $customer; |
160
|
|
|
|
161
|
2 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return CustomerInterface |
166
|
|
|
*/ |
167
|
|
|
public function getCustomer(): CustomerInterface |
168
|
|
|
{ |
169
|
|
|
return $this->customer; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|