Passed
Push — master ( 13ee52...d39dbf )
by Brian
05:37
created
includes/class-getpaid-checkout.php 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -12,168 +12,168 @@  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
-		// Get the items and 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( $invoice );
43
-
44
-		// Save the invoice.
45
-		$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
+        // Get the items and 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( $invoice );
43
+
44
+        // Save the invoice.
45
+        $invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48
-		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
50
-	}
48
+        // Send to the gateway.
49
+        $this->post_process_submission( $invoice, $prepared );
50
+    }
51 51
 
52
-	/**
53
-	 * Validates the submission.
54
-	 *
55
-	 */
56
-	protected function validate_submission() {
52
+    /**
53
+     * Validates the submission.
54
+     *
55
+     */
56
+    protected function validate_submission() {
57 57
 
58
-		$submission = $this->payment_form_submission;
59
-		$data       = $submission->get_data();
58
+        $submission = $this->payment_form_submission;
59
+        $data       = $submission->get_data();
60 60
 
61
-		// Do we have an error?
61
+        // Do we have an error?
62 62
         if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
63
+            wp_send_json_error( $submission->last_error );
64 64
         }
65 65
 
66
-		// We need a billing email.
66
+        // We need a billing email.
67 67
         if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
68 68
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
69
-		}
69
+        }
70 70
 
71
-		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
74
-		}
71
+        // Non-recurring gateways should not be allowed to process recurring invoices.
72
+        if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
74
+        }
75 75
 	
76
-		// Ensure the gateway is active.
77
-		if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
-		}
76
+        // Ensure the gateway is active.
77
+        if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
+        }
80 80
 
81
-		// Clear any existing errors.
82
-		wpinv_clear_errors();
81
+        // Clear any existing errors.
82
+        wpinv_clear_errors();
83 83
 		
84
-		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
84
+        // Allow themes and plugins to hook to errors
85
+        do_action( 'getpaid_checkout_error_checks', $submission );
86 86
 		
87
-		// Do we have any errors?
87
+        // Do we have any errors?
88 88
         if ( wpinv_get_errors() ) {
89 89
             wp_send_json_error( getpaid_get_errors_html() );
90
-		}
90
+        }
91 91
 
92
-	}
92
+    }
93 93
 
94
-	/**
95
-	 * Retrieves submission items.
96
-	 *
97
-	 * @return GetPaid_Form_Item[]
98
-	 */
99
-	protected function get_submission_items() {
94
+    /**
95
+     * Retrieves submission items.
96
+     *
97
+     * @return GetPaid_Form_Item[]
98
+     */
99
+    protected function get_submission_items() {
100 100
 
101
-		$items = $this->payment_form_submission->get_items();
101
+        $items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104 104
         if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) {
105 105
             wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) );
106
-		}
106
+        }
107 107
 
108
-		return $items;
109
-	}
108
+        return $items;
109
+    }
110 110
 
111
-	/**
112
-	 * Retrieves submission invoice.
113
-	 *
114
-	 * @return WPInv_Invoice
115
-	 */
116
-	protected function get_submission_invoice() {
117
-		$submission = $this->payment_form_submission;
111
+    /**
112
+     * Retrieves submission invoice.
113
+     *
114
+     * @return WPInv_Invoice
115
+     */
116
+    protected function get_submission_invoice() {
117
+        $submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
120
-			return new WPInv_Invoice();
119
+        if ( ! $submission->has_invoice() ) {
120
+            return new WPInv_Invoice();
121 121
         }
122 122
 
123
-		$invoice = $submission->get_invoice();
123
+        $invoice = $submission->get_invoice();
124 124
 
125
-		// Make sure that it is neither paid or refunded.
126
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
-		}
125
+        // Make sure that it is neither paid or refunded.
126
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
+        }
129 129
 
130
-		return $invoice;
131
-	}
130
+        return $invoice;
131
+    }
132 132
 
133
-	/**
134
-	 * Processes the submission invoice.
135
-	 *
136
-	 * @param WPInv_Invoice $invoice
137
-	 * @param GetPaid_Form_Item[] $items
138
-	 * @return WPInv_Invoice
139
-	 */
140
-	protected function process_submission_invoice( $invoice, $items ) {
133
+    /**
134
+     * Processes the submission invoice.
135
+     *
136
+     * @param WPInv_Invoice $invoice
137
+     * @param GetPaid_Form_Item[] $items
138
+     * @return WPInv_Invoice
139
+     */
140
+    protected function process_submission_invoice( $invoice, $items ) {
141 141
 
142
-		$submission = $this->payment_form_submission;
143
-		$data       = $submission->get_data();
142
+        $submission = $this->payment_form_submission;
143
+        $data       = $submission->get_data();
144 144
 
145
-		// Set-up the invoice details.
146
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
-		$invoice->set_user_id( $this->get_submission_customer() );
148
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
145
+        // Set-up the invoice details.
146
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
+        $invoice->set_user_id( $this->get_submission_customer() );
148
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
149 149
         $invoice->set_items( $items );
150 150
         $invoice->set_fees( $submission->get_fees() );
151 151
         $invoice->set_taxes( $submission->get_taxes() );
152
-		$invoice->set_discounts( $submission->get_discounts() );
153
-		$invoice->set_gateway( $data['wpi-gateway'] );
152
+        $invoice->set_discounts( $submission->get_discounts() );
153
+        $invoice->set_gateway( $data['wpi-gateway'] );
154 154
 
155
-		if ( $submission->has_discount_code() ) {
155
+        if ( $submission->has_discount_code() ) {
156 156
             $invoice->set_discount_code( $submission->get_discount_code() );
157
-		}
158
-
159
-		getpaid_maybe_add_default_address( $invoice );
160
-		return $invoice;
161
-	}
162
-
163
-	/**
164
-	 * Retrieves the submission's customer.
165
-	 *
166
-	 * @return int The customer id.
167
-	 */
168
-	protected function get_submission_customer() {
169
-		$submission = $this->payment_form_submission;
170
-
171
-		// If this is an existing invoice...
172
-		if ( $submission->has_invoice() ) {
173
-			return $submission->get_invoice()->get_user_id();
174
-		}
175
-
176
-		// (Maybe) create the user.
157
+        }
158
+
159
+        getpaid_maybe_add_default_address( $invoice );
160
+        return $invoice;
161
+    }
162
+
163
+    /**
164
+     * Retrieves the submission's customer.
165
+     *
166
+     * @return int The customer id.
167
+     */
168
+    protected function get_submission_customer() {
169
+        $submission = $this->payment_form_submission;
170
+
171
+        // If this is an existing invoice...
172
+        if ( $submission->has_invoice() ) {
173
+            return $submission->get_invoice()->get_user_id();
174
+        }
175
+
176
+        // (Maybe) create the user.
177 177
         $user = get_current_user_id();
178 178
 
179 179
         if ( empty( $user ) ) {
@@ -190,31 +190,31 @@  discard block
 block discarded – undo
190 190
 
191 191
         if ( is_numeric( $user ) ) {
192 192
             return $user;
193
-		}
193
+        }
194 194
 
195
-		return $user->ID;
195
+        return $user->ID;
196 196
 
197
-	}
197
+    }
198 198
 
199
-	/**
199
+    /**
200 200
      * Prepares submission data for saving to the database.
201 201
      *
202
-	 * @param WPInv_Invoice $invoice
202
+     * @param WPInv_Invoice $invoice
203 203
      */
