Passed
Push — develop ( fe46ee...35ba56 )
by Remco
03:51
created

print_link()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 21
rs 9.9
1
<?php
2
3
$matrix = array();
4
5
$components = array(
6
	'id'             => 'ID',
7
	'number'         => 'Number',
8
	'reference'      => 'Reference',
9
	'sku'            => array(
10
		'label' => 'SKU',
11
		'link'  => 'https://en.wikipedia.org/wiki/Stock_keeping_unit',
12
	),
13
	'name'           => 'Name',
14
	'label'          => 'Label',
15
	'description'    => 'Description',
16
	'quantity'       => 'Quantity',
17
	'price'          => 'Price',
18
	'net_price'      => 'Net Price',
19
	'total'          => 'Total',
20
	'subtotal'       => 'Subtotal',
21
	'net_total'      => 'Net Total',
22
	'amount'         => 'Amount',
23
	'currency'       => 'Currency',
24
	'tax'            => 'Tax',
25
	'tax_amount'     => 'Tax Amount',
26
	'tax_class'      => 'Tax Class',
27
	'tax_percentage' => 'Tax Percentage',
28
	'tax_rate'       => 'Tax Rate',
29
	'vat'            => array(
30
		'label' => 'VAT',
31
		'link'  => 'https://euvatrates.com/rates.json',
32
	),
33
	'vat_code'       => array(
34
		'label' => 'VAT Code',
35
		'link'  => 'https://euvatrates.com/rates.json',
36
	),
37
	'vat_category'   => array(
38
		'label' => 'VAT Category',
39
		'link'  => 'https://euvatrates.com/rates.json',
40
	),
41
	'shipping'       => 'Shipping',
42
	'type'           => 'Type',
43
	'url'            => 'URL',
44
	'image_url'      => 'Image URL',
45
	'status'         => 'Status',
46
	'stock'          => 'Stock',
47
	'discount'       => 'Discount',
48
	'pending'        => 'Pending',
49
	'category'       => 'Category',
50
	'discount'       => 'Discount',
51
	'product_id'     => 'Product ID',
52
);
53
54
$sources = array(
55
	'adyen'    => array(
56
		'label'      => 'Adyen',
57
		'link'       => 'https://docs.adyen.com/developers/api-reference/common-api#address',
58
		'components' => array(
59
60
		),
61
	),
62
	'ingenico' => array(
63
		'label'      => 'Ingenico',
64
		'link'       => 'https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/java/payments/create.html#payments-create-request-example',
65
		'components' => array(
66
67
		),
68
	),
69
	'klarna' => array(
70
		'label'      => 'Klarna',
71
		'link'       => 'https://developers.klarna.com/en/nl/kpm/checkout-api#address-structure',
72
		'components' => array(
73
74
		),
75
	),
76
	'mollie' => array(
77
		'label'      => 'Mollie',
78
		'link'       => 'https://docs.mollie.com/guides/common-data-types#address-object',
79
		'components' => array(
80
81
		),
82
	),
83
	'multisafepay' => array(
84
		'label'      => 'MultiSafepay',
85
		'link'       => 'https://github.com/wp-pay-gateways/multisafepay',
86
		'components' => array(
87
88
		),
89
	),
90
	'omnikassa-2' => array(
91
		'label'      => 'OmniKassa 2.0',
92
		'link'       => 'https://github.com/wp-pay-gateways/omnikassa-2/blob/master/documentation/handleiding-api-koppeling-rabo-smartpin-en_29970886.pdf',
93
		'components' => array(
94
			'id'  => array(
95
				'name'        => 'id',
96
				'description' => 'Item id',
97
				'example'     => 'A1000',
98
			),
99
			'name' => array(
100
				'name'        => 'name',
101
				'description' => 'Item name',
102
				'required'    => true,
103
				'example'     => 'Jackie O Round Sunglasses',
104
			),
105
			'description'   => array(
106
				'name'        => 'description',
107
				'description' => 'Item description',
108
				'example'     => 'These distinct, feminine frames balance a classic Jackie-O styling with a modern look.',
109
			),
110
			'quantity'  => array(
111
				'name'        => 'quantity',
112
				'description' => 'number: 1-2147483647',
113
				'required'    => true,
114
				'example'     => '1',
115
			),
116
			'amount'  => array(
117
				'name'        => 'amount',
118
				'description' => 'The amount in cents, including VAT, of the item each, see below for more details.',
119
				'required'    => true,
120
				'example'     => 'If the piece price of an order item (excluding VAT) is € 12.98 and a VAT rate of 21% is applied. The piece price including VAT € 12.98 + 21% = € 15.71',
121
			),
122
			'tax'  => array(
123
				'name'        => 'tax',
124
				'description' => 'The VAT of the item each, see below for more details',
125
			),
126
			'category'  => array(
127
				'name'        => 'category',
128
				'description' => 'Product category: PHYSICAL or DIGITAL',
129
				'required'    => true,
130
				'example'     => 'PHYSICAL',
131
			),
132
			'vat_category'  => array(
133
				'name'        => 'vatCategory',
134
				'description' => 'The VAT category of the product. The values refer to the different rates that are used in the Netherlands: 1 = High (currently 21%), 2 = Low (currently 6%), 3 = Zero (0%), 4 = None (exempt from VAT)',
135
				'example'     => '1',
136
			),
137
		),
138
	),
139
	'paypal' => array(
140
		'label'      => 'PayPal',
141
		'link'       => 'https://developer.paypal.com/docs/api/payments/v1/#definition-item',
142
		'components' => array(
143
144
		),
145
	),
146
	'pay.nl' => array(
147
		'label'      => 'Pay.nl',
148
		'link'       => 'https://www.pay.nl/docs/developers.php',
149
		'components' => array(
150
			'id'  => array(
151
				'name'        => 'productId',
152
				'type'        => 'integer',
153
				'description' => 'Het interne product id binnen uw systeem',
154
			),
155
			'description' => array(
156
				'name'        => 'description',
157
				'type'        => 'string',
158
				'description' => 'Omschrijving van het bestelde product',
159
			),
160
			'price'  => array(
161
				'name'        => 'price',
162
				'type'        => 'integer',
163
				'description' => 'Productprijs in centen, dus €3,50 is 350',
164
			),
165
			'quantity'  => array(
166
				'name'        => 'quantity',
167
				'type'        => 'integer',
168
				'description' => 'Aantal bestelde producten met het betreffende product id',
169
			),
170
			'vat_code'  => array(
171
				'name'        => 'vatCode',
172
				'type'        => 'string',
173
				'description' => 'BTW code, mogelijke waarden: H: high, N: zero, L: low',
174
			),
175
			'vat_percentage'  => array(
176
				'name'        => 'vatPercentage',
177
			),
178
			'discount'        => array(
179
				'name'        => 'discount',
180
			),
181
		),
182
	),
183
	'sisow' => array(
184
		'label'      => 'Sisow',
185
		'link'       => 'https://www.sisow.nl/implementatie-api',
186
		'components' => array(
187
			'id'  => array(
188
				'name'        => 'product_id_x',
189
				'description' => 'Product code',
190
			),
191
			'description'  => array(
192
				'name'        => 'product_description_x',
193
				'description' => 'Omschrijving van het product',
194
			),
195
			'quantity'  => array(
196
				'name'        => 'product_quantity_x',
197
				'description' => 'Aantal besteld',
198
			),
199
			'net_price'  => array(
200
				'name'        => 'product_netprice_x',
201
				'description' => 'Netto prijs van het product',
202
			),
203
			'total'  => array(
204
				'name'        => 'product_total_x',
205
				'description' => 'Totaal bedrag van de orderregel inclusief BTW',
206
			),
207
			'net_total'  => array(
208
				'name'        => 'product_nettotal_x',
209
				'description' => 'Totaal bedrag van de orderregel exclusief BTW',
210
			),
211
			'tax'  => array(
212
				'name'        => 'product_tax_x',
213
				'description' => 'BTW bedrag in centen van de orderregel',
214
			),
215
			'tax_rate'  => array(
216
				'name'        => 'product_taxrate_x',
217
				'description' => 'BTW percentage (21% doorgeven als 2100)',
218
			),
219
		),
220
	),
221
	'easy-digital-downloads' => array(
222
		'label'      => 'Easy Digital Downloads',
223
		'link'       => 'https://github.com/easydigitaldownloads/easy-digital-downloads/blob/2.9.7/includes/admin/reporting/class-export-payments.php',
224
		'components' => array(
225
226
		),
227
	),
228
	'gravityforms' => array(
229
		'label'      => 'Gravity Forms',
230
		'link'       => 'https://github.com/wp-premium/gravityforms/blob/2.3.2/includes/fields/class-gf-field-address.php#L48-L52',
231
		'components' => array(
232
233
		),
234
	),
235
	'memberpress' => array(
236
		'label'      => 'MemberPress',
237
		'link'       => 'https://github.com/wp-premium/memberpress-business/blob/1.3.36/app/models/MeprUser.php#L1296-L1317',
238
		'components' => array(
239
240
		),
241
	),
242
	'restrict-content-pro' => array(
243
		'label'      => 'Restrict Content Pro',
244
		'link'       => 'https://github.com/restrictcontentpro/restrict-content',
245
		'components' => array(
246
247
		),
248
	),
249
	'woocommerce' => array(
250
		'label'      => 'WooCommerce',
251
		'links'      => array(
252
			'https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-order-item.php',
253
			'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/api/legacy/v1/class-wc-api-orders.php#L98-L234'
254
		),
255
		'components' => array(
256
			'id'  => array(
257
				'name'        => 'id',
258
			),
259
			'subtotal'  => array(
260
				'name'        => 'subtotal',
261
				'description' => array(
262
					'Get line subtotal - this is the cost before discount.',
263
					'wc_format_decimal( $order->get_line_subtotal( $item ), 2 )',
264
					'public function get_line_subtotal( $item, $inc_tax = false, $round = true )',
265
				),
266
				'links'       => array(
267
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/api/legacy/v1/class-wc-api-orders.php#L181',
268
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/abstracts/abstract-wc-order.php#L1511-L1533',
269
				),
270
			),
271
			'total'  => array(
272
				'name'        => 'total',
273
				'description' => array(
274
					'Calculate line total - useful for gateways.',
275
					'wc_format_decimal( $order->get_line_total( $item ), 2 )',
276
					'public function get_line_total( $item, $inc_tax = false, $round = true )',
277
				),
278
				'links'       => array(
279
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/api/legacy/v1/class-wc-api-orders.php#L182',
280
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/abstracts/abstract-wc-order.php#L1559-L1579',
281
				),
282
			),
283
			'total_tax'  => array(
284
				'name'        => 'total_tax',
285
				'description' => array(
286
					'Get line tax - useful for gateways.',
287
					'wc_format_decimal( $order->get_line_tax( $item ), 2 )',
288
					'public function get_line_tax( $item )',
289
					'public function get_total_tax( $context = \'view\' )',
290
				),
291
				'links'       => array(
292
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/api/legacy/v1/class-wc-api-orders.php#L183',
293
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/abstracts/abstract-wc-order.php#L1599-L1607',
294
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/abstracts/abstract-wc-order.php#L363-L371',
295
				),
296
			),
297
			'price'  => array(
298
				'name'        => 'price',
299
				'description' => array(
300
					'Calculate item cost - useful for gateways.',
301
					'wc_format_decimal( $order->get_item_total( $item ), 2 )',
302
					'public function get_item_total( $item, $inc_tax = false, $round = true )',
303
				),
304
				'links'       => array(
305
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/api/legacy/v1/class-wc-api-orders.php#L184',
306
					'https://github.com/woocommerce/woocommerce/blob/3.4.5/includes/abstracts/abstract-wc-order.php#L1535-L1557',
307
				),
308
			),
309
			'quantity'  => array(
310
				'name'        => 'quantity',
311
			),
312
			'tax_class'  => array(
313
				'name'        => 'tax_class',
314
			),
315
			'name'  => array(
316
				'name'        => 'name',
317
			),
318
			'product_id'  => array(
319
				'name'        => 'product_id',
320
			),
321
			'sku'  => array(
322
				'name'        => 'sku',
323
			),
324
		),
325
	),
326
	'google-analytics' => array(
327
		'label'      => 'Google Analytics',
328
		'link'       => 'https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce',
329
		'components' => array(
330
			'id'  => array(
331
				'name'        => 'id',
332
				'description' => 'The transaction ID. This ID is what links items to the transactions to which they belong. (e.g. 1234)',
333
				'required'    => true,
334
			),
335
			'name'  => array(
336
				'name'        => 'name',
337
				'description' => 'The item name. (e.g. Fluffy Pink Bunnies)',
338
				'required'    => true,
339
			),
340
			'sku'  => array(
341
				'name'        => 'sku',
342
				'description' => 'Specifies the SKU or item code. (e.g. SKU47)',
343
			),
344
			'category'  => array(
345
				'name'        => 'category',
346
				'description' => 'The category to which the item belongs (e.g. Party Toys)',
347
			),
348
			'price'  => array(
349
				'name'        => 'price',
350
				'description' => 'The individual, unit, price for each item. (e.g. 11.99)',
351
			),
352
			'quantity'  => array(
353
				'name'        => 'quantity',
354
				'description' => 'The number of units purchased in the transaction. If a non-integer value is passed into this field (e.g. 1.5), it will be rounded to the closest integer value.',
355
			),
356
		),
357
	),
358
	'mailchimp' => array(
359
		'label'      => 'MailChimp',
360
		'link'       => 'https://developer.mailchimp.com/documentation/mailchimp/reference/ecommerce/stores/carts/lines/',
361
		'components' => array(
362
			'id'  => array(
363
				'name'        => 'id',
364
				'description' => 'A unique identifier for the cart line item.',
365
			),
366
			'quantity'  => array(
367
				'name'        => 'quantity',
368
				'description' => 'The quantity of a cart line item.',
369
			),
370
			'price'  => array(
371
				'name'        => 'price',
372
				'description' => 'The price of a cart line item.',
373
			),
374
		),
375
	),
376
	'apple-pay' => array(
377
		'label'      => 'Apple Pay',
378
		'link'       => 'https://developer.apple.com/documentation/apple_pay_on_the_web/applepaylineitem',
379
		'components' => array(
380
			'label'  => array(
381
				'name'        => 'label',
382
				'description' => 'A short, localized description of the line item.',
383
				'required'    => true,
384
			),
385
			'amount' => array(
386
				'name'        => 'amount',
387
				'description' => 'The monetary amount of the line item.',
388
				'required'    => true,
389
			),
390
			'type'   => array(
391
				'name'        => 'type',
392
				'description' => 'A value that indicates whether the line item is final or pending.',
393
			),
394
		),
395
	),
396
	'schema.org' => array(
397
		'label'      => 'Schema.org',
398
		'link'       => 'https://schema.org/OrderItem',
399
		'components' => array(
400
			'number'       => array(
401
				'name'        => 'orderItemNumber',
402
				'description' => 'The identifier of the order item',
403
			),
404
			'status'       => array(
405
				'name'        => 'orderItemStatus',
406
				'description' => 'The current status of the order item.',
407
			),
408
			'quantity'     => array(
409
				'name'        => 'orderQuantity',
410
				'description' => 'The number of the item ordered. If the property is not set, assume the quantity is one.',
411
			),
412
		),
413
	),
414
	'payment-request' => array(
415
		'label'      => 'Payment Request API',
416
		'link'       => 'https://www.w3.org/TR/payment-request/#dom-paymentitem',
417
		'components' => array(
418
			'label'       => array(
419
				'name'        => 'label',
420
				'description' => 'A human-readable description of the item. The user agent may display this to the user.',
421
				'required'    => true,
422
			),
423
			'amount'       => array(
424
				'name'        => 'amount',
425
				'description' => 'A PaymentCurrencyAmount containing the monetary amount for the item.',
426
				'required'    => true,
427
			),
428
			'pending'       => array(
429
				'name'        => 'pending',
430
				'description' => 'A boolean. When set to true it means that the amount member is not final. This is commonly used to show items such as shipping or tax amounts that depend upon selection of shipping address or shipping option. User agents MAY indicate pending fields in the user interface for the payment request.',
431
				'required'    => true,
432
			),
433
		),
434
	),
435
);
436
437
function print_link( $array ) {
438
	$links = array();
439
440
	if ( array_key_exists( 'links', $array ) ) {
441
		$links = $array['links'];
442
	}
443
444
	if ( array_key_exists( 'link', $array ) ) {
445
		$links[] = $array['link'];
446
	}
447
448
	$html = array();
449
450
	foreach ( $links as $link ) {
451
		$html[] = sprintf(
452
			'<a href="%s"><i class="fas fa-info-circle"></i></a>',
453
			$link
454
		);
455
	}
456
457
	echo implode( ' ', $html );
458
}
459
460
?>
461
<!doctype html>
462
463
<html lang="en">
464
	<head>
