Passed
Push — master ( 12e336...bef24b )
by Brian
04:19
created
widgets/getpaid.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -36,36 +36,36 @@  discard block
 block discarded – undo
36 36
                     'desc_tip'    => true,
37 37
                     'default'     => '',
38 38
                     'advanced'    => false
39
-				),
39
+                ),
40 40
 
41 41
                 'form'  => array(
42
-	                'title'       => __( 'Form', 'invoicing' ),
43
-	                'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
44
-	                'type'        => 'text',
45
-	                'desc_tip'    => true,
46
-	                'default'     => '',
47
-	                'placeholder' => __('1','invoicing'),
48
-	                'advanced'    => false
49
-				),
50
-
51
-				'item'  => array(
52
-	                'title'       => __( 'Items', 'invoicing' ),
53
-	                'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
54
-	                'type'        => 'text',
55
-	                'desc_tip'    => true,
56
-	                'default'     => '',
57
-	                'placeholder' => __('1','invoicing'),
58
-	                'advanced'    => false
59
-				),
42
+                    'title'       => __( 'Form', 'invoicing' ),
43
+                    'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
44
+                    'type'        => 'text',
45
+                    'desc_tip'    => true,
46
+                    'default'     => '',
47
+                    'placeholder' => __('1','invoicing'),
48
+                    'advanced'    => false
49
+                ),
50
+
51
+                'item'  => array(
52
+                    'title'       => __( 'Items', 'invoicing' ),
53
+                    'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
54
+                    'type'        => 'text',
55
+                    'desc_tip'    => true,
56
+                    'default'     => '',
57
+                    'placeholder' => __('1','invoicing'),
58
+                    'advanced'    => false
59
+                ),
60 60
 
61 61
                 'button'  => array(
62
-	                'title'       => __( 'Button', 'invoicing' ),
63
-	                'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
64
-	                'type'        => 'text',
65
-	                'desc_tip'    => true,
66
-	                'default'     => '',
67
-	                'advanced'    => false
68
-				)
62
+                    'title'       => __( 'Button', 'invoicing' ),
63
+                    'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
64
+                    'type'        => 'text',
65
+                    'desc_tip'    => true,
66
+                    'default'     => '',
67
+                    'advanced'    => false
68
+                )
69 69
 
70 70
             )
71 71
 
@@ -75,96 +75,96 @@  discard block
 block discarded – undo
75 75
         parent::__construct( $options );
76 76
     }
77 77
 
78
-	/**
79
-	 * The Super block output function.
80
-	 *
81
-	 * @param array $args
82
-	 * @param array $widget_args
83
-	 * @param string $content
84
-	 *
85
-	 * @return string
86
-	 */
78
+    /**
79
+     * The Super block output function.
80
+     *
81
+     * @param array $args
82
+     * @param array $widget_args
83
+     * @param string $content
84
+     *
85
+     * @return string
86
+     */
87 87
     public function output( $args = array(), $widget_args = array(), $content = '' ) {
88 88
 
89
-	    // Is the shortcode set up correctly?
90
-		if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
91
-			return aui()->alert(
92
-				array(
93
-					'type'    => 'warning',
94
-					'content' => __( 'No payment form or item selected', 'invoicing' ),
95
-				)
96
-			);
97
-		}
98
-
99
-		// Payment form or button?
100
-		if ( ! empty( $args['form'] ) ) {
101
-			return $this->handle_payment_form(  $args );
102
-		} else {
103
-			return $this->handle_buy_item(  $args );
104
-		}
105
-
106
-	}
107
-
108
-	/**
109
-	 * Displaying a payment form
110
-	 *
111
-	 * @return string
112
-	 */
89
+        // Is the shortcode set up correctly?
90
+        if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
91
+            return aui()->alert(
92
+                array(
93
+                    'type'    => 'warning',
94
+                    'content' => __( 'No payment form or item selected', 'invoicing' ),
95
+                )
96
+            );
97
+        }
98
+
99
+        // Payment form or button?
100
+        if ( ! empty( $args['form'] ) ) {
101
+            return $this->handle_payment_form(  $args );
102
+        } else {
103
+            return $this->handle_buy_item(  $args );
104
+        }
105
+
106
+    }
107
+
108
+    /**
109
+     * Displaying a payment form
110
+     *
111
+     * @return string
112
+     */
113 113
     protected function handle_payment_form( $args = array() ) {
114 114
 
115
-		if ( empty( $args['button'] ) ) {
116
-			ob_start();
117
-			getpaid_display_payment_form( $args['form'] );
118
-			return ob_get_clean();
119
-		}
115
+        if ( empty( $args['button'] ) ) {
116
+            ob_start();
117
+            getpaid_display_payment_form( $args['form'] );
118
+            return ob_get_clean();
119
+        }
120 120
 
121
-		return $this->payment_form_button( $args['form'], $args['button'] );
122
-	}
121
+        return $this->payment_form_button( $args['form'], $args['button'] );
122
+    }
123 123
 
