Test Failed
Push — develop ( 8028c8...517b56 )
by Reüel
03:22
created

views/page-customer.php (1 issue)

Labels
Severity
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
$mollie_customer_id = \filter_input( INPUT_GET, 'id', FILTER_SANITIZE_STRING );
14
15
global $wpdb;
16
17
$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
				INNER 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
$client = new Client( $data->api_key );
39
40
/**
41
 * Customer.
42
 *
43
 * @link https://docs.mollie.com/reference/v2/customers-api/get-customer
44
 */
45
$customer = $client->get_customer( $mollie_customer_id );
46
47
/**
48
 * Mandates.
49
 *
50
 * @link https://docs.mollie.com/reference/v2/mandates-api/list-mandates
51
 */
52
$response = $client->get_mandates( $mollie_customer_id );
53
54
$mandates = $response->_embedded->mandates;
55
56
/**
57
 * WordPress user.
58
 */
59
$users = $wpdb->get_results(
60
	$wpdb->prepare(
61
		"
62
		SELECT
63
			user.*
64
		FROM
65
			$wpdb->pronamic_pay_mollie_customer_users AS mollie_customer_user
66
				INNER JOIN
67
			$wpdb->users AS user
68
					ON mollie_customer_user.user_id = user.ID
69
		WHERE
70
			mollie_customer_user.customer_id = %d
71
		;
72
		",
73
		$data->id
74
	)
75
);
76
77
?>
78
<div class="wrap">
79
	<h1><?php echo \esc_html( \get_admin_page_title() ); ?></h1>
80
81
	<h2>
82
	<?php
83
84
	echo \wp_kses(
85
		\sprintf(
86
			/* translators: %s: Mollie customer ID. */
87
			\__( 'Customer %s', 'pronamic_ideal' ),
88
			\sprintf(
89
				'<code>%s</code>',
90
				$mollie_customer_id
91
			)
92
		),
93
		array(
94
			'code' => array(),
95
		)
96
	);
97
98
	?>
99
	</h2>
100
101
	<table class="form-table">
102
		<tbody>
103
			<tr>
104
				<th scope="row"><?php \esc_html_e( 'ID', 'pronamic_ideal' ); ?></th>
105
				<td>
106
					<code><?php echo \esc_html( $customer->id ); ?></code>
107
				</td>
108
			</tr>
109
			<tr>
110
				<th scope="row"><?php \esc_html_e( 'Mode', 'pronamic_ideal' ); ?></th>
111
				<td>
112
					<?php
113
114
					switch ( $customer->mode ) {
115
						case 'test':
116
							\esc_html_e( 'Test', 'pronamic_ideal' );
117
118
							break;
119
						case 'live':
120
							\esc_html_e( 'Live', 'pronamic_ideal' );
121
122
							break;
123
						default:
124
							echo \esc_html( $customer->mode );
125
126
							break;
127
					}
128
129
					?>
130
				</td>
131
			</tr>
132
			<tr>
133
				<th scope="row"><?php \esc_html_e( 'Name', 'pronamic_ideal' ); ?></th>
134
				<td>
135
					<?php echo \esc_html( $customer->name ); ?>
136
				</td>
137
			</tr>
138
			<tr>
139
				<th scope="row"><?php \esc_html_e( 'Email', 'pronamic_ideal' ); ?></th>
140
				<td>
141
					<?php
142
143
					if ( null !== $customer->email ) {
144
						printf(
145
							'<a href="%s">%s</a>',
146
							esc_attr( 'mailto:' . $customer->email ),
147
							esc_html( $customer->email )
148
						);
149
					}
150
151
					?>
152
				</td>
153
			</tr>
154
			<tr>
155
				<th scope="row"><?php \esc_html_e( 'Locale', 'pronamic_ideal' ); ?></th>
156
				<td>
157
					<?php
158
159
					if ( null !== $customer->locale ) {
160
						printf(
161
							'<code>%s</code>',
162
							esc_html( $customer->locale )
163
						);
164
					}
165
166
					?>
167
				</td>
168
			</tr>
169
			<tr>
170
				<th scope="row"><?php \esc_html_e( 'Link', 'pronamic_ideal' ); ?></th>
171
				<td>
172
					<?php
173
174
					$mollie_link = \sprintf(
175
						'https://www.mollie.com/dashboard/customers/%s',
176
						$customer->id
177
					);
178
179
					\printf(
180
						'<a href="%s">%s</a>',
181
						\esc_url( $mollie_link ),
182
						\esc_html( $mollie_link )
183
					);
184
185
					?>
186
				</td>
187
			</tr>
188
		</tbody>
189
	</table>
