Passed
Push — master ( 17a77b...f99e01 )
by Brian
05:28
created
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Spacing   +205 added lines, -205 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
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = getpaid_get_non_query_string_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = getpaid_get_non_query_string_ipn_url($this->id);
72 72
 
73
-        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'));
74
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,79 +100,79 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication' => $this->get_auth_params(),
112 112
                 'profile'                => array(
113
-                    'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'        => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'              => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'        => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'              => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'    => array(
117 117
                         'customerType' => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'       => array(
121
-                            'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
124
-                            'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'   => getpaid_limit_length($invoice->get_address(), 60),
124
+                            'city'      => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'     => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'   => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'      => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'      => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     ),
133 133
                 ),
134
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             ),
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
 
142 142
             // In case the payment profile already exists remotely.
143
-            if ( 'dup_payment_profile' === $response->get_error_code() ) {
144
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
145
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
146
-                return strtok( '.' );
143
+            if ('dup_payment_profile' === $response->get_error_code()) {
144
+                $customer_profile_id = strtok($response->get_error_message(), '.');
145
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
146
+                return strtok('.');
147 147
             }
148 148
 
149 149
             // In case the customer profile already exists remotely.
150
-            if ( 'E00039' === $response->get_error_code() ) {
151
-                $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() );
152
-                $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id );
153
-                return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save );
150
+            if ('E00039' === $response->get_error_code()) {
151
+                $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message());
152
+                $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id);
153
+                return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save);
154 154
             }
155 155
 
156 156
             return $response;
157 157
         }
158 158
 
159
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
159
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
160 160
 
161 161
         // Save the payment token.
162
-        if ( $save ) {
162
+        if ($save) {
163 163
             $this->save_token(
164 164
                 array(
165 165
                     'id'      => $response->customerPaymentProfileIdList[0],
166
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
166
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4),
167 167
                     'default' => true,
168
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
168
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
169 169
                 )
170 170
             );
171 171
         }
172 172
 
173 173
         // Add a note about the validation response.
174 174
         $invoice->add_note(
175
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
175
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
176 176
             false,
177 177
             false,
178 178
             true
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @return string|WP_Error Profile id.
190 190
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
191 191
 	 */
192
-	public function get_customer_profile( $profile_id ) {
192
+	public function get_customer_profile($profile_id) {
193 193
 
194 194
         // Generate args.
195 195
         $args = array(
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             ),
200 200
         );
201 201
 
202
-        return $this->post( $args, false );
202
+        return $this->post($args, false);
203 203
 
204 204
     }
205 205
 
@@ -214,18 +214,18 @@  discard block
 block discarded – undo
214 214
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
215 215
 	 * @return string|WP_Error Profile id.
216 216
 	 */
217
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
217
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
218 218
 
219 219
         // Remove non-digits from the number
220
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
220
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
221 221
 
222 222
         // Prepare card details.
223
-        $payment_information                          = $this->get_payment_information( $submission_data['authorizenet'] );
223
+        $payment_information                          = $this->get_payment_information($submission_data['authorizenet']);
224 224
 
225 225
         // Authorize.NET does not support saving the same card twice.
226
-        $cached_information                           = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice );
226
+        $cached_information                           = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice);
227 227
 
228
-        if ( $cached_information ) {
228
+        if ($cached_information) {
229 229
             return $cached_information;
230 230
         }
231 231
 
@@ -238,34 +238,34 @@  discard block
 block discarded – undo
238 238
 
239 239
                     // Billing information.
240 240
                     'billTo'  => array(
241
-                        'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
242
-                        'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
243
-                        'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
244
-                        'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
245
-                        'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
246
-                        'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
247
-                        'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
241
+                        'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
242
+                        'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
243
+                        'address'   => getpaid_limit_length($invoice->get_address(), 60),
244
+                        'city'      => getpaid_limit_length($invoice->get_city(), 40),
245
+                        'state'     => getpaid_limit_length($invoice->get_state(), 40),
246
+                        'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
247
+                        'country'   => getpaid_limit_length($invoice->get_country(), 60),
248 248
                     ),
249 249
 
250 250
                     // Payment information.
251 251
                     'payment' => $payment_information,
252 252
                 ),
253
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
253
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
254 254
             ),
255 255
         );
256 256
 
257
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
257
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
258 258
 
259
-        if ( is_wp_error( $response ) ) {
259
+        if (is_wp_error($response)) {
260 260
 
261 261
             // In case the payment profile already exists remotely.
262
-            if ( 'dup_payment_profile' == $response->get_error_code() ) {
263
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
264
-                $payment_profile_id  = strtok( '.' );
265
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
262
+            if ('dup_payment_profile' == $response->get_error_code()) {
263
+                $customer_profile_id = strtok($response->get_error_message(), '.');
264
+                $payment_profile_id  = strtok('.');
265
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
266 266
 
267 267
                 // Cache payment profile id.
268
-                $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id );
268
+                $this->add_payment_profile_to_cache($payment_information, $payment_profile_id);
269 269
 
270 270
                 return $payment_profile_id;
271 271
             }
@@ -274,29 +274,29 @@  discard block
 block discarded – undo
274 274
         }
275 275
 
276 276
         // Save the payment token.
277
-        if ( $save ) {
277
+        if ($save) {
278 278
             $this->save_token(
279 279
                 array(
280 280
                     'id'      => $response->customerPaymentProfileId,
281
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
281
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4),
282 282
                     'default' => true,
283
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
283
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
284 284
                 )
285 285
             );
286 286
         }
287 287
 
288 288
         // Cache payment profile id.
289
-        $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId );
289
+        $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId);
290 290
 
291 291
         // Add a note about the validation response.
292 292
         $invoice->add_note(
293
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
293
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
294 294
             false,
295 295
             false,
296 296
             true
297 297
         );
298 298
 
299
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile );
299
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile);
300 300
 
301 301
         return $response->customerPaymentProfileId;
302 302
     }
@@ -308,12 +308,12 @@  discard block
 block discarded – undo
308 308
      * @param array $payment_details.
309 309
 	 * @return array|false Profile id.
310 310
 	 */
311
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
311
+	public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) {
312 312
 
313
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
314
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
313
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
314
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
315 315
 
316
-        if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) {
316
+        if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) {
317 317
             return false;
318 318
         }
319 319
 
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
             'getCustomerPaymentProfileRequest' => array(
323 323
                 'merchantAuthentication'   => $this->get_auth_params(),
324 324
                 'customerProfileId'        => $customer_profile,
325
-                'customerPaymentProfileId' => $cached_information[ $payment_details ],
325
+                'customerPaymentProfileId' => $cached_information[$payment_details],
326 326
             ),
327 327
         );
328 328
 
329
-        $response = $this->post( $args, $invoice );
329
+        $response = $this->post($args, $invoice);
330 330
 
331
-        return is_wp_error( $response ) ? false : $cached_information[ $payment_details ];
331
+        return is_wp_error($response) ? false : $cached_information[$payment_details];
332 332
 
333 333
     }
334 334
 
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
      * @param array $payment_details.
340 340
      * @param string $payment_profile_id.
341 341
 	 */
342
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
342
+	public function add_payment_profile_to_cache($payment_details, $payment_profile_id) {
343 343
 
344
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
345
-        $cached_information = is_array( $cached_information ) ? $cached_information : array();
346
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
344
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
345
+        $cached_information = is_array($cached_information) ? $cached_information : array();
346
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
347 347
 
348
-        $cached_information[ $payment_details ] = $payment_profile_id;
349
-        update_option( 'getpaid_authorize_net_cached_profiles', $cached_information );
348
+        $cached_information[$payment_details] = $payment_profile_id;
349
+        update_option('getpaid_authorize_net_cached_profiles', $cached_information);
350 350
 
351 351
     }
352 352
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 * @return string|WP_Error Profile id.
360 360
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
361 361
 	 */
362
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
362
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
363 363
 
364 364
         // Generate args.
365 365
         $args = array(
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
             ),
371 371
         );
372 372
 
373
-        return $this->post( $args, false );
373
+        return $this->post($args, false);
374 374
 
375 375
     }
376 376
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
384 384
 	 * @return WP_Error|object
385 385
 	 */
386
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
386
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
387 387
 
388 388
         // Generate args.
389 389
         $args = array(
@@ -403,28 +403,28 @@  discard block
 block discarded – undo
403 403
                         ),
404 404
                     ),
405 405
                     'order'           => array(
406
-                        'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ),
406
+                        'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20),
407 407
                     ),
408
-                    'lineItems'       => array( 'lineItem' => $this->get_line_items( $invoice ) ),
408
+                    'lineItems'       => array('lineItem' => $this->get_line_items($invoice)),
409 409
                     'tax'             => array(
410 410
                         'amount' => $invoice->get_total_tax(),
411
-                        'name'   => __( 'TAX', 'invoicing' ),
411
+                        'name'   => __('TAX', 'invoicing'),
412 412
                     ),
413
-                    'poNumber'        => getpaid_limit_length( $invoice->get_number(), 25 ),
413
+                    'poNumber'        => getpaid_limit_length($invoice->get_number(), 25),
414 414
                     'customer'        => array(
415
-                        'id'    => getpaid_limit_length( $invoice->get_user_id(), 25 ),
416
-                        'email' => getpaid_limit_length( $invoice->get_email(), 25 ),
415
+                        'id'    => getpaid_limit_length($invoice->get_user_id(), 25),
416
+                        'email' => getpaid_limit_length($invoice->get_email(), 25),
417 417
                     ),
418 418
                     'customerIP'      => $invoice->get_ip(),
419 419
                 ),
420 420
             ),
421 421
         );
422 422
 
423
-        if ( 0 == $invoice->get_total_tax() ) {
424
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
423
+        if (0 == $invoice->get_total_tax()) {
424
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
425 425
         }
426 426
 
427
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
427
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
428 428
 
429 429
     }
430 430
 
@@ -434,29 +434,29 @@  discard block
 block discarded – undo
434 434
      * @param stdClass $result Api response.
435 435
 	 * @param WPInv_Invoice $invoice Invoice.
436 436
 	 */
