Passed
Push — master ( ca9ae5...63ce67 )
by Brian
05:15
created
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -12,180 +12,180 @@  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
+    }
133 117
 
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
-		}
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
138 125
 
139
-		return $invoice;
140
-	}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
141 131
 
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 ) {
132
+        $invoice = $submission->get_invoice();
150 133
 
151
-		$submission = $this->payment_form_submission;
152
-		$data       = $submission->get_data();
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
+        }
153 138
 
154
-		// Set-up the invoice details.
155
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
-		$invoice->set_user_id( $this->get_submission_customer() );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
139
+        return $invoice;
140
+    }
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 ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+        $data       = $submission->get_data();
153
+
154
+        // Set-up the invoice details.
155
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
+        $invoice->set_user_id( $this->get_submission_customer() );
157
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158 158
         $invoice->set_items( $items );
159 159
         $invoice->set_fees( $submission->get_fees() );
160 160
         $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $data['wpi-gateway'] );
161
+        $invoice->set_discounts( $submission->get_discounts() );
162
+        $invoice->set_gateway( $data['wpi-gateway'] );
163 163
 
164
-		$address_confirmed = $submission->get_field( 'confirm-address' );
165
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
164
+        $address_confirmed = $submission->get_field( 'confirm-address' );
165
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
166 166
 
167
-		if ( $submission->has_discount_code() ) {
167
+        if ( $submission->has_discount_code() ) {
168 168
             $invoice->set_discount_code( $submission->get_discount_code() );
169
-		}
170
-
171
-		getpaid_maybe_add_default_address( $invoice );
172
-		return $invoice;
173
-	}
174
-
175
-	/**
176
-	 * Retrieves the submission's customer.
177
-	 *
178
-	 * @return int The customer id.
179
-	 */
180
-	protected function get_submission_customer() {
181
-		$submission = $this->payment_form_submission;
182
-
183
-		// If this is an existing invoice...
184
-		if ( $submission->has_invoice() ) {
185
-			return $submission->get_invoice()->get_user_id();
186
-		}
187
-
188
-		// (Maybe) create the user.
169
+        }
170
+
171
+        getpaid_maybe_add_default_address( $invoice );
172
+        return $invoice;
173
+    }
174
+
175
+    /**
176
+     * Retrieves the submission's customer.
177
+     *
178
+     * @return int The customer id.
179
+     */
180
+    protected function get_submission_customer() {
181
+        $submission = $this->payment_form_submission;
182
+
183
+        // If this is an existing invoice...
184
+        if ( $submission->has_invoice() ) {
185
+            return $submission->get_invoice()->get_user_id();
186
+        }
187
+
188
+        // (Maybe) create the user.
189 189
         $user = get_current_user_id();
190 190
 
191 191
         if ( empty( $user ) ) {
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
         if ( empty( $user ) ) {
196 196
             $user = wpinv_create_user( $submission->get_billing_email() );
197 197
 
198
-			// (Maybe) send new user notification.
199
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
200
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
201
-				wp_send_new_user_notifications( $user, 'user' );
202
-			}
198
+            // (Maybe) send new user notification.
199
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
200
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
201
+                wp_send_new_user_notifications( $user, 'user' );
202
+            }
203 203
 
204 204
         }
205 205
 
@@ -209,31 +209,31 @@  discard block
 block discarded – undo
209 209
 
210 210
         if ( is_numeric( $user ) ) {
211 211
             return $user;
212
-		}
212
+        }
213 213
 
214
-		return $user->ID;
214
+        return $user->ID;
215 215
 
216
-	}
216
+    }
217 217
 
218
-	/**
218
+    /**
219 219
      * Prepares submission data for saving to the database.
220 220
      *
221
-	 * @return array
221
+     * @return array
222 222
      */
223 223
     public function prepare_submission_data_for_saving() {
224 224
 
225
-		$submission = $this->payment_form_submission;
225
+        $submission = $this->payment_form_submission;
226 226
 
227
-		// Prepared submission details.
227
+        // Prepared submission details.
228 228
         $prepared = array();
229 229
 
230 230
         // Raw submission details.
231
-		$data     = $submission->get_data();
231
+        $data     = $submission->get_data();
232 232
 
233
-		// Loop through the submitted details.
233
+        // Loop through the submitted details.
234 234
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
235 235
 
236
-			// Skip premade fields.
236
+            // Skip premade fields.
237 237
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
238 238
                 continue;
239 239
             }
@@ -251,176 +251,176 @@  discard block
 block discarded – undo
251 251
                     $label = $field['label'];
252 252
                 }
253 253
 
254
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
254
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
255 255
 
256 256
             }
257 257
 
258
-		}
258
+        }
259 259
 
260
-		return $prepared;
260
+        return $prepared;
261 261
 
262
-	}
262
+    }
263 263
 
264
-	/**
264
+    /**
265 265
      * Retrieves address details.
266 266
      *
267
-	 * @return array
268
-	 * @param WPInv_Invoice $invoice
269
-	 * @param string $type
267
+     * @return array
268
+     * @param WPInv_Invoice $invoice
269
+     * @param string $type
270 270
      */
271 271
     public function prepare_address_details( $invoice, $type = 'billing' ) {
272 272
 
273
-		$data     = $this->payment_form_submission->get_data();
274
-		$type     = sanitize_key( $type );
275
-		$address  = array();
276
-		$prepared = array();
273
+        $data     = $this->payment_form_submission->get_data();
274
+        $type     = sanitize_key( $type );
275
+        $address  = array();
276
+        $prepared = array();
277 277
 
278
-		if ( ! empty( $data[ $type ] ) ) {
279
-			$address = $data[ $type ];
280
-		}
278
+        if ( ! empty( $data[ $type ] ) ) {
279
+            $address = $data[ $type ];
280
+        }
281 281
 
282
-		// Clean address details.
283
-		foreach ( $address as $key => $value ) {
284
-			$key             = sanitize_key( $key );
285
-			$key             = str_replace( 'wpinv_', '', $key );
286
-			$value           = wpinv_clean( $value );
287
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
288
-		}
282
+        // Clean address details.
283
+        foreach ( $address as $key => $value ) {
284
+            $key             = sanitize_key( $key );
285
+            $key             = str_replace( 'wpinv_', '', $key );
286
+            $value           = wpinv_clean( $value );
287
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
288
+        }
289 289
 
290
-		// Filter address details.
291
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
290
+        // Filter address details.
291
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
292 292
 
293
-		// Remove non-whitelisted values.
294
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
293
+        // Remove non-whitelisted values.
294
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
295 295
 
296
-	}
296
+    }
297 297
 
298
-	/**
298
+    /**
299 299
      * Prepares the billing details.
300 300
      *
301
-	 * @return array
302
-	 * @param WPInv_Invoice $invoice
301
+     * @return array
302
+     * @param WPInv_Invoice $invoice
303 303
      */
304 304
     protected function prepare_billing_info( &$invoice ) {
305 305
 
306
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
306
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
307 307
 
308
-		// Update the invoice with the billing details.
309
-		$invoice->set_props( $billing_address );
308
+        // Update the invoice with the billing details.
309
+        $invoice->set_props( $billing_address );
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Prepares the shipping details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318 318
      */
319 319
     protected function prepare_shipping_info( $invoice ) {
320 320
 
321
-		$data = $this->payment_form_submission->get_data();
321
+        $data = $this->payment_form_submission->get_data();
322 322
 
323
-		if ( empty( $data['same-shipping-address'] ) ) {
324
-			return $this->prepare_address_details( $invoice, 'shipping' );
325
-		}
323
+        if ( empty( $data['same-shipping-address'] ) ) {
324
+            return $this->prepare_address_details( $invoice, 'shipping' );
325
+        }
326 326
 
327
-		return $this->prepare_address_details( $invoice, 'billing' );
327
+        return $this->prepare_address_details( $invoice, 'billing' );
328 328
 
329
-	}
329
+    }
330 330
 
331
-	/**
332
-	 * Confirms the submission is valid and send users to the gateway.
333
-	 *
334
-	 * @param WPInv_Invoice $invoice
335
-	 * @param array $prepared_payment_form_data
336
-	 * @param array $shipping
337
-	 */
338
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
331
+    /**
332
+     * Confirms the submission is valid and send users to the gateway.
333
+     *
334
+     * @param WPInv_Invoice $invoice
335
+     * @param array $prepared_payment_form_data
336
+     * @param array $shipping
337
+     */
338
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
339 339
 
340
-		// Ensure the invoice exists.
340
+        // Ensure the invoice exists.
341 341
         if ( ! $invoice->exists() ) {
342 342
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
343 343
         }
344 344
 
345
-		// Save payment form data.
346
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
345
+        // Save payment form data.
346
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
347 347
         if ( ! empty( $prepared_payment_form_data ) ) {
348 348
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
349
-		}
349
+        }
350 350
 
351
-		// Save payment form data.
351
+        // Save payment form data.
352 352
         if ( ! empty( $shipping ) ) {
353 353
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
354
-		}
354
+        }
355 355
 
356
-		// Backwards compatibility.
356
+        // Backwards compatibility.
357 357
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
358 358
 
359
-		$this->process_payment( $invoice );
359
+        $this->process_payment( $invoice );
360 360
 
361 361
         // If we are here, there was an error.
362
-		wpinv_send_back_to_checkout( $invoice );
362
+        wpinv_send_back_to_checkout( $invoice );
363 363
 
364
-	}
364
+    }
365 365
 
366
-	/**
367
-	 * Processes the actual payment.
368
-	 *
369
-	 * @param WPInv_Invoice $invoice
370
-	 */
371
-	protected function process_payment( $invoice ) {
366
+    /**
367
+     * Processes the actual payment.
368
+     *
369
+     * @param WPInv_Invoice $invoice
370
+     */
371
+    protected function process_payment( $invoice ) {
372 372
 
373
-		// Clear any checkout errors.
374
-		wpinv_clear_errors();
373
+        // Clear any checkout errors.
374
+        wpinv_clear_errors();
375 375
 
376
-		// No need to send free invoices to the gateway.
377
-		if ( $invoice->is_free() ) {
378
-			$this->process_free_payment( $invoice );
379
-		}
376
+        // No need to send free invoices to the gateway.
377
+        if ( $invoice->is_free() ) {
378
+            $this->process_free_payment( $invoice );
379
+        }
380 380
 
381
-		$submission = $this->payment_form_submission;
381
+        $submission = $this->payment_form_submission;
382 382
 
383
-		// Fires before sending to the gateway.
384
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
383
+        // Fires before sending to the gateway.
384
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
385 385
 
386
-		// Allow the sumission data to be modified before it is sent to the gateway.
387
-		$submission_data    = $submission->get_data();
388
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
389
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
386
+        // Allow the sumission data to be modified before it is sent to the gateway.
387
+        $submission_data    = $submission->get_data();
388
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
389
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
390 390
 
391
-		// Validate the currency.
392
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
393
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
394
-		}
391
+        // Validate the currency.
392
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
393
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
394
+        }
395 395
 
396
-		// Check to see if we have any errors.
397
-		if ( wpinv_get_errors() ) {
398
-			wpinv_send_back_to_checkout( $invoice );
399
-		}
396
+        // Check to see if we have any errors.
397
+        if ( wpinv_get_errors() ) {
398
+            wpinv_send_back_to_checkout( $invoice );
399
+        }
400 400
 
401
-		// Send info to the gateway for payment processing
402
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
401
+        // Send info to the gateway for payment processing
402
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
403 403
 
404
-		// Backwards compatibility.
405
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
404
+        // Backwards compatibility.
405
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
406 406
 
407
-	}
407
+    }
408 408
 
409
-	/**
410
-	 * Marks the invoice as paid in case the checkout is free.
411
-	 *
412
-	 * @param WPInv_Invoice $invoice
413
-	 */
414
-	protected function process_free_payment( $invoice ) {
409
+    /**
410
+     * Marks the invoice as paid in case the checkout is free.
411
+     *
412
+     * @param WPInv_Invoice $invoice
413
+     */
414
+    protected function process_free_payment( $invoice ) {
415 415
 
416
-		$invoice->set_gateway( 'none' );
417
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
418
-		$invoice->mark_paid();
419
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
416
+        $invoice->set_gateway( 'none' );
417
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
418
+        $invoice->mark_paid();
419
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
420 420
 
421
-	}
421
+    }
422 422
 
423
-	/**
423
+    /**
424 424
      * Sends a redrect response to payment details.
425 425
      *
426 426
      */
Please login to merge, or discard this patch.
includes/admin/views/wizard-header.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@
 block discarded – undo
20 20
 			<title><?php esc_html_e( 'GetPaid &rsaquo; Setup Wizard', 'invoicing' ); ?></title>
21 21
 			<?php
22 22
                 getpaid_admin()->enqeue_scripts();
23
-				wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' );
24
-				wp_print_styles( 'select2' );
23
+                wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' );
24
+                wp_print_styles( 'select2' );
25 25
                 wp_print_scripts( 'select2' );
26
-				wp_print_scripts( 'wpinv-admin-script' );
26
+                wp_print_scripts( 'wpinv-admin-script' );
27 27
                 do_action( 'admin_print_styles' );
28 28
                 do_action( 'admin_head' );
29
-			?>
29
+            ?>
30 30
 			<style>
31 31
 				body, p{
32 32
 					font-size: 16px;
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+        $anchor = __( 'Deactivate', 'invoicing' );
61
+        $title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64 64
     } else if( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+        $anchor = __( 'Activate', 'invoicing' );
77
+        $title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
             'getpaid-nonce'
92 92
         )
93 93
     );
94
-	$anchor = __( 'Delete', 'invoicing' );
95
-	$title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
94
+    $anchor = __( 'Delete', 'invoicing' );
95
+    $title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
96 96
     $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
97 97
 
98 98
     $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
     $name       = isset( $option['name'] ) ? $option['name'] : '';
196 196
     $cb         = "wpinv_{$option['type']}_callback";
197 197
     $section    = "wpinv_settings_{$tab}_$section";
198
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
198
+    $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
199 199
 
200
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
201
-		$tip   = wpinv_clean( $option['desc'] );
202
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
203
-		unset( $option['desc'] );
204
-	}
200
+    if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
201
+        $tip   = wpinv_clean( $option['desc'] );
202
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
203
+        unset( $option['desc'] );
204
+    }
205 205
 
206 206
     // Loop through all tabs.
207 207
     add_settings_field(
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
             'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
229 229
             'onchange'    => isset( $option['onchange'] )   ? $option['onchange']     : '',
230 230
             'custom'      => isset( $option['custom'] )     ? $option['custom']       : '',
231
-			'default_content' => isset( $option['default_content'] )     ? $option['default_content']       : '',
232
-			'class'       => isset( $option['class'] )     ? $option['class']         : '',
233
-			'style'       => isset( $option['style'] )     ? $option['style']         : '',
231
+            'default_content' => isset( $option['default_content'] )     ? $option['default_content']       : '',
232
+            'class'       => isset( $option['class'] )     ? $option['class']         : '',
233
+            'style'       => isset( $option['style'] )     ? $option['style']         : '',
234 234
             'cols'        => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
235 235
             'rows'        => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
236 236
         )
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
  * @return array
245 245
  */
246 246
 function wpinv_get_registered_settings() {
247
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
247
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
248 248
 }
249 249
 
250 250
 /**
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
  */
264 264
 function wpinv_settings_sanitize( $input = array() ) {
265 265
 
266
-	$wpinv_options = wpinv_get_options();
267
-	$raw_referrer  = wp_get_raw_referer();
266
+    $wpinv_options = wpinv_get_options();
267
+    $raw_referrer  = wp_get_raw_referer();
268 268
 
269 269
     if ( empty( $raw_referrer ) ) {
270
-		return array_merge( $wpinv_options, $input );
270
+        return array_merge( $wpinv_options, $input );
271 271
     }
272 272
 
273 273
     wp_parse_str( $raw_referrer, $referrer );
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
         }
293 293
 
294 294
         // General filter
295
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
295
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
296 296
 