465
		<meta charset="utf-8">
466
467
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
468
469
		<!-- Bootstrap CSS -->
470
		<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
471
472
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
473
474
		<title>Pronamic Pay - Payment Items</title>
475
	</head>
476
477
	<body>
478
		<h1>Pronamic Pay - Payment Items</h1>
479
480
		<table class="table table-sm table-striped table-hover">
481
			<thead>
482
				<tr>
483
					<th scope="col">Component</th>
484
485
					<?php foreach ( $sources as $source ) : ?>
486
487
						<th scope="col">
488
							<?php
489
490
							echo $source['label'];
491
492
							echo ' ';
493
494
							print_link( $source );
495
496
							?>
497
						</th>
498
499
					<?php endforeach; ?>
500
501
				</tr>
502
			</thead>
503
504
			<tbody>
505
				
506
				<?php foreach ( $components as $key => $data ) : ?>
507
508
					<tr>
509
						<th scope="row">
510
							<?php
511
512
							if ( is_array( $data ) ) {
513
								echo $data['label'];
514
515
								echo ' ';
516
517
								print_link( $data );
518
							} else {
519
								echo $data;
520
							}
521
522
							?>
523
						</th>
524
525
						<?php foreach ( $sources as $source ) : ?>
526
527
							<td>
528
								<?php