437
-	public function process_charge_response( $result, $invoice ) {
437
+	public function process_charge_response($result, $invoice) {
438 438
 
439 439
         wpinv_clear_errors();
440 440
 		$response_code = (int) $result->transactionResponse->responseCode;
441 441
 
442 442
 		// Succeeded.
443
-		if ( 1 == $response_code || 4 == $response_code ) {
443
+		if (1 == $response_code || 4 == $response_code) {
444 444
 
445 445
 			// Maybe set a transaction id.
446
-			if ( ! empty( $result->transactionResponse->transId ) ) {
447
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
446
+			if (!empty($result->transactionResponse->transId)) {
447
+				$invoice->set_transaction_id($result->transactionResponse->transId);
448 448
 			}
449 449
 
450
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
450
+			$invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
451 451
 
452
-			if ( 1 == $response_code ) {
452
+			if (1 == $response_code) {
453 453
 				return $invoice->mark_paid();
454 454
 			}
455 455
 
456
-			$invoice->set_status( 'wpi-onhold' );
456
+			$invoice->set_status('wpi-onhold');
457 457
         	$invoice->add_note(
458 458
                 sprintf(
459
-                    __( 'Held for review: %s', 'invoicing' ),
459
+                    __('Held for review: %s', 'invoicing'),
460 460
                     $result->transactionResponse->messages->message[0]->description
461 461
                 )
462 462
 			);
@@ -465,11 +465,11 @@  discard block
 block discarded – undo
465 465
 
466 466
 		}
467 467
 
468
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
468
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
469 469
 
470
-        if ( ! empty( $result->transactionResponse->errors ) ) {
470
+        if (!empty($result->transactionResponse->errors)) {
471 471
             $errors = (object) $result->transactionResponse->errors;
472
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
472
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
473 473
         }
474 474
 
475 475
     }
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	 * @param array $card Card details.
482 482
 	 * @return array
483 483
 	 */
484
-	public function get_payment_information( $card ) {
484
+	public function get_payment_information($card) {
485 485
         return array(
486 486
 
487 487
             'creditCard' => array(
@@ -500,8 +500,8 @@  discard block
 block discarded – undo
500 500
 	 * @param WPInv_Invoice $invoice Invoice.
501 501
 	 * @return string
502 502
 	 */
503
-	public function get_customer_profile_meta_name( $invoice ) {
504
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
503
+	public function get_customer_profile_meta_name($invoice) {
504
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
505 505
     }
506 506
 
507 507
     /**
@@ -512,34 +512,34 @@  discard block
 block discarded – undo
512 512
      * @param WPInv_Invoice $invoice
513 513
 	 * @return WP_Error|string The payment profile id
514 514
 	 */
515
-	public function validate_submission_data( $submission_data, $invoice ) {
515
+	public function validate_submission_data($submission_data, $invoice) {
516 516
 
517 517
         // Validate authentication details.
518 518
         $auth = $this->get_auth_params();
519 519
 
520
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
521
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) );
520
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
521
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
522 522
         }
523 523
 
524 524
         // Validate the payment method.
525
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
526
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) );
525
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
526
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
527 527
         }
528 528
 
529 529
         // Are we adding a new payment method?
530
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
530
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
531 531
             return $submission_data['getpaid-authorizenet-payment-method'];
532 532
         }
533 533
 
534 534
         // Retrieve the customer profile id.
535
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
535
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
536 536
 
537 537
         // Create payment method.
538
-        if ( empty( $profile_id ) ) {
539
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
538
+        if (empty($profile_id)) {
539
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
540 540
         }
541 541
 
542
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
542
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
543 543
 
544 544
     }
545 545
 
@@ -550,32 +550,32 @@  discard block
 block discarded – undo
550 550
 	 * @param WPInv_Invoice $invoice Invoice.
551 551
 	 * @return array
552 552
 	 */
553
-	public function get_line_items( $invoice ) {
553
+	public function get_line_items($invoice) {
554 554
         $items = array();
555 555
 
556
-        foreach ( $invoice->get_items() as $item ) {
556
+        foreach ($invoice->get_items() as $item) {
557 557
 
558 558
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
559 559
             $items[] = array(
560
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
561
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
562
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
563
-                'quantity'    => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ),
560
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
561
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
562
+                'description' => getpaid_limit_length($item->get_description(), 255),
563
+                'quantity'    => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()),
564 564
                 'unitPrice'   => (float) $amount,
565 565
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
566 566
             );
567 567
 
568 568
         }
569 569
 
570
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
570
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
571 571
 
572
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
572
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
573 573
 
574
-            if ( $amount > 0 ) {
574
+            if ($amount > 0) {
575 575
                 $items[] = array(
576
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
577
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
578
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
576
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
577
+                    'name'        => getpaid_limit_length($fee_name, 31),
578
+                    'description' => getpaid_limit_length($fee_name, 255),
579 579
                     'quantity'    => '1',
580 580
                     'unitPrice'   => (float) $amount,
581 581
                     'taxable'     => false,
@@ -595,36 +595,36 @@  discard block
 block discarded – undo
595 595
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
596 596
 	 * @return array
597 597
 	 */
598
-	public function process_payment( $invoice, $submission_data, $submission ) {
598
+	public function process_payment($invoice, $submission_data, $submission) {
599 599
 
600 600
         // Validate the submitted data.
601
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
601
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
602 602
 
603 603
         // Do we have an error?
604
-        if ( is_wp_error( $payment_profile_id ) ) {
605
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
606
-            wpinv_send_back_to_checkout( $invoice );
604
+        if (is_wp_error($payment_profile_id)) {
605
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
606
+            wpinv_send_back_to_checkout($invoice);
607 607
         }
608 608
 
609 609
         // Save the payment method to the order.
610
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
610
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
611 611
 
612 612
         // Check if this is a subscription or not.
613
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
614
-        if ( ! empty( $subscriptions ) ) {
615
-            $this->process_subscription( $invoice, $subscriptions );
613
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
614
+        if (!empty($subscriptions)) {
615
+            $this->process_subscription($invoice, $subscriptions);
616 616
         }
617 617
 
618 618
         // If it is free, send to the success page.
619
-        if ( ! $invoice->needs_payment() ) {
619
+        if (!$invoice->needs_payment()) {
620 620
             $invoice->mark_paid();
621
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
621
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
622 622
         }
623 623
 
624 624
         // Charge the payment profile.
625
-        $this->process_initial_payment( $invoice );
625
+        $this->process_initial_payment($invoice);
626 626
 
627
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
627
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
628 628
 
629 629
         exit;
630 630
 
@@ -635,23 +635,23 @@  discard block
 block discarded – undo
635 635
 	 *
636 636
      * @param WPInv_Invoice $invoice Invoice.
637 637
 	 */
638
-	protected function process_initial_payment( $invoice ) {
638
+	protected function process_initial_payment($invoice) {
639 639
 
640
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
641
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
642
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
640
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
641
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
642
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
643 643
 
644 644
 		// Do we have an error?
645
-		if ( is_wp_error( $result ) ) {
646
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
647
-			wpinv_send_back_to_checkout( $invoice );
645
+		if (is_wp_error($result)) {
646
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
647
+			wpinv_send_back_to_checkout($invoice);
648 648
 		}
649 649
 
650 650
 		// Process the response.
651
-		$this->process_charge_response( $result, $invoice );
651
+		$this->process_charge_response($result, $invoice);
652 652
 
653
-		if ( wpinv_get_errors() ) {
654
-			wpinv_send_back_to_checkout( $invoice );
653
+		if (wpinv_get_errors()) {
654
+			wpinv_send_back_to_checkout($invoice);
655 655
 		}
656 656
 
657 657
 	}
@@ -662,30 +662,30 @@  discard block
 block discarded – undo
662 662
      * @param WPInv_Invoice $invoice Invoice.
663 663
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
664 664
 	 */
665
-	public function process_subscription( $invoice, $subscriptions ) {
665
+	public function process_subscription($invoice, $subscriptions) {
666 666
 
667 667
         // Check if there is an initial amount to charge.
668
-        if ( (float) $invoice->get_total() > 0 ) {
669
-			$this->process_initial_payment( $invoice );
668
+        if ((float) $invoice->get_total() > 0) {
669
+			$this->process_initial_payment($invoice);
670 670
         }
671 671
 
672 672
         // Activate the subscriptions.
673
-        $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
673
+        $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
674 674
 
675
-        foreach ( $subscriptions as $subscription ) {
676
-            if ( $subscription->exists() ) {
677
-                $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
678
-                $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
675
+        foreach ($subscriptions as $subscription) {
676
+            if ($subscription->exists()) {
677
+                $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
678
+                $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
679 679
 
680
-                $subscription->set_next_renewal_date( $expiry );
681
-                $subscription->set_date_created( current_time( 'mysql' ) );
682
-                $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
680
+                $subscription->set_next_renewal_date($expiry);
681
+                $subscription->set_date_created(current_time('mysql'));
682
+                $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
683 683
                 $subscription->activate();
684 684
             }
685 685
         }
686 686
 
687 687
 		// Redirect to the success page.
688
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
688
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
689 689
 
690 690
     }
691 691
 
@@ -695,11 +695,11 @@  discard block
 block discarded – undo
695 695
 	 *
696 696
      * @param WPInv_Subscription $subscription
697 697
 	 */
698
-	public function maybe_renew_subscription( $subscription ) {
698
+	public function maybe_renew_subscription($subscription) {
699 699
 
700 700
         // Ensure its our subscription && it's active.
701
-        if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
702
-            $this->renew_subscription( $subscription );
701
+        if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) {
702
+            $this->renew_subscription($subscription);
703 703
         }
704 704
 
705 705
 	}
@@ -709,28 +709,28 @@  discard block
 block discarded – undo
709 709
 	 *
710 710
      * @param WPInv_Subscription $subscription
711 711
 	 */
712
-	public function renew_subscription( $subscription ) {
712
+	public function renew_subscription($subscription) {
713 713
 
714 714
 		// Generate the renewal invoice.
715 715
 		$new_invoice = $subscription->create_payment();
716 716
 		$old_invoice = $subscription->get_parent_payment();
717 717
 
718
-        if ( empty( $new_invoice ) ) {
719
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
718
+        if (empty($new_invoice)) {
719
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
720 720
             $subscription->failing();
721 721
             return;
722 722
         }
723 723
 
724 724
         // Charge the payment method.
725
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
726
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
727
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
725
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
726
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
727
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
728 728
 
729 729
 		// Do we have an error?
730
-		if ( is_wp_error( $result ) ) {
730
+		if (is_wp_error($result)) {
731 731
 
732 732
 			$old_invoice->add_note(
733
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
733
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
734 734
 				true,
735 735
 				false,
736 736
 				true
@@ -741,12 +741,12 @@  discard block
 block discarded – undo
741 741
 		}
742 742
 
743 743
 		// Process the response.
744
-		$this->process_charge_response( $result, $new_invoice );
744
+		$this->process_charge_response($result, $new_invoice);
745 745
 
746
-		if ( wpinv_get_errors() ) {
746
+		if (wpinv_get_errors()) {
747 747
 
748 748
 			$old_invoice->add_note(
749
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
749
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
750 750
 				true,
751 751
 				false,
752 752
 				true
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 
757 757
         }
758 758
 
759
-        $subscription->add_payment( array(), $new_invoice );
759
+        $subscription->add_payment(array(), $new_invoice);
760 760
         $subscription->renew();
761 761
     }
762 762
 
@@ -767,33 +767,33 @@  discard block
 block discarded – undo
767 767
 	 * @param GetPaid_Form_Item[] $items
768 768
 	 * @return WPInv_Invoice
769 769
 	 */
770
-	public function process_addons( $invoice, $items ) {
770
+	public function process_addons($invoice, $items) {
771 771
 
772 772
         global $getpaid_authorize_addons;
773 773
 
774 774
         $getpaid_authorize_addons = array();
775
-        foreach ( $items as $item ) {
775
+        foreach ($items as $item) {
776 776
 
777
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
777
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
778 778
                 $getpaid_authorize_addons[] = $item;
779 779
             }
780 780
 }
781 781
 
782
-        if ( empty( $getpaid_authorize_addons ) ) {
782
+        if (empty($getpaid_authorize_addons)) {
783 783
             return;
784 784
         }
785 785
 
786 786
         $invoice->recalculate_total();
787 787
 
788
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
789
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
788
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
789
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
790 790
 
791
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
792
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
793
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
791
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
792
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
793
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
794 794
 
795
-        if ( is_wp_error( $result ) ) {
796
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
795
+        if (is_wp_error($result)) {
796
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
797 797
             return;
798 798
         }
799 799
 
@@ -806,19 +806,19 @@  discard block
 block discarded – undo
806 806
      * @param array $args
807 807
 	 * @return array
808 808
 	 */
809
-    public function filter_addons_request( $args ) {
809
+    public function filter_addons_request($args) {
810 810
 
811 811
         global $getpaid_authorize_addons;
812 812
         $total = 0;
813 813
 
814
-        foreach ( $getpaid_authorize_addons as $addon ) {
814
+        foreach ($getpaid_authorize_addons as $addon) {
815 815
             $total += $addon->get_sub_total();
816 816
         }
817 817
 
818 818
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
819 819
 
820
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
821
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
820
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
821
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
822 822
         }
823 823
 
824 824
         return $args;
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
     public function sandbox_notice() {
832 832
 
833 833
         return sprintf(
834
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
834
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'),
835 835
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
836 836
             '</a>'
837 837
         );
@@ -843,42 +843,42 @@  discard block
 block discarded – undo
843 843
 	 *
844 844
 	 * @param array $admin_settings
845 845
 	 */
846
-	public function admin_settings( $admin_settings ) {
846
+	public function admin_settings($admin_settings) {
847 847
 
848 848
         $currencies = sprintf(
849
-            __( 'Supported Currencies: %s', 'invoicing' ),
850
-            implode( ', ', $this->currencies )
849
+            __('Supported Currencies: %s', 'invoicing'),
850
+            implode(', ', $this->currencies)
851 851
         );
852 852
 
853 853
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
854
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
854
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
855 855
 
856 856
         $admin_settings['authorizenet_login_id'] = array(
857 857
             'type' => 'text',
858 858
             'id'   => 'authorizenet_login_id',
859
-            'name' => __( 'API Login ID', 'invoicing' ),
860
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
859
+            'name' => __('API Login ID', 'invoicing'),
860
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
861 861
         );
862 862
 
863 863
         $admin_settings['authorizenet_transaction_key'] = array(
864 864
             'type' => 'text',
865 865
             'id'   => 'authorizenet_transaction_key',
866
-            'name' => __( 'Transaction Key', 'invoicing' ),
866
+            'name' => __('Transaction Key', 'invoicing'),
867 867
         );
868 868
 
869 869
         $admin_settings['authorizenet_signature_key'] = array(
870 870
             'type' => 'text',
871 871
             'id'   => 'authorizenet_signature_key',
872
-            'name' => __( 'Signature Key', 'invoicing' ),
873
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
872
+            'name' => __('Signature Key', 'invoicing'),
873
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
874 874
         );
875 875
 
876 876
         $admin_settings['authorizenet_ipn_url'] = array(
877 877
             'type'     => 'ipn_url',
878 878
             'id'       => 'authorizenet_ipn_url',
879
-            'name'     => __( 'Webhook URL', 'invoicing' ),
879
+            'name'     => __('Webhook URL', 'invoicing'),
880 880
             'std'      => $this->notify_url,
881
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
881
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
882 882
             'custom'   => 'authorizenet',
883 883
             'readonly' => true,
884 884
         );
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-address.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,14 +21,14 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the invoice.
27
-        $invoice  = new WPInv_Invoice( $post );
28
-        $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
-        $customer = new WP_User( $customer );
30
-        $display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
27
+        $invoice  = new WPInv_Invoice($post);
28
+        $customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id();
29
+        $customer = new WP_User($customer);
30
+        $display  = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email);
31
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
32 32
 
33 33
         ?>
34 34
 
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
                         <div class="col-12 col-sm-6">
44 44
                             <div id="getpaid-invoice-user-id-wrapper" class="form-group">
45 45
                                 <div>
46
-                                    <label for="post_author_override"><?php esc_html_e( 'Customer', 'invoicing' ); ?></label>
46
+                                    <label for="post_author_override"><?php esc_html_e('Customer', 'invoicing'); ?></label>
47 47
                                 </div>
48 48
                                 <div>
49
-                                    <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>">
50
-                                        <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html( $display ); ?> </option>)
49
+                                    <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>">
50
+                                        <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html($display); ?> </option>)
51 51
                                     </select>
52 52
                                 </div>
53 53
                             </div>
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
                                             'type'        => 'text',
61 61
                                             'id'          => 'getpaid-invoice-new-user-email',
62 62
                                             'name'        => 'wpinv_email',
63
-                                            'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
63
+                                            'label'       => __('Email', 'invoicing') . '<span class="required">*</span>',
64 64
                                             'label_type'  => 'vertical',
65 65
                                             'placeholder' => '[email protected]',
66 66
                                             'class'       => 'form-control-sm',
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
                             </div>
72 72
                         </div>
73 73
                         <div class="col-12 col-sm-6 form-group mt-sm-4">
74
-                            <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?>
74
+                            <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?>
75 75
                                 <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)">
76 76
                                     <i aria-hidden="true" class="fa fa-refresh"></i>
77
-                                    <?php esc_html_e( 'Fill User Details', 'invoicing' ); ?>
77
+                                    <?php esc_html_e('Fill User Details', 'invoicing'); ?>
78 78
                                 </a>
79 79
                                 <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)">
80 80
                                     <i aria-hidden="true" class="fa fa-plus"></i>
81
-                                    <?php esc_html_e( 'Add New User', 'invoicing' ); ?>
81
+                                    <?php esc_html_e('Add New User', 'invoicing'); ?>
82 82
                                 </a>
83 83
                                 <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)">
84 84
                                     <i aria-hidden="true" class="fa fa-close"></i>
85
-                                    <?php esc_html_e( 'Cancel', 'invoicing' ); ?>
85
+                                    <?php esc_html_e('Cancel', 'invoicing'); ?>
86 86
                                 </a>
87 87
                             <?php endif; ?>
88 88
                         </div>
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
                                         'type'        => 'text',
96 96
                                         'id'          => 'wpinv_first_name',
97 97
                                         'name'        => 'wpinv_first_name',
98
-                                        'label'       => __( 'First Name', 'invoicing' ),
98
+                                        'label'       => __('First Name', 'invoicing'),
99 99
                                         'label_type'  => 'vertical',
100 100
                                         'placeholder' => '',
101 101
                                         'class'       => 'form-control-sm',
102
-                                        'value'       => $invoice->get_first_name( 'edit' ),
102
+                                        'value'       => $invoice->get_first_name('edit'),
103 103
                                     ),
104 104
                                     true
105 105
                                 );
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
112 112
                                         'type'        => 'text',
113 113
                                         'id'          => 'wpinv_last_name',
114 114
                                         'name'        => 'wpinv_last_name',
115
-                                        'label'       => __( 'Last Name', 'invoicing' ),
115
+                                        'label'       => __('Last Name', 'invoicing'),
116 116
                                         'label_type'  => 'vertical',
117 117
                                         'placeholder' => '',
118 118
                                         'class'       => 'form-control-sm',
119
-                                        'value'       => $invoice->get_last_name( 'edit' ),
119
+                                        'value'       => $invoice->get_last_name('edit'),
120 120
                                     ),
121 121
                                     true
122 122
                                 );
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
                                         'type'        => 'text',
133 133
                                         'id'          => 'wpinv_company',
134 134
                                         'name'        => 'wpinv_company',
135
-                                        'label'       => __( 'Company', 'invoicing' ),
135
+                                        'label'       => __('Company', 'invoicing'),
136 136
                                         'label_type'  => 'vertical',
137 137
                                         'placeholder' => '',
138 138
                                         'class'       => 'form-control-sm',
139
-                                        'value'       => $invoice->get_company( 'edit' ),
139
+                                        'value'       => $invoice->get_company('edit'),
140 140
                                     ),
141 141
                                     true
142 142
                                 );
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
                                         'type'        => 'text',
150 150
                                         'id'          => 'wpinv_vat_number',
151 151
                                         'name'        => 'wpinv_vat_number',
152
-                                        'label'       => __( 'Vat Number', 'invoicing' ),
152
+                                        'label'       => __('Vat Number', 'invoicing'),
153 153
                                         'label_type'  => 'vertical',
154 154
                                         'placeholder' => '',
155 155
                                         'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
156
-                                        'value'       => $invoice->get_vat_number( 'edit' ),
156
+                                        'value'       => $invoice->get_vat_number('edit'),
157 157
                                     ),
158 158
                                     true
159 159
                                 );
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
                                         'type'        => 'text',
170 170
                                         'id'          => 'wpinv_address',
171 171
                                         'name'        => 'wpinv_address',
172
-                                        'label'       => __( 'Address', 'invoicing' ),
172
+                                        'label'       => __('Address', 'invoicing'),
173 173
                                         'label_type'  => 'vertical',
174 174
                                         'placeholder' => '',
175 175
                                         'class'       => 'form-control-sm',
176
-                                        'value'       => $invoice->get_address( 'edit' ),
176
+                                        'value'       => $invoice->get_address('edit'),
177 177
                                     ),
178 178
                                     true
179 179
                                 );
@@ -186,11 +186,11 @@  discard block
 block discarded – undo
186 186
                                         'type'        => 'text',
187 187
                                         'id'          => 'wpinv_city',
188 188
                                         'name'        => 'wpinv_city',
189
-                                        'label'       => __( 'City', 'invoicing' ),
189
+                                        'label'       => __('City', 'invoicing'),
190 190
                                         'label_type'  => 'vertical',
191 191
                                         'placeholder' => '',
192 192
                                         'class'       => 'form-control-sm',
193
-                                        'value'       => $invoice->get_city( 'edit' ),
193
+                                        'value'       => $invoice->get_city('edit'),
194 194
                                     ),
195 195
                                     true
196 196
                                 );
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
                                     array(
206 206
                                         'id'               => 'wpinv_country',
207 207
                                         'name'             => 'wpinv_country',
208
-                                        'label'            => __( 'Country', 'invoicing' ),
208
+                                        'label'            => __('Country', 'invoicing'),
209 209
                                         'label_type'       => 'vertical',
210
-                                        'placeholder'      => __( 'Choose a country', 'invoicing' ),
210
+                                        'placeholder'      => __('Choose a country', 'invoicing'),
211 211
                                         'class'            => 'form-control-sm getpaid-recalculate-prices-on-change',
212
-                                        'value'            => $invoice->get_country( 'edit' ),
212
+                                        'value'            => $invoice->get_country('edit'),
213 213
                                         'options'          => wpinv_get_country_list(),
214 214
                                         'data-allow-clear' => 'false',
215 215
                                         'select2'          => true,
@@ -221,20 +221,20 @@  discard block
 block discarded – undo
221 221
                         <div class="col-12 col-sm-6">
222 222
                             <?php
223 223
 
224
-                                $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
224
+                                $states = wpinv_get_country_states($invoice->get_country('edit'));
225 225
 
226
-                                if ( empty( $states ) ) {
226
+                                if (empty($states)) {
227 227
 
228 228
 								aui()->input(
229 229
 								array(
230 230
 								'type'        => 'text',
231 231
 								'id'          => 'wpinv_state',
232 232
 								'name'        => 'wpinv_state',
233
-								'label'       => __( 'State', 'invoicing' ),
233
+								'label'       => __('State', 'invoicing'),
234 234
 								'label_type'  => 'vertical',
235 235
 								'placeholder' => '',
236 236
 								'class'       => 'form-control-sm',
237
-								'value'       => $invoice->get_state( 'edit' ),
237
+								'value'       => $invoice->get_state('edit'),
238 238
 								),
239 239
 								true
240 240
 							);
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
 								array(
246 246
 								'id'               => 'wpinv_state',
247 247
 								'name'             => 'wpinv_state',
248
-								'label'            => __( 'State', 'invoicing' ),
248
+								'label'            => __('State', 'invoicing'),
249 249
 								'label_type'       => 'vertical',
250
-								'placeholder'      => __( 'Select a state', 'invoicing' ),
250
+								'placeholder'      => __('Select a state', 'invoicing'),
251 251
 								'class'            => 'form-control-sm',
252
-								'value'            => $invoice->get_state( 'edit' ),
252
+								'value'            => $invoice->get_state('edit'),
253 253
 								'options'          => $states,
254 254
 								'data-allow-clear' => 'false',
255 255
 								'select2'          => true,
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
                                         'type'        => 'text',
272 272
                                         'id'          => 'wpinv_zip',
273 273
                                         'name'        => 'wpinv_zip',
274
-                                        'label'       => __( 'Zip / Postal Code', 'invoicing' ),
274
+                                        'label'       => __('Zip / Postal Code', 'invoicing'),
275 275
                                         'label_type'  => 'vertical',
276 276
                                         'placeholder' => '',
277 277
                                         'class'       => 'form-control-sm',
278
-                                        'value'       => $invoice->get_zip( 'edit' ),
278
+                                        'value'       => $invoice->get_zip('edit'),
279 279
                                     ),
280 280
                                     true
281 281
                                 );
@@ -288,11 +288,11 @@  discard block
 block discarded – undo
288 288
                                         'type'        => 'text',
289 289
                                         'id'          => 'wpinv_phone',
290 290
                                         'name'        => 'wpinv_phone',
291
-                                        'label'       => __( 'Phone', 'invoicing' ),
291
+                                        'label'       => __('Phone', 'invoicing'),
292 292
                                         'label_type'  => 'vertical',
293 293
                                         'placeholder' => '',
294 294
                                         'class'       => 'form-control-sm',
295
-                                        'value'       => $invoice->get_phone( 'edit' ),
295
+                                        'value'       => $invoice->get_phone('edit'),
296 296
                                     ),
297 297
                                     true
298 298
                                 );
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
                         </div>
301 301
                     </div>
302 302
 
303
-                    <?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?>
304
-                        <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?>
303
+                    <?php if (!apply_filters('getpaid_use_new_invoice_items_metabox', false)) : ?>
304
+                        <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?>
305 305
 
306 306
                         <div class="row">
307 307
                             <div class="col-12 col-sm-6">
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
                                         array(
311 311
                                             'id'          => 'wpinv_template',
312 312
                                             'name'        => 'wpinv_template',
313
-                                            'label'       => __( 'Template', 'invoicing' ),
313
+                                            'label'       => __('Template', 'invoicing'),
314 314
                                             'label_type'  => 'vertical',
315
-                                            'placeholder' => __( 'Choose a template', 'invoicing' ),
315
+                                            'placeholder' => __('Choose a template', 'invoicing'),
316 316
                                             'class'       => 'form-control-sm',
317
-                                            'value'       => $invoice->get_template( 'edit' ),
317
+                                            'value'       => $invoice->get_template('edit'),
318 318
                                             'options'     => array(
319
-                                                'quantity' => __( 'Quantity', 'invoicing' ),
320
-                                                'hours'    => __( 'Hours', 'invoicing' ),
319
+                                                'quantity' => __('Quantity', 'invoicing'),
320
+                                                'hours'    => __('Hours', 'invoicing'),
321 321
                                                 //'amount'   => __( 'Amount Only', 'invoicing' ),
322 322
                                             ),
323 323
                                             'data-allow-clear' => 'false',
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
                                         array(
336 336
                                             'id'          => 'wpinv_currency',
337 337
                                             'name'        => 'wpinv_currency',
338
-                                            'label'       => __( 'Currency', 'invoicing' ),
338
+                                            'label'       => __('Currency', 'invoicing'),
339 339
                                             'label_type'  => 'vertical',
340
-                                            'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
340
+                                            'placeholder' => __('Select Invoice Currency', 'invoicing'),
341 341
                                             'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
342
-                                            'value'       => $invoice->get_currency( 'edit' ),
342
+                                            'value'       => $invoice->get_currency('edit'),
343 343
                                             'required'    => false,
344 344
                                             'data-allow-clear' => 'false',
345 345
                                             'select2'     => true,
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
                             </div>
353 353
                         </div>
354 354
 
355
-                        <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?>
355
+                        <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?>
356 356
                     <?php endif; ?>
357 357
 
358 358
                     <div class="row">
@@ -363,11 +363,11 @@  discard block
 block discarded – undo
363 363
                                         'type'        => 'text',
364 364
                                         'id'          => 'wpinv_company_id',
365 365
                                         'name'        => 'wpinv_company_id',
366
-                                        'label'       => __( 'Company ID', 'invoicing' ),
366
+                                        'label'       => __('Company ID', 'invoicing'),
367 367
                                         'label_type'  => 'vertical',
368 368
                                         'placeholder' => '',
369 369
                                         'class'       => 'form-control-sm',
370
-                                        'value'       => $invoice->get_company_id( 'edit' ),
370
+                                        'value'       => $invoice->get_company_id('edit'),
371 371
                                     ),
372 372
                                     true
373 373
                                 );
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
                         </div>
376 376
                     </div>
377 377
 
378
-                    <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?>
378
+                    <?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?>
379 379
             </div>
380 380
         <?php
381 381
     }
@@ -385,51 +385,51 @@  discard block
 block discarded – undo
385 385
 	 *
386 386
 	 * @param int $post_id
387 387
 	 */
388
-	public static function save( $post_id ) {
388
+	public static function save($post_id) {
389 389
 
390 390
         // Prepare the invoice.
391
-        $invoice = new WPInv_Invoice( $post_id );
391
+        $invoice = new WPInv_Invoice($post_id);
392 392
 
393 393
         // Load new data.
394 394
         $invoice->set_props(
395 395
 			array(
396
-                'template'       => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null,
397
-                'email_cc'       => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null,
398
-                'disable_taxes'  => ! empty( $_POST['disable_taxes'] ),
399
-                'currency'       => isset( $_POST['wpinv_currency'] ) ? wpinv_clean( $_POST['wpinv_currency'] ) : null,
400
-                'gateway'        => ( $invoice->needs_payment() && isset( $_POST['wpinv_gateway'] ) ) ? wpinv_clean( $_POST['wpinv_gateway'] ) : null,
401
-                'address'        => isset( $_POST['wpinv_address'] ) ? wpinv_clean( $_POST['wpinv_address'] ) : null,
402
-                'vat_number'     => isset( $_POST['wpinv_vat_number'] ) ? wpinv_clean( $_POST['wpinv_vat_number'] ) : null,
403
-                'company'        => isset( $_POST['wpinv_company'] ) ? wpinv_clean( $_POST['wpinv_company'] ) : null,
404
-                'company_id'     => isset( $_POST['wpinv_company_id'] ) ? wpinv_clean( $_POST['wpinv_company_id'] ) : null,
405
-                'zip'            => isset( $_POST['wpinv_zip'] ) ? wpinv_clean( $_POST['wpinv_zip'] ) : null,
406
-                'state'          => isset( $_POST['wpinv_state'] ) ? wpinv_clean( $_POST['wpinv_state'] ) : null,
407
-                'city'           => isset( $_POST['wpinv_city'] ) ? wpinv_clean( $_POST['wpinv_city'] ) : null,
408
-                'country'        => isset( $_POST['wpinv_country'] ) ? wpinv_clean( $_POST['wpinv_country'] ) : null,
409
-                'phone'          => isset( $_POST['wpinv_phone'] ) ? wpinv_clean( $_POST['wpinv_phone'] ) : null,
410
-                'first_name'     => isset( $_POST['wpinv_first_name'] ) ? wpinv_clean( $_POST['wpinv_first_name'] ) : null,
411
-                'last_name'      => isset( $_POST['wpinv_last_name'] ) ? wpinv_clean( $_POST['wpinv_last_name'] ) : null,
412
-                'author'         => isset( $_POST['post_author_override'] ) ? wpinv_clean( $_POST['post_author_override'] ) : null,
413
-                'date_created'   => isset( $_POST['date_created'] ) ? wpinv_clean( $_POST['date_created'] ) : null,
414
-                'date_completed' => isset( $_POST['wpinv_date_completed'] ) ? wpinv_clean( $_POST['wpinv_date_completed'] ) : null,
415
-                'due_date'       => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null,
416
-                'number'         => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null,
417
-                'status'         => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null,
396
+                'template'       => isset($_POST['wpinv_template']) ? wpinv_clean($_POST['wpinv_template']) : null,
397
+                'email_cc'       => isset($_POST['wpinv_cc']) ? wpinv_clean($_POST['wpinv_cc']) : null,
398
+                'disable_taxes'  => !empty($_POST['disable_taxes']),
399
+                'currency'       => isset($_POST['wpinv_currency']) ? wpinv_clean($_POST['wpinv_currency']) : null,
400
+                'gateway'        => ($invoice->needs_payment() && isset($_POST['wpinv_gateway'])) ? wpinv_clean($_POST['wpinv_gateway']) : null,
401
+                'address'        => isset($_POST['wpinv_address']) ? wpinv_clean($_POST['wpinv_address']) : null,
402
+                'vat_number'     => isset($_POST['wpinv_vat_number']) ? wpinv_clean($_POST['wpinv_vat_number']) : null,
403
+                'company'        => isset($_POST['wpinv_company']) ? wpinv_clean($_POST['wpinv_company']) : null,
404
+                'company_id'     => isset($_POST['wpinv_company_id']) ? wpinv_clean($_POST['wpinv_company_id']) : null,
405
+                'zip'            => isset($_POST['wpinv_zip']) ? wpinv_clean($_POST['wpinv_zip']) : null,
406
+                'state'          => isset($_POST['wpinv_state']) ? wpinv_clean($_POST['wpinv_state']) : null,
407
+                'city'           => isset($_POST['wpinv_city']) ? wpinv_clean($_POST['wpinv_city']) : null,
408
+                'country'        => isset($_POST['wpinv_country']) ? wpinv_clean($_POST['wpinv_country']) : null,
409
+                'phone'          => isset($_POST['wpinv_phone']) ? wpinv_clean($_POST['wpinv_phone']) : null,
410
+                'first_name'     => isset($_POST['wpinv_first_name']) ? wpinv_clean($_POST['wpinv_first_name']) : null,
411
+                'last_name'      => isset($_POST['wpinv_last_name']) ? wpinv_clean($_POST['wpinv_last_name']) : null,
412
+                'author'         => isset($_POST['post_author_override']) ? wpinv_clean($_POST['post_author_override']) : null,
413
+                'date_created'   => isset($_POST['date_created']) ? wpinv_clean($_POST['date_created']) : null,
414
+                'date_completed' => isset($_POST['wpinv_date_completed']) ? wpinv_clean($_POST['wpinv_date_completed']) : null,
415
+                'due_date'       => isset($_POST['wpinv_due_date']) ? wpinv_clean($_POST['wpinv_due_date']) : null,
416
+                'number'         => isset($_POST['wpinv_number']) ? wpinv_clean($_POST['wpinv_number']) : null,
417
+                'status'         => isset($_POST['wpinv_status']) ? wpinv_clean($_POST['wpinv_status']) : null,
418 418
 			)
419 419
         );
420 420
 
421 421
         // Discount code.
422
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
422
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
423 423
 
424
-            if ( isset( $_POST['wpinv_discount_code'] ) ) {
425
-                $invoice->set_discount_code( wpinv_clean( $_POST['wpinv_discount_code'] ) );
424
+            if (isset($_POST['wpinv_discount_code'])) {
425
+                $invoice->set_discount_code(wpinv_clean($_POST['wpinv_discount_code']));
426 426
             }
427 427
 
428
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
429
-            if ( $discount->exists() ) {
430
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
428
+            $discount = new WPInv_Discount($invoice->get_discount_code());
429
+            if ($discount->exists()) {
430
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
431 431
             } else {
432
-                $invoice->remove_discount( 'discount_code' );
432
+                $invoice->remove_discount('discount_code');
433 433
             }
434 434
 
435 435
             // Recalculate totals.
@@ -438,16 +438,16 @@  discard block
 block discarded – undo
438 438
         }
439 439
 
440 440
         // If we're creating a new user...
441
-        if ( ! empty( $_POST['wpinv_new_user'] ) && is_email( stripslashes( $_POST['wpinv_email'] ) ) ) {
441
+        if (!empty($_POST['wpinv_new_user']) && is_email(stripslashes($_POST['wpinv_email']))) {
442 442
 
443 443
             // Attempt to create the user.
444
-            $user = wpinv_create_user( sanitize_email( stripslashes( $_POST['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
444
+            $user = wpinv_create_user(sanitize_email(stripslashes($_POST['wpinv_email'])), $invoice->get_first_name() . $invoice->get_last_name());
445 445
 
446 446
             // If successful, update the invoice author.
447
-            if ( is_numeric( $user ) ) {
448
-                $invoice->set_author( $user );
447
+            if (is_numeric($user)) {
448
+                $invoice->set_author($user);
449 449
             } else {
450
-                wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
450
+                wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__);
451 451
             }
452 452
         }
453 453
 
@@ -461,16 +461,16 @@  discard block
 block discarded – undo
461 461
         $GLOBALS['wpinv_skip_invoice_notification'] = false;
462 462
 
463 463
         // (Maybe) send new user notification.
464
-        $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
465
-        if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
466
-            wp_send_new_user_notifications( $user, 'user' );
464
+        $should_send_notification = wpinv_get_option('disable_new_user_emails');
465
+        if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) {
466
+            wp_send_new_user_notifications($user, 'user');
467 467
         }
468 468
 
469
-        if ( ! empty( $_POST['send_to_customer'] ) && ! $invoice->is_draft() ) {
470
-            getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
469
+        if (!empty($_POST['send_to_customer']) && !$invoice->is_draft()) {
470
+            getpaid()->get('invoice_emails')->user_invoice($invoice, true);
471 471
         }
472 472
 
473 473
         // Fires after an invoice is saved.
474
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
474
+		do_action('wpinv_invoice_metabox_saved', $invoice);
475 475
 	}
476 476
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
125
+
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
131
+
132
+        $invoice = $submission->get_invoice();
133 133
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
138 138
 
139
-		return $invoice;
140
-	}
139
+        return $invoice;
140
+    }
141 141
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150 150
 
151
-		$submission = $this->payment_form_submission;
151
+        $submission = $this->payment_form_submission;
152 152
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
200
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
+            $name = implode( '', array_filter( $name ) );
202 202
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
203 203
 
204
-			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
208
-			}
209
-		}
204
+            // (Maybe) send new user notification.
205
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
+                wp_send_new_user_notifications( $user, 'user' );
208
+            }
209
+        }
210 210
 
211 211
         if ( is_wp_error( $user ) ) {
212 212
             wp_send_json_error( $user->get_error_message() );
@@ -214,47 +214,47 @@  discard block
 block discarded – undo
214 214
 
215 215
         if ( is_numeric( $user ) ) {
216 216
             return $user;
217
-		}
217
+        }
218 218
 
219
-		return $user->ID;
219
+        return $user->ID;
220 220
 
221
-	}
221
+    }
222 222
 
223
-	/**
223
+    /**
224 224
      * Prepares submission data for saving to the database.
225 225
      *
226
-	 * @return array
226
+     * @return array
227 227
      */
228 228
     public function prepare_submission_data_for_saving() {
229 229
 
230
-		$submission = $this->payment_form_submission;
230
+        $submission = $this->payment_form_submission;
231 231
 
232
-		// Prepared submission details.
232
+        // Prepared submission details.
233 233
         $prepared = array(
234
-			'all'  => array(),
235
-			'meta' => array(),
236
-		);
234
+            'all'  => array(),
235
+            'meta' => array(),
236
+        );
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+        $data     = $submission->get_data();
240 240
 
241
-		// Loop through the submitted details.
241
+        // Loop through the submitted details.
242 242
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243 243
 
244
-			// Skip premade fields.
244
+            // Skip premade fields.
245 245
             if ( ! empty( $field['premade'] ) ) {
246 246
                 continue;
247 247
             }
248 248
 
249
-			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
249
+            // Ensure address is provided.
250
+            if ( $field['type'] == 'address' ) {
251 251
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+                foreach ( $field['fields'] as $address_field ) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
-					}
255
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
+                    }
258 258
 }
259 259
 }
260 260
 
@@ -266,31 +266,31 @@  discard block
 block discarded – undo
266 266
             // Handle misc fields.
267 267
             if ( isset( $data[ $field['id'] ] ) ) {
268 268
 
269
-				// Uploads.
270
-				if ( $field['type'] == 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
269
+                // Uploads.
270
+                if ( $field['type'] == 'file_upload' ) {
271
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
-					}
273
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
+                    }
276 276
 
277
-					$value = array();
277
+                    $value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
-						$value[] = sprintf(
281
-							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
284
-						);
285
-					}
279
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+                        $value[] = sprintf(
281
+                            '<a href="%s" target="_blank">%s</a>',
282
+                            esc_url_raw( $url ),
283
+                            esc_html( $name )
284
+                        );
285
+                    }
286 286
 
287
-					$value = implode( ' | ', $value );
287
+                    $value = implode( ' | ', $value );
288 288
 
289
-				} elseif ( $field['type'] == 'checkbox' ) {
290
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
-				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
-				}
289
+                } elseif ( $field['type'] == 'checkbox' ) {
290
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
+                } else {
292
+                    $value = wp_kses_post( $data[ $field['id'] ] );
293
+                }
294 294
 
295 295
                 $label = $field['id'];
296 296
 
@@ -298,188 +298,188 @@  discard block
 block discarded – undo
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
-				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+                if ( ! empty( $field['add_meta'] ) ) {
302
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
+                }
304
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305 305
 
306 306
             }
307 307
 }
308 308
 
309
-		return $prepared;
309
+        return $prepared;
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Retrieves address details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
318
-	 * @param string $type
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318
+     * @param string $type
319 319
      */
320 320
     public function prepare_address_details( $invoice, $type = 'billing' ) {
321 321
 
322
-		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
324
-		$address  = array();
325
-		$prepared = array();
322
+        $data     = $this->payment_form_submission->get_data();
323
+        $type     = sanitize_key( $type );
324
+        $address  = array();
325
+        $prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
329
-		}
327
+        if ( ! empty( $data[ $type ] ) ) {
328
+            $address = $data[ $type ];
329
+        }
330 330
 
331
-		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
-		}
331
+        // Clean address details.
332
+        foreach ( $address as $key => $value ) {
333
+            $key             = sanitize_key( $key );
334
+            $key             = str_replace( 'wpinv_', '', $key );
335
+            $value           = wpinv_clean( $value );
336
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
+        }
338 338
 
339
-		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
339
+        // Filter address details.
340
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341 341
 
342
-		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
342
+        // Remove non-whitelisted values.
343
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344 344
 
345
-	}
345
+    }
346 346
 
347
-	/**
347
+    /**
348 348
      * Prepares the billing details.
349 349
      *
350
-	 * @return array
351
-	 * @param WPInv_Invoice $invoice
350
+     * @return array
351
+     * @param WPInv_Invoice $invoice
352 352
      */
353 353
     protected function prepare_billing_info( &$invoice ) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
356 356
 
357
-		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
357
+        // Update the invoice with the billing details.
358
+        $invoice->set_props( $billing_address );
359 359
 
360
-	}
360
+    }
361 361
 
362
-	/**
362
+    /**
363 363
      * Prepares the shipping details.
364 364
      *
365
-	 * @return array
366
-	 * @param WPInv_Invoice $invoice
365
+     * @return array
366
+     * @param WPInv_Invoice $invoice
367 367
      */
368 368
     protected function prepare_shipping_info( $invoice ) {
369 369
 
370
-		$data = $this->payment_form_submission->get_data();
370
+        $data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
-		}
372
+        if ( empty( $data['same-shipping-address'] ) ) {
373
+            return $this->prepare_address_details( $invoice, 'shipping' );
374
+        }
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+        return $this->prepare_address_details( $invoice, 'billing' );
377 377
 
378
-	}
378
+    }
379 379
 
380
-	/**
381
-	 * Confirms the submission is valid and send users to the gateway.
382
-	 *
383
-	 * @param WPInv_Invoice $invoice
384
-	 * @param array $prepared_payment_form_data
385
-	 * @param array $shipping
386
-	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
380
+    /**
381
+     * Confirms the submission is valid and send users to the gateway.
382
+     *
383
+     * @param WPInv_Invoice $invoice
384
+     * @param array $prepared_payment_form_data
385
+     * @param array $shipping
386
+     */
387
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388 388
 
389
-		// Ensure the invoice exists.
389
+        // Ensure the invoice exists.
390 390
         if ( ! $invoice->exists() ) {
391 391
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392 392
         }
393 393
 
394
-		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
394
+        // Save payment form data.
395
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396 396
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
+        if ( ! empty( $prepared_payment_form_data ) ) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
-			}
400
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+            }
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
-			}
404
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+            }
407 407
 }