297
-		// Key specific filter.
298
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
297
+        // Key specific filter.
298
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
299 299
     }
300 300
 
301 301
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -338,14 +338,14 @@  discard block
 block discarded – undo
338 338
 
339 339
     foreach ( $new_rates as $rate ) {
340 340
 
341
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
342
-		$rate['name']    = sanitize_text_field( $rate['name'] );
343
-		$rate['state']   = sanitize_text_field( $rate['state'] );
344
-		$rate['country'] = sanitize_text_field( $rate['country'] );
345
-		$rate['global']  = empty( $rate['state'] );
346
-		$tax_rates[]     = $rate;
341
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
342
+        $rate['name']    = sanitize_text_field( $rate['name'] );
343
+        $rate['state']   = sanitize_text_field( $rate['state'] );
344
+        $rate['country'] = sanitize_text_field( $rate['country'] );
345
+        $rate['global']  = empty( $rate['state'] );
346
+        $tax_rates[]     = $rate;
347 347
 
348
-	}
348
+    }
349 349
 
350 350
     update_option( 'wpinv_tax_rates', $tax_rates );
351 351
 
@@ -358,11 +358,11 @@  discard block
 block discarded – undo
358 358
     $tabs['general']  = __( 'General', 'invoicing' );
359 359
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
360 360
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
361
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
361
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
362 362
 
363
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
364
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
365
-	}
363
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
364
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
365
+    }
366 366
 
367 367
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
368 368
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -401,14 +401,14 @@  discard block
 block discarded – undo
401 401
         ) ),
402 402
         'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
403 403
             'main'  => __( 'Tax Settings', 'invoicing' ),
404
-			'rates' => __( 'Tax Rates', 'invoicing' ),
405
-			'vat'   => __( 'EU VAT Settings', 'invoicing' )
404
+            'rates' => __( 'Tax Rates', 'invoicing' ),
405
+            'vat'   => __( 'EU VAT Settings', 'invoicing' )
406 406
         ) ),
407 407
         'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
408 408
             'main' => __( 'Email Settings', 'invoicing' ),
409
-		) ),
409
+        ) ),
410 410
 
411
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
411
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
412 412
 
413 413
         'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
414 414
             'main' => __( 'Privacy policy', 'invoicing' ),
@@ -428,48 +428,48 @@  discard block
 block discarded – undo
428 428
 }
429 429
 
430 430
 function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
431
-	$pages_options = array();
431
+    $pages_options = array();
432 432
 
433
-	if( $default_label !== NULL && $default_label !== false ) {
434
-		$pages_options = array( '' => $default_label ); // Blank option
435
-	}
433
+    if( $default_label !== NULL && $default_label !== false ) {
434
+        $pages_options = array( '' => $default_label ); // Blank option
435
+    }
436 436
 
437
-	$pages = get_pages();
438
-	if ( $pages ) {
439
-		foreach ( $pages as $page ) {
440
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
437
+    $pages = get_pages();
438
+    if ( $pages ) {
439
+        foreach ( $pages as $page ) {
440
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
441 441
             $pages_options[ $page->ID ] = $title;
442
-		}
443
-	}
442
+        }
443
+    }
444 444
 
445
-	return $pages_options;
445
+    return $pages_options;
446 446
 }
447 447
 
448 448
 function wpinv_header_callback( $args ) {
449
-	if ( !empty( $args['desc'] ) ) {
449
+    if ( !empty( $args['desc'] ) ) {
450 450
         echo $args['desc'];
451 451
     }
452 452
 }
453 453
 
454 454
 function wpinv_hidden_callback( $args ) {
455 455
 
456
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
457
-	$value   = wpinv_get_option( $args['id'], $std );
456
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
457
+    $value   = wpinv_get_option( $args['id'], $std );
458 458
 
459
-	if ( isset( $args['set_value'] ) ) {
460
-		$value = $args['set_value'];
461
-	}
459
+    if ( isset( $args['set_value'] ) ) {
460
+        $value = $args['set_value'];
461
+    }
462 462
 
463
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
464
-		$args['readonly'] = true;
465
-		$name  = '';
466
-	} else {
467
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
468
-	}
463
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
464
+        $args['readonly'] = true;
465
+        $name  = '';
466
+    } else {
467
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
468
+    }
469 469
 
470
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
470
+    $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
471 471
     
472
-	echo $html;
472
+    echo $html;
473 473
 }
474 474
 
475 475
 /**
@@ -477,12 +477,12 @@  discard block
 block discarded – undo
477 477
  */
478 478
 function wpinv_checkbox_callback( $args ) {
479 479
 
480
-	$std = isset( $args['std'] ) ? $args['std'] : '';
481
-	$std = wpinv_get_option( $args['id'], $std );
482
-	$id  = esc_attr( $args['id'] );
480
+    $std = isset( $args['std'] ) ? $args['std'] : '';
481
+    $std = wpinv_get_option( $args['id'], $std );
482
+    $id  = esc_attr( $args['id'] );
483 483
 
484
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
485
-	?>
484
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
485
+    ?>
486 486
 		<fieldset>
487 487
 			<label>
488 488
 				<input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
@@ -494,75 +494,75 @@  discard block
 block discarded – undo
494 494
 
495 495
 function wpinv_multicheck_callback( $args ) {
496 496
 
497
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
498
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
497
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
498
+    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
499 499
 
500
-	if ( ! empty( $args['options'] ) ) {
500
+    if ( ! empty( $args['options'] ) ) {
501 501
 
502
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
503
-		$value   = wpinv_get_option( $args['id'], $std );
502
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
503
+        $value   = wpinv_get_option( $args['id'], $std );
504 504
 
505
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
505
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
506 506
         foreach( $args['options'] as $key => $option ):
507
-			$sanitize_key = wpinv_sanitize_key( $key );
508
-			if ( in_array( $sanitize_key, $value ) ) { 
509
-				$enabled = $sanitize_key;
510
-			} else { 
511
-				$enabled = NULL; 
512
-			}
513
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
514
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
515
-		endforeach;
516
-		echo '</div>';
517
-		echo '<p class="description">' . $args['desc'] . '</p>';
518
-	}
507
+            $sanitize_key = wpinv_sanitize_key( $key );
508
+            if ( in_array( $sanitize_key, $value ) ) { 
509
+                $enabled = $sanitize_key;
510
+            } else { 
511
+                $enabled = NULL; 
512
+            }
513
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
514
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
515
+        endforeach;
516
+        echo '</div>';
517
+        echo '<p class="description">' . $args['desc'] . '</p>';
518
+    }
519 519
 }
520 520
 
521 521
 function wpinv_payment_icons_callback( $args ) {
522 522
     
523 523
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
524
-	$value   = wpinv_get_option( $args['id'], false);
524
+    $value   = wpinv_get_option( $args['id'], false);
525 525
 
526
-	if ( ! empty( $args['options'] ) ) {
527
-		foreach( $args['options'] as $key => $option ) {
526
+    if ( ! empty( $args['options'] ) ) {
527
+        foreach( $args['options'] as $key => $option ) {
528 528
             $sanitize_key = wpinv_sanitize_key( $key );
529 529
             
530
-			if( empty( $value ) ) {
531
-				$enabled = $option;
532
-			} else {
533
-				$enabled = NULL;
534
-			}
535
-
536
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
537
-
538
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
539
-
540
-				if ( wpinv_string_is_image_url( $key ) ) {
541
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
542
-				} else {
543
-					$card = strtolower( str_replace( ' ', '', $option ) );
544
-
545
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
546
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
547
-					} else {
548
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
549
-						$content_dir = WP_CONTENT_DIR;
550
-
551
-						if ( function_exists( 'wp_normalize_path' ) ) {
552
-							// Replaces backslashes with forward slashes for Windows systems
553
-							$image = wp_normalize_path( $image );
554
-							$content_dir = wp_normalize_path( $content_dir );
555
-						}
556
-
557
-						$image = str_replace( $content_dir, content_url(), $image );
558
-					}
559
-
560
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
561
-				}
562
-			echo $option . '</label>';
563
-		}
564
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
565
-	}
530
+            if( empty( $value ) ) {
531
+                $enabled = $option;
532
+            } else {
533
+                $enabled = NULL;
534
+            }
535
+
536
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
537
+
538
+                echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
539
+
540
+                if ( wpinv_string_is_image_url( $key ) ) {
541
+                    echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
542
+                } else {
543
+                    $card = strtolower( str_replace( ' ', '', $option ) );
544
+
545
+                    if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
546
+                        $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
547
+                    } else {
548
+                        $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
549
+                        $content_dir = WP_CONTENT_DIR;
550
+
551
+                        if ( function_exists( 'wp_normalize_path' ) ) {
552
+                            // Replaces backslashes with forward slashes for Windows systems
553
+                            $image = wp_normalize_path( $image );
554
+                            $content_dir = wp_normalize_path( $content_dir );
555
+                        }
556
+
557
+                        $image = str_replace( $content_dir, content_url(), $image );
558
+                    }
559
+
560
+                    echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
561
+                }
562
+            echo $option . '</label>';
563
+        }
564
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
565
+    }
566 566
 }
567 567
 
568 568
 /**
@@ -570,9 +570,9 @@  discard block
 block discarded – undo
570 570
  */
571 571
 function wpinv_radio_callback( $args ) {
572 572
 
573
-	$std = isset( $args['std'] ) ? $args['std'] : '';
574
-	$std = wpinv_get_option( $args['id'], $std );
575
-	?>
573
+    $std = isset( $args['std'] ) ? $args['std'] : '';
574
+    $std = wpinv_get_option( $args['id'], $std );
575
+    ?>
576 576
 		<fieldset>
577 577
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
578 578
 				<?php foreach( $args['options'] as $key => $option ) : ?>
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 			</ul>
587 587
 		</fieldset>
588 588
 	<?php
589
-	getpaid_settings_description_callback( $args );
589
+    getpaid_settings_description_callback( $args );
590 590
 }
591 591
 
592 592
 /**
@@ -594,10 +594,10 @@  discard block
 block discarded – undo
594 594
  */
595 595
 function getpaid_settings_description_callback( $args ) {
596 596
 
597
-	if ( ! empty( $args['desc'] ) ) {
598
-		$description = wp_kses_post( $args['desc'] );
599
-		echo "<p class='description'>$description</p>";
600
-	}
597
+    if ( ! empty( $args['desc'] ) ) {
598
+        $description = wp_kses_post( $args['desc'] );
599
+        echo "<p class='description'>$description</p>";
600
+    }
601 601
 
602 602
 }
603 603
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
  */
607 607
 function wpinv_gateways_callback() {
608 608
 
609
-	?>
609
+    ?>
610 610
 		</td>
611 611
 	</tr>
612 612
 	<tr class="bsui">
@@ -620,22 +620,22 @@  discard block
 block discarded – undo
620 620
     
621 621
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
622 622
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
623
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
624
-	$value   = wpinv_get_option( $args['id'], $std );
623
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
624
+    $value   = wpinv_get_option( $args['id'], $std );
625 625
 
626
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
626
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
627 627
 
628
-	foreach ( $args['options'] as $key => $option ) :
629
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
628
+    foreach ( $args['options'] as $key => $option ) :
629
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
630 630
             $selected = selected( $key, $args['selected'], false );
631 631
         } else {
632 632
             $selected = selected( $key, $value, false );
633 633
         }
634
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
635
-	endforeach;
634
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
635
+    endforeach;
636 636
 
637
-	echo '</select>';
638
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
637
+    echo '</select>';
638
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
639 639
 }
640 640
 
641 641
 /**
@@ -646,29 +646,29 @@  discard block
 block discarded – undo
646 646
  */
647 647
 function wpinv_settings_attrs_helper( $args ) {
648 648
 
649
-	$value        = isset( $args['std'] ) ? $args['std'] : '';
650
-	$id           = esc_attr( $args['id'] );
651
-	$placeholder  = esc_attr( $args['placeholder'] );
649
+    $value        = isset( $args['std'] ) ? $args['std'] : '';
650
+    $id           = esc_attr( $args['id'] );
651
+    $placeholder  = esc_attr( $args['placeholder'] );
652 652
 
653
-	if ( ! empty( $args['faux'] ) ) {
654
-		$args['readonly'] = true;
655
-		$name             = '';
656
-	} else {
657
-		$value  = wpinv_get_option( $args['id'], $value );
658
-		$name   = "wpinv_settings[$id]";
659
-	}
653
+    if ( ! empty( $args['faux'] ) ) {
654
+        $args['readonly'] = true;
655
+        $name             = '';
656
+    } else {
657
+        $value  = wpinv_get_option( $args['id'], $value );
658
+        $name   = "wpinv_settings[$id]";
659
+    }
660 660
 
661
-	$value    = is_scalar( $value ) ? esc_attr( $value ) : '';
662
-	$class    = esc_attr( $args['class'] );
663
-	$style    = esc_attr( $args['style'] );
664
-	$readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
661
+    $value    = is_scalar( $value ) ? esc_attr( $value ) : '';
662
+    $class    = esc_attr( $args['class'] );
663
+    $style    = esc_attr( $args['style'] );
664
+    $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
665 665
 
666
-	$onchange = '';
666
+    $onchange = '';
667 667
     if ( ! empty( $args['onchange'] ) ) {
668 668
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
669
-	}
669
+    }
670 670
 
671
-	return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
671
+    return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
672 672
 }
673 673
 
674 674
 /**
@@ -676,11 +676,11 @@  discard block
 block discarded – undo
676 676
  */