529
530
								if ( isset( $source['components'][ $key ] ) ) {
531
									$component = $source['components'][ $key ];
532
533
									$name     = null;
534
									$tip      = null;
535
									$optional = null;
536
									$warning  = null;
537
538
									if ( is_array( $component ) ) {
539
										$name     = $component['name'];
540
541
										if ( array_key_exists( 'description', $component ) ) {
542
											$description = $component['description'];
543
											$description = is_array( $description ) ? $description : array( $description );
544
545
											$tip = implode( "\r\n", $description );
546
										}
547
548
										if ( array_key_exists( 'optional', $component ) ) {
549
											$optional = $component['optional'];
550
										}
551
552
										if ( array_key_exists( 'required', $component ) ) {
553
											$optional = ! $component['required'];
554
										}
555
556
										if ( array_key_exists( 'warning', $component ) ) {
557
											$warning = $component['warning'];
558
										}
559
									} else {
560
										$name = $component;
561
									}
562
563
									printf(
564
										'<code>%s</code>',
565
										$name
566
									);
567
568
									if ( ! empty( $tip ) ) {
569
										echo ' ';
570
571
										printf(
572
											'<i class="fas fa-info-circle" data-toggle="tooltip" data-placement="top" title="%s"></i>',
573
											$tip
574
										);
575
									}
576
577
									if ( null !== $optional ) {
578
										echo ' ';
579
580
										printf(
581
											'<i class="fas %s" data-toggle="tooltip" data-placement="top" title="%s"></i>',
582
											$optional ? 'fa-dot-circle' : 'fa-circle',
583
											$optional ? 'Optional' : 'Required'
584
										);
585
									}
586
587
									if ( null !== $warning ) {
588
										echo ' ';
589
590
										printf(
591
											'<i class="fas fa-exclamation-triangle" data-toggle="tooltip" data-placement="top" title="%s"></i>',
592
											$warning
593
										);
594
									}
595
596
									echo ' ';
597
598
									print_link( $component );
599
								}