124
-	/**
125
-	 * Displays a payment form button.
126
-	 *
127
-	 * @return string
128
-	 */
124
+    /**
125
+     * Displays a payment form button.
126
+     *
127
+     * @return string
128
+     */
129 129
     protected function payment_form_button( $form, $button ) {
130
-		return getpaid_get_payment_button( $button, $form );
131
-	}
132
-
133
-	/**
134
-	 * Selling an item
135
-	 *
136
-	 * @return string
137
-	 */
130
+        return getpaid_get_payment_button( $button, $form );
131
+    }
132
+
133
+    /**
134
+     * Selling an item
135
+     *
136
+     * @return string
137
+     */
138 138
     protected function handle_buy_item( $args = array() ) {
139 139
 
140
-		if ( empty( $args['button'] ) ) {
141
-			return $this->buy_item_form( $args['item'] );
142
-		}
140
+        if ( empty( $args['button'] ) ) {
141
+            return $this->buy_item_form( $args['item'] );
142
+        }
143 143
 
144
-		return $this->buy_item_button( $args['item'], $args['button'] );
144
+        return $this->buy_item_button( $args['item'], $args['button'] );
145 145
 
146
-	}
146
+    }
147 147
 
148
-	/**
149
-	 * Displays a buy item form.
150
-	 *
151
-	 * @return string
152
-	 */
148
+    /**
149
+     * Displays a buy item form.
150
+     *
151
+     * @return string
152
+     */
153 153
     protected function buy_item_form( $item ) {
154
-		$items = getpaid_convert_items_to_array( $item );
155
-		ob_start();
156
-		getpaid_display_item_payment_form( $items );
157
-		return ob_get_clean();
158
-	}
159
-
160
-	/**
161
-	 * Displays a buy item button.
162
-	 *
163
-	 * @return string
164
-	 */
154
+        $items = getpaid_convert_items_to_array( $item );
155
+        ob_start();
156
+        getpaid_display_item_payment_form( $items );
157
+        return ob_get_clean();
158
+    }
159
+
160
+    /**
161
+     * Displays a buy item button.
162
+     *
163
+     * @return string
164
+     */
165 165
     protected function buy_item_button( $item, $button ) {
166
-		$button = getpaid_get_payment_button( $button, null, $item );
167
-		return apply_filters( 'getpaid_buy_item_button_widget', $button, $item );
166
+        $button = getpaid_get_payment_button( $button, null, $item );
167
+        return apply_filters( 'getpaid_buy_item_button_widget', $button, $item );
168 168
     }
169 169
 
170 170
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 4;
35 35
 
36 36
     /**
37
-	 * Endpoint for requests from Authorize.net.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	protected $notify_url;
42
-
43
-	/**
44
-	 * Endpoint for requests to Authorize.net.
45
-	 *
46
-	 * @var string
47
-	 */
37
+     * Endpoint for requests from Authorize.net.
38
+     *
39
+     * @var string
40
+     */
41
+    protected $notify_url;
42
+
43
+    /**
44
+     * Endpoint for requests to Authorize.net.
45
+     *
46
+     * @var string
47
+     */
48 48
     protected $endpoint;
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
63 63
 
