Passed
Push — master ( b3b246...bcec86 )
by Brian
05:30
created
includes/class-wpinv.php 2 patches
Spacing   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * @param string $prop The prop to set.
64 64
 	 * @param mixed $value The value to retrieve.
65 65
 	 */
66
-	public function set( $prop, $value ) {
67
-		$this->data[ $prop ] = $value;
66
+	public function set($prop, $value) {
67
+		$this->data[$prop] = $value;
68 68
 	}
69 69
 
70 70
 	/**
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
 	 * @param string $prop The prop to set.
74 74
 	 * @return mixed The value.
75 75
 	 */
76
-	public function get( $prop ) {
76
+	public function get($prop) {
77 77
 
78
-		if ( isset( $this->data[ $prop ] ) ) {
79
-			return $this->data[ $prop ];
78
+		if (isset($this->data[$prop])) {
79
+			return $this->data[$prop];
80 80
 		}
81 81
 
82 82
 		return null;
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
 	public function set_properties() {
89 89
 
90 90
 		// Sessions.
91
-		$this->set( 'session', new WPInv_Session_Handler() );
92
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
91
+		$this->set('session', new WPInv_Session_Handler());
92
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
93 93
 		$this->tax              = new WPInv_EUVat();
94 94
 		$this->tax->init();
95 95
 		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
96 96
 
97 97
 		// Init other objects.
98
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
99
-		$this->set( 'session', new WPInv_Session_Handler() );
100
-		$this->set( 'notes', new WPInv_Notes() );
101
-		$this->set( 'api', new WPInv_API() );
102
-		$this->set( 'post_types', new GetPaid_Post_Types() );
103
-		$this->set( 'template', new GetPaid_Template() );
104
-		$this->set( 'admin', new GetPaid_Admin() );
105
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
106
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
107
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
108
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
109
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
98
+		$this->set('reports', new WPInv_Reports()); // TODO: Refactor.
99
+		$this->set('session', new WPInv_Session_Handler());
100
+		$this->set('notes', new WPInv_Notes());
101
+		$this->set('api', new WPInv_API());
102
+		$this->set('post_types', new GetPaid_Post_Types());
103
+		$this->set('template', new GetPaid_Template());
104
+		$this->set('admin', new GetPaid_Admin());
105
+		$this->set('subscriptions', new WPInv_Subscriptions());
106
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
107
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
108
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
109
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
110 110
 
111 111
 	}
112 112
 
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * Define plugin constants.
115 115
 	 */
116 116
 	public function define_constants() {
117
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
118
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
117
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
118
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
119 119
 		$this->version = WPINV_VERSION;
120 120
 	}
121 121
 
@@ -126,27 +126,27 @@  discard block
 block discarded – undo
126 126
 	 */
127 127
 	protected function init_hooks() {
128 128
 		/* Internationalize the text strings used. */
129
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
129
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
130 130
 
131 131
 		// Init the plugin after WordPress inits.
132
-		add_action( 'init', array( $this, 'init' ), 1 );
133
-		add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
134
-		add_action( 'init', array( &$this, 'wpinv_actions' ) );
135
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
132
+		add_action('init', array($this, 'init'), 1);
133
+		add_action('getpaid_init', array($this, 'maybe_process_ipn'), 5);
134
+		add_action('init', array(&$this, 'wpinv_actions'));
135
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
136 136
 
137
-		if ( class_exists( 'BuddyPress' ) ) {
138
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
137
+		if (class_exists('BuddyPress')) {
138
+			add_action('bp_include', array(&$this, 'bp_invoicing_init'));
139 139
 		}
140 140
 
141
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
142
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
143
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
144
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
145
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
141
+		add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
142
+		add_action('wp_footer', array(&$this, 'wp_footer'));
143
+		add_action('widgets_init', array(&$this, 'register_widgets'));
144
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
145
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
146 146
 
147 147
 		// Fires after registering actions.
148
-		do_action( 'wpinv_actions', $this );
149
-		do_action( 'getpaid_actions', $this );
148
+		do_action('wpinv_actions', $this);
149
+		do_action('getpaid_actions', $this);
150 150
 
151 151
 	}
152 152
 
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 		/* Internationalize the text strings used. */
155 155
 		$this->load_textdomain();
156 156
 
157
-		do_action( 'wpinv_loaded' );
157
+		do_action('wpinv_loaded');
158 158
 
159 159
 		// Fix oxygen page builder conflict
160
-		if ( function_exists( 'ct_css_output' ) ) {
160
+		if (function_exists('ct_css_output')) {
161 161
 			wpinv_oxygen_fix_conflict();
162 162
 		}
163 163
 	}
@@ -167,21 +167,21 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @since 1.0
169 169
 	 */
170
-	public function load_textdomain( $locale = NULL ) {
171
-		if ( empty( $locale ) ) {
172
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
170
+	public function load_textdomain($locale = NULL) {
171
+		if (empty($locale)) {
172
+			$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
173 173
 		}
174 174
 
175
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
175
+		$locale = apply_filters('plugin_locale', $locale, 'invoicing');
176 176
 
177
-		unload_textdomain( 'invoicing' );
178
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
179
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
177
+		unload_textdomain('invoicing');
178
+		load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
179
+		load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
180 180
 
181 181
 		/**
182 182
 		 * Define language constants.
183 183
 		 */
184
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
184
+		require_once(WPINV_PLUGIN_DIR . 'language.php');
185 185
 	}
186 186
 
187 187
 	/**
@@ -190,90 +190,90 @@  discard block
 block discarded – undo
190 190
 	public function includes() {
191 191
 
192 192
 		// Start with the settings.
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
193
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
194 194
 
195 195
 		// Packages/libraries.
196
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
196
+		require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
197
+		require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
198 198
 
199 199
 		// Load functions.
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
206
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
207
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
208
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
209
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
210
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
211
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
212
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
200
+		require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php');
201
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
202
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
203
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
204
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
205
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
206
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
207
+		require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php');
208
+		require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php');
209
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
210
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
211
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
212
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
213
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
214
+		require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php');
215 215
 
216 216
 		// Register autoloader.
217 217
 		try {
218
-			spl_autoload_register( array( $this, 'autoload' ), true );
219
-		} catch ( Exception $e ) {
220
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
218
+			spl_autoload_register(array($this, 'autoload'), true);
219
+		} catch (Exception $e) {
220
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
221 221
 		}
222 222
 
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
235
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
236
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
237
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
238
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
239
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
240
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
241
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
242
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
243
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
223
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
224
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
225
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
226
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
227
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
228
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
229
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
230
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
231
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
232
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
233
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
234
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
235
+		require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
236
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
237
+		require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
238
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
239
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
240
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
241
+		require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
242
+		require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
243
+		require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
244 244
 
245 245
 		/**
246 246
 		 * Load the tax class.
247 247
 		 */
248
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
249
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
248
+		if (!class_exists('WPInv_EUVat')) {
249
+			require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
250 250
 		}
251 251
 
252
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
252
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
253 253
 			GetPaid_Post_Types_Admin::init();
254 254
 
255
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
256
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
257
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
258
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
259
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
260
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
261
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
262
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
255
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
256
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
257
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
258
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
259
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
260
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
261
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
262
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
263 263
 			// load the user class only on the users.php page
264 264
 			global $pagenow;
265
-			if($pagenow=='users.php'){
265
+			if ($pagenow == 'users.php') {
266 266
 				new WPInv_Admin_Users();
267 267
 			}
268 268
 		}
269 269
 
270 270
 		// Register cli commands
271
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
272
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
273
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
271
+		if (defined('WP_CLI') && WP_CLI) {
272
+			require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
273
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
274 274
 		}
275 275
 
276
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
276
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
277 277
 	}
278 278
 
279 279
 	/**
@@ -284,21 +284,21 @@  discard block
 block discarded – undo
284 284
 	 * @since       1.0.19
285 285
 	 * @return      void
286 286
 	 */
287
-	public function autoload( $class_name ) {
287
+	public function autoload($class_name) {
288 288
 
289 289
 		// Normalize the class name...
290
-		$class_name  = strtolower( $class_name );
290
+		$class_name = strtolower($class_name);
291 291
 
292 292
 		// ... and make sure it is our class.
293
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
293
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
294 294
 			return;
295 295
 		}
296 296
 
297 297
 		// Next, prepare the file name from the class.
298
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
298
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
299 299
 
300 300
 		// Base path of the classes.
301
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
301
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
302 302
 
303 303
 		// And an array of possible locations in order of importance.
304 304
 		$locations = array(
@@ -310,10 +310,10 @@  discard block
 block discarded – undo
310 310
 			"$plugin_path/includes/admin/meta-boxes",
311 311
 		);
312 312
 
313
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
313
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
314 314
 
315
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
316
-				include trailingslashit( $location ) . $file_name;
315
+			if (file_exists(trailingslashit($location) . $file_name)) {
316
+				include trailingslashit($location) . $file_name;
317 317
 				break;
318 318
 			}
319 319
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	public function init() {
328 328
 
329 329
 		// Fires before getpaid inits.
330
-		do_action( 'before_getpaid_init', $this );
330
+		do_action('before_getpaid_init', $this);
331 331
 
332 332
 		// Load default gateways.
333 333
 		$gateways = apply_filters(
@@ -341,12 +341,12 @@  discard block
 block discarded – undo
341 341
 			)
342 342
 		);
343 343
 
344
-		foreach ( $gateways as $id => $class ) {
345
-			$this->gateways[ $id ] = new $class();
344
+		foreach ($gateways as $id => $class) {
345
+			$this->gateways[$id] = new $class();
346 346
 		}
347 347
 
348 348
 		// Fires after getpaid inits.
349
-		do_action( 'getpaid_init', $this );
349
+		do_action('getpaid_init', $this);
350 350
 
351 351
 	}
352 352
 
@@ -356,69 +356,69 @@  discard block
 block discarded – undo
356 356
 	public function maybe_process_ipn() {
357 357
 
358 358
 		// Ensure that this is an IPN request.
359
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
359
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
360 360
 			return;
361 361
 		}
362 362
 
363
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
363
+		$gateway = wpinv_clean($_GET['wpi-gateway']);
364 364
 
365
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
366
-		do_action( "wpinv_verify_{$gateway}_ipn" );
365
+		do_action('wpinv_verify_payment_ipn', $gateway);
366
+		do_action("wpinv_verify_{$gateway}_ipn");
367 367
 		exit;
368 368
 
369 369
 	}
370 370
 
371 371
 	public function enqueue_scripts() {
372
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
372
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
373 373
 
374
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
375
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
376
-		wp_enqueue_style( 'wpinv_front_style' );
374
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css');
375
+		wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version);
376
+		wp_enqueue_style('wpinv_front_style');
377 377
 
378 378
 		// Register scripts
379
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
380
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
379
+		wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
380
+		wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
381 381
 
382 382
 		$localize                         = array();
383
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
384
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
383
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
384
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
385 385
 		$localize['currency_symbol']      = wpinv_currency_symbol();
386 386
 		$localize['currency_pos']         = wpinv_currency_position();
387 387
 		$localize['thousand_sep']         = wpinv_thousands_separator();
388 388
 		$localize['decimal_sep']          = wpinv_decimal_separator();
389 389
 		$localize['decimals']             = wpinv_decimals();
390
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
390
+		$localize['txtComplete']          = __('Continue', 'invoicing');
391 391
 		$localize['UseTaxes']             = wpinv_use_taxes();
392
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
393
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
394
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
392
+		$localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
393
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
394
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
395 395
 
396
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
396
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
397 397
 
398
-		wp_enqueue_script( 'jquery-blockui' );
398
+		wp_enqueue_script('jquery-blockui');
399 399
 		$autofill_api = wpinv_get_option('address_autofill_api');
400 400
 		$autofill_active = wpinv_get_option('address_autofill_active');
401
-		if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
402
-			if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
403
-				wp_dequeue_script( 'google-maps-api' );
401
+		if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
402
+			if (wp_script_is('google-maps-api', 'enqueued')) {
403
+				wp_dequeue_script('google-maps-api');
404 404
 			}
405
-			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
406
-			wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
405
+			wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
406
+			wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
407 407
 		}
408 408
 
409
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
410
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
409
+		wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all');
410
+		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
411 411
 
412
-		wp_enqueue_script( 'wpinv-front-script' );
413
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
412
+		wp_enqueue_script('wpinv-front-script');
413
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
414 414
 
415
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
416
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
415
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
416
+		wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
417 417
 	}
418 418
 
419 419
 	public function wpinv_actions() {
420
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
421
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
420
+		if (isset($_REQUEST['wpi_action'])) {
421
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
422 422
 		}
423 423
 	}
424 424
 
@@ -430,23 +430,23 @@  discard block
 block discarded – undo
430 430
      */
431 431
     public function maybe_do_authenticated_action() {
432 432
 
433
-        if ( is_user_logged_in() && isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
434
-            $key = sanitize_key( $_REQUEST['getpaid-action'] );
435
-            do_action( "getpaid_authenticated_action_$key", $_REQUEST );
433
+        if (is_user_logged_in() && isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
434
+            $key = sanitize_key($_REQUEST['getpaid-action']);
435
+            do_action("getpaid_authenticated_action_$key", $_REQUEST);
436 436
         }
437 437
 
438 438
     }
439 439
 
440
-	public function pre_get_posts( $wp_query ) {
441
-		if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
442
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
440
+	public function pre_get_posts($wp_query) {
441
+		if (!is_admin() && !empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
442
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
443 443
 		}
444 444
 
445 445
 		return $wp_query;
446 446
 	}
447 447
 
448 448
 	public function bp_invoicing_init() {
449
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
449
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
450 450
 	}
451 451
 
452 452
 	/**
@@ -467,8 +467,8 @@  discard block
 block discarded – undo
467 467
 			)
468 468
 		);
469 469
 
470
-		foreach ( $widgets as $widget ) {
471
-			register_widget( $widget );
470
+		foreach ($widgets as $widget) {
471
+			register_widget($widget);
472 472
 		}
473 473
 		
474 474
 	}
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
 	 * @since 1.0.19
480 480
 	 * @param int[] $excluded_posts_ids
481 481
 	 */
482
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
482
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
483 483
 
484 484
 		// Ensure that we have an array.
485
-		if ( ! is_array( $excluded_posts_ids ) ) {
485
+		if (!is_array($excluded_posts_ids)) {
486 486
 			$excluded_posts_ids = array();
487 487
 		}
488 488
 
@@ -490,24 +490,24 @@  discard block
 block discarded – undo
490 490
 		$our_pages = array();
491 491
 
492 492
 		// Checkout page.
493
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
493
+		$our_pages[] = wpinv_get_option('checkout_page', false);
494 494
 
495 495
 		// Success page.
496
-		$our_pages[] = wpinv_get_option( 'success_page', false );
496
+		$our_pages[] = wpinv_get_option('success_page', false);
497 497
 
498 498
 		// Failure page.
499
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
499
+		$our_pages[] = wpinv_get_option('failure_page', false);
500 500
 
501 501
 		// History page.
502
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
502
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
503 503
 
504 504
 		// Subscriptions page.
505
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
505
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
506 506
 
507
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
507
+		$our_pages   = array_map('intval', array_filter($our_pages));
508 508
 
509 509
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
510
-		return array_unique( $excluded_posts_ids );
510
+		return array_unique($excluded_posts_ids);
511 511
 
512 512
 	}
513 513
 
Please login to merge, or discard this patch.
Indentation   +477 added lines, -477 removed lines patch added patch discarded remove patch
@@ -14,420 +14,420 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * Tax instance.
40
-	 *
41
-	 * @var WPInv_EUVat
42
-	 */
43
-	public $tax;
44
-
45
-	/**
46
-	 * @param array An array of payment gateways.
47
-	 */
48
-	public $gateways;
49
-
50
-	/**
51
-	 * Class constructor.
52
-	 */
53
-	public function __construct() {
54
-		$this->define_constants();
55
-		$this->includes();
56
-		$this->init_hooks();
57
-		$this->set_properties();
58
-	}
59
-
60
-	/**
61
-	 * Sets a custom data property.
62
-	 * 
63
-	 * @param string $prop The prop to set.
64
-	 * @param mixed $value The value to retrieve.
65
-	 */
66
-	public function set( $prop, $value ) {
67
-		$this->data[ $prop ] = $value;
68
-	}
69
-
70
-	/**
71
-	 * Gets a custom data property.
72
-	 *
73
-	 * @param string $prop The prop to set.
74
-	 * @return mixed The value.
75
-	 */
76
-	public function get( $prop ) {
77
-
78
-		if ( isset( $this->data[ $prop ] ) ) {
79
-			return $this->data[ $prop ];
80
-		}
81
-
82
-		return null;
83
-	}
84
-
85
-	/**
86
-	 * Define class properties.
87
-	 */
88
-	public function set_properties() {
89
-
90
-		// Sessions.
91
-		$this->set( 'session', new WPInv_Session_Handler() );
92
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
-		$this->tax              = new WPInv_EUVat();
94
-		$this->tax->init();
95
-		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
96
-
97
-		// Init other objects.
98
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
99
-		$this->set( 'session', new WPInv_Session_Handler() );
100
-		$this->set( 'notes', new WPInv_Notes() );
101
-		$this->set( 'api', new WPInv_API() );
102
-		$this->set( 'post_types', new GetPaid_Post_Types() );
103
-		$this->set( 'template', new GetPaid_Template() );
104
-		$this->set( 'admin', new GetPaid_Admin() );
105
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
106
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
107
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
108
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
109
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
110
-
111
-	}
112
-
113
-	 /**
114
-	 * Define plugin constants.
115
-	 */
116
-	public function define_constants() {
117
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
118
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
119
-		$this->version = WPINV_VERSION;
120
-	}
121
-
122
-	/**
123
-	 * Hook into actions and filters.
124
-	 *
125
-	 * @since 1.0.19
126
-	 */
127
-	protected function init_hooks() {
128
-		/* Internationalize the text strings used. */
129
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
130
-
131
-		// Init the plugin after WordPress inits.
132
-		add_action( 'init', array( $this, 'init' ), 1 );
133
-		add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
134
-		add_action( 'init', array( &$this, 'wpinv_actions' ) );
135
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
136
-
137
-		if ( class_exists( 'BuddyPress' ) ) {
138
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
139
-		}
140
-
141
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
142
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
143
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
144
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
145
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
146
-
147
-		// Fires after registering actions.
148
-		do_action( 'wpinv_actions', $this );
149
-		do_action( 'getpaid_actions', $this );
150
-
151
-	}
152
-
153
-	public function plugins_loaded() {
154
-		/* Internationalize the text strings used. */
155
-		$this->load_textdomain();
156
-
157
-		do_action( 'wpinv_loaded' );
158
-
159
-		// Fix oxygen page builder conflict
160
-		if ( function_exists( 'ct_css_output' ) ) {
161
-			wpinv_oxygen_fix_conflict();
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Load the translation of the plugin.
167
-	 *
168
-	 * @since 1.0
169
-	 */
170
-	public function load_textdomain( $locale = NULL ) {
171
-		if ( empty( $locale ) ) {
172
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
173
-		}
174
-
175
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
176
-
177
-		unload_textdomain( 'invoicing' );
178
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
179
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
180
-
181
-		/**
182
-		 * Define language constants.
183
-		 */
184
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
185
-	}
186
-
187
-	/**
188
-	 * Include required core files used in admin and on the frontend.
189
-	 */
190
-	public function includes() {
191
-
192
-		// Start with the settings.
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
194
-
195
-		// Packages/libraries.
196
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
198
-
199
-		// Load functions.
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
206
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
207
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
208
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
209
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
210
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
211
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
212
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
215
-
216
-		// Register autoloader.
217
-		try {
218
-			spl_autoload_register( array( $this, 'autoload' ), true );
219
-		} catch ( Exception $e ) {
220
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
221
-		}
222
-
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
235
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
236
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
237
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
238
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
239
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
240
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
241
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
242
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
243
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
244
-
245
-		/**
246
-		 * Load the tax class.
247
-		 */
248
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
249
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
250
-		}
251
-
252
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
253
-			GetPaid_Post_Types_Admin::init();
254
-
255
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
256
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
257
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
258
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
259
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
260
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
261
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
262
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
263
-			// load the user class only on the users.php page
264
-			global $pagenow;
265
-			if($pagenow=='users.php'){
266
-				new WPInv_Admin_Users();
267
-			}
268
-		}
269
-
270
-		// Register cli commands
271
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
272
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
273
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
274
-		}
275
-
276
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
277
-	}
278
-
279
-	/**
280
-	 * Class autoloader
281
-	 *
282
-	 * @param       string $class_name The name of the class to load.
283
-	 * @access      public
284
-	 * @since       1.0.19
285
-	 * @return      void
286
-	 */
287
-	public function autoload( $class_name ) {
288
-
289
-		// Normalize the class name...
290
-		$class_name  = strtolower( $class_name );
291
-
292
-		// ... and make sure it is our class.
293
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
294
-			return;
295
-		}
296
-
297
-		// Next, prepare the file name from the class.
298
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
299
-
300
-		// Base path of the classes.
301
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
302
-
303
-		// And an array of possible locations in order of importance.
304
-		$locations = array(
305
-			"$plugin_path/includes",
306
-			"$plugin_path/includes/data-stores",
307
-			"$plugin_path/includes/gateways",
308
-			"$plugin_path/includes/payments",
309
-			"$plugin_path/includes/api",
310
-			"$plugin_path/includes/admin",
311
-			"$plugin_path/includes/admin/meta-boxes",
312
-		);
313
-
314
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
315
-
316
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
317
-				include trailingslashit( $location ) . $file_name;
318
-				break;
319
-			}
320
-
321
-		}
322
-
323
-	}
324
-
325
-	/**
326
-	 * Inits hooks etc.
327
-	 */
328
-	public function init() {
329
-
330
-		// Fires before getpaid inits.
331
-		do_action( 'before_getpaid_init', $this );
332
-
333
-		// Load default gateways.
334
-		$gateways = apply_filters(
335
-			'getpaid_default_gateways',
336
-			array(
337
-				'manual'        => 'GetPaid_Manual_Gateway',
338
-				'paypal'        => 'GetPaid_Paypal_Gateway',
339
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
340
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
341
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
342
-			)
343
-		);
344
-
345
-		foreach ( $gateways as $id => $class ) {
346
-			$this->gateways[ $id ] = new $class();
347
-		}
348
-
349
-		// Fires after getpaid inits.
350
-		do_action( 'getpaid_init', $this );
351
-
352
-	}
353
-
354
-	/**
355
-	 * Checks if this is an IPN request and processes it.
356
-	 */
357
-	public function maybe_process_ipn() {
358
-
359
-		// Ensure that this is an IPN request.
360
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
361
-			return;
362
-		}
363
-
364
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
365
-
366
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
367
-		do_action( "wpinv_verify_{$gateway}_ipn" );
368
-		exit;
369
-
370
-	}
371
-
372
-	public function enqueue_scripts() {
373
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
374
-
375
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
376
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
377
-		wp_enqueue_style( 'wpinv_front_style' );
378
-
379
-		// Register scripts
380
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
381
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
382
-
383
-		$localize                         = array();
384
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
385
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
386
-		$localize['currency_symbol']      = wpinv_currency_symbol();
387
-		$localize['currency_pos']         = wpinv_currency_position();
388
-		$localize['thousand_sep']         = wpinv_thousands_separator();
389
-		$localize['decimal_sep']          = wpinv_decimal_separator();
390
-		$localize['decimals']             = wpinv_decimals();
391
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
392
-		$localize['UseTaxes']             = wpinv_use_taxes();
393
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
394
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
395
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
396
-
397
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
398
-
399
-		wp_enqueue_script( 'jquery-blockui' );
400
-		$autofill_api = wpinv_get_option('address_autofill_api');
401
-		$autofill_active = wpinv_get_option('address_autofill_active');
402
-		if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
403
-			if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
404
-				wp_dequeue_script( 'google-maps-api' );
405
-			}
406
-			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
407
-			wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
408
-		}
409
-
410
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
411
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
412
-
413
-		wp_enqueue_script( 'wpinv-front-script' );
414
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
415
-
416
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
417
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
418
-	}
419
-
420
-	public function wpinv_actions() {
421
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
422
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
423
-		}
424
-	}
425
-
426
-	/**
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * Tax instance.
40
+     *
41
+     * @var WPInv_EUVat
42
+     */
43
+    public $tax;
44
+
45
+    /**
46
+     * @param array An array of payment gateways.
47
+     */
48
+    public $gateways;
49
+
50
+    /**
51
+     * Class constructor.
52
+     */
53
+    public function __construct() {
54
+        $this->define_constants();
55
+        $this->includes();
56
+        $this->init_hooks();
57
+        $this->set_properties();
58
+    }
59
+
60
+    /**
61
+     * Sets a custom data property.
62
+     * 
63
+     * @param string $prop The prop to set.
64
+     * @param mixed $value The value to retrieve.
65
+     */
66
+    public function set( $prop, $value ) {
67
+        $this->data[ $prop ] = $value;
68
+    }
69
+
70
+    /**
71
+     * Gets a custom data property.
72
+     *
73
+     * @param string $prop The prop to set.
74
+     * @return mixed The value.
75
+     */
76
+    public function get( $prop ) {
77
+
78
+        if ( isset( $this->data[ $prop ] ) ) {
79
+            return $this->data[ $prop ];
80
+        }
81
+
82
+        return null;
83
+    }
84
+
85
+    /**
86
+     * Define class properties.
87
+     */
88
+    public function set_properties() {
89
+
90
+        // Sessions.
91
+        $this->set( 'session', new WPInv_Session_Handler() );
92
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
+        $this->tax              = new WPInv_EUVat();
94
+        $this->tax->init();
95
+        $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
96
+
97
+        // Init other objects.
98
+        $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
99
+        $this->set( 'session', new WPInv_Session_Handler() );
100
+        $this->set( 'notes', new WPInv_Notes() );
101
+        $this->set( 'api', new WPInv_API() );
102
+        $this->set( 'post_types', new GetPaid_Post_Types() );
103
+        $this->set( 'template', new GetPaid_Template() );
104
+        $this->set( 'admin', new GetPaid_Admin() );
105
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
106
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
107
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
108
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
109
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
110
+
111
+    }
112
+
113
+        /**
114
+         * Define plugin constants.
115
+         */
116
+    public function define_constants() {
117
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
118
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
119
+        $this->version = WPINV_VERSION;
120
+    }
121
+
122
+    /**
123
+     * Hook into actions and filters.
124
+     *
125
+     * @since 1.0.19
126
+     */
127
+    protected function init_hooks() {
128
+        /* Internationalize the text strings used. */
129
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
130
+
131
+        // Init the plugin after WordPress inits.
132
+        add_action( 'init', array( $this, 'init' ), 1 );
133
+        add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
134
+        add_action( 'init', array( &$this, 'wpinv_actions' ) );
135
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
136
+
137
+        if ( class_exists( 'BuddyPress' ) ) {
138
+            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
139
+        }
140
+
141
+        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
142
+        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
143
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
144
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
145
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
146
+
147
+        // Fires after registering actions.
148
+        do_action( 'wpinv_actions', $this );
149
+        do_action( 'getpaid_actions', $this );
150
+
151
+    }
152
+
153
+    public function plugins_loaded() {
154
+        /* Internationalize the text strings used. */
155
+        $this->load_textdomain();
156
+
157
+        do_action( 'wpinv_loaded' );
158
+
159
+        // Fix oxygen page builder conflict
160
+        if ( function_exists( 'ct_css_output' ) ) {
161
+            wpinv_oxygen_fix_conflict();
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Load the translation of the plugin.
167
+     *
168
+     * @since 1.0
169
+     */
170
+    public function load_textdomain( $locale = NULL ) {
171
+        if ( empty( $locale ) ) {
172
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
173
+        }
174
+
175
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
176
+
177
+        unload_textdomain( 'invoicing' );
178
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
179
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
180
+
181
+        /**
182
+         * Define language constants.
183
+         */
184
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
185
+    }
186
+
187
+    /**
188
+     * Include required core files used in admin and on the frontend.
189
+     */
190
+    public function includes() {
191
+
192
+        // Start with the settings.
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
194
+
195
+        // Packages/libraries.
196
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
198
+
199
+        // Load functions.
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
206
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
207
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
208
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
209
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
210
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
211
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
212
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
213
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
215
+
216
+        // Register autoloader.
217
+        try {
218
+            spl_autoload_register( array( $this, 'autoload' ), true );
219
+        } catch ( Exception $e ) {
220
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
221
+        }
222
+
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
234
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
235
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
236
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
237
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
238
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
239
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
240
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
241
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
242
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
243
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
244
+
245
+        /**
246
+         * Load the tax class.
247
+         */
248
+        if ( ! class_exists( 'WPInv_EUVat' ) ) {
249
+            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
250
+        }
251
+
252
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
253
+            GetPaid_Post_Types_Admin::init();
254
+
255
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
256
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
257
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
258
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
259
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
260
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
261
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
262
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
263
+            // load the user class only on the users.php page
264
+            global $pagenow;
265
+            if($pagenow=='users.php'){
266
+                new WPInv_Admin_Users();
267
+            }
268
+        }
269
+
270
+        // Register cli commands
271
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
272
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
273
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
274
+        }
275
+
276
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
277
+    }
278
+
279
+    /**
280
+     * Class autoloader
281
+     *
282
+     * @param       string $class_name The name of the class to load.
283
+     * @access      public
284
+     * @since       1.0.19
285
+     * @return      void
286
+     */
287
+    public function autoload( $class_name ) {
288
+
289
+        // Normalize the class name...
290
+        $class_name  = strtolower( $class_name );
291
+
292
+        // ... and make sure it is our class.
293
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
294
+            return;
295
+        }
296
+
297
+        // Next, prepare the file name from the class.
298
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
299
+
300
+        // Base path of the classes.
301
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
302
+
303
+        // And an array of possible locations in order of importance.
304
+        $locations = array(
305
+            "$plugin_path/includes",
306
+            "$plugin_path/includes/data-stores",
307
+            "$plugin_path/includes/gateways",
308
+            "$plugin_path/includes/payments",
309
+            "$plugin_path/includes/api",
310
+            "$plugin_path/includes/admin",
311
+            "$plugin_path/includes/admin/meta-boxes",
312
+        );
313
+
314
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
315
+
316
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
317
+                include trailingslashit( $location ) . $file_name;
318
+                break;
319
+            }
320
+
321
+        }
322
+
323
+    }
324
+
325
+    /**
326
+     * Inits hooks etc.
327
+     */
328
+    public function init() {
329
+
330
+        // Fires before getpaid inits.
331
+        do_action( 'before_getpaid_init', $this );
332
+
333
+        // Load default gateways.
334
+        $gateways = apply_filters(
335
+            'getpaid_default_gateways',
336
+            array(
337
+                'manual'        => 'GetPaid_Manual_Gateway',
338
+                'paypal'        => 'GetPaid_Paypal_Gateway',
339
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
340
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
341
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
342
+            )
343
+        );
344
+
345
+        foreach ( $gateways as $id => $class ) {
346
+            $this->gateways[ $id ] = new $class();
347
+        }
348
+
349
+        // Fires after getpaid inits.
350
+        do_action( 'getpaid_init', $this );
351
+
352
+    }
353
+
354
+    /**
355
+     * Checks if this is an IPN request and processes it.
356
+     */
357
+    public function maybe_process_ipn() {
358
+
359
+        // Ensure that this is an IPN request.
360
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
361
+            return;
362
+        }
363
+
364
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
365
+
366
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
367
+        do_action( "wpinv_verify_{$gateway}_ipn" );
368
+        exit;
369
+
370
+    }
371
+
372
+    public function enqueue_scripts() {
373
+        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
374
+
375
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
376
+        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
377
+        wp_enqueue_style( 'wpinv_front_style' );
378
+
379
+        // Register scripts
380
+        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
381
+        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
382
+
383
+        $localize                         = array();
384
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
385
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
386
+        $localize['currency_symbol']      = wpinv_currency_symbol();
387
+        $localize['currency_pos']         = wpinv_currency_position();
388
+        $localize['thousand_sep']         = wpinv_thousands_separator();
389
+        $localize['decimal_sep']          = wpinv_decimal_separator();
390
+        $localize['decimals']             = wpinv_decimals();
391
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
392
+        $localize['UseTaxes']             = wpinv_use_taxes();
393
+        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
394
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
395
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
396
+
397
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
398
+
399
+        wp_enqueue_script( 'jquery-blockui' );
400
+        $autofill_api = wpinv_get_option('address_autofill_api');
401
+        $autofill_active = wpinv_get_option('address_autofill_active');
402
+        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
403
+            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
404
+                wp_dequeue_script( 'google-maps-api' );
405
+            }
406
+            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
407
+            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
408
+        }
409
+
410
+        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
411
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
412
+
413
+        wp_enqueue_script( 'wpinv-front-script' );
414
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
415
+
416
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
417
+        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
418
+    }
419
+
420
+    public function wpinv_actions() {
421
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
422
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
423
+        }
424
+    }
425
+
426
+    /**
427 427
      * Fires an action after verifying that a user can fire them.
428
-	 *
429
-	 * Note: If the action is on an invoice, subscription etc, esure that the
430
-	 * current user owns the invoice/subscription.
428
+     *
429
+     * Note: If the action is on an invoice, subscription etc, esure that the
430
+     * current user owns the invoice/subscription.
431 431
      */