677 677
 function wpinv_text_callback( $args ) {
678 678
 
679
-	$desc = wp_kses_post( $args['desc'] );
680
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
681
-	$attr = wpinv_settings_attrs_helper( $args );
679
+    $desc = wp_kses_post( $args['desc'] );
680
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
681
+    $attr = wpinv_settings_attrs_helper( $args );
682 682
 
683
-	?>
683
+    ?>
684 684
 		<label style="width: 100%;">
685 685
 			<input type="text" <?php echo $attr; ?>>
686 686
 			<?php echo $desc; ?>
@@ -694,14 +694,14 @@  discard block
 block discarded – undo
694 694
  */
695 695
 function wpinv_number_callback( $args ) {
696 696
 
697
-	$desc = wp_kses_post( $args['desc'] );
698
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
699
-	$attr = wpinv_settings_attrs_helper( $args );
700
-	$max  = intval( $args['max'] );
701
-	$min  = intval( $args['min'] );
702
-	$step = floatval( $args['step'] );
697
+    $desc = wp_kses_post( $args['desc'] );
698
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
699
+    $attr = wpinv_settings_attrs_helper( $args );
700
+    $max  = intval( $args['max'] );
701
+    $min  = intval( $args['min'] );
702
+    $step = floatval( $args['step'] );
703 703
 
704
-	?>
704
+    ?>
705 705
 		<label style="width: 100%;">
706 706
 			<input type="number" step="<?php echo $step; ?>" max="<?php echo $max; ?>" min="<?php echo $min; ?>" <?php echo $attr; ?>>
707 707
 			<?php echo $desc; ?>
@@ -713,36 +713,36 @@  discard block
 block discarded – undo
713 713
 function wpinv_textarea_callback( $args ) {
714 714
     
715 715
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
716
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
717
-	$value   = wpinv_get_option( $args['id'], $std );
716
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
717
+    $value   = wpinv_get_option( $args['id'], $std );
718 718
 
719 719
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
720 720
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
721 721
 
722
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
723
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
722
+    $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
723
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
724 724
 
725
-	echo $html;
725
+    echo $html;
726 726
 }
727 727
 
728 728
 function wpinv_password_callback( $args ) {
729 729
     
730 730
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
731
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
732
-	$value   = wpinv_get_option( $args['id'], $std );
731
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
732
+    $value   = wpinv_get_option( $args['id'], $std );
733 733
 
734
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
735
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
736
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
734
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
735
+    $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
736
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
737 737
 
738
-	echo $html;
738
+    echo $html;
739 739
 }
740 740
 
741 741
 function wpinv_missing_callback($args) {
742
-	printf(
743
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
744
-		'<strong>' . $args['id'] . '</strong>'
745
-	);
742
+    printf(
743
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
744
+        '<strong>' . $args['id'] . '</strong>'
745
+    );
746 746
 }
747 747
 
748 748
 /**
@@ -750,14 +750,14 @@  discard block
 block discarded – undo
750 750
  */
751 751
 function wpinv_select_callback( $args ) {
752 752
 
753
-	$desc   = wp_kses_post( $args['desc'] );
754
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
755
-	$attr   = wpinv_settings_attrs_helper( $args );
756
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
757
-	$value  = wpinv_get_option( $args['id'], $value );
758
-	$rand   = uniqid( 'random_id' );
753
+    $desc   = wp_kses_post( $args['desc'] );
754
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
755
+    $attr   = wpinv_settings_attrs_helper( $args );
756
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
757
+    $value  = wpinv_get_option( $args['id'], $value );
758
+    $rand   = uniqid( 'random_id' );
759 759
 
760
-	?>
760
+    ?>
761 761
 		<label style="width: 100%;">
762 762
 			<select <?php echo $attr; ?>>
763 763
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -790,104 +790,104 @@  discard block
 block discarded – undo
790 790
 function wpinv_color_select_callback( $args ) {
791 791
     
792 792
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
793
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
794
-	$value   = wpinv_get_option( $args['id'], $std );
793
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
794
+    $value   = wpinv_get_option( $args['id'], $std );
795 795
 
796
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
796
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
797 797
 
798
-	foreach ( $args['options'] as $option => $color ) {
799
-		$selected = selected( $option, $value, false );
800
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
801
-	}
798
+    foreach ( $args['options'] as $option => $color ) {
799
+        $selected = selected( $option, $value, false );
800
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
801
+    }
802 802
 
803
-	$html .= '</select>';
804
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
803
+    $html .= '</select>';
804
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
805 805
 
806
-	echo $html;
806
+    echo $html;
807 807
 }
808 808
 
809 809
 function wpinv_rich_editor_callback( $args ) {
810
-	global $wp_version;
810
+    global $wp_version;
811 811
     
812 812
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
813 813
 
814
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
815
-	$value   = wpinv_get_option( $args['id'], $std );
814
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
815
+    $value   = wpinv_get_option( $args['id'], $std );
816 816
 	
817
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
818
-		$value = $std;
819
-	}
817
+    if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
818
+        $value = $std;
819
+    }
820 820
 
821
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
821
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
822 822
 
823
-	$html = '<div class="getpaid-settings-editor-input">';
824
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
825
-		ob_start();
826
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
827
-		$html .= ob_get_clean();
828
-	} else {
829
-		$html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
830
-	}
823
+    $html = '<div class="getpaid-settings-editor-input">';
824
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
825
+        ob_start();
826
+        wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
827
+        $html .= ob_get_clean();
828
+    } else {
829
+        $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
830
+    }
831 831
 
832
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
832
+    $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
833 833
 
834
-	echo $html;
834
+    echo $html;
835 835
 }
836 836
 
837 837
 function wpinv_upload_callback( $args ) {
838 838
     
839 839
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
840 840
 
841
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
842
-	$value   = wpinv_get_option( $args['id'], $std );
841
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
842
+    $value   = wpinv_get_option( $args['id'], $std );
843 843
 
844
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
845
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
846
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
847
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
844
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
845
+    $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
846
+    $html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
847
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
848 848
 
849
-	echo $html;
849
+    echo $html;
850 850
 }
851 851
 
852 852
 function wpinv_color_callback( $args ) {
853 853
 
854
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
855
-	$value       = wpinv_get_option( $args['id'], $std );
854
+    $std         = isset( $args['std'] ) ? $args['std'] : '';
855
+    $value       = wpinv_get_option( $args['id'], $std );
856 856
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
857 857
 
858
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
859
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
858
+    $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
859
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
860 860
 
861
-	echo $html;
861
+    echo $html;
862 862
 }
863 863
 
864 864
 function wpinv_country_states_callback($args) {
865 865
 
866
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
867
-	$value   = wpinv_get_option( $args['id'], $std );
866
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
867
+    $value   = wpinv_get_option( $args['id'], $std );
868 868
 
869 869
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
870 870
 
871
-	if ( isset( $args['placeholder'] ) ) {
872
-		$placeholder = $args['placeholder'];
873
-	} else {
874
-		$placeholder = '';
875
-	}
871
+    if ( isset( $args['placeholder'] ) ) {
872
+        $placeholder = $args['placeholder'];
873
+    } else {
874
+        $placeholder = '';
875
+    }
876 876
 
877
-	$states = wpinv_get_country_states();
877
+    $states = wpinv_get_country_states();
878 878
 
879
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
880
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
879
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
880
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
881 881
 
882
-	foreach ( $states as $option => $name ) {
883
-		$selected = selected( $option, $value, false );
884
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
885
-	}
882
+    foreach ( $states as $option => $name ) {
883
+        $selected = selected( $option, $value, false );
884
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
885
+    }
886 886
 
887
-	$html .= '</select>';
888
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
887
+    $html .= '</select>';
888
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
889 889
 
890
-	echo $html;
890
+    echo $html;
891 891
 }
892 892
 
893 893
 /**
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
  */
896 896
 function wpinv_tax_rates_callback() {
897 897
 	
898
-	?>
898
+    ?>
899 899
 		</td>
900 900
 	</tr>
901 901
 	<tr class="bsui">
@@ -910,17 +910,17 @@  discard block
 block discarded – undo
910 910
  * Displays a tax rate' edit row.
911 911
  */
912 912
 function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) {
913
-	ob_start();
913
+    ob_start();
914 914
 
915
-	$key                      = sanitize_key( $key );
916
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
917
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
915
+    $key                      = sanitize_key( $key );
916
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
917
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
918 918
 
919
-	if ( $echo ) {
920
-		echo ob_get_clean();
921
-	} else {
922
-		return ob_get_clean(); 
923
-	}
919
+    if ( $echo ) {
920
+        echo ob_get_clean();
921
+    } else {
922
+        return ob_get_clean(); 
923
+    }
924 924
 
925 925
 }
926 926
 
@@ -948,14 +948,14 @@  discard block
 block discarded – undo
948 948
                 </td>
949 949
                 <td>
950 950
 					<a href="<?php
951
-						echo esc_url(
952
-							wp_nonce_url(
953
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
954
-								'getpaid-nonce',
955
-								'getpaid-nonce'
956
-							)
957
-						);
958
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
951
+                        echo esc_url(
952
+                            wp_nonce_url(
953
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
954
+                                'getpaid-nonce',
955
+                                'getpaid-nonce'
956
+                            )
957
+                        );
958
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
959 959
                 </td>
960 960
             </tr>
961 961
 			<tr>
@@ -965,14 +965,14 @@  discard block
 block discarded – undo
965 965
                 </td>
966 966
                 <td>
967 967
 					<a href="<?php
968
-						echo esc_url(
969
-							wp_nonce_url(
970
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
971
-								'getpaid-nonce',
972
-								'getpaid-nonce'
973
-							)
974
-						);
975
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
968
+                        echo esc_url(
969
+                            wp_nonce_url(
970
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
971
+                                'getpaid-nonce',
972
+                                'getpaid-nonce'
973
+                            )
974
+                        );
975
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
976 976
                 </td>
977 977
             </tr>
978 978
 			<tr>
@@ -982,14 +982,14 @@  discard block
 block discarded – undo
982 982
                 </td>
983 983
                 <td>
984 984
 					<a href="<?php
985
-						echo esc_url(
986
-							wp_nonce_url(
987
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
988
-								'getpaid-nonce',
989
-								'getpaid-nonce'
990
-							)
991
-						);
992
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
985
+                        echo esc_url(
986
+                            wp_nonce_url(
987
+                                add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
988
+                                'getpaid-nonce',
989
+                                'getpaid-nonce'
990
+                            )
991
+                        );
992
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
993 993
                 </td>
994 994
             </tr>
995 995
 
@@ -1000,14 +1000,14 @@  discard block
 block discarded – undo
1000 1000
                 </td>
1001 1001
                 <td>
1002 1002
 					<a href="<?php
1003
-						echo esc_url(
1004
-							wp_nonce_url(
1005
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1006
-								'getpaid-nonce',
1007
-								'getpaid-nonce'
1008
-							)
1009
-						);
1010
-					?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a>
1003
+                        echo esc_url(
1004
+                            wp_nonce_url(
1005
+                                add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1006
+                                'getpaid-nonce',
1007
+                                'getpaid-nonce'
1008
+                            )
1009
+                        );
1010
+                    ?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a>
1011 1011
                 </td>
1012 1012
             </tr>
1013 1013
 
@@ -1021,19 +1021,19 @@  discard block
 block discarded – undo
1021 1021
 
1022 1022
 
1023 1023
 function wpinv_descriptive_text_callback( $args ) {
1024
-	echo wp_kses_post( $args['desc'] );
1024
+    echo wp_kses_post( $args['desc'] );
1025 1025
 }
1026 1026
 
1027 1027
 function wpinv_raw_html_callback( $args ) {
1028
-	echo $args['desc'];
1028
+    echo $args['desc'];
1029 1029
 }
1030 1030
 
1031 1031
 function wpinv_hook_callback( $args ) {
1032
-	do_action( 'wpinv_' . $args['id'], $args );
1032
+    do_action( 'wpinv_' . $args['id'], $args );
1033 1033
 }
1034 1034
 
1035 1035
 function wpinv_set_settings_cap() {
1036
-	return wpinv_get_capability();
1036
+    return wpinv_get_capability();
1037 1037
 }
1038 1038
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1039 1039
 
@@ -1057,15 +1057,15 @@  discard block
 block discarded – undo
1057 1057
  */
1058 1058
 function wpinv_get_merge_tags_help_text( $subscription = false ) {
1059 1059
 
1060
-	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1061
-	$link = sprintf(
1062
-		'<strong><a href="%s" target="_blank">%s</a></strong>',
1063
-		$url,
1064
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1065
-	);
1060
+    $url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1061
+    $link = sprintf(
1062
+        '<strong><a href="%s" target="_blank">%s</a></strong>',
1063
+        $url,
1064
+        esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1065
+    );
1066 1066
 
1067
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1067
+    $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1068 1068
 
1069
-	return "$description $link";
1069
+    return "$description $link";
1070 1070
 
1071 1071
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +535 added lines, -535 removed lines patch added patch discarded remove patch
@@ -14,89 +14,89 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29 29
 	
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct(){
38
+     * Class constructor.
39
+     */
40
+    public function __construct(){
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect') );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66 66
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
74
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
75
-		do_action( 'getpaid_init_admin_hooks', $this );
76
-
77
-		// Setup/welcome
78
-		if ( ! empty( $_GET['page'] ) ) {
79
-			switch ( $_GET['page'] ) {
80
-				case 'gp-setup' :
81
-					include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
82
-					break;
83
-			}
84
-		}
67
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
70
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
71
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
74
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
75
+        do_action( 'getpaid_init_admin_hooks', $this );
76
+
77
+        // Setup/welcome
78
+        if ( ! empty( $_GET['page'] ) ) {
79
+            switch ( $_GET['page'] ) {
80
+                case 'gp-setup' :
81
+                    include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
82
+                    break;
83
+            }
84
+        }
85 85
 
86 86
     }
87 87
 
88 88
     /**
89
-	 * Register admin scripts
90
-	 *
91
-	 */
92
-	public function enqeue_scripts() {
89
+     * Register admin scripts
90
+     *
91
+     */
92
+    public function enqeue_scripts() {
93 93
         global $current_screen, $pagenow;
94 94
 
95
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
96
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
95
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
96
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
97 97
 
98 98
         if ( ! empty( $current_screen->post_type ) ) {
99
-			$page = $current_screen->post_type;
99
+            $page = $current_screen->post_type;
100 100
         }
101 101
 
102 102
         // General styles.
@@ -117,54 +117,54 @@  discard block
 block discarded – undo
117 117
         }
118 118
 
119 119
         // Payment form scripts.
120
-		if ( 'wpi_payment_form' == $page && $editing ) {
120
+        if ( 'wpi_payment_form' == $page && $editing ) {
121 121
             $this->load_payment_form_scripts();
122 122
         }
123 123
 
124
-		if ( $page == 'wpinv-subscriptions' ) {
125
-			wp_enqueue_script( 'postbox' );
126
-		}
124
+        if ( $page == 'wpinv-subscriptions' ) {
125
+            wp_enqueue_script( 'postbox' );
126
+        }
127 127
 
128 128
     }
129 129
 
130 130
     /**
131
-	 * Returns admin js translations.
132
-	 *
133
-	 */
134
-	protected function get_admin_i18() {
131
+     * Returns admin js translations.
132
+     *
133
+     */
134
+    protected function get_admin_i18() {
135 135
         global $post;
136 136
 
137
-		$date_range = array(
138
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
139
-		);
137
+        $date_range = array(
138
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
139
+        );
140 140
 
141
-		if ( $date_range['period'] == 'custom' ) {
141
+        if ( $date_range['period'] == 'custom' ) {
142 142
 			
143
-			if ( isset( $_GET['from'] ) ) {
144
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
145
-			}
143
+            if ( isset( $_GET['from'] ) ) {
144
+                $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
145
+            }
146 146
 
147
-			if ( isset( $_GET['to'] ) ) {
148
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
149
-			}
147
+            if ( isset( $_GET['to'] ) ) {
148
+                $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
149
+            }
150 150
 
151
-		}
151
+        }
152 152
 
153 153
         $i18n = array(
154 154
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
155 155
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
156
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
157
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
158
-			'rest_root'                 => esc_url_raw( rest_url() ),
159
-			'date_range'                => $date_range,
156
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
157
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
158
+            'rest_root'                 => esc_url_raw( rest_url() ),
159
+            'date_range'                => $date_range,
160 160
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
161 161
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
162 162
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
163 163
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
164 164
             'tax'                       => wpinv_tax_amount(),
165 165
             'discount'                  => 0,
166
-			'currency_symbol'           => wpinv_currency_symbol(),
167
-			'currency'                  => wpinv_get_currency(),
166
+            'currency_symbol'           => wpinv_currency_symbol(),
167
+            'currency'                  => wpinv_get_currency(),
168 168
             'currency_pos'              => wpinv_currency_position(),
169 169
             'thousand_sep'              => wpinv_thousands_separator(),
170 170
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -184,118 +184,118 @@  discard block
 block discarded – undo
184 184
             'item_description'          => __( 'Item Description', 'invoicing' ),
185 185
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
186 186
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
187
-			'searching'                 => __( 'Searching', 'invoicing' ),
188
-			'loading'                   => __( 'Loading...', 'invoicing' ),
189
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
190
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
187
+            'searching'                 => __( 'Searching', 'invoicing' ),
188
+            'loading'                   => __( 'Loading...', 'invoicing' ),
189
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
190
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
191 191
         );
192 192
 
193
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
193
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
194 194
 
195
-			$invoice              = new WPInv_Invoice( $post );
196
-			$i18n['save_invoice'] = sprintf(
197
-				__( 'Save %s', 'invoicing' ),
198
-				ucfirst( $invoice->get_invoice_quote_type() )
199
-			);
195
+            $invoice              = new WPInv_Invoice( $post );
196
+            $i18n['save_invoice'] = sprintf(
197
+                __( 'Save %s', 'invoicing' ),
198
+                ucfirst( $invoice->get_invoice_quote_type() )
199
+            );
200 200
 
201
-			$i18n['invoice_description'] = sprintf(
202
-				__( '%s Description', 'invoicing' ),
203
-				ucfirst( $invoice->get_invoice_quote_type() )
204
-			);
201
+            $i18n['invoice_description'] = sprintf(
202
+                __( '%s Description', 'invoicing' ),
203
+                ucfirst( $invoice->get_invoice_quote_type() )
204
+            );
205 205
 
206
-		}
207
-		return $i18n;
208
-	}
206
+        }
207
+        return $i18n;
208
+    }
209 209
 
210
-	/**
211
-	 * Change the admin footer text on GetPaid admin pages.
212
-	 *
213
-	 * @since  2.0.0
214
-	 * @param  string $footer_text
215
-	 * @return string
216
-	 */
217
-	public function admin_footer_text( $footer_text ) {
218
-		global $current_screen;
210
+    /**
211
+     * Change the admin footer text on GetPaid admin pages.
212
+     *
213
+     * @since  2.0.0
214
+     * @param  string $footer_text
215
+     * @return string
216
+     */
217
+    public function admin_footer_text( $footer_text ) {
218
+        global $current_screen;
219 219
 
220
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
220
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
221 221
 
222 222
         if ( ! empty( $current_screen->post_type ) ) {
223
-			$page = $current_screen->post_type;
223
+            $page = $current_screen->post_type;
224 224
         }
225 225
 
226 226
         // General styles.
227 227
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
228 228
 
229
-			// Change the footer text
230
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
231
-
232
-				$rating_url  = esc_url(
233
-					wp_nonce_url(
234
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
235
-						'getpaid-nonce',
236
-						'getpaid-nonce'
237
-						)
238
-				);
239
-
240
-				$footer_text = sprintf(
241
-					/* translators: %s: five stars */
242
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
243
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
244
-				);
245
-
246
-			} else {
247
-
248
-				$footer_text = sprintf(
249
-					/* translators: %s: GetPaid */
250
-					__( 'Thank you for using %s!', 'invoicing' ),
251
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
252
-				);
253
-
254
-			}
255
-
256
-		}
257
-
258
-		return $footer_text;
259
-	}
260
-
261
-	/**
262
-	 * Redirects to wp.org to rate the plugin.
263
-	 *
264
-	 * @since  2.0.0
265
-	 */
266
-	public function redirect_to_wordpress_rating_page() {
267
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
268
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
269
-		exit;
270
-	}
271
-
272
-    /**
273
-	 * Loads payment form js.
274
-	 *
275
-	 */
276
-	protected function load_payment_form_scripts() {
229
+            // Change the footer text
230
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
231
+
232
+                $rating_url  = esc_url(
233
+                    wp_nonce_url(
234
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
235
+                        'getpaid-nonce',
236
+                        'getpaid-nonce'
237
+                        )
238
+                );
239
+
240
+                $footer_text = sprintf(
241
+                    /* translators: %s: five stars */
242
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
243
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
244
+                );
245
+
246
+            } else {
247
+
248
+                $footer_text = sprintf(
249
+                    /* translators: %s: GetPaid */
250
+                    __( 'Thank you for using %s!', 'invoicing' ),
251
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
252
+                );
253
+
254
+            }
255
+
256
+        }
257
+
258
+        return $footer_text;
259
+    }
260
+
261
+    /**
262
+     * Redirects to wp.org to rate the plugin.
263
+     *
264
+     * @since  2.0.0
265
+     */
266
+    public function redirect_to_wordpress_rating_page() {
267
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
268
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
269
+        exit;
270
+    }
271
+
272
+    /**
273
+     * Loads payment form js.
274
+     *
275
+     */
276
+    protected function load_payment_form_scripts() {
277 277
         global $post;
278 278
 
279 279
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
280
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
281
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
280
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
281
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
282 282
 
283
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
284
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
283
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
284
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
285 285
 
286
-		wp_localize_script(
286
+        wp_localize_script(
287 287
             'wpinv-admin-payment-form-script',
288 288
             'wpinvPaymentFormAdmin',
289 289
             array(
290
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
291
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
292
-				'currency'      => wpinv_currency_symbol(),
293
-				'position'      => wpinv_currency_position(),
294
-				'decimals'      => (int) wpinv_decimals(),
295
-				'thousands_sep' => wpinv_thousands_separator(),
296
-				'decimals_sep'  => wpinv_decimal_separator(),
297
-				'form_items'    => gepaid_get_form_items( $post->ID ),
298
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
290
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
291
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
292
+                'currency'      => wpinv_currency_symbol(),
293
+                'position'      => wpinv_currency_position(),
294
+                'decimals'      => (int) wpinv_decimals(),
295
+                'thousands_sep' => wpinv_thousands_separator(),
296
+                'decimals_sep'  => wpinv_decimal_separator(),
297
+                'form_items'    => gepaid_get_form_items( $post->ID ),
298
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
299 299
             )
300 300
         );
301 301
 
@@ -304,20 +304,20 @@  discard block
 block discarded – undo
304 304
     }
305 305
 
306 306
     /**
307
-	 * Add our classes to admin pages.
307
+     * Add our classes to admin pages.
308 308
      *
309 309
      * @param string $classes
310 310
      * @return string
311
-	 *
312
-	 */
311
+     *
312
+     */
313 313
     public function admin_body_class( $classes ) {
314
-		global $pagenow, $post, $current_screen;
314
+        global $pagenow, $post, $current_screen;
315 315
 
316 316
 
317 317
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
318 318
 
319 319
         if ( ! empty( $current_screen->post_type ) ) {
320
-			$page = $current_screen->post_type;
320
+            $page = $current_screen->post_type;
321 321
         }
322 322
 
323 323
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -326,59 +326,59 @@  discard block
 block discarded – undo
326 326
 
327 327
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
328 328
             $classes .= ' wpinv-cpt wpinv';
329
-		}
329
+        }
330 330
 		
