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