408 408
 
409
-		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
409
+        // Save payment form data.
410
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411 411
         if ( ! empty( $shipping ) ) {
412 412
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
-		}
413
+        }
414 414
 
415
-		// Backwards compatibility.
415
+        // Backwards compatibility.
416 416
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417 417
 
418
-		$this->process_payment( $invoice );
418
+        $this->process_payment( $invoice );
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+        wpinv_send_back_to_checkout( $invoice );
422 422
 
423
-	}
423
+    }
424 424
 
425
-	/**
426
-	 * Processes the actual payment.
427
-	 *
428
-	 * @param WPInv_Invoice $invoice
429
-	 */
430
-	protected function process_payment( $invoice ) {
425
+    /**
426
+     * Processes the actual payment.
427
+     *
428
+     * @param WPInv_Invoice $invoice
429
+     */
430
+    protected function process_payment( $invoice ) {
431 431
 
432
-		// Clear any checkout errors.
433
-		wpinv_clear_errors();
432
+        // Clear any checkout errors.
433
+        wpinv_clear_errors();
434 434
 
435
-		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
438
-		}
435
+        // No need to send free invoices to the gateway.
436
+        if ( $invoice->is_free() ) {
437
+            $this->process_free_payment( $invoice );
438
+        }
439 439
 
440
-		$submission = $this->payment_form_submission;
440
+        $submission = $this->payment_form_submission;
441 441
 
442
-		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
442
+        // Fires before sending to the gateway.
443
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
444 444
 
445
-		// Allow the sumission data to be modified before it is sent to the gateway.
446
-		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
445
+        // Allow the sumission data to be modified before it is sent to the gateway.
446
+        $submission_data    = $submission->get_data();
447
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
449 449
 
450
-		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
453
-		}
450
+        // Validate the currency.
451
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
453
+        }
454 454
 
