Passed
Push — master ( 4d2fb8...f16077 )
by Brian
05:24
created
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -20,402 +20,402 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		$installed = get_option( 'gepaid_installed_on' );
52
-
53
-		if ( empty( $installed ) ) {
54
-			update_option( 'gepaid_installed_on', time() );
55
-		}
56
-
57
-		if ( method_exists( $this, $method ) ) {
58
-			$this->$method();
59
-		}
60
-
61
-	}
62
-
63
-	/**
64
-	 * Do a fresh install.
65
-	 *
66
-	 */
67
-	public function upgrade_from_0() {
68
-
69
-		// Save default tax rates.
70
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
71
-	}
72
-
73
-	/**
74
-	 * Upgrade to 0.0.5
75
-	 *
76
-	 */
77
-	public function upgrade_from_004() {
78
-		global $wpdb;
79
-
80
-		// Invoices.
81
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
82
-		if ( ! empty( $results ) ) {
83
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
84
-
85
-			// Clean post cache
86
-			foreach ( $results as $row ) {
87
-				clean_post_cache( $row->ID );
88
-			}
89
-		}
90
-
91
-		// Item meta key changes
92
-		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
93
-		$results = $wpdb->get_results( $query );
94
-
95
-		if ( ! empty( $results ) ) {
96
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
97
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
98
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
99
-
100
-			foreach ( $results as $row ) {
101
-				clean_post_cache( $row->post_id );
102
-			}
103
-		}
104
-
105
-		$this->upgrade_from_118();
106
-	}
107
-
108
-	/**
109
-	 * Upgrade to version 2.0.0.
110
-	 *
111
-	 */
112
-	public function upgrade_from_118() {
113
-		$this->migrate_old_invoices();
114
-		$this->upgrade_from_279();
115
-	}
116
-
117
-	/**
118
-	 * Upgrade to version 2.0.0.
119
-	 *
120
-	 */
121
-	public function upgrade_from_279() {
122
-		self::migrate_old_customers();
123
-	}
124
-
125
-	/**
126
-	 * Give administrators the capability to manage GetPaid.
127
-	 *
128
-	 */
129
-	public function add_capabilities() {
130
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
131
-	}
132
-
133
-	/**
134
-	 * Retreives GetPaid pages.
135
-	 *
136
-	 */
137
-	public static function get_pages() {
138
-
139
-		return apply_filters(
140
-			'wpinv_create_pages',
141
-			array(
142
-
143
-				// Checkout page.
144
-				'checkout_page'             => array(
145
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
146
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
147
-					'content' => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        $installed = get_option( 'gepaid_installed_on' );
52
+
53
+        if ( empty( $installed ) ) {
54
+            update_option( 'gepaid_installed_on', time() );
55
+        }
56
+
57
+        if ( method_exists( $this, $method ) ) {
58
+            $this->$method();
59
+        }
60
+
61
+    }
62
+
63
+    /**
64
+     * Do a fresh install.
65
+     *
66
+     */
67
+    public function upgrade_from_0() {
68
+
69
+        // Save default tax rates.
70
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
71
+    }
72
+
73
+    /**
74
+     * Upgrade to 0.0.5
75
+     *
76
+     */
77
+    public function upgrade_from_004() {
78
+        global $wpdb;
79
+
80
+        // Invoices.
81
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
82
+        if ( ! empty( $results ) ) {
83
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
84
+
85
+            // Clean post cache
86
+            foreach ( $results as $row ) {
87
+                clean_post_cache( $row->ID );
88
+            }
89
+        }
90
+
91
+        // Item meta key changes
92
+        $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
93
+        $results = $wpdb->get_results( $query );
94
+
95
+        if ( ! empty( $results ) ) {
96
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
97
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
98
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
99
+
100
+            foreach ( $results as $row ) {
101
+                clean_post_cache( $row->post_id );
102
+            }
103
+        }
104
+
105
+        $this->upgrade_from_118();
106
+    }
107
+
108
+    /**
109
+     * Upgrade to version 2.0.0.
110
+     *
111
+     */
112
+    public function upgrade_from_118() {
113
+        $this->migrate_old_invoices();
114
+        $this->upgrade_from_279();
115
+    }
116
+
117
+    /**
118
+     * Upgrade to version 2.0.0.
119
+     *
120
+     */
121
+    public function upgrade_from_279() {
122
+        self::migrate_old_customers();
123
+    }
124
+
125
+    /**
126
+     * Give administrators the capability to manage GetPaid.
127
+     *
128
+     */
129
+    public function add_capabilities() {
130
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
131
+    }
132
+
133
+    /**
134
+     * Retreives GetPaid pages.
135
+     *
136
+     */
137
+    public static function get_pages() {
138
+
139
+        return apply_filters(
140
+            'wpinv_create_pages',
141
+            array(
142
+
143
+                // Checkout page.
144
+                'checkout_page'             => array(
145
+                    'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
146
+                    'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
147
+                    'content' => '
148 148
 						<!-- wp:shortcode -->
149 149
 						[wpinv_checkout]
150 150
 						<!-- /wp:shortcode -->
151 151
 					',
152
-					'parent'  => '',
153
-				),
154
-
155
-				// Invoice history page.
156
-				'invoice_history_page'      => array(
157
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
158
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
159
-					'content' => '
152
+                    'parent'  => '',
153
+                ),
154
+
155
+                // Invoice history page.
156
+                'invoice_history_page'      => array(
157
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
158
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
159
+                    'content' => '
160 160
 					<!-- wp:shortcode -->
161 161
 					[wpinv_history]
162 162
 					<!-- /wp:shortcode -->
163 163
 				',
164
-					'parent'  => '',
165
-				),
166
-
167
-				// Success page content.
168
-				'success_page'              => array(
169
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
170
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
171
-					'content' => '
164
+                    'parent'  => '',
165
+                ),
166
+
167
+                // Success page content.
168
+                'success_page'              => array(
169
+                    'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
170
+                    'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
171
+                    'content' => '
172 172
 					<!-- wp:shortcode -->
173 173
 					[wpinv_receipt]
174 174
 					<!-- /wp:shortcode -->
175 175
 				',
176
-					'parent'  => 'gp-checkout',
177
-				),
178
-
179
-				// Failure page content.
180
-				'failure_page'              => array(
181
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
182
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
183
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
184
-					'parent'  => 'gp-checkout',
185
-				),
186
-
187
-				// Subscriptions history page.
188
-				'invoice_subscription_page' => array(
189
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
190
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
191
-					'content' => '
176
+                    'parent'  => 'gp-checkout',
177
+                ),
178
+
179
+                // Failure page content.
180
+                'failure_page'              => array(
181
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
182
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
183
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
184
+                    'parent'  => 'gp-checkout',
185
+                ),
186
+
187
+                // Subscriptions history page.
188
+                'invoice_subscription_page' => array(
189
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
190
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
191
+                    'content' => '
192 192
 					<!-- wp:shortcode -->
193 193
 					[wpinv_subscriptions]
194 194
 					<!-- /wp:shortcode -->
195 195
 				',
196
-					'parent'  => '',
197
-				),
198
-
199
-			)
200
-		);
201
-
202
-	}
203
-
204
-	/**
205
-	 * Re-create GetPaid pages.
206
-	 *
207
-	 */
208
-	public function create_pages() {
209
-
210
-		foreach ( self::get_pages() as $key => $page ) {
211
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
212
-		}
213
-
214
-	}
215
-
216
-	/**
217
-	 * Migrates old invoices to new invoices.
218
-	 *
219
-	 */
220
-	public function migrate_old_invoices() {
221
-		global $wpdb;
222
-
223
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
224
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
225
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
226
-		$invoices            = array_unique(
227
-			get_posts(
228
-				array(
229
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
230
-					'posts_per_page' => -1,
231
-					'fields'         => 'ids',
232
-					'post_status'    => array_keys( get_post_stati() ),
233
-					'exclude'        => (array) $migrated,
234
-				)
235
-			)
236
-		);
237
-
238
-		// Abort if we do not have any invoices.
239
-		if ( empty( $invoices ) ) {
240
-			return;
241
-		}
242
-
243
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
244
-
245
-		$invoice_rows = array();
246
-		foreach ( $invoices as $invoice ) {
247
-
248
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
249
-
250
-			if ( empty( $invoice->ID ) ) {
251
-				return;
252
-			}
253
-
254
-			$fields = array(
255
-				'post_id'            => $invoice->ID,
256
-				'number'             => $invoice->get_number(),
257
-				'key'                => $invoice->get_key(),
258
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
259
-				'mode'               => $invoice->mode,
260
-				'user_ip'            => $invoice->get_ip(),
261
-				'first_name'         => $invoice->get_first_name(),
262
-				'last_name'          => $invoice->get_last_name(),
263
-				'address'            => $invoice->get_address(),
264
-				'city'               => $invoice->city,
265
-				'state'              => $invoice->state,
266
-				'country'            => $invoice->country,
267
-				'zip'                => $invoice->zip,
268
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
269
-				'gateway'            => $invoice->get_gateway(),
270
-				'transaction_id'     => $invoice->get_transaction_id(),
271
-				'currency'           => $invoice->get_currency(),
272
-				'subtotal'           => $invoice->get_subtotal(),
273
-				'tax'                => $invoice->get_tax(),
274
-				'fees_total'         => $invoice->get_fees_total(),
275
-				'total'              => $invoice->get_total(),
276
-				'discount'           => $invoice->get_discount(),
277
-				'discount_code'      => $invoice->get_discount_code(),
278
-				'disable_taxes'      => $invoice->disable_taxes,
279
-				'due_date'           => $invoice->get_due_date(),
280
-				'completed_date'     => $invoice->get_completed_date(),
281
-				'company'            => $invoice->company,
282
-				'vat_number'         => $invoice->vat_number,
283
-				'vat_rate'           => $invoice->vat_rate,
284
-				'custom_meta'        => $invoice->payment_meta,
285
-			);
286
-
287
-			foreach ( $fields as $key => $val ) {
288
-				if ( is_null( $val ) ) {
289
-					$val = '';
290
-				}
291
-				$val = maybe_serialize( $val );
292
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
293
-			}
294
-
295
-			$fields = implode( ', ', $fields );
296
-			$invoice_rows[] = "($fields)";
297
-
298
-			$item_rows    = array();
299
-			$item_columns = array();
300
-			foreach ( $invoice->get_cart_details() as $details ) {
301
-				$fields = array(
302
-					'post_id'          => $invoice->ID,
303
-					'item_id'          => $details['id'],
304
-					'item_name'        => $details['name'],
305
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
306
-					'vat_rate'         => $details['vat_rate'],
307
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
308
-					'tax'              => $details['tax'],
309
-					'item_price'       => $details['item_price'],
310
-					'custom_price'     => $details['custom_price'],
311
-					'quantity'         => $details['quantity'],
312
-					'discount'         => $details['discount'],
313
-					'subtotal'         => $details['subtotal'],
314
-					'price'            => $details['price'],
315
-					'meta'             => $details['meta'],
316
-					'fees'             => $details['fees'],
317
-				);
318
-
319
-				$item_columns = array_keys( $fields );
320
-
321
-				foreach ( $fields as $key => $val ) {
322
-					if ( is_null( $val ) ) {
323
-						$val = '';
324
-					}
325
-					$val = maybe_serialize( $val );
326
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
327
-				}
328
-
329
-				$fields = implode( ', ', $fields );
330
-				$item_rows[] = "($fields)";
331
-			}
332
-
333
-			$item_rows    = implode( ', ', $item_rows );
334
-			$item_columns = implode( ', ', $item_columns );
335
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
336
-		}
337
-
338
-		if ( empty( $invoice_rows ) ) {
339
-			return;
340
-		}
341
-
342
-		$invoice_rows = implode( ', ', $invoice_rows );
343
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
344
-
345
-	}
346
-
347
-	/**
348
-	 * Migrates old customers to new table.
349
-	 *
350
-	 */
351
-	public static function migrate_old_customers() {
352
-		global $wpdb;
353
-
354
-		// Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
355
-		$invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
356
-
357
-		foreach ( $invoice_ids as $invoice_id ) {
358
-			$invoice = wpinv_get_invoice( $invoice_id );
359
-
360
-			if ( empty( $invoice ) ) {
361
-				continue;
362
-			}
363
-
364
-			// Fetch customer from the user ID.
365
-			$user_id = $invoice->get_user_id();
366
-
367
-			if ( empty( $user_id ) ) {
368
-				continue;
369
-			}
370
-
371
-			$customer = getpaid_get_customer_by_user_id( $user_id );
372
-
373
-			// Create if not exists.
374
-			if ( empty( $customer ) ) {
375
-				$customer = new GetPaid_Customer( 0 );
376
-				$customer->clone_user( $user_id );
377
-				$customer->save();
378
-			}
379
-
380
-			$invoice->set_customer_id( $customer->get_id() );
381
-			$invoice->save();
382
-		}
383
-
384
-	}
385
-
386
-	/**
387
-	 * Migrates old invoices to new invoices.
388
-	 *
389
-	 */
390
-	public static function rename_gateways_label() {
391
-		global $wpdb;
392
-
393
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
394
-
395
-			$wpdb->update(
396
-				$wpdb->prefix . 'getpaid_invoices',
397
-				array( 'gateway' => $gateway ),
398
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
399
-				'%s',
400
-				'%s'
401
-			);
402
-
403
-		}
404
-	}
405
-
406
-	/**
407
-	 * Returns the DB schema.
408
-	 *
409
-	 */
410
-	public static function get_db_schema() {
411
-		global $wpdb;
412
-
413
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
414
-
415
-		$charset_collate = $wpdb->get_charset_collate();
196
+                    'parent'  => '',
197
+                ),
198
+
199
+            )
200
+        );
201
+
202
+    }
203
+
204
+    /**
205
+     * Re-create GetPaid pages.
206
+     *
207
+     */
208
+    public function create_pages() {
209
+
210
+        foreach ( self::get_pages() as $key => $page ) {
211
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
212
+        }
213
+
214
+    }
215
+
216
+    /**
217
+     * Migrates old invoices to new invoices.
218
+     *
219
+     */
220
+    public function migrate_old_invoices() {
221
+        global $wpdb;
222
+
223
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
224
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
225
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
226
+        $invoices            = array_unique(
227
+            get_posts(
228
+                array(
229
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
230
+                    'posts_per_page' => -1,
231
+                    'fields'         => 'ids',
232
+                    'post_status'    => array_keys( get_post_stati() ),
233
+                    'exclude'        => (array) $migrated,
234
+                )
235
+            )
236
+        );
237
+
238
+        // Abort if we do not have any invoices.
239
+        if ( empty( $invoices ) ) {
240
+            return;
241
+        }
242
+
243
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
244
+
245
+        $invoice_rows = array();
246
+        foreach ( $invoices as $invoice ) {
247
+
248
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
249
+
250
+            if ( empty( $invoice->ID ) ) {
251
+                return;
252
+            }
253
+
254
+            $fields = array(
255
+                'post_id'            => $invoice->ID,
256
+                'number'             => $invoice->get_number(),
257
+                'key'                => $invoice->get_key(),
258
+                'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
259
+                'mode'               => $invoice->mode,
260
+                'user_ip'            => $invoice->get_ip(),
261
+                'first_name'         => $invoice->get_first_name(),
262
+                'last_name'          => $invoice->get_last_name(),
263
+                'address'            => $invoice->get_address(),
264
+                'city'               => $invoice->city,
265
+                'state'              => $invoice->state,
266
+                'country'            => $invoice->country,
267
+                'zip'                => $invoice->zip,
268
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
269
+                'gateway'            => $invoice->get_gateway(),
270
+                'transaction_id'     => $invoice->get_transaction_id(),
271
+                'currency'           => $invoice->get_currency(),
272
+                'subtotal'           => $invoice->get_subtotal(),
273
+                'tax'                => $invoice->get_tax(),
274
+                'fees_total'         => $invoice->get_fees_total(),
275
+                'total'              => $invoice->get_total(),
276
+                'discount'           => $invoice->get_discount(),
277
+                'discount_code'      => $invoice->get_discount_code(),
278
+                'disable_taxes'      => $invoice->disable_taxes,
279
+                'due_date'           => $invoice->get_due_date(),
280
+                'completed_date'     => $invoice->get_completed_date(),
281
+                'company'            => $invoice->company,
282
+                'vat_number'         => $invoice->vat_number,
283
+                'vat_rate'           => $invoice->vat_rate,
284
+                'custom_meta'        => $invoice->payment_meta,
285
+            );
286
+
287
+            foreach ( $fields as $key => $val ) {
288
+                if ( is_null( $val ) ) {
289
+                    $val = '';
290
+                }
291
+                $val = maybe_serialize( $val );
292
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
293
+            }
294
+
295
+            $fields = implode( ', ', $fields );
296
+            $invoice_rows[] = "($fields)";
297
+
298
+            $item_rows    = array();
299
+            $item_columns = array();
300
+            foreach ( $invoice->get_cart_details() as $details ) {
301
+                $fields = array(
302
+                    'post_id'          => $invoice->ID,
303
+                    'item_id'          => $details['id'],
304
+                    'item_name'        => $details['name'],
305
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
306
+                    'vat_rate'         => $details['vat_rate'],
307
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
308
+                    'tax'              => $details['tax'],
309
+                    'item_price'       => $details['item_price'],
310
+                    'custom_price'     => $details['custom_price'],
311
+                    'quantity'         => $details['quantity'],
312
+                    'discount'         => $details['discount'],
313
+                    'subtotal'         => $details['subtotal'],
314
+                    'price'            => $details['price'],
315
+                    'meta'             => $details['meta'],
316
+                    'fees'             => $details['fees'],
317
+                );
318
+
319
+                $item_columns = array_keys( $fields );
320
+
321
+                foreach ( $fields as $key => $val ) {
322
+                    if ( is_null( $val ) ) {
323
+                        $val = '';
324
+                    }
325
+                    $val = maybe_serialize( $val );
326
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
327
+                }
328
+
329
+                $fields = implode( ', ', $fields );
330
+                $item_rows[] = "($fields)";
331
+            }
332
+
333
+            $item_rows    = implode( ', ', $item_rows );
334
+            $item_columns = implode( ', ', $item_columns );
335
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
336
+        }
337
+
338
+        if ( empty( $invoice_rows ) ) {
339
+            return;
340
+        }
341
+
342
+        $invoice_rows = implode( ', ', $invoice_rows );
343
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
344
+
345
+    }
346
+
347
+    /**
348
+     * Migrates old customers to new table.
349
+     *
350
+     */
351
+    public static function migrate_old_customers() {
352
+        global $wpdb;
353
+
354
+        // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
355
+        $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
356
+
357
+        foreach ( $invoice_ids as $invoice_id ) {
358
+            $invoice = wpinv_get_invoice( $invoice_id );
359
+
360
+            if ( empty( $invoice ) ) {
361
+                continue;
362
+            }
363
+
364
+            // Fetch customer from the user ID.
365
+            $user_id = $invoice->get_user_id();
366
+
367
+            if ( empty( $user_id ) ) {
368
+                continue;
369
+            }
370
+
371
+            $customer = getpaid_get_customer_by_user_id( $user_id );
372
+
373
+            // Create if not exists.
374
+            if ( empty( $customer ) ) {
375
+                $customer = new GetPaid_Customer( 0 );
376
+                $customer->clone_user( $user_id );
377
+                $customer->save();
378
+            }
379
+
380
+            $invoice->set_customer_id( $customer->get_id() );
381
+            $invoice->save();
382
+        }
383
+
384
+    }
385
+
386
+    /**
387
+     * Migrates old invoices to new invoices.
388
+     *
389
+     */
390
+    public static function rename_gateways_label() {
391
+        global $wpdb;
392
+
393
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
394
+
395
+            $wpdb->update(
396
+                $wpdb->prefix . 'getpaid_invoices',
397
+                array( 'gateway' => $gateway ),
398
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
399
+                '%s',
400
+                '%s'
401
+            );
402
+
403
+        }
404
+    }
405
+
406
+    /**
407
+     * Returns the DB schema.
408
+     *
409
+     */
410
+    public static function get_db_schema() {
411
+        global $wpdb;
412
+
413
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
414
+
415
+        $charset_collate = $wpdb->get_charset_collate();
416 416
 
417
-		// Subscriptions.
418
-		$schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
417
+        // Subscriptions.
418
+        $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
419 419
 			id bigint(20) unsigned NOT NULL auto_increment,
420 420
 			customer_id bigint(20) NOT NULL,
421 421
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
 			KEY customer_and_status (customer_id, status)
439 439
 		  ) $charset_collate;";