331
-		if ( getpaid_is_invoice_post_type( $page ) ) {
331
+        if ( getpaid_is_invoice_post_type( $page ) ) {
332 332
             $classes .= ' getpaid-is-invoice-cpt';
333 333
         }
334 334
 
335
-		return $classes;
335
+        return $classes;
336 336
     }
337 337
 
338 338
     /**
339
-	 * Maybe show the AyeCode Connect Notice.
340
-	 */
341
-	public function init_ayecode_connect_helper(){
339
+     * Maybe show the AyeCode Connect Notice.
340
+     */
341
+    public function init_ayecode_connect_helper(){
342 342
 
343 343
         new AyeCode_Connect_Helper(
344 344
             array(
345
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
346
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
347
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
348
-				'connect_button'    => __("Connect Site","invoicing"),
349
-				'connecting_button'    => __("Connecting...","invoicing"),
350
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
351
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
345
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
346
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
347
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
348
+                'connect_button'    => __("Connect Site","invoicing"),
349
+                'connecting_button'    => __("Connecting...","invoicing"),
350
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
351
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
352 352
             ),
353 353
             array( 'wpi-addons' )
354 354
         );
355 355
 
356 356
     }
357 357
 
358
-	/**
359
-	 * Redirect users to settings on activation.
360
-	 *
361
-	 * @return void
362
-	 */
363
-	public function activation_redirect() {
358
+    /**
359
+     * Redirect users to settings on activation.
360
+     *
361
+     * @return void
362
+     */
363
+    public function activation_redirect() {
364 364
 
365
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
365
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
366 366
 
367
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
368
-			return;
369
-		}
367
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
368
+            return;
369
+        }
370 370
 
371
-		// Bail if activating from network, or bulk
372
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
373
-			return;
374
-		}
371
+        // Bail if activating from network, or bulk
372
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
373
+            return;
374
+        }
375 375
 
376
-	    update_option( 'wpinv_redirected_to_settings', 1 );
376
+        update_option( 'wpinv_redirected_to_settings', 1 );
377 377
 
378 378
         wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
379 379
         exit;
380 380
 
381
-	}
381
+    }
382 382
 
383 383
     /**
384 384
      * Fires an admin action after verifying that a user can fire them.
@@ -392,458 +392,458 @@  discard block
 block discarded – undo
392 392
 
393 393
     }
394 394
 
395
-	/**
395
+    /**
396 396
      * Sends a payment reminder to a customer.
397
-	 * 
398
-	 * @param array $args
397
+     * 
398
+     * @param array $args
399 399
      */
400 400
     public function send_customer_invoice( $args ) {
401
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
401
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
402 402
 
403
-		if ( $sent ) {
404
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
405
-		} else {
406
-			$this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
407
-		}
403
+        if ( $sent ) {
404
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
405
+        } else {
406
+            $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
407
+        }
408 408
 
409
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
410
-		exit;
411
-	}
409
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
410
+        exit;
411
+    }
412 412
 
413
-	/**
413
+    /**
414 414
      * Sends a payment reminder to a customer.
415
-	 * 
416
-	 * @param array $args
415
+     * 
416
+     * @param array $args
417 417
      */
418 418
     public function send_customer_payment_reminder( $args ) {
419
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
419
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
420 420
 
421
-		if ( $sent ) {
422
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
423
-		} else {
424
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
425
-		}
421
+        if ( $sent ) {
422
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
423
+        } else {
424
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
425
+        }
426 426
 
427
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
428
-		exit;
429
-	}
427
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
428
+        exit;
429
+    }
430 430
 
431
-	/**
431
+    /**
432 432
      * Resets tax rates.
433
-	 * 
433
+     * 
434 434
      */
435 435
     public function admin_reset_tax_rates() {
436 436
 
437
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
438
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
439
-		exit;
437
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
438
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
439
+        exit;
440 440
 
441
-	}
441
+    }
442 442
 
443
-	/**
443
+    /**
444 444
      * Resets admin pages.
445
-	 * 
445
+     * 
446 446
      */
447 447
     public function admin_create_missing_pages() {
448
-		$installer = new GetPaid_Installer();
449
-		$installer->create_pages();
450
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
451
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
452
-		exit;
453
-	}
454
-
455
-	/**
448
+        $installer = new GetPaid_Installer();
449
+        $installer->create_pages();
450
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
451
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
452
+        exit;
453
+    }
454
+
455
+    /**
456 456
      * Creates an missing admin tables.
457
-	 * 
457
+     * 
458 458
      */
459 459
     public function admin_create_missing_tables() {
460
-		global $wpdb;
461
-		$installer = new GetPaid_Installer();
460
+        global $wpdb;
461
+        $installer = new GetPaid_Installer();
462 462
 
463
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
464
-			$installer->create_subscriptions_table();
463
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
464
+            $installer->create_subscriptions_table();
465 465
 
466
-			if ( $wpdb->last_error !== '' ) {
467
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
468
-			}
469
-		}
466
+            if ( $wpdb->last_error !== '' ) {
467
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
468
+            }
469
+        }
470 470
 
471
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
472
-			$installer->create_invoices_table();
471
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
472
+            $installer->create_invoices_table();
473 473
 
474
-			if ( $wpdb->last_error !== '' ) {
475
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
476
-			}
477
-		}
474
+            if ( $wpdb->last_error !== '' ) {
475
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
476
+            }
477
+        }
478 478
 
479
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
480
-			$installer->create_invoice_items_table();
479
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
480
+            $installer->create_invoice_items_table();
481 481
 
482
-			if ( $wpdb->last_error !== '' ) {
483
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
484
-			}
485
-		}
482
+            if ( $wpdb->last_error !== '' ) {
483
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
484
+            }
485
+        }
486 486
 
487
-		if ( ! $this->has_notices() ) {
488
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
489
-		}
487
+        if ( ! $this->has_notices() ) {
488
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
489
+        }
490 490
 
491
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
492
-		exit;
493
-	}
491
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
492
+        exit;
493
+    }
494 494
 
495
-	/**
495
+    /**
496 496
      * Migrates old invoices to the new database tables.
497
-	 * 
497
+     * 
498 498
      */
499 499
     public function admin_migrate_old_invoices() {
500 500
 
501
-		// Migrate the invoices.
502
-		$installer = new GetPaid_Installer();
503
-		$installer->migrate_old_invoices();
501
+        // Migrate the invoices.
502
+        $installer = new GetPaid_Installer();
503
+        $installer->migrate_old_invoices();
504 504
 
505
-		// Show an admin message.
506
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
505
+        // Show an admin message.
506
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
507 507
 
508
-		// Redirect the admin.
509
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
510
-		exit;
508
+        // Redirect the admin.
509
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
510
+        exit;
511 511
 
512
-	}
512
+    }
513 513
 
514
-	/**
514
+    /**
515 515
      * Download customers.
516
-	 * 
516
+     * 
517 517
      */
518 518
     public function admin_download_customers() {
519
-		global $wpdb;
519
+        global $wpdb;
520 520
 
521
-		$output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
521
+        $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
522 522
 
523
-		header( "Content-Type:text/csv" );
524
-		header( "Content-Disposition:attachment;filename=customers.csv" );
523
+        header( "Content-Type:text/csv" );
524
+        header( "Content-Disposition:attachment;filename=customers.csv" );
525 525
 
526
-		$post_types = '';
526
+        $post_types = '';
527 527
 
528
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
529
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
530
-		}
528
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
529
+            $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
530
+        }
531 531
 
532
-		$post_types = rtrim( $post_types, ' OR' );
532
+        $post_types = rtrim( $post_types, ' OR' );
533 533
 
534
-		$customers = $wpdb->get_col(
535
-			$wpdb->prepare(
536
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
537
-			)
538
-		);
534
+        $customers = $wpdb->get_col(
535
+            $wpdb->prepare(
536
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
537
+            )
538
+        );
539 539
 
540
-		$columns = array(
541
-			'name'     => __( 'Name', 'invoicing' ),
542
-			'email'    => __( 'Email', 'invoicing' ),
543
-			'country'  => __( 'Country', 'invoicing' ),
544
-			'state'    => __( 'State', 'invoicing' ),
545
-			'city'     => __( 'City', 'invoicing' ),
546
-			'zip'      => __( 'ZIP', 'invoicing' ),
547
-			'address'  => __( 'Address', 'invoicing' ),
548
-			'phone'    => __( 'Phone', 'invoicing' ),
549
-			'company'  => __( 'Company', 'invoicing' ),
550
-			'invoices' => __( 'Invoices', 'invoicing' ),
551
-			'total'    => __( 'Total Spend', 'invoicing' ),
552
-			'signup'   => __( 'Date created', 'invoicing' ),
553
-		);
540
+        $columns = array(
541
+            'name'     => __( 'Name', 'invoicing' ),
542
+            'email'    => __( 'Email', 'invoicing' ),
543
+            'country'  => __( 'Country', 'invoicing' ),
544
+            'state'    => __( 'State', 'invoicing' ),
545
+            'city'     => __( 'City', 'invoicing' ),
546
+            'zip'      => __( 'ZIP', 'invoicing' ),
547
+            'address'  => __( 'Address', 'invoicing' ),
548
+            'phone'    => __( 'Phone', 'invoicing' ),
549
+            'company'  => __( 'Company', 'invoicing' ),
550
+            'invoices' => __( 'Invoices', 'invoicing' ),
551
+            'total'    => __( 'Total Spend', 'invoicing' ),
552
+            'signup'   => __( 'Date created', 'invoicing' ),
553
+        );
554 554
 
555
-		// Output the csv column headers.
556
-		fputcsv( $output, array_values( $columns ) );
555
+        // Output the csv column headers.
556
+        fputcsv( $output, array_values( $columns ) );
557 557
 
558
-		// Loop through
559
-		$table = new WPInv_Customers_Table();
560
-		foreach ( $customers as $customer_id ) {
558
+        // Loop through
559
+        $table = new WPInv_Customers_Table();
560
+        foreach ( $customers as $customer_id ) {
561 561
 
562
-			$user = get_user_by( 'id', $customer_id );
563
-			$row  = array();
564
-			if ( empty( $user ) ) {
565
-				continue;
566
-			}
562
+            $user = get_user_by( 'id', $customer_id );
563
+            $row  = array();
564
+            if ( empty( $user ) ) {
565
+                continue;
566
+            }
567 567
 
568
-			foreach ( array_keys( $columns ) as $column ) {
568
+            foreach ( array_keys( $columns ) as $column ) {
569 569
 
570
-				$method = 'column_' . $column;
570
+                $method = 'column_' . $column;
571 571
 
572
-				if ( 'name' == $column ) {
573
-					$value = sanitize_text_field( $user->display_name );
574
-				} else if( 'email' == $column ) {
575
-					$value = sanitize_email( $user->user_email );
576
-				} else if ( is_callable( array( $table, $method ) ) ) {
577
-					$value = strip_tags( $table->$method( $user ) );
578
-				}
572
+                if ( 'name' == $column ) {
573
+                    $value = sanitize_text_field( $user->display_name );
574
+                } else if( 'email' == $column ) {
575
+                    $value = sanitize_email( $user->user_email );
576
+                } else if ( is_callable( array( $table, $method ) ) ) {
577
+                    $value = strip_tags( $table->$method( $user ) );
578
+                }
579 579
 
580
-				if ( empty( $value ) ) {
581
-					$value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
582
-				}
580
+                if ( empty( $value ) ) {
581
+                    $value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
582
+                }
583 583
 
584
-				$row[] = $value;
584
+                $row[] = $value;
585 585
 
586
-			}
586
+            }
587 587
 
588
-			fputcsv( $output, $row );
589
-		}
588
+            fputcsv( $output, $row );
589
+        }
590 590
 
