Passed
Push — master ( f2523a...21b628 )
by Brian
04:58
created
includes/wpinv-email-functions.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
     $css = getpaid_get_email_css();
110 110
 
111 111
     // include css inliner
112
-	if ( ! class_exists( 'Emogrifier' ) ) {
113
-		include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
112
+    if ( ! class_exists( 'Emogrifier' ) ) {
113
+        include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
114 114
     }
115 115
 
116 116
     // Inline the css.
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     $message = wpinv_email_style_body( $message );
190 190
     $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
191 191
 
192
-	return $mailer->send(
192
+    return $mailer->send(
193 193
         $to,
194 194
         $subject,
195 195
         $message,
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * Please use GetPaid_Notification_Email_Sender
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /*
12 12
 |--------------------------------------------------------------------------
@@ -17,19 +17,19 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Generates the email header.
19 19
  */
20
-function wpinv_email_header( $email_heading ) {
21
-    wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) );
20
+function wpinv_email_header($email_heading) {
21
+    wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading'));
22 22
 }
23
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
23
+add_action('wpinv_email_header', 'wpinv_email_header');
24 24
 
25 25
 
26 26
 /**
27 27
  * Generates the email footer.
28 28
  */
29 29
 function wpinv_email_footer() {
30
-    wpinv_get_template( 'emails/wpinv-email-footer.php' );
30
+    wpinv_get_template('emails/wpinv-email-footer.php');
31 31
 }
32
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
32
+add_action('wpinv_email_footer', 'wpinv_email_footer');
33 33
 
34 34
 
35 35
 /**
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
  * @param string $email_type
40 40
  * @param bool $sent_to_admin
41 41
  */
42
-function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) {
42
+function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) {
43 43
 
44
-    $args = compact( 'invoice', 'email_type', 'sent_to_admin' );
45
-    wpinv_get_template( 'emails/invoice-details.php', $args );
44
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
45
+    wpinv_get_template('emails/invoice-details.php', $args);
46 46
 
47 47
 }
48
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
48
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
49 49
 
50 50
 /**
51 51
  * Display line items in emails.
@@ -54,17 +54,17 @@  discard block
 block discarded – undo
54 54
  * @param string $email_type
55 55
  * @param bool $sent_to_admin
56 56
  */
57
-function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) {
57
+function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) {
58 58
 
59 59
     // Prepare line items.
60
-    $columns = getpaid_invoice_item_columns( $invoice );
61
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
60
+    $columns = getpaid_invoice_item_columns($invoice);
61
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
62 62
 
63 63
     // Load the template.
64
-    wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) );
64
+    wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin'));
65 65
 
66 66
 }
67
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
67
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
68 68
 
69 69
 
70 70
 /**
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
  * @param string $email_type
75 75
  * @param bool $sent_to_admin
76 76
  */
77
-function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) {
77
+function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) {
78 78
 
79
-    $args = compact( 'invoice', 'email_type', 'sent_to_admin' );
80
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args );
79
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
80
+    wpinv_get_template('emails/wpinv-email-billing-details.php', $args);
81 81
 
82 82
 }
83
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
83
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
84 84
 
85 85
 /**
86 86
  * Returns email css.
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
  */
89 89
 function getpaid_get_email_css() {
90 90
 
91
-    $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' );
92
-    return apply_filters( 'wpinv_email_styles', $css );
91
+    $css = wpinv_get_template_html('emails/wpinv-email-styles.php');
92
+    return apply_filters('wpinv_email_styles', $css);
93 93
 
94 94
 }
95 95
 
@@ -100,26 +100,26 @@  discard block
 block discarded – undo
100 100
  * @return string
101 101
  *
102 102
  */
103
-function wpinv_email_style_body( $content ) {
103
+function wpinv_email_style_body($content) {
104 104
 
105
-    if ( ! class_exists( 'DOMDocument' ) ) {
105
+    if (!class_exists('DOMDocument')) {
106 106
         return $content;
107 107
     }
108 108
 
109 109
     $css = getpaid_get_email_css();
110 110
 
111 111
     // include css inliner
112
-	if ( ! class_exists( 'Emogrifier' ) ) {
112
+	if (!class_exists('Emogrifier')) {
113 113
 		include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
114 114
     }
115 115
 
116 116
     // Inline the css.
117 117
     try {
118
-        $emogrifier = new Emogrifier( $content, $css );
118
+        $emogrifier = new Emogrifier($content, $css);
119 119
         $_content   = $emogrifier->emogrify();
120 120
         $content    = $_content;
121
-    } catch ( Exception $e ) {
122
-        wpinv_error_log( $e->getMessage(), 'emogrifier' );
121
+    } catch (Exception $e) {
122
+        wpinv_error_log($e->getMessage(), 'emogrifier');
123 123
     }
124 124
 
125 125
     return $content;
@@ -128,37 +128,37 @@  discard block
 block discarded – undo
128 128
 
129 129
 // Backwards compatibility.
130 130
 function wpinv_init_transactional_emails() {
131
-    foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) {
132
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
131
+    foreach (apply_filters('wpinv_email_actions', array()) as $action) {
132
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
133 133
     }
134 134
 }
135
-add_action( 'init', 'wpinv_init_transactional_emails' );
135
+add_action('init', 'wpinv_init_transactional_emails');
136 136
 
137 137
 function wpinv_send_transactional_email() {
138 138
     $args       = func_get_args();
139 139
     $function   = current_filter() . '_notification';
140
-    do_action_ref_array( $function, $args );
140
+    do_action_ref_array($function, $args);
141 141
 }
142 142
 
143 143
 function wpinv_mail_get_from_address() {
144
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from', get_option( 'admin_email' ) ) );
145
-    return sanitize_email( $from_address );
144
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from', get_option('admin_email')));
145
+    return sanitize_email($from_address);
146 146
 }
147 147
 
148 148
 function wpinv_mail_get_from_name() {
149
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name', get_bloginfo( 'name', 'display' ) ) );
150
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
149
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name', get_bloginfo('name', 'display')));
150
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
151 151
 }
152 152
 
153
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
154
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
155
-    return ( $active ? true : false );
153
+function wpinv_mail_admin_bcc_active($mail_type = '') {
154
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
155
+    return ($active ? true : false);
156 156
 }
157 157
 
158
-function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) {
159
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
158
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
159
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
160 160
 
161
-    switch ( $email_type ) {
161
+    switch ($email_type) {
162 162
         case 'html':
163 163
             $content_type = 'text/html';
164 164
             break;
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
  * @param array        $attachments Any files to attach to the email.
184 184
  * @param string|array $cc An email or array of extra emails to send a copy of the email to.
185 185
  */
186
-function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) {
186
+function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) {
187 187
 
188 188
     $mailer  = new GetPaid_Notification_Email_Sender();
189
-    $message = wpinv_email_style_body( $message );
190
-    $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
189
+    $message = wpinv_email_style_body($message);
190
+    $to      = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc));
191 191
 
192 192
 	return $mailer->send(
193 193
         $to,
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
  * @return array
205 205
  */
206 206
 function wpinv_get_emails() {
207
-    return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) );
207
+    return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings'));
208 208
 }
209 209
 
210 210
 /**
@@ -213,172 +213,172 @@  discard block
 block discarded – undo
213 213
  * @param array $settings
214 214
  * @return array
215 215
  */
216
-function wpinv_settings_emails( $settings = array() ) {
217
-    $settings = array_merge( $settings, wpinv_get_emails() );
218
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
216
+function wpinv_settings_emails($settings = array()) {
217
+    $settings = array_merge($settings, wpinv_get_emails());
218
+    return apply_filters('wpinv_settings_get_emails', $settings);
219 219
 }
220
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
220
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
221 221
 
222 222
 /**
223 223
  * Filter email section names.
224 224
  *
225 225
  */
226
-function wpinv_settings_sections_emails( $settings ) {
227
-    foreach ( wpinv_get_emails() as $key => $email ) {
228
-        $settings[ $key ] = ! empty( $email[ 'email_' . $key . '_header' ]['name'] ) ? strip_tags( $email[ 'email_' . $key . '_header' ]['name'] ) : strip_tags( $key );
226
+function wpinv_settings_sections_emails($settings) {
227
+    foreach (wpinv_get_emails() as $key => $email) {
228
+        $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key);
229 229
     }
230 230
 
231 231
     return $settings;
232 232
 }
233
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
233
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
234 234
 
235
-function wpinv_email_is_enabled( $email_type ) {
235
+function wpinv_email_is_enabled($email_type) {
236 236
     $emails = wpinv_get_emails();
237
-    $enabled = isset( $emails[ $email_type ] ) && wpinv_get_option( 'email_' . $email_type . '_active', 0 ) ? true : false;
237
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
238 238
 
239
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
239
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
240 240
 }
241 241
 
242
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
243
-    switch ( $email_type ) {
242
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
243
+    switch ($email_type) {
244 244
         case 'new_invoice':
245 245
         case 'cancelled_invoice':
246 246
         case 'failed_invoice':
247 247
             $recipient  = wpinv_get_admin_email();
248 248
             break;
249 249
         default:
250
-            $invoice    = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null );
251
-            $recipient  = ! empty( $invoice ) ? $invoice->get_email() : '';
250
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null);
251
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
252 252
             break;
253 253
     }
254 254
 
255
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
255
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
256 256
 }
257 257
 
258 258
 /**
259 259
  * Returns invoice CC recipients
260 260
  */
261
-function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) {
262
-    switch ( $email_type ) {
261
+function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) {
262
+    switch ($email_type) {
263 263
         case 'new_invoice':
264 264
         case 'cancelled_invoice':
265 265
         case 'failed_invoice':
266 266
             return array();
267 267
         break;
268 268
         default:
269
-            $invoice    = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null );
270
-            $recipient  = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true );
271
-            if ( empty( $recipient ) ) {
269
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null);
270
+            $recipient  = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true);
271
+            if (empty($recipient)) {
272 272
                 return array();
273 273
             }
274
-            return array_filter( array_map( 'trim', explode( ',', $recipient ) ) );
274
+            return array_filter(array_map('trim', explode(',', $recipient)));
275 275
         break;
276 276
     }
277 277
 
278 278
 }
279 279
 
280
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
281
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
282
-    $subject    = __( $subject, 'invoicing' );
280
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
281
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
282
+    $subject    = __($subject, 'invoicing');
283 283
 
284
-    $subject    = wpinv_email_format_text( $subject, $invoice );
284
+    $subject    = wpinv_email_format_text($subject, $invoice);
285 285
 
286
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
286
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
287 287
 }
288 288
 
289
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
290
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
291
-    $email_heading = __( $email_heading, 'invoicing' );
289
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
290
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
291
+    $email_heading = __($email_heading, 'invoicing');
292 292
 
293
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
293
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
294 294
 
295
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
295
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
296 296
 }
297 297
 
298
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
299
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
300
-    $content    = __( $content, 'invoicing' );
298
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
299
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
300
+    $content    = __($content, 'invoicing');
301 301
 
302
-    $content    = wpinv_email_format_text( $content, $invoice );
302
+    $content    = wpinv_email_format_text($content, $invoice);
303 303
 
304
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
304
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
305 305
 }
306 306
 
307
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
307
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
308 308
     $from_name = wpinv_mail_get_from_address();
309 309
     $from_email = wpinv_mail_get_from_address();
310 310
 
311
-    $invoice    = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null );
311
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null);
312 312
 
313
-    $headers    = 'From: ' . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
313
+    $headers    = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
314 314
     $headers    .= 'Reply-To: ' . $from_email . "\r\n";
315 315
     $headers    .= 'Content-Type: ' . wpinv_mail_get_content_type() . "\r\n";
316 316
 
317
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
317
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
318 318
 }
319 319
 
320
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
320
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
321 321
     $attachments = array();
322 322
 
323
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
323
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
324 324
 }
325 325
 
326 326
 /**
327 327
  * Searches for and replaces certain placeholders in an email.
328 328
  */
329
-function wpinv_email_format_text( $content, $invoice ) {
329
+function wpinv_email_format_text($content, $invoice) {
330 330
 
331 331
     $replace_array = array(
332 332
         '{site_title}' => wpinv_get_blogname(),
333
-        '{date}'       => getpaid_format_date( current_time( 'mysql' ) ),
333
+        '{date}'       => getpaid_format_date(current_time('mysql')),
334 334
     );
335 335
 
336
-    $invoice = new WPInv_Invoice( $invoice );
336
+    $invoice = new WPInv_Invoice($invoice);
337 337
 
338
-    if ( $invoice->get_id() ) {
338
+    if ($invoice->get_id()) {
339 339
 
340 340
         $replace_array = array_merge(
341 341
             $replace_array,
342 342
             array(
343
-                '{name}'             => sanitize_text_field( $invoice->get_user_full_name() ),
344
-                '{full_name}'        => sanitize_text_field( $invoice->get_user_full_name() ),
345
-                '{first_name}'       => sanitize_text_field( $invoice->get_first_name() ),
346
-                '{last_name}'        => sanitize_text_field( $invoice->get_last_name() ),
347
-                '{email}'            => sanitize_email( $invoice->get_email() ),
348
-                '{invoice_number}'   => sanitize_text_field( $invoice->get_number() ),
349
-                '{invoice_total}'    => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ),
350
-                '{invoice_link}'     => esc_url( $invoice->get_view_url() ),
351
-                '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ),
352
-                '{invoice_date}'     => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
353
-                '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
354
-                '{invoice_quote}'    => sanitize_text_field( $invoice->get_invoice_quote_type() ),
355
-                '{invoice_label}'    => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ),
356
-                '{is_was}'           => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
343
+                '{name}'             => sanitize_text_field($invoice->get_user_full_name()),
344
+                '{full_name}'        => sanitize_text_field($invoice->get_user_full_name()),
345
+                '{first_name}'       => sanitize_text_field($invoice->get_first_name()),
346
+                '{last_name}'        => sanitize_text_field($invoice->get_last_name()),
347
+                '{email}'            => sanitize_email($invoice->get_email()),
348
+                '{invoice_number}'   => sanitize_text_field($invoice->get_number()),
349
+                '{invoice_total}'    => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())),
350
+                '{invoice_link}'     => esc_url($invoice->get_view_url()),
351
+                '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()),
352
+                '{invoice_date}'     => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))),
353
+                '{invoice_due_date}' => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))),
354
+                '{invoice_quote}'    => sanitize_text_field($invoice->get_invoice_quote_type()),
355
+                '{invoice_label}'    => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())),
356
+                '{is_was}'           => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
357 357
             )
358 358
         );
359 359
 
360 360
     }
361 361
 
362 362
     // Let third party plugins filter the arra.
363
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
363
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
364 364
 
365
-    foreach ( $replace_array as $key => $value ) {
366
-        $content = str_replace( $key, $value, $content );
365
+    foreach ($replace_array as $key => $value) {
366
+        $content = str_replace($key, $value, $content);
367 367
     }
368 368
 
369
-    return apply_filters( 'wpinv_email_content_replace', $content );
369
+    return apply_filters('wpinv_email_content_replace', $content);
370 370
 }
371 371
 
372 372
 
373
-function wpinv_email_wrap_message( $message ) {
373
+function wpinv_email_wrap_message($message) {
374 374
     // Buffer
375 375
     ob_start();
376 376
 
377
-    do_action( 'wpinv_email_header' );
377
+    do_action('wpinv_email_header');
378 378
 
379
-    echo wp_kses_post( wpautop( wptexturize( $message ) ) );
379
+    echo wp_kses_post(wpautop(wptexturize($message)));
380 380
 
381
-    do_action( 'wpinv_email_footer' );
381
+    do_action('wpinv_email_footer');
382 382
 
383 383
     // Get contents
384 384
     $message = ob_get_clean();
@@ -386,21 +386,21 @@  discard block
 block discarded – undo
386 386
     return $message;
387 387
 }
388 388
 
389
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) {
390
-    if ( ! empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) {
391
-        $date_format = get_option( 'date_format' );
392
-        $time_format = get_option( 'time_format' );
389
+function wpinv_add_notes_to_invoice_email($invoice, $email_type) {
390
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) {
391
+        $date_format = get_option('date_format');
392
+        $time_format = get_option('time_format');
393 393
         ?>
394 394
         <div id="wpinv-email-notes">
395
-            <h3 class="wpinv-notes-t"><?php echo esc_html( apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ) ); ?></h3>
395
+            <h3 class="wpinv-notes-t"><?php echo esc_html(apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing'))); ?></h3>
396 396
             <ol class="wpinv-notes-lists">
397 397
         <?php
398
-        foreach ( $invoice_notes as $note ) {
399
-            $note_time = strtotime( $note->comment_date );
398
+        foreach ($invoice_notes as $note) {
399
+            $note_time = strtotime($note->comment_date);
400 400
             ?>
401 401
             <li class="comment wpinv-note">
402
-            <p class="wpinv-note-date meta"><?php printf( esc_html__( '%2$s at %3$s', 'invoicing' ), esc_html( $note->comment_author ), esc_html( date_i18n( $date_format, $note_time ) ), esc_html( date_i18n( $time_format, $note_time ) ), esc_html( $note_time ) ); ?></p>
403
-            <div class="wpinv-note-desc description"><?php echo wp_kses_post( wpautop( wptexturize( $note->comment_content ) ) ); ?></div>
402
+            <p class="wpinv-note-date meta"><?php printf(esc_html__('%2$s at %3$s', 'invoicing'), esc_html($note->comment_author), esc_html(date_i18n($date_format, $note_time)), esc_html(date_i18n($time_format, $note_time)), esc_html($note_time)); ?></p>
403
+            <div class="wpinv-note-desc description"><?php echo wp_kses_post(wpautop(wptexturize($note->comment_content))); ?></div>
404 404
             </li>
405 405
             <?php
406 406
         }
@@ -410,4 +410,4 @@  discard block
 block discarded – undo
410 410
         <?php
411 411
     }
412 412
 }
413
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
413
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -12,207 +12,207 @@
 block discarded – undo
12 12
  */
13 13
 class WPInv_Notes {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
-
24
-		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
-
28
-		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
-
31
-		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
33
-	}
34
-
35
-	/**
36
-	 * Filters invoice notes query to only include our notes.
37
-	 *
38
-	 * @param WP_Comment_Query $query
39
-	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
-
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
-			$query->query_vars['type'] = 'wpinv_note';
45
-		} else {
46
-
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
48
-				$query->query_vars['type__not_in'] = array();
49
-			}
50
-
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
-		}
54
-
55
-		return $query;
56
-	}
57
-
58
-	/**
59
-	 * Exclude notes from the comments feed.
60
-	 */
61
-	function wpinv_comment_feed_where( $where ) {
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
-	}
64
-
65
-	/**
66
-	 * Delete comments count cache whenever there is
67
-	 * new comment or the status of a comment changes. Cache
68
-	 * will be regenerated next time WPInv_Notes::wp_count_comments()
69
-	 * is called.
70
-	 */
71
-	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
73
-	}
74
-
75
-	/**
76
-	 * Remove invoice notes from wp_count_comments().
77
-	 *
78
-	 * @since  2.2
79
-	 * @param  object $stats   Comment stats.
80
-	 * @param  int    $post_id Post ID.
81
-	 * @return object
82
-	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
84
-		global $wpdb;
85
-
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
88
-
89
-			if ( ! $stats ) {
90
-				$stats = array(
91
-					'total_comments' => 0,
92
-					'all'            => 0,
93
-				);
94
-
95
-				$count = $wpdb->get_results(
96
-					"
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Filter inovice notes.
21
+        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
+        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
+
24
+        // Delete comments count cache whenever there is a new comment or a comment status changes.
25
+        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
+        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
+
28
+        // Count comments.
29
+        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
+
31
+        // Fires after notes are loaded.
32
+        do_action( 'wpinv_notes_init', $this );
33
+    }
34
+
35
+    /**
36
+     * Filters invoice notes query to only include our notes.
37
+     *
38
+     * @param WP_Comment_Query $query
39
+     */
40
+    public function set_invoice_note_type( $query ) {
41
+        $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
+
43
+        if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
+            $query->query_vars['type'] = 'wpinv_note';
45
+        } else {
46
+
47
+            if ( empty( $query->query_vars['type__not_in'] ) ) {
48
+                $query->query_vars['type__not_in'] = array();
49
+            }
50
+
51
+            $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
+            $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
+        }
54
+
55
+        return $query;
56
+    }
57
+
58
+    /**
59
+     * Exclude notes from the comments feed.
60
+     */
61
+    function wpinv_comment_feed_where( $where ) {
62
+        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
+    }
64
+
65
+    /**
66
+     * Delete comments count cache whenever there is
67
+     * new comment or the status of a comment changes. Cache
68
+     * will be regenerated next time WPInv_Notes::wp_count_comments()
69
+     * is called.
70
+     */
71
+    public function delete_comments_count_cache() {
72
+        delete_transient( 'getpaid_count_comments' );
73
+    }
74
+
75
+    /**
76
+     * Remove invoice notes from wp_count_comments().
77
+     *
78
+     * @since  2.2
79
+     * @param  object $stats   Comment stats.
80
+     * @param  int    $post_id Post ID.
81
+     * @return object
82
+     */
83
+    public function wp_count_comments( $stats, $post_id ) {
84
+        global $wpdb;
85
+
86
+        if ( empty( $post_id ) ) {
87
+            $stats = get_transient( 'getpaid_count_comments' );
88
+
89
+            if ( ! $stats ) {
90
+                $stats = array(
91
+                    'total_comments' => 0,
92
+                    'all'            => 0,
93
+                );
94
+
95
+                $count = $wpdb->get_results(
96
+                    "
97 97
 					SELECT comment_approved, COUNT(*) AS num_comments
98 98
 					FROM {$wpdb->comments}
99 99
 					WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note')
100 100
 					GROUP BY comment_approved
101 101
 					",
102
-					ARRAY_A
103
-				);
104
-
105
-				$approved = array(
106
-					'0'            => 'moderated',
107
-					'1'            => 'approved',
108
-					'spam'         => 'spam',
109
-					'trash'        => 'trash',
110
-					'post-trashed' => 'post-trashed',
111
-				);
112
-
113
-				foreach ( (array) $count as $row ) {
114
-					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
-						$stats['all']            += $row['num_comments'];
117
-						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
-						$stats['total_comments'] += $row['num_comments'];
120
-					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
-					}
124
-				}
125
-
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
129
-					}
130
-				}
131
-
132
-				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
134
-			}
102
+                    ARRAY_A
103
+                );
104
+
105
+                $approved = array(
106
+                    '0'            => 'moderated',
107
+                    '1'            => 'approved',
108
+                    'spam'         => 'spam',
109
+                    'trash'        => 'trash',
110
+                    'post-trashed' => 'post-trashed',
111
+                );
112
+
113
+                foreach ( (array) $count as $row ) {
114
+                    // Don't count post-trashed toward totals.
115
+                    if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
+                        $stats['all']            += $row['num_comments'];
117
+                        $stats['total_comments'] += $row['num_comments'];
118
+                    } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
+                        $stats['total_comments'] += $row['num_comments'];
120
+                    }
121
+                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
+                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
+                    }
124
+                }
125
+
126
+                foreach ( $approved as $key ) {
127
+                    if ( empty( $stats[ $key ] ) ) {
128
+                        $stats[ $key ] = 0;
129
+                    }
130
+                }
131
+
132
+                $stats = (object) $stats;
133
+                set_transient( 'getpaid_count_comments', $stats );
134
+            }
135 135
 }
136 136
 