455
-		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
458
-		}
455
+        // Check to see if we have any errors.
456
+        if ( wpinv_get_errors() ) {
457
+            wpinv_send_back_to_checkout( $invoice );
458
+        }
459 459
 
460
-		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
460
+        // Send info to the gateway for payment processing
461
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
462 462
 
463
-		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
463
+        // Backwards compatibility.
464
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
465 465
 
466
-	}
466
+    }
467 467
 
468
-	/**
469
-	 * Marks the invoice as paid in case the checkout is free.
470
-	 *
471
-	 * @param WPInv_Invoice $invoice
472
-	 */
473
-	protected function process_free_payment( $invoice ) {
468
+    /**
469
+     * Marks the invoice as paid in case the checkout is free.
470
+     *
471
+     * @param WPInv_Invoice $invoice
472
+     */
473
+    protected function process_free_payment( $invoice ) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
-		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
475
+        $invoice->set_gateway( 'none' );
476
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
+        $invoice->mark_paid();
478
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
479 479
 
480
-	}
480
+    }
481 481
 
482
-	/**
482
+    /**
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 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,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wp_send_json_error(__('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,33 +146,33 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
163
-
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+		$invoice->set_currency($submission->get_currency());
163
+
164
+		if ($submission->has_shipping()) {
165
+			$invoice->set_shipping($submission->get_shipping());
166 166
 		}
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+		$address_confirmed = $submission->get_field('confirm-address');
169
+		$invoice->set_address_confirmed(!empty($address_confirmed));
170 170
 
171
-		if ( $submission->has_discount_code() ) {
172
-            $invoice->set_discount_code( $submission->get_discount_code() );
171
+		if ($submission->has_discount_code()) {
172
+            $invoice->set_discount_code($submission->get_discount_code());
173 173
 		}
174 174
 
175
-		getpaid_maybe_add_default_address( $invoice );
175
+		getpaid_maybe_add_default_address($invoice);
176 176
 		return $invoice;
177 177
 	}
178 178
 
@@ -185,34 +185,34 @@  discard block
 block discarded – undo
185 185
 		$submission = $this->payment_form_submission;
186 186
 
187 187
 		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
188
+		if ($submission->has_invoice()) {
189 189
 			return $submission->get_invoice()->get_user_id();
190 190
 		}
191 191
 
192 192
 		// (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = get_user_by( 'email', $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = get_user_by('email', $submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
202
-            $user = wpinv_create_user( $submission->get_billing_email(), $name );
199
+        if (empty($user)) {
200
+			$name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing'));
201
+			$name = implode('', array_filter($name));
202
+            $user = wpinv_create_user($submission->get_billing_email(), $name);
203 203
 
204 204
 			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
205
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
206
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
207
+				wp_send_new_user_notifications($user, 'user');
208 208
 			}
209 209
 		}
210 210
 
211
-        if ( is_wp_error( $user ) ) {
212
-            wp_send_json_error( $user->get_error_message() );
211
+        if (is_wp_error($user)) {
212
+            wp_send_json_error($user->get_error_message());
213 213
         }
214 214
 
215
-        if ( is_numeric( $user ) ) {
215
+        if (is_numeric($user)) {
216 216
             return $user;
217 217
 		}
218 218
 
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
 		);
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+		$data = $submission->get_data();
240 240
 
241 241
 		// Loop through the submitted details.
242
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
242
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
243 243
 
244 244
 			// Skip premade fields.
245
-            if ( ! empty( $field['premade'] ) ) {
245
+            if (!empty($field['premade'])) {
246 246
                 continue;
247 247
             }
248 248
 
249 249
 			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
251
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
250
+			if ($field['type'] == 'address') {
251
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+				foreach ($field['fields'] as $address_field) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
255
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) {
256
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
257 257
 					}
258 258
 }
259 259
 }
260 260
 
261 261
             // If it is required and not set, abort.
262
-            if ( ! $submission->is_required_field_set( $field ) ) {
263
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
262
+            if (!$submission->is_required_field_set($field)) {
263
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
264 264
             }
265 265
 
266 266
             // Handle misc fields.
267
-            if ( isset( $data[ $field['id'] ] ) ) {
267
+            if (isset($data[$field['id']])) {
268 268
 
269 269
 				// Uploads.
270
-				if ( $field['type'] == 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+				if ($field['type'] == 'file_upload') {
271
+					$max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']);
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
273
+					if (count($data[$field['id']]) > $max_file_num) {
274
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
275 275
 					}
276 276
 
277 277
 					$value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
279
+					foreach ($data[$field['id']] as $url => $name) {
280 280
 						$value[] = sprintf(
281 281
 							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
282
+							esc_url_raw($url),
283
+							esc_html($name)
284 284
 						);
285 285
 					}
286 286
 
287
-					$value = implode( ' | ', $value );
287
+					$value = implode(' | ', $value);
288 288
 
289
-				} elseif ( $field['type'] == 'checkbox' ) {
290
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
289
+				} elseif ($field['type'] == 'checkbox') {
290
+					$value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
291 291
 				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
292
+					$value = wp_kses_post($data[$field['id']]);
293 293
 				}
294 294
 
295 295
                 $label = $field['id'];
296 296
 
297
-                if ( isset( $field['label'] ) ) {
297
+                if (isset($field['label'])) {
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+				if (!empty($field['add_meta'])) {
302
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
303 303
 				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
305 305
 
306 306
             }
307 307
 }
@@ -317,30 +317,30 @@  discard block
 block discarded – undo
317 317
 	 * @param WPInv_Invoice $invoice
318 318
 	 * @param string $type
319 319
      */
