Completed
Branch master (b8e26c)
by Remco
04:42
created
Category
src/Listener.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Listener {
20 20
 	public static function listen() {
21
-		if ( filter_has_var( INPUT_GET, 'omnikassa2_webhook' ) ) {
21
+		if (filter_has_var(INPUT_GET, 'omnikassa2_webhook')) {
22 22
 			/**
23 23
 			 * Notification POST request body JSON sample:
24 24
 			 *
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
 			 *  "poiId": "123"
30 30
 			 * }
31 31
 			 */
32
-			$data = json_decode( file_get_contents( 'php://input' ) );
32
+			$data = json_decode(file_get_contents('php://input'));
33 33
 
34
-			if ( ! is_object( $data ) ) {
34
+			if ( ! is_object($data)) {
35 35
 				return;
36 36
 			}
37 37
 
38
-			if ( 'merchant.order.status.changed' !== $data->eventName ) {
38
+			if ('merchant.order.status.changed' !== $data->eventName) {
39 39
 				return;
40 40
 			}
41 41
 
42
-			$query = new \WP_Query( array(
42
+			$query = new \WP_Query(array(
43 43
 				'post_type'      => GatewayPostType::POST_TYPE,
44 44
 				'post_status'    => 'publish',
45 45
 				'posts_per_page' => - 1,
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
 						'value' => 'rabobank-omnikassa-2',
50 50
 					),
51 51
 				),
52
-			) );
52
+			));
53 53
 
54
-			foreach ( $query->posts as $post ) {
54
+			foreach ($query->posts as $post) {
55 55
 				$factory = new ConfigFactory();
56 56
 
57
-				$config = $factory->get_config( $post->ID );
57
+				$config = $factory->get_config($post->ID);
58 58
 
59
-				if ( '' === $config->signing_key ) {
59
+				if ('' === $config->signing_key) {
60 60
 					continue;
61 61
 				}
62 62
 
@@ -65,62 +65,62 @@  discard block
 block discarded – undo
65 65
 
66 66
 				$url = Client::URL_PRODUCTION;
67 67
 
68
-				if ( Gateway::MODE_TEST === $config->mode ) {
68
+				if (Gateway::MODE_TEST === $config->mode) {
69 69
 					$url = Client::URL_SANDBOX;
70 70
 				}
71 71
 
72
-				$client->set_url( $url );
73
-				$client->set_refresh_token( $config->refresh_token );
74
-				$client->set_signing_key( $config->signing_key );
72
+				$client->set_url($url);
73
+				$client->set_refresh_token($config->refresh_token);
74
+				$client->set_signing_key($config->signing_key);
75 75
 
76 76
 				// Retrieve and process announcements
77 77
 				do {
78
-					$response = $client->retrieve_announcement( $data );
78
+					$response = $client->retrieve_announcement($data);
79 79
 
80
-					if ( is_wp_error( $response ) ) {
80
+					if (is_wp_error($response)) {
81 81
 						continue;
82 82
 					}
83 83
 
84 84
 					$order_results = new OrderResults();
85 85
 
86
-					$order_results->set_signing_key( $config->signing_key );
86
+					$order_results->set_signing_key($config->signing_key);
87 87
 
88 88
 					$order_results->more_order_results_available = $response->moreOrderResultsAvailable;
89 89
 					$order_results->order_results                = $response->orderResults;
90 90
 
91 91
 					// Validate signature
92
-					if ( ! Security::validate_signature( $response->signature, $order_results->get_signature() ) ) {
92
+					if ( ! Security::validate_signature($response->signature, $order_results->get_signature())) {
93 93
 						// Invalid signature
94 94
 						continue;
95 95
 					}
96 96
 
97
-					foreach ( $order_results->order_results as $order ) {
97
+					foreach ($order_results->order_results as $order) {
98 98
 						$payment = null;
99 99
 
100
-						if ( '{order_id}' === $config->order_id ) {
101
-							$payment = get_pronamic_payment_by_meta( '_pronamic_payment_order_id', $order->merchantOrderId );
100
+						if ('{order_id}' === $config->order_id) {
101
+							$payment = get_pronamic_payment_by_meta('_pronamic_payment_order_id', $order->merchantOrderId);
102 102
 						}
103 103
 
104
-						if ( null === $payment ) {
105
-							$payment = get_pronamic_payment( $order->merchantOrderId );
104
+						if (null === $payment) {
105
+							$payment = get_pronamic_payment($order->merchantOrderId);
106 106
 						}
107 107
 
108
-						$payment->set_transaction_id( $order->omnikassaOrderId );
109
-						$payment->set_meta( 'omnikassa_2_update_order_status', $order->orderStatus );
108
+						$payment->set_transaction_id($order->omnikassaOrderId);
109
+						$payment->set_meta('omnikassa_2_update_order_status', $order->orderStatus);
110 110
 
111 111
 						// Add note.
112 112
 						$note = sprintf(
113 113
 							/* translators: %s: OmniKassa 2.0 */
114
-							__( 'Webhook requested by %s.', 'pronamic_ideal' ),
115
-							__( 'OmniKassa 2.0', 'pronamic_ideal' )
114
+							__('Webhook requested by %s.', 'pronamic_ideal'),
115
+							__('OmniKassa 2.0', 'pronamic_ideal')
116 116
 						);
117 117
 
118
-						$payment->add_note( $note );
118
+						$payment->add_note($note);
119 119
 
120 120
 						// Update payment.
121
-						Plugin::update_payment( $payment );
121
+						Plugin::update_payment($payment);
122 122
 					}
123
-				} while ( $response->moreOrderResultsAvailable );
123
+				} while ($response->moreOrderResultsAvailable);
124 124
 			}
125 125
 		}
126 126
 	}
Please login to merge, or discard this patch.
src/Security.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,32 +13,32 @@
 block discarded – undo
13 13
  * @since   1.0.0
14 14
  */
15 15
 class Security {
16
-	public static function calculate_signature( $data, $signing_key ) {
17
-		if ( ! is_array( $data ) ) {
16
+	public static function calculate_signature($data, $signing_key) {
17
+		if ( ! is_array($data)) {
18 18
 			return;
19 19
 		}
20 20
 
21
-		if ( '' === $signing_key ) {
21
+		if ('' === $signing_key) {
22 22
 			return;
23 23
 		}
24 24
 
25 25
 		$signature = hash_hmac(
26 26
 			'sha512',
27
-			implode( ',', $data ),
28
-			base64_decode( $signing_key )
27
+			implode(',', $data),
28
+			base64_decode($signing_key)
29 29
 		);
30 30
 
31 31
 		return $signature;
32 32
 	}
33 33
 
34
-	public static function validate_signature( $signature_a, $signature_b ) {
35
-		if ( empty( $signature_a ) || empty( $signature_b ) ) {
34
+	public static function validate_signature($signature_a, $signature_b) {
35
+		if (empty($signature_a) || empty($signature_b)) {
36 36
 			// Empty signature string or null from calculation.
37 37
 
38 38
 			return false;
39 39
 		}
40 40
 
41
-		if ( 0 === strcasecmp( $signature_a, $signature_b ) ) {
41
+		if (0 === strcasecmp($signature_a, $signature_b)) {
42 42
 			// Valid signature
43 43
 			return true;
44 44
 		}
Please login to merge, or discard this patch.
src/Settings.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -16,45 +16,45 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Settings extends GatewaySettings {
18 18
 	public function __construct() {
19
-		add_filter( 'pronamic_pay_gateway_sections', array( $this, 'sections' ) );
20
-		add_filter( 'pronamic_pay_gateway_fields', array( $this, 'fields' ) );
19
+		add_filter('pronamic_pay_gateway_sections', array($this, 'sections'));
20
+		add_filter('pronamic_pay_gateway_fields', array($this, 'fields'));
21 21
 	}
22 22
 
23
-	public function sections( array $sections ) {
23
+	public function sections(array $sections) {
24 24
 		$sections['omnikassa-2'] = array(
25
-			'title'   => __( 'OmniKassa 2.0', 'pronamic_ideal' ),
26
-			'methods' => array( 'omnikassa-2' ),
25
+			'title'   => __('OmniKassa 2.0', 'pronamic_ideal'),
26
+			'methods' => array('omnikassa-2'),
27 27
 		);
28 28
 
29 29
 		// Advanced
30 30
 		$sections['omnikassa-2_advanced'] = array(
31
-			'title'   => __( 'Advanced', 'pronamic_ideal' ),
32
-			'methods' => array( 'omnikassa-2' ),
31
+			'title'   => __('Advanced', 'pronamic_ideal'),
32
+			'methods' => array('omnikassa-2'),
33 33
 		);
34 34
 
35 35
 		// Transaction eedback
36 36
 		$sections['omnikassa-2_feedback'] = array(
37
-			'title'       => __( 'Transaction feedback', 'pronamic_ideal' ),
38
-			'methods'     => array( 'omnikassa-2' ),
37
+			'title'       => __('Transaction feedback', 'pronamic_ideal'),
38
+			'methods'     => array('omnikassa-2'),
39 39
 			'description' => sprintf(
40 40
 				/* translators: %s: OmniKassa 2 */
41
-				__( 'Set the Webhook URL in the %s dashboard to receive automatic transaction status updates.', 'pronamic_ideal' ),
42
-				__( 'OmniKassa 2.0', 'pronamic_ideal' )
41
+				__('Set the Webhook URL in the %s dashboard to receive automatic transaction status updates.', 'pronamic_ideal'),
42
+				__('OmniKassa 2.0', 'pronamic_ideal')
43 43
 			),
44 44
 		);
45 45
 
46 46
 		return $sections;
47 47
 	}
48 48
 
49
-	public function fields( array $fields ) {
49
+	public function fields(array $fields) {
50 50
 		// Refresh Token
51 51
 		$fields[] = array(
52 52
 			'filter'   => FILTER_SANITIZE_STRING,
53 53
 			'section'  => 'omnikassa-2',
54 54
 			'meta_key' => '_pronamic_gateway_omnikassa_2_refresh_token',
55
-			'title'    => _x( 'Refresh Token', 'omnikassa', 'pronamic_ideal' ),
55
+			'title'    => _x('Refresh Token', 'omnikassa', 'pronamic_ideal'),
56 56
 			'type'     => 'textarea',
57
-			'classes'  => array( 'code' ),
57
+			'classes'  => array('code'),
58 58
 		);
59 59
 
60 60
 		// Signing Key
@@ -62,19 +62,19 @@  discard block
 block discarded – undo
62 62
 			'filter'   => FILTER_SANITIZE_STRING,
63 63
 			'section'  => 'omnikassa-2',
64 64
 			'meta_key' => '_pronamic_gateway_omnikassa_2_signing_key',
65
-			'title'    => _x( 'Signing Key', 'omnikassa', 'pronamic_ideal' ),
65
+			'title'    => _x('Signing Key', 'omnikassa', 'pronamic_ideal'),
66 66
 			'type'     => 'text',
67
-			'classes'  => array( 'large-text', 'code' ),
67
+			'classes'  => array('large-text', 'code'),
68 68
 		);
69 69
 
70 70
 		// Transaction feedback
71 71
 		$fields[] = array(
72 72
 			'section' => 'omnikassa-2',
73
-			'title'   => __( 'Transaction feedback', 'pronamic_ideal' ),
73
+			'title'   => __('Transaction feedback', 'pronamic_ideal'),
74 74
 			'type'    => 'description',
75 75
 			'html'    => sprintf(
76 76
 				'<span class="dashicons dashicons-warning"></span> %s',
77
-				__( 'Receiving payment status updates needs additional configuration, if not yet completed.', 'pronamic_ideal' )
77
+				__('Receiving payment status updates needs additional configuration, if not yet completed.', 'pronamic_ideal')
78 78
 			),
79 79
 		);
80 80
 
@@ -83,17 +83,17 @@  discard block
 block discarded – undo
83 83
 			'filter'      => FILTER_SANITIZE_STRING,
84 84
 			'section'     => 'omnikassa-2_advanced',
85 85
 			'meta_key'    => '_pronamic_gateway_omnikassa_2_order_id',
86
-			'title'       => __( 'Order ID', 'pronamic_ideal' ),
86
+			'title'       => __('Order ID', 'pronamic_ideal'),
87 87
 			'type'        => 'text',
88
-			'classes'     => array( 'regular-text', 'code' ),
88
+			'classes'     => array('regular-text', 'code'),
89 89
 			'tooltip'     => sprintf(
90 90
 				/* translators: %s: Parameter */
91
-				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
92
-				sprintf( '<code>%s</code>', 'orderId' )
91
+				__('The OmniKassa %s parameter.', 'pronamic_ideal'),
92
+				sprintf('<code>%s</code>', 'orderId')
93 93
 			),
94 94
 			'description' => sprintf(
95 95
 				'%s %s<br />%s',
96
-				__( 'Available tags:', 'pronamic_ideal' ),
96
+				__('Available tags:', 'pronamic_ideal'),
97 97
 				sprintf(
98 98
 					'<code>%s</code> <code>%s</code>',
99 99
 					'{order_id}',
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 				),
102 102
 				sprintf(
103 103
 					/* translators: %s: {payment_id} */
104
-					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
104
+					__('Default: <code>%s</code>', 'pronamic_ideal'),
105 105
 					'{payment_id}'
106 106
 				)
107 107
 			),
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 		// Webhook
111 111
 		$fields[] = array(
112 112
 			'section'  => 'omnikassa-2_feedback',
113
-			'title'    => __( 'Webhook URL', 'pronamic_ideal' ),
113
+			'title'    => __('Webhook URL', 'pronamic_ideal'),
114 114
 			'type'     => 'text',
115
-			'classes'  => array( 'large-text', 'code' ),
116
-			'value'    => add_query_arg( 'omnikassa2_webhook', '', home_url( '/' ) ),
115
+			'classes'  => array('large-text', 'code'),
116
+			'value'    => add_query_arg('omnikassa2_webhook', '', home_url('/')),
117 117
 			'readonly' => true,
118
-			'methods'  => array( 'omnikassa-2' ),
119
-			'tooltip'  => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
118
+			'methods'  => array('omnikassa-2'),
119
+			'tooltip'  => __('The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal'),
120 120
 		);
121 121
 
122 122
 		return $fields;
Please login to merge, or discard this patch.