137
-		return $stats;
138
-	}
139
-
140
-	/**
141
-	 * Returns an array of invoice notes.
142
-	 *
143
-	 * @param int $invoice_id The invoice ID whose notes to retrieve.
144
-	 * @param string $type Optional. Pass in customer to only return customer notes.
145
-	 * @return WP_Comment[]
146
-	 */
147
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
148
-
149
-		// Default comment args.
150
-		$args = array(
151
-			'post_id' => $invoice_id,
152
-			'orderby' => 'comment_ID',
153
-			'order'   => 'ASC',
154
-		);
155
-
156
-		// Maybe only show customer comments.
157
-		if ( $type == 'customer' ) {
158
-			$args['meta_key']   = '_wpi_customer_note';
159
-			$args['meta_value'] = 1;
160
-		}
161
-
162
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
163
-
164
-		return get_comments( $args );
165
-	}
166
-
167
-	/**
168
-	 * Saves an invoice comment.
169
-	 *
170
-	 * @param WPInv_Invoice $invoice The invoice to add the comment to.
171
-	 * @param string $note The note content.
172
-	 * @param string $note_author The name of the author of the note.
173
-	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174
-	 * @return int|false The new note's ID on success, false on failure.
175
-	 */
176
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
177
-
178
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
179
-
180
-		/**
181
-		 * Insert the comment.
182
-		 */
183
-		$note_id = wp_insert_comment(
184
-			wp_filter_comment(
185
-				array(
186
-					'comment_post_ID'      => $invoice->get_id(),
187
-					'comment_content'      => $note,
188
-					'comment_agent'        => 'Invoicing',
189
-					'user_id'              => get_current_user_id(),
190
-					'comment_author'       => $note_author,
191
-					'comment_author_IP'    => wpinv_get_ip(),
192
-					'comment_author_email' => $author_email,
193
-					'comment_author_url'   => $invoice->get_view_url(),
194
-					'comment_type'         => 'wpinv_note',
195
-				)
196
-			)
197
-		);
198
-
199
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
200
-
201
-		// Are we notifying the customer?
202
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
203
-			return $note_id;
204
-		}
205
-
206
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
207
-		do_action(
137
+        return $stats;
138
+    }
139
+
140
+    /**
141
+     * Returns an array of invoice notes.
142
+     *
143
+     * @param int $invoice_id The invoice ID whose notes to retrieve.
144
+     * @param string $type Optional. Pass in customer to only return customer notes.
145
+     * @return WP_Comment[]
146
+     */
147
+    public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
148
+
149
+        // Default comment args.
150
+        $args = array(
151
+            'post_id' => $invoice_id,
152
+            'orderby' => 'comment_ID',
153
+            'order'   => 'ASC',
154
+        );
155
+
156
+        // Maybe only show customer comments.
157
+        if ( $type == 'customer' ) {
158
+            $args['meta_key']   = '_wpi_customer_note';
159
+            $args['meta_value'] = 1;
160
+        }
161
+
162
+        $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
163
+
164
+        return get_comments( $args );
165
+    }
166
+
167
+    /**
168
+     * Saves an invoice comment.
169
+     *
170
+     * @param WPInv_Invoice $invoice The invoice to add the comment to.
171
+     * @param string $note The note content.
172
+     * @param string $note_author The name of the author of the note.
173
+     * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174
+     * @return int|false The new note's ID on success, false on failure.
175
+     */
176
+    function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
177
+
178
+        do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
179
+
180
+        /**
181
+         * Insert the comment.
182
+         */
183
+        $note_id = wp_insert_comment(
184
+            wp_filter_comment(
185
+                array(
186
+                    'comment_post_ID'      => $invoice->get_id(),
187
+                    'comment_content'      => $note,
188
+                    'comment_agent'        => 'Invoicing',
189
+                    'user_id'              => get_current_user_id(),
190
+                    'comment_author'       => $note_author,
191
+                    'comment_author_IP'    => wpinv_get_ip(),
192
+                    'comment_author_email' => $author_email,
193
+                    'comment_author_url'   => $invoice->get_view_url(),
194
+                    'comment_type'         => 'wpinv_note',
195
+                )
196
+            )
197
+        );
198
+
199
+        do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
200
+
201
+        // Are we notifying the customer?
202
+        if ( empty( $note_id ) || empty( $for_customer ) ) {
203
+            return $note_id;
204
+        }
205
+
206
+        add_comment_meta( $note_id, '_wpi_customer_note', 1 );
207
+        do_action(
208 208
             'wpinv_new_customer_note',
209 209
             array(
210
-				'invoice_id' => $invoice->get_id(),
211
-				'user_note'  => $note,
210
+                'invoice_id' => $invoice->get_id(),
211
+                'user_note'  => $note,
212 212
             )
213 213
         );
214
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
215
-		return $note_id;
216
-	}
214
+        do_action( 'getpaid_new_customer_note', $invoice, $note );
215
+        return $note_id;
216
+    }
217 217
 
218 218
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 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
  * Handles invoice notes.
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
 	public function __construct() {
19 19
 
20 20
 		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
21
+		add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
22
+		add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1);
23 23
 
24 24
 		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
25
+		add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
26
+		add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
27 27
 
28 28
 		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
29
+		add_filter('wp_count_comments', array($this, 'wp_count_comments'), 100, 2);
30 30
 
31 31
 		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
32
+		do_action('wpinv_notes_init', $this);
33 33
 	}
34 34
 
35 35
 	/**
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param WP_Comment_Query $query
39 39
 	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
40
+	public function set_invoice_note_type($query) {
41
+		$post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42 42
 
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
43
+		if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) {
44 44
 			$query->query_vars['type'] = 'wpinv_note';
45 45
 		} else {
46 46
 
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
47
+			if (empty($query->query_vars['type__not_in'])) {
48 48
 				$query->query_vars['type__not_in'] = array();
49 49
 			}
50 50
 
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
51
+			$query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']);
52
+			$query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']);
53 53
 		}
54 54
 
55 55
 		return $query;
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
 	/**
59 59
 	 * Exclude notes from the comments feed.
60 60
 	 */
61
-	function wpinv_comment_feed_where( $where ) {
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
61
+	function wpinv_comment_feed_where($where) {
62
+		return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' ";
63 63
 	}
64 64
 
65 65
 	/**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * is called.
70 70
 	 */
71 71
 	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
72
+		delete_transient('getpaid_count_comments');
73 73
 	}
74 74
 
75 75
 	/**
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 	 * @param  int    $post_id Post ID.
81 81
 	 * @return object
82 82
 	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
83
+	public function wp_count_comments($stats, $post_id) {
84 84
 		global $wpdb;
85 85
 
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
86
+		if (empty($post_id)) {
87
+			$stats = get_transient('getpaid_count_comments');
88 88
 
89
-			if ( ! $stats ) {
89
+			if (!$stats) {
90 90
 				$stats = array(
91 91
 					'total_comments' => 0,
92 92
 					'all'            => 0,
@@ -110,27 +110,27 @@  discard block
 block discarded – undo
110 110
 					'post-trashed' => 'post-trashed',
111 111
 				);
112 112
 
113
-				foreach ( (array) $count as $row ) {
113
+				foreach ((array) $count as $row) {
114 114
 					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
115
+					if (!in_array($row['comment_approved'], array('post-trashed', 'trash', 'spam'), true)) {
116 116
 						$stats['all']            += $row['num_comments'];
117 117
 						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
118
+					} elseif (!in_array($row['comment_approved'], array('post-trashed', 'trash'), true)) {
119 119
 						$stats['total_comments'] += $row['num_comments'];
120 120
 					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
121
+					if (isset($approved[$row['comment_approved']])) {
122
+						$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
123 123
 					}
124 124
 				}
125 125
 
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
126
+				foreach ($approved as $key) {
127
+					if (empty($stats[$key])) {
128
+						$stats[$key] = 0;
129 129
 					}
130 130
 				}
131 131
 
132 132
 				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
133
+				set_transient('getpaid_count_comments', $stats);
134 134
 			}
135 135
 }
136 136
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @param string $type Optional. Pass in customer to only return customer notes.
145 145
 	 * @return WP_Comment[]
146 146
 	 */
147
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
147
+	public function get_invoice_notes($invoice_id = 0, $type = 'all') {
148 148
 
149 149
 		// Default comment args.
150 150
 		$args = array(
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
 		);
155 155
 
156 156
 		// Maybe only show customer comments.
157
-		if ( $type == 'customer' ) {
157
+		if ($type == 'customer') {
158 158
 			$args['meta_key']   = '_wpi_customer_note';
159 159
 			$args['meta_value'] = 1;
160 160
 		}
161 161
 
162
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
162
+		$args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
163 163
 
164
-		return get_comments( $args );
164
+		return get_comments($args);
165 165
 	}
166 166
 
167 167
 	/**
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
 	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174 174
 	 * @return int|false The new note's ID on success, false on failure.
175 175
 	 */
176
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
176
+	function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) {
177 177
 
178
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
178
+		do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer);
179 179
 
180 180
 		/**
181 181
 		 * Insert the comment.
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
 			)
197 197
 		);
198 198
 
199
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
199
+		do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer);
200 200
 
201 201
 		// Are we notifying the customer?
202
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
202
+		if (empty($note_id) || empty($for_customer)) {
203 203
 			return $note_id;
204 204
 		}
205 205
 
206
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
206
+		add_comment_meta($note_id, '_wpi_customer_note', 1);
207 207
 		do_action(
208 208
             'wpinv_new_customer_note',
209 209
             array(
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 				'user_note'  => $note,
212 212
             )
213 213
         );
214
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
214
+		do_action('getpaid_new_customer_note', $invoice, $note);
215 215
 		return $note_id;
216 216
 	}
217 217
 
Please login to merge, or discard this patch.
includes/class-bp-getpaid-component.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -17,45 +17,45 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class BP_GetPaid_Component extends BP_Component {
19 19
 
20
-	/**
21
-	 * Start the component setup process.
22
-	 *
23
-	 * @since 2.1.5
24
-	 */
25
-	public function __construct() {
26
-		parent::start(
27
-			'getpaid',
28
-			'GetPaid',
29
-			buddypress()->plugin_dir,
30
-			array(
31
-				'adminbar_myaccount_order' => 30,
32
-			)
33
-		);
34
-	}
20
+    /**
21
+     * Start the component setup process.
22
+     *
23
+     * @since 2.1.5
24
+     */
25
+    public function __construct() {
26
+        parent::start(
27
+            'getpaid',
28
+            'GetPaid',
29
+            buddypress()->plugin_dir,
30
+            array(
31
+                'adminbar_myaccount_order' => 30,
32
+            )
33
+        );
34
+    }
35 35
 
36 36
     /**
37
-	 * Set up component global variables.
38
-	 *
39
-	 * @since 2.1.5
40
-	 *
41
-	 *
42
-	 * @param array $args {
43
-	 *     All values are optional.
44
-	 *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
-	 *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
-	 *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
-	 *                                           component has a root directory (the slug will be overridden by the
48
-	 *                                           post_name of the directory page). Default: the slug of the directory page
49
-	 *                                           if one is found, otherwise an empty string.
50
-	 *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
-	 *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
-	 *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
-	 *                                           'Search Groups...'.
54
-	 *     @type array    $global_tables         Optional. An array of database table names.
55
-	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56
-	 * }
57
-	 */
58
-	public function setup_globals( $args = array() ) {
37
+     * Set up component global variables.
38
+     *
39
+     * @since 2.1.5
40
+     *
41
+     *
42
+     * @param array $args {
43
+     *     All values are optional.
44
+     *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
+     *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
+     *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
+     *                                           component has a root directory (the slug will be overridden by the
48
+     *                                           post_name of the directory page). Default: the slug of the directory page
49
+     *                                           if one is found, otherwise an empty string.
50
+     *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
+     *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
+     *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
+     *                                           'Search Groups...'.
54
+     *     @type array    $global_tables         Optional. An array of database table names.
55
+     *     @type array    $meta_tables           Optional. An array of metadata table names.
56
+     * }
57
+     */
58
+    public function setup_globals( $args = array() ) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
                 'has_directory' => false,
65 65
             )
66 66
         );
67
-	}
68
-
69
-	/**
70
-	 * Set up component navigation.
71
-	 *
72
-	 * @since 2.1.5
73
-	 *
74
-	 * @see BP_Component::setup_nav() for a description of arguments.
75
-	 *
76
-	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
-	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
-	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
-
81
-		// Abort if the integration is inactive.
67
+    }
68
+
69
+    /**
70
+     * Set up component navigation.
71
+     *
72
+     * @since 2.1.5
73
+     *
74
+     * @see BP_Component::setup_nav() for a description of arguments.
75
+     *
76
+     * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
+     * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
+     */
79
+    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
+
81
+        // Abort if the integration is inactive.
82 82
         if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
83 83
             return;
84 84
         }
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
             return;
89 89
         }
90 90
 
91
-		// Determine user to use.
92
-		$user_domain   = bp_loggedin_user_domain();
93
-		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
95
-
96
-		// Add 'Payments' to the main navigation.
97
-		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
-			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
91
+        // Determine user to use.
92
+        $user_domain   = bp_loggedin_user_domain();
93
+        $slug          = 'getpaid';
94
+        $payments_link = trailingslashit( $user_domain . $slug );
95
+
96
+        // Add 'Payments' to the main navigation.
97
+        $main_nav = array(
98
+            'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
+            'slug'                    => $slug,
100
+            'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
+            'screen_function'         => array( $this, 'display_current_tab' ),
102
+            'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
103 103
             'show_for_displayed_user' => false,
104
-			'item_css_id'             => $this->id,
105
-			'parent_url'              => $user_domain,
106
-			'parent_slug'             => buddypress()->slug,
107
-		);
104
+            'item_css_id'             => $this->id,
105
+            'parent_url'              => $user_domain,
106
+            'parent_slug'             => buddypress()->slug,
107
+        );
108 108
 
109
-		// Add the subnav items to the payments nav item if we are using a theme that supports this.
109
+        // Add the subnav items to the payments nav item if we are using a theme that supports this.
110 110
         foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
111 111
 
112 112
             $sub_nav[] = array(
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118 118
                 'screen_function'         => function() use ( $tab ) {
119
-					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120
-					$this->display_current_tab();
119
+                    $GLOBALS['getpaid_bp_current_tab'] = $tab;
120
+                    $this->display_current_tab();
121 121
                 },
122 122
                 'show_for_displayed_user' => false,
123 123
                 'item_css_id'             => "getpaid-bp-$_slug",
@@ -125,27 +125,27 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
129
-	}
130
-
131
-	/**
132
-	 * Set up the component entries in the WordPress Admin Bar.
133
-	 *
134
-	 * @since 2.1.5
135
-	 *
136
-	 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
-	 *      parameter array.
138
-	 *
139
-	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
-	 *                            description.
141
-	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
128
+        parent::setup_nav( $main_nav, $sub_nav );
129
+    }
143 130
 
144
-		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
146
-
147
-			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
131
+    /**
132
+     * Set up the component entries in the WordPress Admin Bar.
133
+     *
134
+     * @since 2.1.5
135
+     *
136
+     * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
+     *      parameter array.
138
+     *
139
+     * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
+     *                            description.
141
+     */
142
+    public function setup_admin_bar( $wp_admin_nav = array() ) {
143
+
144
+        // Menus for logged in user.
145
+        if ( is_user_logged_in() ) {
146
+
147
+            // Setup the logged in user variables.
148
+            $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
@@ -168,48 +168,48 @@  discard block
 block discarded – undo
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
172
-	}
173
-
174
-	/**
175
-	 * Retrieves the current tab.
176
-	 *
177
-	 * @since 2.1.5
178
-	 */
179
-	public function get_current_tab() {
180
-		global $getpaid_bp_current_tab;
181
-
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
183
-			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
185
-				'content' => '[wpinv_history]',
186
-				'icon'    => 'fas fa-file-invoice',
187
-			);
188
-		}
189
-
190
-		return $getpaid_bp_current_tab;
191
-	}
192
-
193
-	/**
194
-	 * Displays the current tab.
195
-	 *
196
-	 * @since 2.1.5
197
-	 */
198
-	public function display_current_tab() {
199
-
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
171
+        parent::setup_admin_bar( $wp_admin_nav );
172
+    }
173
+
174
+    /**
175
+     * Retrieves the current tab.
176
+     *
177
+     * @since 2.1.5
178
+     */
179
+    public function get_current_tab() {
180
+        global $getpaid_bp_current_tab;
181
+
182
+        if ( empty( $getpaid_bp_current_tab ) ) {
183
+            return array(
184
+                'label'   => __( 'Invoices', 'invoicing' ),
185
+                'content' => '[wpinv_history]',
186
+                'icon'    => 'fas fa-file-invoice',
187
+            );
188
+        }
189
+
190
+        return $getpaid_bp_current_tab;
191
+    }
192
+
193
+    /**
194
+     * Displays the current tab.
195
+     *
196
+     * @since 2.1.5
197
+     */
198
+    public function display_current_tab() {
199
+
200
+        add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
+        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
202 202
 
203 203
         bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
204
-	}
205
-
206
-	/**
207
-	 * Handles the actual display of the current tab.
208
-	 *
209
-	 * @since 2.1.5
210
-	 */
211
-	public function handle_display_current_tab() {
212
-		 getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
-	}
204
+    }
205
+
206
+    /**
207
+     * Handles the actual display of the current tab.
208
+     *
209
+     * @since 2.1.5
210
+     */
211
+    public function handle_display_current_tab() {
212
+            getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
+    }
214 214
 
215 215
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 // Exit if accessed directly.
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * Main GetPaid Class.
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56 56
 	 * }
57 57
 	 */