64 64
     /**
65
-	 * Class constructor.
66
-	 */
67
-	public function __construct() {
65
+     * Class constructor.
66
+     */
67
+    public function __construct() {
68 68
 
69 69
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70 70
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-	 * Displays the payment method select field.
80
-	 *
81
-	 * @param int $invoice_id 0 or invoice id.
82
-	 * @param GetPaid_Payment_Form $form Current payment form.
83
-	 */
79
+     * Displays the payment method select field.
80
+     *
81
+     * @param int $invoice_id 0 or invoice id.
82
+     * @param GetPaid_Payment_Form $form Current payment form.
83
+     */
84 84
     public function payment_fields( $invoice_id, $form ) {
85 85
 
86 86
         // Let the user select a payment method.
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * Creates a customer profile.
95
-	 *
96
-	 *
97
-	 * @param WPInv_Invoice $invoice Invoice.
94
+     * Creates a customer profile.
95
+     *
96
+     *
97
+     * @param WPInv_Invoice $invoice Invoice.
98 98
      * @param array $submission_data Posted checkout fields.
99 99
      * @param bool $save Whether or not to save the payment as a token.
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101
-	 * @return string|WP_Error Payment profile id.
102
-	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
101
+     * @return string|WP_Error Payment profile id.
102
+     */
103
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
104 104
 
105 105
         // Remove non-digits from the number
106 106
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Retrieves a customer profile.
171
-	 *
172
-	 *
173
-	 * @param string $profile_id profile id.
174
-	 * @return string|WP_Error Profile id.
170
+     * Retrieves a customer profile.
171
+     *
172
+     *
173
+     * @param string $profile_id profile id.
174
+     * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176
-	 */
177
-	public function get_customer_profile( $profile_id ) {
176
+     */
177
+    public function get_customer_profile( $profile_id ) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-	 * Creates a customer profile.
193
-	 *
194
-	 *
192
+     * Creates a customer profile.
193
+     *
194
+     *
195 195
      * @param string $profile_id profile id.
196
-	 * @param WPInv_Invoice $invoice Invoice.
196
+     * @param WPInv_Invoice $invoice Invoice.
197 197
      * @param array $submission_data Posted checkout fields.
198 198
      * @param bool $save Whether or not to save the payment as a token.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200
-	 * @return string|WP_Error Profile id.
201
-	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
200
+     * @return string|WP_Error Profile id.
201
+     */
202
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
203 203
 
204 204
         // Remove non-digits from the number
205 205
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -259,15 +259,15 @@  discard block
 block discarded – undo
259 259
     }
260 260
 
261 261
     /**
262
-	 * Retrieves a customer payment profile.
263
-	 *
264
-	 *
265
-	 * @param string $customer_profile_id customer profile id.
262
+     * Retrieves a customer payment profile.
263
+     *
264
+     *
265
+     * @param string $customer_profile_id customer profile id.
266 266
      * @param string $payment_profile_id payment profile id.
267
-	 * @return string|WP_Error Profile id.
267
+     * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269
-	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
269
+     */
270
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -283,15 +283,15 @@  discard block
 block discarded – undo
283 283
     }
284 284
 
285 285
     /**
286
-	 * Charges a customer payment profile.
287
-	 *
286
+     * Charges a customer payment profile.
287
+     *
288 288
      * @param string $customer_profile_id customer profile id.
289 289
      * @param string $payment_profile_id payment profile id.
290
-	 * @param WPInv_Invoice $invoice Invoice.
290
+     * @param WPInv_Invoice $invoice Invoice.
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292
-	 * @return WP_Error|object
293
-	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
292
+     * @return WP_Error|object
293
+     */
294
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -337,41 +337,41 @@  discard block
 block discarded – undo
337 337
     }
338 338
 
339 339
     /**
340
-	 * Processes a customer charge.
341
-	 *
340
+     * Processes a customer charge.
341
+     *
342 342
      * @param stdClass $result Api response.
343
-	 * @param WPInv_Invoice $invoice Invoice.
344
-	 */
345
-	public function process_charge_response( $result, $invoice ) {
343
+     * @param WPInv_Invoice $invoice Invoice.
344
+     */
345
+    public function process_charge_response( $result, $invoice ) {
346 346
 
347 347
         wpinv_clear_errors();
348
-		$response_code = (int) $result->transactionResponse->responseCode;
348
+        $response_code = (int) $result->transactionResponse->responseCode;
349 349
 
350
-		// Succeeded.
351
-		if ( 1 == $response_code || 4 == $response_code ) {
350
+        // Succeeded.
351
+        if ( 1 == $response_code || 4 == $response_code ) {
352 352
 
353
-			// Maybe set a transaction id.
354
-			if ( ! empty( $result->transactionResponse->transId ) ) {
355
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
356
-			}
353
+            // Maybe set a transaction id.
354
+            if ( ! empty( $result->transactionResponse->transId ) ) {
355
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
356
+            }
357 357
 
358
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
358
+            $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
359 359
 
360
-			if ( 1 == $response_code ) {
361
-				return $invoice->mark_paid();
362
-			}
360
+            if ( 1 == $response_code ) {
361
+                return $invoice->mark_paid();
362
+            }
363 363
 
364
-			$invoice->set_status( 'wpi-onhold' );
365
-        	$invoice->add_note(
364
+            $invoice->set_status( 'wpi-onhold' );
365
+            $invoice->add_note(
366 366
                 sprintf(
367 367
                     __( 'Held for review: %s', 'invoicing' ),
368 368
                     $result->transactionResponse->messages->message[0]->description
369 369
                 )
370
-			);
370
+            );
371 371
 
372
-			return $invoice->save();
372
+            return $invoice->save();
373 373
 
374
-		}
374
+        }
375 375
 
376 376
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
377 377
 
@@ -383,13 +383,13 @@  discard block
 block discarded – undo
383 383
     }
384 384
 
385 385
     /**
386
-	 * Returns payment information.
387
-	 *
388
-	 *
389
-	 * @param array $card Card details.
390
-	 * @return array
391
-	 */
392
-	public function get_payment_information( $card ) {
386
+     * Returns payment information.
387
+     *
388
+     *
389
+     * @param array $card Card details.
390
+     * @return array
391
+     */
392
+    public function get_payment_information( $card ) {
393 393
         return array(
394 394
 
395 395
             'creditCard'         => array (
@@ -402,25 +402,25 @@  discard block
 block discarded – undo
402 402
     }
403 403
 
404 404
     /**
405
-	 * Returns the customer profile meta name.
406
-	 *
407
-	 *
408
-	 * @param WPInv_Invoice $invoice Invoice.
409
-	 * @return string
410
-	 */
411
-	public function get_customer_profile_meta_name( $invoice ) {
405
+     * Returns the customer profile meta name.
406
+     *
407
+     *
408
+     * @param WPInv_Invoice $invoice Invoice.
409
+     * @return string
410
+     */
411
+    public function get_customer_profile_meta_name( $invoice ) {
412 412
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
413 413
     }
414 414
 
415 415
     /**
416
-	 * Validates the submitted data.
417
-	 *
418
-	 *
419
-	 * @param array $submission_data Posted checkout fields.
416
+     * Validates the submitted data.
417
+     *
418
+     *
419
+     * @param array $submission_data Posted checkout fields.
420 420
      * @param WPInv_Invoice $invoice
421
-	 * @return WP_Error|string The payment profile id
422
-	 */
423
-	public function validate_submission_data( $submission_data, $invoice ) {
421
+     * @return WP_Error|string The payment profile id
422
+     */
423
+    public function validate_submission_data( $submission_data, $invoice ) {
424 424
 
425 425
         // Validate authentication details.
426 426
         $auth = $this->get_auth_params();
@@ -452,13 +452,13 @@  discard block
 block discarded – undo
452 452
     }
453 453
 
454 454
     /**
455
-	 * Returns invoice line items.
456
-	 *
457
-	 *
458
-	 * @param WPInv_Invoice $invoice Invoice.
459
-	 * @return array
460
-	 */
461
-	public function get_line_items( $invoice ) {
455
+     * Returns invoice line items.
456
+     *
457
+     *
458
+     * @param WPInv_Invoice $invoice Invoice.
459
+     * @return array
460
+     */
461
+    public function get_line_items( $invoice ) {
462 462
         $items = array();
463 463
 
464 464
         foreach ( $invoice->get_items() as $item ) {
@@ -496,15 +496,15 @@  discard block
 block discarded – undo
496 496
     }
497 497
 
498 498
     /**
499
-	 * Process Payment.
500
-	 *
501
-	 *
502
-	 * @param WPInv_Invoice $invoice Invoice.
503
-	 * @param array $submission_data Posted checkout fields.
504
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505
-	 * @return array
506
-	 */
507
-	public function process_payment( $invoice, $submission_data, $submission ) {
499
+     * Process Payment.
500
+     *
501
+     *
502
+     * @param WPInv_Invoice $invoice Invoice.
503
+     * @param array $submission_data Posted checkout fields.
504
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505
+     * @return array
506
+     */
507
+    public function process_payment( $invoice, $submission_data, $submission ) {
508 508
 
509 509
         // Validate the submitted data.
510 510
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -537,69 +537,69 @@  discard block
 block discarded – undo
537 537
 
538 538
         exit;
539 539
 
540
-	}
540
+    }
541 541
 	
542
-	/**
543
-	 * Processes the initial payment.
544
-	 *
542
+    /**
543
+     * Processes the initial payment.
544
+     *
545 545
      * @param WPInv_Invoice $invoice Invoice.
546
-	 */
547
-	protected function process_initial_payment( $invoice ) {
546
+     */
547
+    protected function process_initial_payment( $invoice ) {
548 548
 
549
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
549
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
550 550
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
551
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
551
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
552 552
 
553
-		// Do we have an error?
554
-		if ( is_wp_error( $result ) ) {
555
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
556
-			wpinv_send_back_to_checkout( $invoice );
557
-		}
553
+        // Do we have an error?
554
+        if ( is_wp_error( $result ) ) {
555
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
556
+            wpinv_send_back_to_checkout( $invoice );
557
+        }
558 558
 
559
-		// Process the response.
560
-		$this->process_charge_response( $result, $invoice );
559
+        // Process the response.
560
+        $this->process_charge_response( $result, $invoice );
561 561
 
562
-		if ( wpinv_get_errors() ) {
563
-			wpinv_send_back_to_checkout( $invoice );
564
-		}
562
+        if ( wpinv_get_errors() ) {
563
+            wpinv_send_back_to_checkout( $invoice );
564
+        }
565 565
 
566
-	}
566
+    }
567 567
 
568 568
     /**
569
-	 * Processes recurring payments.
570
-	 *
569
+     * Processes recurring payments.
570
+     *
571 571
      * @param WPInv_Invoice $invoice Invoice.
572 572
      * @param WPInv_Subscription $subscription Subscription.
573
-	 */
574
-	public function process_subscription( $invoice, $subscription ) {
573
+     */
574
+    public function process_subscription( $invoice, $subscription ) {
575 575
 
576 576
         // Check if there is an initial amount to charge.
577 577
         if ( (float) $invoice->get_total() > 0 ) {
578
-			$this->process_initial_payment( $invoice );
578
+            $this->process_initial_payment( $invoice );
579 579
         }
580 580
 
581 581
         // Activate the subscription.
582 582
         $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
583 583
         $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
584 584
 
585
-		$subscription->set_next_renewal_date( $expiry );
586
-		$subscription->set_date_created( current_time( 'mysql' ) );
587
-		$subscription->set_profile_id( $invoice->generate_key() );
588
-		$subscription->activate();
585
+        $subscription->set_next_renewal_date( $expiry );
586
+        $subscription->set_date_created( current_time( 'mysql' ) );
587
+        $subscription->set_profile_id( $invoice->generate_key() );
588
+        $subscription->activate();
589 589
 
590
-		// Redirect to the success page.
590
+        // Redirect to the success page.
591 591
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
592 592
 
593 593
     }
594 594
 
595
-	/**
596
-	 * (Maybe) renews an authorize.net subscription profile.
597
-	 *
598
-	 *
599
-	 * @param bool $should_expire
595
+    /**
596
+     * (Maybe) renews an authorize.net subscription profile.
597
+     *
598
+     *
599
+     * @param bool $should_expire
600 600
      * @param WPInv_Subscription $subscription
601
-	 */
602
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
601
+     */
602
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
603 603
 
604 604
         // Ensure its our subscription && it's active.
605 605
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -616,18 +616,18 @@  discard block
 block discarded – undo
616 616
 
617 617
         return false;
618 618
 
619
-	}
619
+    }
620 620
 
621 621
     /**
622
-	 * Renews a subscription.
623
-	 *
622
+     * Renews a subscription.
623
+     *
624 624
      * @param WPInv_Subscription $subscription
625
-	 */
626
-	public function renew_subscription( $subscription ) {
625
+     */
626
+    public function renew_subscription( $subscription ) {
627 627
 
628
-		// Generate the renewal invoice.
629
-		$new_invoice = $subscription->create_payment();
630
-		$old_invoice = $subscription->get_parent_payment();
628
+        // Generate the renewal invoice.
629
+        $new_invoice = $subscription->create_payment();
630
+        $old_invoice = $subscription->get_parent_payment();
631 631
 
632 632
         if ( empty( $new_invoice ) ) {
633 633
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -636,37 +636,37 @@  discard block
 block discarded – undo
636 636
         }
637 637
 
638 638
         // Charge the payment method.
639
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
642
-
643
-		// Do we have an error?
644
-		if ( is_wp_error( $result ) ) {
645
-
646
-			$old_invoice->add_note(
647
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
648
-				true,
649
-				false,
650
-				true
651
-			);
652
-			$subscription->failing();
653
-			return;
654
-
655
-		}
656
-
657
-		// Process the response.
658
-		$this->process_charge_response( $result, $new_invoice );
659
-
660
-		if ( wpinv_get_errors() ) {
661
-
662
-			$old_invoice->add_note(
663
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
664
-				true,
665
-				false,
666
-				true
667
-			);
668
-			$subscription->failing();
669
-			return;
639
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
642
+
643
+        // Do we have an error?
644
+        if ( is_wp_error( $result ) ) {
645
+
646
+            $old_invoice->add_note(
647
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
648
+                true,
649
+                false,
650
+                true
651
+            );
652
+            $subscription->failing();
653
+            return;
654
+
655
+        }
656
+
657
+        // Process the response.
658
+        $this->process_charge_response( $result, $new_invoice );
659
+
660
+        if ( wpinv_get_errors() ) {
661
+
662
+            $old_invoice->add_note(
663
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
664
+                true,
665
+                false,
666
+                true
667
+            );
668
+            $subscription->failing();
669
+            return;
670 670
 
671 671
         }
672 672
 
@@ -675,13 +675,13 @@  discard block
 block discarded – undo
675 675
     }
676 676
 
677 677
     /**
678
-	 * Processes invoice addons.
679
-	 *
680
-	 * @param WPInv_Invoice $invoice
681
-	 * @param GetPaid_Form_Item[] $items
682
-	 * @return WPInv_Invoice
683
-	 */
684
-	public function process_addons( $invoice, $items ) {
678
+     * Processes invoice addons.
679
+     *
680
+     * @param WPInv_Invoice $invoice
681
+     * @param GetPaid_Form_Item[] $items
682
+     * @return WPInv_Invoice
683
+     */
684
+    public function process_addons( $invoice, $items ) {
685 685
 
686 686
         global $getpaid_authorize_addons;
687 687
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
         $invoice->recalculate_total();
702 702
 
703 703
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
704
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
704
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
705 705
 
706 706
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
707 707
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -716,11 +716,11 @@  discard block
 block discarded – undo
716 716
     }
717 717
 
718 718
     /**
719
-	 * Processes invoice addons.
720
-	 *
719
+     * Processes invoice addons.
720
+     *
721 721
      * @param array $args
722
-	 * @return array
723
-	 */
722
+     * @return array
723
+     */
724 724
     public function filter_addons_request( $args ) {
725 725
 
726 726
         global $getpaid_authorize_addons;
@@ -754,11 +754,11 @@  discard block
 block discarded – undo
754 754
     }
755 755
 
756 756
     /**
757
-	 * Filters the gateway settings.
758
-	 *
759
-	 * @param array $admin_settings
760
-	 */
761
-	public function admin_settings( $admin_settings ) {
757
+     * Filters the gateway settings.
758
+     *
759
+     * @param array $admin_settings
760
+     */
761
+    public function admin_settings( $admin_settings ) {
762 762
 
763 763
         $currencies = sprintf(
764 764
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
             'readonly' => true,
799 799
         );
800 800
 
801
-		return $admin_settings;
802
-	}
801
+        return $admin_settings;
802
+    }
803 803
 
804 804
 }
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@
 block discarded – undo
235 235
         do_action( 'getpaid_checkout_invoice_exception', $invoice );
236 236
     }
237 237
 
238
-	// Do we have any errors?
238
+    // Do we have any errors?
239 239
     if ( wpinv_get_errors() ) {
240 240
         wp_send_json_error( getpaid_get_errors_html( true, false ) );
241 241
     }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -12,176 +12,176 @@  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->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->recalculate_total();
50 50
         $invoice->save();
51 51
 
52
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
52
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
53 53
 
54
-		// Send to the gateway.
55
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
-	}
54
+        // Send to the gateway.
55
+        $this->post_process_submission( $invoice, $prepared, $shipping );
56
+    }
57 57
 
58
-	/**
59
-	 * Validates the submission.
60
-	 *
61
-	 */
62
-	protected function validate_submission() {
58
+    /**
59
+     * Validates the submission.
60
+     *
61
+     */
62
+    protected function validate_submission() {
63 63
 
64
-		$submission = $this->payment_form_submission;
65
-		$data       = $submission->get_data();
64
+        $submission = $this->payment_form_submission;
65
+        $data       = $submission->get_data();
66 66
 
67
-		// Do we have an error?
67
+        // Do we have an error?
68 68
         if ( ! empty( $submission->last_error ) ) {
69
-			wp_send_json_error( $submission->last_error );
69
+            wp_send_json_error( $submission->last_error );
70 70
         }
71 71
 
72
-		// We need a billing email.
72
+        // We need a billing email.
73 73
         if ( ! $submission->has_billing_email() ) {
74 74
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
75
-		}
75
+        }
76 76
 
77
-		// Non-recurring gateways should not be allowed to process recurring invoices.
78
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
79
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
80
-		}
77
+        // Non-recurring gateways should not be allowed to process recurring invoices.
78
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
79
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
80
+        }
81 81
 
82
-		// Ensure the gateway is active.
83
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
84
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
85
-		}
82
+        // Ensure the gateway is active.
83
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
84
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
85
+        }
86 86
 
87
-		// Clear any existing errors.
88
-		wpinv_clear_errors();
87
+        // Clear any existing errors.
88
+        wpinv_clear_errors();
89 89
 
90
-		// Allow themes and plugins to hook to errors
91
-		do_action( 'getpaid_checkout_error_checks', $submission );
90
+        // Allow themes and plugins to hook to errors
91
+        do_action( 'getpaid_checkout_error_checks', $submission );
92 92
 
93
-		// Do we have any errors?
93
+        // Do we have any errors?
94 94
         if ( wpinv_get_errors() ) {
95 95
             wp_send_json_error( getpaid_get_errors_html() );
96
-		}
96
+        }
97 97
 
98
-	}
98
+    }
99 99
 
100
-	/**
101
-	 * Retrieves submission items.
102
-	 *
103
-	 * @return GetPaid_Form_Item[]
104
-	 */
105
-	protected function get_submission_items() {
100
+    /**
101
+     * Retrieves submission items.
102
+     *
103
+     * @return GetPaid_Form_Item[]
104
+     */
105
+    protected function get_submission_items() {
106 106
 
107
-		$items = $this->payment_form_submission->get_items();
107
+        $items = $this->payment_form_submission->get_items();
108 108
 
109 109
         // Ensure that we have items.
110 110
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
111 111
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
112
-		}
113
-
114
-		return $items;
115
-	}
116
-
117
-	/**
118
-	 * Retrieves submission invoice.
119
-	 *
120
-	 * @return WPInv_Invoice
121
-	 */
122
-	protected function get_submission_invoice() {
123
-		$submission = $this->payment_form_submission;
124
-
125
-		if ( ! $submission->has_invoice() ) {
126
-			$invoice = new WPInv_Invoice();
127
-			$invoice->created_via( 'payment_form' );
128
-			return $invoice;
129 112
         }
130 113
 
131
-		$invoice = $submission->get_invoice();
114
+        return $items;
115
+    }
132 116
 
133
-		// Make sure that it is neither paid or refunded.
134
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
135
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
136
-		}
117
+    /**
118
+     * Retrieves submission invoice.
119
+     *
120
+     * @return WPInv_Invoice
121
+     */
122
+    protected function get_submission_invoice() {
123
+        $submission = $this->payment_form_submission;
137 124
 
138
-		return $invoice;
139
-	}
125
+        if ( ! $submission->has_invoice() ) {
126
+            $invoice = new WPInv_Invoice();
127
+            $invoice->created_via( 'payment_form' );
128
+            return $invoice;
129
+        }
140 130
 