320
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
320
+    public function prepare_address_details($invoice, $type = 'billing') {
321 321
 
322 322
 		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
323
+		$type     = sanitize_key($type);
324 324
 		$address  = array();
325 325
 		$prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
327
+		if (!empty($data[$type])) {
328
+			$address = $data[$type];
329 329
 		}
330 330
 
331 331
 		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
332
+		foreach ($address as $key => $value) {
333
+			$key             = sanitize_key($key);
334
+			$key             = str_replace('wpinv_', '', $key);
335
+			$value           = wpinv_clean($value);
336
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
337 337
 		}
338 338
 
339 339
 		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
340
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
341 341
 
342 342
 		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
343
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
344 344
 
345 345
 	}
346 346
 
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 	 * @return array
351 351
 	 * @param WPInv_Invoice $invoice
352 352
      */
353
-    protected function prepare_billing_info( &$invoice ) {
353
+    protected function prepare_billing_info(&$invoice) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
356 356
 
357 357
 		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
358
+		$invoice->set_props($billing_address);
359 359
 
360 360
 	}
361 361
 
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	 * @return array
366 366
 	 * @param WPInv_Invoice $invoice
367 367
      */
368
-    protected function prepare_shipping_info( $invoice ) {
368
+    protected function prepare_shipping_info($invoice) {
369 369
 
370 370
 		$data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
372
+		if (empty($data['same-shipping-address'])) {
373
+			return $this->prepare_address_details($invoice, 'shipping');
374 374
 		}
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+		return $this->prepare_address_details($invoice, 'billing');
377 377
 
378 378
 	}
379 379
 
@@ -384,41 +384,41 @@  discard block
 block discarded – undo
384 384
 	 * @param array $prepared_payment_form_data
385 385
 	 * @param array $shipping
386 386
 	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
387
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
388 388
 
389 389
 		// Ensure the invoice exists.
390
-        if ( ! $invoice->exists() ) {
391
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
390
+        if (!$invoice->exists()) {
391
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
392 392
         }
393 393
 
394 394
 		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
395
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
396
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
397
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
398
+		if (!empty($prepared_payment_form_data)) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
400
+			if (!empty($prepared_payment_form_data['all'])) {
401
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
402 402
 			}
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
404
+			if (!empty($prepared_payment_form_data['meta'])) {
405
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
406 406
 			}
407 407
 }
408 408
 
409 409
 		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411
-        if ( ! empty( $shipping ) ) {
412
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
410
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
411
+        if (!empty($shipping)) {
412
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
413 413
 		}
414 414
 
415 415
 		// Backwards compatibility.
416
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
416
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
417 417
 
418
-		$this->process_payment( $invoice );
418
+		$this->process_payment($invoice);
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+		wpinv_send_back_to_checkout($invoice);
422 422
 
423 423
 	}
424 424
 
@@ -427,41 +427,41 @@  discard block
 block discarded – undo
427 427
 	 *
428 428
 	 * @param WPInv_Invoice $invoice
429 429
 	 */
430
-	protected function process_payment( $invoice ) {
430
+	protected function process_payment($invoice) {
431 431
 
432 432
 		// Clear any checkout errors.
433 433
 		wpinv_clear_errors();
434 434
 
435 435
 		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
436
+		if ($invoice->is_free()) {
437
+			$this->process_free_payment($invoice);
438 438
 		}
439 439
 
440 440
 		$submission = $this->payment_form_submission;
441 441
 
442 442
 		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
443
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
444 444
 
445 445
 		// Allow the sumission data to be modified before it is sent to the gateway.
446 446
 		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
447
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
448
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
449 449
 
450 450
 		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
451
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
452
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
453 453
 		}
454 454
 
455 455
 		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
456
+		if (wpinv_get_errors()) {
457
+			wpinv_send_back_to_checkout($invoice);
458 458
 		}
459 459
 
460 460
 		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
461
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
462 462
 
463 463
 		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
464
+		wpinv_send_to_gateway($submission_gateway, $invoice);
465 465
 
466 466
 	}
467 467
 
@@ -470,12 +470,12 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @param WPInv_Invoice $invoice
472 472
 	 */
473
-	protected function process_free_payment( $invoice ) {
473
+	protected function process_free_payment($invoice) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
475
+		$invoice->set_gateway('none');
476
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
477 477
 		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
478
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
479 479
 
480 480
 	}
481 481
 
@@ -483,9 +483,9 @@  discard block
 block discarded – undo
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
486
-    public function send_redirect_response( $url ) {
487
-        $url = urlencode( $url );
488
-        wp_send_json_success( $url );
486
+    public function send_redirect_response($url) {
487
+        $url = urlencode($url);
488
+        wp_send_json_success($url);
489 489
     }
490 490
 
491 491
 }
Please login to merge, or discard this patch.
includes/class-getpaid-notification-email-sender.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Notification_Email_Sender {
14 14
 
15 15
     /**
16
-	 * Whether or not we should inline CSS into the email.
17
-	 */
18
-	public $inline_css = true;
16
+     * Whether or not we should inline CSS into the email.
17
+     */
18
+    public $inline_css = true;
19 19
 
20 20
     /**
21
-	 * The wp_mail() data.
22
-	 */
21
+     * The wp_mail() data.
22
+     */
23 23
     public $wp_mail_data = null;
24 24
 
25 25
     /**
26
-	 * Sends a new email.
26
+     * Sends a new email.
27 27
      *
28 28
      * @param string|array $to The recipients email or an array of recipient emails.
29 29
      * @param string $subject The email's subject.
@@ -31,49 +31,49 @@  discard block
 block discarded – undo
31 31
      * @param array $attachments The email attachments.
32 32
      *
33 33
      * @return bool
34
-	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
34
+     */
35
+    public function send( $to, $subject, $email, $attachments = array() ) {
36 36
 
37
-		/*
37
+        /*
38 38
 		 * Allow to filter data on per-email basis.
39 39
 		 */
40
-		$data = apply_filters(
41
-			'getpaid_email_data',
42
-			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
-				'headers'     => $this->get_headers(),
47
-				'attachments' => $attachments,
48
-			),
49
-			$this
50
-		);
40
+        $data = apply_filters(
41
+            'getpaid_email_data',
42
+            array(
43
+                'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
+                'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
+                'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
+                'headers'     => $this->get_headers(),
47
+                'attachments' => $attachments,
48
+            ),
49
+            $this
50
+        );
51 51
 
52 52
         // Remove slashes.
53 53
         $data               = (array) wp_unslash( $data );
54 54
 
55 55
         // Cache it.
56
-		$this->wp_mail_data = $data;
56
+        $this->wp_mail_data = $data;
57 57
 
58
-		// Attach our own hooks.
59
-		$this->before_sending();
58
+        // Attach our own hooks.
59
+        $this->before_sending();
60 60
 
61 61
         $result = false;
62 62
 
63 63
         foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
64
+            $result = $this->_send( $to, $data );
65 65
         }
66 66
 
67
-		// Remove our hooks.
68
-		$this->after_sending();
67
+        // Remove our hooks.
68
+        $this->after_sending();
69 69
 
70
-		$this->wp_mail_data = null;
70
+        $this->wp_mail_data = null;
71 71
 
72
-		return $result;
73
-	}
72
+        return $result;
73
+    }
74 74
 
