Passed
Push — master ( e43dde...969080 )
by Brian
05:38
created
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -12,179 +12,179 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
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
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
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' ) );
81
-		}
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' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
125
+
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
131
+
132
+        $invoice = $submission->get_invoice();
133 133
 
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' ) );
137
-		}
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' ) );
137
+        }
138 138
 
139
-		return $invoice;
140
-	}
139
+        return $invoice;
140
+    }
141 141
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150 150
 
151
-		$submission = $this->payment_form_submission;
151
+        $submission = $this->payment_form_submission;
152 152
 
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() ) );
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 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field('wpi-gateway') );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field('wpi-gateway') );
162 162
 
163
-		$address_confirmed = $submission->get_field( 'confirm-address' );
164
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
163
+        $address_confirmed = $submission->get_field( 'confirm-address' );
164
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
165 165
 
166
-		if ( $submission->has_discount_code() ) {
166
+        if ( $submission->has_discount_code() ) {
167 167
             $invoice->set_discount_code( $submission->get_discount_code() );
168
-		}
169
-
170
-		getpaid_maybe_add_default_address( $invoice );
171
-		return $invoice;
172
-	}
173
-
174
-	/**
175
-	 * Retrieves the submission's customer.
176
-	 *
177
-	 * @return int The customer id.
178
-	 */
179
-	protected function get_submission_customer() {
180
-		$submission = $this->payment_form_submission;
181
-
182
-		// If this is an existing invoice...
183
-		if ( $submission->has_invoice() ) {
184
-			return $submission->get_invoice()->get_user_id();
185
-		}
186
-
187
-		// (Maybe) create the user.
168
+        }
169
+
170
+        getpaid_maybe_add_default_address( $invoice );
171
+        return $invoice;
172
+    }
173
+
174
+    /**
175
+     * Retrieves the submission's customer.
176
+     *
177
+     * @return int The customer id.
178
+     */
179
+    protected function get_submission_customer() {
180
+        $submission = $this->payment_form_submission;
181
+
182
+        // If this is an existing invoice...
183
+        if ( $submission->has_invoice() ) {
184
+            return $submission->get_invoice()->get_user_id();
185
+        }
186
+
187
+        // (Maybe) create the user.
188 188
         $user = get_current_user_id();
189 189
 
190 190
         if ( empty( $user ) ) {
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
         if ( empty( $user ) ) {
195 195
             $user = wpinv_create_user( $submission->get_billing_email() );
196 196
 
197
-			// (Maybe) send new user notification.
198
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
199
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
200
-				wp_send_new_user_notifications( $user, 'user' );
201
-			}
197
+            // (Maybe) send new user notification.
198
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
199
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
200
+                wp_send_new_user_notifications( $user, 'user' );
201
+            }
202 202
 
203 203
         }
204 204
 
@@ -208,49 +208,49 @@  discard block
 block discarded – undo
208 208
 
209 209
         if ( is_numeric( $user ) ) {
210 210
             return $user;
211
-		}
211
+        }
212 212
 
213
-		return $user->ID;
213
+        return $user->ID;
214 214
 
215
-	}
215
+    }
216 216
 
217
-	/**
217
+    /**
218 218
      * Prepares submission data for saving to the database.
219 219
      *
220
-	 * @return array
220
+     * @return array
221 221
      */
222 222
     public function prepare_submission_data_for_saving() {
223 223
 
224
-		$submission = $this->payment_form_submission;
224
+        $submission = $this->payment_form_submission;
225 225
 
226
-		// Prepared submission details.
226
+        // Prepared submission details.
227 227
         $prepared = array(
228
-			'all'  => array(),
229
-			'meta' => array(),
230
-		);
228
+            'all'  => array(),
229
+            'meta' => array(),
230
+        );
231 231
 
232 232
         // Raw submission details.
233
-		$data     = $submission->get_data();
233
+        $data     = $submission->get_data();
234 234
 
235
-		// Loop through the submitted details.
235
+        // Loop through the submitted details.
236 236
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
237 237
 
238
-			// Skip premade fields.
238
+            // Skip premade fields.
239 239
             if ( ! empty( $field['premade'] ) ) {
240 240
                 continue;
241 241
             }
242 242
 
243
-			// Ensure address is provided.
244
-			if ( $field['type'] == 'address' ) {
243
+            // Ensure address is provided.
244
+            if ( $field['type'] == 'address' ) {
245 245
                 $address_type = 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
246 246
 
247
-				foreach ( $field['fields'] as $address_field ) {
247
+                foreach ( $field['fields'] as $address_field ) {
248 248
 
249
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
250
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
251
-					}
249
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
250
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
251
+                    }
252 252
 
253
-				}
253
+                }
254 254
 
255 255
             }
256 256
 
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
             // Handle misc fields.