141
-	/**
142
-	 * Processes the submission invoice.
143
-	 *
144
-	 * @param WPInv_Invoice $invoice
145
-	 * @param GetPaid_Form_Item[] $items
146
-	 * @return WPInv_Invoice
147
-	 */
148
-	protected function process_submission_invoice( $invoice, $items ) {
131
+        $invoice = $submission->get_invoice();
149 132
 
150
-		$submission = $this->payment_form_submission;
151
-		$data       = $submission->get_data();
133
+        // Make sure that it is neither paid or refunded.
134
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
135
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
136
+        }
152 137
 
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() ) );
138
+        return $invoice;
139
+    }
140
+
141
+    /**
142
+     * Processes the submission invoice.
143
+     *
144
+     * @param WPInv_Invoice $invoice
145
+     * @param GetPaid_Form_Item[] $items
146
+     * @return WPInv_Invoice
147
+     */
148
+    protected function process_submission_invoice( $invoice, $items ) {
149
+
150
+        $submission = $this->payment_form_submission;
151
+        $data       = $submission->get_data();
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() ) );
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( $data['wpi-gateway'] );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $data['wpi-gateway'] );
162 162
 
163
-		if ( $submission->has_discount_code() ) {
163
+        if ( $submission->has_discount_code() ) {
164 164
             $invoice->set_discount_code( $submission->get_discount_code() );
165
-		}
166
-
167
-		getpaid_maybe_add_default_address( $invoice );
168
-		return $invoice;
169
-	}
170
-
171
-	/**
172
-	 * Retrieves the submission's customer.
173
-	 *
174
-	 * @return int The customer id.
175
-	 */
176
-	protected function get_submission_customer() {
177
-		$submission = $this->payment_form_submission;
178
-
179
-		// If this is an existing invoice...
180
-		if ( $submission->has_invoice() ) {
181
-			return $submission->get_invoice()->get_user_id();
182
-		}
183
-
184
-		// (Maybe) create the user.
165
+        }
166
+
167
+        getpaid_maybe_add_default_address( $invoice );
168
+        return $invoice;
169
+    }
170
+
171
+    /**
172
+     * Retrieves the submission's customer.
173
+     *
174
+     * @return int The customer id.
175
+     */
176
+    protected function get_submission_customer() {
177
+        $submission = $this->payment_form_submission;
178
+
179
+        // If this is an existing invoice...
180
+        if ( $submission->has_invoice() ) {
181
+            return $submission->get_invoice()->get_user_id();
182
+        }
183
+
184
+        // (Maybe) create the user.
185 185
         $user = get_current_user_id();
186 186
 
187 187
         if ( empty( $user ) ) {
@@ -198,31 +198,31 @@  discard block
 block discarded – undo
198 198
 
199 199
         if ( is_numeric( $user ) ) {
200 200
             return $user;
201
-		}
201
+        }
202 202
 
203
-		return $user->ID;
203
+        return $user->ID;
204 204
 
205
-	}
205
+    }
206 206
 