190
191
	<h3><?php \esc_html_e( 'Mandates', 'pronamic_ideal' ); ?></h3>
192
193
	<table class="widefat">
194
		<thead>
195
			<tr>
196
				<th><?php \esc_html_e( 'ID', 'pronamic_ideal' ); ?></th>
197
				<th><?php \esc_html_e( 'Mode', 'pronamic_ideal' ); ?></th>
198
				<th><?php \esc_html_e( 'Status', 'pronamic_ideal' ); ?></th>
199
				<th><?php \esc_html_e( 'Method', 'pronamic_ideal' ); ?></th>
200
				<th><?php \esc_html_e( 'Details', 'pronamic_ideal' ); ?></th>
201
				<th><?php \esc_html_e( 'Mandate Reference', 'pronamic_ideal' ); ?></th>
202
				<th><?php \esc_html_e( 'Signature Date', 'pronamic_ideal' ); ?></th>
203
				<th><?php \esc_html_e( 'Created On', 'pronamic_ideal' ); ?></th>
204
			</tr>
205
		</thead>
206
207
		<tbody>
208
209
			<?php if ( empty( $mandates ) ) : ?>
210
211
				<tr>
212
					<td colspan="4"><?php esc_html_e( 'No mandates found.', 'pronamic_ideal' ); ?></td>
213
				</tr>
214
215
			<?php else : ?>
216
217
				<?php foreach ( $mandates as $mandate ) : ?>
218
219
					<tr>
220
						<td>
221
							<code><?php echo \esc_html( $mandate->id ); ?></code>
222
						</td>
223
						<td>
224
							<?php
225
226
							switch ( $mandate->mode ) {
227
								case 'test':
228
									\esc_html_e( 'Test', 'pronamic_ideal' );
229
230
									break;
231
								case 'live':
232
									\esc_html_e( 'Live', 'pronamic_ideal' );
233
234
									break;
235
								default:
236
									echo \esc_html( $mandate->mode );
237
238
									break;
239
							}
240
241
							?>
242
						</td>
243
						<td>
244
							<?php
245
246
							switch ( $mandate->status ) {
247
								case 'pending':
248
									\esc_html_e( 'Pending', 'pronamic_ideal' );
249
250
									break;
251
								case 'valid':
252
									\esc_html_e( 'Valid', 'pronamic_ideal' );
253
254
									break;
255
								default:
256
									echo \esc_html( $mandate->status );
257
258
									break;
259
							}
260
261
							?>
262
						</td>
263
						<td>
264
							<?php
265
266
							switch ( $mandate->method ) {
267
								case 'creditcard':
268
									\esc_html_e( 'Credit Card', 'pronamic_ideal' );
269
270
									break;
271
								case 'directdebit':
272
									\esc_html_e( 'Direct Debit', 'pronamic_ideal' );
273
274
									break;
275
								default:
276
									echo \esc_html( $mandate->method );
277
278
									break;
279
							}
280
281
							?>
282
						</td>
283
						<td>
284
							<?php