263 263
             if ( isset( $data[ $field['id'] ] ) ) {
264 264
 
265
-				if ( $field['type'] == 'checkbox' ) {
266
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
267
-				} else {
268
-					$value = wp_kses_post( $data[ $field['id'] ] );
269
-				}
265
+                if ( $field['type'] == 'checkbox' ) {
266
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
267
+                } else {
268
+                    $value = wp_kses_post( $data[ $field['id'] ] );
269
+                }
270 270
 
271 271
                 $label = $field['id'];
272 272
 
@@ -274,189 +274,189 @@  discard block
 block discarded – undo
274 274
                     $label = $field['label'];
275 275
                 }
276 276
 
277
-				if ( ! empty( $field['add_meta'] ) ) {
278
-					$prepared['meta'][ wpinv_clean( $label ) ] = $value;
279
-				}
280
-				$prepared['all'][ wpinv_clean( $label ) ] = $value;
277
+                if ( ! empty( $field['add_meta'] ) ) {
278
+                    $prepared['meta'][ wpinv_clean( $label ) ] = $value;
279
+                }
280
+                $prepared['all'][ wpinv_clean( $label ) ] = $value;
281 281
 
282 282
             }
283 283
 
284
-		}
284
+        }
285 285
 
286
-		return $prepared;
286
+        return $prepared;
287 287
 
288
-	}
288
+    }
289 289
 
290
-	/**
290
+    /**
291 291
      * Retrieves address details.
292 292
      *
293
-	 * @return array
294
-	 * @param WPInv_Invoice $invoice
295
-	 * @param string $type
293
+     * @return array
294
+     * @param WPInv_Invoice $invoice
295
+     * @param string $type
296 296
      */
297 297
     public function prepare_address_details( $invoice, $type = 'billing' ) {
298 298
 
299
-		$data     = $this->payment_form_submission->get_data();
300
-		$type     = sanitize_key( $type );
301
-		$address  = array();
302
-		$prepared = array();
299
+        $data     = $this->payment_form_submission->get_data();
300
+        $type     = sanitize_key( $type );
301
+        $address  = array();
302
+        $prepared = array();
303 303
 
304
-		if ( ! empty( $data[ $type ] ) ) {
305
-			$address = $data[ $type ];
306
-		}
304
+        if ( ! empty( $data[ $type ] ) ) {
305
+            $address = $data[ $type ];
306
+        }
307 307
 
308
-		// Clean address details.
309
-		foreach ( $address as $key => $value ) {
310
-			$key             = sanitize_key( $key );
311
-			$key             = str_replace( 'wpinv_', '', $key );
312
-			$value           = wpinv_clean( $value );
313
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
314
-		}
308
+        // Clean address details.
309
+        foreach ( $address as $key => $value ) {
310
+            $key             = sanitize_key( $key );
311
+            $key             = str_replace( 'wpinv_', '', $key );
312
+            $value           = wpinv_clean( $value );
313
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
314
+        }
315 315
 
316
-		// Filter address details.
317
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
316
+        // Filter address details.
317
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
318 318
 
319
-		// Remove non-whitelisted values.
320
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
319
+        // Remove non-whitelisted values.
320
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
321 321
 
322
-	}
322
+    }
323 323
 
324
-	/**
324
+    /**
325 325
      * Prepares the billing details.
326 326
      *
327
-	 * @return array
328
-	 * @param WPInv_Invoice $invoice
327
+     * @return array
328
+     * @param WPInv_Invoice $invoice
329 329
      */
330 330
     protected function prepare_billing_info( &$invoice ) {
331 331
 
332
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
332
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
333 333
 
334
-		// Update the invoice with the billing details.
335
-		$invoice->set_props( $billing_address );
334
+        // Update the invoice with the billing details.
335
+        $invoice->set_props( $billing_address );
336 336
 
337
-	}
337
+    }
338 338
 
339
-	/**
339
+    /**
340 340
      * Prepares the shipping details.
341 341
      *
342
-	 * @return array
343
-	 * @param WPInv_Invoice $invoice
342
+     * @return array
343
+     * @param WPInv_Invoice $invoice
344 344
      */
345 345
     protected function prepare_shipping_info( $invoice ) {
346 346
 
347
-		$data = $this->payment_form_submission->get_data();
347
+        $data = $this->payment_form_submission->get_data();
348 348
 
349
-		if ( empty( $data['same-shipping-address'] ) ) {
350
-			return $this->prepare_address_details( $invoice, 'shipping' );
351
-		}
349
+        if ( empty( $data['same-shipping-address'] ) ) {
350
+            return $this->prepare_address_details( $invoice, 'shipping' );
351
+        }
352 352
 
353
-		return $this->prepare_address_details( $invoice, 'billing' );
353
+        return $this->prepare_address_details( $invoice, 'billing' );
354 354
 
355
-	}
355
+    }
356 356
 