207
-	/**
207
+    /**
208 208
      * Prepares submission data for saving to the database.
209 209
      *
210
-	 * @return array
210
+     * @return array
211 211
      */
212 212
     public function prepare_submission_data_for_saving() {
213 213
 
214
-		$submission = $this->payment_form_submission;
214
+        $submission = $this->payment_form_submission;
215 215
 
216
-		// Prepared submission details.
216
+        // Prepared submission details.
217 217
         $prepared = array();
218 218
 
219 219
         // Raw submission details.
220
-		$data     = $submission->get_data();
220
+        $data     = $submission->get_data();
221 221
 
222
-		// Loop through the submitted details.
222
+        // Loop through the submitted details.
223 223
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
224 224
 
225
-			// Skip premade fields.
225
+            // Skip premade fields.
226 226
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
227 227
                 continue;
228 228
             }
@@ -240,93 +240,93 @@  discard block
 block discarded – undo
240 240
                     $label = $field['label'];
241 241
                 }
242 242
 
243
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
243
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
244 244
 
245 245
             }
246 246
 
247
-		}
247
+        }
248 248
 
249
-		return $prepared;
249
+        return $prepared;
250 250
 
251
-	}
251
+    }
252 252
 
253
-	/**
253
+    /**
254 254
      * Retrieves address details.
255 255
      *
256
-	 * @return array
257
-	 * @param WPInv_Invoice $invoice
258
-	 * @param string $type
256
+     * @return array
257
+     * @param WPInv_Invoice $invoice
258
+     * @param string $type
259 259
      */