440 440
 
441
-		// Invoices.
442
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
441
+        // Invoices.
442
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
443 443
 			post_id BIGINT(20) NOT NULL,
444 444
 			customer_id BIGINT(20) NOT NULL DEFAULT 0,
445 445
             `number` VARCHAR(100),
@@ -476,8 +476,8 @@  discard block
 block discarded – undo
476 476
 			KEY invoice_key (invoice_key)
477 477
 		  ) $charset_collate;";
478 478
 
479
-		// Invoice items.
480
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
479
+        // Invoice items.
480
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
481 481
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
482 482
             post_id BIGINT(20) NOT NULL,
483 483
             item_id BIGINT(20) NOT NULL,
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
 			KEY post_id (post_id)
500 500
 		  ) $charset_collate;";
501 501
 
502
-		// Customers.
503
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers (
502
+        // Customers.
503
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers (
504 504
 			id BIGINT(20) NOT NULL AUTO_INCREMENT,
505 505
 			user_id BIGINT(20) NOT NULL,
506 506
 			email VARCHAR(100) NOT NULL,
@@ -510,38 +510,38 @@  discard block
 block discarded – undo
510 510
 			purchase_count BIGINT(20) NOT NULL DEFAULT 0,
511 511
 			";
512 512
 
513
-		// Add address fields.
514
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
515
-			// Skip id, user_id and email.
516
-			if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
517
-				continue;
518
-			}
519
-
520
-			$field   = sanitize_key( $field );
521
-			$length  = 100;
522
-			$default = '';
523
-
524
-			// Country.
525
-			if ( 'country' === $field ) {
526
-				$length  = 2;
527
-				$default = wpinv_get_default_country();
528
-			}
529
-
530
-			// State.
531
-			if ( 'state' === $field ) {
532
-				$default = wpinv_get_default_state();
533
-			}
534
-
535
-			// Phone, zip.
536
-			if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
537
-				$length = 20;
538
-			}
539
-
540
-			$schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',
513
+        // Add address fields.
514
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
515
+            // Skip id, user_id and email.
516
+            if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
517
+                continue;
518
+            }
519
+
520
+            $field   = sanitize_key( $field );
521
+            $length  = 100;
522
+            $default = '';
523
+
524
+            // Country.
525
+            if ( 'country' === $field ) {
526
+                $length  = 2;
527
+                $default = wpinv_get_default_country();
528
+            }
529
+
530
+            // State.
531
+            if ( 'state' === $field ) {
532
+                $default = wpinv_get_default_state();
533
+            }
534
+
535
+            // Phone, zip.
536
+            if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
537
+                $length = 20;
538
+            }
539
+
540
+            $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',
541 541
 			";
542
-		}
542
+        }
543 543
 
544
-		$schema .= "date_created DATETIME NOT NULL,
544
+        $schema .= "date_created DATETIME NOT NULL,
545 545
 			date_modified DATETIME NOT NULL,
546 546
 			uuid VARCHAR(100) NOT NULL,
547 547
 			PRIMARY KEY  (id),
@@ -549,8 +549,8 @@  discard block
 block discarded – undo
549 549
 			KEY email (email)
550 550
 		  ) $charset_collate;";
551 551
 
552
-		// Customer meta.
553
-		$schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
552
+        // Customer meta.
553
+        $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
554 554
 			meta_id BIGINT(20) NOT NULL AUTO_INCREMENT,
555 555
 			customer_id BIGINT(20) NOT NULL,
556 556
 			meta_key VARCHAR(255) NOT NULL,
@@ -560,55 +560,55 @@  discard block
 block discarded – undo
560 560
 			KEY meta_key (meta_key(191))
561 561
 		  ) $charset_collate;";
562 562
 
563
-		return $schema;
564
-	}
565
-
566
-	/**
567
-	 * Checks if the db schema is up to date.
568
-	 *
569
-	 * @return bool
570
-	 */
571
-	public static function is_db_schema_up_to_date() {
572
-		return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' );
573
-	}
574
-
575
-	/**
576
-	 * Set up the database tables which the plugin needs to function.
577
-	 */
578
-	public static function create_db_tables() {
579
-		global $wpdb;
580
-
581
-		$wpdb->hide_errors();
582
-
583
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
584
-
585
-		$schema = self::get_db_schema();
586
-
587
-		// If invoices table exists, rename key to invoice_key.
588
-		$invoices_table = "{$wpdb->prefix}getpaid_invoices";
589
-
590
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) {
591
-			$fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" );
592
-
593
-			foreach ( $fields as $field ) {
594
-				if ( 'key' === $field->Field ) {
595
-					$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" );
596
-					break;
597
-				}
598
-			}
599
-		}
600
-
601
-		dbDelta( $schema );
602
-		wp_cache_flush();
603
-		update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) );
604
-	}
605
-
606
-	/**
607
-	 * Creates tables if schema is not up to date.
608
-	 */
609
-	public static function maybe_create_db_tables() {
610
-		if ( ! self::is_db_schema_up_to_date() ) {
611
-			self::create_db_tables();
612
-		}
613
-	}
563
+        return $schema;
564
+    }
565
+
566
+    /**
567
+     * Checks if the db schema is up to date.
568
+     *
569
+     * @return bool
570
+     */
571
+    public static function is_db_schema_up_to_date() {
572
+        return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' );
573
+    }
574
+
575
+    /**
576
+     * Set up the database tables which the plugin needs to function.
577
+     */
578
+    public static function create_db_tables() {
579
+        global $wpdb;
580
+
581
+        $wpdb->hide_errors();
582
+
583
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
584
+
585
+        $schema = self::get_db_schema();
586
+
587
+        // If invoices table exists, rename key to invoice_key.
588
+        $invoices_table = "{$wpdb->prefix}getpaid_invoices";
589
+
590
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) {
591
+            $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" );
592
+
593
+            foreach ( $fields as $field ) {
594
+                if ( 'key' === $field->Field ) {
595
+                    $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" );
596
+                    break;
597
+                }
598
+            }
599
+        }
600
+
601
+        dbDelta( $schema );
602
+        wp_cache_flush();
603
+        update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) );
604
+    }
605
+
606
+    /**
607
+     * Creates tables if schema is not up to date.
608
+     */
609
+    public static function maybe_create_db_tables() {
610
+        if ( ! self::is_db_schema_up_to_date() ) {
611
+            self::create_db_tables();
612
+        }
613
+    }
614 614
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-customers-table.php 1 patch
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 // Load WP_List_Table if not loaded
13 13
 if ( ! class_exists( 'WP_List_Table' ) ) {
14
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
14
+    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
15 15
 }
16 16
 