58
-	public function setup_globals( $args = array() ) {
58
+	public function setup_globals($args = array()) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -76,30 +76,30 @@  discard block
 block discarded – undo
76 76
 	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77 77
 	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78 78
 	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
79
+	public function setup_nav($main_nav = array(), $sub_nav = array()) {
80 80
 
81 81
 		// Abort if the integration is inactive.
82
-        if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
82
+        if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) {
83 83
             return;
84 84
         }
85 85
 
86 86
         // Or a user is not viewing their profile.
87
-        if ( bp_displayed_user_id() != bp_loggedin_user_id() ) {
87
+        if (bp_displayed_user_id() != bp_loggedin_user_id()) {
88 88
             return;
89 89
         }
90 90
 
91 91
 		// Determine user to use.
92 92
 		$user_domain   = bp_loggedin_user_domain();
93 93
 		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
94
+		$payments_link = trailingslashit($user_domain . $slug);
95 95
 
96 96
 		// Add 'Payments' to the main navigation.
97 97
 		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
98
+			'name'                    => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'),
99 99
 			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
100
+			'position'                => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug),
101
+			'screen_function'         => array($this, 'display_current_tab'),
102
+			'default_subnav_slug'     => apply_filters('getpaid_default_tab', 'gp-edit-address'),
103 103
             'show_for_displayed_user' => false,
104 104
 			'item_css_id'             => $this->id,
105 105
 			'parent_url'              => $user_domain,
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 
109 109
 		// Add the subnav items to the payments nav item if we are using a theme that supports this.
110
-        foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
110
+        foreach (getpaid_get_user_content_tabs() as $_slug => $tab) {
111 111
 
112 112
             $sub_nav[] = array(
113 113
                 'name'                    => $tab['label'],
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 'parent_url'              => $payments_link,
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118
-                'screen_function'         => function() use ( $tab ) {
118
+                'screen_function'         => function() use ($tab) {
119 119
 					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120 120
 					$this->display_current_tab();
121 121
                 },
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
128
+		parent::setup_nav($main_nav, $sub_nav);
129 129
 	}
130 130
 
131 131
 	/**
@@ -139,36 +139,36 @@  discard block
 block discarded – undo
139 139
 	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140 140
 	 *                            description.
141 141
 	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
142
+	public function setup_admin_bar($wp_admin_nav = array()) {
143 143
 
144 144
 		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
145
+		if (is_user_logged_in()) {
146 146
 
147 147
 			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
148
+			$payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/');
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
152 152
                 'parent' => buddypress()->my_account_menu_id,
153 153
                 'id'     => 'my-account-getpaid',
154
-                'title'  => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ),
155
-                'href'   => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
154
+                'title'  => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'),
155
+                'href'   => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'),
156 156
             );
157 157
 
158
-            foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) {
158
+            foreach (getpaid_get_user_content_tabs() as $slug => $tab) {
159 159
 
160 160
                 $wp_admin_nav[] = array(
161 161
                     'parent'   => 'my-account-getpaid',
162 162
                     'id'       => 'my-account-getpaid' . $slug,
163 163
                     'title'    => $tab['label'],
164
-                    'href'     => trailingslashit( $payments_link . $slug ),
164
+                    'href'     => trailingslashit($payments_link . $slug),
165 165
                     'position' => 20,
166 166
                 );
167 167
 
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
171
+		parent::setup_admin_bar($wp_admin_nav);
172 172
 	}
173 173
 
174 174
 	/**
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 	public function get_current_tab() {
180 180
 		global $getpaid_bp_current_tab;
181 181
 
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
182
+		if (empty($getpaid_bp_current_tab)) {
183 183
 			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
184
+				'label'   => __('Invoices', 'invoicing'),
185 185
 				'content' => '[wpinv_history]',
186 186
 				'icon'    => 'fas fa-file-invoice',
187 187
 			);
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 */
198 198
 	public function display_current_tab() {
199 199
 
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
200
+		add_action('bp_template_content', array($this, 'handle_display_current_tab'));
201
+		$template = apply_filters('bp_core_template_plugin', 'members/single/plugins');
202 202
 
203
-        bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
203
+        bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template));
204 204
 	}
205 205
 
206 206
 	/**
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @since 2.1.5
210 210
 	 */
211 211
 	public function handle_display_current_tab() {
212
-		 getpaid_prepare_user_content_tab( $this->get_current_tab() );
212
+		 getpaid_prepare_user_content_tab($this->get_current_tab());
213 213
 	}
214 214
 
215 215
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-legacy-gateway.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@  discard block
 block discarded – undo
15 15
 abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway {
16 16
 
17 17
     /**
18
-	 * Class constructor.
19
-	 */
20
-	public function __construct() {
18
+     * Class constructor.
19
+     */
20
+    public function __construct() {
21 21
         parent::__construct();
22 22
     }
23 23
 
24 24
     /**
25
-	 * Returns the API URL.
26
-	 *
27
-	 *
28
-	 * @param WPInv_Invoice $invoice Invoice.
29
-	 * @return string
30
-	 */
31
-	public function get_api_url( $invoice ) {
25
+     * Returns the API URL.
26
+     *
27
+     *
28
+     * @param WPInv_Invoice $invoice Invoice.
29
+     * @return string
30
+     */
31
+    public function get_api_url( $invoice ) {
32 32
         return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
36
-	 * Communicates with authorize.net
37
-	 *
38
-	 *
39
-	 * @param array $post Data to post.
36
+     * Communicates with authorize.net
37
+     *
38
+     *
39
+     * @param array $post Data to post.
40 40
      * @param WPInv_Invoice $invoice Invoice.
41
-	 * @return stdClass|WP_Error
42
-	 */
41
+     * @return stdClass|WP_Error
42
+     */
43 43
     public function post( $post, $invoice ) {
44 44
 
45 45
         $url      = $this->get_api_url( $invoice );
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
     }
90 90
 
91 91
     /**
92
-	 * Returns the API authentication params.
93
-	 *
94
-	 *
95
-	 * @return array
96
-	 */
97
-	public function get_auth_params() {
92
+     * Returns the API authentication params.
93
+     *
94
+     *
95
+     * @return array
96
+     */
97
+    public function get_auth_params() {
98 98
 
99 99
         return array(
100 100
             'name'           => $this->get_option( 'login_id' ),
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
     }
105 105
 
106 106
     /**
107
-	 * Cancels a subscription remotely
108
-	 *
109
-	 *
110
-	 * @param WPInv_Subscription $subscription Subscription.
107
+     * Cancels a subscription remotely
108
+     *
109
+     *
110
+     * @param WPInv_Subscription $subscription Subscription.
111 111
      * @param WPInv_Invoice $invoice Invoice.
112
-	 */
113
-	public function cancel_subscription( $subscription, $invoice ) {
112
+     */
113
+    public function cancel_subscription( $subscription, $invoice ) {
114 114
 
115 115
         // Backwards compatibility. New version do not use authorize.net subscriptions.
116 116
         $this->post(
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
     }
127 127
 
128 128
     /**
129
-	 * Processes ipns.
130
-	 *
131
-	 * @return void
132
-	 */
133
-	public function verify_ipn() {
129
+     * Processes ipns.
130
+     *
131
+     * @return void
132
+     */
133
+    public function verify_ipn() {
134 134
 
135 135
         $this->maybe_process_old_ipn();
136 136
 
137 137
         // Validate the IPN.
138 138
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
139
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) );
139
+            wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) );
140 140
         }
141 141
 
142 142
         // Event type.
@@ -175,24 +175,24 @@  discard block
 block discarded – undo
175 175
     }
176 176
 
177 177
     /**
178
-	 * Validates IPN invoices.
179
-	 *
178
+     * Validates IPN invoices.
179
+     *
180 180
      * @param WPInv_Invoice $invoice
181 181
      * @param object $payload
182
-	 * @return void
183
-	 */
184
-	public function validate_ipn_invoice( $invoice, $payload ) {
182
+     * @return void
183
+     */
184
+    public function validate_ipn_invoice( $invoice, $payload ) {
185 185
         if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
186 186
             exit;
187 187
         }
188 188
     }
189 189
 
190 190
     /**
191
-	 * Process subscriptio IPNS.
192
-	 *
193
-	 * @return void
194
-	 */
195
-	public function maybe_process_old_ipn() {
191
+     * Process subscriptio IPNS.
192
+     *
193
+     * @return void
194
+     */
195
+    public function maybe_process_old_ipn() {
196 196
 
197 197
         $data = wp_kses_post_deep( wp_unslash( $_POST ) );
198 198
 
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
     }
235 235
 
236 236
     /**
237
-	 * Validates the old IPN signature.
237
+     * Validates the old IPN signature.
238 238
      *
239 239
      * @param array $posted
240
-	 */
241
-	public function validate_old_ipn_signature( $posted ) {
240
+     */
241
+    public function validate_old_ipn_signature( $posted ) {
242 242
 
243 243
         $signature = $this->get_option( 'signature_key' );
244 244
         if ( ! empty( $signature ) ) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
     }
257 257
 
258 258
     /**
259
-	 * Check Authorize.NET IPN validity.
260
-	 */
261
-	public function validate_ipn() {
259
+     * Check Authorize.NET IPN validity.
260
+     */
261
+    public function validate_ipn() {
262 262
 
263 263
         wpinv_error_log( 'Validating Authorize.NET IPN response' );
264 264
 
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 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 Legacy Payment Gateway class.
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 	 * @param WPInv_Invoice $invoice Invoice.
29 29
 	 * @return string
30 30
 	 */
31
-	public function get_api_url( $invoice ) {
32
-        return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
31
+	public function get_api_url($invoice) {
32
+        return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
@@ -40,48 +40,48 @@  discard block
 block discarded – undo
40 40
      * @param WPInv_Invoice $invoice Invoice.
41 41
 	 * @return stdClass|WP_Error
42 42
 	 */
43
-    public function post( $post, $invoice ) {
43
+    public function post($post, $invoice) {
44 44
 
45
-        $url      = $this->get_api_url( $invoice );
45
+        $url      = $this->get_api_url($invoice);
46 46
         $response = wp_remote_post(
47 47
             $url,
48 48
             array(
49 49
                 'headers' => array(
50 50
                     'Content-Type' => 'application/json; charset=utf-8',
51 51
                 ),
52
-                'body'    => json_encode( $post ),
52
+                'body'    => json_encode($post),
53 53
                 'method'  => 'POST',
54 54
             )
55 55
         );
56 56
 
57
-        if ( is_wp_error( $response ) ) {
57
+        if (is_wp_error($response)) {
58 58
             return $response;
59 59
         }
60 60
 
61
-        $response = wp_unslash( wp_remote_retrieve_body( $response ) );
62
-        $response = preg_replace( '/\xEF\xBB\xBF/', '', $response ); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851
63
-        $response = json_decode( $response );
61
+        $response = wp_unslash(wp_remote_retrieve_body($response));
62
+        $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851
63
+        $response = json_decode($response);
64 64
 
65
-        if ( empty( $response ) ) {
66
-            return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) );
65
+        if (empty($response)) {
66
+            return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing'));
67 67
         }
68 68
 
69
-        if ( $response->messages->resultCode == 'Error' ) {
69
+        if ($response->messages->resultCode == 'Error') {
70 70
 
71
-            if ( $this->is_sandbox( $invoice ) ) {
72
-                wpinv_error_log( $response );
71
+            if ($this->is_sandbox($invoice)) {
72
+                wpinv_error_log($response);
73 73
             }
74 74
 
75
-            if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) {
76
-                return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId );
75
+            if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) {
76
+                return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId);
77 77
             }
78 78
 
79
-            if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) {
79
+            if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) {
80 80
                 $error = $response->transactionResponse->errors[0];
81
-                return new WP_Error( $error->errorCode, $error->errorText );
81
+                return new WP_Error($error->errorCode, $error->errorText);
82 82
             }
83 83
 
84
-            return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text );
84
+            return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text);
85 85
         }
86 86
 
87 87
         return $response;
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 	public function get_auth_params() {
98 98
 
99 99
         return array(
100
-            'name'           => $this->get_option( 'login_id' ),
101
-            'transactionKey' => $this->get_option( 'transaction_key' ),
100
+            'name'           => $this->get_option('login_id'),
101
+            'transactionKey' => $this->get_option('transaction_key'),
102 102
         );
103 103
 
104 104
     }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param WPInv_Subscription $subscription Subscription.
111 111
      * @param WPInv_Invoice $invoice Invoice.
112 112
 	 */
113
-	public function cancel_subscription( $subscription, $invoice ) {
113
+	public function cancel_subscription($subscription, $invoice) {
114 114
 
115 115
         // Backwards compatibility. New version do not use authorize.net subscriptions.
116 116
         $this->post(
@@ -135,38 +135,38 @@  discard block
 block discarded – undo
135 135
         $this->maybe_process_old_ipn();
136 136
 
137 137
         // Validate the IPN.
138
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
139
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) );
138
+        if (empty($_POST) || !$this->validate_ipn()) {
139
+		    wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 200));
140 140
         }
141 141
 
142 142
         // Event type.
143
-        $posted = json_decode( file_get_contents( 'php://input' ) );
144
-        if ( empty( $posted ) ) {
145
-            wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 200 ) );
143
+        $posted = json_decode(file_get_contents('php://input'));
144
+        if (empty($posted)) {
145
+            wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 200));
146 146
         }
147 147
 
148 148
         // Process the IPN.
149
-        $posted = (object) wp_unslash( $posted );
149
+        $posted = (object) wp_unslash($posted);
150 150
 
151 151
         // Process refunds.
152
-        if ( 'net.authorize.payment.refund.created' == $posted->eventType ) {
153
-            $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId );
154
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
152
+        if ('net.authorize.payment.refund.created' == $posted->eventType) {
153
+            $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId);
154
+            $this->validate_ipn_invoice($invoice, $posted->payload);
155 155
             $invoice->refund();
156 156
         }
157 157
 
158 158
         // Held funds approved.
159
-        if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) {
160
-            $invoice = new WPInv_Invoice( $posted->payload->id );
161
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
162
-            $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) );
159
+        if ('net.authorize.payment.fraud.approved' == $posted->eventType) {
160
+            $invoice = new WPInv_Invoice($posted->payload->id);
161
+            $this->validate_ipn_invoice($invoice, $posted->payload);
162
+            $invoice->mark_paid(false, __('Payment released', 'invoicing'));
163 163
         }
164 164
 
165 165
         // Held funds declined.
166
-        if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) {
167
-            $invoice = new WPInv_Invoice( $posted->payload->id );
168
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
169
-            $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) );
166
+        if ('net.authorize.payment.fraud.declined' == $posted->eventType) {
167
+            $invoice = new WPInv_Invoice($posted->payload->id);
168
+            $this->validate_ipn_invoice($invoice, $posted->payload);
169
+            $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing'));
170 170
             $invoice->save();
171 171
         }
172 172
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
      * @param object $payload
182 182
 	 * @return void
183 183
 	 */
184
-	public function validate_ipn_invoice( $invoice, $payload ) {
185
-        if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
184
+	public function validate_ipn_invoice($invoice, $payload) {
185
+        if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) {
186 186
             exit;
187 187
         }
188 188
     }
@@ -194,32 +194,32 @@  discard block
 block discarded – undo
194 194
 	 */
195 195
 	public function maybe_process_old_ipn() {
196 196
 
197
-        $data = wp_kses_post_deep( wp_unslash( $_POST ) );
197
+        $data = wp_kses_post_deep(wp_unslash($_POST));
198 198
 
199 199
         // Only process subscriptions subscriptions.
200
-        if ( empty( $data['x_subscription_id'] ) ) {
200
+        if (empty($data['x_subscription_id'])) {
201 201
             return;
202 202
         }
203 203
 
204 204
         // Check validity.
205
-        $this->validate_old_ipn_signature( $data );
205
+        $this->validate_old_ipn_signature($data);
206 206
 
207 207
         // Fetch the associated subscription.
208
-        $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] );
209
-        $subscription    = new WPInv_Subscription( $subscription_id );
208
+        $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']);
209
+        $subscription    = new WPInv_Subscription($subscription_id);
210 210
 
211 211
         // Abort if it is missing or completed.
212
-        if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) {
212
+        if (!$subscription->get_id() || $subscription->has_status('completed')) {
213 213
             return;
214 214
         }
215 215
 
216 216
         // Payment status.
217
-        if ( 1 == $data['x_response_code'] ) {
217
+        if (1 == $data['x_response_code']) {
218 218
 
219 219
             // Renew the subscription.
220 220
             $subscription->add_payment(
221 221
                 array(
222
-                    'transaction_id' => sanitize_text_field( $data['x_trans_id'] ),
222
+                    'transaction_id' => sanitize_text_field($data['x_trans_id']),
223 223
                     'gateway'        => $this->id,
224 224
                 )
225 225
             );
@@ -238,17 +238,17 @@  discard block
 block discarded – undo
238 238
      *
239 239
      * @param array $posted
240 240
 	 */
241
-	public function validate_old_ipn_signature( $posted ) {
241
+	public function validate_old_ipn_signature($posted) {
242 242
 
243
-        $signature = $this->get_option( 'signature_key' );
244
-        if ( ! empty( $signature ) ) {
245
-            $login_id  = $this->get_option( 'login_id' );
246
-            $trans_id  = wpinv_clean( $_POST['x_trans_id'] );
247
-            $amount    = wpinv_clean( $_POST['x_amount'] );
248
-            $hash      = hash_hmac( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) );
243
+        $signature = $this->get_option('signature_key');
244
+        if (!empty($signature)) {
245
+            $login_id  = $this->get_option('login_id');
246
+            $trans_id  = wpinv_clean($_POST['x_trans_id']);
247
+            $amount    = wpinv_clean($_POST['x_amount']);
248
+            $hash      = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature));
249 249
 
250
-            if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) {
251
-                wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" );
250
+            if (!hash_equals($hash, $posted['x_SHA2_Hash'])) {
251
+                wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash");
252 252
                 exit;
253 253
             }
254 254
 }
@@ -260,28 +260,28 @@  discard block
 block discarded – undo
260 260
 	 */
261 261
 	public function validate_ipn() {
262 262
 
263
-        wpinv_error_log( 'Validating Authorize.NET IPN response' );
263
+        wpinv_error_log('Validating Authorize.NET IPN response');
264 264
 
265
-        if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
265
+        if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) {
266 266
             return false;
267 267
         }
268 268
 
269
-        $signature = $this->get_option( 'signature_key' );
269
+        $signature = $this->get_option('signature_key');
270 270
 
271
-        if ( empty( $signature ) ) {
272
-            wpinv_error_log( 'Error: You have not set a signature key' );
271
+        if (empty($signature)) {
272
+            wpinv_error_log('Error: You have not set a signature key');
273 273
             return false;
274 274
         }
275 275
 
276
-        $hash  = hash_hmac( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) );
276
+        $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature));
277 277
 
278
-        if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
279
-            wpinv_error_log( 'Successfully validated the IPN' );
278
+        if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) {
279
+            wpinv_error_log('Successfully validated the IPN');
280 280
             return true;
281 281
         }
282 282
 
283
-        wpinv_error_log( 'IPN hash is not valid' );
284
-        wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] );
283
+        wpinv_error_log('IPN hash is not valid');
284
+        wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']);
285 285
         return false;
286 286
 
287 287
     }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway-ipn-handler.php 2 patches
Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -12,473 +12,473 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Paypal_Gateway_IPN_Handler {
14 14
 
15
-	/**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	protected $id = 'paypal';
21
-
22
-	/**
23
-	 * Payment method object.
24
-	 *
25
-	 * @var GetPaid_Paypal_Gateway
26
-	 */
27
-	protected $gateway;
28
-
29
-	/**
30
-	 * Class constructor.
31
-	 *
32
-	 * @param GetPaid_Paypal_Gateway $gateway
33
-	 */
34
-	public function __construct( $gateway ) {
35
-		$this->gateway = $gateway;
36
-		$this->verify_ipn();
37
-	}
38
-
39
-	/**
40
-	 * Processes ipns and marks payments as complete.
41
-	 *
42
-	 * @return void
43
-	 */
44
-	public function verify_ipn() {
45
-
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
-
48
-		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
51
-		}
52
-
53
-		// Process the IPN.
54
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
-		$invoice = $this->get_ipn_invoice( $posted );
56
-
57
-		// Abort if it was not paid by our gateway.
58
-		if ( $this->id != $invoice->get_gateway() ) {
59
-			wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
61
-		}
62
-
63
-		$posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
-		$posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
-
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
-
69
-		if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
-			call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
-			wpinv_error_log( 'Done processing IPN', false );
72
-			wp_die( 'Processed', 200 );
73
-		}
74
-
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
77
-
78
-	}
79
-
80
-	/**
81
-	 * Retrieves IPN Invoice.
82
-	 *
83
-	 * @param array $posted
84
-	 * @return WPInv_Invoice
85
-	 */
86
-	protected function get_ipn_invoice( $posted ) {
87
-
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
-
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
92
-
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
-				return $invoice;
96
-			}
15
+    /**
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20
+    protected $id = 'paypal';
21
+
22
+    /**
23
+     * Payment method object.
24
+     *
25
+     * @var GetPaid_Paypal_Gateway
26
+     */
27
+    protected $gateway;
28
+
29
+    /**
30
+     * Class constructor.
31
+     *
32
+     * @param GetPaid_Paypal_Gateway $gateway
33
+     */
34
+    public function __construct( $gateway ) {
35
+        $this->gateway = $gateway;
36
+        $this->verify_ipn();
37
+    }
38
+
39
+    /**
40
+     * Processes ipns and marks payments as complete.
41
+     *
42
+     * @return void
43
+     */
44
+    public function verify_ipn() {
45
+
46
+        wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
+
48
+        // Validate the IPN.
49
+        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
+            wp_die( 'PayPal IPN Request Failure', 500 );
51
+        }
52
+
53
+        // Process the IPN.
54
+        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
+        $invoice = $this->get_ipn_invoice( $posted );
56
+
57
+        // Abort if it was not paid by our gateway.
58
+        if ( $this->id != $invoice->get_gateway() ) {
59
+            wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
+            wp_die( 'Invoice not paid via PayPal', 200 );
61
+        }
62
+
63
+        $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
+        $posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
+
66
+        wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
+        wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
+
69
+        if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
+            call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
+            wpinv_error_log( 'Done processing IPN', false );
72
+            wp_die( 'Processed', 200 );
73
+        }
74
+
75
+        wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
+        wp_die( 'Unsupported IPN type', 200 );
77
+
78
+    }
79
+
80
+    /**
81
+     * Retrieves IPN Invoice.
82
+     *
83
+     * @param array $posted
84
+     * @return WPInv_Invoice
85
+     */
86
+    protected function get_ipn_invoice( $posted ) {
87
+
88
+        wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
+
90
+        if ( ! empty( $posted['custom'] ) ) {
91
+            $invoice = new WPInv_Invoice( $posted['custom'] );
92
+
93
+            if ( $invoice->exists() ) {
94
+                wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
+                return $invoice;
96
+            }
97 97
 }
98 98
 
99
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
100
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
101
-	}
102
-
103
-	/**
104
-	 * Check PayPal IPN validity.
105
-	 */
106
-	protected function validate_ipn() {
99
+        wpinv_error_log( 'Could not retrieve the associated invoice.', false );
100
+        wp_die( 'Could not retrieve the associated invoice.', 200 );
101
+    }
102
+
103
+    /**
104
+     * Check PayPal IPN validity.
105
+     */
106
+    protected function validate_ipn() {
107 107
 
108
-		wpinv_error_log( 'Validating PayPal IPN response', false );
109
-
110
-		// Retrieve the associated invoice.
111
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
112
-		$invoice = $this->get_ipn_invoice( $posted );
113
-
114
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
115
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
116
-		}
117
-
118
-		// Validate the IPN.
119
-		$posted['cmd'] = '_notify-validate';
120
-
121
-		// Send back post vars to paypal.
122
-		$params = array(
123
-			'body'        => $posted,
124
-			'timeout'     => 60,
125
-			'httpversion' => '1.1',
126
-			'compress'    => false,
127
-			'decompress'  => false,
128
-			'user-agent'  => 'GetPaid/' . WPINV_VERSION,
129
-		);
130
-
131
-		// Post back to get a response.
132
-		$response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
133
-
134
-		// Check to see if the request was valid.
135
-		if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
136
-			wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
137
-			return true;
138
-		}
108
+        wpinv_error_log( 'Validating PayPal IPN response', false );
109
+
110
+        // Retrieve the associated invoice.
111
+        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
112
+        $invoice = $this->get_ipn_invoice( $posted );
113
+
114
+        if ( $this->gateway->is_sandbox( $invoice ) ) {
115
+            wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
116
+        }
117
+
118
+        // Validate the IPN.
119
+        $posted['cmd'] = '_notify-validate';
120
+
121
+        // Send back post vars to paypal.
122
+        $params = array(
123
+            'body'        => $posted,
124
+            'timeout'     => 60,
125
+            'httpversion' => '1.1',
126
+            'compress'    => false,
127
+            'decompress'  => false,
128
+            'user-agent'  => 'GetPaid/' . WPINV_VERSION,
129
+        );
130
+
131
+        // Post back to get a response.
132
+        $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
133
+
134
+        // Check to see if the request was valid.
135
+        if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
136
+            wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
137
+            return true;
138
+        }
139 139
 
140
-		if ( is_wp_error( $response ) ) {
141
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
142
-			return false;
143
-		}
140
+        if ( is_wp_error( $response ) ) {
141
+            wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
142
+            return false;
143
+        }
144 144
 
145
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
146
-		return false;
145
+        wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
146
+        return false;
147 147
 
148
-	}
148
+    }
149 149
 
150
-	/**
151
-	 * Check currency from IPN matches the invoice.
152
-	 *
153
-	 * @param WPInv_Invoice $invoice          Invoice object.
154
-	 * @param string   $currency currency to validate.
155
-	 */
156
-	protected function validate_ipn_currency( $invoice, $currency ) {
150
+    /**
151
+     * Check currency from IPN matches the invoice.
152
+     *
153
+     * @param WPInv_Invoice $invoice          Invoice object.
154
+     * @param string   $currency currency to validate.
155
+     */
156
+    protected function validate_ipn_currency( $invoice, $currency ) {
157 157
 
158
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
158
+        if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
159 159
 
160
-			/* translators: %s: currency code. */
161
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
160
+            /* translators: %s: currency code. */
161
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
162 162
 
163
-			wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
164
-		}
163
+            wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
164
+        }
165 165
 
166
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
167
-	}
166
+        wpinv_error_log( $currency, 'Validated IPN Currency', false );
167
+    }
168 168
 
169
-	/**
170
-	 * Check payment amount from IPN matches the invoice.
171
-	 *
172
-	 * @param WPInv_Invoice $invoice          Invoice object.
173
-	 * @param float   $amount amount to validate.
174
-	 */
175
-	protected function validate_ipn_amount( $invoice, $amount ) {
176
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
169
+    /**
170
+     * Check payment amount from IPN matches the invoice.
171
+     *
172
+     * @param WPInv_Invoice $invoice          Invoice object.
173
+     * @param float   $amount amount to validate.
174
+     */
175
+    protected function validate_ipn_amount( $invoice, $amount ) {
176
+        if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
177 177
 
178
-			/* translators: %s: Amount. */
179
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
178
+            /* translators: %s: Amount. */
179
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
180 180
 
181
-			wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
182
-		}
181
+            wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
182
+        }
183 183
 
184
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
185
-	}
184
+        wpinv_error_log( $amount, 'Validated IPN Amount', false );
185
+    }
186 186
 
187
-	/**
188
-	 * Verify receiver email from PayPal.
189
-	 *
190
-	 * @param WPInv_Invoice $invoice          Invoice object.
191
-	 * @param string   $receiver_email Email to validate.
192
-	 */
193
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
194
-		$paypal_email = wpinv_get_option( 'paypal_email' );
187
+    /**
188
+     * Verify receiver email from PayPal.
189
+     *
190
+     * @param WPInv_Invoice $invoice          Invoice object.
191
+     * @param string   $receiver_email Email to validate.
192
+     */
193
+    protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
194
+        $paypal_email = wpinv_get_option( 'paypal_email' );
195 195
 
196
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
197
-			wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
196
+        if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
197
+            wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
198 198
 
199
-			/* translators: %s: email address . */
200
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
199
+            /* translators: %s: email address . */
200
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
201 201
 
202
-			return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
203
-		}
202
+            return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
203
+        }
204 204
 
205
-		wpinv_error_log( 'Validated PayPal Email', false );
206
-	}
205
+        wpinv_error_log( 'Validated PayPal Email', false );
206
+    }
207 207
 
208
-	/**
209
-	 * Handles one time payments.
210
-	 *
211
-	 * @param WPInv_Invoice $invoice  Invoice object.
212
-	 * @param array    $posted Posted data.
213
-	 */
214
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
208
+    /**
209
+     * Handles one time payments.
210
+     *
211
+     * @param WPInv_Invoice $invoice  Invoice object.
212
+     * @param array    $posted Posted data.
213
+     */
214
+    protected function ipn_txn_web_accept( $invoice, $posted ) {
215 215
 
216
-		// Collect payment details
217
-		$payment_status = strtolower( $posted['payment_status'] );
218
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
216
+        // Collect payment details
217
+        $payment_status = strtolower( $posted['payment_status'] );
218
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
219 219
 
220
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
221
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
220
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
221
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
222 222
 
223
-		// Update the transaction id.
224
-		if ( ! empty( $posted['txn_id'] ) ) {
225
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
226
-			$invoice->save();
227
-		}
223
+        // Update the transaction id.
224
+        if ( ! empty( $posted['txn_id'] ) ) {
225
+            $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
226
+            $invoice->save();
227
+        }
228 228
 
229
-		$invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
229
+        $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
230 230
 
231
-		// Process a refund.
232
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
231
+        // Process a refund.
232
+        if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
233 233
 
234
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
234
+            update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
235 235
 
236
-			if ( ! $invoice->is_refunded() ) {
237
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
238
-			}
236
+            if ( ! $invoice->is_refunded() ) {
237
+                $invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
238
+            }
239 239
 
240
-			return wpinv_error_log( $posted['reason_code'], false );
241
-		}
240
+            return wpinv_error_log( $posted['reason_code'], false );
241
+        }
242 242
 