432 432
     public function maybe_do_authenticated_action() {
433 433
 
@@ -438,82 +438,82 @@  discard block
 block discarded – undo
438 438
 
439 439
     }
440 440
 
441
-	public function pre_get_posts( $wp_query ) {
442
-		if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
443
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
444
-		}
445
-
446
-		return $wp_query;
447
-	}
448
-
449
-	public function bp_invoicing_init() {
450
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
451
-	}
452
-
453
-	/**
454
-	 * Register widgets
455
-	 *
456
-	 */
457
-	public function register_widgets() {
458
-		$widgets = apply_filters(
459
-			'getpaid_widget_classes',
460
-			array(
461
-				'WPInv_Checkout_Widget',
462
-				'WPInv_History_Widget',
463
-				'WPInv_Receipt_Widget',
464
-				'WPInv_Subscriptions_Widget',
465
-				'WPInv_Buy_Item_Widget',
466
-				'WPInv_Messages_Widget',
467
-				'WPInv_GetPaid_Widget'
468
-			)
469
-		);
470
-
471
-		foreach ( $widgets as $widget ) {
472
-			register_widget( $widget );
473
-		}
441
+    public function pre_get_posts( $wp_query ) {
442
+        if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
443
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
444
+        }
445
+
446
+        return $wp_query;
447
+    }
448
+
449
+    public function bp_invoicing_init() {
450
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
451
+    }
452
+
453
+    /**
454
+     * Register widgets
455
+     *
456
+     */
457
+    public function register_widgets() {
458
+        $widgets = apply_filters(
459
+            'getpaid_widget_classes',
460
+            array(
461
+                'WPInv_Checkout_Widget',
462
+                'WPInv_History_Widget',
463
+                'WPInv_Receipt_Widget',
464
+                'WPInv_Subscriptions_Widget',
465
+                'WPInv_Buy_Item_Widget',
466
+                'WPInv_Messages_Widget',
467
+                'WPInv_GetPaid_Widget'
468
+            )
469
+        );
470
+
471
+        foreach ( $widgets as $widget ) {
472
+            register_widget( $widget );
473
+        }
474 474
 		
475
-	}
475
+    }
476 476
 
477
-	/**
478
-	 * Remove our pages from yoast sitemaps.
479
-	 *
480
-	 * @since 1.0.19
481
-	 * @param int[] $excluded_posts_ids
482
-	 */
483
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
477
+    /**
478
+     * Remove our pages from yoast sitemaps.
479
+     *
480
+     * @since 1.0.19
481
+     * @param int[] $excluded_posts_ids
482
+     */
483
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
484 484
 
485
-		// Ensure that we have an array.
486
-		if ( ! is_array( $excluded_posts_ids ) ) {
487
-			$excluded_posts_ids = array();
488
-		}
485
+        // Ensure that we have an array.
486
+        if ( ! is_array( $excluded_posts_ids ) ) {
487
+            $excluded_posts_ids = array();
488
+        }
489 489
 
490
-		// Prepare our pages.
491
-		$our_pages = array();
490
+        // Prepare our pages.
491
+        $our_pages = array();
492 492
 
493
-		// Checkout page.
494
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
493
+        // Checkout page.
494
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
495 495
 
496
-		// Success page.
497
-		$our_pages[] = wpinv_get_option( 'success_page', false );
496
+        // Success page.
497
+        $our_pages[] = wpinv_get_option( 'success_page', false );
498 498
 
499
-		// Failure page.
500
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
499
+        // Failure page.
500
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
501 501
 
502
-		// History page.
503
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
502
+        // History page.
503
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
504 504
 
505
-		// Subscriptions page.
506
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
505
+        // Subscriptions page.
506
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
507 507
 
508
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
508
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
509 509
 
510
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
511
-		return array_unique( $excluded_posts_ids );
510
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
511
+        return array_unique( $excluded_posts_ids );
512 512
 
513
-	}
513
+    }
514 514
 
515
-	public function wp_footer() {
516
-		echo '
515
+    public function wp_footer() {
516
+        echo '
517 517
 			<div class="bsui">
518 518
 				<div  id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog">
519 519
 					<div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;">
@@ -524,6 +524,6 @@  discard block
 block discarded – undo
524 524
 				</div>
525 525
 			</div>
526 526
 		';
527
-	}
527
+    }
528 528
 
529 529
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -14,62 +14,62 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28 28
     public $admin_url;
29 29
 
30 30
     /**
31
-	 * Class constructor.
32
-	 */
33
-	public function __construct(){
31
+     * Class constructor.
32
+     */
33
+    public function __construct(){
34 34
 
35 35
         $this->admin_path  = plugin_dir_path( __FILE__ );
36 36
         $this->admin_url   = plugins_url( '/', __FILE__ );
37 37
 
38 38
         if ( is_admin() ) {
39
-			$this->init_admin_hooks();
39
+            $this->init_admin_hooks();
40 40
         }
41 41
 
42 42
     }
43 43
 
44 44
     /**
45
-	 * Init action and filter hooks
46
-	 *
47
-	 */
48
-	private function init_admin_hooks() {
45
+     * Init action and filter hooks
46
+     *
47
+     */
48
+    private function init_admin_hooks() {
49 49
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50 50
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51 51
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52 52
         add_action( 'admin_init', array( $this, 'activation_redirect') );
53 53
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
54
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
+        do_action( 'getpaid_init_admin_hooks', $this );
58 58
 
59 59
     }
60 60
 
61 61
     /**
62
-	 * Register admin scripts
63
-	 *
64
-	 */
65
-	public function enqeue_scripts() {
62
+     * Register admin scripts
63
+     *
64
+     */
65
+    public function enqeue_scripts() {
66 66
         global $current_screen, $pagenow;
67 67
 
68
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
69
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
68
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
69
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
70 70
 
71 71
         if ( ! empty( $current_screen->post_type ) ) {
72
-			$page = $current_screen->post_type;
72
+            $page = $current_screen->post_type;
73 73
         }
74 74
 
75 75
         // General styles.
@@ -93,30 +93,30 @@  discard block
 block discarded – undo
93 93
         }
94 94
 
95 95
         // Payment form scripts.
96
-		if ( 'wpi_payment_form' == $page && $editing ) {
96
+        if ( 'wpi_payment_form' == $page && $editing ) {
97 97
             $this->load_payment_form_scripts();
98 98
         }
99 99
 
100 100
         if ( $page == 'wpinv-subscriptions' ) {
101
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
103
-		}
101
+            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
+            wp_enqueue_script( 'wpinv-sub-admin-script' );
103
+        }
104 104
 
105
-		if ( $page == 'wpinv-reports' ) {
106
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
107
-		}
105
+        if ( $page == 'wpinv-reports' ) {
106
+            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
107
+        }
108 108
 
109
-		if ( $page == 'wpinv-subscriptions' ) {
110
-			wp_enqueue_script( 'postbox' );
111
-		}
109
+        if ( $page == 'wpinv-subscriptions' ) {
110
+            wp_enqueue_script( 'postbox' );
111
+        }
112 112
 
113 113
     }
114 114
 
115 115
     /**
116
-	 * Returns admin js translations.
117
-	 *
118
-	 */
119
-	protected function get_admin_i18() {
116
+     * Returns admin js translations.
117
+     *
118
+     */
119
+    protected function get_admin_i18() {
120 120
         global $post;
121 121
 
122 122
         return array(
@@ -157,32 +157,32 @@  discard block
 block discarded – undo
157 157
     }
158 158
 
159 159
     /**
160
-	 * Loads payment form js.
161
-	 *
162
-	 */
163
-	protected function load_payment_form_scripts() {
160
+     * Loads payment form js.
161
+     *
162
+     */
163
+    protected function load_payment_form_scripts() {
164 164
         global $post;
165 165
 
166 166
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
167
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
168
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
167
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
168
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
169 169
 
170
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
171
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
170
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
171
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
172 172
 
173
-		wp_localize_script(
173
+        wp_localize_script(
174 174
             'wpinv-admin-payment-form-script',
175 175
             'wpinvPaymentFormAdmin',
176 176
             array(
177
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
178
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
179
-				'currency'      => wpinv_currency_symbol(),
180
-				'position'      => wpinv_currency_position(),
181
-				'decimals'      => (int) wpinv_decimals(),
182
-				'thousands_sep' => wpinv_thousands_separator(),
183
-				'decimals_sep'  => wpinv_decimal_separator(),
184
-				'form_items'    => gepaid_get_form_items( $post->ID ),
185
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
177
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
178
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
179
+                'currency'      => wpinv_currency_symbol(),
180
+                'position'      => wpinv_currency_position(),
181
+                'decimals'      => (int) wpinv_decimals(),
182
+                'thousands_sep' => wpinv_thousands_separator(),
183
+                'decimals_sep'  => wpinv_decimal_separator(),
184
+                'form_items'    => gepaid_get_form_items( $post->ID ),
185
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
186 186
             )
187 187
         );
188 188
 
@@ -191,20 +191,20 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Add our classes to admin pages.
194
+     * Add our classes to admin pages.
195 195
      *
196 196
      * @param string $classes
197 197
      * @return string
198
-	 *
199
-	 */
198
+     *
199
+     */
200 200
     public function admin_body_class( $classes ) {
201
-		global $pagenow, $post, $current_screen;
201
+        global $pagenow, $post, $current_screen;
202 202
 
203 203
 
204 204
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
205 205
 
206 206
         if ( ! empty( $current_screen->post_type ) ) {
207
-			$page = $current_screen->post_type;
207
+            $page = $current_screen->post_type;
208 208
         }
209 209
 
210 210
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -215,27 +215,27 @@  discard block
 block discarded – undo
215 215
             $classes .= ' wpinv-cpt wpinv';
216 216
         }
217 217
 
218
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
-			$classes .= ' wpi-editable-n';
220
-		}
218
+        if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
+            $classes .= ' wpi-editable-n';
220
+        }
221 221
 
222
-		return $classes;
222
+        return $classes;
223 223
     }
224 224
 
225 225
     /**
226
-	 * Maybe show the AyeCode Connect Notice.
227
-	 */
228
-	public function init_ayecode_connect_helper(){
226
+     * Maybe show the AyeCode Connect Notice.
227
+     */
228
+    public function init_ayecode_connect_helper(){
229 229
 
230 230
         new AyeCode_Connect_Helper(
231 231
             array(
232
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
235
-				'connect_button'    => __("Connect Site","invoicing"),
236
-				'connecting_button'    => __("Connecting...","invoicing"),
237
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
232
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
235
+                'connect_button'    => __("Connect Site","invoicing"),
236
+                'connecting_button'    => __("Connecting...","invoicing"),
237
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
239 239
             ),
240 240
             array( 'wpi-addons' )
241 241
         );
@@ -247,21 +247,21 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function activation_redirect() {
249 249
 
250
-		// Bail if no activation redirect.
251
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
252
-			return;
253
-		}
250
+        // Bail if no activation redirect.
251
+        if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
252
+            return;
253
+        }
254 254
 
255
-		// Delete the redirect transient.
256
-		delete_transient( '_wpinv_activation_redirect' );
255
+        // Delete the redirect transient.
256
+        delete_transient( '_wpinv_activation_redirect' );
257 257
 
258
-		// Bail if activating from network, or bulk
259
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
-			return;
261
-		}
258
+        // Bail if activating from network, or bulk
259
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
+            return;
261
+        }
262 262
 
263
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
-		exit;
263
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
+        exit;
265 265
     }
266 266
 
267 267
     /**
@@ -276,150 +276,150 @@  discard block
 block discarded – undo
276 276
 
277 277
     }
278 278
 
279
-	/**
279
+    /**
280 280
      * Sends a payment reminder to a customer.
281
-	 * 
282
-	 * @param array $args
281
+     * 
282
+     * @param array $args
283 283
      */
284 284
     public function send_customer_invoice( $args ) {
285
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
285
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
286 286
 
287
-		if ( $sent ) {
288
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
-		} else {
290
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
-		}
287
+        if ( $sent ) {
288
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
+        } else {
290
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
+        }
292 292
 
293
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
-		exit;
295
-	}
293
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
+        exit;
295
+    }
296 296
 
297
-	/**
297
+    /**
298 298
      * Sends a payment reminder to a customer.
299
-	 * 
300
-	 * @param array $args
299
+     * 
300
+     * @param array $args
301 301
      */
302 302
     public function send_customer_payment_reminder( $args ) {
303
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
303
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
304 304
 
305
-		if ( $sent ) {
306
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
-		} else {
308
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
-		}
305
+        if ( $sent ) {
306
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
+        } else {
308
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
+        }
310 310
 
311
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
-		exit;
313
-	}
311
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
+        exit;
313
+    }
314 314
 
315 315
     /**
316
-	 * Returns an array of admin notices.
317
-	 *
318
-	 * @since       1.0.19
316
+     * Returns an array of admin notices.
317
+     *
318
+     * @since       1.0.19
319 319
      * @return array
320
-	 */
321
-	public function get_notices() {
322
-		$notices = get_option( 'wpinv_admin_notices' );
320
+     */
321
+    public function get_notices() {
322
+        $notices = get_option( 'wpinv_admin_notices' );
323 323
         return is_array( $notices ) ? $notices : array();
324
-	}
325
-
326
-	/**
327
-	 * Clears all admin notices
328
-	 *
329
-	 * @access      public
330
-	 * @since       1.0.19
331
-	 */
332
-	public function clear_notices() {
333
-		delete_option( 'wpinv_admin_notices' );
334
-	}
335
-
336
-	/**
337
-	 * Saves a new admin notice
338
-	 *
339
-	 * @access      public
340
-	 * @since       1.0.19
341
-	 */
342
-	public function save_notice( $type, $message ) {
343
-		$notices = $this->get_notices();
344
-
345
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
-			$notices[ $type ] = array();
347
-		}
348
-
349
-		$notices[ $type ][] = $message;
350
-
351
-		update_option( 'wpinv_admin_notices', $notices );
352
-	}
353
-
354
-	/**
355
-	 * Displays a success notice
356
-	 *
357
-	 * @param       string $msg The message to qeue.
358
-	 * @access      public
359
-	 * @since       1.0.19
360
-	 */
361
-	public function show_success( $msg ) {
362
-		$this->save_notice( 'success', $msg );
363
-	}
364
-
365
-	/**
366
-	 * Displays a error notice
367
-	 *
368
-	 * @access      public
369
-	 * @param       string $msg The message to qeue.
370
-	 * @since       1.0.19
371
-	 */
372
-	public function show_error( $msg ) {
373
-		$this->save_notice( 'error', $msg );
374
-	}
375
-
376
-	/**
377
-	 * Displays a warning notice
378
-	 *
379
-	 * @access      public
380
-	 * @param       string $msg The message to qeue.
381
-	 * @since       1.0.19
382
-	 */
383
-	public function show_warning( $msg ) {
384
-		$this->save_notice( 'warning', $msg );
385
-	}
386
-
387
-	/**
388
-	 * Displays a info notice
389
-	 *
390
-	 * @access      public
391
-	 * @param       string $msg The message to qeue.
392
-	 * @since       1.0.19
393
-	 */
394
-	public function show_info( $msg ) {
395
-		$this->save_notice( 'info', $msg );
396
-	}
397
-
398
-	/**
399
-	 * Show notices
400
-	 *
401
-	 * @access      public
402
-	 * @since       1.0.19
403
-	 */
404
-	public function show_notices() {
324
+    }
325
+
326
+    /**
327
+     * Clears all admin notices
328
+     *
329
+     * @access      public
330
+     * @since       1.0.19
331
+     */
332
+    public function clear_notices() {
333
+        delete_option( 'wpinv_admin_notices' );
334
+    }
335
+
336
+    /**
337
+     * Saves a new admin notice
338
+     *
339
+     * @access      public
340
+     * @since       1.0.19
341
+     */
342
+    public function save_notice( $type, $message ) {
343
+        $notices = $this->get_notices();
344
+
345
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
+            $notices[ $type ] = array();
347
+        }
348
+
349
+        $notices[ $type ][] = $message;
350
+
351
+        update_option( 'wpinv_admin_notices', $notices );
352
+    }
353
+
354
+    /**
355
+     * Displays a success notice
356
+     *
357
+     * @param       string $msg The message to qeue.
358
+     * @access      public
359
+     * @since       1.0.19
360
+     */
361
+    public function show_success( $msg ) {
362
+        $this->save_notice( 'success', $msg );
363
+    }
364
+
365
+    /**
366
+     * Displays a error notice
367
+     *
368
+     * @access      public
369
+     * @param       string $msg The message to qeue.
370
+     * @since       1.0.19
371
+     */
372
+    public function show_error( $msg ) {
373
+        $this->save_notice( 'error', $msg );
374
+    }
375
+
376
+    /**
377
+     * Displays a warning notice
378
+     *
379
+     * @access      public
380
+     * @param       string $msg The message to qeue.
381
+     * @since       1.0.19
382
+     */
383
+    public function show_warning( $msg ) {
384
+        $this->save_notice( 'warning', $msg );
385
+    }
386
+
387
+    /**
388
+     * Displays a info notice
389
+     *
390
+     * @access      public
391
+     * @param       string $msg The message to qeue.
392
+     * @since       1.0.19
393
+     */
394
+    public function show_info( $msg ) {
395
+        $this->save_notice( 'info', $msg );
396
+    }
397
+
398
+    /**
399
+     * Show notices
400
+     *
401
+     * @access      public
402
+     * @since       1.0.19
403
+     */
404
+    public function show_notices() {
405 405
 
406 406
         $notices = $this->get_notices();
407 407
         $this->clear_notices();
408 408
 
409
-		foreach ( $notices as $type => $messages ) {
409
+        foreach ( $notices as $type => $messages ) {
410 410
 
411
-			if ( ! is_array( $messages ) ) {
412
-				continue;
413
-			}
411
+            if ( ! is_array( $messages ) ) {
412
+                continue;
413
+            }
414 414
 
415 415
             $type  = sanitize_key( $type );
416
-			foreach ( $messages as $message ) {
416
+            foreach ( $messages as $message ) {
417 417
                 $message = wp_kses_post( $message );
418
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
418
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
419 419
             }
420 420
 
421 421
         }
422 422
 
423
-	}
423
+    }
424 424
 
425 425
 }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * The main admin class.
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
     /**
31 31
 	 * Class constructor.
32 32
 	 */
33
-	public function __construct(){
33
+	public function __construct() {
34 34
 
35
-        $this->admin_path  = plugin_dir_path( __FILE__ );
36
-        $this->admin_url   = plugins_url( '/', __FILE__ );
35
+        $this->admin_path  = plugin_dir_path(__FILE__);
36
+        $this->admin_url   = plugins_url('/', __FILE__);
37 37
 
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
 			$this->init_admin_hooks();
40 40
         }
41 41
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 */
48 48
 	private function init_admin_hooks() {
49
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
53
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
49
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
50
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
51
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
52
+        add_action('admin_init', array($this, 'activation_redirect'));
53
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
54
+		add_action('admin_notices', array($this, 'show_notices'));
55
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
56
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
57
+		do_action('getpaid_init_admin_hooks', $this);
58 58
 
59 59
     }
60 60
 
@@ -65,49 +65,49 @@  discard block
 block discarded – undo
65 65
 	public function enqeue_scripts() {
66 66
         global $current_screen, $pagenow;
67 67
 
68
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
68
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
69 69
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
70 70
 
71
-        if ( ! empty( $current_screen->post_type ) ) {
71
+        if (!empty($current_screen->post_type)) {
72 72
 			$page = $current_screen->post_type;
73 73
         }
74 74
 
75 75
         // General styles.
76
-        if ( false !== stripos( $page, 'wpi' ) ) {
76
+        if (false !== stripos($page, 'wpi')) {
77 77
 
78 78
             // Styles.
79
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
80
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
81
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
82
-            wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
83
-            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
79
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
80
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
81
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
82
+            wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
83
+            wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16');
84 84
 
85 85
             // Scripts.
86
-            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
87
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
86
+            wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true);
87
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
88 88
 
89
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
90
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ),  $version );
91
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
89
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
90
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version);
91
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
92 92
 
93 93
         }
94 94
 
95 95
         // Payment form scripts.