600
601
								?>
602
							</td>
603
604
						<?php endforeach; ?>
605
					</tr>
606
607
				<?php endforeach; ?>
608
609
			</tbody>
610
		</table>
611
612
		<h2>Links</h2>
613
614
		<table class="table table-striped">
615
			<thead>
616
				<tr>
617
					<th scope="col">Title</th>
618
					<th scope="col">URL</th>
619
					<th scope="col">Description</th>
620
				</tr>
621
			</thead>
622
623
			<tbody>
624
				<tr>
625
					<td>
626
						Payment Request API - `PaymentItem` dictionary
627
					</td>
628
					<td>
629
						<a href="https://www.w3.org/TR/payment-request/#dom-paymentitem">https://www.w3.org/TR/payment-request/#dom-paymentitem</a>						
630
					</td>
631
					<td></td>
632
				</tr>
633
			</tbody>
634
		</table>
635
636
		<!-- Optional JavaScript -->
637
		<!-- jQuery first, then Popper.js, then Bootstrap JS -->
638
		<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
639
		<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
640
		<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
641
642
		<script type="text/javascript">
643
			jQuery( document ).ready( function( $ ) {
644
				$( '[data-toggle="tooltip"]' ).tooltip();
645
			} );
646
		</script>
647
	</body>
648
</html>
649