243
-		// Process payments.
244
-		if ( $payment_status == 'completed' ) {
243
+        // Process payments.
244
+        if ( $payment_status == 'completed' ) {
245 245
 
246
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
247
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
248
-			}
246
+            if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
247
+                return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
248
+            }
249 249
 
250
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
250
+            $this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
251 251
 
252
-			$note = '';
252
+            $note = '';
253 253
 
254
-			if ( ! empty( $posted['mc_fee'] ) ) {
255
-				$note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
256
-			}
254
+            if ( ! empty( $posted['mc_fee'] ) ) {
255
+                $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
256
+            }
257 257
 
258
-			if ( ! empty( $posted['payer_status'] ) ) {
259
-				$note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
260
-			}
258
+            if ( ! empty( $posted['payer_status'] ) ) {
259
+                $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
260
+            }
261 261
 
262
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
263
-			return wpinv_error_log( 'Invoice marked as paid.', false );
262
+            $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
263
+            return wpinv_error_log( 'Invoice marked as paid.', false );
264 264
 
265
-		}
265
+        }
266 266
 
267
-		// Pending payments.
268
-		if ( $payment_status == 'pending' ) {
267
+        // Pending payments.
268
+        if ( $payment_status == 'pending' ) {
269 269
 
270
-			/* translators: %s: pending reason. */
271
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
270
+            /* translators: %s: pending reason. */
271
+            $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
272 272
 
273
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
274
-		}
273
+            return wpinv_error_log( 'Invoice marked as "payment held".', false );
274
+        }
275 275
 
276
-		/* translators: %s: payment status. */
277
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
276
+        /* translators: %s: payment status. */
277
+        $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
278 278
 
279
-	}
279
+    }
280 280
 
281
-	/**
282
-	 * Handles one time payments.
283
-	 *
284
-	 * @param WPInv_Invoice $invoice  Invoice object.
285
-	 * @param array    $posted Posted data.
286
-	 */
287
-	protected function ipn_txn_cart( $invoice, $posted ) {
288
-		$this->ipn_txn_web_accept( $invoice, $posted );
289
-	}
281
+    /**
282
+     * Handles one time payments.
283
+     *
284
+     * @param WPInv_Invoice $invoice  Invoice object.
285
+     * @param array    $posted Posted data.
286
+     */
287
+    protected function ipn_txn_cart( $invoice, $posted ) {
288
+        $this->ipn_txn_web_accept( $invoice, $posted );
289
+    }
290 290
 
291
-	/**
292
-	 * Handles subscription sign ups.
293
-	 *
294
-	 * @param WPInv_Invoice $invoice  Invoice object.
295
-	 * @param array    $posted Posted data.
296
-	 */
297
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
291
+    /**
292
+     * Handles subscription sign ups.
293
+     *
294
+     * @param WPInv_Invoice $invoice  Invoice object.
295
+     * @param array    $posted Posted data.
296
+     */
297
+    protected function ipn_txn_subscr_signup( $invoice, $posted ) {
298 298
 
299
-		wpinv_error_log( 'Processing subscription signup', false );
299
+        wpinv_error_log( 'Processing subscription signup', false );
300 300
 
301
-		// Make sure the invoice has a subscription.
302
-		$subscription = getpaid_get_invoice_subscription( $invoice );
301
+        // Make sure the invoice has a subscription.
302
+        $subscription = getpaid_get_invoice_subscription( $invoice );
303 303
 
304
-		if ( empty( $subscription ) ) {
305
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
306
-		}
304
+        if ( empty( $subscription ) ) {
305
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
306
+        }
307 307
 
308
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
308
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
309 309
 
310
-		// Validate the IPN.
311
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
312
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
313
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
310
+        // Validate the IPN.
311
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
312
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
313
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
314 314
 
315
-		// Activate the subscription.
316
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
317
-		$subscription->set_date_created( current_time( 'mysql' ) );
318
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
319
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
320
-		$subscription->activate();
315
+        // Activate the subscription.
316
+        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
317
+        $subscription->set_date_created( current_time( 'mysql' ) );
318
+        $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
319
+        $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
320
+        $subscription->activate();
321 321
 
322
-		// Set the transaction id.
323
-		if ( ! empty( $posted['txn_id'] ) ) {
324
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true );
325
-			$invoice->set_transaction_id( $posted['txn_id'] );
326
-		}
322
+        // Set the transaction id.
323
+        if ( ! empty( $posted['txn_id'] ) ) {
324
+            $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true );
325
+            $invoice->set_transaction_id( $posted['txn_id'] );
326
+        }
327 327
 
328
-		// Update the payment status.
329
-		$invoice->mark_paid();
328
+        // Update the payment status.
329
+        $invoice->mark_paid();
330 330
 
331
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true );
331
+        $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true );
332 332
 
333
-		wpinv_error_log( 'Subscription started.', false );
334
-	}
333
+        wpinv_error_log( 'Subscription started.', false );
334
+    }
335 335
 
336
-	/**
337
-	 * Handles subscription renewals.
338
-	 *
339
-	 * @param WPInv_Invoice $invoice  Invoice object.
340
-	 * @param array    $posted Posted data.
341
-	 */
342
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
336
+    /**
337
+     * Handles subscription renewals.
338
+     *
339
+     * @param WPInv_Invoice $invoice  Invoice object.
340
+     * @param array    $posted Posted data.
341
+     */
342
+    protected function ipn_txn_subscr_payment( $invoice, $posted ) {
343 343
 
344
-		// Make sure the invoice has a subscription.
345
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
344
+        // Make sure the invoice has a subscription.
345
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
346 346
 
347
-		if ( empty( $subscription ) ) {
348
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
349
-		}
347
+        if ( empty( $subscription ) ) {
348
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
349
+        }
350 350
 
351
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
351
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
352 352
 
353
-		// PayPal sends a subscr_payment for the first payment too.
354
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
355
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
356
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
357
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
358
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
359
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
353
+        // PayPal sends a subscr_payment for the first payment too.
354
+        $date_completed = getpaid_format_date( $invoice->get_date_completed() );
355
+        $date_created   = getpaid_format_date( $invoice->get_date_created() );
356
+        $today_date     = getpaid_format_date( current_time( 'mysql' ) );
357
+        $payment_date   = getpaid_format_date( $posted['payment_date'] );
358
+        $subscribe_date = getpaid_format_date( $subscription->get_date_created() );
359
+        $dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
360 360
 
361
-		foreach ( $dates as $date ) {
361
+        foreach ( $dates as $date ) {
362 362
 
363
-			if ( $date !== $today_date && $date !== $payment_date ) {
364
-				continue;
365
-			}
363
+            if ( $date !== $today_date && $date !== $payment_date ) {
364
+                continue;
365
+            }
366 366
 
367
-			if ( ! empty( $posted['txn_id'] ) ) {
368
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );
369
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
370
-			}
367
+            if ( ! empty( $posted['txn_id'] ) ) {
368
+                $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );
369
+                $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
370
+            }
371 371
 
372
-			return $invoice->mark_paid();
373
-
374
-		}
372
+            return $invoice->mark_paid();
373
+
374
+        }
375 375
 
376
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
377
-
378
-		// Abort if the payment is already recorded.
379
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
380
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false );
381
-		}
382
-
383
-		$args = array(
384
-			'transaction_id' => $posted['txn_id'],
385
-			'gateway'        => $this->id,
386
-		);
387
-
388
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
376
+        wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
377
+
378
+        // Abort if the payment is already recorded.
379
+        if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
380
+            return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false );
381
+        }
382
+
383
+        $args = array(
384
+            'transaction_id' => $posted['txn_id'],
385
+            'gateway'        => $this->id,
386
+        );
387
+
388
+        $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
389 389
 
390
-		if ( empty( $invoice ) ) {
391
-			return;
392
-		}
390
+        if ( empty( $invoice ) ) {
391
+            return;
392
+        }
393 393
 
394
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true );
395
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true );
394
+        $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true );
395
+        $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true );
396 396
 
397
-		$subscription->renew();
398
-		wpinv_error_log( 'Subscription renewed.', false );
397
+        $subscription->renew();
398
+        wpinv_error_log( 'Subscription renewed.', false );
399 399
 
400
-	}
400
+    }
401 401
 
402
-	/**
403
-	 * Handles subscription cancelations.
404
-	 *
405
-	 * @param WPInv_Invoice $invoice  Invoice object.
406
-	 */
407
-	protected function ipn_txn_subscr_cancel( $invoice ) {
402
+    /**
403
+     * Handles subscription cancelations.
404
+     *
405
+     * @param WPInv_Invoice $invoice  Invoice object.
406
+     */
407
+    protected function ipn_txn_subscr_cancel( $invoice ) {
408 408
 
409
-		// Make sure the invoice has a subscription.
410
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
411
-
412
-		if ( empty( $subscription ) ) {
413
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
414
-		}
415
-
416
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
417
-		$subscription->cancel();
418
-		wpinv_error_log( 'Subscription cancelled.', false );
409
+        // Make sure the invoice has a subscription.
410
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
411
+
412
+        if ( empty( $subscription ) ) {
413
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
414
+        }
415
+
416
+        wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
417
+        $subscription->cancel();
418
+        wpinv_error_log( 'Subscription cancelled.', false );
419 419
 
420
-	}
420
+    }
421 421
 
422
-	/**
423
-	 * Handles subscription completions.
424
-	 *
425
-	 * @param WPInv_Invoice $invoice  Invoice object.
426
-	 * @param array    $posted Posted data.
427
-	 */
428
-	protected function ipn_txn_subscr_eot( $invoice ) {
422
+    /**
423
+     * Handles subscription completions.
424
+     *
425
+     * @param WPInv_Invoice $invoice  Invoice object.
426
+     * @param array    $posted Posted data.
427
+     */
428
+    protected function ipn_txn_subscr_eot( $invoice ) {
429 429
 
430
-		// Make sure the invoice has a subscription.
431
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
430
+        // Make sure the invoice has a subscription.
431
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
432 432
 
433
-		if ( empty( $subscription ) ) {
434
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
435
-		}
433
+        if ( empty( $subscription ) ) {
434
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
435
+        }
436 436
 
437
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
438
-		$subscription->complete();
439
-		wpinv_error_log( 'Subscription completed.', false );
437
+        wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
438
+        $subscription->complete();
439
+        wpinv_error_log( 'Subscription completed.', false );
440 440
 
441
-	}
441
+    }
442 442
 
443
-	/**
444
-	 * Handles subscription fails.
445
-	 *
446
-	 * @param WPInv_Invoice $invoice  Invoice object.
447
-	 * @param array    $posted Posted data.
448
-	 */
449
-	protected function ipn_txn_subscr_failed( $invoice ) {
443
+    /**
444
+     * Handles subscription fails.
445
+     *
446
+     * @param WPInv_Invoice $invoice  Invoice object.
447
+     * @param array    $posted Posted data.
448
+     */
449
+    protected function ipn_txn_subscr_failed( $invoice ) {
450 450
 
451
-		// Make sure the invoice has a subscription.
452
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
451
+        // Make sure the invoice has a subscription.
452
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
453 453
 
454
-		if ( empty( $subscription ) ) {
455
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
456
-		}
454
+        if ( empty( $subscription ) ) {
455
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
456
+        }
457 457
 
458
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
459
-		$subscription->failing();
460
-		wpinv_error_log( 'Subscription marked as failing.', false );
458
+        wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
459
+        $subscription->failing();
460
+        wpinv_error_log( 'Subscription marked as failing.', false );
461 461
 
462
-	}
462
+    }
463 463
 
464
-	/**
465
-	 * Handles subscription suspensions.
466
-	 *
467
-	 * @param WPInv_Invoice $invoice  Invoice object.
468
-	 * @param array    $posted Posted data.
469
-	 */
470
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
464
+    /**
465
+     * Handles subscription suspensions.
466
+     *
467
+     * @param WPInv_Invoice $invoice  Invoice object.
468
+     * @param array    $posted Posted data.
469
+     */
470
+    protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
471 471
 
472
-		// Make sure the invoice has a subscription.
473
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
472
+        // Make sure the invoice has a subscription.
473
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
474 474
 
475
-		if ( empty( $subscription ) ) {
476
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
477
-		}
478
-
479
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
480
-		$subscription->cancel();
481
-		wpinv_error_log( 'Subscription cancelled.', false );
482
-	}
475
+        if ( empty( $subscription ) ) {
476
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
477
+        }
478
+
479
+        wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
480
+        $subscription->cancel();
481
+        wpinv_error_log( 'Subscription cancelled.', false );
482
+    }
483 483
 
484 484
 }
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 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
  * Paypal Payment Gateway IPN handler class.
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @param GetPaid_Paypal_Gateway $gateway
33 33
 	 */
34
-	public function __construct( $gateway ) {
34
+	public function __construct($gateway) {
35 35
 		$this->gateway = $gateway;
36 36
 		$this->verify_ipn();
37 37
 	}
@@ -43,37 +43,37 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public function verify_ipn() {
45 45
 
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
46
+		wpinv_error_log('GetPaid PayPal IPN Handler', false);
47 47
 
48 48
 		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
49
+		if (empty($_POST) || !$this->validate_ipn()) {
50
+			wp_die('PayPal IPN Request Failure', 500);
51 51
 		}
52 52
 
53 53
 		// Process the IPN.
54
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
-		$invoice = $this->get_ipn_invoice( $posted );
54
+		$posted  = wp_kses_post_deep(wp_unslash($_POST));
55
+		$invoice = $this->get_ipn_invoice($posted);
56 56
 
57 57
 		// Abort if it was not paid by our gateway.
58
-		if ( $this->id != $invoice->get_gateway() ) {
59
-			wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
58
+		if ($this->id != $invoice->get_gateway()) {
59
+			wpinv_error_log('Aborting, Invoice was not paid via PayPal', false);
60
+			wp_die('Invoice not paid via PayPal', 200);
61 61
 		}
62 62
 
63
-		$posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
-		$posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
63
+		$posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : '';
64
+		$posted['txn_type']       = sanitize_key(strtolower($posted['txn_type']));
65 65
 
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
66
+		wpinv_error_log('Payment status:' . $posted['payment_status'], false);
67
+		wpinv_error_log('IPN Type:' . $posted['txn_type'], false);
68 68
 
69
-		if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
-			call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
-			wpinv_error_log( 'Done processing IPN', false );
72
-			wp_die( 'Processed', 200 );
69
+		if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) {
70
+			call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted);
71
+			wpinv_error_log('Done processing IPN', false);
72
+			wp_die('Processed', 200);
73 73
 		}
74 74
 
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
75
+		wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false);
76
+		wp_die('Unsupported IPN type', 200);
77 77
 
78 78
 	}
79 79
 
@@ -83,21 +83,21 @@  discard block
 block discarded – undo
83 83
 	 * @param array $posted
84 84
 	 * @return WPInv_Invoice
85 85
 	 */
86
-	protected function get_ipn_invoice( $posted ) {
86
+	protected function get_ipn_invoice($posted) {
87 87
 
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
88
+		wpinv_error_log('Retrieving PayPal IPN Response Invoice', false);
89 89
 
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
90
+		if (!empty($posted['custom'])) {
91
+			$invoice = new WPInv_Invoice($posted['custom']);
92 92
 
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
93
+			if ($invoice->exists()) {
94
+				wpinv_error_log('Found invoice #' . $invoice->get_number(), false);
95 95
 				return $invoice;
96 96
 			}
97 97
 }
98 98
 
99
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
100
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
99
+		wpinv_error_log('Could not retrieve the associated invoice.', false);
100
+		wp_die('Could not retrieve the associated invoice.', 200);
101 101
 	}
102 102
 
103 103
 	/**
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	protected function validate_ipn() {
107 107
 
108
-		wpinv_error_log( 'Validating PayPal IPN response', false );
108
+		wpinv_error_log('Validating PayPal IPN response', false);
109 109
 
110 110
 		// Retrieve the associated invoice.
111
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
112
-		$invoice = $this->get_ipn_invoice( $posted );
111
+		$posted  = wp_kses_post_deep(wp_unslash($_POST));
112
+		$invoice = $this->get_ipn_invoice($posted);
113 113
 
114
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
115
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
114
+		if ($this->gateway->is_sandbox($invoice)) {
115
+			wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false);
116 116
 		}
117 117
 
118 118
 		// Validate the IPN.
@@ -129,20 +129,20 @@  discard block
 block discarded – undo
129 129
 		);
130 130
 
131 131
 		// Post back to get a response.
132
-		$response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
132
+		$response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params);
133 133
 
134 134
 		// Check to see if the request was valid.
135
-		if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
136
-			wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
135
+		if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) {
136
+			wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false);
137 137
 			return true;
138 138
 		}
139 139
 
140
-		if ( is_wp_error( $response ) ) {
141
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
140
+		if (is_wp_error($response)) {
141
+			wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN');
142 142
 			return false;
143 143
 		}
144 144
 
145
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
145
+		wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN');
146 146
 		return false;
147 147
 
148 148
 	}
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
 	 * @param WPInv_Invoice $invoice          Invoice object.
154 154
 	 * @param string   $currency currency to validate.
155 155
 	 */
156
-	protected function validate_ipn_currency( $invoice, $currency ) {
156
+	protected function validate_ipn_currency($invoice, $currency) {
157 157
 
158
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
158
+		if (strtolower($invoice->get_currency()) !== strtolower($currency)) {
159 159
 
160 160
 			/* translators: %s: currency code. */
161
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
161
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency));
162 162
 
163
-			wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
163
+			wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true);
164 164
 		}
165 165
 
166
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
166
+		wpinv_error_log($currency, 'Validated IPN Currency', false);
167 167
 	}
168 168
 
169 169
 	/**
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
 	 * @param WPInv_Invoice $invoice          Invoice object.
173 173
 	 * @param float   $amount amount to validate.
174 174
 	 */
175
-	protected function validate_ipn_amount( $invoice, $amount ) {
176
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
175
+	protected function validate_ipn_amount($invoice, $amount) {
176
+		if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) {
177 177
 
178 178
 			/* translators: %s: Amount. */
179
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
179
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount));
180 180
 
181
-			wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
181
+			wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true);
182 182
 		}
183 183
 
184
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
184
+		wpinv_error_log($amount, 'Validated IPN Amount', false);
185 185
 	}
186 186
 
187 187
 	/**
@@ -190,19 +190,19 @@  discard block
 block discarded – undo
190 190
 	 * @param WPInv_Invoice $invoice          Invoice object.
191 191
 	 * @param string   $receiver_email Email to validate.
192 192
 	 */
193
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
194
-		$paypal_email = wpinv_get_option( 'paypal_email' );
193
+	protected function validate_ipn_receiver_email($invoice, $receiver_email) {
194
+		$paypal_email = wpinv_get_option('paypal_email');
195 195
 
196
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
197
-			wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
196
+		if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) {
197
+			wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}");
198 198
 
199 199
 			/* translators: %s: email address . */
200
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
200
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email));
201 201
 
202
-			return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
202
+			return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true);
203 203
 		}
204 204
 
205
-		wpinv_error_log( 'Validated PayPal Email', false );
205
+		wpinv_error_log('Validated PayPal Email', false);
206 206
 	}
207 207
 
208 208
 	/**
@@ -211,70 +211,70 @@  discard block
 block discarded – undo
211 211
 	 * @param WPInv_Invoice $invoice  Invoice object.
212 212
 	 * @param array    $posted Posted data.
213 213
 	 */
214
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
214
+	protected function ipn_txn_web_accept($invoice, $posted) {
215 215
 
216 216
 		// Collect payment details
217
-		$payment_status = strtolower( $posted['payment_status'] );
218
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
217
+		$payment_status = strtolower($posted['payment_status']);
218
+		$business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
219 219
 
220
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
221
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
220
+		$this->validate_ipn_receiver_email($invoice, $business_email);
221
+		$this->validate_ipn_currency($invoice, $posted['mc_currency']);
222 222
 
223 223
 		// Update the transaction id.
224
-		if ( ! empty( $posted['txn_id'] ) ) {
225
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
224
+		if (!empty($posted['txn_id'])) {
225
+			$invoice->set_transaction_id(wpinv_clean($posted['txn_id']));
226 226
 			$invoice->save();
227 227
 		}
228 228
 
229
-		$invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
229
+		$invoice->add_system_note(__('Processing invoice IPN', 'invoicing'));
230 230
 
231 231
 		// Process a refund.
232
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
232
+		if ($payment_status == 'refunded' || $payment_status == 'reversed') {
233 233
 
234
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
234
+			update_post_meta($invoice->get_id(), 'refunded_remotely', 1);
235 235
 
236
-			if ( ! $invoice->is_refunded() ) {
237
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
236
+			if (!$invoice->is_refunded()) {
237
+				$invoice->update_status('wpi-refunded', $posted['reason_code']);
238 238
 			}
239 239
 
240
-			return wpinv_error_log( $posted['reason_code'], false );
240
+			return wpinv_error_log($posted['reason_code'], false);
241 241
 		}
242 242
 
243 243
 		// Process payments.
244
-		if ( $payment_status == 'completed' ) {
244
+		if ($payment_status == 'completed') {
245 245
 
246
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
247
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
246
+			if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) {
247
+				return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false);
248 248
 			}
249 249
 
250
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
250
+			$this->validate_ipn_amount($invoice, $posted['mc_gross']);
251 251
 
252 252
 			$note = '';
253 253
 
254
-			if ( ! empty( $posted['mc_fee'] ) ) {
255
-				$note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
254
+			if (!empty($posted['mc_fee'])) {
255
+				$note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee']));
256 256
 			}
257 257
 
258
-			if ( ! empty( $posted['payer_status'] ) ) {
259
-				$note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
258
+			if (!empty($posted['payer_status'])) {
259
+				$note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status']));
260 260
 			}
261 261
 
262
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
263
-			return wpinv_error_log( 'Invoice marked as paid.', false );
262
+			$invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note));
263
+			return wpinv_error_log('Invoice marked as paid.', false);
264 264
 
265 265
 		}
266 266
 
267 267
 		// Pending payments.
268
-		if ( $payment_status == 'pending' ) {
268
+		if ($payment_status == 'pending') {
269 269
 
270 270
 			/* translators: %s: pending reason. */
271
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
271
+			$invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason']));
272 272
 
273
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
273
+			return wpinv_error_log('Invoice marked as "payment held".', false);
274 274
 		}
275 275
 
276 276
 		/* translators: %s: payment status. */
277
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
277
+		$invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status'])));
278 278
 
279 279
 	}
280 280
 
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param WPInv_Invoice $invoice  Invoice object.
285 285
 	 * @param array    $posted Posted data.
286 286
 	 */
287
-	protected function ipn_txn_cart( $invoice, $posted ) {
288
-		$this->ipn_txn_web_accept( $invoice, $posted );
287
+	protected function ipn_txn_cart($invoice, $posted) {
288
+		$this->ipn_txn_web_accept($invoice, $posted);
289 289
 	}
290 290
 
291 291
 	/**
@@ -294,43 +294,43 @@  discard block
 block discarded – undo
294 294
 	 * @param WPInv_Invoice $invoice  Invoice object.
295 295
 	 * @param array    $posted Posted data.
296 296
 	 */
297
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
297
+	protected function ipn_txn_subscr_signup($invoice, $posted) {
298 298
 
299
-		wpinv_error_log( 'Processing subscription signup', false );
299
+		wpinv_error_log('Processing subscription signup', false);
300 300
 
301 301
 		// Make sure the invoice has a subscription.
302
-		$subscription = getpaid_get_invoice_subscription( $invoice );
302
+		$subscription = getpaid_get_invoice_subscription($invoice);
303 303
 
304
-		if ( empty( $subscription ) ) {
305
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
304
+		if (empty($subscription)) {
305
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
306 306
 		}
307 307
 
308
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
308
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
309 309
 
310 310
 		// Validate the IPN.
311
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
312
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
313
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
311
+		$business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
312
+		$this->validate_ipn_receiver_email($invoice, $business_email);
313
+		$this->validate_ipn_currency($invoice, $posted['mc_currency']);
314 314
 
315 315
 		// Activate the subscription.
316
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
317
-		$subscription->set_date_created( current_time( 'mysql' ) );
318
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
319
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
316
+		$duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
317
+		$subscription->set_date_created(current_time('mysql'));
318
+		$subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration)));
319
+		$subscription->set_profile_id(sanitize_text_field($posted['subscr_id']));
320 320
 		$subscription->activate();
321 321
 
322 322
 		// Set the transaction id.
323
-		if ( ! empty( $posted['txn_id'] ) ) {
324
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true );
325
-			$invoice->set_transaction_id( $posted['txn_id'] );
323
+		if (!empty($posted['txn_id'])) {
324
+			$invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
325
+			$invoice->set_transaction_id($posted['txn_id']);
326 326
 		}
327 327
 
328 328
 		// Update the payment status.
329 329
 		$invoice->mark_paid();
330 330
 
331
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true );
331
+		$invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
332 332
 
333
-		wpinv_error_log( 'Subscription started.', false );
333
+		wpinv_error_log('Subscription started.', false);
334 334
 	}
