|
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
|
|
|
public function __construct(ContextInterface $context, ?array $options = []) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->context = $context; |
|
34
|
|
|
$this->options = $options; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @inheritDoc |
|
39
|
|
|
* @throws BadRequestException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function create(CustomerInterface $customer): ?CustomerInterface |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->request('post', $customer) ? $customer : null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param $customer |
|
48
|
|
|
* @param string|null $type |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
|
static function getBody($customer, string $type = null) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
if (!$customer instanceof CustomerInterface) { |
|
54
|
|
|
throw new InvalidCustomerException('Invalid customer or $customer does not implement CustomerInterface!'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$body = [ |
|
58
|
|
|
'customer_id' => $customer->getCustomerId(), |
|
59
|
|
|
'personal_details' => [ |
|
60
|
|
|
'name' => $customer->getName(), |
|
61
|
|
|
'phone' => $customer->getPhone(), |
|
62
|
|
|
'address' => [ |
|
63
|
|
|
'line1' => $customer->getAddress()->getLine1(), |
|
64
|
|
|
'line2' => $customer->getAddress()->getLine2(), |
|
65
|
|
|
'country' => $customer->getAddress()->getCountry(), |
|
66
|
|
|
'postal_code' => $customer->getAddress()->getPostalCode(), |
|
67
|
|
|
'city' => $customer->getAddress()->getCity(), |
|
68
|
|
|
'state' => $customer->getAddress()->getState(), |
|
69
|
|
|
], |
|
70
|
|
|
], |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
return $body; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function setContext(ContextInterface $context): CustomerClientInterface |
|
77
|
|
|
{ |
|
78
|
|
|
$this->context = $context; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @inheritDoc |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function getScopes(): array |
|
85
|
|
|
{ |
|
86
|
|
|
return [ |
|
87
|
|
|
'payment_instruments', |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
function getLastResponse(): ResponseInterface |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
return $this->lastResponse; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* return the context used to created the client. |
|
99
|
|
|
* @return ContextInterface |
|
100
|
|
|
*/ |
|
101
|
|
|
function getContext(): ContextInterface |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
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
|
|
|
function disablePaymentInstrument(CustomerInterface $customer, PaymentInstrumentInterface $paymentInstrument): bool |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
$instrumentClient = new PaymentInstrumentClient($this->getContext(), $this->getOptions()); |
|
116
|
|
|
$instrumentClient->setCustomer($customer); |
|
117
|
|
|
$instrumentClient->setToken($this->getToken()); |
|
118
|
|
|
$response = $instrumentClient->disable($paymentInstrument); |
|
119
|
|
|
$this->setLastResponse($instrumentClient->getLastResponse()); |
|
120
|
|
|
|
|
121
|
|
|
return $response; |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* This must return an Array of PaymentInstrumentInterface |
|
126
|
|
|
* |
|
127
|
|
|
* @param CustomerInterface $customer |
|
128
|
|
|
* @return array |
|
129
|
|
|
*/ |
|
130
|
|
|
function getPaymentInstruments(CustomerInterface $customer): array |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
$instrumentClient = new PaymentInstrumentClient($this->getContext(), $this->getOptions()); |
|
133
|
|
|
$instrumentClient->setCustomer($customer); |
|
134
|
|
|
$instrumentClient->setToken($this->getToken()); |
|
135
|
|
|
$response = $instrumentClient->get(); |
|
136
|
|
|
$this->setLastResponse($instrumentClient->getLastResponse()); |
|
137
|
|
|
|
|
138
|
|
|
return $response; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param ResponseInterface $response |
|
143
|
|
|
* @return SumUpClientInterface |
|
144
|
|
|
*/ |
|
145
|
|
|
function setLastResponse(ResponseInterface $response): SumUpClientInterface |
|
|
|
|
|
|
146
|
|
|
{ |
|
147
|
|
|
$this->lastResponse = $response; |
|
148
|
|
|
|
|
149
|
|
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return array |
|
154
|
|
|
*/ |
|
155
|
|
|
function getOptions(): array |
|
|
|
|
|
|
156
|
|
|
{ |
|
157
|
|
|
return $this->options; |
|
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
|
|
function getEndPoint(): string |
|
|
|
|
|
|
164
|
|
|
{ |
|
165
|
|
|
return 'customers'; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param AccessToken $token |
|
170
|
|
|
* @return SumUpClientInterface |
|
171
|
|
|
*/ |
|
172
|
|
|
function setToken(AccessToken $token): SumUpClientInterface |
|
|
|
|
|
|
173
|
|
|
{ |
|
174
|
|
|
$this->token = $token; |
|
175
|
|
|
|
|
176
|
|
|
return $this; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @return AccessToken |
|
181
|
|
|
*/ |
|
182
|
|
|
function getToken():? AccessToken |
|
|
|
|
|
|
183
|
|
|
{ |
|
184
|
|
|
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