96
-		if ( 'wpi_payment_form' == $page && $editing ) {
96
+		if ('wpi_payment_form' == $page && $editing) {
97 97
             $this->load_payment_form_scripts();
98 98
         }
99 99
 
100
-        if ( $page == 'wpinv-subscriptions' ) {
101
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
100
+        if ($page == 'wpinv-subscriptions') {
101
+			wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
102
+			wp_enqueue_script('wpinv-sub-admin-script');
103 103
 		}
104 104
 
105
-		if ( $page == 'wpinv-reports' ) {
106
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
105
+		if ($page == 'wpinv-reports') {
106
+			wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
107 107
 		}
108 108
 
109
-		if ( $page == 'wpinv-subscriptions' ) {
110
-			wp_enqueue_script( 'postbox' );
109
+		if ($page == 'wpinv-subscriptions') {
110
+			wp_enqueue_script('postbox');
111 111
 		}
112 112
 
113 113
     }
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
         global $post;
121 121
 
122 122
         return array(
123
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
124
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
125
-            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
126
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
127
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
128
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
129
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
123
+            'ajax_url'                  => admin_url('admin-ajax.php'),
124
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
125
+            'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
126
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
127
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
128
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
129
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
130 130
             'tax'                       => wpinv_tax_amount(),
131 131
             'discount'                  => wpinv_discount_amount(),
132 132
             'currency_symbol'           => wpinv_currency_symbol(),
@@ -134,24 +134,24 @@  discard block
 block discarded – undo
134 134
             'thousand_sep'              => wpinv_thousands_separator(),
135 135
             'decimal_sep'               => wpinv_decimal_separator(),
136 136
             'decimals'                  => wpinv_decimals(),
137
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
138
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
139
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
140
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
141
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
142
-            'OneItemMin'                => __( 'Invoice must contain at least one item', 'invoicing' ),
143
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
144
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
145
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
146
-            'emptyInvoice'              => __( 'Add at least one item to save invoice!', 'invoicing' ),
147
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
148
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
149
-            'action_edit'               => __( 'Edit', 'invoicing' ),
150
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
151
-            'item_description'          => __( 'Item Description', 'invoicing' ),
152
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
153
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
154
-            'searching'                 => __( 'Searching', 'invoicing' ),
137
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
138
+            'status_publish'            => wpinv_status_nicename('publish'),
139
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
140
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
141
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
142
+            'OneItemMin'                => __('Invoice must contain at least one item', 'invoicing'),
143
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
144
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
145
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
146
+            'emptyInvoice'              => __('Add at least one item to save invoice!', 'invoicing'),
147
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
148
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
149
+            'action_edit'               => __('Edit', 'invoicing'),
150
+            'action_cancel'             => __('Cancel', 'invoicing'),
151
+            'item_description'          => __('Item Description', 'invoicing'),
152
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
153
+            'discount_description'      => __('Discount Description', 'invoicing'),
154
+            'searching'                 => __('Searching', 'invoicing'),
155 155
         );
156 156
 
157 157
     }
@@ -163,30 +163,30 @@  discard block
 block discarded – undo
163 163
 	protected function load_payment_form_scripts() {
164 164
         global $post;
165 165
 
166
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
167
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
168
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
166
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
167
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
168
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
169 169
 
170
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
171
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
170
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
171
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
172 172
 
173 173
 		wp_localize_script(
174 174
             'wpinv-admin-payment-form-script',
175 175
             'wpinvPaymentFormAdmin',
176 176
             array(
177
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
178
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
177
+				'elements'      => wpinv_get_data('payment-form-elements'),
178
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
179 179
 				'currency'      => wpinv_currency_symbol(),
180 180
 				'position'      => wpinv_currency_position(),
181 181
 				'decimals'      => (int) wpinv_decimals(),
182 182
 				'thousands_sep' => wpinv_thousands_separator(),
183 183
 				'decimals_sep'  => wpinv_decimal_separator(),
184
-				'form_items'    => gepaid_get_form_items( $post->ID ),
184
+				'form_items'    => gepaid_get_form_items($post->ID),
185 185
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
186 186
             )
187 187
         );
188 188
 
189
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
189
+        wp_enqueue_script('wpinv-admin-payment-form-script');
190 190
 
191 191
     }
192 192
 
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
      * @return string
198 198
 	 *
199 199
 	 */
200
-    public function admin_body_class( $classes ) {
200
+    public function admin_body_class($classes) {
201 201
 		global $pagenow, $post, $current_screen;
202 202
 
203 203
 
204
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
204
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
205 205
 
206
-        if ( ! empty( $current_screen->post_type ) ) {
206
+        if (!empty($current_screen->post_type)) {
207 207
 			$page = $current_screen->post_type;
208 208
         }
209 209
 
210
-        if ( false !== stripos( $page, 'wpi' ) ) {
211
-            $classes .= ' wpi-' . sanitize_key( $page );
210
+        if (false !== stripos($page, 'wpi')) {
211
+            $classes .= ' wpi-' . sanitize_key($page);
212 212
         }
213 213
 
214
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
214
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
215 215
             $classes .= ' wpinv-cpt wpinv';
216 216
         }
217 217
 
218
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
218
+		if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
219 219
 			$classes .= ' wpi-editable-n';
220 220
 		}
221 221
 
@@ -225,19 +225,19 @@  discard block
 block discarded – undo
225 225
     /**
226 226
 	 * Maybe show the AyeCode Connect Notice.
227 227
 	 */
228
-	public function init_ayecode_connect_helper(){
228
+	public function init_ayecode_connect_helper() {
229 229
 
230 230
         new AyeCode_Connect_Helper(
231 231
             array(
232
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
235
-				'connect_button'    => __("Connect Site","invoicing"),
236
-				'connecting_button'    => __("Connecting...","invoicing"),
237
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
232
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
233
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
234
+				'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
235
+				'connect_button'    => __("Connect Site", "invoicing"),
236
+				'connecting_button'    => __("Connecting...", "invoicing"),
237
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
238
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
239 239
             ),
240
-            array( 'wpi-addons' )
240
+            array('wpi-addons')
241 241
         );
242 242
 
243 243
     }
@@ -248,19 +248,19 @@  discard block
 block discarded – undo
248 248
     public function activation_redirect() {
249 249
 
250 250
 		// Bail if no activation redirect.
251
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
251
+		if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) {
252 252
 			return;
253 253
 		}
254 254
 
255 255
 		// Delete the redirect transient.
256
-		delete_transient( '_wpinv_activation_redirect' );
256
+		delete_transient('_wpinv_activation_redirect');
257 257
 
258 258
 		// Bail if activating from network, or bulk
259
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
259
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
260 260
 			return;
261 261
 		}
262 262
 
263
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
263
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
264 264
 		exit;
265 265
     }
266 266
 
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
      */
270 270
     public function maybe_do_admin_action() {
271 271
 
272
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
273
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
274
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
272
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
273
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
274
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
275 275
         }
276 276
 
277 277
     }
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 	 * 
282 282
 	 * @param array $args
283 283
      */
284
-    public function send_customer_invoice( $args ) {
285
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
284
+    public function send_customer_invoice($args) {
285
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
286 286
 
287
-		if ( $sent ) {
288
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
287
+		if ($sent) {
288
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
289 289
 		} else {
290
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
290
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
291 291
 		}
292 292
 
293
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
293
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
294 294
 		exit;
295 295
 	}
296 296
 
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 	 * 
300 300
 	 * @param array $args
301 301
      */
302
-    public function send_customer_payment_reminder( $args ) {
303
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
302
+    public function send_customer_payment_reminder($args) {
303
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
304 304
 
305
-		if ( $sent ) {
306
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
305
+		if ($sent) {
306
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
307 307
 		} else {
308
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
308
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
309 309
 		}
310 310
 
311
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
311
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
312 312
 		exit;
313 313
 	}
314 314
 
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
      * @return array
320 320
 	 */
321 321
 	public function get_notices() {
322
-		$notices = get_option( 'wpinv_admin_notices' );
323
-        return is_array( $notices ) ? $notices : array();
322
+		$notices = get_option('wpinv_admin_notices');
323
+        return is_array($notices) ? $notices : array();
324 324
 	}
325 325
 
326 326
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * @since       1.0.19
331 331
 	 */
332 332
 	public function clear_notices() {
333
-		delete_option( 'wpinv_admin_notices' );
333
+		delete_option('wpinv_admin_notices');
334 334
 	}
335 335
 
336 336
 	/**
@@ -339,16 +339,16 @@  discard block
 block discarded – undo
339 339
 	 * @access      public
340 340
 	 * @since       1.0.19
341 341
 	 */
342
-	public function save_notice( $type, $message ) {
342
+	public function save_notice($type, $message) {
343 343
 		$notices = $this->get_notices();
344 344
 
345
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
-			$notices[ $type ] = array();
345
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
346
+			$notices[$type] = array();
347 347
 		}
348 348
 
349
-		$notices[ $type ][] = $message;
349
+		$notices[$type][] = $message;
350 350
 
351
-		update_option( 'wpinv_admin_notices', $notices );
351
+		update_option('wpinv_admin_notices', $notices);
352 352
 	}
353 353
 
354 354
 	/**
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	 * @access      public
359 359
 	 * @since       1.0.19
360 360
 	 */
361
-	public function show_success( $msg ) {
362
-		$this->save_notice( 'success', $msg );
361
+	public function show_success($msg) {
362
+		$this->save_notice('success', $msg);
363 363
 	}
364 364
 
365 365
 	/**
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 	 * @param       string $msg The message to qeue.
370 370
 	 * @since       1.0.19
371 371
 	 */
372
-	public function show_error( $msg ) {
373
-		$this->save_notice( 'error', $msg );
372
+	public function show_error($msg) {
373
+		$this->save_notice('error', $msg);
374 374
 	}
375 375
 
376 376
 	/**
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 	 * @param       string $msg The message to qeue.
381 381
 	 * @since       1.0.19
382 382
 	 */
383
-	public function show_warning( $msg ) {
384
-		$this->save_notice( 'warning', $msg );
383
+	public function show_warning($msg) {
384
+		$this->save_notice('warning', $msg);
385 385
 	}
386 386
 
387 387
 	/**
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
 	 * @param       string $msg The message to qeue.
392 392
 	 * @since       1.0.19
393 393
 	 */
394
-	public function show_info( $msg ) {
395
-		$this->save_notice( 'info', $msg );
394
+	public function show_info($msg) {
395
+		$this->save_notice('info', $msg);
396 396
 	}
397 397
 
398 398
 	/**
@@ -406,15 +406,15 @@  discard block
 block discarded – undo
406 406
         $notices = $this->get_notices();
407 407
         $this->clear_notices();
408 408
 
409
-		foreach ( $notices as $type => $messages ) {
409
+		foreach ($notices as $type => $messages) {
410 410
 
411
-			if ( ! is_array( $messages ) ) {
411
+			if (!is_array($messages)) {
412 412
 				continue;
413 413
 			}
414 414
 
415
-            $type  = sanitize_key( $type );
416
-			foreach ( $messages as $message ) {
417
-                $message = wp_kses_post( $message );
415
+            $type = sanitize_key($type);
416
+			foreach ($messages as $message) {
417
+                $message = wp_kses_post($message);
418 418
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
419 419
             }
420 420
 
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
     
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
     
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -260,24 +260,24 @@  discard block
 block discarded – undo
260 260
         }
261 261
 
262 262
         // Is the request set up correctly?
263
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
264
-			echo aui()->alert(
265
-				array(
266
-					'type'    => 'warning',
267
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
268
-				)
263
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
264
+            echo aui()->alert(
265
+                array(
266
+                    'type'    => 'warning',
267
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
268
+                )
269 269
             );
270 270
             exit;
271 271
         }
272 272
 
273 273
         // Payment form or button?
274
-		if ( ! empty( $_GET['form'] ) ) {
274
+        if ( ! empty( $_GET['form'] ) ) {
275 275
             getpaid_display_payment_form( $_GET['form'] );
276
-		} else if( ! empty( $_GET['invoice'] ) ) {
277
-		    getpaid_display_invoice_payment_form( $_GET['invoice'] );
276
+        } else if( ! empty( $_GET['invoice'] ) ) {
277
+            getpaid_display_invoice_payment_form( $_GET['invoice'] );
278 278
         } else {
279
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
280
-		    getpaid_display_item_payment_form( $items );
279
+            $items = getpaid_convert_items_to_array( $_GET['item'] );
280
+            getpaid_display_item_payment_form( $items );
281 281
         }
282 282
 
283 283
         exit;
Please login to merge, or discard this patch.
Spacing   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -103,36 +103,36 @@  discard block
 block discarded – undo
103 103
             'ip_geolocation'              => true,
104 104
         );
105 105
 
106
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
107
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
108
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
106
+        foreach ($ajax_events as $ajax_event => $nopriv) {
107
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
108
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
109 109
 
110
-            if ( $nopriv ) {
111
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
110
+            if ($nopriv) {
111
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
112
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
113
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
114 114
             }
115 115
         }
116 116
     }
117 117
     
118 118
     public static function add_note() {
119
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
119
+        check_ajax_referer('add-invoice-note', '_nonce');
120 120
 
121
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
121
+        if (!wpinv_current_user_can_manage_invoicing()) {
122 122
             die(-1);
123 123
         }
124 124
 
125
-        $post_id   = absint( $_POST['post_id'] );
126
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
127
-        $note_type = sanitize_text_field( $_POST['note_type'] );
125
+        $post_id   = absint($_POST['post_id']);
126
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
127
+        $note_type = sanitize_text_field($_POST['note_type']);
128 128
 
129 129
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
130 130
 
131
-        if ( $post_id > 0 ) {
132
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
131
+        if ($post_id > 0) {
132
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
133 133
 
134
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
135
-                wpinv_get_invoice_note_line_item( $note_id );
134
+            if ($note_id > 0 && !is_wp_error($note_id)) {
135
+                wpinv_get_invoice_note_line_item($note_id);
136 136
             }
137 137
         }
138 138
 
@@ -140,16 +140,16 @@  discard block
 block discarded – undo
140 140
     }
141 141
 
142 142
     public static function delete_note() {
143
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
143
+        check_ajax_referer('delete-invoice-note', '_nonce');
144 144
 
145
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
145
+        if (!wpinv_current_user_can_manage_invoicing()) {
146 146
             die(-1);
147 147
         }
148 148
 
149
-        $note_id = (int)$_POST['note_id'];
149
+        $note_id = (int) $_POST['note_id'];
150 150
 
151
-        if ( $note_id > 0 ) {
152
-            wp_delete_comment( $note_id, true );
151
+        if ($note_id > 0) {
152
+            wp_delete_comment($note_id, true);
153 153
         }
154 154
 
155 155
         die();
@@ -167,34 +167,34 @@  discard block
 block discarded – undo
167 167
     public static function get_billing_details() {
168 168
 
169 169
         // Verify nonce.
170
-        check_ajax_referer( 'wpinv-nonce' );
170
+        check_ajax_referer('wpinv-nonce');
171 171
 
172 172
         // Can the user manage the plugin?
173
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
173
+        if (!wpinv_current_user_can_manage_invoicing()) {
174 174
             die(-1);
175 175
         }
176 176
 
177 177
         // Do we have a user id?
178 178
         $user_id = $_GET['user_id'];
179 179
 
180
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
180
+        if (empty($user_id) || !is_numeric($user_id)) {
181 181
             die(-1);
182 182
         }
183 183
 
184 184
         // Fetch the billing details.
185
-        $billing_details    = wpinv_get_user_address( $user_id );
186
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
185
+        $billing_details    = wpinv_get_user_address($user_id);
186
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
187 187
 
188 188
         // unset the user id and email.
189
-        $to_ignore = array( 'user_id', 'email' );
189
+        $to_ignore = array('user_id', 'email');
190 190
 
191
-        foreach ( $to_ignore as $key ) {
192
-            if ( isset( $billing_details[ $key ] ) ) {
193
-                unset( $billing_details[ $key ] );
191
+        foreach ($to_ignore as $key) {
192
+            if (isset($billing_details[$key])) {
193
+                unset($billing_details[$key]);
194 194
             }
195 195
         }
196 196
 
197
-        wp_send_json_success( $billing_details );
197
+        wp_send_json_success($billing_details);
198 198
 
199 199
     }
200 200
 
@@ -204,47 +204,47 @@  discard block
 block discarded – undo
204 204
     public static function check_new_user_email() {
205 205
 
206 206
         // Verify nonce.
207
-        check_ajax_referer( 'wpinv-nonce' );
207
+        check_ajax_referer('wpinv-nonce');
208 208
 
209 209
         // Can the user manage the plugin?
210
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
210
+        if (!wpinv_current_user_can_manage_invoicing()) {
211 211
             die(-1);
212 212
         }
213 213
 
214 214
         // We need an email address.
215
-        if ( empty( $_GET['email'] ) ) {
216
-            _e( "Provide the new user's email address", 'invoicing' );
215
+        if (empty($_GET['email'])) {
216
+            _e("Provide the new user's email address", 'invoicing');
217 217
             exit;
218 218
         }
219 219
 
220 220
         // Ensure the email is valid.
221
-        $email = sanitize_text_field( $_GET['email'] );
222
-        if ( ! is_email( $email ) ) {
223
-            _e( 'Invalid email address', 'invoicing' );
221
+        $email = sanitize_text_field($_GET['email']);
222
+        if (!is_email($email)) {
223
+            _e('Invalid email address', 'invoicing');
224 224
             exit;
225 225
         }
226 226
 
227 227
         // And it does not exist.
228
-        if ( email_exists( $email ) ) {
229
-            _e( 'A user with this email address already exists', 'invoicing' );
228
+        if (email_exists($email)) {
229
+            _e('A user with this email address already exists', 'invoicing');
230 230
             exit;
231 231
         }
232 232
 
233
-        wp_send_json_success( true );
233
+        wp_send_json_success(true);
234 234
     }
235 235
     
236 236
     public static function run_tool() {
237
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
238
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
237
+        check_ajax_referer('wpinv-nonce', '_nonce');
238
+        if (!wpinv_current_user_can_manage_invoicing()) {
239 239
             die(-1);
240 240
         }
241 241
         
242
-        $tool = sanitize_text_field( $_POST['tool'] );
242
+        $tool = sanitize_text_field($_POST['tool']);
243 243
         
244
-        do_action( 'wpinv_run_tool' );
244
+        do_action('wpinv_run_tool');
245 245
         
246
-        if ( !empty( $tool ) ) {
247
-            do_action( 'wpinv_tool_' . $tool );
246
+        if (!empty($tool)) {
247
+            do_action('wpinv_tool_' . $tool);
248 248
         }
249 249
     }
250 250
 
@@ -254,30 +254,30 @@  discard block
 block discarded – undo
254 254
     public static function get_payment_form() {
255 255
 
256 256
         // Check nonce.
257
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
258
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
257
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
258
+            _e('Error: Reload the page and try again.', 'invoicing');
259 259
             exit;
260 260
         }
261 261
 
262 262
         // Is the request set up correctly?
263
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
263
+		if (empty($_GET['form']) && empty($_GET['item'])) {
264 264
 			echo aui()->alert(
265 265
 				array(
266 266
 					'type'    => 'warning',
267
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
267
+					'content' => __('No payment form or item provided', 'invoicing'),
268 268
 				)
269 269
             );
270 270
             exit;
271 271
         }
272 272
 
273 273
         // Payment form or button?
274
-		if ( ! empty( $_GET['form'] ) ) {
275
-            getpaid_display_payment_form( $_GET['form'] );
276
-		} else if( ! empty( $_GET['invoice'] ) ) {
277
-		    getpaid_display_invoice_payment_form( $_GET['invoice'] );
274
+		if (!empty($_GET['form'])) {
275
+            getpaid_display_payment_form($_GET['form']);
276
+		} else if (!empty($_GET['invoice'])) {
277
+		    getpaid_display_invoice_payment_form($_GET['invoice']);
278 278
         } else {
279
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
280
-		    getpaid_display_item_payment_form( $items );
279
+			$items = getpaid_convert_items_to_array($_GET['item']);
280
+		    getpaid_display_item_payment_form($items);
281 281
         }
282 282
 
283 283
         exit;
@@ -292,17 +292,17 @@  discard block
 block discarded – undo
292 292
     public static function payment_form() {
293 293
 
294 294
         // Check nonce.
295
-        check_ajax_referer( 'getpaid_form_nonce' );
295
+        check_ajax_referer('getpaid_form_nonce');
296 296
 
297 297
         // ... form fields...
298
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
299
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
298
+        if (empty($_POST['getpaid_payment_form_submission'])) {
299
+            _e('Error: Reload the page and try again.', 'invoicing');
300 300
             exit;
301 301
         }
302 302
 
303 303
         // Process the payment form.
304
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
305
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
304
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
305
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
306 306
         $checkout->process_checkout();
307 307
 
308 308
         exit;
@@ -315,51 +315,51 @@  discard block
 block discarded – undo
315 315
      */
316 316
     public static function get_payment_form_states_field() {
317 317
 
318
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
318
+        if (empty($_GET['country']) || empty($_GET['form'])) {
319 319
             exit;
320 320
         }
321 321
 
322
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
322
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
323 323
 
324
-        if ( empty( $elements ) ) {
324
+        if (empty($elements)) {
325 325
             exit;
326 326
         }
327 327
 
328 328
         $address_fields = array();
329
-        foreach ( $elements as $element ) {
330
-            if ( 'address' === $element['type'] ) {
329
+        foreach ($elements as $element) {
330
+            if ('address' === $element['type']) {
331 331
                 $address_fields = $element;
332 332
                 break;
333 333
             }
334 334
         }
335 335
 
336
-        if ( empty( $address_fields ) ) {
336
+        if (empty($address_fields)) {
337 337
             exit;
338 338
         }
339 339
 
340
-        foreach( $address_fields['fields'] as $address_field ) {
340
+        foreach ($address_fields['fields'] as $address_field) {
341 341
 
342
-            if ( 'wpinv_state' == $address_field['name'] ) {
342
+            if ('wpinv_state' == $address_field['name']) {
343 343
 
344 344
                 $label = $address_field['label'];
345 345
 
346
-                if ( ! empty( $address_field['required'] ) ) {
346
+                if (!empty($address_field['required'])) {
347 347
                     $label .= "<span class='text-danger'> *</span>";
348 348
                 }
349 349
 
350
-                $states = wpinv_get_country_states( $_GET['country'] );
350
+                $states = wpinv_get_country_states($_GET['country']);
351 351
 
352
-                if ( ! empty( $states ) ) {
352
+                if (!empty($states)) {
353 353
 
354 354
                     $html = aui()->select(
355 355
                             array(
356 356
                                 'options'          => $states,
357
-                                'name'             => esc_attr( $address_field['name'] ),
358
-                                'id'               => esc_attr( $address_field['name'] ),
359
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
357
+                                'name'             => esc_attr($address_field['name']),
358
+                                'id'               => esc_attr($address_field['name']),
359
+                                'placeholder'      => esc_attr($address_field['placeholder']),
360 360
                                 'required'         => (bool) $address_field['required'],
361 361
                                 'no_wrap'          => true,
362
-                                'label'            => wp_kses_post( $label ),
362
+                                'label'            => wp_kses_post($label),
363 363
                                 'select2'          => false,
364 364
                             )
365 365
                         );
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
 
369 369
                     $html = aui()->input(
370 370
                             array(
371
-                                'name'       => esc_attr( $address_field['name'] ),
372
-                                'id'         => esc_attr( $address_field['name'] ),
371
+                                'name'       => esc_attr($address_field['name']),
372
+                                'id'         => esc_attr($address_field['name']),
373 373
                                 'required'   => (bool) $address_field['required'],
374
-                                'label'      => wp_kses_post( $label ),
374
+                                'label'      => wp_kses_post($label),
375 375
                                 'no_wrap'    => true,
376 376
                                 'type'       => 'text',
377 377
                             )
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 
380 380
                 }
381 381
 
382
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
382
+                wp_send_json_success(str_replace('sr-only', '', $html));
383 383
                 exit;
384 384
 
385 385
             }
@@ -395,56 +395,56 @@  discard block
 block discarded – undo
395 395
     public static function recalculate_invoice_totals() {
396 396
 
397 397
         // Verify nonce.
398
-        check_ajax_referer( 'wpinv-nonce' );
398
+        check_ajax_referer('wpinv-nonce');
399 399
 
400
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
400
+        if (!wpinv_current_user_can_manage_invoicing()) {
401 401
             exit;
402 402
         }
403 403
 
404 404
         // We need an invoice.
405
-        if ( empty( $_POST['post_id'] ) ) {
405
+        if (empty($_POST['post_id'])) {
406 406
             exit;
407 407
         }
408 408
 
409 409
         // Fetch the invoice.
410
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
410
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
411 411
 
412 412
         // Ensure it exists.
413
-        if ( ! $invoice->get_id() ) {
413
+        if (!$invoice->get_id()) {
414 414
             exit;
415 415
         }
416 416
 
417 417
         // Maybe set the country, state, currency.
418
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
419
-            if ( isset( $_POST[ $key ] ) ) {
418
+        foreach (array('country', 'state', 'currency') as $key) {
419
+            if (isset($_POST[$key])) {
420 420
                 $method = "set_$key";
421
-                $invoice->$method( $_POST[ $key ] );
421
+                $invoice->$method($_POST[$key]);
422 422
             }
423 423
         }
424 424
 
425 425
         // Maybe disable taxes.
426
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
426
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
427 427
 
428 428
         // Recalculate totals.
429 429
         $invoice->recalculate_total();
430 430
 
431
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
431
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
432 432
 
433
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
434
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
435
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
433
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
434
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
435
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
436 436
         }
437 437
 
438 438
         $totals = array(
439
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
440
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
441
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
439
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
440
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
441
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
442 442
             'total'    => $total,
443 443
         );
444 444
 
445
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
445
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
446 446
 
447
-        wp_send_json_success( compact( 'totals' ) );
447
+        wp_send_json_success(compact('totals'));
448 448
     }
449 449
 
450 450
     /**
@@ -453,33 +453,33 @@  discard block
 block discarded – undo
453 453
     public static function get_invoice_items() {
454 454
 
455 455
         // Verify nonce.
456
-        check_ajax_referer( 'wpinv-nonce' );
456
+        check_ajax_referer('wpinv-nonce');
457 457
 
458
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
458
+        if (!wpinv_current_user_can_manage_invoicing()) {
459 459
             exit;
460 460
         }
461 461
 
462 462
         // We need an invoice and items.
463
-        if ( empty( $_POST['post_id'] ) ) {
463
+        if (empty($_POST['post_id'])) {
464 464
             exit;
465 465
         }
466 466
 
467 467
         // Fetch the invoice.
468
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
468
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
469 469
 
470 470
         // Ensure it exists.
471
-        if ( ! $invoice->get_id() ) {
471
+        if (!$invoice->get_id()) {
472 472
             exit;
473 473
         }
474 474
 
475 475
         // Return an array of invoice items.
476 476
         $items = array();
477 477
 
478
-        foreach ( $invoice->get_items() as $item_id => $item ) {
479
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
478
+        foreach ($invoice->get_items() as $item_id => $item) {
479
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
480 480
         }
481 481
 
482
-        wp_send_json_success( compact( 'items' ) );
482
+        wp_send_json_success(compact('items'));
483 483
     }
484 484
 
485 485
     /**
@@ -488,50 +488,50 @@  discard block
 block discarded – undo
488 488
     public static function edit_invoice_item() {
489 489
 
490 490
         // Verify nonce.
491
-        check_ajax_referer( 'wpinv-nonce' );
491
+        check_ajax_referer('wpinv-nonce');
492 492
 
493
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
493
+        if (!wpinv_current_user_can_manage_invoicing()) {
494 494
             exit;
495 495
         }
496 496
 
497 497
         // We need an invoice and item details.
498
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
498
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
499 499
             exit;
500 500
         }
501 501
 
502 502
         // Fetch the invoice.
503
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
503
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
504 504
 
505 505
         // Ensure it exists and its not been paid for.
506
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
506
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
507 507
             exit;
508 508
         }
509 509
 
510 510
         // Format the data.
511
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
511
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
512 512
 
513 513
         // Ensure that we have an item id.
514
-        if ( empty( $data['id'] ) ) {
514
+        if (empty($data['id'])) {
515 515
             exit;
516 516
         }
517 517
 
518 518
         // Abort if the invoice does not have the specified item.
519
-        $item = $invoice->get_item( (int) $data['id'] );
519
+        $item = $invoice->get_item((int) $data['id']);
520 520
 
521
-        if ( empty( $item ) ) {
521
+        if (empty($item)) {
522 522
             exit;
523 523
         }
524 524
 
525 525
         // Update the item.
526
-        $item->set_price( $data['price'] );
527
-        $item->set_name( $data['name'] );
528
-        $item->set_description( $data['description'] );
529
-        $item->set_quantity( $data['quantity'] );
526
+        $item->set_price($data['price']);
527
+        $item->set_name($data['name']);
528
+        $item->set_description($data['description']);
529
+        $item->set_quantity($data['quantity']);
530 530
 
531 531
         // Add it to the invoice.
532
-        $error = $invoice->add_item( $item );
532
+        $error = $invoice->add_item($item);
533 533
         $alert = false;
534
-        if ( is_wp_error( $error ) ) {
534
+        if (is_wp_error($error)) {
535 535
             $alert = $error->get_error_message();
536 536
         }
537 537
 
@@ -544,11 +544,11 @@  discard block
 block discarded – undo
544 544
         // Return an array of invoice items.
545 545
         $items = array();
546 546
 
547
-        foreach ( $invoice->get_items() as $item_id => $item ) {
548
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
547
+        foreach ($invoice->get_items() as $item_id => $item) {
548
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
549 549
         }
550 550
 
551
-        wp_send_json_success( compact( 'items', 'alert' ) );
551
+        wp_send_json_success(compact('items', 'alert'));
552 552
     }
553 553
 
554 554
     /**
@@ -557,33 +557,33 @@  discard block
 block discarded – undo
557 557
     public static function remove_invoice_item() {
558 558
 
559 559
         // Verify nonce.
560
-        check_ajax_referer( 'wpinv-nonce' );
560
+        check_ajax_referer('wpinv-nonce');
561 561
 
562
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
562
+        if (!wpinv_current_user_can_manage_invoicing()) {
563 563
             exit;
564 564
         }
565 565
 
566 566
         // We need an invoice and an item.
567
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
567
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
568 568
             exit;
569 569
         }
570 570
 
571 571
         // Fetch the invoice.
572
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
572
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
573 573
 
574 574
         // Ensure it exists and its not been paid for.
575
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
575
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
576 576
             exit;
577 577
         }
578 578
 
579 579
         // Abort if the invoice does not have the specified item.
580
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
580
+        $item = $invoice->get_item((int) $_POST['item_id']);
581 581
 
582
-        if ( empty( $item ) ) {
582
+        if (empty($item)) {
583 583
             exit;
584 584
         }
585 585
 
586
-        $invoice->remove_item( (int) $_POST['item_id'] );
586
+        $invoice->remove_item((int) $_POST['item_id']);
587 587
 
588 588
         // Update totals.
589 589
         $invoice->recalculate_total();
@@ -594,11 +594,11 @@  discard block
 block discarded – undo
594 594
         // Return an array of invoice items.
595 595
         $items = array();
596 596
 
597
-        foreach ( $invoice->get_items() as $item_id => $item ) {
598
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
597
+        foreach ($invoice->get_items() as $item_id => $item) {
598
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
599 599
         }
600 600
 
601
-        wp_send_json_success( compact( 'items' ) );
601
+        wp_send_json_success(compact('items'));
602 602
     }
603 603
 
604 604
     /**
@@ -607,39 +607,39 @@  discard block
 block discarded – undo
607 607
     public static function add_invoice_items() {
608 608
 
609 609
         // Verify nonce.
610
-        check_ajax_referer( 'wpinv-nonce' );
610
+        check_ajax_referer('wpinv-nonce');
611 611
 
612
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
612
+        if (!wpinv_current_user_can_manage_invoicing()) {
613 613
             exit;
614 614
         }
615 615
 
616 616
         // We need an invoice and items.
617
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
617
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
618 618
             exit;
619 619
         }
620 620
 
621 621
         // Fetch the invoice.
622
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
622
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
623 623
         $alert   = false;
624 624
 
625 625
         // Ensure it exists and its not been paid for.
626
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
626
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
627 627
             exit;
628 628
         }
629 629
 
630 630
         // Add the items.
631
-        foreach ( $_POST['items'] as $data ) {
631
+        foreach ($_POST['items'] as $data) {
632 632
 
633
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
633
+            $item = new GetPaid_Form_Item($data['id']);
634 634
 
635
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
636
-                $item->set_quantity( $data[ 'qty' ] );
635
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
636
+                $item->set_quantity($data['qty']);
637 637
             }
638 638
 
639
-            if ( $item->get_id() > 0 ) {
640
-                $error = $invoice->add_item( $item );
639
+            if ($item->get_id() > 0) {
640
+                $error = $invoice->add_item($item);
641 641
 
642
-                if ( is_wp_error( $error ) ) {
642
+                if (is_wp_error($error)) {
643 643
                     $alert = $error->get_error_message();
644 644
                 }
645 645
 
@@ -654,11 +654,11 @@  discard block
 block discarded – undo
654 654
         // Return an array of invoice items.
655 655
         $items = array();
656 656
 
657
-        foreach ( $invoice->get_items() as $item_id => $item ) {
658
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
657
+        foreach ($invoice->get_items() as $item_id => $item) {
658
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
659 659
         }
660 660
 
661
-        wp_send_json_success( compact( 'items', 'alert' ) );
661
+        wp_send_json_success(compact('items', 'alert'));
662 662
     }
663 663
 
664 664
     /**
@@ -667,15 +667,15 @@  discard block
 block discarded – undo
667 667
     public static function get_invoicing_items() {
668 668
 
669 669
         // Verify nonce.
670
-        check_ajax_referer( 'wpinv-nonce' );
670
+        check_ajax_referer('wpinv-nonce');
671 671
 
672
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
672
+        if (!wpinv_current_user_can_manage_invoicing()) {
673 673
             exit;
674 674
         }
675 675
 
676 676
         // We need a search term.
677
-        if ( empty( $_GET['search'] ) ) {
678
-            wp_send_json_success( array() );
677
+        if (empty($_GET['search'])) {
678
+            wp_send_json_success(array());
679 679
         }
680 680
 
681 681
         // Retrieve items.
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
             'orderby'        => 'title',
685 685
             'order'          => 'ASC',
686 686
             'posts_per_page' => -1,
687
-            'post_status'    => array( 'publish' ),
688
-            's'              => trim( $_GET['search'] ),
687
+            'post_status'    => array('publish'),
688
+            's'              => trim($_GET['search']),
689 689
             'meta_query'     => array(
690 690
                 array(
691 691
                     'key'       => '_wpinv_type',
@@ -695,14 +695,14 @@  discard block
 block discarded – undo
695 695
             )
696 696
         );
697 697
 
698
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
698
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
699 699
         $data  = array();
700 700
 
701 701
 
702
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
702
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
703 703
 
704
-        foreach ( $items as $item ) {
705
-            $item      = new GetPaid_Form_Item( $item );
704
+        foreach ($items as $item) {
705
+            $item = new GetPaid_Form_Item($item);
706 706
             $data[] = array(
707 707
                 'id'        => $item->get_id(),
708 708
                 'text'      => $item->get_name(),
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
             );
711 711
         }
712 712
 
713
-        wp_send_json_success( $data );
713
+        wp_send_json_success($data);
714 714
 
715 715
     }
716 716
 
@@ -720,24 +720,24 @@  discard block
 block discarded – undo
720 720
     public static function get_aui_states_field() {
721 721
 
722 722
         // Verify nonce.
723
-        check_ajax_referer( 'wpinv-nonce' );
723
+        check_ajax_referer('wpinv-nonce');
724 724
 
725 725
         // We need a country.
726
-        if ( empty( $_GET['country'] ) ) {
726
+        if (empty($_GET['country'])) {
727 727
             exit;
728 728
         }
729 729
 
730
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
731
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
730
+        $states = wpinv_get_country_states(trim($_GET['country']));
731
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
732 732
 
733
-        if ( empty( $states ) ) {
733
+        if (empty($states)) {
734 734
 
735 735
             $html = aui()->input(
736 736
                 array(
737 737
                     'type'        => 'text',
738 738
                     'id'          => 'wpinv_state',
739 739
                     'name'        => 'wpinv_state',
740
-                    'label'       => __( 'State', 'invoicing' ),
740
+                    'label'       => __('State', 'invoicing'),
741 741
                     'label_type'  => 'vertical',
742 742
                     'placeholder' => 'Liège',
743 743
                     'class'       => 'form-control-sm',
@@ -751,9 +751,9 @@  discard block
 block discarded – undo
751 751
                 array(
752 752
                     'id'          => 'wpinv_state',
753 753
                     'name'        => 'wpinv_state',
754
-                    'label'       => __( 'State', 'invoicing' ),
754
+                    'label'       => __('State', 'invoicing'),
755 755
                     'label_type'  => 'vertical',
756
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
756
+                    'placeholder' => __('Select a state', 'invoicing'),
757 757
                     'class'       => 'form-control-sm',
758 758
                     'value'       => $state,
759 759
                     'options'     => $states,
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
         wp_send_json_success(
768 768
             array(
769 769
                 'html'   => $html,
770
-                'select' => ! empty ( $states )
770
+                'select' => !empty ($states)
771 771
             )
772 772
         );
773 773
 
@@ -781,46 +781,46 @@  discard block
 block discarded – undo
781 781
     public static function ip_geolocation() {
782 782
 
783 783
         // Check nonce.
784
-        check_ajax_referer( 'getpaid-ip-location' );
784
+        check_ajax_referer('getpaid-ip-location');
785 785
 
786 786
         // IP address.
787
-        if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) {
788
-            _e( 'Invalid IP Address.', 'invoicing' );
787
+        if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) {
788
+            _e('Invalid IP Address.', 'invoicing');
789 789
             exit;
790 790
         }
791 791
 
792 792
         // Retrieve location info.
793
-        $location = getpaid_geolocate_ip_address( $_GET['ip'] );
793
+        $location = getpaid_geolocate_ip_address($_GET['ip']);
794 794
 
795
-        if ( empty( $location ) ) {
796
-            _e( 'Unable to find geolocation for the IP Address.', 'invoicing' );
795
+        if (empty($location)) {
796
+            _e('Unable to find geolocation for the IP Address.', 'invoicing');
797 797
             exit;
798 798
         }
799 799
 
800 800
         // Sorry.
801
-        extract( $location );
801
+        extract($location);
802 802
 
803 803
         // Prepare the address.
804 804
         $content = '';
805 805
 
806
-        if ( ! empty( $location['city'] ) ) {
807
-            $content .=  $location['city']  . ', ';
806
+        if (!empty($location['city'])) {
807
+            $content .= $location['city'] . ', ';
808 808
         }
809 809
         
810
-        if ( ! empty( $location['region'] ) ) {
811
-            $content .=  $location['region']  . ', ';
810
+        if (!empty($location['region'])) {
811
+            $content .= $location['region'] . ', ';
812 812
         }
813 813
         
814
-        $content .=  $location['country'] . ' (' . $location['iso'] . ')';
814
+        $content .= $location['country'] . ' (' . $location['iso'] . ')';
815 815
 
816 816
         $location['address'] = $content;
817 817
 
818
-        $content  = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>';
819
-        $content .= '<p>'. $location['credit'] . '</p>';
818
+        $content  = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>';
819
+        $content .= '<p>' . $location['credit'] . '</p>';
820 820
 
821 821
         $location['content'] = $content;
822 822
 
823
-        wpinv_get_template( 'geolocation.php', $location );
823
+        wpinv_get_template('geolocation.php', $location);
824 824
 
825 825
         exit;
826 826
     }
@@ -833,11 +833,11 @@  discard block
 block discarded – undo
833 833
     public static function payment_form_refresh_prices() {
834 834
 
835 835
         // Check nonce.
836
-        check_ajax_referer( 'getpaid_form_nonce' );
836
+        check_ajax_referer('getpaid_form_nonce');
837 837
 
838 838
         // ... form fields...
839
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
840
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
839
+        if (empty($_POST['getpaid_payment_form_submission'])) {
840
+            _e('Error: Reload the page and try again.', 'invoicing');
841 841
             exit;
842 842
         }
843 843
 
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
         $submission = new GetPaid_Payment_Form_Submission();
846 846
 
847 847
         // Do we have an error?
848
-        if ( ! empty( $submission->last_error ) ) {
848
+        if (!empty($submission->last_error)) {
849 849
             echo $submission->last_error;
850 850
             exit;
851 851
         }
@@ -858,43 +858,43 @@  discard block
 block discarded – undo
858 858
             'is_free'       => $submission->get_payment_details(),
859 859
 
860 860
             'totals'        => array(
861
-                'subtotal'  => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ),
862
-                'discount'  => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ),
863
-                'fees'      => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ),
864
-                'tax'       => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ),
865
-                'total'     => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
861
+                'subtotal'  => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()),
862
+                'discount'  => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()),
863
+                'fees'      => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()),
864
+                'tax'       => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()),
865
+                'total'     => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
866 866
             ),
867 867
 
868 868
             'texts'         => array(
869
-                '.getpaid-checkout-total-payable' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
869
+                '.getpaid-checkout-total-payable' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
870 870
             )
871 871
 
872 872
         );
873 873
 
874 874
         // Add items.
875 875
         $items = $submission->get_items();
876
-        if ( ! empty( $items ) ) {
876
+        if (!empty($items)) {
877 877
             $result['items'] = array();
878 878
 
879
-            foreach( $items as $item_id => $item ) {
880
-                $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_quantity() ) );
879
+            foreach ($items as $item_id => $item) {
880
+                $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_quantity()));
881 881
             }
882 882
         }
883 883
 
884 884
         // Add invoice.
885
-        if ( $submission->has_invoice() ) {
885
+        if ($submission->has_invoice()) {
886 886
             $result['invoice'] = $submission->get_invoice()->ID;
887 887
         }
888 888
 
889 889
         // Add discount code.
890
-        if ( $submission->has_discount_code() ) {
890
+        if ($submission->has_discount_code()) {
891 891
             $result['discount_code'] = $submission->get_discount_code();
892 892
         }
893 893
 
894 894
         // Filter the result.
895
-        $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission );
895
+        $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission);
896 896
 
897
-        wp_send_json_success( $result );
897
+        wp_send_json_success($result);
898 898
     }
899 899
 
900 900
     /**
@@ -905,53 +905,53 @@  discard block
 block discarded – undo
905 905
     public static function buy_items() {
906 906
         $user_id = get_current_user_id();
907 907
 
908
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
909
-            wp_send_json( array(
910
-                'success' => wp_login_url( wp_get_referer() )
911
-            ) );
908
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
909
+            wp_send_json(array(
910
+                'success' => wp_login_url(wp_get_referer())
911
+            ));
912 912
         } else {
913 913
             // Only check nonce if logged in as it could be cached when logged out.
914
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
915
-                wp_send_json( array(
916
-                    'error' => __( 'Security checks failed.', 'invoicing' )
917
-                ) );
914
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
915
+                wp_send_json(array(
916
+                    'error' => __('Security checks failed.', 'invoicing')
917
+                ));
918 918
                 wp_die();
919 919
             }
920 920
 
921 921
             // allow to set a custom price through post_id
922 922
             $items = $_POST['items'];
923
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
924
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
923
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
924
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
925 925
 
926 926
             $cart_items = array();
927
-            if ( $items ) {
928
-                $items = explode( ',', $items );
927
+            if ($items) {
928
+                $items = explode(',', $items);
929 929
 
930
-                foreach( $items as $item ) {
930
+                foreach ($items as $item) {
931 931
                     $item_id = $item;
932 932
                     $quantity = 1;
933 933
 
934
-                    if ( strpos( $item, '|' ) !== false ) {
935
-                        $item_parts = explode( '|', $item );
934
+                    if (strpos($item, '|') !== false) {
935
+                        $item_parts = explode('|', $item);
936 936
                         $item_id = $item_parts[0];
937 937
                         $quantity = $item_parts[1];
938 938
                     }
939 939
 
940
-                    if ( $item_id && $quantity ) {
940
+                    if ($item_id && $quantity) {
941 941
                         $cart_items_arr = array(
942
-                            'id'            => (int)$item_id,
943
-                            'quantity'      => (int)$quantity
942
+                            'id'            => (int) $item_id,
943
+                            'quantity'      => (int) $quantity
944 944
                         );
945 945
 
946 946
                         // If there is a related post id then add it to meta
947
-                        if ( $related_post_id ) {
947
+                        if ($related_post_id) {
948 948
                             $cart_items_arr['meta'] = array(
949 949
                                 'post_id'   => $related_post_id
950 950
                             );
951 951
                         }
952 952
 
953 953
                         // If there is a custom price then set it.
954
-                        if ( $custom_item_price ) {
954
+                        if ($custom_item_price) {
955 955
                             $cart_items_arr['custom_price'] = $custom_item_price;
956 956
                         }
957 957
 
@@ -967,37 +967,37 @@  discard block
 block discarded – undo
967 967
              * @param int $related_post_id The related post id if any.
968 968
              * @since 1.0.0
969 969
              */
970
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
970
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
971 971
 
972 972
             // Make sure its not in the cart already, if it is then redirect to checkout.
973 973
             $cart_invoice = wpinv_get_invoice_cart();
974 974
 
975
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
976
-                wp_send_json( array(
975
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
976
+                wp_send_json(array(
977 977
                     'success' =>  $cart_invoice->get_checkout_payment_url()
978
-                ) );
978
+                ));
979 979
                 wp_die();
980 980
             }
981 981
 
982 982
             // Check if user has invoice with same items waiting to be paid.
983
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
984
-            if ( !empty( $user_invoices ) ) {
985
-                foreach( $user_invoices as $user_invoice ) {
983
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
984
+            if (!empty($user_invoices)) {
985
+                foreach ($user_invoices as $user_invoice) {
986 986
                     $user_cart_details = array();
987
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
987
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
988 988
                     $cart_details = $invoice->get_cart_details();
989 989
 
990
-                    if ( !empty( $cart_details ) ) {
991
-                        foreach ( $cart_details as $invoice_item ) {
990
+                    if (!empty($cart_details)) {
991
+                        foreach ($cart_details as $invoice_item) {
992 992
                             $ii_arr = array();
993
-                            $ii_arr['id'] = (int)$invoice_item['id'];
994
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
993
+                            $ii_arr['id'] = (int) $invoice_item['id'];
994
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
995 995
 
996
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
996
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
997 997
                                 $ii_arr['meta'] = $invoice_item['meta'];
998 998
                             }
999 999
 
1000
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1000
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1001 1001
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1002 1002
                             }
1003 1003
 
@@ -1005,17 +1005,17 @@  discard block
 block discarded – undo
1005 1005
                         }
1006 1006
                     }
1007 1007
 
1008
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1009
-                        wp_send_json( array(
1008
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1009
+                        wp_send_json(array(
1010 1010
                             'success' =>  $invoice->get_checkout_payment_url()
1011
-                        ) );
1011
+                        ));
1012 1012
                         wp_die();
1013 1013
                     }
1014 1014
                 }
1015 1015
             }
1016 1016
 
1017 1017
             // Create invoice and send user to checkout
1018
-            if ( !empty( $cart_items ) ) {
1018
+            if (!empty($cart_items)) {
1019 1019
                 $invoice_data = array(
1020 1020
                     'status'        =>  'wpi-pending',
1021 1021
                     'created_via'   =>  'wpi',
@@ -1023,21 +1023,21 @@  discard block
 block discarded – undo
1023 1023
                     'cart_details'  =>  $cart_items,
1024 1024
                 );
1025 1025
 
1026
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1026
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1027 1027
 
1028
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1029
-                    wp_send_json( array(
1028
+                if (!empty($invoice) && isset($invoice->ID)) {
1029
+                    wp_send_json(array(
1030 1030
                         'success' =>  $invoice->get_checkout_payment_url()
1031
-                    ) );
1031
+                    ));
1032 1032
                 } else {
1033
-                    wp_send_json( array(
1034
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1035
-                    ) );
1033
+                    wp_send_json(array(
1034
+                        'error' => __('Invoice failed to create', 'invoicing')
1035
+                    ));
1036 1036
                 }
1037 1037
             } else {
1038
-                wp_send_json( array(
1039
-                    'error' => __( 'Items not valid.', 'invoicing' )
1040
-                ) );
1038
+                wp_send_json(array(
1039
+                    'error' => __('Items not valid.', 'invoicing')
1040
+                ));
1041 1041
             }
1042 1042
         }
1043 1043
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -12,168 +12,168 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Get the items and invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving( $invoice );
43
-
44
-		// Save the invoice.
45
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Get the items and invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving( $invoice );
43
+
44
+        // Save the invoice.
45
+        $invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48
-		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
50
-	}
48
+        // Send to the gateway.
49
+        $this->post_process_submission( $invoice, $prepared );
50
+    }
51 51
 
52
-	/**
53
-	 * Validates the submission.
54
-	 *
55
-	 */
56
-	protected function validate_submission() {
52
+    /**
53
+     * Validates the submission.
54
+     *
55
+     */
56
+    protected function validate_submission() {
57 57
 
58
-		$submission = $this->payment_form_submission;
59
-		$data       = $submission->get_data();
58
+        $submission = $this->payment_form_submission;
59
+        $data       = $submission->get_data();
60 60
 
61
-		// Do we have an error?
61
+        // Do we have an error?
62 62
         if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
63
+            wp_send_json_error( $submission->last_error );
64 64
         }
65 65
 
66
-		// We need a billing email.
66
+        // We need a billing email.
67 67
         if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
68 68
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
69
-		}
69
+        }
70 70
 
71
-		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
74
-		}
71
+        // Non-recurring gateways should not be allowed to process recurring invoices.
72
+        if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
74
+        }
75 75
 	
76
-		// Ensure the gateway is active.
77
-		if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
-		}
76
+        // Ensure the gateway is active.
77
+        if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
+        }
80 80
 
81
-		// Clear any existing errors.
82
-		wpinv_clear_errors();
81
+        // Clear any existing errors.
82
+        wpinv_clear_errors();
83 83
 		
84
-		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
84
+        // Allow themes and plugins to hook to errors
85
+        do_action( 'getpaid_checkout_error_checks', $submission );
86 86
 		
87
-		// Do we have any errors?
87
+        // Do we have any errors?
88 88
         if ( wpinv_get_errors() ) {
89 89
             wp_send_json_error( getpaid_get_errors_html() );
90
-		}
90
+        }
91 91
 
92
-	}
92
+    }
93 93
 
94
-	/**
95
-	 * Retrieves submission items.
96
-	 *
97
-	 * @return GetPaid_Form_Item[]
98
-	 */
99
-	protected function get_submission_items() {
94
+    /**
95
+     * Retrieves submission items.
96
+     *
97
+     * @return GetPaid_Form_Item[]
98
+     */
99
+    protected function get_submission_items() {
100 100
 
101
-		$items = $this->payment_form_submission->get_items();
101
+        $items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104 104
         if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) {
105 105
             wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) );
106
-		}
106
+        }
107 107
 
108
-		return $items;
109
-	}
108
+        return $items;
109
+    }
110 110
 
111
-	/**
112
-	 * Retrieves submission invoice.
113
-	 *
114
-	 * @return WPInv_Invoice
115
-	 */
116
-	protected function get_submission_invoice() {
117
-		$submission = $this->payment_form_submission;
111
+    /**
112
+     * Retrieves submission invoice.
113
+     *
114
+     * @return WPInv_Invoice
115
+     */
116
+    protected function get_submission_invoice() {
117
+        $submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
120
-			return new WPInv_Invoice();
119
+        if ( ! $submission->has_invoice() ) {
120
+            return new WPInv_Invoice();
121 121
         }
122 122
 
123
-		$invoice = $submission->get_invoice();
123
+        $invoice = $submission->get_invoice();
124 124
 
125
-		// Make sure that it is neither paid or refunded.
126
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
-		}
125
+        // Make sure that it is neither paid or refunded.
126
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
+        }
129 129
 
130
-		return $invoice;
131
-	}
130
+        return $invoice;
131
+    }
132 132
 
133
-	/**
134
-	 * Processes the submission invoice.
135
-	 *
136
-	 * @param WPInv_Invoice $invoice
137
-	 * @param GetPaid_Form_Item[] $items
138
-	 * @return WPInv_Invoice
139
-	 */
140
-	protected function process_submission_invoice( $invoice, $items ) {
133
+    /**
134
+     * Processes the submission invoice.
135
+     *
136
+     * @param WPInv_Invoice $invoice
137
+     * @param GetPaid_Form_Item[] $items
138
+     * @return WPInv_Invoice
139
+     */
140
+    protected function process_submission_invoice( $invoice, $items ) {
141 141
 
142
-		$submission = $this->payment_form_submission;
143
-		$data       = $submission->get_data();
142
+        $submission = $this->payment_form_submission;
143
+        $data       = $submission->get_data();
144 144
 
145
-		// Set-up the invoice details.
146
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
-		$invoice->set_user_id( $this->get_submission_customer() );
148
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
145
+        // Set-up the invoice details.
146
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
+        $invoice->set_user_id( $this->get_submission_customer() );
148
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
149 149
         $invoice->set_items( $items );
150 150
         $invoice->set_fees( $submission->get_fees() );
151 151
         $invoice->set_taxes( $submission->get_taxes() );
152
-		$invoice->set_discounts( $submission->get_discounts() );
153
-		$invoice->set_gateway( $data['wpi-gateway'] );
152
+        $invoice->set_discounts( $submission->get_discounts() );
153
+        $invoice->set_gateway( $data['wpi-gateway'] );
154 154
 
155
-		if ( $submission->has_discount_code() ) {
155
+        if ( $submission->has_discount_code() ) {
156 156
             $invoice->set_discount_code( $submission->get_discount_code() );
157
-		}
158
-
159
-		getpaid_maybe_add_default_address( $invoice );
160
-		return $invoice;
161
-	}
162
-
163
-	/**
164
-	 * Retrieves the submission's customer.
165
-	 *
166
-	 * @return int The customer id.
167
-	 */
168
-	protected function get_submission_customer() {
169
-		$submission = $this->payment_form_submission;
170
-
171
-		// If this is an existing invoice...
172
-		if ( $submission->has_invoice() ) {
173
-			return $submission->get_invoice()->get_user_id();
174
-		}
175
-
176
-		// (Maybe) create the user.
157
+        }
158
+
159
+        getpaid_maybe_add_default_address( $invoice );
160
+        return $invoice;
161
+    }
162
+
163
+    /**
164
+     * Retrieves the submission's customer.
165
+     *
166
+     * @return int The customer id.
167
+     */
168
+    protected function get_submission_customer() {
169
+        $submission = $this->payment_form_submission;
170
+
171
+        // If this is an existing invoice...
172
+        if ( $submission->has_invoice() ) {
173
+            return $submission->get_invoice()->get_user_id();
174
+        }
175
+
176
+        // (Maybe) create the user.
177 177
         $user = get_current_user_id();
178 178
 
179 179
         if ( empty( $user ) ) {
@@ -190,31 +190,31 @@  discard block
 block discarded – undo
190 190
 
191 191
         if ( is_numeric( $user ) ) {
192 192
             return $user;
193
-		}
193
+        }
194 194
 
195
-		return $user->ID;
195
+        return $user->ID;
196 196
 
197
-	}
197
+    }
198 198
 
199
-	/**
199
+    /**
200 200
      * Prepares submission data for saving to the database.
201 201
      *
202
-	 * @param WPInv_Invoice $invoice
202
+     * @param WPInv_Invoice $invoice
203 203
      */
204 204
     public function prepare_submission_data_for_saving( &$invoice ) {
205 205
 
206
-		$submission = $this->payment_form_submission;
206
+        $submission = $this->payment_form_submission;
207 207
 
208
-		// Prepared submission details.
208
+        // Prepared submission details.
209 209
         $prepared = array();
210 210
 
211 211
         // Raw submission details.
212
-		$data = $submission->get_data();
212
+        $data = $submission->get_data();
213 213
 		
214
-		// Loop throught the submitted details.
214
+        // Loop throught the submitted details.
215 215
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
216 216
 
217
-			// Skip premade fields.
217
+            // Skip premade fields.
218 218
             if ( ! empty( $field['premade'] ) ) {
219 219
                 continue;
220 220
             }
@@ -257,26 +257,26 @@  discard block
 block discarded – undo
257 257
                 $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
258 258
             }
259 259
 
260
-		}
260
+        }
261 261
 		
262
-		return $prepared;
262
+        return $prepared;
263 263
 
264
-	}
264
+    }
265 265
 
266
-	/**
267
-	 * Confirms the submission is valid and send users to the gateway.
268
-	 *
269
-	 * @param WPInv_Invoice $invoice
270
-	 * @param array $prepared_payment_form_data
271
-	 */
272
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
266
+    /**
267
+     * Confirms the submission is valid and send users to the gateway.
268
+     *
269
+     * @param WPInv_Invoice $invoice
270
+     * @param array $prepared_payment_form_data
271
+     */
272
+    protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
273 273
 
274
-		// Ensure the invoice exists.
274
+        // Ensure the invoice exists.
275 275
         if ( $invoice->get_id() == 0 ) {
276 276
             wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
277 277
         }
278 278
 
279
-		// Was this invoice created via the payment form?
279
+        // Was this invoice created via the payment form?
280 280
         if ( ! $this->payment_form_submission->has_invoice() ) {
281 281
             update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' );
282 282
         }
@@ -284,65 +284,65 @@  discard block
 block discarded – undo
284 284
         // Save payment form data.
285 285
         if ( ! empty( $prepared_payment_form_data ) ) {
286 286
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
287
-		}
287
+        }
288 288
 
289
-		// Backwards compatibility.
289
+        // Backwards compatibility.
290 290
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
291 291
 
292
-		$this->process_payment( $invoice );
292
+        $this->process_payment( $invoice );
293 293
 
294 294
         // If we are here, there was an error.
295
-		wpinv_send_back_to_checkout();
295
+        wpinv_send_back_to_checkout();
296 296
 
297
-	}
297
+    }
298 298
 
