Passed
Pull Request — master (#462)
by Viktor
04:15
created
templates/invoice/details-top.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,24 +7,24 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14
-        <?php do_action( 'getpaid_before_invoice_details_top', $invoice ); ?>
14
+        <?php do_action('getpaid_before_invoice_details_top', $invoice); ?>
15 15
 
16 16
         <div class="getpaid-invoice-details-top mb-5">
17 17
             <div class="row">
18 18
                 <div class="col-12 col-sm-6 text-sm-left">
19
-                    <?php do_action( 'getpaid_invoice_details_top_left', $invoice ); ?>
19
+                    <?php do_action('getpaid_invoice_details_top_left', $invoice); ?>
20 20
                 </div>
21 21
 
22 22
                 <div class="col-12 col-sm-6 text-sm-right">
23
-                    <?php do_action( 'getpaid_invoice_details_top_right', $invoice ); ?>
23
+                    <?php do_action('getpaid_invoice_details_top_right', $invoice); ?>
24 24
                 </div>
25 25
             </div>
26 26
         </div>
27 27
 
28
-        <?php do_action( 'getpaid_after_invoice_details_top', $invoice ); ?>
28
+        <?php do_action('getpaid_after_invoice_details_top', $invoice); ?>
29 29
 
30 30
 <?php
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +390 added lines, -390 removed lines patch added patch discarded remove patch
@@ -12,444 +12,444 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
-	}
152
-
153
-	/**
154
-	 * Helper function to send an email.
155
-	 *
156
-	 * @param WPInv_Invoice $invoice
157
-	 * @param GetPaid_Notification_Email $email
158
-	 * @param string $type
159
-	 * @param string|array $recipients
160
-	 * @param array $extra_args Extra template args.
161
-	 */
162
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
-
164
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
-
166
-		$mailer     = new GetPaid_Notification_Email_Sender();
167
-		$merge_tags = $email->get_merge_tags();
168
-
169
-		$result = $mailer->send(
170
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
-			$email->get_content( $merge_tags, $extra_args ),
173
-			$email->get_attachments()
174
-		);
175
-
176
-		// Maybe send a copy to the admin.
177
-		if ( $email->include_admin_bcc() ) {
178
-			$mailer->send(
179
-				wpinv_get_admin_email(),
180
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
-				$email->get_content( $merge_tags ),
182
-				$email->get_attachments()
183
-			);
184
-		}
185
-
186
-		if ( ! $result ) {
187
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
188
-		}
189
-
190
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
191
-
192
-		return $result;
193
-	}
194
-
195
-	/**
196
-	 * Also send emails to any cc users.
197
-	 *
198
-	 * @param array $recipients
199
-	 * @param GetPaid_Notification_Email $email
200
-	 */
201
-	public function filter_email_recipients( $recipients, $email ) {
202
-
203
-		if ( ! $email->is_admin_email() ) {
204
-			$cc = $email->object->get_email_cc();
205
-
206
-			if ( ! empty( $cc ) ) {
207
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
209
-			}
210
-
211
-		}
212
-
213
-		return $recipients;
214
-
215
-	}
216
-
217
-	/**
218
-	 * Sends a new invoice notification.
219
-	 *
220
-	 * @param WPInv_Invoice $invoice
221
-	 */
222
-	public function new_invoice( $invoice ) {
223
-
224
-		// Only send this email for invoices created via the admin page.
225
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
226
-			return;
227
-		}
228
-
229
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
230
-		$recipient = wpinv_get_admin_email();
231
-
232
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
233
-
234
-	}
235
-
236
-	/**
237
-	 * Sends a cancelled invoice notification.
238
-	 *
239
-	 * @param WPInv_Invoice $invoice
240
-	 */
241
-	public function cancelled_invoice( $invoice ) {
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
+    }
152
+
153
+    /**
154
+     * Helper function to send an email.
155
+     *
156
+     * @param WPInv_Invoice $invoice
157
+     * @param GetPaid_Notification_Email $email
158
+     * @param string $type
159
+     * @param string|array $recipients
160
+     * @param array $extra_args Extra template args.
161
+     */
162
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
+
164
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
+
166
+        $mailer     = new GetPaid_Notification_Email_Sender();
167
+        $merge_tags = $email->get_merge_tags();
168
+
169
+        $result = $mailer->send(
170
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
+            $email->get_content( $merge_tags, $extra_args ),
173
+            $email->get_attachments()
174
+        );
175
+
176
+        // Maybe send a copy to the admin.
177
+        if ( $email->include_admin_bcc() ) {
178
+            $mailer->send(
179
+                wpinv_get_admin_email(),
180
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
+                $email->get_content( $merge_tags ),
182
+                $email->get_attachments()
183
+            );
184
+        }
185
+
186
+        if ( ! $result ) {
187
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
188
+        }
189
+
190
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
191
+
192
+        return $result;
193
+    }
194
+
195
+    /**
196
+     * Also send emails to any cc users.
197
+     *
198
+     * @param array $recipients
199
+     * @param GetPaid_Notification_Email $email
200
+     */
201
+    public function filter_email_recipients( $recipients, $email ) {
202
+
203
+        if ( ! $email->is_admin_email() ) {
204
+            $cc = $email->object->get_email_cc();
205
+
206
+            if ( ! empty( $cc ) ) {
207
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
209
+            }
210
+
211
+        }
212
+
213
+        return $recipients;
214
+
215
+    }
216
+
217
+    /**
218
+     * Sends a new invoice notification.
219
+     *
220
+     * @param WPInv_Invoice $invoice
221
+     */
222
+    public function new_invoice( $invoice ) {
223
+
224
+        // Only send this email for invoices created via the admin page.
225
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
226
+            return;
227
+        }
228
+
229
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
230
+        $recipient = wpinv_get_admin_email();
231
+
232
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
233
+
234
+    }
235
+
236
+    /**
237
+     * Sends a cancelled invoice notification.
238
+     *
239
+     * @param WPInv_Invoice $invoice
240
+     */
241
+    public function cancelled_invoice( $invoice ) {
242 242
 
243
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
244
-		$recipient = wpinv_get_admin_email();
243
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
244
+        $recipient = wpinv_get_admin_email();
245 245
 
246
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
246
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
247 247
 
248
-	}
248
+    }
249 249
 
250
-	/**
251
-	 * Sends a failed invoice notification.
252
-	 *
253
-	 * @param WPInv_Invoice $invoice
254
-	 */
255
-	public function failed_invoice( $invoice ) {
250
+    /**
251
+     * Sends a failed invoice notification.
252
+     *
253
+     * @param WPInv_Invoice $invoice
254
+     */
255
+    public function failed_invoice( $invoice ) {
256 256
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
258
-		$recipient = wpinv_get_admin_email();
257
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
258
+        $recipient = wpinv_get_admin_email();
259 259
 
260
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
260
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
261 261
 
262
-	}
262
+    }
263 263
 
264
-	/**
265
-	 * Sends a notification whenever an invoice is put on hold.
266
-	 *
267
-	 * @param WPInv_Invoice $invoice
268
-	 */
269
-	public function onhold_invoice( $invoice ) {
264
+    /**
265
+     * Sends a notification whenever an invoice is put on hold.
266
+     *
267
+     * @param WPInv_Invoice $invoice
268
+     */
269
+    public function onhold_invoice( $invoice ) {
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = $invoice->get_email();
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = $invoice->get_email();
273 273
 
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275 275
 
276
-	}
276
+    }
277 277
 
278
-	/**
279
-	 * Sends a notification whenever an invoice is marked as processing payment.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function processing_invoice( $invoice ) {
278
+    /**
279
+     * Sends a notification whenever an invoice is marked as processing payment.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function processing_invoice( $invoice ) {
284 284
 
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = $invoice->get_email();
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
+        $recipient = $invoice->get_email();
287 287
 
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289 289
 
290
-	}
290
+    }
291 291
 
292
-	/**
293
-	 * Sends a notification whenever an invoice is paid.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice
296
-	 */
297
-	public function completed_invoice( $invoice ) {
292
+    /**
293
+     * Sends a notification whenever an invoice is paid.
294
+     *
295
+     * @param WPInv_Invoice $invoice
296
+     */
297
+    public function completed_invoice( $invoice ) {
298 298
 
299
-		// (Maybe) abort if it is a renewal invoice.
300
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
301
-			return;
302
-		}
299
+        // (Maybe) abort if it is a renewal invoice.
300
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
301
+            return;
302
+        }
303 303
 
304
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
305
-		$recipient = $invoice->get_email();
304
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
305
+        $recipient = $invoice->get_email();
306 306
 
307
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
307
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
308 308
 
309
-	}
309
+    }
310 310
 
311
-	/**
312
-	 * Sends a notification whenever an invoice is refunded.
313
-	 *
314
-	 * @param WPInv_Invoice $invoice
315
-	 */
316
-	public function refunded_invoice( $invoice ) {
311
+    /**
312
+     * Sends a notification whenever an invoice is refunded.
313
+     *
314
+     * @param WPInv_Invoice $invoice
315
+     */
316
+    public function refunded_invoice( $invoice ) {
317 317
 
318
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
319
-		$recipient = $invoice->get_email();
318
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
319
+        $recipient = $invoice->get_email();
320 320
 
321
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
321
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
322 322
 
323
-	}
323
+    }
324 324
 
325
-	/**
326
-	 * Notifies a user about new invoices
327
-	 *
328
-	 * @param WPInv_Invoice $invoice
329
-	 */
330
-	public function user_invoice( $invoice ) {
325
+    /**
326
+     * Notifies a user about new invoices
327
+     *
328
+     * @param WPInv_Invoice $invoice
329
+     */
330
+    public function user_invoice( $invoice ) {
331 331
 
332
-		// Only send this email for invoices created via the admin page.
333
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
334
-			return;
335
-		}
332
+        // Only send this email for invoices created via the admin page.
333
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
334
+            return;
335
+        }
336 336
 
337
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
338
-		$recipient = $invoice->get_email();
337
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
338
+        $recipient = $invoice->get_email();
339 339
 
340
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
340
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
341 341
 
342
-	}
342
+    }
343 343
 
344
-	/**
345
-	 * Checks if an invoice is a payment form invoice.
346
-	 *
347
-	 * @param int $invoice
348
-	 * @return bool
349
-	 */
350
-	public function is_payment_form_invoice( $invoice ) {
351
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
352
-	}
344
+    /**
345
+     * Checks if an invoice is a payment form invoice.
346
+     *
347
+     * @param int $invoice
348
+     * @return bool
349
+     */
350
+    public function is_payment_form_invoice( $invoice ) {
351
+        return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
352
+    }
353 353
 
354
-	/**
355
-	 * Notifies admin about new invoice notes
356
-	 *
357
-	 * @param WPInv_Invoice $invoice
358
-	 * @param string $note
359
-	 */
360
-	public function user_note( $invoice, $note ) {
354
+    /**
355
+     * Notifies admin about new invoice notes
356
+     *
357
+     * @param WPInv_Invoice $invoice
358
+     * @param string $note
359
+     */
360
+    public function user_note( $invoice, $note ) {
361 361
 
362
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
363
-		$recipient = $invoice->get_email();
364
-
365
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
366
-
367
-	}
362
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
363
+        $recipient = $invoice->get_email();
364
+
365
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
366
+
367
+    }
368 368
 
369
-	/**
370
-	 * (Force) Sends overdue notices.
371
-	 *
372
-	 * @param WPInv_Invoice $invoice
373
-	 */
374
-	public function force_send_overdue_notice( $invoice ) {
375
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
376
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
377
-	}
378
-
379
-	/**
380
-	 * Sends overdue notices.
381
-	 *
382
-	 * @TODO: Create an invoices query class.
383
-	 */
384
-	public function overdue() {
385
-		global $wpdb;
386
-
387
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
388
-
389
-		// Fetch reminder days.
390
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
391
-
392
-		// Abort if non is set.
393
-		if ( empty( $reminder_days ) ) {
394
-			return;
395
-		}
396
-
397
-		// Retrieve date query.
398
-		$date_query = $this->get_date_query( $reminder_days );
399
-
400
-		// Invoices table.
401
-		$table = $wpdb->prefix . 'getpaid_invoices';
402
-
403
-		// Fetch invoices.
404
-		$invoices  = $wpdb->get_col(
405
-			"SELECT posts.ID FROM $wpdb->posts as posts
369
+    /**
370
+     * (Force) Sends overdue notices.
371
+     *
372
+     * @param WPInv_Invoice $invoice
373
+     */
374
+    public function force_send_overdue_notice( $invoice ) {
375
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
376
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
377
+    }
378
+
379
+    /**
380
+     * Sends overdue notices.
381
+     *
382
+     * @TODO: Create an invoices query class.
383
+     */
384
+    public function overdue() {
385
+        global $wpdb;
386
+
387
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
388
+
389
+        // Fetch reminder days.
390
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
391
+
392
+        // Abort if non is set.
393
+        if ( empty( $reminder_days ) ) {
394
+            return;
395
+        }
396
+
397
+        // Retrieve date query.
398
+        $date_query = $this->get_date_query( $reminder_days );
399
+
400
+        // Invoices table.
401
+        $table = $wpdb->prefix . 'getpaid_invoices';
402
+
403
+        // Fetch invoices.
404
+        $invoices  = $wpdb->get_col(
405
+            "SELECT posts.ID FROM $wpdb->posts as posts
406 406
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
407 407
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
408 408
 
409
-		foreach ( $invoices as $invoice ) {
409
+        foreach ( $invoices as $invoice ) {
410 410
 
411
-			// Only send this email for invoices created via the admin page.
412
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
413
-				$invoice       = new WPInv_Invoice( $invoice );
414
-				$email->object = $invoice;
411
+            // Only send this email for invoices created via the admin page.
412
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
413
+                $invoice       = new WPInv_Invoice( $invoice );
414
+                $email->object = $invoice;
415 415
 
416
-				if ( $invoice->needs_payment() ) {
417
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
418
-				}
416
+                if ( $invoice->needs_payment() ) {
417
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
418
+                }
419 419
 
420
-			}
420
+            }
421 421
 
422
-		}
422
+        }
423 423
 
424
-	}
424
+    }
425 425
 
426
-	/**
427
-	 * Calculates the date query for an invoices query
428
-	 *
429
-	 * @param array $reminder_days
430
-	 * @return string
431
-	 */
432
-	public function get_date_query( $reminder_days ) {
426
+    /**
427
+     * Calculates the date query for an invoices query
428
+     *
429
+     * @param array $reminder_days
430
+     * @return string
431
+     */
432
+    public function get_date_query( $reminder_days ) {
433 433
 
434
-		$date_query = array(
435
-			'relation'  => 'OR'
436
-		);
434
+        $date_query = array(
435
+            'relation'  => 'OR'
436
+        );
437 437
 
438
-		foreach ( $reminder_days as $days ) {
439
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
438
+        foreach ( $reminder_days as $days ) {
439
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
440 440
 
441
-			$date_query[] = array(
442
-				'year'  => $date['year'],
443
-				'month' => $date['month'],
444
-				'day'   => $date['day'],
445
-			);
441
+            $date_query[] = array(
442
+                'year'  => $date['year'],
443
+                'month' => $date['month'],
444
+                'day'   => $date['day'],
445
+            );
446 446
 
447
-		}
447
+        }
448 448
 
449
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
449
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
450 450
 
451
-		return $date_query->get_sql();
451
+        return $date_query->get_sql();
452 452
 
453
-	}
453
+    }
454 454
 
455 455
 }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 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 class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,35 +119,35 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'               => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'    => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'       => wpinv_price(wpinv_format_amount($invoice->get_total())),
138
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'        => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'    => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'       => sanitize_text_field(strtolower($invoice->get_label())),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_label())),
145
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
150
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
151 151
 	}
152 152
 
153 153
 	/**
@@ -159,35 +159,35 @@  discard block
 block discarded – undo
159 159
 	 * @param string|array $recipients
160 160
 	 * @param array $extra_args Extra template args.
161 161
 	 */
162
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
162
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
163 163
 
164
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
164
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
165 165
 
166 166
 		$mailer     = new GetPaid_Notification_Email_Sender();
167 167
 		$merge_tags = $email->get_merge_tags();
168 168
 
169 169
 		$result = $mailer->send(
170
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
-			$email->get_content( $merge_tags, $extra_args ),
170
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
171
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
172
+			$email->get_content($merge_tags, $extra_args),
173 173
 			$email->get_attachments()
174 174
 		);
175 175
 
176 176
 		// Maybe send a copy to the admin.