591
-		fclose( $output );
592
-		exit;
591
+        fclose( $output );
592
+        exit;
593 593
 
594
-	}
594
+    }
595 595
 
596
-	/**
596
+    /**
597 597
      * Installs a plugin.
598
-	 *
599
-	 * @param array $data
598
+     *
599
+     * @param array $data
600 600
      */
601 601
     public function admin_install_plugin( $data ) {
602 602
 
603
-		if ( ! empty( $data['plugins'] ) ) {
604
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
605
-			wp_cache_flush();
603
+        if ( ! empty( $data['plugins'] ) ) {
604
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
605
+            wp_cache_flush();
606 606
 
607
-			foreach ( $data['plugins'] as $slug => $file ) {
608
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
609
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
610
-				$installed  = $upgrader->install( $plugin_zip );
607
+            foreach ( $data['plugins'] as $slug => $file ) {
608
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
609
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
610
+                $installed  = $upgrader->install( $plugin_zip );
611 611
 
612
-				if ( ! is_wp_error( $installed ) && $installed ) {
613
-					activate_plugin( $file, '', false, true );
614
-				} else {
615
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
616
-				}
612
+                if ( ! is_wp_error( $installed ) && $installed ) {
613
+                    activate_plugin( $file, '', false, true );
614
+                } else {
615
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
616
+                }
617 617
 
618
-			}
618
+            }
619 619
 
620
-		}
620
+        }
621 621
 
622
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
623
-		wp_safe_redirect( $redirect );
624
-		exit;
622
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
623
+        wp_safe_redirect( $redirect );
624
+        exit;
625 625
 
626
-	}
626
+    }
627 627
 
628
-	/**
628
+    /**
629 629
      * Connects a gateway.
630
-	 *
631
-	 * @param array $data
630
+     *
631
+     * @param array $data
632 632
      */
633 633
     public function admin_connect_gateway( $data ) {
634 634
 
635
-		if ( ! empty( $data['plugin'] ) ) {
635
+        if ( ! empty( $data['plugin'] ) ) {
636 636
 
637
-			$gateway     = sanitize_key( $data['plugin'] );
638
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
637
+            $gateway     = sanitize_key( $data['plugin'] );
638
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
639 639
 
640
-			if ( ! empty( $connect_url ) ) {
641
-				wp_redirect( $connect_url );
642
-				exit;
643
-			}
640
+            if ( ! empty( $connect_url ) ) {
641
+                wp_redirect( $connect_url );
642
+                exit;
643
+            }
644 644
 
645
-			if ( 'stripe' == $data['plugin'] ) {
646
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
645
+            if ( 'stripe' == $data['plugin'] ) {
646
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
647 647
 
648
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
649
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
650
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
651
-					$upgrader->install( $plugin_zip );
652
-				}
648
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
649
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
650
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
651
+                    $upgrader->install( $plugin_zip );
652
+                }
653 653
 
654
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
655
-			}
654
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
655
+            }
656 656
 
657
-			if ( ! empty( $connect_url ) ) {
658
-				wp_redirect( $connect_url );
659
-				exit;
660
-			}
657
+            if ( ! empty( $connect_url ) ) {
658
+                wp_redirect( $connect_url );
659
+                exit;
660
+            }
661 661
 
662
-		}
662
+        }
663 663
 
664
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
665
-		wp_safe_redirect( $redirect );
666
-		exit;
664
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
665
+        wp_safe_redirect( $redirect );
666
+        exit;
667 667
 
668
-	}
668
+    }
669 669
 
670
-	/**
670
+    /**
671 671
      * Recalculates discounts.
672
-	 * 
672
+     * 
673 673
      */
674 674
     public function admin_recalculate_discounts() {
675
-		global $wpdb;
675
+        global $wpdb;
676 676
 
677
-		// Fetch all invoices that have discount codes.
678
-		$table    = $wpdb->prefix . 'getpaid_invoices';
679
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
677
+        // Fetch all invoices that have discount codes.
678
+        $table    = $wpdb->prefix . 'getpaid_invoices';
679
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
680 680
 
681
-		foreach ( $invoices as $invoice ) {
681
+        foreach ( $invoices as $invoice ) {
682 682
 
683
-			$invoice = new WPInv_Invoice( $invoice );
683
+            $invoice = new WPInv_Invoice( $invoice );
684 684
 
685
-			if ( ! $invoice->exists() ) {
686
-				continue;
687
-			}
685
+            if ( ! $invoice->exists() ) {
686
+                continue;
687
+            }
688 688
 
689
-			// Abort if the discount does not exist or does not apply here.
690
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
691
-			if ( ! $discount->exists() ) {
692
-				continue;
693
-			}
689
+            // Abort if the discount does not exist or does not apply here.
690
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
691
+            if ( ! $discount->exists() ) {
692
+                continue;
693
+            }
694 694
 
695
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
696
-			$invoice->recalculate_total();
695
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
696
+            $invoice->recalculate_total();
697 697
 
698
-			if ( $invoice->get_total_discount() > 0 ) {
699
-				$invoice->save();
700
-			}
698
+            if ( $invoice->get_total_discount() > 0 ) {
699
+                $invoice->save();
700
+            }
701 701
 
702
-		}
702
+        }
703 703
 
704
-		// Show an admin message.
705
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
704
+        // Show an admin message.
705
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
706 706
 
707
-		// Redirect the admin.
708
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
709
-		exit;
707
+        // Redirect the admin.
708
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
709
+        exit;
710 710
 
711
-	}
711
+    }
712 712
 
713 713
     /**
714
-	 * Returns an array of admin notices.
715
-	 *
716
-	 * @since       1.0.19
714
+     * Returns an array of admin notices.
715
+     *
716
+     * @since       1.0.19
717 717
      * @return array
718
-	 */
719
-	public function get_notices() {
720
-		$notices = get_option( 'wpinv_admin_notices' );
718
+     */
719
+    public function get_notices() {
720
+        $notices = get_option( 'wpinv_admin_notices' );
721 721
         return is_array( $notices ) ? $notices : array();
722
-	}
722
+    }
723 723
 
724
-	/**
725
-	 * Checks if we have any admin notices.
726
-	 *
727
-	 * @since       2.0.4
724
+    /**
725
+     * Checks if we have any admin notices.
726
+     *
727
+     * @since       2.0.4
728 728
      * @return array
729
-	 */
730
-	public function has_notices() {
731
-		return count( $this->get_notices() ) > 0;
732
-	}
733
-
734
-	/**
735
-	 * Clears all admin notices
736
-	 *
737
-	 * @access      public
738
-	 * @since       1.0.19
739
-	 */
740
-	public function clear_notices() {
741
-		delete_option( 'wpinv_admin_notices' );
742
-	}
743
-
744
-	/**
745
-	 * Saves a new admin notice
746
-	 *
747
-	 * @access      public
748
-	 * @since       1.0.19
749
-	 */
750
-	public function save_notice( $type, $message ) {
751
-		$notices = $this->get_notices();
752
-
753
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
754
-			$notices[ $type ] = array();
755
-		}
756
-
757
-		$notices[ $type ][] = $message;
758
-
759
-		update_option( 'wpinv_admin_notices', $notices );
760
-	}
761
-
762
-	/**
763
-	 * Displays a success notice
764
-	 *
765
-	 * @param       string $msg The message to qeue.
766
-	 * @access      public
767
-	 * @since       1.0.19
768
-	 */
769
-	public function show_success( $msg ) {
770
-		$this->save_notice( 'success', $msg );
771
-	}
772
-
773
-	/**
774
-	 * Displays a error notice
775
-	 *
776
-	 * @access      public
777
-	 * @param       string $msg The message to qeue.
778
-	 * @since       1.0.19
779
-	 */
780
-	public function show_error( $msg ) {
781
-		$this->save_notice( 'error', $msg );
782
-	}
783
-
784
-	/**
785
-	 * Displays a warning notice
786
-	 *
787
-	 * @access      public
788
-	 * @param       string $msg The message to qeue.
789
-	 * @since       1.0.19
790
-	 */
791
-	public function show_warning( $msg ) {
792
-		$this->save_notice( 'warning', $msg );
793
-	}
794
-
795
-	/**
796
-	 * Displays a info notice
797
-	 *
798
-	 * @access      public
799
-	 * @param       string $msg The message to qeue.
800
-	 * @since       1.0.19
801
-	 */
802
-	public function show_info( $msg ) {
803
-		$this->save_notice( 'info', $msg );
804
-	}
805
-
806
-	/**
807
-	 * Show notices
808
-	 *
809
-	 * @access      public
810
-	 * @since       1.0.19
811
-	 */
812
-	public function show_notices() {
729
+     */
730
+    public function has_notices() {
731
+        return count( $this->get_notices() ) > 0;
732
+    }
733
+
734
+    /**
735
+     * Clears all admin notices
736
+     *
737
+     * @access      public
738
+     * @since       1.0.19
739
+     */
740
+    public function clear_notices() {
741
+        delete_option( 'wpinv_admin_notices' );
742
+    }
743
+
744
+    /**
745
+     * Saves a new admin notice
746
+     *
747
+     * @access      public
748
+     * @since       1.0.19
749
+     */
750
+    public function save_notice( $type, $message ) {
751
+        $notices = $this->get_notices();
752
+
753
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
754
+            $notices[ $type ] = array();
755
+        }
756
+
757
+        $notices[ $type ][] = $message;
758
+
759
+        update_option( 'wpinv_admin_notices', $notices );
760
+    }
761
+
762
+    /**
763
+     * Displays a success notice
764
+     *
765
+     * @param       string $msg The message to qeue.
766
+     * @access      public
767
+     * @since       1.0.19
768
+     */
769
+    public function show_success( $msg ) {
770
+        $this->save_notice( 'success', $msg );
771
+    }
772
+
773
+    /**
774
+     * Displays a error notice
775
+     *
776
+     * @access      public
777
+     * @param       string $msg The message to qeue.
778
+     * @since       1.0.19
779
+     */
780
+    public function show_error( $msg ) {
781
+        $this->save_notice( 'error', $msg );
782
+    }
783
+
784
+    /**
785
+     * Displays a warning notice
786
+     *
787
+     * @access      public
788
+     * @param       string $msg The message to qeue.
789
+     * @since       1.0.19
790
+     */
791
+    public function show_warning( $msg ) {
792
+        $this->save_notice( 'warning', $msg );
793
+    }
794
+
795
+    /**
796
+     * Displays a info notice
797
+     *
798
+     * @access      public
799
+     * @param       string $msg The message to qeue.
800
+     * @since       1.0.19
801
+     */
802
+    public function show_info( $msg ) {
803
+        $this->save_notice( 'info', $msg );
804
+    }
805
+
806
+    /**
807
+     * Show notices
808
+     *
809
+     * @access      public
810
+     * @since       1.0.19
811
+     */
812
+    public function show_notices() {
813 813
 
814 814
         $notices = $this->get_notices();
815 815
         $this->clear_notices();
816 816
 
817
-		foreach ( $notices as $type => $messages ) {
817
+        foreach ( $notices as $type => $messages ) {
818 818
 
819
-			if ( ! is_array( $messages ) ) {
820
-				continue;
821
-			}
819
+            if ( ! is_array( $messages ) ) {
820
+                continue;
821
+            }
822 822
 
823 823
             $type  = sanitize_key( $type );
824
-			foreach ( $messages as $message ) {
824
+            foreach ( $messages as $message ) {
825 825
                 $message = wp_kses_post( $message );
826
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
826
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
827 827
             }
828 828
 
829 829
         }
830 830
 
831
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
832
-
833
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
834
-				$url     = wp_nonce_url(
835
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
836
-					'getpaid-nonce',
837
-					'getpaid-nonce'
838
-				);
839
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
840
-				$message2 = __( 'Generate Pages', 'invoicing' );
841
-				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
842
-				break;
843
-			}
831
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
832
+
833
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
834
+                $url     = wp_nonce_url(
835
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
836
+                    'getpaid-nonce',
837
+                    'getpaid-nonce'
838
+                );
839
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
840
+                $message2 = __( 'Generate Pages', 'invoicing' );
841
+                echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
842
+                break;
843
+            }
844 844
 
845
-		}
845
+        }
846 846
 
847
-	}
847
+    }
848 848
 
849 849
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-setup-wizard.php 1 patch
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -17,390 +17,390 @@
 block discarded – undo
17 17
  */
