@@ -1,41 +1,41 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined('ABSPATH') ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | global $post; |
6 | 6 | $invoice_id = $post->ID; |
7 | -$invoice = wpinv_get_invoice( $invoice_id ); |
|
8 | -if ( empty( $invoice ) ) { |
|
7 | +$invoice = wpinv_get_invoice($invoice_id); |
|
8 | +if (empty($invoice)) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | -$type = $post->post_type == 'wpi_invoice' ? __( 'Invoice', 'invoicing' ): __( 'Quotation', 'invoicing' ); |
|
12 | -do_action( 'wpinv_invoice_print_before_display', $invoice ); ?><!DOCTYPE html> |
|
11 | +$type = $post->post_type == 'wpi_invoice' ? __('Invoice', 'invoicing') : __('Quotation', 'invoicing'); |
|
12 | +do_action('wpinv_invoice_print_before_display', $invoice); ?><!DOCTYPE html> |
|
13 | 13 | <html <?php language_attributes(); ?>> |
14 | 14 | <head> |
15 | 15 | <meta charset="UTF-8"> |
16 | 16 | <title><?php wp_title() ?></title> |
17 | - <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
|
17 | + <meta charset="<?php bloginfo('charset'); ?>" /> |
|
18 | 18 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
19 | 19 | <meta name="robots" content="noindex,nofollow"> |
20 | 20 | |
21 | - <?php do_action( 'wpinv_invoice_print_head', $invoice ); ?> |
|
21 | + <?php do_action('wpinv_invoice_print_head', $invoice); ?> |
|
22 | 22 | </head> |
23 | 23 | <body class="body wpinv wpinv-print"> |
24 | - <?php do_action( 'wpinv_invoice_print_body_start', $invoice ); ?> |
|
24 | + <?php do_action('wpinv_invoice_print_body_start', $invoice); ?> |
|
25 | 25 | <div class="container wpinv-wrap"> |
26 | - <?php if ( $watermark = wpinv_watermark( $invoice_id ) ) { ?> |
|
27 | - <div class="watermark no-print"><p><?php echo esc_html( $watermark ) ?></p></div> |
|
26 | + <?php if ($watermark = wpinv_watermark($invoice_id)) { ?> |
|
27 | + <div class="watermark no-print"><p><?php echo esc_html($watermark) ?></p></div> |
|
28 | 28 | <?php } ?> |
29 | 29 | <!-- ///// Start PDF header --> |
30 | 30 | <htmlpageheader name="wpinv-pdf-header"> |
31 | - <?php do_action( 'wpinv_invoice_print_before_header', $invoice ); ?> |
|
31 | + <?php do_action('wpinv_invoice_print_before_header', $invoice); ?> |
|
32 | 32 | <div class="row wpinv-header"> |
33 | 33 | <div class="col-xs-6 wpinv-business"> |
34 | - <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
35 | - <?php if ( $logo = wpinv_get_business_logo() ) { ?> |
|
36 | - <img class="logo" src="<?php echo esc_url( $logo ); ?>"> |
|
34 | + <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
35 | + <?php if ($logo = wpinv_get_business_logo()) { ?> |
|
36 | + <img class="logo" src="<?php echo esc_url($logo); ?>"> |
|
37 | 37 | <?php } else { ?> |
38 | - <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
38 | + <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1> |
|
39 | 39 | <?php } ?> |
40 | 40 | </a> |
41 | 41 | </div> |
@@ -44,56 +44,56 @@ discard block |
||
44 | 44 | <h2><?php echo $type; ?></h2> |
45 | 45 | </div> |
46 | 46 | </div> |
47 | - <?php do_action( 'wpinv_invoice_print_after_header', $invoice ); ?> |
|
47 | + <?php do_action('wpinv_invoice_print_after_header', $invoice); ?> |
|
48 | 48 | </htmlpageheader> |
49 | 49 | <!-- End PDF header ///// --> |
50 | 50 | |
51 | - <?php do_action( 'wpinv_invoice_print_before_top_content', $invoice ); ?> |
|
51 | + <?php do_action('wpinv_invoice_print_before_top_content', $invoice); ?> |
|
52 | 52 | <div class="row wpinv-top-content"> |
53 | 53 | <div class="col-xs-12 col-sm-6 wpinv-addresses"> |
54 | 54 | <div class="col-xs-12 wpinv-address wpinv-from-address"> |
55 | 55 | <?php wpinv_display_from_address(); ?> |
56 | 56 | </div> |
57 | 57 | <div class="col-xs-12 wpinv-address wpinv-to-address"> |
58 | - <?php wpinv_display_to_address( $invoice_id ); ?> |
|
58 | + <?php wpinv_display_to_address($invoice_id); ?> |
|
59 | 59 | </div> |
60 | 60 | </div> |
61 | 61 | <div class="col-xs-12 col-sm-6 wpinv-details"> |
62 | 62 | <div class="col-xs-12 wpinv-line-details"> |
63 | - <?php do_action( 'wpinv_invoice_print_before_details', $invoice ); ?> |
|
64 | - <?php wpinv_display_invoice_details( $invoice ); ?> |
|
65 | - <?php do_action( 'wpinv_invoice_print_after_details', $invoice ); ?> |
|
63 | + <?php do_action('wpinv_invoice_print_before_details', $invoice); ?> |
|
64 | + <?php wpinv_display_invoice_details($invoice); ?> |
|
65 | + <?php do_action('wpinv_invoice_print_after_details', $invoice); ?> |
|
66 | 66 | </div> |
67 | 67 | </div> |
68 | 68 | </div> |
69 | - <?php do_action( 'wpinv_invoice_print_after_top_content', $invoice ); ?> |
|
69 | + <?php do_action('wpinv_invoice_print_after_top_content', $invoice); ?> |
|
70 | 70 | |
71 | - <?php do_action( 'wpinv_invoice_print_middle', $invoice ); ?> |
|
71 | + <?php do_action('wpinv_invoice_print_middle', $invoice); ?> |
|
72 | 72 | |
73 | - <?php do_action( 'wpinv_invoice_print_before_line_items', $invoice ); ?> |
|
73 | + <?php do_action('wpinv_invoice_print_before_line_items', $invoice); ?> |
|
74 | 74 | <div class="row wpinv-items"> |
75 | 75 | <div class="col-sm-12 wpinv-line-items"> |
76 | - <?php wpinv_display_line_items( $invoice_id ); ?> |
|
76 | + <?php wpinv_display_line_items($invoice_id); ?> |
|
77 | 77 | </div> |
78 | 78 | </div> |
79 | - <?php do_action( 'wpinv_invoice_print_after_line_items', $invoice ); ?> |
|
79 | + <?php do_action('wpinv_invoice_print_after_line_items', $invoice); ?> |
|
80 | 80 | |
81 | 81 | <!-- ///// Start PDF footer --> |
82 | 82 | <htmlpagefooter name="wpinv-pdf-footer"> |
83 | - <?php do_action( 'wpinv_invoice_print_before_footer', $invoice ); ?> |
|
83 | + <?php do_action('wpinv_invoice_print_before_footer', $invoice); ?> |
|
84 | 84 | <div class="row wpinv-footer"> |
85 | 85 | <div class="col-sm-12"> |
86 | - <?php if ( $term_text = wpinv_get_terms_text() ) { ?> |
|
87 | - <div class="terms-text"><?php echo wpautop( $term_text ); ?></div> |
|
86 | + <?php if ($term_text = wpinv_get_terms_text()) { ?> |
|
87 | + <div class="terms-text"><?php echo wpautop($term_text); ?></div> |
|
88 | 88 | <?php } ?> |
89 | 89 | <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div> |
90 | - <div class="print-only"><?php _e( 'Page ', 'invoicing' ) ?> {PAGENO}/{nbpg}</div> |
|
90 | + <div class="print-only"><?php _e('Page ', 'invoicing') ?> {PAGENO}/{nbpg}</div> |
|
91 | 91 | </div> |
92 | 92 | </div> |
93 | - <?php do_action( 'wpinv_invoice_print_after_footer', $invoice ); ?> |
|
93 | + <?php do_action('wpinv_invoice_print_after_footer', $invoice); ?> |
|
94 | 94 | </htmlpagefooter> |
95 | 95 | <!-- End PDF footer ///// --> |
96 | 96 | </div><!-- END wpinv-wrap --> |
97 | - <?php do_action( 'wpinv_invoice_print_body_end', $invoice ); ?> |
|
97 | + <?php do_action('wpinv_invoice_print_body_end', $invoice); ?> |
|
98 | 98 | </body> |
99 | 99 | </html> |
100 | 100 | \ No newline at end of file |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_worldpay_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_worldpay_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_worldpay_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,120 +24,120 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
29 | + if (!empty($invoice)) { |
|
30 | 30 | $quantities_enabled = wpinv_item_quantities_enabled(); |
31 | 31 | |
32 | - $instId = wpinv_get_option( 'worldpay_instId', false ); |
|
32 | + $instId = wpinv_get_option('worldpay_instId', false); |
|
33 | 33 | $cartId = $invoice->get_number(); |
34 | - $testMode = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0; |
|
34 | + $testMode = wpinv_is_test_mode('worldpay') ? 100 : 0; |
|
35 | 35 | $name = $invoice->get_user_full_name(); |
36 | - $address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
36 | + $address = wp_strip_all_tags($invoice->get_address(), true); |
|
37 | 37 | $postcode = $invoice->zip; |
38 | 38 | $tel = $invoice->phone; |
39 | 39 | $email = $invoice->get_email(); |
40 | 40 | $country = $invoice->country; |
41 | - $amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
41 | + $amount = wpinv_sanitize_amount($invoice->get_total()); |
|
42 | 42 | $currency = wpinv_get_currency(); |
43 | 43 | |
44 | 44 | $items = array(); |
45 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
45 | + foreach ($invoice->get_cart_details() as $item) { |
|
46 | 46 | $item_desc = $item['name']; |
47 | - $quantity = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | - $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
47 | + $quantity = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | + $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
49 | 49 | |
50 | 50 | $items[] = $item_desc; |
51 | 51 | } |
52 | 52 | |
53 | - $desc = implode( ', ', $items ); |
|
54 | - if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) { |
|
55 | - $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
53 | + $desc = implode(', ', $items); |
|
54 | + if (wpinv_use_taxes() && $invoice->get_tax() > 0) { |
|
55 | + $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $extra_params = array(); |
59 | 59 | $extra_params['MC_description'] = $desc; |
60 | - $extra_params['MC_callback'] = wpinv_get_ipn_url( 'worldpay' ); |
|
60 | + $extra_params['MC_callback'] = wpinv_get_ipn_url('worldpay'); |
|
61 | 61 | $extra_params['MC_key'] = $invoice->get_key(); |
62 | 62 | $extra_params['MC_invoice_id'] = $invoice->ID; |
63 | 63 | $extra_params['address1'] = $address; |
64 | 64 | $extra_params['town'] = $invoice->city; |
65 | 65 | $extra_params['region'] = $invoice->state; |
66 | - $extra_params['amountString'] = $invoice->get_total( true ); |
|
67 | - $extra_params['countryString'] = wpinv_country_name( $invoice->country ); |
|
66 | + $extra_params['amountString'] = $invoice->get_total(true); |
|
67 | + $extra_params['countryString'] = wpinv_country_name($invoice->country); |
|
68 | 68 | $extra_params['compName'] = $invoice->company; |
69 | 69 | |
70 | - $extra_params = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice ); |
|
70 | + $extra_params = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice); |
|
71 | 71 | |
72 | - $redirect_text = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' ); |
|
73 | - $redirect_text = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice ); |
|
72 | + $redirect_text = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing'); |
|
73 | + $redirect_text = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice); |
|
74 | 74 | |
75 | 75 | // Empty the shopping cart |
76 | 76 | wpinv_empty_cart(); |
77 | 77 | ?> |
78 | 78 | <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555"> |
79 | -<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?> |
|
80 | -<h3><?php echo $redirect_text ;?></h3> |
|
79 | +<?php do_action('wpinv_worldpay_form_before', $invoice); ?> |
|
80 | +<h3><?php echo $redirect_text; ?></h3> |
|
81 | 81 | <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST"> |
82 | - <input type="hidden" value="<?php echo $amount;?>" name="amount"> |
|
83 | - <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId"> |
|
84 | - <input type="hidden" value="<?php echo $currency;?>" name="currency"> |
|
85 | - <input type="hidden" value="<?php echo $instId;?>" name="instId"> |
|
86 | - <input type="hidden" value="<?php echo $testMode;?>" name="testMode"> |
|
87 | - <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name"> |
|
88 | - <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address"> |
|
89 | - <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode"> |
|
90 | - <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel"> |
|
91 | - <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email"> |
|
92 | - <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country"> |
|
93 | - <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc"> |
|
94 | - <?php foreach ( $extra_params as $param => $value ) { ?> |
|
95 | - <?php if ( !empty( $value !== false ) ) { ?> |
|
96 | - <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>"> |
|
82 | + <input type="hidden" value="<?php echo $amount; ?>" name="amount"> |
|
83 | + <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId"> |
|
84 | + <input type="hidden" value="<?php echo $currency; ?>" name="currency"> |
|
85 | + <input type="hidden" value="<?php echo $instId; ?>" name="instId"> |
|
86 | + <input type="hidden" value="<?php echo $testMode; ?>" name="testMode"> |
|
87 | + <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name"> |
|
88 | + <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address"> |
|
89 | + <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode"> |
|
90 | + <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel"> |
|
91 | + <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email"> |
|
92 | + <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country"> |
|
93 | + <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc"> |
|
94 | + <?php foreach ($extra_params as $param => $value) { ?> |
|
95 | + <?php if (!empty($value !== false)) { ?> |
|
96 | + <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>"> |
|
97 | 97 | <?php } ?> |
98 | 98 | <?php } ?> |
99 | - <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?> |
|
100 | - <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>"> |
|
99 | + <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?> |
|
100 | + <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>"> |
|
101 | 101 | </form> |
102 | 102 | <script type="text/javascript">document.wpi_worldpay_form.submit();</script> |
103 | -<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?> |
|
103 | +<?php do_action('wpinv_worldpay_form_after', $invoice); ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | } else { |
107 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
107 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
108 | 108 | // If errors are present, send the user back to the purchase page so they can be corrected |
109 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
109 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
110 | 110 | } |
111 | 111 | } |
112 | -add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' ); |
|
112 | +add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_worldpay_redirect() { |
115 | - $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
115 | + $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
116 | 116 | |
117 | - return apply_filters( 'wpinv_worldpay_redirect', $redirect ); |
|
117 | + return apply_filters('wpinv_worldpay_redirect', $redirect); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | function wpinv_process_worldpay_ipn() { |
121 | - $request = wpinv_get_post_data( 'post' ); |
|
121 | + $request = wpinv_get_post_data('post'); |
|
122 | 122 | |
123 | - if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) { |
|
123 | + if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) { |
|
124 | 124 | $invoice_id = $request['MC_invoice_id']; |
125 | 125 | |
126 | - if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
127 | - if ( $request['transStatus'] == 'Y' ) { |
|
128 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
129 | - wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] ); |
|
130 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) ); |
|
126 | + if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) { |
|
127 | + if ($request['transStatus'] == 'Y') { |
|
128 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
129 | + wpinv_set_payment_transaction_id($invoice_id, $request['transId']); |
|
130 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId'])); |
|
131 | 131 | return; |
132 | - } else if ( $request['transStatus'] == 'C' ) { |
|
133 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
134 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) ); |
|
132 | + } else if ($request['transStatus'] == 'C') { |
|
133 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
134 | + wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing')); |
|
135 | 135 | |
136 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id ); |
|
136 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | return; |
142 | 142 | } |
143 | -add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' ); |
|
144 | 143 | \ No newline at end of file |
144 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
145 | 145 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
2 | +function wpinv_get_subscriptions($args = array()) { |
|
3 | + if (empty($args['parent_invoice_id'])) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | ); |
15 | 15 | |
16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
17 | - $args = wp_parse_args( $args, $defaults ); |
|
17 | + $args = wp_parse_args($args, $defaults); |
|
18 | 18 | |
19 | - if( $args['numberposts'] < 1 ) { |
|
19 | + if ($args['numberposts'] < 1) { |
|
20 | 20 | $args['numberposts'] = 999999999999; |
21 | 21 | } |
22 | 22 | |
23 | - $posts = get_posts( $args ); |
|
23 | + $posts = get_posts($args); |
|
24 | 24 | $subscriptions = array(); |
25 | - if ( !empty( $posts ) ) { |
|
26 | - foreach ( $posts as $post ) { |
|
27 | - if ( !empty( $post->ID ) ) { |
|
28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
25 | + if (!empty($posts)) { |
|
26 | + foreach ($posts as $post) { |
|
27 | + if (!empty($post->ID)) { |
|
28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | return $subscriptions; |
35 | 35 | } |
36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
37 | 37 | global $wpdb; |
38 | 38 | |
39 | - if ( empty( $id ) ) { |
|
39 | + if (empty($id)) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $id = esc_sql( $id ); |
|
43 | + $id = esc_sql($id); |
|
44 | 44 | |
45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
46 | 46 | |
47 | - if ( $invoice_id != null ) { |
|
48 | - return wpinv_get_invoice( $invoice_id ); |
|
47 | + if ($invoice_id != null) { |
|
48 | + return wpinv_get_invoice($invoice_id); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return false; |
@@ -55,49 +55,49 @@ discard block |
||
55 | 55 | * Records a new payment on the subscription |
56 | 56 | * |
57 | 57 | */ |
58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
59 | - $args = wp_parse_args( $subscription_args, array( |
|
58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
59 | + $args = wp_parse_args($subscription_args, array( |
|
60 | 60 | 'amount' => '', |
61 | 61 | 'transaction_id' => '', |
62 | 62 | 'gateway' => '' |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
70 | - if ( empty( $parent_invoice ) ) { |
|
69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
70 | + if (empty($parent_invoice)) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $invoice = new WPInv_Invoice(); |
75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
77 | 77 | //$invoice->set( 'status', 'publish' ); |
78 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
79 | - $invoice->set( 'key', $parent_invoice->get_key() ); |
|
78 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
79 | + $invoice->set('key', $parent_invoice->get_key()); |
|
80 | 80 | |
81 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
82 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
83 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
84 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
81 | + $invoice->set('ip', $parent_invoice->ip); |
|
82 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
83 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
84 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
85 | 85 | ///$invoice->set( 'email', $parent_invoice->get_email() ); |
86 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
87 | - $invoice->set( 'address', $parent_invoice->address ); |
|
88 | - $invoice->set( 'city', $parent_invoice->city ); |
|
89 | - $invoice->set( 'country', $parent_invoice->country ); |
|
90 | - $invoice->set( 'state', $parent_invoice->state ); |
|
91 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
92 | - $invoice->set( 'company', $parent_invoice->company ); |
|
93 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
94 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
95 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
96 | - |
|
97 | - if ( empty( $args['gateway'] ) ) { |
|
98 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
86 | + $invoice->set('phone', $parent_invoice->phone); |
|
87 | + $invoice->set('address', $parent_invoice->address); |
|
88 | + $invoice->set('city', $parent_invoice->city); |
|
89 | + $invoice->set('country', $parent_invoice->country); |
|
90 | + $invoice->set('state', $parent_invoice->state); |
|
91 | + $invoice->set('zip', $parent_invoice->zip); |
|
92 | + $invoice->set('company', $parent_invoice->company); |
|
93 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
94 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
95 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
96 | + |
|
97 | + if (empty($args['gateway'])) { |
|
98 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
99 | 99 | } else { |
100 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
100 | + $invoice->set('gateway', $args['gateway']); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | // increase the earnings for each item in the subscription |
106 | 106 | $items = $recurring_details['cart_details']; |
107 | 107 | |
108 | - if ( $items ) { |
|
108 | + if ($items) { |
|
109 | 109 | $add_items = array(); |
110 | 110 | $cart_details = array(); |
111 | 111 | |
112 | - foreach ( $items as $item ) { |
|
112 | + foreach ($items as $item) { |
|
113 | 113 | $add_item = array(); |
114 | 114 | $add_item['id'] = $item['id']; |
115 | 115 | $add_item['quantity'] = $item['quantity']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | - $invoice->set( 'items', $add_items ); |
|
122 | + $invoice->set('items', $add_items); |
|
123 | 123 | $invoice->cart_details = $cart_details; |
124 | 124 | } |
125 | 125 | |
@@ -129,277 +129,277 @@ discard block |
||
129 | 129 | $tax = $recurring_details['tax']; |
130 | 130 | $discount = $recurring_details['discount']; |
131 | 131 | |
132 | - if ( $discount > 0 ) { |
|
133 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
132 | + if ($discount > 0) { |
|
133 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
134 | 134 | } |
135 | 135 | |
136 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
137 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
138 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
139 | - $invoice->total = wpinv_round_amount( $total ); |
|
136 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
137 | + $invoice->tax = wpinv_round_amount($tax); |
|
138 | + $invoice->discount = wpinv_round_amount($discount); |
|
139 | + $invoice->total = wpinv_round_amount($total); |
|
140 | 140 | $invoice->save(); |
141 | 141 | |
142 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
142 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
143 | 143 | sleep(1); |
144 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
144 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
145 | 145 | |
146 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
146 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
147 | 147 | |
148 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
148 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
149 | 149 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
150 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
151 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
150 | + $subscription_data['created'] = current_time('mysql', 0); |
|
151 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
152 | 152 | |
153 | 153 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
154 | - $invoice->update_subscription( $subscription_data ); |
|
154 | + $invoice->update_subscription($subscription_data); |
|
155 | 155 | |
156 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
157 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
156 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
157 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
158 | 158 | |
159 | 159 | return $invoice; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
162 | +function wpinv_payment_exists($txn_id = '') { |
|
163 | 163 | global $wpdb; |
164 | 164 | |
165 | - if ( empty( $txn_id ) ) { |
|
165 | + if (empty($txn_id)) { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | - $txn_id = esc_sql( $txn_id ); |
|
169 | + $txn_id = esc_sql($txn_id); |
|
170 | 170 | |
171 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
171 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
172 | 172 | |
173 | - if ( $invoice != null ) { |
|
173 | + if ($invoice != null) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | |
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
181 | - if ( empty( $invoice ) ) { |
|
180 | +function wpinv_is_subscription_payment($invoice = '') { |
|
181 | + if (empty($invoice)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
185 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
186 | - $invoice = wpinv_get_invoice( $invoice ); |
|
185 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
186 | + $invoice = wpinv_get_invoice($invoice); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( empty( $invoice ) ) { |
|
189 | + if (empty($invoice)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( $invoice->is_renewal() ) { |
|
193 | + if ($invoice->is_renewal()) { |
|
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | |
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
201 | - if ( empty( $invoice ) ) { |
|
200 | +function wpinv_payment_subscription_data($invoice = '') { |
|
201 | + if (empty($invoice)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
206 | - $invoice = wpinv_get_invoice( $invoice ); |
|
205 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
206 | + $invoice = wpinv_get_invoice($invoice); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( empty( $invoice ) ) { |
|
209 | + if (empty($invoice)) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | 213 | return $invoice->get_subscription_data(); |
214 | 214 | } |
215 | 215 | |
216 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
217 | - if ( empty( $invoice ) ) { |
|
216 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
217 | + if (empty($invoice)) { |
|
218 | 218 | return false; |
219 | 219 | } |
220 | 220 | |
221 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
222 | - $invoice = wpinv_get_invoice( $invoice ); |
|
221 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
222 | + $invoice = wpinv_get_invoice($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( empty( $invoice ) ) { |
|
225 | + if (empty($invoice)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
229 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
232 | +function wpinv_get_pretty_subscription_period($period) { |
|
233 | 233 | $frequency = ''; |
234 | 234 | //Format period details |
235 | - switch ( $period ) { |
|
235 | + switch ($period) { |
|
236 | 236 | case 'D' : |
237 | 237 | case 'day' : |
238 | - $frequency = __( 'Daily', 'invoicing' ); |
|
238 | + $frequency = __('Daily', 'invoicing'); |
|
239 | 239 | break; |
240 | 240 | case 'W' : |
241 | 241 | case 'week' : |
242 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
242 | + $frequency = __('Weekly', 'invoicing'); |
|
243 | 243 | break; |
244 | 244 | case 'M' : |
245 | 245 | case 'month' : |
246 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
246 | + $frequency = __('Monthly', 'invoicing'); |
|
247 | 247 | break; |
248 | 248 | case 'Y' : |
249 | 249 | case 'year' : |
250 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
250 | + $frequency = __('Yearly', 'invoicing'); |
|
251 | 251 | break; |
252 | 252 | default : |
253 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
253 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
254 | 254 | break; |
255 | 255 | } |
256 | 256 | |
257 | 257 | return $frequency; |
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
260 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
261 | 261 | $frequency = ''; |
262 | 262 | //Format period details |
263 | - switch ( $period ) { |
|
263 | + switch ($period) { |
|
264 | 264 | case 'D' : |
265 | 265 | case 'day' : |
266 | - $frequency = __( 'Day', 'invoicing' ); |
|
266 | + $frequency = __('Day', 'invoicing'); |
|
267 | 267 | break; |
268 | 268 | case 'W' : |
269 | 269 | case 'week' : |
270 | - $frequency = __( 'Week', 'invoicing' ); |
|
270 | + $frequency = __('Week', 'invoicing'); |
|
271 | 271 | break; |
272 | 272 | case 'M' : |
273 | 273 | case 'month' : |
274 | - $frequency = __( 'Month', 'invoicing' ); |
|
274 | + $frequency = __('Month', 'invoicing'); |
|
275 | 275 | break; |
276 | 276 | case 'Y' : |
277 | 277 | case 'year' : |
278 | - $frequency = __( 'Year', 'invoicing' ); |
|
278 | + $frequency = __('Year', 'invoicing'); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
281 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
282 | 282 | break; |
283 | 283 | } |
284 | 284 | |
285 | 285 | return $frequency; |
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
288 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
289 | 289 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
290 | 290 | |
291 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
292 | - $amount = __( 'Free', 'invoicing' ); |
|
291 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
292 | + $amount = __('Free', 'invoicing'); |
|
293 | 293 | $interval = $trial_interval; |
294 | 294 | $period = $trial_period; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $description = ''; |
298 | - switch ( $period ) { |
|
298 | + switch ($period) { |
|
299 | 299 | case 'D' : |
300 | 300 | case 'day' : |
301 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
301 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
302 | 302 | break; |
303 | 303 | case 'W' : |
304 | 304 | case 'week' : |
305 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
305 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
306 | 306 | break; |
307 | 307 | case 'M' : |
308 | 308 | case 'month' : |
309 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
309 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
310 | 310 | break; |
311 | 311 | case 'Y' : |
312 | 312 | case 'year' : |
313 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
313 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
314 | 314 | break; |
315 | 315 | } |
316 | 316 | |
317 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
317 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
320 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
321 | 321 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
322 | 322 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
323 | 323 | |
324 | 324 | $description = ''; |
325 | - switch ( $period ) { |
|
325 | + switch ($period) { |
|
326 | 326 | case 'D' : |
327 | 327 | case 'day' : |
328 | - if ( (int)$bill_times > 0 ) { |
|
329 | - if ( $interval > 1 ) { |
|
330 | - if ( $bill_times > 1 ) { |
|
331 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
328 | + if ((int)$bill_times > 0) { |
|
329 | + if ($interval > 1) { |
|
330 | + if ($bill_times > 1) { |
|
331 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
332 | 332 | } else { |
333 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
333 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
334 | 334 | } |
335 | 335 | } else { |
336 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
336 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
337 | 337 | } |
338 | 338 | } else { |
339 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
339 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
340 | 340 | } |
341 | 341 | break; |
342 | 342 | case 'W' : |
343 | 343 | case 'week' : |
344 | - if ( (int)$bill_times > 0 ) { |
|
345 | - if ( $interval > 1 ) { |
|
346 | - if ( $bill_times > 1 ) { |
|
347 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
344 | + if ((int)$bill_times > 0) { |
|
345 | + if ($interval > 1) { |
|
346 | + if ($bill_times > 1) { |
|
347 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
348 | 348 | } else { |
349 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
349 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
352 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
353 | 353 | } |
354 | 354 | } else { |
355 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
355 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
356 | 356 | } |
357 | 357 | break; |
358 | 358 | case 'M' : |
359 | 359 | case 'month' : |
360 | - if ( (int)$bill_times > 0 ) { |
|
361 | - if ( $interval > 1 ) { |
|
362 | - if ( $bill_times > 1 ) { |
|
363 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
360 | + if ((int)$bill_times > 0) { |
|
361 | + if ($interval > 1) { |
|
362 | + if ($bill_times > 1) { |
|
363 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
364 | 364 | } else { |
365 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
365 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
366 | 366 | } |
367 | 367 | } else { |
368 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
368 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
369 | 369 | } |
370 | 370 | } else { |
371 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
371 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
372 | 372 | } |
373 | 373 | break; |
374 | 374 | case 'Y' : |
375 | 375 | case 'year' : |
376 | - if ( (int)$bill_times > 0 ) { |
|
377 | - if ( $interval > 1 ) { |
|
378 | - if ( $bill_times > 1 ) { |
|
379 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
376 | + if ((int)$bill_times > 0) { |
|
377 | + if ($interval > 1) { |
|
378 | + if ($bill_times > 1) { |
|
379 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
380 | 380 | } else { |
381 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
381 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
382 | 382 | } |
383 | 383 | } else { |
384 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
384 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
385 | 385 | } |
386 | 386 | } else { |
387 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
387 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
388 | 388 | } |
389 | 389 | break; |
390 | 390 | } |
391 | 391 | |
392 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
392 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
393 | 393 | } |
394 | 394 | |
395 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
396 | - if ( empty( $invoice ) ) { |
|
395 | +function wpinv_subscription_payment_desc($invoice) { |
|
396 | + if (empty($invoice)) { |
|
397 | 397 | return NULL; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $description = ''; |
401 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
402 | - if ( $item->has_free_trial() ) { |
|
401 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
402 | + if ($item->has_free_trial()) { |
|
403 | 403 | $trial_period = $item->get_trial_period(); |
404 | 404 | $trial_interval = $item->get_trial_interval(); |
405 | 405 | } else { |
@@ -407,45 +407,45 @@ discard block |
||
407 | 407 | $trial_interval = 0; |
408 | 408 | } |
409 | 409 | |
410 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
410 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
411 | 411 | } |
412 | 412 | |
413 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
413 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
417 | - $initial_total = wpinv_round_amount( $initial ); |
|
418 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
416 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
417 | + $initial_total = wpinv_round_amount($initial); |
|
418 | + $recurring_total = wpinv_round_amount($recurring); |
|
419 | 419 | |
420 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
420 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
421 | 421 | // Free trial |
422 | 422 | } else { |
423 | - if ( $bill_times == 1 ) { |
|
423 | + if ($bill_times == 1) { |
|
424 | 424 | $recurring_total = $initial_total; |
425 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
425 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
426 | 426 | $bill_times--; |
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency ); |
|
431 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency ); |
|
430 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency); |
|
431 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency); |
|
432 | 432 | |
433 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
433 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
434 | 434 | |
435 | - if ( $initial_total != $recurring_total ) { |
|
436 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
435 | + if ($initial_total != $recurring_total) { |
|
436 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
437 | 437 | |
438 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
438 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
439 | 439 | } else { |
440 | 440 | $description = $recurring; |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
443 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
447 | - if ( !empty( $invoice->ID ) ) { |
|
448 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
446 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
447 | + if (!empty($invoice->ID)) { |
|
448 | + wpinv_failed_invoice_notification($invoice->ID); |
|
449 | 449 | } |
450 | 450 | } |
451 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
452 | 451 | \ No newline at end of file |
452 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
453 | 453 | \ No newline at end of file |
@@ -1,121 +1,121 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function wpinv_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish' ), |
|
149 | + 'post_status' => array('publish'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
225 | - if ( empty( $invoice_id ) ) { |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,61 +255,61 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'free' => !( (float)$total > 0 ) && $invoice->is_free() ? true : false, |
|
266 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'free' => !((float)$total > 0) && $invoice->is_free() ? true : false, |
|
266 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
267 | 267 | ); |
268 | 268 | |
269 | - if ( $return ) { |
|
269 | + if ($return) { |
|
270 | 270 | return $response; |
271 | 271 | } |
272 | 272 | |
273 | - wp_send_json( $response ); |
|
273 | + wp_send_json($response); |
|
274 | 274 | } |
275 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
276 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
277 | 277 | |
278 | 278 | // VAT Settings |
279 | -function wpinv_vat_rate_add_callback( $args ) { |
|
279 | +function wpinv_vat_rate_add_callback($args) { |
|
280 | 280 | ?> |
281 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
282 | 282 | <?php |
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
285 | +function wpinv_vat_rate_delete_callback($args) { |
|
286 | 286 | global $wpinv_euvat; |
287 | 287 | |
288 | 288 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
289 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
290 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
289 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
290 | + if (isset($vat_classes[$vat_class])) { |
|
291 | 291 | ?> |
292 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
293 | 293 | <?php |
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_vat_rates_callback( $args ) { |
|
297 | +function wpinv_vat_rates_callback($args) { |
|
298 | 298 | global $wpinv_euvat; |
299 | 299 | |
300 | 300 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
301 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
301 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
302 | 302 | |
303 | 303 | $eu_states = $wpinv_euvat->get_eu_states(); |
304 | 304 | $countries = wpinv_get_country_list(); |
305 | 305 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
306 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
306 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
307 | 307 | ob_start(); |
308 | 308 | ?> |
309 | 309 | </td><tr> |
310 | 310 | <td colspan="2" class="wpinv_vat_tdbox"> |
311 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
312 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
311 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
312 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
313 | 313 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
314 | 314 | <colgroup> |
315 | 315 | <col width="50px" /> |
@@ -321,43 +321,43 @@ discard block |
||
321 | 321 | </colgroup> |
322 | 322 | <thead> |
323 | 323 | <tr> |
324 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
328 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
324 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
328 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
329 | 329 | </tr> |
330 | 330 | </thead> |
331 | 331 | <tbody> |
332 | - <?php if( !empty( $eu_states ) ) { ?> |
|
332 | + <?php if (!empty($eu_states)) { ?> |
|
333 | 333 | <?php |
334 | - foreach ( $eu_states as $state ) { |
|
335 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
334 | + foreach ($eu_states as $state) { |
|
335 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
336 | 336 | |
337 | 337 | // Filter the rate for each country |
338 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
338 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
339 | 339 | |
340 | 340 | // If one does not exist create a default |
341 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
341 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
342 | 342 | |
343 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
344 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
345 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
346 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
343 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
344 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
345 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
346 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
347 | 347 | ?> |
348 | 348 | <tr> |
349 | 349 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
350 | 350 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
351 | 351 | <td class="wpinv_vat_global"> |
352 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
353 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
354 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
352 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
353 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
354 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
355 | 355 | </td> |
356 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
356 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
358 | 358 | <td class="wpinv_vat_group"> |
359 | 359 | <?php |
360 | - echo wpinv_html_select( array( |
|
360 | + echo wpinv_html_select(array( |
|
361 | 361 | 'name' => 'vat_rates[' . $state . '][group]', |
362 | 362 | 'selected' => $vat_group, |
363 | 363 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | 'chosen' => false, |
368 | 368 | 'show_option_all' => false, |
369 | 369 | 'show_option_none' => false |
370 | - ) ); |
|
370 | + )); |
|
371 | 371 | ?> |
372 | 372 | </td> |
373 | 373 | </tr> |
374 | 374 | <?php } ?> |
375 | 375 | <tr> |
376 | 376 | <td colspan="6" style="background-color:#fafafa;"> |
377 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
378 | 378 | </td> |
379 | 379 | </tr> |
380 | 380 | <?php } ?> |
@@ -386,35 +386,35 @@ discard block |
||
386 | 386 | echo $content; |
387 | 387 | } |
388 | 388 | |
389 | -function wpinv_vat_number_callback( $args ) { |
|
389 | +function wpinv_vat_number_callback($args) { |
|
390 | 390 | global $wpinv_euvat; |
391 | 391 | |
392 | 392 | $vat_number = $wpinv_euvat->get_vat_number(); |
393 | 393 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
394 | 394 | |
395 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
396 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
395 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
396 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
397 | 397 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
398 | 398 | |
399 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
400 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
399 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
400 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
401 | 401 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
402 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
403 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
402 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
403 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
404 | 404 | |
405 | 405 | echo $html; |
406 | 406 | } |
407 | 407 | |
408 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
408 | +function wpinv_eu_fallback_rate_callback($args) { |
|
409 | 409 | global $wpinv_options; |
410 | 410 | |
411 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
412 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
411 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
412 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
413 | 413 | |
414 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
415 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
417 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
414 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
415 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
417 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
418 | 418 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
419 | 419 | echo $html; |
420 | 420 | ?> |
@@ -422,36 +422,36 @@ discard block |
||
422 | 422 | <?php |
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
425 | +function wpinv_vat_ip_lookup_callback($args) { |
|
426 | 426 | global $wpinv_options, $wpinv_euvat; |
427 | 427 | |
428 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
428 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
429 | 429 | |
430 | 430 | $options = array(); |
431 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
432 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
431 | + if (function_exists('geoip_country_code_by_name')) { |
|
432 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
436 | 436 | |
437 | - if ( !function_exists( 'bcadd' ) ) { |
|
438 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
437 | + if (!function_exists('bcadd')) { |
|
438 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
439 | 439 | } else { |
440 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
440 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
441 | 441 | } |
442 | 442 | |
443 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
444 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
443 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
444 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
445 | 445 | } |
446 | 446 | |
447 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
448 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
447 | + if (function_exists('simplexml_load_file')) { |
|
448 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
449 | 449 | } |
450 | 450 | |
451 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
452 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
451 | + $options['site'] = __('Use default country', 'invoicing'); |
|
452 | + $options['default'] = __('Auto', 'invoicing'); |
|
453 | 453 | |
454 | - $html = wpinv_html_select( array( |
|
454 | + $html = wpinv_html_select(array( |
|
455 | 455 | 'name' => "wpinv_settings[{$args['id']}]", |
456 | 456 | 'selected' => $value, |
457 | 457 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -464,23 +464,23 @@ discard block |
||
464 | 464 | )); |
465 | 465 | |
466 | 466 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
467 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
467 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
468 | 468 | $desc .= '<p>'; |
469 | - if ( empty( $geoip2_message ) ) { |
|
470 | - if ( $geoip2_database ) { |
|
469 | + if (empty($geoip2_message)) { |
|
470 | + if ($geoip2_database) { |
|
471 | 471 | $last_updated = ''; |
472 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
473 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
474 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
472 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
473 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
474 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
475 | 475 | } |
476 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
476 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
477 | 477 | } else { |
478 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
478 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
479 | 479 | } |
480 | 480 | } else { |
481 | 481 | $desc .= $geoip2_message; |
482 | 482 | } |
483 | - $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
483 | + $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
484 | 484 | $desc .= '</label>'; |
485 | 485 | |
486 | 486 | $html .= $desc; |
@@ -1,60 +1,60 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
|
5 | +add_filter('wpinv_authorizenet_support_subscription', '__return_true'); |
|
6 | 6 | |
7 | -function wpinv_authorizenet_cc_form( $invoice_id ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
9 | - $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : ''; |
|
7 | +function wpinv_authorizenet_cc_form($invoice_id) { |
|
8 | + $invoice = wpinv_get_invoice($invoice_id); |
|
9 | + $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : ''; |
|
10 | 10 | ?> |
11 | 11 | <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default"> |
12 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div> |
|
12 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div> |
|
13 | 13 | <div class="panel-body"> |
14 | 14 | <div class="form-group required"> |
15 | - <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-8"> |
17 | - <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]"> |
|
17 | + <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]"> |
|
18 | 18 | </div> |
19 | 19 | </div> |
20 | 20 | <div class="form-group required"> |
21 | - <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-8"> |
23 | - <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]"> |
|
23 | + <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]"> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="form-group required"> |
27 | - <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label> |
|
28 | 28 | <div class="col-sm-2"> |
29 | 29 | <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]"> |
30 | - <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
31 | - <option value="<?php echo $value;?>"><?php echo $value;?></option> |
|
30 | + <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
31 | + <option value="<?php echo $value; ?>"><?php echo $value; ?></option> |
|
32 | 32 | <?php } ?> |
33 | 33 | </select> |
34 | 34 | </div> |
35 | 35 | <div class="col-sm-2"> |
36 | 36 | <select class="form-control" name="authorizenet[cc_expire_year]"> |
37 | - <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?> |
|
38 | - <option value="<?php echo $i;?>"><?php echo $i;?></option> |
|
37 | + <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?> |
|
38 | + <option value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div class="form-group required"> |
44 | - <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-8"> |
46 | - <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]""> |
|
46 | + <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]""> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | <?php |
52 | 52 | } |
53 | -add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 ); |
|
53 | +add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1); |
|
54 | 54 | |
55 | -function wpinv_process_authorizenet_payment( $purchase_data ) { |
|
56 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
57 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_process_authorizenet_payment($purchase_data) { |
|
56 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
57 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Collect payment data |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Record the pending payment |
75 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
75 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
76 | 76 | |
77 | - if ( !empty( $invoice ) ) { |
|
78 | - $authorizenet_card = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array(); |
|
77 | + if (!empty($invoice)) { |
|
78 | + $authorizenet_card = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array(); |
|
79 | 79 | $card_defaults = array( |
80 | 80 | 'cc_owner' => $invoice->get_user_full_name(), |
81 | 81 | 'cc_number' => false, |
@@ -83,174 +83,174 @@ discard block |
||
83 | 83 | 'cc_expire_year' => false, |
84 | 84 | 'cc_cvv2' => false, |
85 | 85 | ); |
86 | - $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults ); |
|
86 | + $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults); |
|
87 | 87 | |
88 | - if ( empty( $authorizenet_card['cc_owner'] ) ) { |
|
89 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
88 | + if (empty($authorizenet_card['cc_owner'])) { |
|
89 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
90 | 90 | } |
91 | - if ( empty( $authorizenet_card['cc_number'] ) ) { |
|
92 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
91 | + if (empty($authorizenet_card['cc_number'])) { |
|
92 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
93 | 93 | } |
94 | - if ( empty( $authorizenet_card['cc_expire_month'] ) ) { |
|
95 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
94 | + if (empty($authorizenet_card['cc_expire_month'])) { |
|
95 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
96 | 96 | } |
97 | - if ( empty( $authorizenet_card['cc_expire_year'] ) ) { |
|
98 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
97 | + if (empty($authorizenet_card['cc_expire_year'])) { |
|
98 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
99 | 99 | } |
100 | - if ( empty( $authorizenet_card['cc_cvv2'] ) ) { |
|
101 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
100 | + if (empty($authorizenet_card['cc_cvv2'])) { |
|
101 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $errors = wpinv_get_errors(); |
105 | 105 | |
106 | - if ( empty( $errors ) ) { |
|
106 | + if (empty($errors)) { |
|
107 | 107 | $invoice_id = $invoice->ID; |
108 | 108 | $quantities_enabled = wpinv_item_quantities_enabled(); |
109 | 109 | $use_taxes = wpinv_use_taxes(); |
110 | 110 | |
111 | 111 | $authorizeAIM = wpinv_authorizenet_AIM(); |
112 | - $authorizeAIM->first_name = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 ); |
|
113 | - $authorizeAIM->last_name = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 ); |
|
114 | - $authorizeAIM->company = wpinv_utf8_substr( $invoice->company, 0, 50 ); |
|
115 | - $authorizeAIM->address = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 ); |
|
116 | - $authorizeAIM->city = wpinv_utf8_substr( $invoice->city, 0, 40 ); |
|
117 | - $authorizeAIM->state = wpinv_utf8_substr( $invoice->state, 0, 40 ); |
|
118 | - $authorizeAIM->zip = wpinv_utf8_substr( $invoice->zip, 0, 40 ); |
|
119 | - $authorizeAIM->country = wpinv_utf8_substr( $invoice->country, 0, 60 ); |
|
120 | - $authorizeAIM->phone = wpinv_utf8_substr( $invoice->phone, 0, 25 ); |
|
121 | - $authorizeAIM->email = wpinv_utf8_substr( $invoice->get_email(), 0, 255 ); |
|
122 | - $authorizeAIM->amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
123 | - $authorizeAIM->card_num = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) ); |
|
124 | - $authorizeAIM->exp_date = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] ); |
|
125 | - $authorizeAIM->card_code = sanitize_text_field( $authorizenet_card['cc_cvv2'] ); |
|
112 | + $authorizeAIM->first_name = wpinv_utf8_substr($invoice->get_first_name(), 0, 50); |
|
113 | + $authorizeAIM->last_name = wpinv_utf8_substr($invoice->get_last_name(), 0, 50); |
|
114 | + $authorizeAIM->company = wpinv_utf8_substr($invoice->company, 0, 50); |
|
115 | + $authorizeAIM->address = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60); |
|
116 | + $authorizeAIM->city = wpinv_utf8_substr($invoice->city, 0, 40); |
|
117 | + $authorizeAIM->state = wpinv_utf8_substr($invoice->state, 0, 40); |
|
118 | + $authorizeAIM->zip = wpinv_utf8_substr($invoice->zip, 0, 40); |
|
119 | + $authorizeAIM->country = wpinv_utf8_substr($invoice->country, 0, 60); |
|
120 | + $authorizeAIM->phone = wpinv_utf8_substr($invoice->phone, 0, 25); |
|
121 | + $authorizeAIM->email = wpinv_utf8_substr($invoice->get_email(), 0, 255); |
|
122 | + $authorizeAIM->amount = wpinv_sanitize_amount($invoice->get_total()); |
|
123 | + $authorizeAIM->card_num = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number'])); |
|
124 | + $authorizeAIM->exp_date = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']); |
|
125 | + $authorizeAIM->card_code = sanitize_text_field($authorizenet_card['cc_cvv2']); |
|
126 | 126 | $authorizeAIM->invoice_num = $invoice->ID; |
127 | 127 | |
128 | 128 | $item_desc = array(); |
129 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
130 | - $quantity = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | - $item_name = wpinv_utf8_substr( $item['name'], 0, 31 ); |
|
132 | - $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
129 | + foreach ($invoice->get_cart_details() as $item) { |
|
130 | + $quantity = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | + $item_name = wpinv_utf8_substr($item['name'], 0, 31); |
|
132 | + $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
133 | 133 | |
134 | - $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
134 | + $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
135 | 135 | } |
136 | 136 | |
137 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
137 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
138 | 138 | |
139 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
140 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
139 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
140 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
141 | 141 | |
142 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
142 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $invoice->get_discount() > 0 ) { |
|
146 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
145 | + if ($invoice->get_discount() > 0) { |
|
146 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
147 | 147 | } |
148 | 148 | |
149 | - $item_description = wpinv_utf8_substr( $item_desc, 0, 255 ); |
|
150 | - $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
149 | + $item_description = wpinv_utf8_substr($item_desc, 0, 255); |
|
150 | + $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
151 | 151 | |
152 | - $authorizeAIM->description = wpinv_utf8_substr( $item_description, 0, 255 ); |
|
152 | + $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255); |
|
153 | 153 | |
154 | 154 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
155 | 155 | |
156 | - if ( $is_recurring ) { |
|
156 | + if ($is_recurring) { |
|
157 | 157 | $authorizeAIM->recurring_billing = true; |
158 | 158 | } |
159 | 159 | |
160 | 160 | try { |
161 | - if ( $is_recurring ) { |
|
161 | + if ($is_recurring) { |
|
162 | 162 | $response = $authorizeAIM->authorizeOnly(); |
163 | 163 | } else { |
164 | 164 | $response = $authorizeAIM->authorizeAndCapture(); |
165 | 165 | } |
166 | 166 | |
167 | - if ( $response->approved || $response->held ) { |
|
168 | - if ( $response->approved ) { |
|
169 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
167 | + if ($response->approved || $response->held) { |
|
168 | + if ($response->approved) { |
|
169 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
170 | 170 | } |
171 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
171 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
172 | 172 | |
173 | - $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ); |
|
173 | + $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code); |
|
174 | 174 | |
175 | - wpinv_insert_payment_note( $invoice_id, $message ); |
|
175 | + wpinv_insert_payment_note($invoice_id, $message); |
|
176 | 176 | |
177 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
177 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
178 | 178 | |
179 | 179 | wpinv_clear_errors(); |
180 | 180 | wpinv_empty_cart(); |
181 | 181 | |
182 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
182 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
183 | 183 | } else { |
184 | - if ( !empty( $response->response_reason_text ) ) { |
|
185 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
186 | - } else if ( !empty( $response->error_message ) ) { |
|
187 | - $error = __( $response->error_message, 'invoicing' ); |
|
184 | + if (!empty($response->response_reason_text)) { |
|
185 | + $error = __($response->response_reason_text, 'invoicing'); |
|
186 | + } else if (!empty($response->error_message)) { |
|
187 | + $error = __($response->error_message, 'invoicing'); |
|
188 | 188 | } else { |
189 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
189 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
190 | 190 | } |
191 | 191 | |
192 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
192 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
193 | 193 | |
194 | - wpinv_set_error( 'payment_error', $error ); |
|
195 | - wpinv_record_gateway_error( $error, $response ); |
|
196 | - wpinv_insert_payment_note( $invoice_id, $error ); |
|
194 | + wpinv_set_error('payment_error', $error); |
|
195 | + wpinv_record_gateway_error($error, $response); |
|
196 | + wpinv_insert_payment_note($invoice_id, $error); |
|
197 | 197 | |
198 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
198 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
199 | 199 | } |
200 | - } catch ( AuthorizeNetException $e ) { |
|
201 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
202 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
203 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
200 | + } catch (AuthorizeNetException $e) { |
|
201 | + wpinv_set_error('request_error', $e->getMessage()); |
|
202 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
203 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
204 | 204 | } |
205 | 205 | } else { |
206 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
206 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
207 | 207 | } |
208 | 208 | } else { |
209 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice ); |
|
210 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
209 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice); |
|
210 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
211 | 211 | } |
212 | 212 | } |
213 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
213 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
214 | 214 | |
215 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
216 | - if ( empty( $subscription_id ) ) { |
|
215 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
216 | + if (empty($subscription_id)) { |
|
217 | 217 | return false; |
218 | 218 | } |
219 | 219 | |
220 | 220 | try { |
221 | 221 | $authnetXML = wpinv_authorizenet_XML(); |
222 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
222 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
223 | 223 | |
224 | 224 | return $authnetXML->isSuccessful(); |
225 | - } catch( Exception $e ) { |
|
226 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
225 | + } catch (Exception $e) { |
|
226 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | return false; |
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
233 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
234 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
232 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
233 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
234 | + if (empty($authorizenet_md5_hash)) { |
|
235 | 235 | return true; |
236 | 236 | } |
237 | 237 | |
238 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
238 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
239 | 239 | |
240 | - return hash_equals( $compare_md5, $md5_hash ); |
|
240 | + return hash_equals($compare_md5, $md5_hash); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | function wpinv_authorizenet_AIM() { |
244 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
245 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
244 | + if (!class_exists('AuthorizeNetException')) { |
|
245 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
246 | 246 | } |
247 | 247 | |
248 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
248 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
249 | 249 | |
250 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
251 | - $authorizeAIM->setSandbox( true ); |
|
250 | + if (wpinv_is_test_mode('authorizenet')) { |
|
251 | + $authorizeAIM->setSandbox(true); |
|
252 | 252 | } else { |
253 | - $authorizeAIM->setSandbox( false ); |
|
253 | + $authorizeAIM->setSandbox(false); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -259,164 +259,164 @@ discard block |
||
259 | 259 | } |
260 | 260 | |
261 | 261 | function wpinv_authorizenet_XML() { |
262 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
263 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
262 | + if (!class_exists('AuthnetXML')) { |
|
263 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
264 | 264 | } |
265 | 265 | |
266 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
266 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet')); |
|
267 | 267 | |
268 | 268 | return $authnetXML; |
269 | 269 | } |
270 | 270 | |
271 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
272 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
271 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
272 | + if (empty($response) || empty($invoice)) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | - if ( $invoice->is_recurring() && !empty( $response->approved ) ) { |
|
277 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
276 | + if ($invoice->is_recurring() && !empty($response->approved)) { |
|
277 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
278 | 278 | |
279 | - if ( !empty( $subscription ) && $subscription->isSuccessful() ) { |
|
280 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
279 | + if (!empty($subscription) && $subscription->isSuccessful()) { |
|
280 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
281 | 281 | |
282 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
282 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
283 | 283 | |
284 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
284 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
285 | 285 | } else { |
286 | - if ( isset( $subscription->messages->message ) ) { |
|
286 | + if (isset($subscription->messages->message)) { |
|
287 | 287 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
288 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
288 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
289 | 289 | } else { |
290 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
291 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
290 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
291 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
292 | 292 | } |
293 | 293 | |
294 | - wpinv_record_gateway_error( $error, $subscription ); |
|
294 | + wpinv_record_gateway_error($error, $subscription); |
|
295 | 295 | |
296 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) ); |
|
296 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error)); |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | } |
300 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
300 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
301 | 301 | |
302 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
303 | - if ( empty( $invoice ) ) { |
|
302 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
303 | + if (empty($invoice)) { |
|
304 | 304 | return false; |
305 | 305 | } |
306 | 306 | |
307 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
307 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
308 | 308 | |
309 | 309 | try { |
310 | 310 | $authnetXML = wpinv_authorizenet_XML(); |
311 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
312 | - } catch( Exception $e ) { |
|
311 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
312 | + } catch (Exception $e) { |
|
313 | 313 | $authnetXML = array(); |
314 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
314 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | return $authnetXML; |
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
321 | - if ( empty( $invoice ) ) { |
|
320 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
321 | + if (empty($invoice)) { |
|
322 | 322 | return false; |
323 | 323 | } |
324 | 324 | |
325 | - $subscription_item = $invoice->get_recurring( true ); |
|
326 | - if ( empty( $subscription_item ) ) { |
|
325 | + $subscription_item = $invoice->get_recurring(true); |
|
326 | + if (empty($subscription_item)) { |
|
327 | 327 | return false; |
328 | 328 | } |
329 | 329 | |
330 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
330 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
331 | 331 | $subscription_name = $invoice->get_subscription_name(); |
332 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
333 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
332 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
333 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
334 | 334 | $interval = $subscription_item->get_recurring_interval(); |
335 | 335 | $period = $subscription_item->get_recurring_period(); |
336 | 336 | $bill_times = (int)$subscription_item->get_recurring_limit(); |
337 | 337 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
338 | 338 | |
339 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
339 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
340 | 340 | $interval = $time_period['interval']; |
341 | 341 | $period = $time_period['period']; |
342 | 342 | |
343 | 343 | $current_tz = date_default_timezone_get(); |
344 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
345 | - $today = date( 'Y-m-d' ); |
|
346 | - date_default_timezone_set( $current_tz ); |
|
344 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
345 | + $today = date('Y-m-d'); |
|
346 | + date_default_timezone_set($current_tz); |
|
347 | 347 | |
348 | 348 | $free_trial = $invoice->is_free_trial(); |
349 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
349 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
350 | 350 | $trial_interval = $subscription_item->get_trial_interval(); |
351 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
351 | + $trial_period = $subscription_item->get_trial_period(true); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | $subscription = array(); |
355 | 355 | $subscription['name'] = $subscription_name; |
356 | 356 | |
357 | 357 | $subscription['paymentSchedule'] = array( |
358 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
358 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
359 | 359 | 'startDate' => $today, |
360 | 360 | 'totalOccurrences' => $bill_times, |
361 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
361 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
362 | 362 | ); |
363 | 363 | |
364 | 364 | $subscription['amount'] = $recurring_amount; |
365 | 365 | $subscription['trialAmount'] = $initial_amount; |
366 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
367 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
368 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
366 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
367 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
368 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
369 | 369 | |
370 | 370 | $subscription['billTo'] = array( |
371 | 371 | 'firstName' => $invoice->get_first_name(), |
372 | 372 | 'lastName' => $invoice->get_last_name(), |
373 | 373 | 'company' => $invoice->company, |
374 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
374 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
375 | 375 | 'city' => $invoice->city, |
376 | 376 | 'state' => $invoice->state, |
377 | 377 | 'zip' => $invoice->zip, |
378 | 378 | 'country' => $invoice->country, |
379 | 379 | ); |
380 | 380 | |
381 | - $params = array( 'subscription' => $subscription ); |
|
381 | + $params = array('subscription' => $subscription); |
|
382 | 382 | |
383 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
383 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
384 | 384 | } |
385 | 385 | |
386 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
387 | - $card_defaults = array( |
|
386 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
387 | + $card_defaults = array( |
|
388 | 388 | 'cc_owner' => null, |
389 | 389 | 'cc_number' => null, |
390 | 390 | 'cc_expire_month' => null, |
391 | 391 | 'cc_expire_year' => null, |
392 | 392 | 'cc_cvv2' => null, |
393 | 393 | ); |
394 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
394 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
395 | 395 | |
396 | 396 | $card_details = array( |
397 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
398 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
399 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
397 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
398 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
399 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
400 | 400 | ); |
401 | 401 | |
402 | 402 | return $card_details; |
403 | 403 | } |
404 | 404 | |
405 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
406 | - if ( empty( $invoice ) || empty( $subscription ) ) { |
|
405 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
406 | + if (empty($invoice) || empty($subscription)) { |
|
407 | 407 | return false; |
408 | 408 | } |
409 | 409 | |
410 | - $subscription_item = $invoice->get_recurring( true ); |
|
411 | - if ( empty( $subscription_item ) ) { |
|
410 | + $subscription_item = $invoice->get_recurring(true); |
|
411 | + if (empty($subscription_item)) { |
|
412 | 412 | return false; |
413 | 413 | } |
414 | 414 | |
415 | 415 | $invoice_id = $invoice->ID; |
416 | 416 | $subscriptionId = (array)$subscription->subscriptionId; |
417 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id; |
|
417 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id; |
|
418 | 418 | |
419 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) ); |
|
419 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id)); |
|
420 | 420 | |
421 | 421 | $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active'; |
422 | 422 | |
@@ -424,16 +424,16 @@ discard block |
||
424 | 424 | 'profile_id' => $subscription_id, |
425 | 425 | 'item_id' => $subscription_item->ID, |
426 | 426 | 'initial_amount' => $invoice->get_total(), |
427 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
427 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
428 | 428 | 'period' => $subscription_item->get_recurring_period(), |
429 | 429 | 'interval' => $subscription_item->get_recurring_interval(), |
430 | 430 | 'bill_times' => $subscription_item->get_recurring_limit(), |
431 | - 'expiration' => $invoice->get_new_expiration( $subscription_item->ID ), |
|
431 | + 'expiration' => $invoice->get_new_expiration($subscription_item->ID), |
|
432 | 432 | 'status' => $status, |
433 | - 'created' => current_time( 'mysql', 0 ) |
|
433 | + 'created' => current_time('mysql', 0) |
|
434 | 434 | ); |
435 | 435 | |
436 | - if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) { |
|
436 | + if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) { |
|
437 | 437 | $args['trial_period'] = $subscription_item->get_trial_period(); |
438 | 438 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
439 | 439 | } else { |
@@ -441,58 +441,58 @@ discard block |
||
441 | 441 | $args['trial_interval'] = 0; |
442 | 442 | } |
443 | 443 | |
444 | - return $invoice->update_subscription( $args ); |
|
444 | + return $invoice->update_subscription($args); |
|
445 | 445 | } |
446 | 446 | |
447 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
448 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
447 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
448 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
449 | 449 | $error = false; |
450 | 450 | |
451 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
451 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
452 | 452 | $error = true; |
453 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
453 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
454 | 454 | } |
455 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
455 | + if (empty($post['authorizenet']['cc_number'])) { |
|
456 | 456 | $error = true; |
457 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
457 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
458 | 458 | } |
459 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
459 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
460 | 460 | $error = true; |
461 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
461 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
462 | 462 | } |
463 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
463 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
464 | 464 | $error = true; |
465 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
465 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
466 | 466 | } |
467 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
467 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
468 | 468 | $error = true; |
469 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
469 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
470 | 470 | } |
471 | 471 | |
472 | - if ( $error ) { |
|
472 | + if ($error) { |
|
473 | 473 | return; |
474 | 474 | } |
475 | 475 | |
476 | 476 | $invoice = wpinv_get_invoice_cart(); |
477 | 477 | |
478 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
479 | - $subscription_item = $invoice->get_recurring( true ); |
|
478 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
479 | + $subscription_item = $invoice->get_recurring(true); |
|
480 | 480 | |
481 | 481 | $interval = $subscription_item->get_recurring_interval(); |
482 | 482 | $period = $subscription_item->get_recurring_period(); |
483 | 483 | |
484 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
485 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
484 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
485 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | } |
489 | 489 | } |
490 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
490 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
491 | 491 | |
492 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
493 | - $subscription_interval = absint( $subscription_interval ); |
|
492 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
493 | + $subscription_interval = absint($subscription_interval); |
|
494 | 494 | |
495 | - switch( $subscription_period ) { |
|
495 | + switch ($subscription_period) { |
|
496 | 496 | case 'W': |
497 | 497 | case 'week': |
498 | 498 | case 'weeks': |
@@ -502,14 +502,14 @@ discard block |
||
502 | 502 | case 'M': |
503 | 503 | case 'month': |
504 | 504 | case 'months': |
505 | - if ( $subscription_interval > 12 ) { |
|
505 | + if ($subscription_interval > 12) { |
|
506 | 506 | $subscription_interval = 12; |
507 | 507 | } |
508 | 508 | |
509 | 509 | $interval = $subscription_interval; |
510 | 510 | $period = 'months'; |
511 | 511 | |
512 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
512 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
513 | 513 | $interval = $subscription_interval * 30; |
514 | 514 | $period = 'days'; |
515 | 515 | } |
@@ -526,40 +526,40 @@ discard block |
||
526 | 526 | break; |
527 | 527 | } |
528 | 528 | |
529 | - return compact( 'interval', 'period' ); |
|
529 | + return compact('interval', 'period'); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | function wpinv_authorizenet_process_ipn() { |
533 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
533 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
534 | 534 | return; |
535 | 535 | } |
536 | 536 | |
537 | - $subscription_id = intval( $_POST['x_subscription_id'] ); |
|
537 | + $subscription_id = intval($_POST['x_subscription_id']); |
|
538 | 538 | |
539 | - if ( $subscription_id ) { |
|
540 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
541 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
542 | - $response_code = intval( $_POST['x_response_code'] ); |
|
543 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
539 | + if ($subscription_id) { |
|
540 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
541 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
542 | + $response_code = intval($_POST['x_response_code']); |
|
543 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
544 | 544 | |
545 | - if ( 1 == $response_code ) { |
|
545 | + if (1 == $response_code) { |
|
546 | 546 | // Approved |
547 | - do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id ); |
|
548 | - } else if ( 2 == $response_code ) { |
|
547 | + do_action('wpinv_authorizenet_renewal_payment', $transaction_id); |
|
548 | + } else if (2 == $response_code) { |
|
549 | 549 | // Declined |
550 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
551 | - do_action( 'wpinv_authorizenet_renewal_error', $transaction_id ); |
|
552 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
550 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
551 | + do_action('wpinv_authorizenet_renewal_error', $transaction_id); |
|
552 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
553 | 553 | // An expired card |
554 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
555 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id ); |
|
554 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
555 | + do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id); |
|
556 | 556 | |
557 | 557 | } else { |
558 | 558 | // Other Error |
559 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
559 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | } |
565 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
566 | 565 | \ No newline at end of file |
566 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
567 | 567 | \ No newline at end of file |
@@ -7,51 +7,51 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_API { |
15 | 15 | protected $post_type = 'wpi_invoice'; |
16 | 16 | |
17 | - public function __construct( $params = array() ) { |
|
17 | + public function __construct($params = array()) { |
|
18 | 18 | } |
19 | - public function insert_invoice( $data ) { |
|
19 | + public function insert_invoice($data) { |
|
20 | 20 | global $wpdb; |
21 | 21 | //wpinv_transaction_query( 'start' ); |
22 | 22 | |
23 | 23 | try { |
24 | - if ( empty( $data['invoice'] ) ) { |
|
25 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
24 | + if (empty($data['invoice'])) { |
|
25 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
26 | 26 | } |
27 | 27 | |
28 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data['invoice'], $this ); |
|
28 | + $data = apply_filters('wpinv_api_create_invoice_data', $data['invoice'], $this); |
|
29 | 29 | |
30 | - $invoice = wpinv_insert_invoice( $data, true ); |
|
31 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
32 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
30 | + $invoice = wpinv_insert_invoice($data, true); |
|
31 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
32 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | // HTTP 201 Created |
36 | - $this->send_status( 201 ); |
|
36 | + $this->send_status(201); |
|
37 | 37 | |
38 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
38 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
39 | 39 | |
40 | 40 | //wpinv_transaction_query( 'commit' ); |
41 | 41 | |
42 | - return wpinv_get_invoice( $invoice->ID ); |
|
43 | - } catch ( WPInv_API_Exception $e ) { |
|
42 | + return wpinv_get_invoice($invoice->ID); |
|
43 | + } catch (WPInv_API_Exception $e) { |
|
44 | 44 | //wpinv_transaction_query( 'rollback' ); |
45 | 45 | |
46 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
46 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - public function send_status( $code ) { |
|
51 | - status_header( $code ); |
|
50 | + public function send_status($code) { |
|
51 | + status_header($code); |
|
52 | 52 | } |
53 | 53 | |
54 | - protected function set_billing_details( $invoice, $data ) { |
|
54 | + protected function set_billing_details($invoice, $data) { |
|
55 | 55 | $address_fields = array( |
56 | 56 | 'user_id', |
57 | 57 | 'first_name', |
@@ -70,66 +70,66 @@ discard block |
||
70 | 70 | $billing_details = array(); |
71 | 71 | $user_id = $invoice->get_user_id(); |
72 | 72 | |
73 | - foreach ( $address_fields as $field ) { |
|
74 | - if ( isset( $data['billing_details'][ $field ] ) ) { |
|
75 | - $value = sanitize_text_field( $data['billing_details'][ $field ] ); |
|
73 | + foreach ($address_fields as $field) { |
|
74 | + if (isset($data['billing_details'][$field])) { |
|
75 | + $value = sanitize_text_field($data['billing_details'][$field]); |
|
76 | 76 | |
77 | - if ( $field == 'country' && empty( $value ) ) { |
|
78 | - if ( !empty( $invoice->country ) ) { |
|
77 | + if ($field == 'country' && empty($value)) { |
|
78 | + if (!empty($invoice->country)) { |
|
79 | 79 | $value = $invoice->country; |
80 | 80 | } else { |
81 | - $value = wpinv_default_billing_country( '', $user_id ); |
|
81 | + $value = wpinv_default_billing_country('', $user_id); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - if ( $field == 'state' && empty( $value ) ) { |
|
86 | - if ( !empty( $invoice->state ) ) { |
|
85 | + if ($field == 'state' && empty($value)) { |
|
86 | + if (!empty($invoice->state)) { |
|
87 | 87 | $value = $invoice->state; |
88 | 88 | } else { |
89 | 89 | $value = wpinv_get_default_state(); |
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - $invoice->set( $field, $value ); |
|
93 | + $invoice->set($field, $value); |
|
94 | 94 | |
95 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value ); |
|
95 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | 99 | return $invoice; |
100 | 100 | } |
101 | 101 | |
102 | - protected function set_discount( $invoice, $data ) { |
|
103 | - if ( isset( $data['discount'] ) ) { |
|
104 | - $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) ); |
|
102 | + protected function set_discount($invoice, $data) { |
|
103 | + if (isset($data['discount'])) { |
|
104 | + $invoice->set('discount', wpinv_round_amount($data['discount'])); |
|
105 | 105 | |
106 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) ); |
|
106 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount'])); |
|
107 | 107 | |
108 | - if ( isset( $data['discount_code'] ) ) { |
|
109 | - $invoice->set( 'discount_code', $data['discount_code'] ); |
|
108 | + if (isset($data['discount_code'])) { |
|
109 | + $invoice->set('discount_code', $data['discount_code']); |
|
110 | 110 | |
111 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] ); |
|
111 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | 115 | return $invoice; |
116 | 116 | } |
117 | 117 | |
118 | - protected function set_items( $invoice, $data ) { |
|
119 | - if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
118 | + protected function set_items($invoice, $data) { |
|
119 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
120 | 120 | $items_array = array(); |
121 | 121 | |
122 | - if ( !empty( $invoice->country ) ) { |
|
122 | + if (!empty($invoice->country)) { |
|
123 | 123 | $country = $invoice->country; |
124 | - } else if ( !empty( $data['billing_details']['country'] ) ) { |
|
124 | + } else if (!empty($data['billing_details']['country'])) { |
|
125 | 125 | $country = $data['billing_details']['country']; |
126 | 126 | } else { |
127 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() ); |
|
127 | + $country = wpinv_default_billing_country('', $invoice->get_user_id()); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ( !empty( $invoice->state ) ) { |
|
130 | + if (!empty($invoice->state)) { |
|
131 | 131 | $state = $invoice->state; |
132 | - } else if ( !empty( $data['billing_details']['state'] ) ) { |
|
132 | + } else if (!empty($data['billing_details']['state'])) { |
|
133 | 133 | $state = $data['billing_details']['state']; |
134 | 134 | } else { |
135 | 135 | $state = wpinv_get_default_state(); |
@@ -138,54 +138,54 @@ discard block |
||
138 | 138 | $_POST['country'] = $country; |
139 | 139 | $_POST['state'] = $state; |
140 | 140 | |
141 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' ); |
|
141 | + $rate = wpinv_get_tax_rate($country, $state, 'global'); |
|
142 | 142 | |
143 | 143 | $total_tax = 0; |
144 | - foreach ( $data['items'] as $item ) { |
|
145 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
146 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : ''; |
|
147 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : ''; |
|
148 | - $amount = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0; |
|
144 | + foreach ($data['items'] as $item) { |
|
145 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
146 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : ''; |
|
147 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : ''; |
|
148 | + $amount = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0; |
|
149 | 149 | |
150 | - if ( !empty( $item['vat_rates_class'] ) ) { |
|
150 | + if (!empty($item['vat_rates_class'])) { |
|
151 | 151 | $vat_rates_class = $item['vat_rates_class']; |
152 | 152 | } else { |
153 | 153 | $vat_rates_class = '_standard'; |
154 | 154 | } |
155 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id ); |
|
155 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id); |
|
156 | 156 | |
157 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0; |
|
157 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0; |
|
158 | 158 | $total_tax += $tax; |
159 | 159 | |
160 | 160 | $items_array[] = array( |
161 | 161 | 'id' => $id, |
162 | - 'title' => esc_html( $title ), |
|
163 | - 'description' => esc_html( $desc ), |
|
164 | - 'amount' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
165 | - 'subtotal' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
162 | + 'title' => esc_html($title), |
|
163 | + 'description' => esc_html($desc), |
|
164 | + 'amount' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
165 | + 'subtotal' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
166 | 166 | 'vat_rates_class' => $vat_rates_class, |
167 | 167 | 'vat_rate' => $vat_rate, |
168 | - 'tax' => $tax > 0 ? wpinv_round_amount( $tax ) : 0, |
|
168 | + 'tax' => $tax > 0 ? wpinv_round_amount($tax) : 0, |
|
169 | 169 | ); |
170 | 170 | } |
171 | 171 | |
172 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) ); |
|
173 | - $invoice->set( 'tax', wpinv_round_amount( $total_tax ) ); |
|
172 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax)); |
|
173 | + $invoice->set('tax', wpinv_round_amount($total_tax)); |
|
174 | 174 | |
175 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice ); |
|
175 | + $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); |
|
176 | 176 | |
177 | - $invoice->set( 'items', $items_array ); |
|
178 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array ); |
|
177 | + $invoice->set('items', $items_array); |
|
178 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | return $invoice; |
182 | 182 | } |
183 | 183 | |
184 | - protected function set_invoice_meta( $invoice_id, $invoice_meta ) { |
|
185 | - foreach ( $invoice_meta as $meta_key => $meta_value ) { |
|
184 | + protected function set_invoice_meta($invoice_id, $invoice_meta) { |
|
185 | + foreach ($invoice_meta as $meta_key => $meta_value) { |
|
186 | 186 | |
187 | - if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { |
|
188 | - update_post_meta( $invoice_id, $meta_key, $meta_value ); |
|
187 | + if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { |
|
188 | + update_post_meta($invoice_id, $meta_key, $meta_value); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | class WPInv_API_Exception extends Exception { |
196 | 196 | protected $error_code; |
197 | 197 | |
198 | - public function __construct( $error_code, $error_message, $http_status_code ) { |
|
198 | + public function __construct($error_code, $error_message, $http_status_code) { |
|
199 | 199 | $this->error_code = $error_code; |
200 | - parent::__construct( $error_message, $http_status_code ); |
|
200 | + parent::__construct($error_message, $http_status_code); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | public function getErrorCode() { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | 6 | global $wpinv_euvat, $ajax_cart_details; |
@@ -11,158 +11,158 @@ discard block |
||
11 | 11 | $quantities_enabled = wpinv_item_quantities_enabled(); |
12 | 12 | $use_taxes = wpinv_use_taxes(); |
13 | 13 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
14 | -$tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
15 | -$tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
14 | +$tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
15 | +$tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
16 | 16 | |
17 | -do_action( 'wpinv_before_email_items', $invoice ); ?> |
|
17 | +do_action('wpinv_before_email_items', $invoice); ?> |
|
18 | 18 | <div id="wpinv-email-items"> |
19 | - <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3> |
|
19 | + <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3> |
|
20 | 20 | <table id="wpinv_checkout_cart" class="table table-bordered table-hover"> |
21 | 21 | <thead> |
22 | 22 | <tr class="wpinv_cart_header_row"> |
23 | - <?php do_action( 'wpinv_email_items_table_header_first' ); ?> |
|
24 | - <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th> |
|
25 | - <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th> |
|
26 | - <?php if ( $quantities_enabled ) { ?> |
|
27 | - <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th> |
|
23 | + <?php do_action('wpinv_email_items_table_header_first'); ?> |
|
24 | + <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th> |
|
25 | + <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th> |
|
26 | + <?php if ($quantities_enabled) { ?> |
|
27 | + <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th> |
|
28 | 28 | <?php } ?> |
29 | - <?php if ( !$zero_tax && $use_taxes ) { ?> |
|
29 | + <?php if (!$zero_tax && $use_taxes) { ?> |
|
30 | 30 | <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th> |
31 | 31 | <?php } ?> |
32 | - <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
33 | - <?php do_action( 'wpinv_email_items_table_header_last' ); ?> |
|
32 | + <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
33 | + <?php do_action('wpinv_email_items_table_header_last'); ?> |
|
34 | 34 | </tr> |
35 | 35 | </thead> |
36 | 36 | <tbody> |
37 | 37 | <?php |
38 | - do_action( 'wpinv_email_items_before' ); |
|
39 | - if ( $cart_items ) { |
|
40 | - foreach ( $cart_items as $key => $item ) { |
|
41 | - $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL; |
|
38 | + do_action('wpinv_email_items_before'); |
|
39 | + if ($cart_items) { |
|
40 | + foreach ($cart_items as $key => $item) { |
|
41 | + $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL; |
|
42 | 42 | ?> |
43 | - <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>"> |
|
44 | - <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?> |
|
43 | + <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>"> |
|
44 | + <?php do_action('wpinv_email_items_table_body_first', $item); ?> |
|
45 | 45 | <td class="wpinv_cart_item_name text-left"> |
46 | 46 | <?php |
47 | - if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) { |
|
47 | + if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) { |
|
48 | 48 | echo '<div class="wpinv_cart_item_image">'; |
49 | - echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) ); |
|
49 | + echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25))); |
|
50 | 50 | echo '</div>'; |
51 | 51 | } |
52 | - $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item ); |
|
52 | + $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item); |
|
53 | 53 | echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>'; |
54 | 54 | |
55 | 55 | $summary = ''; |
56 | - if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) { |
|
57 | - $post_link = '<a href="' . get_permalink( $item['meta']['post_id'] ) .'" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id']) ) . '</a>'; |
|
58 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link ); |
|
56 | + if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) { |
|
57 | + $post_link = '<a href="' . get_permalink($item['meta']['post_id']) . '" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id'])) . '</a>'; |
|
58 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link); |
|
59 | 59 | } |
60 | 60 | |
61 | - $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice ); |
|
62 | - if ( !empty( $summary ) ) { |
|
61 | + $summary = apply_filters('wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice); |
|
62 | + if (!empty($summary)) { |
|
63 | 63 | echo '<p class="small">' . $summary . '</p>'; |
64 | 64 | } |
65 | 65 | |
66 | - do_action( 'wpinv_email_cart_item_title_after', $item, $key ); |
|
66 | + do_action('wpinv_email_cart_item_title_after', $item, $key); |
|
67 | 67 | ?> |
68 | 68 | </td> |
69 | 69 | <td class="wpinv_cart_item_price text-right"> |
70 | 70 | <?php |
71 | - echo wpinv_cart_item_price( $item ); |
|
72 | - do_action( 'wpinv_email_cart_item_price_after', $item, $key ); |
|
71 | + echo wpinv_cart_item_price($item); |
|
72 | + do_action('wpinv_email_cart_item_price_after', $item, $key); |
|
73 | 73 | ?> |
74 | 74 | </td> |
75 | - <?php if ( $quantities_enabled ) { ?> |
|
75 | + <?php if ($quantities_enabled) { ?> |
|
76 | 76 | <td class="wpinv_cart_item_qty text-right"> |
77 | 77 | <?php |
78 | - echo wpinv_get_cart_item_quantity( $item ); |
|
79 | - do_action( 'wpinv_email_item_quantitiy', $item, $key ); |
|
78 | + echo wpinv_get_cart_item_quantity($item); |
|
79 | + do_action('wpinv_email_item_quantitiy', $item, $key); |
|
80 | 80 | ?> |
81 | 81 | </td> |
82 | 82 | <?php } ?> |
83 | - <?php if ( !$zero_tax && $use_taxes ) { ?> |
|
83 | + <?php if (!$zero_tax && $use_taxes) { ?> |
|
84 | 84 | <td class="wpinv_cart_item_tax text-right"> |
85 | 85 | <?php |
86 | - echo wpinv_cart_item_tax( $item ); |
|
87 | - do_action( 'wpinv_email_item_tax', $item, $key ); |
|
86 | + echo wpinv_cart_item_tax($item); |
|
87 | + do_action('wpinv_email_item_tax', $item, $key); |
|
88 | 88 | ?> |
89 | 89 | </td> |
90 | 90 | <?php } ?> |
91 | 91 | <td class="wpinv_cart_item_subtotal text-right"> |
92 | 92 | <?php |
93 | - echo wpinv_cart_item_subtotal( $item ); |
|
94 | - do_action( 'wpinv_email_item_subtotal', $item, $key ); |
|
93 | + echo wpinv_cart_item_subtotal($item); |
|
94 | + do_action('wpinv_email_item_subtotal', $item, $key); |
|
95 | 95 | ?> |
96 | 96 | </td> |
97 | - <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?> |
|
97 | + <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?> |
|
98 | 98 | </tr> |
99 | 99 | <?php } ?> |
100 | 100 | <?php } ?> |
101 | - <?php do_action( 'wpinv_email_items_middle' ); ?> |
|
102 | - <?php do_action( 'wpinv_email_items_after' ); ?> |
|
101 | + <?php do_action('wpinv_email_items_middle'); ?> |
|
102 | + <?php do_action('wpinv_email_items_after'); ?> |
|
103 | 103 | </tbody> |
104 | 104 | <tfoot> |
105 | - <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?> |
|
106 | - <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?> |
|
105 | + <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?> |
|
106 | + <?php if (has_action('wpinv_email_footer_buttons')) { ?> |
|
107 | 107 | <tr class="wpinv_cart_footer_row"> |
108 | - <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?> |
|
109 | - <td colspan="<?php echo ( $cart_columns ); ?>"> |
|
110 | - <?php do_action( 'wpinv_email_footer_buttons' ); ?> |
|
108 | + <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?> |
|
109 | + <td colspan="<?php echo ($cart_columns); ?>"> |
|
110 | + <?php do_action('wpinv_email_footer_buttons'); ?> |
|
111 | 111 | </td> |
112 | - <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?> |
|
112 | + <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?> |
|
113 | 113 | </tr> |
114 | 114 | <?php } ?> |
115 | 115 | |
116 | - <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?> |
|
116 | + <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?> |
|
117 | 117 | <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"> |
118 | - <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?> |
|
119 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
120 | - <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong> |
|
118 | + <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?> |
|
119 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
120 | + <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong> |
|
121 | 121 | </td> |
122 | 122 | <td class="wpinv_cart_subtotal text-right"> |
123 | - <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span> |
|
123 | + <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span> |
|
124 | 124 | </td> |
125 | - <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?> |
|
125 | + <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?> |
|
126 | 126 | </tr> |
127 | 127 | <?php } ?> |
128 | 128 | |
129 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
129 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
130 | 130 | <tr class="wpinv_cart_footer_row wpinv_cart_discount_row"> |
131 | - <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?> |
|
132 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right"> |
|
133 | - <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong> |
|
131 | + <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?> |
|
132 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right"> |
|
133 | + <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong> |
|
134 | 134 | </td> |
135 | 135 | <td class="wpinv_cart_discount text-right"> |
136 | - <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span> |
|
136 | + <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span> |
|
137 | 137 | </td> |
138 | - <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?> |
|
138 | + <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?> |
|
139 | 139 | </tr> |
140 | 140 | <?php } ?> |
141 | 141 | |
142 | - <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?> |
|
142 | + <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?> |
|
143 | 143 | <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"> |
144 | - <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?> |
|
145 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right"> |
|
144 | + <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?> |
|
145 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right"> |
|
146 | 146 | <strong><?php echo $tax_label; ?>:</strong> |
147 | 147 | </td> |
148 | 148 | <td class="wpinv_cart_tax text-right"> |
149 | - <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span> |
|
149 | + <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span> |
|
150 | 150 | </td> |
151 | - <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?> |
|
151 | + <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?> |
|
152 | 152 | </tr> |
153 | 153 | <?php } ?> |
154 | 154 | |
155 | 155 | <tr class="wpinv_cart_footer_row"> |
156 | - <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?> |
|
157 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right"> |
|
158 | - <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?> |
|
156 | + <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?> |
|
157 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right"> |
|
158 | + <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?> |
|
159 | 159 | </td> |
160 | 160 | <td class="wpinv_cart_total text-right"> |
161 | - <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span> |
|
161 | + <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span> |
|
162 | 162 | </td> |
163 | - <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?> |
|
163 | + <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?> |
|
164 | 164 | </tr> |
165 | 165 | </tfoot> |
166 | 166 | </table> |
167 | 167 | </div> |
168 | -<?php do_action( 'wpinv_after_email_items', $invoice ); ?> |
|
169 | 168 | \ No newline at end of file |
169 | +<?php do_action('wpinv_after_email_items', $invoice); ?> |
|
170 | 170 | \ No newline at end of file |
@@ -5,140 +5,140 @@ |
||
5 | 5 | |
6 | 6 | global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns, $wpi_session; |
7 | 7 | $invoice = wpinv_get_invoice_cart(); |
8 | -$cart_items = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details(); |
|
8 | +$cart_items = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details(); |
|
9 | 9 | $quantities_enabled = wpinv_item_quantities_enabled(); |
10 | 10 | $use_taxes = wpinv_use_taxes(); |
11 | 11 | $tax_label = $wpinv_euvat->tax_label(); |
12 | -$tax_title = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
12 | +$tax_title = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
13 | 13 | ?> |
14 | 14 | <table id="wpinv_checkout_cart" class="table table-bordered table-hover"> |
15 | 15 | <thead> |
16 | 16 | <tr class="wpinv_cart_header_row"> |
17 | - <?php do_action( 'wpinv_checkout_table_header_first' ); ?> |
|
18 | - <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th> |
|
19 | - <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th> |
|
20 | - <?php if ( $quantities_enabled ) { ?> |
|
21 | - <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th> |
|
17 | + <?php do_action('wpinv_checkout_table_header_first'); ?> |
|
18 | + <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th> |
|
19 | + <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th> |
|
20 | + <?php if ($quantities_enabled) { ?> |
|
21 | + <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th> |
|
22 | 22 | <?php } ?> |
23 | - <?php if ( $use_taxes ) { ?> |
|
23 | + <?php if ($use_taxes) { ?> |
|
24 | 24 | <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th> |
25 | 25 | <?php } ?> |
26 | - <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
27 | - <?php do_action( 'wpinv_checkout_table_header_last' ); ?> |
|
26 | + <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
27 | + <?php do_action('wpinv_checkout_table_header_last'); ?> |
|
28 | 28 | </tr> |
29 | 29 | </thead> |
30 | 30 | <tbody> |
31 | 31 | <?php |
32 | - do_action( 'wpinv_cart_items_before' ); |
|
32 | + do_action('wpinv_cart_items_before'); |
|
33 | 33 | |
34 | - if ( $cart_items ) { |
|
35 | - foreach ( $cart_items as $key => $item ) { |
|
36 | - $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL; |
|
34 | + if ($cart_items) { |
|
35 | + foreach ($cart_items as $key => $item) { |
|
36 | + $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL; |
|
37 | 37 | ?> |
38 | - <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>"> |
|
39 | - <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?> |
|
38 | + <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>"> |
|
39 | + <?php do_action('wpinv_checkout_table_body_first', $item); ?> |
|
40 | 40 | <td class="wpinv_cart_item_name text-left"> |
41 | 41 | <?php |
42 | - if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) { |
|
42 | + if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) { |
|
43 | 43 | echo '<div class="wpinv_cart_item_image">'; |
44 | - echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) ); |
|
44 | + echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25))); |
|
45 | 45 | echo '</div>'; |
46 | 46 | } |
47 | - $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item ); |
|
47 | + $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item); |
|
48 | 48 | echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>'; |
49 | - if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) { |
|
50 | - $post_link = !empty( $item['meta']['invoice_title'] ) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id'] ); |
|
51 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link ); |
|
52 | - echo '<small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
49 | + if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) { |
|
50 | + $post_link = !empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id']); |
|
51 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link); |
|
52 | + echo '<small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
53 | 53 | } |
54 | - do_action( 'wpinv_checkout_cart_item_title_after', $item, $key ); |
|
54 | + do_action('wpinv_checkout_cart_item_title_after', $item, $key); |
|
55 | 55 | ?> |
56 | 56 | </td> |
57 | 57 | <td class="wpinv_cart_item_price text-right"> |
58 | 58 | <?php |
59 | - echo wpinv_cart_item_price( $item ); |
|
60 | - do_action( 'wpinv_checkout_cart_item_price_after', $item, $key ); |
|
59 | + echo wpinv_cart_item_price($item); |
|
60 | + do_action('wpinv_checkout_cart_item_price_after', $item, $key); |
|
61 | 61 | ?> |
62 | 62 | </td> |
63 | - <?php if ( $quantities_enabled ) { ?> |
|
63 | + <?php if ($quantities_enabled) { ?> |
|
64 | 64 | <td class="wpinv_cart_item_qty text-right"> |
65 | 65 | <?php |
66 | - echo wpinv_get_cart_item_quantity( $item ); |
|
67 | - do_action( 'wpinv_cart_item_quantitiy', $item, $key ); |
|
66 | + echo wpinv_get_cart_item_quantity($item); |
|
67 | + do_action('wpinv_cart_item_quantitiy', $item, $key); |
|
68 | 68 | ?> |
69 | 69 | </td> |
70 | 70 | <?php } ?> |
71 | - <?php if ( $use_taxes ) { ?> |
|
71 | + <?php if ($use_taxes) { ?> |
|
72 | 72 | <td class="wpinv_cart_item_tax text-right"> |
73 | 73 | <?php |
74 | - echo wpinv_cart_item_tax( $item ); |
|
74 | + echo wpinv_cart_item_tax($item); |
|
75 | 75 | //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() ); |
76 | - do_action( 'wpinv_cart_item_tax', $item, $key ); |
|
76 | + do_action('wpinv_cart_item_tax', $item, $key); |
|
77 | 77 | ?> |
78 | 78 | </td> |
79 | 79 | <?php } ?> |
80 | 80 | <td class="wpinv_cart_item_subtotal text-right"> |
81 | 81 | <?php |
82 | - echo wpinv_cart_item_subtotal( $item ); |
|
83 | - do_action( 'wpinv_cart_item_subtotal', $item, $key ); |
|
82 | + echo wpinv_cart_item_subtotal($item); |
|
83 | + do_action('wpinv_cart_item_subtotal', $item, $key); |
|
84 | 84 | ?> |
85 | 85 | </td> |
86 | - <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?> |
|
86 | + <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?> |
|
87 | 87 | </tr> |
88 | 88 | <?php } ?> |
89 | 89 | <?php } ?> |
90 | - <?php do_action( 'wpinv_cart_items_middle' ); ?> |
|
91 | - <?php do_action( 'wpinv_cart_items_after' ); ?> |
|
90 | + <?php do_action('wpinv_cart_items_middle'); ?> |
|
91 | + <?php do_action('wpinv_cart_items_after'); ?> |
|
92 | 92 | </tbody> |
93 | 93 | <tfoot> |
94 | 94 | <?php $cart_columns = wpinv_checkout_cart_columns(); ?> |
95 | - <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?> |
|
95 | + <?php if (has_action('wpinv_cart_footer_buttons')) { ?> |
|
96 | 96 | <tr class="wpinv_cart_footer_row"> |
97 | - <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?> |
|
98 | - <td colspan="<?php echo ( $cart_columns ); ?>"> |
|
99 | - <?php do_action( 'wpinv_cart_footer_buttons' ); ?> |
|
97 | + <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?> |
|
98 | + <td colspan="<?php echo ($cart_columns); ?>"> |
|
99 | + <?php do_action('wpinv_cart_footer_buttons'); ?> |
|
100 | 100 | </td> |
101 | - <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?> |
|
101 | + <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?> |
|
102 | 102 | </tr> |
103 | 103 | <?php } ?> |
104 | 104 | |
105 | - <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?> |
|
106 | - <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
107 | - <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?> |
|
108 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
109 | - <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong> |
|
105 | + <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?> |
|
106 | + <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>> |
|
107 | + <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?> |
|
108 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
109 | + <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong> |
|
110 | 110 | </td> |
111 | 111 | <td class="wpinv_cart_subtotal text-right"> |
112 | - <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items ); ?></span> |
|
112 | + <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items); ?></span> |
|
113 | 113 | </td> |
114 | - <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?> |
|
114 | + <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?> |
|
115 | 115 | </tr> |
116 | 116 | <?php } ?> |
117 | 117 | |
118 | - <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?> |
|
118 | + <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?> |
|
119 | 119 | |
120 | - <?php if ( $use_taxes ) { ?> |
|
121 | - <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
122 | - <?php do_action( 'wpinv_checkout_table_tax_first' ); ?> |
|
123 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right"> |
|
120 | + <?php if ($use_taxes) { ?> |
|
121 | + <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>> |
|
122 | + <?php do_action('wpinv_checkout_table_tax_first'); ?> |
|
123 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right"> |
|
124 | 124 | <strong><?php echo $tax_label; ?>:</strong> |
125 | 125 | </td> |
126 | 126 | <td class="wpinv_cart_tax text-right"> |
127 | - <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items ) ); ?></span> |
|
127 | + <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items)); ?></span> |
|
128 | 128 | </td> |
129 | - <?php do_action( 'wpinv_checkout_table_tax_last' ); ?> |
|
129 | + <?php do_action('wpinv_checkout_table_tax_last'); ?> |
|
130 | 130 | </tr> |
131 | 131 | <?php } ?> |
132 | 132 | |
133 | 133 | <tr class="wpinv_cart_footer_row wpinv_cart_total_row"> |
134 | - <?php do_action( 'wpinv_checkout_table_footer_first' ); ?> |
|
135 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right"> |
|
136 | - <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?> |
|
134 | + <?php do_action('wpinv_checkout_table_footer_first'); ?> |
|
135 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right"> |
|
136 | + <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?> |
|
137 | 137 | </td> |
138 | 138 | <td class="wpinv_cart_total text-right"> |
139 | - <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span> |
|
139 | + <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span> |
|
140 | 140 | </td> |
141 | - <?php do_action( 'wpinv_checkout_table_footer_last' ); ?> |
|
141 | + <?php do_action('wpinv_checkout_table_footer_last'); ?> |
|
142 | 142 | </tr> |
143 | 143 | </tfoot> |
144 | 144 | </table> |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -21,68 +21,68 @@ discard block |
||
21 | 21 | public function init() { |
22 | 22 | global $wp_filesystem; |
23 | 23 | |
24 | - if ( empty( $wp_filesystem ) ) { |
|
25 | - require_once( ABSPATH . '/wp-admin/includes/file.php' ); |
|
24 | + if (empty($wp_filesystem)) { |
|
25 | + require_once(ABSPATH . '/wp-admin/includes/file.php'); |
|
26 | 26 | WP_Filesystem(); |
27 | 27 | global $wp_filesystem; |
28 | 28 | } |
29 | 29 | $this->wp_filesystem = $wp_filesystem; |
30 | 30 | |
31 | 31 | $this->export_dir = $this->export_location(); |
32 | - $this->export_url = $this->export_location( true ); |
|
32 | + $this->export_url = $this->export_location(true); |
|
33 | 33 | $this->export = 'invoicing'; |
34 | 34 | $this->filetype = 'csv'; |
35 | 35 | $this->per_page = 20; |
36 | 36 | |
37 | - do_action( 'wpinv_class_reports_init', $this ); |
|
37 | + do_action('wpinv_class_reports_init', $this); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function includes() { |
41 | - do_action( 'wpinv_class_reports_includes', $this ); |
|
41 | + do_action('wpinv_class_reports_includes', $this); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function actions() { |
45 | - if ( is_admin() ) { |
|
46 | - add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 ); |
|
47 | - add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) ); |
|
48 | - add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) ); |
|
45 | + if (is_admin()) { |
|
46 | + add_action('admin_menu', array($this, 'add_submenu'), 10); |
|
47 | + add_action('wpinv_reports_tab_export', array($this, 'export')); |
|
48 | + add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export')); |
|
49 | 49 | |
50 | 50 | // Export Invoices. |
51 | - add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) ); |
|
52 | - add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) ); |
|
53 | - add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) ); |
|
54 | - add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) ); |
|
51 | + add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export')); |
|
52 | + add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns')); |
|
53 | + add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data')); |
|
54 | + add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status')); |
|
55 | 55 | } |
56 | - do_action( 'wpinv_class_reports_actions', $this ); |
|
56 | + do_action('wpinv_class_reports_actions', $this); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function add_submenu() { |
60 | 60 | global $wpi_reports_page; |
61 | - $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) ); |
|
61 | + $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page')); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function reports_page() { |
65 | - if ( !wp_script_is( 'postbox', 'enqueued' ) ) { |
|
66 | - wp_enqueue_script( 'postbox' ); |
|
65 | + if (!wp_script_is('postbox', 'enqueued')) { |
|
66 | + wp_enqueue_script('postbox'); |
|
67 | 67 | } |
68 | - if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { |
|
69 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
68 | + if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) { |
|
69 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
70 | 70 | } |
71 | 71 | |
72 | - $current_page = admin_url( 'admin.php?page=wpinv-reports' ); |
|
73 | - $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export'; |
|
72 | + $current_page = admin_url('admin.php?page=wpinv-reports'); |
|
73 | + $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export'; |
|
74 | 74 | ?> |
75 | 75 | <div class="wrap wpi-reports-wrap"> |
76 | - <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1> |
|
76 | + <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1> |
|
77 | 77 | <h2 class="nav-tab-wrapper wp-clearfix"> |
78 | - <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a> |
|
79 | - <?php do_action( 'wpinv_reports_page_tabs' ); ;?> |
|
78 | + <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a> |
|
79 | + <?php do_action('wpinv_reports_page_tabs'); ;?> |
|
80 | 80 | </h2> |
81 | 81 | <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>"> |
82 | 82 | <?php |
83 | - do_action( 'wpinv_reports_page_top' ); |
|
84 | - do_action( 'wpinv_reports_tab_' . $active_tab ); |
|
85 | - do_action( 'wpinv_reports_page_bottom' ); |
|
83 | + do_action('wpinv_reports_page_top'); |
|
84 | + do_action('wpinv_reports_tab_' . $active_tab); |
|
85 | + do_action('wpinv_reports_page_bottom'); |
|
86 | 86 | ?> |
87 | 87 | </div> |
88 | 88 | <?php |
@@ -90,97 +90,97 @@ discard block |
||
90 | 90 | |
91 | 91 | public function export() { |
92 | 92 | $statuses = wpinv_get_invoice_statuses(); |
93 | - $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses ); |
|
93 | + $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses); |
|
94 | 94 | ?> |
95 | 95 | <div class="metabox-holder"> |
96 | 96 | <div id="post-body"> |
97 | 97 | <div id="post-body-content"> |
98 | - <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?> |
|
98 | + <?php do_action('wpinv_reports_tab_export_content_top'); ?> |
|
99 | 99 | |
100 | 100 | <div class="postbox wpi-export-invoices"> |
101 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2> |
|
101 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2> |
|
102 | 102 | <div class="inside"> |
103 | - <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p> |
|
103 | + <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p> |
|
104 | 104 | <form id="wpi-export-invoices" class="wpi-export-form" method="post"> |
105 | - <?php echo wpinv_html_date_field( array( |
|
105 | + <?php echo wpinv_html_date_field(array( |
|
106 | 106 | 'id' => 'wpi_export_from_date', |
107 | 107 | 'name' => 'from_date', |
108 | 108 | 'data' => array( |
109 | 109 | 'dateFormat' => 'yy-mm-dd' |
110 | 110 | ), |
111 | - 'placeholder' => __( 'From date', 'invoicing' ) ) |
|
111 | + 'placeholder' => __('From date', 'invoicing') ) |
|
112 | 112 | ); ?> |
113 | - <?php echo wpinv_html_date_field( array( |
|
113 | + <?php echo wpinv_html_date_field(array( |
|
114 | 114 | 'id' => 'wpi_export_to_date', |
115 | 115 | 'name' => 'to_date', |
116 | 116 | 'data' => array( |
117 | 117 | 'dateFormat' => 'yy-mm-dd' |
118 | 118 | ), |
119 | - 'placeholder' => __( 'To date', 'invoicing' ) ) |
|
119 | + 'placeholder' => __('To date', 'invoicing') ) |
|
120 | 120 | ); ?> |
121 | 121 | <span id="wpinv-status-wrap"> |
122 | - <?php echo wpinv_html_select( array( |
|
122 | + <?php echo wpinv_html_select(array( |
|
123 | 123 | 'options' => $statuses, |
124 | 124 | 'name' => 'status', |
125 | 125 | 'id' => 'wpi_export_status', |
126 | 126 | 'show_option_all' => false, |
127 | 127 | 'show_option_none' => false, |
128 | 128 | 'class' => '', |
129 | - ) ); ?> |
|
130 | - <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?> |
|
129 | + )); ?> |
|
130 | + <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?> |
|
131 | 131 | </span> |
132 | 132 | <span id="wpinv-submit-wrap"> |
133 | 133 | <input type="hidden" value="invoices" name="export" /> |
134 | - <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" /> |
|
134 | + <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" /> |
|
135 | 135 | </span> |
136 | 136 | </form> |
137 | 137 | </div> |
138 | 138 | </div> |
139 | 139 | |
140 | - <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?> |
|
140 | + <?php do_action('wpinv_reports_tab_export_content_bottom'); ?> |
|
141 | 141 | </div> |
142 | 142 | </div> |
143 | 143 | </div> |
144 | 144 | <?php |
145 | 145 | } |
146 | 146 | |
147 | - public function export_location( $relative = false ) { |
|
147 | + public function export_location($relative = false) { |
|
148 | 148 | $upload_dir = wp_upload_dir(); |
149 | - $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache'; |
|
150 | - $export_location = apply_filters( 'wpinv_export_location', $export_location, $relative ); |
|
149 | + $export_location = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache'; |
|
150 | + $export_location = apply_filters('wpinv_export_location', $export_location, $relative); |
|
151 | 151 | |
152 | - return trailingslashit( $export_location ); |
|
152 | + return trailingslashit($export_location); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | public function check_export_location() { |
156 | 156 | try { |
157 | - if ( empty( $this->wp_filesystem ) ) { |
|
158 | - return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' ); |
|
157 | + if (empty($this->wp_filesystem)) { |
|
158 | + return __('Filesystem ERROR: Could not access filesystem.', 'invoicing'); |
|
159 | 159 | } |
160 | 160 | |
161 | - if ( is_wp_error( $this->wp_filesystem ) ) { |
|
162 | - return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' ); |
|
161 | + if (is_wp_error($this->wp_filesystem)) { |
|
162 | + return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing'); |
|
163 | 163 | } |
164 | 164 | |
165 | - $is_dir = $this->wp_filesystem->is_dir( $this->export_dir ); |
|
166 | - $is_writeable = $is_dir && is_writeable( $this->export_dir ); |
|
165 | + $is_dir = $this->wp_filesystem->is_dir($this->export_dir); |
|
166 | + $is_writeable = $is_dir && is_writeable($this->export_dir); |
|
167 | 167 | |
168 | - if ( $is_dir && $is_writeable ) { |
|
168 | + if ($is_dir && $is_writeable) { |
|
169 | 169 | return true; |
170 | - } else if ( $is_dir && !$is_writeable ) { |
|
171 | - if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
172 | - return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir ); |
|
170 | + } else if ($is_dir && !$is_writeable) { |
|
171 | + if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) { |
|
172 | + return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return true; |
176 | 176 | } else { |
177 | - if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
178 | - return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir ); |
|
177 | + if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) { |
|
178 | + return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | return true; |
182 | 182 | } |
183 | - } catch ( Exception $e ) { |
|
183 | + } catch (Exception $e) { |
|
184 | 184 | return $e->getMessage(); |
185 | 185 | } |
186 | 186 | } |
@@ -188,130 +188,130 @@ discard block |
||
188 | 188 | public function ajax_export() { |
189 | 189 | $response = array(); |
190 | 190 | $response['success'] = false; |
191 | - $response['msg'] = __( 'Invalid export request found.', 'invoicing' ); |
|
191 | + $response['msg'] = __('Invalid export request found.', 'invoicing'); |
|
192 | 192 | |
193 | - if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) { |
|
194 | - wp_send_json( $response ); |
|
193 | + if (empty($_POST['data']) || !current_user_can('manage_options')) { |
|
194 | + wp_send_json($response); |
|
195 | 195 | } |
196 | 196 | |
197 | - parse_str( $_POST['data'], $data ); |
|
197 | + parse_str($_POST['data'], $data); |
|
198 | 198 | |
199 | - $data['step'] = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; |
|
199 | + $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1; |
|
200 | 200 | |
201 | 201 | $_REQUEST = (array)$data; |
202 | - if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) { |
|
203 | - $response['msg'] = __( 'Security check failed.', 'invoicing' ); |
|
204 | - wp_send_json( $response ); |
|
202 | + if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) { |
|
203 | + $response['msg'] = __('Security check failed.', 'invoicing'); |
|
204 | + wp_send_json($response); |
|
205 | 205 | } |
206 | 206 | |
207 | - if ( ( $error = $this->check_export_location( true ) ) !== true ) { |
|
208 | - $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' ); |
|
209 | - wp_send_json( $response ); |
|
207 | + if (($error = $this->check_export_location(true)) !== true) { |
|
208 | + $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing'); |
|
209 | + wp_send_json($response); |
|
210 | 210 | } |
211 | 211 | |
212 | - $this->set_export_params( $_REQUEST ); |
|
212 | + $this->set_export_params($_REQUEST); |
|
213 | 213 | |
214 | 214 | $return = $this->process_export_step(); |
215 | 215 | $done = $this->get_export_status(); |
216 | 216 | |
217 | - if ( $return ) { |
|
217 | + if ($return) { |
|
218 | 218 | $this->step += 1; |
219 | 219 | |
220 | 220 | $response['success'] = true; |
221 | 221 | $response['msg'] = ''; |
222 | 222 | |
223 | - if ( $done >= 100 ) { |
|
223 | + if ($done >= 100) { |
|
224 | 224 | $this->step = 'done'; |
225 | - $new_filename = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype; |
|
225 | + $new_filename = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype; |
|
226 | 226 | $new_file = $this->export_dir . $new_filename; |
227 | 227 | |
228 | - if ( file_exists( $this->file ) ) { |
|
229 | - $this->wp_filesystem->move( $this->file, $new_file, true ); |
|
228 | + if (file_exists($this->file)) { |
|
229 | + $this->wp_filesystem->move($this->file, $new_file, true); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( file_exists( $new_file ) ) { |
|
233 | - $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) ); |
|
232 | + if (file_exists($new_file)) { |
|
233 | + $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2)); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | 237 | $response['data']['step'] = $this->step; |
238 | 238 | $response['data']['done'] = $done; |
239 | 239 | } else { |
240 | - $response['msg'] = __( 'No data found for export.', 'invoicing' ); |
|
240 | + $response['msg'] = __('No data found for export.', 'invoicing'); |
|
241 | 241 | } |
242 | 242 | |
243 | - wp_send_json( $response ); |
|
243 | + wp_send_json($response); |
|
244 | 244 | } |
245 | 245 | |
246 | - public function set_export_params( $request ) { |
|
246 | + public function set_export_params($request) { |
|
247 | 247 | $this->empty = false; |
248 | - $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1; |
|
249 | - $this->export = !empty( $request['export'] ) ? $request['export'] : $this->export; |
|
248 | + $this->step = !empty($request['step']) ? absint($request['step']) : 1; |
|
249 | + $this->export = !empty($request['export']) ? $request['export'] : $this->export; |
|
250 | 250 | $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype; |
251 | 251 | $this->file = $this->export_dir . $this->filename; |
252 | 252 | |
253 | - do_action( 'wpinv_export_set_params_' . $this->export, $request ); |
|
253 | + do_action('wpinv_export_set_params_' . $this->export, $request); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | public function get_columns() { |
257 | 257 | $columns = array( |
258 | - 'id' => __( 'ID', 'invoicing' ), |
|
259 | - 'date' => __( 'Date', 'invoicing' ) |
|
258 | + 'id' => __('ID', 'invoicing'), |
|
259 | + 'date' => __('Date', 'invoicing') |
|
260 | 260 | ); |
261 | 261 | |
262 | - return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns ); |
|
262 | + return apply_filters('wpinv_export_get_columns_' . $this->export, $columns); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | protected function get_export_file() { |
266 | 266 | $file = ''; |
267 | 267 | |
268 | - if ( $this->wp_filesystem->exists( $this->file ) ) { |
|
269 | - $file = $this->wp_filesystem->get_contents( $this->file ); |
|
268 | + if ($this->wp_filesystem->exists($this->file)) { |
|
269 | + $file = $this->wp_filesystem->get_contents($this->file); |
|
270 | 270 | } else { |
271 | - $this->wp_filesystem->put_contents( $this->file, '' ); |
|
271 | + $this->wp_filesystem->put_contents($this->file, ''); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | return $file; |
275 | 275 | } |
276 | 276 | |
277 | - protected function attach_export_data( $data = '' ) { |
|
278 | - $filedata = $this->get_export_file(); |
|
279 | - $filedata .= $data; |
|
277 | + protected function attach_export_data($data = '') { |
|
278 | + $filedata = $this->get_export_file(); |
|
279 | + $filedata .= $data; |
|
280 | 280 | |
281 | - $this->wp_filesystem->put_contents( $this->file, $filedata ); |
|
281 | + $this->wp_filesystem->put_contents($this->file, $filedata); |
|
282 | 282 | |
283 | - $rows = file( $this->file, FILE_SKIP_EMPTY_LINES ); |
|
283 | + $rows = file($this->file, FILE_SKIP_EMPTY_LINES); |
|
284 | 284 | $columns = $this->get_columns(); |
285 | - $columns = empty( $columns ) ? 0 : 1; |
|
285 | + $columns = empty($columns) ? 0 : 1; |
|
286 | 286 | |
287 | - $this->empty = count( $rows ) == $columns ? true : false; |
|
287 | + $this->empty = count($rows) == $columns ? true : false; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | public function print_columns() { |
291 | 291 | $column_data = ''; |
292 | 292 | $columns = $this->get_columns(); |
293 | 293 | $i = 1; |
294 | - foreach( $columns as $key => $column ) { |
|
295 | - $column_data .= '"' . addslashes( $column ) . '"'; |
|
296 | - $column_data .= $i == count( $columns ) ? '' : ','; |
|
294 | + foreach ($columns as $key => $column) { |
|
295 | + $column_data .= '"' . addslashes($column) . '"'; |
|
296 | + $column_data .= $i == count($columns) ? '' : ','; |
|
297 | 297 | $i++; |
298 | 298 | } |
299 | 299 | $column_data .= "\r\n"; |
300 | 300 | |
301 | - $this->attach_export_data( $column_data ); |
|
301 | + $this->attach_export_data($column_data); |
|
302 | 302 | |
303 | 303 | return $column_data; |
304 | 304 | } |
305 | 305 | |
306 | 306 | public function process_export_step() { |
307 | - if ( $this->step < 2 ) { |
|
308 | - @unlink( $this->file ); |
|
307 | + if ($this->step < 2) { |
|
308 | + @unlink($this->file); |
|
309 | 309 | $this->print_columns(); |
310 | 310 | } |
311 | 311 | |
312 | 312 | $return = $this->print_rows(); |
313 | 313 | |
314 | - if ( $return ) { |
|
314 | + if ($return) { |
|
315 | 315 | return true; |
316 | 316 | } else { |
317 | 317 | return false; |
@@ -320,23 +320,23 @@ discard block |
||
320 | 320 | |
321 | 321 | public function get_export_status() { |
322 | 322 | $status = 100; |
323 | - return apply_filters( 'wpinv_get_export_status_' . $this->export, $status ); |
|
323 | + return apply_filters('wpinv_get_export_status_' . $this->export, $status); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | public function get_export_data() { |
327 | 327 | $data = array( |
328 | 328 | 0 => array( |
329 | 329 | 'id' => '', |
330 | - 'data' => date( 'F j, Y' ) |
|
330 | + 'data' => date('F j, Y') |
|
331 | 331 | ), |
332 | 332 | 1 => array( |
333 | 333 | 'id' => '', |
334 | - 'data' => date( 'F j, Y' ) |
|
334 | + 'data' => date('F j, Y') |
|
335 | 335 | ) |
336 | 336 | ); |
337 | 337 | |
338 | - $data = apply_filters( 'wpinv_export_get_data', $data ); |
|
339 | - $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data ); |
|
338 | + $data = apply_filters('wpinv_export_get_data', $data); |
|
339 | + $data = apply_filters('wpinv_export_get_data_' . $this->export, $data); |
|
340 | 340 | |
341 | 341 | return $data; |
342 | 342 | } |
@@ -346,20 +346,20 @@ discard block |
||
346 | 346 | $data = $this->get_export_data(); |
347 | 347 | $columns = $this->get_columns(); |
348 | 348 | |
349 | - if ( $data ) { |
|
350 | - foreach ( $data as $row ) { |
|
349 | + if ($data) { |
|
350 | + foreach ($data as $row) { |
|
351 | 351 | $i = 1; |
352 | - foreach ( $row as $key => $column ) { |
|
353 | - if ( array_key_exists( $key, $columns ) ) { |
|
354 | - $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"'; |
|
355 | - $row_data .= $i == count( $columns ) ? '' : ','; |
|
352 | + foreach ($row as $key => $column) { |
|
353 | + if (array_key_exists($key, $columns)) { |
|
354 | + $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"'; |
|
355 | + $row_data .= $i == count($columns) ? '' : ','; |
|
356 | 356 | $i++; |
357 | 357 | } |
358 | 358 | } |
359 | 359 | $row_data .= "\r\n"; |
360 | 360 | } |
361 | 361 | |
362 | - $this->attach_export_data( $row_data ); |
|
362 | + $this->attach_export_data($row_data); |
|
363 | 363 | |
364 | 364 | return $row_data; |
365 | 365 | } |
@@ -368,46 +368,46 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | // Export Invoices. |
371 | - public function set_invoices_export( $request ) { |
|
372 | - $this->from_date = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : ''; |
|
373 | - $this->to_date = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : ''; |
|
374 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish'; |
|
371 | + public function set_invoices_export($request) { |
|
372 | + $this->from_date = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : ''; |
|
373 | + $this->to_date = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : ''; |
|
374 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish'; |
|
375 | 375 | } |
376 | 376 | |
377 | - public function get_invoices_columns( $columns = array() ) { |
|
377 | + public function get_invoices_columns($columns = array()) { |
|
378 | 378 | $columns = array( |
379 | - 'id' => __( 'ID', 'invoicing' ), |
|
380 | - 'number' => __( 'Number', 'invoicing' ), |
|
381 | - 'date' => __( 'Date', 'invoicing' ), |
|
382 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
383 | - 'status_nicename' => __( 'Status Nicename', 'invoicing' ), |
|
384 | - 'status' => __( 'Status', 'invoicing' ), |
|
385 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
386 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
387 | - 'user_id' => __( 'User ID', 'invoicing' ), |
|
388 | - 'email' => __( 'Email', 'invoicing' ), |
|
389 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
390 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
391 | - 'address' => __( 'Address', 'invoicing' ), |
|
392 | - 'city' => __( 'City', 'invoicing' ), |
|
393 | - 'state' => __( 'State', 'invoicing' ), |
|
394 | - 'country' => __( 'Country', 'invoicing' ), |
|
395 | - 'zip' => __( 'Zipcode', 'invoicing' ), |
|
396 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
397 | - 'company' => __( 'Company', 'invoicing' ), |
|
398 | - 'vat_number' => __( 'Vat Number', 'invoicing' ), |
|
399 | - 'ip' => __( 'IP', 'invoicing' ), |
|
400 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
401 | - 'gateway_nicename' => __( 'Gateway Nicename', 'invoicing' ), |
|
402 | - 'transaction_id'=> __( 'Transaction ID', 'invoicing' ), |
|
403 | - 'currency' => __( 'Currency', 'invoicing' ), |
|
404 | - 'due_date' => __( 'Due Date', 'invoicing' ), |
|
379 | + 'id' => __('ID', 'invoicing'), |
|
380 | + 'number' => __('Number', 'invoicing'), |
|
381 | + 'date' => __('Date', 'invoicing'), |
|
382 | + 'amount' => __('Amount', 'invoicing'), |
|
383 | + 'status_nicename' => __('Status Nicename', 'invoicing'), |
|
384 | + 'status' => __('Status', 'invoicing'), |
|
385 | + 'tax' => __('Tax', 'invoicing'), |
|
386 | + 'discount' => __('Discount', 'invoicing'), |
|
387 | + 'user_id' => __('User ID', 'invoicing'), |
|
388 | + 'email' => __('Email', 'invoicing'), |
|
389 | + 'first_name' => __('First Name', 'invoicing'), |
|
390 | + 'last_name' => __('Last Name', 'invoicing'), |
|
391 | + 'address' => __('Address', 'invoicing'), |
|
392 | + 'city' => __('City', 'invoicing'), |
|
393 | + 'state' => __('State', 'invoicing'), |
|
394 | + 'country' => __('Country', 'invoicing'), |
|
395 | + 'zip' => __('Zipcode', 'invoicing'), |
|
396 | + 'phone' => __('Phone', 'invoicing'), |
|
397 | + 'company' => __('Company', 'invoicing'), |
|
398 | + 'vat_number' => __('Vat Number', 'invoicing'), |
|
399 | + 'ip' => __('IP', 'invoicing'), |
|
400 | + 'gateway' => __('Gateway', 'invoicing'), |
|
401 | + 'gateway_nicename' => __('Gateway Nicename', 'invoicing'), |
|
402 | + 'transaction_id'=> __('Transaction ID', 'invoicing'), |
|
403 | + 'currency' => __('Currency', 'invoicing'), |
|
404 | + 'due_date' => __('Due Date', 'invoicing'), |
|
405 | 405 | ); |
406 | 406 | |
407 | 407 | return $columns; |
408 | 408 | } |
409 | 409 | |
410 | - public function get_invoices_data( $response = array() ) { |
|
410 | + public function get_invoices_data($response = array()) { |
|
411 | 411 | $args = array( |
412 | 412 | 'limit' => $this->per_page, |
413 | 413 | 'page' => $this->step, |
@@ -415,35 +415,35 @@ discard block |
||
415 | 415 | 'orderby' => 'date', |
416 | 416 | ); |
417 | 417 | |
418 | - if ( $this->status != 'any' ) { |
|
418 | + if ($this->status != 'any') { |
|
419 | 419 | $args['status'] = $this->status; |
420 | 420 | } |
421 | 421 | |
422 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
422 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
423 | 423 | $args['date_query'] = array( |
424 | 424 | array( |
425 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
426 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
425 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
426 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
427 | 427 | 'inclusive' => true |
428 | 428 | ) |
429 | 429 | ); |
430 | 430 | } |
431 | 431 | |
432 | - $invoices = wpinv_get_invoices( $args ); |
|
432 | + $invoices = wpinv_get_invoices($args); |
|
433 | 433 | |
434 | 434 | $data = array(); |
435 | 435 | |
436 | - if ( !empty( $invoices ) ) { |
|
437 | - foreach ( $invoices as $invoice ) { |
|
436 | + if (!empty($invoices)) { |
|
437 | + foreach ($invoices as $invoice) { |
|
438 | 438 | $row = array( |
439 | 439 | 'id' => $invoice->ID, |
440 | 440 | 'number' => $invoice->get_number(), |
441 | - 'date' => $invoice->get_invoice_date( false ), |
|
442 | - 'amount' => wpinv_round_amount( $invoice->get_total() ), |
|
443 | - 'status_nicename' => $invoice->get_status( true ), |
|
441 | + 'date' => $invoice->get_invoice_date(false), |
|
442 | + 'amount' => wpinv_round_amount($invoice->get_total()), |
|
443 | + 'status_nicename' => $invoice->get_status(true), |
|
444 | 444 | 'status' => $invoice->get_status(), |
445 | - 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '', |
|
446 | - 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '', |
|
445 | + 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '', |
|
446 | + 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '', |
|
447 | 447 | 'user_id' => $invoice->get_user_id(), |
448 | 448 | 'email' => $invoice->get_email(), |
449 | 449 | 'first_name' => $invoice->get_first_name(), |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | 'due_date' => $invoice->needs_payment() ? $invoice->get_due_date() : '', |
465 | 465 | ); |
466 | 466 | |
467 | - $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice ); |
|
467 | + $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | return $data; |
@@ -480,29 +480,29 @@ discard block |
||
480 | 480 | 'return' => 'ids', |
481 | 481 | ); |
482 | 482 | |
483 | - if ( $this->status != 'any' ) { |
|
483 | + if ($this->status != 'any') { |
|
484 | 484 | $args['status'] = $this->status; |
485 | 485 | } |
486 | 486 | |
487 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
487 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
488 | 488 | $args['date_query'] = array( |
489 | 489 | array( |
490 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
491 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
490 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
491 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
492 | 492 | 'inclusive' => true |
493 | 493 | ) |
494 | 494 | ); |
495 | 495 | } |
496 | 496 | |
497 | - $invoices = wpinv_get_invoices( $args ); |
|
498 | - $total = !empty( $invoices ) ? count( $invoices ) : 0; |
|
497 | + $invoices = wpinv_get_invoices($args); |
|
498 | + $total = !empty($invoices) ? count($invoices) : 0; |
|
499 | 499 | $status = 100; |
500 | 500 | |
501 | - if ( $total > 0 ) { |
|
502 | - $status = ( ( $this->per_page * $this->step ) / $total ) * 100; |
|
501 | + if ($total > 0) { |
|
502 | + $status = (($this->per_page * $this->step) / $total) * 100; |
|
503 | 503 | } |
504 | 504 | |
505 | - if ( $status > 100 ) { |
|
505 | + if ($status > 100) { |
|
506 | 506 | $status = 100; |
507 | 507 | } |
508 | 508 |