17 17
 /**
@@ -23,304 +23,304 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class WPInv_Customers_Table extends WP_List_Table {
25 25
 
26
-	/**
27
-	 * @var int Number of items per page
28
-	 * @since 1.0.19
29
-	 */
30
-	public $per_page = 25;
31
-
32
-	/**
33
-	 * @var int Number of items
34
-	 * @since 1.0.19
35
-	 */
36
-	public $total_count = 0;
37
-
38
-	public $query;
39
-
40
-	/**
41
-	 * Get things started
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @see WP_List_Table::__construct()
45
-	 */
46
-	public function __construct() {
47
-
48
-		// Set parent defaults
49
-		parent::__construct(
26
+    /**
27
+     * @var int Number of items per page
28
+     * @since 1.0.19
29
+     */
30
+    public $per_page = 25;
31
+
32
+    /**
33
+     * @var int Number of items
34
+     * @since 1.0.19
35
+     */
36
+    public $total_count = 0;
37
+
38
+    public $query;
39
+
40
+    /**
41
+     * Get things started
42
+     *
43
+     * @since 1.0.19
44
+     * @see WP_List_Table::__construct()
45
+     */
46
+    public function __construct() {
47
+
48
+        // Set parent defaults
49
+        parent::__construct(
50 50
             array(
51
-				'singular' => 'id',
52
-				'plural'   => 'ids',
53
-				'ajax'     => false,
51
+                'singular' => 'id',
52
+                'plural'   => 'ids',
53
+                'ajax'     => false,
54 54
             )
55 55
         );
56 56
 
57
-	}
58
-
59
-	/**
60
-	 * Gets the name of the primary column.
61
-	 *
62
-	 * @since 1.0.19
63
-	 * @access protected
64
-	 *
65
-	 * @return string Name of the primary column.
66
-	 */
67
-	protected function get_primary_column_name() {
68
-		return 'customer';
69
-	}
70
-
71
-	/**
72
-	 * This function renders most of the columns in the list table.
73
-	 *
74
-	 * @since 1.0.19
75
-	 *
76
-	 * @param GetPaid_Customer $customer
77
-	 * @param string $column_name The name of the column
78
-	 *
79
-	 * @return string Column Name
80
-	 */
81
-	public function column_default( $customer, $column_name ) {
82
-		$value = esc_html( $customer->get( $column_name ) );
83
-		return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $customer );
84
-	}
85
-
86
-	/**
87
-	 * Displays the country column.
88
-	 *
89
-	 * @since 1.0.19
90
-	 *
91
-	 * @param GetPaid_Customer $customer
92
-	 *
93
-	 * @return string Column Name
94
-	 */
95
-	public function column_country( $customer ) {
96
-		$country = wpinv_sanitize_country( $customer->get( 'country' ) );
97
-		if ( $country ) {
98
-			$country = wpinv_country_name( $country );
99
-		}
100
-		return esc_html( $country );
101
-	}
102
-
103
-	/**
104
-	 * Displays the state column.
105
-	 *
106
-	 * @since 1.0.19
107
-	 *
108
-	 * @param GetPaid_Customer $customer
109
-	 *
110
-	 * @return string Column Name
111
-	 */
112
-	public function column_state( $customer ) {
113
-		$country = wpinv_sanitize_country( $customer->get( 'country' ) );
114
-		$state   = $customer->get( 'state' );
115
-		if ( $state ) {
116
-			$state = wpinv_state_name( $state, $country );
117
-		}
118
-
119
-		return esc_html( $state );
120
-	}
121
-
122
-	/**
123
-	 * Displays the signup column.
124
-	 *
125
-	 * @since 1.0.19
126
-	 *
127
-	 * @param GetPaid_Customer $customer
128
-	 *
129
-	 * @return string Column Name
130
-	 */
131
-	public function column_date_created( $customer ) {
132
-		return getpaid_format_date_value( $customer->get( 'date_created' ) );
133
-	}
134
-
135
-	/**
136
-	 * Displays the total spent column.
137
-	 *
138
-	 * @since 1.0.19
139
-	 *
140
-	 * @param GetPaid_Customer $customer
141
-	 *
142
-	 * @return string Column Name
143
-	 */
144
-	public function column_purchase_value( $customer ) {
145
-		return wpinv_price( (float) $customer->get( 'purchase_value' ) );
146
-	}
147
-
148
-	/**
149
-	 * Displays the total spent column.
150
-	 *
151
-	 * @since 1.0.19
152
-	 *
153
-	 * @param GetPaid_Customer $customer
154
-	 *
155
-	 * @return string Column Name
156
-	 */
157
-	public function column_purchase_count( $customer ) {
158
-		$value = $customer->get( 'purchase_count' );
159
-		$url   = $customer->get( 'user_id' ) ? add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $customer->get( 'user_id' ), ), admin_url( 'edit.php' ) ) : '';
160
-
161
-		return ( empty( $value ) || empty( $url ) ) ? (int) $value : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>';
162
-
163
-	}
164
-
165
-	/**
166
-	 * Displays the customers name
167
-	 *
168
-	 * @param  GetPaid_Customer $customer customer.
169
-	 * @return string
170
-	 */
171
-	public function column_customer( $customer ) {
172
-
173
-		$first_name = $customer->get( 'first_name' );
174
-		$last_name  = $customer->get( 'last_name' );
175
-		$email      = $customer->get( 'email' );
176
-		$avatar     = get_avatar( $customer->get( 'user_id' ) ? $customer->get( 'user_id' ) : $email, 32 );
177
-
178
-		// Customer view URL.
179
-		$view_url    = $customer->get( 'user_id' ) ? esc_url( add_query_arg( 'user_id', $customer->get( 'user_id' ), admin_url( 'user-edit.php' ) ) ) : false;
180
-		$row_actions = $view_url ? $this->row_actions(
181
-			array(
182
-				'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
183
-			)
184
-		) : '';
185
-
186
-		// Customer's name.
187
-		$name   = esc_html( trim( "$first_name $last_name" ) );
188
-
189
-		if ( ! empty( $name ) ) {
190
-			$name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
191
-		}
192
-
193
-		$email = "<div class='row-title'><a href='mailto:$email'>$email</a></div>";
194
-
195
-		return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
196
-
197
-	}
198
-
199
-	/**
200
-	 * Retrieve the current page number
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @return int Current page number
204
-	 */
205
-	public function get_paged() {
206
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
207
-	}
208
-
209
-	/**
210
-	 * Returns bulk actions.
211
-	 *
212
-	 * @since 1.0.19
213
-	 * @return void
214
-	 */
215
-	public function bulk_actions( $which = '' ) {
216
-		return array();
217
-	}
218
-
219
-	/**
220
-	 *  Prepares the display query
221
-	 */
222
-	public function prepare_query() {
223
-
224
-		// Prepare query args.
225
-		$query = array(
226
-			'number' => $this->per_page,
227
-			'paged'  => $this->get_paged(),
228
-		);
229
-
230
-		foreach ( array( 'orderby', 'order', 's' ) as $field ) {
231
-			if ( isset( $_GET[ $field ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
232
-				$query[ $field ] = wpinv_clean( rawurlencode_deep( $_GET[ $field ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
233
-			}
234
-		}
235
-
236
-		foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) {
237
-
238
-			if ( isset( $_GET[ $field ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
239
-				$query[ $field ] = wpinv_clean( rawurlencode_deep( $_GET[ $field ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
240
-			}
241
-
242
-			// Min max.
243
-			if ( '%f' === $type || '%d' === $type ) {
244
-
245
-				if ( isset( $_GET[ $field . '_min' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
246
-					$query[ $field . '_min' ] = floatval( $_GET[ $field . '_min' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
247
-				}
248
-
249
-				if ( isset( $_GET[ $field . '_max' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
250
-					$query[ $field . '_max' ] = floatval( $_GET[ $field . '_max' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
251
-				}
252
-			}
253
-		}
254
-
255
-		// Prepare class properties.
256
-		$this->query       = getpaid_get_customers( $query, 'query' );
257
-		$this->total_count = $this->query->get_total();
258
-		$this->items       = $this->query->get_results();
259
-	}
260
-
261
-	/**
262
-	 * Setup the final data for the table
263
-	 *
264
-	 */
265
-	public function prepare_items() {
266
-
267
-		$columns  = $this->get_columns();
268
-		$hidden   = array();
269
-		$sortable = $this->get_sortable_columns();
270
-		$this->prepare_query();
271
-
272
-		$this->_column_headers = array( $columns, $hidden, $sortable );
273
-
274
-		$this->set_pagination_args(
275
-			array(
276
-				'total_items' => $this->total_count,
277
-				'per_page'    => $this->per_page,
278
-				'total_pages' => ceil( $this->total_count / $this->per_page ),
279
-			)
280
-		);
281
-	}
282
-
283
-	/**
284
-	 * Sortable table columns.
285
-	 *
286
-	 * @return array
287
-	 */
288
-	public function get_sortable_columns() {
289
-		$sortable = array(
290
-			'customer' => array( 'first_name', true ),
291
-		);
292
-
293
-		foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) {
294
-			$sortable[ $field ] = array( $field, true );
295
-		}
296
-
297
-		return apply_filters( 'manage_getpaid_customers_sortable_table_columns', $sortable );
298
-	}
299
-
300
-	/**
301
-	 * Table columns
302
-	 *
303
-	 * @return array
304
-	 */
305
-	public function get_columns() {
306
-		$columns = array(
307
-			'cb'       => '<input type="checkbox" />',
308
-			'customer' => __( 'Customer', 'invoicing' ),
309
-		);
310
-
311
-		// Add address fields.
312
-		foreach ( getpaid_user_address_fields() as $key => $value ) {
313
-
314
-			// Skip id, user_id and email.
315
-			if ( ! in_array( $key, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid', 'first_name', 'last_name' ), true ) ) {
316
-				$columns[ $key ] = $value;
317
-			}
318
-		}
319
-
320
-		$columns['purchase_value'] = __( 'Total Spend', 'invoicing' );
321
-		$columns['purchase_count'] = __( 'Invoices', 'invoicing' );
322
-		$columns['date_created']   = __( 'Date created', 'invoicing' );
323
-
324
-		return apply_filters( 'manage_getpaid_customers_table_columns', $columns );
325
-	}
57
+    }
58
+
59
+    /**
60
+     * Gets the name of the primary column.
61
+     *
62
+     * @since 1.0.19
63
+     * @access protected
64
+     *
65
+     * @return string Name of the primary column.
66
+     */
67
+    protected function get_primary_column_name() {
68
+        return 'customer';
69
+    }
70
+
71
+    /**
72
+     * This function renders most of the columns in the list table.
73
+     *
74
+     * @since 1.0.19
75
+     *
76
+     * @param GetPaid_Customer $customer
77
+     * @param string $column_name The name of the column
78
+     *
79
+     * @return string Column Name
80
+     */
81
+    public function column_default( $customer, $column_name ) {
82
+        $value = esc_html( $customer->get( $column_name ) );
83
+        return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $customer );
84
+    }
85
+
86
+    /**
87
+     * Displays the country column.
88
+     *
89
+     * @since 1.0.19
90
+     *
91
+     * @param GetPaid_Customer $customer
92
+     *
93
+     * @return string Column Name
94
+     */
95
+    public function column_country( $customer ) {
96
+        $country = wpinv_sanitize_country( $customer->get( 'country' ) );
97
+        if ( $country ) {
98
+            $country = wpinv_country_name( $country );
99
+        }
100
+        return esc_html( $country );
101
+    }
102
+
103
+    /**
104
+     * Displays the state column.
105
+     *
106
+     * @since 1.0.19
107
+     *
108
+     * @param GetPaid_Customer $customer
109
+     *
110
+     * @return string Column Name
111
+     */
112
+    public function column_state( $customer ) {
113
+        $country = wpinv_sanitize_country( $customer->get( 'country' ) );
114
+        $state   = $customer->get( 'state' );
115
+        if ( $state ) {
116
+            $state = wpinv_state_name( $state, $country );
117
+        }
118
+
119
+        return esc_html( $state );
120
+    }
121
+
122
+    /**
123
+     * Displays the signup column.
124
+     *
125
+     * @since 1.0.19
126
+     *
127
+     * @param GetPaid_Customer $customer
128
+     *
129
+     * @return string Column Name
130
+     */
131
+    public function column_date_created( $customer ) {
132
+        return getpaid_format_date_value( $customer->get( 'date_created' ) );
133
+    }
134
+
135
+    /**
136
+     * Displays the total spent column.
137
+     *
138
+     * @since 1.0.19
139
+     *
140
+     * @param GetPaid_Customer $customer
141
+     *
142
+     * @return string Column Name
143
+     */
144
+    public function column_purchase_value( $customer ) {
145
+        return wpinv_price( (float) $customer->get( 'purchase_value' ) );
146
+    }
147
+
148
+    /**
149
+     * Displays the total spent column.
150
+     *
151
+     * @since 1.0.19
152
+     *
153
+     * @param GetPaid_Customer $customer
154
+     *
155
+     * @return string Column Name
156
+     */
157
+    public function column_purchase_count( $customer ) {
158
+        $value = $customer->get( 'purchase_count' );
159
+        $url   = $customer->get( 'user_id' ) ? add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $customer->get( 'user_id' ), ), admin_url( 'edit.php' ) ) : '';
160
+
161
+        return ( empty( $value ) || empty( $url ) ) ? (int) $value : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>';
162
+
163
+    }
164
+
165
+    /**
166
+     * Displays the customers name
167
+     *
168
+     * @param  GetPaid_Customer $customer customer.
169
+     * @return string
170
+     */
171
+    public function column_customer( $customer ) {
172
+
173
+        $first_name = $customer->get( 'first_name' );
174
+        $last_name  = $customer->get( 'last_name' );
175
+        $email      = $customer->get( 'email' );
176
+        $avatar     = get_avatar( $customer->get( 'user_id' ) ? $customer->get( 'user_id' ) : $email, 32 );
177
+
178
+        // Customer view URL.
179
+        $view_url    = $customer->get( 'user_id' ) ? esc_url( add_query_arg( 'user_id', $customer->get( 'user_id' ), admin_url( 'user-edit.php' ) ) ) : false;
180
+        $row_actions = $view_url ? $this->row_actions(
181
+            array(
182
+                'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
183
+            )
184
+        ) : '';
185
+
186
+        // Customer's name.
187
+        $name   = esc_html( trim( "$first_name $last_name" ) );
188
+
189
+        if ( ! empty( $name ) ) {
190
+            $name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
191
+        }
192
+
193
+        $email = "<div class='row-title'><a href='mailto:$email'>$email</a></div>";
194
+
195
+        return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
196
+
197
+    }
198
+
199
+    /**
200
+     * Retrieve the current page number
201
+     *
202
+     * @since 1.0.19
203
+     * @return int Current page number
204
+     */
205
+    public function get_paged() {
206
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
207
+    }
208
+
209
+    /**
210
+     * Returns bulk actions.
211
+     *
212
+     * @since 1.0.19
213
+     * @return void
214
+     */
215
+    public function bulk_actions( $which = '' ) {
216
+        return array();
217
+    }
218
+
219
+    /**
220
+     *  Prepares the display query
221
+     */
222
+    public function prepare_query() {
223
+
224
+        // Prepare query args.
225
+        $query = array(
226
+            'number' => $this->per_page,
227
+            'paged'  => $this->get_paged(),
228
+        );
229
+
230
+        foreach ( array( 'orderby', 'order', 's' ) as $field ) {
231
+            if ( isset( $_GET[ $field ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
232
+                $query[ $field ] = wpinv_clean( rawurlencode_deep( $_GET[ $field ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
233
+            }
234
+        }
235
+
236
+        foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) {
237
+
238
+            if ( isset( $_GET[ $field ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
239
+                $query[ $field ] = wpinv_clean( rawurlencode_deep( $_GET[ $field ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
240
+            }
241
+
242
+            // Min max.
243
+            if ( '%f' === $type || '%d' === $type ) {
244
+
245
+                if ( isset( $_GET[ $field . '_min' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
246
+                    $query[ $field . '_min' ] = floatval( $_GET[ $field . '_min' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
247
+                }
248
+
249
+                if ( isset( $_GET[ $field . '_max' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
250
+                    $query[ $field . '_max' ] = floatval( $_GET[ $field . '_max' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
251
+                }
252
+            }
253
+        }
254
+
255
+        // Prepare class properties.
256
+        $this->query       = getpaid_get_customers( $query, 'query' );
257
+        $this->total_count = $this->query->get_total();
258
+        $this->items       = $this->query->get_results();
259
+    }
260
+
261
+    /**
262
+     * Setup the final data for the table
263
+     *
264
+     */
265
+    public function prepare_items() {
266
+
267
+        $columns  = $this->get_columns();
268
+        $hidden   = array();
269
+        $sortable = $this->get_sortable_columns();
270
+        $this->prepare_query();
271
+
272
+        $this->_column_headers = array( $columns, $hidden, $sortable );
273
+
274
+        $this->set_pagination_args(
275
+            array(
276
+                'total_items' => $this->total_count,
277
+                'per_page'    => $this->per_page,
278
+                'total_pages' => ceil( $this->total_count / $this->per_page ),
279
+            )
280
+        );
281
+    }
282
+
283
+    /**
284
+     * Sortable table columns.
285
+     *
286
+     * @return array
287
+     */
288
+    public function get_sortable_columns() {
289
+        $sortable = array(
290
+            'customer' => array( 'first_name', true ),
291
+        );
292
+
293
+        foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) {
294
+            $sortable[ $field ] = array( $field, true );
295
+        }
296
+
297
+        return apply_filters( 'manage_getpaid_customers_sortable_table_columns', $sortable );
298
+    }
299
+
300
+    /**
301
+     * Table columns
302
+     *
303
+     * @return array
304
+     */
305
+    public function get_columns() {
306
+        $columns = array(
307
+            'cb'       => '<input type="checkbox" />',
308
+            'customer' => __( 'Customer', 'invoicing' ),
309
+        );
310
+
311
+        // Add address fields.
312
+        foreach ( getpaid_user_address_fields() as $key => $value ) {
313
+
314
+            // Skip id, user_id and email.
315
+            if ( ! in_array( $key, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid', 'first_name', 'last_name' ), true ) ) {
316
+                $columns[ $key ] = $value;
317
+            }
318
+        }
319
+
320
+        $columns['purchase_value'] = __( 'Total Spend', 'invoicing' );
321
+        $columns['purchase_count'] = __( 'Invoices', 'invoicing' );
322
+        $columns['date_created']   = __( 'Date created', 'invoicing' );
323
+
324
+        return apply_filters( 'manage_getpaid_customers_table_columns', $columns );
325
+    }
326 326
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +490 added lines, -490 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,545 +15,545 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'_wpinv_phone',
34
-		'_wpinv_company_id',
35
-		'wpinv_shipping',
36
-		'wpinv_email_cc',
37
-		'wpinv_template',
38
-		'wpinv_created_via',
39
-	);
40
-
41
-	/**
42
-	 * A map of meta keys to data props.
43
-	 *
44
-	 * @since 1.0.19
45
-	 *
46
-	 * @var array
47
-	 */
48
-	protected $meta_key_to_props = array(
49
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
-		'_wpinv_subscription_id'   => 'subscription_id',
51
-		'_wpinv_taxes'             => 'taxes',
52
-		'_wpinv_fees'              => 'fees',
53
-		'_wpinv_discounts'         => 'discounts',
54
-		'_wpinv_submission_id'     => 'submission_id',
55
-		'_wpinv_payment_form'      => 'payment_form',
56
-		'_wpinv_is_viewed'         => 'is_viewed',
57
-		'wpinv_email_cc'           => 'email_cc',
58
-		'wpinv_template'           => 'template',
59
-		'wpinv_created_via'        => 'created_via',
60
-		'_wpinv_phone'             => 'phone',
61
-		'_wpinv_company_id'        => 'company_id',
62
-		'wpinv_shipping'           => 'shipping',
63
-	);
64
-
65
-	/**
66
-	 * A map of database fields to data props.
67
-	 *
68
-	 * @since 1.0.19
69
-	 *
70
-	 * @var array
71
-	 */
72
-	protected $database_fields_to_props = array(
73
-		'post_id'            => 'id',
74
-		'number'             => 'number',
75
-		'currency'           => 'currency',
76
-		'invoice_key'        => 'key',
77
-		'type'               => 'type',
78
-		'mode'               => 'mode',
79
-		'user_ip'            => 'user_ip',
80
-		'first_name'         => 'first_name',
81
-		'last_name'          => 'last_name',
82
-		'address'            => 'address',
83
-		'city'               => 'city',
84
-		'state'              => 'state',
85
-		'country'            => 'country',
86
-		'zip'                => 'zip',
87
-		'zip'                => 'zip',
88
-		'adddress_confirmed' => 'address_confirmed',
89
-		'gateway'            => 'gateway',
90
-		'transaction_id'     => 'transaction_id',
91
-		'currency'           => 'currency',
92
-		'subtotal'           => 'subtotal',
93
-		'tax'                => 'total_tax',
94
-		'fees_total'         => 'total_fees',
95
-		'discount'           => 'total_discount',
96
-		'total'              => 'total',
97
-		'discount_code'      => 'discount_code',
98
-		'disable_taxes'      => 'disable_taxes',
99
-		'due_date'           => 'due_date',
100
-		'completed_date'     => 'completed_date',
101
-		'company'            => 'company',
102
-		'vat_number'         => 'vat_number',
103
-		'vat_rate'           => 'vat_rate',
104
-		'customer_id'        => 'customer_id',
105
-	);
106
-
107
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        '_wpinv_phone',
34
+        '_wpinv_company_id',
35
+        'wpinv_shipping',
36
+        'wpinv_email_cc',
37
+        'wpinv_template',
38
+        'wpinv_created_via',
39
+    );
40
+
41
+    /**
42
+     * A map of meta keys to data props.
43
+     *
44
+     * @since 1.0.19
45
+     *
46
+     * @var array
47
+     */
48
+    protected $meta_key_to_props = array(
49
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
+        '_wpinv_subscription_id'   => 'subscription_id',
51
+        '_wpinv_taxes'             => 'taxes',
52
+        '_wpinv_fees'              => 'fees',
53
+        '_wpinv_discounts'         => 'discounts',
54
+        '_wpinv_submission_id'     => 'submission_id',
55
+        '_wpinv_payment_form'      => 'payment_form',
56
+        '_wpinv_is_viewed'         => 'is_viewed',
57
+        'wpinv_email_cc'           => 'email_cc',
58
+        'wpinv_template'           => 'template',
59
+        'wpinv_created_via'        => 'created_via',
60
+        '_wpinv_phone'             => 'phone',
61
+        '_wpinv_company_id'        => 'company_id',
62
+        'wpinv_shipping'           => 'shipping',
63
+    );
64
+
65
+    /**
66
+     * A map of database fields to data props.
67
+     *
68
+     * @since 1.0.19
69
+     *
70
+     * @var array
71
+     */
72
+    protected $database_fields_to_props = array(
73
+        'post_id'            => 'id',
74
+        'number'             => 'number',
75
+        'currency'           => 'currency',
76
+        'invoice_key'        => 'key',
77
+        'type'               => 'type',
78
+        'mode'               => 'mode',
79
+        'user_ip'            => 'user_ip',
80
+        'first_name'         => 'first_name',
81
+        'last_name'          => 'last_name',
82
+        'address'            => 'address',
83
+        'city'               => 'city',
84
+        'state'              => 'state',
85
+        'country'            => 'country',
86
+        'zip'                => 'zip',
87
+        'zip'                => 'zip',
88
+        'adddress_confirmed' => 'address_confirmed',
89
+        'gateway'            => 'gateway',
90
+        'transaction_id'     => 'transaction_id',
91
+        'currency'           => 'currency',
92
+        'subtotal'           => 'subtotal',
93
+        'tax'                => 'total_tax',
94
+        'fees_total'         => 'total_fees',
95
+        'discount'           => 'total_discount',
96
+        'total'              => 'total',
97
+        'discount_code'      => 'discount_code',
98
+        'disable_taxes'      => 'disable_taxes',
99
+        'due_date'           => 'due_date',
100
+        'completed_date'     => 'completed_date',
101
+        'company'            => 'company',
102
+        'vat_number'         => 'vat_number',
103
+        'vat_rate'           => 'vat_rate',
104
+        'customer_id'        => 'customer_id',
105
+    );
106
+
107
+    /*
108 108
 	|--------------------------------------------------------------------------
109 109
 	| CRUD Methods
110 110
 	|--------------------------------------------------------------------------
111 111
 	*/
112 112
 
113
-	/**
114
-	 * Method to create a new invoice in the database.
115
-	 *
116
-	 * @param WPInv_Invoice $invoice Invoice object.
117
-	 */
118
-	public function create( &$invoice ) {
119
-		$invoice->set_version( WPINV_VERSION );
120
-		$invoice->set_date_created( current_time( 'mysql' ) );
121
-
122
-		// Create a new post.
123
-		$id = wp_insert_post(
124
-			apply_filters(
125
-				'getpaid_new_invoice_data',
126
-				array(
127
-					'post_date'    => $invoice->get_date_created( 'edit' ),
128
-					'post_type'    => $invoice->get_post_type( 'edit' ),
129
-					'post_status'  => $this->get_post_status( $invoice ),
130
-					'ping_status'  => 'closed',
131
-					'post_author'  => $invoice->get_user_id( 'edit' ),
132
-					'post_title'   => $invoice->get_title( 'edit' ),
133
-					'post_excerpt' => $invoice->get_description( 'edit' ),
134
-					'post_parent'  => $invoice->get_parent_id( 'edit' ),
135
-				)
136
-			),
137
-			true
138
-		);
139
-
140
-		if ( $id && ! is_wp_error( $id ) ) {
141
-
142
-			// Update the new id and regenerate a title.
143
-			$invoice->set_id( $id );
144
-
145
-			$invoice->maybe_set_number();
146
-
147
-			wp_update_post(
148
-				array(
149
-					'ID'         => $invoice->get_id(),
150
-					'post_title' => $invoice->get_number( 'edit' ),
151
-					'post_name'  => $invoice->get_path( 'edit' ),
152
-				)
153
-			);
154
-
155
-			// Save special fields and items.
156
-			$this->save_special_fields( $invoice );
157
-			$this->save_items( $invoice );
158
-
159
-			// Update meta data.
160
-			$this->update_post_meta( $invoice );
161
-			$invoice->save_meta_data();
162
-
163
-			// Apply changes.
164
-			$invoice->apply_changes();
165
-			$this->clear_caches( $invoice );
166
-
167
-			// Fires after a new invoice is created.
168
-			do_action( 'getpaid_new_invoice', $invoice );
169
-			return true;
170
-		}
171
-
172
-		if ( is_wp_error( $id ) ) {
173
-			$invoice->last_error = $id->get_error_message();
174
-		}
175
-
176
-		return false;
177
-	}
178
-
179
-	/**
180
-	 * Method to read an invoice from the database.
181
-	 *
182
-	 * @param WPInv_Invoice $invoice Invoice object.
183
-	 *
184
-	 */
185
-	public function read( &$invoice ) {
186
-
187
-		$invoice->set_defaults();
188
-		$invoice_object = get_post( $invoice->get_id() );
189
-
190
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
191
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
192
-			$invoice->set_id( 0 );
193
-			return false;
194
-		}
195
-
196
-		$invoice->set_props(
197
-			array(
198
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
199
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
200
-				'status'        => $invoice_object->post_status,
201
-				'author'        => $invoice_object->post_author,
202
-				'description'   => $invoice_object->post_excerpt,
203
-				'parent_id'     => $invoice_object->post_parent,
204
-				'name'          => $invoice_object->post_title,
205
-				'path'          => $invoice_object->post_name,
206
-				'post_type'     => $invoice_object->post_type,
207
-			)
208
-		);
209
-
210
-		$invoice->set_type( $invoice_object->post_type );
211
-
212
-		$this->read_object_data( $invoice, $invoice_object );
213
-		$this->add_special_fields( $invoice );
214
-		$this->add_items( $invoice );
215
-		$invoice->read_meta_data();
216
-		$invoice->set_object_read( true );
217
-		do_action( 'getpaid_read_invoice', $invoice );
218
-
219
-	}
220
-
221
-	/**
222
-	 * Method to update an invoice in the database.
223
-	 *
224
-	 * @param WPInv_Invoice $invoice Invoice object.
225
-	 */
226
-	public function update( &$invoice ) {
227
-		$invoice->save_meta_data();
228
-		$invoice->set_version( WPINV_VERSION );
229
-
230
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
231
-			$invoice->set_date_created( current_time( 'mysql' ) );
232
-		}
233
-
234
-		// Ensure both the key and number are set.
235
-		$invoice->get_path();
236
-
237
-		// Grab the current status so we can compare.
238
-		$previous_status = get_post_status( $invoice->get_id() );
239
-
240
-		$changes = $invoice->get_changes();
241
-
242
-		// Only update the post when the post data changes.
243
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
244
-			$post_data = array(
245
-				'post_date'     => $invoice->get_date_created( 'edit' ),
246
-				'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ),
247
-				'post_status'   => $invoice->get_status( 'edit' ),
248
-				'post_title'    => $invoice->get_name( 'edit' ),
249
-				'post_author'   => $invoice->get_user_id( 'edit' ),
250
-				'post_modified' => $invoice->get_date_modified( 'edit' ),
251
-				'post_excerpt'  => $invoice->get_description( 'edit' ),
252
-				'post_parent'   => $invoice->get_parent_id( 'edit' ),
253
-				'post_name'     => $invoice->get_path( 'edit' ),
254
-				'post_type'     => $invoice->get_post_type( 'edit' ),
255
-			);
256
-
257
-			/**
258
-			 * When updating this object, to prevent infinite loops, use $wpdb
259
-			 * to update data, since wp_update_post spawns more calls to the
260
-			 * save_post action.
261
-			 *
262
-			 * This ensures hooks are fired by either WP itself (admin screen save),
263
-			 * or an update purely from CRUD.
264
-			 */
265
-			if ( doing_action( 'save_post' ) ) {
266
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
267
-				clean_post_cache( $invoice->get_id() );
268
-			} else {
269
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
270
-			}
271
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
272
-		}
273
-
274
-		// Update meta data.
275
-		$this->update_post_meta( $invoice );
276
-
277
-		// Save special fields and items.
278
-		$this->save_special_fields( $invoice );
279
-		$this->save_items( $invoice );
280
-
281
-		// Apply the changes.
282
-		$invoice->apply_changes();
283
-
284
-		// Clear caches.
285
-		$this->clear_caches( $invoice );
286
-
287
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
288
-		$new_status = $invoice->get_status( 'edit' );
289
-
290
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
291
-			do_action( 'getpaid_new_invoice', $invoice );
292
-		} else {
293
-			do_action( 'getpaid_update_invoice', $invoice );
294
-		}
295
-
296
-	}
297
-
298
-	/*
113
+    /**
114
+     * Method to create a new invoice in the database.
115
+     *
116
+     * @param WPInv_Invoice $invoice Invoice object.
117
+     */
118
+    public function create( &$invoice ) {
119
+        $invoice->set_version( WPINV_VERSION );
120
+        $invoice->set_date_created( current_time( 'mysql' ) );
121
+
122
+        // Create a new post.
123
+        $id = wp_insert_post(
124
+            apply_filters(
125
+                'getpaid_new_invoice_data',
126
+                array(
127
+                    'post_date'    => $invoice->get_date_created( 'edit' ),
128
+                    'post_type'    => $invoice->get_post_type( 'edit' ),
129
+                    'post_status'  => $this->get_post_status( $invoice ),
130
+                    'ping_status'  => 'closed',
131
+                    'post_author'  => $invoice->get_user_id( 'edit' ),
132
+                    'post_title'   => $invoice->get_title( 'edit' ),
133
+                    'post_excerpt' => $invoice->get_description( 'edit' ),
134
+                    'post_parent'  => $invoice->get_parent_id( 'edit' ),
135
+                )
136
+            ),
137
+            true
138
+        );
139
+
140
+        if ( $id && ! is_wp_error( $id ) ) {
141
+
142
+            // Update the new id and regenerate a title.
143
+            $invoice->set_id( $id );
144
+
145
+            $invoice->maybe_set_number();
146
+
147
+            wp_update_post(
148
+                array(
149
+                    'ID'         => $invoice->get_id(),
150
+                    'post_title' => $invoice->get_number( 'edit' ),
151
+                    'post_name'  => $invoice->get_path( 'edit' ),
152
+                )
153
+            );
154
+
155
+            // Save special fields and items.
156
+            $this->save_special_fields( $invoice );
157
+            $this->save_items( $invoice );
158
+
159
+            // Update meta data.
160
+            $this->update_post_meta( $invoice );
161
+            $invoice->save_meta_data();
162
+
163
+            // Apply changes.
164
+            $invoice->apply_changes();
165
+            $this->clear_caches( $invoice );
166
+
167
+            // Fires after a new invoice is created.
168
+            do_action( 'getpaid_new_invoice', $invoice );
169
+            return true;
170
+        }
171
+
172
+        if ( is_wp_error( $id ) ) {
173
+            $invoice->last_error = $id->get_error_message();
174
+        }
175
+
176
+        return false;
177
+    }
178
+
179
+    /**
180
+     * Method to read an invoice from the database.
181
+     *
182
+     * @param WPInv_Invoice $invoice Invoice object.
183
+     *
184
+     */
185
+    public function read( &$invoice ) {
186
+
187
+        $invoice->set_defaults();
188
+        $invoice_object = get_post( $invoice->get_id() );
189
+
190
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
191
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
192
+            $invoice->set_id( 0 );
193
+            return false;
194
+        }
195
+
196
+        $invoice->set_props(
197
+            array(
198
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
199
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
200
+                'status'        => $invoice_object->post_status,
201
+                'author'        => $invoice_object->post_author,
202
+                'description'   => $invoice_object->post_excerpt,
203
+                'parent_id'     => $invoice_object->post_parent,
204
+                'name'          => $invoice_object->post_title,
205
+                'path'          => $invoice_object->post_name,
206
+                'post_type'     => $invoice_object->post_type,
207
+            )
208
+        );
209
+
210
+        $invoice->set_type( $invoice_object->post_type );
211
+
212
+        $this->read_object_data( $invoice, $invoice_object );
213
+        $this->add_special_fields( $invoice );
214
+        $this->add_items( $invoice );
215
+        $invoice->read_meta_data();
216
+        $invoice->set_object_read( true );
217
+        do_action( 'getpaid_read_invoice', $invoice );
218
+
219
+    }
220
+
221
+    /**
222
+     * Method to update an invoice in the database.
223
+     *
224
+     * @param WPInv_Invoice $invoice Invoice object.
225
+     */
226
+    public function update( &$invoice ) {
227
+        $invoice->save_meta_data();
228
+        $invoice->set_version( WPINV_VERSION );
229
+
230
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
231
+            $invoice->set_date_created( current_time( 'mysql' ) );
232
+        }
233
+
234
+        // Ensure both the key and number are set.
235
+        $invoice->get_path();
236
+
237
+        // Grab the current status so we can compare.
238
+        $previous_status = get_post_status( $invoice->get_id() );
239
+
240
+        $changes = $invoice->get_changes();
241
+
242
+        // Only update the post when the post data changes.
243
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
244
+            $post_data = array(
245
+                'post_date'     => $invoice->get_date_created( 'edit' ),
246
+                'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ),
247
+                'post_status'   => $invoice->get_status( 'edit' ),
248
+                'post_title'    => $invoice->get_name( 'edit' ),
249
+                'post_author'   => $invoice->get_user_id( 'edit' ),
250
+                'post_modified' => $invoice->get_date_modified( 'edit' ),
251
+                'post_excerpt'  => $invoice->get_description( 'edit' ),
252
+                'post_parent'   => $invoice->get_parent_id( 'edit' ),
253
+                'post_name'     => $invoice->get_path( 'edit' ),
254
+                'post_type'     => $invoice->get_post_type( 'edit' ),
255
+            );
256
+
257
+            /**
258
+             * When updating this object, to prevent infinite loops, use $wpdb
259
+             * to update data, since wp_update_post spawns more calls to the
260
+             * save_post action.
261
+             *
262
+             * This ensures hooks are fired by either WP itself (admin screen save),
263
+             * or an update purely from CRUD.
264
+             */
265
+            if ( doing_action( 'save_post' ) ) {
266
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
267
+                clean_post_cache( $invoice->get_id() );
268
+            } else {
269
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
270
+            }
271
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
272
+        }
273
+
274
+        // Update meta data.
275
+        $this->update_post_meta( $invoice );
276
+
277
+        // Save special fields and items.
278
+        $this->save_special_fields( $invoice );
279
+        $this->save_items( $invoice );
280
+
281
+        // Apply the changes.
282
+        $invoice->apply_changes();
283
+
284
+        // Clear caches.
285
+        $this->clear_caches( $invoice );
286
+
287
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
288
+        $new_status = $invoice->get_status( 'edit' );
289
+
290
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
291
+            do_action( 'getpaid_new_invoice', $invoice );
292
+        } else {
293
+            do_action( 'getpaid_update_invoice', $invoice );
294
+        }
295
+
296
+    }
297
+
298
+    /*
299 299
 	|--------------------------------------------------------------------------
300 300
 	| Additional Methods
301 301
 	|--------------------------------------------------------------------------
302 302
 	*/
303 303
 
304
-	/**
304
+    /**
305 305
      * Retrieves special fields and adds to the invoice.
306
-	 *
307
-	 * @param WPInv_Invoice $invoice Invoice object.
306
+     *
307
+     * @param WPInv_Invoice $invoice Invoice object.
308 308
      */
309 309
     public function add_special_fields( &$invoice ) {
310
-		global $wpdb;
311
-
312
-		// Maybe retrieve from the cache.
313
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
314
-
315
-		// If not found, retrieve from the db.
316
-		if ( false === $data ) {
317
-			$table = $wpdb->prefix . 'getpaid_invoices';
318
-
319
-			$data  = $wpdb->get_row(
320
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
321
-				ARRAY_A
322
-			);
323
-
324
-			// Update the cache with our data
325
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
326
-
327
-		}
328
-
329
-		// Abort if the data does not exist.
330
-		if ( empty( $data ) ) {
331
-			$invoice->set_object_read( true );
332
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
333
-			return;
334
-		}
335
-
336
-		$props = array();
337
-
338
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
339
-
340
-			if ( $db_field == 'post_id' ) {
341
-				continue;
342
-			}
343
-
344
-			$props[ $prop ] = $data[ $db_field ];
345
-		}
346
-
347
-		$invoice->set_props( $props );
348
-
349
-	}
350
-
351
-	/**
352
-	 * Gets a list of special fields that need updated based on change state
353
-	 * or if they are present in the database or not.
354
-	 *
355
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
356
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
357
-	 */
358
-	protected function get_special_fields_to_update( $invoice ) {
359
-		$fields_to_update = array();
360
-		$changed_props   = $invoice->get_changes();
361
-
362
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
363
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
364
-			if ( array_key_exists( $prop, $changed_props ) ) {
365
-				$fields_to_update[ $database_field ] = $prop;
366
-			}
367
-		}
368
-
369
-		return $fields_to_update;
370
-	}
371
-
372
-	/**
373
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
374
-	 *
375
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
376
-	 * @since 1.0.19
377
-	 */
378
-	protected function update_special_fields( &$invoice ) {
379
-		global $wpdb;
380
-
381
-		$updated_props    = array();
382
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
383
-
384
-		foreach ( $fields_to_update as $database_field => $prop ) {
385
-			$value = $invoice->{"get_$prop"}( 'edit' );
386
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
387
-			$value = is_bool( $value ) ? (int) $value : $value;
388
-			$updated_props[ $database_field ] = maybe_serialize( $value );
389
-		}
390
-
391
-		if ( ! empty( $updated_props ) ) {
392
-
393
-			$table = $wpdb->prefix . 'getpaid_invoices';
394
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
395
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
396
-			do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props );
397
-
398
-		}
399
-
400
-	}
401
-
402
-	/**
403
-	 * Helper method that inserts special fields to the database.
404
-	 *
405
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
406
-	 * @since 1.0.19
407
-	 */
408
-	protected function insert_special_fields( &$invoice ) {
409
-		global $wpdb;
410
-
411
-		$updated_props   = array();
412
-
413
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
414
-			$value = $invoice->{"get_$prop"}( 'edit' );
415
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
416
-			$value = is_bool( $value ) ? (int) $value : $value;
417
-			$updated_props[ $database_field ] = maybe_serialize( $value );
418
-		}
419
-
420
-		$table = $wpdb->prefix . 'getpaid_invoices';
421
-		$wpdb->insert( $table, $updated_props );
422
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
423
-		do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props );
424
-
425
-	}
426
-
427
-	/**
310
+        global $wpdb;
311
+
312
+        // Maybe retrieve from the cache.
313
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
314
+
315
+        // If not found, retrieve from the db.
316
+        if ( false === $data ) {
317
+            $table = $wpdb->prefix . 'getpaid_invoices';
318
+
319
+            $data  = $wpdb->get_row(
320
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
321
+                ARRAY_A
322
+            );
323
+
324
+            // Update the cache with our data
325
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
326
+
327
+        }
328
+
329
+        // Abort if the data does not exist.
330
+        if ( empty( $data ) ) {
331
+            $invoice->set_object_read( true );
332
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
333
+            return;
334
+        }
335
+
336
+        $props = array();
337
+
338
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
339
+
340
+            if ( $db_field == 'post_id' ) {
341
+                continue;
342
+            }
343
+
344
+            $props[ $prop ] = $data[ $db_field ];
345
+        }
346
+
347
+        $invoice->set_props( $props );
348
+
349
+    }
350
+
351
+    /**
352
+     * Gets a list of special fields that need updated based on change state
353
+     * or if they are present in the database or not.
354
+     *
355
+     * @param  WPInv_Invoice $invoice       The Invoice object.
356
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
357
+     */
358
+    protected function get_special_fields_to_update( $invoice ) {
359
+        $fields_to_update = array();
360
+        $changed_props   = $invoice->get_changes();
361
+
362
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
363
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
364
+            if ( array_key_exists( $prop, $changed_props ) ) {
365
+                $fields_to_update[ $database_field ] = $prop;
366
+            }
367
+        }
368
+
369
+        return $fields_to_update;
370
+    }
371
+
372
+    /**
373
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
374
+     *
375
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
376
+     * @since 1.0.19
377
+     */
378
+    protected function update_special_fields( &$invoice ) {
379
+        global $wpdb;
380
+
381
+        $updated_props    = array();
382
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
383
+
384
+        foreach ( $fields_to_update as $database_field => $prop ) {
385
+            $value = $invoice->{"get_$prop"}( 'edit' );
386
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
387
+            $value = is_bool( $value ) ? (int) $value : $value;
388
+            $updated_props[ $database_field ] = maybe_serialize( $value );
389
+        }
390
+
391
+        if ( ! empty( $updated_props ) ) {
392
+
393
+            $table = $wpdb->prefix . 'getpaid_invoices';
394
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
395
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
396
+            do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props );
397
+
398
+        }
399
+
400
+    }
401
+
402
+    /**
403
+     * Helper method that inserts special fields to the database.
404
+     *
405
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
406
+     * @since 1.0.19
407
+     */
408
+    protected function insert_special_fields( &$invoice ) {
409
+        global $wpdb;
410
+
411
+        $updated_props   = array();
412
+
413
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
414
+            $value = $invoice->{"get_$prop"}( 'edit' );
415
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
416
+            $value = is_bool( $value ) ? (int) $value : $value;
417
+            $updated_props[ $database_field ] = maybe_serialize( $value );
418
+        }
419
+
420
+        $table = $wpdb->prefix . 'getpaid_invoices';
421
+        $wpdb->insert( $table, $updated_props );
422
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
423
+        do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props );
424
+
425
+    }
426
+
427
+    /**
428 428
      * Saves all special fields.
429
-	 *
430
-	 * @param WPInv_Invoice $invoice Invoice object.
429
+     *
430
+     * @param WPInv_Invoice $invoice Invoice object.
431 431
      */
432 432
     public function save_special_fields( &$invoice ) {
433
-		global $wpdb;
433
+        global $wpdb;
434 434
 
435
-		// The invoices table.
436
-		$table = $wpdb->prefix . 'getpaid_invoices';
437
-		$id    = (int) $invoice->get_id();
438
-		$invoice->maybe_set_key();
435
+        // The invoices table.
436
+        $table = $wpdb->prefix . 'getpaid_invoices';
437
+        $id    = (int) $invoice->get_id();
438
+        $invoice->maybe_set_key();
439 439
 
440
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
440
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
441 441
 
442
-			$this->update_special_fields( $invoice );
442
+            $this->update_special_fields( $invoice );
443 443
 
444
-		} else {
444
+        } else {
445 445
 
446
-			$this->insert_special_fields( $invoice );
446
+            $this->insert_special_fields( $invoice );
447 447
 
448
-		}
448
+        }
449 449
 
450
-	}
450
+    }
451 451
 
452
-	/**
452
+    /**
453 453
      * Set's up cart details.
454
-	 *
455
-	 * @param WPInv_Invoice $invoice Invoice object.
454
+     *
455
+     * @param WPInv_Invoice $invoice Invoice object.
456 456
      */
457 457
     public function add_items( &$invoice ) {
458
-		global $wpdb;
458
+        global $wpdb;
459 459
 
460
-		// Maybe retrieve from the cache.
461
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
460
+        // Maybe retrieve from the cache.
461
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
462 462
 
463
-		// If not found, retrieve from the db.
464
-		if ( false === $items ) {
465
-			$table = $wpdb->prefix . 'getpaid_invoice_items';
463
+        // If not found, retrieve from the db.
464
+        if ( false === $items ) {
465
+            $table = $wpdb->prefix . 'getpaid_invoice_items';
466 466
 
467
-			$items = $wpdb->get_results(
468
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
469
-			);
467
+            $items = $wpdb->get_results(
468
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
469
+            );
470 470
 
471
-			// Update the cache with our data
472
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
471
+            // Update the cache with our data
472
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
473 473
 
474
-		}
474
+        }
475 475
 
476
-		// Abort if no items found.
476
+        // Abort if no items found.
477 477
         if ( empty( $items ) ) {
478 478
             return;
479
-		}
480
-
481
-		$_items = array();
482
-		foreach ( $items as $item_data ) {
483
-			$item = new GetPaid_Form_Item( $item_data->item_id );
484
-
485
-			// Set item data.
486
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
487
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
488
-			$item->set_name( $item_data->item_name );
489
-			$item->set_description( $item_data->item_description );
490
-			$item->set_price( $item_data->item_price );
491
-			$item->set_quantity( $item_data->quantity );
492
-			$item->set_item_meta( $item_data->meta );
493
-			$_items[] = $item;
494
-		}
495
-
496
-		$invoice->set_items( $_items );
497
-	}
498
-
499
-	/**
479
+        }
480
+
481
+        $_items = array();
482
+        foreach ( $items as $item_data ) {
483
+            $item = new GetPaid_Form_Item( $item_data->item_id );
484
+
485
+            // Set item data.
486
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
487
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
488
+            $item->set_name( $item_data->item_name );
489
+            $item->set_description( $item_data->item_description );
490
+            $item->set_price( $item_data->item_price );
491
+            $item->set_quantity( $item_data->quantity );
492
+            $item->set_item_meta( $item_data->meta );
493
+            $_items[] = $item;
494
+        }
495
+
496
+        $invoice->set_items( $_items );
497
+    }
498
+
499
+    /**
500 500
      * Saves cart details.
501
-	 *
502
-	 * @param WPInv_Invoice $invoice Invoice object.
501
+     *
502
+     * @param WPInv_Invoice $invoice Invoice object.
503 503
      */
504 504
     public function save_items( $invoice ) {
505 505
 
506
-		// Delete previously existing items.
507
-		$this->delete_items( $invoice );
506
+        // Delete previously existing items.
507
+        $this->delete_items( $invoice );
508 508
 
509
-		$table   = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
509
+        $table   = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
510 510
 
511
-		foreach ( $invoice->get_cart_details() as $item_data ) {
512
-			$item_data = array_map( 'maybe_serialize', $item_data );
513
-			$GLOBALS['wpdb']->insert( $table, $item_data );
514
-		}
511
+        foreach ( $invoice->get_cart_details() as $item_data ) {
512
+            $item_data = array_map( 'maybe_serialize', $item_data );
513
+            $GLOBALS['wpdb']->insert( $table, $item_data );
514
+        }
515 515
 
516
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
517
-		do_action( 'getpaid_invoice_save_items', $invoice );
516
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
517
+        do_action( 'getpaid_invoice_save_items', $invoice );
518 518
 
519
-	}
519
+    }
520 520
 
521
-	/**
521
+    /**
522 522
      * Deletes an invoice's cart details from the database.
523
-	 *
524
-	 * @param WPInv_Invoice $invoice Invoice object.
523
+     *
524
+     * @param WPInv_Invoice $invoice Invoice object.
525 525
      */
526 526
     public function delete_items( $invoice ) {
527
-		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
528
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
529
-	}
527
+        $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
528
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
529
+    }
530 530
 
531
-	/**
531
+    /**
532 532
      * Deletes an invoice's special fields from the database.
533
-	 *
534
-	 * @param WPInv_Invoice $invoice Invoice object.
533
+     *
534
+     * @param WPInv_Invoice $invoice Invoice object.
535 535
      */
536 536
     public function delete_special_fields( $invoice ) {
537
-		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
538
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
539
-	}
540
-
541
-	/**
542
-	 * Get the status to save to the post object.
543
-	 *
544
-	 *
545
-	 * @since 1.0.19
546
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
547
-	 * @return string
548
-	 */
549
-	protected function get_post_status( $object ) {
550
-		$object_status = $object->get_status( 'edit' );
551
-
552
-		if ( ! $object_status ) {
553
-			$object_status = $object->get_default_status();
554
-		}
555
-
556
-		return $object_status;
557
-	}
537
+        $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
538
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
539
+    }
540
+
541
+    /**
542
+     * Get the status to save to the post object.
543
+     *
544
+     *
545
+     * @since 1.0.19
546
+     * @param  WPInv_Invoice $object GetPaid_Data object.
547
+     * @return string
548
+     */
549
+    protected function get_post_status( $object ) {
550
+        $object_status = $object->get_status( 'edit' );
551
+
552
+        if ( ! $object_status ) {
553
+            $object_status = $object->get_default_status();
554
+        }
555
+
556
+        return $object_status;
557
+    }
558 558
 
559 559
 }
Please login to merge, or discard this patch.
includes/class-getpaid-customer.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -15,69 +15,69 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Customer extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23 23
     protected $data_store_name = 'customer';
24 24
 
25 25
     /**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'customer';
31
-
32
-	/**
33
-	 * Get the customer if ID is passed, otherwise the customer is new and empty.
34
-	 *
35
-	 * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36
-	 */
37
-	public function __construct( $customer = 0 ) {
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'customer';
31
+
32
+    /**
33
+     * Get the customer if ID is passed, otherwise the customer is new and empty.
34
+     *
35
+     * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36
+     */
37
+    public function __construct( $customer = 0 ) {
38 38
 
39 39
         // Setup default customer data.
40 40
         $this->setup_default_data();
41 41
 
42
-		if ( is_numeric( $customer ) ) {
43
-			$this->set_id( $customer );
44
-		} elseif ( $customer instanceof self ) {
45
-			$this->set_id( $customer->get_id() );
46
-		} elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
-			$this->set_id( $customer_id );
48
-		} elseif ( ! empty( $customer->id ) ) {
49
-			$this->set_id( $customer->id );
50
-		}
42
+        if ( is_numeric( $customer ) ) {
43
+            $this->set_id( $customer );
44
+        } elseif ( $customer instanceof self ) {
45
+            $this->set_id( $customer->get_id() );
46
+        } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
+            $this->set_id( $customer_id );
48
+        } elseif ( ! empty( $customer->id ) ) {
49
+            $this->set_id( $customer->id );
50
+        }
51 51
 
52 52
         // Load the datastore.
53
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
53
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
54 54
 
55
-		if ( $this->get_id() > 0 ) {
56
-			$this->data_store->read( $this );
55
+        if ( $this->get_id() > 0 ) {
56
+            $this->data_store->read( $this );
57 57
         }
58 58
 
59 59
         $this->set_object_read( true );
60
-	}
60
+    }
61 61
 
62 62
     /**
63
-	 * Sets up default customer data.
64
-	 */
65
-	private function setup_default_data() {
63
+     * Sets up default customer data.
64
+     */
65
+    private function setup_default_data() {
66 66
 
67 67
         $this->data = array(
68
-			'user_id'        => 0,
69
-			'email'          => '',
70
-			'email_cc'       => '',
71
-			'status'         => 'active',
72
-			'purchase_value' => 0,
73
-			'purchase_count' => 0,
74
-			'date_created'   => current_time( 'mysql' ),
75
-			'date_modified'  => current_time( 'mysql' ),
76
-			'uuid'           => wp_generate_uuid4(),
77
-		);
68
+            'user_id'        => 0,
69
+            'email'          => '',
70
+            'email_cc'       => '',
71
+            'status'         => 'active',
72
+            'purchase_value' => 0,
73
+            'purchase_count' => 0,
74
+            'date_created'   => current_time( 'mysql' ),
75
+            'date_modified'  => current_time( 'mysql' ),
76
+            'uuid'           => wp_generate_uuid4(),
77
+        );
78 78
 
79 79
         // Add address fields.
80
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
80
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
81 81
 
82 82
             if ( isset( $this->data[ $field ] ) ) {
83 83
                 continue;
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
                 continue;
96 96
             }
97 97
 
98
-			$this->data[ $field ] = '';
99
-		}
98
+            $this->data[ $field ] = '';
99
+        }
100 100
 
101 101
         $this->default_data = $this->data;
102
-	}
103
-
104
-	/**
105
-	 * Given a customer email or user id, it returns a customer id.
106
-	 *
107
-	 * @static
108
-	 * @param string $value
109
-	 * @since 1.0.15
110
-	 * @return int
111
-	 */
112
-	public static function get_customer_id_by( $value, $by = 'email' ) {
113
-		global $wpdb;
102
+    }
103
+
104
+    /**
105
+     * Given a customer email or user id, it returns a customer id.
106
+     *
107
+     * @static
108
+     * @param string $value
109
+     * @since 1.0.15
110
+     * @return int
111
+     */
112
+    public static function get_customer_id_by( $value, $by = 'email' ) {
113
+        global $wpdb;
114 114
 
115 115
         // Prepare value.
116 116
         if ( 'email' === $by ) {
@@ -125,12 +125,12 @@  discard block
 block discarded – undo
125 125
             return 0;
126 126
         }
127 127
 
128
-		// Maybe retrieve from the cache.
128
+        // Maybe retrieve from the cache.
129 129
         $cache_key   = 'getpaid_customer_ids_by_' . $by;
130
-		$customer_id = wp_cache_get( $value, $cache_key );
131
-		if ( false !== $customer_id ) {
132
-			return $customer_id;
133
-		}
130
+        $customer_id = wp_cache_get( $value, $cache_key );
131
+        if ( false !== $customer_id ) {
132
+            return $customer_id;
133
+        }
134 134
 
135 135
         if ( 'email' === $by ) {
136 136
             $customer_id = (int) $wpdb->get_var(
@@ -142,23 +142,23 @@  discard block
 block discarded – undo
142 142
             );
143 143
         }
144 144
 
145
-		// Update the cache with our data
146
-		wp_cache_set( $value, $customer_id, $cache_key );
145
+        // Update the cache with our data
146
+        wp_cache_set( $value, $customer_id, $cache_key );
147 147
 
148
-		return $customer_id;
148
+        return $customer_id;
149 149
 
150
-	}
150
+    }
151 151
 