75
-	/**
76
-	 * Does the actual sending.
75
+    /**
76
+     * Does the actual sending.
77 77
      *
78 78
      * @param string $to The recipient's email.
79 79
      * @param array $data The email's data.
@@ -81,81 +81,81 @@  discard block
 block discarded – undo
81 81
      * @param array $attachments The email attachments.
82 82
      *
83 83
      * @return bool
84
-	 */
85
-	protected function _send( $to, $data ) {
86
-
87
-		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
-
90
-		// Send the actual email.
91
-		$result = call_user_func(
92
-			$sending_function,
93
-			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
-			$data['email'],
96
-			$data['headers'],
97
-			$data['attachments']
98
-		);
99
-
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
-		}
104
-
105
-		return $result;
106
-	}
84
+     */
85
+    protected function _send( $to, $data ) {
86
+
87
+        // Prepare the sending function.
88
+        $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
+
90
+        // Send the actual email.
91
+        $result = call_user_func(
92
+            $sending_function,
93
+            $to,
94
+            html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
+            $data['email'],
96
+            $data['headers'],
97
+            $data['attachments']
98
+        );
99
+
100
+        if ( ! $result ) {
101
+            $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
+            wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
+        }
104
+
105
+        return $result;
106
+    }
107 107
 
108 108
     /**
109
-	 * Retrieves email headers.
110
-	 */
111
-	public function get_headers() {
109
+     * Retrieves email headers.
110
+     */
111
+    public function get_headers() {
112 112
 
113
-		$name       = $this->get_from_name();
114
-		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
113
+        $name       = $this->get_from_name();
114
+        $reply_to   = $this->get_reply_to();
115
+        $headers    = array( "Reply-To:$name <$reply_to>" );
116 116
 
117
-		return apply_filters( 'getpaid_email_headers', $headers, $this );
117
+        return apply_filters( 'getpaid_email_headers', $headers, $this );
118 118
 
119
-	}
119
+    }
120 120
 