357
-	/**
358
-	 * Confirms the submission is valid and send users to the gateway.
359
-	 *
360
-	 * @param WPInv_Invoice $invoice
361
-	 * @param array $prepared_payment_form_data
362
-	 * @param array $shipping
363
-	 */
364
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
357
+    /**
358
+     * Confirms the submission is valid and send users to the gateway.
359
+     *
360
+     * @param WPInv_Invoice $invoice
361
+     * @param array $prepared_payment_form_data
362
+     * @param array $shipping
363
+     */
364
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
365 365
 
366
-		// Ensure the invoice exists.
366
+        // Ensure the invoice exists.
367 367
         if ( ! $invoice->exists() ) {
368 368
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
369 369
         }
370 370
 
371
-		// Save payment form data.
372
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
371
+        // Save payment form data.
372
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
373 373
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
374
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
375
-		if ( ! empty( $prepared_payment_form_data ) ) {
374
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
375
+        if ( ! empty( $prepared_payment_form_data ) ) {
376 376
 
377
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
378
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
379
-			}
377
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
378
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
379
+            }
380 380
 
381
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
382
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
383
-			}
381
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
382
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
383
+            }
384 384
 
385
-		}
385
+        }
386 386
 
387
-		// Save payment form data.
387
+        // Save payment form data.
388 388
         if ( ! empty( $shipping ) ) {
389 389
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
390
-		}
390
+        }
391 391
 
392
-		// Backwards compatibility.
392
+        // Backwards compatibility.
393 393
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
394 394
 
395
-		$this->process_payment( $invoice );
395
+        $this->process_payment( $invoice );
396 396
 
397 397
         // If we are here, there was an error.
398
-		wpinv_send_back_to_checkout( $invoice );
398
+        wpinv_send_back_to_checkout( $invoice );
399 399
 
400
-	}
400
+    }
401 401
 
402
-	/**
403
-	 * Processes the actual payment.
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 */
407
-	protected function process_payment( $invoice ) {
402
+    /**
403
+     * Processes the actual payment.
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     */
407
+    protected function process_payment( $invoice ) {
408 408
 
409
-		// Clear any checkout errors.
410
-		wpinv_clear_errors();
409
+        // Clear any checkout errors.
410
+        wpinv_clear_errors();
411 411
 
412
-		// No need to send free invoices to the gateway.
413
-		if ( $invoice->is_free() ) {
414
-			$this->process_free_payment( $invoice );
415
-		}
412
+        // No need to send free invoices to the gateway.
413
+        if ( $invoice->is_free() ) {
414
+            $this->process_free_payment( $invoice );
415
+        }
416 416
 
417
-		$submission = $this->payment_form_submission;
417
+        $submission = $this->payment_form_submission;
418 418
 
419
-		// Fires before sending to the gateway.
420
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
419
+        // Fires before sending to the gateway.
420
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
421 421
 
422
-		// Allow the sumission data to be modified before it is sent to the gateway.
423
-		$submission_data    = $submission->get_data();
424
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
425
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
422
+        // Allow the sumission data to be modified before it is sent to the gateway.
423
+        $submission_data    = $submission->get_data();
424
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
425
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
426 426
 
427
-		// Validate the currency.
428
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
429
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
430
-		}
427
+        // Validate the currency.
428
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
429
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
430
+        }
431 431
 
432
-		// Check to see if we have any errors.
433
-		if ( wpinv_get_errors() ) {
434
-			wpinv_send_back_to_checkout( $invoice );
435
-		}
432
+        // Check to see if we have any errors.
433
+        if ( wpinv_get_errors() ) {
434
+            wpinv_send_back_to_checkout( $invoice );
435
+        }
436 436
 
437
-		// Send info to the gateway for payment processing
438
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
437
+        // Send info to the gateway for payment processing
438
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
439 439
 
440
-		// Backwards compatibility.
441
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
440
+        // Backwards compatibility.
441
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
442 442
 
443
-	}
443
+    }
444 444
 
445
-	/**
446
-	 * Marks the invoice as paid in case the checkout is free.
447
-	 *
448
-	 * @param WPInv_Invoice $invoice
449
-	 */
450
-	protected function process_free_payment( $invoice ) {
445
+    /**
446
+     * Marks the invoice as paid in case the checkout is free.
447
+     *
448
+     * @param WPInv_Invoice $invoice
449
+     */
450
+    protected function process_free_payment( $invoice ) {
451 451
 
452
-		$invoice->set_gateway( 'none' );
453
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
454
-		$invoice->mark_paid();
455
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
452
+        $invoice->set_gateway( 'none' );
453
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
454
+        $invoice->mark_paid();
455
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
456 456
 
457
-	}
457
+    }
458 458
 
459
-	/**
459
+    /**
460 460
      * Sends a redrect response to payment details.
461 461
      *
462 462
      */
Please login to merge, or discard this patch.