152
-	/**
152
+    /**
153 153
      * Clears the customer's cache.
154 154
      */
155 155
     public function clear_cache() {
156 156
         wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' );
157 157
         wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' );
158
-		wp_cache_delete( $this->get_id(), 'getpaid_customers' );
159
-	}
158
+        wp_cache_delete( $this->get_id(), 'getpaid_customers' );
159
+    }
160 160
 
161
-	/*
161
+    /*
162 162
 	|--------------------------------------------------------------------------
163 163
 	| CRUD methods
164 164
 	|--------------------------------------------------------------------------
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
             return call_user_func( array( $this, 'get_' . $key ), $context );
190 190
         }
191 191
 
192
-		return $this->get_prop( $key, $context );
192
+        return $this->get_prop( $key, $context );
193 193
 
194 194
     }
195 195
 
196
-	/*
196
+    /*
197 197
 	|--------------------------------------------------------------------------
198 198
 	| Setters
199 199
 	|--------------------------------------------------------------------------
@@ -216,114 +216,114 @@  discard block
 block discarded – undo
216 216
             return call_user_func( array( $this, 'set_' . $key ), $value );
217 217
         }
218 218
 
219
-		return $this->set_prop( $key, $value );
219
+        return $this->set_prop( $key, $value );
220 220
 
221 221
     }
222 222
 
223
-	/**
224
-	 * Sets customer status.
225
-	 *
226
-	 * @since 1.0.0
227
-	 * @param  string $status New status.
228
-	 */
229
-	public function set_status( $status ) {
230
-
231
-		if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
-			return $this->set_prop( 'status', $status );
233
-		}
234
-
235
-		$this->set_prop( 'status', 'inactive' );
236
-	}
237
-
238
-	/**
239
-	 * Sets the purchase value.
240
-	 *
241
-	 * @since 1.0.0
242
-	 * @param float $purchase_value.
243
-	 */
244
-	public function set_purchase_value( $purchase_value ) {
245
-		$this->set_prop( 'purchase_value', (float) $purchase_value );
246
-	}
223
+    /**
224
+     * Sets customer status.
225
+     *
226
+     * @since 1.0.0
227
+     * @param  string $status New status.
228
+     */
229
+    public function set_status( $status ) {
230
+
231
+        if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
+            return $this->set_prop( 'status', $status );
233
+        }
234
+
235
+        $this->set_prop( 'status', 'inactive' );
236
+    }
237
+
238
+    /**
239
+     * Sets the purchase value.
240
+     *
241
+     * @since 1.0.0
242
+     * @param float $purchase_value.
243
+     */
244
+    public function set_purchase_value( $purchase_value ) {
245
+        $this->set_prop( 'purchase_value', (float) $purchase_value );
246
+    }
247 247
 