260 260
     public function prepare_address_details( $invoice, $type = 'billing' ) {
261 261
 
262
-		$data     = $this->payment_form_submission->get_data();
263
-		$type     = sanitize_key( $type );
264
-		$address  = array();
265
-		$prepared = array();
262
+        $data     = $this->payment_form_submission->get_data();
263
+        $type     = sanitize_key( $type );
264
+        $address  = array();
265
+        $prepared = array();
266 266
 
267
-		if ( ! empty( $data[ $type ] ) ) {
268
-			$address = $data[ $type ];
269
-		}
267
+        if ( ! empty( $data[ $type ] ) ) {
268
+            $address = $data[ $type ];
269
+        }
270 270
 
271
-		// Clean address details.
272
-		foreach ( $address as $key => $value ) {
273
-			$key             = sanitize_key( $key );
274
-			$key             = str_replace( 'wpinv_', '', $key );
275
-			$value           = wpinv_clean( $value );
276
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
277
-		}
271
+        // Clean address details.
272
+        foreach ( $address as $key => $value ) {
273
+            $key             = sanitize_key( $key );
274
+            $key             = str_replace( 'wpinv_', '', $key );
275
+            $value           = wpinv_clean( $value );
276
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
277
+        }
278 278
 
279
-		// Filter address details.
280
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
279
+        // Filter address details.
280
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
281 281
 
282
-		// Remove non-whitelisted values.
283
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
282
+        // Remove non-whitelisted values.
283
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
284 284
 
285
-	}
285
+    }
286 286
 