18 18
 class GetPaid_Admin_Setup_Wizard {
19 19
 
20
-	/**
21
-	 * @var string Current Step
22
-	 */
23
-	protected $step = '';
24
-
25
-	/**
26
-	 * @var string|false Previous Step
27
-	 */
28
-	protected $previous_step = '';
29
-
30
-	/**
31
-	 * @var string|false Next Step
32
-	 */
33
-	protected $next_step = '';
34
-
35
-	/**
36
-	 * @var array All available steps for the setup wizard
37
-	 */
38
-	protected $steps = array();
39
-
40
-	/**
41
-	 * Class constructor.
42
-	 *
43
-	 * @since 2.4.0
44
-	 */
45
-	public function __construct() {
46
-
47
-		if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
-			add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
-			add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
-		}
51
-
52
-	}
53
-
54
-	/**
55
-	 * Add admin menus/screens.
56
-	 *
57
-	 * @since 2.4.0
58
-	 */
59
-	public function add_menu() {
60
-		add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
-	}
62
-
63
-	/**
64
-	 * Sets up the setup wizard.
65
-	 *
66
-	 * @since 2.4.0
67
-	 */
68
-	public function setup_wizard() {
69
-
70
-		if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
-			$this->setup_globals();
72
-			$this->maybe_save_current_step();
73
-			$this->display_wizard();
74
-			exit;
75
-		}
76
-
77
-	}
78
-
79
-	/**
80
-	 * Sets up class variables.
81
-	 *
82
-	 * @since 2.4.0
83
-	 */
84
-	protected function setup_globals() {
85
-		$this->steps         = $this->get_setup_steps();
86
-		$this->step          = $this->get_current_step();
87
-		$this->previous_step = $this->get_previous_step();
88
-		$this->next_step     = $this->get_next_step();
89
-	}
90
-
91
-	/**
92
-	 * Saves the current step.
93
-	 *
94
-	 * @since 2.4.0
95
-	 */
96
-	protected function maybe_save_current_step() {
97
-		if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
98
-			call_user_func( $this->steps[ $this->step ]['handler'], $this );
99
-		}
100
-	}
101
-
102
-	/**
103
-	 * Returns the setup steps.
104
-	 *
105
-	 * @since 2.4.0
106
-	 * @return array
107
-	 */
108
-	protected function get_setup_steps() {
109
-
110
-		$steps = array(
111
-
112
-			'introduction'     => array(
113
-				'name'    => __( 'Introduction', 'invoicing' ),
114
-				'view'    => array( $this, 'setup_introduction' ),
115
-				'handler' => '',
116
-			),
117
-
118
-			'business_details'             => array(
119
-				'name'    => __( "Business Details", 'invoicing' ),
120
-				'view'    => array( $this, 'setup_business' ),
121
-				'handler' => '',
122
-			),
123
-
124
-			'currency' => array(
125
-				'name'    => __( 'Currency', 'invoicing' ),
126
-				'view'    => array( $this, 'setup_currency' ),
127
-				'handler' => '',
128
-			),
129
-
130
-			'payments'        => array(
131
-				'name'    => __( 'Payment Gateways', 'invoicing' ),
132
-				'view'    => array( $this, 'setup_payments' ),
133
-				'handler' => array( $this, 'setup_payments_save' ),
134
-			),
135
-
136
-			'recommend'          => array(
137
-				'name'    => __( 'Recommend', 'invoicing' ),
138
-				'view'    => array( $this, 'setup_recommend' ),
139
-				'handler' => '',
140
-			),
141
-
142
-			'next_steps'       => array(
143
-				'name'    => __( 'Get Paid', 'invoicing' ),
144
-				'view'    => array( $this, 'setup_ready' ),
145
-				'handler' => '',
146
-			),
147
-
148
-		);
149
-
150
-		return apply_filters( 'getpaid_setup_wizard_steps', $steps );
151
-
152
-	}
153
-
154
-	/**
155
-	 * Returns the current step.
156
-	 *
157
-	 * @since 2.4.0
158
-	 * @return string
159
-	 */
160
-	protected function get_current_step() {
161
-		$step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
162
-		return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
163
-	}
164
-
165
-	/**
166
-	 * Returns the previous step.
167
-	 *
168
-	 * @since 2.4.0
169
-	 * @return string|false
170
-	 */
171
-	protected function get_previous_step() {
172
-
173
-		$previous = false;
174
-		$current  = $this->step;
175
-		foreach ( array_keys( $this->steps ) as $step ) {
176
-			if ( $current === $step ) {
177
-				return $previous;
178
-			}
179
-
180
-			$previous = $step;
181
-		}
182
-
183
-		return false;
184
-	}
185
-
186
-	/**
187
-	 * Returns the next step.
188
-	 *
189
-	 * @since 2.4.0
190
-	 * @return string|false
191
-	 */
192
-	protected function get_next_step() {
193
-
194
-		$on_current = false;
195
-		$current    = $this->step;
196
-		foreach ( array_keys( $this->steps ) as $step ) {
197
-
198
-			if ( $on_current ) {
199
-				return $step;
200
-			}
201
-
202
-			if ( $current === $step ) {
203
-				return $on_current = true;
204
-			}
205
-
206
-		}
207
-
208
-		return false;
209
-	}
210
-
211
-	/**
212
-	 * Displays the setup wizard.
213
-	 *
214
-	 * @since 2.4.0
215
-	 */
216
-	public function display_wizard() {
217
-		$this->display_header();
218
-		$this->display_current_step();
219
-		$this->display_footer();
220
-	}
221
-
222
-	/**
223
-	 * Displays the Wizard Header.
224
-	 *
225
-	 * @since 2.0.0
226
-	 */
227
-	public function display_header() {
228
-		$steps     = $this->steps;
229
-		$current   = $this->step;
230
-		$next_step = $this->next_step;
231
-		array_shift( $steps );
232
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
233
-	}
234
-
235
-	/**
236
-	 * Displays the content for the current step.
237
-	 *
238
-	 * @since 2.4.0
239
-	 */
240
-	public function display_current_step() {
241
-		?>
20
+    /**
21
+     * @var string Current Step
22
+     */
23
+    protected $step = '';
24
+
25
+    /**
26
+     * @var string|false Previous Step
27
+     */
28
+    protected $previous_step = '';
29
+
30
+    /**
31
+     * @var string|false Next Step
32
+     */
33
+    protected $next_step = '';
34
+
35
+    /**
36
+     * @var array All available steps for the setup wizard
37
+     */
38
+    protected $steps = array();
39
+
40
+    /**
41
+     * Class constructor.
42
+     *
43
+     * @since 2.4.0
44
+     */
45
+    public function __construct() {
46
+
47
+        if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
+            add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
+            add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
+        }
51
+
52
+    }
53
+
54
+    /**
55
+     * Add admin menus/screens.
56
+     *
57
+     * @since 2.4.0
58
+     */
59
+    public function add_menu() {
60
+        add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
+    }
62
+
63
+    /**
64
+     * Sets up the setup wizard.
65
+     *
66
+     * @since 2.4.0
67
+     */
68
+    public function setup_wizard() {
69
+
70
+        if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
+            $this->setup_globals();
72
+            $this->maybe_save_current_step();
73
+            $this->display_wizard();
74
+            exit;
75
+        }
76
+
77
+    }
78
+
79
+    /**
80
+     * Sets up class variables.
81
+     *
82
+     * @since 2.4.0
83
+     */
84
+    protected function setup_globals() {
85
+        $this->steps         = $this->get_setup_steps();
86
+        $this->step          = $this->get_current_step();
87
+        $this->previous_step = $this->get_previous_step();
88
+        $this->next_step     = $this->get_next_step();
89
+    }
90
+
91
+    /**
92
+     * Saves the current step.
93
+     *
94
+     * @since 2.4.0
95
+     */
96
+    protected function maybe_save_current_step() {
97
+        if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
98
+            call_user_func( $this->steps[ $this->step ]['handler'], $this );
99
+        }
100
+    }
101
+
102
+    /**
103
+     * Returns the setup steps.
104
+     *
105
+     * @since 2.4.0
106
+     * @return array
107
+     */
108
+    protected function get_setup_steps() {
109
+
110
+        $steps = array(
111
+
112
+            'introduction'     => array(
113
+                'name'    => __( 'Introduction', 'invoicing' ),
114
+                'view'    => array( $this, 'setup_introduction' ),
115
+                'handler' => '',
116
+            ),
117
+
118
+            'business_details'             => array(
119
+                'name'    => __( "Business Details", 'invoicing' ),
120
+                'view'    => array( $this, 'setup_business' ),
121
+                'handler' => '',
122
+            ),
123
+
124
+            'currency' => array(
125
+                'name'    => __( 'Currency', 'invoicing' ),
126
+                'view'    => array( $this, 'setup_currency' ),
127
+                'handler' => '',
128
+            ),
129
+
130
+            'payments'        => array(
131
+                'name'    => __( 'Payment Gateways', 'invoicing' ),
132
+                'view'    => array( $this, 'setup_payments' ),
133
+                'handler' => array( $this, 'setup_payments_save' ),
134
+            ),
135
+
136
+            'recommend'          => array(
137
+                'name'    => __( 'Recommend', 'invoicing' ),
138
+                'view'    => array( $this, 'setup_recommend' ),
139
+                'handler' => '',
140
+            ),
141
+
142
+            'next_steps'       => array(
143
+                'name'    => __( 'Get Paid', 'invoicing' ),
144
+                'view'    => array( $this, 'setup_ready' ),
145
+                'handler' => '',
146
+            ),
147
+
148
+        );
149
+
150
+        return apply_filters( 'getpaid_setup_wizard_steps', $steps );
151
+
152
+    }
153
+
154
+    /**
155
+     * Returns the current step.
156
+     *
157
+     * @since 2.4.0
158
+     * @return string
159
+     */
160
+    protected function get_current_step() {
161
+        $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
162
+        return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
163
+    }
164
+
165
+    /**
166
+     * Returns the previous step.
167
+     *
168
+     * @since 2.4.0
169
+     * @return string|false
170
+     */
171
+    protected function get_previous_step() {
172
+
173
+        $previous = false;
174
+        $current  = $this->step;
175
+        foreach ( array_keys( $this->steps ) as $step ) {
176
+            if ( $current === $step ) {
177
+                return $previous;
178
+            }
179
+
180
+            $previous = $step;
181
+        }
182
+
183
+        return false;
184
+    }
185
+
186
+    /**
187
+     * Returns the next step.
188
+     *
189
+     * @since 2.4.0
190
+     * @return string|false
191
+     */
192
+    protected function get_next_step() {
193
+
194
+        $on_current = false;
195
+        $current    = $this->step;
196
+        foreach ( array_keys( $this->steps ) as $step ) {
197
+
198
+            if ( $on_current ) {
199
+                return $step;
200
+            }
201
+
202
+            if ( $current === $step ) {
203
+                return $on_current = true;
204
+            }
205
+
206
+        }
207
+
208
+        return false;
209
+    }
210
+
211
+    /**
212
+     * Displays the setup wizard.
213
+     *
214
+     * @since 2.4.0
215
+     */
216
+    public function display_wizard() {
217
+        $this->display_header();
218
+        $this->display_current_step();
219
+        $this->display_footer();
220
+    }
221
+
222
+    /**
223
+     * Displays the Wizard Header.
224
+     *
225
+     * @since 2.0.0
226
+     */
227
+    public function display_header() {
228
+        $steps     = $this->steps;
229
+        $current   = $this->step;
230
+        $next_step = $this->next_step;
231
+        array_shift( $steps );
232
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
233
+    }
234
+
235
+    /**
236
+     * Displays the content for the current step.
237
+     *
238
+     * @since 2.4.0
239
+     */
240
+    public function display_current_step() {
241
+        ?>
242 242
 			<div class="gp-setup-content rowx mw-100 text-center mb-3">
243 243
 				<div class="col-12 col-md-5 m-auto">
244 244
 					<?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?>
245 245
 				</div>
246 246
 			</div>
247 247
 		<?php
248
-	}
249
-
250
-	/**
251
-	 * Setup Wizard Footer.
252
-	 *
253
-	 * @since 2.4.0
254
-	 */
255
-	public function display_footer() {
256
-
257
-		if ( isset( $_GET['step'] ) ) {
258
-			$next_url = esc_url( $this->get_next_step_link() );
259
-			$label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
260
-
261
-			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>';
262
-		}
263
-
264
-		echo '</body></html>';
265
-	}
266
-
267
-	/**
268
-	 * Introduction step.
269
-	 *
270
-	 * @since 2.0.0
271
-	 */
272
-	public function setup_introduction() {
273
-		$next_url = $this->get_next_step_link();
274
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
275
-	}
276
-
277
-	/**
278
-	 * Get the URL for the next step's screen.
279
-	 *
280
-	 * @param string step   slug (default: current step)
281
-	 *
282
-	 * @return string       URL for next step if a next step exists.
283
-	 *                      Admin URL if it's the last step.
284
-	 *                      Empty string on failure.
285
-	 * @since 3.0.0
286
-	 */
287
-	public function get_next_step_link( $step = '' ) {
288
-		if ( ! $step ) {
289
-			$step = $this->step;
290
-		}
291
-
292
-		$keys = array_keys( $this->steps );
293
-		if ( end( $keys ) === $step ) {
294
-			return admin_url();
295
-		}
296
-
297
-		$step_index = array_search( $step, $keys );
298
-		if ( false === $step_index ) {
299
-			return '';
300
-		}
301
-
302
-		return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ));
303
-	}
304
-
305
-	/**
306
-	 * Setup maps api.
307
-	 *
308
-	 * @since 2.0.0
309
-	 */
310
-	public function setup_business() {
311
-		$next_url = $this->get_next_step_link();
312
-		$wizard   = $this;
313
-		$page     = 'wpinv_settings_general_main';
314
-		$section  = 'wpinv_settings_general_main';
315
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
316
-	}
317
-
318
-	/**
319
-	 * Default Location settings.
320
-	 *
321
-	 * @since 2.0.0
322
-	 */
323
-	public function setup_currency() {
324
-		$next_url = $this->get_next_step_link();
325
-		$wizard   = $this;
326
-		$page     = 'wpinv_settings_general_currency_section';
327
-		$section  = 'wpinv_settings_general_currency_section';
328
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
329
-	}
330
-
331
-	/**
332
-	 * Installation of recommended plugins.
333
-	 *
334
-	 * @since 1.0.0
335
-	 */
336
-	public function setup_recommend() {
337
-		$next_url            = $this->get_next_step_link();
338
-		$recommended_plugins = self::get_recommend_wp_plugins();
339
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
340
-	}
341
-
342
-	/**
343
-	 * A list of recommended wp.org plugins.
344
-	 * @return array
345
-	 */
346
-	public static function get_recommend_wp_plugins(){
347
-		return array(
348
-			'ayecode-connect' => array(
349
-				'file'   => 'ayecode-connect/ayecode-connect.php',
350
-				'url'    => 'https://wordpress.org/plugins/ayecode-connect/',
351
-				'slug'   => 'ayecode-connect',
352
-				'name'   => 'AyeCode Connect',
353
-				'desc'   => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ),
354
-			),
355
-			'invoicing-quotes' => array(
356
-				'file'   => 'invoicing-quotes/wpinv-quote.php',
357
-				'url'    => 'https://wordpress.org/plugins/invoicing-quotes/',
358
-				'slug'   => 'invoicing-quotes',
359
-				'name'   => 'Customer Quotes',
360
-				'desc'   => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'),
361
-			),
362
-			'userswp'    => array(
363
-				'file'   => 'userswp/userswp.php',
364
-				'url'    => 'https://wordpress.org/plugins/userswp/',
365
-				'slug'   => 'userswp',
366
-				'name'   => 'UsersWP',
367
-				'desc'   => __('Frontend user login and registration as well as slick profile pages.','geodirectory'),
368
-			),
369
-		);
370
-	}
371
-
372
-	/**
373
-	 * Dummy Data setup.
374
-	 *
375
-	 * @since 2.4.0
376
-	 */
377
-	public function setup_payments() {
378
-		$next_url = $this->get_next_step_link();
379
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
380
-	}
381
-
382
-	/**
383
-	 * Dummy data save.
384
-	 *
385
-	 * This is done via ajax so we just pass onto the next step.
386
-	 *
387
-	 * @since 2.0.0
388
-	 */
389
-	public function setup_payments_save() {
390
-		check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
391
-		wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
392
-		wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
393
-		exit;
394
-	}
395
-
396
-	/**
397
-	 * Final step.
398
-	 *
399
-	 * @since 2.0.0
400
-	 */
401
-	public function setup_ready() {
402
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
403
-	}
248
+    }
249
+
250
+    /**
251
+     * Setup Wizard Footer.
252
+     *
253
+     * @since 2.4.0
254
+     */
255
+    public function display_footer() {
256
+
257
+        if ( isset( $_GET['step'] ) ) {
258
+            $next_url = esc_url( $this->get_next_step_link() );
259
+            $label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
260
+
261
+            echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>';
262
+        }
263
+
264
+        echo '</body></html>';
265
+    }
266
+
267
+    /**
268
+     * Introduction step.
269
+     *
270
+     * @since 2.0.0
271
+     */
272
+    public function setup_introduction() {
273
+        $next_url = $this->get_next_step_link();
274
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
275
+    }
276
+
277
+    /**
278
+     * Get the URL for the next step's screen.
279
+     *
280
+     * @param string step   slug (default: current step)
281
+     *
282
+     * @return string       URL for next step if a next step exists.
283
+     *                      Admin URL if it's the last step.
284
+     *                      Empty string on failure.
285
+     * @since 3.0.0
286
+     */
287
+    public function get_next_step_link( $step = '' ) {
288
+        if ( ! $step ) {
289
+            $step = $this->step;
290
+        }
291
+
292
+        $keys = array_keys( $this->steps );
293
+        if ( end( $keys ) === $step ) {
294
+            return admin_url();
295
+        }
296
+
297
+        $step_index = array_search( $step, $keys );
298
+        if ( false === $step_index ) {
299
+            return '';
300
+        }
301
+
302
+        return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ));
303
+    }
304
+
305
+    /**
306
+     * Setup maps api.
307
+     *
308
+     * @since 2.0.0
309
+     */
310
+    public function setup_business() {
311
+        $next_url = $this->get_next_step_link();
312
+        $wizard   = $this;
313
+        $page     = 'wpinv_settings_general_main';
314
+        $section  = 'wpinv_settings_general_main';
315
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
316
+    }
317
+
318
+    /**
319
+     * Default Location settings.
320
+     *
321
+     * @since 2.0.0
322
+     */
323
+    public function setup_currency() {
324
+        $next_url = $this->get_next_step_link();
325
+        $wizard   = $this;
326
+        $page     = 'wpinv_settings_general_currency_section';
327
+        $section  = 'wpinv_settings_general_currency_section';
328
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
329
+    }
330
+
331
+    /**
332
+     * Installation of recommended plugins.
333
+     *
334
+     * @since 1.0.0
335
+     */
336
+    public function setup_recommend() {
337
+        $next_url            = $this->get_next_step_link();
338
+        $recommended_plugins = self::get_recommend_wp_plugins();
339
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
340
+    }
341
+
342
+    /**
343
+     * A list of recommended wp.org plugins.
344
+     * @return array
345
+     */
346
+    public static function get_recommend_wp_plugins(){
347
+        return array(
348
+            'ayecode-connect' => array(
349
+                'file'   => 'ayecode-connect/ayecode-connect.php',
350
+                'url'    => 'https://wordpress.org/plugins/ayecode-connect/',
351
+                'slug'   => 'ayecode-connect',
352
+                'name'   => 'AyeCode Connect',
353
+                'desc'   => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ),
354
+            ),
355
+            'invoicing-quotes' => array(
356
+                'file'   => 'invoicing-quotes/wpinv-quote.php',
357
+                'url'    => 'https://wordpress.org/plugins/invoicing-quotes/',
358
+                'slug'   => 'invoicing-quotes',
359
+                'name'   => 'Customer Quotes',
360
+                'desc'   => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'),
361
+            ),
362
+            'userswp'    => array(
363
+                'file'   => 'userswp/userswp.php',
364
+                'url'    => 'https://wordpress.org/plugins/userswp/',
365
+                'slug'   => 'userswp',
366
+                'name'   => 'UsersWP',
367
+                'desc'   => __('Frontend user login and registration as well as slick profile pages.','geodirectory'),
368
+            ),
369
+        );
370
+    }
371
+
372
+    /**
373
+     * Dummy Data setup.
374
+     *
375
+     * @since 2.4.0
376
+     */
377
+    public function setup_payments() {
378
+        $next_url = $this->get_next_step_link();
379
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
380
+    }
381
+
382
+    /**
383
+     * Dummy data save.
384
+     *
385
+     * This is done via ajax so we just pass onto the next step.
386
+     *
387
+     * @since 2.0.0
388
+     */
389
+    public function setup_payments_save() {
390
+        check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
391
+        wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
392
+        wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
393
+        exit;
394
+    }
395
+
396
+    /**
397
+     * Final step.
398
+     *
399
+     * @since 2.0.0
400
+     */
401
+    public function setup_ready() {
402
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
403
+    }
404 404
 