335 335
 
336 336
 	/**
@@ -339,45 +339,45 @@  discard block
 block discarded – undo
339 339
 	 * @param WPInv_Invoice $invoice  Invoice object.
340 340
 	 * @param array    $posted Posted data.
341 341
 	 */
342
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
342
+	protected function ipn_txn_subscr_payment($invoice, $posted) {
343 343
 
344 344
 		// Make sure the invoice has a subscription.
345
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
345
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
346 346
 
347
-		if ( empty( $subscription ) ) {
348
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
347
+		if (empty($subscription)) {
348
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
349 349
 		}
350 350
 
351
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
351
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
352 352
 
353 353
 		// PayPal sends a subscr_payment for the first payment too.
354
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
355
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
356
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
357
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
358
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
359
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
354
+		$date_completed = getpaid_format_date($invoice->get_date_completed());
355
+		$date_created   = getpaid_format_date($invoice->get_date_created());
356
+		$today_date     = getpaid_format_date(current_time('mysql'));
357
+		$payment_date   = getpaid_format_date($posted['payment_date']);
358
+		$subscribe_date = getpaid_format_date($subscription->get_date_created());
359
+		$dates          = array_filter(compact('date_completed', 'date_created', 'subscribe_date'));
360 360
 
361
-		foreach ( $dates as $date ) {
361
+		foreach ($dates as $date) {
362 362
 
363
-			if ( $date !== $today_date && $date !== $payment_date ) {
363
+			if ($date !== $today_date && $date !== $payment_date) {
364 364
 				continue;
365 365
 			}
366 366
 
367
-			if ( ! empty( $posted['txn_id'] ) ) {
368
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );
369
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
367
+			if (!empty($posted['txn_id'])) {
368
+				$invoice->set_transaction_id(sanitize_text_field($posted['txn_id']));
369
+				$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true);
370 370
 			}
371 371
 
372 372
 			return $invoice->mark_paid();
373 373
 
374 374
 		}
375 375
 
376
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
376
+		wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false);
377 377
 
378 378
 		// Abort if the payment is already recorded.
379
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
380
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false );
379
+		if (wpinv_get_id_by_transaction_id($posted['txn_id'])) {
380
+			return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false);
381 381
 		}
382 382
 
383 383
 		$args = array(
@@ -385,17 +385,17 @@  discard block
 block discarded – undo
385 385
 			'gateway'        => $this->id,
386 386
 		);
387 387
 
388
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
388
+		$invoice = wpinv_get_invoice($subscription->add_payment($args));
389 389
 
390
-		if ( empty( $invoice ) ) {
390
+		if (empty($invoice)) {
391 391
 			return;
392 392
 		}
393 393
 
394
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true );
395
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true );
394
+		$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
395
+		$invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
396 396
 
397 397
 		$subscription->renew();
398
-		wpinv_error_log( 'Subscription renewed.', false );
398
+		wpinv_error_log('Subscription renewed.', false);
399 399
 
400 400
 	}
401 401
 
@@ -404,18 +404,18 @@  discard block
 block discarded – undo
404 404
 	 *
405 405
 	 * @param WPInv_Invoice $invoice  Invoice object.
406 406
 	 */
407
-	protected function ipn_txn_subscr_cancel( $invoice ) {
407
+	protected function ipn_txn_subscr_cancel($invoice) {
408 408
 
409 409
 		// Make sure the invoice has a subscription.
410
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
410
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
411 411
 
412
-		if ( empty( $subscription ) ) {
413
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
412
+		if (empty($subscription)) {
413
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
414 414
 		}
415 415
 
416
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
416
+		wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false);
417 417
 		$subscription->cancel();
418
-		wpinv_error_log( 'Subscription cancelled.', false );
418
+		wpinv_error_log('Subscription cancelled.', false);
419 419
 
420 420
 	}
421 421
 
@@ -425,18 +425,18 @@  discard block
 block discarded – undo
425 425
 	 * @param WPInv_Invoice $invoice  Invoice object.
426 426
 	 * @param array    $posted Posted data.
427 427
 	 */
428
-	protected function ipn_txn_subscr_eot( $invoice ) {
428
+	protected function ipn_txn_subscr_eot($invoice) {
429 429
 
430 430
 		// Make sure the invoice has a subscription.
431
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
431
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
432 432
 
433
-		if ( empty( $subscription ) ) {
434
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
433
+		if (empty($subscription)) {
434
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
435 435
 		}
436 436
 
437
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
437
+		wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false);
438 438
 		$subscription->complete();
439
-		wpinv_error_log( 'Subscription completed.', false );
439
+		wpinv_error_log('Subscription completed.', false);
440 440
 
441 441
 	}
442 442
 
@@ -446,18 +446,18 @@  discard block
 block discarded – undo
446 446
 	 * @param WPInv_Invoice $invoice  Invoice object.
447 447
 	 * @param array    $posted Posted data.
448 448
 	 */
449
-	protected function ipn_txn_subscr_failed( $invoice ) {
449
+	protected function ipn_txn_subscr_failed($invoice) {
450 450
 
451 451
 		// Make sure the invoice has a subscription.
452
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
452
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
453 453
 
454
-		if ( empty( $subscription ) ) {
455
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
454
+		if (empty($subscription)) {
455
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
456 456
 		}
457 457
 
458
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
458
+		wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false);
459 459
 		$subscription->failing();
460
-		wpinv_error_log( 'Subscription marked as failing.', false );
460
+		wpinv_error_log('Subscription marked as failing.', false);
461 461
 
462 462
 	}
463 463
 
@@ -467,18 +467,18 @@  discard block
 block discarded – undo
467 467
 	 * @param WPInv_Invoice $invoice  Invoice object.
468 468
 	 * @param array    $posted Posted data.
469 469
 	 */
470
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
470
+	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) {
471 471
 
472 472
 		// Make sure the invoice has a subscription.
473
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
473
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
474 474
 
475
-		if ( empty( $subscription ) ) {
476
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
475
+		if (empty($subscription)) {
476
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
477 477
 		}
478 478
 
479
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
479
+		wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false);
480 480
 		$subscription->cancel();
481
-		wpinv_error_log( 'Subscription cancelled.', false );
481
+		wpinv_error_log('Subscription cancelled.', false);
482 482
 	}
483 483
 
484 484
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 2 patches
Indentation   +232 added lines, -232 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', 'single_subscription_group', 'multiple_subscription_groups' );
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'] );
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
     }
183 183
 
184 184
     /**
185
-	 * Retrieves a customer profile.
186
-	 *
187
-	 *
188
-	 * @param string $profile_id profile id.
189
-	 * @return string|WP_Error Profile id.
185
+     * Retrieves a customer profile.
186
+     *
187
+     *
188
+     * @param string $profile_id profile id.
189
+     * @return string|WP_Error Profile id.
190 190
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
191
-	 */
192
-	public function get_customer_profile( $profile_id ) {
191
+     */
192
+    public function get_customer_profile( $profile_id ) {
193 193
 
194 194
         // Generate args.
195 195
         $args = array(
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
     }
205 205
 
206 206
     /**
207
-	 * Creates a customer profile.
208
-	 *
209
-	 *
207
+     * Creates a customer profile.
208
+     *
209
+     *
210 210
      * @param string $profile_id profile id.
211
-	 * @param WPInv_Invoice $invoice Invoice.
211
+     * @param WPInv_Invoice $invoice Invoice.
212 212
      * @param array $submission_data Posted checkout fields.
213 213
      * @param bool $save Whether or not to save the payment as a token.
214 214
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
215
-	 * @return string|WP_Error Profile id.
216
-	 */
217
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
215
+     * @return string|WP_Error Profile id.
216
+     */
217
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
218 218
 
219 219
         // Remove non-digits from the number
220 220
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
     }
303 303
 
304 304
     /**
305
-	 * Retrieves payment details from cache.
306
-	 *
307
-	 *
305
+     * Retrieves payment details from cache.
306
+     *
307
+     *
308 308
      * @param array $payment_details.
309
-	 * @return array|false Profile id.
310
-	 */
311
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
309
+     * @return array|false Profile id.
310
+     */
311
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
312 312
 
313 313
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
314 314
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -333,13 +333,13 @@  discard block
 block discarded – undo
333 333
     }
334 334
 
335 335
     /**
336
-	 * Securely adds payment details to cache.
337
-	 *
338
-	 *
336
+     * Securely adds payment details to cache.
337
+     *
338
+     *
339 339
      * @param array $payment_details.
340 340
      * @param string $payment_profile_id.
341
-	 */
342
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
341
+     */
342
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
343 343
 
344 344
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
345 345
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -351,15 +351,15 @@  discard block
 block discarded – undo
351 351
     }
352 352
 
353 353
     /**
354
-	 * Retrieves a customer payment profile.
355
-	 *
356
-	 *
357
-	 * @param string $customer_profile_id customer profile id.
354
+     * Retrieves a customer payment profile.
355
+     *
356
+     *
357
+     * @param string $customer_profile_id customer profile id.
358 358
      * @param string $payment_profile_id payment profile id.
359
-	 * @return string|WP_Error Profile id.
359
+     * @return string|WP_Error Profile id.
360 360
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
361
-	 */
362
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
361
+     */
362
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
363 363
 
364 364
         // Generate args.
365 365
         $args = array(
@@ -375,15 +375,15 @@  discard block
 block discarded – undo
375 375
     }
376 376
 
377 377
     /**
378
-	 * Charges a customer payment profile.
379
-	 *
378
+     * Charges a customer payment profile.
379
+     *
380 380
      * @param string $customer_profile_id customer profile id.
381 381
      * @param string $payment_profile_id payment profile id.
382
-	 * @param WPInv_Invoice $invoice Invoice.
382
+     * @param WPInv_Invoice $invoice Invoice.
383 383
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
384
-	 * @return WP_Error|object
385
-	 */
386
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
384
+     * @return WP_Error|object
385
+     */
386
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
387 387
 
388 388
         // Generate args.
389 389
         $args = array(
@@ -429,41 +429,41 @@  discard block
 block discarded – undo
429 429
     }
430 430
 
431 431
     /**
432
-	 * Processes a customer charge.
433
-	 *
432
+     * Processes a customer charge.
433
+     *
434 434
      * @param stdClass $result Api response.
435
-	 * @param WPInv_Invoice $invoice Invoice.
436
-	 */
437
-	public function process_charge_response( $result, $invoice ) {
435
+     * @param WPInv_Invoice $invoice Invoice.
436
+     */
437
+    public function process_charge_response( $result, $invoice ) {
438 438
 
439 439
         wpinv_clear_errors();
440
-		$response_code = (int) $result->transactionResponse->responseCode;
440
+        $response_code = (int) $result->transactionResponse->responseCode;
441 441
 
442
-		// Succeeded.
443
-		if ( 1 == $response_code || 4 == $response_code ) {
442
+        // Succeeded.
443
+        if ( 1 == $response_code || 4 == $response_code ) {
444 444
 
445
-			// Maybe set a transaction id.
446
-			if ( ! empty( $result->transactionResponse->transId ) ) {
447
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
448
-			}
445
+            // Maybe set a transaction id.
446
+            if ( ! empty( $result->transactionResponse->transId ) ) {
447
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
448
+            }
449 449
 
450
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
450
+            $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
451 451
 
452
-			if ( 1 == $response_code ) {
453
-				return $invoice->mark_paid();
454
-			}
452
+            if ( 1 == $response_code ) {
453
+                return $invoice->mark_paid();
454
+            }
455 455
 
456
-			$invoice->set_status( 'wpi-onhold' );
457
-        	$invoice->add_note(
456
+            $invoice->set_status( 'wpi-onhold' );
457
+            $invoice->add_note(
458 458
                 sprintf(
459 459
                     __( 'Held for review: %s', 'invoicing' ),
460 460
                     $result->transactionResponse->messages->message[0]->description
461 461
                 )
462
-			);
462
+            );
463 463
 
464
-			return $invoice->save();
464
+            return $invoice->save();
465 465
 
466
-		}
466
+        }
467 467
 
468 468
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
469 469
 
@@ -475,13 +475,13 @@  discard block
 block discarded – undo
475 475
     }
476 476
 
477 477
     /**
478
-	 * Returns payment information.
479
-	 *
480
-	 *
481
-	 * @param array $card Card details.
482
-	 * @return array
483
-	 */
484
-	public function get_payment_information( $card ) {
478
+     * Returns payment information.
479
+     *
480
+     *
481
+     * @param array $card Card details.
482
+     * @return array
483
+     */
484
+    public function get_payment_information( $card ) {
485 485
         return array(
486 486
 
487 487
             'creditCard' => array(
@@ -494,25 +494,25 @@  discard block
 block discarded – undo
494 494
     }
495 495
 
496 496
     /**
497
-	 * Returns the customer profile meta name.
498
-	 *
499
-	 *
500
-	 * @param WPInv_Invoice $invoice Invoice.
501
-	 * @return string
502
-	 */
503
-	public function get_customer_profile_meta_name( $invoice ) {
497
+     * Returns the customer profile meta name.
498
+     *
499
+     *
500
+     * @param WPInv_Invoice $invoice Invoice.
501
+     * @return string
502
+     */
503
+    public function get_customer_profile_meta_name( $invoice ) {
504 504
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
505 505
     }
506 506
 
507 507
     /**
508
-	 * Validates the submitted data.
509
-	 *
510
-	 *
511
-	 * @param array $submission_data Posted checkout fields.
508
+     * Validates the submitted data.
509
+     *
510
+     *
511
+     * @param array $submission_data Posted checkout fields.
512 512
      * @param WPInv_Invoice $invoice
513
-	 * @return WP_Error|string The payment profile id
514
-	 */
515
-	public function validate_submission_data( $submission_data, $invoice ) {
513
+     * @return WP_Error|string The payment profile id
514
+     */
515
+    public function validate_submission_data( $submission_data, $invoice ) {
516 516
 
517 517
         // Validate authentication details.
518 518
         $auth = $this->get_auth_params();
@@ -544,13 +544,13 @@  discard block
 block discarded – undo
544 544
     }
545 545
 
546 546
     /**
547
-	 * Returns invoice line items.
548
-	 *
549
-	 *
550
-	 * @param WPInv_Invoice $invoice Invoice.
551
-	 * @return array
552
-	 */
553
-	public function get_line_items( $invoice ) {
547
+     * Returns invoice line items.
548
+     *
549
+     *
550
+     * @param WPInv_Invoice $invoice Invoice.
551
+     * @return array
552
+     */
553
+    public function get_line_items( $invoice ) {
554 554
         $items = array();
555 555
 
556 556
         foreach ( $invoice->get_items() as $item ) {
@@ -587,15 +587,15 @@  discard block
 block discarded – undo
587 587
     }
588 588
 
589 589
     /**
590
-	 * Process Payment.
591
-	 *
592
-	 *
593
-	 * @param WPInv_Invoice $invoice Invoice.
594
-	 * @param array $submission_data Posted checkout fields.
595
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
596
-	 * @return array
597
-	 */
598
-	public function process_payment( $invoice, $submission_data, $submission ) {
590
+     * Process Payment.
591
+     *
592
+     *
593
+     * @param WPInv_Invoice $invoice Invoice.
594
+     * @param array $submission_data Posted checkout fields.
595
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
596
+     * @return array
597
+     */
598
+    public function process_payment( $invoice, $submission_data, $submission ) {
599 599
 
600 600
         // Validate the submitted data.
601 601
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -628,45 +628,45 @@  discard block
 block discarded – undo
628 628
 
629 629
         exit;
630 630
 
631
-	}
631
+    }
632 632
 
633
-	/**
634
-	 * Processes the initial payment.
635
-	 *
633
+    /**
634
+     * Processes the initial payment.
635
+     *
636 636
      * @param WPInv_Invoice $invoice Invoice.
637
-	 */
638
-	protected function process_initial_payment( $invoice ) {
637
+     */
638
+    protected function process_initial_payment( $invoice ) {
639 639
 
640
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
641 641
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
642
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
642
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
643 643
 
644
-		// Do we have an error?
645
-		if ( is_wp_error( $result ) ) {
646
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
647
-			wpinv_send_back_to_checkout( $invoice );
648
-		}
644
+        // Do we have an error?
645
+        if ( is_wp_error( $result ) ) {
646
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
647
+            wpinv_send_back_to_checkout( $invoice );
648
+        }
649 649
 
650
-		// Process the response.
651
-		$this->process_charge_response( $result, $invoice );
650
+        // Process the response.
651
+        $this->process_charge_response( $result, $invoice );
652 652
 
653
-		if ( wpinv_get_errors() ) {
654
-			wpinv_send_back_to_checkout( $invoice );
655
-		}
653
+        if ( wpinv_get_errors() ) {
654
+            wpinv_send_back_to_checkout( $invoice );
655
+        }
656 656
 
657
-	}
657
+    }
658 658
 
659 659
     /**
660
-	 * Processes recurring payments.
661
-	 *
660
+     * Processes recurring payments.
661
+     *
662 662
      * @param WPInv_Invoice $invoice Invoice.
663 663
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
664
-	 */
665
-	public function process_subscription( $invoice, $subscriptions ) {
664
+     */
665
+    public function process_subscription( $invoice, $subscriptions ) {
666 666
 
667 667
         // Check if there is an initial amount to charge.
668 668
         if ( (float) $invoice->get_total() > 0 ) {
669
-			$this->process_initial_payment( $invoice );
669
+            $this->process_initial_payment( $invoice );
670 670
         }
671 671
 
672 672
         // Activate the subscriptions.
@@ -684,36 +684,36 @@  discard block
 block discarded – undo
684 684
             }
685 685
         }
686 686
 
687
-		// Redirect to the success page.
687
+        // Redirect to the success page.
688 688
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
689 689
 
690 690
     }
691 691
 
692
-	/**
693
-	 * (Maybe) renews an authorize.net subscription profile.
694
-	 *
695
-	 *
692
+    /**
693
+     * (Maybe) renews an authorize.net subscription profile.
694
+     *
695
+     *
696 696
      * @param WPInv_Subscription $subscription
697
-	 */
698
-	public function maybe_renew_subscription( $subscription ) {
697
+     */
698
+    public function maybe_renew_subscription( $subscription ) {
699 699
 
700 700
         // Ensure its our subscription && it's active.
701 701
         if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
702 702
             $this->renew_subscription( $subscription );
703 703
         }
704 704
 
705
-	}
705
+    }
706 706
 
707 707
     /**
708
-	 * Renews a subscription.
709
-	 *
708
+     * Renews a subscription.
709
+     *
710 710
      * @param WPInv_Subscription $subscription
711
-	 */
712
-	public function renew_subscription( $subscription ) {
711
+     */
712
+    public function renew_subscription( $subscription ) {
713 713
 
714
-		// Generate the renewal invoice.
715
-		$new_invoice = $subscription->create_payment();
716
-		$old_invoice = $subscription->get_parent_payment();
714
+        // Generate the renewal invoice.
715
+        $new_invoice = $subscription->create_payment();
716
+        $old_invoice = $subscription->get_parent_payment();
717 717
 
718 718
         if ( empty( $new_invoice ) ) {
719 719
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -722,37 +722,37 @@  discard block
 block discarded – undo
722 722
         }
723 723
 
724 724
         // Charge the payment method.
725
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
726
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
727
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
728
-
729
-		// Do we have an error?
730
-		if ( is_wp_error( $result ) ) {
731
-
732
-			$old_invoice->add_note(
733
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
734
-				true,
735
-				false,
736
-				true
737
-			);
738
-			$subscription->failing();
739
-			return;
740
-
741
-		}
742
-
743
-		// Process the response.
744
-		$this->process_charge_response( $result, $new_invoice );
745
-
746
-		if ( wpinv_get_errors() ) {
747
-
748
-			$old_invoice->add_note(
749
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
750
-				true,
751
-				false,
752
-				true
753
-			);
754
-			$subscription->failing();
755
-			return;
725
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
726
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
727
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
728
+
729
+        // Do we have an error?
730
+        if ( is_wp_error( $result ) ) {
731
+
732
+            $old_invoice->add_note(
733
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
734
+                true,
735
+                false,
736
+                true
737
+            );
738
+            $subscription->failing();
739
+            return;
740
+
741
+        }
742
+
743
+        // Process the response.
744
+        $this->process_charge_response( $result, $new_invoice );
745
+
746
+        if ( wpinv_get_errors() ) {
747
+
748
+            $old_invoice->add_note(
749
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
750
+                true,
751
+                false,
752
+                true
753
+            );
754
+            $subscription->failing();
755
+            return;
756 756
 
757 757
         }
758 758
 
@@ -761,13 +761,13 @@  discard block
 block discarded – undo
761 761
     }
762 762
 
763 763
     /**
764
-	 * Processes invoice addons.
765
-	 *
766
-	 * @param WPInv_Invoice $invoice
767
-	 * @param GetPaid_Form_Item[] $items
768
-	 * @return WPInv_Invoice
769
-	 */
770
-	public function process_addons( $invoice, $items ) {
764
+     * Processes invoice addons.
765
+     *
766
+     * @param WPInv_Invoice $invoice
767
+     * @param GetPaid_Form_Item[] $items
768
+     * @return WPInv_Invoice
769
+     */
770
+    public function process_addons( $invoice, $items ) {
771 771
 
772 772
         global $getpaid_authorize_addons;
773 773
 
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
         $invoice->recalculate_total();
787 787
 
788 788
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
789
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
789
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
790 790
 
791 791
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
792 792
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -801,11 +801,11 @@  discard block
 block discarded – undo
801 801
     }
802 802
 
803 803
     /**
804
-	 * Processes invoice addons.
805
-	 *
804
+     * Processes invoice addons.
805
+     *
806 806
      * @param array $args
807
-	 * @return array
808
-	 */
807
+     * @return array
808
+     */
809 809
     public function filter_addons_request( $args ) {
810 810
 
811 811
         global $getpaid_authorize_addons;
@@ -839,11 +839,11 @@  discard block
 block discarded – undo
839 839
     }
840 840
 
841 841
     /**
842
-	 * Filters the gateway settings.
843
-	 *
844
-	 * @param array $admin_settings
845
-	 */
846
-	public function admin_settings( $admin_settings ) {
842
+     * Filters the gateway settings.
843
+     *
844
+     * @param array $admin_settings
845
+     */
846
+    public function admin_settings( $admin_settings ) {
847 847
 
848 848
         $currencies = sprintf(
849 849
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
             'readonly' => true,
884 884
         );
885 885
 
886
-		return $admin_settings;
887
-	}
886
+        return $admin_settings;
887
+    }
888 888
 
889 889
 }
Please login to merge, or discard this patch.
Spacing   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = getpaid_get_non_query_string_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = getpaid_get_non_query_string_ipn_url($this->id);
72 72
 
73
-        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'));
74
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,79 +100,79 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication' => $this->get_auth_params(),
112 112
                 'profile'                => array(
113
-                    'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'        => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'              => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'        => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'              => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'    => array(
117 117
                         'customerType' => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'       => array(
121
-                            'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
124
-                            'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'   => getpaid_limit_length($invoice->get_address(), 60),
124
+                            'city'      => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'     => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'   => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'      => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'      => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     ),
133 133
                 ),
134
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             ),
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
 
142 142
             // In case the payment profile already exists remotely.
143
-            if ( 'dup_payment_profile' == $response->get_error_code() ) {
144
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
145
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
146
-                return strtok( '.' );
143
+            if ('dup_payment_profile' == $response->get_error_code()) {
144
+                $customer_profile_id = strtok($response->get_error_message(), '.');
145
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
146
+                return strtok('.');
147 147
             }
148 148
 
149 149
             // In case the customer profile already exists remotely.
150
-            if ( 'E00039' == $response->get_error_code() ) {
151
-                $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() );
152
-                $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id );
153
-                return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save );
150
+            if ('E00039' == $response->get_error_code()) {
151
+                $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message());
152
+                $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id);
153
+                return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save);
154 154
             }
155 155
 
156 156
             return $response;
157 157
         }
158 158
 
159
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
159
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
160 160
 
161 161
         // Save the payment token.
162
-        if ( $save ) {
162
+        if ($save) {
163 163
             $this->save_token(
164 164
                 array(
165 165
                     'id'      => $response->customerPaymentProfileIdList[0],
166
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
166
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
167 167
                     'default' => true,
168
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
168
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
169 169
                 )
170 170
             );
171 171
         }
172 172
 
173 173
         // Add a note about the validation response.
174 174
         $invoice->add_note(
175
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
175
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
176 176
             false,
177 177
             false,
178 178
             true
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @return string|WP_Error Profile id.
190 190
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
191 191
 	 */
192
-	public function get_customer_profile( $profile_id ) {
192
+	public function get_customer_profile($profile_id) {
193 193
 
194 194
         // Generate args.
195 195
         $args = array(
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             ),
200 200
         );
201 201
 
202
-        return $this->post( $args, false );
202
+        return $this->post($args, false);
203 203
 
204 204
     }
205 205
 
@@ -214,18 +214,18 @@  discard block
 block discarded – undo
214 214
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
215 215
 	 * @return string|WP_Error Profile id.
216 216
 	 */
217
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
217
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
218 218
 
219 219
         // Remove non-digits from the number
220
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
220
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
221 221
 
222 222
         // Prepare card details.
223
-        $payment_information                          = $this->get_payment_information( $submission_data['authorizenet'] );
223
+        $payment_information                          = $this->get_payment_information($submission_data['authorizenet']);
224 224
 
225 225
         // Authorize.NET does not support saving the same card twice.
226
-        $cached_information                           = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice );
226
+        $cached_information                           = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice);
227 227
 
228
-        if ( $cached_information ) {
228
+        if ($cached_information) {
229 229
             return $cached_information;
230 230
         }
231 231
 
@@ -238,34 +238,34 @@  discard block
 block discarded – undo
238 238
 
239 239
                     // Billing information.
240 240
                     'billTo'  => array(
241
-                        'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
242
-                        'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
243
-                        'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
244
-                        'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
245
-                        'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
246
-                        'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
247
-                        'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
241
+                        'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
242
+                        'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
243
+                        'address'   => getpaid_limit_length($invoice->get_address(), 60),
244
+                        'city'      => getpaid_limit_length($invoice->get_city(), 40),
245
+                        'state'     => getpaid_limit_length($invoice->get_state(), 40),
246
+                        'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
247
+                        'country'   => getpaid_limit_length($invoice->get_country(), 60),
248 248
                     ),
249 249
 
250 250
                     // Payment information.
251 251
                     'payment' => $payment_information,
252 252
                 ),
253
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
253
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
254 254
             ),
255 255
         );