299
-	/**
300
-	 * Processes the actual payment.
301
-	 *
302
-	 * @param WPInv_Invoice $invoice
303
-	 */
304
-	protected function process_payment( $invoice ) {
299
+    /**
300
+     * Processes the actual payment.
301
+     *
302
+     * @param WPInv_Invoice $invoice
303
+     */
304
+    protected function process_payment( $invoice ) {
305 305
 
306
-		$submission = $this->payment_form_submission;
306
+        $submission = $this->payment_form_submission;
307 307
 
308
-		// No need to send free invoices to the gateway.
309
-		if ( $invoice->is_free() ) {
310
-			$invoice->set_gateway( 'none' );
311
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
312
-			$invoice->mark_paid();
313
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
314
-		}
308
+        // No need to send free invoices to the gateway.
309
+        if ( $invoice->is_free() ) {
310
+            $invoice->set_gateway( 'none' );
311
+            $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
312
+            $invoice->mark_paid();
313
+            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
314
+        }
315 315
 
316
-		// Clear any checkout errors.
317
-		wpinv_clear_errors();
316
+        // Clear any checkout errors.
317
+        wpinv_clear_errors();
318 318
 
319
-		// Fires before sending to the gateway.
320
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
319
+        // Fires before sending to the gateway.
320
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
321 321
 
322
-		// Allow the sumission data to be modified before it is sent to the gateway.
323
-		$submission_data    = $submission->get_data();
324
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
325
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
322
+        // Allow the sumission data to be modified before it is sent to the gateway.
323
+        $submission_data    = $submission->get_data();
324
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
325
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
326 326
 
327
-		// Validate the currency.
328
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
329
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
330
-		}
327
+        // Validate the currency.
328
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
329
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
330
+        }
331 331
 
332
-		// Check to see if we have any errors.
333
-		if ( wpinv_get_errors() ) {
334
-			wpinv_send_back_to_checkout();
335
-		}
332
+        // Check to see if we have any errors.
333
+        if ( wpinv_get_errors() ) {
334
+            wpinv_send_back_to_checkout();
335
+        }
336 336
 
337
-		// Send info to the gateway for payment processing
338
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
337
+        // Send info to the gateway for payment processing
338
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
339 339
 
340
-		// Backwards compatibility.
341
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
340
+        // Backwards compatibility.
341
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
342 342
 
343
-	}
343
+    }
344 344
 
345
-	/**
345
+    /**
346 346
      * Sends a redrect response to payment details.
347 347
      *
348 348
      */
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 		// Get the items and invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving( $invoice );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42
+		$prepared   = $this->prepare_submission_data_for_saving($invoice);
43 43
 
44 44
 		// Save the invoice.
45 45
 		$invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48 48
 		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
49
+		$this->post_process_submission($invoice, $prepared);
50 50
 	}
51 51
 
52 52
 	/**
@@ -59,34 +59,34 @@  discard block
 block discarded – undo
59 59
 		$data       = $submission->get_data();
60 60
 
61 61
 		// Do we have an error?
62
-        if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
62
+        if (!empty($submission->last_error)) {
63
+			wp_send_json_error($submission->last_error);
64 64
         }
65 65
 
66 66
 		// We need a billing email.
67
-        if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
68
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
67
+        if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) {
68
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
69 69
 		}
70 70
 
71 71
 		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
72
+		if ($submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
73
+			wp_send_json_error(__('The selected payment gateway does not support subscription payment.', 'invoicing'));
74 74
 		}
75 75
 	
76 76
 		// Ensure the gateway is active.
77
-		if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
77
+		if (!wpinv_is_gateway_active($data['wpi-gateway'])) {
78
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
79 79
 		}
80 80
 
81 81
 		// Clear any existing errors.
82 82
 		wpinv_clear_errors();
83 83
 		
84 84
 		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
85
+		do_action('getpaid_checkout_error_checks', $submission);
86 86
 		
87 87
 		// Do we have any errors?
88
-        if ( wpinv_get_errors() ) {
89
-            wp_send_json_error( getpaid_get_errors_html() );
88
+        if (wpinv_get_errors()) {
89
+            wp_send_json_error(getpaid_get_errors_html());
90 90
 		}
91 91
 
92 92
 	}
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 		$items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104
-        if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) {
105
-            wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) );
104
+        if (empty($items) && 0 == count($this->payment_form_submission->get_fees())) {
105
+            wp_send_json_error(__('Please select at least one item.', 'invoicing'));
106 106
 		}
107 107
 
108 108
 		return $items;
@@ -116,15 +116,15 @@  discard block
 block discarded – undo
116 116
 	protected function get_submission_invoice() {
117 117
 		$submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
119
+		if (!$submission->has_invoice()) {
120 120
 			return new WPInv_Invoice();
121 121
         }
122 122
 
123 123
 		$invoice = $submission->get_invoice();
124 124
 
125 125
 		// Make sure that it is neither paid or refunded.
126
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
126
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
127
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
128 128
 		}
129 129
 
130 130
 		return $invoice;
@@ -137,26 +137,26 @@  discard block
 block discarded – undo
137 137
 	 * @param GetPaid_Form_Item[] $items
138 138
 	 * @return WPInv_Invoice
139 139
 	 */