248 248
     /**
249
-	 * Sets the purchase count.
250
-	 *
251
-	 * @since 1.0.0
252
-	 * @param int $purchase_count.
253
-	 */
254
-	public function set_purchase_count( $purchase_count ) {
255
-		$this->set_prop( 'purchase_count', absint( $purchase_count ) );
256
-	}
249
+     * Sets the purchase count.
250
+     *
251
+     * @since 1.0.0
252
+     * @param int $purchase_count.
253
+     */
254
+    public function set_purchase_count( $purchase_count ) {
255
+        $this->set_prop( 'purchase_count', absint( $purchase_count ) );
256
+    }
257 257
 
258 258
     /**
259
-	 * Sets the user id.
260
-	 *
261
-	 * @since 1.0.0
262
-	 * @param int $user_id.
263
-	 */
264
-	public function set_user_id( $user_id ) {
265
-		$this->set_prop( 'user_id', absint( $user_id ) );
266
-	}
259
+     * Sets the user id.
260
+     *
261
+     * @since 1.0.0
262
+     * @param int $user_id.
263
+     */
264
+    public function set_user_id( $user_id ) {
265
+        $this->set_prop( 'user_id', absint( $user_id ) );
266
+    }
267 267
 
268 268
     /**
269
-	 * Sets the email.
270
-	 *
271
-	 * @since 1.0.0
272
-	 * @param string $email.
273
-	 */
274
-	public function set_email( $email ) {
269
+     * Sets the email.
270
+     *
271
+     * @since 1.0.0
272
+     * @param string $email.
273
+     */
274
+    public function set_email( $email ) {
275 275
         $email = is_string( $email ) ? sanitize_email( $email ) : '';
276
-		$this->set_prop( 'email', $email );
277
-	}
276
+        $this->set_prop( 'email', $email );
277
+    }
278 278
 
279 279
     /**
280
-	 * Sets the email cc.
281
-	 *
282
-	 * @since 1.0.0
283
-	 * @param string $email_cc.
284
-	 */
285
-	public function set_email_cc( $email_cc ) {
280
+     * Sets the email cc.
281
+     *
282
+     * @since 1.0.0
283
+     * @param string $email_cc.
284
+     */
285
+    public function set_email_cc( $email_cc ) {
286 286
         $email_cc = implode( ', ', wp_parse_list( $email_cc ) );
287
-		$this->set_prop( 'email_cc', $email_cc );
288
-	}
287
+        $this->set_prop( 'email_cc', $email_cc );
288
+    }
289 289
 
290 290
     /**
291
-	 * Sets the created date.
292
-	 *
293
-	 * @since 1.0.0
294
-	 * @param  string $date_created date created.
295
-	 */
296
-	public function set_date_created( $date_created ) {
291
+     * Sets the created date.
292
+     *
293
+     * @since 1.0.0
294
+     * @param  string $date_created date created.
295
+     */
296
+    public function set_date_created( $date_created ) {
297 297
 
298
-		$date = strtotime( $date_created );
298
+        $date = strtotime( $date_created );
299 299
 
300 300
         if ( $date && $date_created !== '0000-00-00 00:00:00'  && $date_created !== '0000-00-00 00:00' ) {
301 301
             $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) );
302 302
             return;
303
-		}
303
+        }
304 304
 
305
-		$this->set_prop( 'date_created', null );
306
-	}
305
+        $this->set_prop( 'date_created', null );
306
+    }
307 307
 
308 308
     /**
309
-	 * Sets the created date.
310
-	 *
311
-	 * @since 1.0.0
312
-	 * @param  string $date_modified date created.
313
-	 */
314
-	public function set_date_modified( $date_modified ) {
309
+     * Sets the created date.
310
+     *
311
+     * @since 1.0.0
312
+     * @param  string $date_modified date created.
313
+     */
314
+    public function set_date_modified( $date_modified ) {
315 315
 
316
-		$date = strtotime( $date_modified );
316
+        $date = strtotime( $date_modified );
317 317
 
318 318
         if ( $date && $date_modified !== '0000-00-00 00:00:00'  && $date_modified !== '0000-00-00 00:00' ) {
319 319
             $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) );
320 320
             return;
321
-		}
321
+        }
322 322
 
323
-		$this->set_prop( 'date_modified', null );
324
-	}
323
+        $this->set_prop( 'date_modified', null );
324
+    }
325 325
 
326
-	/*
326
+    /*
327 327
 	|--------------------------------------------------------------------------
328 328
 	| Additional methods
329 329
 	|--------------------------------------------------------------------------
@@ -332,12 +332,12 @@  discard block
 block discarded – undo
332 332
 	|
333 333
 	*/
334 334
 
335
-	/**
336
-	 * Saves the customer.
337
-	 *
338
-	 * @since 1.0.0
339
-	 */
340
-	public function save() {
335
+    /**
336
+     * Saves the customer.
337
+     *
338
+     * @since 1.0.0
339
+     */
340
+    public function save() {
341 341
 
342 342
         $maybe_set = array(
343 343
             'uuid'         => wp_generate_uuid4(),
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
         $this->set( 'date_modified', current_time( 'mysql' ) );
356 356
 
357
-		return parent::save();
358
-	}
357
+        return parent::save();
358
+    }
359 359
 
360 360
     /**
361
-	 * Helper method to clone a customer from a user ID.
362
-	 *
363
-	 * @since 1.0.0
364
-	 * @param int $user_id.
365
-	 */
366
-	public function clone_user( $user_id ) {
361
+     * Helper method to clone a customer from a user ID.
362
+     *
363
+     * @since 1.0.0
364
+     * @param int $user_id.
365
+     */
366
+    public function clone_user( $user_id ) {
367 367
         $user = get_userdata( $user_id );
368 368
 
369 369
         if ( empty( $user ) ) {
370 370
             return;
371 371
         }
372 372
 
373
-		$this->set_user_id( $user->ID );
373
+        $this->set_user_id( $user->ID );
374 374
         $this->set_email( $user->user_email );
375 375
         $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) );
376 376
         $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) );
377 377
         $this->set( 'first_name', $user->first_name );
378 378
         $this->set( 'last_name', $user->last_name );
379
-		$this->set_date_created( $user->user_registered );
379
+        $this->set_date_created( $user->user_registered );
380 380
 
381 381
         // Fetch extra data from WC or old GetPaid.
382 382
         $prefixes = array(
@@ -400,18 +400,18 @@  discard block
 block discarded – undo
400 400
                     continue;
401 401
                 }
402 402
             }
403
-		}
404
-	}
403
+        }
404
+    }
405 405
 
406 406
     /**
407
-	 * Helper method to migrate an existing user ID to the new customers table.
408
-	 *
409
-	 * @since 1.0.0
410
-	 * @param int $user_id.
411
-	 */
412
-	public function migrate_from_user( $user_id ) {
407
+     * Helper method to migrate an existing user ID to the new customers table.
408
+     *
409
+     * @since 1.0.0
410
+     * @param int $user_id.
411
+     */
412
+    public function migrate_from_user( $user_id ) {
413 413
         $this->clone_user( $user_id );
414 414
         do_action( 'getpaid_customer_migrated_from_user', $this, $user_id );
415 415
         $this->save();
416
-	}
416
+    }
417 417
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items    = $this->get_submission_items();
40
-		$invoice  = $this->get_submission_invoice();
41
-		$invoice  = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items    = $this->get_submission_items();
40
+        $invoice  = $this->get_submission_invoice();
41
+        $invoice  = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
133 125
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
138 131
 
139
-		return $invoice;
140
-	}
132
+        $invoice = $submission->get_invoice();
141 133
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
150 138
 
151
-		$submission = $this->payment_form_submission;
139
+        return $invoice;
140
+    }
152 141
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
200
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
+            $name = implode( '', array_filter( $name ) );
202 202
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
203 203
 
204
-			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
208
-			}
209
-		}
204
+            // (Maybe) send new user notification.
205
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
+                wp_send_new_user_notifications( $user, 'user' );
208
+            }
209
+        }
210 210
 
211 211
         if ( is_wp_error( $user ) ) {
212 212
             wp_send_json_error( $user->get_error_message() );
@@ -214,49 +214,49 @@  discard block
 block discarded – undo
214 214
 
215 215
         if ( is_numeric( $user ) ) {
216 216
             return $user;
217
-		}
217
+        }
218 218
 
219
-		return $user->ID;
219
+        return $user->ID;
220 220
 
221
-	}
221
+    }
222 222
 
223
-	/**
223
+    /**
224 224
      * Prepares submission data for saving to the database.
225 225
      *
226
-	 * @return array
226
+     * @return array
227 227
      */
228 228
     public function prepare_submission_data_for_saving() {
229 229
 
230
-		$submission = $this->payment_form_submission;
230
+        $submission = $this->payment_form_submission;
231 231
 
232
-		// Prepared submission details.
232
+        // Prepared submission details.
233 233
         $prepared = array(
234
-			'all'  => array(),
235
-			'meta' => array(),
236
-		);
234
+            'all'  => array(),
235
+            'meta' => array(),
236
+        );
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+        $data     = $submission->get_data();
240 240
 
241
-		// Loop through the submitted details.
241
+        // Loop through the submitted details.
242 242
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243 243
 
244
-			// Skip premade fields.
244
+            // Skip premade fields.
245 245
             if ( ! empty( $field['premade'] ) ) {
246 246
                 continue;
247 247
             }
248 248
 
249
-			// Ensure address is provided.
250
-			if ( 'address' === $field['type'] ) {
249
+            // Ensure address is provided.
250
+            if ( 'address' === $field['type'] ) {
251 251
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+                foreach ( $field['fields'] as $address_field ) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
-					}
258
-			}
259
-		}
255
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
256
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
+                    }
258
+            }
259
+        }
260 260
 
261 261
             // If it is required and not set, abort.
262 262
             if ( ! $submission->is_required_field_set( $field ) ) {
@@ -266,31 +266,31 @@  discard block
 block discarded – undo
266 266
             // Handle misc fields.
267 267
             if ( isset( $data[ $field['id'] ] ) ) {
268 268
 
269
-				// Uploads.
270
-				if ( 'file_upload' === $field['type'] ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
269
+                // Uploads.
270
+                if ( 'file_upload' === $field['type'] ) {
271
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
-					}
273
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
+                    }
276 276
 
277
-					$value = array();
277
+                    $value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
-						$value[] = sprintf(
281
-							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
284
-						);
285
-					}
279
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+                        $value[] = sprintf(
281
+                            '<a href="%s" target="_blank">%s</a>',
282
+                            esc_url_raw( $url ),
283
+                            esc_html( $name )
284
+                        );
285
+                    }
286 286
 
287
-					$value = implode( ' | ', $value );
287
+                    $value = implode( ' | ', $value );
288 288
 
289
-				} elseif ( 'checkbox' === $field['type'] ) {
290
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
-				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
-				}
289
+                } elseif ( 'checkbox' === $field['type'] ) {
290
+                    $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
+                } else {
292
+                    $value = wp_kses_post( $data[ $field['id'] ] );
293
+                }
294 294
 
295 295
                 $label = $field['id'];
296 296
 
@@ -298,192 +298,192 @@  discard block
 block discarded – undo
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
-				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+                if ( ! empty( $field['add_meta'] ) ) {
302
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
+                }
304
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305 305
 
306 306
             }
307
-		}
307
+        }
308 308
 
309
-		return $prepared;
309
+        return $prepared;
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Retrieves address details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
318
-	 * @param string $type
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318
+     * @param string $type
319 319
      */
320 320
     public function prepare_address_details( $invoice, $type = 'billing' ) {
321 321
 
322
-		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
324
-		$address  = array();
325
-		$prepared = array();
322
+        $data     = $this->payment_form_submission->get_data();
323
+        $type     = sanitize_key( $type );
324
+        $address  = array();
325
+        $prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
329
-		}
327
+        if ( ! empty( $data[ $type ] ) ) {
328
+            $address = $data[ $type ];
329
+        }
330 330
 
331
-		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
-		}
331
+        // Clean address details.
332
+        foreach ( $address as $key => $value ) {
333
+            $key             = sanitize_key( $key );
334
+            $key             = str_replace( 'wpinv_', '', $key );
335
+            $value           = wpinv_clean( $value );
336
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
+        }
338 338
 
339
-		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
339
+        // Filter address details.
340
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341 341
 
342
-		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
342
+        // Remove non-whitelisted values.
343
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344 344
 
345
-	}
345
+    }
346 346
 
347
-	/**
347
+    /**
348 348
      * Prepares the billing details.
349 349
      *
350
-	 * @return array
351
-	 * @param WPInv_Invoice $invoice
350
+     * @return array
351
+     * @param WPInv_Invoice $invoice
352 352
      */
353 353
     protected function prepare_billing_info( &$invoice ) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
356 356
 
357
-		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
357
+        // Update the invoice with the billing details.
358
+        $invoice->set_props( $billing_address );
359 359
 