285
286
							switch ( $mandate->method ) {
287
								case 'creditcard':
288
									?>
289
									<dl style="margin: 0;">
290
291
										<?php if ( ! empty( $mandate->details->cardHolder ) ) : ?>
292
293
											<dt><?php \esc_html_e( 'Card Holder', 'pronamic_ideal' ); ?></dt>
294
											<dd>
295
												<?php echo \esc_html( $mandate->details->cardHolder ); ?>
296
											</dd>
297
298
										<?php endif; ?>
299
300
										<?php if ( ! empty( $mandate->details->cardNumber ) ) : ?>
301
302
											<dt><?php \esc_html_e( 'Card Number', 'pronamic_ideal' ); ?></dt>
303
											<dd>
304
												<?php echo \esc_html( $mandate->details->cardNumber ); ?>
305
											</dd>
306
307
										<?php endif; ?>
308
309
										<?php if ( ! empty( $mandate->details->cardLabel ) ) : ?>
310
311
											<dt><?php \esc_html_e( 'Card Label', 'pronamic_ideal' ); ?></dt>
312
											<dd>
313
												<?php echo \esc_html( $mandate->details->cardLabel ); ?>
314
											</dd>
315
316
										<?php endif; ?>
317
318
										<?php if ( ! empty( $mandate->details->cardFingerprint ) ) : ?>
319
320
											<dt><?php \esc_html_e( 'Card Fingerprint', 'pronamic_ideal' ); ?></dt>
321
											<dd>
322
												<?php echo \esc_html( $mandate->details->cardFingerprint ); ?>
323
											</dd>
324
325
										<?php endif; ?>
326
327
										<?php if ( ! empty( $mandate->details->cardExpiryDate ) ) : ?>
328
329
											<dt><?php \esc_html_e( 'Card Expiry Date', 'pronamic_ideal' ); ?></dt>
330
											<dd>
331
												<?php echo \esc_html( $mandate->details->cardExpiryDate ); ?>
332
											</dd>
333
334
										<?php endif; ?>
335
									</dl>
336
									<?php
337
338
									break;
339
								case 'directdebit':
340
									?>
341
									<dl style="margin: 0;">
342
343
										<?php if ( ! empty( $mandate->details->consumerName ) ) : ?>
344
345
											<dt><?php \esc_html_e( 'Consumer Name', 'pronamic_ideal' ); ?></dt>
346
											<dd>
347
												<?php echo \esc_html( $mandate->details->consumerName ); ?>
348
											</dd>
349
350
										<?php endif; ?>
351
352
										<?php if ( ! empty( $mandate->details->consumerAccount ) ) : ?>
353
354
											<dt><?php \esc_html_e( 'Consumer Account', 'pronamic_ideal' ); ?></dt>
355
											<dd>
356
												<?php echo \esc_html( $mandate->details->consumerAccount ); ?>
357
											</dd>
358
359
										<?php endif; ?>
360
361
										<?php if ( ! empty( $mandate->details->consumerBic ) ) : ?>
362
363
											<dt><?php \esc_html_e( 'Consumer BIC', 'pronamic_ideal' ); ?></dt>
364
											<dd>
365
												<?php echo \esc_html( $mandate->details->consumerBic ); ?>
366
											</dd>
367
368
										<?php endif; ?>
369
									</dl>
370
									<?php
371
372
									break;
373
								default:
374
									?>
375
									<pre><?php echo \esc_html( \wp_json_encode( $mandate->details, \JSON_PRETTY_PRINT ) ); ?></pre>
0 ignored issues
show
It seems like wp_json_encode($mandate-...ils, JSON_PRETTY_PRINT) can also be of type false; however, parameter $text of esc_html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

375
									<pre><?php echo \esc_html( /** @scrutinizer ignore-type */ \wp_json_encode( $mandate->details, \JSON_PRETTY_PRINT ) ); ?></pre>
Loading history...
376
									<?php
377
378
									break;
379
							}
380
381
							?>
382
						</td>
383
						<td>
384
							<?php echo \esc_html( $mandate->mandateReference ); ?>
385
						</td>
386
						<td>
387
							<?php
388
389
							$signature_date = new \DateTime( $mandate->signatureDate );
390
391
							echo \esc_html( $signature_date->format( 'd-m-Y' ) );
392
393
							?>
394
						</td>
395
						<td>
396
							<?php
397
398
							$created_on = new \DateTime( $mandate->createdAt );
399
400
							echo \esc_html( $created_on->format( 'd-m-Y H:i:s' ) );
401
402
							?>
403
						</td>
404
					</tr>
405
406
				<?php endforeach; ?>
407
408
			<?php endif; ?>
409
410
		</tbody>
411
	</table>
412
413
	<h3><?php \esc_html_e( 'WordPress Users', 'pronamic_ideal' ); ?></h3>
414
415
	<table class="widefat">
416
		<thead>
417
			<tr>
418
				<th><?php \esc_html_e( 'ID', 'pronamic_ideal' ); ?></th>
419
				<th><?php \esc_html_e( 'Email', 'pronamic_ideal' ); ?></th>
420
				<th><?php \esc_html_e( 'Display Name', 'pronamic_ideal' ); ?></th>
421
			</tr>
422
		</thead>
423
424
		<tbody>	
425
426
			<?php if ( empty( $users ) ) : ?>
427
428
				<tr>
429
					<td colspan="3"><?php esc_html_e( 'No users found.', 'pronamic_ideal' ); ?></td>
430
				</tr>
431
432
			<?php else : ?>
433
434
				<?php foreach ( $users as $user ) : ?>
435
436
					<tr>
437
						<td>
438
							<code><?php echo \esc_html( $user->ID ); ?></code>
439
						</td>
440
						<td>
441
							<?php
442
443
							printf(
444
								'<a href="%s">%s</a>',
445
								esc_attr( 'mailto:' . $user->user_email ),
446
								esc_html( $user->user_email )
447
							);
448
449
							?>
450
						</td>
451
						<td>
452
							<?php echo \esc_html( $user->display_name ); ?>
453
						</td>
454
					</tr>
455
456
				<?php endforeach; ?>
457
458
			<?php endif; ?>
459
460
		</tbody>
461
	</table>
462
</div>
463