Failed Conditions
Push — develop ( 531a2b...d80767 )
by Remco
04:01
created

src/Listener.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Webhook Listener.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 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
use Pronamic\WordPress\Pay\WebhookManager;
0 ignored issues
show
The type Pronamic\WordPress\Pay\WebhookManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Title: ING Kassa Compleet listener
18
 * Description:
19
 * Copyright: 2005-2019 Pronamic
20
 * Company: Pronamic
21
 *
22
 * @author  Reüel van der Steege
23
 * @version 2.0.0
24
 * @since   1.0.1
25
 */
26
class Listener {
27
	/**
28
	 * Listen to ING Kassa Compleet webhook requests.
29
	 */
30
	public static function listen() {
31
		if ( ! filter_has_var( INPUT_GET, 'ing_kassa_compleet_webhook' ) ) {
32
			return;
33
		}
34
35
		$data = json_decode( file_get_contents( 'php://input' ) );
36
37
		if ( is_object( $data ) && isset( $data->order_id ) ) {
38
			$payment = get_pronamic_payment_by_transaction_id( $data->order_id );
39
40
			if ( null === $payment ) {
41
				return;
42
			}
43
44
			// Add note.
45
			$note = sprintf(
46
				/* translators: %s: ING */
47
				__( 'Webhook requested by %s.', 'pronamic_ideal' ),
48
				__( 'ING', 'pronamic_ideal' )
49
			);
50
51
			$payment->add_note( $note );
52
53
			// Log webhook request.
54
			WebhookManager::log_payment( $payment );
55
56
			// Update payment.
57
			Plugin::update_payment( $payment, false );
58
		}
59
	}
60
}
61