256 256
 
257
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
257
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
258 258
 
259
-        if ( is_wp_error( $response ) ) {
259
+        if (is_wp_error($response)) {
260 260
 
261 261
             // In case the payment profile already exists remotely.
262
-            if ( 'dup_payment_profile' == $response->get_error_code() ) {
263
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
264
-                $payment_profile_id  = strtok( '.' );
265
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
262
+            if ('dup_payment_profile' == $response->get_error_code()) {
263
+                $customer_profile_id = strtok($response->get_error_message(), '.');
264
+                $payment_profile_id  = strtok('.');
265
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
266 266
 
267 267
                 // Cache payment profile id.
268
-                $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id );
268
+                $this->add_payment_profile_to_cache($payment_information, $payment_profile_id);
269 269
 
270 270
                 return $payment_profile_id;
271 271
             }
@@ -274,29 +274,29 @@  discard block
 block discarded – undo
274 274
         }
275 275
 
276 276
         // Save the payment token.
277
-        if ( $save ) {
277
+        if ($save) {
278 278
             $this->save_token(
279 279
                 array(
280 280
                     'id'      => $response->customerPaymentProfileId,
281
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
281
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
282 282
                     'default' => true,
283
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
283
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
284 284
                 )
285 285
             );
286 286
         }
287 287
 
288 288
         // Cache payment profile id.
289
-        $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId );
289
+        $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId);
290 290
 
291 291
         // Add a note about the validation response.
292 292
         $invoice->add_note(
293
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
293
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
294 294
             false,
295 295
             false,
296 296
             true
297 297
         );
298 298
 
299
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile );
299
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile);
300 300
 
301 301
         return $response->customerPaymentProfileId;
302 302
     }
@@ -308,12 +308,12 @@  discard block
 block discarded – undo
308 308
      * @param array $payment_details.
309 309
 	 * @return array|false Profile id.
310 310
 	 */
311
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
311
+	public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) {
312 312
 
313
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
314
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
313
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
314
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
315 315
 
316
-        if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) {
316
+        if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) {
317 317
             return false;
318 318
         }
319 319
 
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
             'getCustomerPaymentProfileRequest' => array(
323 323
                 'merchantAuthentication'   => $this->get_auth_params(),
324 324
                 'customerProfileId'        => $customer_profile,
325
-                'customerPaymentProfileId' => $cached_information[ $payment_details ],
325
+                'customerPaymentProfileId' => $cached_information[$payment_details],
326 326
             ),
327 327
         );
328 328
 
329
-        $response = $this->post( $args, $invoice );
329
+        $response = $this->post($args, $invoice);
330 330
 
331
-        return is_wp_error( $response ) ? false : $cached_information[ $payment_details ];
331
+        return is_wp_error($response) ? false : $cached_information[$payment_details];
332 332
 
333 333
     }
334 334
 
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
      * @param array $payment_details.
340 340
      * @param string $payment_profile_id.
341 341
 	 */
342
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
342
+	public function add_payment_profile_to_cache($payment_details, $payment_profile_id) {
343 343
 
344
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
345
-        $cached_information = is_array( $cached_information ) ? $cached_information : array();
346
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
344
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
345
+        $cached_information = is_array($cached_information) ? $cached_information : array();
346
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
347 347
 
348
-        $cached_information[ $payment_details ] = $payment_profile_id;
349
-        update_option( 'getpaid_authorize_net_cached_profiles', $cached_information );
348
+        $cached_information[$payment_details] = $payment_profile_id;
349
+        update_option('getpaid_authorize_net_cached_profiles', $cached_information);
350 350
 
351 351
     }
352 352
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 * @return string|WP_Error Profile id.
360 360
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
361 361
 	 */
362
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
362
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
363 363
 
364 364
         // Generate args.
365 365
         $args = array(
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
             ),
371 371
         );
372 372
 
373
-        return $this->post( $args, false );
373
+        return $this->post($args, false);
374 374
 
375 375
     }
376 376
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
384 384
 	 * @return WP_Error|object
385 385
 	 */
386
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
386
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
387 387
 
388 388
         // Generate args.
389 389
         $args = array(
@@ -403,28 +403,28 @@  discard block
 block discarded – undo
403 403
                         ),
404 404
                     ),
405 405
                     'order'           => array(
406
-                        'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ),
406
+                        'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20),
407 407
                     ),
408
-                    'lineItems'       => array( 'lineItem' => $this->get_line_items( $invoice ) ),
408
+                    'lineItems'       => array('lineItem' => $this->get_line_items($invoice)),
409 409
                     'tax'             => array(
410 410
                         'amount' => $invoice->get_total_tax(),
411
-                        'name'   => __( 'TAX', 'invoicing' ),
411
+                        'name'   => __('TAX', 'invoicing'),
412 412
                     ),
413
-                    'poNumber'        => getpaid_limit_length( $invoice->get_number(), 25 ),
413
+                    'poNumber'        => getpaid_limit_length($invoice->get_number(), 25),
414 414
                     'customer'        => array(
415
-                        'id'    => getpaid_limit_length( $invoice->get_user_id(), 25 ),
416
-                        'email' => getpaid_limit_length( $invoice->get_email(), 25 ),
415
+                        'id'    => getpaid_limit_length($invoice->get_user_id(), 25),
416
+                        'email' => getpaid_limit_length($invoice->get_email(), 25),
417 417
                     ),
418 418
                     'customerIP'      => $invoice->get_ip(),
419 419
                 ),
420 420
             ),
421 421
         );
422 422
 
423
-        if ( 0 == $invoice->get_total_tax() ) {
424
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
423
+        if (0 == $invoice->get_total_tax()) {
424
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
425 425
         }
426 426
 
427
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
427
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
428 428
 
429 429
     }
430 430
 
@@ -434,29 +434,29 @@  discard block
 block discarded – undo
434 434
      * @param stdClass $result Api response.
435 435
 	 * @param WPInv_Invoice $invoice Invoice.
436 436
 	 */
