Passed
Push — master ( 2f113f...8b5318 )
by Remco
06:36
created
src/Gateway.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -28,23 +28,23 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param \Pronamic\WordPress\Pay\Gateways\OmniKassa2\Config $config Config.
30 30
 	 */
31
-	public function __construct( Config $config ) {
32
-		parent::__construct( $config );
31
+	public function __construct(Config $config) {
32
+		parent::__construct($config);
33 33
 
34
-		$this->set_method( self::METHOD_HTTP_REDIRECT );
34
+		$this->set_method(self::METHOD_HTTP_REDIRECT);
35 35
 
36 36
 		// Client.
37 37
 		$this->client = new Client();
38 38
 
39 39
 		$url = Client::URL_PRODUCTION;
40 40
 
41
-		if ( self::MODE_TEST === $config->mode ) {
41
+		if (self::MODE_TEST === $config->mode) {
42 42
 			$url = Client::URL_SANDBOX;
43 43
 		}
44 44
 
45
-		$this->client->set_url( $url );
46
-		$this->client->set_refresh_token( $config->refresh_token );
47
-		$this->client->set_signing_key( $config->signing_key );
45
+		$this->client->set_url($url);
46
+		$this->client->set_refresh_token($config->refresh_token);
47
+		$this->client->set_signing_key($config->signing_key);
48 48
 	}
49 49
 
50 50
 	/**
@@ -69,39 +69,39 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @param Payment $payment Payment.
71 71
 	 */
72
-	public function start( Payment $payment ) {
73
-		$merchant_order_id = $payment->format_string( $this->config->order_id );
72
+	public function start(Payment $payment) {
73
+		$merchant_order_id = $payment->format_string($this->config->order_id);
74 74
 
75
-		$payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id );
75
+		$payment->set_meta('omnikassa_2_merchant_order_id', $merchant_order_id);
76 76
 
77 77
 		$amount = new Money(
78 78
 			$payment->get_currency(),
79
-			Core_Util::amount_to_cents( $payment->get_amount()->get_amount() )
79
+			Core_Util::amount_to_cents($payment->get_amount()->get_amount())
80 80
 		);
81 81
 
82 82
 		$merchant_return_url = $payment->get_return_url();
83 83
 
84
-		$order = new Order( $merchant_order_id, $amount, $merchant_return_url );
84
+		$order = new Order($merchant_order_id, $amount, $merchant_return_url);
85 85
 
86
-		$order->set_description( $payment->get_description() );
87
-		$order->set_language( $payment->get_language() );
86
+		$order->set_description($payment->get_description());
87
+		$order->set_language($payment->get_language());
88 88
 
89 89
 		// Payment brand.
90
-		$payment_brand = PaymentBrands::transform( $payment->get_method() );
90
+		$payment_brand = PaymentBrands::transform($payment->get_method());
91 91
 
92
-		$order->set_payment_brand( $payment_brand );
92
+		$order->set_payment_brand($payment_brand);
93 93
 
94
-		if ( null !== $payment_brand ) {
94
+		if (null !== $payment_brand) {
95 95
 			// Payment brand force should only be set if payment brand is not empty.
96
-			$order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE );
96
+			$order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE);
97 97
 		}
98 98
 
99
-		if ( ! $this->config->is_access_token_valid() ) {
99
+		if ( ! $this->config->is_access_token_valid()) {
100 100
 			$data = $this->client->get_access_token_data();
101 101
 
102 102
 			$error = $this->client->get_error();
103 103
 
104
-			if ( is_wp_error( $error ) ) {
104
+			if (is_wp_error($error)) {
105 105
 				$this->error = $error;
106 106
 
107 107
 				return;
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 			$this->config->access_token             = $data->token;
111 111
 			$this->config->access_token_valid_until = $data->validUntil;
112 112
 
113
-			update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token );
114
-			update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token_valid_until', $data->validUntil );
113
+			update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token);
114
+			update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token_valid_until', $data->validUntil);
115 115
 		}
116 116
 
117
-		$result = $this->client->order_announce( $this->config, $order );
117
+		$result = $this->client->order_announce($this->config, $order);
118 118
 
119 119
 		$error = $this->client->get_error();
120 120
 
121
-		if ( is_wp_error( $error ) ) {
121
+		if (is_wp_error($error)) {
122 122
 			$this->error = $error;
123 123
 
124 124
 			return;
125 125
 		}
126 126
 
127
-		if ( $result ) {
128
-			$payment->set_action_url( $result->redirectUrl );
127
+		if ($result) {
128
+			$payment->set_action_url($result->redirectUrl);
129 129
 		}
130 130
 	}
131 131
 
@@ -134,45 +134,45 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @param Payment $payment Payment.
136 136
 	 */
137
-	public function update_status( Payment $payment ) {
138
-		if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok.
137
+	public function update_status(Payment $payment) {
138
+		if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok.
139 139
 			return;
140 140
 		}
141 141
 
142
-		$parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok.
142
+		$parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok.
143 143
 
144 144
 		// Note.
145 145
 		$note_values = array(
146 146
 			'order_id'  => $parameters->get_order_id(),
147 147
 			'status'    => $parameters->get_status(),
148 148
 			'signature' => $parameters->get_signature(),
149
-			'valid'     => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false',
149
+			'valid'     => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false',
150 150
 		);
151 151
 
152 152
 		$note = '';
153 153
 
154 154
 		$note .= '<p>';
155
-		$note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' );
155
+		$note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal');
156 156
 		$note .= '</p>';
157 157
 
158 158
 		$note .= '<dl>';
159 159
 
160
-		foreach ( $note_values as $key => $value ) {
161
-			$note .= sprintf( '<dt>%s</dt>', esc_html( $key ) );
162
-			$note .= sprintf( '<dd>%s</dd>', esc_html( $value ) );
160
+		foreach ($note_values as $key => $value) {
161
+			$note .= sprintf('<dt>%s</dt>', esc_html($key));
162
+			$note .= sprintf('<dd>%s</dd>', esc_html($value));
163 163
 		}
164 164
 
165 165
 		$note .= '</dl>';
166 166
 
167
-		$payment->add_note( $note );
167
+		$payment->add_note($note);
168 168
 
169 169
 		// Validate.
170
-		if ( ! $parameters->is_valid( $this->config->signing_key ) ) {
170
+		if ( ! $parameters->is_valid($this->config->signing_key)) {
171 171
 			return;
172 172
 		}
173 173
 
174 174
 		// Status.
175
-		$payment->set_status( Statuses::transform( $parameters->get_status() ) );
175
+		$payment->set_status(Statuses::transform($parameters->get_status()));
176 176
 	}
177 177
 
178 178
 	/**
@@ -180,14 +180,14 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @param Notification $notification Notification.
182 182
 	 */
183
-	public function handle_notification( Notification $notification ) {
184
-		if ( ! $notification->is_valid( $this->config->signing_key ) ) {
183
+	public function handle_notification(Notification $notification) {
184
+		if ( ! $notification->is_valid($this->config->signing_key)) {
185 185
 			return;
186 186
 		}
187 187
 
188
-		switch ( $notification->get_event_name() ) {
188
+		switch ($notification->get_event_name()) {
189 189
 			case 'merchant.order.status.changed':
190
-				return $this->handle_merchant_order_staus_changed( $notification );
190
+				return $this->handle_merchant_order_staus_changed($notification);
191 191
 		}
192 192
 	}
193 193
 
@@ -196,38 +196,38 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @param Notification $notification Notification.
198 198
 	 */
199
-	private function handle_merchant_order_staus_changed( Notification $notification ) {
199
+	private function handle_merchant_order_staus_changed(Notification $notification) {
200 200
 		do {
201
-			$order_results = $this->client->get_order_results( $notification->get_authentication() );
201
+			$order_results = $this->client->get_order_results($notification->get_authentication());
202 202
 
203
-			if ( ! $order_results->is_valid( $this->config->signing_key ) ) {
203
+			if ( ! $order_results->is_valid($this->config->signing_key)) {
204 204
 				return;
205 205
 			}
206 206
 
207
-			foreach ( $order_results as $order_result ) {
208
-				$payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() );
207
+			foreach ($order_results as $order_result) {
208
+				$payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id());
209 209
 
210
-				if ( empty( $payment ) ) {
210
+				if (empty($payment)) {
211 211
 					continue;
212 212
 				}
213 213
 
214
-				$payment->set_transaction_id( $order_result->get_omnikassa_order_id() );
215
-				$payment->set_status( Statuses::transform( $order_result->get_order_status() ) );
214
+				$payment->set_transaction_id($order_result->get_omnikassa_order_id());
215
+				$payment->set_status(Statuses::transform($order_result->get_order_status()));
216 216
 
217 217
 				// Note.
218 218
 				$note = '';
219 219
 
220 220
 				$note .= '<p>';
221
-				$note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' );
221
+				$note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal');
222 222
 				$note .= '</p>';
223 223
 				$note .= '<pre>';
224
-				$note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT );
224
+				$note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT);
225 225
 				$note .= '</pre>';
226 226
 
227
-				$payment->add_note( $note );
227
+				$payment->add_note($note);
228 228
 
229 229
 				$payment->save();
230 230
 			}
231
-		} while ( $order_results->more_available() );
231
+		} while ($order_results->more_available());
232 232
 	}
233 233
 }
Please login to merge, or discard this patch.
src/WebhookListener.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
 	 * Listen to OmniKassa 2.0 webhook requests.
26 26
 	 */
27 27
 	public static function listen() {
28
-		if ( ! filter_has_var( INPUT_GET, 'omnikassa2_webhook' ) ) {
28
+		if ( ! filter_has_var(INPUT_GET, 'omnikassa2_webhook')) {
29 29
 			return;
30 30
 		}
31 31
 
32
-		$json = file_get_contents( 'php://input' );
32
+		$json = file_get_contents('php://input');
33 33
 
34
-		$notification = Notification::from_json( $json );
34
+		$notification = Notification::from_json($json);
35 35
 
36 36
 		$query = new \WP_Query(
37 37
 			array(
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 			)
48 48
 		);
49 49
 
50
-		foreach ( $query->posts as $post ) {
51
-			$gateway = Plugin::get_gateway( $post->ID );
50
+		foreach ($query->posts as $post) {
51
+			$gateway = Plugin::get_gateway($post->ID);
52 52
 
53
-			$gateway->handle_notification( $notification );
53
+			$gateway->handle_notification($notification);
54 54
 		}
55 55
 	}
56 56
 }
Please login to merge, or discard this patch.