@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @deprecated |
@@ -19,48 +19,48 @@ discard block |
||
19 | 19 | * @deprecated |
20 | 20 | */ |
21 | 21 | function wpinv_get_invoice_cart() { |
22 | - return wpinv_get_invoice( getpaid_get_current_invoice_id() ); |
|
22 | + return wpinv_get_invoice(getpaid_get_current_invoice_id()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @deprecated |
27 | 27 | */ |
28 | -function wpinv_get_invoice_description( $invoice ) { |
|
29 | - $invoice = new WPInv_Invoice( $invoice ); |
|
28 | +function wpinv_get_invoice_description($invoice) { |
|
29 | + $invoice = new WPInv_Invoice($invoice); |
|
30 | 30 | return $invoice->get_description(); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @deprecated |
35 | 35 | */ |
36 | -function wpinv_get_invoice_currency_code( $invoice ) { |
|
37 | - $invoice = new WPInv_Invoice( $invoice ); |
|
36 | +function wpinv_get_invoice_currency_code($invoice) { |
|
37 | + $invoice = new WPInv_Invoice($invoice); |
|
38 | 38 | return $invoice->get_currency(); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @deprecated |
43 | 43 | */ |
44 | -function wpinv_get_payment_user_email( $invoice ) { |
|
45 | - $invoice = new WPInv_Invoice( $invoice ); |
|
44 | +function wpinv_get_payment_user_email($invoice) { |
|
45 | + $invoice = new WPInv_Invoice($invoice); |
|
46 | 46 | return $invoice->get_email(); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @deprecated |
51 | 51 | */ |
52 | -function wpinv_get_user_id( $invoice ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice ); |
|
52 | +function wpinv_get_user_id($invoice) { |
|
53 | + $invoice = new WPInv_Invoice($invoice); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @deprecated |
59 | 59 | */ |
60 | -function wpinv_get_invoice_status( $invoice, $return_label = false ) { |
|
61 | - $invoice = new WPInv_Invoice( $invoice ); |
|
60 | +function wpinv_get_invoice_status($invoice, $return_label = false) { |
|
61 | + $invoice = new WPInv_Invoice($invoice); |
|
62 | 62 | |
63 | - if ( $return_label ) { |
|
63 | + if ($return_label) { |
|
64 | 64 | return $invoice->get_status_nicename(); |
65 | 65 | } |
66 | 66 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @deprecated |
72 | 72 | */ |
73 | -function wpinv_get_payment_gateway( $invoice, $return_label = false ) { |
|
74 | - $invoice = new WPInv_Invoice( $invoice ); |
|
73 | +function wpinv_get_payment_gateway($invoice, $return_label = false) { |
|
74 | + $invoice = new WPInv_Invoice($invoice); |
|
75 | 75 | |
76 | - if ( $return_label ) { |
|
76 | + if ($return_label) { |
|
77 | 77 | return $invoice->get_gateway_title(); |
78 | 78 | } |
79 | 79 | |
@@ -83,75 +83,75 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @deprecated |
85 | 85 | */ |
86 | -function wpinv_get_payment_gateway_name( $invoice ) { |
|
87 | - return wpinv_get_payment_gateway( $invoice, true ); |
|
86 | +function wpinv_get_payment_gateway_name($invoice) { |
|
87 | + return wpinv_get_payment_gateway($invoice, true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @deprecated |
92 | 92 | */ |
93 | -function wpinv_get_payment_transaction_id( $invoice ) { |
|
94 | - $invoice = new WPInv_Invoice( $invoice ); |
|
93 | +function wpinv_get_payment_transaction_id($invoice) { |
|
94 | + $invoice = new WPInv_Invoice($invoice); |
|
95 | 95 | return $invoice->get_transaction_id(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @deprecated |
100 | 100 | */ |
101 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
102 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
103 | - return $invoice->get_meta( $meta_key, $single ); |
|
101 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
102 | + $invoice = new WPInv_Invoice($invoice_id); |
|
103 | + return $invoice->get_meta($meta_key, $single); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @deprecated |
108 | 108 | */ |
109 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) { |
|
110 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
111 | - return $invoice->update_meta_data( $meta_key, $meta_value ); |
|
109 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') { |
|
110 | + $invoice = new WPInv_Invoice($invoice_id); |
|
111 | + return $invoice->update_meta_data($meta_key, $meta_value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @deprecated |
116 | 116 | */ |
117 | -function wpinv_get_items( $invoice = 0 ) { |
|
118 | - $invoice = new WPInv_Invoice( $invoice ); |
|
117 | +function wpinv_get_items($invoice = 0) { |
|
118 | + $invoice = new WPInv_Invoice($invoice); |
|
119 | 119 | return $invoice->get_items(); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @deprecated |
124 | 124 | */ |
125 | -function wpinv_get_fees( $invoice = 0 ) { |
|
126 | - $invoice = new WPInv_Invoice( $invoice ); |
|
125 | +function wpinv_get_fees($invoice = 0) { |
|
126 | + $invoice = new WPInv_Invoice($invoice); |
|
127 | 127 | return $invoice->get_fees(); |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @deprecated |
132 | 132 | */ |
133 | -function wpinv_get_invoice_ip( $invoice ) { |
|
134 | - $invoice = new WPInv_Invoice( $invoice ); |
|
133 | +function wpinv_get_invoice_ip($invoice) { |
|
134 | + $invoice = new WPInv_Invoice($invoice); |
|
135 | 135 | return $invoice->get_ip(); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @deprecated |
140 | 140 | */ |
141 | -function wpinv_get_invoice_user_info( $invoice ) { |
|
142 | - $invoice = new WPInv_Invoice( $invoice ); |
|
141 | +function wpinv_get_invoice_user_info($invoice) { |
|
142 | + $invoice = new WPInv_Invoice($invoice); |
|
143 | 143 | return $invoice->get_user_info(); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @deprecated |
148 | 148 | */ |
149 | -function wpinv_subtotal( $invoice = 0, $currency = false ) { |
|
150 | - $invoice = new WPInv_Invoice( $invoice ); |
|
149 | +function wpinv_subtotal($invoice = 0, $currency = false) { |
|
150 | + $invoice = new WPInv_Invoice($invoice); |
|
151 | 151 | $subtotal = $invoice->get_subtotal(); |
152 | 152 | |
153 | - if ( $currency ) { |
|
154 | - return wpinv_price( $subtotal, $invoice->get_currency() ); |
|
153 | + if ($currency) { |
|
154 | + return wpinv_price($subtotal, $invoice->get_currency()); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | return $subtotal; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | /** |
161 | 161 | * @deprecated |
162 | 162 | */ |
163 | -function wpinv_tax( $invoice = 0, $currency = false ) { |
|
164 | - $invoice = new WPInv_Invoice( $invoice ); |
|
163 | +function wpinv_tax($invoice = 0, $currency = false) { |
|
164 | + $invoice = new WPInv_Invoice($invoice); |
|
165 | 165 | $tax = $invoice->get_total_tax(); |
166 | 166 | |
167 | - if ( $currency ) { |
|
168 | - return wpinv_price( $tax, $invoice->get_currency() ); |
|
167 | + if ($currency) { |
|
168 | + return wpinv_price($tax, $invoice->get_currency()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $tax; |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @deprecated |
176 | 176 | */ |
177 | -function wpinv_discount( $invoice = 0, $currency = false ) { |
|
178 | - $invoice = new WPInv_Invoice( $invoice ); |
|
177 | +function wpinv_discount($invoice = 0, $currency = false) { |
|
178 | + $invoice = new WPInv_Invoice($invoice); |
|
179 | 179 | $discount = $invoice->get_total_discount(); |
180 | 180 | |
181 | - if ( $currency ) { |
|
182 | - return wpinv_price( $discount, $invoice->get_currency() ); |
|
181 | + if ($currency) { |
|
182 | + return wpinv_price($discount, $invoice->get_currency()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return $discount; |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @deprecated |
190 | 190 | */ |
191 | -function wpinv_discount_code( $invoice = 0 ) { |
|
192 | - $invoice = new WPInv_Invoice( $invoice ); |
|
191 | +function wpinv_discount_code($invoice = 0) { |
|
192 | + $invoice = new WPInv_Invoice($invoice); |
|
193 | 193 | return $invoice->get_discount_code(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @deprecated |
198 | 198 | */ |
199 | -function wpinv_payment_total( $invoice = 0, $currency = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice ); |
|
199 | +function wpinv_payment_total($invoice = 0, $currency = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice); |
|
201 | 201 | $total = $invoice->get_total(); |
202 | 202 | |
203 | - if ( $currency ) { |
|
204 | - return wpinv_price( $total, $invoice->get_currency() ); |
|
203 | + if ($currency) { |
|
204 | + return wpinv_price($total, $invoice->get_currency()); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $total; |
@@ -210,51 +210,51 @@ discard block |
||
210 | 210 | /** |
211 | 211 | * @deprecated |
212 | 212 | */ |
213 | -function wpinv_get_date_created( $invoice = 0, $format = '' ) { |
|
214 | - $invoice = new WPInv_Invoice( $invoice ); |
|
213 | +function wpinv_get_date_created($invoice = 0, $format = '') { |
|
214 | + $invoice = new WPInv_Invoice($invoice); |
|
215 | 215 | |
216 | - $format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
|
216 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
217 | 217 | $date_created = $invoice->get_created_date(); |
218 | 218 | |
219 | - return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
219 | + return empty($date_created) ? date_i18n($format, strtotime($date_created)) : ''; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @deprecated |
224 | 224 | */ |
225 | -function wpinv_get_invoice_date( $invoice = 0, $format = '' ) { |
|
226 | - wpinv_get_date_created( $invoice, $format ); |
|
225 | +function wpinv_get_invoice_date($invoice = 0, $format = '') { |
|
226 | + wpinv_get_date_created($invoice, $format); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * @deprecated |
231 | 231 | */ |
232 | -function wpinv_get_invoice_vat_number( $invoice = 0 ) { |
|
233 | - $invoice = new WPInv_Invoice( $invoice ); |
|
232 | +function wpinv_get_invoice_vat_number($invoice = 0) { |
|
233 | + $invoice = new WPInv_Invoice($invoice); |
|
234 | 234 | return $invoice->get_vat_number(); |
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @deprecated |
239 | 239 | */ |
240 | -function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
241 | - $invoice = new WPInv_Invoice( $invoice ); |
|
242 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
240 | +function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
241 | + $invoice = new WPInv_Invoice($invoice); |
|
242 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @deprecated |
247 | 247 | */ |
248 | -function wpinv_get_payment_key( $invoice = 0 ) { |
|
249 | - $invoice = new WPInv_Invoice( $invoice ); |
|
248 | +function wpinv_get_payment_key($invoice = 0) { |
|
249 | + $invoice = new WPInv_Invoice($invoice); |
|
250 | 250 | return $invoice->get_key(); |
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | 254 | * @deprecated |
255 | 255 | */ |
256 | -function wpinv_get_invoice_number( $invoice = 0 ) { |
|
257 | - $invoice = new WPInv_Invoice( $invoice ); |
|
256 | +function wpinv_get_invoice_number($invoice = 0) { |
|
257 | + $invoice = new WPInv_Invoice($invoice); |
|
258 | 258 | return $invoice->get_number(); |
259 | 259 | } |
260 | 260 | |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * @deprecated |
403 | 403 | */ |
404 | -function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) { |
|
405 | - $invoice = new WPInv_Invoice( $invoice ); |
|
406 | - return $invoice->update_status( $new_status ); |
|
404 | +function wpinv_update_payment_status($invoice, $new_status = 'publish') { |
|
405 | + $invoice = new WPInv_Invoice($invoice); |
|
406 | + return $invoice->update_status($new_status); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * @deprecated |
458 | 458 | */ |
459 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
459 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
460 | 460 | |
461 | 461 | // Fetch the invoice. |
462 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
462 | + $invoice = new WPInv_Invoice($invoice_id); |
|
463 | 463 | |
464 | - if ( 0 == $invoice->get_id() ) { |
|
464 | + if (0 == $invoice->get_id()) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Prepare the transaction id. |
469 | - if ( empty( $transaction_id ) ) { |
|
469 | + if (empty($transaction_id)) { |
|
470 | 470 | $transaction_id = $invoice_id; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Set the transaction id; |
474 | - $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) ); |
|
474 | + $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice)); |
|
475 | 475 | |
476 | 476 | // Save the invoice. |
477 | 477 | return $invoice->save(); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | * @param WPInv_Invoice $invoice |
485 | 485 | * @param string $gateway |
486 | 486 | */ |
487 | -function wpinv_send_to_gateway( $gateway, $invoice ) { |
|
487 | +function wpinv_send_to_gateway($gateway, $invoice) { |
|
488 | 488 | |
489 | 489 | $payment_data = array( |
490 | 490 | 'invoice_id' => $invoice->get_id(), |
491 | 491 | 'items' => $invoice->get_cart_details(), |
492 | - 'cart_discounts' => array( $invoice->get_discount_code() ), |
|
492 | + 'cart_discounts' => array($invoice->get_discount_code()), |
|
493 | 493 | 'fees' => $invoice->get_total_fees(), |
494 | 494 | 'subtotal' => $invoice->get_subtotal(), |
495 | 495 | 'discount' => $invoice->get_total_discount(), |
@@ -497,16 +497,16 @@ discard block |
||
497 | 497 | 'price' => $invoice->get_total(), |
498 | 498 | 'invoice_key' => $invoice->get_key(), |
499 | 499 | 'user_email' => $invoice->get_email(), |
500 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
500 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
501 | 501 | 'user_info' => $invoice->get_user_info(), |
502 | - 'post_data' => wp_kses_post( wp_unslash( $_POST ) ), |
|
502 | + 'post_data' => wp_kses_post(wp_unslash($_POST)), |
|
503 | 503 | 'cart_details' => $invoice->get_cart_details(), |
504 | 504 | 'gateway' => $gateway, |
505 | 505 | 'card_info' => array(), |
506 | - 'gateway_nonce' => wp_create_nonce( 'wpi-gateway' ), |
|
506 | + 'gateway_nonce' => wp_create_nonce('wpi-gateway'), |
|
507 | 507 | ); |
508 | 508 | |
509 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
509 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | /** |
520 | 520 | * @deprecated |
521 | 521 | */ |
522 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
523 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
524 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
525 | - wp_die( esc_html( $message ), esc_html( $title ), array( 'response' => (int) $status ) ); |
|
522 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
523 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
524 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
525 | + wp_die(esc_html($message), esc_html($title), array('response' => (int) $status)); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -640,14 +640,14 @@ discard block |
||
640 | 640 | /** |
641 | 641 | * @deprecated |
642 | 642 | */ |
643 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
644 | - return empty( $status_display ) ? sanitize_text_field( $status ) : sanitize_text_field( $status_display ); |
|
643 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
644 | + return empty($status_display) ? sanitize_text_field($status) : sanitize_text_field($status_display); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | 648 | * @deprecated |
649 | 649 | */ |
650 | -function wpinv_clean_invoice_number( $number ) { |
|
650 | +function wpinv_clean_invoice_number($number) { |
|
651 | 651 | return $number; |
652 | 652 | } |
653 | 653 | |
@@ -852,12 +852,12 @@ discard block |
||
852 | 852 | /** |
853 | 853 | * @deprecated |
854 | 854 | */ |
855 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
855 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
856 | 856 | |
857 | - if ( $echo ) { |
|
858 | - echo wp_kses_post( wpinv_item_price( $item_id ) ); |
|
857 | + if ($echo) { |
|
858 | + echo wp_kses_post(wpinv_item_price($item_id)); |
|
859 | 859 | } else { |
860 | - return wpinv_item_price( $item_id ); |
|
860 | + return wpinv_item_price($item_id); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | } |
@@ -1272,6 +1272,6 @@ discard block |
||
1272 | 1272 | * @return WPInv_Subscription|bool |
1273 | 1273 | * @deprecated |
1274 | 1274 | */ |
1275 | -function wpinv_get_subscription( $invoice ) { |
|
1276 | - return wpinv_get_invoice_subscription( $invoice ); |
|
1275 | +function wpinv_get_subscription($invoice) { |
|
1276 | + return wpinv_get_invoice_subscription($invoice); |
|
1277 | 1277 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Bank transfer Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
44 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
45 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
42 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
43 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
44 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
45 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
48 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
49 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
50 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
51 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
52 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + public function process_payment($invoice, $submission_data, $submission) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
67 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
68 | 68 | |
69 | 69 | // Set it as pending payment. |
70 | - if ( ! $invoice->needs_payment() ) { |
|
70 | + if (!$invoice->needs_payment()) { |
|
71 | 71 | $invoice->mark_paid(); |
72 | - } elseif ( ! $invoice->is_paid() ) { |
|
73 | - $invoice->set_status( 'wpi-onhold' ); |
|
72 | + } elseif (!$invoice->is_paid()) { |
|
73 | + $invoice->set_status('wpi-onhold'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Save it. |
77 | 77 | $invoice->save(); |
78 | 78 | |
79 | 79 | // Send to the success page. |
80 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
80 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -86,17 +86,17 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WPInv_Invoice $invoice Invoice. |
88 | 88 | */ |
89 | - public function thankyou_page( $invoice ) { |
|
89 | + public function thankyou_page($invoice) { |
|
90 | 90 | |
91 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
91 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
92 | 92 | |
93 | 93 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
94 | 94 | |
95 | - if ( ! empty( $this->instructions ) ) { |
|
96 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
95 | + if (!empty($this->instructions)) { |
|
96 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
97 | 97 | } |
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details($invoice); |
|
100 | 100 | |
101 | 101 | echo '</div>'; |
102 | 102 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | * @param string $email_type Email format: plain text or HTML. |
112 | 112 | * @param bool $sent_to_admin Sent to admin. |
113 | 113 | */ |
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
114 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
117 | 117 | |
118 | 118 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ($this->instructions) { |
|
121 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details($invoice); |
|
125 | 125 | |
126 | 126 | echo '</div>'; |
127 | 127 | |
@@ -134,50 +134,50 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Invoice $invoice Invoice. |
136 | 136 | */ |
137 | - protected function bank_details( $invoice ) { |
|
137 | + protected function bank_details($invoice) { |
|
138 | 138 | |
139 | 139 | // Get the invoice country and country $locale. |
140 | 140 | $country = $invoice->get_country(); |
141 | 141 | $locale = $this->get_country_locale(); |
142 | 142 | |
143 | 143 | // Get sortcode label in the $locale array and use appropriate one. |
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
144 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
148 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
149 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
150 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
151 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
152 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
147 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
148 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
149 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
150 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
151 | + 'iban' => __('IBAN', 'invoicing'), |
|
152 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
153 | 153 | 'sort_code' => $sortcode, |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $bank_info = array(); |
157 | 157 | |
158 | - foreach ( $bank_fields as $field => $label ) { |
|
159 | - $value = $this->get_option( $field ); |
|
158 | + foreach ($bank_fields as $field => $label) { |
|
159 | + $value = $this->get_option($field); |
|
160 | 160 | |
161 | - if ( ! empty( $value ) ) { |
|
162 | - $bank_info[ $field ] = array( |
|
161 | + if (!empty($value)) { |
|
162 | + $bank_info[$field] = array( |
|
163 | 163 | 'label' => $label, |
164 | 164 | 'value' => $value, |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info ); |
|
169 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info); |
|
170 | 170 | |
171 | - if ( empty( $bank_info ) ) { |
|
171 | + if (empty($bank_info)) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'))) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | 177 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . "</td></tr>" . PHP_EOL; |
|
179 | + foreach ($bank_info as $key => $data) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . "</td></tr>" . PHP_EOL; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | echo '</table>'; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function get_country_locale() { |
193 | 193 | |
194 | - if ( empty( $this->locale ) ) { |
|
194 | + if (empty($this->locale)) { |
|
195 | 195 | |
196 | 196 | // Locale information to be used - only those that are not 'Sort Code'. |
197 | 197 | $this->locale = apply_filters( |
@@ -199,42 +199,42 @@ discard block |
||
199 | 199 | array( |
200 | 200 | 'AU' => array( |
201 | 201 | 'sortcode' => array( |
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
202 | + 'label' => __('BSB', 'invoicing'), |
|
203 | 203 | ), |
204 | 204 | ), |
205 | 205 | 'CA' => array( |
206 | 206 | 'sortcode' => array( |
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
207 | + 'label' => __('Bank transit number', 'invoicing'), |
|
208 | 208 | ), |
209 | 209 | ), |
210 | 210 | 'IN' => array( |
211 | 211 | 'sortcode' => array( |
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
212 | + 'label' => __('IFSC', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | ), |
215 | 215 | 'IT' => array( |
216 | 216 | 'sortcode' => array( |
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
217 | + 'label' => __('Branch sort', 'invoicing'), |
|
218 | 218 | ), |
219 | 219 | ), |
220 | 220 | 'NZ' => array( |
221 | 221 | 'sortcode' => array( |
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | + 'label' => __('Bank code', 'invoicing'), |
|
223 | 223 | ), |
224 | 224 | ), |
225 | 225 | 'SE' => array( |
226 | 226 | 'sortcode' => array( |
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
227 | + 'label' => __('Bank code', 'invoicing'), |
|
228 | 228 | ), |
229 | 229 | ), |
230 | 230 | 'US' => array( |
231 | 231 | 'sortcode' => array( |
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
232 | + 'label' => __('Routing number', 'invoicing'), |
|
233 | 233 | ), |
234 | 234 | ), |
235 | 235 | 'ZA' => array( |
236 | 236 | 'sortcode' => array( |
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
237 | + 'label' => __('Branch code', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | ), |
240 | 240 | ) |
@@ -251,51 +251,51 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param array $admin_settings |
253 | 253 | */ |
254 | - public function admin_settings( $admin_settings ) { |
|
254 | + public function admin_settings($admin_settings) { |
|
255 | 255 | |
256 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
256 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | 261 | // Get sortcode label in the $locale array and use appropriate one. |
262 | 262 | $country = wpinv_default_billing_country(); |
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
263 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
264 | 264 | |
265 | 265 | $admin_settings['bank_transfer_ac_name'] = array( |
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
268 | + 'name' => __('Account Name', 'invoicing'), |
|
269 | 269 | ); |
270 | 270 | |
271 | 271 | $admin_settings['bank_transfer_ac_no'] = array( |
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
274 | + 'name' => __('Account Number', 'invoicing'), |
|
275 | 275 | ); |
276 | 276 | |
277 | 277 | $admin_settings['bank_transfer_bank_name'] = array( |
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
280 | + 'name' => __('Bank Name', 'invoicing'), |
|
281 | 281 | ); |
282 | 282 | |
283 | 283 | $admin_settings['bank_transfer_ifsc'] = array( |
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
286 | + 'name' => __('IFSC Code', 'invoicing'), |
|
287 | 287 | ); |
288 | 288 | |
289 | 289 | $admin_settings['bank_transfer_iban'] = array( |
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
292 | + 'name' => __('IBAN', 'invoicing'), |
|
293 | 293 | ); |
294 | 294 | |
295 | 295 | $admin_settings['bank_transfer_bic'] = array( |
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
298 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
299 | 299 | ); |
300 | 300 | |
301 | 301 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | |
307 | 307 | $admin_settings['bank_transfer_info'] = array( |
308 | 308 | 'id' => 'bank_transfer_info', |
309 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
310 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
309 | + 'name' => __('Instructions', 'invoicing'), |
|
310 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
311 | 311 | 'type' => 'textarea', |
312 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
312 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
313 | 313 | 'cols' => 50, |
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param GetPaid_Form_Item[] $items |
325 | 325 | * @return WPInv_Invoice |
326 | 326 | */ |
327 | - public function process_addons( $invoice, $items ) { |
|
327 | + public function process_addons($invoice, $items) { |
|
328 | 328 | |
329 | - foreach ( $items as $item ) { |
|
330 | - $invoice->add_item( $item ); |
|
329 | + foreach ($items as $item) { |
|
330 | + $invoice->add_item($item); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @param WPInv_Subscription $subscription |
342 | 342 | */ |
343 | - public function maybe_renew_subscription( $subscription ) { |
|
343 | + public function maybe_renew_subscription($subscription) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
346 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
347 | 347 | $subscription->create_payment(); |
348 | 348 | } |
349 | 349 | |
@@ -355,41 +355,41 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function invoice_paid( $invoice ) { |
|
358 | + public function invoice_paid($invoice) { |
|
359 | 359 | |
360 | 360 | // Abort if not paid by bank transfer. |
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
361 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Is it a parent payment? |
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
366 | + if (0 == $invoice->get_parent_id()) { |
|
367 | 367 | |
368 | 368 | // (Maybe) activate subscriptions. |
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
370 | 370 | |
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
371 | + if (!empty($subscriptions)) { |
|
372 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
373 | 373 | |
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
374 | + foreach ($subscriptions as $subscription) { |
|
375 | + if ($subscription->exists()) { |
|
376 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
377 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
378 | 378 | |
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
379 | + $subscription->set_next_renewal_date($expiry); |
|
380 | + $subscription->set_date_created(current_time('mysql')); |
|
381 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
382 | 382 | $subscription->activate(); |
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
389 | 389 | |
390 | 390 | // Renew the subscription. |
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
391 | + if ($subscription && $subscription->exists()) { |
|
392 | + $subscription->add_payment(array(), $invoice); |
|
393 | 393 | $subscription->renew(); |
394 | 394 | } |
395 | 395 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Abstaract Payment Gateway class. |
@@ -139,50 +139,50 @@ discard block |
||
139 | 139 | public function __construct() { |
140 | 140 | |
141 | 141 | // Register gateway. |
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
142 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
143 | 143 | |
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
144 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
145 | 145 | |
146 | 146 | // Add support for various features. |
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
147 | + foreach ($this->supports as $feature) { |
|
148 | + add_filter("wpinv_{$this->id}_support_{$feature}", '__return_true'); |
|
149 | + add_filter("getpaid_{$this->id}_support_{$feature}", '__return_true'); |
|
150 | + add_filter("getpaid_{$this->id}_supports_{$feature}", '__return_true'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Invoice addons. |
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
154 | + if ($this->supports('addons')) { |
|
155 | + add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Gateway settings. |
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
159 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
160 | 160 | |
161 | 161 | // Gateway checkout fiellds. |
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
163 | 163 | |
164 | 164 | // Process payment. |
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
165 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
166 | 166 | |
167 | 167 | // Change the checkout button text. |
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | + if (!empty($this->checkout_button_text)) { |
|
169 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Check if a gateway is valid for a given currency. |
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
174 | 174 | |
175 | 175 | // Generate the transaction url. |
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
177 | 177 | |
178 | 178 | // Generate the subscription url. |
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
179 | + add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2); |
|
180 | 180 | |
181 | 181 | // Confirm payments. |
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
183 | 183 | |
184 | 184 | // Verify IPNs. |
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
186 | 186 | |
187 | 187 | } |
188 | 188 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @since 1.0.19 |
193 | 193 | * @return bool |
194 | 194 | */ |
195 | - public function is( $gateway ) { |
|
195 | + public function is($gateway) { |
|
196 | 196 | return $gateway == $this->id; |
197 | 197 | } |
198 | 198 | |
@@ -202,23 +202,23 @@ discard block |
||
202 | 202 | * @since 1.0.19 |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - public function get_tokens( $sandbox = null ) { |
|
205 | + public function get_tokens($sandbox = null) { |
|
206 | 206 | |
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
208 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
209 | 209 | |
210 | - if ( is_array( $tokens ) ) { |
|
210 | + if (is_array($tokens)) { |
|
211 | 211 | $this->tokens = $tokens; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
215 | + if (!is_bool($sandbox)) { |
|
216 | 216 | return $this->tokens; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Filter tokens. |
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
220 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
221 | + return wp_list_filter($this->tokens, $args); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @since 1.0.19 |
229 | 229 | */ |
230 | - public function save_token( $token ) { |
|
230 | + public function save_token($token) { |
|
231 | 231 | |
232 | 232 | $tokens = $this->get_tokens(); |
233 | 233 | $tokens[] = $token; |
234 | 234 | |
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
235 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
236 | 236 | |
237 | 237 | $this->tokens = $tokens; |
238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return string |
245 | 245 | */ |
246 | 246 | public function get_method_title() { |
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
247 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return string |
254 | 254 | */ |
255 | 255 | public function get_method_description() { |
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
256 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param WPInv_Invoice $invoice Invoice object. |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public function get_return_url( $invoice ) { |
|
265 | + public function get_return_url($invoice) { |
|
266 | 266 | |
267 | 267 | // Payment success url |
268 | 268 | $return_url = add_query_arg( |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | wpinv_get_success_page_uri() |
275 | 275 | ); |
276 | 276 | |
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
277 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -283,24 +283,24 @@ discard block |
||
283 | 283 | * @param string $content Success page content. |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - public function confirm_payment( $content ) { |
|
286 | + public function confirm_payment($content) { |
|
287 | 287 | |
288 | 288 | // Retrieve the invoice. |
289 | 289 | $invoice_id = getpaid_get_current_invoice_id(); |
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
290 | + $invoice = wpinv_get_invoice($invoice_id); |
|
291 | 291 | |
292 | 292 | // Ensure that it exists and that it is pending payment. |
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
293 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
294 | 294 | return $content; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Can the user view this invoice?? |
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
298 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
299 | 299 | return $content; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Show payment processing indicator. |
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
303 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @param GetPaid_Form_Item[] $items |
318 | 318 | * @return WPInv_Invoice |
319 | 319 | */ |
320 | - public function process_addons( $invoice, $items ) { |
|
320 | + public function process_addons($invoice, $items) { |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * @param WPInv_Invoice $invoice Invoice object. |
329 | 329 | * @return string transaction URL, or empty string. |
330 | 330 | */ |
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
331 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
332 | 332 | |
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | 334 | |
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
335 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
336 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
337 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $transaction_url; |
@@ -348,15 +348,15 @@ discard block |
||
348 | 348 | * @param WPInv_Subscription $subscription Subscription objectt. |
349 | 349 | * @return string subscription URL, or empty string. |
350 | 350 | */ |
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
351 | + public function generate_subscription_url($subscription_url, $subscription) { |
|
352 | 352 | |
353 | - $profile_id = $subscription->get_profile_id(); |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | 354 | |
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
355 | + if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) { |
|
356 | 356 | |
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
357 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
358 | + $replace = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
360 | 360 | |
361 | 361 | } |
362 | 362 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return bool |
370 | 370 | */ |
371 | 371 | public function is_available() { |
372 | - return ! empty( $this->enabled ); |
|
372 | + return !empty($this->enabled); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @return string |
379 | 379 | */ |
380 | 380 | public function get_title() { |
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
381 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @return string |
388 | 388 | */ |
389 | 389 | public function get_description() { |
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
390 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -399,9 +399,9 @@ discard block |
||
399 | 399 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
400 | 400 | * @return void |
401 | 401 | */ |
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
402 | + public function process_payment($invoice, $submission_data, $submission) { |
|
403 | 403 | // Process the payment then either redirect to the success page or the gateway. |
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
404 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | * @param string $reason Refund reason. |
416 | 416 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
417 | 417 | */ |
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
418 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
419 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | * @param int $invoice_id 0 or invoice id. |
426 | 426 | * @param GetPaid_Payment_Form $form Current payment form. |
427 | 427 | */ |
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
428 | + public function payment_fields($invoice_id, $form) { |
|
429 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @param array $admin_settings |
436 | 436 | */ |
437 | - public function admin_settings( $admin_settings ) { |
|
437 | + public function admin_settings($admin_settings) { |
|
438 | 438 | return $admin_settings; |
439 | 439 | } |
440 | 440 | |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @param string $option |
445 | 445 | */ |
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
446 | + public function get_option($option, $default = false) { |
|
447 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -457,8 +457,8 @@ discard block |
||
457 | 457 | * @return bool True if the gateway supports the feature, false otherwise. |
458 | 458 | * @since 1.0.19 |
459 | 459 | */ |
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
460 | + public function supports($feature) { |
|
461 | + return getpaid_payment_gateway_supports($this->id, $feature); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -466,36 +466,36 @@ discard block |
||
466 | 466 | * |
467 | 467 | * @param bool $save whether or not to display the save button. |
468 | 468 | */ |
469 | - public function get_cc_form( $save = false ) { |
|
469 | + public function get_cc_form($save = false) { |
|
470 | 470 | |
471 | 471 | ob_start(); |
472 | 472 | |
473 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
473 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
474 | 474 | |
475 | 475 | $months = array( |
476 | - '01' => __( 'January', 'invoicing' ), |
|
477 | - '02' => __( 'February', 'invoicing' ), |
|
478 | - '03' => __( 'March', 'invoicing' ), |
|
479 | - '04' => __( 'April', 'invoicing' ), |
|
480 | - '05' => __( 'May', 'invoicing' ), |
|
481 | - '06' => __( 'June', 'invoicing' ), |
|
482 | - '07' => __( 'July', 'invoicing' ), |
|
483 | - '08' => __( 'August', 'invoicing' ), |
|
484 | - '09' => __( 'September', 'invoicing' ), |
|
485 | - '10' => __( 'October', 'invoicing' ), |
|
486 | - '11' => __( 'November', 'invoicing' ), |
|
487 | - '12' => __( 'December', 'invoicing' ), |
|
476 | + '01' => __('January', 'invoicing'), |
|
477 | + '02' => __('February', 'invoicing'), |
|
478 | + '03' => __('March', 'invoicing'), |
|
479 | + '04' => __('April', 'invoicing'), |
|
480 | + '05' => __('May', 'invoicing'), |
|
481 | + '06' => __('June', 'invoicing'), |
|
482 | + '07' => __('July', 'invoicing'), |
|
483 | + '08' => __('August', 'invoicing'), |
|
484 | + '09' => __('September', 'invoicing'), |
|
485 | + '10' => __('October', 'invoicing'), |
|
486 | + '11' => __('November', 'invoicing'), |
|
487 | + '12' => __('December', 'invoicing'), |
|
488 | 488 | ); |
489 | 489 | |
490 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
490 | + $year = (int) date('Y', current_time('timestamp')); |
|
491 | 491 | $years = array(); |
492 | 492 | |
493 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
494 | - $years[ $year + $i ] = $year + $i; |
|
493 | + for ($i = 0; $i <= 10; $i++) { |
|
494 | + $years[$year + $i] = $year + $i; |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | ?> |
498 | - <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
|
498 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1"> |
|
499 | 499 | |
500 | 500 | |
501 | 501 | <div class="getpaid-cc-card-inner"> |
@@ -504,14 +504,14 @@ discard block |
||
504 | 504 | <div class="col-12"> |
505 | 505 | |
506 | 506 | <div class="form-group"> |
507 | - <label for="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>"><?php esc_html_e( 'Card number', 'invoicing' ); ?></label> |
|
507 | + <label for="<?php echo esc_attr("$id_prefix-cc-number"); ?>"><?php esc_html_e('Card number', 'invoicing'); ?></label> |
|
508 | 508 | <div class="input-group input-group-sm"> |
509 | 509 | <div class="input-group-prepend "> |
510 | 510 | <span class="input-group-text"> |
511 | 511 | <i class="fa fa-credit-card"></i> |
512 | 512 | </span> |
513 | 513 | </div> |
514 | - <input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ); ?>" id="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
514 | + <input type="text" name="<?php echo esc_attr($this->id . '[cc_number]'); ?>" id="<?php echo esc_attr("$id_prefix-cc-number"); ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
515 | 515 | </div> |
516 | 516 | </div> |
517 | 517 | |
@@ -519,16 +519,16 @@ discard block |
||
519 | 519 | |
520 | 520 | <div class="col-12"> |
521 | 521 | <div class="form-group"> |
522 | - <label><?php esc_html_e( 'Expiration', 'invoicing' ); ?></label> |
|
522 | + <label><?php esc_html_e('Expiration', 'invoicing'); ?></label> |
|
523 | 523 | <div class="form-row"> |
524 | 524 | |
525 | 525 | <div class="col"> |
526 | - <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_month]"> |
|
527 | - <option disabled selected="selected"><?php esc_html_e( 'MM', 'invoicing' ); ?></option> |
|
526 | + <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
527 | + <option disabled selected="selected"><?php esc_html_e('MM', 'invoicing'); ?></option> |
|
528 | 528 | |
529 | 529 | <?php |
530 | - foreach ( $months as $key => $month ) { |
|
531 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . "</option>" . PHP_EOL; |
|
530 | + foreach ($months as $key => $month) { |
|
531 | + echo "<option value='" . esc_attr($key) . "'>" . esc_html($month) . "</option>" . PHP_EOL; |
|
532 | 532 | } |
533 | 533 | ?> |
534 | 534 | |
@@ -536,12 +536,12 @@ discard block |
||
536 | 536 | </div> |
537 | 537 | |
538 | 538 | <div class="col"> |
539 | - <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_year]"> |
|
540 | - <option disabled selected="selected"><?php esc_html_e( 'YY', 'invoicing' ); ?></option> |
|
539 | + <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
540 | + <option disabled selected="selected"><?php esc_html_e('YY', 'invoicing'); ?></option> |
|
541 | 541 | |
542 | 542 | <?php |
543 | - foreach ( $years as $key => $year ) { |
|
544 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . "</option>" . PHP_EOL; |
|
543 | + foreach ($years as $key => $year) { |
|
544 | + echo "<option value='" . esc_attr($key) . "'>" . esc_html($year) . "</option>" . PHP_EOL; |
|
545 | 545 | } |
546 | 546 | ?> |
547 | 547 | |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | array( |
559 | 559 | 'name' => $this->id . '[cc_cvv2]', |
560 | 560 | 'id' => "$id_prefix-cc-cvv2", |
561 | - 'label' => __( 'CCV', 'invoicing' ), |
|
561 | + 'label' => __('CCV', 'invoicing'), |
|
562 | 562 | 'label_type' => 'vertical', |
563 | 563 | 'class' => 'form-control-sm', |
564 | 564 | 'extra_attributes' => array( |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | |
575 | 575 | <?php |
576 | 576 | |
577 | - if ( $save ) { |
|
577 | + if ($save) { |
|
578 | 578 | $this->save_payment_method_checkbox(); |
579 | 579 | } |
580 | 580 | |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | * |
594 | 594 | * @since 1.0.19 |
595 | 595 | */ |
596 | - public function new_payment_method_entry( $form ) { |
|
597 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . " . </div>"; |
|
596 | + public function new_payment_method_entry($form) { |
|
597 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses($form, getpaid_allowed_html()) . " . </div>"; |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -603,10 +603,10 @@ discard block |
||
603 | 603 | * @since 1.0.19 |
604 | 604 | */ |
605 | 605 | public function saved_payment_methods() { |
606 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
606 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
607 | 607 | |
608 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
609 | - $this->get_saved_payment_method_option_html( $token ); |
|
608 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
609 | + $this->get_saved_payment_method_option_html($token); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | $this->get_new_payment_method_option_html(); |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * @param array $token Payment Token. |
622 | 622 | * @return string Generated payment method HTML |
623 | 623 | */ |
624 | - public function get_saved_payment_method_option_html( $token ) { |
|
624 | + public function get_saved_payment_method_option_html($token) { |
|
625 | 625 | |
626 | 626 | printf( |
627 | 627 | '<li class="getpaid-payment-method form-group"> |
@@ -630,11 +630,11 @@ discard block |
||
630 | 630 | <span>%3$s</span> |
631 | 631 | </label> |
632 | 632 | </li>', |
633 | - esc_attr( $this->id ), |
|
634 | - esc_attr( $token['id'] ), |
|
635 | - esc_html( $token['name'] ), |
|
636 | - checked( empty( $token['default'] ), false, false ), |
|
637 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
633 | + esc_attr($this->id), |
|
634 | + esc_attr($token['id']), |
|
635 | + esc_html($token['name']), |
|
636 | + checked(empty($token['default']), false, false), |
|
637 | + empty($token['currency']) ? 'none' : esc_attr($token['currency']) |
|
638 | 638 | ); |
639 | 639 | |
640 | 640 | } |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | */ |
647 | 647 | public function get_new_payment_method_option_html() { |
648 | 648 | |
649 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
649 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
650 | 650 | |
651 | 651 | printf( |
652 | 652 | '<li class="getpaid-new-payment-method"> |
@@ -655,8 +655,8 @@ discard block |
||
655 | 655 | <span>%2$s</span> |
656 | 656 | </label> |
657 | 657 | </li>', |
658 | - esc_attr( $this->id ), |
|
659 | - esc_html( $label ) |
|
658 | + esc_attr($this->id), |
|
659 | + esc_html($label) |
|
660 | 660 | ); |
661 | 661 | |
662 | 662 | } |
@@ -671,10 +671,10 @@ discard block |
||
671 | 671 | aui()->input( |
672 | 672 | array( |
673 | 673 | 'type' => 'checkbox', |
674 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
675 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
674 | + 'name' => esc_attr("getpaid-$this->id-new-payment-method"), |
|
675 | + 'id' => esc_attr(uniqid($this->id)), |
|
676 | 676 | 'required' => false, |
677 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
677 | + 'label' => esc_html__('Save payment method', 'invoicing'), |
|
678 | 678 | 'value' => 'true', |
679 | 679 | 'checked' => true, |
680 | 680 | 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
@@ -689,9 +689,9 @@ discard block |
||
689 | 689 | * |
690 | 690 | * @return array |
691 | 691 | */ |
692 | - public function register_gateway( $gateways ) { |
|
692 | + public function register_gateway($gateways) { |
|
693 | 693 | |
694 | - $gateways[ $this->id ] = array( |
|
694 | + $gateways[$this->id] = array( |
|
695 | 695 | |
696 | 696 | 'admin_label' => $this->method_title, |
697 | 697 | 'checkout_label' => $this->title, |
@@ -709,13 +709,13 @@ discard block |
||
709 | 709 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
710 | 710 | * @return bool |
711 | 711 | */ |
712 | - public function is_sandbox( $invoice = null ) { |
|
712 | + public function is_sandbox($invoice = null) { |
|
713 | 713 | |
714 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
714 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
715 | 715 | return $invoice->get_mode() == 'test'; |
716 | 716 | } |
717 | 717 | |
718 | - return wpinv_is_test_mode( $this->id ); |
|
718 | + return wpinv_is_test_mode($this->id); |
|
719 | 719 | |
720 | 720 | } |
721 | 721 | |
@@ -733,15 +733,15 @@ discard block |
||
733 | 733 | * |
734 | 734 | * @return bool |
735 | 735 | */ |
736 | - public function validate_currency( $validation, $currency ) { |
|
736 | + public function validate_currency($validation, $currency) { |
|
737 | 737 | |
738 | 738 | // Required currencies. |
739 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
739 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
740 | 740 | return false; |
741 | 741 | } |
742 | 742 | |
743 | 743 | // Excluded currencies. |
744 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
744 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
745 | 745 | return false; |
746 | 746 | } |
747 | 747 | |
@@ -752,13 +752,13 @@ discard block |
||
752 | 752 | * Displays an error |
753 | 753 | * |
754 | 754 | */ |
755 | - public function show_error( $code, $message, $type ) { |
|
755 | + public function show_error($code, $message, $type) { |
|
756 | 756 | |
757 | - if ( is_admin() ) { |
|
758 | - getpaid_admin()->{"show_$type"}( $message ); |
|
757 | + if (is_admin()) { |
|
758 | + getpaid_admin()->{"show_$type"}($message); |
|
759 | 759 | } |
760 | 760 | |
761 | - wpinv_set_error( $code, $message, $type ); |
|
761 | + wpinv_set_error($code, $message, $type); |
|
762 | 762 | |
763 | 763 | } |
764 | 764 |
@@ -4,7 +4,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ), |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ), |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | |
142 | 142 | // In case the payment profile already exists remotely. |
143 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
144 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
145 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
146 | - return strtok( '.' ); |
|
143 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
144 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
145 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
146 | + return strtok('.'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // In case the customer profile already exists remotely. |
150 | - if ( 'E00039' == $response->get_error_code() ) { |
|
151 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
152 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
153 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
150 | + if ('E00039' == $response->get_error_code()) { |
|
151 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
152 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
153 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $response; |
157 | 157 | } |
158 | 158 | |
159 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
159 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
160 | 160 | |
161 | 161 | // Save the payment token. |
162 | - if ( $save ) { |
|
162 | + if ($save) { |
|
163 | 163 | $this->save_token( |
164 | 164 | array( |
165 | 165 | 'id' => $response->customerPaymentProfileIdList[0], |
166 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
166 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
167 | 167 | 'default' => true, |
168 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
168 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Add a note about the validation response. |
174 | 174 | $invoice->add_note( |
175 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
175 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
176 | 176 | false, |
177 | 177 | false, |
178 | 178 | true |
@@ -189,7 +189,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | // Save the payment token. |
277 | - if ( $save ) { |
|
277 | + if ($save) { |
|
278 | 278 | $this->save_token( |
279 | 279 | array( |
280 | 280 | 'id' => $response->customerPaymentProfileId, |
281 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
281 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
282 | 282 | 'default' => true, |
283 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
283 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
284 | 284 | ) |
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Cache payment profile id. |
289 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
289 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
290 | 290 | |
291 | 291 | // Add a note about the validation response. |
292 | 292 | $invoice->add_note( |
293 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
293 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
294 | 294 | false, |
295 | 295 | false, |
296 | 296 | true |
297 | 297 | ); |
298 | 298 | |
299 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
299 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
300 | 300 | |
301 | 301 | return $response->customerPaymentProfileId; |
302 | 302 | } |
@@ -308,12 +308,12 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
353 | + if ('objects' == $return && 'view' == $context) { |
|
354 | 354 | return $prepared; |
355 | 355 | } |
356 | 356 | |
357 | 357 | $items = array(); |
358 | - foreach ( $prepared as $item ) { |
|
358 | + foreach ($prepared as $item) { |
|
359 | 359 | $items[] = $item->prepare_data_for_use(); |
360 | 360 | } |
361 | 361 | |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | * @param int $item_id The item id to return. |
370 | 370 | * @return GetPaid_Form_Item|bool |
371 | 371 | */ |
372 | - public function get_item( $item_id ) { |
|
372 | + public function get_item($item_id) { |
|
373 | 373 | |
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
374 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
378 | + foreach ($this->get_items() as $item) { |
|
379 | + if ($item->get_id() == (int) $item_id) { |
|
380 | 380 | return $item; |
381 | 381 | } |
382 | 382 | } |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param string $element_type The element type to return. |
393 | 393 | * @return array|bool |
394 | 394 | */ |
395 | - public function get_element_type( $element_type ) { |
|
395 | + public function get_element_type($element_type) { |
|
396 | 396 | |
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
397 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
401 | + foreach ($this->get_prop('elements') as $element) { |
|
402 | 402 | |
403 | - if ( $element['type'] == $element_type ) { |
|
403 | + if ($element['type'] == $element_type) { |
|
404 | 404 | return $element; |
405 | 405 | } |
406 | 406 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return float |
418 | 418 | */ |
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
419 | + public function get_earned($context = 'view') { |
|
420 | + return $this->get_prop('earned', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return float |
429 | 429 | */ |
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
430 | + public function get_refunded($context = 'view') { |
|
431 | + return $this->get_prop('refunded', $context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return float |
440 | 440 | */ |
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
441 | + public function get_cancelled($context = 'view') { |
|
442 | + return $this->get_prop('cancelled', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
452 | + public function get_failed($context = 'view') { |
|
453 | + return $this->get_prop('failed', $context); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @return string |
462 | 462 | */ |
463 | 463 | public function get_currency() { |
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
464 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /* |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @since 1.0.19 |
482 | 482 | */ |
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
483 | + public function set_version($value) { |
|
484 | + $this->set_prop('version', $value); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @param string $value Value to set. |
492 | 492 | * @return bool Whether or not the date was set. |
493 | 493 | */ |
494 | - public function set_date_created( $value ) { |
|
495 | - $date = strtotime( $value ); |
|
494 | + public function set_date_created($value) { |
|
495 | + $date = strtotime($value); |
|
496 | 496 | |
497 | - if ( $date ) { |
|
498 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
497 | + if ($date) { |
|
498 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | * @param string $value Value to set. |
511 | 511 | * @return bool Whether or not the date was set. |
512 | 512 | */ |
513 | - public function set_date_modified( $value ) { |
|
514 | - $date = strtotime( $value ); |
|
513 | + public function set_date_modified($value) { |
|
514 | + $date = strtotime($value); |
|
515 | 515 | |
516 | - if ( $date ) { |
|
517 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
516 | + if ($date) { |
|
517 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @since 1.0.19 |
529 | 529 | * @param string $value New name. |
530 | 530 | */ |
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
531 | + public function set_name($value) { |
|
532 | + $this->set_prop('name', sanitize_text_field($value)); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @since 1.0.19 |
539 | 539 | * @param string $value New name. |
540 | 540 | */ |
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
541 | + public function set_title($value) { |
|
542 | + $this->set_name($value); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | * @since 1.0.19 |
549 | 549 | * @param int $value New author. |
550 | 550 | */ |
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
551 | + public function set_author($value) { |
|
552 | + $this->set_prop('author', (int) $value); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | * @sinve 2.3.4 Array values sanitized. |
560 | 560 | * @param array $value Form elements. |
561 | 561 | */ |
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
562 | + public function set_elements($value) { |
|
563 | + if (is_array($value)) { |
|
564 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -572,36 +572,36 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed |
574 | 574 | */ |
575 | - public function sanitize_array_values( $value ) { |
|
575 | + public function sanitize_array_values($value) { |
|
576 | 576 | |
577 | 577 | // sanitize |
578 | - if ( ! empty( $value ) ) { |
|
578 | + if (!empty($value)) { |
|
579 | 579 | |
580 | - foreach ( $value as $key => $val_arr ) { |
|
580 | + foreach ($value as $key => $val_arr) { |
|
581 | 581 | |
582 | - if ( is_array( $val_arr ) ) { |
|
582 | + if (is_array($val_arr)) { |
|
583 | 583 | // check if we have sub array items. |
584 | 584 | $sub_arr = array(); |
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
585 | + foreach ($val_arr as $key2 => $val2) { |
|
586 | + if (is_array($val2)) { |
|
587 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
588 | + unset($val_arr[$key][$key2]); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | 592 | // we allow some html in description so we sanitize it separately. |
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
593 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
594 | 594 | |
595 | 595 | // sanitize array elements |
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
596 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
597 | 597 | |
598 | 598 | // add back the description if set |
599 | - if ( isset( $val_arr['description'] ) ) { |
|
600 | -$value[ $key ]['description'] = $help_text;} |
|
599 | + if (isset($val_arr['description'])) { |
|
600 | +$value[$key]['description'] = $help_text; } |
|
601 | 601 | |
602 | 602 | // add back sub array items after its been sanitized. |
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
603 | + if (!empty($sub_arr)) { |
|
604 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @since 1.0.19 |
617 | 617 | * @param array $value Form elements. |
618 | 618 | */ |
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
619 | + public function set_items($value) { |
|
620 | + if (is_array($value)) { |
|
621 | + $this->set_prop('items', $value); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -628,9 +628,9 @@ discard block |
||
628 | 628 | * @since 1.0.19 |
629 | 629 | * @param float $value Amount earned. |
630 | 630 | */ |
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
631 | + public function set_earned($value) { |
|
632 | + $value = max((float) $value, 0); |
|
633 | + $this->set_prop('earned', $value); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | * @since 1.0.19 |
640 | 640 | * @param float $value Amount refunded. |
641 | 641 | */ |
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
642 | + public function set_refunded($value) { |
|
643 | + $value = max((float) $value, 0); |
|
644 | + $this->set_prop('refunded', $value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param float $value Amount cancelled. |
652 | 652 | */ |
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
653 | + public function set_cancelled($value) { |
|
654 | + $value = max((float) $value, 0); |
|
655 | + $this->set_prop('cancelled', $value); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | * @since 1.0.19 |
662 | 662 | * @param float $value Amount cancelled. |
663 | 663 | */ |
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
664 | + public function set_failed($value) { |
|
665 | + $value = max((float) $value, 0); |
|
666 | + $this->set_prop('failed', $value); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * @deprecated |
673 | 673 | * @return int item id |
674 | 674 | */ |
675 | - public function create( $data = array() ) { |
|
675 | + public function create($data = array()) { |
|
676 | 676 | |
677 | 677 | // Set the properties. |
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
678 | + if (is_array($data)) { |
|
679 | + $this->set_props($data); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Save the item. |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @deprecated |
691 | 691 | * @return int item id |
692 | 692 | */ |
693 | - public function update( $data = array() ) { |
|
694 | - return $this->create( $data ); |
|
693 | + public function update($data = array()) { |
|
694 | + return $this->create($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /* |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
714 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
726 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
726 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
727 | 727 | $is_active = false; |
728 | 728 | } |
729 | 729 | |
730 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
730 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | * @since 1.0.19 |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function has_item( $item_id ) { |
|
740 | - return false !== $this->get_item( $item_id ); |
|
739 | + public function has_item($item_id) { |
|
740 | + return false !== $this->get_item($item_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @since 1.0.19 |
747 | 747 | * @return bool |
748 | 748 | */ |
749 | - public function has_element_type( $element_type ) { |
|
750 | - return false !== $this->get_element_type( $element_type ); |
|
749 | + public function has_element_type($element_type) { |
|
750 | + return false !== $this->get_element_type($element_type); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
761 | + if (!empty($this->invoice)) { |
|
762 | 762 | return $this->invoice->is_recurring(); |
763 | 763 | } |
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ($this->get_items() as $item) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
767 | + if ($item->is_recurring()) { |
|
768 | 768 | return true; |
769 | 769 | } |
770 | 770 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @since 1.0.19 |
779 | 779 | */ |
780 | - public function get_html( $extra_markup = '' ) { |
|
780 | + public function get_html($extra_markup = '') { |
|
781 | 781 | |
782 | 782 | // Return the HTML. |
783 | 783 | return wpinv_get_template_html( |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @since 1.0.19 |
797 | 797 | */ |
798 | - public function display( $extra_markup = '' ) { |
|
798 | + public function display($extra_markup = '') { |
|
799 | 799 | return wpinv_get_template( |
800 | 800 | 'payment-forms/form.php', |
801 | 801 | array( |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports Class. |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | * |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
24 | + add_action('getpaid_authenticated_admin_action_export_invoices', array($this, 'export_invoices')); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | |
34 | 34 | add_submenu_page( |
35 | 35 | 'wpinv', |
36 | - __( 'Reports', 'invoicing' ), |
|
37 | - __( 'Reports', 'invoicing' ), |
|
36 | + __('Reports', 'invoicing'), |
|
37 | + __('Reports', 'invoicing'), |
|
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | - array( $this, 'display_reports_page' ) |
|
40 | + array($this, 'display_reports_page') |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | } |
@@ -50,46 +50,46 @@ discard block |
||
50 | 50 | |
51 | 51 | // Prepare variables. |
52 | 52 | $tabs = $this->get_tabs(); |
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
53 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
54 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | 56 | // Display the current tab. |
57 | 57 | ?> |
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
61 | - <h1><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1> |
|
61 | + <h1><?php echo esc_html($tabs[$current_tab]); ?></h1> |
|
62 | 62 | |
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach ( $tabs as $key => $label ) { |
|
66 | + foreach ($tabs as $key => $label) { |
|
67 | 67 | |
68 | - $key = sanitize_key( $key ); |
|
69 | - $label = esc_html( $label ); |
|
68 | + $key = sanitize_key($key); |
|
69 | + $label = esc_html($label); |
|
70 | 70 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
71 | 71 | $url = esc_url( |
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
72 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
73 | 73 | ); |
74 | 74 | |
75 | - echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
75 | + echo wp_kses_post("\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>"); |
|
76 | 76 | |
77 | 77 | } |
78 | 78 | ?> |
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
82 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
83 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
82 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
83 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
84 | 84 | </div> |
85 | 85 | |
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | 89 | // Wordfence loads an unsupported version of chart js on our page. |
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
90 | + wp_deregister_style('chart-js'); |
|
91 | + wp_deregister_script('chart-js'); |
|
92 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array('jquery'), '3.7.1', true); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | public function get_tabs() { |
102 | 102 | |
103 | 103 | $tabs = array( |
104 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | - 'export' => __( 'Export', 'invoicing' ), |
|
104 | + 'reports' => __('Reports', 'invoicing'), |
|
105 | + 'export' => __('Export', 'invoicing'), |
|
106 | 106 | ); |
107 | 107 | |
108 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
108 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $args |
137 | 137 | */ |
138 | - public function download_graph( $args ) { |
|
138 | + public function download_graph($args) { |
|
139 | 139 | |
140 | - if ( ! empty( $args['graph'] ) ) { |
|
140 | + if (!empty($args['graph'])) { |
|
141 | 141 | $downloader = new GetPaid_Graph_Downloader(); |
142 | - $downloader->download( $args['graph'] ); |
|
142 | + $downloader->download($args['graph']); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | } |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param array $args |
151 | 151 | */ |
152 | - public function export_invoices( $args ) { |
|
152 | + public function export_invoices($args) { |
|
153 | 153 | |
154 | - if ( ! empty( $args['post_type'] ) ) { |
|
154 | + if (!empty($args['post_type'])) { |
|
155 | 155 | |
156 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
156 | + if ('subscriptions' === $args['post_type']) { |
|
157 | 157 | $downloader = new GetPaid_Subscription_Exporter(); |
158 | 158 | } else { |
159 | 159 | $downloader = new GetPaid_Invoice_Exporter(); |
160 | 160 | } |
161 | 161 | |
162 | - $downloader->export( $args['post_type'], $args ); |
|
162 | + $downloader->export($args['post_type'], $args); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Export Class. |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | public function display() { |
20 | 20 | |
21 | 21 | echo "<div class='row mt-4' style='max-width: 920px;' >"; |
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
22 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
23 | + $this->display_post_type_export($post_type); |
|
24 | 24 | } |
25 | 25 | $this->display_subscription_export(); |
26 | 26 | echo '</div>'; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * Retrieves the download url. |
32 | 32 | * |
33 | 33 | */ |
34 | - public function get_download_url( $post_type ) { |
|
34 | + public function get_download_url($post_type) { |
|
35 | 35 | |
36 | 36 | return wp_nonce_url( |
37 | 37 | add_query_arg( |
38 | 38 | array( |
39 | 39 | 'getpaid-admin-action' => 'export_invoices', |
40 | - 'post_type' => urlencode( $post_type ), |
|
40 | + 'post_type' => urlencode($post_type), |
|
41 | 41 | ) |
42 | 42 | ), |
43 | 43 | 'getpaid-nonce', |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * Displays a single post type export card. |
51 | 51 | * |
52 | 52 | */ |
53 | - public function display_post_type_export( $post_type ) { |
|
53 | + public function display_post_type_export($post_type) { |
|
54 | 54 | |
55 | 55 | ?> |
56 | 56 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | <strong> |
62 | 62 | <?php |
63 | 63 | printf( |
64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
64 | + esc_html__('Export %s', 'invoicing'), |
|
65 | + esc_html(getpaid_get_post_type_label($post_type)) |
|
66 | 66 | ); |
67 | 67 | ?> |
68 | 68 | </strong> |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | |
71 | 71 | <div class="card-body"> |
72 | 72 | |
73 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
|
73 | + <form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>"> |
|
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
76 | + $this->display_markup($this->generate_from_date($post_type)); |
|
77 | + $this->display_markup($this->generate_to_date($post_type)); |
|
78 | + $this->display_markup($this->generate_post_status_select($post_type)); |
|
79 | + $this->display_markup($this->generate_file_type_select($post_type)); |
|
80 | + submit_button(__('Download', 'invoicing')); |
|
81 | 81 | ?> |
82 | 82 | |
83 | 83 | </form> |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * Generates the from date input field. |
96 | 96 | * |
97 | 97 | */ |
98 | - public function generate_from_date( $post_type ) { |
|
98 | + public function generate_from_date($post_type) { |
|
99 | 99 | |
100 | 100 | return aui()->input( |
101 | 101 | array( |
102 | 102 | 'name' => 'from_date', |
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
103 | + 'id' => esc_attr("$post_type-from_date"), |
|
104 | 104 | 'placeholder' => 'yy-mm-dd', |
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
105 | + 'label' => __('From Date', 'invoicing'), |
|
106 | 106 | 'label_type' => 'vertical', |
107 | 107 | 'label_class' => 'd-block', |
108 | 108 | 'type' => 'datepicker', |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * Generates the to date input field. |
116 | 116 | * |
117 | 117 | */ |
118 | - public function generate_to_date( $post_type ) { |
|
118 | + public function generate_to_date($post_type) { |
|
119 | 119 | |
120 | 120 | return aui()->input( |
121 | 121 | array( |
122 | 122 | 'name' => 'to_date', |
123 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
123 | + 'id' => esc_attr("$post_type-to_date"), |
|
124 | 124 | 'placeholder' => 'yy-mm-dd', |
125 | - 'label' => __( 'To Date', 'invoicing' ), |
|
125 | + 'label' => __('To Date', 'invoicing'), |
|
126 | 126 | 'label_type' => 'vertical', |
127 | 127 | 'label_class' => 'd-block', |
128 | 128 | 'type' => 'datepicker', |
@@ -135,20 +135,20 @@ discard block |
||
135 | 135 | * Generates the to post status select field. |
136 | 136 | * |
137 | 137 | */ |
138 | - public function generate_post_status_select( $post_type ) { |
|
138 | + public function generate_post_status_select($post_type) { |
|
139 | 139 | |
140 | - if ( 'subscriptions' === $post_type ) { |
|
140 | + if ('subscriptions' === $post_type) { |
|
141 | 141 | $options = getpaid_get_subscription_statuses(); |
142 | 142 | } else { |
143 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
143 | + $options = wpinv_get_invoice_statuses(true, false, $post_type); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return aui()->select( |
147 | 147 | array( |
148 | 148 | 'name' => 'status', |
149 | - 'id' => esc_attr( "$post_type-status" ), |
|
150 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | - 'label' => __( 'Status', 'invoicing' ), |
|
149 | + 'id' => esc_attr("$post_type-status"), |
|
150 | + 'placeholder' => __('All Statuses', 'invoicing'), |
|
151 | + 'label' => __('Status', 'invoicing'), |
|
152 | 152 | 'label_type' => 'vertical', |
153 | 153 | 'label_class' => 'd-block', |
154 | 154 | 'options' => $options, |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | * Generates the to file type select field. |
162 | 162 | * |
163 | 163 | */ |
164 | - public function generate_file_type_select( $post_type ) { |
|
164 | + public function generate_file_type_select($post_type) { |
|
165 | 165 | |
166 | 166 | return aui()->select( |
167 | 167 | array( |
168 | 168 | 'name' => 'file_type', |
169 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | - 'label' => __( 'Export File', 'invoicing' ), |
|
169 | + 'id' => esc_attr("$post_type-file_type"), |
|
170 | + 'placeholder' => __('Select File Type', 'invoicing'), |
|
171 | + 'label' => __('Export File', 'invoicing'), |
|
172 | 172 | 'label_type' => 'vertical', |
173 | 173 | 'label_class' => 'd-block', |
174 | 174 | 'options' => array( |
175 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | - 'xml' => __( 'XML', 'invoicing' ), |
|
177 | - 'json' => __( 'JSON', 'invoicing' ), |
|
175 | + 'csv' => __('CSV', 'invoicing'), |
|
176 | + 'xml' => __('XML', 'invoicing'), |
|
177 | + 'json' => __('JSON', 'invoicing'), |
|
178 | 178 | ), |
179 | 179 | ) |
180 | 180 | ); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * Displays a field's markup. |
186 | 186 | * |
187 | 187 | */ |
188 | - public function display_markup( $markup ) { |
|
188 | + public function display_markup($markup) { |
|
189 | 189 | |
190 | 190 | echo wp_kses( |
191 | 191 | str_replace( |
@@ -214,20 +214,20 @@ discard block |
||
214 | 214 | |
215 | 215 | <div class="card-header"> |
216 | 216 | <strong> |
217 | - <?php esc_html_e( 'Export Subscriptions', 'invoicing' ); ?> |
|
217 | + <?php esc_html_e('Export Subscriptions', 'invoicing'); ?> |
|
218 | 218 | </strong> |
219 | 219 | </div> |
220 | 220 | |
221 | 221 | <div class="card-body"> |
222 | 222 | |
223 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
|
223 | + <form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>"> |
|
224 | 224 | |
225 | 225 | <?php |
226 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
227 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
228 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
229 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
230 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
226 | + $this->display_markup($this->generate_from_date('subscriptions')); |
|
227 | + $this->display_markup($this->generate_to_date('subscriptions')); |
|
228 | + $this->display_markup($this->generate_post_status_select('subscriptions')); |
|
229 | + $this->display_markup($this->generate_file_type_select('subscriptions')); |
|
230 | + submit_button(__('Download', 'invoicing')); |
|
231 | 231 | ?> |
232 | 232 | |
233 | 233 | </form> |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
32 | 32 | */ |
33 | - public function prepare_handler( $graph ) { |
|
33 | + public function prepare_handler($graph) { |
|
34 | 34 | |
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
35 | + if (empty($this->handler->views[$graph])) { |
|
36 | + wp_die(esc_html__('Invalid Graph', 'invoicing'), 400); |
|
37 | 37 | } |
38 | 38 | |
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
39 | + return new $this->handler->views[$graph]['class'](); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function prepare_output() { |
49 | 49 | |
50 | - $output = fopen( 'php://output', 'w' ); |
|
50 | + $output = fopen('php://output', 'w'); |
|
51 | 51 | |
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
52 | + if (false === $output) { |
|
53 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function prepare_file_type( $graph ) { |
|
64 | + public function prepare_file_type($graph) { |
|
65 | 65 | |
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
66 | + $file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']); |
|
67 | + $file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d')); |
|
68 | 68 | |
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
69 | + header("Content-Type:application/$file_type"); |
|
70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
71 | 71 | |
72 | 72 | return $file_type; |
73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
76 | 76 | * Handles the actual download. |
77 | 77 | * |
78 | 78 | */ |
79 | - public function download( $graph ) { |
|
79 | + public function download($graph) { |
|
80 | 80 | global $wpdb; |
81 | 81 | |
82 | - $handler = $this->prepare_handler( $graph ); |
|
82 | + $handler = $this->prepare_handler($graph); |
|
83 | 83 | $stream = $this->prepare_output(); |
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
86 | + $file_type = $this->prepare_file_type($graph); |
|
87 | + |
|
88 | + if ('csv' == $file_type) { |
|
89 | + $this->download_csv($stats, $stream, $headers); |
|
90 | + } elseif ('xml' == $file_type) { |
|
91 | + $this->download_xml($stats, $stream, $headers); |
|
92 | 92 | } else { |
93 | - $this->download_json( $stats, $stream, $headers ); |
|
93 | + $this->download_json($stats, $stream, $headers); |
|
94 | 94 | } |
95 | 95 | |
96 | - fclose( $stream ); |
|
96 | + fclose($stream); |
|
97 | 97 | exit; |
98 | 98 | } |
99 | 99 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * @param array $headers The fields to stream. |
106 | 106 | * @since 1.0.19 |
107 | 107 | */ |
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
108 | + public function download_csv($stats, $stream, $headers) { |
|
109 | 109 | |
110 | 110 | // Output the csv column headers. |
111 | - fputcsv( $stream, $headers ); |
|
111 | + fputcsv($stream, $headers); |
|
112 | 112 | |
113 | 113 | // Loop through |
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
114 | + foreach ($stats as $stat) { |
|
115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
116 | + $row = array_map('maybe_serialize', $row); |
|
117 | + fputcsv($stream, $row); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | * @param array $headers The fields to stream. |
128 | 128 | * @since 1.0.19 |
129 | 129 | */ |
130 | - public function download_json( $stats, $stream, $headers ) { |
|
130 | + public function download_json($stats, $stream, $headers) { |
|
131 | 131 | |
132 | 132 | $prepared = array(); |
133 | 133 | |
134 | 134 | // Loop through |
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
135 | + foreach ($stats as $stat) { |
|
136 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
137 | 137 | } |
138 | 138 | |
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
139 | + fwrite($stream, wp_json_encode($prepared)); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | * @param array $headers The fields to stream. |
149 | 149 | * @since 1.0.19 |
150 | 150 | */ |
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
151 | + public function download_xml($stats, $stream, $headers) { |
|
152 | 152 | |
153 | 153 | $prepared = array(); |
154 | 154 | |
155 | 155 | // Loop through |
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
156 | + foreach ($stats as $stat) { |
|
157 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
158 | 158 | } |
159 | 159 | |
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
160 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
161 | + $this->convert_array_xml($prepared, $xml); |
|
162 | 162 | |
163 | - fwrite( $stream, $xml->asXML() ); |
|
163 | + fwrite($stream, $xml->asXML()); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -170,24 +170,24 @@ discard block |
||
170 | 170 | * @access public |
171 | 171 | * @since 1.0.19 |
172 | 172 | */ |
173 | - public function convert_array_xml( $data, $xml ) { |
|
173 | + public function convert_array_xml($data, $xml) { |
|
174 | 174 | |
175 | 175 | // Loop through |
176 | - foreach ( $data as $key => $value ) { |
|
176 | + foreach ($data as $key => $value) { |
|
177 | 177 | |
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
178 | + $key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key); |
|
179 | 179 | |
180 | - if ( is_array( $value ) ) { |
|
180 | + if (is_array($value)) { |
|
181 | 181 | |
182 | - if ( is_numeric( $key ) ) { |
|
182 | + if (is_numeric($key)) { |
|
183 | 183 | $key = 'item' . $key; //dealing with <0/>..<n/> issues |
184 | 184 | } |
185 | 185 | |
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
186 | + $subnode = $xml->addChild($key); |
|
187 | + $this->convert_array_xml($value, $subnode); |
|
188 | 188 | |
189 | 189 | } else { |
190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
190 | + $xml->addChild($key, htmlspecialchars($value)); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function prepare_row( $row, $fields ) { |
|
204 | + public function prepare_row($row, $fields) { |
|
205 | 205 | |
206 | 206 | $prepared = array(); |
207 | 207 | $row = (array) $row; |
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ($fields as $field) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
211 | + if ($field === 'total') { |
|
212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
216 | + if ($field === 'total_raw') { |
|
217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
218 | 218 | continue; |
219 | 219 | } |
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[$field] = strip_tags($row[$field]); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 |