Listener::listen()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 2
b 0
f 0
nc 4
nop 0
dl 0
loc 28
ccs 0
cts 17
cp 0
crap 30
rs 9.5222
1
<?php
2
/**
3
 * Webhook Listener.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\ING\KassaCompleet
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\ING\KassaCompleet;
12
13
use Pronamic\WordPress\Pay\Plugin;
14
15
/**
16
 * Title: ING Kassa Compleet listener
17
 * Description:
18
 * Copyright: 2005-2021 Pronamic
19
 * Company: Pronamic
20
 *
21
 * @author  Reüel van der Steege
22
 * @version 2.0.0
23
 * @since   1.0.1
24
 */
25
class Listener {
26
	/**
27
	 * Listen to ING Kassa Compleet webhook requests.
28
	 */
29
	public static function listen() {
30
		if ( ! filter_has_var( INPUT_GET, 'ing_kassa_compleet_webhook' ) ) {
31
			return;
32
		}
33
34
		$data = json_decode( file_get_contents( 'php://input' ) );
35
36
		if ( is_object( $data ) && isset( $data->order_id ) ) {
37
			$payment = get_pronamic_payment_by_transaction_id( $data->order_id );
38
39
			if ( null === $payment ) {
40
				return;
41
			}
42
43
			// Add note.
44
			$note = sprintf(
45
				/* translators: %s: payment provider name */
46
				__( 'Webhook requested by %s.', 'pronamic_ideal' ),
47
				__( 'ING', 'pronamic_ideal' )
48
			);
49
50
			$payment->add_note( $note );
51
52
			// Log webhook request.
53
			do_action( 'pronamic_pay_webhook_log_payment', $payment );
54
55
			// Update payment.
56
			Plugin::update_payment( $payment, false );
57
		}
58
	}
59
}
60