360
-	}
360
+    }
361 361
 
362
-	/**
362
+    /**
363 363
      * Prepares the shipping details.
364 364
      *
365
-	 * @return array
366
-	 * @param WPInv_Invoice $invoice
365
+     * @return array
366
+     * @param WPInv_Invoice $invoice
367 367
      */
368 368
     protected function prepare_shipping_info( $invoice ) {
369 369
 
370
-		$data = $this->payment_form_submission->get_data();
370
+        $data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
-		}
372
+        if ( empty( $data['same-shipping-address'] ) ) {
373
+            return $this->prepare_address_details( $invoice, 'shipping' );
374
+        }
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+        return $this->prepare_address_details( $invoice, 'billing' );
377 377
 
378
-	}
378
+    }
379 379
 
380
-	/**
381
-	 * Confirms the submission is valid and send users to the gateway.
382
-	 *
383
-	 * @param WPInv_Invoice $invoice
384
-	 * @param array $prepared_payment_form_data
385
-	 * @param array $shipping
386
-	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
380
+    /**
381
+     * Confirms the submission is valid and send users to the gateway.
382
+     *
383
+     * @param WPInv_Invoice $invoice
384
+     * @param array $prepared_payment_form_data
385
+     * @param array $shipping
386
+     */
387
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388 388
 
389
-		// Ensure the invoice exists.
389
+        // Ensure the invoice exists.
390 390
         if ( ! $invoice->exists() ) {
391 391
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392 392
         }
393 393
 
394
-		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
394
+        // Save payment form data.
395
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396 396
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
+        if ( ! empty( $prepared_payment_form_data ) ) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
-			}
400
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+            }
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
-			}
407
-		}
404
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+            }
407
+        }
408 408
 
409
-		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
409
+        // Save payment form data.
410
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411 411
         if ( ! empty( $shipping ) ) {
412 412
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
-		}
413
+        }
414 414
 
415
-		// Backwards compatibility.
415
+        // Backwards compatibility.
416 416
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417 417
 
418
-		try {
419
-			$this->process_payment( $invoice );
420
-		} catch ( Exception $e ) {
421
-			wpinv_set_error( 'payment_error', $e->getMessage() );
422
-		}
418
+        try {
419
+            $this->process_payment( $invoice );
420
+        } catch ( Exception $e ) {
421
+            wpinv_set_error( 'payment_error', $e->getMessage() );
422
+        }
423 423
 
424 424
         // If we are here, there was an error.
425
-		wpinv_send_back_to_checkout( $invoice );
425
+        wpinv_send_back_to_checkout( $invoice );
426 426
 
427
-	}
427
+    }
428 428
 
429
-	/**
430
-	 * Processes the actual payment.
431
-	 *
432
-	 * @param WPInv_Invoice $invoice
433
-	 */
434
-	protected function process_payment( $invoice ) {
429
+    /**
430
+     * Processes the actual payment.
431
+     *
432
+     * @param WPInv_Invoice $invoice
433
+     */
434
+    protected function process_payment( $invoice ) {
435 435
 
436
-		// Clear any checkout errors.
437
-		wpinv_clear_errors();
436
+        // Clear any checkout errors.
437
+        wpinv_clear_errors();
438 438
 
439
-		// No need to send free invoices to the gateway.
440
-		if ( $invoice->is_free() ) {
441
-			$this->process_free_payment( $invoice );
442
-		}
439
+        // No need to send free invoices to the gateway.
440
+        if ( $invoice->is_free() ) {
441
+            $this->process_free_payment( $invoice );
442
+        }
443 443
 
444
-		$submission = $this->payment_form_submission;
444
+        $submission = $this->payment_form_submission;
445 445
 
446
-		// Fires before sending to the gateway.
447
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
446
+        // Fires before sending to the gateway.
447
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
448 448
 
449
-		// Allow the sumission data to be modified before it is sent to the gateway.
450
-		$submission_data    = $submission->get_data();
451
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
452
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
449
+        // Allow the sumission data to be modified before it is sent to the gateway.
450
+        $submission_data    = $submission->get_data();
451
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
452
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
453 453
 
454
-		// Validate the currency.
455
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
456
-			wpinv_set_error( 'invalid_currency' );
457
-		}
454
+        // Validate the currency.
455
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
456
+            wpinv_set_error( 'invalid_currency' );
457
+        }
458 458
 
459
-		// Check to see if we have any errors.
460
-		if ( wpinv_get_errors() ) {
461
-			wpinv_send_back_to_checkout( $invoice );
462
-		}
459
+        // Check to see if we have any errors.
460
+        if ( wpinv_get_errors() ) {
461
+            wpinv_send_back_to_checkout( $invoice );
462
+        }
463 463
 
464
-		// Send info to the gateway for payment processing
465
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
464
+        // Send info to the gateway for payment processing
465
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
466 466
 
467
-		// Backwards compatibility.
468
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
467
+        // Backwards compatibility.
468
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
469 469
 
470
-	}
470
+    }
471 471
 
472
-	/**
473
-	 * Marks the invoice as paid in case the checkout is free.
474
-	 *
475
-	 * @param WPInv_Invoice $invoice
476
-	 */
477
-	protected function process_free_payment( $invoice ) {
472
+    /**
473
+     * Marks the invoice as paid in case the checkout is free.
474
+     *
475
+     * @param WPInv_Invoice $invoice
476
+     */
477
+    protected function process_free_payment( $invoice ) {
478 478
 
479
-		$invoice->set_gateway( 'none' );
480
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
481
-		$invoice->mark_paid();
482
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
479
+        $invoice->set_gateway( 'none' );
480
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
481
+        $invoice->mark_paid();
482
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
483 483
 
484
-	}
484
+    }
485 485
 
486
-	/**
486
+    /**
487 487
      * Sends a redrect response to payment details.
488 488
      *
489 489
      */
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-items.php 1 patch
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
             $class .= ' wpi-recurring';
76 76
         }
77 77
 
78
-		$refund_url = wp_nonce_url(
79
-			add_query_arg(
80
-				array(
81
-					'getpaid-admin-action' => 'refund_invoice',
82
-					'invoice_id'           => $invoice->get_id(),
83
-				)
84
-			),
85
-			'getpaid-nonce',
86
-			'getpaid-nonce'
87
-		);
78
+        $refund_url = wp_nonce_url(
79
+            add_query_arg(
80
+                array(
81
+                    'getpaid-admin-action' => 'refund_invoice',
82
+                    'invoice_id'           => $invoice->get_id(),
83
+                )
84
+            ),
85
+            'getpaid-nonce',
86
+            'getpaid-nonce'
87
+        );
88 88
     ?>
89 89
 
90 90
         <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>">
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
                             <th class="
97 97
                             <?php
98 98
                             echo esc_attr( $key );
99
-							echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100
-							?>
99
+                            echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100
+                            ?>
101 101
 							"><?php echo wp_kses_post( $label ); ?></th>
102 102
                         <?php endforeach; ?>
103 103
                     </tr>
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                 <tbody class="wpinv-line-items">
107 107
                     <?php
108 108
                         foreach ( $invoice->get_items() as $int => $item ) {
109
-						self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
109
+                        self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
110 110
                         }
111 111
                     ?>
112 112
                 </tbody>
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
                                                         <?php
152 152
                                                         wpinv_html_select(
153 153
                                                             array(
154
-																'options'          => $item_types,
155
-																'name'             => '_wpinv_quick[type]',
156
-																'id'               => '_wpinv_quick_type',
157
-																'selected'         => 'custom',
158
-																'show_option_all'  => false,
159
-																'show_option_none' => false,
160
-																'class'            => 'gdmbx2-text-medium wpinv-quick-type',
154
+                                                                'options'          => $item_types,
155
+                                                                'name'             => '_wpinv_quick[type]',
156
+                                                                'id'               => '_wpinv_quick_type',
157
+                                                                'selected'         => 'custom',
158
+                                                                'show_option_all'  => false,
159
+                                                                'show_option_none' => false,
160
+                                                                'class'            => 'gdmbx2-text-medium wpinv-quick-type',
161 161
                                                             )
162 162
                                                         );
163 163
                                                             ?>
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
                                                             <?php
173 173
                                                                 wpinv_html_select(
174 174
                                                                     array(
175
-																		'options'          => array_merge(
176
-																			array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
177
-																			getpaid_get_tax_rules()
178
-																		),
179
-																		'name'             => '_wpinv_quick[vat_rule]',
180
-																		'id'               => '_wpinv_quick_vat_rule',
181
-																		'show_option_all'  => false,
182
-																		'show_option_none' => false,
183
-																		'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
184
-																		'selected'         => 'digital',
175
+                                                                        'options'          => array_merge(
176
+                                                                            array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
177
+                                                                            getpaid_get_tax_rules()
178
+                                                                        ),
179
+                                                                        'name'             => '_wpinv_quick[vat_rule]',
180
+                                                                        'id'               => '_wpinv_quick_vat_rule',
181
+                                                                        'show_option_all'  => false,
182
+                                                                        'show_option_none' => false,
183
+                                                                        'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
184
+                                                                        'selected'         => 'digital',
185 185
                                                                     )
186 186
                                                                 );
187 187
                                                             ?>
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
                                                             <?php
195 195
                                                                 wpinv_html_select(
196 196
                                                                     array(
197
-																		'options'          => array_merge(
198
-																			array( '' => __( 'Select VAT Class', 'invoicing' ) ),
199
-																			getpaid_get_tax_classes()
200
-																		),
201
-																		'name'             => '_wpinv_quick[vat_class]',
202
-																		'id'               => '_wpinv_quick_vat_class',
203
-																		'show_option_all'  => false,
204
-																		'show_option_none' => false,
205
-																		'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
206
-																		'selected'         => '_standard',
197
+                                                                        'options'          => array_merge(
198
+                                                                            array( '' => __( 'Select VAT Class', 'invoicing' ) ),
199
+                                                                            getpaid_get_tax_classes()
200
+                                                                        ),
201
+                                                                        'name'             => '_wpinv_quick[vat_class]',
202
+                                                                        'id'               => '_wpinv_quick_vat_class',
203
+                                                                        'show_option_all'  => false,
204
+                                                                        'show_option_none' => false,
205
+                                                                        'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
206
+                                                                        'selected'         => '_standard',
207 207
                                                                     )
208 208
                                                                 );
209 209
                                                             ?>
@@ -294,37 +294,37 @@  discard block
 block discarded – undo
294 294
 								</p>
295 295
 								<?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?>
296 296
 									<?php
297
-										aui()->input(
298
-											array(
299
-												'type'  => 'checkbox',
300
-												'name'  => 'getpaid_refund_remote',
301
-												'id'    => 'getpaid_refund_remote',
302
-												'label' => sprintf(
303
-													'Refund payment in %s',
304
-													wpinv_get_gateway_admin_label( $invoice->get_gateway() )
305
-												),
306
-												'value' => 1,
307
-												'class' => 'getpaid-refund-field',
308
-											),
309
-											true
310
-										);
311
-									?>
297
+                                        aui()->input(
298
+                                            array(
299
+                                                'type'  => 'checkbox',
300
+                                                'name'  => 'getpaid_refund_remote',
301
+                                                'id'    => 'getpaid_refund_remote',
302
+                                                'label' => sprintf(
303
+                                                    'Refund payment in %s',
304
+                                                    wpinv_get_gateway_admin_label( $invoice->get_gateway() )
305
+                                                ),
306
+                                                'value' => 1,
307
+                                                'class' => 'getpaid-refund-field',
308
+                                            ),
309
+                                            true
310
+                                        );
311
+                                    ?>
312 312
 								<?php endif; ?>
313 313
 
314 314
 								<?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?>
315 315
 									<?php
316
-										aui()->input(
317
-											array(
318
-												'type'  => 'checkbox',
319
-												'name'  => 'getpaid_cancel_subscription',
320
-												'id'    => 'getpaid_cancel_subscription',
321
-												'label' => __( 'Cancel subscription', 'invoicing' ),
322
-												'value' => 1,
323
-												'class' => 'getpaid-refund-field',
324
-											),
325
-											true
326
-										);
327
-									?>
316
+                                        aui()->input(
317
+                                            array(
318
+                                                'type'  => 'checkbox',
319
+                                                'name'  => 'getpaid_cancel_subscription',
320
+                                                'id'    => 'getpaid_cancel_subscription',
321
+                                                'label' => __( 'Cancel subscription', 'invoicing' ),
322
+                                                'value' => 1,
323
+                                                'class' => 'getpaid-refund-field',
324
+                                            ),
325
+                                            true
326
+                                        );
327
+                                    ?>
328 328
 								<?php endif; ?>
329 329
                             </div>
330 330
                             <div class="modal-footer">
@@ -364,23 +364,23 @@  discard block
 block discarded – undo
364 364
                 <?php
365 365
                     if ( $invoice->is_paid() ) {
366 366
 
367
-						printf(
368
-							'<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
369
-							esc_html__( 'Refund', 'invoicing' )
370
-						);
367
+                        printf(
368
+                            '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
369
+                            esc_html__( 'Refund', 'invoicing' )
370
+                        );
371 371
                     } elseif ( ! $invoice->is_refunded() ) {
372
-						wpinv_item_dropdown(
373
-							array(
374
-								'name'           => 'wpinv_invoice_item',
375
-								'id'             => 'wpinv_invoice_item',
376
-								'show_recurring' => true,
377
-								'class'          => 'wpi_select2',
378
-							)
379
-						);
380
-
381
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
382
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
383
-						echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
372
+                        wpinv_item_dropdown(
373
+                            array(
374
+                                'name'           => 'wpinv_invoice_item',
375
+                                'id'             => 'wpinv_invoice_item',
376
+                                'show_recurring' => true,
377
+                                'class'          => 'wpi_select2',
378
+                            )
379
+                        );
380
+
381
+                        echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
382
+                        echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
383
+                        echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
384 384
 
385 385
                     }
386 386
                 ?>
@@ -397,72 +397,72 @@  discard block
 block discarded – undo
397 397
             <?php foreach ( array_keys( $columns ) as $column ) : ?>
398 398
                 <td class="
399 399
 					<?php
400
-						echo esc_attr( $column );
401
-						echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
402
-					?>
400
+                        echo esc_attr( $column );
401
+                        echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
402
+                    ?>
403 403
 				">
404 404
                     <?php
405 405
                         switch ( $column ) {
406
-						case 'id':
407
-							echo (int) $item->get_id();
408
-							break;
409
-						case 'title':
410
-							printf(
411
-								'<a href="%s" target="_blank">%s</a>',
412
-								esc_url( get_edit_post_link( $item->get_id() ) ),
413
-								esc_html( $item->get_raw_name() )
414
-							);
415
-
416
-							$summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
417
-							if ( $summary !== '' ) {
418
-								printf(
419
-									'<span class="meta">%s</span>',
420
-									wp_kses_post( wpautop( $summary ) )
421
-								);
422
-							}
423
-
424
-							printf(
425
-								'<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
426
-								esc_attr( $item->get_raw_name() ),
427
-								(int) $item->get_id()
428
-							);
429
-
430
-							printf(
431
-								'<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
432
-								(int) $item->get_id(),
433
-								esc_attr( $item->get_description() )
434
-							);
435
-
436
-							break;
437
-						case 'price':
438
-							printf(
439
-								'<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
440
-								esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
441
-								(int) $item->get_id()
442
-							);
443
-
444
-							break;
445
-						case 'qty':
446
-							printf(
447
-								'<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
448
-								floatval( $item->get_quantity() ),
449
-								(int) $item->get_id()
450
-							);
451
-
452
-							break;
453
-						case 'total':
454
-							wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
455
-
456
-							break;
457
-						case 'tax':
458
-							echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
459
-
460
-							break;
461
-						case 'action':
462
-							if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
463
-								echo '<i class="fa fa-trash wpinv-item-remove"></i>';
406
+                        case 'id':
407
+                            echo (int) $item->get_id();
408
+                            break;
409
+                        case 'title':
410
+                            printf(
411
+                                '<a href="%s" target="_blank">%s</a>',
412
+                                esc_url( get_edit_post_link( $item->get_id() ) ),
413
+                                esc_html( $item->get_raw_name() )
414
+                            );
415
+
416
+                            $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
417
+                            if ( $summary !== '' ) {
418
+                                printf(
419
+                                    '<span class="meta">%s</span>',
420
+                                    wp_kses_post( wpautop( $summary ) )
421
+                                );
422
+                            }
423
+
424
+                            printf(
425
+                                '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
426
+                                esc_attr( $item->get_raw_name() ),
427
+                                (int) $item->get_id()
428
+                            );
429
+
430
+                            printf(
431
+                                '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
432
+                                (int) $item->get_id(),
433
+                                esc_attr( $item->get_description() )
434
+                            );
435
+
436
+                            break;
437
+                        case 'price':
438
+                            printf(
439
+                                '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
440
+                                esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
441
+                                (int) $item->get_id()
442
+                            );
443
+
444
+                            break;
445
+                        case 'qty':
446
+                            printf(
447
+                                '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
448
+                                floatval( $item->get_quantity() ),
449
+                                (int) $item->get_id()
450
+                            );
451
+
452
+                            break;
453
+                        case 'total':
454
+                            wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
455
+
456
+                            break;
457
+                        case 'tax':
458
+                            echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
459
+
460
+                            break;
461
+                        case 'action':
462
+                            if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
463
+                                echo '<i class="fa fa-trash wpinv-item-remove"></i>';
464 464
                                 }
465
-							break;
465
+                            break;
466 466
                         }
467 467
                         do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice );
468 468
                     ?>
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
     }
474 474
 
475 475
     /**
476
-	 * Output the metabox.
477
-	 *
478
-	 * @param WP_Post $post
479
-	 */
476
+     * Output the metabox.
477
+     *
478
+     * @param WP_Post $post
479
+     */
480 480
     public static function output2( $post ) {
481 481
 
482 482
         // Prepare the invoice.
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +620 added lines, -620 removed lines patch added patch discarded remove patch
@@ -14,94 +14,94 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
29
-
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29
+
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct() {
38
+     * Class constructor.
39
+     */
40
+    public function __construct() {
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect' ) );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) );
66
+        add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
67
+        add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) );
68
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
69
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
70 70
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
75
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
76
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
77
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
78
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
79
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
80
-		do_action( 'getpaid_init_admin_hooks', $this );
81
-
82
-		// Setup/welcome
83
-		if ( ! empty( $_GET['page'] ) ) {
84
-			switch ( sanitize_text_field( $_GET['page'] ) ) {
85
-				case 'gp-setup':
86
-					include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
87
-					break;
88
-			}
89
-		}
90
-
91
-    }
92
-
93
-    /**
94
-	 * Register admin scripts
95
-	 *
96
-	 */
97
-	public function enqeue_scripts() {
71
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
74
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
75
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
76
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
77
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
78
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
79
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
80
+        do_action( 'getpaid_init_admin_hooks', $this );
81
+
82
+        // Setup/welcome
83
+        if ( ! empty( $_GET['page'] ) ) {
84
+            switch ( sanitize_text_field( $_GET['page'] ) ) {
85
+                case 'gp-setup':
86
+                    include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
87
+                    break;
88
+            }
89
+        }
90
+
91
+    }
92
+
93
+    /**
94
+     * Register admin scripts
95
+     *
96
+     */
97
+    public function enqeue_scripts() {
98 98
         global $current_screen, $pagenow;
99 99
 
100
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
101
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
100
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
101
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
102 102
 
103 103
         if ( ! empty( $current_screen->post_type ) ) {
104
-			$page = $current_screen->post_type;
104
+            $page = $current_screen->post_type;
105 105
         }
106 106
 
107 107
         // General styles.
@@ -122,53 +122,53 @@  discard block
 block discarded – undo
122 122
         }
123 123
 