405 405
 }
406 406
 
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
     
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
     
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -259,24 +259,24 @@  discard block
 block discarded – undo
259 259
         check_ajax_referer( 'getpaid_form_nonce' );
260 260
 
261 261
         // Is the request set up correctly?
262
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
263
-			echo aui()->alert(
264
-				array(
265
-					'type'    => 'warning',
266
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
267
-				)
262
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
263
+            echo aui()->alert(
264
+                array(
265
+                    'type'    => 'warning',
266
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
267
+                )
268 268
             );
269 269
             exit;
270 270
         }
271 271
 
272 272
         // Payment form or button?
273
-		if ( ! empty( $_GET['form'] ) ) {
273
+        if ( ! empty( $_GET['form'] ) ) {
274 274
             getpaid_display_payment_form( urldecode( $_GET['form'] ) );
275
-		} else if( ! empty( $_GET['invoice'] ) ) {
276
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
275
+        } else if( ! empty( $_GET['invoice'] ) ) {
276
+            getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
277 277
         } else {
278
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
279
-		    getpaid_display_item_payment_form( $items );
278
+            $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
279
+            getpaid_display_item_payment_form( $items );
280 280
         }
281 281
 
282 282
         exit;
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
         if ( is_wp_error( $error ) ) {
598 598
             $alert = $error->get_error_message();
599 599
             wp_send_json_success( compact( 'alert' ) );
600
-         }
600
+            }
601 601
 
602 602
         // Update totals.
603 603
         $invoice->recalculate_total();
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-items.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
     }
320 320
 
321 321
     /**
322
-	 * Output the metabox.
323
-	 *
324
-	 * @param WP_Post $post
325
-	 */
322
+     * Output the metabox.
323
+     *
324
+     * @param WP_Post $post
325
+     */
326 326
     public static function output2( $post ) {
327 327
 
328 328
         // Prepare the invoice.
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Indentation   +394 added lines, -394 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_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 = 'paypal';
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', 'single_subscription_group' );
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 = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
90
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92 92
 
93 93
         parent::__construct();
94 94
     }
95 95
 
96 96
     /**
97
-	 * Process Payment.
98
-	 *
99
-	 *
100
-	 * @param WPInv_Invoice $invoice Invoice.
101
-	 * @param array $submission_data Posted checkout fields.
102
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
-	 * @return array
104
-	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
97
+     * Process Payment.
98
+     *
99
+     *
100
+     * @param WPInv_Invoice $invoice Invoice.
101
+     * @param array $submission_data Posted checkout fields.
102
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
+     * @return array
104
+     */
105
+    public function process_payment( $invoice, $submission_data, $submission ) {
106 106
 
107 107
         // Get redirect url.
108 108
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get the PayPal request URL for an invoice.
129
-	 *
130
-	 * @param  WPInv_Invoice $invoice Invoice object.
131
-	 * @return string
132
-	 */
133
-	public function get_request_url( $invoice ) {
128
+     * Get the PayPal request URL for an invoice.
129
+     *
130
+     * @param  WPInv_Invoice $invoice Invoice object.
131
+     * @return string
132
+     */
133
+    public function get_request_url( $invoice ) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139 139
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -146,44 +146,44 @@  discard block
 block discarded – undo
146 146
 
147 147
         return add_query_arg( $paypal_args, $this->endpoint );
148 148
 
149
-	}
149
+    }
150 150
 
151 151
     /**
152
-	 * Get PayPal Args for passing to PP.
153
-	 *
154
-	 * @param  WPInv_Invoice $invoice Invoice object.
155
-	 * @return array
156
-	 */
157
-	protected function get_paypal_args( $invoice ) {
152
+     * Get PayPal Args for passing to PP.
153
+     *
154
+     * @param  WPInv_Invoice $invoice Invoice object.
155
+     * @return array
156
+     */
157
+    protected function get_paypal_args( $invoice ) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
-
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
-			$force_one_line_item = true;
164
-		}
165
-
166
-		$paypal_args = apply_filters(
167
-			'getpaid_paypal_args',
168
-			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
171
-			),
172
-			$invoice
173
-		);
174
-
175
-		return $this->fix_request_length( $invoice, $paypal_args );
160
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+
162
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+            $force_one_line_item = true;
164
+        }
165
+
166
+        $paypal_args = apply_filters(
167
+            'getpaid_paypal_args',
168
+            array_merge(
169
+                $this->get_transaction_args( $invoice ),
170
+                $this->get_line_item_args( $invoice, $force_one_line_item )
171
+            ),
172
+            $invoice
173
+        );
174
+
175
+        return $this->fix_request_length( $invoice, $paypal_args );
176 176
     }
177 177
 
178 178
     /**
179
-	 * Get transaction args for paypal request.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 * @return array
183
-	 */
184
-	protected function get_transaction_args( $invoice ) {
185
-
186
-		return array(
179
+     * Get transaction args for paypal request.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     * @return array
183
+     */
184
+    protected function get_transaction_args( $invoice ) {
185
+
186
+        return array(
187 187
             'cmd'           => '_cart',
188 188
             'business'      => wpinv_get_option( 'paypal_email', false ),
189 189
             'no_shipping'   => '1',
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
     }
209 209
 
210 210
     /**
211
-	 * Get line item args for paypal request.
212
-	 *
213
-	 * @param  WPInv_Invoice $invoice Invoice object.
214
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
215
-	 * @return array
216
-	 */
217
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
211
+     * Get line item args for paypal request.
212
+     *
213
+     * @param  WPInv_Invoice $invoice Invoice object.
214
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
215
+     * @return array
216
+     */
217
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
218 218
 
219 219
         // Maybe send invoice as a single item.
220
-		if ( $force_one_line_item ) {
220
+        if ( $force_one_line_item ) {
221 221
             return $this->get_line_item_args_single_item( $invoice );
222 222
         }
223 223
 
@@ -237,129 +237,129 @@  discard block
 block discarded – undo
237 237
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
238 238
         }
239 239
 
240
-		return array_merge( $line_item_args, $this->get_line_items() );
240
+        return array_merge( $line_item_args, $this->get_line_items() );
241 241
 
242 242
     }
243 243
 
244 244
     /**
245
-	 * Get line item args for paypal request as a single line item.
246
-	 *
247
-	 * @param  WPInv_Invoice $invoice Invoice object.
248
-	 * @return array
249
-	 */
250
-	protected function get_line_item_args_single_item( $invoice ) {
251
-		$this->delete_line_items();
245
+     * Get line item args for paypal request as a single line item.
246
+     *
247
+     * @param  WPInv_Invoice $invoice Invoice object.
248
+     * @return array
249
+     */
250
+    protected function get_line_item_args_single_item( $invoice ) {
251
+        $this->delete_line_items();
252 252
 
253 253
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
254
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
254
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255 255
 
256
-		return $this->get_line_items();
256
+        return $this->get_line_items();
257 257
     }
258 258
 
259 259
     /**
260
-	 * Return all line items.
261
-	 */
262
-	protected function get_line_items() {
263
-		return $this->line_items;
264
-	}
260
+     * Return all line items.
261
+     */
262
+    protected function get_line_items() {
263
+        return $this->line_items;
264
+    }
265 265
 
266 266
     /**
267
-	 * Remove all line items.
268
-	 */
269
-	protected function delete_line_items() {
270
-		$this->line_items = array();
267
+     * Remove all line items.
268
+     */
269
+    protected function delete_line_items() {
270
+        $this->line_items = array();
271 271
     }
272 272
 
273 273
     /**
274
-	 * Prepare line items to send to paypal.
275
-	 *
276
-	 * @param  WPInv_Invoice $invoice Invoice object.
277
-	 */
278
-	protected function prepare_line_items( $invoice ) {
279
-		$this->delete_line_items();
280
-
281
-		// Items.
282
-		foreach ( $invoice->get_items() as $item ) {
283
-			$amount   = $item->get_price();
284
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
285
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
274
+     * Prepare line items to send to paypal.
275
+     *
276
+     * @param  WPInv_Invoice $invoice Invoice object.
277
+     */
278
+    protected function prepare_line_items( $invoice ) {
279
+        $this->delete_line_items();
280
+
281
+        // Items.
282
+        foreach ( $invoice->get_items() as $item ) {
283
+            $amount   = $item->get_price();
284
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
285
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
286 286
         }
287 287
 
288 288
         // Fees.
289
-		foreach ( $invoice->get_fees() as $fee => $data ) {
289
+        foreach ( $invoice->get_fees() as $fee => $data ) {
290 290
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
291 291
         }
292 292
 
293 293
     }
294 294
 
295 295
     /**
296
-	 * Add PayPal Line Item.
297
-	 *
298
-	 * @param  string $item_name Item name.
299
-	 * @param  float    $quantity Item quantity.
300
-	 * @param  float  $amount Amount.
301
-	 * @param  string $item_number Item number.
302
-	 */
303
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
304
-		$index = ( count( $this->line_items ) / 4 ) + 1;
305
-
306
-		$item = apply_filters(
307
-			'getpaid_paypal_line_item',
308
-			array(
309
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
310
-				'quantity'    => (float) $quantity,
311
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
312
-				'item_number' => $item_number,
313
-			),
314
-			$item_name,
315
-			$quantity,
316
-			$amount,
317
-			$item_number
318
-		);
319
-
320
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
296
+     * Add PayPal Line Item.
297
+     *
298
+     * @param  string $item_name Item name.
299
+     * @param  float    $quantity Item quantity.
300
+     * @param  float  $amount Amount.
301
+     * @param  string $item_number Item number.
302
+     */
303
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
304
+        $index = ( count( $this->line_items ) / 4 ) + 1;
305
+
306
+        $item = apply_filters(
307
+            'getpaid_paypal_line_item',
308
+            array(
309
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
310
+                'quantity'    => (float) $quantity,
311
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
312
+                'item_number' => $item_number,
313
+            ),
314
+            $item_name,
315
+            $quantity,
316
+            $amount,
317
+            $item_number
318
+        );
319
+
320
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
321 321
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
322 322
 
323 323
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
324
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
325
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
324
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
325
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
326 326
     }
327 327
 
328 328
     /**
329
-	 * If the default request with line items is too long, generate a new one with only one line item.
330
-	 *
331
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
332
-	 *
333
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
334
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
335
-	 * @return array
336
-	 */
337
-	protected function fix_request_length( $invoice, $paypal_args ) {
338
-		$max_paypal_length = 2083;
339
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
340
-
341
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
342
-			return $paypal_args;
343
-		}
344
-
345
-		return apply_filters(
346
-			'getpaid_paypal_args',
347
-			array_merge(
348
-				$this->get_transaction_args( $invoice ),
349
-				$this->get_line_item_args( $invoice, true )
350
-			),
351
-			$invoice
352
-		);
329
+     * If the default request with line items is too long, generate a new one with only one line item.
330
+     *
331
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
332
+     *
333
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
334
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
335
+     * @return array
336
+     */
337
+    protected function fix_request_length( $invoice, $paypal_args ) {
338
+        $max_paypal_length = 2083;
339
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
340
+
341
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
342
+            return $paypal_args;
343
+        }
344
+
345
+        return apply_filters(
346
+            'getpaid_paypal_args',
347
+            array_merge(
348
+                $this->get_transaction_args( $invoice ),
349
+                $this->get_line_item_args( $invoice, true )
350
+            ),
351
+            $invoice
352
+        );
353 353
 
354 354
     }
355 355
 
356 356
     /**
357
-	 * Processes recurring invoices.
358
-	 *
359
-	 * @param  array $paypal_args PayPal args.
360
-	 * @param  WPInv_Invoice    $invoice Invoice object.
361
-	 */
362
-	public function process_subscription( $paypal_args, $invoice ) {
357
+     * Processes recurring invoices.
358
+     *
359
+     * @param  array $paypal_args PayPal args.
360
+     * @param  WPInv_Invoice    $invoice Invoice object.
361
+     */
362
+    public function process_subscription( $paypal_args, $invoice ) {
363 363
 
364 364
         // Make sure this is a subscription.
365 365
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -384,11 +384,11 @@  discard block
 block discarded – undo
384 384
 
385 385
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
386 386
 
387
-			// Trial period length.
388
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
387
+            // Trial period length.
388
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
389 389
 
390
-			// Trial period.
391
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
390
+            // Trial period.
391
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
392 392
 
393 393
         } else if ( $initial_amount != $recurring_amount ) {
394 394
 
@@ -411,40 +411,40 @@  discard block
 block discarded – undo
411 411
         }
412 412
 
413 413
         // We have a recurring payment
414
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
414
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
415 415
 
416
-			// Subscription price
417
-			$paypal_args['a3'] = $recurring_amount;
416
+            // Subscription price
417
+            $paypal_args['a3'] = $recurring_amount;
418 418
 
419
-			// Subscription duration
420
-			$paypal_args['p3'] = $interval;
419
+            // Subscription duration
420
+            $paypal_args['p3'] = $interval;
421 421
 
422
-			// Subscription period
423
-			$paypal_args['t3'] = $period;
422
+            // Subscription period
423
+            $paypal_args['t3'] = $period;
424 424
 
425 425
         }
426 426
 
427 427
         // Recurring payments
428
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
428
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
429 429
 
430
-			// Non-recurring payments
431
-			$paypal_args['src'] = 0;
430
+            // Non-recurring payments
431
+            $paypal_args['src'] = 0;
432 432
 
433
-		} else {
433
+        } else {
434 434
 
435
-			$paypal_args['src'] = 1;
435
+            $paypal_args['src'] = 1;
436 436
 
437
-			if ( $bill_times > 0 ) {
437
+            if ( $bill_times > 0 ) {
438 438
 
439
-				// An initial period is being used to charge a sign-up fee
440
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
441
-					$bill_times--;
442
-				}
439
+                // An initial period is being used to charge a sign-up fee
440
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
441
+                    $bill_times--;
442
+                }
443 443
 
444 444
                 // Make sure it's not over the max of 52
445 445
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
446 446
 
447
-			}
447
+            }
448 448
         }
449 449
 
450 450
         // Force return URL so that order description & instructions display
@@ -460,19 +460,19 @@  discard block
 block discarded – undo
460 460
         }
461 461
 
462 462
         return apply_filters(
463
-			'getpaid_paypal_subscription_args',
464
-			$paypal_args,
465
-			$invoice
463
+            'getpaid_paypal_subscription_args',
464
+            $paypal_args,
465
+            $invoice
466 466
         );
467 467
 
468 468
     }
