1 | <?php |
||
2 | /** |
||
3 | * Page customer |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2020 Pronamic |
||
7 | * @license GPL-3.0-or-later |
||
8 | * @package Pronamic\WordPress\Pay\Gateways\Mollie |
||
9 | */ |
||
10 | |||
11 | namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
||
12 | |||
13 | global $wpdb; |
||
14 | |||
15 | $mollie_customer_id = \filter_input( INPUT_GET, 'id', FILTER_SANITIZE_STRING ); |
||
16 | |||
17 | $mollie_customer_data = $wpdb->get_row( |
||
18 | $wpdb->prepare( |
||
19 | " |
||
20 | SELECT |
||
21 | mollie_customer.*, |
||
22 | IF ( mollie_customer.test_mode, mollie_profile.api_key_test, mollie_profile.api_key_live ) AS api_key |
||
23 | FROM |
||
24 | $wpdb->pronamic_pay_mollie_customers AS mollie_customer |
||
25 | LEFT JOIN |
||
26 | $wpdb->pronamic_pay_mollie_profiles AS mollie_profile |
||
27 | ON mollie_customer.profile_id = mollie_profile.id |
||
28 | WHERE |
||
29 | mollie_customer.mollie_id = %s |
||
30 | LIMIT |
||
31 | 1 |
||
32 | ; |
||
33 | ", |
||
34 | $mollie_customer_id |
||
35 | ) |
||
36 | ); |
||
37 | |||
38 | $mollie_customer = null; |
||
39 | |||
40 | $mollie_customer_mandates = null; |
||
41 | |||
42 | if ( $mollie_customer_data->api_key ) { |
||
43 | $client = new Client( $mollie_customer_data->api_key ); |
||
44 | |||
45 | /** |
||
46 | * Customer. |
||
47 | * |
||
48 | * @link https://docs.mollie.com/reference/v2/customers-api/get-customer |
||
49 | */ |
||
50 | $mollie_customer = $client->get_customer( $mollie_customer_id ); |
||
51 | |||
52 | /** |
||
53 | * Mandates. |
||
54 | * |
||
55 | * @link https://docs.mollie.com/reference/v2/mandates-api/list-mandates |
||
56 | */ |
||
57 | $response = $client->get_mandates( $mollie_customer_id ); |
||
58 | |||
59 | $mollie_customer_mandates = $response->_embedded->mandates; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * WordPress user. |
||
64 | */ |
||
65 | $users = $wpdb->get_results( |
||
66 | $wpdb->prepare( |
||
67 | " |
||
68 | SELECT |
||
69 | user.* |
||
70 | FROM |
||
71 | $wpdb->pronamic_pay_mollie_customer_users AS mollie_customer_user |
||
72 | INNER JOIN |
||
73 | $wpdb->users AS user |
||
74 | ON mollie_customer_user.user_id = user.ID |
||
75 | WHERE |
||
76 | mollie_customer_user.customer_id = %d |
||
77 | ; |
||
78 | ", |
||
79 | $mollie_customer_data->id |
||
80 | ) |
||
81 | ); |
||
82 | |||
83 | ?> |
||
84 | <div class="wrap"> |
||
85 | <h1><?php echo \esc_html( \get_admin_page_title() ); ?></h1> |
||
86 | |||
87 | <h2> |
||
88 | <?php |
||
89 | |||
90 | echo \wp_kses( |
||
91 | \sprintf( |
||
92 | /* translators: %s: Mollie customer ID. */ |
||
93 | \__( 'Customer %s', 'pronamic_ideal' ), |
||
94 | \sprintf( |
||
95 | '<code>%s</code>', |
||
96 | $mollie_customer_id |
||
97 | ) |
||
98 | ), |
||
99 | array( |
||
100 | 'code' => array(), |
||
101 | ) |
||
102 | ); |
||
103 | |||
104 | ?> |
||
105 | </h2> |
||
106 | |||
107 | <table class="form-table"> |
||
108 | <tbody> |
||
109 | <tr> |
||
110 | <th scope="row"><?php \esc_html_e( 'ID', 'pronamic_ideal' ); ?></th> |
||
111 | <td> |
||
112 | <code><?php echo \esc_html( $mollie_customer_data->id ); ?></code> |
||
113 | </td> |
||
114 | </tr> |
||
115 | <tr> |
||
116 | <th scope="row"><?php \esc_html_e( 'Mode', 'pronamic_ideal' ); ?></th> |
||
117 | <td> |
||
118 | <?php $mollie_customer_data->test_mode ? \esc_html_e( 'Test', 'pronamic_ideal' ) : \esc_html_e( 'Live', 'pronamic_ideal' ); ?> |
||
119 | </td> |
||
120 | </tr> |
||
121 | <tr> |
||
122 | <th scope="row"><?php \esc_html_e( 'Name', 'pronamic_ideal' ); ?></th> |
||
123 | <td> |
||
124 | <?php echo \esc_html( $mollie_customer_data->name ); ?> |
||
125 | </td> |
||
126 | </tr> |
||
127 | <tr> |
||
128 | <th scope="row"><?php \esc_html_e( 'Email', 'pronamic_ideal' ); ?></th> |
||
129 | <td> |
||
130 | <?php |
||
131 | |||
132 | if ( null !== $mollie_customer_data->email ) { |
||
133 | printf( |
||
134 | '<a href="%s">%s</a>', |
||
135 | esc_attr( 'mailto:' . $mollie_customer_data->email ), |
||
136 | esc_html( $mollie_customer_data->email ) |
||
137 | ); |
||
138 | } |
||
139 | |||
140 | ?> |
||
141 | </td> |
||
142 | </tr> |
||
143 | |||
144 | <?php if ( null !== $mollie_customer ) : ?> |
||
145 | |||
146 | <tr> |
||
147 | <th scope="row"><?php \esc_html_e( 'Locale', 'pronamic_ideal' ); ?></th> |
||
148 | <td> |
||
149 | <?php |
||
150 | |||
151 | if ( null !== $mollie_customer->locale ) { |
||
152 | printf( |
||
153 | '<code>%s</code>', |
||
154 | esc_html( $mollie_customer->locale ) |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | ?> |
||
159 | </td> |
||
160 | </tr> |
||
161 | |||
162 | <?php endif; ?> |
||
163 | |||
164 | <tr> |
||
165 | <th scope="row"><?php \esc_html_e( 'Link', 'pronamic_ideal' ); ?></th> |
||
166 | <td> |
||
167 | <?php |
||
168 | |||
169 | $mollie_link = \sprintf( |
||
170 | 'https://www.mollie.com/dashboard/customers/%s', |
||
171 | $mollie_customer_id |
||
172 | ); |
||
173 | |||
174 | \printf( |
||
175 | '<a href="%s">%s</a>', |
||
176 | \esc_url( $mollie_link ), |
||
177 | \esc_html( $mollie_link ) |
||
178 | ); |
||
179 | |||
180 | ?> |
||
181 | </td> |
||
182 | </tr> |
||
183 | </tbody> |
||
184 | </table> |
||
185 | |||
186 | <?php if ( null !== $mollie_customer_mandates ) : ?> |
||
187 | |||
188 | <h3><?php \esc_html_e( 'Mandates', 'pronamic_ideal' ); ?></h3> |
||
189 | |||
190 | <table class="widefat"> |
||
191 | <thead> |
||
192 | <tr> |
||
193 | <th><?php \esc_html_e( 'ID', 'pronamic_ideal' ); ?></th> |
||
194 | <th><?php \esc_html_e( 'Mode', 'pronamic_ideal' ); ?></th> |
||
195 | <th><?php \esc_html_e( 'Status', 'pronamic_ideal' ); ?></th> |
||
196 | <th><?php \esc_html_e( 'Method', 'pronamic_ideal' ); ?></th> |
||
197 | <th><?php \esc_html_e( 'Details', 'pronamic_ideal' ); ?></th> |
||
198 | <th><?php \esc_html_e( 'Mandate Reference', 'pronamic_ideal' ); ?></th> |
||
199 | <th><?php \esc_html_e( 'Signature Date', 'pronamic_ideal' ); ?></th> |
||
200 | <th><?php \esc_html_e( 'Created On', 'pronamic_ideal' ); ?></th> |
||
201 | </tr> |
||
202 | </thead> |
||
203 | |||
204 | <tbody> |
||
205 | |||
206 | <?php if ( empty( $mollie_customer_mandates ) ) : ?> |
||
207 | |||
208 | <tr> |
||
209 | <td colspan="4"><?php esc_html_e( 'No mandates found.', 'pronamic_ideal' ); ?></td> |
||
210 | </tr> |
||
211 | |||
212 | <?php else : ?> |
||
213 | |||
214 | <?php foreach ( $mollie_customer_mandates as $mandate ) : ?> |
||
215 | |||
216 | <tr> |
||
217 | <td> |
||
218 | <code><?php echo \esc_html( $mandate->id ); ?></code> |
||
219 | </td> |
||
220 | <td> |
||
221 | <?php |
||
222 | |||
223 | switch ( $mandate->mode ) { |
||
224 | case 'test': |
||
225 | \esc_html_e( 'Test', 'pronamic_ideal' ); |
||
226 | |||
227 | break; |
||
228 | case 'live': |
||
229 | \esc_html_e( 'Live', 'pronamic_ideal' ); |
||
230 | |||
231 | break; |
||
232 | default: |
||
233 | echo \esc_html( $mandate->mode ); |
||
234 | |||
235 | break; |
||
236 | } |
||
237 | |||
238 | ?> |
||
239 | </td> |
||
240 | <td> |
||
241 | <?php |
||
242 | |||
243 | switch ( $mandate->status ) { |
||
244 | case 'pending': |
||
245 | \esc_html_e( 'Pending', 'pronamic_ideal' ); |
||
246 | |||
247 | break; |
||
248 | case 'valid': |
||
249 | \esc_html_e( 'Valid', 'pronamic_ideal' ); |
||
250 | |||
251 | break; |
||
252 | default: |
||
253 | echo \esc_html( $mandate->status ); |
||
254 | |||
255 | break; |
||
256 | } |
||
257 | |||
258 | ?> |
||
259 | </td> |
||
260 | <td> |
||
261 | <?php |
||
262 | |||
263 | switch ( $mandate->method ) { |
||
264 | case 'creditcard': |
||
265 | \esc_html_e( 'Credit Card', 'pronamic_ideal' ); |
||
266 | |||
267 | break; |
||
268 | case 'directdebit': |
||
269 | \esc_html_e( 'Direct Debit', 'pronamic_ideal' ); |
||
270 | |||
271 | break; |
||
272 | default: |
||
273 | echo \esc_html( $mandate->method ); |
||
274 | |||
275 | break; |
||
276 | } |
||
277 | |||
278 | ?> |
||
279 | </td> |
||
280 | <td> |
||
281 | <?php |
||
282 | |||
283 | switch ( $mandate->method ) { |
||
284 | case 'creditcard': |
||
285 | ?> |
||
286 | <dl style="margin: 0;"> |
||
287 | |||
288 | <?php if ( ! empty( $mandate->details->cardHolder ) ) : ?> |
||
289 | |||
290 | <dt><?php \esc_html_e( 'Card Holder', 'pronamic_ideal' ); ?></dt> |
||
291 | <dd> |
||
292 | <?php echo \esc_html( $mandate->details->cardHolder ); ?> |
||
293 | </dd> |
||
294 | |||
295 | <?php endif; ?> |
||
296 | |||
297 | <?php if ( ! empty( $mandate->details->cardNumber ) ) : ?> |
||
298 | |||
299 | <dt><?php \esc_html_e( 'Card Number', 'pronamic_ideal' ); ?></dt> |
||
300 | <dd> |
||
301 | <?php echo \esc_html( $mandate->details->cardNumber ); ?> |
||
302 | </dd> |
||
303 | |||
304 | <?php endif; ?> |
||
305 | |||
306 | <?php if ( ! empty( $mandate->details->cardLabel ) ) : ?> |
||
307 | |||
308 | <dt><?php \esc_html_e( 'Card Label', 'pronamic_ideal' ); ?></dt> |
||
309 | <dd> |
||
310 | <?php echo \esc_html( $mandate->details->cardLabel ); ?> |
||
311 | </dd> |
||
312 | |||
313 | <?php endif; ?> |
||
314 | |||
315 | <?php if ( ! empty( $mandate->details->cardFingerprint ) ) : ?> |
||
316 | |||
317 | <dt><?php \esc_html_e( 'Card Fingerprint', 'pronamic_ideal' ); ?></dt> |
||
318 | <dd> |
||
319 | <?php echo \esc_html( $mandate->details->cardFingerprint ); ?> |
||
320 | </dd> |
||
321 | |||
322 | <?php endif; ?> |
||
323 | |||
324 | <?php if ( ! empty( $mandate->details->cardExpiryDate ) ) : ?> |
||
325 | |||
326 | <dt><?php \esc_html_e( 'Card Expiry Date', 'pronamic_ideal' ); ?></dt> |
||
327 | <dd> |
||
328 | <?php echo \esc_html( $mandate->details->cardExpiryDate ); ?> |
||
329 | </dd> |
||
330 | |||
331 | <?php endif; ?> |
||
332 | </dl> |
||
333 | <?php |
||
334 | |||
335 | break; |
||
336 | case 'directdebit': |
||
337 | ?> |
||
338 | <dl style="margin: 0;"> |
||
339 | |||
340 | <?php if ( ! empty( $mandate->details->consumerName ) ) : ?> |
||
341 | |||
342 | <dt><?php \esc_html_e( 'Consumer Name', 'pronamic_ideal' ); ?></dt> |
||
343 | <dd> |
||
344 | <?php echo \esc_html( $mandate->details->consumerName ); ?> |
||
345 | </dd> |
||
346 | |||
347 | <?php endif; ?> |
||
348 | |||
349 | <?php if ( ! empty( $mandate->details->consumerAccount ) ) : ?> |
||
350 | |||
351 | <dt><?php \esc_html_e( 'Consumer Account', 'pronamic_ideal' ); ?></dt> |
||
352 | <dd> |
||
353 | <?php echo \esc_html( $mandate->details->consumerAccount ); ?> |
||
354 | </dd> |
||
355 | |||
356 | <?php endif; ?> |
||
357 | |||
358 | <?php if ( ! empty( $mandate->details->consumerBic ) ) : ?> |
||
359 | |||
360 | <dt><?php \esc_html_e( 'Consumer BIC', 'pronamic_ideal' ); ?></dt> |
||
361 | <dd> |
||
362 | <?php echo \esc_html( $mandate->details->consumerBic ); ?> |
||
363 | </dd> |
||
364 | |||
365 | <?php endif; ?> |
||
366 | </dl> |
||
367 | <?php |
||
368 | |||
369 | break; |
||
370 | default: |
||
371 | ?> |
||
372 | <pre><?php echo \esc_html( \wp_json_encode( $mandate->details, \JSON_PRETTY_PRINT ) ); ?></pre> |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
373 | <?php |
||
374 | |||
375 | break; |
||
376 | } |
||
377 | |||
378 | ?> |
||
379 | </td> |
||
380 | <td> |
||
381 | <?php |
||
382 | |||
383 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Mollie. |
||
384 | echo \esc_html( $mandate->mandateReference ); |
||
385 | |||
386 | ?> |
||
387 | </td> |
||
388 | <td> |
||
389 | <?php |
||
390 | |||
391 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Mollie. |
||
392 | $signature_date = new \DateTime( $mandate->signatureDate ); |
||
393 | |||
394 | echo \esc_html( $signature_date->format( 'd-m-Y' ) ); |
||
395 | |||
396 | ?> |
||
397 | </td> |
||
398 | <td> |
||
399 | <?php |
||
400 | |||
401 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Mollie. |
||
402 | $created_on = new \DateTime( $mandate->createdAt ); |
||
403 | |||
404 | echo \esc_html( $created_on->format( 'd-m-Y H:i:s' ) ); |
||
405 | |||
406 | ?> |
||
407 | </td> |
||
408 | </tr> |
||
409 | |||
410 | <?php endforeach; ?> |
||
411 | |||
412 | <?php endif; ?> |
||
413 | |||
414 | </tbody> |
||
415 | </table> |
||
416 | |||
417 | <?php endif; ?> |
||
418 | |||
419 | <h3><?php \esc_html_e( 'WordPress Users', 'pronamic_ideal' ); ?></h3> |
||
420 | |||
421 | <table class="widefat"> |
||
422 | <thead> |
||
423 | <tr> |
||
424 | <th><?php \esc_html_e( 'ID', 'pronamic_ideal' ); ?></th> |
||
425 | <th><?php \esc_html_e( 'Email', 'pronamic_ideal' ); ?></th> |
||
426 | <th><?php \esc_html_e( 'Display Name', 'pronamic_ideal' ); ?></th> |
||
427 | </tr> |
||
428 | </thead> |
||
429 | |||
430 | <tbody> |
||
431 | |||
432 | <?php if ( empty( $users ) ) : ?> |
||
433 | |||
434 | <tr> |
||
435 | <td colspan="3"><?php esc_html_e( 'No users found.', 'pronamic_ideal' ); ?></td> |
||
436 | </tr> |
||
437 | |||
438 | <?php else : ?> |
||
439 | |||
440 | <?php foreach ( $users as $user ) : ?> |
||
441 | |||
442 | <tr> |
||
443 | <td> |
||
444 | <code><?php echo \esc_html( $user->ID ); ?></code> |
||
445 | </td> |
||
446 | <td> |
||
447 | <?php |
||
448 | |||
449 | printf( |
||
450 | '<a href="%s">%s</a>', |
||
451 | esc_attr( 'mailto:' . $user->user_email ), |
||
452 | esc_html( $user->user_email ) |
||
453 | ); |
||
454 | |||
455 | ?> |
||
456 | </td> |
||
457 | <td> |
||
458 | <?php echo \esc_html( $user->display_name ); ?> |
||
459 | </td> |
||
460 | </tr> |
||
461 | |||
462 | <?php endforeach; ?> |
||
463 | |||
464 | <?php endif; ?> |
||
465 | |||
466 | </tbody> |
||
467 | </table> |
||
468 | </div> |
||
469 |