124 124
         // Payment form scripts.
125
-		if ( 'wpi_payment_form' == $page && $editing ) {
125
+        if ( 'wpi_payment_form' == $page && $editing ) {
126 126
             $this->load_payment_form_scripts();
127 127
         }
128 128
 
129
-		if ( $page == 'wpinv-subscriptions' ) {
130
-			wp_enqueue_script( 'postbox' );
131
-		}
129
+        if ( $page == 'wpinv-subscriptions' ) {
130
+            wp_enqueue_script( 'postbox' );
131
+        }
132 132
 
133 133
     }
134 134
 
135 135
     /**
136
-	 * Returns admin js translations.
137
-	 *
138
-	 */
139
-	protected function get_admin_i18() {
136
+     * Returns admin js translations.
137
+     *
138
+     */
139
+    protected function get_admin_i18() {
140 140
         global $post;
141 141
 
142
-		$date_range = array(
143
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
144
-		);
142
+        $date_range = array(
143
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
144
+        );
145 145
 
146
-		if ( $date_range['period'] == 'custom' ) {
146
+        if ( $date_range['period'] == 'custom' ) {
147 147
 
148
-			if ( isset( $_GET['from'] ) ) {
149
-				$date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
150
-			}
148
+            if ( isset( $_GET['from'] ) ) {
149
+                $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
150
+            }
151 151
 
152
-			if ( isset( $_GET['to'] ) ) {
153
-				$date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
154
-			}
152
+            if ( isset( $_GET['to'] ) ) {
153
+                $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
154
+            }
155 155
 }
156 156
 
157 157
         $i18n = array(
158 158
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
159 159
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
160
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
161
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
162
-			'rest_root'                 => esc_url_raw( rest_url() ),
163
-			'date_range'                => $date_range,
160
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
161
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
162
+            'rest_root'                 => esc_url_raw( rest_url() ),
163
+            'date_range'                => $date_range,
164 164
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
165 165
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
166 166
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
167 167
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
168 168
             'tax'                       => wpinv_tax_amount(),
169 169
             'discount'                  => 0,
170
-			'currency_symbol'           => wpinv_currency_symbol(),
171
-			'currency'                  => wpinv_get_currency(),
170
+            'currency_symbol'           => wpinv_currency_symbol(),
171
+            'currency'                  => wpinv_get_currency(),
172 172
             'currency_pos'              => wpinv_currency_position(),
173 173
             'thousand_sep'              => wpinv_thousands_separator(),
174 174
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -188,118 +188,118 @@  discard block
 block discarded – undo
188 188
             'item_description'          => __( 'Item Description', 'invoicing' ),
189 189
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
190 190
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
191
-			'searching'                 => __( 'Searching', 'invoicing' ),
192
-			'loading'                   => __( 'Loading...', 'invoicing' ),
193
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
194
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
195
-			'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
191
+            'searching'                 => __( 'Searching', 'invoicing' ),
192
+            'loading'                   => __( 'Loading...', 'invoicing' ),
193
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
194
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
195
+            'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
196 196
         );
197 197
 
198
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
198
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
199 199
 
200
-			$invoice              = new WPInv_Invoice( $post );
201
-			$i18n['save_invoice'] = sprintf(
202
-				__( 'Save %s', 'invoicing' ),
203
-				ucfirst( $invoice->get_invoice_quote_type() )
204
-			);
200
+            $invoice              = new WPInv_Invoice( $post );
201
+            $i18n['save_invoice'] = sprintf(
202
+                __( 'Save %s', 'invoicing' ),
203
+                ucfirst( $invoice->get_invoice_quote_type() )
204
+            );
205 205
 
206
-			$i18n['invoice_description'] = sprintf(
207
-				__( '%s Description', 'invoicing' ),
208
-				ucfirst( $invoice->get_invoice_quote_type() )
209
-			);
206
+            $i18n['invoice_description'] = sprintf(
207
+                __( '%s Description', 'invoicing' ),
208
+                ucfirst( $invoice->get_invoice_quote_type() )
209
+            );
210 210
 
211
-		}
212
-		return $i18n;
213
-	}
211
+        }
212
+        return $i18n;
213
+    }
214 214
 
215
-	/**
216
-	 * Change the admin footer text on GetPaid admin pages.
217
-	 *
218
-	 * @since  2.0.0
219
-	 * @param  string $footer_text
220
-	 * @return string
221
-	 */
222
-	public function admin_footer_text( $footer_text ) {
223
-		global $current_screen;
215
+    /**
216
+     * Change the admin footer text on GetPaid admin pages.
217
+     *
218
+     * @since  2.0.0
219
+     * @param  string $footer_text
220
+     * @return string
221
+     */
222
+    public function admin_footer_text( $footer_text ) {
223
+        global $current_screen;
224 224
 
225
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
225
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
226 226
 
227 227
         if ( ! empty( $current_screen->post_type ) ) {
228
-			$page = $current_screen->post_type;
228
+            $page = $current_screen->post_type;
229 229
         }
230 230
 
231 231
         // General styles.
232 232
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
233 233
 
234
-			// Change the footer text
235
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
234
+            // Change the footer text
235
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
236 236
 
237
-				$rating_url  = esc_url(
238
-					wp_nonce_url(
239
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
240
-						'getpaid-nonce',
241
-						'getpaid-nonce'
237
+                $rating_url  = esc_url(
238
+                    wp_nonce_url(
239
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
240
+                        'getpaid-nonce',
241
+                        'getpaid-nonce'
242 242
                     )
243
-				);
243
+                );
244 244
 
245
-				$footer_text = sprintf(
246
-					/* translators: %s: five stars */
247
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
248
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
249
-				);
245
+                $footer_text = sprintf(
246
+                    /* translators: %s: five stars */
247
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
248
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
249
+                );
250 250
 
251
-			} else {
251
+            } else {
252 252
 
253
-				$footer_text = sprintf(
254
-					/* translators: %s: GetPaid */
255
-					__( 'Thank you for using %s!', 'invoicing' ),
256
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
257
-				);
253
+                $footer_text = sprintf(
254
+                    /* translators: %s: GetPaid */
255
+                    __( 'Thank you for using %s!', 'invoicing' ),
256
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
257
+                );
258 258
 
259
-			}
259
+            }
260 260
 }
261 261
 
262
-		return $footer_text;
263
-	}
264
-
265
-	/**
266
-	 * Redirects to wp.org to rate the plugin.
267
-	 *
268
-	 * @since  2.0.0
269
-	 */
270
-	public function redirect_to_wordpress_rating_page() {
271
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
272
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
273
-		exit;
274
-	}
275
-
276
-    /**
277
-	 * Loads payment form js.
278
-	 *
279
-	 */
280
-	protected function load_payment_form_scripts() {
262
+        return $footer_text;
263
+    }
264
+
265
+    /**
266
+     * Redirects to wp.org to rate the plugin.
267
+     *
268
+     * @since  2.0.0
269
+     */
270
+    public function redirect_to_wordpress_rating_page() {
271
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
272
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
273
+        exit;
274
+    }
275
+
276
+    /**
277
+     * Loads payment form js.
278
+     *
279
+     */
280
+    protected function load_payment_form_scripts() {
281 281
         global $post;
282 282
 
283 283
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
284
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
285
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
284
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
285
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
286 286
 
287
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
288
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
287
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
288
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
289 289
 
290
-		wp_localize_script(
290
+        wp_localize_script(
291 291
             'wpinv-admin-payment-form-script',
292 292
             'wpinvPaymentFormAdmin',
293 293
             array(
294
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
295
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
296
-				'currency'      => wpinv_currency_symbol(),
297
-				'position'      => wpinv_currency_position(),
298
-				'decimals'      => (int) wpinv_decimals(),
299
-				'thousands_sep' => wpinv_thousands_separator(),
300
-				'decimals_sep'  => wpinv_decimal_separator(),
301
-				'form_items'    => gepaid_get_form_items( $post->ID ),
302
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
294
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
295
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
296
+                'currency'      => wpinv_currency_symbol(),
297
+                'position'      => wpinv_currency_position(),
298
+                'decimals'      => (int) wpinv_decimals(),
299
+                'thousands_sep' => wpinv_thousands_separator(),
300
+                'decimals_sep'  => wpinv_decimal_separator(),
301
+                'form_items'    => gepaid_get_form_items( $post->ID ),
302
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
303 303
             )
304 304
         );
305 305
 
@@ -308,19 +308,19 @@  discard block
 block discarded – undo
308 308
     }
309 309
 
310 310
     /**
311
-	 * Add our classes to admin pages.
311
+     * Add our classes to admin pages.
312 312
      *
313 313
      * @param string $classes
314 314
      * @return string
315
-	 *
316
-	 */
315
+     *
316
+     */
317 317
     public function admin_body_class( $classes ) {
318
-		global $pagenow, $post, $current_screen;
318
+        global $pagenow, $post, $current_screen;
319 319
 
320 320
         $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
321 321
 
322 322
         if ( ! empty( $current_screen->post_type ) ) {
323
-			$page = $current_screen->post_type;
323
+            $page = $current_screen->post_type;
324 324
         }
325 325
 
326 326
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -329,70 +329,70 @@  discard block
 block discarded – undo
329 329
 
330 330
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
331 331
             $classes .= ' wpinv-cpt wpinv';
332
-		}
332
+        }
333 333
 
334
-		if ( getpaid_is_invoice_post_type( $page ) ) {
334
+        if ( getpaid_is_invoice_post_type( $page ) ) {
335 335
             $classes .= ' getpaid-is-invoice-cpt';
336 336
         }
337 337
 
338
-		return $classes;
338
+        return $classes;
339 339
     }
340 340
 
341 341
     /**
342
-	 * Maybe show the AyeCode Connect Notice.
343
-	 */
344
-	public function init_ayecode_connect_helper() {
342
+     * Maybe show the AyeCode Connect Notice.
343
+     */
344
+    public function init_ayecode_connect_helper() {
345 345
 
346
-		// Register with the deactivation survey class.
347
-		AyeCode_Deactivation_Survey::instance(
346
+        // Register with the deactivation survey class.
347
+        AyeCode_Deactivation_Survey::instance(
348 348
             array(
349
-				'slug'              => 'invoicing',
350
-				'version'           => WPINV_VERSION,
351
-				'support_url'       => 'https://wpgetpaid.com/support/',
352
-				'documentation_url' => 'https://docs.wpgetpaid.com/',
353
-				'activated'         => (int) get_option( 'gepaid_installed_on' ),
349
+                'slug'              => 'invoicing',
350
+                'version'           => WPINV_VERSION,
351
+                'support_url'       => 'https://wpgetpaid.com/support/',
352
+                'documentation_url' => 'https://docs.wpgetpaid.com/',
353
+                'activated'         => (int) get_option( 'gepaid_installed_on' ),
354 354
             )
355 355
         );
356 356
 
357 357
         new AyeCode_Connect_Helper(
358 358
             array(
359
-				'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
360
-				'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
361
-				'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
362
-				'connect_button'    => __( 'Connect Site', 'invoicing' ),
363
-				'connecting_button' => __( 'Connecting...', 'invoicing' ),
364
-				'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
365
-				'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
359
+                'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
360
+                'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
361
+                'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
362
+                'connect_button'    => __( 'Connect Site', 'invoicing' ),
363
+                'connecting_button' => __( 'Connecting...', 'invoicing' ),
364
+                'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
365
+                'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
366 366
             ),
367 367
             array( 'wpi-addons' )
368 368
         );
369 369
 
370 370
     }
371 371
 
372
-	/**
373
-	 * Redirect users to settings on activation.
374
-	 *
375
-	 * @return void
376
-	 */
377
-	public function activation_redirect() {
372
+    /**
373
+     * Redirect users to settings on activation.
374
+     *
375
+     * @return void
376
+     */
377
+    public function activation_redirect() {
378 378
 
379
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
379
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
380 380
 
381
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
382
-			return;
383
-		}
381
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
382
+            return;
383
+        }
384 384
 
385
-		// Bail if activating from network, or bulk
386
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
387
-			return;
388
-		}
385
+        // Bail if activating from network, or bulk
386
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
387
+            return;
388
+        }
389 389
 
390
-	    update_option( 'wpinv_redirected_to_settings', 1 );
390
+        update_option( 'wpinv_redirected_to_settings', 1 );
391 391
 
392 392
         wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
393 393
         exit;
394 394
 
395
-	}
395
+    }
396 396
 
397 397
     /**
398 398
      * Fires an admin action after verifying that a user can fire them.
@@ -405,555 +405,555 @@  discard block
 block discarded – undo
405 405
         }
406 406
     }
407 407
 
408
-	/**
408
+    /**
409 409
      * Duplicate invoice.
410
-	 *
411
-	 * @param array $args
410
+     *
411
+     * @param array $args
412 412
      */
413 413
     public function duplicate_invoice( $args ) {
414 414
 
415
-		if ( empty( $args['invoice_id'] ) ) {
416
-			return;
417
-		}
415
+        if ( empty( $args['invoice_id'] ) ) {
416
+            return;
417
+        }
418 418
 
419
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
419
+        $invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
420 420
 
421
-		if ( ! $invoice->exists() ) {
422
-			return;
423
-		}
421
+        if ( ! $invoice->exists() ) {
422
+            return;
423
+        }
424 424
 
425
-		$new_invoice = getpaid_duplicate_invoice( $invoice );
426
-		$new_invoice->save();
425
+        $new_invoice = getpaid_duplicate_invoice( $invoice );
426
+        $new_invoice->save();
427 427
 
428
-		if ( $new_invoice->exists() ) {
428
+        if ( $new_invoice->exists() ) {
429 429
 
430
-			getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) );
430
+            getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) );
431 431
 
432
-			wp_safe_redirect(
433
-				add_query_arg(
434
-					array(
435
-						'action' => 'edit',
436
-						'post'   => $new_invoice->get_id(),
437
-					),
438
-					admin_url( 'post.php' )
439
-				)
440
-			);
441
-			exit;
432
+            wp_safe_redirect(
433
+                add_query_arg(
434
+                    array(
435
+                        'action' => 'edit',
436
+                        'post'   => $new_invoice->get_id(),
437
+                    ),
438
+                    admin_url( 'post.php' )
439
+                )
440
+            );
441
+            exit;
442 442
 
443
-		}
443
+        }
444 444
 
445
-		getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) );
445
+        getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) );
446 446
 
447
-	}
447
+    }
448 448
 
449
-	/**
449
+    /**
450 450
      * Refund an invoice.
451
-	 *
452
-	 * @param array $args
451
+     *
452
+     * @param array $args
453 453
      */
454 454
     public function refund_invoice( $args ) {
455 455
 
456
-		if ( empty( $args['invoice_id'] ) ) {
457
-			return;
458
-		}
459
-
460
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
461
-
462
-		if ( ! $invoice->exists() || $invoice->is_refunded() ) {
463
-			return;
464
-		}
465
-
466
-		$invoice->refund();
467
-
468
-		// Refund remotely.
469
-		if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) {
470
-			do_action( 'getpaid_refund_invoice_remotely', $invoice );
471
-		}
472
-
473
-		// Cancel subscriptions.
474
-		if ( ! empty( $args['getpaid_cancel_subscription'] ) ) {
475
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
476
-
477
-			if ( ! empty( $subscriptions ) ) {
478
-				if ( ! is_array( $subscriptions ) ) {
479
-					$subscriptions = array( $subscriptions );
480
-				}
481
-
482
-				foreach ( $subscriptions as $subscription ) {
483
-					$subscription->cancel();
484
-					$invoice->add_system_note(
485
-						sprintf(
486
-							// translators: %s: subscription ID.
487
-							__( 'Subscription #%s cancelled', 'invoicing' ),
488
-							$subscription->get_id()
489
-						)
490
-					);
491
-				}
492
-			}
493
-		}
494
-
495
-		// Add notice.
496
-		$this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) );
497
-
498
-		// Redirect.
499
-		wp_safe_redirect(
500
-			remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) )
501
-		);
502
-	}
503
-
504
-	/**
456
+        if ( empty( $args['invoice_id'] ) ) {
457
+            return;
458
+        }
459
+
460
+        $invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
461
+
462
+        if ( ! $invoice->exists() || $invoice->is_refunded() ) {
463
+            return;
464
+        }
465
+
466
+        $invoice->refund();
467
+
468
+        // Refund remotely.
469
+        if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) {
470
+            do_action( 'getpaid_refund_invoice_remotely', $invoice );
471
+        }
472
+
473
+        // Cancel subscriptions.
474
+        if ( ! empty( $args['getpaid_cancel_subscription'] ) ) {
475
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
476
+
477
+            if ( ! empty( $subscriptions ) ) {
478
+                if ( ! is_array( $subscriptions ) ) {
479
+                    $subscriptions = array( $subscriptions );
480
+                }
481
+
482
+                foreach ( $subscriptions as $subscription ) {
483
+                    $subscription->cancel();
484
+                    $invoice->add_system_note(
485
+                        sprintf(
486
+                            // translators: %s: subscription ID.
487
+                            __( 'Subscription #%s cancelled', 'invoicing' ),
488
+                            $subscription->get_id()
489
+                        )
490
+                    );
491
+                }
492
+            }
493
+        }
494
+
495
+        // Add notice.
496
+        $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) );
497
+
498
+        // Redirect.
499
+        wp_safe_redirect(
500
+            remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) )
501
+        );
502
+    }
503
+
504
+    /**
505 505
      * Sends a payment reminder to a customer.
506
-	 *
507
-	 * @param array $args
506
+     *
507
+     * @param array $args
508 508
      */
509 509
     public function duplicate_payment_form( $args ) {
510 510
 
511
-		if ( empty( $args['form_id'] ) ) {
512
-			return;
513
-		}
514
-
515
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
511
+        if ( empty( $args['form_id'] ) ) {
512
+            return;
513
+        }
516 514
 
517
-		if ( ! $form->exists() ) {
518
-			return;
519
-		}
515
+        $form = new GetPaid_Payment_Form( (int) $args['form_id'] );
520 516
 
521
-		$new_form = new GetPaid_Payment_Form();
522
-		$new_form->set_author( $form->get_author( 'edit' ) );
523
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
524
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
525
-		$new_form->set_items( $form->get_items( 'edit' ) );
526
-		$new_form->save();
517
+        if ( ! $form->exists() ) {
518
+            return;
519
+        }
527 520
 
528
-		if ( $new_form->exists() ) {
529
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
530
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
531
-		} else {
532
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
533
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
534
-		}
521
+        $new_form = new GetPaid_Payment_Form();
522
+        $new_form->set_author( $form->get_author( 'edit' ) );
523
+        $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
524
+        $new_form->set_elements( $form->get_elements( 'edit' ) );
525
+        $new_form->set_items( $form->get_items( 'edit' ) );
526
+        $new_form->save();
527
+
528
+        if ( $new_form->exists() ) {
529
+            $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
530
+            $url = get_edit_post_link( $new_form->get_id(), 'edit' );
531
+        } else {
532
+            $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
533
+            $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
534
+        }
535 535
 
536
-		wp_redirect( $url );
537
-		exit;
538
-	}
536
+        wp_redirect( $url );
537
+        exit;
538
+    }
539 539
 
540
-	/**
540
+    /**
541 541
      * Resets form stats.
542
-	 *
543
-	 * @param array $args
542
+     *
543
+     * @param array $args
544 544
      */