204 204
     public function prepare_submission_data_for_saving( &$invoice ) {
205 205
 
206
-		$submission = $this->payment_form_submission;
206
+        $submission = $this->payment_form_submission;
207 207
 
208
-		// Prepared submission details.
208
+        // Prepared submission details.
209 209
         $prepared = array();
210 210
 
211 211
         // Raw submission details.
212
-		$data = $submission->get_data();
212
+        $data = $submission->get_data();
213 213
 		
214
-		// Loop throught the submitted details.
214
+        // Loop throught the submitted details.
215 215
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
216 216
 
217
-			// Skip premade fields.
217
+            // Skip premade fields.
218 218
             if ( ! empty( $field['premade'] ) ) {
219 219
                 continue;
220 220
             }
@@ -257,26 +257,26 @@  discard block
 block discarded – undo
257 257
                 $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
258 258
             }
259 259
 
260
-		}
260
+        }
261 261
 		
262
-		return $prepared;
262
+        return $prepared;
263 263
 
264
-	}
264
+    }
265 265
 
266
-	/**
267
-	 * Confirms the submission is valid and send users to the gateway.
268
-	 *
269
-	 * @param WPInv_Invoice $invoice
270
-	 * @param array $prepared_payment_form_data
271
-	 */
272
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
266
+    /**
267
+     * Confirms the submission is valid and send users to the gateway.
268
+     *
269
+     * @param WPInv_Invoice $invoice
270
+     * @param array $prepared_payment_form_data
271
+     */
272
+    protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
273 273
 
274
-		// Ensure the invoice exists.
274
+        // Ensure the invoice exists.
275 275
         if ( $invoice->get_id() == 0 ) {
276 276
             wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
277 277
         }
278 278
 
279
-		// Was this invoice created via the payment form?
279
+        // Was this invoice created via the payment form?
280 280
         if ( ! $this->payment_form_submission->has_invoice() ) {
281 281
             update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' );
282 282
         }
@@ -284,65 +284,65 @@  discard block
 block discarded – undo
284 284
         // Save payment form data.
285 285
         if ( ! empty( $prepared_payment_form_data ) ) {
286 286
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
287
-		}
287
+        }
288 288
 
289
-		// Backwards compatibility.
289
+        // Backwards compatibility.
290 290
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
291 291
 
292
-		$this->process_payment( $invoice );
292
+        $this->process_payment( $invoice );
293 293
 
294 294
         // If we are here, there was an error.
295
-		wpinv_send_back_to_checkout();
295
+        wpinv_send_back_to_checkout();
296 296
 
297
-	}
297
+    }
298 298
 
299
-	/**
300
-	 * Processes the actual payment.
301
-	 *
302
-	 * @param WPInv_Invoice $invoice
303
-	 */
304
-	protected function process_payment( $invoice ) {
299
+    /**
300
+     * Processes the actual payment.
301
+     *
302
+     * @param WPInv_Invoice $invoice
303
+     */
304
+    protected function process_payment( $invoice ) {
305 305
 
306
-		$submission = $this->payment_form_submission;
306
+        $submission = $this->payment_form_submission;
307 307
 
308
-		// No need to send free invoices to the gateway.
309
-		if ( $invoice->is_free() ) {
310
-			$invoice->set_gateway( 'none' );
311
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
312
-			$invoice->mark_paid();
313
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
314
-		}
308
+        // No need to send free invoices to the gateway.
309
+        if ( $invoice->is_free() ) {
310
+            $invoice->set_gateway( 'none' );
311
+            $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
312
+            $invoice->mark_paid();
313
+            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
314
+        }
315 315
 
316
-		// Clear any checkout errors.
317
-		wpinv_clear_errors();
316
+        // Clear any checkout errors.
317
+        wpinv_clear_errors();
318 318
 
319
-		// Fires before sending to the gateway.
320
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
319
+        // Fires before sending to the gateway.
320
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
321 321
 
322
-		// Allow the sumission data to be modified before it is sent to the gateway.
323
-		$submission_data    = $submission->get_data();
324
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
325
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
322
+        // Allow the sumission data to be modified before it is sent to the gateway.
323
+        $submission_data    = $submission->get_data();
324
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
325
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
326 326
 
327
-		// Validate the currency.
328
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
329
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
330
-		}
327
+        // Validate the currency.
328
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
329
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
330
+        }
331 331
 
332
-		// Check to see if we have any errors.
333
-		if ( wpinv_get_errors() ) {
334
-			wpinv_send_back_to_checkout();
335
-		}
332
+        // Check to see if we have any errors.
333
+        if ( wpinv_get_errors() ) {
334
+            wpinv_send_back_to_checkout();
335
+        }
336 336
 
337
-		// Send info to the gateway for payment processing
338
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
337
+        // Send info to the gateway for payment processing
338
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
339 339
 
340
-		// Backwards compatibility.
341
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
340
+        // Backwards compatibility.
341
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
342 342
 
343
-	}
343
+    }
344 344
 
345
-	/**
345
+    /**
346 346
      * Sends a redrect response to payment details.
347 347
      *
348 348
      */
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 		// Get the items and invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving( $invoice );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42
+		$prepared   = $this->prepare_submission_data_for_saving($invoice);
43 43
 
44 44
 		// Save the invoice.
45 45
 		$invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48 48
 		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
49
+		$this->post_process_submission($invoice, $prepared);
50 50
 	}
51 51
 
52 52
 	/**
@@ -59,34 +59,34 @@  discard block
 block discarded – undo
59 59
 		$data       = $submission->get_data();
60 60
 
61 61
 		// Do we have an error?
62
-        if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
62
+        if (!empty($submission->last_error)) {
63
+			wp_send_json_error($submission->last_error);
64 64
         }
65 65
 
66 66
 		// We need a billing email.
67
-        if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
68
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
67
+        if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) {
68
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
69 69
 		}
70 70
 
71 71
 		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
72
+		if ($submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
73
+			wp_send_json_error(__('The selected payment gateway does not support subscription payment.', 'invoicing'));
74 74
 		}
75 75
 	
76 76
 		// Ensure the gateway is active.
77
-		if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
77
+		if (!wpinv_is_gateway_active($data['wpi-gateway'])) {
78
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
79 79
 		}
80 80
 
81 81
 		// Clear any existing errors.
82 82
 		wpinv_clear_errors();
83 83
 		
84 84
 		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
85
+		do_action('getpaid_checkout_error_checks', $submission);
86 86
 		
87 87
 		// Do we have any errors?
88
-        if ( wpinv_get_errors() ) {
89
-            wp_send_json_error( getpaid_get_errors_html() );
88
+        if (wpinv_get_errors()) {
89
+            wp_send_json_error(getpaid_get_errors_html());
90 90
 		}
91 91
 
92 92
 	}
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 		$items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104
-        if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) {
105
-            wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) );
104
+        if (empty($items) && 0 == count($this->payment_form_submission->get_fees())) {
105
+            wp_send_json_error(__('Please select at least one item.', 'invoicing'));
106 106
 		}
107 107
 
108 108
 		return $items;
@@ -116,15 +116,15 @@  discard block
 block discarded – undo
116 116
 	protected function get_submission_invoice() {
117 117
 		$submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
119
+		if (!$submission->has_invoice()) {
120 120
 			return new WPInv_Invoice();
121 121
         }
122 122
 
123 123
 		$invoice = $submission->get_invoice();
124 124
 
125 125
 		// Make sure that it is neither paid or refunded.
126
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
126
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
127
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
128 128
 		}
129 129
 
130 130
 		return $invoice;
@@ -137,26 +137,26 @@  discard block
 block discarded – undo
137 137
 	 * @param GetPaid_Form_Item[] $items
138 138
 	 * @return WPInv_Invoice
139 139
 	 */