121 121
     /**
122
-	 * Fires before an email is sent
123
-	 *
124
-	 * @since 1.0.0
125
-	 */
126
-	public function before_sending() {
122
+     * Fires before an email is sent
123
+     *
124
+     * @since 1.0.0
125
+     */
126
+    public function before_sending() {
127 127
 
128 128
         do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
129
+        add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
+        add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
+        add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
+        add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
133 133
 
134
-	}
134
+    }
135 135
 
136 136
     /**
137
-	 * Returns the from name.
138
-	 */
139
-	public function get_from_name() {
137
+     * Returns the from name.
138
+     */
139
+    public function get_from_name() {
140 140
 
141 141
         $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name = get_bloginfo( 'name' );
143
+        if ( empty( $from_name ) ) {
144
+            $from_name = get_bloginfo( 'name' );
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+        return wp_specialchars_decode( $from_name, ENT_QUOTES );
148 148
     }
149 149
 
150 150
     /**
151
-	 * Returns the from email.
152
-	 */
153
-	public function get_from_address() {
151
+     * Returns the from email.
152
+     */
153
+    public function get_from_address() {
154 154
 
155 155
         $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
158
-			$from_address = $this->default_from_address();
157
+        if ( ! is_email( $from_address ) ) {
158
+            $from_address = $this->default_from_address();
159 159
         }
160 160
 
161 161
         return $from_address;
@@ -163,75 +163,75 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     /**
166
-	 * The default emails from address.
167
-	 *
168
-	 * Defaults to wordpress@$sitename
169
-	 * Some hosts will block outgoing mail from this address if it doesn't exist,
170
-	 * but there's no easy alternative. Defaulting to admin_email might appear to be
171
-	 * another option, but some hosts may refuse to relay mail from an unknown domain.
172
-	 *
173
-	 */
174
-	public function default_from_address() {
175
-
176
-		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
180
-		}
181
-
182
-		$from_email = 'wordpress@' . $sitename;
183
-
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
166
+     * The default emails from address.
167
+     *
168
+     * Defaults to wordpress@$sitename
169
+     * Some hosts will block outgoing mail from this address if it doesn't exist,
170
+     * but there's no easy alternative. Defaulting to admin_email might appear to be
171
+     * another option, but some hosts may refuse to relay mail from an unknown domain.
172
+     *
173
+     */
174
+    public function default_from_address() {
175
+
176
+        // Get the site domain and get rid of www.
177
+        $sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
+        if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
+            $sitename = substr( $sitename, 4 );
180
+        }
181
+
182
+        $from_email = 'wordpress@' . $sitename;
183
+
184
+        return apply_filters( 'getpaid_default_from_address', $from_email );
185 185
 
186 186
     }
187 187
 
188 188
     /**
189
-	 * Get the email reply-to.
190
-	 *
191
-	 *
192
-	 * @return string The email reply-to address.
193
-	 */
194
-	public function get_reply_to() {
189
+     * Get the email reply-to.
190
+     *
191
+     *
192
+     * @return string The email reply-to address.
193
+     */
194
+    public function get_reply_to() {
195 195
 
196
-		$reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
196
+        $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to = get_option( 'admin_email' );
200
-		}
198
+        if ( ! is_email( $reply_to ) ) {
199
+            $reply_to = get_option( 'admin_email' );
200
+        }
201 201
 
202
-		return $reply_to;
202
+        return $reply_to;
203 203
     }
204 204
 
205 205
     /**
206
-	 * Get the email content type.
207
-	 *
208
-	 */
209
-	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
206
+     * Get the email content type.
207
+     *
208
+     */
209
+    public function get_content_type() {
210
+        return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
211 211
     }
212 212
 
213 213
     /**
214
-	 * Ensures that our email messages are not messed up by template plugins.
215
-	 *
216
-	 * @return array wp_mail_data.
217
-	 */
218
-	public function ensure_email_content( $args ) {
219
-		$args['message'] = $this->wp_mail_data['email'];
220
-		return $args;
214
+     * Ensures that our email messages are not messed up by template plugins.
215
+     *
216
+     * @return array wp_mail_data.
217
+     */
218
+    public function ensure_email_content( $args ) {
219
+        $args['message'] = $this->wp_mail_data['email'];
220
+        return $args;
221 221
     }
222 222
 
223 223
     /**
224
-	 * A little house keeping after an email is sent.
225
-	 *
226
- 	 */
227
-	public function after_sending() {
224
+     * A little house keeping after an email is sent.
225
+     *
226
+     */
227
+    public function after_sending() {
228 228
 
229 229
         do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
230
+        remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
+        remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
+        remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
+        remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
234 234
 
235
-	}
235
+    }
236 236
 
237 237
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 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
  * This function is responsible for sending emails.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @return bool
34 34
 	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
35
+	public function send($to, $subject, $email, $attachments = array()) {
36 36
 
37 37
 		/*
38 38
 		 * Allow to filter data on per-email basis.
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 		$data = apply_filters(
41 41
 			'getpaid_email_data',
42 42
 			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
43
+				'to'          => array_filter(array_unique(wpinv_parse_list($to))),
44
+				'subject'     => htmlspecialchars_decode(wp_strip_all_tags($subject), ENT_QUOTES),
45
+				'email'       => apply_filters('wpinv_mail_content', $email),
46 46
 				'headers'     => $this->get_headers(),
47 47
 				'attachments' => $attachments,
48 48
 			),
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		);
51 51
 
52 52
         // Remove slashes.
53
-        $data               = (array) wp_unslash( $data );
53
+        $data = (array) wp_unslash($data);
54 54
 
55 55
         // Cache it.
56 56
 		$this->wp_mail_data = $data;
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 
61 61
         $result = false;
62 62
 
63
-        foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
63
+        foreach ($this->wp_mail_data['to'] as $to) {
64
+			$result = $this->_send($to, $data);
65 65
         }
66 66
 
67 67
 		// Remove our hooks.
@@ -82,24 +82,24 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @return bool
84 84
 	 */
85
-	protected function _send( $to, $data ) {
85
+	protected function _send($to, $data) {
86 86
 
87 87
 		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
88
+		$sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail');
89 89
 
90 90
 		// Send the actual email.
91 91
 		$result = call_user_func(
92 92
 			$sending_function,
93 93
 			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
94
+			html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')),
95 95
 			$data['email'],
96 96
 			$data['headers'],
97 97
 			$data['attachments']
98 98
 		);
99 99
 
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
100
+		if (!$result) {
101
+			$log_message = wp_sprintf(__("\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']);
102
+			wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__);
103 103
 		}
104 104
 
105 105
 		return $result;
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$name       = $this->get_from_name();
114 114
 		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
115
+		$headers    = array("Reply-To:$name <$reply_to>");
116 116
 
117
-		return apply_filters( 'getpaid_email_headers', $headers, $this );
117
+		return apply_filters('getpaid_email_headers', $headers, $this);
118 118
 
119 119
 	}
120 120
 
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function before_sending() {
127 127
 
128
-        do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
128
+        do_action('getpaid_before_send_email', $this);
129
+		add_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
130
+		add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
131
+		add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
132
+		add_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
133 133
 
134 134
 	}
135 135
 
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function get_from_name() {
140 140
 
141
-        $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
141
+        $from_name = wpinv_get_option('email_from_name', get_bloginfo('name'));
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name = get_bloginfo( 'name' );
143
+		if (empty($from_name)) {
144
+			$from_name = get_bloginfo('name');
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+		return wp_specialchars_decode($from_name, ENT_QUOTES);
148 148
     }
149 149
 
150 150
     /**
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function get_from_address() {
154 154
 
155
-        $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
155
+        $from_address = wpinv_get_option('email_from', $this->default_from_address());
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
157
+		if (!is_email($from_address)) {
158 158
 			$from_address = $this->default_from_address();
159 159
         }
160 160
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	public function default_from_address() {
175 175
 
176 176
 		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
177
+		$sitename = strtolower($_SERVER['SERVER_NAME']);
178
+		if (substr($sitename, 0, 4) == 'www.') {
179
+			$sitename = substr($sitename, 4);
180 180
 		}
181 181
 
182 182
 		$from_email = 'wordpress@' . $sitename;
183 183
 
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
184
+		return apply_filters('getpaid_default_from_address', $from_email);
185 185
 
186 186
     }
187 187
 
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	public function get_reply_to() {
195 195
 
196
-		$reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
196
+		$reply_to = current(wpinv_parse_list(wpinv_get_admin_email()));
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to = get_option( 'admin_email' );
198
+		if (!is_email($reply_to)) {
199
+			$reply_to = get_option('admin_email');
200 200
 		}
201 201
 
202 202
 		return $reply_to;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 */
209 209
 	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
210
+		return apply_filters('getpaid_email_content_type', 'text/html', $this);
211 211
     }
212 212
 
213 213
     /**
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return array wp_mail_data.
217 217
 	 */
218
-	public function ensure_email_content( $args ) {
218
+	public function ensure_email_content($args) {
219 219
 		$args['message'] = $this->wp_mail_data['email'];
220 220
 		return $args;
221 221
     }
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
  	 */
227 227
 	public function after_sending() {
228 228
 
229
-        do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
229
+        do_action('getpaid_after_send_email', $this->wp_mail_data);
230
+		remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
231
+		remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
232
+		remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
233
+		remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
234 234
 
235 235
 	}
236 236
 
Please login to merge, or discard this patch.