177
-		if ( $email->include_admin_bcc() ) {
177
+		if ($email->include_admin_bcc()) {
178 178
 			$mailer->send(
179 179
 				wpinv_get_admin_email(),
180
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
-				$email->get_content( $merge_tags ),
180
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
181
+				$email->get_content($merge_tags),
182 182
 				$email->get_attachments()
183 183
 			);
184 184
 		}
185 185
 
186
-		if ( ! $result ) {
187
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
186
+		if (!$result) {
187
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
188 188
 		}
189 189
 
190
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
190
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
191 191
 
192 192
 		return $result;
193 193
 	}
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
 	 * @param array $recipients
199 199
 	 * @param GetPaid_Notification_Email $email
200 200
 	 */
201
-	public function filter_email_recipients( $recipients, $email ) {
201
+	public function filter_email_recipients($recipients, $email) {
202 202
 
203
-		if ( ! $email->is_admin_email() ) {
203
+		if (!$email->is_admin_email()) {
204 204
 			$cc = $email->object->get_email_cc();
205 205
 
206
-			if ( ! empty( $cc ) ) {
207
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
206
+			if (!empty($cc)) {
207
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
208
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
209 209
 			}
210 210
 
211 211
 		}
@@ -219,17 +219,17 @@  discard block
 block discarded – undo
219 219
 	 *
220 220
 	 * @param WPInv_Invoice $invoice
221 221
 	 */
222
-	public function new_invoice( $invoice ) {
222
+	public function new_invoice($invoice) {
223 223
 
224 224
 		// Only send this email for invoices created via the admin page.
225
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
225
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
226 226
 			return;
227 227
 		}
228 228
 
229
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
229
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
230 230
 		$recipient = wpinv_get_admin_email();
231 231
 
232
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
232
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
233 233
 
234 234
 	}
235 235
 
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
 	 *
239 239
 	 * @param WPInv_Invoice $invoice
240 240
 	 */
241
-	public function cancelled_invoice( $invoice ) {
241
+	public function cancelled_invoice($invoice) {
242 242
 
243
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
243
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
244 244
 		$recipient = wpinv_get_admin_email();
245 245
 
246
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
246
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
247 247
 
248 248
 	}
249 249
 
@@ -252,12 +252,12 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @param WPInv_Invoice $invoice
254 254
 	 */
255
-	public function failed_invoice( $invoice ) {
255
+	public function failed_invoice($invoice) {
256 256
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
257
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
258 258
 		$recipient = wpinv_get_admin_email();
259 259
 
260
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
260
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
261 261
 
262 262
 	}
263 263
 
@@ -266,12 +266,12 @@  discard block
 block discarded – undo
266 266
 	 *
267 267
 	 * @param WPInv_Invoice $invoice
268 268
 	 */
269
-	public function onhold_invoice( $invoice ) {
269
+	public function onhold_invoice($invoice) {
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
272 272
 		$recipient = $invoice->get_email();
273 273
 
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
275 275
 
276 276
 	}
277 277
 
@@ -280,12 +280,12 @@  discard block
 block discarded – undo
280 280
 	 *
281 281
 	 * @param WPInv_Invoice $invoice
282 282
 	 */
283
-	public function processing_invoice( $invoice ) {
283
+	public function processing_invoice($invoice) {
284 284
 
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
286 286
 		$recipient = $invoice->get_email();
287 287
 
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
289 289
 
290 290
 	}
291 291
 
@@ -294,17 +294,17 @@  discard block
 block discarded – undo
294 294
 	 *
295 295
 	 * @param WPInv_Invoice $invoice
296 296
 	 */
297
-	public function completed_invoice( $invoice ) {
297
+	public function completed_invoice($invoice) {
298 298
 
299 299
 		// (Maybe) abort if it is a renewal invoice.
300
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
300
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
301 301
 			return;
302 302
 		}
303 303
 
304
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
304
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
305 305
 		$recipient = $invoice->get_email();
306 306
 
307
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
307
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
308 308
 
309 309
 	}
310 310
 
@@ -313,12 +313,12 @@  discard block
 block discarded – undo
313 313
 	 *
314 314
 	 * @param WPInv_Invoice $invoice
315 315
 	 */
316
-	public function refunded_invoice( $invoice ) {
316
+	public function refunded_invoice($invoice) {
317 317
 
318
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
318
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
319 319
 		$recipient = $invoice->get_email();
320 320
 
321
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
321
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
322 322
 
323 323
 	}
324 324
 
@@ -327,17 +327,17 @@  discard block
 block discarded – undo
327 327
 	 *
328 328
 	 * @param WPInv_Invoice $invoice
329 329
 	 */
330
-	public function user_invoice( $invoice ) {
330
+	public function user_invoice($invoice) {
331 331
 
332 332
 		// Only send this email for invoices created via the admin page.
333
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
333
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
334 334
 			return;
335 335
 		}
336 336
 
337
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
337
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
338 338
 		$recipient = $invoice->get_email();
339 339
 
340
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
340
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
341 341
 
342 342
 	}
343 343
 
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 	 * @param int $invoice
348 348
 	 * @return bool
349 349
 	 */
350
-	public function is_payment_form_invoice( $invoice ) {
351
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
350
+	public function is_payment_form_invoice($invoice) {
351
+		return empty($_GET['getpaid-admin-action']) && 'payment_form' == get_post_meta($invoice, 'wpinv_created_via', true);
352 352
 	}
353 353
 
354 354
 	/**
@@ -357,12 +357,12 @@  discard block
 block discarded – undo
357 357
 	 * @param WPInv_Invoice $invoice
358 358
 	 * @param string $note
359 359
 	 */
360
-	public function user_note( $invoice, $note ) {
360
+	public function user_note($invoice, $note) {
361 361
 
362
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
362
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
363 363
 		$recipient = $invoice->get_email();
364 364
 
365
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
365
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
366 366
 
367 367
 	}
368 368
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 	 *
372 372
 	 * @param WPInv_Invoice $invoice
373 373
 	 */
374
-	public function force_send_overdue_notice( $invoice ) {
375
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
376
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
374
+	public function force_send_overdue_notice($invoice) {
375
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
376
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
377 377
 	}
378 378
 
379 379
 	/**
@@ -384,37 +384,37 @@  discard block
 block discarded – undo
384 384
 	public function overdue() {
385 385
 		global $wpdb;
386 386
 
387
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
387
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
388 388
 
389 389
 		// Fetch reminder days.
390
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
390
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
391 391
 
392 392
 		// Abort if non is set.
393
-		if ( empty( $reminder_days ) ) {
393
+		if (empty($reminder_days)) {
394 394
 			return;
395 395
 		}
396 396
 
397 397
 		// Retrieve date query.
398
-		$date_query = $this->get_date_query( $reminder_days );
398
+		$date_query = $this->get_date_query($reminder_days);
399 399
 
400 400
 		// Invoices table.
401 401
 		$table = $wpdb->prefix . 'getpaid_invoices';
402 402
 
403 403
 		// Fetch invoices.
404
-		$invoices  = $wpdb->get_col(
404
+		$invoices = $wpdb->get_col(
405 405
 			"SELECT posts.ID FROM $wpdb->posts as posts
406 406
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
407 407
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
408 408
 
409
-		foreach ( $invoices as $invoice ) {
409
+		foreach ($invoices as $invoice) {
410 410
 
411 411
 			// Only send this email for invoices created via the admin page.
412
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
413
-				$invoice       = new WPInv_Invoice( $invoice );
412
+			if (!$this->is_payment_form_invoice($invoice)) {
413
+				$invoice       = new WPInv_Invoice($invoice);
414 414
 				$email->object = $invoice;
415 415
 
416
-				if ( $invoice->needs_payment() ) {
417
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
416
+				if ($invoice->needs_payment()) {
417
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
418 418
 				}
419 419
 
420 420
 			}
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
 	 * @param array $reminder_days
430 430
 	 * @return string
431 431
 	 */
432
-	public function get_date_query( $reminder_days ) {
432
+	public function get_date_query($reminder_days) {
433 433
 
434 434
 		$date_query = array(
435 435
 			'relation'  => 'OR'
436 436
 		);
437 437
 
438
-		foreach ( $reminder_days as $days ) {
439
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
438
+		foreach ($reminder_days as $days) {
439
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
440 440
 
441 441
 			$date_query[] = array(
442 442
 				'year'  => $date['year'],
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 
447 447
 		}
448 448
 
449
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
449
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
450 450
 
451 451
 		return $date_query->get_sql();
452 452
 
Please login to merge, or discard this patch.
templates/invoice/invoice.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
         <?php
19 19
 
20 20
             // Fires when printing the header.
21
-            do_action( 'getpaid_invoice_header', $invoice );
21
+            do_action('getpaid_invoice_header', $invoice);
22 22
 
23 23
             // Print the opening wrapper.
24 24
             echo '<div class="container bg-white border mt-4 mb-4 p-4 position-relative flex-grow-1">';
@@ -27,16 +27,16 @@  discard block
 block discarded – undo
27 27
             wpinv_print_errors();
28 28
 
29 29
             // Fires when printing the invoice details.
30
-            do_action( 'getpaid_invoice_details', $invoice );
30
+            do_action('getpaid_invoice_details', $invoice);
31 31
 
32 32
             // Fires when printing the invoice line items.
33
-            do_action( 'getpaid_invoice_line_items', $invoice );
33
+            do_action('getpaid_invoice_line_items', $invoice);
34 34
 
35 35
             // Print the closing wrapper.
36 36
             echo '</div>';
37 37
 
38 38
             // Fires when printing the invoice footer.
39
-            do_action( 'getpaid_invoice_footer', $invoice );
39
+            do_action('getpaid_invoice_footer', $invoice);
40 40
 
41 41
         ?>
42 42
 
Please login to merge, or discard this patch.
widgets/getpaid.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -36,36 +36,36 @@  discard block
 block discarded – undo
36 36
                     'desc_tip'    => true,
37 37
                     'default'     => '',
38 38
                     'advanced'    => false
39
-				),
39
+                ),
40 40
 
41 41
                 'form'  => array(
42
-	                'title'       => __( 'Form', 'invoicing' ),
43
-	                'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
44
-	                'type'        => 'text',
45
-	                'desc_tip'    => true,
46
-	                'default'     => '',
47
-	                'placeholder' => __('1','invoicing'),
48
-	                'advanced'    => false
49
-				),
50
-
51
-				'item'  => array(
52
-	                'title'       => __( 'Items', 'invoicing' ),
53
-	                'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
54
-	                'type'        => 'text',
55
-	                'desc_tip'    => true,
56
-	                'default'     => '',
57
-	                'placeholder' => __('1','invoicing'),
58
-	                'advanced'    => false
59
-				),
42
+                    'title'       => __( 'Form', 'invoicing' ),
43
+                    'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
44
+                    'type'        => 'text',
45
+                    'desc_tip'    => true,
46
+                    'default'     => '',
47
+                    'placeholder' => __('1','invoicing'),
48
+                    'advanced'    => false
49
+                ),
50
+
51
+                'item'  => array(
52
+                    'title'       => __( 'Items', 'invoicing' ),
53
+                    'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
54
+                    'type'        => 'text',
55
+                    'desc_tip'    => true,
56
+                    'default'     => '',
57
+                    'placeholder' => __('1','invoicing'),
58
+                    'advanced'    => false
59
+                ),
60 60
 
61 61
                 'button'  => array(
62
-	                'title'       => __( 'Button', 'invoicing' ),
63
-	                'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
64
-	                'type'        => 'text',
65
-	                'desc_tip'    => true,
66
-	                'default'     => '',
67
-	                'advanced'    => false
68
-				)
62
+                    'title'       => __( 'Button', 'invoicing' ),
63
+                    'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
64
+                    'type'        => 'text',
65
+                    'desc_tip'    => true,
66
+                    'default'     => '',
67
+                    'advanced'    => false
68
+                )
69 69
 
70 70
             )
71 71
 
@@ -75,96 +75,96 @@  discard block
 block discarded – undo
75 75
         parent::__construct( $options );
76 76
     }
77 77
 
78
-	/**
79
-	 * The Super block output function.
80
-	 *
81
-	 * @param array $args
82
-	 * @param array $widget_args
83
-	 * @param string $content
84
-	 *
85
-	 * @return string
86
-	 */
78
+    /**
79
+     * The Super block output function.
80
+     *
81
+     * @param array $args
82
+     * @param array $widget_args
83
+     * @param string $content
84
+     *
85
+     * @return string
86
+     */
87 87
     public function output( $args = array(), $widget_args = array(), $content = '' ) {
88 88
 
89
-	    // Is the shortcode set up correctly?
90
-		if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
91
-			return aui()->alert(
92
-				array(
93
-					'type'    => 'warning',
94
-					'content' => __( 'No payment form or item selected', 'invoicing' ),
95
-				)
96
-			);
97
-		}
98
-
99
-		// Payment form or button?
100
-		if ( ! empty( $args['form'] ) ) {
101
-			return $this->handle_payment_form(  $args );
102
-		} else {
103
-			return $this->handle_buy_item(  $args );
104
-		}
105
-
106
-	}
107
-
108
-	/**
109
-	 * Displaying a payment form
110
-	 *
111
-	 * @return string
112
-	 */
89
+        // Is the shortcode set up correctly?
90
+        if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
91
+            return aui()->alert(
92
+                array(
93
+                    'type'    => 'warning',
94
+                    'content' => __( 'No payment form or item selected', 'invoicing' ),
95
+                )
96
+            );
97
+        }
98
+
99
+        // Payment form or button?
100
+        if ( ! empty( $args['form'] ) ) {
101
+            return $this->handle_payment_form(  $args );
102
+        } else {
103
+            return $this->handle_buy_item(  $args );
104
+        }
105
+
106
+    }
107
+
108
+    /**
109
+     * Displaying a payment form
110
+     *
111
+     * @return string
112
+     */
113 113
     protected function handle_payment_form( $args = array() ) {
114 114
 
115
-		if ( empty( $args['button'] ) ) {
116
-			ob_start();
117
-			getpaid_display_payment_form( $args['form'] );
118
-			return ob_get_clean();
119
-		}
115
+        if ( empty( $args['button'] ) ) {
116
+            ob_start();
117
+            getpaid_display_payment_form( $args['form'] );
118
+            return ob_get_clean();
119
+        }
120 120
 
121
-		return $this->payment_form_button( $args['form'], $args['button'] );
122
-	}
121
+        return $this->payment_form_button( $args['form'], $args['button'] );
122
+    }
123 123
 
124
-	/**
125
-	 * Displays a payment form button.
126
-	 *
127
-	 * @return string
128
-	 */
124
+    /**
125
+     * Displays a payment form button.
126
+     *
127
+     * @return string
128
+     */
129 129
     protected function payment_form_button( $form, $button ) {
130
-		return getpaid_get_payment_button( $button, $form );
131
-	}
132
-
133
-	/**
134
-	 * Selling an item
135
-	 *
136
-	 * @return string
137
-	 */
130
+        return getpaid_get_payment_button( $button, $form );
131
+    }
132
+
133
+    /**
134
+     * Selling an item
135
+     *
136
+     * @return string
137
+     */
138 138
     protected function handle_buy_item( $args = array() ) {
139 139
 
140
-		if ( empty( $args['button'] ) ) {
141
-			return $this->buy_item_form( $args['item'] );
142
-		}
140
+        if ( empty( $args['button'] ) ) {
141
+            return $this->buy_item_form( $args['item'] );
142
+        }
143 143
 
144
-		return $this->buy_item_button( $args['item'], $args['button'] );
144
+        return $this->buy_item_button( $args['item'], $args['button'] );
145 145
 
146
-	}
146
+    }
147 147
 
148
-	/**
149
-	 * Displays a buy item form.
150
-	 *
151
-	 * @return string
152
-	 */
148
+    /**
149
+     * Displays a buy item form.
150
+     *
151
+     * @return string
152
+     */
153 153
     protected function buy_item_form( $item ) {
154
-		$items = getpaid_convert_items_to_array( $item );
155
-		ob_start();
156
-		getpaid_display_item_payment_form( $items );
157
-		return ob_get_clean();
158
-	}
159
-
160
-	/**
161
-	 * Displays a buy item button.
162
-	 *
163
-	 * @return string
164
-	 */
154
+        $items = getpaid_convert_items_to_array( $item );
155
+        ob_start();
156
+        getpaid_display_item_payment_form( $items );
157
+        return ob_get_clean();
158
+    }
159
+
160
+    /**
161
+     * Displays a buy item button.
162
+     *
163
+     * @return string
164
+     */
165 165
     protected function buy_item_button( $item, $button ) {
166
-		$button = getpaid_get_payment_button( $button, null, $item );
167
-		return apply_filters( 'getpaid_buy_item_button_widget', $button, $item );
166
+        $button = getpaid_get_payment_button( $button, null, $item );
167
+        return apply_filters( 'getpaid_buy_item_button_widget', $button, $item );
168 168
     }
169 169
 
170 170
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit;
4 4
 }
5 5
 
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
             'block-keywords'=> "['invoicing','buy', 'buy item', 'form']",
23 23
             'class_name'     => __CLASS__,
24 24
             'base_id'       => 'getpaid',
25
-            'name'          => __('GetPaid','invoicing'),
25
+            'name'          => __('GetPaid', 'invoicing'),
26 26
             'widget_ops'    => array(
27 27
                 'classname'   => 'getpaid bsui',
28
-                'description' => esc_html__('Show payment forms or buttons.','invoicing'),
28
+                'description' => esc_html__('Show payment forms or buttons.', 'invoicing'),
29 29
             ),
30 30
             'arguments'     => array(
31 31
 
32 32
                 'title'  => array(
33
-                    'title'       => __( 'Widget title', 'invoicing' ),
34
-                    'desc'        => __( 'Enter widget title.', 'invoicing' ),
33
+                    'title'       => __('Widget title', 'invoicing'),
34
+                    'desc'        => __('Enter widget title.', 'invoicing'),
35 35
                     'type'        => 'text',
36 36
                     'desc_tip'    => true,
37 37
                     'default'     => '',
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
 				),
40 40
 
41 41
                 'form'  => array(
42
-	                'title'       => __( 'Form', 'invoicing' ),
43
-	                'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
42
+	                'title'       => __('Form', 'invoicing'),
43
+	                'desc'        => __('Enter a form id in case you want to display a specific payment form', 'invoicing'),
44 44
 	                'type'        => 'text',
45 45
 	                'desc_tip'    => true,
46 46
 	                'default'     => '',
47
-	                'placeholder' => __('1','invoicing'),
47
+	                'placeholder' => __('1', 'invoicing'),
48 48
 	                'advanced'    => false
49 49
 				),
50 50
 
51 51
 				'item'  => array(
52
-	                'title'       => __( 'Items', 'invoicing' ),
53
-	                'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
52
+	                'title'       => __('Items', 'invoicing'),
53
+	                'desc'        => __('Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing'),
54 54
 	                'type'        => 'text',
55 55
 	                'desc_tip'    => true,
56 56
 	                'default'     => '',
57
-	                'placeholder' => __('1','invoicing'),
57
+	                'placeholder' => __('1', 'invoicing'),
58 58
 	                'advanced'    => false
59 59
 				),
60 60
 
61 61
                 'button'  => array(
62
-	                'title'       => __( 'Button', 'invoicing' ),
63
-	                'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
62
+	                'title'       => __('Button', 'invoicing'),
63
+	                'desc'        => __('Enter button label in case you would like to display the forms in a popup.', 'invoicing'),
64 64
 	                'type'        => 'text',
65 65
 	                'desc_tip'    => true,
66 66
 	                'default'     => '',
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         );
73 73
 
74 74
 
75
-        parent::__construct( $options );
75
+        parent::__construct($options);
76 76
     }
77 77
 
78 78
 	/**
@@ -84,23 +84,23 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return string
86 86
 	 */
87
-    public function output( $args = array(), $widget_args = array(), $content = '' ) {
87
+    public function output($args = array(), $widget_args = array(), $content = '') {
88 88
 
89 89
 	    // Is the shortcode set up correctly?
90
-		if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
90
+		if (empty($args['form']) && empty($args['item'])) {
91 91
 			return aui()->alert(
92 92
 				array(
93 93
 					'type'    => 'warning',
94
-					'content' => __( 'No payment form or item selected', 'invoicing' ),
94
+					'content' => __('No payment form or item selected', 'invoicing'),
95 95
 				)
96 96
 			);
97 97
 		}
98 98
 
99 99
 		// Payment form or button?
100
-		if ( ! empty( $args['form'] ) ) {
101
-			return $this->handle_payment_form(  $args );
100
+		if (!empty($args['form'])) {
101
+			return $this->handle_payment_form($args);
102 102
 		} else {
103
-			return $this->handle_buy_item(  $args );
103
+			return $this->handle_buy_item($args);
104 104
 		}
105 105
 
106 106
 	}
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
 	 *
111 111
 	 * @return string
112 112
 	 */
113
-    protected function handle_payment_form( $args = array() ) {
113
+    protected function handle_payment_form($args = array()) {
114 114
 
115
-		if ( empty( $args['button'] ) ) {
115
+		if (empty($args['button'])) {
116 116
 			ob_start();
117
-			getpaid_display_payment_form( $args['form'] );
117
+			getpaid_display_payment_form($args['form']);
118 118
 			return ob_get_clean();
119 119
 		}
120 120
 
121
-		return $this->payment_form_button( $args['form'], $args['button'] );
121
+		return $this->payment_form_button($args['form'], $args['button']);
122 122
 	}
123 123
 
124 124
 	/**
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @return string
128 128
 	 */
129
-    protected function payment_form_button( $form, $button ) {
130
-		return getpaid_get_payment_button( $button, $form );
129
+    protected function payment_form_button($form, $button) {
130
+		return getpaid_get_payment_button($button, $form);
131 131
 	}
132 132
 
133 133
 	/**
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @return string
137 137
 	 */
138
-    protected function handle_buy_item( $args = array() ) {
138
+    protected function handle_buy_item($args = array()) {
139 139
 
140
-		if ( empty( $args['button'] ) ) {
141
-			return $this->buy_item_form( $args['item'] );
140
+		if (empty($args['button'])) {
141
+			return $this->buy_item_form($args['item']);
142 142
 		}
143 143
 
144
-		return $this->buy_item_button( $args['item'], $args['button'] );
144
+		return $this->buy_item_button($args['item'], $args['button']);
145 145
 
146 146
 	}
147 147
 
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * @return string
152 152
 	 */
153
-    protected function buy_item_form( $item ) {
154
-		$items = getpaid_convert_items_to_array( $item );
153
+    protected function buy_item_form($item) {
154
+		$items = getpaid_convert_items_to_array($item);
155 155
 		ob_start();
156
-		getpaid_display_item_payment_form( $items );
156
+		getpaid_display_item_payment_form($items);
157 157
 		return ob_get_clean();
158 158
 	}
159 159
 
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 	 *
163 163
 	 * @return string
164 164
 	 */
165
-    protected function buy_item_button( $item, $button ) {
166
-		$button = getpaid_get_payment_button( $button, null, $item );
167
-		return apply_filters( 'getpaid_buy_item_button_widget', $button, $item );
165
+    protected function buy_item_button($item, $button) {
166
+		$button = getpaid_get_payment_button($button, null, $item);
167
+		return apply_filters('getpaid_buy_item_button_widget', $button, $item);
168 168
     }
169 169
 
170 170
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 4;
35 35
 
36 36
     /**
37
-	 * Endpoint for requests from Authorize.net.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	protected $notify_url;
42
-
43
-	/**
44
-	 * Endpoint for requests to Authorize.net.
45
-	 *
46
-	 * @var string
47
-	 */
37
+     * Endpoint for requests from Authorize.net.
38
+     *
39
+     * @var string
40
+     */
41
+    protected $notify_url;
42
+
43
+    /**
44
+     * Endpoint for requests to Authorize.net.
45
+     *
46
+     * @var string
47
+     */
48 48
     protected $endpoint;
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
63 63
 
64 64
     /**
65
-	 * Class constructor.
66
-	 */
67
-	public function __construct() {
65
+     * Class constructor.
66
+     */
67
+    public function __construct() {
68 68
 
69 69
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70 70
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-	 * Displays the payment method select field.
80
-	 *
81
-	 * @param int $invoice_id 0 or invoice id.
82
-	 * @param GetPaid_Payment_Form $form Current payment form.
83
-	 */
79
+     * Displays the payment method select field.
80
+     *
81
+     * @param int $invoice_id 0 or invoice id.
82
+     * @param GetPaid_Payment_Form $form Current payment form.
83
+     */
84 84
     public function payment_fields( $invoice_id, $form ) {
85 85
 
86 86
         // Let the user select a payment method.
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * Creates a customer profile.
95
-	 *
96
-	 *
97
-	 * @param WPInv_Invoice $invoice Invoice.
94
+     * Creates a customer profile.
95
+     *
96
+     *
97
+     * @param WPInv_Invoice $invoice Invoice.
98 98
      * @param array $submission_data Posted checkout fields.
99 99
      * @param bool $save Whether or not to save the payment as a token.
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101
-	 * @return string|WP_Error Payment profile id.
102
-	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
101
+     * @return string|WP_Error Payment profile id.
102
+     */
103
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
104 104
 
105 105
         // Remove non-digits from the number
106 106
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Retrieves a customer profile.
171
-	 *
172
-	 *
173
-	 * @param string $profile_id profile id.
174
-	 * @return string|WP_Error Profile id.
170
+     * Retrieves a customer profile.
171
+     *
172
+     *
173
+     * @param string $profile_id profile id.
174
+     * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176
-	 */
177
-	public function get_customer_profile( $profile_id ) {
176
+     */
177
+    public function get_customer_profile( $profile_id ) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-	 * Creates a customer profile.
193
-	 *
194
-	 *
192
+     * Creates a customer profile.
193
+     *
194
+     *
195 195
      * @param string $profile_id profile id.
196
-	 * @param WPInv_Invoice $invoice Invoice.
196
+     * @param WPInv_Invoice $invoice Invoice.
197 197
      * @param array $submission_data Posted checkout fields.
198 198
      * @param bool $save Whether or not to save the payment as a token.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200
-	 * @return string|WP_Error Profile id.
201
-	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
200
+     * @return string|WP_Error Profile id.
201
+     */
202
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
203 203
 
204 204
         // Remove non-digits from the number
205 205
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -259,15 +259,15 @@  discard block
 block discarded – undo
259 259
     }
260 260
 
261 261
     /**
262
-	 * Retrieves a customer payment profile.
263
-	 *
264
-	 *
265
-	 * @param string $customer_profile_id customer profile id.
262
+     * Retrieves a customer payment profile.
263
+     *
264
+     *
265
+     * @param string $customer_profile_id customer profile id.
266 266
      * @param string $payment_profile_id payment profile id.
267
-	 * @return string|WP_Error Profile id.
267
+     * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269
-	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
269
+     */
270
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -283,15 +283,15 @@  discard block
 block discarded – undo
283 283
     }
284 284
 
285 285
     /**
286
-	 * Charges a customer payment profile.
287
-	 *
286
+     * Charges a customer payment profile.
287
+     *
288 288
      * @param string $customer_profile_id customer profile id.
289 289
      * @param string $payment_profile_id payment profile id.
290
-	 * @param WPInv_Invoice $invoice Invoice.
290
+     * @param WPInv_Invoice $invoice Invoice.
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292
-	 * @return WP_Error|object
293
-	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
292
+     * @return WP_Error|object
293
+     */
294
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -337,41 +337,41 @@  discard block
 block discarded – undo
337 337
     }
338 338
 
339 339
     /**
340
-	 * Processes a customer charge.
341
-	 *
340
+     * Processes a customer charge.
341
+     *
342 342
      * @param stdClass $result Api response.
343
-	 * @param WPInv_Invoice $invoice Invoice.
344
-	 */
345
-	public function process_charge_response( $result, $invoice ) {
343
+     * @param WPInv_Invoice $invoice Invoice.
344
+     */
345
+    public function process_charge_response( $result, $invoice ) {
346 346
 
347 347
         wpinv_clear_errors();
348
-		$response_code = (int) $result->transactionResponse->responseCode;
348
+        $response_code = (int) $result->transactionResponse->responseCode;
349 349
 
350
-		// Succeeded.
351
-		if ( 1 == $response_code || 4 == $response_code ) {
350
+        // Succeeded.
351
+        if ( 1 == $response_code || 4 == $response_code ) {
352 352
 
353
-			// Maybe set a transaction id.
354
-			if ( ! empty( $result->transactionResponse->transId ) ) {
355
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
356
-			}
353
+            // Maybe set a transaction id.
354
+            if ( ! empty( $result->transactionResponse->transId ) ) {
355
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
356
+            }
357 357
 
358
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
358
+            $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
359 359
 
360
-			if ( 1 == $response_code ) {
361
-				return $invoice->mark_paid();
362
-			}
360
+            if ( 1 == $response_code ) {
361
+                return $invoice->mark_paid();
362
+            }
363 363
 
364
-			$invoice->set_status( 'wpi-onhold' );
365
-        	$invoice->add_note(
364
+            $invoice->set_status( 'wpi-onhold' );
365
+            $invoice->add_note(
366 366
                 sprintf(
367 367
                     __( 'Held for review: %s', 'invoicing' ),
368 368
                     $result->transactionResponse->messages->message[0]->description
369 369
                 )
370
-			);
370
+            );
371 371
 
372
-			return $invoice->save();
372
+            return $invoice->save();
373 373
 
374
-		}
374
+        }
375 375
 
376 376
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
377 377
 
@@ -383,13 +383,13 @@  discard block
 block discarded – undo
383 383
     }
384 384
 
385 385
     /**
386
-	 * Returns payment information.
387
-	 *
388
-	 *
389
-	 * @param array $card Card details.
390
-	 * @return array
391
-	 */
392
-	public function get_payment_information( $card ) {
386
+     * Returns payment information.
387
+     *
388
+     *
389
+     * @param array $card Card details.
390
+     * @return array
391
+     */
392
+    public function get_payment_information( $card ) {
393 393
         return array(
394 394
 
395 395
             'creditCard'         => array (
@@ -402,25 +402,25 @@  discard block
 block discarded – undo
402 402
     }
403 403
 
404 404
     /**
405
-	 * Returns the customer profile meta name.
406
-	 *
407
-	 *
408
-	 * @param WPInv_Invoice $invoice Invoice.
409
-	 * @return string
410
-	 */
411
-	public function get_customer_profile_meta_name( $invoice ) {
405
+     * Returns the customer profile meta name.
406
+     *
407
+     *
408
+     * @param WPInv_Invoice $invoice Invoice.
409
+     * @return string
410
+     */
411
+    public function get_customer_profile_meta_name( $invoice ) {
412 412
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
413 413
     }
414 414
 
415 415
     /**
416
-	 * Validates the submitted data.
417
-	 *
418
-	 *
419
-	 * @param array $submission_data Posted checkout fields.
416
+     * Validates the submitted data.
417
+     *
418
+     *
419
+     * @param array $submission_data Posted checkout fields.
420 420
      * @param WPInv_Invoice $invoice
421
-	 * @return WP_Error|string The payment profile id
422
-	 */
423
-	public function validate_submission_data( $submission_data, $invoice ) {
421
+     * @return WP_Error|string The payment profile id
422
+     */
423
+    public function validate_submission_data( $submission_data, $invoice ) {
424 424
 
425 425
         // Validate authentication details.
426 426
         $auth = $this->get_auth_params();
@@ -452,13 +452,13 @@  discard block
 block discarded – undo
452 452
     }
453 453
 
454 454
     /**
455
-	 * Returns invoice line items.
456
-	 *
457
-	 *
458
-	 * @param WPInv_Invoice $invoice Invoice.
459
-	 * @return array
460
-	 */
461
-	public function get_line_items( $invoice ) {
455
+     * Returns invoice line items.
456
+     *
457
+     *
458
+     * @param WPInv_Invoice $invoice Invoice.
459
+     * @return array
460
+     */
461
+    public function get_line_items( $invoice ) {
462 462
         $items = array();
463 463
 
464 464
         foreach ( $invoice->get_items() as $item ) {
@@ -496,15 +496,15 @@  discard block
 block discarded – undo
496 496
     }
497 497
 
498 498
     /**
499
-	 * Process Payment.
500
-	 *
501
-	 *
502
-	 * @param WPInv_Invoice $invoice Invoice.
503
-	 * @param array $submission_data Posted checkout fields.
504
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505
-	 * @return array
506
-	 */
507
-	public function process_payment( $invoice, $submission_data, $submission ) {
499
+     * Process Payment.
500
+     *
501
+     *
502
+     * @param WPInv_Invoice $invoice Invoice.
503
+     * @param array $submission_data Posted checkout fields.
504
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505
+     * @return array
506
+     */
507
+    public function process_payment( $invoice, $submission_data, $submission ) {
508 508
 
509 509
         // Validate the submitted data.
510 510
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -537,69 +537,69 @@  discard block
 block discarded – undo
537 537
 
538 538
         exit;
539 539
 
540
-	}
540
+    }
541 541
 	
542
-	/**
543
-	 * Processes the initial payment.
544
-	 *
542
+    /**
543
+     * Processes the initial payment.
544
+     *
545 545
      * @param WPInv_Invoice $invoice Invoice.
546
-	 */
547
-	protected function process_initial_payment( $invoice ) {
546
+     */
547
+    protected function process_initial_payment( $invoice ) {
548 548
 
549
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
549
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
550 550
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
551
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
551
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
552 552
 
553
-		// Do we have an error?
554
-		if ( is_wp_error( $result ) ) {
555
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
556
-			wpinv_send_back_to_checkout( $invoice );
557
-		}
553
+        // Do we have an error?
554
+        if ( is_wp_error( $result ) ) {
555
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
556
+            wpinv_send_back_to_checkout( $invoice );
557
+        }
558 558
 
559
-		// Process the response.
560
-		$this->process_charge_response( $result, $invoice );
559
+        // Process the response.
560
+        $this->process_charge_response( $result, $invoice );
561 561
 
562
-		if ( wpinv_get_errors() ) {
563
-			wpinv_send_back_to_checkout( $invoice );
564
-		}
562
+        if ( wpinv_get_errors() ) {
563
+            wpinv_send_back_to_checkout( $invoice );
564
+        }
565 565
 
566
-	}
566
+    }
567 567
 
568 568
     /**
569
-	 * Processes recurring payments.
570
-	 *
569
+     * Processes recurring payments.
570
+     *
571 571
      * @param WPInv_Invoice $invoice Invoice.
572 572
      * @param WPInv_Subscription $subscription Subscription.
573
-	 */
574
-	public function process_subscription( $invoice, $subscription ) {
573
+     */
574
+    public function process_subscription( $invoice, $subscription ) {
575 575
 
576 576
         // Check if there is an initial amount to charge.
577 577
         if ( (float) $invoice->get_total() > 0 ) {
578
-			$this->process_initial_payment( $invoice );
578
+            $this->process_initial_payment( $invoice );
579 579
         }
580 580
 
581 581
         // Activate the subscription.
582 582
         $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
583 583
         $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
584 584
 
585
-		$subscription->set_next_renewal_date( $expiry );
586
-		$subscription->set_date_created( current_time( 'mysql' ) );
587
-		$subscription->set_profile_id( $invoice->generate_key() );
588
-		$subscription->activate();
585
+        $subscription->set_next_renewal_date( $expiry );
586
+        $subscription->set_date_created( current_time( 'mysql' ) );
587
+        $subscription->set_profile_id( $invoice->generate_key() );
588
+        $subscription->activate();
589 589
 
590
-		// Redirect to the success page.
590
+        // Redirect to the success page.
591 591
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
592 592
 
593 593
     }
594 594
 
595
-	/**
596
-	 * (Maybe) renews an authorize.net subscription profile.
597
-	 *
598
-	 *
599
-	 * @param bool $should_expire
595
+    /**
596
+     * (Maybe) renews an authorize.net subscription profile.
597
+     *
598
+     *
599
+     * @param bool $should_expire
600 600
      * @param WPInv_Subscription $subscription
601
-	 */
602
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
601
+     */
602
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
603 603
 
604 604
         // Ensure its our subscription && it's active.
605 605
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -616,18 +616,18 @@  discard block
 block discarded – undo
616 616
 
617 617
         return false;
618 618
 
619
-	}
619
+    }
620 620
 
621 621
     /**
622
-	 * Renews a subscription.
623
-	 *
622
+     * Renews a subscription.
623
+     *
624 624
      * @param WPInv_Subscription $subscription
625
-	 */
626
-	public function renew_subscription( $subscription ) {
625
+     */
626
+    public function renew_subscription( $subscription ) {
627 627
 
628
-		// Generate the renewal invoice.
629
-		$new_invoice = $subscription->create_payment();
630
-		$old_invoice = $subscription->get_parent_payment();
628
+        // Generate the renewal invoice.
629
+        $new_invoice = $subscription->create_payment();
630
+        $old_invoice = $subscription->get_parent_payment();
631 631
 
632 632
         if ( empty( $new_invoice ) ) {
633 633
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -636,37 +636,37 @@  discard block
 block discarded – undo
636 636
         }
637 637
 
638 638
         // Charge the payment method.
639
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
642
-
643
-		// Do we have an error?
644
-		if ( is_wp_error( $result ) ) {
645
-
646
-			$old_invoice->add_note(
647
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
648
-				true,
649
-				false,
650
-				true
651
-			);
652
-			$subscription->failing();
653
-			return;
654
-
655
-		}
656
-
657
-		// Process the response.
658
-		$this->process_charge_response( $result, $new_invoice );
659
-
660
-		if ( wpinv_get_errors() ) {
661
-
662
-			$old_invoice->add_note(
663
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
664
-				true,
665
-				false,
666
-				true
667
-			);
668
-			$subscription->failing();
669
-			return;
639
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
642
+
643
+        // Do we have an error?
644
+        if ( is_wp_error( $result ) ) {
645
+
646
+            $old_invoice->add_note(
647
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
648
+                true,
649
+                false,
650
+                true
651
+            );
652
+            $subscription->failing();
653
+            return;
654
+
655
+        }
656
+
657
+        // Process the response.
658
+        $this->process_charge_response( $result, $new_invoice );
659
+
660
+        if ( wpinv_get_errors() ) {
661
+
662
+            $old_invoice->add_note(
663
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
664
+                true,
665
+                false,
666
+                true
667
+            );
668
+            $subscription->failing();
669
+            return;
670 670
 
671 671
         }
672 672
 
@@ -675,13 +675,13 @@  discard block
 block discarded – undo
675 675
     }
676 676
 
677 677
     /**
678
-	 * Processes invoice addons.
679
-	 *
680
-	 * @param WPInv_Invoice $invoice
681
-	 * @param GetPaid_Form_Item[] $items
682
-	 * @return WPInv_Invoice
683
-	 */
684
-	public function process_addons( $invoice, $items ) {
678
+     * Processes invoice addons.
679
+     *
680
+     * @param WPInv_Invoice $invoice
681
+     * @param GetPaid_Form_Item[] $items
682
+     * @return WPInv_Invoice
683
+     */
684
+    public function process_addons( $invoice, $items ) {
685 685
 
686 686
         global $getpaid_authorize_addons;
687 687
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
         $invoice->recalculate_total();
702 702
 
703 703
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
704
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
704
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
705 705
 
706 706
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
707 707
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -716,11 +716,11 @@  discard block
 block discarded – undo
716 716
     }
717 717
 
718 718
     /**
719
-	 * Processes invoice addons.
720
-	 *
719
+     * Processes invoice addons.
720
+     *
721 721
      * @param array $args
722
-	 * @return array
723
-	 */
722
+     * @return array
723
+     */
724 724
     public function filter_addons_request( $args ) {
725 725
 
726 726
         global $getpaid_authorize_addons;
@@ -754,11 +754,11 @@  discard block
 block discarded – undo
754 754
     }
755 755
 
756 756
     /**
757
-	 * Filters the gateway settings.
758
-	 *
759
-	 * @param array $admin_settings
760
-	 */
761
-	public function admin_settings( $admin_settings ) {
757
+     * Filters the gateway settings.
758
+     *
759
+     * @param array $admin_settings
760
+     */
761
+    public function admin_settings( $admin_settings ) {
762 762
 
763 763
         $currencies = sprintf(
764 764
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
             'readonly' => true,
799 799
         );
800 800
 
801
-		return $admin_settings;
802
-	}
801
+        return $admin_settings;
802
+    }
803 803
 
804 804
 }
Please login to merge, or discard this patch.
Spacing   +172 added lines, -172 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' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens', 'addons');
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           = wpinv_get_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
72 72
 
73
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
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
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,64 +100,64 @@  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_last_name(), 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_last_name(), 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
             return $response;
142 142
         }
143 143
 
144
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
144
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
145 145
 
146 146
         // Save the payment token.
147
-        if ( $save ) {
147
+        if ($save) {
148 148
             $this->save_token(
149 149
                 array(
150 150
                     'id'      => $response->customerPaymentProfileIdList[0],
151
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
152 152
                     'default' => true,
153
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
153
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
154 154
                 )
155 155
             );
156 156
         }
157 157
 
158 158
         // Add a note about the validation response.
159 159
         $invoice->add_note(
160
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
160
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
161 161
             false,
162 162
             false,
163 163
             true
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176 176
 	 */
177
-	public function get_customer_profile( $profile_id ) {
177
+	public function get_customer_profile($profile_id) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             )
185 185
         );
186 186
 
187
-        return $this->post( $args, false );
187
+        return $this->post($args, false);
188 188
 
189 189
     }
190 190
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200 200
 	 * @return string|WP_Error Profile id.
201 201
 	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
202
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
203 203
 
204 204
         // Remove non-digits from the number
205
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
205
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
206 206
 
207 207
         // Generate args.
208 208
         $args = array(
@@ -213,34 +213,34 @@  discard block
 block discarded – undo
213 213
 
214 214
                     // Billing information.
215 215
                     'billTo'           => array(
216
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
217
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
218
-                        'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
219
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
220
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
221
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
222
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
216
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
217
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
218
+                        'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
219
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
220
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
221
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
222
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
223 223
                     ),
224 224
 
225 225
                     // Payment information.
226
-                    'payment'          => $this->get_payment_information( $submission_data['authorizenet'] )
226
+                    'payment'          => $this->get_payment_information($submission_data['authorizenet'])
227 227
                 ),
228
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
228
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
229 229
             )
230 230
         );
231 231
 
232
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
232
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
233 233
 
234
-        if ( is_wp_error( $response ) ) {
234
+        if (is_wp_error($response)) {
235 235
             return $response;
236 236
         }
237 237
 
238 238
         // Save the payment token.
239
-        if ( $save ) {
239
+        if ($save) {
240 240
             $this->save_token(
241 241
                 array(
242 242
                     'id'      => $response->customerPaymentProfileId,
243
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
244 244
                     'default' => true
245 245
                 )
246 246
             );
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
         // Add a note about the validation response.
250 250
         $invoice->add_note(
251
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
251
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
252 252
             false,
253 253
             false,
254 254
             true
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269 269
 	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
270
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
 
281
-        return $this->post( $args, false );
281
+        return $this->post($args, false);
282 282
 
283 283
     }
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292 292
 	 * @return WP_Error|object
293 293
 	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
294
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -311,28 +311,28 @@  discard block
 block discarded – undo
311 311
                         )
312 312
                     ),
313 313
                     'order'                    => array(
314
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
314
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
315 315
                     ),
316
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
316
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
317 317
                     'tax'                      => array(
318 318
                         'amount'               => $invoice->get_total_tax(),
319
-                        'name'                 => __( 'TAX', 'invoicing' ),
319
+                        'name'                 => __('TAX', 'invoicing'),
320 320
                     ),
321
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
321
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
322 322
                     'customer'                 => array(
323
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
324
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
323
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
324
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
325 325
                     ),
326 326
                     'customerIP'               => $invoice->get_ip(),
327 327
                 )
328 328
             )
329 329
         );
330 330
 
331
-        if ( 0 == $invoice->get_total_tax() ) {
332
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
331
+        if (0 == $invoice->get_total_tax()) {
332
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
333 333
         }
334 334
 
335
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
335
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
336 336
 
337 337
     }
338 338
 
@@ -342,29 +342,29 @@  discard block
 block discarded – undo
342 342
      * @param stdClass $result Api response.
343 343
 	 * @param WPInv_Invoice $invoice Invoice.
344 344
 	 */
345
-	public function process_charge_response( $result, $invoice ) {
345
+	public function process_charge_response($result, $invoice) {
346 346
 
347 347
         wpinv_clear_errors();
348 348
 		$response_code = (int) $result->transactionResponse->responseCode;
349 349
 
350 350
 		// Succeeded.
351
-		if ( 1 == $response_code || 4 == $response_code ) {
351
+		if (1 == $response_code || 4 == $response_code) {
352 352
 
353 353
 			// Maybe set a transaction id.
354
-			if ( ! empty( $result->transactionResponse->transId ) ) {
355
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
354
+			if (!empty($result->transactionResponse->transId)) {
355
+				$invoice->set_transaction_id($result->transactionResponse->transId);
356 356
 			}
357 357
 
358
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
358
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
359 359
 
360
-			if ( 1 == $response_code ) {
360
+			if (1 == $response_code) {
361 361
 				return $invoice->mark_paid();
362 362
 			}
363 363
 
364
-			$invoice->set_status( 'wpi-onhold' );
364
+			$invoice->set_status('wpi-onhold');
365 365
         	$invoice->add_note(
366 366
                 sprintf(
367
-                    __( 'Held for review: %s', 'invoicing' ),
367
+                    __('Held for review: %s', 'invoicing'),
368 368
                     $result->transactionResponse->messages->message[0]->description
369 369
                 )
370 370
 			);
@@ -373,11 +373,11 @@  discard block
 block discarded – undo
373 373
 
374 374
 		}
375 375
 
376
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
376
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
377 377
 
378
-        if ( ! empty( $result->transactionResponse->errors ) ) {
378
+        if (!empty($result->transactionResponse->errors)) {
379 379
             $errors = (object) $result->transactionResponse->errors;
380
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
380
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
381 381
         }
382 382
 
383 383
     }
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
 	 * @param array $card Card details.
390 390
 	 * @return array
391 391
 	 */
392
-	public function get_payment_information( $card ) {
392
+	public function get_payment_information($card) {
393 393
         return array(
394 394
 
395
-            'creditCard'         => array (
395
+            'creditCard'         => array(
396 396
                 'cardNumber'     => $card['cc_number'],
397 397
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
398 398
                 'cardCode'       => $card['cc_cvv2'],
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param WPInv_Invoice $invoice Invoice.
409 409
 	 * @return string
410 410
 	 */
411
-	public function get_customer_profile_meta_name( $invoice ) {
412
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
411
+	public function get_customer_profile_meta_name($invoice) {
412
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
413 413
     }
414 414
 
415 415
     /**
@@ -420,34 +420,34 @@  discard block
 block discarded – undo
420 420
      * @param WPInv_Invoice $invoice
421 421
 	 * @return WP_Error|string The payment profile id
422 422
 	 */
423
-	public function validate_submission_data( $submission_data, $invoice ) {
423
+	public function validate_submission_data($submission_data, $invoice) {
424 424
 
425 425
         // Validate authentication details.
426 426
         $auth = $this->get_auth_params();
427 427
 
428
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
429
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
428
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
429
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
430 430
         }
431 431
 
432 432
         // Validate the payment method.
433
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
434
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
433
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
434
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
435 435
         }
436 436
 
437 437
         // Are we adding a new payment method?
438
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
438
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
439 439
             return $submission_data['getpaid-authorizenet-payment-method'];
440 440
         }
441 441
 
442 442
         // Retrieve the customer profile id.
443
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
443
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
444 444
 
445 445
         // Create payment method.
446
-        if ( empty( $profile_id ) ) {
447
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
446
+        if (empty($profile_id)) {
447
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
448 448
         }
449 449
 
450
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
450
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
451 451
 
452 452
     }
453 453
 
@@ -458,16 +458,16 @@  discard block
 block discarded – undo
458 458
 	 * @param WPInv_Invoice $invoice Invoice.
459 459
 	 * @return array
460 460
 	 */
461
-	public function get_line_items( $invoice ) {
461
+	public function get_line_items($invoice) {
462 462
         $items = array();
463 463
 
464
-        foreach ( $invoice->get_items() as $item ) {
464
+        foreach ($invoice->get_items() as $item) {
465 465
 
466 466
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
467 467
             $items[] = array(
468
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
469
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
470
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
468
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
469
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
470
+                'description' => getpaid_limit_length($item->get_description(), 255),
471 471
                 'quantity'    => (string) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
472 472
                 'unitPrice'   => (float) $amount,
473 473
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -475,15 +475,15 @@  discard block
 block discarded – undo
475 475
 
476 476
         }
477 477
 
478
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
478
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
479 479
 
480
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
480
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
481 481
 
482
-            if ( $amount > 0 ) {
482
+            if ($amount > 0) {
483 483
                 $items[] = array(
484
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
485
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
486
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
484
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
485
+                    'name'        => getpaid_limit_length($fee_name, 31),
486
+                    'description' => getpaid_limit_length($fee_name, 255),
487 487
                     'quantity'    => '1',
488 488
                     'unitPrice'   => (float) $amount,
489 489
                     'taxable'     => false,
@@ -504,36 +504,36 @@  discard block
 block discarded – undo
504 504
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505 505
 	 * @return array
506 506
 	 */
507
-	public function process_payment( $invoice, $submission_data, $submission ) {
507
+	public function process_payment($invoice, $submission_data, $submission) {
508 508
 
509 509
         // Validate the submitted data.
510
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
510
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
511 511
 
512 512
         // Do we have an error?
513
-        if ( is_wp_error( $payment_profile_id ) ) {
514
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
515
-            wpinv_send_back_to_checkout( $invoice );
513
+        if (is_wp_error($payment_profile_id)) {
514
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
515
+            wpinv_send_back_to_checkout($invoice);
516 516
         }
517 517
 
518 518
         // Save the payment method to the order.
519
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
519
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
520 520
 
521 521
         // Check if this is a subscription or not.
522
-        $subscription = getpaid_get_invoice_subscription( $invoice );
523
-        if ( ! empty( $subscription ) ) {
524
-            $this->process_subscription( $invoice, $subscription );
522
+        $subscription = getpaid_get_invoice_subscription($invoice);
523
+        if (!empty($subscription)) {
524
+            $this->process_subscription($invoice, $subscription);
525 525
         }
526 526
 
527 527
         // If it is free, send to the success page.
528
-        if ( ! $invoice->needs_payment() ) {
528
+        if (!$invoice->needs_payment()) {
529 529
             $invoice->mark_paid();
530
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
530
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
531 531
         }
532 532
 
533 533
         // Charge the payment profile.
534
-        $this->process_initial_payment( $invoice );
534
+        $this->process_initial_payment($invoice);
535 535
 
536
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
536
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
537 537
 
538 538
         exit;
539 539
 
@@ -544,23 +544,23 @@  discard block
 block discarded – undo
544 544
 	 *
545 545
      * @param WPInv_Invoice $invoice Invoice.
546 546
 	 */
547
-	protected function process_initial_payment( $invoice ) {
547
+	protected function process_initial_payment($invoice) {
548 548
 
549
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
550
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
551
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
549
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
550
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
551
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
552 552
 
553 553
 		// Do we have an error?
554
-		if ( is_wp_error( $result ) ) {
555
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
556
-			wpinv_send_back_to_checkout( $invoice );
554
+		if (is_wp_error($result)) {
555
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
556
+			wpinv_send_back_to_checkout($invoice);
557 557
 		}
558 558
 
559 559
 		// Process the response.
560
-		$this->process_charge_response( $result, $invoice );
560
+		$this->process_charge_response($result, $invoice);
561 561
 
562
-		if ( wpinv_get_errors() ) {
563
-			wpinv_send_back_to_checkout( $invoice );
562
+		if (wpinv_get_errors()) {
563
+			wpinv_send_back_to_checkout($invoice);
564 564
 		}
565 565
 
566 566
 	}
@@ -571,24 +571,24 @@  discard block
 block discarded – undo
571 571
      * @param WPInv_Invoice $invoice Invoice.
572 572
      * @param WPInv_Subscription $subscription Subscription.
573 573
 	 */
574
-	public function process_subscription( $invoice, $subscription ) {
574
+	public function process_subscription($invoice, $subscription) {
575 575
 
576 576
         // Check if there is an initial amount to charge.
577
-        if ( (float) $invoice->get_total() > 0 ) {
578
-			$this->process_initial_payment( $invoice );
577
+        if ((float) $invoice->get_total() > 0) {
578
+			$this->process_initial_payment($invoice);
579 579
         }
580 580
 
581 581
         // Activate the subscription.
582
-        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
583
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
582
+        $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
583
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
584 584
 
585
-		$subscription->set_next_renewal_date( $expiry );
586
-		$subscription->set_date_created( current_time( 'mysql' ) );
587
-		$subscription->set_profile_id( $invoice->generate_key() );
585
+		$subscription->set_next_renewal_date($expiry);
586
+		$subscription->set_date_created(current_time('mysql'));
587
+		$subscription->set_profile_id($invoice->generate_key());
588 588
 		$subscription->activate();
589 589
 
590 590
 		// Redirect to the success page.
591
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
591
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
592 592
 
593 593
     }
594 594
 
@@ -599,20 +599,20 @@  discard block
 block discarded – undo
599 599
 	 * @param bool $should_expire
600 600
      * @param WPInv_Subscription $subscription
601 601
 	 */
602
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
602
+	public function maybe_renew_subscription($should_expire, $subscription) {
603 603
 
604 604
         // Ensure its our subscription && it's active.
605
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
605
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
606 606
             return $should_expire;
607 607
         }
608 608
 
609 609
         // If this is the last renewal, complete the subscription.
610
-        if ( $subscription->is_last_renewal() ) {
610
+        if ($subscription->is_last_renewal()) {
611 611
             $subscription->complete();
612 612
             return false;
613 613
         }
614 614
 
615
-        $this->renew_subscription( $subscription );
615
+        $this->renew_subscription($subscription);
616 616
 
617 617
         return false;
618 618
 
@@ -623,28 +623,28 @@  discard block
 block discarded – undo
623 623
 	 *
624 624
      * @param WPInv_Subscription $subscription
625 625
 	 */
626
-	public function renew_subscription( $subscription ) {
626
+	public function renew_subscription($subscription) {
627 627
 
628 628
 		// Generate the renewal invoice.
629 629
 		$new_invoice = $subscription->create_payment();
630 630
 		$old_invoice = $subscription->get_parent_payment();
631 631
 
632
-        if ( empty( $new_invoice ) ) {
633
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
632
+        if (empty($new_invoice)) {
633
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
634 634
             $subscription->failing();
635 635
             return;
636 636
         }
637 637
 
638 638
         // Charge the payment method.
639
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
639
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
640
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
641
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
642 642
 
643 643
 		// Do we have an error?
644
-		if ( is_wp_error( $result ) ) {
644
+		if (is_wp_error($result)) {
645 645
 
646 646
 			$old_invoice->add_note(
647
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
647
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
648 648
 				true,
649 649
 				false,
650 650
 				true
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 		}
656 656
 
657 657
 		// Process the response.
658
-		$this->process_charge_response( $result, $new_invoice );
658
+		$this->process_charge_response($result, $new_invoice);
659 659
 
660
-		if ( wpinv_get_errors() ) {
660
+		if (wpinv_get_errors()) {
661 661
 
662 662
 			$old_invoice->add_note(
663
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
663
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
664 664
 				true,
665 665
 				false,
666 666
 				true
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 
671 671
         }
672 672
 
673
-        $subscription->add_payment( array(), $new_invoice );
673
+        $subscription->add_payment(array(), $new_invoice);
674 674
         $subscription->renew();
675 675
     }
676 676
 
@@ -681,34 +681,34 @@  discard block
 block discarded – undo
681 681
 	 * @param GetPaid_Form_Item[] $items
682 682
 	 * @return WPInv_Invoice
683 683
 	 */
684
-	public function process_addons( $invoice, $items ) {
684
+	public function process_addons($invoice, $items) {
685 685
 
686 686
         global $getpaid_authorize_addons;
687 687
 
688 688
         $getpaid_authorize_addons = array();
689
-        foreach ( $items as $item ) {
689
+        foreach ($items as $item) {
690 690
 
691
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
691
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
692 692
                 $getpaid_authorize_addons[] = $item;
693 693
             }
694 694
 
695 695
         }
696 696
 
697
-        if ( empty( $getpaid_authorize_addons ) ) {
697
+        if (empty($getpaid_authorize_addons)) {
698 698
             return;
699 699
         }
700 700
 
701 701
         $invoice->recalculate_total();
702 702
 
703
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
704
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
703
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
704
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
705 705
 
706
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
707
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
708
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
706
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
707
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
708
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
709 709
 
710
-        if ( is_wp_error( $result ) ) {
711
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
710
+        if (is_wp_error($result)) {
711
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
712 712
             return;
713 713
         }
714 714
 
@@ -721,19 +721,19 @@  discard block
 block discarded – undo
721 721
      * @param array $args
722 722
 	 * @return array
723 723
 	 */
724
-    public function filter_addons_request( $args ) {
724
+    public function filter_addons_request($args) {
725 725
 
726 726
         global $getpaid_authorize_addons;
727 727
         $total = 0;
728 728
 
729
-        foreach ( $getpaid_authorize_addons as $addon ) {
729
+        foreach ($getpaid_authorize_addons as $addon) {
730 730
             $total += $addon->get_sub_total();
731 731
         }
732 732
 
733 733
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
734 734
 
735
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
736
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
735
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
736
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
737 737
         }
738 738
 
739 739
         return $args;
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
     public function sandbox_notice() {
747 747
 
748 748
         return sprintf(
749
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
749
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
750 750
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
751 751
             '</a>'
752 752
         );
@@ -758,42 +758,42 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @param array $admin_settings
760 760
 	 */
761
-	public function admin_settings( $admin_settings ) {
761
+	public function admin_settings($admin_settings) {
762 762
 
763 763
         $currencies = sprintf(
764
-            __( 'Supported Currencies: %s', 'invoicing' ),
765
-            implode( ', ', $this->currencies )
764
+            __('Supported Currencies: %s', 'invoicing'),
765
+            implode(', ', $this->currencies)
766 766
         );
767 767
 
768 768
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
769
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
769
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
770 770
 
771 771
         $admin_settings['authorizenet_login_id'] = array(
772 772
             'type' => 'text',
773 773
             'id'   => 'authorizenet_login_id',
774
-            'name' => __( 'API Login ID', 'invoicing' ),
775
-            '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>',
774
+            'name' => __('API Login ID', 'invoicing'),
775
+            '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>',
776 776
         );
777 777
 
778 778
         $admin_settings['authorizenet_transaction_key'] = array(
779 779
             'type' => 'text',
780 780
             'id'   => 'authorizenet_transaction_key',
781
-            'name' => __( 'Transaction Key', 'invoicing' ),
781
+            'name' => __('Transaction Key', 'invoicing'),
782 782
         );
783 783
 
784 784
         $admin_settings['authorizenet_signature_key'] = array(
785 785
             'type' => 'text',
786 786
             'id'   => 'authorizenet_signature_key',
787
-            'name' => __( 'Signature Key', 'invoicing' ),
788
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
787
+            'name' => __('Signature Key', 'invoicing'),
788
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
789 789
         );
790 790
 
791 791
         $admin_settings['authorizenet_ipn_url'] = array(
792 792
             'type'     => 'ipn_url',
793 793
             'id'       => 'authorizenet_ipn_url',
794
-            'name'     => __( 'Webhook URL', 'invoicing' ),
794
+            'name'     => __('Webhook URL', 'invoicing'),
795 795
             'std'      => $this->notify_url,
796
-            '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>',
796
+            '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>',
797 797
             'custom'   => 'authorizenet',
798 798
             'readonly' => true,
799 799
         );
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@
 block discarded – undo
235 235
         do_action( 'getpaid_checkout_invoice_exception', $invoice );
236 236
     }
237 237
 
238
-	// Do we have any errors?
238
+    // Do we have any errors?
239 239
     if ( wpinv_get_errors() ) {
240 240
         wp_send_json_error( getpaid_get_errors_html( true, false ) );
241 241
     }
Please login to merge, or discard this patch.
Spacing   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_is_subscription_payment( $invoice = '' ) {
3
-    if ( empty( $invoice ) ) {
2
+function wpinv_is_subscription_payment($invoice = '') {
3
+    if (empty($invoice)) {
4 4
         return false;
5 5
     }
6 6
     
7
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-        $invoice = wpinv_get_invoice( $invoice );
7
+    if (!is_object($invoice) && is_scalar($invoice)) {
8
+        $invoice = wpinv_get_invoice($invoice);
9 9
     }
10 10
     
11
-    if ( empty( $invoice ) ) {
11
+    if (empty($invoice)) {
12 12
         return false;
13 13
     }
14 14
         
15
-    if ( $invoice->is_renewal() ) {
15
+    if ($invoice->is_renewal()) {
16 16
         return true;
17 17
     }
18 18
 
19 19
     return false;
20 20
 }
21 21
 
22
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-    if ( empty( $invoice ) ) {
22
+function wpinv_payment_link_transaction_id($invoice = '') {
23
+    if (empty($invoice)) {
24 24
         return false;
25 25
     }
26 26
     
27
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-        $invoice = wpinv_get_invoice( $invoice );
27
+    if (!is_object($invoice) && is_scalar($invoice)) {
28
+        $invoice = wpinv_get_invoice($invoice);
29 29
     }
30 30
     
31
-    if ( empty( $invoice ) ) {
31
+    if (empty($invoice)) {
32 32
         return false;
33 33
     }
34 34
 
35
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
36 36
 }
37 37
 
38
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
38
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
39
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
40 40
     
41
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
42
-        $amount = __( 'Free', 'invoicing' );
41
+    if ($trial_interval > 0 && !empty($trial_period)) {
42
+        $amount = __('Free', 'invoicing');
43 43
         $interval = $trial_interval;
44 44
         $period = $trial_period;
45 45
     }
46 46
     
47 47
     $description = '';
48
-    switch ( $period ) {
48
+    switch ($period) {
49 49
         case 'D' :
50 50
         case 'day' :
51
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
51
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
52 52
             break;
53 53
         case 'W' :
54 54
         case 'week' :
55
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
56 56
             break;
57 57
         case 'M' :
58 58
         case 'month' :
59
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
59
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
60 60
             break;
61 61
         case 'Y' :
62 62
         case 'year' :
63
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
63
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
64 64
             break;
65 65
     }
66 66
 
67
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
67
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
68 68
 }
69 69
 
70
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-    $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
70
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
71
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
72
+    $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0;
73 73
     
74 74
     $description = '';
75
-    switch ( $period ) {
75
+    switch ($period) {
76 76
         case 'D' :
77 77
         case 'day' :            
78
-            if ( (int)$bill_times > 0 ) {
79
-                if ( $interval > 1 ) {
80
-                    if ( $bill_times > 1 ) {
81
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
78
+            if ((int) $bill_times > 0) {
79
+                if ($interval > 1) {
80
+                    if ($bill_times > 1) {
81
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
                     } else {
83
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
83
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
84 84
                     }
85 85
                 } else {
86
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
                 }
88 88
             } else {
89
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
89
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
90 90
             }
91 91
             break;
92 92
         case 'W' :
93 93
         case 'week' :            
94
-            if ( (int)$bill_times > 0 ) {
95
-                if ( $interval > 1 ) {
96
-                    if ( $bill_times > 1 ) {
97
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
94
+            if ((int) $bill_times > 0) {
95
+                if ($interval > 1) {
96
+                    if ($bill_times > 1) {
97
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
                     } else {
99
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
99
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
100 100
                     }
101 101
                 } else {
102
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
                 }
104 104
             } else {
105
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
106 106
             }
107 107
             break;
108 108
         case 'M' :
109 109
         case 'month' :            
110
-            if ( (int)$bill_times > 0 ) {
111
-                if ( $interval > 1 ) {
112
-                    if ( $bill_times > 1 ) {
113
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
110
+            if ((int) $bill_times > 0) {
111
+                if ($interval > 1) {
112
+                    if ($bill_times > 1) {
113
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
                     } else {
115
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
115
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
116 116
                     }
117 117
                 } else {
118
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
                 }
120 120
             } else {
121
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
121
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
122 122
             }
123 123
             break;
124 124
         case 'Y' :
125 125
         case 'year' :            
126
-            if ( (int)$bill_times > 0 ) {
127
-                if ( $interval > 1 ) {
128
-                    if ( $bill_times > 1 ) {
129
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
126
+            if ((int) $bill_times > 0) {
127
+                if ($interval > 1) {
128
+                    if ($bill_times > 1) {
129
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
                     } else {
131
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
131
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
132 132
                     }
133 133
                 } else {
134
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
                 }
136 136
             } else {
137
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
137
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
138 138
             }
139 139
             break;
140 140
     }
141 141
 
142
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
142
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
143 143
 }
144 144
 
145
-function wpinv_subscription_payment_desc( $invoice ) {
146
-    if ( empty( $invoice ) ) {
145
+function wpinv_subscription_payment_desc($invoice) {
146
+    if (empty($invoice)) {
147 147
         return NULL;
148 148
     }
149 149
 
150 150
     $description = '';
151
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-        if ( $item->has_free_trial() ) {
151
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
152
+        if ($item->has_free_trial()) {
153 153
             $trial_period = $item->get_trial_period();
154 154
             $trial_interval = $item->get_trial_interval();
155 155
         } else {
@@ -157,40 +157,40 @@  discard block
 block discarded – undo
157 157
             $trial_interval = 0;
158 158
         }
159 159
         
160
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
160
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
161 161
     }
162 162
     
163
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
163
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
164 164
 }
165 165
 
166
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-    $initial_total      = wpinv_round_amount( $initial );
168
-    $recurring_total    = wpinv_round_amount( $recurring );
166
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
167
+    $initial_total      = wpinv_round_amount($initial);
168
+    $recurring_total    = wpinv_round_amount($recurring);
169 169
     
170
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
170
+    if ($trial_interval > 0 && !empty($trial_period)) {
171 171
         // Free trial
172 172
     } else {
173
-        if ( $bill_times == 1 ) {
173
+        if ($bill_times == 1) {
174 174
             $recurring_total = $initial_total;
175
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
176 176
             $bill_times--;
177 177
         }
178 178
     }
179 179
     
180
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
181
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
180
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
181
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
182 182
     
183
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
184 184
         
185
-    if ( $initial_total != $recurring_total ) {
186
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+    if ($initial_total != $recurring_total) {
186
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
187 187
         
188
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
188
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
189 189
     } else {
190 190
         $description    = $recurring;
191 191
     }
192 192
     
193
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
194 194
 }
195 195
 
196 196
 /**
@@ -200,27 +200,27 @@  discard block
 block discarded – undo
200 200
  * @param string $card_number Card number.
201 201
  * @return string
202 202
  */
203
-function getpaid_get_card_name( $card_number ) {
203
+function getpaid_get_card_name($card_number) {
204 204
 
205 205
     // Known regexes.
206 206
     $regexes = array(
207
-        '/^4/'                     => __( 'Visa', 'invoicing' ),
208
-        '/^5[1-5]/'                => __( 'Mastercard', 'invoicing' ),
209
-        '/^3[47]/'                 => __( 'Amex', 'invoicing' ),
210
-        '/^3(?:0[0-5]|[68])/'      => __( 'Diners Club', 'invoicing' ),
211
-        '/^6(?:011|5)/'            => __( 'Discover', 'invoicing' ),
212
-        '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ),
207
+        '/^4/'                     => __('Visa', 'invoicing'),
208
+        '/^5[1-5]/'                => __('Mastercard', 'invoicing'),
209
+        '/^3[47]/'                 => __('Amex', 'invoicing'),
210
+        '/^3(?:0[0-5]|[68])/'      => __('Diners Club', 'invoicing'),
211
+        '/^6(?:011|5)/'            => __('Discover', 'invoicing'),
212
+        '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'),
213 213
     );
214 214
 
215 215
     // Confirm if one matches.
216
-    foreach ( $regexes as $regex => $card ) {
217
-        if ( preg_match ( $regex, $card_number ) >= 1 ) {
216
+    foreach ($regexes as $regex => $card) {
217
+        if (preg_match($regex, $card_number) >= 1) {
218 218
             return $card;
219 219
         }
220 220
     }
221 221
 
222 222
     // None matched.
223
-    return __( 'Card', 'invoicing' );
223
+    return __('Card', 'invoicing');
224 224
 
225 225
 }
226 226
 
@@ -229,16 +229,16 @@  discard block
 block discarded – undo
229 229
  * 
230 230
  * @param WPInv_Invoice|int|null $invoice
231 231
  */
232
-function wpinv_send_back_to_checkout( $invoice = null ) {
232
+function wpinv_send_back_to_checkout($invoice = null) {
233 233
 
234
-    if ( ! empty( $invoice ) ) {
235
-        do_action( 'getpaid_checkout_invoice_exception', $invoice );
234
+    if (!empty($invoice)) {
235
+        do_action('getpaid_checkout_invoice_exception', $invoice);
236 236
     }
237 237
 
238 238
 	// Do we have any errors?
239
-    if ( wpinv_get_errors() ) {
240
-        wp_send_json_error( getpaid_get_errors_html( true, false ) );
239
+    if (wpinv_get_errors()) {
240
+        wp_send_json_error(getpaid_get_errors_html(true, false));
241 241
     }
242 242
 
243
-    wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
243
+    wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing'));
244 244
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -12,176 +12,176 @@  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->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->recalculate_total();
50 50
         $invoice->save();
51 51
 
52
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
52
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
53 53
 
54
-		// Send to the gateway.
55
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
-	}
54
+        // Send to the gateway.
55
+        $this->post_process_submission( $invoice, $prepared, $shipping );
56
+    }
57 57
 
58
-	/**
59
-	 * Validates the submission.
60
-	 *
61
-	 */
62
-	protected function validate_submission() {
58
+    /**
59
+     * Validates the submission.
60
+     *
61
+     */
62
+    protected function validate_submission() {
63 63
 
64
-		$submission = $this->payment_form_submission;
65
-		$data       = $submission->get_data();
64
+        $submission = $this->payment_form_submission;
65
+        $data       = $submission->get_data();
66 66
 
67
-		// Do we have an error?
67
+        // Do we have an error?
68 68
         if ( ! empty( $submission->last_error ) ) {
69
-			wp_send_json_error( $submission->last_error );
69
+            wp_send_json_error( $submission->last_error );
70 70
         }
71 71
 
72
-		// We need a billing email.
72
+        // We need a billing email.
73 73
         if ( ! $submission->has_billing_email() ) {
74 74
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
75
-		}
75
+        }
76 76
 
77
-		// Non-recurring gateways should not be allowed to process recurring invoices.
78
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
79
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
80
-		}
77
+        // Non-recurring gateways should not be allowed to process recurring invoices.
78
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
79
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
80
+        }
81 81
 
82
-		// Ensure the gateway is active.
83
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
84
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
85
-		}
82
+        // Ensure the gateway is active.
83
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
84
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
85
+        }
86 86
 
87
-		// Clear any existing errors.
88
-		wpinv_clear_errors();
87
+        // Clear any existing errors.
88
+        wpinv_clear_errors();
89 89
 
90
-		// Allow themes and plugins to hook to errors
91
-		do_action( 'getpaid_checkout_error_checks', $submission );
90
+        // Allow themes and plugins to hook to errors
91
+        do_action( 'getpaid_checkout_error_checks', $submission );
92 92
 
93
-		// Do we have any errors?
93
+        // Do we have any errors?
94 94
         if ( wpinv_get_errors() ) {
95 95
             wp_send_json_error( getpaid_get_errors_html() );
96
-		}
96
+        }
97 97
 
98
-	}
98
+    }
99 99
 
100
-	/**
101
-	 * Retrieves submission items.
102
-	 *
103
-	 * @return GetPaid_Form_Item[]
104
-	 */
105
-	protected function get_submission_items() {
100
+    /**
101
+     * Retrieves submission items.
102
+     *
103
+     * @return GetPaid_Form_Item[]
104
+     */
105
+    protected function get_submission_items() {
106 106
 
107
-		$items = $this->payment_form_submission->get_items();
107
+        $items = $this->payment_form_submission->get_items();
108 108
 
109 109
         // Ensure that we have items.
110 110
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
111 111
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
112
-		}
113
-
114
-		return $items;
115
-	}
116
-
117
-	/**
118
-	 * Retrieves submission invoice.
119
-	 *
120
-	 * @return WPInv_Invoice
121
-	 */
122
-	protected function get_submission_invoice() {
123
-		$submission = $this->payment_form_submission;
124
-
125
-		if ( ! $submission->has_invoice() ) {
126
-			$invoice = new WPInv_Invoice();
127
-			$invoice->created_via( 'payment_form' );
128
-			return $invoice;
129 112
         }
130 113
 
131
-		$invoice = $submission->get_invoice();
114
+        return $items;
115
+    }
132 116
 
133
-		// Make sure that it is neither paid or refunded.
134
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
135
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
136
-		}
117
+    /**
118
+     * Retrieves submission invoice.
119
+     *
120
+     * @return WPInv_Invoice
121
+     */
122
+    protected function get_submission_invoice() {
123
+        $submission = $this->payment_form_submission;
137 124
 
138
-		return $invoice;
139
-	}
125
+        if ( ! $submission->has_invoice() ) {
126
+            $invoice = new WPInv_Invoice();
127
+            $invoice->created_via( 'payment_form' );
128
+            return $invoice;
129
+        }
140 130
 
141
-	/**
142
-	 * Processes the submission invoice.
143
-	 *
144
-	 * @param WPInv_Invoice $invoice
145
-	 * @param GetPaid_Form_Item[] $items
146
-	 * @return WPInv_Invoice
147
-	 */
148
-	protected function process_submission_invoice( $invoice, $items ) {
131
+        $invoice = $submission->get_invoice();
149 132
 
150
-		$submission = $this->payment_form_submission;
151
-		$data       = $submission->get_data();
133
+        // Make sure that it is neither paid or refunded.
134
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
135
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
136
+        }
152 137
 
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() ) );
138
+        return $invoice;
139
+    }
140
+
141
+    /**
142
+     * Processes the submission invoice.
143
+     *
144
+     * @param WPInv_Invoice $invoice
145
+     * @param GetPaid_Form_Item[] $items
146
+     * @return WPInv_Invoice
147
+     */
148
+    protected function process_submission_invoice( $invoice, $items ) {
149
+
150
+        $submission = $this->payment_form_submission;
151
+        $data       = $submission->get_data();
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $data['wpi-gateway'] );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $data['wpi-gateway'] );
162 162
 
163
-		if ( $submission->has_discount_code() ) {
163
+        if ( $submission->has_discount_code() ) {
164 164
             $invoice->set_discount_code( $submission->get_discount_code() );
165
-		}
166
-
167
-		getpaid_maybe_add_default_address( $invoice );
168
-		return $invoice;
169
-	}
170
-
171
-	/**
172
-	 * Retrieves the submission's customer.
173
-	 *
174
-	 * @return int The customer id.
175
-	 */
176
-	protected function get_submission_customer() {
177
-		$submission = $this->payment_form_submission;
178
-
179
-		// If this is an existing invoice...
180
-		if ( $submission->has_invoice() ) {
181
-			return $submission->get_invoice()->get_user_id();
182
-		}
183
-
184
-		// (Maybe) create the user.
165
+        }
166
+
167
+        getpaid_maybe_add_default_address( $invoice );
168
+        return $invoice;
169
+    }
170
+
171
+    /**
172
+     * Retrieves the submission's customer.
173
+     *
174
+     * @return int The customer id.
175
+     */
176
+    protected function get_submission_customer() {
177
+        $submission = $this->payment_form_submission;
178
+
179
+        // If this is an existing invoice...
180
+        if ( $submission->has_invoice() ) {
181
+            return $submission->get_invoice()->get_user_id();
182
+        }
183
+
184
+        // (Maybe) create the user.
185 185
         $user = get_current_user_id();
186 186
 
187 187
         if ( empty( $user ) ) {
@@ -198,31 +198,31 @@  discard block
 block discarded – undo
198 198
 
199 199
         if ( is_numeric( $user ) ) {
200 200
             return $user;
201
-		}
201
+        }
202 202
 
203
-		return $user->ID;
203
+        return $user->ID;
204 204
 
205
-	}
205
+    }
206 206
 
207
-	/**
207
+    /**
208 208
      * Prepares submission data for saving to the database.
209 209
      *
210
-	 * @return array
210
+     * @return array
211 211
      */
212 212
     public function prepare_submission_data_for_saving() {
213 213
 
214
-		$submission = $this->payment_form_submission;
214
+        $submission = $this->payment_form_submission;
215 215
 
216
-		// Prepared submission details.
216
+        // Prepared submission details.
217 217
         $prepared = array();
218 218
 
219 219
         // Raw submission details.
220
-		$data     = $submission->get_data();
220
+        $data     = $submission->get_data();
221 221
 
222
-		// Loop through the submitted details.
222
+        // Loop through the submitted details.
223 223
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
224 224
 
225
-			// Skip premade fields.
225
+            // Skip premade fields.
226 226
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
227 227
                 continue;
228 228
             }
@@ -240,93 +240,93 @@  discard block
 block discarded – undo
240 240
                     $label = $field['label'];
241 241
                 }
242 242
 
243
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
243
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
244 244
 
245 245
             }
246 246
 
247
-		}
247
+        }
248 248
 
249
-		return $prepared;
249
+        return $prepared;
250 250
 
251
-	}
251
+    }
252 252
 
253
-	/**
253
+    /**
254 254
      * Retrieves address details.
255 255
      *
256
-	 * @return array
257
-	 * @param WPInv_Invoice $invoice
258
-	 * @param string $type
256
+     * @return array
257
+     * @param WPInv_Invoice $invoice
258
+     * @param string $type
259 259
      */
260 260
     public function prepare_address_details( $invoice, $type = 'billing' ) {
261 261
 
262
-		$data     = $this->payment_form_submission->get_data();
263
-		$type     = sanitize_key( $type );
264
-		$address  = array();
265
-		$prepared = array();
262
+        $data     = $this->payment_form_submission->get_data();
263
+        $type     = sanitize_key( $type );
264
+        $address  = array();
265
+        $prepared = array();
266 266
 
267
-		if ( ! empty( $data[ $type ] ) ) {
268
-			$address = $data[ $type ];
269
-		}
267
+        if ( ! empty( $data[ $type ] ) ) {
268
+            $address = $data[ $type ];
269
+        }
270 270
 
271
-		// Clean address details.
272
-		foreach ( $address as $key => $value ) {
273
-			$key             = sanitize_key( $key );
274
-			$key             = str_replace( 'wpinv_', '', $key );
275
-			$value           = wpinv_clean( $value );
276
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
277
-		}
271
+        // Clean address details.
272
+        foreach ( $address as $key => $value ) {
273
+            $key             = sanitize_key( $key );
274
+            $key             = str_replace( 'wpinv_', '', $key );
275
+            $value           = wpinv_clean( $value );
276
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
277
+        }
278 278
 
279
-		// Filter address details.
280
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
279
+        // Filter address details.
280
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
281 281
 
282
-		// Remove non-whitelisted values.
283
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
282
+        // Remove non-whitelisted values.
283
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
284 284
 
285
-	}
285
+    }
286 286
 
287
-	/**
287
+    /**
288 288
      * Prepares the billing details.
289 289
      *
290
-	 * @return array
291
-	 * @param WPInv_Invoice $invoice
290
+     * @return array
291
+     * @param WPInv_Invoice $invoice
292 292
      */
293 293
     protected function prepare_billing_info( &$invoice ) {
294 294
 
295
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
295
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
296 296
 
297
-		// Update the invoice with the billing details.
298
-		$invoice->set_props( $billing_address );
297
+        // Update the invoice with the billing details.
298
+        $invoice->set_props( $billing_address );
299 299
 
300
-	}
300
+    }
301 301
 
302
-	/**
302
+    /**
303 303
      * Prepares the shipping details.
304 304
      *
305
-	 * @return array
306
-	 * @param WPInv_Invoice $invoice
305
+     * @return array
306
+     * @param WPInv_Invoice $invoice
307 307
      */
308 308
     protected function prepare_shipping_info( $invoice ) {
309 309
 
310
-		$data = $this->payment_form_submission->get_data();
310
+        $data = $this->payment_form_submission->get_data();
311 311
 
312
-		if ( empty( $data['same-shipping-address'] ) ) {
313
-			return $this->prepare_address_details( $invoice, 'shipping' );
314
-		}
312
+        if ( empty( $data['same-shipping-address'] ) ) {
313
+            return $this->prepare_address_details( $invoice, 'shipping' );
314
+        }
315 315
 
316
-		return $this->prepare_address_details( $invoice, 'billing' );
316
+        return $this->prepare_address_details( $invoice, 'billing' );
317 317
 
318
-	}
318
+    }
319 319
 
320
-	/**
321
-	 * Confirms the submission is valid and send users to the gateway.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 * @param array $prepared_payment_form_data
325
-	 * @param array $shipping
326
-	 */
327
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
320
+    /**
321
+     * Confirms the submission is valid and send users to the gateway.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     * @param array $prepared_payment_form_data
325
+     * @param array $shipping
326
+     */
327
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
328 328
 
329
-		// Ensure the invoice exists.
329
+        // Ensure the invoice exists.
330 330
         if ( ! $invoice->exists() ) {
331 331
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
332 332
         }
@@ -334,81 +334,81 @@  discard block
 block discarded – undo
334 334
         // Save payment form data.
335 335
         if ( ! empty( $prepared_payment_form_data ) ) {
336 336
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
337
-		}
337
+        }
338 338
 
339
-		// Save payment form data.
339
+        // Save payment form data.
340 340
         if ( ! empty( $shipping ) ) {
341 341
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
342
-		}
342
+        }
343 343
 
344
-		// Backwards compatibility.
344
+        // Backwards compatibility.
345 345
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
346 346
 
347
-		$this->process_payment( $invoice );
347
+        $this->process_payment( $invoice );
348 348
 
349 349
         // If we are here, there was an error.
350
-		wpinv_send_back_to_checkout( $invoice );
350
+        wpinv_send_back_to_checkout( $invoice );
351 351
 
352
-	}
352
+    }
353 353
 
354
-	/**
355
-	 * Processes the actual payment.
356
-	 *
357
-	 * @param WPInv_Invoice $invoice
358
-	 */
359
-	protected function process_payment( $invoice ) {
354
+    /**
355
+     * Processes the actual payment.
356
+     *
357
+     * @param WPInv_Invoice $invoice
358
+     */
359
+    protected function process_payment( $invoice ) {
360 360
 
361
-		// Clear any checkout errors.
362
-		wpinv_clear_errors();
361
+        // Clear any checkout errors.
362
+        wpinv_clear_errors();
363 363
 
364
-		// No need to send free invoices to the gateway.
365
-		if ( $invoice->is_free() ) {
366
-			$this->process_free_payment( $invoice );
367
-		}
364
+        // No need to send free invoices to the gateway.
365
+        if ( $invoice->is_free() ) {
366
+            $this->process_free_payment( $invoice );
367
+        }
368 368
 
369
-		$submission = $this->payment_form_submission;
369
+        $submission = $this->payment_form_submission;
370 370
 
371
-		// Fires before sending to the gateway.
372
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
371
+        // Fires before sending to the gateway.
372
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
373 373
 
374
-		// Allow the sumission data to be modified before it is sent to the gateway.
375
-		$submission_data    = $submission->get_data();
376
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
377
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
374
+        // Allow the sumission data to be modified before it is sent to the gateway.
375
+        $submission_data    = $submission->get_data();
376
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
377
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
378 378
 
379
-		// Validate the currency.
380
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
381
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
382
-		}
379
+        // Validate the currency.
380
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
381
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
382
+        }
383 383
 
384
-		// Check to see if we have any errors.
385
-		if ( wpinv_get_errors() ) {
386
-			wpinv_send_back_to_checkout( $invoice );
387
-		}
384
+        // Check to see if we have any errors.
385
+        if ( wpinv_get_errors() ) {
386
+            wpinv_send_back_to_checkout( $invoice );
387
+        }
388 388
 
389
-		// Send info to the gateway for payment processing
390
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
389
+        // Send info to the gateway for payment processing
390
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
391 391
 
392
-		// Backwards compatibility.
393
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
392
+        // Backwards compatibility.
393
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
394 394
 
395
-	}
395
+    }
396 396
 
397
-	/**
398
-	 * Marks the invoice as paid in case the checkout is free.
399
-	 *
400
-	 * @param WPInv_Invoice $invoice
401
-	 */
402
-	protected function process_free_payment( $invoice ) {
397
+    /**
398
+     * Marks the invoice as paid in case the checkout is free.
399
+     *
400
+     * @param WPInv_Invoice $invoice
401
+     */
402
+    protected function process_free_payment( $invoice ) {
403 403
 
404
-		$invoice->set_gateway( 'none' );
405
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
406
-		$invoice->mark_paid();
407
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
404
+        $invoice->set_gateway( 'none' );
405
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
406
+        $invoice->mark_paid();
407
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
408 408
 
409
-	}
409
+    }
410 410
 
411
-	/**
411
+    /**
412 412
      * Sends a redrect response to payment details.
413 413
      *
414 414
      */
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 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,21 +38,21 @@  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 49
 		$invoice->recalculate_total();
50 50
         $invoice->save();
51 51
 
52
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
52
+		do_action('getpaid_checkout_invoice_updated', $invoice);
53 53
 
54 54
 		// Send to the gateway.
55
-		$this->post_process_submission( $invoice, $prepared, $shipping );
55
+		$this->post_process_submission($invoice, $prepared, $shipping);
56 56
 	}
57 57
 
58 58
 	/**
@@ -65,34 +65,34 @@  discard block
 block discarded – undo
65 65
 		$data       = $submission->get_data();
66 66
 
67 67
 		// Do we have an error?
68
-        if ( ! empty( $submission->last_error ) ) {
69
-			wp_send_json_error( $submission->last_error );
68
+        if (!empty($submission->last_error)) {
69
+			wp_send_json_error($submission->last_error);
70 70
         }
71 71
 
72 72
 		// We need a billing email.
73
-        if ( ! $submission->has_billing_email() ) {
74
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
73
+        if (!$submission->has_billing_email()) {
74
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
75 75
 		}
76 76
 
77 77
 		// Non-recurring gateways should not be allowed to process recurring invoices.
78
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
79
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
78
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
79
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
80 80
 		}
81 81
 
82 82
 		// Ensure the gateway is active.
83
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
84
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
83
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
84
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
85 85
 		}
86 86
 
87 87
 		// Clear any existing errors.
88 88
 		wpinv_clear_errors();
89 89
 
90 90
 		// Allow themes and plugins to hook to errors
91
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+		do_action('getpaid_checkout_error_checks', $submission);
92 92
 
93 93
 		// Do we have any errors?
94
-        if ( wpinv_get_errors() ) {
95
-            wp_send_json_error( getpaid_get_errors_html() );
94
+        if (wpinv_get_errors()) {
95
+            wp_send_json_error(getpaid_get_errors_html());
96 96
 		}
97 97
 
98 98
 	}
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 		$items = $this->payment_form_submission->get_items();
108 108
 
109 109
         // Ensure that we have items.
110
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
111
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
110
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
111
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
112 112
 		}
113 113
 
114 114
 		return $items;
@@ -122,17 +122,17 @@  discard block
 block discarded – undo
122 122
 	protected function get_submission_invoice() {
123 123
 		$submission = $this->payment_form_submission;
124 124
 
125
-		if ( ! $submission->has_invoice() ) {
125
+		if (!$submission->has_invoice()) {
126 126
 			$invoice = new WPInv_Invoice();
127
-			$invoice->created_via( 'payment_form' );
127
+			$invoice->created_via('payment_form');
128 128
 			return $invoice;
129 129
         }
130 130
 
131 131
 		$invoice = $submission->get_invoice();
132 132
 
133 133
 		// Make sure that it is neither paid or refunded.
134
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
135
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
134
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
135
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
136 136
 		}
137 137
 
138 138
 		return $invoice;
@@ -145,26 +145,26 @@  discard block
 block discarded – undo
145 145
 	 * @param GetPaid_Form_Item[] $items
146 146
 	 * @return WPInv_Invoice
147 147
 	 */
148
-	protected function process_submission_invoice( $invoice, $items ) {
148
+	protected function process_submission_invoice($invoice, $items) {
149 149
 
150 150
 		$submission = $this->payment_form_submission;
151 151
 		$data       = $submission->get_data();
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( $data['wpi-gateway'] );
162
-
163
-		if ( $submission->has_discount_code() ) {
164
-            $invoice->set_discount_code( $submission->get_discount_code() );
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($data['wpi-gateway']);
162
+
163
+		if ($submission->has_discount_code()) {
164
+            $invoice->set_discount_code($submission->get_discount_code());
165 165
 		}
166 166
 
167
-		getpaid_maybe_add_default_address( $invoice );
167
+		getpaid_maybe_add_default_address($invoice);
168 168
 		return $invoice;
169 169
 	}
170 170
 
@@ -177,26 +177,26 @@  discard block
 block discarded – undo
177 177
 		$submission = $this->payment_form_submission;
178 178
 
179 179
 		// If this is an existing invoice...
180
-		if ( $submission->has_invoice() ) {
180
+		if ($submission->has_invoice()) {
181 181
 			return $submission->get_invoice()->get_user_id();
182 182
 		}
183 183
 
184 184
 		// (Maybe) create the user.
185 185
         $user = get_current_user_id();
186 186
 
187
-        if ( empty( $user ) ) {
188
-            $user = get_user_by( 'email', $submission->get_billing_email() );
187
+        if (empty($user)) {
188
+            $user = get_user_by('email', $submission->get_billing_email());
189 189
         }
190 190
 
191
-        if ( empty( $user ) ) {
192
-            $user = wpinv_create_user( $submission->get_billing_email() );
191
+        if (empty($user)) {
192
+            $user = wpinv_create_user($submission->get_billing_email());
193 193
         }
194 194
 
195
-        if ( is_wp_error( $user ) ) {
196
-            wp_send_json_error( $user->get_error_message() );
195
+        if (is_wp_error($user)) {
196
+            wp_send_json_error($user->get_error_message());
197 197
         }
198 198
 
199
-        if ( is_numeric( $user ) ) {
199
+        if (is_numeric($user)) {
200 200
             return $user;
201 201
 		}
202 202
 
@@ -217,30 +217,30 @@  discard block
 block discarded – undo
217 217
         $prepared = array();
218 218
 
219 219
         // Raw submission details.
220
-		$data     = $submission->get_data();
220
+		$data = $submission->get_data();
221 221
 
222 222
 		// Loop through the submitted details.
223
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
223
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
224 224
 
225 225
 			// Skip premade fields.
226
-            if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
226
+            if (!empty($field['premade']) || $field['type'] == 'address') {
227 227
                 continue;
228 228
             }
229 229
 
230 230
             // If it is required and not set, abort.
231
-            if ( ! $submission->is_required_field_set( $field ) ) {
232
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
231
+            if (!$submission->is_required_field_set($field)) {
232
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
233 233
             }
234 234
 
235 235
             // Handle misc fields.
236
-            if ( isset( $data[ $field['id'] ] ) ) {
236
+            if (isset($data[$field['id']])) {
237 237
                 $label = $field['id'];
238 238
 
239
-                if ( isset( $field['label'] ) ) {
239
+                if (isset($field['label'])) {
240 240
                     $label = $field['label'];
241 241
                 }
242 242
 
243
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
243
+				$prepared[wpinv_clean($label)] = wp_kses_post($data[$field['id']]);
244 244
 
245 245
             }
246 246
 
@@ -257,30 +257,30 @@  discard block
 block discarded – undo
257 257
 	 * @param WPInv_Invoice $invoice
258 258
 	 * @param string $type
259 259
      */
260
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
260
+    public function prepare_address_details($invoice, $type = 'billing') {
261 261
 
262 262
 		$data     = $this->payment_form_submission->get_data();
263
-		$type     = sanitize_key( $type );
263
+		$type     = sanitize_key($type);
264 264
 		$address  = array();
265 265
 		$prepared = array();
266 266
 
267
-		if ( ! empty( $data[ $type ] ) ) {
268
-			$address = $data[ $type ];
267
+		if (!empty($data[$type])) {
268
+			$address = $data[$type];
269 269
 		}
270 270
 
271 271
 		// Clean address details.
272
-		foreach ( $address as $key => $value ) {
273
-			$key             = sanitize_key( $key );
274
-			$key             = str_replace( 'wpinv_', '', $key );
275
-			$value           = wpinv_clean( $value );
276
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
272
+		foreach ($address as $key => $value) {
273
+			$key             = sanitize_key($key);
274
+			$key             = str_replace('wpinv_', '', $key);
275
+			$value           = wpinv_clean($value);
276
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
277 277
 		}
278 278
 
279 279
 		// Filter address details.
280
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
280
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
281 281
 
282 282
 		// Remove non-whitelisted values.
283
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
283
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
284 284
 
285 285
 	}
286 286
 
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 	 * @return array
291 291
 	 * @param WPInv_Invoice $invoice
292 292
      */
293
-    protected function prepare_billing_info( &$invoice ) {
293
+    protected function prepare_billing_info(&$invoice) {
294 294
 
295
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
295
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
296 296
 
297 297
 		// Update the invoice with the billing details.
298
-		$invoice->set_props( $billing_address );
298
+		$invoice->set_props($billing_address);
299 299
 
300 300
 	}
301 301
 
@@ -305,15 +305,15 @@  discard block
 block discarded – undo
305 305
 	 * @return array
306 306
 	 * @param WPInv_Invoice $invoice
307 307
      */
308
-    protected function prepare_shipping_info( $invoice ) {
308
+    protected function prepare_shipping_info($invoice) {
309 309
 
310 310
 		$data = $this->payment_form_submission->get_data();
311 311
 
312
-		if ( empty( $data['same-shipping-address'] ) ) {
313
-			return $this->prepare_address_details( $invoice, 'shipping' );
312
+		if (empty($data['same-shipping-address'])) {
313
+			return $this->prepare_address_details($invoice, 'shipping');
314 314
 		}
315 315
 
316
-		return $this->prepare_address_details( $invoice, 'billing' );
316
+		return $this->prepare_address_details($invoice, 'billing');
317 317
 
318 318
 	}
319 319
 
@@ -324,30 +324,30 @@  discard block
 block discarded – undo
324 324
 	 * @param array $prepared_payment_form_data
325 325
 	 * @param array $shipping
326 326
 	 */
327
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
327
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
328 328
 
329 329
 		// Ensure the invoice exists.
330
-        if ( ! $invoice->exists() ) {
331
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
330
+        if (!$invoice->exists()) {
331
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
332 332
         }
333 333
 
334 334
         // Save payment form data.
335
-        if ( ! empty( $prepared_payment_form_data ) ) {
336
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
335
+        if (!empty($prepared_payment_form_data)) {
336
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
337 337
 		}
338 338
 
339 339
 		// Save payment form data.
340
-        if ( ! empty( $shipping ) ) {
341
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
340
+        if (!empty($shipping)) {
341
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
342 342
 		}
343 343
 
344 344
 		// Backwards compatibility.
345
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
345
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
346 346
 
347
-		$this->process_payment( $invoice );
347
+		$this->process_payment($invoice);
348 348
 
349 349
         // If we are here, there was an error.
350
-		wpinv_send_back_to_checkout( $invoice );
350
+		wpinv_send_back_to_checkout($invoice);
351 351
 
352 352
 	}
353 353
 
@@ -356,41 +356,41 @@  discard block
 block discarded – undo
356 356
 	 *
357 357
 	 * @param WPInv_Invoice $invoice
358 358
 	 */
359
-	protected function process_payment( $invoice ) {
359
+	protected function process_payment($invoice) {
360 360
 
361 361
 		// Clear any checkout errors.
362 362
 		wpinv_clear_errors();
363 363
 
364 364
 		// No need to send free invoices to the gateway.
365
-		if ( $invoice->is_free() ) {
366
-			$this->process_free_payment( $invoice );
365
+		if ($invoice->is_free()) {
366
+			$this->process_free_payment($invoice);
367 367
 		}
368 368
 
369 369
 		$submission = $this->payment_form_submission;
370 370
 
371 371
 		// Fires before sending to the gateway.
372
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
372
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
373 373
 
374 374
 		// Allow the sumission data to be modified before it is sent to the gateway.
375 375
 		$submission_data    = $submission->get_data();
376
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
377
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
376
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
377
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
378 378
 
379 379
 		// Validate the currency.
380
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
381
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
380
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
381
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
382 382
 		}
383 383
 
384 384
 		// Check to see if we have any errors.
385
-		if ( wpinv_get_errors() ) {
386
-			wpinv_send_back_to_checkout( $invoice );
385
+		if (wpinv_get_errors()) {
386
+			wpinv_send_back_to_checkout($invoice);
387 387
 		}
388 388
 
389 389
 		// Send info to the gateway for payment processing
390
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
390
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
391 391
 
392 392
 		// Backwards compatibility.
393
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
393
+		wpinv_send_to_gateway($submission_gateway, $invoice);
394 394
 
395 395
 	}
396 396
 
@@ -399,12 +399,12 @@  discard block
 block discarded – undo
399 399
 	 *
400 400
 	 * @param WPInv_Invoice $invoice
401 401
 	 */
402
-	protected function process_free_payment( $invoice ) {
402
+	protected function process_free_payment($invoice) {
403 403
 
404
-		$invoice->set_gateway( 'none' );
405
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
404
+		$invoice->set_gateway('none');
405
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
406 406
 		$invoice->mark_paid();
407
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
407
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
408 408
 
409 409
 	}
410 410
 
@@ -412,9 +412,9 @@  discard block
 block discarded – undo
412 412
      * Sends a redrect response to payment details.
413 413
      *
414 414
      */
415
-    public function send_redirect_response( $url ) {
416
-        $url = urlencode( $url );
417
-        wp_send_json_success( $url );
415
+    public function send_redirect_response($url) {
416
+        $url = urlencode($url);
417
+        wp_send_json_success($url);
418 418
     }
419 419
 
420 420
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
     
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
     
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -255,24 +255,24 @@  discard block
 block discarded – undo
255 255
         check_ajax_referer( 'getpaid_form_nonce' );
256 256
 
257 257
         // Is the request set up correctly?
258
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
259
-			echo aui()->alert(
260
-				array(
261
-					'type'    => 'warning',
262
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
263
-				)
258
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
259
+            echo aui()->alert(
260
+                array(
261
+                    'type'    => 'warning',
262
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
263
+                )
264 264
             );
265 265
             exit;
266 266
         }
267 267
 
268 268
         // Payment form or button?
269
-		if ( ! empty( $_GET['form'] ) ) {
269
+        if ( ! empty( $_GET['form'] ) ) {
270 270
             getpaid_display_payment_form( urldecode( $_GET['form'] ) );
271
-		} else if( ! empty( $_GET['invoice'] ) ) {
272
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
271
+        } else if( ! empty( $_GET['invoice'] ) ) {
272
+            getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
273 273
         } else {
274
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
275
-		    getpaid_display_item_payment_form( $items );
274
+            $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
275
+            getpaid_display_item_payment_form( $items );
276 276
         }
277 277
 
278 278
         exit;
Please login to merge, or discard this patch.
Spacing   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -101,36 +101,36 @@  discard block
 block discarded – undo
101 101
             'payment_form_refresh_prices' => true,
102 102
         );
103 103
 
104
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
105
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
106
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
104
+        foreach ($ajax_events as $ajax_event => $nopriv) {
105
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
106
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
107 107
 
108
-            if ( $nopriv ) {
109
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
110
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
108
+            if ($nopriv) {
109
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
110
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
             }
113 113
         }
114 114
     }
115 115
     
116 116
     public static function add_note() {
117
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
117
+        check_ajax_referer('add-invoice-note', '_nonce');
118 118
 
119
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
119
+        if (!wpinv_current_user_can_manage_invoicing()) {
120 120
             die(-1);
121 121
         }
122 122
 
123
-        $post_id   = absint( $_POST['post_id'] );
124
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
125
-        $note_type = sanitize_text_field( $_POST['note_type'] );
123
+        $post_id   = absint($_POST['post_id']);
124
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
125
+        $note_type = sanitize_text_field($_POST['note_type']);
126 126
 
127 127
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
128 128
 
129
-        if ( $post_id > 0 ) {
130
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
129
+        if ($post_id > 0) {
130
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
131 131
 
132
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
133
-                wpinv_get_invoice_note_line_item( $note_id );
132
+            if ($note_id > 0 && !is_wp_error($note_id)) {
133
+                wpinv_get_invoice_note_line_item($note_id);
134 134
             }
135 135
         }
136 136
 
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
     }
139 139
 
140 140
     public static function delete_note() {
141
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
141
+        check_ajax_referer('delete-invoice-note', '_nonce');
142 142
 
143
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
143
+        if (!wpinv_current_user_can_manage_invoicing()) {
144 144
             die(-1);
145 145
         }
146 146
 
147
-        $note_id = (int)$_POST['note_id'];
147
+        $note_id = (int) $_POST['note_id'];
148 148
 
149
-        if ( $note_id > 0 ) {
150
-            wp_delete_comment( $note_id, true );
149
+        if ($note_id > 0) {
150
+            wp_delete_comment($note_id, true);
151 151
         }
152 152
 
153 153
         die();
@@ -165,34 +165,34 @@  discard block
 block discarded – undo
165 165
     public static function get_billing_details() {
166 166
 
167 167
         // Verify nonce.
168
-        check_ajax_referer( 'wpinv-nonce' );
168
+        check_ajax_referer('wpinv-nonce');
169 169
 
170 170
         // Can the user manage the plugin?
171
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
171
+        if (!wpinv_current_user_can_manage_invoicing()) {
172 172
             die(-1);
173 173
         }
174 174
 
175 175
         // Do we have a user id?
176 176
         $user_id = $_GET['user_id'];
177 177
 
178
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
178
+        if (empty($user_id) || !is_numeric($user_id)) {
179 179
             die(-1);
180 180
         }
181 181
 
182 182
         // Fetch the billing details.
183
-        $billing_details    = wpinv_get_user_address( $user_id );
184
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
183
+        $billing_details    = wpinv_get_user_address($user_id);
184
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
185 185
 
186 186
         // unset the user id and email.
187
-        $to_ignore = array( 'user_id', 'email' );
187
+        $to_ignore = array('user_id', 'email');
188 188
 
189
-        foreach ( $to_ignore as $key ) {
190
-            if ( isset( $billing_details[ $key ] ) ) {
191
-                unset( $billing_details[ $key ] );
189
+        foreach ($to_ignore as $key) {
190
+            if (isset($billing_details[$key])) {
191
+                unset($billing_details[$key]);
192 192
             }
193 193
         }
194 194
 
195
-        wp_send_json_success( $billing_details );
195
+        wp_send_json_success($billing_details);
196 196
 
197 197
     }
198 198
 
@@ -202,47 +202,47 @@  discard block
 block discarded – undo
202 202
     public static function check_new_user_email() {
203 203
 
204 204
         // Verify nonce.
205
-        check_ajax_referer( 'wpinv-nonce' );
205
+        check_ajax_referer('wpinv-nonce');
206 206
 
207 207
         // Can the user manage the plugin?
208
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
208
+        if (!wpinv_current_user_can_manage_invoicing()) {
209 209
             die(-1);
210 210
         }
211 211
 
212 212
         // We need an email address.
213
-        if ( empty( $_GET['email'] ) ) {
214
-            _e( "Provide the new user's email address", 'invoicing' );
213
+        if (empty($_GET['email'])) {
214
+            _e("Provide the new user's email address", 'invoicing');
215 215
             exit;
216 216
         }
217 217
 
218 218
         // Ensure the email is valid.
219
-        $email = sanitize_text_field( $_GET['email'] );
220
-        if ( ! is_email( $email ) ) {
221
-            _e( 'Invalid email address', 'invoicing' );
219
+        $email = sanitize_text_field($_GET['email']);
220
+        if (!is_email($email)) {
221
+            _e('Invalid email address', 'invoicing');
222 222
             exit;
223 223
         }
224 224
 
225 225
         // And it does not exist.
226
-        if ( email_exists( $email ) ) {
227
-            _e( 'A user with this email address already exists', 'invoicing' );
226
+        if (email_exists($email)) {
227
+            _e('A user with this email address already exists', 'invoicing');
228 228
             exit;
229 229
         }
230 230
 
231
-        wp_send_json_success( true );
231
+        wp_send_json_success(true);
232 232
     }
233 233
     
234 234
     public static function run_tool() {
235
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
236
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
235
+        check_ajax_referer('wpinv-nonce', '_nonce');
236
+        if (!wpinv_current_user_can_manage_invoicing()) {
237 237
             die(-1);
238 238
         }
239 239
         
240
-        $tool = sanitize_text_field( $_POST['tool'] );
240
+        $tool = sanitize_text_field($_POST['tool']);
241 241
         
242
-        do_action( 'wpinv_run_tool' );
242
+        do_action('wpinv_run_tool');
243 243
         
244
-        if ( !empty( $tool ) ) {
245
-            do_action( 'wpinv_tool_' . $tool );
244
+        if (!empty($tool)) {
245
+            do_action('wpinv_tool_' . $tool);
246 246
         }
247 247
     }
248 248
 
@@ -252,27 +252,27 @@  discard block
 block discarded – undo
252 252
     public static function get_payment_form() {
253 253
 
254 254
         // Check nonce.
255
-        check_ajax_referer( 'getpaid_form_nonce' );
255
+        check_ajax_referer('getpaid_form_nonce');
256 256
 
257 257
         // Is the request set up correctly?
258
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
258
+		if (empty($_GET['form']) && empty($_GET['item'])) {
259 259
 			echo aui()->alert(
260 260
 				array(
261 261
 					'type'    => 'warning',
262
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
262
+					'content' => __('No payment form or item provided', 'invoicing'),
263 263
 				)
264 264
             );
265 265
             exit;
266 266
         }
267 267
 
268 268
         // Payment form or button?
269
-		if ( ! empty( $_GET['form'] ) ) {
270
-            getpaid_display_payment_form( urldecode( $_GET['form'] ) );
271
-		} else if( ! empty( $_GET['invoice'] ) ) {
272
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
269
+		if (!empty($_GET['form'])) {
270
+            getpaid_display_payment_form(urldecode($_GET['form']));
271
+		} else if (!empty($_GET['invoice'])) {
272
+		    getpaid_display_invoice_payment_form(urldecode($_GET['invoice']));
273 273
         } else {
274
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
275
-		    getpaid_display_item_payment_form( $items );
274
+			$items = getpaid_convert_items_to_array(urldecode($_GET['item']));
275
+		    getpaid_display_item_payment_form($items);
276 276
         }
277 277
 
278 278
         exit;
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
     public static function payment_form() {
288 288
 
289 289
         // Check nonce.
290
-        check_ajax_referer( 'getpaid_form_nonce' );
290
+        check_ajax_referer('getpaid_form_nonce');
291 291
 
292 292
         // ... form fields...
293
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
294
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
293
+        if (empty($_POST['getpaid_payment_form_submission'])) {
294
+            _e('Error: Reload the page and try again.', 'invoicing');
295 295
             exit;
296 296
         }
297 297
 
298 298
         // Process the payment form.
299
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
300
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
299
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
300
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
301 301
         $checkout->process_checkout();
302 302
 
303 303
         exit;
@@ -310,55 +310,55 @@  discard block
 block discarded – undo
310 310
      */
311 311
     public static function get_payment_form_states_field() {
312 312
 
313
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
313
+        if (empty($_GET['country']) || empty($_GET['form'])) {
314 314
             exit;
315 315
         }
316 316
 
317
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
317
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
318 318
 
319
-        if ( empty( $elements ) ) {
319
+        if (empty($elements)) {
320 320
             exit;
321 321
         }
322 322
 
323 323
         $address_fields = array();
324
-        foreach ( $elements as $element ) {
325
-            if ( 'address' === $element['type'] ) {
324
+        foreach ($elements as $element) {
325
+            if ('address' === $element['type']) {
326 326
                 $address_fields = $element;
327 327
                 break;
328 328
             }
329 329
         }
330 330
 
331
-        if ( empty( $address_fields ) ) {
331
+        if (empty($address_fields)) {
332 332
             exit;
333 333
         }
334 334
 
335
-        foreach ( $address_fields['fields'] as $address_field ) {
335
+        foreach ($address_fields['fields'] as $address_field) {
336 336
 
337
-            if ( 'wpinv_state' == $address_field['name'] ) {
337
+            if ('wpinv_state' == $address_field['name']) {
338 338
 
339
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
340
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
341
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
342
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
343
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
344
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
339
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
340
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
341
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
342
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
343
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
344
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
345 345
 
346
-                if ( ! empty( $address_field['required'] ) ) {
346
+                if (!empty($address_field['required'])) {
347 347
                     $label .= "<span class='text-danger'> *</span>";
348 348
                 }
349 349
 
350
-                $html = getpaid_get_states_select_markup (
351
-                    sanitize_text_field( $_GET['country'] ),
350
+                $html = getpaid_get_states_select_markup(
351
+                    sanitize_text_field($_GET['country']),
352 352
                     $value,
353 353
                     $placeholder,
354 354
                     $label,
355 355
                     $description,
356
-                    ! empty( $address_field['required'] ),
356
+                    !empty($address_field['required']),
357 357
                     $wrap_class,
358
-                    wpinv_clean( $_GET['name'] )
358
+                    wpinv_clean($_GET['name'])
359 359
                 );
360 360
 
361
-                wp_send_json_success( $html );
361
+                wp_send_json_success($html);
362 362
                 exit;
363 363
 
364 364
             }
@@ -374,56 +374,56 @@  discard block
 block discarded – undo
374 374
     public static function recalculate_invoice_totals() {
375 375
 
376 376
         // Verify nonce.
377
-        check_ajax_referer( 'wpinv-nonce' );
377
+        check_ajax_referer('wpinv-nonce');
378 378
 
379
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
379
+        if (!wpinv_current_user_can_manage_invoicing()) {
380 380
             exit;
381 381
         }
382 382
 
383 383
         // We need an invoice.
384
-        if ( empty( $_POST['post_id'] ) ) {
384
+        if (empty($_POST['post_id'])) {
385 385
             exit;
386 386
         }
387 387
 
388 388
         // Fetch the invoice.
389
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
389
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
390 390
 
391 391
         // Ensure it exists.
392
-        if ( ! $invoice->get_id() ) {
392
+        if (!$invoice->get_id()) {
393 393
             exit;
394 394
         }
395 395
 
396 396
         // Maybe set the country, state, currency.
397
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
398
-            if ( isset( $_POST[ $key ] ) ) {
397
+        foreach (array('country', 'state', 'currency') as $key) {
398
+            if (isset($_POST[$key])) {
399 399
                 $method = "set_$key";
400
-                $invoice->$method( $_POST[ $key ] );
400
+                $invoice->$method($_POST[$key]);
401 401
             }
402 402
         }
403 403
 
404 404
         // Maybe disable taxes.
405
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
405
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
406 406
 
407 407
         // Recalculate totals.
408 408
         $invoice->recalculate_total();
409 409
 
410
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
410
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
411 411
 
412
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
413
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
414
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
412
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
413
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
414
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
415 415
         }
416 416
 
417 417
         $totals = array(
418
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
419
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
420
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
418
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
419
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
420
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
421 421
             'total'    => $total,
422 422
         );
423 423
 
424
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
424
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
425 425
 
426
-        wp_send_json_success( compact( 'totals' ) );
426
+        wp_send_json_success(compact('totals'));
427 427
     }
428 428
 
429 429
     /**
@@ -432,33 +432,33 @@  discard block
 block discarded – undo
432 432
     public static function get_invoice_items() {
433 433
 
434 434
         // Verify nonce.
435
-        check_ajax_referer( 'wpinv-nonce' );
435
+        check_ajax_referer('wpinv-nonce');
436 436
 
437
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
437
+        if (!wpinv_current_user_can_manage_invoicing()) {
438 438
             exit;
439 439
         }
440 440
 
441 441
         // We need an invoice and items.
442
-        if ( empty( $_POST['post_id'] ) ) {
442
+        if (empty($_POST['post_id'])) {
443 443
             exit;
444 444
         }
445 445
 
446 446
         // Fetch the invoice.
447
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
447
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
448 448
 
449 449
         // Ensure it exists.
450
-        if ( ! $invoice->get_id() ) {
450
+        if (!$invoice->get_id()) {
451 451
             exit;
452 452
         }
453 453
 
454 454
         // Return an array of invoice items.
455 455
         $items = array();
456 456
 
457
-        foreach ( $invoice->get_items() as $item_id => $item ) {
458
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
457
+        foreach ($invoice->get_items() as $item_id => $item) {
458
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
459 459
         }
460 460
 
461
-        wp_send_json_success( compact( 'items' ) );
461
+        wp_send_json_success(compact('items'));
462 462
     }
463 463
 
464 464
     /**
@@ -467,50 +467,50 @@  discard block
 block discarded – undo
467 467
     public static function edit_invoice_item() {
468 468
 
469 469
         // Verify nonce.
470
-        check_ajax_referer( 'wpinv-nonce' );
470
+        check_ajax_referer('wpinv-nonce');
471 471
 
472
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
472
+        if (!wpinv_current_user_can_manage_invoicing()) {
473 473
             exit;
474 474
         }
475 475
 
476 476
         // We need an invoice and item details.
477
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
477
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
478 478
             exit;
479 479
         }
480 480
 
481 481
         // Fetch the invoice.
482
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
482
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
483 483
 
484 484
         // Ensure it exists and its not been paid for.
485
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
485
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
486 486
             exit;
487 487
         }
488 488
 
489 489
         // Format the data.
490
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
490
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
491 491
 
492 492
         // Ensure that we have an item id.
493
-        if ( empty( $data['id'] ) ) {
493
+        if (empty($data['id'])) {
494 494
             exit;
495 495
         }
496 496
 
497 497
         // Abort if the invoice does not have the specified item.
498
-        $item = $invoice->get_item( (int) $data['id'] );
498
+        $item = $invoice->get_item((int) $data['id']);
499 499
 
500
-        if ( empty( $item ) ) {
500
+        if (empty($item)) {
501 501
             exit;
502 502
         }
503 503
 
504 504
         // Update the item.
505
-        $item->set_price( $data['price'] );
506
-        $item->set_name( $data['name'] );
507
-        $item->set_description( $data['description'] );
508
-        $item->set_quantity( $data['quantity'] );
505
+        $item->set_price($data['price']);
506
+        $item->set_name($data['name']);
507
+        $item->set_description($data['description']);
508
+        $item->set_quantity($data['quantity']);
509 509
 
510 510
         // Add it to the invoice.
511
-        $error = $invoice->add_item( $item );
511
+        $error = $invoice->add_item($item);
512 512
         $alert = false;
513
-        if ( is_wp_error( $error ) ) {
513
+        if (is_wp_error($error)) {
514 514
             $alert = $error->get_error_message();
515 515
         }
516 516
 
@@ -523,11 +523,11 @@  discard block
 block discarded – undo
523 523
         // Return an array of invoice items.
524 524
         $items = array();
525 525
 
526
-        foreach ( $invoice->get_items() as $item_id => $item ) {
527
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
526
+        foreach ($invoice->get_items() as $item_id => $item) {
527
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
528 528
         }
529 529
 
530
-        wp_send_json_success( compact( 'items', 'alert' ) );
530
+        wp_send_json_success(compact('items', 'alert'));
531 531
     }
532 532
 
533 533
     /**
@@ -536,33 +536,33 @@  discard block
 block discarded – undo
536 536
     public static function remove_invoice_item() {
537 537
 
538 538
         // Verify nonce.
539
-        check_ajax_referer( 'wpinv-nonce' );
539
+        check_ajax_referer('wpinv-nonce');
540 540
 
541
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
541
+        if (!wpinv_current_user_can_manage_invoicing()) {
542 542
             exit;
543 543
         }
544 544
 
545 545
         // We need an invoice and an item.
546
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
546
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
547 547
             exit;
548 548
         }
549 549
 
550 550
         // Fetch the invoice.
551
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
551
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
552 552
 
553 553
         // Ensure it exists and its not been paid for.
554
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
554
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
555 555
             exit;
556 556
         }
557 557
 
558 558
         // Abort if the invoice does not have the specified item.
559
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
559
+        $item = $invoice->get_item((int) $_POST['item_id']);
560 560
 
561
-        if ( empty( $item ) ) {
561
+        if (empty($item)) {
562 562
             exit;
563 563
         }
564 564
 
565
-        $invoice->remove_item( (int) $_POST['item_id'] );
565
+        $invoice->remove_item((int) $_POST['item_id']);
566 566
 
567 567
         // Update totals.
568 568
         $invoice->recalculate_total();
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
         // Return an array of invoice items.
574 574
         $items = array();
575 575
 
576
-        foreach ( $invoice->get_items() as $item_id => $item ) {
577
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
576
+        foreach ($invoice->get_items() as $item_id => $item) {
577
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
578 578
         }
579 579
 
580
-        wp_send_json_success( compact( 'items' ) );
580
+        wp_send_json_success(compact('items'));
581 581
     }
582 582
 
583 583
     /**
@@ -586,39 +586,39 @@  discard block
 block discarded – undo
586 586
     public static function add_invoice_items() {
587 587
 
588 588
         // Verify nonce.
589
-        check_ajax_referer( 'wpinv-nonce' );
589
+        check_ajax_referer('wpinv-nonce');
590 590
 
591
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
591
+        if (!wpinv_current_user_can_manage_invoicing()) {
592 592
             exit;
593 593
         }
594 594
 
595 595
         // We need an invoice and items.
596
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
596
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
597 597
             exit;
598 598
         }
599 599
 
600 600
         // Fetch the invoice.
601
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
601
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
602 602
         $alert   = false;
603 603
 
604 604
         // Ensure it exists and its not been paid for.
605
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
605
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
606 606
             exit;
607 607
         }
608 608
 
609 609
         // Add the items.
610
-        foreach ( $_POST['items'] as $data ) {
610
+        foreach ($_POST['items'] as $data) {
611 611
 
612
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
612
+            $item = new GetPaid_Form_Item($data['id']);
613 613
 
614
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
615
-                $item->set_quantity( $data[ 'qty' ] );
614
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
615
+                $item->set_quantity($data['qty']);
616 616
             }
617 617
 
618
-            if ( $item->get_id() > 0 ) {
619
-                $error = $invoice->add_item( $item );
618
+            if ($item->get_id() > 0) {
619
+                $error = $invoice->add_item($item);
620 620
 
621
-                if ( is_wp_error( $error ) ) {
621
+                if (is_wp_error($error)) {
622 622
                     $alert = $error->get_error_message();
623 623
                 }
624 624
 
@@ -633,11 +633,11 @@  discard block
 block discarded – undo
633 633
         // Return an array of invoice items.
634 634
         $items = array();
635 635
 
636
-        foreach ( $invoice->get_items() as $item_id => $item ) {
637
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
636
+        foreach ($invoice->get_items() as $item_id => $item) {
637
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
638 638
         }
639 639
 
640
-        wp_send_json_success( compact( 'items', 'alert' ) );
640
+        wp_send_json_success(compact('items', 'alert'));
641 641
     }
642 642
 
643 643
     /**
@@ -646,15 +646,15 @@  discard block
 block discarded – undo
646 646
     public static function get_invoicing_items() {
647 647
 
648 648
         // Verify nonce.
649
-        check_ajax_referer( 'wpinv-nonce' );
649
+        check_ajax_referer('wpinv-nonce');
650 650
 
651
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
651
+        if (!wpinv_current_user_can_manage_invoicing()) {
652 652
             exit;
653 653
         }
654 654
 
655 655
         // We need a search term.
656
-        if ( empty( $_GET['search'] ) ) {
657
-            wp_send_json_success( array() );
656
+        if (empty($_GET['search'])) {
657
+            wp_send_json_success(array());
658 658
         }
659 659
 
660 660
         // Retrieve items.
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
             'orderby'        => 'title',
664 664
             'order'          => 'ASC',
665 665
             'posts_per_page' => -1,
666
-            'post_status'    => array( 'publish' ),
667
-            's'              => trim( $_GET['search'] ),
666
+            'post_status'    => array('publish'),
667
+            's'              => trim($_GET['search']),
668 668
             'meta_query'     => array(
669 669
                 array(
670 670
                     'key'       => '_wpinv_type',
@@ -674,22 +674,22 @@  discard block
 block discarded – undo
674 674
             )
675 675
         );
676 676
 
677
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
677
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
678 678
         $data  = array();
679 679
 
680 680
 
681
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
681
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
682 682
 
683
-        foreach ( $items as $item ) {
684
-            $item      = new GetPaid_Form_Item( $item );
683
+        foreach ($items as $item) {
684
+            $item = new GetPaid_Form_Item($item);
685 685
             $data[] = array(
686 686
                 'id'        => (int) $item->get_id(),
687
-                'text'      => strip_tags( $item->get_name() ),
688
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
687
+                'text'      => strip_tags($item->get_name()),
688
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
689 689
             );
690 690
         }
691 691
 
692
-        wp_send_json_success( $data );
692
+        wp_send_json_success($data);
693 693
 
694 694
     }
695 695
 
@@ -699,26 +699,26 @@  discard block
 block discarded – undo
699 699
     public static function get_aui_states_field() {
700 700
 
701 701
         // Verify nonce.
702
-        check_ajax_referer( 'wpinv-nonce' );
702
+        check_ajax_referer('wpinv-nonce');
703 703
 
704 704
         // We need a country.
705
-        if ( empty( $_GET['country'] ) ) {
705
+        if (empty($_GET['country'])) {
706 706
             exit;
707 707
         }
708 708
 
709
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
710
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
709
+        $states = wpinv_get_country_states(trim($_GET['country']));
710
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
711 711
 
712
-        if ( empty( $states ) ) {
712
+        if (empty($states)) {
713 713
 
714 714
             $html = aui()->input(
715 715
                 array(
716 716
                     'type'        => 'text',
717 717
                     'id'          => 'wpinv_state',
718 718
                     'name'        => 'wpinv_state',
719
-                    'label'       => __( 'State', 'invoicing' ),
719
+                    'label'       => __('State', 'invoicing'),
720 720
                     'label_type'  => 'vertical',
721
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
721
+                    'placeholder' => __('Select a state', 'invoicing'),
722 722
                     'class'       => 'form-control-sm',
723 723
                     'value'       => $state,
724 724
                 )
@@ -730,9 +730,9 @@  discard block
 block discarded – undo
730 730
                 array(
731 731
                     'id'          => 'wpinv_state',
732 732
                     'name'        => 'wpinv_state',
733
-                    'label'       => __( 'State', 'invoicing' ),
733
+                    'label'       => __('State', 'invoicing'),
734 734
                     'label_type'  => 'vertical',
735
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
735
+                    'placeholder' => __('Select a state', 'invoicing'),
736 736
                     'class'       => 'form-control-sm',
737 737
                     'value'       => $state,
738 738
                     'options'     => $states,
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
         wp_send_json_success(
747 747
             array(
748 748
                 'html'   => $html,
749
-                'select' => ! empty ( $states )
749
+                'select' => !empty ($states)
750 750
             )
751 751
         );
752 752
 
@@ -760,11 +760,11 @@  discard block
 block discarded – undo
760 760
     public static function payment_form_refresh_prices() {
761 761
 
762 762
         // Check nonce.
763
-        check_ajax_referer( 'getpaid_form_nonce' );
763
+        check_ajax_referer('getpaid_form_nonce');
764 764
 
765 765
         // ... form fields...
766
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
767
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
766
+        if (empty($_POST['getpaid_payment_form_submission'])) {
767
+            _e('Error: Reload the page and try again.', 'invoicing');
768 768
             exit;
769 769
         }
770 770
 
@@ -772,18 +772,18 @@  discard block
 block discarded – undo
772 772
         $submission = new GetPaid_Payment_Form_Submission();
773 773
 
774 774
         // Do we have an error?
775
-        if ( ! empty( $submission->last_error ) ) {
775
+        if (!empty($submission->last_error)) {
776 776
             echo $submission->last_error;
777 777
             exit;
778 778
         }
779 779
 
780 780
         // Prepare the response.
781
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
781
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
782 782
         
783 783
         // Filter the response.
784
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
784
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
785 785
 
786
-        wp_send_json_success( $response );
786
+        wp_send_json_success($response);
787 787
     }
788 788
 
789 789
 }
Please login to merge, or discard this patch.
includes/user-functions.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
161 161
 
162
-	if ( current_user_can( 'manage_options' ) ) {
163
-		return 'manage_options';
164
-	};
162
+    if ( current_user_can( 'manage_options' ) ) {
163
+        return 'manage_options';
164
+    };
165 165
 
166
-	return $capalibilty;
166
+    return $capalibilty;
167 167
 }
168 168
 
169 169
 /**
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 function wpinv_create_user( $email ) {
186 186
 
187 187
     // Prepare user values.
188
-	$args = array(
189
-		'user_login' => wpinv_generate_user_name( $email ),
190
-		'user_pass'  => wp_generate_password(),
191
-		'user_email' => $email,
188
+    $args = array(
189
+        'user_login' => wpinv_generate_user_name( $email ),
190
+        'user_pass'  => wp_generate_password(),
191
+        'user_email' => $email,
192 192
         'role'       => 'subscriber',
193 193
     );
194 194
 
@@ -205,20 +205,20 @@  discard block
 block discarded – undo
205 205
 function wpinv_generate_user_name( $prefix = '' ) {
206 206
 
207 207
     // If prefix is an email, retrieve the part before the email.
208
-	$prefix = strtok( $prefix, '@' );
208
+    $prefix = strtok( $prefix, '@' );
209 209
 
210
-	// Trim to 4 characters max.
211
-	$prefix = sanitize_user( $prefix );
210
+    // Trim to 4 characters max.
211
+    $prefix = sanitize_user( $prefix );
212 212
 
213
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
215
-		$prefix = 'gtp';
216
-	}
213
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
+    if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
215
+        $prefix = 'gtp';
216
+    }
217 217
 
218
-	$username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
-	if ( username_exists( $username ) ) {
220
-		return wpinv_generate_user_name( $username );
221
-	}
218
+    $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
+    if ( username_exists( $username ) ) {
220
+        return wpinv_generate_user_name( $username );
221
+    }
222 222
 
223 223
     return $username;
224 224
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package GetPaid
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  *  Generates a users select dropdown.
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
  * @param array $args
17 17
  * @see wp_dropdown_users
18 18
  */
19
-function wpinv_dropdown_users( $args = '' ) {
19
+function wpinv_dropdown_users($args = '') {
20 20
 
21
-    if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) {
21
+    if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) {
22 22
         $args['show'] = 'display_name_with_login';
23 23
     }
24 24
 
25
-    return wp_dropdown_users( $args );
25
+    return wp_dropdown_users($args);
26 26
 }
27 27
 
28 28
 /**
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
  * @return string capability to check against
33 33
  * @param string $capalibilty Optional. The alternative capability to check against.
34 34
  */
35
-function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
35
+function wpinv_get_capability($capalibilty = 'manage_invoicing') {
36 36
 
37
-	if ( current_user_can( 'manage_options' ) ) {
37
+	if (current_user_can('manage_options')) {
38 38
 		return 'manage_options';
39 39
 	};
40 40
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  * @return bool
49 49
  */
50 50
 function wpinv_current_user_can_manage_invoicing() {
51
-    return current_user_can( wpinv_get_capability() );
51
+    return current_user_can(wpinv_get_capability());
52 52
 }
53 53
 
54 54
 /**
@@ -57,17 +57,17 @@  discard block
 block discarded – undo
57 57
  * @since 1.0.19
58 58
  * @return int|WP_Error
59 59
  */
60
-function wpinv_create_user( $email ) {
60
+function wpinv_create_user($email) {
61 61
 
62 62
     // Prepare user values.
63 63
 	$args = array(
64
-		'user_login' => wpinv_generate_user_name( $email ),
64
+		'user_login' => wpinv_generate_user_name($email),
65 65
 		'user_pass'  => wp_generate_password(),
66 66
 		'user_email' => $email,
67 67
         'role'       => 'subscriber',
68 68
     );
69 69
 
70
-    return wp_insert_user( $args );
70
+    return wp_insert_user($args);
71 71
 
72 72
 }
73 73
 
@@ -77,22 +77,22 @@  discard block
 block discarded – undo
77 77
  * @since 1.0.19
78 78
  * @return bool|WP_User
79 79
  */
80
-function wpinv_generate_user_name( $prefix = '' ) {
80
+function wpinv_generate_user_name($prefix = '') {
81 81
 
82 82
     // If prefix is an email, retrieve the part before the email.
83
-	$prefix = strtok( $prefix, '@' );
83
+	$prefix = strtok($prefix, '@');
84 84
 
85 85
 	// Trim to 4 characters max.
86
-	$prefix = sanitize_user( $prefix );
86
+	$prefix = sanitize_user($prefix);
87 87
 
88
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
89
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
88
+	$illegal_logins = (array) apply_filters('illegal_user_logins', array());
89
+	if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) {
90 90
 		$prefix = 'gtp';
91 91
 	}
92 92
 
93
-	$username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
94
-	if ( username_exists( $username ) ) {
95
-		return wpinv_generate_user_name( $username );
93
+	$username = $prefix . '_' . zeroise(wp_rand(0, 9999), 4);
94
+	if (username_exists($username)) {
95
+		return wpinv_generate_user_name($username);
96 96
 	}
97 97
 
98 98
     return $username;
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 
111 111
         // Slug - invoices.
112 112
         'gp-invoices'   => array(
113
-            'label'     => __( 'Invoices', 'invoicing' ), // Name of the tab.
113
+            'label'     => __('Invoices', 'invoicing'), // Name of the tab.
114 114
             'content'   => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead.
115 115
             'icon'      => 'fas fa-file-invoice', // Shown on some profile plugins.
116 116
         ),
117 117
 
118 118
         'gp-subscriptions' => array(
119
-            'label'        => __( 'Subscriptions', 'invoicing' ),
119
+            'label'        => __('Subscriptions', 'invoicing'),
120 120
             'content'      => '[wpinv_subscriptions]',
121 121
             'icon'         => 'fas fa-redo',
122 122
         )
123 123
     );
124 124
 
125
-    return apply_filters( 'getpaid_user_content_tabs', $tabs );
125
+    return apply_filters('getpaid_user_content_tabs', $tabs);
126 126
 }
127 127
 
128 128
 /**
@@ -132,19 +132,19 @@  discard block
 block discarded – undo
132 132
  * @param array $tab
133 133
  * @return array
134 134
  */
135
-function getpaid_prepare_user_content_tab( $tab ) {
135
+function getpaid_prepare_user_content_tab($tab) {
136 136
 
137
-    if ( ! empty( $tab['callback'] ) ) {
138
-        return call_user_func( $tab['callback'] );
137
+    if (!empty($tab['callback'])) {
138
+        return call_user_func($tab['callback']);
139 139
     }
140 140
 
141
-    if ( ! empty( $tab['content'] ) ) {
142
-        return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) );
141
+    if (!empty($tab['content'])) {
142
+        return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content']))))))));
143 143
     }
144 144
 
145 145
     $notice = aui()->alert(
146 146
         array(
147
-            'content'     => __( 'This tab has no content or content callback.', 'invoicing' ),
147
+            'content'     => __('This tab has no content or content callback.', 'invoicing'),
148 148
             'type'        => 'error',
149 149
         )
150 150
     );
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
  * @param string $default
161 161
  * @return array
162 162
  */
163
-function getpaid_get_tab_url( $tab, $default ) {
163
+function getpaid_get_tab_url($tab, $default) {
164 164
     global $getpaid_tab_url;
165 165
 
166
-    if ( empty( $getpaid_tab_url ) ) {
166
+    if (empty($getpaid_tab_url)) {
167 167
         return $default;
168 168
     }
169 169
 
170
-    return sprintf( $getpaid_tab_url, $tab );
170
+    return sprintf($getpaid_tab_url, $tab);
171 171
 
172 172
 }
173 173
 
@@ -186,27 +186,27 @@  discard block
 block discarded – undo
186 186
  * @param  array $tabs
187 187
  * @return array
188 188
  */
189
-function getpaid_filter_userswp_account_tabs( $tabs ) {
189
+function getpaid_filter_userswp_account_tabs($tabs) {
190 190
 
191 191
     // Abort if the integration is inactive.
192
-    if ( ! getpaid_is_userswp_integration_active() ) {
192
+    if (!getpaid_is_userswp_integration_active()) {
193 193
         return $tabs;
194 194
     }
195 195
 
196
-    $new_tabs   = array();
196
+    $new_tabs = array();
197 197
 
198
-    foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) {
198
+    foreach (getpaid_get_user_content_tabs() as $slug => $tab) {
199 199
 
200
-        $new_tabs[ $slug ] = array(
201
-            'title' => $tab[ 'label'],
202
-            'icon'  =>  $tab[ 'icon'],
200
+        $new_tabs[$slug] = array(
201
+            'title' => $tab['label'],
202
+            'icon'  =>  $tab['icon'],
203 203
         );
204 204
 
205 205
     }
206 206
 
207
-    return array_merge( $new_tabs, $tabs );
207
+    return array_merge($new_tabs, $tabs);
208 208
 }
209
-add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' );
209
+add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs');
210 210
 
211 211
 /**
212 212
  * Display our UsersWP account tabs.
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
  * @param  array $tabs
216 216
  * @return array
217 217
  */
218
-function getpaid_display_userswp_account_tabs( $tab ) {
218
+function getpaid_display_userswp_account_tabs($tab) {
219 219
     global $getpaid_tab_url;
220 220
 
221 221
     $our_tabs = getpaid_get_user_content_tabs();
222 222
 
223
-    if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) {
224
-        $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() );
225
-        echo getpaid_prepare_user_content_tab( $our_tabs[ $tab ] );
223
+    if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) {
224
+        $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url());
225
+        echo getpaid_prepare_user_content_tab($our_tabs[$tab]);
226 226
     }
227 227
 
228 228
 }
229
-add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' );
229
+add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs');
230 230
 
231 231
 
232 232
 /**
@@ -237,17 +237,17 @@  discard block
 block discarded – undo
237 237
  * @param  string $tab   Current tab.
238 238
  * @return string Title.
239 239
  */
240
-function getpaid_filter_userswp_account_title( $title, $tab ) {
240
+function getpaid_filter_userswp_account_title($title, $tab) {
241 241
 
242
-    $our_tabs   = getpaid_get_user_content_tabs();
242
+    $our_tabs = getpaid_get_user_content_tabs();
243 243
 
244
-    if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) {
245
-        return $our_tabs[ $tab ]['label'];
244
+    if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) {
245
+        return $our_tabs[$tab]['label'];
246 246
     }
247 247
 
248 248
     return $title;
249 249
 }
250
-add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 );
250
+add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2);
251 251
 
252 252
 /**
253 253
  * Registers the UsersWP integration settings.
@@ -256,26 +256,26 @@  discard block
 block discarded – undo
256 256
  * @param  array $settings An array of integration settings.
257 257
  * @return array
258 258
  */
259
-function getpaid_register_userswp_settings( $settings ) {
259
+function getpaid_register_userswp_settings($settings) {
260 260
 
261
-    if ( defined( 'USERSWP_PLUGIN_FILE' ) ) {
261
+    if (defined('USERSWP_PLUGIN_FILE')) {
262 262
 
263 263
         $settings[] = array(
264 264
 
265 265
             'id'       => 'userswp',
266
-            'label'    => __( 'UsersWP', 'invoicing' ),
266
+            'label'    => __('UsersWP', 'invoicing'),
267 267
             'settings' => array(
268 268
 
269 269
                 'userswp_settings' => array(
270 270
                     'id'   => 'userswp_settings',
271
-                    'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>',
271
+                    'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>',
272 272
                     'type' => 'header',
273 273
                 ),
274 274
 
275 275
                 'enable_userswp' => array(
276 276
                     'id'         => 'enable_userswp',
277
-                    'name'       => __( 'Enable Integration', 'invoicing' ),
278
-                    'desc'       => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ),
277
+                    'name'       => __('Enable Integration', 'invoicing'),
278
+                    'desc'       => __('Display GetPaid items on UsersWP account page.', 'invoicing'),
279 279
                     'type'       => 'checkbox',
280 280
                     'std'        => 1,
281 281
                 )
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 
289 289
     return $settings;
290 290
 }
291
-add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' );
291
+add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings');
292 292
 
293 293
 /**
294 294
  * Checks if the integration is enabled.
@@ -297,6 +297,6 @@  discard block
 block discarded – undo
297 297
  * @return bool
298 298
  */
299 299
 function getpaid_is_userswp_integration_active() {
300
-    $enabled = wpinv_get_option( 'enable_userswp', 1 );
301
-    return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled );
300
+    $enabled = wpinv_get_option('enable_userswp', 1);
301
+    return defined('USERSWP_PLUGIN_FILE') && !empty($enabled);
302 302
 }
Please login to merge, or discard this patch.