140
-	protected function process_submission_invoice( $invoice, $items ) {
140
+	protected function process_submission_invoice($invoice, $items) {
141 141
 
142 142
 		$submission = $this->payment_form_submission;
143 143
 		$data       = $submission->get_data();
144 144
 
145 145
 		// Set-up the invoice details.
146
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
-		$invoice->set_user_id( $this->get_submission_customer() );
148
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
149
-        $invoice->set_items( $items );
150
-        $invoice->set_fees( $submission->get_fees() );
151
-        $invoice->set_taxes( $submission->get_taxes() );
152
-		$invoice->set_discounts( $submission->get_discounts() );
153
-		$invoice->set_gateway( $data['wpi-gateway'] );
154
-
155
-		if ( $submission->has_discount_code() ) {
156
-            $invoice->set_discount_code( $submission->get_discount_code() );
146
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
147
+		$invoice->set_user_id($this->get_submission_customer());
148
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
149
+        $invoice->set_items($items);
150
+        $invoice->set_fees($submission->get_fees());
151
+        $invoice->set_taxes($submission->get_taxes());
152
+		$invoice->set_discounts($submission->get_discounts());
153
+		$invoice->set_gateway($data['wpi-gateway']);
154
+
155
+		if ($submission->has_discount_code()) {
156
+            $invoice->set_discount_code($submission->get_discount_code());
157 157
 		}
158 158
 
159
-		getpaid_maybe_add_default_address( $invoice );
159
+		getpaid_maybe_add_default_address($invoice);
160 160
 		return $invoice;
161 161
 	}
162 162
 
@@ -169,26 +169,26 @@  discard block
 block discarded – undo
169 169
 		$submission = $this->payment_form_submission;
170 170
 
171 171
 		// If this is an existing invoice...
172
-		if ( $submission->has_invoice() ) {
172
+		if ($submission->has_invoice()) {
173 173
 			return $submission->get_invoice()->get_user_id();
174 174
 		}
175 175
 
176 176
 		// (Maybe) create the user.
177 177
         $user = get_current_user_id();
178 178
 
179
-        if ( empty( $user ) ) {
180
-            $user = get_user_by( 'email', $submission->get_billing_email() );
179
+        if (empty($user)) {
180
+            $user = get_user_by('email', $submission->get_billing_email());
181 181
         }
182 182
 
183
-        if ( empty( $user ) ) {
184
-            $user = wpinv_create_user( $submission->get_billing_email() );
183
+        if (empty($user)) {
184
+            $user = wpinv_create_user($submission->get_billing_email());
185 185
         }
186 186
 
187
-        if ( is_wp_error( $user ) ) {
188
-            wp_send_json_error( $user->get_error_message() );
187
+        if (is_wp_error($user)) {
188
+            wp_send_json_error($user->get_error_message());
189 189
         }
190 190
 
191
-        if ( is_numeric( $user ) ) {
191
+        if (is_numeric($user)) {
192 192
             return $user;
193 193
 		}
194 194
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      *
202 202
 	 * @param WPInv_Invoice $invoice
203 203
      */
204
-    public function prepare_submission_data_for_saving( &$invoice ) {
204
+    public function prepare_submission_data_for_saving(&$invoice) {
205 205
 
206 206
 		$submission = $this->payment_form_submission;
207 207
 
@@ -212,49 +212,49 @@  discard block
 block discarded – undo
212 212
 		$data = $submission->get_data();
213 213
 		
214 214
 		// Loop throught the submitted details.
215
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
215
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
216 216
 
217 217
 			// Skip premade fields.
218
-            if ( ! empty( $field['premade'] ) ) {
218
+            if (!empty($field['premade'])) {
219 219
                 continue;
220 220
             }
221 221
 
222 222
             // If it is required and not set, abort.
223
-            if ( ! $submission->is_required_field_set( $field ) ) {
224
-                wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
223
+            if (!$submission->is_required_field_set($field)) {
224
+                wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
225 225
             }
226 226
 
227 227
             // Handle address fields.
228
-            if ( $field['type'] == 'address' ) {
228
+            if ($field['type'] == 'address') {
229 229
 
230
-                foreach ( $field['fields'] as $address_field ) {
230
+                foreach ($field['fields'] as $address_field) {
231 231
 
232 232
                     // skip if it is not visible.
233
-                    if ( empty( $address_field['visible'] ) ) {
233
+                    if (empty($address_field['visible'])) {
234 234
                         continue;
235 235
                     }
236 236
 
237 237
                     // If it is required and not set, abort
238
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
239
-                        wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
238
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
239
+                        wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
240 240
                     }
241 241
 
242
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
243
-                        $name   = str_replace( 'wpinv_', '', $address_field['name'] );
242
+                    if (isset($data[$address_field['name']])) {
243
+                        $name   = str_replace('wpinv_', '', $address_field['name']);
244 244
                         $method = "set_$name";
245
-                        $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) );
245
+                        $invoice->$method(wpinv_clean($data[$address_field['name']]));
246 246
                     }
247 247
 
248 248
                 }
249 249
 
250
-            } else if ( isset( $data[ $field['id'] ] ) ) {
250
+            } else if (isset($data[$field['id']])) {
251 251
                 $label = $field['id'];
252 252
 
253
-                if ( isset( $field['label'] ) ) {
253
+                if (isset($field['label'])) {
254 254
                     $label = $field['label'];
255 255
                 }
256 256
 
257
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
257
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
258 258
             }
259 259
 
260 260
 		}
@@ -269,27 +269,27 @@  discard block
 block discarded – undo
269 269
 	 * @param WPInv_Invoice $invoice
270 270
 	 * @param array $prepared_payment_form_data
271 271
 	 */
272
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
272
+	protected function post_process_submission($invoice, $prepared_payment_form_data) {
273 273
 
274 274
 		// Ensure the invoice exists.
275
-        if ( $invoice->get_id() == 0 ) {
276
-            wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
275
+        if ($invoice->get_id() == 0) {
276
+            wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing'));
277 277
         }
278 278
 
279 279
 		// Was this invoice created via the payment form?
280
-        if ( ! $this->payment_form_submission->has_invoice() ) {
281
-            update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' );
280
+        if (!$this->payment_form_submission->has_invoice()) {
281
+            update_post_meta($invoice->get_id(), 'wpinv_created_via', 'payment_form');
282 282
         }
283 283
 
284 284
         // Save payment form data.
285
-        if ( ! empty( $prepared_payment_form_data ) ) {
286
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
285
+        if (!empty($prepared_payment_form_data)) {
286
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
287 287
 		}
288 288
 
289 289
 		// Backwards compatibility.
290
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
290
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
291 291
 
292
-		$this->process_payment( $invoice );
292
+		$this->process_payment($invoice);
293 293
 
294 294
         // If we are here, there was an error.
295 295
 		wpinv_send_back_to_checkout();
@@ -301,44 +301,44 @@  discard block
 block discarded – undo
301 301
 	 *
302 302
 	 * @param WPInv_Invoice $invoice
303 303
 	 */
304
-	protected function process_payment( $invoice ) {
304
+	protected function process_payment($invoice) {
305 305
 
306 306
 		$submission = $this->payment_form_submission;
307 307
 
308 308
 		// No need to send free invoices to the gateway.
309
-		if ( $invoice->is_free() ) {
310
-			$invoice->set_gateway( 'none' );
311
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
309
+		if ($invoice->is_free()) {
310
+			$invoice->set_gateway('none');
311
+			$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
312 312
 			$invoice->mark_paid();
313
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
313
+			wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
314 314
 		}
315 315
 
316 316
 		// Clear any checkout errors.
317 317
 		wpinv_clear_errors();
318 318
 
319 319
 		// Fires before sending to the gateway.
320
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
320
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
321 321
 
322 322
 		// Allow the sumission data to be modified before it is sent to the gateway.
323 323
 		$submission_data    = $submission->get_data();
324
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
325
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
324
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
325
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
326 326
 
327 327
 		// Validate the currency.
328
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
329
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
328
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
329
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing'));
330 330
 		}
331 331
 
332 332
 		// Check to see if we have any errors.
333
-		if ( wpinv_get_errors() ) {
333
+		if (wpinv_get_errors()) {
334 334
 			wpinv_send_back_to_checkout();
335 335
 		}
336 336
 
337 337
 		// Send info to the gateway for payment processing
338
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
338
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
339 339
 
340 340
 		// Backwards compatibility.
341
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
341
+		wpinv_send_to_gateway($submission_gateway, $invoice);
342 342
 
343 343
 	}
344 344
 
@@ -346,9 +346,9 @@  discard block
 block discarded – undo
346 346
      * Sends a redrect response to payment details.
347 347
      *
348 348
      */
349
-    public function send_redirect_response( $url ) {
350
-        $url = urlencode( $url );
351
-        wp_send_json_success( $url );
349
+    public function send_redirect_response($url) {
350
+        $url = urlencode($url);
351
+        wp_send_json_success($url);
352 352
     }
353 353
 
354 354
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 2 patches
Indentation   +519 added lines, -519 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'               => 'draft',
34
-		'version'              => '',
35
-		'date_created'         => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'               => 'draft',
34
+        'version'              => '',
35
+        'date_created'         => null,
36 36
         'date_modified'        => null,
37 37
         'name'                 => '',
38 38
         'author'               => 1,
39 39
         'elements'             => null,
40
-		'items'                => null,
41
-		'earned'               => 0,
42
-		'refunded'             => 0,
43
-		'cancelled'            => 0,
44
-		'failed'               => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,349 +114,349 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'          => 'gtscicd',
237
-					'name'        => 'gtscicd',
238
-					'type'        => 'gateway_select',
239
-					'premade'     => true
234
+                $_elements[] = array(
235
+                    'text'        => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'          => 'gtscicd',
237
+                    'name'        => 'gtscicd',
238
+                    'type'        => 'gateway_select',
239
+                    'premade'     => true
240 240
 			
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266
+
267
+        // Convert the items.
268
+        $prepared = array();
266 269
 
267
-		// Convert the items.
268
-		$prepared = array();
270
+        foreach ( $items as $key => $value ) {
269 271
 
270
-		foreach ( $items as $key => $value ) {
272
+            // Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
271 274
 
272
-			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
274 278
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
279
+                continue;
278 280
 
279
-				continue;
281
+            }
280 282
 
281
-			}
283
+            // $item_id => $quantity
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
282 286
 
283
-			// $item_id => $quantity
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
287
+                if ( $item->can_purchase() ) {
288
+                    $item->set_quantity( $value );
289
+                    $prepared[] = $item;
290
+                }
286 291
 
287
-				if ( $item->can_purchase() ) {
288
-					$item->set_quantity( $value );
289
-					$prepared[] = $item;
290
-				}
292
+                continue;
293
+            }
291 294
 
292
-				continue;
293
-			}
295
+            // $item_id => array( 'price' => 10 )
296
+            if ( is_numeric( $key ) && is_array( $value ) ) {
297
+                $item = new GetPaid_Form_Item( $key );
294 298
 
295
-			// $item_id => array( 'price' => 10 )
296
-			if ( is_numeric( $key ) && is_array( $value ) ) {
297
-				$item = new GetPaid_Form_Item( $key );
299
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
300
+                    $item->set_price( $value['price'] );
301
+                }
298 302
 
299
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
300
-					$item->set_price( $value['price'] );
301
-				}
303
+                if ( $item->can_purchase() ) {
304
+                    $prepared[] = $item;
305
+                }
302 306
 
303
-				if ( $item->can_purchase() ) {
304
-					$prepared[] = $item;
305
-				}
307
+                continue;
308
+            }
306 309
 
307
-				continue;
308
-			}
310
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
309 311
 
310
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
312
+                $item = new GetPaid_Form_Item( $value['id'] );
311 313
 
312
-				$item = new GetPaid_Form_Item( $value['id'] );
314
+                if ( ! $item->can_purchase() ) {
315
+                    continue;
316
+                }
313 317
 
314
-				if ( ! $item->can_purchase() ) {
315
-					continue;
316
-				}
318
+                // Sub-total (Cart items).
319
+                if ( isset( $value['subtotal'] ) ) {
320
+                    $item->set_price( $value['subtotal'] );
321
+                }
317 322
 
318
-				// Sub-total (Cart items).
319
-				if ( isset( $value['subtotal'] ) ) {
320
-					$item->set_price( $value['subtotal'] );
321
-				}
323
+                if ( isset( $value['quantity'] ) ) {
324
+                    $item->set_quantity( $value['quantity'] );
325
+                }
326
+
327
+                if ( isset( $value['allow_quantities'] ) ) {
328
+                    $item->set_allow_quantities( $value['allow_quantities'] );
329
+                }
330
+
331
+                if ( isset( $value['required'] ) ) {
332
+                    $item->set_is_required( $value['required'] );
333
+                }
334
+
335
+                if ( isset( $value['description'] ) ) {
336
+                    $item->set_custom_description( $value['description'] );
337
+                }
338
+
339
+                $prepared[] = $item;
340
+                continue;
341
+
342
+            }
343
+        }
344
+
345
+        if ( 'objects' == $return && 'view' == $context ) {
346
+            return $prepared;
347
+        }
348
+
349
+        $items = array();
350
+        foreach ( $prepared as $item ) {
351
+            $items[] = $item->prepare_data_for_use();
352
+        }
353
+
354
+        return $items;
355
+    }
356
+
357
+    /**
358
+     * Get a single item belonging to the form.
359
+     *
360
+     * @since 1.0.19
361
+     * @param  int $item_id The item id to return.
362
+     * @return GetPaid_Form_Item|bool
363
+     */
364
+    public function get_item( $item_id ) {
365
+
366
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
367
+            return false;
368
+        }
369
+
370
+        foreach( $this->get_items() as $item ) {
371
+            if ( $item->get_id() == (int) $item_id ) {
372
+                return $item;
373
+            }
374
+        }
375
+
376
+        return false;
377
+
378
+    }
379
+
380
+    /**
381
+     * Gets a single element.
382
+     *
383
+     * @since 1.0.19
384
+     * @param  string $element_type The element type to return.
385
+     * @return array|bool
386
+     */
387
+    public function get_element_type( $element_type ) {
388
+
389
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
390
+            return false;
391
+        }
392
+
393
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
394
+
395
+            if ( $element['type'] == $element_type ) {
396
+                return $element;
397
+            }
398
+
399
+        }
400
+
401
+        return false;
402
+
403
+    }
404
+
405
+    /**
406
+     * Get the total amount earned via this form.
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return array
411
+     */
412
+    public function get_earned( $context = 'view' ) {
413
+        return $this->get_prop( 'earned', $context );
414
+    }
415
+
416
+    /**
417
+     * Get the total amount refunded via this form.
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return array
422
+     */
423
+    public function get_refunded( $context = 'view' ) {
424
+        return $this->get_prop( 'refunded', $context );
425
+    }
322 426
 
323
-				if ( isset( $value['quantity'] ) ) {
324
-					$item->set_quantity( $value['quantity'] );
325
-				}
427
+    /**
428
+     * Get the total amount cancelled via this form.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return array
433
+     */
434
+    public function get_cancelled( $context = 'view' ) {
435
+        return $this->get_prop( 'cancelled', $context );
436
+    }
326 437
 
327
-				if ( isset( $value['allow_quantities'] ) ) {
328
-					$item->set_allow_quantities( $value['allow_quantities'] );
329
-				}
438
+    /**
439
+     * Get the total amount failed via this form.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return array
444
+     */
445
+    public function get_failed( $context = 'view' ) {
446
+        return $this->get_prop( 'failed', $context );
447
+    }
330 448
 
331
-				if ( isset( $value['required'] ) ) {
332
-					$item->set_is_required( $value['required'] );
333
-				}
334
-
335
-				if ( isset( $value['description'] ) ) {
336
-					$item->set_custom_description( $value['description'] );
337
-				}
338
-
339
-				$prepared[] = $item;
340
-				continue;
341
-
342
-			}
343
-		}
344
-
345
-		if ( 'objects' == $return && 'view' == $context ) {
346
-			return $prepared;
347
-		}
348
-
349
-		$items = array();
350
-		foreach ( $prepared as $item ) {
351
-			$items[] = $item->prepare_data_for_use();
352
-		}
353
-
354
-		return $items;
355
-	}
356
-
357
-	/**
358
-	 * Get a single item belonging to the form.
359
-	 *
360
-	 * @since 1.0.19
361
-	 * @param  int $item_id The item id to return.
362
-	 * @return GetPaid_Form_Item|bool
363
-	 */
364
-	public function get_item( $item_id ) {
365
-
366
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
367
-			return false;
368
-		}
369
-
370
-		foreach( $this->get_items() as $item ) {
371
-			if ( $item->get_id() == (int) $item_id ) {
372
-				return $item;
373
-			}
374
-		}
375
-
376
-		return false;
377
-
378
-	}
379
-
380
-	/**
381
-	 * Gets a single element.
382
-	 *
383
-	 * @since 1.0.19
384
-	 * @param  string $element_type The element type to return.
385
-	 * @return array|bool
386
-	 */
387
-	public function get_element_type( $element_type ) {
388
-
389
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
390
-			return false;
391
-		}
392
-
393
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
394
-
395
-			if ( $element['type'] == $element_type ) {
396
-				return $element;
397
-			}
398
-
399
-		}
400
-
401
-		return false;
402
-
403
-	}
404
-
405
-	/**
406
-	 * Get the total amount earned via this form.
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return array
411
-	 */
412
-	public function get_earned( $context = 'view' ) {
413
-		return $this->get_prop( 'earned', $context );
414
-	}
415
-
416
-	/**
417
-	 * Get the total amount refunded via this form.
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return array
422
-	 */
423
-	public function get_refunded( $context = 'view' ) {
424
-		return $this->get_prop( 'refunded', $context );
425
-	}
426
-
427
-	/**
428
-	 * Get the total amount cancelled via this form.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return array
433
-	 */
434
-	public function get_cancelled( $context = 'view' ) {
435
-		return $this->get_prop( 'cancelled', $context );
436
-	}
437
-
438
-	/**
439
-	 * Get the total amount failed via this form.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return array
444
-	 */
445
-	public function get_failed( $context = 'view' ) {
446
-		return $this->get_prop( 'failed', $context );
447
-	}
448
-
449
-	/**
450
-	 * Get the currency.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return string
455
-	 */
456
-	public function get_currency() {
457
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
458
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
459
-	}
449
+    /**
450
+     * Get the currency.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return string
455
+     */
456
+    public function get_currency() {
457
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
458
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
459
+    }
460 460
 
461 461
     /*
462 462
 	|--------------------------------------------------------------------------
@@ -469,22 +469,22 @@  discard block
 block discarded – undo
469 469
     */
470 470
 
471 471
     /**
472
-	 * Set plugin version when the item was created.
473
-	 *
474
-	 * @since 1.0.19
475
-	 */
476
-	public function set_version( $value ) {
477
-		$this->set_prop( 'version', $value );
472
+     * Set plugin version when the item was created.
473
+     *
474
+     * @since 1.0.19
475
+     */
476
+    public function set_version( $value ) {
477
+        $this->set_prop( 'version', $value );
478 478
     }
479 479
 
480 480
     /**
481
-	 * Set date when the item was created.
482
-	 *
483
-	 * @since 1.0.19
484
-	 * @param string $value Value to set.
481
+     * Set date when the item was created.
482
+     *
483
+     * @since 1.0.19
484
+     * @param string $value Value to set.
485 485
      * @return bool Whether or not the date was set.
486
-	 */
487
-	public function set_date_created( $value ) {
486
+     */
487
+    public function set_date_created( $value ) {
488 488
         $date = strtotime( $value );
489 489
 
490 490
         if ( $date ) {
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
     }
498 498
 
499 499
     /**
500
-	 * Set date when the item was last modified.
501
-	 *
502
-	 * @since 1.0.19
503
-	 * @param string $value Value to set.
500
+     * Set date when the item was last modified.
501
+     *
502
+     * @since 1.0.19
503
+     * @param string $value Value to set.
504 504
      * @return bool Whether or not the date was set.
505
-	 */
506
-	public function set_date_modified( $value ) {
505
+     */
506
+    public function set_date_modified( $value ) {
507 507
         $date = strtotime( $value );
508 508
 
509 509
         if ( $date ) {
@@ -516,118 +516,118 @@  discard block
 block discarded – undo
516 516
     }
517 517
 
518 518
     /**
519
-	 * Set the item name.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  string $value New name.
523
-	 */
524
-	public function set_name( $value ) {
525
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
526
-    }
527
-
528
-    /**
529
-	 * Alias of self::set_name().
530
-	 *
531
-	 * @since 1.0.19
532
-	 * @param  string $value New name.
533
-	 */
534
-	public function set_title( $value ) {
535
-		$this->set_name( $value );
536
-    }
537
-
538
-    /**
539
-	 * Set the owner of the item.
540
-	 *
541
-	 * @since 1.0.19
542
-	 * @param  int $value New author.
543
-	 */
544
-	public function set_author( $value ) {
545
-		$this->set_prop( 'author', (int) $value );
546
-	}
547
-
548
-	/**
549
-	 * Set the form elements.
550
-	 *
551
-	 * @since 1.0.19
552
-	 * @param  array $value Form elements.
553
-	 */
554
-	public function set_elements( $value ) {
555
-		if ( is_array( $value ) ) {
556
-			$this->set_prop( 'elements', $value );
557
-		}
558
-	}
559
-
560
-	/**
561
-	 * Set the form items.
562
-	 *
563
-	 * @since 1.0.19
564
-	 * @param  array $value Form elements.
565
-	 */
566
-	public function set_items( $value ) {
567
-		if ( is_array( $value ) ) {
568
-			$this->set_prop( 'items', $value );
569
-		}
570
-	}
571
-
572
-	/**
573
-	 * Set the total amount earned via this form.
574
-	 *
575
-	 * @since 1.0.19
576
-	 * @param  float $value Amount earned.
577
-	 */
578
-	public function set_earned( $value ) {
579
-		$value = max( (float) $value, 0 );
580
-		$this->set_prop( 'earned', $value );
581
-	}
582
-
583
-	/**
584
-	 * Set the total amount refunded via this form.
585
-	 *
586
-	 * @since 1.0.19
587
-	 * @param  float $value Amount refunded.
588
-	 */
589
-	public function set_refunded( $value ) {
590
-		$value = max( (float) $value, 0 );
591
-		$this->set_prop( 'refunded', $value );
592
-	}
593
-
594
-	/**
595
-	 * Set the total amount cancelled via this form.
596
-	 *
597
-	 * @since 1.0.19
598
-	 * @param  float $value Amount cancelled.
599
-	 */
600
-	public function set_cancelled( $value ) {
601
-		$value = max( (float) $value, 0 );
602
-		$this->set_prop( 'cancelled', $value );
603
-	}
604
-
605
-	/**
606
-	 * Set the total amount failed via this form.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  float $value Amount cancelled.
610
-	 */
611
-	public function set_failed( $value ) {
612
-		$value = max( (float) $value, 0 );
613
-		$this->set_prop( 'failed', $value );
614
-	}
519
+     * Set the item name.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  string $value New name.
523
+     */
524
+    public function set_name( $value ) {
525
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
526
+    }
527
+
528
+    /**
529
+     * Alias of self::set_name().
530
+     *
531
+     * @since 1.0.19
532
+     * @param  string $value New name.
533
+     */
534
+    public function set_title( $value ) {
535
+        $this->set_name( $value );
536
+    }
537
+
538
+    /**
539
+     * Set the owner of the item.
540
+     *
541
+     * @since 1.0.19
542
+     * @param  int $value New author.
543
+     */
544
+    public function set_author( $value ) {
545
+        $this->set_prop( 'author', (int) $value );
546
+    }
547
+
548
+    /**
549
+     * Set the form elements.
550
+     *
551
+     * @since 1.0.19
552
+     * @param  array $value Form elements.
553
+     */
554
+    public function set_elements( $value ) {
555
+        if ( is_array( $value ) ) {
556
+            $this->set_prop( 'elements', $value );
557
+        }
558
+    }
559
+
560
+    /**
561
+     * Set the form items.
562
+     *
563
+     * @since 1.0.19
564
+     * @param  array $value Form elements.
565
+     */
566
+    public function set_items( $value ) {
567
+        if ( is_array( $value ) ) {
568
+            $this->set_prop( 'items', $value );
569
+        }
570
+    }
571
+
572
+    /**
573
+     * Set the total amount earned via this form.
574
+     *
575
+     * @since 1.0.19
576
+     * @param  float $value Amount earned.
577
+     */
578
+    public function set_earned( $value ) {
579
+        $value = max( (float) $value, 0 );
580
+        $this->set_prop( 'earned', $value );
581
+    }
582
+
583
+    /**
584
+     * Set the total amount refunded via this form.
585
+     *
586
+     * @since 1.0.19
587
+     * @param  float $value Amount refunded.
588
+     */
589
+    public function set_refunded( $value ) {
590
+        $value = max( (float) $value, 0 );
591
+        $this->set_prop( 'refunded', $value );
592
+    }
593
+
594
+    /**
595
+     * Set the total amount cancelled via this form.
596
+     *
597
+     * @since 1.0.19
598
+     * @param  float $value Amount cancelled.
599
+     */
600
+    public function set_cancelled( $value ) {
601
+        $value = max( (float) $value, 0 );
602
+        $this->set_prop( 'cancelled', $value );
603
+    }
604
+
605
+    /**
606
+     * Set the total amount failed via this form.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  float $value Amount cancelled.
610
+     */
611
+    public function set_failed( $value ) {
612
+        $value = max( (float) $value, 0 );
613
+        $this->set_prop( 'failed', $value );
614
+    }
615 615
 
616 616
     /**
617 617
      * Create an item. For backwards compatibilty.
618 618
      *
619 619
      * @deprecated
620
-	 * @return int item id
620
+     * @return int item id
621 621
      */
622 622
     public function create( $data = array() ) {
623 623
 
624
-		// Set the properties.
625
-		if ( is_array( $data ) ) {
626
-			$this->set_props( $data );
627
-		}
624
+        // Set the properties.
625
+        if ( is_array( $data ) ) {
626
+            $this->set_props( $data );
627
+        }
628 628
 
629
-		// Save the item.
630
-		return $this->save();
629
+        // Save the item.
630
+        return $this->save();
631 631
 
632 632
     }
633 633
 
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
      * Updates an item. For backwards compatibilty.
636 636
      *
637 637
      * @deprecated
638
-	 * @return int item id
638
+     * @return int item id
639 639
      */
640 640
     public function update( $data = array() ) {
641 641
         return $this->create( $data );
@@ -651,22 +651,22 @@  discard block
 block discarded – undo
651 651
 	*/
652 652
 
653 653
     /**
654
-	 * Checks whether this is the default payment form.
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @return bool
658
-	 */
654
+     * Checks whether this is the default payment form.
655
+     *
656
+     * @since 1.0.19
657
+     * @return bool
658
+     */
659 659
     public function is_default() {
660 660
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
661 661
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
662
-	}
662
+    }
663 663
 
664 664
     /**
665
-	 * Checks whether the form is active.
666
-	 *
667
-	 * @since 1.0.19
668
-	 * @return bool
669
-	 */
665
+     * Checks whether the form is active.
666
+     *
667
+     * @since 1.0.19
668
+     * @return bool
669
+     */
670 670
     public function is_active() {
671 671
         $is_active = 0 !== (int) $this->get_id();
672 672
 
@@ -675,70 +675,70 @@  discard block
 block discarded – undo
675 675
         }
676 676
 
677 677
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
678
-	}
679
-
680
-	/**
681
-	 * Checks whether the form has a given item.
682
-	 *
683
-	 * @since 1.0.19
684
-	 * @return bool
685
-	 */
678
+    }
679
+
680
+    /**
681
+     * Checks whether the form has a given item.
682
+     *
683
+     * @since 1.0.19
684
+     * @return bool
685
+     */
686 686
     public function has_item( $item_id ) {
687 687
         return false !== $this->get_item( $item_id );
688
-	}
689
-
690
-	/**
691
-	 * Checks whether the form has a given element.
692
-	 *
693
-	 * @since 1.0.19
694
-	 * @return bool
695
-	 */
688
+    }
689
+
690
+    /**
691
+     * Checks whether the form has a given element.
692
+     *
693
+     * @since 1.0.19
694
+     * @return bool
695
+     */
696 696
     public function has_element_type( $element_type ) {
697 697
         return false !== $this->get_element_type( $element_type );
698
-	}
699
-
700
-	/**
701
-	 * Checks whether this form is recurring or not.
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @return bool
705
-	 */
698
+    }
699
+
700
+    /**
701
+     * Checks whether this form is recurring or not.
702
+     *
703
+     * @since 1.0.19
704
+     * @return bool
705
+     */
706 706
     public function is_recurring() {
707 707
 
708
-		if ( ! empty( $this->invoice ) ) {
709
-			return $this->invoice->is_recurring();
710
-		}
708
+        if ( ! empty( $this->invoice ) ) {
709
+            return $this->invoice->is_recurring();
710
+        }
711 711
 
712
-		foreach ( $this->get_items() as $item ) {
712
+        foreach ( $this->get_items() as $item ) {
713 713
 
714
-			if ( $item->is_recurring() ) {
715
-				return true;
716
-			}
714
+            if ( $item->is_recurring() ) {
715
+                return true;
716
+            }
717 717
 
718
-		}
718
+        }
719 719
 
720 720
         return false;
721
-	}
721
+    }
722 722
 
723
-	/**
724
-	 * Retrieves the form's html.
725
-	 *
726
-	 * @since 1.0.19
727
-	 */
723
+    /**
724
+     * Retrieves the form's html.
725
+     *
726
+     * @since 1.0.19
727
+     */
728 728
     public function get_html() {
729 729
 
730
-		// Return the HTML.
731
-		return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
730
+        // Return the HTML.
731
+        return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
732 732
 
733
-	}
733
+    }
734 734
 
735
-	/**
736
-	 * Displays the payment form.
737
-	 *
738
-	 * @since 1.0.19
739
-	 */
735
+    /**
736
+     * Displays the payment form.
737
+     *
738
+     * @since 1.0.19
739
+     */
740 740
     public function display() {
741
-		echo $this->get_html();
741
+        echo $this->get_html();
742 742
     }
743 743
 
744 744
 }
Please login to merge, or discard this patch.
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
75
+	public function __construct($form = 0) {
76
+		parent::__construct($form);
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+		if (is_numeric($form) && $form > 0) {
79
+			$this->set_id($form);
80
+		} elseif ($form instanceof self) {
81 81
 
82
-			$this->set_id( $form->get_id() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 89
 		}
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
93 93
 
94
-		if ( $this->get_id() > 0 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 
99 99
 	}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param  string $context View or edit context.
121 121
 	 * @return string
122 122
 	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
123
+	public function get_version($context = 'view') {
124
+		return $this->get_prop('version', $context);
125 125
     }
126 126
 
127 127
     /**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
134
+	public function get_date_created($context = 'view') {
135
+		return $this->get_prop('date_created', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
146
-        $date = $this->get_date_created( $context );
145
+	public function get_date_created_gmt($context = 'view') {
146
+        $date = $this->get_date_created($context);
147 147
 
148
-        if ( $date ) {
149
-            $date = get_gmt_from_date( $date );
148
+        if ($date) {
149
+            $date = get_gmt_from_date($date);
150 150
         }
151 151
 		return $date;
152 152
     }
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param  string $context View or edit context.
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
161
+	public function get_date_modified($context = 'view') {
162
+		return $this->get_prop('date_modified', $context);
163 163
     }
164 164
 
165 165
     /**
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param  string $context View or edit context.
170 170
 	 * @return string
171 171
 	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
173
-        $date = $this->get_date_modified( $context );
172
+	public function get_date_modified_gmt($context = 'view') {
173
+        $date = $this->get_date_modified($context);
174 174
 
175
-        if ( $date ) {
176
-            $date = get_gmt_from_date( $date );
175
+        if ($date) {
176
+            $date = get_gmt_from_date($date);
177 177
         }
178 178
 		return $date;
179 179
     }
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  string $context View or edit context.
186 186
 	 * @return string
187 187
 	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
188
+	public function get_name($context = 'view') {
189
+		return $this->get_prop('name', $context);
190 190
     }
191 191
 
192 192
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param  string $context View or edit context.
197 197
 	 * @return string
198 198
 	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
199
+	public function get_title($context = 'view') {
200
+		return $this->get_name($context);
201 201
 	}
202 202
 
203 203
     /**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 * @param  string $context View or edit context.
208 208
 	 * @return int
209 209
 	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
210
+	public function get_author($context = 'view') {
211
+		return (int) $this->get_prop('author', $context);
212 212
     }
213 213
 
214 214
     /**
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return array
220 220
 	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
221
+	public function get_elements($context = 'view') {
222
+		$elements = $this->get_prop('elements', $context);
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
225
-            return wpinv_get_data( 'sample-payment-form' );
224
+		if (empty($elements) || !is_array($elements)) {
225
+            return wpinv_get_data('sample-payment-form');
226 226
 		}
227 227
 
228 228
 		// Ensure that all required elements exist.
229 229
 		$_elements = array();
230
-		foreach ( $elements as $element ) {
230
+		foreach ($elements as $element) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
233 233
 
234 234
 				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
235
+					'text'        => __('Select Payment Method', 'invoicing'),
236 236
 					'id'          => 'gtscicd',
237 237
 					'name'        => 'gtscicd',
238 238
 					'type'        => 'gateway_select',
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 	 * @param  string $return objects or arrays.
258 258
 	 * @return GetPaid_Form_Item[]
259 259
 	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
260
+	public function get_items($context = 'view', $return = 'objects') {
261
+		$items = $this->get_prop('items', $context);
262 262
 
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
264
-            $items = wpinv_get_data( 'sample-payment-form-items' );
263
+		if (empty($items) || !is_array($items)) {
264
+            $items = wpinv_get_data('sample-payment-form-items');
265 265
 		}
266 266
 
267 267
 		// Convert the items.
268 268
 		$prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+		foreach ($items as $key => $value) {
271 271
 
272 272
 			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
273
+			if ($value instanceof GetPaid_Form_Item) {
274 274
 
275
-				if ( $value->can_purchase() ) {
275
+				if ($value->can_purchase()) {
276 276
 					$prepared[] = $value;
277 277
 				}
278 278
 
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
 			}
282 282
 
283 283
 			// $item_id => $quantity
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
284
+			if (is_numeric($key) && is_numeric($value)) {
285
+				$item = new GetPaid_Form_Item($key);
286 286
 
287
-				if ( $item->can_purchase() ) {
288
-					$item->set_quantity( $value );
287
+				if ($item->can_purchase()) {
288
+					$item->set_quantity($value);
289 289
 					$prepared[] = $item;
290 290
 				}
291 291
 
@@ -293,47 +293,47 @@  discard block
 block discarded – undo
293 293
 			}
294 294
 
295 295
 			// $item_id => array( 'price' => 10 )
296
-			if ( is_numeric( $key ) && is_array( $value ) ) {
297
-				$item = new GetPaid_Form_Item( $key );
296
+			if (is_numeric($key) && is_array($value)) {
297
+				$item = new GetPaid_Form_Item($key);
298 298
 
299
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
300
-					$item->set_price( $value['price'] );
299
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
300
+					$item->set_price($value['price']);
301 301
 				}
302 302
 
303
-				if ( $item->can_purchase() ) {
303
+				if ($item->can_purchase()) {
304 304
 					$prepared[] = $item;
305 305
 				}
306 306
 
307 307
 				continue;
308 308
 			}
309 309
 
310
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
310
+			if (is_array($value) && isset($value['id'])) {
311 311
 
312
-				$item = new GetPaid_Form_Item( $value['id'] );
312
+				$item = new GetPaid_Form_Item($value['id']);
313 313
 
314
-				if ( ! $item->can_purchase() ) {
314
+				if (!$item->can_purchase()) {
315 315
 					continue;
316 316
 				}
317 317
 
318 318
 				// Sub-total (Cart items).
319
-				if ( isset( $value['subtotal'] ) ) {
320
-					$item->set_price( $value['subtotal'] );
319
+				if (isset($value['subtotal'])) {
320
+					$item->set_price($value['subtotal']);
321 321
 				}
322 322
 
323
-				if ( isset( $value['quantity'] ) ) {
324
-					$item->set_quantity( $value['quantity'] );
323
+				if (isset($value['quantity'])) {
324
+					$item->set_quantity($value['quantity']);
325 325
 				}
326 326
 
327
-				if ( isset( $value['allow_quantities'] ) ) {
328
-					$item->set_allow_quantities( $value['allow_quantities'] );
327
+				if (isset($value['allow_quantities'])) {
328
+					$item->set_allow_quantities($value['allow_quantities']);
329 329
 				}
330 330
 
331
-				if ( isset( $value['required'] ) ) {
332
-					$item->set_is_required( $value['required'] );
331
+				if (isset($value['required'])) {
332
+					$item->set_is_required($value['required']);
333 333
 				}
334 334
 
335
-				if ( isset( $value['description'] ) ) {
336
-					$item->set_custom_description( $value['description'] );
335
+				if (isset($value['description'])) {
336
+					$item->set_custom_description($value['description']);
337 337
 				}
338 338
 
339 339
 				$prepared[] = $item;
@@ -342,12 +342,12 @@  discard block
 block discarded – undo
342 342
 			}
343 343
 		}
344 344
 
345
-		if ( 'objects' == $return && 'view' == $context ) {
345
+		if ('objects' == $return && 'view' == $context) {
346 346
 			return $prepared;
347 347
 		}
348 348
 
349 349
 		$items = array();
350
-		foreach ( $prepared as $item ) {
350
+		foreach ($prepared as $item) {
351 351
 			$items[] = $item->prepare_data_for_use();
352 352
 		}
353 353
 
@@ -361,14 +361,14 @@  discard block
 block discarded – undo
361 361
 	 * @param  int $item_id The item id to return.
362 362
 	 * @return GetPaid_Form_Item|bool
363 363
 	 */
364
-	public function get_item( $item_id ) {
364
+	public function get_item($item_id) {
365 365
 
366
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
366
+		if (empty($item_id) || !is_numeric($item_id)) {
367 367
 			return false;
368 368
 		}
369 369
 
370
-		foreach( $this->get_items() as $item ) {
371
-			if ( $item->get_id() == (int) $item_id ) {
370
+		foreach ($this->get_items() as $item) {
371
+			if ($item->get_id() == (int) $item_id) {
372 372
 				return $item;
373 373
 			}
374 374
 		}
@@ -384,15 +384,15 @@  discard block
 block discarded – undo
384 384
 	 * @param  string $element_type The element type to return.
385 385
 	 * @return array|bool
386 386
 	 */
387
-	public function get_element_type( $element_type ) {
387
+	public function get_element_type($element_type) {
388 388
 
389
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
389
+		if (empty($element_type) || !is_scalar($element_type)) {
390 390
 			return false;
391 391
 		}
392 392
 
393
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
393
+		foreach ($this->get_prop('elements') as $element) {
394 394
 
395
-			if ( $element['type'] == $element_type ) {
395
+			if ($element['type'] == $element_type) {
396 396
 				return $element;
397 397
 			}
398 398
 
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 * @param  string $context View or edit context.
410 410
 	 * @return array
411 411
 	 */
412
-	public function get_earned( $context = 'view' ) {
413
-		return $this->get_prop( 'earned', $context );
412
+	public function get_earned($context = 'view') {
413
+		return $this->get_prop('earned', $context);
414 414
 	}
415 415
 
416 416
 	/**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $context View or edit context.
421 421
 	 * @return array
422 422
 	 */
423
-	public function get_refunded( $context = 'view' ) {
424
-		return $this->get_prop( 'refunded', $context );
423
+	public function get_refunded($context = 'view') {
424
+		return $this->get_prop('refunded', $context);
425 425
 	}
426 426
 
427 427
 	/**
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @param  string $context View or edit context.
432 432
 	 * @return array
433 433
 	 */
434
-	public function get_cancelled( $context = 'view' ) {
435
-		return $this->get_prop( 'cancelled', $context );
434
+	public function get_cancelled($context = 'view') {
435
+		return $this->get_prop('cancelled', $context);
436 436
 	}
437 437
 
438 438
 	/**
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param  string $context View or edit context.
443 443
 	 * @return array
444 444
 	 */
445
-	public function get_failed( $context = 'view' ) {
446
-		return $this->get_prop( 'failed', $context );
445
+	public function get_failed($context = 'view') {
446
+		return $this->get_prop('failed', $context);
447 447
 	}
448 448
 
449 449
 	/**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @return string
455 455
 	 */
456 456
 	public function get_currency() {
457
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
458
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
457
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
458
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
459 459
 	}
460 460
 
461 461
     /*
@@ -473,8 +473,8 @@  discard block
 block discarded – undo
473 473
 	 *
474 474
 	 * @since 1.0.19
475 475
 	 */
476
-	public function set_version( $value ) {
477
-		$this->set_prop( 'version', $value );
476
+	public function set_version($value) {
477
+		$this->set_prop('version', $value);
478 478
     }
479 479
 
480 480
     /**
@@ -484,11 +484,11 @@  discard block
 block discarded – undo
484 484
 	 * @param string $value Value to set.
485 485
      * @return bool Whether or not the date was set.
486 486
 	 */
487
-	public function set_date_created( $value ) {
488
-        $date = strtotime( $value );
487
+	public function set_date_created($value) {
488
+        $date = strtotime($value);
489 489
 
490
-        if ( $date ) {
491
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
490
+        if ($date) {
491
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
492 492
             return true;
493 493
         }
494 494
 
@@ -503,11 +503,11 @@  discard block
 block discarded – undo
503 503
 	 * @param string $value Value to set.
504 504
      * @return bool Whether or not the date was set.
505 505
 	 */
506
-	public function set_date_modified( $value ) {
507
-        $date = strtotime( $value );
506
+	public function set_date_modified($value) {
507
+        $date = strtotime($value);
508 508
 
509
-        if ( $date ) {
510
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
509
+        if ($date) {
510
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
511 511
             return true;
512 512
         }
513 513
 
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
 	 * @since 1.0.19
522 522
 	 * @param  string $value New name.
523 523
 	 */
524
-	public function set_name( $value ) {
525
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
524
+	public function set_name($value) {
525
+		$this->set_prop('name', sanitize_text_field($value));
526 526
     }
527 527
 
528 528
     /**
@@ -531,8 +531,8 @@  discard block
 block discarded – undo
531 531
 	 * @since 1.0.19
532 532
 	 * @param  string $value New name.
533 533
 	 */
534
-	public function set_title( $value ) {
535
-		$this->set_name( $value );
534
+	public function set_title($value) {
535
+		$this->set_name($value);
536 536
     }
537 537
 
538 538
     /**
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 	 * @since 1.0.19
542 542
 	 * @param  int $value New author.
543 543
 	 */
544
-	public function set_author( $value ) {
545
-		$this->set_prop( 'author', (int) $value );
544
+	public function set_author($value) {
545
+		$this->set_prop('author', (int) $value);
546 546
 	}
547 547
 
548 548
 	/**
@@ -551,9 +551,9 @@  discard block
 block discarded – undo
551 551
 	 * @since 1.0.19
552 552
 	 * @param  array $value Form elements.
553 553
 	 */
554
-	public function set_elements( $value ) {
555
-		if ( is_array( $value ) ) {
556
-			$this->set_prop( 'elements', $value );
554
+	public function set_elements($value) {
555
+		if (is_array($value)) {
556
+			$this->set_prop('elements', $value);
557 557
 		}
558 558
 	}
559 559
 
@@ -563,9 +563,9 @@  discard block
 block discarded – undo
563 563
 	 * @since 1.0.19
564 564
 	 * @param  array $value Form elements.
565 565
 	 */
566
-	public function set_items( $value ) {
567
-		if ( is_array( $value ) ) {
568
-			$this->set_prop( 'items', $value );
566
+	public function set_items($value) {
567
+		if (is_array($value)) {
568
+			$this->set_prop('items', $value);
569 569
 		}
570 570
 	}
571 571
 
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
 	 * @since 1.0.19
576 576
 	 * @param  float $value Amount earned.
577 577
 	 */
578
-	public function set_earned( $value ) {
579
-		$value = max( (float) $value, 0 );
580
-		$this->set_prop( 'earned', $value );
578
+	public function set_earned($value) {
579
+		$value = max((float) $value, 0);
580
+		$this->set_prop('earned', $value);
581 581
 	}
582 582
 
583 583
 	/**
@@ -586,9 +586,9 @@  discard block
 block discarded – undo
586 586
 	 * @since 1.0.19
587 587
 	 * @param  float $value Amount refunded.
588 588
 	 */
589
-	public function set_refunded( $value ) {
590
-		$value = max( (float) $value, 0 );
591
-		$this->set_prop( 'refunded', $value );
589
+	public function set_refunded($value) {
590
+		$value = max((float) $value, 0);
591
+		$this->set_prop('refunded', $value);
592 592
 	}
593 593
 
594 594
 	/**
@@ -597,9 +597,9 @@  discard block
 block discarded – undo
597 597
 	 * @since 1.0.19
598 598
 	 * @param  float $value Amount cancelled.
599 599
 	 */
600
-	public function set_cancelled( $value ) {
601
-		$value = max( (float) $value, 0 );
602
-		$this->set_prop( 'cancelled', $value );
600
+	public function set_cancelled($value) {
601
+		$value = max((float) $value, 0);
602
+		$this->set_prop('cancelled', $value);
603 603
 	}
604 604
 
605 605
 	/**
@@ -608,9 +608,9 @@  discard block
 block discarded – undo
608 608
 	 * @since 1.0.19
609 609
 	 * @param  float $value Amount cancelled.
610 610
 	 */
611
-	public function set_failed( $value ) {
612
-		$value = max( (float) $value, 0 );
613
-		$this->set_prop( 'failed', $value );
611
+	public function set_failed($value) {
612
+		$value = max((float) $value, 0);
613
+		$this->set_prop('failed', $value);
614 614
 	}
615 615
 
616 616
     /**
@@ -619,11 +619,11 @@  discard block
 block discarded – undo
619 619
      * @deprecated
620 620
 	 * @return int item id
621 621
      */
622
-    public function create( $data = array() ) {
622
+    public function create($data = array()) {
623 623
 
624 624
 		// Set the properties.
625
-		if ( is_array( $data ) ) {
626
-			$this->set_props( $data );
625
+		if (is_array($data)) {
626
+			$this->set_props($data);
627 627
 		}
628 628
 
629 629
 		// Save the item.
@@ -637,8 +637,8 @@  discard block
 block discarded – undo
637 637
      * @deprecated
638 638
 	 * @return int item id
639 639
      */
640
-    public function update( $data = array() ) {
641
-        return $this->create( $data );
640
+    public function update($data = array()) {
641
+        return $this->create($data);
642 642
     }
643 643
 
644 644
     /*
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 	 */
659 659
     public function is_default() {
660 660
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
661
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
661
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
662 662
 	}
663 663
 
664 664
     /**
@@ -670,11 +670,11 @@  discard block
 block discarded – undo
670 670
     public function is_active() {
671 671
         $is_active = 0 !== (int) $this->get_id();
672 672
 
673
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
673
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
674 674
             $is_active = false;
675 675
         }
676 676
 
677
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
677
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
678 678
 	}
679 679
 
680 680
 	/**
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
 	 * @since 1.0.19
684 684
 	 * @return bool
685 685
 	 */
686
-    public function has_item( $item_id ) {
687
-        return false !== $this->get_item( $item_id );
686
+    public function has_item($item_id) {
687
+        return false !== $this->get_item($item_id);
688 688
 	}
689 689
 
690 690
 	/**
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	 * @since 1.0.19
694 694
 	 * @return bool
695 695
 	 */
696
-    public function has_element_type( $element_type ) {
697
-        return false !== $this->get_element_type( $element_type );
696
+    public function has_element_type($element_type) {
697
+        return false !== $this->get_element_type($element_type);
698 698
 	}
699 699
 
700 700
 	/**
@@ -705,13 +705,13 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
     public function is_recurring() {
707 707
 
708
-		if ( ! empty( $this->invoice ) ) {
708
+		if (!empty($this->invoice)) {
709 709
 			return $this->invoice->is_recurring();
710 710
 		}
711 711
 
712
-		foreach ( $this->get_items() as $item ) {
712
+		foreach ($this->get_items() as $item) {
713 713
 
714
-			if ( $item->is_recurring() ) {
714
+			if ($item->is_recurring()) {
715 715
 				return true;
716 716
 			}
717 717
 
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
     public function get_html() {
729 729
 
730 730
 		// Return the HTML.
731
-		return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
731
+		return wpinv_get_template_html('payment-forms/form.php', array('form' => $this));
732 732
 
733 733
 	}
734 734
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-forms.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -13,128 +13,128 @@
 block discarded – undo
13 13
 class GetPaid_Payment_Forms {
14 14
 
15 15
     /**
16
-	 * Class constructor
17
-	 *
18
-	 */
19
-	public function __construct() {
20
-
21
-		// Update a payment form's revenue whenever an invoice is paid for or refunded.
22
-		add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) );
23
-		add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) );
24
-
25
-		// Sync form amount whenever invoice statuses change.
26
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 );
27
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 );
28
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 );
29
-
30
-	}
31
-
32
-	/**
33
-	 * Increments a form's revenue whenever there is a payment.
34
-	 *
35
-	 * @param WPInv_Invoice $invoice
36
-	 */
37
-	public function increment_form_revenue( $invoice ) {
38
-
39
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
40
-		if ( $form->get_id() ) {
41
-			$form->set_earned( $form->get_earned() + $invoice->get_total() );
42
-			$form->save();
43
-		}
44
-
45
-	}
46
-
47
-	/**
48
-	 * Decreases form revenue whenever invoice payment changes.
49
-	 *
50
-	 * @param WPInv_Invoice $invoice
51
-	 */
52
-	public function decrease_form_revenue( $invoice ) {
53
-
54
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
55
-		if ( $form->get_id() ) {
56
-			$form->set_earned( $form->get_earned() - $invoice->get_total() );
57
-			$form->save();
58
-		}
59
-
60
-	}
61
-
62
-	/**
63
-	 * Updates a form's failed amount.
64
-	 *
65
-	 * @param WPInv_Invoice $invoice
66
-	 * @param string $from
67
-	 * @param string $to
68
-	 */
69
-	public function update_form_failed_amount( $invoice, $from, $to ) {
70
-
71
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
72
-		if ( $form->get_id() ) {
73
-			return;
74
-		}
75
-
76
-		if ( 'wpi-failed' == $from ) {
77
-			$form->set_failed( $form->get_failed() - $invoice->get_total() );
78
-			$form->save();
79
-		}
80
-
81
-		if ( 'wpi-failed' == $to ) {
82
-			$form->set_failed( $form->get_failed() + $invoice->get_total() );
83
-			$form->save();
84
-		}
85
-
86
-	}
87
-
88
-	/**
89
-	 * Updates a form's refunded amount.
90
-	 *
91
-	 * @param WPInv_Invoice $invoice
92
-	 * @param string $from
93
-	 * @param string $to
94
-	 */
95
-	public function update_form_refunded_amount( $invoice, $from, $to ) {
96
-
97
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
98
-		if ( $form->get_id() ) {
99
-			return;
100
-		}
101
-
102
-		if ( 'wpi-refunded' == $from ) {
103
-			$form->set_refunded( $form->get_refunded() - $invoice->get_total() );
104
-			$form->save();
105
-		}
106
-
107
-		if ( 'wpi-refunded' == $to ) {
108
-			$form->set_refunded( $form->get_refunded() + $invoice->get_total() );
109
-			$form->save();
110
-		}
111
-
112
-	}
113
-
114
-	/**
115
-	 * Updates a form's cancelled amount.
116
-	 *
117
-	 * @param WPInv_Invoice $invoice
118
-	 * @param string $from
119
-	 * @param string $to
120
-	 */
121
-	public function update_form_cancelled_amount( $invoice, $from, $to ) {
122
-
123
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
124
-		if ( $form->get_id() ) {
125
-			return;
126
-		}
127
-
128
-		if ( 'wpi-cancelled' == $from ) {
129
-			$form->set_cancelled( $form->get_cancelled() - $invoice->get_total() );
130
-			$form->save();
131
-		}
132
-
133
-		if ( 'wpi-cancelled' == $to ) {
134
-			$form->set_cancelled( $form->get_cancelled() + $invoice->get_total() );
135
-			$form->save();
136
-		}
137
-
138
-	}
16
+     * Class constructor
17
+     *
18
+     */
19
+    public function __construct() {
20
+
21
+        // Update a payment form's revenue whenever an invoice is paid for or refunded.
22
+        add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) );
23
+        add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) );
24
+
25
+        // Sync form amount whenever invoice statuses change.
26
+        add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 );
27
+        add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 );
28
+        add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 );
29
+
30
+    }
31
+
32
+    /**
33
+     * Increments a form's revenue whenever there is a payment.
34
+     *
35
+     * @param WPInv_Invoice $invoice
36
+     */
37
+    public function increment_form_revenue( $invoice ) {
38
+
39
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
40
+        if ( $form->get_id() ) {
41
+            $form->set_earned( $form->get_earned() + $invoice->get_total() );
42
+            $form->save();
43
+        }
44
+
45
+    }
46
+
47
+    /**
48
+     * Decreases form revenue whenever invoice payment changes.
49
+     *
50
+     * @param WPInv_Invoice $invoice
51
+     */
52
+    public function decrease_form_revenue( $invoice ) {
53
+
54
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
55
+        if ( $form->get_id() ) {
56
+            $form->set_earned( $form->get_earned() - $invoice->get_total() );
57
+            $form->save();
58
+        }
59
+
60
+    }
61
+
62
+    /**
63
+     * Updates a form's failed amount.
64
+     *
65
+     * @param WPInv_Invoice $invoice
66
+     * @param string $from
67
+     * @param string $to
68
+     */
69
+    public function update_form_failed_amount( $invoice, $from, $to ) {
70
+
71
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
72
+        if ( $form->get_id() ) {
73
+            return;
74
+        }
75
+
76
+        if ( 'wpi-failed' == $from ) {
77
+            $form->set_failed( $form->get_failed() - $invoice->get_total() );
78
+            $form->save();
79
+        }
80
+
81
+        if ( 'wpi-failed' == $to ) {
82
+            $form->set_failed( $form->get_failed() + $invoice->get_total() );
83
+            $form->save();
84
+        }
85
+
86
+    }
87
+
88
+    /**
89
+     * Updates a form's refunded amount.
90
+     *
91
+     * @param WPInv_Invoice $invoice
92
+     * @param string $from
93
+     * @param string $to
94
+     */
95
+    public function update_form_refunded_amount( $invoice, $from, $to ) {
96
+
97
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
98
+        if ( $form->get_id() ) {
99
+            return;
100
+        }
101
+
102
+        if ( 'wpi-refunded' == $from ) {
103
+            $form->set_refunded( $form->get_refunded() - $invoice->get_total() );
104
+            $form->save();
105
+        }
106
+
107
+        if ( 'wpi-refunded' == $to ) {
108
+            $form->set_refunded( $form->get_refunded() + $invoice->get_total() );
109
+            $form->save();
110
+        }
111
+
112
+    }
113
+
114
+    /**
115
+     * Updates a form's cancelled amount.
116
+     *
117
+     * @param WPInv_Invoice $invoice
118
+     * @param string $from
119
+     * @param string $to
120
+     */
121
+    public function update_form_cancelled_amount( $invoice, $from, $to ) {
122
+
123
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
124
+        if ( $form->get_id() ) {
125
+            return;
126
+        }
127
+
128
+        if ( 'wpi-cancelled' == $from ) {
129
+            $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() );
130
+            $form->save();
131
+        }
132
+
133
+        if ( 'wpi-cancelled' == $to ) {
134
+            $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() );
135
+            $form->save();
136
+        }
137
+
138
+    }
139 139
 
140 140
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment forms controller class
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
 	public function __construct() {
20 20
 
21 21
 		// Update a payment form's revenue whenever an invoice is paid for or refunded.
22
-		add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) );
23
-		add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) );
22
+		add_action('getpaid_invoice_payment_status_changed', array($this, 'increment_form_revenue'));
23
+		add_action('getpaid_invoice_payment_status_reversed', array($this, 'decrease_form_revenue'));
24 24
 
25 25
 		// Sync form amount whenever invoice statuses change.
26
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 );
27
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 );
28
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 );
26
+		add_action('getpaid_invoice_status_changed', array($this, 'update_form_failed_amount'), 10, 3);
27
+		add_action('getpaid_invoice_status_changed', array($this, 'update_form_refunded_amount'), 10, 3);
28
+		add_action('getpaid_invoice_status_changed', array($this, 'update_form_cancelled_amount'), 10, 3);
29 29
 
30 30
 	}
31 31
 
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param WPInv_Invoice $invoice
36 36
 	 */
37
-	public function increment_form_revenue( $invoice ) {
37
+	public function increment_form_revenue($invoice) {
38 38
 
39
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
40
-		if ( $form->get_id() ) {
41
-			$form->set_earned( $form->get_earned() + $invoice->get_total() );
39
+		$form = new GetPaid_Payment_Form($invoice->get_payment_form());
40
+		if ($form->get_id()) {
41
+			$form->set_earned($form->get_earned() + $invoice->get_total());
42 42
 			$form->save();
43 43
 		}
44 44
 
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @param WPInv_Invoice $invoice
51 51
 	 */
52
-	public function decrease_form_revenue( $invoice ) {
52
+	public function decrease_form_revenue($invoice) {
53 53
 
54
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
55
-		if ( $form->get_id() ) {
56
-			$form->set_earned( $form->get_earned() - $invoice->get_total() );
54
+		$form = new GetPaid_Payment_Form($invoice->get_payment_form());
55
+		if ($form->get_id()) {
56
+			$form->set_earned($form->get_earned() - $invoice->get_total());
57 57
 			$form->save();
58 58
 		}
59 59
 
@@ -66,20 +66,20 @@  discard block
 block discarded – undo
66 66
 	 * @param string $from
67 67
 	 * @param string $to
68 68
 	 */
69
-	public function update_form_failed_amount( $invoice, $from, $to ) {
69
+	public function update_form_failed_amount($invoice, $from, $to) {
70 70
 
71
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
72
-		if ( $form->get_id() ) {
71
+		$form = new GetPaid_Payment_Form($invoice->get_payment_form());
72
+		if ($form->get_id()) {
73 73
 			return;
74 74
 		}
75 75
 
76
-		if ( 'wpi-failed' == $from ) {
77
-			$form->set_failed( $form->get_failed() - $invoice->get_total() );
76
+		if ('wpi-failed' == $from) {
77
+			$form->set_failed($form->get_failed() - $invoice->get_total());
78 78
 			$form->save();
79 79
 		}
80 80
 
81
-		if ( 'wpi-failed' == $to ) {
82
-			$form->set_failed( $form->get_failed() + $invoice->get_total() );
81
+		if ('wpi-failed' == $to) {
82
+			$form->set_failed($form->get_failed() + $invoice->get_total());
83 83
 			$form->save();
84 84
 		}
85 85
 
@@ -92,20 +92,20 @@  discard block
 block discarded – undo
92 92
 	 * @param string $from
93 93
 	 * @param string $to
94 94
 	 */
95
-	public function update_form_refunded_amount( $invoice, $from, $to ) {
95
+	public function update_form_refunded_amount($invoice, $from, $to) {
96 96
 
97
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
98
-		if ( $form->get_id() ) {
97
+		$form = new GetPaid_Payment_Form($invoice->get_payment_form());
98
+		if ($form->get_id()) {
99 99
 			return;
100 100
 		}
101 101
 
102
-		if ( 'wpi-refunded' == $from ) {
103
-			$form->set_refunded( $form->get_refunded() - $invoice->get_total() );
102
+		if ('wpi-refunded' == $from) {
103
+			$form->set_refunded($form->get_refunded() - $invoice->get_total());
104 104
 			$form->save();
105 105
 		}
106 106
 
107
-		if ( 'wpi-refunded' == $to ) {
108
-			$form->set_refunded( $form->get_refunded() + $invoice->get_total() );
107
+		if ('wpi-refunded' == $to) {
108
+			$form->set_refunded($form->get_refunded() + $invoice->get_total());
109 109
 			$form->save();
110 110
 		}
111 111
 
@@ -118,20 +118,20 @@  discard block
 block discarded – undo
118 118
 	 * @param string $from
119 119
 	 * @param string $to
120 120
 	 */
121
-	public function update_form_cancelled_amount( $invoice, $from, $to ) {
121
+	public function update_form_cancelled_amount($invoice, $from, $to) {
122 122
 
123
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
124
-		if ( $form->get_id() ) {
123
+		$form = new GetPaid_Payment_Form($invoice->get_payment_form());
124
+		if ($form->get_id()) {
125 125
 			return;
126 126
 		}
127 127
 
128
-		if ( 'wpi-cancelled' == $from ) {
129
-			$form->set_cancelled( $form->get_cancelled() - $invoice->get_total() );
128
+		if ('wpi-cancelled' == $from) {
129
+			$form->set_cancelled($form->get_cancelled() - $invoice->get_total());
130 130
 			$form->save();
131 131
 		}
132 132
 
133
-		if ( 'wpi-cancelled' == $to ) {
134
-			$form->set_cancelled( $form->get_cancelled() + $invoice->get_total() );
133
+		if ('wpi-cancelled' == $to) {
134
+			$form->set_cancelled($form->get_cancelled() + $invoice->get_total());
135 135
 			$form->save();
136 136
 		}
137 137
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-fees.php 2 patches
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -12,119 +12,119 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Fees {
14 14
 
15
-	/**
16
-	 * The fee validation error.
17
-	 * @var string
18
-	 */
19
-	public $fee_error;
20
-
21
-	/**
22
-	 * Submission fees.
23
-	 * @var array
24
-	 */
25
-	public $fees = array();
15
+    /**
16
+     * The fee validation error.
17
+     * @var string
18
+     */
19
+    public $fee_error;
20
+
21
+    /**
22
+     * Submission fees.
23
+     * @var array
24
+     */
25
+    public $fees = array();
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Process any existing invoice fees.
35
+        if ( $submission->has_invoice() ) {
36
+            $this->fees = $submission->get_invoice()->get_fees();
37
+        }
38
+
39
+        // Process price fields.
40
+        $data         = $submission->get_data();
41
+        $payment_form = $submission->get_payment_form();
42
+
43
+        foreach ( $payment_form->get_elements() as $element ) {
44
+
45
+            if ( 'price_input' == $element['type'] ) {
46
+                $this->process_price_input( $element, $data );
47
+            }
48
+
49
+            if ( 'price_select' == $element['type'] ) {
50
+                $this->process_price_select( $element, $data );
51
+            }
52
+
53
+        }
54
+
55
+    }
56
+
57
+    /**
58
+     * Process a price input field.
59
+     *
60
+     * @param array $element
61
+     * @param array $data
62
+     */
63
+    public function process_price_input( $element, $data ) {
64
+
65
+        // Abort if not passed.
66
+        if ( empty( $data[ $element['id'] ] ) ) {
67
+            return;
68
+        }
69
+
70
+        $amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
71
+        $minimum = (float) wpinv_sanitize_amount( $element['minimum'] );
72
+
73
+        if ( $amount < $minimum ) {
74
+            return $this->set_error( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) );
75
+        }
76
+
77
+        $this['fees'][ $element['label'] ] = array(
78
+            'name'          => $element['label'],
79
+            'initial_fee'   => $amount,
80
+            'recurring_fee' => 0,
81
+        );
82
+
83
+    }
84
+
85
+    /**
86
+     * Process a price select field.
87
+     *
88
+     * @param array $element
89
+     * @param array $data
90
+     */
91
+    public function process_price_select( $element, $data ) {
92
+
93
+        // Abort if not passed.
94
+        if ( empty( $data[ $element['id'] ] ) ) {
95
+            return;
96
+        }
97
+
98
+        $options  = getpaid_convert_price_string_to_options( $element['options'] );
99
+        $selected = wpinv_parse_list( $data[ $element['id'] ] );
100
+        $total    = 0;
101
+
102
+        foreach ( $selected as $price ) {
103
+
104
+            if ( ! isset( $options[ $price ] ) ) {
105
+                return $this->set_error( __( 'You have selected an invalid amount', 'invoicing' ) );
106
+            }
107
+
108
+            $total += (float) wpinv_sanitize_amount( $price );
109
+        }
110
+
111
+        $this['fees'][ $element['label'] ] = array(
112
+            'name'          => $element['label'],
113
+            'initial_fee'   => $total,
114
+            'recurring_fee' => 0,
115
+        );
116
+
117
+    }
26 118
 
27 119
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Process any existing invoice fees.
35
-		if ( $submission->has_invoice() ) {
36
-			$this->fees = $submission->get_invoice()->get_fees();
37
-		}
38
-
39
-		// Process price fields.
40
-		$data         = $submission->get_data();
41
-		$payment_form = $submission->get_payment_form();
42
-
43
-		foreach ( $payment_form->get_elements() as $element ) {
44
-
45
-			if ( 'price_input' == $element['type'] ) {
46
-				$this->process_price_input( $element, $data );
47
-			}
48
-
49
-			if ( 'price_select' == $element['type'] ) {
50
-				$this->process_price_select( $element, $data );
51
-			}
52
-
53
-		}
54
-
55
-	}
56
-
57
-	/**
58
-	 * Process a price input field.
59
-	 *
60
-	 * @param array $element
61
-	 * @param array $data
62
-	 */
63
-	public function process_price_input( $element, $data ) {
64
-
65
-		// Abort if not passed.
66
-		if ( empty( $data[ $element['id'] ] ) ) {
67
-			return;
68
-		}
69
-
70
-		$amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
71
-		$minimum = (float) wpinv_sanitize_amount( $element['minimum'] );
72
-
73
-		if ( $amount < $minimum ) {
74
-			return $this->set_error( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) );
75
-		}
76
-
77
-		$this['fees'][ $element['label'] ] = array(
78
-			'name'          => $element['label'],
79
-			'initial_fee'   => $amount,
80
-			'recurring_fee' => 0,
81
-		);
82
-
83
-	}
84
-
85
-	/**
86
-	 * Process a price select field.
87
-	 *
88
-	 * @param array $element
89
-	 * @param array $data
90
-	 */
91
-	public function process_price_select( $element, $data ) {
92
-
93
-		// Abort if not passed.
94
-		if ( empty( $data[ $element['id'] ] ) ) {
95
-			return;
96
-		}
97
-
98
-		$options  = getpaid_convert_price_string_to_options( $element['options'] );
99
-		$selected = wpinv_parse_list( $data[ $element['id'] ] );
100
-		$total    = 0;
101
-
102
-		foreach ( $selected as $price ) {
103
-
104
-			if ( ! isset( $options[ $price ] ) ) {
105
-				return $this->set_error( __( 'You have selected an invalid amount', 'invoicing' ) );
106
-			}
107
-
108
-			$total += (float) wpinv_sanitize_amount( $price );
109
-		}
110
-
111
-		$this['fees'][ $element['label'] ] = array(
112
-			'name'          => $element['label'],
113
-			'initial_fee'   => $total,
114
-			'recurring_fee' => 0,
115
-		);
116
-
117
-	}
118
-
119
-	/**
120
-	 * Sets an error without overwriting the previous error.
121
-	 *
122
-	 * @param string $error
123
-	 */
124
-	public function set_error( $error ) {
125
-		if ( empty( $this->fee_error ) ) {
126
-			$this->fee_error    = $error;
127
-		}
128
-	}
120
+     * Sets an error without overwriting the previous error.
121
+     *
122
+     * @param string $error
123
+     */
124
+    public function set_error( $error ) {
125
+        if ( empty( $this->fee_error ) ) {
126
+            $this->fee_error    = $error;
127
+        }
128
+    }
129 129
 
130 130
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission fees class
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param GetPaid_Payment_Form_Submission $submission
31 31
 	 */
32
-	public function __construct( $submission ) {
32
+	public function __construct($submission) {
33 33
 
34 34
 		// Process any existing invoice fees.
35
-		if ( $submission->has_invoice() ) {
35
+		if ($submission->has_invoice()) {
36 36
 			$this->fees = $submission->get_invoice()->get_fees();
37 37
 		}
38 38
 
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
 		$data         = $submission->get_data();
41 41
 		$payment_form = $submission->get_payment_form();
42 42
 
43
-		foreach ( $payment_form->get_elements() as $element ) {
43
+		foreach ($payment_form->get_elements() as $element) {
44 44
 
45
-			if ( 'price_input' == $element['type'] ) {
46
-				$this->process_price_input( $element, $data );
45
+			if ('price_input' == $element['type']) {
46
+				$this->process_price_input($element, $data);
47 47
 			}
48 48
 
49
-			if ( 'price_select' == $element['type'] ) {
50
-				$this->process_price_select( $element, $data );
49
+			if ('price_select' == $element['type']) {
50
+				$this->process_price_select($element, $data);
51 51
 			}
52 52
 
53 53
 		}
@@ -60,21 +60,21 @@  discard block
 block discarded – undo
60 60
 	 * @param array $element
61 61
 	 * @param array $data
62 62
 	 */
63
-	public function process_price_input( $element, $data ) {
63
+	public function process_price_input($element, $data) {
64 64
 
65 65
 		// Abort if not passed.
66
-		if ( empty( $data[ $element['id'] ] ) ) {
66
+		if (empty($data[$element['id']])) {
67 67
 			return;
68 68
 		}
69 69
 
70
-		$amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
71
-		$minimum = (float) wpinv_sanitize_amount( $element['minimum'] );
70
+		$amount  = (float) wpinv_sanitize_amount($data[$element['id']]);
71
+		$minimum = (float) wpinv_sanitize_amount($element['minimum']);
72 72
 
73
-		if ( $amount < $minimum ) {
74
-			return $this->set_error( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) );
73
+		if ($amount < $minimum) {
74
+			return $this->set_error(sprintf(__('The minimum allowed amount is %s', 'invoicing'), $minimum));
75 75
 		}
76 76
 
77
-		$this['fees'][ $element['label'] ] = array(
77
+		$this['fees'][$element['label']] = array(
78 78
 			'name'          => $element['label'],
79 79
 			'initial_fee'   => $amount,
80 80
 			'recurring_fee' => 0,
@@ -88,27 +88,27 @@  discard block
 block discarded – undo
88 88
 	 * @param array $element
89 89
 	 * @param array $data
90 90
 	 */
91
-	public function process_price_select( $element, $data ) {
91
+	public function process_price_select($element, $data) {
92 92
 
93 93
 		// Abort if not passed.
94
-		if ( empty( $data[ $element['id'] ] ) ) {
94
+		if (empty($data[$element['id']])) {
95 95
 			return;
96 96
 		}
97 97
 
98
-		$options  = getpaid_convert_price_string_to_options( $element['options'] );
99
-		$selected = wpinv_parse_list( $data[ $element['id'] ] );
98
+		$options  = getpaid_convert_price_string_to_options($element['options']);
99
+		$selected = wpinv_parse_list($data[$element['id']]);
100 100
 		$total    = 0;
101 101
 
102
-		foreach ( $selected as $price ) {
102
+		foreach ($selected as $price) {
103 103
 
104
-			if ( ! isset( $options[ $price ] ) ) {
105
-				return $this->set_error( __( 'You have selected an invalid amount', 'invoicing' ) );
104
+			if (!isset($options[$price])) {
105
+				return $this->set_error(__('You have selected an invalid amount', 'invoicing'));
106 106
 			}
107 107
 
108
-			$total += (float) wpinv_sanitize_amount( $price );
108
+			$total += (float) wpinv_sanitize_amount($price);
109 109
 		}
110 110
 
111
-		$this['fees'][ $element['label'] ] = array(
111
+		$this['fees'][$element['label']] = array(
112 112
 			'name'          => $element['label'],
113 113
 			'initial_fee'   => $total,
114 114
 			'recurring_fee' => 0,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @param string $error
123 123
 	 */
124
-	public function set_error( $error ) {
125
-		if ( empty( $this->fee_error ) ) {
126
-			$this->fee_error    = $error;
124
+	public function set_error($error) {
125
+		if (empty($this->fee_error)) {
126
+			$this->fee_error = $error;
127 127
 		}
128 128
 	}
129 129
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -12,252 +12,252 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * The tax validation error.
17
-	 * @var string
18
-	 */
19
-	public $tax_error;
20
-
21
-	/**
22
-	 * Submission taxes.
23
-	 * @var array
24
-	 */
25
-	public $taxes = array();
26
-
27
-	/**
28
-	 * Initial tax.
29
-	 * @var float
30
-	 */
31
-	protected $initial_tax = 0;
32
-
33
-	/**
34
-	 * Recurring tax.
35
-	 * @var float
36
-	 */
37
-	protected $recurring_tax = 0;
15
+    /**
16
+     * The tax validation error.
17
+     * @var string
18
+     */
19
+    public $tax_error;
20
+
21
+    /**
22
+     * Submission taxes.
23
+     * @var array
24
+     */
25
+    public $taxes = array();
26
+
27
+    /**
28
+     * Initial tax.
29
+     * @var float
30
+     */
31
+    protected $initial_tax = 0;
32
+
33
+    /**
34
+     * Recurring tax.
35
+     * @var float
36
+     */
37
+    protected $recurring_tax = 0;
38
+
39
+    /**
40
+     * Class constructor
41
+     *
42
+     * @param GetPaid_Payment_Form_Submission $submission
43
+     */
44
+    public function __construct( $submission ) {
45
+
46
+        // Make sure that taxes are enabled.
47
+        if ( ! $submission->use_taxes() ) {
48
+            return;
49
+        }
50
+
51
+        // Validate VAT number.
52
+        $this->validate_vat( $submission );
53
+
54
+        foreach ( $submission->get_items() as $item ) {
55
+            $this->process_item_tax( $item, $submission );
56
+        }
57
+
58
+        // Process any existing invoice taxes.
59
+        if ( $submission->has_invoice() ) {
60
+            $this->taxes = $submission->get_invoice()->get_taxes();
61
+        }
62
+
63
+        // Add VAT.
64
+        $this->taxes['vat'] = array(
65
+            'name'          => 'vat',
66
+            'initial_tax'   => $this->initial_tax,
67
+            'recurring_tax' => $this->recurring_tax,
68
+        );
69
+
70
+    }
71
+
72
+    /**
73
+     * Maybe process tax.
74
+     *
75
+     * @since 1.0.19
76
+     * @param GetPaid_Form_Item $item
77
+     * @param GetPaid_Payment_Form_Submission $submission
78
+     */
79
+    public function process_item_tax( $item, $submission ) {
80
+
81
+        // Abort early if an error occurred.
82
+        if ( ! empty( $this->tax_error ) ) {
83
+            return;
84
+        }
85
+
86
+        $rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
87
+        $price    = $item->get_sub_total();
88
+        $item_tax = $price * $rate * 0.01;
89
+
90
+        if ( wpinv_prices_include_tax() ) {
91
+            $item_tax = $price - ( $price - $price * $rate * 0.01 );
92
+        }
93
+
94
+        $this->initial_tax += $item_tax;
95
+
96
+        if ( $item->is_recurring() ) {
97
+            $this->recurring_tax += $item_tax;
98
+        }
99
+
100
+    }
101
+
102
+    /**
103
+     * Sets an error without overwriting the previous error.
104
+     *
105
+     * @param string $error
106
+     */
107
+    public function set_error( $error ) {
108
+        if ( empty( $this->tax_error ) ) {
109
+            $this->tax_error = $error;
110
+        }
111
+    }
112
+
113
+    /**
114
+     * Checks if the submission has a digital item.
115
+     *
116
+     * @param GetPaid_Payment_Form_Submission $submission
117
+     * @since 1.0.19
118
+     * @return bool
119
+     */
120
+    public function has_digital_item( $submission ) {
121
+
122
+        foreach ( $submission->get_items() as $item ) {
123
+
124
+            if ( 'digital' == $item->get_vat_rule() ) {
125
+                return true;
126
+                break;
127
+            }
128
+
129
+        }
130
+
131
+        return false;
132
+    }
133
+
134
+    /**
135
+     * Checks if this is an eu purchase.
136
+     *
137
+     * @param GetPaid_Payment_Form_Submission $submission
138
+     * @param bool                            $has_digital
139
+     * @since 1.0.19
140
+     * @return bool
141
+     */
142
+    public function is_eu_transaction( $submission, $has_digital ) {
143
+
144
+        // Both from EU.
145
+        if ( getpaid_is_eu_state( $submission->country ) && ( getpaid_is_eu_state( wpinv_get_default_country() ) || $has_digital ) ) {
146
+            return true;
147
+        }
148
+
149
+        // Both from GST.
150
+        if ( getpaid_is_gst_country( $submission->country ) && getpaid_is_gst_country( wpinv_get_default_country() ) ) {
151
+            return true;
152
+        }
153
+
154
+        return false;
155
+    }
156
+
157
+    /**
158
+     * Retrieves the vat number.
159
+     *
160
+     * @param GetPaid_Payment_Form_Submission $submission
161
+     * @since 1.0.19
162
+     * @return string
163
+     */
164
+    public function get_vat_number( $submission ) {
165
+
166
+        $data = $submission->get_data();
167
+
168
+        // Retrieve from the posted number.
169
+        if ( ! empty( $data['wpinv_vat_number'] ) ) {
170
+            return wpinv_clean( $data['wpinv_vat_number'] );
171
+        }
172
+
173
+        // Retrieve from the invoice.
174
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
175
+    }
176
+
177
+    /**
178
+     * Retrieves the company.
179
+     *
180
+     * @param GetPaid_Payment_Form_Submission $submission
181
+     * @since 1.0.19
182
+     * @return string
183
+     */
184
+    public function get_company( $submission ) {
185
+
186
+        $data = $submission->get_data();
187
+
188
+        // Retrieve from the posted data.
189
+        if ( ! empty( $data['wpinv_company'] ) ) {
190
+            return wpinv_clean( $data['wpinv_company'] );
191
+        }
192
+
193
+        // Retrieve from the invoice.
194
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
195
+    }
196
+
197
+    /**
198
+     * Retrieves the company.
199
+     *
200
+     * @param bool $ip_in_eu Whether the selected IP is from the EU
201
+     * @param bool $country_in_eu Whether the selected country is from the EU
202
+     * @since 1.0.19
203
+     * @return string
204
+     */
205
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
206
+
207
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
208
+        $prevent_b2c = ! empty( $prevent_b2c );
209
+        $is_eu       = $ip_in_eu || $country_in_eu;
210
+
211
+        return $prevent_b2c && $is_eu;
212
+    }
38 213
 
39 214
     /**
40
-	 * Class constructor
41
-	 *
42
-	 * @param GetPaid_Payment_Form_Submission $submission
43
-	 */
44
-	public function __construct( $submission ) {
45
-
46
-		// Make sure that taxes are enabled.
47
-		if ( ! $submission->use_taxes() ) {
48
-			return;
49
-		}
50
-
51
-		// Validate VAT number.
52
-		$this->validate_vat( $submission );
53
-
54
-		foreach ( $submission->get_items() as $item ) {
55
-			$this->process_item_tax( $item, $submission );
56
-		}
57
-
58
-		// Process any existing invoice taxes.
59
-		if ( $submission->has_invoice() ) {
60
-			$this->taxes = $submission->get_invoice()->get_taxes();
61
-		}
62
-
63
-		// Add VAT.
64
-		$this->taxes['vat'] = array(
65
-			'name'          => 'vat',
66
-			'initial_tax'   => $this->initial_tax,
67
-			'recurring_tax' => $this->recurring_tax,
68
-		);
69
-
70
-	}
71
-
72
-	/**
73
-	 * Maybe process tax.
74
-	 *
75
-	 * @since 1.0.19
76
-	 * @param GetPaid_Form_Item $item
77
-	 * @param GetPaid_Payment_Form_Submission $submission
78
-	 */
79
-	public function process_item_tax( $item, $submission ) {
80
-
81
-		// Abort early if an error occurred.
82
-		if ( ! empty( $this->tax_error ) ) {
83
-			return;
84
-		}
85
-
86
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
87
-		$price    = $item->get_sub_total();
88
-		$item_tax = $price * $rate * 0.01;
89
-
90
-		if ( wpinv_prices_include_tax() ) {
91
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
92
-		}
93
-
94
-		$this->initial_tax += $item_tax;
95
-
96
-		if ( $item->is_recurring() ) {
97
-			$this->recurring_tax += $item_tax;
98
-		}
99
-
100
-	}
101
-
102
-	/**
103
-	 * Sets an error without overwriting the previous error.
104
-	 *
105
-	 * @param string $error
106
-	 */
107
-	public function set_error( $error ) {
108
-		if ( empty( $this->tax_error ) ) {
109
-			$this->tax_error = $error;
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * Checks if the submission has a digital item.
115
-	 *
116
-	 * @param GetPaid_Payment_Form_Submission $submission
117
-	 * @since 1.0.19
118
-	 * @return bool
119
-	 */
120
-	public function has_digital_item( $submission ) {
121
-
122
-		foreach ( $submission->get_items() as $item ) {
123
-
124
-			if ( 'digital' == $item->get_vat_rule() ) {
125
-				return true;
126
-				break;
127
-			}
128
-
129
-		}
130
-
131
-		return false;
132
-	}
133
-
134
-	/**
135
-	 * Checks if this is an eu purchase.
136
-	 *
137
-	 * @param GetPaid_Payment_Form_Submission $submission
138
-	 * @param bool                            $has_digital
139
-	 * @since 1.0.19
140
-	 * @return bool
141
-	 */
142
-	public function is_eu_transaction( $submission, $has_digital ) {
143
-
144
-		// Both from EU.
145
-		if ( getpaid_is_eu_state( $submission->country ) && ( getpaid_is_eu_state( wpinv_get_default_country() ) || $has_digital ) ) {
146
-			return true;
147
-		}
148
-
149
-		// Both from GST.
150
-		if ( getpaid_is_gst_country( $submission->country ) && getpaid_is_gst_country( wpinv_get_default_country() ) ) {
151
-			return true;
152
-		}
153
-
154
-		return false;
155
-	}
156
-
157
-	/**
158
-	 * Retrieves the vat number.
159
-	 *
160
-	 * @param GetPaid_Payment_Form_Submission $submission
161
-	 * @since 1.0.19
162
-	 * @return string
163
-	 */
164
-	public function get_vat_number( $submission ) {
165
-
166
-		$data = $submission->get_data();
167
-
168
-		// Retrieve from the posted number.
169
-		if ( ! empty( $data['wpinv_vat_number'] ) ) {
170
-			return wpinv_clean( $data['wpinv_vat_number'] );
171
-		}
172
-
173
-		// Retrieve from the invoice.
174
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
175
-	}
176
-
177
-	/**
178
-	 * Retrieves the company.
179
-	 *
180
-	 * @param GetPaid_Payment_Form_Submission $submission
181
-	 * @since 1.0.19
182
-	 * @return string
183
-	 */
184
-	public function get_company( $submission ) {
185
-
186
-		$data = $submission->get_data();
187
-
188
-		// Retrieve from the posted data.
189
-		if ( ! empty( $data['wpinv_company'] ) ) {
190
-			return wpinv_clean( $data['wpinv_company'] );
191
-		}
192
-
193
-		// Retrieve from the invoice.
194
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
195
-	}
196
-
197
-	/**
198
-	 * Retrieves the company.
199
-	 *
200
-	 * @param bool $ip_in_eu Whether the selected IP is from the EU
201
-	 * @param bool $country_in_eu Whether the selected country is from the EU
202
-	 * @since 1.0.19
203
-	 * @return string
204
-	 */
205
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
206
-
207
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
208
-		$prevent_b2c = ! empty( $prevent_b2c );
209
-		$is_eu       = $ip_in_eu || $country_in_eu;
210
-
211
-		return $prevent_b2c && $is_eu;
212
-	}
213
-
214
-	/**
215
-	 * Validate VAT data.
216
-	 *
217
-	 * @param GetPaid_Payment_Form_Submission $submission
218
-	 * @since 1.0.19
219
-	 */
220
-	public function validate_vat( $submission ) {
221
-
222
-		$has_digital = $this->has_digital_item( $submission );
223
-		$in_eu       = $this->is_eu_transaction( $submission, $has_digital );
224
-
225
-		// Abort if we are not validating vat numbers.
226
-		if ( ! $has_digital && ! $in_eu ) {
215
+     * Validate VAT data.
216
+     *
217
+     * @param GetPaid_Payment_Form_Submission $submission
218
+     * @since 1.0.19
219
+     */
220
+    public function validate_vat( $submission ) {
221
+
222
+        $has_digital = $this->has_digital_item( $submission );
223
+        $in_eu       = $this->is_eu_transaction( $submission, $has_digital );
224
+
225
+        // Abort if we are not validating vat numbers.
226
+        if ( ! $has_digital && ! $in_eu ) {
227 227
             return;
228
-		}
228
+        }
229 229
 
230
-		// Prepare variables.
231
-		$vat_number  = $this->get_vat_number( $submission );
232
-		$company     = $this->get_company( $submission );
233
-		$ip_country  = WPInv_EUVat::get_country_by_ip();
230
+        // Prepare variables.
231
+        $vat_number  = $this->get_vat_number( $submission );
232
+        $company     = $this->get_company( $submission );
233
+        $ip_country  = WPInv_EUVat::get_country_by_ip();
234 234
         $is_eu       = getpaid_is_eu_state( $submission->country );
235 235
         $is_ip_eu    = getpaid_is_eu_state( $ip_country );
236 236
 
237
-		// If we're preventing business to consumer purchases, ensure
238
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
237
+        // If we're preventing business to consumer purchases, ensure
238
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
239 239
 
240
-			// Ensure that a vat number has been specified.
241
-			return $this->set_error(
242
-				wp_sprintf(
243
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
244
-					getpaid_vat_name()
245
-				)
246
-			);
240
+            // Ensure that a vat number has been specified.
241
+            return $this->set_error(
242
+                wp_sprintf(
243
+                    __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
244
+                    getpaid_vat_name()
245
+                )
246
+            );
247 247
 
248
-		}
248
+        }
249 249
 
250
-		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
251
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
250
+        // Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
251
+        if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
252 252
             return;
253
-		}
253
+        }
254 254
 
255
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
255
+        $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
256 256
 
257
-		if ( is_string( $is_valid ) ) {
258
-			$this->set_error( $is_valid );
259
-		}
257
+        if ( is_string( $is_valid ) ) {
258
+            $this->set_error( $is_valid );
259
+        }
260 260
 
261
-	}
261
+    }
262 262
 
263 263
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission taxes class
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @param GetPaid_Payment_Form_Submission $submission
43 43
 	 */
44
-	public function __construct( $submission ) {
44
+	public function __construct($submission) {
45 45
 
46 46
 		// Make sure that taxes are enabled.
47
-		if ( ! $submission->use_taxes() ) {
47
+		if (!$submission->use_taxes()) {
48 48
 			return;
49 49
 		}
50 50
 
51 51
 		// Validate VAT number.
52
-		$this->validate_vat( $submission );
52
+		$this->validate_vat($submission);
53 53
 
54
-		foreach ( $submission->get_items() as $item ) {
55
-			$this->process_item_tax( $item, $submission );
54
+		foreach ($submission->get_items() as $item) {
55
+			$this->process_item_tax($item, $submission);
56 56
 		}
57 57
 
58 58
 		// Process any existing invoice taxes.
59
-		if ( $submission->has_invoice() ) {
59
+		if ($submission->has_invoice()) {
60 60
 			$this->taxes = $submission->get_invoice()->get_taxes();
61 61
 		}
62 62
 
@@ -76,24 +76,24 @@  discard block
 block discarded – undo
76 76
 	 * @param GetPaid_Form_Item $item
77 77
 	 * @param GetPaid_Payment_Form_Submission $submission
78 78
 	 */
79
-	public function process_item_tax( $item, $submission ) {
79
+	public function process_item_tax($item, $submission) {
80 80
 
81 81
 		// Abort early if an error occurred.
82
-		if ( ! empty( $this->tax_error ) ) {
82
+		if (!empty($this->tax_error)) {
83 83
 			return;
84 84
 		}
85 85
 
86
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
86
+		$rate     = wpinv_get_tax_rate($submission->country, $submission->state, $item->get_id());
87 87
 		$price    = $item->get_sub_total();
88 88
 		$item_tax = $price * $rate * 0.01;
89 89
 
90
-		if ( wpinv_prices_include_tax() ) {
91
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
90
+		if (wpinv_prices_include_tax()) {
91
+			$item_tax = $price - ($price - $price * $rate * 0.01);
92 92
 		}
93 93
 
94 94
 		$this->initial_tax += $item_tax;
95 95
 
96
-		if ( $item->is_recurring() ) {
96
+		if ($item->is_recurring()) {
97 97
 			$this->recurring_tax += $item_tax;
98 98
 		}
99 99
 
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @param string $error
106 106
 	 */
107
-	public function set_error( $error ) {
108
-		if ( empty( $this->tax_error ) ) {
107
+	public function set_error($error) {
108
+		if (empty($this->tax_error)) {
109 109
 			$this->tax_error = $error;
110 110
 		}
111 111
 	}
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 	 * @since 1.0.19
118 118
 	 * @return bool
119 119
 	 */
120
-	public function has_digital_item( $submission ) {
120
+	public function has_digital_item($submission) {
121 121
 
122
-		foreach ( $submission->get_items() as $item ) {
122
+		foreach ($submission->get_items() as $item) {
123 123
 
124
-			if ( 'digital' == $item->get_vat_rule() ) {
124
+			if ('digital' == $item->get_vat_rule()) {
125 125
 				return true;
126 126
 				break;
127 127
 			}
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 	 * @since 1.0.19
140 140
 	 * @return bool
141 141
 	 */
142
-	public function is_eu_transaction( $submission, $has_digital ) {
142
+	public function is_eu_transaction($submission, $has_digital) {
143 143
 
144 144
 		// Both from EU.
145
-		if ( getpaid_is_eu_state( $submission->country ) && ( getpaid_is_eu_state( wpinv_get_default_country() ) || $has_digital ) ) {
145
+		if (getpaid_is_eu_state($submission->country) && (getpaid_is_eu_state(wpinv_get_default_country()) || $has_digital)) {
146 146
 			return true;
147 147
 		}
148 148
 
149 149
 		// Both from GST.
150
-		if ( getpaid_is_gst_country( $submission->country ) && getpaid_is_gst_country( wpinv_get_default_country() ) ) {
150
+		if (getpaid_is_gst_country($submission->country) && getpaid_is_gst_country(wpinv_get_default_country())) {
151 151
 			return true;
152 152
 		}
153 153
 
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
 	 * @since 1.0.19
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_vat_number( $submission ) {
164
+	public function get_vat_number($submission) {
165 165
 
166 166
 		$data = $submission->get_data();
167 167
 
168 168
 		// Retrieve from the posted number.
169
-		if ( ! empty( $data['wpinv_vat_number'] ) ) {
170
-			return wpinv_clean( $data['wpinv_vat_number'] );
169
+		if (!empty($data['wpinv_vat_number'])) {
170
+			return wpinv_clean($data['wpinv_vat_number']);
171 171
 		}
172 172
 
173 173
 		// Retrieve from the invoice.
@@ -181,13 +181,13 @@  discard block
 block discarded – undo
181 181
 	 * @since 1.0.19
182 182
 	 * @return string
183 183
 	 */
184
-	public function get_company( $submission ) {
184
+	public function get_company($submission) {
185 185
 
186 186
 		$data = $submission->get_data();
187 187
 
188 188
 		// Retrieve from the posted data.
189
-		if ( ! empty( $data['wpinv_company'] ) ) {
190
-			return wpinv_clean( $data['wpinv_company'] );
189
+		if (!empty($data['wpinv_company'])) {
190
+			return wpinv_clean($data['wpinv_company']);
191 191
 		}
192 192
 
193 193
 		// Retrieve from the invoice.
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
 	 * @since 1.0.19
203 203
 	 * @return string
204 204
 	 */
205
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
205
+	public function requires_vat($ip_in_eu, $country_in_eu) {
206 206
 
207
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
208
-		$prevent_b2c = ! empty( $prevent_b2c );
207
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
208
+		$prevent_b2c = !empty($prevent_b2c);
209 209
 		$is_eu       = $ip_in_eu || $country_in_eu;
210 210
 
211 211
 		return $prevent_b2c && $is_eu;
@@ -217,30 +217,30 @@  discard block
 block discarded – undo
217 217
 	 * @param GetPaid_Payment_Form_Submission $submission
218 218
 	 * @since 1.0.19
219 219
 	 */
220
-	public function validate_vat( $submission ) {
220
+	public function validate_vat($submission) {
221 221
 
222
-		$has_digital = $this->has_digital_item( $submission );
223
-		$in_eu       = $this->is_eu_transaction( $submission, $has_digital );
222
+		$has_digital = $this->has_digital_item($submission);
223
+		$in_eu       = $this->is_eu_transaction($submission, $has_digital);
224 224
 
225 225
 		// Abort if we are not validating vat numbers.
226
-		if ( ! $has_digital && ! $in_eu ) {
226
+		if (!$has_digital && !$in_eu) {
227 227
             return;
228 228
 		}
229 229
 
230 230
 		// Prepare variables.
231
-		$vat_number  = $this->get_vat_number( $submission );
232
-		$company     = $this->get_company( $submission );
231
+		$vat_number  = $this->get_vat_number($submission);
232
+		$company     = $this->get_company($submission);
233 233
 		$ip_country  = WPInv_EUVat::get_country_by_ip();
234
-        $is_eu       = getpaid_is_eu_state( $submission->country );
235
-        $is_ip_eu    = getpaid_is_eu_state( $ip_country );
234
+        $is_eu       = getpaid_is_eu_state($submission->country);
235
+        $is_ip_eu    = getpaid_is_eu_state($ip_country);
236 236
 
237 237
 		// If we're preventing business to consumer purchases, ensure
238
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
238
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
239 239
 
240 240
 			// Ensure that a vat number has been specified.
241 241
 			return $this->set_error(
242 242
 				wp_sprintf(
243
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
243
+					__('Please enter your %s number to verify your purchase is by an EU business.', 'invoicing'),
244 244
 					getpaid_vat_name()
245 245
 				)
246 246
 			);
@@ -248,14 +248,14 @@  discard block
 block discarded – undo
248 248
 		}
249 249
 
250 250
 		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
251
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
251
+		if (!$is_eu || !$in_eu || empty($vat_number)) {
252 252
             return;
253 253
 		}
254 254
 
255
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
255
+		$is_valid = WPInv_EUVat::validate_vat_number($vat_number, $company, $submission->country);
256 256
 
257
-		if ( is_string( $is_valid ) ) {
258
-			$this->set_error( $is_valid );
257
+		if (is_string($is_valid)) {
258
+			$this->set_error($is_valid);
259 259
 		}
260 260
 
261 261
 	}
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +686 added lines, -686 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,395 +10,395 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18 18
 
19
-	/**
20
-	 * Sets the associated payment form.
21
-	 *
22
-	 * @var GetPaid_Payment_Form
23
-	 */
19
+    /**
20
+     * Sets the associated payment form.
21
+     *
22
+     * @var GetPaid_Payment_Form
23
+     */
24 24
     protected $payment_form = null;
25 25
 
26 26
     /**
27
-	 * The country for the submission.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	public $country = null;
32
-
33
-    /**
34
-	 * The state for the submission.
35
-	 *
36
-	 * @since 1.0.19
37
-	 * @var string
38
-	 */
39
-	public $state = null;
40
-
41
-	/**
42
-	 * The invoice associated with the submission.
43
-	 *
44
-	 * @var WPInv_Invoice
45
-	 */
46
-	protected $invoice = null;
47
-
48
-	/**
49
-	 * The raw submission data.
50
-	 *
51
-	 * @var array
52
-	 */
53
-	protected $data = null;
54
-
55
-	/**
56
-	 * Whether this submission contains a recurring item.
57
-	 *
58
-	 * @var bool
59
-	 */
60
-	public $has_recurring = false;
61
-
62
-	/**
63
-	 * The sub total amount for the submission.
64
-	 *
65
-	 * @var float
66
-	 */
67
-	public $subtotal_amount = 0;
68
-
69
-	/**
70
-	 * The total discount amount for the submission.
71
-	 *
72
-	 * @var float
73
-	 */
74
-	protected $total_discount_amount = 0;
75
-
76
-	/**
77
-	 * The total recurring discount amount for the submission.
78
-	 *
79
-	 * @var float
80
-	 */
81
-	protected $total_recurring_discount_amount = 0;
82
-
83
-	/**
84
-	 * The total tax amount for the submission.
85
-	 *
86
-	 * @var float
87
-	 */
88
-	protected $total_tax_amount = 0;
89
-
90
-	/**
91
-	 * The total recurring tax amount for the submission.
92
-	 *
93
-	 * @var float
94
-	 */
95
-	protected $total_recurring_tax_amount = 0;
96
-
97
-	/**
98
-	 * An array of fees for the submission.
99
-	 *
100
-	 * @var array
101
-	 */
102
-	protected $fees = array();
103
-
104
-	/**
105
-	 * The total fees amount for the submission.
106
-	 *
107
-	 * @var float
108
-	 */
109
-	protected $total_fees_amount = 0;
110
-
111
-	/**
112
-	 * The total fees amount for the submission.
113
-	 *
114
-	 * @var float
115
-	 */
116
-	protected $total_recurring_fees_amount = 0;
117
-
118
-	/**
119
-	 * An array of discounts for the submission.
120
-	 *
121
-	 * @var array
122
-	 */
123
-	protected $discounts = array();
124
-
125
-	/**
126
-	 * An array of taxes for the submission.
127
-	 *
128
-	 * @var array
129
-	 */
130
-	protected $taxes = array();
131
-
132
-	/**
133
-	 * An array of items for the submission.
134
-	 *
135
-	 * @var GetPaid_Form_Item[]
136
-	 */
137
-	protected $items = array();
138
-
139
-	/**
140
-	 * The last error.
141
-	 *
142
-	 * @var string
143
-	 */
144
-	public $last_error = null;
145
-
146
-	/**
147
-	 * Is the discount valid?
148
-	 *
149
-	 * @var bool
150
-	 */
151
-	public $is_discount_valid = true;
152
-
153
-    /**
154
-	 * Class constructor.
155
-	 *
156
-	 */
157
-	public function __construct() {
158
-
159
-		// Set the state and country to the default state and country.
160
-		$this->country = wpinv_default_billing_country();
161
-		$this->state = wpinv_get_default_state();
162
-
163
-		// Do we have an actual submission?
164
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
165
-			$this->load_data( $_POST );
166
-		}
167
-
168
-	}
169
-
170
-	/**
171
-	 * Loads submission data.
172
-	 *
173
-	 * @param array $data
174
-	 */
175
-	public function load_data( $data ) {
176
-
177
-		// Prepare submitted data...
178
-		$data = wp_unslash( $data );
179
-
180
-		// Filter the data.
181
-		$data = apply_filters( 'getpaid_submission_data', $data, $this );
182
-
183
-		$this->data = $data;
184
-
185
-		$this->id = md5( wp_json_encode( $data ) );
186
-
187
-		// Every submission needs an active payment form.
188
-		if ( empty( $data['form_id'] ) ) {
189
-			$this->last_error = __( 'Missing payment form', 'invoicing' );
27
+     * The country for the submission.
28
+     *
29
+     * @var string
30
+     */
31
+    public $country = null;
32
+
33
+    /**
34
+     * The state for the submission.
35
+     *
36
+     * @since 1.0.19
37
+     * @var string
38
+     */
39
+    public $state = null;
40
+
41
+    /**
42
+     * The invoice associated with the submission.
43
+     *
44
+     * @var WPInv_Invoice
45
+     */
46
+    protected $invoice = null;
47
+
48
+    /**
49
+     * The raw submission data.
50
+     *
51
+     * @var array
52
+     */
53
+    protected $data = null;
54
+
55
+    /**
56
+     * Whether this submission contains a recurring item.
57
+     *
58
+     * @var bool
59
+     */
60
+    public $has_recurring = false;
61
+
62
+    /**
63
+     * The sub total amount for the submission.
64
+     *
65
+     * @var float
66
+     */
67
+    public $subtotal_amount = 0;
68
+
69
+    /**
70
+     * The total discount amount for the submission.
71
+     *
72
+     * @var float
73
+     */
74
+    protected $total_discount_amount = 0;
75
+
76
+    /**
77
+     * The total recurring discount amount for the submission.
78
+     *
79
+     * @var float
80
+     */
81
+    protected $total_recurring_discount_amount = 0;
82
+
83
+    /**
84
+     * The total tax amount for the submission.
85
+     *
86
+     * @var float
87
+     */
88
+    protected $total_tax_amount = 0;
89
+
90
+    /**
91
+     * The total recurring tax amount for the submission.
92
+     *
93
+     * @var float
94
+     */
95
+    protected $total_recurring_tax_amount = 0;
96
+
97
+    /**
98
+     * An array of fees for the submission.
99
+     *
100
+     * @var array
101
+     */
102
+    protected $fees = array();
103
+
104
+    /**
105
+     * The total fees amount for the submission.
106
+     *
107
+     * @var float
108
+     */
109
+    protected $total_fees_amount = 0;
110
+
111
+    /**
112
+     * The total fees amount for the submission.
113
+     *
114
+     * @var float
115
+     */
116
+    protected $total_recurring_fees_amount = 0;
117
+
118
+    /**
119
+     * An array of discounts for the submission.
120
+     *
121
+     * @var array
122
+     */
123
+    protected $discounts = array();
124
+
125
+    /**
126
+     * An array of taxes for the submission.
127
+     *
128
+     * @var array
129
+     */
130
+    protected $taxes = array();
131
+
132
+    /**
133
+     * An array of items for the submission.
134
+     *
135
+     * @var GetPaid_Form_Item[]
136
+     */
137
+    protected $items = array();
138
+
139
+    /**
140
+     * The last error.
141
+     *
142
+     * @var string
143
+     */
144
+    public $last_error = null;
145
+
146
+    /**
147
+     * Is the discount valid?
148
+     *
149
+     * @var bool
150
+     */
151
+    public $is_discount_valid = true;
152
+
153
+    /**
154
+     * Class constructor.
155
+     *
156
+     */
157
+    public function __construct() {
158
+
159
+        // Set the state and country to the default state and country.
160
+        $this->country = wpinv_default_billing_country();
161
+        $this->state = wpinv_get_default_state();
162
+
163
+        // Do we have an actual submission?
164
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
165
+            $this->load_data( $_POST );
166
+        }
167
+
168
+    }
169
+
170
+    /**
171
+     * Loads submission data.
172
+     *
173
+     * @param array $data
174
+     */
175
+    public function load_data( $data ) {
176
+
177
+        // Prepare submitted data...
178
+        $data = wp_unslash( $data );
179
+
180
+        // Filter the data.
181
+        $data = apply_filters( 'getpaid_submission_data', $data, $this );
182
+
183
+        $this->data = $data;
184
+
185
+        $this->id = md5( wp_json_encode( $data ) );
186
+
187
+        // Every submission needs an active payment form.
188
+        if ( empty( $data['form_id'] ) ) {
189
+            $this->last_error = __( 'Missing payment form', 'invoicing' );
190 190
             return;
191
-		}
191
+        }
192 192
 
193
-		// Fetch the payment form.
194
-		$form = new GetPaid_Payment_Form( $data['form_id'] );
193
+        // Fetch the payment form.
194
+        $form = new GetPaid_Payment_Form( $data['form_id'] );
195 195
 
196
-		if ( ! $form->is_active() ) {
197
-			$this->last_error = __( 'Payment form not active', 'invoicing' );
198
-			return;
199
-		}
196
+        if ( ! $form->is_active() ) {
197
+            $this->last_error = __( 'Payment form not active', 'invoicing' );
198
+            return;
199
+        }
200 200
 
201
-		// Fetch the payment form.
202
-		$this->payment_form = $form;
201
+        // Fetch the payment form.
202
+        $this->payment_form = $form;
203 203
 
204
-		// For existing invoices, make sure that it is valid.
204
+        // For existing invoices, make sure that it is valid.
205 205
         if ( ! empty( $data['invoice_id'] ) ) {
206 206
             $invoice = wpinv_get_invoice( $data['invoice_id'] );
207 207
 
208 208
             if ( empty( $invoice ) ) {
209
-				$this->last_error = __( 'Invalid invoice', 'invoicing' );
209
+                $this->last_error = __( 'Invalid invoice', 'invoicing' );
210 210
                 return;
211
-			}
211
+            }
212 212
 
213
-			if ( $invoice->is_paid() ) {
214
-				$this->last_error = __( 'This invoice is already paid for.', 'invoicing' );
213
+            if ( $invoice->is_paid() ) {
214
+                $this->last_error = __( 'This invoice is already paid for.', 'invoicing' );
215 215
                 return;
216
-			}
216
+            }
217 217
 
218
-			$this->payment_form->set_items( $invoice->get_items() );
218
+            $this->payment_form->set_items( $invoice->get_items() );
219 219
 
220
-			$this->country = $invoice->get_country();
221
-			$this->state   = $invoice->get_state();
222
-			$this->invoice = $invoice;
220
+            $this->country = $invoice->get_country();
221
+            $this->state   = $invoice->get_state();
222
+            $this->invoice = $invoice;
223 223
 
224
-		// Default forms do not have items.
224
+        // Default forms do not have items.
225 225
         } else if ( $form->is_default() && isset( $data['getpaid-items'] ) ) {
226
-			$this->payment_form->set_items( wpinv_clean( $data['getpaid-items'] ) );
227
-		}
228
-
229
-		// User's country.
230
-		if ( ! empty( $data['wpinv_country'] ) ) {
231
-			$this->country = $data['wpinv_country'];
232
-		}
233
-
234
-		// User's state.
235
-		if ( ! empty( $data['wpinv_state'] ) ) {
236
-			$this->country = $data['wpinv_state'];
237
-		}
238
-
239
-		// Handle items.
240
-		$selected_items = array();
241
-		if ( ! empty( $data['getpaid-items'] ) ) {
242
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
243
-		}
244
-
245
-		foreach ( $this->payment_form->get_items() as $item ) {
246
-
247
-			// Continue if this is an optional item and it has not been selected.
248
-			if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
249
-				continue;
250
-			}
251
-
252
-			// (maybe) let customers change the quantities and prices.
253
-			if ( isset( $selected_items[ $item->get_id() ] ) ) {
254
-
255
-				// Maybe change the quantities.
256
-				if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
257
-					$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
258
-				}
259
-
260
-				// Maybe change the price.
261
-				if ( $item->user_can_set_their_price() ) {
262
-					$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
263
-
264
-					// But don't get lower than the minimum price.
265
-					if ( $price < $item->get_minimum_price() ) {
266
-						$price = $item->get_minimum_price();
267
-					}
268
-
269
-					$item->set_price( $price );
270
-
271
-				}
272
-
273
-			}
274
-
275
-			// Add the item to the form.
276
-			$this->add_item( $item );
277
-
278
-		}
279
-
280
-		// Fired when we are done processing a submission.
281
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
282
-
283
-		// Handle discounts.
284
-		$this->process_discount();
285
-
286
-	}
287
-
288
-    /**
289
-	 * Returns the payment form.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @return GetPaid_Payment_Form
293
-	 */
294
-	public function get_payment_form() {
295
-		return $this->payment_form;
296
-	}
297
-
298
-	/**
299
-	 * Returns the associated invoice.
300
-	 *
301
-	 * @since 1.0.19
302
-	 * @return WPInv_Invoice
303
-	 */
304
-	public function get_invoice() {
305
-		return $this->invoice;
306
-	}
307
-
308
-	/**
309
-	 * Checks whether there is an invoice associated with this submission.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @return bool
313
-	 */
314
-	public function has_invoice() {
315
-		return ! empty( $this->invoice );
316
-	}
317
-
318
-	/**
319
-	 * Returns the appropriate currency for the submission.
320
-	 *
321
-	 * @since 1.0.19
322
-	 * @return string
323
-	 */
324
-	public function get_currency() {
325
-		if ( $this->has_invoice() ) {
326
-			return $this->invoice->get_currency();
327
-		}
328
-		return wpinv_get_currency();
329
-    }
330
-
331
-    /**
332
-	 * Returns the raw submission data.
333
-	 *
334
-	 * @since 1.0.19
335
-	 * @return array
336
-	 */
337
-	public function get_data() {
338
-		return $this->data;
339
-	}
340
-
341
-	/**
342
-	 * Checks if a required field is set.
343
-	 *
344
-	 * @since 1.0.19
345
-	 */
346
-	public function is_required_field_set( $field ) {
347
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
348
-	}
349
-
350
-	///////// Items //////////////
351
-
352
-	/**
353
-	 * Adds an item to the submission.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param GetPaid_Form_Item $item
357
-	 */
358
-	public function add_item( $item ) {
359
-
360
-		// Make sure that it is available for purchase.
361
-		if ( ! $item->can_purchase() ) {
362
-			return;
363
-		}
364
-
365
-		// Do we have a recurring item?
366
-		if ( $item->is_recurring() ) {
367
-
368
-			if ( $this->has_recurring ) {
369
-				$this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' );
370
-			}
371
-
372
-			$this->has_recurring = true;
373
-
374
-		}
375
-
376
-		$this->items[ $item->get_id() ] = $item;
377
-
378
-		$this->subtotal_amount += $item->get_sub_total();
379
-
380
-	}
381
-
382
-	/**
383
-	 * Retrieves a specific item.
384
-	 *
385
-	 * @since 1.0.19
386
-	 */
387
-	public function get_item( $item_id ) {
388
-		return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
389
-	}
390
-
391
-	/**
392
-	 * Returns all items.
393
-	 *
394
-	 * @since 1.0.19
395
-	 * @return GetPaid_Form_Item[]
396
-	 */
397
-	public function get_items() {
398
-		return $this->items;
399
-	}
400
-
401
-	/*
226
+            $this->payment_form->set_items( wpinv_clean( $data['getpaid-items'] ) );
227
+        }
228
+
229
+        // User's country.
230
+        if ( ! empty( $data['wpinv_country'] ) ) {
231
+            $this->country = $data['wpinv_country'];
232
+        }
233
+
234
+        // User's state.
235
+        if ( ! empty( $data['wpinv_state'] ) ) {
236
+            $this->country = $data['wpinv_state'];
237
+        }
238
+
239
+        // Handle items.
240
+        $selected_items = array();
241
+        if ( ! empty( $data['getpaid-items'] ) ) {
242
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
243
+        }
244
+
245
+        foreach ( $this->payment_form->get_items() as $item ) {
246
+
247
+            // Continue if this is an optional item and it has not been selected.
248
+            if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
249
+                continue;
250
+            }
251
+
252
+            // (maybe) let customers change the quantities and prices.
253
+            if ( isset( $selected_items[ $item->get_id() ] ) ) {
254
+
255
+                // Maybe change the quantities.
256
+                if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
257
+                    $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
258
+                }
259
+
260
+                // Maybe change the price.
261
+                if ( $item->user_can_set_their_price() ) {
262
+                    $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
263
+
264
+                    // But don't get lower than the minimum price.
265
+                    if ( $price < $item->get_minimum_price() ) {
266
+                        $price = $item->get_minimum_price();
267
+                    }
268
+
269
+                    $item->set_price( $price );
270
+
271
+                }
272
+
273
+            }
274
+
275
+            // Add the item to the form.
276
+            $this->add_item( $item );
277
+
278
+        }
279
+
280
+        // Fired when we are done processing a submission.
281
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
282
+
283
+        // Handle discounts.
284
+        $this->process_discount();
285
+
286
+    }
287
+
288
+    /**
289
+     * Returns the payment form.
290
+     *
291
+     * @since 1.0.19
292
+     * @return GetPaid_Payment_Form
293
+     */
294
+    public function get_payment_form() {
295
+        return $this->payment_form;
296
+    }
297
+
298
+    /**
299
+     * Returns the associated invoice.
300
+     *
301
+     * @since 1.0.19
302
+     * @return WPInv_Invoice
303
+     */
304
+    public function get_invoice() {
305
+        return $this->invoice;
306
+    }
307
+
308
+    /**
309
+     * Checks whether there is an invoice associated with this submission.
310
+     *
311
+     * @since 1.0.19
312
+     * @return bool
313
+     */
314
+    public function has_invoice() {
315
+        return ! empty( $this->invoice );
316
+    }
317
+
318
+    /**
319
+     * Returns the appropriate currency for the submission.
320
+     *
321
+     * @since 1.0.19
322
+     * @return string
323
+     */
324
+    public function get_currency() {
325
+        if ( $this->has_invoice() ) {
326
+            return $this->invoice->get_currency();
327
+        }
328
+        return wpinv_get_currency();
329
+    }
330
+
331
+    /**
332
+     * Returns the raw submission data.
333
+     *
334
+     * @since 1.0.19
335
+     * @return array
336
+     */
337
+    public function get_data() {
338
+        return $this->data;
339
+    }
340
+
341
+    /**
342
+     * Checks if a required field is set.
343
+     *
344
+     * @since 1.0.19
345
+     */
346
+    public function is_required_field_set( $field ) {
347
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
348
+    }
349
+
350
+    ///////// Items //////////////
351
+
352
+    /**
353
+     * Adds an item to the submission.
354
+     *
355
+     * @since 1.0.19
356
+     * @param GetPaid_Form_Item $item
357
+     */
358
+    public function add_item( $item ) {
359
+
360
+        // Make sure that it is available for purchase.
361
+        if ( ! $item->can_purchase() ) {
362
+            return;
363
+        }
364
+
365
+        // Do we have a recurring item?
366
+        if ( $item->is_recurring() ) {
367
+
368
+            if ( $this->has_recurring ) {
369
+                $this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' );
370
+            }
371
+
372
+            $this->has_recurring = true;
373
+
374
+        }
375
+
376
+        $this->items[ $item->get_id() ] = $item;
377
+
378
+        $this->subtotal_amount += $item->get_sub_total();
379
+
380
+    }
381
+
382
+    /**
383
+     * Retrieves a specific item.
384
+     *
385
+     * @since 1.0.19
386
+     */
387
+    public function get_item( $item_id ) {
388
+        return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
389
+    }
390
+
391
+    /**
392
+     * Returns all items.
393
+     *
394
+     * @since 1.0.19
395
+     * @return GetPaid_Form_Item[]
396
+     */
397
+    public function get_items() {
398
+        return $this->items;
399
+    }
400
+
401
+    /*
402 402
 	|--------------------------------------------------------------------------
403 403
 	| Taxes
404 404
 	|--------------------------------------------------------------------------
@@ -407,86 +407,86 @@  discard block
 block discarded – undo
407 407
 	| or only one-time.
408 408
     */
409 409
 
410
-	/**
411
-	 * Prepares the submission's taxes.
412
-	 *
413
-	 * @since 1.0.19
414
-	 */
415
-	public function process_taxes() {
416
-
417
-		$tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
418
-
419
-		if ( ! empty( $tax_processor->tax_error) ) {
420
-			$this->last_error = $tax_processor->tax_error;
421
-			return;
422
-		}
423
-
424
-		foreach ( $tax_processor->taxes as $tax ) {
425
-			$this->add_tax( $tax );
426
-		}
427
-
428
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
429
-	}
430
-
431
-	/**
432
-	 * Adds a tax to the submission.
433
-	 *
434
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
435
-	 * @since 1.0.19
436
-	 */
437
-	public function add_tax( $tax ) {
438
-
439
-		$this->total_tax_amount           += wpinv_sanitize_amount( $tax['initial_tax'] );
440
-		$this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] );
441
-		$this->taxes[ $tax['name'] ]       = $tax;
442
-
443
-	}
444
-
445
-	/**
446
-	 * Whether or not we'll use taxes for the submission.
447
-	 *
448
-	 * @since 1.0.19
449
-	 */
450
-	public function use_taxes() {
451
-
452
-		$use_taxes = wpinv_use_taxes();
453
-
454
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
455
-			$use_taxes = false;
456
-		}
457
-
458
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
459
-
460
-	}
461
-
462
-	/**
463
-	 * Returns the total tax amount.
464
-	 *
465
-	 * @since 1.0.19
466
-	 */
467
-	public function get_total_tax() {
468
-		return $this->total_tax_amount;
469
-	}
470
-
471
-	/**
472
-	 * Returns the total recurring tax amount.
473
-	 *
474
-	 * @since 1.0.19
475
-	 */
476
-	public function get_total_recurring_tax() {
477
-		return $this->total_recurring_tax_amount;
478
-	}
479
-
480
-	/**
481
-	 * Returns all taxes.
482
-	 *
483
-	 * @since 1.0.19
484
-	 */
485
-	public function get_taxes() {
486
-		return $this->taxes;
487
-	}
488
-
489
-	/*
410
+    /**
411
+     * Prepares the submission's taxes.
412
+     *
413
+     * @since 1.0.19
414
+     */
415
+    public function process_taxes() {
416
+
417
+        $tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
418
+
419
+        if ( ! empty( $tax_processor->tax_error) ) {
420
+            $this->last_error = $tax_processor->tax_error;
421
+            return;
422
+        }
423
+
424
+        foreach ( $tax_processor->taxes as $tax ) {
425
+            $this->add_tax( $tax );
426
+        }
427
+
428
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
429
+    }
430
+
431
+    /**
432
+     * Adds a tax to the submission.
433
+     *
434
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
435
+     * @since 1.0.19
436
+     */
437
+    public function add_tax( $tax ) {
438
+
439
+        $this->total_tax_amount           += wpinv_sanitize_amount( $tax['initial_tax'] );
440
+        $this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] );
441
+        $this->taxes[ $tax['name'] ]       = $tax;
442
+
443
+    }
444
+
445
+    /**
446
+     * Whether or not we'll use taxes for the submission.
447
+     *
448
+     * @since 1.0.19
449
+     */
450
+    public function use_taxes() {
451
+
452
+        $use_taxes = wpinv_use_taxes();
453
+
454
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
455
+            $use_taxes = false;
456
+        }
457
+
458
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
459
+
460
+    }
461
+
462
+    /**
463
+     * Returns the total tax amount.
464
+     *
465
+     * @since 1.0.19
466
+     */
467
+    public function get_total_tax() {
468
+        return $this->total_tax_amount;
469
+    }
470
+
471
+    /**
472
+     * Returns the total recurring tax amount.
473
+     *
474
+     * @since 1.0.19
475
+     */
476
+    public function get_total_recurring_tax() {
477
+        return $this->total_recurring_tax_amount;
478
+    }
479
+
480
+    /**
481
+     * Returns all taxes.
482
+     *
483
+     * @since 1.0.19
484
+     */
485
+    public function get_taxes() {
486
+        return $this->taxes;
487
+    }
488
+
489
+    /*
490 490
 	|--------------------------------------------------------------------------
491 491
 	| Discounts
492 492
 	|--------------------------------------------------------------------------
@@ -495,116 +495,116 @@  discard block
 block discarded – undo
495 495
 	| or only one-time. They also do not have to come from a discount code.
496 496
     */
497 497
 
498
-	/**
499
-	 * Prepares the submission's discount.
500
-	 *
501
-	 * @since 1.0.19
502
-	 */
503
-	public function process_discount() {
504
-
505
-		$total            = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
506
-		$discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total );
507
-
508
-		if ( ! $discount_handler->is_discount_valid ) {
509
-			$this->last_error = $discount_handler->discount_error;
510
-			return;
511
-		}
512
-
513
-		// Process any existing invoice discounts.
514
-		if ( $this->has_invoice() ) {
515
-			$discounts = $this->get_invoice()->get_discounts();
516
-
517
-			foreach ( $discounts as $discount ) {
518
-				$this->add_discount( $discount );
519
-			}
520
-
521
-		}
522
-
523
-		if ( $discount_handler->has_discount ) {
524
-			$this->add_discount( $discount_handler->calculate_discount( $this ) );
525
-		}
526
-
527
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
528
-	}
529
-
530
-	/**
531
-	 * Adds a discount to the submission.
532
-	 *
533
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
534
-	 * @since 1.0.19
535
-	 */
536
-	public function add_discount( $discount ) {
537
-
538
-		$this->total_discount_amount           += wpinv_sanitize_amount( $discount['initial_discount'] );
539
-		$this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] );
540
-		$this->discounts[ $discount['name'] ]   = $discount;
541
-
542
-	}
543
-
544
-	/**
545
-	 * Removes a discount from the submission.
546
-	 *
547
-	 * @since 1.0.19
548
-	 */
549
-	public function remove_discount( $name ) {
550
-
551
-		if ( isset( $this->discounts[ $name ] ) ) {
552
-			$discount                               = $this->discounts[ $name ];
553
-			$this->total_discount_amount           -= $discount['initial_discount'];
554
-			$this->total_recurring_discount_amount -= $discount['recurring_discount'];
555
-			unset( $this->discounts[ $name ] );
556
-		}
557
-
558
-	}
559
-
560
-	/**
561
-	 * Checks whether there is a discount code associated with this submission.
562
-	 *
563
-	 * @since 1.0.19
564
-	 * @return bool
565
-	 */
566
-	public function has_discount_code() {
567
-		return ! empty( $this->discounts['discount_code'] );
568
-	}
569
-
570
-	/**
571
-	 * Returns the discount code.
572
-	 *
573
-	 * @since 1.0.19
574
-	 * @return string
575
-	 */
576
-	public function get_discount_code() {
577
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
578
-	}
579
-
580
-	/**
581
-	 * Returns the total discount amount.
582
-	 *
583
-	 * @since 1.0.19
584
-	 */
585
-	public function get_total_discount() {
586
-		return $this->total_discount_amount;
587
-	}
588
-
589
-	/**
590
-	 * Returns the total recurring discount amount.
591
-	 *
592
-	 * @since 1.0.19
593
-	 */
594
-	public function get_total_recurring_discount() {
595
-		return $this->total_recurring_discount_amount;
596
-	}
597
-
598
-	/**
599
-	 * Returns all discounts.
600
-	 *
601
-	 * @since 1.0.19
602
-	 */
603
-	public function get_discounts() {
604
-		return $this->discounts;
605
-	}
606
-
607
-	/*
498
+    /**
499
+     * Prepares the submission's discount.
500
+     *
501
+     * @since 1.0.19
502
+     */
503
+    public function process_discount() {
504
+
505
+        $total            = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
506
+        $discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total );
507
+
508
+        if ( ! $discount_handler->is_discount_valid ) {
509
+            $this->last_error = $discount_handler->discount_error;
510
+            return;
511
+        }
512
+
513
+        // Process any existing invoice discounts.
514
+        if ( $this->has_invoice() ) {
515
+            $discounts = $this->get_invoice()->get_discounts();
516
+
517
+            foreach ( $discounts as $discount ) {
518
+                $this->add_discount( $discount );
519
+            }
520
+
521
+        }
522
+
523
+        if ( $discount_handler->has_discount ) {
524
+            $this->add_discount( $discount_handler->calculate_discount( $this ) );
525
+        }
526
+
527
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
528
+    }
529
+
530
+    /**
531
+     * Adds a discount to the submission.
532
+     *
533
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
534
+     * @since 1.0.19
535
+     */
536
+    public function add_discount( $discount ) {
537
+
538
+        $this->total_discount_amount           += wpinv_sanitize_amount( $discount['initial_discount'] );
539
+        $this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] );
540
+        $this->discounts[ $discount['name'] ]   = $discount;
541
+
542
+    }
543
+
544
+    /**
545
+     * Removes a discount from the submission.
546
+     *
547
+     * @since 1.0.19
548
+     */
549
+    public function remove_discount( $name ) {
550
+
551
+        if ( isset( $this->discounts[ $name ] ) ) {
552
+            $discount                               = $this->discounts[ $name ];
553
+            $this->total_discount_amount           -= $discount['initial_discount'];
554
+            $this->total_recurring_discount_amount -= $discount['recurring_discount'];
555
+            unset( $this->discounts[ $name ] );
556
+        }
557
+
558
+    }
559
+
560
+    /**
561
+     * Checks whether there is a discount code associated with this submission.
562
+     *
563
+     * @since 1.0.19
564
+     * @return bool
565
+     */
566
+    public function has_discount_code() {
567
+        return ! empty( $this->discounts['discount_code'] );
568
+    }
569
+
570
+    /**
571
+     * Returns the discount code.
572
+     *
573
+     * @since 1.0.19
574
+     * @return string
575
+     */
576
+    public function get_discount_code() {
577
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
578
+    }
579
+
580
+    /**
581
+     * Returns the total discount amount.
582
+     *
583
+     * @since 1.0.19
584
+     */
585
+    public function get_total_discount() {
586
+        return $this->total_discount_amount;
587
+    }
588
+
589
+    /**
590
+     * Returns the total recurring discount amount.
591
+     *
592
+     * @since 1.0.19
593
+     */
594
+    public function get_total_recurring_discount() {
595
+        return $this->total_recurring_discount_amount;
596
+    }
597
+
598
+    /**
599
+     * Returns all discounts.
600
+     *
601
+     * @since 1.0.19
602
+     */
603
+    public function get_discounts() {
604
+        return $this->discounts;
605
+    }
606
+
607
+    /*
608 608
 	|--------------------------------------------------------------------------
609 609
 	| Fees
610 610
 	|--------------------------------------------------------------------------
@@ -614,131 +614,131 @@  discard block
 block discarded – undo
614 614
 	| fees.
615 615
     */
616 616
 
617
-	/**
618
-	 * Prepares the submission's fees.
619
-	 *
620
-	 * @since 1.0.19
621
-	 */
622
-	public function process_fees() {
623
-
624
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
625
-
626
-		if ( ! empty( $fees_processor->fee_error) ) {
627
-			$this->last_error = $fees_processor->fee_error;
628
-			return;
629
-		}
630
-
631
-		foreach ( $fees_processor->fees as $fee ) {
632
-			$this->add_fee( $fee );
633
-		}
634
-
635
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
636
-	}
637
-
638
-	/**
639
-	 * Adds a fee to the submission.
640
-	 *
641
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
642
-	 * @since 1.0.19
643
-	 */
644
-	public function add_fee( $fee ) {
645
-
646
-		$this->total_fees_amount           += wpinv_sanitize_amount( $fee['initial_fee'] );
647
-		$this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] );
648
-		$this->fees[ $fee['name'] ]         = $fee;
649
-
650
-	}
651
-
652
-	/**
653
-	 * Removes a fee from the submission.
654
-	 *
655
-	 * @since 1.0.19
656
-	 */
657
-	public function remove_fee( $name ) {
658
-
659
-		if ( isset( $this->fees[ $name ] ) ) {
660
-			$fee                                = $this->fees[ $name ];
661
-			$this->total_fees_amount           -= $fee['initial_fee'];
662
-			$this->total_recurring_fees_amount -= $fee['recurring_fee'];
663
-			unset( $this->fees[ $name ] );
664
-		}
665
-
666
-	}
667
-
668
-	/**
669
-	 * Returns the total fees amount.
670
-	 *
671
-	 * @since 1.0.19
672
-	 */
673
-	public function get_total_fees() {
674
-		return $this->total_fees_amount;
675
-	}
676
-
677
-	/**
678
-	 * Returns the total recurring fees amount.
679
-	 *
680
-	 * @since 1.0.19
681
-	 */
682
-	public function get_total_recurring_fees() {
683
-		return $this->total_recurring_fees_amount;
684
-	}
685
-
686
-	/**
687
-	 * Returns all fees.
688
-	 *
689
-	 * @since 1.0.19
690
-	 */
691
-	public function get_fees() {
692
-		return $this->fees;
693
-	}
694
-
695
-	// MISC //
696
-
697
-	/**
698
-	 * Returns the total amount to collect for this submission.
699
-	 *
700
-	 * @since 1.0.19
701
-	 */
702
-	public function get_total() {
703
-		$total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
704
-		$total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
705
-		return wpinv_sanitize_amount( $total );
706
-	}
707
-
708
-	/**
709
-	 * Whether payment details should be collected for this submission.
710
-	 *
711
-	 * @since 1.0.19
712
-	 */
713
-	public function get_payment_details() {
714
-		$collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
715
-
716
-		if ( $this->has_recurring ) {
717
-			$collect = true;
718
-		}
719
-
720
-		$collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
721
-		return $collect;
722
-	}
723
-
724
-	/**
725
-	 * Returns the billing email of the user.
726
-	 *
727
-	 * @since 1.0.19
728
-	 */
729
-	public function get_billing_email() {
730
-		$billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
731
-		return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
732
-	}
733
-
734
-	/**
735
-	 * Checks if the submitter has a billing email.
736
-	 *
737
-	 * @since 1.0.19
738
-	 */
739
-	public function has_billing_email() {
740
-		$billing_email = $this->get_billing_email();
741
-		return ! empty( $billing_email );
742
-	}
617
+    /**
618
+     * Prepares the submission's fees.
619
+     *
620
+     * @since 1.0.19
621
+     */
622
+    public function process_fees() {
623
+
624
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
625
+
626
+        if ( ! empty( $fees_processor->fee_error) ) {
627
+            $this->last_error = $fees_processor->fee_error;
628
+            return;
629
+        }
630
+
631
+        foreach ( $fees_processor->fees as $fee ) {
632
+            $this->add_fee( $fee );
633
+        }
634
+
635
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
636
+    }
637
+
638
+    /**
639
+     * Adds a fee to the submission.
640
+     *
641
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
642
+     * @since 1.0.19
643
+     */
644
+    public function add_fee( $fee ) {
645
+
646
+        $this->total_fees_amount           += wpinv_sanitize_amount( $fee['initial_fee'] );
647
+        $this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] );
648
+        $this->fees[ $fee['name'] ]         = $fee;
649
+
650
+    }
651
+
652
+    /**
653
+     * Removes a fee from the submission.
654
+     *
655
+     * @since 1.0.19
656
+     */
657
+    public function remove_fee( $name ) {
658
+
659
+        if ( isset( $this->fees[ $name ] ) ) {
660
+            $fee                                = $this->fees[ $name ];
661
+            $this->total_fees_amount           -= $fee['initial_fee'];
662
+            $this->total_recurring_fees_amount -= $fee['recurring_fee'];
663
+            unset( $this->fees[ $name ] );
664
+        }
665
+
666
+    }
667
+
668
+    /**
669
+     * Returns the total fees amount.
670
+     *
671
+     * @since 1.0.19
672
+     */
673
+    public function get_total_fees() {
674
+        return $this->total_fees_amount;
675
+    }
676
+
677
+    /**
678
+     * Returns the total recurring fees amount.
679
+     *
680
+     * @since 1.0.19
681
+     */
682
+    public function get_total_recurring_fees() {
683
+        return $this->total_recurring_fees_amount;
684
+    }
685
+
686
+    /**
687
+     * Returns all fees.
688
+     *
689
+     * @since 1.0.19
690
+     */
691
+    public function get_fees() {
692
+        return $this->fees;
693
+    }
694
+
695
+    // MISC //
696
+
697
+    /**
698
+     * Returns the total amount to collect for this submission.
699
+     *
700
+     * @since 1.0.19
701
+     */
702
+    public function get_total() {
703
+        $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
704
+        $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
705
+        return wpinv_sanitize_amount( $total );
706
+    }
707
+
708
+    /**
709
+     * Whether payment details should be collected for this submission.
710
+     *
711
+     * @since 1.0.19
712
+     */
713
+    public function get_payment_details() {
714
+        $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
715
+
716
+        if ( $this->has_recurring ) {
717
+            $collect = true;
718
+        }
719
+
720
+        $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
721
+        return $collect;
722
+    }
723
+
724
+    /**
725
+     * Returns the billing email of the user.
726
+     *
727
+     * @since 1.0.19
728
+     */
729
+    public function get_billing_email() {
730
+        $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
731
+        return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
732
+    }
733
+
734
+    /**
735
+     * Checks if the submitter has a billing email.
736
+     *
737
+     * @since 1.0.19
738
+     */
739
+    public function has_billing_email() {
740
+        $billing_email = $this->get_billing_email();
741
+        return ! empty( $billing_email );
742
+    }
743 743
 
744 744
 }
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 		$this->state = wpinv_get_default_state();
162 162
 
163 163
 		// Do we have an actual submission?
164
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
165
-			$this->load_data( $_POST );
164
+		if (isset($_POST['getpaid_payment_form_submission'])) {
165
+			$this->load_data($_POST);
166 166
 		}
167 167
 
168 168
 	}
@@ -172,29 +172,29 @@  discard block
 block discarded – undo
172 172
 	 *
173 173
 	 * @param array $data
174 174
 	 */
175
-	public function load_data( $data ) {
175
+	public function load_data($data) {
176 176
 
177 177
 		// Prepare submitted data...
178
-		$data = wp_unslash( $data );
178
+		$data = wp_unslash($data);
179 179
 
180 180
 		// Filter the data.
181
-		$data = apply_filters( 'getpaid_submission_data', $data, $this );
181
+		$data = apply_filters('getpaid_submission_data', $data, $this);
182 182
 
183 183
 		$this->data = $data;
184 184
 
185
-		$this->id = md5( wp_json_encode( $data ) );
185
+		$this->id = md5(wp_json_encode($data));
186 186
 
187 187
 		// Every submission needs an active payment form.
188
-		if ( empty( $data['form_id'] ) ) {
189
-			$this->last_error = __( 'Missing payment form', 'invoicing' );
188
+		if (empty($data['form_id'])) {
189
+			$this->last_error = __('Missing payment form', 'invoicing');
190 190
             return;
191 191
 		}
192 192
 
193 193
 		// Fetch the payment form.
194
-		$form = new GetPaid_Payment_Form( $data['form_id'] );
194
+		$form = new GetPaid_Payment_Form($data['form_id']);
195 195
 
196
-		if ( ! $form->is_active() ) {
197
-			$this->last_error = __( 'Payment form not active', 'invoicing' );
196
+		if (!$form->is_active()) {
197
+			$this->last_error = __('Payment form not active', 'invoicing');
198 198
 			return;
199 199
 		}
200 200
 
@@ -202,83 +202,83 @@  discard block
 block discarded – undo
202 202
 		$this->payment_form = $form;
203 203
 
204 204
 		// For existing invoices, make sure that it is valid.
205
-        if ( ! empty( $data['invoice_id'] ) ) {
206
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
205
+        if (!empty($data['invoice_id'])) {
206
+            $invoice = wpinv_get_invoice($data['invoice_id']);
207 207
 
208
-            if ( empty( $invoice ) ) {
209
-				$this->last_error = __( 'Invalid invoice', 'invoicing' );
208
+            if (empty($invoice)) {
209
+				$this->last_error = __('Invalid invoice', 'invoicing');
210 210
                 return;
211 211
 			}
212 212
 
213
-			if ( $invoice->is_paid() ) {
214
-				$this->last_error = __( 'This invoice is already paid for.', 'invoicing' );
213
+			if ($invoice->is_paid()) {
214
+				$this->last_error = __('This invoice is already paid for.', 'invoicing');
215 215
                 return;
216 216
 			}
217 217
 
218
-			$this->payment_form->set_items( $invoice->get_items() );
218
+			$this->payment_form->set_items($invoice->get_items());
219 219
 
220 220
 			$this->country = $invoice->get_country();
221 221
 			$this->state   = $invoice->get_state();
222 222
 			$this->invoice = $invoice;
223 223
 
224 224
 		// Default forms do not have items.
225
-        } else if ( $form->is_default() && isset( $data['getpaid-items'] ) ) {
226
-			$this->payment_form->set_items( wpinv_clean( $data['getpaid-items'] ) );
225
+        } else if ($form->is_default() && isset($data['getpaid-items'])) {
226
+			$this->payment_form->set_items(wpinv_clean($data['getpaid-items']));
227 227
 		}
228 228
 
229 229
 		// User's country.
230
-		if ( ! empty( $data['wpinv_country'] ) ) {
230
+		if (!empty($data['wpinv_country'])) {
231 231
 			$this->country = $data['wpinv_country'];
232 232
 		}
233 233
 
234 234
 		// User's state.
235
-		if ( ! empty( $data['wpinv_state'] ) ) {
235
+		if (!empty($data['wpinv_state'])) {
236 236
 			$this->country = $data['wpinv_state'];
237 237
 		}
238 238
 
239 239
 		// Handle items.
240 240
 		$selected_items = array();
241
-		if ( ! empty( $data['getpaid-items'] ) ) {
242
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
241
+		if (!empty($data['getpaid-items'])) {
242
+			$selected_items = wpinv_clean($data['getpaid-items']);
243 243
 		}
244 244
 
245
-		foreach ( $this->payment_form->get_items() as $item ) {
245
+		foreach ($this->payment_form->get_items() as $item) {
246 246
 
247 247
 			// Continue if this is an optional item and it has not been selected.
248
-			if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
248
+			if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
249 249
 				continue;
250 250
 			}
251 251
 
252 252
 			// (maybe) let customers change the quantities and prices.
253
-			if ( isset( $selected_items[ $item->get_id() ] ) ) {
253
+			if (isset($selected_items[$item->get_id()])) {
254 254
 
255 255
 				// Maybe change the quantities.
256
-				if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
257
-					$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
256
+				if ($item->allows_quantities() && is_numeric($selected_items[$item->get_id()]['quantity'])) {
257
+					$item->set_quantity((int) $selected_items[$item->get_id()]['quantity']);
258 258
 				}
259 259
 
260 260
 				// Maybe change the price.
261
-				if ( $item->user_can_set_their_price() ) {
262
-					$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
261
+				if ($item->user_can_set_their_price()) {
262
+					$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
263 263
 
264 264
 					// But don't get lower than the minimum price.
265
-					if ( $price < $item->get_minimum_price() ) {
265
+					if ($price < $item->get_minimum_price()) {
266 266
 						$price = $item->get_minimum_price();
267 267
 					}
268 268
 
269
-					$item->set_price( $price );
269
+					$item->set_price($price);
270 270
 
271 271
 				}
272 272
 
273 273
 			}
274 274
 
275 275
 			// Add the item to the form.
276
-			$this->add_item( $item );
276
+			$this->add_item($item);
277 277
 
278 278
 		}
279 279
 
280 280
 		// Fired when we are done processing a submission.
281
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
281
+		do_action_ref_array('getpaid_process_submission', array(&$this));
282 282
 
283 283
 		// Handle discounts.
284 284
 		$this->process_discount();
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 * @return bool
313 313
 	 */
314 314
 	public function has_invoice() {
315
-		return ! empty( $this->invoice );
315
+		return !empty($this->invoice);
316 316
 	}
317 317
 
318 318
 	/**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @return string
323 323
 	 */
324 324
 	public function get_currency() {
325
-		if ( $this->has_invoice() ) {
325
+		if ($this->has_invoice()) {
326 326
 			return $this->invoice->get_currency();
327 327
 		}
328 328
 		return wpinv_get_currency();
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 	 *
344 344
 	 * @since 1.0.19
345 345
 	 */
346
-	public function is_required_field_set( $field ) {
347
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
346
+	public function is_required_field_set($field) {
347
+		return empty($field['required']) || !empty($this->data[$field['id']]);
348 348
 	}
349 349
 
350 350
 	///////// Items //////////////
@@ -355,25 +355,25 @@  discard block
 block discarded – undo
355 355
 	 * @since 1.0.19
356 356
 	 * @param GetPaid_Form_Item $item
357 357
 	 */
358
-	public function add_item( $item ) {
358
+	public function add_item($item) {
359 359
 
360 360
 		// Make sure that it is available for purchase.
361
-		if ( ! $item->can_purchase() ) {
361
+		if (!$item->can_purchase()) {
362 362
 			return;
363 363
 		}
364 364
 
365 365
 		// Do we have a recurring item?
366
-		if ( $item->is_recurring() ) {
366
+		if ($item->is_recurring()) {
367 367
 
368
-			if ( $this->has_recurring ) {
369
-				$this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' );
368
+			if ($this->has_recurring) {
369
+				$this->last_error = __('You can only buy one recurring item at a time.', 'invoicing');
370 370
 			}
371 371
 
372 372
 			$this->has_recurring = true;
373 373
 
374 374
 		}
375 375
 
376
-		$this->items[ $item->get_id() ] = $item;
376
+		$this->items[$item->get_id()] = $item;
377 377
 
378 378
 		$this->subtotal_amount += $item->get_sub_total();
379 379
 
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 	 *
385 385
 	 * @since 1.0.19
386 386
 	 */
387
-	public function get_item( $item_id ) {
388
-		return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
387
+	public function get_item($item_id) {
388
+		return isset($this->items[$item_id]) ? $this->items[$item_id] : null;
389 389
 	}
390 390
 
391 391
 	/**
@@ -414,18 +414,18 @@  discard block
 block discarded – undo
414 414
 	 */
415 415
 	public function process_taxes() {
416 416
 
417
-		$tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
417
+		$tax_processor = new GetPaid_Payment_Form_Submission_Taxes($this);
418 418
 
419
-		if ( ! empty( $tax_processor->tax_error) ) {
419
+		if (!empty($tax_processor->tax_error)) {
420 420
 			$this->last_error = $tax_processor->tax_error;
421 421
 			return;
422 422
 		}
423 423
 
424
-		foreach ( $tax_processor->taxes as $tax ) {
425
-			$this->add_tax( $tax );
424
+		foreach ($tax_processor->taxes as $tax) {
425
+			$this->add_tax($tax);
426 426
 		}
427 427
 
428
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
428
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
429 429
 	}
430 430
 
431 431
 	/**
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
435 435
 	 * @since 1.0.19
436 436
 	 */
437
-	public function add_tax( $tax ) {
437
+	public function add_tax($tax) {
438 438
 
439
-		$this->total_tax_amount           += wpinv_sanitize_amount( $tax['initial_tax'] );
440
-		$this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] );
441
-		$this->taxes[ $tax['name'] ]       = $tax;
439
+		$this->total_tax_amount           += wpinv_sanitize_amount($tax['initial_tax']);
440
+		$this->total_recurring_tax_amount += wpinv_sanitize_amount($tax['recurring_tax']);
441
+		$this->taxes[$tax['name']]       = $tax;
442 442
 
443 443
 	}
444 444
 
@@ -451,11 +451,11 @@  discard block
 block discarded – undo
451 451
 
452 452
 		$use_taxes = wpinv_use_taxes();
453 453
 
454
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
454
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
455 455
 			$use_taxes = false;
456 456
 		}
457 457
 
458
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
458
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
459 459
 
460 460
 	}
461 461
 
@@ -503,28 +503,28 @@  discard block
 block discarded – undo
503 503
 	public function process_discount() {
504 504
 
505 505
 		$total            = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
506
-		$discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total );
506
+		$discount_handler = new GetPaid_Payment_Form_Submission_Discount($this, $total);
507 507
 
508
-		if ( ! $discount_handler->is_discount_valid ) {
508
+		if (!$discount_handler->is_discount_valid) {
509 509
 			$this->last_error = $discount_handler->discount_error;
510 510
 			return;
511 511
 		}
512 512
 
513 513
 		// Process any existing invoice discounts.
514
-		if ( $this->has_invoice() ) {
514
+		if ($this->has_invoice()) {
515 515
 			$discounts = $this->get_invoice()->get_discounts();
516 516
 
517
-			foreach ( $discounts as $discount ) {
518
-				$this->add_discount( $discount );
517
+			foreach ($discounts as $discount) {
518
+				$this->add_discount($discount);
519 519
 			}
520 520
 
521 521
 		}
522 522
 
523
-		if ( $discount_handler->has_discount ) {
524
-			$this->add_discount( $discount_handler->calculate_discount( $this ) );
523
+		if ($discount_handler->has_discount) {
524
+			$this->add_discount($discount_handler->calculate_discount($this));
525 525
 		}
526 526
 
527
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
527
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
528 528
 	}
529 529
 
530 530
 	/**
@@ -533,11 +533,11 @@  discard block
 block discarded – undo
533 533
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
534 534
 	 * @since 1.0.19
535 535
 	 */
536
-	public function add_discount( $discount ) {
536
+	public function add_discount($discount) {
537 537
 
538
-		$this->total_discount_amount           += wpinv_sanitize_amount( $discount['initial_discount'] );
539
-		$this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] );
540
-		$this->discounts[ $discount['name'] ]   = $discount;
538
+		$this->total_discount_amount           += wpinv_sanitize_amount($discount['initial_discount']);
539
+		$this->total_recurring_discount_amount += wpinv_sanitize_amount($discount['recurring_discount']);
540
+		$this->discounts[$discount['name']]   = $discount;
541 541
 
542 542
 	}
543 543
 
@@ -546,13 +546,13 @@  discard block
 block discarded – undo
546 546
 	 *
547 547
 	 * @since 1.0.19
548 548
 	 */
549
-	public function remove_discount( $name ) {
549
+	public function remove_discount($name) {
550 550
 
551
-		if ( isset( $this->discounts[ $name ] ) ) {
552
-			$discount                               = $this->discounts[ $name ];
551
+		if (isset($this->discounts[$name])) {
552
+			$discount                               = $this->discounts[$name];
553 553
 			$this->total_discount_amount           -= $discount['initial_discount'];
554 554
 			$this->total_recurring_discount_amount -= $discount['recurring_discount'];
555
-			unset( $this->discounts[ $name ] );
555
+			unset($this->discounts[$name]);
556 556
 		}
557 557
 
558 558
 	}
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
 	 * @return bool
565 565
 	 */
566 566
 	public function has_discount_code() {
567
-		return ! empty( $this->discounts['discount_code'] );
567
+		return !empty($this->discounts['discount_code']);
568 568
 	}
569 569
 
570 570
 	/**
@@ -621,18 +621,18 @@  discard block
 block discarded – undo
621 621
 	 */
622 622
 	public function process_fees() {
623 623
 
624
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
624
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
625 625
 
626
-		if ( ! empty( $fees_processor->fee_error) ) {
626
+		if (!empty($fees_processor->fee_error)) {
627 627
 			$this->last_error = $fees_processor->fee_error;
628 628
 			return;
629 629
 		}
630 630
 
631
-		foreach ( $fees_processor->fees as $fee ) {
632
-			$this->add_fee( $fee );
631
+		foreach ($fees_processor->fees as $fee) {
632
+			$this->add_fee($fee);
633 633
 		}
634 634
 
635
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
635
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
636 636
 	}
637 637
 
638 638
 	/**
@@ -641,11 +641,11 @@  discard block
 block discarded – undo
641 641
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
642 642
 	 * @since 1.0.19
643 643
 	 */
644
-	public function add_fee( $fee ) {
644
+	public function add_fee($fee) {
645 645
 
646
-		$this->total_fees_amount           += wpinv_sanitize_amount( $fee['initial_fee'] );
647
-		$this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] );
648
-		$this->fees[ $fee['name'] ]         = $fee;
646
+		$this->total_fees_amount           += wpinv_sanitize_amount($fee['initial_fee']);
647
+		$this->total_recurring_fees_amount += wpinv_sanitize_amount($fee['recurring_fee']);
648
+		$this->fees[$fee['name']]         = $fee;
649 649
 
650 650
 	}
651 651
 
@@ -654,13 +654,13 @@  discard block
 block discarded – undo
654 654
 	 *
655 655
 	 * @since 1.0.19
656 656
 	 */
657
-	public function remove_fee( $name ) {
657
+	public function remove_fee($name) {
658 658
 
659
-		if ( isset( $this->fees[ $name ] ) ) {
660
-			$fee                                = $this->fees[ $name ];
659
+		if (isset($this->fees[$name])) {
660
+			$fee                                = $this->fees[$name];
661 661
 			$this->total_fees_amount           -= $fee['initial_fee'];
662 662
 			$this->total_recurring_fees_amount -= $fee['recurring_fee'];
663
-			unset( $this->fees[ $name ] );
663
+			unset($this->fees[$name]);
664 664
 		}
665 665
 
666 666
 	}
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
 	 */
702 702
 	public function get_total() {
703 703
 		$total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
704
-		$total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
705
-		return wpinv_sanitize_amount( $total );
704
+		$total = apply_filters('getpaid_get_submission_total_amount', $total, $this);
705
+		return wpinv_sanitize_amount($total);
706 706
 	}
707 707
 
708 708
 	/**
@@ -713,11 +713,11 @@  discard block
 block discarded – undo
713 713
 	public function get_payment_details() {
714 714
 		$collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
715 715
 
716
-		if ( $this->has_recurring ) {
716
+		if ($this->has_recurring) {
717 717
 			$collect = true;
718 718
 		}
719 719
 
720
-		$collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
720
+		$collect = apply_filters('getpaid_submission_collect_payment_details', $collect, $this);
721 721
 		return $collect;
722 722
 	}
723 723
 
@@ -727,8 +727,8 @@  discard block
 block discarded – undo
727 727
 	 * @since 1.0.19
728 728
 	 */
729 729
 	public function get_billing_email() {
730
-		$billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
731
-		return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
730
+		$billing_email = empty($this->data['billing_email']) ? '' : $this->data['billing_email'];
731
+		return apply_filters('getpaid_get_submission_billing_email', $billing_email, $this);
732 732
 	}
733 733
 
734 734
 	/**
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 	 */
739 739
 	public function has_billing_email() {
740 740
 		$billing_email = $this->get_billing_email();
741
-		return ! empty( $billing_email );
741
+		return !empty($billing_email);
742 742
 	}
743 743
 
744 744
 }
Please login to merge, or discard this patch.