1
|
|
|
<?php |
2
|
|
|
namespace BPCI\SumUp\Customer; |
3
|
|
|
|
4
|
|
|
use BPCI\SumUp\ContextInterface; |
5
|
|
|
use BPCI\SumUp\Customer\PaymentInstrument\PaymentInstrumentClient; |
6
|
|
|
use BPCI\SumUp\Customer\PaymentInstrument\PaymentInstrumentInterface; |
7
|
|
|
use BPCI\SumUp\Exception\BadRequestException; |
8
|
|
|
use BPCI\SumUp\Exception\InvalidCustomerException; |
9
|
|
|
use BPCI\SumUp\OAuth\AccessToken; |
10
|
|
|
use BPCI\SumUp\SumUpClientInterface; |
11
|
|
|
use BPCI\SumUp\Traits\Client; |
12
|
|
|
use BPCI\SumUp\Traits\ClientInterface; |
13
|
|
|
use BPCI\SumUp\Utils\Hydrator; |
|
|
|
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
15
|
|
|
|
16
|
|
|
class CustomerClient implements CustomerClientInterface, ClientInterface |
17
|
|
|
{ |
18
|
|
|
use Client; |
19
|
|
|
|
20
|
|
|
const ENDPOINT = 'customers'; |
21
|
|
|
protected $context; |
22
|
|
|
protected $token; |
23
|
|
|
protected $lastResponse; |
24
|
|
|
protected $options = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* CheckoutClientInterface constructor. |
28
|
|
|
* @param ContextInterface $context |
29
|
|
|
* @param array $options |
30
|
|
|
*/ |
31
|
3 |
|
public function __construct(ContextInterface $context, ?array $options = []) |
32
|
|
|
{ |
33
|
3 |
|
$this->context = $context; |
34
|
3 |
|
$this->options = $options; |
35
|
3 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritDoc |
39
|
|
|
* @throws BadRequestException |
40
|
|
|
*/ |
41
|
1 |
|
public function create(CustomerInterface $customer): ?CustomerInterface |
42
|
|
|
{ |
43
|
1 |
|
return $this->request('post', $customer) ? $customer : null; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $customer |
48
|
|
|
* @param string|null $type |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
1 |
|
static function getBody($customer, string $type = null) |
|
|
|
|
52
|
|
|
{ |
53
|
1 |
|
if (!$customer instanceof CustomerInterface) { |
54
|
|
|
throw new InvalidCustomerException('Invalid customer or $customer does not implement CustomerInterface!'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$body = [ |
58
|
1 |
|
'customer_id' => $customer->getCustomerId(), |
59
|
|
|
'personal_details' => [ |
60
|
1 |
|
'name' => $customer->getName(), |
61
|
1 |
|
'phone' => $customer->getPhone(), |
62
|
|
|
'address' => [ |
63
|
1 |
|
'line1' => $customer->getAddress()->getLine1(), |
64
|
1 |
|
'line2' => $customer->getAddress()->getLine2(), |
65
|
1 |
|
'country' => $customer->getAddress()->getCountry(), |
66
|
1 |
|
'postal_code' => $customer->getAddress()->getPostalCode(), |
67
|
1 |
|
'city' => $customer->getAddress()->getCity(), |
68
|
1 |
|
'state' => $customer->getAddress()->getState(), |
69
|
|
|
], |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
|
73
|
1 |
|
return $body; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setContext(ContextInterface $context): CustomerClientInterface |
77
|
|
|
{ |
78
|
|
|
$this->context = $context; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritDoc |
83
|
|
|
*/ |
84
|
1 |
|
public static function getScopes(): array |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
1 |
|
'payment_instruments', |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
function getLastResponse(): ResponseInterface |
|
|
|
|
92
|
|
|
{ |
93
|
1 |
|
return $this->lastResponse; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* return the context used to created the client. |
99
|
|
|
* @return ContextInterface |
100
|
|
|
*/ |
101
|
3 |
|
function getContext(): ContextInterface |
|
|
|
|
102
|
|
|
{ |
103
|
3 |
|
return $this->context; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Delete a customer card. |
108
|
|
|
* |
109
|
|
|
* @param CustomerInterface $customer |
110
|
|
|
* @param PaymentInstrumentInterface $paymentInstrument |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
1 |
|
function disablePaymentInstrument(CustomerInterface $customer, PaymentInstrumentInterface $paymentInstrument): bool |
|
|
|
|
114
|
|
|
{ |
115
|
1 |
|
$instrumentClient = new PaymentInstrumentClient($this->getContext(), $this->getOptions()); |
116
|
1 |
|
$instrumentClient->setCustomer($customer); |
117
|
1 |
|
$instrumentClient->setToken($this->getToken()); |
118
|
1 |
|
$response = $instrumentClient->disable($paymentInstrument); |
119
|
1 |
|
$this->setLastResponse($instrumentClient->getLastResponse()); |
120
|
|
|
|
121
|
1 |
|
return $response; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* This must return an Array of PaymentInstrumentInterface |
126
|
|
|
* |
127
|
|
|
* @param CustomerInterface $customer |
128
|
|
|
* @return array |
129
|
|
|
*/ |
130
|
1 |
|
function getPaymentInstruments(CustomerInterface $customer): array |
|
|
|
|
131
|
|
|
{ |
132
|
1 |
|
$instrumentClient = new PaymentInstrumentClient($this->getContext(), $this->getOptions()); |
133
|
1 |
|
$instrumentClient->setCustomer($customer); |
134
|
1 |
|
$instrumentClient->setToken($this->getToken()); |
135
|
1 |
|
$response = $instrumentClient->get(); |
136
|
1 |
|
$this->setLastResponse($instrumentClient->getLastResponse()); |
137
|
|
|
|
138
|
1 |
|
return $response; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param ResponseInterface $response |
143
|
|
|
* @return SumUpClientInterface |
144
|
|
|
*/ |
145
|
3 |
|
function setLastResponse(ResponseInterface $response): SumUpClientInterface |
|
|
|
|
146
|
|
|
{ |
147
|
3 |
|
$this->lastResponse = $response; |
148
|
|
|
|
149
|
3 |
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return array |
154
|
|
|
*/ |
155
|
3 |
|
function getOptions(): array |
|
|
|
|
156
|
|
|
{ |
157
|
3 |
|
return $this->options; |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return string |
162
|
|
|
*/ |
163
|
1 |
|
function getEndPoint(): string |
|
|
|
|
164
|
|
|
{ |
165
|
1 |
|
return 'customers'; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param AccessToken $token |
170
|
|
|
* @return SumUpClientInterface |
171
|
|
|
*/ |
172
|
3 |
|
function setToken(AccessToken $token): SumUpClientInterface |
|
|
|
|
173
|
|
|
{ |
174
|
3 |
|
$this->token = $token; |
175
|
|
|
|
176
|
3 |
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return AccessToken |
181
|
|
|
*/ |
182
|
3 |
|
function getToken():? AccessToken |
|
|
|
|
183
|
|
|
{ |
184
|
3 |
|
return $this->token; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths