Listener::listen()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 38
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 3
eloc 21
c 5
b 0
f 0
nc 3
nop 0
dl 0
loc 38
ccs 0
cts 26
cp 0
crap 12
rs 9.584
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Icepay;
4
5
use Pronamic\WordPress\Pay\Core\Util;
6
use Pronamic\WordPress\Pay\Plugin;
7
8
/**
9
 * Title: ICEPAY listener
10
 * Description:
11
 * Copyright: 2005-2021 Pronamic
12
 * Company: Pronamic
13
 *
14
 * @author Remco Tolsma
15
 * @version 2.0.6
16
 */
17
class Listener {
18
	/**
19
	 * Listen.
20
	 *
21
	 * @return void
22
	 */
23
	public static function listen() {
24
		$variable_names = array(
25
			'Status',
26
			'StatusCode',
27
			'Merchant',
28
			'OrderID',
29
			'PaymentID',
30
			'Reference',
31
			'TransactionID',
32
			'Checksum',
33
		);
34
35
		if ( ! Util::input_has_vars( INPUT_POST, $variable_names ) ) {
36
			return;
37
		}
38
39
		$reference = filter_input( INPUT_POST, 'OrderID', FILTER_SANITIZE_STRING );
40
41
		$payment = get_pronamic_payment( $reference );
42
43
		if ( null === $payment ) {
44
			return;
45
		}
46
47
		// Add note.
48
		$note = sprintf(
49
			/* translators: %s: payment provider name */
50
			__( 'Webhook requested by %s.', 'pronamic_ideal' ),
51
			__( 'ICEPAY', 'pronamic_ideal' )
52
		);
53
54
		$payment->add_note( $note );
55
56
		// Log webhook request.
57
		do_action( 'pronamic_pay_webhook_log_payment', $payment );
58
59
		// Update payment.
60
		Plugin::update_payment( $payment );
61
	}
62
}
63