545 545
     public function reset_form_stats( $args ) {
546 546
 
547
-		if ( empty( $args['form_id'] ) ) {
548
-			return;
549
-		}
547
+        if ( empty( $args['form_id'] ) ) {
548
+            return;
549
+        }
550 550
 
551
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
551
+        $form = new GetPaid_Payment_Form( (int) $args['form_id'] );
552 552
 
553
-		if ( ! $form->exists() ) {
554
-			return;
555
-		}
553
+        if ( ! $form->exists() ) {
554
+            return;
555
+        }
556 556
 
557
-		$form->set_earned( 0 );
558
-		$form->set_refunded( 0 );
559
-		$form->set_cancelled( 0 );
560
-		$form->set_failed( 0 );
561
-		$form->save();
557
+        $form->set_earned( 0 );
558
+        $form->set_refunded( 0 );
559
+        $form->set_cancelled( 0 );
560
+        $form->set_failed( 0 );
561
+        $form->save();
562 562
 
563
-		$this->show_success( __( 'Form stats reset successfully', 'invoicing' ) );
563
+        $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) );
564 564
 
565
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) );
566
-		exit;
567
-	}
565
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) );
566
+        exit;
567
+    }
568 568
 
569
-	/**
569
+    /**
570 570
      * Sends a payment reminder to a customer.
571
-	 *
572
-	 * @param array $args
571
+     *
572
+     * @param array $args
573 573
      */
574 574
     public function send_customer_invoice( $args ) {
575
-		getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
576
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
577
-		exit;
578
-	}
575
+        getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
576
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
577
+        exit;
578
+    }
579 579
 
580
-	/**
580
+    /**
581 581
      * Sends a payment reminder to a customer.
582
-	 *
583
-	 * @param array $args
582
+     *
583
+     * @param array $args
584 584
      */
585 585
     public function send_customer_payment_reminder( $args ) {
586
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
586
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
587 587
 
588
-		if ( $sent ) {
589
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
590
-		} else {
591
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
592
-		}
588
+        if ( $sent ) {
589
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
590
+        } else {
591
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
592
+        }
593 593
 
594
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
595
-		exit;
596
-	}
594
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
595
+        exit;
596
+    }
597 597
 
598
-	/**
598
+    /**
599 599
      * Resets tax rates.
600
-	 *
600
+     *
601 601
      */
602 602
     public function admin_reset_tax_rates() {
603 603
 
604
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
605
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
606
-		exit;
604
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
605
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
606
+        exit;
607 607
 
608
-	}
608
+    }
609 609
 
610
-	/**
610
+    /**
611 611
      * Resets admin pages.
612
-	 *
612
+     *
613 613
      */
614 614
     public function admin_create_missing_pages() {
615
-		$installer = new GetPaid_Installer();
616
-		$installer->create_pages();
617
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
618
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
619
-		exit;
620
-	}
621
-
622
-	/**
623
-	 * Refreshes the permalinks.
624
-	 */
625
-	public function admin_refresh_permalinks() {
626
-		flush_rewrite_rules();
627
-		$this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
628
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
629
-		exit;
630
-	}
631
-
632
-	/**
615
+        $installer = new GetPaid_Installer();
616
+        $installer->create_pages();
617
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
618
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
619
+        exit;
620
+    }
621
+
622
+    /**
623
+     * Refreshes the permalinks.
624
+     */
625
+    public function admin_refresh_permalinks() {
626
+        flush_rewrite_rules();
627
+        $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
628
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
629
+        exit;
630
+    }
631
+
632
+    /**
633 633
      * Creates missing admin tables.
634
-	 *
634
+     *
635 635
      */
636 636
     public function admin_create_missing_tables() {
637
-		global $wpdb;
637
+        global $wpdb;
638 638
 
639
-		GetPaid_Installer::create_db_tables();
640
-		GetPaid_Installer::migrate_old_customers();
639
+        GetPaid_Installer::create_db_tables();
640
+        GetPaid_Installer::migrate_old_customers();
641 641
 
642
-		if ( '' !== $wpdb->last_error ) {
643
-			$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
644
-		} else {
645
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
646
-		}
642
+        if ( '' !== $wpdb->last_error ) {
643
+            $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
644
+        } else {
645
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
646
+        }
647 647
 
648
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
649
-		exit;
650
-	}
648
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
649
+        exit;
650
+    }
651 651
 
652
-	/**
652
+    /**
653 653
      * Migrates old invoices to the new database tables.
654
-	 *
654
+     *
655 655
      */
656 656
     public function admin_migrate_old_invoices() {
657 657
 
658
-		// Migrate the invoices.
659
-		$installer = new GetPaid_Installer();
660
-		$installer->migrate_old_invoices();
658
+        // Migrate the invoices.
659
+        $installer = new GetPaid_Installer();
660
+        $installer->migrate_old_invoices();
661 661
 
662
-		// Show an admin message.
663
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
662
+        // Show an admin message.
663
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
664 664
 
665
-		// Redirect the admin.
666
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
667
-		exit;
665
+        // Redirect the admin.
666
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
667
+        exit;
668 668
 
669
-	}
669
+    }
670 670
 
671
-	/**
671
+    /**
672 672
      * Download customers.
673
-	 *
673
+     *
674 674
      */
675 675
     public function admin_download_customers() {
676 676
 
677
-		$output = fopen( 'php://output', 'w' );
677
+        $output = fopen( 'php://output', 'w' );
678 678
 
679
-		if ( false === $output ) {
680
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
681
-		}
679
+        if ( false === $output ) {
680
+            wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
681
+        }
682 682
 
683
-		header( 'Content-Type:text/csv' );
684
-		header( 'Content-Disposition:attachment;filename=customers.csv' );
683
+        header( 'Content-Type:text/csv' );
684
+        header( 'Content-Disposition:attachment;filename=customers.csv' );
685 685
 
686
-		/** @var GetPaid_Customer[] $customers */
687
-		$customers = getpaid_get_customers( array( 'number' => -1 ) );
688
-		$columns   = array_keys( GetPaid_Customer_Data_Store::get_database_fields() );
686
+        /** @var GetPaid_Customer[] $customers */
687
+        $customers = getpaid_get_customers( array( 'number' => -1 ) );
688
+        $columns   = array_keys( GetPaid_Customer_Data_Store::get_database_fields() );
689 689
 
690
-		// Output the csv column headers.
691
-		fputcsv( $output, $columns );
690
+        // Output the csv column headers.
691
+        fputcsv( $output, $columns );
692 692
 
693
-		// Loop through
694
-		foreach ( $customers as $customer ) {
693
+        // Loop through
694
+        foreach ( $customers as $customer ) {
695 695
 
696
-			$row  = array();
696
+            $row  = array();
697 697
 
698
-			foreach ( $columns as $column ) {
699
-				$row[]  = (string) maybe_serialize( $customer->get( $column, 'edit' ) );
700
-			}
698
+            foreach ( $columns as $column ) {
699
+                $row[]  = (string) maybe_serialize( $customer->get( $column, 'edit' ) );
700
+            }
701 701
 
702
-			fputcsv( $output, $row );
703
-		}
702
+            fputcsv( $output, $row );
703
+        }
704 704
 
705
-		fclose( $output );
706
-		exit;
705
+        fclose( $output );
706
+        exit;
707 707
 
708
-	}
708
+    }
709 709
 
710
-	/**
710
+    /**
711 711
      * Installs a plugin.
712
-	 *
713
-	 * @param array $data
712
+     *
713
+     * @param array $data
714 714
      */
715 715
     public function admin_install_plugin( $data ) {
716 716
 
717
-		if ( ! empty( $data['plugins'] ) ) {
718
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
719
-			wp_cache_flush();
717
+        if ( ! empty( $data['plugins'] ) ) {
718
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
719
+            wp_cache_flush();
720 720
 
721
-			foreach ( $data['plugins'] as $slug => $file ) {
722
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
723
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
724
-				$installed  = $upgrader->install( $plugin_zip );
721
+            foreach ( $data['plugins'] as $slug => $file ) {
722
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
723
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
724
+                $installed  = $upgrader->install( $plugin_zip );
725 725
 
726
-				if ( ! is_wp_error( $installed ) && $installed ) {
727
-					activate_plugin( $file, '', false, true );
728
-				} else {
729
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
730
-				}
726
+                if ( ! is_wp_error( $installed ) && $installed ) {
727
+                    activate_plugin( $file, '', false, true );
728
+                } else {
729
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
730
+                }
731 731
 }
732 732
 }
733 733
 
734
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
735
-		wp_safe_redirect( $redirect );
736
-		exit;
734
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
735
+        wp_safe_redirect( $redirect );
736
+        exit;
737 737
 
738
-	}
738
+    }
739 739
 
740
-	/**
740
+    /**
741 741
      * Connects a gateway.
742
-	 *
743
-	 * @param array $data
742
+     *
743
+     * @param array $data
744 744
      */
745 745
     public function admin_connect_gateway( $data ) {
746 746
 
747
-		if ( ! empty( $data['plugin'] ) ) {
747
+        if ( ! empty( $data['plugin'] ) ) {
748 748
 
749
-			$gateway     = sanitize_key( $data['plugin'] );
750
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
749
+            $gateway     = sanitize_key( $data['plugin'] );
750
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
751 751
 
752
-			if ( ! empty( $connect_url ) ) {
753
-				wp_redirect( $connect_url );
754
-				exit;
755
-			}
752
+            if ( ! empty( $connect_url ) ) {
753
+                wp_redirect( $connect_url );
754
+                exit;
755
+            }
756 756
 
757
-			if ( 'stripe' == $data['plugin'] ) {
758
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
759
-				include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
760
-				wp_cache_flush();
757
+            if ( 'stripe' == $data['plugin'] ) {
758
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
759
+                include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
760
+                wp_cache_flush();
761 761
 
762
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
763
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
764
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
765
-					$upgrader->install( $plugin_zip );
766
-				}
762
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
763
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
764
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
765
+                    $upgrader->install( $plugin_zip );
766
+                }
767 767
 
768
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
769
-			}
768
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
769
+            }
770 770
 
771
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
772
-			if ( ! empty( $connect_url ) ) {
773
-				wp_redirect( $connect_url );
774
-				exit;
775
-			}
771
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
772
+            if ( ! empty( $connect_url ) ) {
773
+                wp_redirect( $connect_url );
774
+                exit;
775
+            }
776 776
 }
777 777
 
778
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
779
-		wp_safe_redirect( $redirect );
780
-		exit;
778
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
779
+        wp_safe_redirect( $redirect );
780
+        exit;
781 781
 
782
-	}
782
+    }
783 783
 
784
-	/**
784
+    /**
785 785
      * Recalculates discounts.
786
-	 *
786
+     *
787 787
      */
788 788
     public function admin_recalculate_discounts() {
789
-		global $wpdb;
789
+        global $wpdb;
790 790
 
791
-		// Fetch all invoices that have discount codes.
792
-		$table    = $wpdb->prefix . 'getpaid_invoices';
793
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
791
+        // Fetch all invoices that have discount codes.
792
+        $table    = $wpdb->prefix . 'getpaid_invoices';
793
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
794 794
 
795
-		foreach ( $invoices as $invoice ) {
795
+        foreach ( $invoices as $invoice ) {
796 796
 
797
-			$invoice = new WPInv_Invoice( $invoice );
797
+            $invoice = new WPInv_Invoice( $invoice );
798 798
 
799
-			if ( ! $invoice->exists() ) {
800
-				continue;
801
-			}
799
+            if ( ! $invoice->exists() ) {
800
+                continue;
801
+            }
802 802
 
803
-			// Abort if the discount does not exist or does not apply here.
804
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
805
-			if ( ! $discount->exists() ) {
806
-				continue;
807
-			}
803
+            // Abort if the discount does not exist or does not apply here.
804
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
805
+            if ( ! $discount->exists() ) {
806
+                continue;
807
+            }
808 808
 
809
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
810
-			$invoice->recalculate_total();
809
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
810
+            $invoice->recalculate_total();
811 811
 
812
-			if ( $invoice->get_total_discount() > 0 ) {
813
-				$invoice->save();
814
-			}
812
+            if ( $invoice->get_total_discount() > 0 ) {
813
+                $invoice->save();
814
+            }
815 815
 }
816 816
 
817
-		// Show an admin message.
818
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
817
+        // Show an admin message.
818
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
819 819
 
820
-		// Redirect the admin.
821
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
822
-		exit;
820
+        // Redirect the admin.
821
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
822
+        exit;
823 823
 
824
-	}
824
+    }
825 825
 
826 826
     /**
827
-	 * Returns an array of admin notices.
828
-	 *
829
-	 * @since       1.0.19
827
+     * Returns an array of admin notices.
828
+     *
829
+     * @since       1.0.19
830 830
      * @return array
831
-	 */
832
-	public function get_notices() {
833
-		$notices = get_option( 'wpinv_admin_notices' );
831
+     */
832
+    public function get_notices() {
833
+        $notices = get_option( 'wpinv_admin_notices' );
834 834
         return is_array( $notices ) ? $notices : array();
835
-	}
835
+    }
836 836
 
837
-	/**
838
-	 * Checks if we have any admin notices.
839
-	 *
840
-	 * @since       2.0.4
837
+    /**
838
+     * Checks if we have any admin notices.
839
+     *
840
+     * @since       2.0.4
841 841
      * @return array
842
-	 */
843
-	public function has_notices() {
844
-		return count( $this->get_notices() ) > 0;
845
-	}
846
-
847
-	/**
848
-	 * Clears all admin notices
849
-	 *
850
-	 * @access      public
851
-	 * @since       1.0.19
852
-	 */
853
-	public function clear_notices() {
854
-		delete_option( 'wpinv_admin_notices' );
855
-	}
856
-
857
-	/**
858
-	 * Saves a new admin notice
859
-	 *
860
-	 * @access      public
861
-	 * @since       1.0.19
862
-	 */
863
-	public function save_notice( $type, $message ) {
864
-		$notices = $this->get_notices();
865
-
866
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
867
-			$notices[ $type ] = array();
868
-		}
869
-
870
-		$notices[ $type ][] = $message;
871
-
872
-		update_option( 'wpinv_admin_notices', $notices );
873
-	}
874
-
875
-	/**
876
-	 * Displays a success notice
877
-	 *
878
-	 * @param       string $msg The message to qeue.
879
-	 * @access      public
880
-	 * @since       1.0.19
881
-	 */
882
-	public function show_success( $msg ) {
883
-		$this->save_notice( 'success', $msg );
884
-	}
885
-
886
-	/**
887
-	 * Displays a error notice
888
-	 *
889
-	 * @access      public
890
-	 * @param       string $msg The message to qeue.
891
-	 * @since       1.0.19
892
-	 */
893
-	public function show_error( $msg ) {
894
-		$this->save_notice( 'error', $msg );
895
-	}
896
-
897
-	/**
898
-	 * Displays a warning notice
899
-	 *
900
-	 * @access      public
901
-	 * @param       string $msg The message to qeue.
902
-	 * @since       1.0.19
903
-	 */
904
-	public function show_warning( $msg ) {
905
-		$this->save_notice( 'warning', $msg );
906
-	}
907
-
908
-	/**
909
-	 * Displays a info notice
910
-	 *
911
-	 * @access      public
912
-	 * @param       string $msg The message to qeue.
913
-	 * @since       1.0.19
914
-	 */
915
-	public function show_info( $msg ) {
916
-		$this->save_notice( 'info', $msg );
917
-	}
918
-
919
-	/**
920
-	 * Show notices
921
-	 *
922
-	 * @access      public
923
-	 * @since       1.0.19
924
-	 */
925
-	public function show_notices() {
842
+     */
843
+    public function has_notices() {
844
+        return count( $this->get_notices() ) > 0;
845
+    }
846
+
847
+    /**
848
+     * Clears all admin notices
849
+     *
850
+     * @access      public
851
+     * @since       1.0.19
852
+     */
853
+    public function clear_notices() {
854
+        delete_option( 'wpinv_admin_notices' );
855
+    }
856
+
857
+    /**
858
+     * Saves a new admin notice
859
+     *
860
+     * @access      public
861
+     * @since       1.0.19
862
+     */
863
+    public function save_notice( $type, $message ) {
864
+        $notices = $this->get_notices();
865
+
866
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
867
+            $notices[ $type ] = array();
868
+        }
869
+
870
+        $notices[ $type ][] = $message;
871
+
872
+        update_option( 'wpinv_admin_notices', $notices );
873
+    }
874
+
875
+    /**
876
+     * Displays a success notice
877
+     *
878
+     * @param       string $msg The message to qeue.
879
+     * @access      public
880
+     * @since       1.0.19
881
+     */
882
+    public function show_success( $msg ) {
883
+        $this->save_notice( 'success', $msg );
884
+    }
885
+
886
+    /**
887
+     * Displays a error notice
888
+     *
889
+     * @access      public
890
+     * @param       string $msg The message to qeue.
891
+     * @since       1.0.19
892
+     */
893
+    public function show_error( $msg ) {
894
+        $this->save_notice( 'error', $msg );
895
+    }
896
+
897
+    /**
898
+     * Displays a warning notice
899
+     *
900
+     * @access      public
901
+     * @param       string $msg The message to qeue.
902
+     * @since       1.0.19
903
+     */
904
+    public function show_warning( $msg ) {
905
+        $this->save_notice( 'warning', $msg );
906
+    }
907
+
908
+    /**
909
+     * Displays a info notice
910
+     *
911
+     * @access      public
912
+     * @param       string $msg The message to qeue.
913
+     * @since       1.0.19
914
+     */
915
+    public function show_info( $msg ) {
916
+        $this->save_notice( 'info', $msg );
917
+    }
918
+
919
+    /**
920
+     * Show notices
921
+     *
922
+     * @access      public
923
+     * @since       1.0.19
924
+     */
925
+    public function show_notices() {
926 926
 
927 927
         $notices = $this->get_notices();
928 928
         $this->clear_notices();
929 929
 
930
-		foreach ( $notices as $type => $messages ) {
930
+        foreach ( $notices as $type => $messages ) {
931 931
 
932
-			if ( ! is_array( $messages ) ) {
933
-				continue;
934
-			}
932
+            if ( ! is_array( $messages ) ) {
933
+                continue;
934
+            }
935 935
 
936 936
             $type  = esc_attr( $type );
937
-			foreach ( $messages as $message ) {
938
-				echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
937
+            foreach ( $messages as $message ) {
938
+                echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
939 939
             }
940 940
 }
941 941
 
942
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
943
-
944
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
945
-				$url     = wp_nonce_url(
946
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
947
-					'getpaid-nonce',
948
-					'getpaid-nonce'
949
-				);
950
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
951
-				$message2 = __( 'Generate Pages', 'invoicing' );
952
-				echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
953
-				break;
954
-			}
942
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
943
+
944
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
945
+                $url     = wp_nonce_url(
946
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
947
+                    'getpaid-nonce',
948
+                    'getpaid-nonce'
949
+                );
950
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
951
+                $message2 = __( 'Generate Pages', 'invoicing' );
952
+                echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
953
+                break;
954
+            }
955 955
 }
956 956
 
957
-	}
957
+    }
958 958
 
959 959
 }
Please login to merge, or discard this patch.
invoicing.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.8.1' );
26
+    define( 'WPINV_VERSION', '2.8.1' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
  * Bail if we are not in WP.
8 8
  */
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit;
10
+    exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16 16
 add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
18
-	$this_version = "0.2.1";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
22
-	}
17
+    global $ayecode_ui_version,$ayecode_ui_file_key;
18
+    $this_version = "0.2.1";
19
+    if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
+        $ayecode_ui_version = $this_version ;
21
+        $ayecode_ui_file_key = wp_hash( __FILE__ );
22
+    }
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28 28
 add_action('after_setup_theme', function () {
29
-	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
-	}
29
+    global $ayecode_ui_file_key;
30
+    if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
+        include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
+        include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
+    }
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39 39
 if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
42
-			return false;
43
-		}
44
-		return AUI::instance();
45
-	}
40
+    function aui(){
41
+        if(!class_exists("AUI",false)){
42
+            return false;
43
+        }
44
+        return AUI::instance();
45
+    }
46 46
 }
Please login to merge, or discard this patch.