140
-	protected function process_submission_invoice( $invoice, $items ) {
140
+	protected function process_submission_invoice($invoice, $items) {
141 141
 
142 142
 		$submission = $this->payment_form_submission;
143 143
 		$data       = $submission->get_data();
144 144
 
145 145
 		// Set-up the invoice details.
146
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
-		$invoice->set_user_id( $this->get_submission_customer() );
148
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
149
-        $invoice->set_items( $items );
150
-        $invoice->set_fees( $submission->get_fees() );
151
-        $invoice->set_taxes( $submission->get_taxes() );
152
-		$invoice->set_discounts( $submission->get_discounts() );
153
-		$invoice->set_gateway( $data['wpi-gateway'] );
154
-
155
-		if ( $submission->has_discount_code() ) {
156
-            $invoice->set_discount_code( $submission->get_discount_code() );
146
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
147
+		$invoice->set_user_id($this->get_submission_customer());
148
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
149
+        $invoice->set_items($items);
150
+        $invoice->set_fees($submission->get_fees());
151
+        $invoice->set_taxes($submission->get_taxes());
152
+		$invoice->set_discounts($submission->get_discounts());
153
+		$invoice->set_gateway($data['wpi-gateway']);
154
+
155
+		if ($submission->has_discount_code()) {
156
+            $invoice->set_discount_code($submission->get_discount_code());
157 157
 		}
158 158
 
159
-		getpaid_maybe_add_default_address( $invoice );
159
+		getpaid_maybe_add_default_address($invoice);
160 160
 		return $invoice;
161 161
 	}
162 162
 
@@ -169,26 +169,26 @@  discard block
 block discarded – undo
169 169
 		$submission = $this->payment_form_submission;
170 170
 
171 171
 		// If this is an existing invoice...
172
-		if ( $submission->has_invoice() ) {
172
+		if ($submission->has_invoice()) {
173 173
 			return $submission->get_invoice()->get_user_id();
174 174
 		}
175 175
 
176 176
 		// (Maybe) create the user.
177 177
         $user = get_current_user_id();
178 178
 
179
-        if ( empty( $user ) ) {
180
-            $user = get_user_by( 'email', $submission->get_billing_email() );
179
+        if (empty($user)) {
180
+            $user = get_user_by('email', $submission->get_billing_email());
181 181
         }
182 182
 
183
-        if ( empty( $user ) ) {
184
-            $user = wpinv_create_user( $submission->get_billing_email() );
183
+        if (empty($user)) {
184
+            $user = wpinv_create_user($submission->get_billing_email());
185 185
         }
186 186
 
187
-        if ( is_wp_error( $user ) ) {
188
-            wp_send_json_error( $user->get_error_message() );
187
+        if (is_wp_error($user)) {
188
+            wp_send_json_error($user->get_error_message());
189 189
         }
190 190
 
191
-        if ( is_numeric( $user ) ) {
191
+        if (is_numeric($user)) {
192 192
             return $user;
193 193
 		}
194 194
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      *
202 202
 	 * @param WPInv_Invoice $invoice
203 203
      */
204
-    public function prepare_submission_data_for_saving( &$invoice ) {
204
+    public function prepare_submission_data_for_saving(&$invoice) {
205 205
 
206 206
 		$submission = $this->payment_form_submission;
207 207
 
@@ -212,49 +212,49 @@  discard block
 block discarded – undo
212 212
 		$data = $submission->get_data();
213 213
 		
214 214
 		// Loop throught the submitted details.
215
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
215
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
216 216
 
217 217
 			// Skip premade fields.
218
-            if ( ! empty( $field['premade'] ) ) {
218
+            if (!empty($field['premade'])) {
219 219
                 continue;
220 220
             }
221 221
 
222 222
             // If it is required and not set, abort.
223
-            if ( ! $submission->is_required_field_set( $field ) ) {
224
-                wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
223
+            if (!$submission->is_required_field_set($field)) {
224
+                wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
225 225
             }
226 226
 
227 227
             // Handle address fields.
228
-            if ( $field['type'] == 'address' ) {
228
+            if ($field['type'] == 'address') {
229 229
 
230
-                foreach ( $field['fields'] as $address_field ) {
230
+                foreach ($field['fields'] as $address_field) {
231 231
 
232 232
                     // skip if it is not visible.
233
-                    if ( empty( $address_field['visible'] ) ) {
233
+                    if (empty($address_field['visible'])) {
234 234
                         continue;
235 235
                     }
236 236
 
237 237
                     // If it is required and not set, abort
238
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
239
-                        wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
238
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
239
+                        wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
240 240
                     }
241 241
 
242
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
243
-                        $name   = str_replace( 'wpinv_', '', $address_field['name'] );
242
+                    if (isset($data[$address_field['name']])) {
243
+                        $name   = str_replace('wpinv_', '', $address_field['name']);
244 244
                         $method = "set_$name";
245
-                        $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) );
245
+                        $invoice->$method(wpinv_clean($data[$address_field['name']]));
246 246
                     }
247 247
 
248 248
                 }
249 249
 
250
-            } else if ( isset( $data[ $field['id'] ] ) ) {
250
+            } else if (isset($data[$field['id']])) {
251 251
                 $label = $field['id'];
252 252
 
253
-                if ( isset( $field['label'] ) ) {
253
+                if (isset($field['label'])) {
254 254
                     $label = $field['label'];
255 255
                 }
256 256
 
257
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
257
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
258 258
             }
259 259
 
260 260
 		}
@@ -269,27 +269,27 @@  discard block
 block discarded – undo
269 269
 	 * @param WPInv_Invoice $invoice
270 270
 	 * @param array $prepared_payment_form_data
271 271
 	 */
272
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
272
+	protected function post_process_submission($invoice, $prepared_payment_form_data) {
273 273
 
274 274
 		// Ensure the invoice exists.
275
-        if ( $invoice->get_id() == 0 ) {
276
-            wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
275
+        if ($invoice->get_id() == 0) {
276
+            wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing'));
277 277
         }
278 278
 
279 279
 		// Was this invoice created via the payment form?
280
-        if ( ! $this->payment_form_submission->has_invoice() ) {
281
-            update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' );
280
+        if (!$this->payment_form_submission->has_invoice()) {
281
+            update_post_meta($invoice->get_id(), 'wpinv_created_via', 'payment_form');
282 282
         }
283 283
 
284 284
         // Save payment form data.
285
-        if ( ! empty( $prepared_payment_form_data ) ) {
286
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
285
+        if (!empty($prepared_payment_form_data)) {
286
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
287 287
 		}
288 288
 
289 289
 		// Backwards compatibility.
290
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
290
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
291 291
 
292
-		$this->process_payment( $invoice );
292
+		$this->process_payment($invoice);
293 293
 
294 294
         // If we are here, there was an error.
295 295
 		wpinv_send_back_to_checkout();
@@ -301,44 +301,44 @@  discard block
 block discarded – undo
301 301
 	 *
302 302
 	 * @param WPInv_Invoice $invoice
303 303
 	 */
304
-	protected function process_payment( $invoice ) {
304
+	protected function process_payment($invoice) {
305 305
 
306 306
 		$submission = $this->payment_form_submission;
307 307
 
308 308
 		// No need to send free invoices to the gateway.
309
-		if ( $invoice->is_free() ) {
310
-			$invoice->set_gateway( 'none' );
311
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
309
+		if ($invoice->is_free()) {
310
+			$invoice->set_gateway('none');
311
+			$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
312 312
 			$invoice->mark_paid();
313
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
313
+			wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
314 314
 		}
315 315
 
316 316
 		// Clear any checkout errors.
317 317
 		wpinv_clear_errors();
318 318
 
319 319
 		// Fires before sending to the gateway.
320
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
320
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
321 321
 
322 322
 		// Allow the sumission data to be modified before it is sent to the gateway.
323 323
 		$submission_data    = $submission->get_data();
324
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
325
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
324
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
325
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
326 326
 
327 327
 		// Validate the currency.
328
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
329
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
328
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
329
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing'));
330 330
 		}
331 331
 
332 332
 		// Check to see if we have any errors.
333
-		if ( wpinv_get_errors() ) {
333
+		if (wpinv_get_errors()) {
334 334
 			wpinv_send_back_to_checkout();
335 335
 		}
336 336
 
337 337
 		// Send info to the gateway for payment processing
338
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
338
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
339 339
 
340 340
 		// Backwards compatibility.
341
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
341
+		wpinv_send_to_gateway($submission_gateway, $invoice);
342 342
 
343 343
 	}
344 344
 
@@ -346,9 +346,9 @@  discard block
 block discarded – undo
346 346
      * Sends a redrect response to payment details.
347 347
      *
348 348
      */
349
-    public function send_redirect_response( $url ) {
350
-        $url = urlencode( $url );
351
-        wp_send_json_success( $url );
349
+    public function send_redirect_response($url) {
350
+        $url = urlencode($url);
351
+        wp_send_json_success($url);
352 352
     }
353 353
 
354 354
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 2 patches
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -14,61 +14,61 @@  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
-	 */
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 28
     public $admin_url;
29 29
 
30 30
     /**
31
-	 * Class constructor.
32
-	 */
33
-	public function __construct(){
31
+     * Class constructor.
32
+     */
33
+    public function __construct(){
34 34
 
35 35
         $this->admin_path  = plugin_dir_path( __FILE__ );
36 36
         $this->admin_url   = plugins_url( '/', __FILE__ );
37 37
 
38 38
         if ( is_admin() ) {
39
-			$this->init_admin_hooks();
39
+            $this->init_admin_hooks();
40 40
         }
41 41
 
42 42
     }
43 43
 
44 44
     /**
45
-	 * Init action and filter hooks
46
-	 *
47
-	 */
48
-	private function init_admin_hooks() {
45
+     * Init action and filter hooks
46
+     *
47
+     */
48
+    private function init_admin_hooks() {
49 49
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50 50
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51 51
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52 52
         add_action( 'admin_init', array( $this, 'activation_redirect') );
53 53
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
54
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
+        do_action( 'getpaid_init_admin_hooks', $this );
58 58
 
59 59
     }
60 60
 
61 61
     /**
62
-	 * Register admin scripts
63
-	 *
64
-	 */
65
-	public function enqeue_scripts() {
62
+     * Register admin scripts
63
+     *
64
+     */
65
+    public function enqeue_scripts() {
66 66
         global $current_screen;
67 67
 
68 68
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
69 69
 
70 70
         if ( ! empty( $current_screen->post_type ) ) {
71
-			$page = $current_screen->post_type;
71
+            $page = $current_screen->post_type;
72 72
         }
73 73
 
74 74
         // General styles.
@@ -92,30 +92,30 @@  discard block
 block discarded – undo
92 92
         }
93 93
 
94 94
         // Payment form scripts.
95
-		if ( 'wpi_payment_form' == $page ) {
95
+        if ( 'wpi_payment_form' == $page ) {
96 96
             $this->load_payment_form_scripts();
97 97
         }
98 98
 
99 99
         if ( $page == 'wpinv-subscriptions' ) {
100
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
102
-		}
100
+            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
+            wp_enqueue_script( 'wpinv-sub-admin-script' );
102
+        }
103 103
 
104
-		if ( $page == 'wpinv-reports' ) {
105
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
106
-		}
104
+        if ( $page == 'wpinv-reports' ) {
105
+            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
106
+        }
107 107
 
108
-		if ( $page == 'wpinv-subscriptions' ) {
109
-			wp_enqueue_script( 'postbox' );
110
-		}
108
+        if ( $page == 'wpinv-subscriptions' ) {
109
+            wp_enqueue_script( 'postbox' );
110
+        }
111 111
 
112 112
     }
113 113
 
114 114
     /**
115
-	 * Returns admin js translations.
116
-	 *
117
-	 */
118
-	protected function get_admin_i18() {
115
+     * Returns admin js translations.
116
+     *
117
+     */
118
+    protected function get_admin_i18() {
119 119
         global $post;
120 120
 
121 121
         return array(
@@ -156,33 +156,33 @@  discard block
 block discarded – undo
156 156
     }
157 157
 
158 158
     /**
159
-	 * Loads payment form js.
160
-	 *
161
-	 */
162
-	protected function load_payment_form_scripts() {
159
+     * Loads payment form js.
160
+     *
161
+     */
162
+    protected function load_payment_form_scripts() {
163 163
         global $post;
164 164
 
165 165
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
166
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
166
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
168 168
 
169
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
169
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
171 171
 
172
-		wp_localize_script(
172
+        wp_localize_script(
173 173
             'wpinv-admin-payment-form-script',
174 174
             'wpinvPaymentFormAdmin',
175 175
             array(
176
-				'elements'      => getpaid()->form_elements->get_elements(),
177
-				'form_elements' => getpaid()->form_elements->get_form_elements( $post->ID ),
178
-				'all_items'     => getpaid()->form_elements->get_published_items(),
179
-				'currency'      => wpinv_currency_symbol(),
180
-				'position'      => wpinv_currency_position(),
181
-				'decimals'      => (int) wpinv_decimals(),
182
-				'thousands_sep' => wpinv_thousands_separator(),
183
-				'decimals_sep'  => wpinv_decimal_separator(),
184
-				'form_items'    => getpaid()->form_elements->get_form_items( $post->ID ),
185
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
176
+                'elements'      => getpaid()->form_elements->get_elements(),
177
+                'form_elements' => getpaid()->form_elements->get_form_elements( $post->ID ),
178
+                'all_items'     => getpaid()->form_elements->get_published_items(),
179
+                'currency'      => wpinv_currency_symbol(),
180
+                'position'      => wpinv_currency_position(),
181
+                'decimals'      => (int) wpinv_decimals(),
182
+                'thousands_sep' => wpinv_thousands_separator(),
183
+                'decimals_sep'  => wpinv_decimal_separator(),
184
+                'form_items'    => getpaid()->form_elements->get_form_items( $post->ID ),
185
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
186 186
             )
187 187
         );
188 188
 
@@ -191,20 +191,20 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Add our classes to admin pages.
194
+     * Add our classes to admin pages.
195 195
      *
196 196
      * @param string $classes
197 197
      * @return string
198
-	 *
199
-	 */
198
+     *
199
+     */
200 200
     public function admin_body_class( $classes ) {
201
-		global $pagenow, $post, $current_screen;
201
+        global $pagenow, $post, $current_screen;
202 202
 
203 203
 
204 204
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
205 205
 
206 206
         if ( ! empty( $current_screen->post_type ) ) {
207
-			$page = $current_screen->post_type;
207
+            $page = $current_screen->post_type;
208 208
         }
209 209
 
210 210
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -215,27 +215,27 @@  discard block
 block discarded – undo
215 215
             $classes .= ' wpinv-cpt wpinv';
216 216
         }
217 217
 
218
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
-			$classes .= ' wpi-editable-n';
220
-		}
218
+        if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
+            $classes .= ' wpi-editable-n';
220
+        }
221 221
 
222
-		return $classes;
222
+        return $classes;
223 223
     }
224 224
 
225 225
     /**
226
-	 * Maybe show the AyeCode Connect Notice.
227
-	 */
228
-	public function init_ayecode_connect_helper(){
226
+     * Maybe show the AyeCode Connect Notice.
227
+     */
228
+    public function init_ayecode_connect_helper(){
229 229
 
230 230
         new AyeCode_Connect_Helper(
231 231
             array(
232
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
-				'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>" ),
235
-				'connect_button'    => __("Connect Site","invoicing"),
236
-				'connecting_button'    => __("Connecting...","invoicing"),
237
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
232
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
+                '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>" ),
235
+                'connect_button'    => __("Connect Site","invoicing"),
236
+                'connecting_button'    => __("Connecting...","invoicing"),
237
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
239 239
             ),
240 240
             array( 'wpi-addons' )
241 241
         );
@@ -247,21 +247,21 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function activation_redirect() {
249 249
 
250
-		// Bail if no activation redirect.
251
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
252
-			return;
253
-		}
250
+        // Bail if no activation redirect.
251
+        if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
252
+            return;
253
+        }
254 254
 
255
-		// Delete the redirect transient.
256
-		delete_transient( '_wpinv_activation_redirect' );
255
+        // Delete the redirect transient.
256
+        delete_transient( '_wpinv_activation_redirect' );
257 257
 
258
-		// Bail if activating from network, or bulk
259
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
-			return;
261
-		}
258
+        // Bail if activating from network, or bulk
259
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
+            return;
261
+        }
262 262
 
263
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
-		exit;
263
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
+        exit;
265 265
     }
266 266
 
267 267
     /**
@@ -276,150 +276,150 @@  discard block
 block discarded – undo
276 276
 
277 277
     }
278 278
 
279
-	/**
279
+    /**
280 280
      * Sends a payment reminder to a customer.
281
-	 * 
282
-	 * @param array $args
281
+     * 
282
+     * @param array $args
283 283
      */
284 284
     public function send_customer_invoice( $args ) {
285
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
285
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
286 286
 
287
-		if ( $sent ) {
288
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
-		} else {
290
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
-		}
287
+        if ( $sent ) {
288
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
+        } else {
290
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
+        }
292 292
 
293
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
-		exit;
295
-	}
293
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
+        exit;
295
+    }
296 296
 
297
-	/**
297
+    /**
298 298
      * Sends a payment reminder to a customer.
299
-	 * 
300
-	 * @param array $args
299
+     * 
300
+     * @param array $args
301 301
      */
302 302
     public function send_customer_payment_reminder( $args ) {
303
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
303
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
304 304
 
305
-		if ( $sent ) {
306
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
-		} else {
308
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
-		}
305
+        if ( $sent ) {
306
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
+        } else {
308
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
+        }
310 310
 
311
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
-		exit;
313
-	}
311
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
+        exit;
313
+    }
314 314
 
315 315
     /**
316
-	 * Returns an array of admin notices.
317
-	 *
318
-	 * @since       1.0.19
316
+     * Returns an array of admin notices.
317
+     *
318
+     * @since       1.0.19
319 319
      * @return array
320
-	 */
321
-	public function get_notices() {
322
-		$notices = get_option( 'wpinv_admin_notices' );
320
+     */
321
+    public function get_notices() {
322
+        $notices = get_option( 'wpinv_admin_notices' );
323 323
         return is_array( $notices ) ? $notices : array();
324
-	}
325
-
326
-	/**
327
-	 * Clears all admin notices
328
-	 *
329
-	 * @access      public
330
-	 * @since       1.0.19
331
-	 */
332
-	public function clear_notices() {
333
-		delete_option( 'wpinv_admin_notices' );
334
-	}
335
-
336
-	/**
337
-	 * Saves a new admin notice
338
-	 *
339
-	 * @access      public
340
-	 * @since       1.0.19
341
-	 */
342
-	public function save_notice( $type, $message ) {
343
-		$notices = $this->get_notices();
344
-
345
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
-			$notices[ $type ] = array();
347
-		}
348
-
349
-		$notices[ $type ][] = $message;
350
-
351
-		update_option( 'wpinv_admin_notices', $notices );
352
-	}
353
-
354
-	/**
355
-	 * Displays a success notice
356
-	 *
357
-	 * @param       string $msg The message to qeue.
358
-	 * @access      public
359
-	 * @since       1.0.19
360
-	 */
361
-	public function show_success( $msg ) {
362
-		$this->save_notice( 'success', $msg );
363
-	}
364
-
365
-	/**
366
-	 * Displays a error notice
367
-	 *
368
-	 * @access      public
369
-	 * @param       string $msg The message to qeue.
370
-	 * @since       1.0.19
371
-	 */
372
-	public function show_error( $msg ) {
373
-		$this->save_notice( 'error', $msg );
374
-	}
375
-
376
-	/**
377
-	 * Displays a warning notice
378
-	 *
379
-	 * @access      public
380
-	 * @param       string $msg The message to qeue.
381
-	 * @since       1.0.19
382
-	 */
383
-	public function show_warning( $msg ) {
384
-		$this->save_notice( 'warning', $msg );
385
-	}
386
-
387
-	/**
388
-	 * Displays a info notice
389
-	 *
390
-	 * @access      public
391
-	 * @param       string $msg The message to qeue.
392
-	 * @since       1.0.19
393
-	 */
394
-	public function show_info( $msg ) {
395
-		$this->save_notice( 'info', $msg );
396
-	}
397
-
398
-	/**
399
-	 * Show notices
400
-	 *
401
-	 * @access      public
402
-	 * @since       1.0.19
403
-	 */
404
-	public function show_notices() {
324
+    }
325
+
326
+    /**
327
+     * Clears all admin notices
328
+     *
329
+     * @access      public
330
+     * @since       1.0.19
331
+     */
332
+    public function clear_notices() {
333
+        delete_option( 'wpinv_admin_notices' );
334
+    }
335
+
336
+    /**
337
+     * Saves a new admin notice
338
+     *
339
+     * @access      public
340
+     * @since       1.0.19
341
+     */
342
+    public function save_notice( $type, $message ) {
343
+        $notices = $this->get_notices();
344
+
345
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
+            $notices[ $type ] = array();
347
+        }
348
+
349
+        $notices[ $type ][] = $message;
350
+
351
+        update_option( 'wpinv_admin_notices', $notices );
352
+    }
353
+
354
+    /**
355
+     * Displays a success notice
356
+     *
357
+     * @param       string $msg The message to qeue.
358
+     * @access      public
359
+     * @since       1.0.19
360
+     */
361
+    public function show_success( $msg ) {
362
+        $this->save_notice( 'success', $msg );
363
+    }
364
+
365
+    /**
366
+     * Displays a error notice
367
+     *
368
+     * @access      public
369
+     * @param       string $msg The message to qeue.
370
+     * @since       1.0.19
371
+     */
372
+    public function show_error( $msg ) {
373
+        $this->save_notice( 'error', $msg );
374
+    }
375
+
376
+    /**
377
+     * Displays a warning notice
378
+     *
379
+     * @access      public
380
+     * @param       string $msg The message to qeue.
381
+     * @since       1.0.19
382
+     */
383
+    public function show_warning( $msg ) {
384
+        $this->save_notice( 'warning', $msg );
385
+    }
386
+
387
+    /**
388
+     * Displays a info notice
389
+     *
390
+     * @access      public
391
+     * @param       string $msg The message to qeue.
392
+     * @since       1.0.19
393
+     */
394
+    public function show_info( $msg ) {
395
+        $this->save_notice( 'info', $msg );
396
+    }
397
+
398
+    /**
399
+     * Show notices
400
+     *
401
+     * @access      public
402
+     * @since       1.0.19
403
+     */
404
+    public function show_notices() {
405 405
 
406 406
         $notices = $this->get_notices();
407 407
         $this->clear_notices();
408 408
 
409
-		foreach ( $notices as $type => $messages ) {
409
+        foreach ( $notices as $type => $messages ) {
410 410
 
411
-			if ( ! is_array( $messages ) ) {
412
-				continue;
413
-			}
411
+            if ( ! is_array( $messages ) ) {
412
+                continue;
413
+            }
414 414
 
415 415
             $type  = sanitize_key( $type );
416
-			foreach ( $messages as $message ) {
416
+            foreach ( $messages as $message ) {
417 417
                 $message = wp_kses_post( $message );
418
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
418
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
419 419
             }
420 420
 
421 421
         }
422 422
 
423
-	}
423
+    }
424 424
 
425 425
 }
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * The main admin class.
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
     /**
31 31
 	 * Class constructor.
32 32
 	 */
33
-	public function __construct(){
33
+	public function __construct() {
34 34
 
35
-        $this->admin_path  = plugin_dir_path( __FILE__ );
36
-        $this->admin_url   = plugins_url( '/', __FILE__ );
35
+        $this->admin_path  = plugin_dir_path(__FILE__);
36
+        $this->admin_url   = plugins_url('/', __FILE__);
37 37
 
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
 			$this->init_admin_hooks();
40 40
         }
41 41
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 */
48 48
 	private function init_admin_hooks() {
49
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
53
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
49
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
50
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
51
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
52
+        add_action('admin_init', array($this, 'activation_redirect'));
53
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
54
+		add_action('admin_notices', array($this, 'show_notices'));
55
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
56
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
57
+		do_action('getpaid_init_admin_hooks', $this);
58 58
 
59 59
     }
60 60
 
@@ -65,48 +65,48 @@  discard block
 block discarded – undo
65 65
 	public function enqeue_scripts() {
66 66
         global $current_screen;
67 67
 
68
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
68
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
69 69
 
70
-        if ( ! empty( $current_screen->post_type ) ) {
70
+        if (!empty($current_screen->post_type)) {
71 71
 			$page = $current_screen->post_type;
72 72
         }
73 73
 
74 74
         // General styles.
75
-        if ( false!== stripos( $page, 'wpi' ) ) {
75
+        if (false !== stripos($page, 'wpi')) {
76 76
 
77 77
             // Styles.
78
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
79
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
80
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
81
-            wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
82
-            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
78
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
79
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
80
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
81
+            wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
82
+            wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16');
83 83
 
84 84
             // Scripts.
85
-            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
86
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
85
+            wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true);
86
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
87 87
 
88
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
89
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ),  $version );
90
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
88
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
89
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version);
90
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
91 91
 
92 92
         }
93 93
 
94 94
         // Payment form scripts.
95
-		if ( 'wpi_payment_form' == $page ) {
95
+		if ('wpi_payment_form' == $page) {
96 96
             $this->load_payment_form_scripts();
97 97
         }
98 98
 
99
-        if ( $page == 'wpinv-subscriptions' ) {
100
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
99
+        if ($page == 'wpinv-subscriptions') {
100
+			wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
101
+			wp_enqueue_script('wpinv-sub-admin-script');
102 102
 		}
103 103
 
104
-		if ( $page == 'wpinv-reports' ) {
105
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
104
+		if ($page == 'wpinv-reports') {
105
+			wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
106 106
 		}
107 107
 
108
-		if ( $page == 'wpinv-subscriptions' ) {
109
-			wp_enqueue_script( 'postbox' );
108
+		if ($page == 'wpinv-subscriptions') {
109
+			wp_enqueue_script('postbox');
110 110
 		}
111 111
 
112 112
     }
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
         global $post;
120 120
 
121 121
         return array(
122
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
123
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
124
-            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
125
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
126
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
127
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
128
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
122
+            'ajax_url'                  => admin_url('admin-ajax.php'),
123
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
124
+            'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
125
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
126
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
127
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
128
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
129 129
             'tax'                       => wpinv_tax_amount(),
130 130
             'discount'                  => wpinv_discount_amount(),
131 131
             'currency_symbol'           => wpinv_currency_symbol(),
@@ -133,24 +133,24 @@  discard block
 block discarded – undo
133 133
             'thousand_sep'              => wpinv_thousands_separator(),
134 134
             'decimal_sep'               => wpinv_decimal_separator(),
135 135
             'decimals'                  => wpinv_decimals(),
136
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
137
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
138
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
139
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
140
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
141
-            'OneItemMin'                => __( 'Invoice must contain at least one item', 'invoicing' ),
142
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
143
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
144
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
145
-            'emptyInvoice'              => __( 'Add at least one item to save invoice!', 'invoicing' ),
146
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
147
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
148
-            'action_edit'               => __( 'Edit', 'invoicing' ),
149
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
150
-            'item_description'          => __( 'Item Description', 'invoicing' ),
151
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
152
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
153
-            'searching'                 => __( 'Searching', 'invoicing' ),
136
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
137
+            'status_publish'            => wpinv_status_nicename('publish'),
138
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
139
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
140
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
141
+            'OneItemMin'                => __('Invoice must contain at least one item', 'invoicing'),
142
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
143
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
144
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
145
+            'emptyInvoice'              => __('Add at least one item to save invoice!', 'invoicing'),
146
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
147
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
148
+            'action_edit'               => __('Edit', 'invoicing'),
149
+            'action_cancel'             => __('Cancel', 'invoicing'),
150
+            'item_description'          => __('Item Description', 'invoicing'),
151
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
152
+            'discount_description'      => __('Discount Description', 'invoicing'),
153
+            'searching'                 => __('Searching', 'invoicing'),
154 154
         );
155 155
 
156 156
     }
@@ -162,31 +162,31 @@  discard block
 block discarded – undo
162 162
 	protected function load_payment_form_scripts() {
163 163
         global $post;
164 164
 
165
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
166
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
165
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
166
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
167
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
168 168
 
169
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
169
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
170
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
171 171
 
172 172
 		wp_localize_script(
173 173
             'wpinv-admin-payment-form-script',
174 174
             'wpinvPaymentFormAdmin',
175 175
             array(
176 176
 				'elements'      => getpaid()->form_elements->get_elements(),
177
-				'form_elements' => getpaid()->form_elements->get_form_elements( $post->ID ),
177
+				'form_elements' => getpaid()->form_elements->get_form_elements($post->ID),
178 178
 				'all_items'     => getpaid()->form_elements->get_published_items(),
179 179
 				'currency'      => wpinv_currency_symbol(),
180 180
 				'position'      => wpinv_currency_position(),
181 181
 				'decimals'      => (int) wpinv_decimals(),
182 182
 				'thousands_sep' => wpinv_thousands_separator(),
183 183
 				'decimals_sep'  => wpinv_decimal_separator(),
184
-				'form_items'    => getpaid()->form_elements->get_form_items( $post->ID ),
184
+				'form_items'    => getpaid()->form_elements->get_form_items($post->ID),
185 185
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
186 186
             )
187 187
         );
188 188
 
189
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
189
+        wp_enqueue_script('wpinv-admin-payment-form-script');
190 190
 
191 191
     }
192 192
 
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
      * @return string
198 198
 	 *
199 199
 	 */
200
-    public function admin_body_class( $classes ) {
200
+    public function admin_body_class($classes) {
201 201
 		global $pagenow, $post, $current_screen;
202 202
 
203 203
 
204
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
204
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
205 205
 
206
-        if ( ! empty( $current_screen->post_type ) ) {
206
+        if (!empty($current_screen->post_type)) {
207 207
 			$page = $current_screen->post_type;
208 208
         }
209 209
 
210
-        if ( false !== stripos( $page, 'wpi' ) ) {
211
-            $classes .= ' wpi-' . sanitize_key( $page );
210
+        if (false !== stripos($page, 'wpi')) {
211
+            $classes .= ' wpi-' . sanitize_key($page);
212 212
         }
213 213
 
214
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
214
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
215 215
             $classes .= ' wpinv-cpt wpinv';
216 216
         }
217 217
 
218
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
218
+		if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
219 219
 			$classes .= ' wpi-editable-n';
220 220
 		}
221 221
 
@@ -225,19 +225,19 @@  discard block
 block discarded – undo
225 225
     /**
226 226
 	 * Maybe show the AyeCode Connect Notice.
227 227
 	 */
228
-	public function init_ayecode_connect_helper(){
228
+	public function init_ayecode_connect_helper() {
229 229
 
230 230
         new AyeCode_Connect_Helper(
231 231
             array(
232
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
-				'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>" ),
235
-				'connect_button'    => __("Connect Site","invoicing"),
236
-				'connecting_button'    => __("Connecting...","invoicing"),
237
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
232
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
233
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
234
+				'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>"),
235
+				'connect_button'    => __("Connect Site", "invoicing"),
236
+				'connecting_button'    => __("Connecting...", "invoicing"),
237
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
238
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
239 239
             ),
240
-            array( 'wpi-addons' )
240
+            array('wpi-addons')
241 241
         );
242 242
 
243 243
     }
@@ -248,19 +248,19 @@  discard block
 block discarded – undo
248 248
     public function activation_redirect() {
249 249
 
250 250
 		// Bail if no activation redirect.
251
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
251
+		if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) {
252 252
 			return;
253 253
 		}
254 254
 
255 255
 		// Delete the redirect transient.
256
-		delete_transient( '_wpinv_activation_redirect' );
256
+		delete_transient('_wpinv_activation_redirect');
257 257
 
258 258
 		// Bail if activating from network, or bulk
259
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
259
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
260 260
 			return;
261 261
 		}
262 262
 
263
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
263
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
264 264
 		exit;
265 265
     }
266 266
 
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
      */
270 270
     public function maybe_do_admin_action() {
271 271
 
272
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
273
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
274
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
272
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
273
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
274
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
275 275
         }
276 276
 
277 277
     }
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 	 * 
282 282
 	 * @param array $args
283 283
      */
284
-    public function send_customer_invoice( $args ) {
285
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
284
+    public function send_customer_invoice($args) {
285
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
286 286
 
287
-		if ( $sent ) {
288
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
287
+		if ($sent) {
288
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
289 289
 		} else {
290
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
290
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
291 291
 		}
292 292
 
293
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
293
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
294 294
 		exit;
295 295
 	}
296 296
 
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 	 * 
300 300
 	 * @param array $args
301 301
      */
302
-    public function send_customer_payment_reminder( $args ) {
303
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
302
+    public function send_customer_payment_reminder($args) {
303
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
304 304
 
305
-		if ( $sent ) {
306
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
305
+		if ($sent) {
306
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
307 307
 		} else {
308
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
308
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
309 309
 		}
310 310
 
311
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
311
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
312 312
 		exit;
313 313
 	}
314 314
 
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
      * @return array
320 320
 	 */
321 321
 	public function get_notices() {
322
-		$notices = get_option( 'wpinv_admin_notices' );
323
-        return is_array( $notices ) ? $notices : array();
322
+		$notices = get_option('wpinv_admin_notices');
323
+        return is_array($notices) ? $notices : array();
324 324
 	}
325 325
 
326 326
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * @since       1.0.19
331 331
 	 */
332 332
 	public function clear_notices() {
333
-		delete_option( 'wpinv_admin_notices' );
333
+		delete_option('wpinv_admin_notices');
334 334
 	}
335 335
 
336 336
 	/**
@@ -339,16 +339,16 @@  discard block
 block discarded – undo
339 339
 	 * @access      public
340 340
 	 * @since       1.0.19
341 341
 	 */
342
-	public function save_notice( $type, $message ) {
342
+	public function save_notice($type, $message) {
343 343
 		$notices = $this->get_notices();
344 344
 
345
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
-			$notices[ $type ] = array();
345
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
346
+			$notices[$type] = array();
347 347
 		}
348 348
 
349
-		$notices[ $type ][] = $message;
349
+		$notices[$type][] = $message;
350 350
 
351
-		update_option( 'wpinv_admin_notices', $notices );
351
+		update_option('wpinv_admin_notices', $notices);
352 352
 	}
353 353
 
354 354
 	/**
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	 * @access      public
359 359
 	 * @since       1.0.19
360 360
 	 */
361
-	public function show_success( $msg ) {
362
-		$this->save_notice( 'success', $msg );
361
+	public function show_success($msg) {
362
+		$this->save_notice('success', $msg);
363 363
 	}
364 364
 
365 365
 	/**
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 	 * @param       string $msg The message to qeue.
370 370
 	 * @since       1.0.19
371 371
 	 */
372
-	public function show_error( $msg ) {
373
-		$this->save_notice( 'error', $msg );
372
+	public function show_error($msg) {
373
+		$this->save_notice('error', $msg);
374 374
 	}
375 375
 
376 376
 	/**
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 	 * @param       string $msg The message to qeue.
381 381
 	 * @since       1.0.19
382 382
 	 */
383
-	public function show_warning( $msg ) {
384
-		$this->save_notice( 'warning', $msg );
383
+	public function show_warning($msg) {
384
+		$this->save_notice('warning', $msg);
385 385
 	}
386 386
 
387 387
 	/**
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
 	 * @param       string $msg The message to qeue.
392 392
 	 * @since       1.0.19
393 393
 	 */
394
-	public function show_info( $msg ) {
395
-		$this->save_notice( 'info', $msg );
394
+	public function show_info($msg) {
395
+		$this->save_notice('info', $msg);
396 396
 	}
397 397
 
398 398
 	/**
@@ -406,15 +406,15 @@  discard block
 block discarded – undo
406 406
         $notices = $this->get_notices();
407 407
         $this->clear_notices();
408 408
 
409
-		foreach ( $notices as $type => $messages ) {
409
+		foreach ($notices as $type => $messages) {
410 410
 
411
-			if ( ! is_array( $messages ) ) {
411
+			if (!is_array($messages)) {
412 412
 				continue;
413 413
 			}
414 414
 
415
-            $type  = sanitize_key( $type );
416
-			foreach ( $messages as $message ) {
417
-                $message = wp_kses_post( $message );
415
+            $type = sanitize_key($type);
416
+			foreach ($messages as $message) {
417
+                $message = wp_kses_post($message);
418 418
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
419 419
             }
420 420
 
Please login to merge, or discard this patch.
includes/error-functions.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -117,14 +117,14 @@
 block discarded – undo
117 117
  */
118 118
 function getpaid_doing_it_wrong( $function, $message, $version ) {
119 119
 
120
-	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121
-
122
-	if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) {
123
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
124
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
125
-	} else {
126
-		_doing_it_wrong( $function, $message, $version );
127
-	}
120
+    $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121
+
122
+    if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) {
123
+        do_action( 'doing_it_wrong_run', $function, $message, $version );
124
+        error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
125
+    } else {
126
+        _doing_it_wrong( $function, $message, $version );
127
+    }
128 128
 
129 129
 }
130 130
 
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns the errors as html
@@ -14,27 +14,27 @@  discard block
 block discarded – undo
14 14
  * @param clear whether or not to clear the errors.
15 15
  * @since  1.0.19
16 16
  */
17
-function getpaid_get_errors_html( $clear = true ) {
17
+function getpaid_get_errors_html($clear = true) {
18 18
 
19 19
     $errors = '';
20
-    foreach ( wpinv_get_errors() as $error ) {
21
-        $type     = 'error';
20
+    foreach (wpinv_get_errors() as $error) {
21
+        $type = 'error';
22 22
 
23
-        if ( is_array( $error ) ) {
23
+        if (is_array($error)) {
24 24
             $type  = $error['type'];
25 25
             $error = $error['text'];
26 26
         }
27 27
 
28 28
         $errors .= aui()->alert(
29 29
             array(
30
-                'content'     => wp_kses_post( $error ),
30
+                'content'     => wp_kses_post($error),
31 31
                 'type'        => $type,
32 32
             )
33 33
         );
34 34
 
35 35
     }
36 36
 
37
-    if ( $clear ){
37
+    if ($clear) {
38 38
         wpinv_clear_errors();
39 39
     }
40 40
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
  * @return array
56 56
  */
57 57
 function wpinv_get_errors() {
58
-    $errors = getpaid_session()->get( 'wpinv_errors' );
59
-    return is_array( $errors ) ? $errors : array();
58
+    $errors = getpaid_session()->get('wpinv_errors');
59
+    return is_array($errors) ? $errors : array();
60 60
 }
61 61
 
62 62
 /**
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
  * @param string $error_message The error message.
67 67
  * @param string $type Either error, info, warning, primary, dark, light or success.
68 68
  */
69
-function wpinv_set_error( $error_id, $error_message, $type = 'error' ) {
69
+function wpinv_set_error($error_id, $error_message, $type = 'error') {
70 70
 
71 71
     $errors              = wpinv_get_errors();
72
-    $errors[ $error_id ] = array(
72
+    $errors[$error_id] = array(
73 73
         'type' =>  $type,
74 74
         'text' =>  $error_message,
75 75
     );
76 76
 
77
-    getpaid_session()->set( 'wpinv_errors', $errors );
77
+    getpaid_session()->set('wpinv_errors', $errors);
78 78
 }
79 79
 
80 80
 /**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
  * 
83 83
  */
84 84
 function wpinv_has_errors() {
85
-    return count( wpinv_get_errors() ) > 0;
85
+    return count(wpinv_get_errors()) > 0;
86 86
 }
87 87
 
88 88
 /**
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  */
92 92
 function wpinv_clear_errors() {
93
-    getpaid_session()->set( 'wpinv_errors', null );
93
+    getpaid_session()->set('wpinv_errors', null);
94 94
 }
95 95
 
96 96
 /**
97 97
  * Clears a single error.
98 98
  * 
99 99
  */
100
-function wpinv_unset_error( $error_id ) {
100
+function wpinv_unset_error($error_id) {
101 101
     $errors = wpinv_get_errors();
102 102
 
103
-    if ( isset( $errors[ $error_id ] ) ) {
104
-        unset( $errors[ $error_id ] );
103
+    if (isset($errors[$error_id])) {
104
+        unset($errors[$error_id]);
105 105
     }
106 106
 
107
-    getpaid_session()->set( 'wpinv_errors', $errors );
107
+    getpaid_session()->set('wpinv_errors', $errors);
108 108
 }
109 109
 
110 110
 /**
@@ -115,15 +115,15 @@  discard block
 block discarded – undo
115 115
  * @param string $message Message to log.
116 116
  * @param string $version Version the message was added in.
117 117
  */
118
-function getpaid_doing_it_wrong( $function, $message, $version ) {
118
+function getpaid_doing_it_wrong($function, $message, $version) {
119 119
 
120 120
 	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121 121
 
122
-	if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) {
123
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
124
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
122
+	if (wp_doing_ajax() || defined('REST_REQUEST')) {
123
+		do_action('doing_it_wrong_run', $function, $message, $version);
124
+		error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
125 125
 	} else {
126
-		_doing_it_wrong( $function, $message, $version );
126
+		_doing_it_wrong($function, $message, $version);
127 127
 	}
128 128
 
129 129
 }
@@ -137,38 +137,38 @@  discard block
 block discarded – undo
137 137
  * @param string $line The line that contains the error.
138 138
  * @param bool $exit Whether or not to exit function execution.
139 139
  */
140
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
140
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
141 141
     
142
-    if ( true === apply_filters( 'wpinv_log_errors', true ) ) {
142
+    if (true === apply_filters('wpinv_log_errors', true)) {
143 143
 
144 144
         // Ensure the log is a scalar.
145
-        if ( ! is_scalar( $log ) ) {
146
-            $log = print_r( $log, true );
145
+        if (!is_scalar($log)) {
146
+            $log = print_r($log, true);
147 147
         }
148 148
 
149 149
         // Add title.
150
-        if ( ! empty( $title ) ) {
151
-            $log  = $title . ' ' . trim( $log );
150
+        if (!empty($title)) {
151
+            $log = $title . ' ' . trim($log);
152 152
         }
153 153
 
154 154
         // Add the file to the label.
155
-        if ( ! empty( $file ) ) {
155
+        if (!empty($file)) {
156 156
             $log .= ' in ' . $file;
157 157
         }
158 158
 
159 159
         // Add the line number to the label.
160
-        if ( ! empty( $line ) ) {
160
+        if (!empty($line)) {
161 161
             $log .= ' on line ' . $line;
162 162
         }
163 163
 
164 164
         // Log the message.
165
-        error_log( trim ( $log ) );
165
+        error_log(trim($log));
166 166
 
167 167
         // ... and a backtrace.
168
-        error_log( 'Backtrace ' . wp_debug_backtrace_summary() );
168
+        error_log('Backtrace ' . wp_debug_backtrace_summary());
169 169
 
170 170
         // Maybe exit.
171
-        if ( $exit ) {
171
+        if ($exit) {
172 172
             exit;
173 173
         }
174 174
 
Please login to merge, or discard this patch.