469 469
 
470 470
     /**
471
-	 * Processes ipns and marks payments as complete.
472
-	 *
473
-	 * @return void
474
-	 */
475
-	public function verify_ipn() {
471
+     * Processes ipns and marks payments as complete.
472
+     *
473
+     * @return void
474
+     */
475
+    public function verify_ipn() {
476 476
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
477 477
     }
478 478
 
@@ -482,19 +482,19 @@  discard block
 block discarded – undo
482 482
     public function sandbox_notice() {
483 483
 
484 484
         return sprintf(
485
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
486
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
487
-			'</a>'
488
-		);
485
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
486
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
487
+            '</a>'
488
+        );
489 489
 
490 490
     }
491 491
 
492
-	/**
493
-	 * Filters the gateway settings.
494
-	 *
495
-	 * @param array $admin_settings
496
-	 */
497
-	public function admin_settings( $admin_settings ) {
492
+    /**
493
+     * Filters the gateway settings.
494
+     *
495
+     * @param array $admin_settings
496
+     */
497
+    public function admin_settings( $admin_settings ) {
498 498
 
499 499
         $currencies = sprintf(
500 500
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -504,89 +504,89 @@  discard block
 block discarded – undo
504 504
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
505 505
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
506 506
 
507
-		// Access tokens.
507
+        // Access tokens.
508 508
         $live_account    = wpinv_get_option( 'paypal_live_access_token' );
509 509
         $sandbox_account = wpinv_get_option( 'paypal_test_access_token' );
510 510
 
511
-		$admin_settings['paypal_connect'] = array(
512
-			'type'       => 'raw_html',
513
-			'id'         => 'paypal_connect',
514
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
515
-			'desc'       => sprintf(
516
-				'<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div>%s',
517
-				esc_url( self::get_connect_url( false ) ),
518
-				__( 'Connect to PayPal', 'invoicing' ),
519
-				__( 'Connected', 'invoicing' ),
520
-				esc_url( self::get_connect_url( true ) ),
521
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
522
-				__( 'Connected', 'invoicing' ),
523
-				$this->get_js()
524
-			),
525
-		);
526
-
527
-		$admin_settings['disable_paypal_connect'] = array(
528
-			'type'       => 'checkbox',
529
-			'id'         => 'disable_paypal_connect',
530
-			'name'       => __( 'Manual Mode', 'invoicing' ),
531
-			'desc'       => __( 'Manually enter your credentials', 'invoicing' ),
532
-			'std'        => false,
533
-		);
511
+        $admin_settings['paypal_connect'] = array(
512
+            'type'       => 'raw_html',
513
+            'id'         => 'paypal_connect',
514
+            'name'       => __( 'Connect to PayPal', 'invoicing' ),
515
+            'desc'       => sprintf(
516
+                '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div>%s',
517
+                esc_url( self::get_connect_url( false ) ),
518
+                __( 'Connect to PayPal', 'invoicing' ),
519
+                __( 'Connected', 'invoicing' ),
520
+                esc_url( self::get_connect_url( true ) ),
521
+                __( 'Connect to PayPal Sandox', 'invoicing' ),
522
+                __( 'Connected', 'invoicing' ),
523
+                $this->get_js()
524
+            ),
525
+        );
526
+
527
+        $admin_settings['disable_paypal_connect'] = array(
528
+            'type'       => 'checkbox',
529
+            'id'         => 'disable_paypal_connect',
530
+            'name'       => __( 'Manual Mode', 'invoicing' ),
531
+            'desc'       => __( 'Manually enter your credentials', 'invoicing' ),
532
+            'std'        => false,
533
+        );
534 534
 
535 535
         $admin_settings['paypal_email'] = array(
536 536
             'type'  => 'text',
537
-			'class' => 'live-auth-data',
537
+            'class' => 'live-auth-data',
538 538
             'id'    => 'paypal_email',
539 539
             'name'  => __( 'Live Email Address', 'invoicing' ),
540 540
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
541 541
         );
542 542
 
543
-		$admin_settings['paypal_merchant_id'] = array(
543
+        $admin_settings['paypal_merchant_id'] = array(
544 544
             'type'  => 'text',
545
-			'class' => 'live-auth-data',
545
+            'class' => 'live-auth-data',
546 546
             'id'    => 'paypal_merchant_id',
547 547
             'name'  => __( 'Live Merchant ID', 'invoicing' ),
548 548
         );
549 549
 
550
-		$admin_settings['paypal_client_id'] = array(
550
+        $admin_settings['paypal_client_id'] = array(
551 551
             'type'  => 'text',
552
-			'class' => 'live-auth-data',
552
+            'class' => 'live-auth-data',
553 553
             'id'    => 'paypal_client_id',
554 554
             'name'  => __( 'Live Client ID', 'invoicing' ),
555 555
         );
556 556
 
557
-		$admin_settings['paypal_client_secret'] = array(
557
+        $admin_settings['paypal_client_secret'] = array(
558 558
             'type'  => 'text',
559
-			'class' => 'live-auth-data',
559
+            'class' => 'live-auth-data',
560 560
             'id'    => 'paypal_client_secret',
561 561
             'name'  => __( 'Live Client Secret', 'invoicing' ),
562 562
         );
563 563
 
564
-		$admin_settings['paypal_sandbox_email'] = array(
564
+        $admin_settings['paypal_sandbox_email'] = array(
565 565
             'type'  => 'text',
566
-			'class' => 'sandbox-auth-data',
566
+            'class' => 'sandbox-auth-data',
567 567
             'id'    => 'paypal_sandbox_email',
568 568
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
569 569
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
570
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
570
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
571 571
         );
572 572
 
573
-		$admin_settings['paypal_sandbox_merchant_id'] = array(
573
+        $admin_settings['paypal_sandbox_merchant_id'] = array(
574 574
             'type'  => 'text',
575
-			'class' => 'sandbox-auth-data',
575
+            'class' => 'sandbox-auth-data',
576 576
             'id'    => 'paypal_sandbox_merchant_id',
577 577
             'name'  => __( 'Sandbox Merchant ID', 'invoicing' ),
578 578
         );
579 579
 
580
-		$admin_settings['paypal_sandbox_client_id'] = array(
580
+        $admin_settings['paypal_sandbox_client_id'] = array(
581 581
             'type'  => 'text',
582
-			'class' => 'sandbox-auth-data',
582
+            'class' => 'sandbox-auth-data',
583 583
             'id'    => 'paypal_sandbox_client_id',
584 584
             'name'  => __( 'Sandbox Client ID', 'invoicing' ),
585 585
         );
586 586
 
587
-		$admin_settings['paypal_sandbox_client_secret'] = array(
587
+        $admin_settings['paypal_sandbox_client_secret'] = array(
588 588
             'type'  => 'text',
589
-			'class' => 'sandbox-auth-data',
589
+            'class' => 'sandbox-auth-data',
590 590
             'id'    => 'paypal_sandbox_client_secret',
591 591
             'name'  => __( 'Sandbox Client Secret', 'invoicing' ),
592 592
         );
@@ -600,29 +600,29 @@  discard block
 block discarded – undo
600 600
             'readonly' => true,
601 601
         );
602 602
 
603
-		return $admin_settings;
604
-	}
603
+        return $admin_settings;
604
+    }
605 605
 
606
-	/**
607
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
608
-	 *
609
-	 *
606
+    /**
607
+     * Retrieves the PayPal connect URL when using the setup wizzard.
608
+     *
609
+     *
610 610
      * @param array $data
611 611
      * @return string
612
-	 */
613
-	public static function maybe_get_connect_url( $url = '', $data ) {
614
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
615
-	}
616
-
617
-	/**
618
-	 * Retrieves the PayPal connect URL.
619
-	 *
620
-	 *
612
+     */
613
+    public static function maybe_get_connect_url( $url = '', $data ) {
614
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
615
+    }
616
+
617
+    /**
618
+     * Retrieves the PayPal connect URL.
619
+     *
620
+     *
621 621
      * @param bool $is_sandbox
622
-	 * @param string $redirect
622
+     * @param string $redirect
623 623
      * @return string
624
-	 */
625
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
624
+     */
625
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
626 626
 
627 627
         $redirect_url = add_query_arg(
628 628
             array(
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
                 'tab'                  => 'gateways',
633 633
                 'section'              => 'paypal',
634 634
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
635
-				'redirect'             => urlencode( $redirect ),
635
+                'redirect'             => urlencode( $redirect ),
636 636
             ),
637 637
             admin_url( 'admin.php' )
638 638
         );
@@ -647,12 +647,12 @@  discard block
 block discarded – undo
647 647
 
648 648
     }
649 649
 
650
-	/**
651
-	 * Generates settings page js.
652
-	 *
650
+    /**
651
+     * Generates settings page js.
652
+     *
653 653
      * @return void
654
-	 */
655
-	public static function get_js() {
654
+     */
655
+    public static function get_js() {
656 656
         ob_start();
657 657
         ?>
658 658
             <script>
@@ -698,109 +698,109 @@  discard block
 block discarded – undo
698 698
         return ob_get_clean();
699 699
     }
700 700
 
701
-	/**
702
-	 * Connects to PayPal.
703
-	 *
704
-	 * @param array $data Connection data.
705
-	 * @return void
706
-	 */
707
-	public function connect_paypal( $data ) {
708
-
709
-		$sandbox      = $this->is_sandbox();
710
-		$data         = wp_unslash( $data );
711
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
712
-
713
-		if ( isset( $data['live_mode'] ) ) {
714
-			$sandbox = empty( $data['live_mode'] );
715
-		}
716
-
717
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
718
-		wpinv_update_option( 'paypal_active', 1 );
719
-
720
-		if ( ! empty( $data['error_description'] ) ) {
721
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
722
-		} else {
723
-
724
-			// Retrieve the user info.
725
-			$user_info = wp_remote_get(
726
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
727
-				array(
728
-
729
-					'headers' => array(
730
-						'Authorization' => 'Bearer ' . $access_token,
731
-						'Content-type'  => 'application/json',
732
-					)
733
-
734
-				)
735
-			);
736
-
737
-			if ( is_wp_error( $user_info ) ) {
738
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
739
-			} else {
740
-
741
-				// Create application.
742
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
743
-				$app       = wp_remote_post(
744
-					! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications',
745
-					array(
746
-
747
-						'body'    => array(
748
-							'application_type' => 'web',
749
-							'redirect_uris'    => array(
750
-								add_query_arg( 'getpaid_oauth', 'paypal', home_url() ),
751
-							),
752
-							'client_name'      => 'GetPaid',
753
-							'contacts'         => array( $user_info->emails[0]->value ),
754
-							'payer_id'         => $user_info->payer_id,
755
-							'migrated_app'     => '',
756
-						),
757
-						'headers' => array(
758
-							'Authorization' => 'Bearer ' . $access_token,
759
-							'Content-type'  => 'application/json',
760
-						)
761
-
762
-					)
763
-				);
764
-
765
-				if ( is_wp_error( $app ) ) {
766
-					getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) );
767
-				} else {
768
-
769
-					$app = json_decode( wp_remote_retrieve_body( $app ) );
770
-					wpinv_error_log( $app );
771
-					if ( $sandbox ) {
772
-						wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
773
-						wpinv_update_option( 'paypal_sandbox_merchant_id', '' );
774
-						wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( '' ) );
775
-						wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( '' ) );
776
-						wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( '' ) );
777
-						wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
778
-						set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
779
-						getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
780
-					} else {
781
-						wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
782
-						wpinv_update_option( 'paypal_merchant_id', '' );
783
-						wpinv_update_option( 'paypal_client_id', sanitize_text_field( '' ) );
784
-						wpinv_update_option( 'paypal_client_secret', sanitize_text_field( '' ) );
785
-						wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( '' ) );
786
-						wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
787
-						set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
788
-						getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
789
-					}
701
+    /**
702
+     * Connects to PayPal.
703
+     *
704
+     * @param array $data Connection data.
705
+     * @return void
706
+     */
707
+    public function connect_paypal( $data ) {
790 708
 
791
-				}
709
+        $sandbox      = $this->is_sandbox();
710
+        $data         = wp_unslash( $data );
711
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
792 712
 
793
-			}
713
+        if ( isset( $data['live_mode'] ) ) {
714
+            $sandbox = empty( $data['live_mode'] );
715
+        }
794 716
 
795
-		}
717
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
718
+        wpinv_update_option( 'paypal_active', 1 );
796 719
 
797
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
720
+        if ( ! empty( $data['error_description'] ) ) {
721
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
722
+        } else {
723
+
724
+            // Retrieve the user info.
725
+            $user_info = wp_remote_get(
726
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
727
+                array(
728
+
729
+                    'headers' => array(
730
+                        'Authorization' => 'Bearer ' . $access_token,
731
+                        'Content-type'  => 'application/json',
732
+                    )
798 733
 
799
-		if ( isset( $data['step'] ) ) {
800
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
801
-		}
802
-		wp_redirect( $redirect );
803
-		exit;
804
-	}
734
+                )
735
+            );
736
+
737
+            if ( is_wp_error( $user_info ) ) {
738
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
739
+            } else {
740
+
741
+                // Create application.
742
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
743
+                $app       = wp_remote_post(
744
+                    ! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications',
745
+                    array(
746
+
747
+                        'body'    => array(
748
+                            'application_type' => 'web',
749
+                            'redirect_uris'    => array(
750
+                                add_query_arg( 'getpaid_oauth', 'paypal', home_url() ),
751
+                            ),
752
+                            'client_name'      => 'GetPaid',
753
+                            'contacts'         => array( $user_info->emails[0]->value ),
754
+                            'payer_id'         => $user_info->payer_id,
755
+                            'migrated_app'     => '',
756
+                        ),
757
+                        'headers' => array(
758
+                            'Authorization' => 'Bearer ' . $access_token,
759
+                            'Content-type'  => 'application/json',
760
+                        )
761
+
762
+                    )
763
+                );
764
+
765
+                if ( is_wp_error( $app ) ) {
766
+                    getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) );
767
+                } else {
768
+
769
+                    $app = json_decode( wp_remote_retrieve_body( $app ) );
770
+                    wpinv_error_log( $app );
771
+                    if ( $sandbox ) {
772
+                        wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
773
+                        wpinv_update_option( 'paypal_sandbox_merchant_id', '' );
774
+                        wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( '' ) );
775
+                        wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( '' ) );
776
+                        wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( '' ) );
777
+                        wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
778
+                        set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
779
+                        getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
780
+                    } else {
781
+                        wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
782
+                        wpinv_update_option( 'paypal_merchant_id', '' );
783
+                        wpinv_update_option( 'paypal_client_id', sanitize_text_field( '' ) );
784
+                        wpinv_update_option( 'paypal_client_secret', sanitize_text_field( '' ) );
785
+                        wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( '' ) );
786
+                        wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
787
+                        set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
788
+                        getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
789
+                    }
790
+
791
+                }
792
+
793
+            }
794
+
795
+        }
796
+
797
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
798
+
799
+        if ( isset( $data['step'] ) ) {
800
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
801
+        }
802
+        wp_redirect( $redirect );
803
+        exit;
804
+    }
805 805
 
806 806
 }
Please login to merge, or discard this patch.