287
-	/**
287
+    /**
288 288
      * Prepares the billing details.
289 289
      *
290
-	 * @return array
291
-	 * @param WPInv_Invoice $invoice
290
+     * @return array
291
+     * @param WPInv_Invoice $invoice
292 292
      */
293 293
     protected function prepare_billing_info( &$invoice ) {
294 294
 
295
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
295
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
296 296
 
297
-		// Update the invoice with the billing details.
298
-		$invoice->set_props( $billing_address );
297
+        // Update the invoice with the billing details.
298
+        $invoice->set_props( $billing_address );
299 299
 
300
-	}
300
+    }
301 301
 
302
-	/**
302
+    /**
303 303
      * Prepares the shipping details.
304 304
      *
305
-	 * @return array
306
-	 * @param WPInv_Invoice $invoice
305
+     * @return array
306
+     * @param WPInv_Invoice $invoice
307 307
      */
308 308
     protected function prepare_shipping_info( $invoice ) {
309 309
 
310
-		$data = $this->payment_form_submission->get_data();
310
+        $data = $this->payment_form_submission->get_data();
311 311
 
312
-		if ( empty( $data['same-shipping-address'] ) ) {
313
-			return $this->prepare_address_details( $invoice, 'shipping' );
314
-		}
312
+        if ( empty( $data['same-shipping-address'] ) ) {
313
+            return $this->prepare_address_details( $invoice, 'shipping' );
314
+        }
315 315
 
316
-		return $this->prepare_address_details( $invoice, 'billing' );
316
+        return $this->prepare_address_details( $invoice, 'billing' );
317 317
 
318
-	}
318
+    }
319 319
 
