Passed
Push — master ( d38a02...8763a4 )
by Brian
04:29
created
includes/payments/class-getpaid-checkout.php 1 patch
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wp_send_json_error(__('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,33 +146,33 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
163
-
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+		$invoice->set_currency($submission->get_currency());
163
+
164
+		if ($submission->has_shipping()) {
165
+			$invoice->set_shipping($submission->get_shipping());
166 166
 		}
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+		$address_confirmed = $submission->get_field('confirm-address');
169
+		$invoice->set_address_confirmed(!empty($address_confirmed));
170 170
 
171
-		if ( $submission->has_discount_code() ) {
172
-            $invoice->set_discount_code( $submission->get_discount_code() );
171
+		if ($submission->has_discount_code()) {
172
+            $invoice->set_discount_code($submission->get_discount_code());
173 173
 		}
174 174
 
175
-		getpaid_maybe_add_default_address( $invoice );
175
+		getpaid_maybe_add_default_address($invoice);
176 176
 		return $invoice;
177 177
 	}
178 178
 
@@ -185,34 +185,34 @@  discard block
 block discarded – undo
185 185
 		$submission = $this->payment_form_submission;
186 186
 
187 187
 		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
188
+		if ($submission->has_invoice()) {
189 189
 			return $submission->get_invoice()->get_user_id();
190 190
 		}
191 191
 
192 192
 		// (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = get_user_by( 'email', $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = get_user_by('email', $submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
202
-            $user = wpinv_create_user( $submission->get_billing_email(), $name );
199
+        if (empty($user)) {
200
+			$name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing'));
201
+			$name = implode('', array_filter($name));
202
+            $user = wpinv_create_user($submission->get_billing_email(), $name);
203 203
 
204 204
 			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
205
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
206
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
207
+				wp_send_new_user_notifications($user, 'user');
208 208
 			}
209 209
 		}
210 210
 
211
-        if ( is_wp_error( $user ) ) {
212
-            wp_send_json_error( $user->get_error_message() );
211
+        if (is_wp_error($user)) {
212
+            wp_send_json_error($user->get_error_message());
213 213
         }
214 214
 
215
-        if ( is_numeric( $user ) ) {
215
+        if (is_numeric($user)) {
216 216
             return $user;
217 217
 		}
218 218
 
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
 		);
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+		$data = $submission->get_data();
240 240
 
241 241
 		// Loop through the submitted details.
242
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
242
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
243 243
 
244 244
 			// Skip premade fields.
245
-            if ( ! empty( $field['premade'] ) ) {
245
+            if (!empty($field['premade'])) {
246 246
                 continue;
247 247
             }
248 248
 
249 249
 			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
251
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
250
+			if ($field['type'] == 'address') {
251
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+				foreach ($field['fields'] as $address_field) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
255
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) {
256
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
257 257
 					}
258 258
 			}
259 259
 		}
260 260
 
261 261
             // If it is required and not set, abort.
262
-            if ( ! $submission->is_required_field_set( $field ) ) {
263
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
262
+            if (!$submission->is_required_field_set($field)) {
263
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
264 264
             }
265 265
 
266 266
             // Handle misc fields.
267
-            if ( isset( $data[ $field['id'] ] ) ) {
267
+            if (isset($data[$field['id']])) {
268 268
 
269 269
 				// Uploads.
270
-				if ( $field['type'] === 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+				if ($field['type'] === 'file_upload') {
271
+					$max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']);
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
273
+					if (count($data[$field['id']]) > $max_file_num) {
274
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
275 275
 					}
276 276
 
277 277
 					$value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
279
+					foreach ($data[$field['id']] as $url => $name) {
280 280
 						$value[] = sprintf(
281 281
 							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
282
+							esc_url_raw($url),
283
+							esc_html($name)
284 284
 						);
285 285
 					}
286 286
 
287
-					$value = implode( ' | ', $value );
287
+					$value = implode(' | ', $value);
288 288
 
289
-				} elseif ( $field['type'] === 'checkbox' ) {
290
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
289
+				} elseif ($field['type'] === 'checkbox') {
290
+					$value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
291 291
 				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
292
+					$value = wp_kses_post($data[$field['id']]);
293 293
 				}
294 294
 
295 295
                 $label = $field['id'];
296 296
 
297
-                if ( isset( $field['label'] ) ) {
297
+                if (isset($field['label'])) {
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+				if (!empty($field['add_meta'])) {
302
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
303 303
 				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
305 305
 
306 306
             }
307 307
 		}
@@ -317,30 +317,30 @@  discard block
 block discarded – undo
317 317
 	 * @param WPInv_Invoice $invoice
318 318
 	 * @param string $type
319 319
      */
320
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
320
+    public function prepare_address_details($invoice, $type = 'billing') {
321 321
 
322 322
 		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
323
+		$type     = sanitize_key($type);
324 324
 		$address  = array();
325 325
 		$prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
327
+		if (!empty($data[$type])) {
328
+			$address = $data[$type];
329 329
 		}
330 330
 
331 331
 		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
332
+		foreach ($address as $key => $value) {
333
+			$key             = sanitize_key($key);
334
+			$key             = str_replace('wpinv_', '', $key);
335
+			$value           = wpinv_clean($value);
336
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
337 337
 		}
338 338
 
339 339
 		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
340
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
341 341
 
342 342
 		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
343
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
344 344
 
345 345
 	}
346 346
 
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 	 * @return array
351 351
 	 * @param WPInv_Invoice $invoice
352 352
      */
353
-    protected function prepare_billing_info( &$invoice ) {
353
+    protected function prepare_billing_info(&$invoice) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
356 356
 
357 357
 		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
358
+		$invoice->set_props($billing_address);
359 359
 
360 360
 	}
361 361
 
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	 * @return array
366 366
 	 * @param WPInv_Invoice $invoice
367 367
      */
368
-    protected function prepare_shipping_info( $invoice ) {
368
+    protected function prepare_shipping_info($invoice) {
369 369
 
370 370
 		$data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
372
+		if (empty($data['same-shipping-address'])) {
373
+			return $this->prepare_address_details($invoice, 'shipping');
374 374
 		}
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+		return $this->prepare_address_details($invoice, 'billing');
377 377
 
378 378
 	}
379 379
 
@@ -384,41 +384,41 @@  discard block
 block discarded – undo
384 384
 	 * @param array $prepared_payment_form_data
385 385
 	 * @param array $shipping
386 386
 	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
387
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
388 388
 
389 389
 		// Ensure the invoice exists.
390
-        if ( ! $invoice->exists() ) {
391
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
390
+        if (!$invoice->exists()) {
391
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
392 392
         }
393 393
 
394 394
 		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
395
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
396
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
397
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
398
+		if (!empty($prepared_payment_form_data)) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
400
+			if (!empty($prepared_payment_form_data['all'])) {
401
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
402 402
 			}
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
404
+			if (!empty($prepared_payment_form_data['meta'])) {
405
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
406 406
 			}
407 407
 }
408 408
 
409 409
 		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411
-        if ( ! empty( $shipping ) ) {
412
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
410
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
411
+        if (!empty($shipping)) {
412
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
413 413
 		}
414 414
 
415 415
 		// Backwards compatibility.
416
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
416
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
417 417
 
418
-		$this->process_payment( $invoice );
418
+		$this->process_payment($invoice);
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+		wpinv_send_back_to_checkout($invoice);
422 422
 
423 423
 	}
424 424
 
@@ -427,41 +427,41 @@  discard block
 block discarded – undo
427 427
 	 *
428 428
 	 * @param WPInv_Invoice $invoice
429 429
 	 */
430
-	protected function process_payment( $invoice ) {
430
+	protected function process_payment($invoice) {
431 431
 
432 432
 		// Clear any checkout errors.
433 433
 		wpinv_clear_errors();
434 434
 
435 435
 		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
436
+		if ($invoice->is_free()) {
437
+			$this->process_free_payment($invoice);
438 438
 		}
439 439
 
440 440
 		$submission = $this->payment_form_submission;
441 441
 
442 442
 		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
443
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
444 444
 
445 445
 		// Allow the sumission data to be modified before it is sent to the gateway.
446 446
 		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
447
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
448
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
449 449
 
450 450
 		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
451
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
452
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
453 453
 		}
454 454
 
455 455
 		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
456
+		if (wpinv_get_errors()) {
457
+			wpinv_send_back_to_checkout($invoice);
458 458
 		}
459 459
 
460 460
 		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
461
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
462 462
 
463 463
 		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
464
+		wpinv_send_to_gateway($submission_gateway, $invoice);
465 465
 
466 466
 	}
467 467
 
@@ -470,12 +470,12 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @param WPInv_Invoice $invoice
472 472
 	 */
473
-	protected function process_free_payment( $invoice ) {
473
+	protected function process_free_payment($invoice) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
475
+		$invoice->set_gateway('none');
476
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
477 477
 		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
478
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
479 479
 
480 480
 	}
481 481
 
@@ -483,9 +483,9 @@  discard block
 block discarded – undo
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
486
-    public function send_redirect_response( $url ) {
487
-        $url = urlencode( $url );
488
-        wp_send_json_success( $url );
486
+    public function send_redirect_response($url) {
487
+        $url = urlencode($url);
488
+        wp_send_json_success($url);
489 489
     }
490 490
 
491 491
 }
Please login to merge, or discard this patch.
invoicing.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  * @package GetPaid
16 16
  */
17 17
 
18
-defined( 'ABSPATH' ) || exit;
18
+defined('ABSPATH') || exit;
19 19
 
20 20
 // Define constants.
21
-if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
21
+if (!defined('WPINV_PLUGIN_FILE')) {
22
+	define('WPINV_PLUGIN_FILE', __FILE__);
23 23
 }
24 24
 
25
-if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.6.15' );
25
+if (!defined('WPINV_VERSION')) {
26
+	define('WPINV_VERSION', '2.6.15');
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30
-if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
30
+if (!class_exists('WPInv_Plugin', false)) {
31
+	require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  */
40 40
 function getpaid() {
41 41
 
42
-    if ( empty( $GLOBALS['invoicing'] ) ) {
42
+    if (empty($GLOBALS['invoicing'])) {
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
  * @since  2.0.8
53 53
  */
54 54
 function getpaid_deactivation_hook() {
55
-    update_option( 'wpinv_flush_permalinks', 1 );
55
+    update_option('wpinv_flush_permalinks', 1);
56 56
 }
57
-register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' );
57
+register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook');
58 58
 
59 59
 /**
60 60
  * @deprecated
@@ -64,4 +64,4 @@  discard block
 block discarded – undo
64 64
 }
65 65
 
66 66
 // Kickstart the plugin.
67
-add_action( 'plugins_loaded', 'getpaid', -100 );
67
+add_action('plugins_loaded', 'getpaid', -100);
Please login to merge, or discard this patch.