Passed
Push — feature/post-pay ( ce3905...0cdbab )
by Remco
05:03
created
src/Gateway.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -35,23 +35,23 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param Config $config Config.
37 37
 	 */
38
-	public function __construct( Config $config ) {
39
-		parent::__construct( $config );
38
+	public function __construct(Config $config) {
39
+		parent::__construct($config);
40 40
 
41
-		$this->set_method( self::METHOD_HTTP_REDIRECT );
41
+		$this->set_method(self::METHOD_HTTP_REDIRECT);
42 42
 
43 43
 		// Client.
44 44
 		$this->client = new Client();
45 45
 
46 46
 		$url = Client::URL_PRODUCTION;
47 47
 
48
-		if ( self::MODE_TEST === $config->mode ) {
48
+		if (self::MODE_TEST === $config->mode) {
49 49
 			$url = Client::URL_SANDBOX;
50 50
 		}
51 51
 
52
-		$this->client->set_url( $url );
53
-		$this->client->set_refresh_token( $config->refresh_token );
54
-		$this->client->set_signing_key( $config->signing_key );
52
+		$this->client->set_url($url);
53
+		$this->client->set_refresh_token($config->refresh_token);
54
+		$this->client->set_signing_key($config->signing_key);
55 55
 	}
56 56
 
57 57
 	/**
@@ -78,71 +78,71 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param Payment $payment Payment.
80 80
 	 */
81
-	public function start( Payment $payment ) {
81
+	public function start(Payment $payment) {
82 82
 		// Merchant order ID.
83
-		$merchant_order_id = $payment->format_string( $this->config->order_id );
83
+		$merchant_order_id = $payment->format_string($this->config->order_id);
84 84
 
85
-		$payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id );
85
+		$payment->set_meta('omnikassa_2_merchant_order_id', $merchant_order_id);
86 86
 
87 87
 		// New order.
88 88
 		$order = new Order(
89 89
 			$merchant_order_id,
90
-			MoneyTransformer::transform( $payment->get_amount() ),
90
+			MoneyTransformer::transform($payment->get_amount()),
91 91
 			$payment->get_return_url()
92 92
 		);
93 93
 
94 94
 		// Shipping address.
95
-		$order->set_shipping_detail( AddressTransformer::transform( $payment->get_shipping_address() ) );
95
+		$order->set_shipping_detail(AddressTransformer::transform($payment->get_shipping_address()));
96 96
 
97 97
 		// Billing address.
98
-		$order->set_billing_detail( AddressTransformer::transform( $payment->get_billing_address() ) );
98
+		$order->set_billing_detail(AddressTransformer::transform($payment->get_billing_address()));
99 99
 
100 100
 		// Customer information.
101 101
 		$customer = $payment->get_customer();
102 102
 
103
-		if ( null !== $customer ) {
104
-			$order->set_language( $customer->get_language() );
103
+		if (null !== $customer) {
104
+			$order->set_language($customer->get_language());
105 105
 
106 106
 			$customer_information = new CustomerInformation();
107 107
 
108
-			$customer_information->set_email_address( $customer->get_email() );
109
-			$customer_information->set_date_of_birth( $customer->get_birth_date() );
110
-			$customer_information->set_gender( $customer->get_gender() );
111
-			$customer_information->set_telephone_number( $customer->get_phone() );
108
+			$customer_information->set_email_address($customer->get_email());
109
+			$customer_information->set_date_of_birth($customer->get_birth_date());
110
+			$customer_information->set_gender($customer->get_gender());
111
+			$customer_information->set_telephone_number($customer->get_phone());
112 112
 
113
-			$order->set_customer_information( $customer_information );
113
+			$order->set_customer_information($customer_information);
114 114
 		}
115 115
 
116 116
 		// Payment brand.
117
-		$payment_brand = PaymentBrands::transform( $payment->get_method() );
117
+		$payment_brand = PaymentBrands::transform($payment->get_method());
118 118
 
119
-		$order->set_payment_brand( $payment_brand );
119
+		$order->set_payment_brand($payment_brand);
120 120
 
121
-		if ( null !== $payment_brand ) {
121
+		if (null !== $payment_brand) {
122 122
 			// Payment brand force should only be set if payment brand is not empty.
123
-			$order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE );
123
+			$order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE);
124 124
 		}
125 125
 
126 126
 		// Description.
127
-		$order->set_description( $payment->get_description() );
127
+		$order->set_description($payment->get_description());
128 128
 
129 129
 		// Lines.
130
-		if ( null !== $payment->get_lines() ) {
130
+		if (null !== $payment->get_lines()) {
131 131
 			$order_items = $order->new_items();
132 132
 
133
-			foreach ( $payment->get_lines() as $line ) {
133
+			foreach ($payment->get_lines() as $line) {
134 134
 				$item = $order_items->new_item(
135 135
 					$line->get_name(),
136 136
 					$line->get_quantity(),
137
-					MoneyTransformer::transform( $line->get_total_amount() ),
138
-					Category::transform( $line->get_type() )
137
+					MoneyTransformer::transform($line->get_total_amount()),
138
+					Category::transform($line->get_type())
139 139
 				);
140 140
 
141
-				$item->set_id( $line->get_id() );
142
-				$item->set_description( $line->get_description() );
141
+				$item->set_id($line->get_id());
142
+				$item->set_description($line->get_description());
143 143
 
144
-				if ( null != $line->get_tax_amount() ) {
145
-					$item->set_tax( MoneyTransformer::transform( $line->get_tax_amount() ) );
144
+				if (null != $line->get_tax_amount()) {
145
+					$item->set_tax(MoneyTransformer::transform($line->get_tax_amount()));
146 146
 				}
147 147
 			}
148 148
 		}
@@ -151,20 +151,20 @@  discard block
 block discarded – undo
151 151
 		$this->maybe_update_access_token();
152 152
 
153 153
 		// Handle errors.
154
-		if ( $this->get_client_error() ) {
154
+		if ($this->get_client_error()) {
155 155
 			return;
156 156
 		}
157 157
 
158 158
 		// Announce order.
159
-		$result = $this->client->order_announce( $this->config, $order );
159
+		$result = $this->client->order_announce($this->config, $order);
160 160
 
161 161
 		// Handle errors.
162
-		if ( $this->get_client_error() ) {
162
+		if ($this->get_client_error()) {
163 163
 			return;
164 164
 		}
165 165
 
166
-		if ( $result ) {
167
-			$payment->set_action_url( $result->redirectUrl );
166
+		if ($result) {
167
+			$payment->set_action_url($result->redirectUrl);
168 168
 		}
169 169
 	}
170 170
 
@@ -173,45 +173,45 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @param Payment $payment Payment.
175 175
 	 */
176
-	public function update_status( Payment $payment ) {
177
-		if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok.
176
+	public function update_status(Payment $payment) {
177
+		if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok.
178 178
 			return;
179 179
 		}
180 180
 
181
-		$parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok.
181
+		$parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok.
182 182
 
183 183
 		// Note.
184 184
 		$note_values = array(
185 185
 			'order_id'  => $parameters->get_order_id(),
186 186
 			'status'    => $parameters->get_status(),
187 187
 			'signature' => $parameters->get_signature(),
188
-			'valid'     => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false',
188
+			'valid'     => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false',
189 189
 		);
190 190
 
191 191
 		$note = '';
192 192
 
193 193
 		$note .= '<p>';
194
-		$note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' );
194
+		$note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal');
195 195
 		$note .= '</p>';
196 196
 
197 197
 		$note .= '<dl>';
198 198
 
199
-		foreach ( $note_values as $key => $value ) {
200
-			$note .= sprintf( '<dt>%s</dt>', esc_html( $key ) );
201
-			$note .= sprintf( '<dd>%s</dd>', esc_html( $value ) );
199
+		foreach ($note_values as $key => $value) {
200
+			$note .= sprintf('<dt>%s</dt>', esc_html($key));
201
+			$note .= sprintf('<dd>%s</dd>', esc_html($value));
202 202
 		}
203 203
 
204 204
 		$note .= '</dl>';
205 205
 
206
-		$payment->add_note( $note );
206
+		$payment->add_note($note);
207 207
 
208 208
 		// Validate.
209
-		if ( ! $parameters->is_valid( $this->config->signing_key ) ) {
209
+		if ( ! $parameters->is_valid($this->config->signing_key)) {
210 210
 			return;
211 211
 		}
212 212
 
213 213
 		// Status.
214
-		$payment->set_status( Statuses::transform( $parameters->get_status() ) );
214
+		$payment->set_status(Statuses::transform($parameters->get_status()));
215 215
 	}
216 216
 
217 217
 	/**
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 	 *
222 222
 	 * @return void
223 223
 	 */
224
-	public function handle_notification( Notification $notification ) {
225
-		if ( ! $notification->is_valid( $this->config->signing_key ) ) {
224
+	public function handle_notification(Notification $notification) {
225
+		if ( ! $notification->is_valid($this->config->signing_key)) {
226 226
 			return;
227 227
 		}
228 228
 
229
-		switch ( $notification->get_event_name() ) {
229
+		switch ($notification->get_event_name()) {
230 230
 			case 'merchant.order.status.changed':
231
-				$this->handle_merchant_order_status_changed( $notification );
231
+				$this->handle_merchant_order_status_changed($notification);
232 232
 		}
233 233
 	}
234 234
 
@@ -239,39 +239,39 @@  discard block
 block discarded – undo
239 239
 	 *
240 240
 	 * @return void
241 241
 	 */
242
-	private function handle_merchant_order_status_changed( Notification $notification ) {
242
+	private function handle_merchant_order_status_changed(Notification $notification) {
243 243
 		do {
244
-			$order_results = $this->client->get_order_results( $notification->get_authentication() );
244
+			$order_results = $this->client->get_order_results($notification->get_authentication());
245 245
 
246
-			if ( ! $order_results || $order_results->is_valid( $this->config->signing_key ) ) {
246
+			if ( ! $order_results || $order_results->is_valid($this->config->signing_key)) {
247 247
 				return;
248 248
 			}
249 249
 
250
-			foreach ( $order_results as $order_result ) {
251
-				$payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() );
250
+			foreach ($order_results as $order_result) {
251
+				$payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id());
252 252
 
253
-				if ( empty( $payment ) ) {
253
+				if (empty($payment)) {
254 254
 					continue;
255 255
 				}
256 256
 
257
-				$payment->set_transaction_id( $order_result->get_omnikassa_order_id() );
258
-				$payment->set_status( Statuses::transform( $order_result->get_order_status() ) );
257
+				$payment->set_transaction_id($order_result->get_omnikassa_order_id());
258
+				$payment->set_status(Statuses::transform($order_result->get_order_status()));
259 259
 
260 260
 				// Note.
261 261
 				$note = '';
262 262
 
263 263
 				$note .= '<p>';
264
-				$note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' );
264
+				$note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal');
265 265
 				$note .= '</p>';
266 266
 				$note .= '<pre>';
267
-				$note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT );
267
+				$note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT);
268 268
 				$note .= '</pre>';
269 269
 
270
-				$payment->add_note( $note );
270
+				$payment->add_note($note);
271 271
 
272 272
 				$payment->save();
273 273
 			}
274
-		} while ( $order_results->more_available() );
274
+		} while ($order_results->more_available());
275 275
 	}
276 276
 
277 277
 	/**
@@ -280,20 +280,20 @@  discard block
 block discarded – undo
280 280
 	 * @return void
281 281
 	 */
282 282
 	private function maybe_update_access_token() {
283
-		if ( $this->config->is_access_token_valid() ) {
283
+		if ($this->config->is_access_token_valid()) {
284 284
 			return;
285 285
 		}
286 286
 
287 287
 		$data = $this->client->get_access_token_data();
288 288
 
289
-		if ( ! is_object( $data ) ) {
289
+		if ( ! is_object($data)) {
290 290
 			return;
291 291
 		}
292 292
 
293 293
 		$this->config->access_token             = $data->token;
294 294
 		$this->config->access_token_valid_until = $data->validUntil;
295 295
 
296
-		update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token );
296
+		update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token);
297 297
 		update_post_meta(
298 298
 			$this->config->post_id,
299 299
 			'_pronamic_gateway_omnikassa_2_access_token_valid_until',
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	private function get_client_error() {
310 310
 		$error = $this->client->get_error();
311 311
 
312
-		if ( is_wp_error( $error ) ) {
312
+		if (is_wp_error($error)) {
313 313
 			$this->error = $error;
314 314
 
315 315
 			return $error;
Please login to merge, or discard this patch.