320
-	/**
321
-	 * Confirms the submission is valid and send users to the gateway.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 * @param array $prepared_payment_form_data
325
-	 * @param array $shipping
326
-	 */
327
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
320
+    /**
321
+     * Confirms the submission is valid and send users to the gateway.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     * @param array $prepared_payment_form_data
325
+     * @param array $shipping
326
+     */
327
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
328 328
 
329
-		// Ensure the invoice exists.
329
+        // Ensure the invoice exists.
330 330
         if ( ! $invoice->exists() ) {
331 331
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
332 332
         }
@@ -334,81 +334,81 @@  discard block
 block discarded – undo
334 334
         // Save payment form data.
335 335
         if ( ! empty( $prepared_payment_form_data ) ) {
336 336
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
337
-		}
337
+        }
338 338
 
339
-		// Save payment form data.
339
+        // Save payment form data.
340 340
         if ( ! empty( $shipping ) ) {
341 341
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
342
-		}
342
+        }
343 343
 
344
-		// Backwards compatibility.
344
+        // Backwards compatibility.
345 345
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
346 346
 
347
-		$this->process_payment( $invoice );
347
+        $this->process_payment( $invoice );
348 348
 
349 349
         // If we are here, there was an error.
350
-		wpinv_send_back_to_checkout( $invoice );
350
+        wpinv_send_back_to_checkout( $invoice );
351 351
 
352
-	}
352
+    }
353 353
 
354
-	/**
355
-	 * Processes the actual payment.
356
-	 *
357
-	 * @param WPInv_Invoice $invoice
358
-	 */
359
-	protected function process_payment( $invoice ) {
354
+    /**
355
+     * Processes the actual payment.
356
+     *
357
+     * @param WPInv_Invoice $invoice
358
+     */
359
+    protected function process_payment( $invoice ) {
360 360
 
361
-		// Clear any checkout errors.
362
-		wpinv_clear_errors();
361
+        // Clear any checkout errors.
362
+        wpinv_clear_errors();
363 363
 
364
-		// No need to send free invoices to the gateway.
365
-		if ( $invoice->is_free() ) {
366
-			$this->process_free_payment( $invoice );
367
-		}
364
+        // No need to send free invoices to the gateway.
365
+        if ( $invoice->is_free() ) {
366
+            $this->process_free_payment( $invoice );
367
+        }
368 368
 
369
-		$submission = $this->payment_form_submission;
369
+        $submission = $this->payment_form_submission;
370 370
 
371
-		// Fires before sending to the gateway.
372
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
371
+        // Fires before sending to the gateway.
372
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
373 373
 
374
-		// Allow the sumission data to be modified before it is sent to the gateway.
375
-		$submission_data    = $submission->get_data();
376
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
377
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
374
+        // Allow the sumission data to be modified before it is sent to the gateway.
375
+        $submission_data    = $submission->get_data();
376
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
377
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
378 378
 
379
-		// Validate the currency.
380
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
381
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
382
-		}
379
+        // Validate the currency.
380
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
381
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
382
+        }
383 383
 
384
-		// Check to see if we have any errors.
385
-		if ( wpinv_get_errors() ) {
386
-			wpinv_send_back_to_checkout( $invoice );
387
-		}
384
+        // Check to see if we have any errors.
385
+        if ( wpinv_get_errors() ) {
386
+            wpinv_send_back_to_checkout( $invoice );
387
+        }
388 388
 
389
-		// Send info to the gateway for payment processing
390
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
389
+        // Send info to the gateway for payment processing
390
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
391 391
 
392
-		// Backwards compatibility.
393
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
392
+        // Backwards compatibility.
393
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
394 394
 
395
-	}
395
+    }
396 396
 
397
-	/**
398
-	 * Marks the invoice as paid in case the checkout is free.
399
-	 *
400
-	 * @param WPInv_Invoice $invoice
401
-	 */
402
-	protected function process_free_payment( $invoice ) {
397
+    /**
398
+     * Marks the invoice as paid in case the checkout is free.
399
+     *
400
+     * @param WPInv_Invoice $invoice
401
+     */
402
+    protected function process_free_payment( $invoice ) {
403 403
 
404
-		$invoice->set_gateway( 'none' );
405
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
406
-		$invoice->mark_paid();
407
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
404
+        $invoice->set_gateway( 'none' );
405
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
406
+        $invoice->mark_paid();
407
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
408 408
 
409
-	}
409
+    }
410 410
 
411
-	/**
411
+    /**
412 412
      * Sends a redrect response to payment details.
413 413
      *
414 414
      */
Please login to merge, or discard this patch.