437
-	public function process_charge_response( $result, $invoice ) {
437
+	public function process_charge_response($result, $invoice) {
438 438
 
439 439
         wpinv_clear_errors();
440 440
 		$response_code = (int) $result->transactionResponse->responseCode;
441 441
 
442 442
 		// Succeeded.
443
-		if ( 1 == $response_code || 4 == $response_code ) {
443
+		if (1 == $response_code || 4 == $response_code) {
444 444
 
445 445
 			// Maybe set a transaction id.
446
-			if ( ! empty( $result->transactionResponse->transId ) ) {
447
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
446
+			if (!empty($result->transactionResponse->transId)) {
447
+				$invoice->set_transaction_id($result->transactionResponse->transId);
448 448
 			}
449 449
 
450
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
450
+			$invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
451 451
 
452
-			if ( 1 == $response_code ) {
452
+			if (1 == $response_code) {
453 453
 				return $invoice->mark_paid();
454 454
 			}
455 455
 
456
-			$invoice->set_status( 'wpi-onhold' );
456
+			$invoice->set_status('wpi-onhold');
457 457
         	$invoice->add_note(
458 458
                 sprintf(
459
-                    __( 'Held for review: %s', 'invoicing' ),
459
+                    __('Held for review: %s', 'invoicing'),
460 460
                     $result->transactionResponse->messages->message[0]->description
461 461
                 )
462 462
 			);
@@ -465,11 +465,11 @@  discard block
 block discarded – undo
465 465
 
466 466
 		}
467 467
 
468
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
468
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
469 469
 
470
-        if ( ! empty( $result->transactionResponse->errors ) ) {
470
+        if (!empty($result->transactionResponse->errors)) {
471 471
             $errors = (object) $result->transactionResponse->errors;
472
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
472
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
473 473
         }
474 474
 
475 475
     }
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	 * @param array $card Card details.
482 482
 	 * @return array
483 483
 	 */
484
-	public function get_payment_information( $card ) {
484
+	public function get_payment_information($card) {
485 485
         return array(
486 486
 
487 487
             'creditCard' => array(
@@ -500,8 +500,8 @@  discard block
 block discarded – undo
500 500
 	 * @param WPInv_Invoice $invoice Invoice.
501 501
 	 * @return string
502 502
 	 */
503
-	public function get_customer_profile_meta_name( $invoice ) {
504
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
503
+	public function get_customer_profile_meta_name($invoice) {
504
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
505 505
     }
506 506
 
507 507
     /**
@@ -512,34 +512,34 @@  discard block
 block discarded – undo
512 512
      * @param WPInv_Invoice $invoice
513 513
 	 * @return WP_Error|string The payment profile id
514 514
 	 */
515
-	public function validate_submission_data( $submission_data, $invoice ) {
515
+	public function validate_submission_data($submission_data, $invoice) {
516 516
 
517 517
         // Validate authentication details.
518 518
         $auth = $this->get_auth_params();
519 519
 
520
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
521
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) );
520
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
521
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
522 522
         }
523 523
 
524 524
         // Validate the payment method.
525
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
526
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) );
525
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
526
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
527 527
         }
528 528
 
529 529
         // Are we adding a new payment method?
530
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
530
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
531 531
             return $submission_data['getpaid-authorizenet-payment-method'];
532 532
         }
533 533
 
534 534
         // Retrieve the customer profile id.
535
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
535
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
536 536
 
537 537
         // Create payment method.
538
-        if ( empty( $profile_id ) ) {
539
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
538
+        if (empty($profile_id)) {
539
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
540 540
         }
541 541
 
542
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
542
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
543 543
 
544 544
     }
545 545
 
@@ -550,32 +550,32 @@  discard block
 block discarded – undo
550 550
 	 * @param WPInv_Invoice $invoice Invoice.
551 551
 	 * @return array
552 552
 	 */
553
-	public function get_line_items( $invoice ) {
553
+	public function get_line_items($invoice) {
554 554
         $items = array();
555 555
 
556
-        foreach ( $invoice->get_items() as $item ) {
556
+        foreach ($invoice->get_items() as $item) {
557 557
 
558 558
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
559 559
             $items[] = array(
560
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
561
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
562
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
563
-                'quantity'    => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ),
560
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
561
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
562
+                'description' => getpaid_limit_length($item->get_description(), 255),
563
+                'quantity'    => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()),
564 564
                 'unitPrice'   => (float) $amount,
565 565
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
566 566
             );
567 567
 
568 568
         }
569 569
 
570
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
570
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
571 571
 
572
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
572
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
573 573
 
574
-            if ( $amount > 0 ) {
574
+            if ($amount > 0) {
575 575
                 $items[] = array(
576
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
577
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
578
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
576
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
577
+                    'name'        => getpaid_limit_length($fee_name, 31),
578
+                    'description' => getpaid_limit_length($fee_name, 255),
579 579
                     'quantity'    => '1',
580 580
                     'unitPrice'   => (float) $amount,
581 581
                     'taxable'     => false,
@@ -595,36 +595,36 @@  discard block
 block discarded – undo
595 595
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
596 596
 	 * @return array
597 597
 	 */
598
-	public function process_payment( $invoice, $submission_data, $submission ) {
598
+	public function process_payment($invoice, $submission_data, $submission) {
599 599
 
600 600
         // Validate the submitted data.
601
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
601
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
602 602
 
603 603
         // Do we have an error?
604
-        if ( is_wp_error( $payment_profile_id ) ) {
605
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
606
-            wpinv_send_back_to_checkout( $invoice );
604
+        if (is_wp_error($payment_profile_id)) {
605
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
606
+            wpinv_send_back_to_checkout($invoice);
607 607
         }
608 608
 
609 609
         // Save the payment method to the order.
610
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
610
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
611 611
 
612 612
         // Check if this is a subscription or not.
613
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
614
-        if ( ! empty( $subscriptions ) ) {
615
-            $this->process_subscription( $invoice, $subscriptions );
613
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
614
+        if (!empty($subscriptions)) {
615
+            $this->process_subscription($invoice, $subscriptions);
616 616
         }
617 617
 
618 618
         // If it is free, send to the success page.
619
-        if ( ! $invoice->needs_payment() ) {
619
+        if (!$invoice->needs_payment()) {
620 620
             $invoice->mark_paid();
621
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
621
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
622 622
         }
623 623
 
624 624
         // Charge the payment profile.
625
-        $this->process_initial_payment( $invoice );
625
+        $this->process_initial_payment($invoice);
626 626
 
627
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
627
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
628 628
 
629 629
         exit;
630 630
 
@@ -635,23 +635,23 @@  discard block
 block discarded – undo
635 635
 	 *
636 636
      * @param WPInv_Invoice $invoice Invoice.
637 637
 	 */
638
-	protected function process_initial_payment( $invoice ) {
638
+	protected function process_initial_payment($invoice) {
639 639
 
640
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
641
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
642
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
640
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
641
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
642
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
643 643
 
644 644
 		// Do we have an error?
645
-		if ( is_wp_error( $result ) ) {
646
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
647
-			wpinv_send_back_to_checkout( $invoice );
645
+		if (is_wp_error($result)) {
646
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
647
+			wpinv_send_back_to_checkout($invoice);
648 648
 		}
649 649
 
650 650
 		// Process the response.
651
-		$this->process_charge_response( $result, $invoice );
651
+		$this->process_charge_response($result, $invoice);
652 652
 
653
-		if ( wpinv_get_errors() ) {
654
-			wpinv_send_back_to_checkout( $invoice );
653
+		if (wpinv_get_errors()) {
654
+			wpinv_send_back_to_checkout($invoice);
655 655
 		}
656 656
 
657 657
 	}
@@ -662,30 +662,30 @@  discard block
 block discarded – undo
662 662
      * @param WPInv_Invoice $invoice Invoice.
663 663
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
664 664
 	 */
665
-	public function process_subscription( $invoice, $subscriptions ) {
665
+	public function process_subscription($invoice, $subscriptions) {
666 666
 
667 667
         // Check if there is an initial amount to charge.
668
-        if ( (float) $invoice->get_total() > 0 ) {
669
-			$this->process_initial_payment( $invoice );
668
+        if ((float) $invoice->get_total() > 0) {
669
+			$this->process_initial_payment($invoice);
670 670
         }
671 671
 
672 672
         // Activate the subscriptions.
673
-        $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
673
+        $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
674 674
 
675
-        foreach ( $subscriptions as $subscription ) {
676
-            if ( $subscription->exists() ) {
677
-                $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
678
-                $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
675
+        foreach ($subscriptions as $subscription) {
676
+            if ($subscription->exists()) {
677
+                $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
678
+                $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
679 679
 
680
-                $subscription->set_next_renewal_date( $expiry );
681
-                $subscription->set_date_created( current_time( 'mysql' ) );
682
-                $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
680
+                $subscription->set_next_renewal_date($expiry);
681
+                $subscription->set_date_created(current_time('mysql'));
682
+                $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
683 683
                 $subscription->activate();
684 684
             }
685 685
         }
686 686
 
687 687
 		// Redirect to the success page.
688
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
688
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
689 689
 
690 690
     }
691 691
 
@@ -695,11 +695,11 @@  discard block
 block discarded – undo
695 695
 	 *
696 696
      * @param WPInv_Subscription $subscription
697 697
 	 */
698
-	public function maybe_renew_subscription( $subscription ) {
698
+	public function maybe_renew_subscription($subscription) {
699 699
 
700 700
         // Ensure its our subscription && it's active.
701
-        if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
702
-            $this->renew_subscription( $subscription );
701
+        if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) {
702
+            $this->renew_subscription($subscription);
703 703
         }
704 704
 
705 705
 	}
@@ -709,28 +709,28 @@  discard block
 block discarded – undo
709 709
 	 *
710 710
      * @param WPInv_Subscription $subscription
711 711
 	 */
712
-	public function renew_subscription( $subscription ) {
712
+	public function renew_subscription($subscription) {
713 713
 
714 714
 		// Generate the renewal invoice.
715 715
 		$new_invoice = $subscription->create_payment();
716 716
 		$old_invoice = $subscription->get_parent_payment();
717 717
 
718
-        if ( empty( $new_invoice ) ) {
719
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
718
+        if (empty($new_invoice)) {
719
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
720 720
             $subscription->failing();
721 721
             return;
722 722
         }
723 723
 
724 724
         // Charge the payment method.
725
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
726
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
727
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
725
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
726
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
727
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
728 728
 
729 729
 		// Do we have an error?
730
-		if ( is_wp_error( $result ) ) {
730
+		if (is_wp_error($result)) {
731 731
 
732 732
 			$old_invoice->add_note(
733
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
733
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
734 734
 				true,
735 735
 				false,
736 736
 				true
@@ -741,12 +741,12 @@  discard block
 block discarded – undo
741 741
 		}
742 742
 
743 743
 		// Process the response.
744
-		$this->process_charge_response( $result, $new_invoice );
744
+		$this->process_charge_response($result, $new_invoice);
745 745
 
746
-		if ( wpinv_get_errors() ) {
746
+		if (wpinv_get_errors()) {
747 747
 
748 748
 			$old_invoice->add_note(
749
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
749
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
750 750
 				true,
751 751
 				false,
752 752
 				true
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 
757 757
         }
758 758
 
759
-        $subscription->add_payment( array(), $new_invoice );
759
+        $subscription->add_payment(array(), $new_invoice);
760 760
         $subscription->renew();
761 761
     }
762 762
 
@@ -767,33 +767,33 @@  discard block
 block discarded – undo
767 767
 	 * @param GetPaid_Form_Item[] $items
768 768
 	 * @return WPInv_Invoice
769 769
 	 */
770
-	public function process_addons( $invoice, $items ) {
770
+	public function process_addons($invoice, $items) {
771 771
 
772 772
         global $getpaid_authorize_addons;
773 773
 
774 774
         $getpaid_authorize_addons = array();
775
-        foreach ( $items as $item ) {
775
+        foreach ($items as $item) {
776 776
 
777
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
777
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
778 778
                 $getpaid_authorize_addons[] = $item;
779 779
             }
780 780
 }
781 781
 
782
-        if ( empty( $getpaid_authorize_addons ) ) {
782
+        if (empty($getpaid_authorize_addons)) {
783 783
             return;
784 784
         }
785 785
 
786 786
         $invoice->recalculate_total();
787 787
 
788
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
789
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
788
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
789
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
790 790
 
791
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
792
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
793
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
791
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
792
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
793
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
794 794
 
795
-        if ( is_wp_error( $result ) ) {
796
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
795
+        if (is_wp_error($result)) {
796
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
797 797
             return;
798 798
         }
799 799
 
@@ -806,19 +806,19 @@  discard block
 block discarded – undo
806 806
      * @param array $args
807 807
 	 * @return array
808 808
 	 */
809
-    public function filter_addons_request( $args ) {
809
+    public function filter_addons_request($args) {
810 810
 
811 811
         global $getpaid_authorize_addons;
812 812
         $total = 0;
813 813
 
814
-        foreach ( $getpaid_authorize_addons as $addon ) {
814
+        foreach ($getpaid_authorize_addons as $addon) {
815 815
             $total += $addon->get_sub_total();
816 816
         }
817 817
 
818 818
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
819 819
 
820
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
821
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
820
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
821
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
822 822
         }
823 823
 
824 824
         return $args;
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
     public function sandbox_notice() {
832 832
 
833 833
         return sprintf(
834
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
834
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'),
835 835
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
836 836
             '</a>'
837 837
         );
@@ -843,42 +843,42 @@  discard block
 block discarded – undo
843 843
 	 *
844 844
 	 * @param array $admin_settings
845 845
 	 */
846
-	public function admin_settings( $admin_settings ) {
846
+	public function admin_settings($admin_settings) {
847 847
 
848 848
         $currencies = sprintf(
849
-            __( 'Supported Currencies: %s', 'invoicing' ),
850
-            implode( ', ', $this->currencies )
849
+            __('Supported Currencies: %s', 'invoicing'),
850
+            implode(', ', $this->currencies)
851 851
         );
852 852
 
853 853
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
854
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
854
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
855 855
 
856 856
         $admin_settings['authorizenet_login_id'] = array(
857 857
             'type' => 'text',
858 858
             'id'   => 'authorizenet_login_id',
859
-            'name' => __( 'API Login ID', 'invoicing' ),
860
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
859
+            'name' => __('API Login ID', 'invoicing'),
860
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
861 861
         );
862 862
 
863 863
         $admin_settings['authorizenet_transaction_key'] = array(
864 864
             'type' => 'text',
865 865
             'id'   => 'authorizenet_transaction_key',
866
-            'name' => __( 'Transaction Key', 'invoicing' ),
866
+            'name' => __('Transaction Key', 'invoicing'),
867 867
         );
868 868
 
869 869
         $admin_settings['authorizenet_signature_key'] = array(
870 870
             'type' => 'text',
871 871
             'id'   => 'authorizenet_signature_key',
872
-            'name' => __( 'Signature Key', 'invoicing' ),
873
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
872
+            'name' => __('Signature Key', 'invoicing'),
873
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
874 874
         );
875 875
 
876 876
         $admin_settings['authorizenet_ipn_url'] = array(
877 877
             'type'     => 'ipn_url',
878 878
             'id'       => 'authorizenet_ipn_url',
879
-            'name'     => __( 'Webhook URL', 'invoicing' ),
879
+            'name'     => __('Webhook URL', 'invoicing'),
880 880
             'std'      => $this->notify_url,
881
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
881
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
882 882
             'custom'   => 'authorizenet',
883 883
             'readonly' => true,
884 884
         );
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-worldpay-gateway.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,65 +13,65 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Worldpay_Gateway extends GetPaid_Payment_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 = 'worldpay';
21 21
 
22 22
     /**
23
-	 * Payment method order.
24
-	 *
25
-	 * @var int
26
-	 */
23
+     * Payment method order.
24
+     *
25
+     * @var int
26
+     */
27 27
     public $order = 5;
28 28
 
29 29
     /**
30
-	 * Endpoint for requests from Worldpay.
31
-	 *
32
-	 * @var string
33
-	 */
34
-	protected $notify_url;
35
-
36
-	/**
37
-	 * Endpoint for requests to Worldpay.
38
-	 *
39
-	 * @var string
40
-	 */
30
+     * Endpoint for requests from Worldpay.
31
+     *
32
+     * @var string
33
+     */
34
+    protected $notify_url;
35
+
36
+    /**
37
+     * Endpoint for requests to Worldpay.
38
+     *
39
+     * @var string
40
+     */
41 41
     protected $endpoint;
42 42
 
43 43
     /**
44
-	 * An array of features that this gateway supports.
45
-	 *
46
-	 * @var array
47
-	 */
44
+     * An array of features that this gateway supports.
45
+     *
46
+     * @var array
47
+     */
48 48
     protected $supports = array( 'sandbox' );
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
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://www.{sandbox}paypal.com/activity/payment/%s';
63 63
 
64 64
     /**
65
-	 * URL to view a subscription.
66
-	 *
67
-	 * @var string
68
-	 */
69
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
65
+     * URL to view a subscription.
66
+     *
67
+     * @var string
68
+     */
69
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
70 70
 
71 71
     /**
72
-	 * Class constructor.
73
-	 */
74
-	public function __construct() {
72
+     * Class constructor.
73
+     */
74
+    public function __construct() {
75 75
 
76 76
         $this->method_title         = __( 'Worldpay', 'invoicing' );
77 77
         $this->title                = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' );
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * Process Payment.
89
-	 *
90
-	 *
91
-	 * @param WPInv_Invoice $invoice Invoice.
92
-	 * @param array $submission_data Posted checkout fields.
93
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94
-	 * @return array
95
-	 */
96
-	public function process_payment( $invoice, $submission_data, $submission ) {
88
+     * Process Payment.
89
+     *
90
+     *
91
+     * @param WPInv_Invoice $invoice Invoice.
92
+     * @param array $submission_data Posted checkout fields.
93
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94
+     * @return array
95
+     */
96
+    public function process_payment( $invoice, $submission_data, $submission ) {
97 97
 
98 98
         // Get redirect url.
99 99
         $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) );
@@ -128,31 +128,31 @@  discard block
 block discarded – undo
128 128
     }
129 129
 
130 130
     /**
131
-	 * Get the Worldpay request URL for an invoice.
132
-	 *
133
-	 * @param  WPInv_Invoice $invoice Invoice object.
134
-	 * @return string
135
-	 */
136
-	public function get_request_url( $invoice ) {
131
+     * Get the Worldpay request URL for an invoice.
132
+     *
133
+     * @param  WPInv_Invoice $invoice Invoice object.
134
+     * @return string
135
+     */
136
+    public function get_request_url( $invoice ) {
137 137
 
138 138
         // Endpoint for this request
139
-		$this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
139
+        $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
140 140
 
141 141
         return $this->endpoint;
142 142
 
143
-	}
143
+    }
144 144
 
145 145
     /**
146
-	 * Get Worldpay Args for passing to Worldpay.
147
-	 *
148
-	 * @param  WPInv_Invoice $invoice Invoice object.
149
-	 * @return array
150
-	 */
151
-	protected function get_worldpay_args( $invoice ) {
152
-
153
-		return apply_filters(
154
-			'getpaid_worldpay_args',
155
-			array(
146
+     * Get Worldpay Args for passing to Worldpay.
147
+     *
148
+     * @param  WPInv_Invoice $invoice Invoice object.
149
+     * @return array
150
+     */
151
+    protected function get_worldpay_args( $invoice ) {
152
+
153
+        return apply_filters(
154
+            'getpaid_worldpay_args',
155
+            array(
156 156
                 'amount'         => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory
157 157
                 'cartId'         => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased
158 158
                 'currency'       => wpinv_clean( $invoice->get_currency() ), // mandatory
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
                 'countryString'  => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ),
178 178
                 'compName'       => wpinv_clean( $invoice->get_company() ),
179 179
             ),
180
-			$invoice
181
-		);
180
+            $invoice
181
+        );
182 182
 
183 183
     }
184 184
 
185 185
     /**
186
-	 * Secures worldpay args with an md5 hash.
187
-	 *
188
-	 * @param  array $args Gateway args.
189
-	 * @return array
190
-	 */
191
-	public function hash_args( $args ) {
186
+     * Secures worldpay args with an md5 hash.
187
+     *
188
+     * @param  array $args Gateway args.
189
+     * @return array
190
+     */
191
+    public function hash_args( $args ) {
192 192
 
193 193
         $md5_secret = $this->get_option( 'md5_secret' );
194 194
 
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
     }
205 205
 
206 206
     /**
207
-	 * Processes ipns and marks payments as complete.
208
-	 *
209
-	 * @return void
210
-	 */
211
-	public function verify_ipn() {
207
+     * Processes ipns and marks payments as complete.
208
+     *
209
+     * @return void
210
+     */
211
+    public function verify_ipn() {
212 212
 
213 213
         // Validate the IPN.
214 214
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
215
-		    wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
216
-		}
215
+            wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
216
+        }
217 217
 
218 218
         // Process the IPN.
219 219
         $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
                 $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) );
230 230
             }
231 231
 
232
-             // Update the ip address.
233
-             if ( ! empty( $posted['ipAddress'] ) ) {
232
+                // Update the ip address.
233
+                if ( ! empty( $posted['ipAddress'] ) ) {
234 234
                 $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) );
235 235
             }
236 236
 
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
     }
258 258
 
259 259
     /**
260
-	 * Check Worldpay IPN validity.
261
-	 */
262
-	public function validate_ipn() {
260
+     * Check Worldpay IPN validity.
261
+     */
262
+    public function validate_ipn() {
263 263
 
264 264
         wpinv_error_log( 'Validating Worldpay IPN response' );
265 265
 
@@ -305,11 +305,11 @@  discard block
 block discarded – undo
305 305
     }
306 306
 
307 307
     /**
308
-	 * Filters the gateway settings.
309
-	 *
310
-	 * @param array $admin_settings
311
-	 */
312
-	public function admin_settings( $admin_settings ) {
308
+     * Filters the gateway settings.
309
+     *
310
+     * @param array $admin_settings
311
+     */
312
+    public function admin_settings( $admin_settings ) {
313 313
 
314 314
         $currencies = sprintf(
315 315
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             'readonly' => true,
351 351
         );
352 352
 
353
-		return $admin_settings;
354
-	}
353
+        return $admin_settings;
354
+    }
355 355
 
356 356
 }
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 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
  * Worldpay Payment Gateway class.
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @var array
47 47
 	 */
48
-    protected $supports = array( 'sandbox' );
48
+    protected $supports = array('sandbox');
49 49
 
50 50
     /**
51 51
 	 * Currencies this gateway is allowed for.
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
55
+	public $currencies = array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	public function __construct() {
75 75
 
76
-        $this->method_title         = __( 'Worldpay', 'invoicing' );
77
-        $this->title                = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' );
78
-        $this->checkout_button_text = __( 'Proceed to Worldpay', 'invoicing' );
79
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
76
+        $this->method_title         = __('Worldpay', 'invoicing');
77
+        $this->title                = __('Worldpay - Credit Card / Debit Card', 'invoicing');
78
+        $this->checkout_button_text = __('Proceed to Worldpay', 'invoicing');
79
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
80 80
 
81
-        add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 );
82
-        add_filter( 'getpaid_worldpay_args', array( $this, 'hash_args' ) );
81
+        add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2);
82
+        add_filter('getpaid_worldpay_args', array($this, 'hash_args'));
83 83
 
84 84
         parent::__construct();
85 85
     }
@@ -93,24 +93,24 @@  discard block
 block discarded – undo
93 93
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94 94
 	 * @return array
95 95
 	 */
96
-	public function process_payment( $invoice, $submission_data, $submission ) {
96
+	public function process_payment($invoice, $submission_data, $submission) {
97 97
 
98 98
         // Get redirect url.
99
-        $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) );
99
+        $worldpay_redirect = esc_url($this->get_request_url($invoice));
100 100
 
101 101
         // Get submission args.
102
-        $worldpay_args     = $this->get_worldpay_args( $invoice );
102
+        $worldpay_args     = $this->get_worldpay_args($invoice);
103 103
 
104 104
         $form = "<form action='$worldpay_redirect' name='wpi_worldpay_form' method='POST'>";
105 105
 
106
-        foreach ( $worldpay_args as $key => $value ) {
106
+        foreach ($worldpay_args as $key => $value) {
107 107
 
108
-            if ( false === $value || '' === trim( $value ) ) {
108
+            if (false === $value || '' === trim($value)) {
109 109
                 continue;
110 110
             }
111 111
 
112
-            $value = esc_attr( $value );
113
-            $key   = wpinv_clean( $key );
112
+            $value = esc_attr($value);
113
+            $key   = wpinv_clean($key);
114 114
             $form .= "<input type='hidden' name='$key' value='$value'>";
115 115
         }
116 116
 
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 * @param  WPInv_Invoice $invoice Invoice object.
134 134
 	 * @return string
135 135
 	 */
136
-	public function get_request_url( $invoice ) {
136
+	public function get_request_url($invoice) {
137 137
 
138 138
         // Endpoint for this request
139
-		$this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
139
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
140 140
 
141 141
         return $this->endpoint;
142 142
 
@@ -148,34 +148,34 @@  discard block
 block discarded – undo
148 148
 	 * @param  WPInv_Invoice $invoice Invoice object.
149 149
 	 * @return array
150 150
 	 */
151
-	protected function get_worldpay_args( $invoice ) {
151
+	protected function get_worldpay_args($invoice) {
152 152
 
153 153
 		return apply_filters(
154 154
 			'getpaid_worldpay_args',
155 155
 			array(
156
-                'amount'         => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory
157
-                'cartId'         => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased
158
-                'currency'       => wpinv_clean( $invoice->get_currency() ), // mandatory
159
-                'instId'         => wpinv_clean( $this->get_option( 'instId', '' ) ), // mandatory
160
-                'testMode'       => $this->is_sandbox( $invoice ) ? 100 : 0, // mandatory
161
-                'name'           => wpinv_clean( $invoice->get_full_name() ),
162
-                'address'        => wpinv_clean( $invoice->get_address() ),
163
-                'postcode'       => wpinv_clean( $invoice->get_zip() ),
164
-                'tel'            => wpinv_clean( $invoice->get_phone() ),
165
-                'email'          => sanitize_email( $invoice->get_email() ),
166
-                'country'        => wpinv_clean( $invoice->get_country() ),
167
-                'desc'           => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ),
168
-                'MC_description' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ),
169
-                'MC_callback'    => esc_url_raw( $this->notify_url ),
170
-                'resultfile'     => esc_url_raw( $this->get_return_url( $invoice ) ),
171
-                'MC_key'         => wpinv_clean( $invoice->get_key() ),
156
+                'amount'         => wpinv_sanitize_amount($invoice->get_total()), // mandatory
157
+                'cartId'         => wpinv_clean($invoice->get_number()), // mandatory reference for the item purchased
158
+                'currency'       => wpinv_clean($invoice->get_currency()), // mandatory
159
+                'instId'         => wpinv_clean($this->get_option('instId', '')), // mandatory
160
+                'testMode'       => $this->is_sandbox($invoice) ? 100 : 0, // mandatory
161
+                'name'           => wpinv_clean($invoice->get_full_name()),
162
+                'address'        => wpinv_clean($invoice->get_address()),
163
+                'postcode'       => wpinv_clean($invoice->get_zip()),
164
+                'tel'            => wpinv_clean($invoice->get_phone()),
165
+                'email'          => sanitize_email($invoice->get_email()),
166
+                'country'        => wpinv_clean($invoice->get_country()),
167
+                'desc'           => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())),
168
+                'MC_description' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())),
169
+                'MC_callback'    => esc_url_raw($this->notify_url),
170
+                'resultfile'     => esc_url_raw($this->get_return_url($invoice)),
171
+                'MC_key'         => wpinv_clean($invoice->get_key()),
172 172
                 'MC_invoice_id'  => $invoice->get_id(),
173
-                'address1'       => wpinv_clean( $invoice->get_address() ),
174
-                'town'           => wpinv_clean( $invoice->get_city() ),
175
-                'region'         => wpinv_clean( $invoice->get_state() ),
176
-                'amountString'   => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
177
-                'countryString'  => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ),
178
-                'compName'       => wpinv_clean( $invoice->get_company() ),
173
+                'address1'       => wpinv_clean($invoice->get_address()),
174
+                'town'           => wpinv_clean($invoice->get_city()),
175
+                'region'         => wpinv_clean($invoice->get_state()),
176
+                'amountString'   => wpinv_price($invoice->get_total(), $invoice->get_currency()),
177
+                'countryString'  => wpinv_clean(wpinv_country_name($invoice->get_country())),
178
+                'compName'       => wpinv_clean($invoice->get_company()),
179 179
             ),
180 180
 			$invoice
181 181
 		);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
 	 * @param  array $args Gateway args.
189 189
 	 * @return array
190 190
 	 */
191
-	public function hash_args( $args ) {
191
+	public function hash_args($args) {
192 192
 
193
-        $md5_secret = $this->get_option( 'md5_secret' );
193
+        $md5_secret = $this->get_option('md5_secret');
194 194
 
195 195
         // Abort if there is no secret.
196
-        if ( empty( $md5_secret ) ) {
196
+        if (empty($md5_secret)) {
197 197
             return $args;
198 198
         }
199 199
 
200 200
         // Hash the args.
201
-        $args['signature'] = md5( "$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}" );
201
+        $args['signature'] = md5("$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}");
202 202
 
203 203
         return $args;
204 204
     }
@@ -211,43 +211,43 @@  discard block
 block discarded – undo
211 211
 	public function verify_ipn() {
212 212
 
213 213
         // Validate the IPN.
214
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
215
-		    wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
214
+        if (empty($_POST) || !$this->validate_ipn()) {
215
+		    wp_die('Worldpay IPN Request Failure', 'Worldpay IPN', array('response' => 500));
216 216
 		}
217 217
 
218 218
         // Process the IPN.
219
-        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
220
-        $invoice = wpinv_get_invoice( $posted['MC_invoice_id'] );
219
+        $posted  = wp_kses_post_deep(wp_unslash($_POST));
220
+        $invoice = wpinv_get_invoice($posted['MC_invoice_id']);
221 221
 
222
-        if ( $invoice && $this->id == $invoice->get_gateway() ) {
222
+        if ($invoice && $this->id == $invoice->get_gateway()) {
223 223
 
224
-            wpinv_error_log( 'Found invoice #' . $invoice->get_number() );
225
-            wpinv_error_log( 'Payment status:' . $posted['transStatus'] );
224
+            wpinv_error_log('Found invoice #' . $invoice->get_number());
225
+            wpinv_error_log('Payment status:' . $posted['transStatus']);
226 226
 
227 227
             // Update the transaction id.
228
-            if ( ! empty( $posted['transId'] ) ) {
229
-                $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) );
228
+            if (!empty($posted['transId'])) {
229
+                $invoice->set_transaction_id(wpinv_clean($posted['transId']));
230 230
             }
231 231
 
232 232
              // Update the ip address.
233
-             if ( ! empty( $posted['ipAddress'] ) ) {
234
-                $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) );
233
+             if (!empty($posted['ipAddress'])) {
234
+                $invoice->set_ip(wpinv_clean($posted['ipAddress']));
235 235
             }
236 236
 
237
-            if ( $posted['transStatus'] == 'Y' ) {
238
-                $invoice->set_completed_date( date( 'Y-m-d H:i:s', $posted['transTime'] ) );
237
+            if ($posted['transStatus'] == 'Y') {
238
+                $invoice->set_completed_date(date('Y-m-d H:i:s', $posted['transTime']));
239 239
                 $invoice->mark_paid();
240 240
                 return;
241 241
             }
242 242
 
243
-            if ( $posted['transStatus'] == 'C' ) {
244
-                $invoice->set_status( 'wpi-failed' );
245
-                $invoice->add_note( __( 'Payment transaction failed while processing Worldpay payment.', 'invoicing' ), false, false, true );
243
+            if ($posted['transStatus'] == 'C') {
244
+                $invoice->set_status('wpi-failed');
245
+                $invoice->add_note(__('Payment transaction failed while processing Worldpay payment.', 'invoicing'), false, false, true);
246 246
                 $invoice->save();
247 247
                 return;
248 248
             }
249 249
 
250
-            wpinv_error_log( 'Aborting, Invalid transaction status:' . $posted['transStatus'] );
250
+            wpinv_error_log('Aborting, Invalid transaction status:' . $posted['transStatus']);
251 251
             $invoice->save();
252 252
 
253 253
         }
@@ -261,27 +261,27 @@  discard block
 block discarded – undo
261 261
 	 */
262 262
 	public function validate_ipn() {
263 263
 
264
-        wpinv_error_log( 'Validating Worldpay IPN response' );
264
+        wpinv_error_log('Validating Worldpay IPN response');
265 265
 
266
-        $data = wp_kses_post_deep( wp_unslash( $_POST ) );
266
+        $data = wp_kses_post_deep(wp_unslash($_POST));
267 267
 
268 268
         // Verify installation.
269
-        if ( empty( $data['instId'] ) || $data['instId'] != wpinv_clean( $this->get_option( 'instId', '' ) ) ) {
270
-            wpinv_error_log( 'Received invalid installation ID from Worldpay IPN' );
269
+        if (empty($data['instId']) || $data['instId'] != wpinv_clean($this->get_option('instId', ''))) {
270
+            wpinv_error_log('Received invalid installation ID from Worldpay IPN');
271 271
             return false;
272 272
         }
273 273
 
274 274
         // Verify invoice.
275
-        if ( empty( $data['cartId'] ) || ! wpinv_get_id_by_invoice_number( $data['cartId'] ) ) {
276
-            wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' );
275
+        if (empty($data['cartId']) || !wpinv_get_id_by_invoice_number($data['cartId'])) {
276
+            wpinv_error_log('Received invalid invoice number from Worldpay IPN');
277 277
             return false;
278 278
         }
279 279
 
280 280
         // (maybe) verify password.
281
-        $password = $this->get_option( 'callback_password' );
281
+        $password = $this->get_option('callback_password');
282 282
 
283
-        if ( ! empty( $password ) && ( empty( $data['callbackPW'] ) || $password != $data['callbackPW'] ) ) {
284
-            wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' );
283
+        if (!empty($password) && (empty($data['callbackPW']) || $password != $data['callbackPW'])) {
284
+            wpinv_error_log('Received invalid invoice number from Worldpay IPN');
285 285
             return false;
286 286
         }
287 287
 
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
     /**
293 293
      * Displays a notice on the checkout page if sandbox is enabled.
294 294
      */
295
-    public function sandbox_notice( $description, $gateway ) {
296
-        if ( 'worldpay' == $gateway && wpinv_is_test_mode( 'worldpay' ) ) {
295
+    public function sandbox_notice($description, $gateway) {
296
+        if ('worldpay' == $gateway && wpinv_is_test_mode('worldpay')) {
297 297
             $description .= '<br>' . sprintf(
298
-                __( 'SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
298
+                __('SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing'),
299 299
                 '<a href="https://developer.worldpay.com/docs/wpg/directintegration/abouttesting">',
300 300
                 '</a>'
301 301
             );
@@ -309,43 +309,43 @@  discard block
 block discarded – undo
309 309
 	 *
310 310
 	 * @param array $admin_settings
311 311
 	 */
312
-	public function admin_settings( $admin_settings ) {
312
+	public function admin_settings($admin_settings) {
313 313
 
314 314
         $currencies = sprintf(
315
-            __( 'Supported Currencies: %s', 'invoicing' ),
316
-            implode( ', ', $this->currencies )
315
+            __('Supported Currencies: %s', 'invoicing'),
316
+            implode(', ', $this->currencies)
317 317
         );
318 318
 
319 319
         $admin_settings['worldpay_active']['desc'] = $admin_settings['worldpay_active']['desc'] . " ($currencies)";
320
-        $admin_settings['worldpay_desc']['std']    = __( 'Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing' );
320
+        $admin_settings['worldpay_desc']['std']    = __('Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing');
321 321
 
322 322
         $admin_settings['worldpay_instId'] = array(
323 323
             'type' => 'text',
324 324
             'id'   => 'worldpay_instId',
325
-            'name' => __( 'Installation Id', 'invoicing' ),
326
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
325
+            'name' => __('Installation Id', 'invoicing'),
326
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
327 327
         );
328 328
 
329 329
         $admin_settings['worldpay_md5_secret'] = array(
330 330
             'type' => 'text',
331 331
             'id'   => 'worldpay_md5_secret',
332
-            'name' => __( 'MD5 secret', 'invoicing' ),
333
-            'desc' => __( 'Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing' ) . '<code>instId:amount:currency:cartId</code>',
332
+            'name' => __('MD5 secret', 'invoicing'),
333
+            'desc' => __('Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing') . '<code>instId:amount:currency:cartId</code>',
334 334
         );
335 335
 
336 336
         $admin_settings['worldpay_callbackPW'] = array(
337 337
             'type' => 'text',
338 338
             'id'   => 'worldpay_callbackPW',
339
-            'name' => __( 'Payment Response password', 'invoicing' ),
340
-            'desc' => __( 'Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing' ),
339
+            'name' => __('Payment Response password', 'invoicing'),
340
+            'desc' => __('Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing'),
341 341
         );
342 342
 
343 343
         $admin_settings['worldpay_ipn_url'] = array(
344 344
             'type'     => 'ipn_url',
345 345
             'id'       => 'worldpay_ipn_url',
346
-            'name'     => __( 'Payment Response URL', 'invoicing' ),
346
+            'name'     => __('Payment Response URL', 'invoicing'),
347 347
             'std'      => $this->notify_url,
348
-            'desc'     => __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing' ),
348
+            'desc'     => __('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing'),
349 349
             'custom'   => 'worldpay',
350 350
             'readonly' => true,
351 351
         );
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions-db.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * The Subscriptions DB Class
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
             'transaction_id'    => '',
73 73
             'parent_payment_id' => 0,
74 74
             'product_id'        => 0,
75
-            'created'           => date( 'Y-m-d H:i:s' ),
76
-            'expiration'        => date( 'Y-m-d H:i:s' ),
75
+            'created'           => date('Y-m-d H:i:s'),
76
+            'expiration'        => date('Y-m-d H:i:s'),
77 77
             'trial_period'      => '',
78 78
             'status'            => '',
79 79
             'profile_id'        => '',
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
      * @access  public
87 87
      * @since   1.0.0
88 88
      */
89
-    public function get_subscriptions( $args = array() ) {
90
-        return getpaid_get_subscriptions( $args );
89
+    public function get_subscriptions($args = array()) {
90
+        return getpaid_get_subscriptions($args);
91 91
     }
92 92
 
93 93
     /**
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
      * @access  public
97 97
      * @since   1.0.0
98 98
      */
99
-    public function count( $args = array() ) {
100
-        return getpaid_get_subscriptions( $args, 'count' );
99
+    public function count($args = array()) {
100
+        return getpaid_get_subscriptions($args, 'count');
101 101
     }
102 102
 
103 103
     /**
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
         KEY customer_and_status ( customer_id, status)
134 134
         ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
135 135
 
136
-        dbDelta( $sql );
136
+        dbDelta($sql);
137 137
 
138
-        update_option( $this->table_name . '_db_version', $this->version );
138
+        update_option($this->table_name . '_db_version', $this->version);
139 139
     }
140 140
 
141 141
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 2 patches
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -13,299 +13,299 @@
 block discarded – undo
13 13
 class GetPaid_Subscription_Notification_Emails {
14 14
 
15 15
     /**
16
-	 * The array of subscription email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $subscription_actions;
16
+     * The array of subscription email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $subscription_actions;
21 21
 
22 22
     /**
23
-	 * Class constructor
23
+     * Class constructor
24 24
      *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->subscription_actions = apply_filters(
29
-			'getpaid_notification_email_subscription_triggers',
30
-			array(
31
-				'getpaid_subscription_trialling' => 'subscription_trial',
32
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
-				'getpaid_subscription_expired'   => 'subscription_expired',
34
-				'getpaid_subscription_completed' => 'subscription_complete',
35
-				'getpaid_daily_maintenance'      => 'renewal_reminder',
36
-			)
37
-		);
38
-
39
-		$this->init_hooks();
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_trialling' => 'subscription_trial',
32
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
+                'getpaid_subscription_expired'   => 'subscription_expired',
34
+                'getpaid_subscription_completed' => 'subscription_complete',
35
+                'getpaid_daily_maintenance'      => 'renewal_reminder',
36
+            )
37
+        );
38
+
39
+        $this->init_hooks();
40 40
 
41 41
     }
42 42
 
43 43
     /**
44
-	 * Registers email hooks.
45
-	 */
46
-	public function init_hooks() {
47
-
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
50
-
51
-			$email = new GetPaid_Notification_Email( $email_type );
52
-
53
-			if ( ! $email->is_active() ) {
54
-				continue;
55
-			}
56
-
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
59
-				continue;
60
-			}
61
-
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
-
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * Filters subscription merge tags.
70
-	 *
71
-	 * @param array $merge_tags
72
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
-	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
75
-
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
-			$merge_tags = array_merge(
78
-				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
80
-			);
81
-		}
82
-
83
-		return $merge_tags;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Generates subscription merge tags.
89
-	 *
90
-	 * @param WPInv_Subscription $subscription
91
-	 * @return array
92
-	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
94
-
95
-		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
97
-			return array();
98
-		}
99
-
100
-		$invoice    = $subscription->get_parent_invoice();
101
-		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
-			'{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
-			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
-		);
113
-
114
-	}
115
-
116
-	/**
117
-	 * Checks if we should send a notification for a subscription.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return bool
121
-	 */
122
-	public function should_send_notification( $invoice ) {
123
-		return 0 != $invoice->get_id();
124
-	}
125
-
126
-	/**
127
-	 * Returns notification recipients.
128
-	 *
129
-	 * @param WPInv_Invoice $invoice
130
-	 * @return array
131
-	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
134
-
135
-		$cc = $invoice->get_email_cc();
136
-
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
-		}
141
-
142
-		return $recipients;
143
-	}
144
-
145
-	/**
146
-	 * Helper function to send an email.
147
-	 *
148
-	 * @param WPInv_Subscription $subscription
149
-	 * @param GetPaid_Notification_Email $email
150
-	 * @param string $type
151
-	 * @param array $extra_args Extra template args.
152
-	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
-
155
-		// Abort in case the parent invoice does not exist.
156
-		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
158
-			return;
159
-		}
160
-
161
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
162
-			return;
163
-		}
164
-
165
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
166
-
167
-		$recipients  = $this->get_recipients( $invoice );
168
-		$mailer      = new GetPaid_Notification_Email_Sender();
169
-		$merge_tags  = $email->get_merge_tags();
170
-		$content     = $email->get_content( $merge_tags, $extra_args );
171
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
172
-		$attachments = $email->get_attachments();
173
-
174
-		$result = $mailer->send(
175
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
176
-			$subject,
177
-			$content,
178
-			$attachments
179
-		);
180
-
181
-		// Maybe send a copy to the admin.
182
-		if ( $email->include_admin_bcc() ) {
183
-			$mailer->send(
184
-				wpinv_get_admin_email(),
185
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
186
-				$content,
187
-				$attachments
188
-			);
189
-		}
190
-
191
-		if ( $result ) {
192
-			$invoice->add_system_note(
193
-				sprintf(
194
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
195
-					sanitize_key( $type ),
196
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
197
-				)
198
-			);
199
-		} else {
200
-			$invoice->add_system_note(
201
-				sprintf(
202
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
203
-					sanitize_key( $type ),
204
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
205
-				)
206
-			);
207
-		}
208
-
209
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
210
-
211
-	}
44
+     * Registers email hooks.
45
+     */
46
+    public function init_hooks() {
47
+
48
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
+        foreach ( $this->subscription_actions as $hook => $email_type ) {
50
+
51
+            $email = new GetPaid_Notification_Email( $email_type );
52
+
53
+            if ( ! $email->is_active() ) {
54
+                continue;
55
+            }
56
+
57
+            if ( method_exists( $this, $email_type ) ) {
58
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
59
+                continue;
60
+            }
61
+
62
+            do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
+
64
+        }
65
+
66
+    }
212 67
 
213 68
     /**
214
-	 * Sends a new trial notification.
215
-	 *
216
-	 * @param WPInv_Subscription $subscription
217
-	 */
218
-	public function subscription_trial( $subscription ) {
69
+     * Filters subscription merge tags.
70
+     *
71
+     * @param array $merge_tags
72
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
+     */
74
+    public function subscription_merge_tags( $merge_tags, $object ) {
219 75
 
220
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
-		$this->send_email( $subscription, $email, __FUNCTION__ );
76
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
+            $merge_tags = array_merge(
78
+                $merge_tags,
79
+                $this->get_subscription_merge_tags( $object )
80
+            );
81
+        }
222 82
 
223
-	}
83
+        return $merge_tags;
224 84
 
225
-	/**
226
-	 * Sends a cancelled subscription notification.
227
-	 *
228
-	 * @param WPInv_Subscription $subscription
229
-	 */
230
-	public function subscription_cancelled( $subscription ) {
85
+    }
231 86
 
232
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
-		$this->send_email( $subscription, $email, __FUNCTION__ );
87
+    /**
88
+     * Generates subscription merge tags.
89
+     *
90
+     * @param WPInv_Subscription $subscription
91
+     * @return array
92
+     */
93
+    public function get_subscription_merge_tags( $subscription ) {
94
+
95
+        // Abort if it does not exist.
96
+        if ( ! $subscription->get_id() ) {
97
+            return array();
98
+        }
99
+
100
+        $invoice    = $subscription->get_parent_invoice();
101
+        return array(
102
+            '{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
+            '{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
+            '{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
+            '{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
+            '{subscription_id}'               => absint( $subscription->get_id() ),
107
+            '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
+            '{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
+            '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
+            '{subscription_bill_times}'       => $subscription->get_bill_times(),
111
+            '{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
+        );
234 113
 
235
-	}
114
+    }
236 115
 
237
-	/**
238
-	 * Sends a subscription expired notification.
239
-	 *
240
-	 * @param WPInv_Subscription $subscription
241
-	 */
242
-	public function subscription_expired( $subscription ) {
116
+    /**
117
+     * Checks if we should send a notification for a subscription.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return bool
121
+     */
122
+    public function should_send_notification( $invoice ) {
123
+        return 0 != $invoice->get_id();
124
+    }
243 125
 
244
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
-		$this->send_email( $subscription, $email, __FUNCTION__ );
126
+    /**
127
+     * Returns notification recipients.
128
+     *
129
+     * @param WPInv_Invoice $invoice
130
+     * @return array
131
+     */
132
+    public function get_recipients( $invoice ) {
133
+        $recipients = array( $invoice->get_email() );
246 134
 
247
-	}
135
+        $cc = $invoice->get_email_cc();
248 136
 
249
-	/**
250
-	 * Sends a completed subscription notification.
251
-	 *
252
-	 * @param WPInv_Subscription $subscription
253
-	 */
254
-	public function subscription_complete( $subscription ) {
137
+        if ( ! empty( $cc ) ) {
138
+            $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
+            $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
+        }
255 141
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
258 144
 
259
-	}
145
+    /**
146
+     * Helper function to send an email.
147
+     *
148
+     * @param WPInv_Subscription $subscription
149
+     * @param GetPaid_Notification_Email $email
150
+     * @param string $type
151
+     * @param array $extra_args Extra template args.
152
+     */
153
+    public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
+
155
+        // Abort in case the parent invoice does not exist.
156
+        $invoice = $subscription->get_parent_invoice();
157
+        if ( ! $this->should_send_notification( $invoice ) ) {
158
+            return;
159
+        }
160
+
161
+        if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
162
+            return;
163
+        }
164
+
165
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
166
+
167
+        $recipients  = $this->get_recipients( $invoice );
168
+        $mailer      = new GetPaid_Notification_Email_Sender();
169
+        $merge_tags  = $email->get_merge_tags();
170
+        $content     = $email->get_content( $merge_tags, $extra_args );
171
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
172
+        $attachments = $email->get_attachments();
173
+
174
+        $result = $mailer->send(
175
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
176
+            $subject,
177
+            $content,
178
+            $attachments
179
+        );
180
+
181
+        // Maybe send a copy to the admin.
182
+        if ( $email->include_admin_bcc() ) {
183
+            $mailer->send(
184
+                wpinv_get_admin_email(),
185
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
186
+                $content,
187
+                $attachments
188
+            );
189
+        }
190
+
191
+        if ( $result ) {
192
+            $invoice->add_system_note(
193
+                sprintf(
194
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
195
+                    sanitize_key( $type ),
196
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
197
+                )
198
+            );
199
+        } else {
200
+            $invoice->add_system_note(
201
+                sprintf(
202
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
203
+                    sanitize_key( $type ),
204
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
205
+                )
206
+            );
207
+        }
208
+
209
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
260 210
 
261
-	/**
262
-	 * Sends a subscription renewal reminder notification.
263
-	 *
264
-	 */
265
-	public function renewal_reminder() {
211
+    }
266 212
 
267
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
213
+    /**
214
+     * Sends a new trial notification.
215
+     *
216
+     * @param WPInv_Subscription $subscription
217
+     */
218
+    public function subscription_trial( $subscription ) {
268 219
 
269
-		// Fetch reminder days.
270
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
220
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
+        $this->send_email( $subscription, $email, __FUNCTION__ );
271 222
 
272
-		// Abort if non is set.
273
-		if ( empty( $reminder_days ) ) {
274
-			return;
275
-		}
223
+    }
276 224
 
277
-		// Fetch matching subscriptions.
225
+    /**
226
+     * Sends a cancelled subscription notification.
227
+     *
228
+     * @param WPInv_Subscription $subscription
229
+     */
230
+    public function subscription_cancelled( $subscription ) {
231
+
232
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
+        $this->send_email( $subscription, $email, __FUNCTION__ );
234
+
235
+    }
236
+
237
+    /**
238
+     * Sends a subscription expired notification.
239
+     *
240
+     * @param WPInv_Subscription $subscription
241
+     */
242
+    public function subscription_expired( $subscription ) {
243
+
244
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
+        $this->send_email( $subscription, $email, __FUNCTION__ );
246
+
247
+    }
248
+
249
+    /**
250
+     * Sends a completed subscription notification.
251
+     *
252
+     * @param WPInv_Subscription $subscription
253
+     */
254
+    public function subscription_complete( $subscription ) {
255
+
256
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
+        $this->send_email( $subscription, $email, __FUNCTION__ );
258
+
259
+    }
260
+
261
+    /**
262
+     * Sends a subscription renewal reminder notification.
263
+     *
264
+     */
265
+    public function renewal_reminder() {
266
+
267
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
268
+
269
+        // Fetch reminder days.
270
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
271
+
272
+        // Abort if non is set.
273
+        if ( empty( $reminder_days ) ) {
274
+            return;
275
+        }
276
+
277
+        // Fetch matching subscriptions.
278 278
         $args  = array(
279 279
             'number'             => -1,
280
-			'count_total'        => false,
281
-			'status'             => 'trialling active',
280
+            'count_total'        => false,
281
+            'status'             => 'trialling active',
282 282
             'date_expires_query' => array(
283
-				'relation' => 'OR',
283
+                'relation' => 'OR',
284 284
             ),
285
-		);
285
+        );
286 286
 
287
-		foreach ( $reminder_days as $days ) {
288
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
287
+        foreach ( $reminder_days as $days ) {
288
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
289 289
 
290
-			$args['date_expires_query'][] = array(
291
-				'year'  => $date['year'],
292
-				'month' => $date['month'],
293
-				'day'   => $date['day'],
294
-			);
290
+            $args['date_expires_query'][] = array(
291
+                'year'  => $date['year'],
292
+                'month' => $date['month'],
293
+                'day'   => $date['day'],
294
+            );
295 295
 
296
-		}
296
+        }
297 297
 
298
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
298
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
299 299
 
300 300
         foreach ( $subscriptions as $subscription ) {
301 301
 
302
-			// Skip packages.
303
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
304
-				$email->object = $subscription;
305
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
306
-			}
302
+            // Skip packages.
303
+            if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
304
+                $email->object = $subscription;
305
+                $this->send_email( $subscription, $email, __FUNCTION__ );
306
+            }
307 307
 }
308 308
 
309
-	}
309
+    }
310 310
 
311 311
 }
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 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 subscription notificaiton emails.
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	public function init_hooks() {
47 47
 
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
48
+		add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2);
49
+		foreach ($this->subscription_actions as $hook => $email_type) {
50 50
 
51
-			$email = new GetPaid_Notification_Email( $email_type );
51
+			$email = new GetPaid_Notification_Email($email_type);
52 52
 
53
-			if ( ! $email->is_active() ) {
53
+			if (!$email->is_active()) {
54 54
 				continue;
55 55
 			}
56 56
 
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
57
+			if (method_exists($this, $email_type)) {
58
+				add_action($hook, array($this, $email_type), 100, 2);
59 59
 				continue;
60 60
 			}
61 61
 
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
62
+			do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook);
63 63
 
64 64
 		}
65 65
 
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
 	 * @param array $merge_tags
72 72
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73 73
 	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
74
+	public function subscription_merge_tags($merge_tags, $object) {
75 75
 
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
76
+		if (is_a($object, 'WPInv_Subscription')) {
77 77
 			$merge_tags = array_merge(
78 78
 				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
79
+				$this->get_subscription_merge_tags($object)
80 80
 			);
81 81
 		}
82 82
 
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
 	 * @param WPInv_Subscription $subscription
91 91
 	 * @return array
92 92
 	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
93
+	public function get_subscription_merge_tags($subscription) {
94 94
 
95 95
 		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
96
+		if (!$subscription->get_id()) {
97 97
 			return array();
98 98
 		}
99 99
 
100
-		$invoice    = $subscription->get_parent_invoice();
100
+		$invoice = $subscription->get_parent_invoice();
101 101
 		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
-			'{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
102
+			'{subscription_renewal_date}'     => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')),
103
+			'{subscription_created}'          => getpaid_format_date_value($subscription->get_date_created()),
104
+			'{subscription_status}'           => sanitize_text_field($subscription->get_status_label()),
105
+			'{subscription_profile_id}'       => sanitize_text_field($subscription->get_profile_id()),
106
+			'{subscription_id}'               => absint($subscription->get_id()),
107
+			'{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())),
108
+			'{subscription_initial_amount}'   => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())),
109
+			'{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''),
110 110
 			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
111
+			'{subscription_url}'              => esc_url($subscription->get_view_url()),
112 112
 		);
113 113
 
114 114
 	}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return bool
121 121
 	 */
122
-	public function should_send_notification( $invoice ) {
122
+	public function should_send_notification($invoice) {
123 123
 		return 0 != $invoice->get_id();
124 124
 	}
125 125
 
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 	 * @param WPInv_Invoice $invoice
130 130
 	 * @return array
131 131
 	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
132
+	public function get_recipients($invoice) {
133
+		$recipients = array($invoice->get_email());
134 134
 
135 135
 		$cc = $invoice->get_email_cc();
136 136
 
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
137
+		if (!empty($cc)) {
138
+			$cc = array_map('sanitize_email', wpinv_parse_list($cc));
139
+			$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
140 140
 		}
141 141
 
142 142
 		return $recipients;
@@ -150,63 +150,63 @@  discard block
 block discarded – undo
150 150
 	 * @param string $type
151 151
 	 * @param array $extra_args Extra template args.
152 152
 	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
153
+	public function send_email($subscription, $email, $type, $extra_args = array()) {
154 154
 
155 155
 		// Abort in case the parent invoice does not exist.
156 156
 		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
157
+		if (!$this->should_send_notification($invoice)) {
158 158
 			return;
159 159
 		}
160 160
 
161
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
161
+		if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) {
162 162
 			return;
163 163
 		}
164 164
 
165
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
165
+		do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email);
166 166
 
167
-		$recipients  = $this->get_recipients( $invoice );
167
+		$recipients  = $this->get_recipients($invoice);
168 168
 		$mailer      = new GetPaid_Notification_Email_Sender();
169 169
 		$merge_tags  = $email->get_merge_tags();
170
-		$content     = $email->get_content( $merge_tags, $extra_args );
171
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
170
+		$content     = $email->get_content($merge_tags, $extra_args);
171
+		$subject     = $email->add_merge_tags($email->get_subject(), $merge_tags);
172 172
 		$attachments = $email->get_attachments();
173 173
 
174 174
 		$result = $mailer->send(
175
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
175
+			apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email),
176 176
 			$subject,
177 177
 			$content,
178 178
 			$attachments
179 179
 		);
180 180
 
181 181
 		// Maybe send a copy to the admin.
182
-		if ( $email->include_admin_bcc() ) {
182
+		if ($email->include_admin_bcc()) {
183 183
 			$mailer->send(
184 184
 				wpinv_get_admin_email(),
185
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
185
+				$subject . __(' - ADMIN BCC COPY', 'invoicing'),
186 186
 				$content,
187 187
 				$attachments
188 188
 			);
189 189
 		}
190 190
 
191
-		if ( $result ) {
191
+		if ($result) {
192 192
 			$invoice->add_system_note(
193 193
 				sprintf(
194
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
195
-					sanitize_key( $type ),
196
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
194
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
195
+					sanitize_key($type),
196
+					$email->is_admin_email() ? __('admin') : __('the customer')
197 197
 				)
198 198
 			);
199 199
 		} else {
200 200
 			$invoice->add_system_note(
201 201
 				sprintf(
202
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
203
-					sanitize_key( $type ),
204
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
202
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
203
+					sanitize_key($type),
204
+					$email->is_admin_email() ? __('admin') : __('the customer')
205 205
 				)
206 206
 			);
207 207
 		}
208 208
 
209
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
209
+		do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email);
210 210
 
211 211
 	}
212 212
 
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @param WPInv_Subscription $subscription
217 217
 	 */
218
-	public function subscription_trial( $subscription ) {
218
+	public function subscription_trial($subscription) {
219 219
 
220
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
-		$this->send_email( $subscription, $email, __FUNCTION__ );
220
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
221
+		$this->send_email($subscription, $email, __FUNCTION__);
222 222
 
223 223
 	}
224 224
 
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @param WPInv_Subscription $subscription
229 229
 	 */
230
-	public function subscription_cancelled( $subscription ) {
230
+	public function subscription_cancelled($subscription) {
231 231
 
232
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
-		$this->send_email( $subscription, $email, __FUNCTION__ );
232
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
233
+		$this->send_email($subscription, $email, __FUNCTION__);
234 234
 
235 235
 	}
236 236
 
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
 	 *
240 240
 	 * @param WPInv_Subscription $subscription
241 241
 	 */
242
-	public function subscription_expired( $subscription ) {
242
+	public function subscription_expired($subscription) {
243 243
 
244
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
-		$this->send_email( $subscription, $email, __FUNCTION__ );
244
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
245
+		$this->send_email($subscription, $email, __FUNCTION__);
246 246
 
247 247
 	}
248 248
 
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
 	 *
252 252
 	 * @param WPInv_Subscription $subscription
253 253
 	 */
254
-	public function subscription_complete( $subscription ) {
254
+	public function subscription_complete($subscription) {
255 255
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
-		$this->send_email( $subscription, $email, __FUNCTION__ );
256
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
257
+		$this->send_email($subscription, $email, __FUNCTION__);
258 258
 
259 259
 	}
260 260
 
@@ -264,18 +264,18 @@  discard block
 block discarded – undo
264 264
 	 */
265 265
 	public function renewal_reminder() {
266 266
 
267
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
267
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
268 268
 
269 269
 		// Fetch reminder days.
270
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
270
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
271 271
 
272 272
 		// Abort if non is set.
273
-		if ( empty( $reminder_days ) ) {
273
+		if (empty($reminder_days)) {
274 274
 			return;
275 275
 		}
276 276
 
277 277
 		// Fetch matching subscriptions.
278
-        $args  = array(
278
+        $args = array(
279 279
             'number'             => -1,
280 280
 			'count_total'        => false,
281 281
 			'status'             => 'trialling active',
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
             ),
285 285
 		);
286 286
 
287
-		foreach ( $reminder_days as $days ) {
288
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
287
+		foreach ($reminder_days as $days) {
288
+			$date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp'))));
289 289
 
290 290
 			$args['date_expires_query'][] = array(
291 291
 				'year'  => $date['year'],
@@ -295,14 +295,14 @@  discard block
 block discarded – undo
295 295
 
296 296
 		}
297 297
 
298
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
298
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
299 299
 
300
-        foreach ( $subscriptions as $subscription ) {
300
+        foreach ($subscriptions as $subscription) {
301 301
 
302 302
 			// Skip packages.
303
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
303
+			if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) {
304 304
 				$email->object = $subscription;
305
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
305
+            	$this->send_email($subscription, $email, __FUNCTION__);
306 306
 			}
307 307
 }
308 308
 
Please login to merge, or discard this patch.