@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Privacy/GDPR related functionality which ties into WordPress functionality. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy Class. |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | * Init - hook into events. |
15 | 15 | */ |
16 | 16 | public function __construct() { |
17 | - parent::__construct( __( 'Invoicing', 'invoicing' ) ); |
|
17 | + parent::__construct(__('Invoicing', 'invoicing')); |
|
18 | 18 | |
19 | 19 | // Include supporting classes. |
20 | 20 | include_once 'class-wpinv-privacy-exporters.php'; |
21 | 21 | |
22 | 22 | // This hook registers Invoicing data exporters. |
23 | - $this->add_exporter( 'wpinv-customer-invoices', __( 'Customer Invoices', 'invoicing' ), array( 'WPInv_Privacy_Exporters', 'customer_invoice_data_exporter' ) ); |
|
23 | + $this->add_exporter('wpinv-customer-invoices', __('Customer Invoices', 'invoicing'), array('WPInv_Privacy_Exporters', 'customer_invoice_data_exporter')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -30,28 +30,28 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function get_privacy_message() { |
32 | 32 | |
33 | - $content = '<h2>' . __( 'Invoices and checkout', 'invoicing' ) . '</h2>' . |
|
33 | + $content = '<h2>' . __('Invoices and checkout', 'invoicing') . '</h2>' . |
|
34 | 34 | '<div contenteditable="false">' . |
35 | - '<p class="wp-policy-help">' . __( 'Example privacy texts.', 'invoicing' ) . '</p>' . |
|
35 | + '<p class="wp-policy-help">' . __('Example privacy texts.', 'invoicing') . '</p>' . |
|
36 | 36 | '</div>' . |
37 | - '<p>' . __( 'We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing' ) . '</p>' . |
|
38 | - '<p>' . __( 'Handling this data also allows us to:', 'invoicing' ) . '</p>' . |
|
37 | + '<p>' . __('We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing') . '</p>' . |
|
38 | + '<p>' . __('Handling this data also allows us to:', 'invoicing') . '</p>' . |
|
39 | 39 | '<ul>' . |
40 | - '<li>' . __( '- Send you important account/order/service information.', 'invoicing' ) . '</li>' . |
|
41 | - '<li>' . __( '- Estimate taxes based on your location.', 'invoicing' ) . '</li>' . |
|
42 | - '<li>' . __( '- Respond to your queries or complaints.', 'invoicing' ) . '</li>' . |
|
43 | - '<li>' . __( '- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
44 | - '<li>' . __( '- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing' ) . '</li>' . |
|
45 | - '<li>' . __( '- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
40 | + '<li>' . __('- Send you important account/order/service information.', 'invoicing') . '</li>' . |
|
41 | + '<li>' . __('- Estimate taxes based on your location.', 'invoicing') . '</li>' . |
|
42 | + '<li>' . __('- Respond to your queries or complaints.', 'invoicing') . '</li>' . |
|
43 | + '<li>' . __('- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing') . '</li>' . |
|
44 | + '<li>' . __('- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing') . '</li>' . |
|
45 | + '<li>' . __('- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing') . '</li>' . |
|
46 | 46 | '</ul>' . |
47 | - '<p>' . __( 'In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing' ) . '</p>' . |
|
48 | - '<h2>' . __( 'What we share with others', 'invoicing' ) . '</h2>' . |
|
49 | - '<p>' . __( 'We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing' ) . '</p>' . |
|
47 | + '<p>' . __('In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing') . '</p>' . |
|
48 | + '<h2>' . __('What we share with others', 'invoicing') . '</h2>' . |
|
49 | + '<p>' . __('We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing') . '</p>' . |
|
50 | 50 | '<div contenteditable="false">' . |
51 | - '<p class="wp-policy-help">' . __( 'In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing' ) . '</p>' . |
|
51 | + '<p class="wp-policy-help">' . __('In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing') . '</p>' . |
|
52 | 52 | '</div>' . |
53 | - '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing' ) . '</p>' . |
|
54 | - '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing' ) . '</p>'; |
|
53 | + '<p>' . __('We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing') . '</p>' . |
|
54 | + '<p>' . __('Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing') . '</p>'; |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | // '</p>' . |
63 | 63 | // '</div>'; |
64 | 64 | |
65 | - return apply_filters( 'wpinv_privacy_policy_content', $content ); |
|
65 | + return apply_filters('wpinv_privacy_policy_content', $content); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | } |
@@ -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 | |
@@ -14,74 +14,74 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function init() { |
17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
17 | + do_action('wpinv_class_notes_init', $this); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function includes() { |
21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
21 | + do_action('wpinv_class_notes_includes', $this); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function actions() { |
25 | 25 | // Secure inovice notes |
26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
27 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
27 | + add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1); |
|
28 | 28 | |
29 | 29 | // Count comments |
30 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 ); |
|
30 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2); |
|
31 | 31 | |
32 | 32 | // Delete comments count cache whenever there is a new comment or a comment status changes |
33 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
34 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
33 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
34 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
35 | 35 | |
36 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
36 | + do_action('wpinv_class_notes_actions', $this); |
|
37 | 37 | } |
38 | 38 | |
39 | - public function set_invoice_note_type( $query ) { |
|
40 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
39 | + public function set_invoice_note_type($query) { |
|
40 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
41 | 41 | |
42 | - if ( $post_ID && in_array(get_post_type( $post_ID ), array($this->invoice_post_type, 'wpi_quote' )) ) { |
|
42 | + if ($post_ID && in_array(get_post_type($post_ID), array($this->invoice_post_type, 'wpi_quote'))) { |
|
43 | 43 | $query->query_vars['type__in'] = $this->comment_type; |
44 | 44 | $query->query_vars['type__not_in'] = ''; |
45 | 45 | } else { |
46 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
47 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
48 | - $key = array_search( $this->comment_type, $type_in ); |
|
49 | - unset( $query->query_vars['type__in'][$key] ); |
|
50 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
46 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
47 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
48 | + $key = array_search($this->comment_type, $type_in); |
|
49 | + unset($query->query_vars['type__in'][$key]); |
|
50 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
51 | 51 | $query->query_vars['type__in'] = ''; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
56 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
55 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
56 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
57 | 57 | $query->query_vars['type__not_in'][] = $this->comment_type; |
58 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
58 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
59 | 59 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
60 | 60 | $query->query_vars['type__not_in'][] = $this->comment_type; |
61 | 61 | } |
62 | 62 | } else { |
63 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
63 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | 67 | return $query; |
68 | 68 | } |
69 | 69 | |
70 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
70 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
71 | 71 | $args = array( |
72 | 72 | 'post_id' => $invoice_id, |
73 | 73 | 'orderby' => 'comment_ID', |
74 | 74 | 'order' => 'ASC', |
75 | 75 | ); |
76 | 76 | |
77 | - if ( $type == 'customer' ) { |
|
77 | + if ($type == 'customer') { |
|
78 | 78 | $args['meta_key'] = '_wpi_customer_note'; |
79 | 79 | $args['meta_value'] = 1; |
80 | 80 | } |
81 | 81 | |
82 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
82 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
83 | 83 | |
84 | - return get_comments( $args ); |
|
84 | + return get_comments($args); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @return void |
93 | 93 | */ |
94 | 94 | public function delete_comments_count_cache() { |
95 | - delete_transient( 'wpinv_count_comments' ); |
|
95 | + delete_transient('wpinv_count_comments'); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -103,16 +103,16 @@ discard block |
||
103 | 103 | * @param int $post_id Post ID. |
104 | 104 | * @return object |
105 | 105 | */ |
106 | - public function wp_count_comments( $stats, $post_id ) { |
|
106 | + public function wp_count_comments($stats, $post_id) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - if ( 0 === $post_id ) { |
|
110 | - $stats = get_transient( 'wpinv_count_comments' ); |
|
109 | + if (0 === $post_id) { |
|
110 | + $stats = get_transient('wpinv_count_comments'); |
|
111 | 111 | |
112 | - if ( ! $stats ) { |
|
112 | + if (!$stats) { |
|
113 | 113 | $stats = array(); |
114 | 114 | |
115 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A ); |
|
115 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A); |
|
116 | 116 | |
117 | 117 | $total = 0; |
118 | 118 | $approved = array( |
@@ -123,33 +123,33 @@ discard block |
||
123 | 123 | 'post-trashed' => 'post-trashed', |
124 | 124 | ); |
125 | 125 | |
126 | - foreach ( (array) $count as $row ) { |
|
126 | + foreach ((array)$count as $row) { |
|
127 | 127 | // Do not count post-trashed toward totals. |
128 | - if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) { |
|
128 | + if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) { |
|
129 | 129 | $total += $row['num_comments']; |
130 | 130 | } |
131 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
132 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
131 | + if (isset($approved[$row['comment_approved']])) { |
|
132 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | $stats['total_comments'] = $total; |
137 | 137 | $stats['all'] = $total; |
138 | - foreach ( $approved as $key ) { |
|
139 | - if ( empty( $stats[ $key ] ) ) { |
|
140 | - $stats[ $key ] = 0; |
|
138 | + foreach ($approved as $key) { |
|
139 | + if (empty($stats[$key])) { |
|
140 | + $stats[$key] = 0; |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - $stats = (object) $stats; |
|
145 | - set_transient( 'wpinv_count_comments', $stats ); |
|
144 | + $stats = (object)$stats; |
|
145 | + set_transient('wpinv_count_comments', $stats); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | return $stats; |
150 | 150 | } |
151 | 151 | |
152 | - function wpinv_comment_feed_where($where){ |
|
153 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
152 | + function wpinv_comment_feed_where($where) { |
|
153 | + return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' "; |
|
154 | 154 | } |
155 | 155 | } |
@@ -11,49 +11,49 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | - if ( $wpi_version == WPINV_VERSION ) { |
|
16 | + if ($wpi_version == WPINV_VERSION) { |
|
17 | 17 | return; |
18 | 18 | } |
19 | 19 | |
20 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
20 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
21 | 21 | wpinv_v005_upgrades(); |
22 | 22 | } |
23 | 23 | |
24 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
24 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
25 | 25 | wpinv_v110_upgrades(); |
26 | 26 | } |
27 | 27 | |
28 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
28 | + update_option('wpinv_version', WPINV_VERSION); |
|
29 | 29 | } |
30 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
30 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
31 | 31 | |
32 | 32 | function wpinv_v005_upgrades() { |
33 | 33 | global $wpdb; |
34 | 34 | |
35 | 35 | // Invoices status |
36 | - $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
37 | - if ( !empty( $results ) ) { |
|
38 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
36 | + $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
37 | + if (!empty($results)) { |
|
38 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
39 | 39 | |
40 | 40 | // Clean post cache |
41 | - foreach ( $results as $row ) { |
|
42 | - clean_post_cache( $row->ID ); |
|
41 | + foreach ($results as $row) { |
|
42 | + clean_post_cache($row->ID); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Item meta key changes |
47 | 47 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
48 | - $results = $wpdb->get_results( $query ); |
|
48 | + $results = $wpdb->get_results($query); |
|
49 | 49 | |
50 | - if ( !empty( $results ) ) { |
|
51 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
52 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
53 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
50 | + if (!empty($results)) { |
|
51 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
52 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
53 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
54 | 54 | |
55 | - foreach ( $results as $row ) { |
|
56 | - clean_post_cache( $row->post_id ); |
|
55 | + foreach ($results as $row) { |
|
56 | + clean_post_cache($row->post_id); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -74,79 +74,79 @@ discard block |
||
74 | 74 | function wpinv_convert_old_subscriptions() { |
75 | 75 | global $wpdb; |
76 | 76 | |
77 | - $query = "SELECT ". $wpdb->posts .".ID FROM ". $wpdb->posts ." INNER JOIN ". $wpdb->postmeta ." ON ( ". $wpdb->posts .".ID = ". $wpdb->postmeta .".post_id ) WHERE 1=1 AND ". $wpdb->postmeta .".meta_key = '_wpinv_subscr_status' AND (". $wpdb->postmeta .".meta_value = 'pending' OR ". $wpdb->postmeta .".meta_value = 'active' OR ". $wpdb->postmeta .".meta_value = 'cancelled' OR ". $wpdb->postmeta .".meta_value = 'completed' OR ". $wpdb->postmeta .".meta_value = 'expired' OR ". $wpdb->postmeta .".meta_value = 'trialling' OR ". $wpdb->postmeta .".meta_value = 'failing') AND ". $wpdb->posts .".post_type = 'wpi_invoice' GROUP BY ". $wpdb->posts .".ID ORDER BY ". $wpdb->posts .".ID ASC"; |
|
77 | + $query = "SELECT " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON ( " . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id ) WHERE 1=1 AND " . $wpdb->postmeta . ".meta_key = '_wpinv_subscr_status' AND (" . $wpdb->postmeta . ".meta_value = 'pending' OR " . $wpdb->postmeta . ".meta_value = 'active' OR " . $wpdb->postmeta . ".meta_value = 'cancelled' OR " . $wpdb->postmeta . ".meta_value = 'completed' OR " . $wpdb->postmeta . ".meta_value = 'expired' OR " . $wpdb->postmeta . ".meta_value = 'trialling' OR " . $wpdb->postmeta . ".meta_value = 'failing') AND " . $wpdb->posts . ".post_type = 'wpi_invoice' GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC"; |
|
78 | 78 | |
79 | - $results = $wpdb->get_results( $query ); |
|
79 | + $results = $wpdb->get_results($query); |
|
80 | 80 | |
81 | - if ( empty( $results ) ) { |
|
81 | + if (empty($results)) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - foreach ( $results as $row ) { |
|
86 | - $invoice = new WPInv_Invoice( $row->ID ); |
|
85 | + foreach ($results as $row) { |
|
86 | + $invoice = new WPInv_Invoice($row->ID); |
|
87 | 87 | |
88 | - if ( empty( $invoice->ID ) ) { |
|
88 | + if (empty($invoice->ID)) { |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if ( $invoice->has_status( 'wpi-renewal' ) ) { |
|
92 | + if ($invoice->has_status('wpi-renewal')) { |
|
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | - $item = $invoice->get_recurring( true ); |
|
96 | + $item = $invoice->get_recurring(true); |
|
97 | 97 | |
98 | - if ( empty( $item ) ) { |
|
98 | + if (empty($item)) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | 102 | $is_free_trial = $invoice->is_free_trial(); |
103 | - $profile_id = get_post_meta( $invoice->ID, '_wpinv_subscr_profile_id', true ); |
|
104 | - $subscription_status = get_post_meta( $invoice->ID, '_wpinv_subscr_status', true ); |
|
103 | + $profile_id = get_post_meta($invoice->ID, '_wpinv_subscr_profile_id', true); |
|
104 | + $subscription_status = get_post_meta($invoice->ID, '_wpinv_subscr_status', true); |
|
105 | 105 | $transaction_id = $invoice->get_transaction_id(); |
106 | 106 | |
107 | 107 | // Last invoice |
108 | - $query = "SELECT ID, post_date FROM ". $wpdb->posts ." WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | - $last_payment = $wpdb->get_row( $query ); |
|
108 | + $query = "SELECT ID, post_date FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | + $last_payment = $wpdb->get_row($query); |
|
110 | 110 | |
111 | - if ( !empty( $last_payment ) ) { |
|
112 | - $invoice_date = $last_payment->post_date; |
|
111 | + if (!empty($last_payment)) { |
|
112 | + $invoice_date = $last_payment->post_date; |
|
113 | 113 | |
114 | - $meta_profile_id = get_post_meta( $last_payment->ID, '_wpinv_subscr_profile_id', true ); |
|
115 | - $meta_transaction_id = get_post_meta( $last_payment->ID, '_wpinv_transaction_id', true ); |
|
114 | + $meta_profile_id = get_post_meta($last_payment->ID, '_wpinv_subscr_profile_id', true); |
|
115 | + $meta_transaction_id = get_post_meta($last_payment->ID, '_wpinv_transaction_id', true); |
|
116 | 116 | |
117 | - if ( !empty( $meta_profile_id ) ) { |
|
118 | - $profile_id = $meta_profile_id; |
|
117 | + if (!empty($meta_profile_id)) { |
|
118 | + $profile_id = $meta_profile_id; |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( !empty( $meta_transaction_id ) ) { |
|
122 | - $transaction_id = $meta_transaction_id; |
|
121 | + if (!empty($meta_transaction_id)) { |
|
122 | + $transaction_id = $meta_transaction_id; |
|
123 | 123 | } |
124 | 124 | } else { |
125 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
125 | + $invoice_date = $invoice->get_invoice_date(false); |
|
126 | 126 | } |
127 | 127 | |
128 | - $profile_id = empty( $profile_id ) ? $invoice->ID : $profile_id; |
|
129 | - $status = empty( $subscription_status ) ? 'pending' : $subscription_status; |
|
128 | + $profile_id = empty($profile_id) ? $invoice->ID : $profile_id; |
|
129 | + $status = empty($subscription_status) ? 'pending' : $subscription_status; |
|
130 | 130 | |
131 | - $period = $item->get_recurring_period( true ); |
|
131 | + $period = $item->get_recurring_period(true); |
|
132 | 132 | $interval = $item->get_recurring_interval(); |
133 | 133 | $bill_times = (int)$item->get_recurring_limit(); |
134 | 134 | $add_period = $interval . ' ' . $period; |
135 | 135 | $trial_period = ''; |
136 | 136 | |
137 | - if ( $invoice->is_free_trial() ) { |
|
138 | - $trial_period = $item->get_trial_period( true ); |
|
137 | + if ($invoice->is_free_trial()) { |
|
138 | + $trial_period = $item->get_trial_period(true); |
|
139 | 139 | $free_interval = $item->get_trial_interval(); |
140 | 140 | $trial_period = $free_interval . ' ' . $trial_period; |
141 | 141 | |
142 | - if ( empty( $last_payment ) ) { |
|
142 | + if (empty($last_payment)) { |
|
143 | 143 | $add_period = $trial_period; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
148 | - if ( strtotime( $expiration ) < strtotime( date_i18n( 'Y-m-d' ) ) ) { |
|
149 | - if ( $status == 'active' || $status == 'trialling' || $status == 'pending' ) { |
|
147 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
148 | + if (strtotime($expiration) < strtotime(date_i18n('Y-m-d'))) { |
|
149 | + if ($status == 'active' || $status == 'trialling' || $status == 'pending') { |
|
150 | 150 | $status = 'expired'; |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'frequency' => $interval, |
160 | 160 | 'period' => $period, |
161 | 161 | 'initial_amount' => $invoice->get_total(), |
162 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
162 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
163 | 163 | 'bill_times' => $bill_times, |
164 | 164 | 'created' => $invoice_date, |
165 | 165 | 'expiration' => $expiration, |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | ); |
170 | 170 | |
171 | 171 | $subs_db = new WPInv_Subscriptions_DB; |
172 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) ); |
|
173 | - $subscription = reset( $subs ); |
|
172 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
|
173 | + $subscription = reset($subs); |
|
174 | 174 | |
175 | - if ( empty( $subscription ) || $subscription->id <= 0 ) { |
|
175 | + if (empty($subscription) || $subscription->id <= 0) { |
|
176 | 176 | $subscription = new WPInv_Subscription(); |
177 | - $new_sub = $subscription->create( $args ); |
|
177 | + $new_sub = $subscription->create($args); |
|
178 | 178 | |
179 | - if ( !empty( $bill_times ) && $new_sub->get_times_billed() >= $bill_times && ( 'active' == $new_sub->status || 'trialling' == $new_sub->status ) ) { |
|
179 | + if (!empty($bill_times) && $new_sub->get_times_billed() >= $bill_times && ('active' == $new_sub->status || 'trialling' == $new_sub->status)) { |
|
180 | 180 | $new_sub->complete(); // Mark completed if all times billed |
181 | 181 | } |
182 | 182 | } |
@@ -186,20 +186,20 @@ discard block |
||
186 | 186 | function wpinv_update_new_email_settings() { |
187 | 187 | global $wpinv_options; |
188 | 188 | |
189 | - $current_options = get_option( 'wpinv_settings', array() ); |
|
189 | + $current_options = get_option('wpinv_settings', array()); |
|
190 | 190 | $options = array( |
191 | - 'email_new_invoice_body' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ), |
|
192 | - 'email_cancelled_invoice_body' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ), |
|
193 | - 'email_failed_invoice_body' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ), |
|
194 | - 'email_onhold_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ), |
|
195 | - 'email_processing_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ), |
|
196 | - 'email_refunded_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ), |
|
197 | - 'email_user_invoice_body' => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
198 | - 'email_user_note_body' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ), |
|
199 | - 'email_overdue_body' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
191 | + 'email_new_invoice_body' => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'), |
|
192 | + 'email_cancelled_invoice_body' => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'), |
|
193 | + 'email_failed_invoice_body' => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'), |
|
194 | + 'email_onhold_invoice_body' => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'), |
|
195 | + 'email_processing_invoice_body' => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'), |
|
196 | + 'email_refunded_invoice_body' => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'), |
|
197 | + 'email_user_invoice_body' => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
198 | + 'email_user_note_body' => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'), |
|
199 | + 'email_overdue_body' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
200 | 200 | ); |
201 | 201 | |
202 | - foreach ($options as $option => $value){ |
|
202 | + foreach ($options as $option => $value) { |
|
203 | 203 | if (!isset($current_options[$option])) { |
204 | 204 | $current_options[$option] = $value; |
205 | 205 | } |
@@ -207,5 +207,5 @@ discard block |
||
207 | 207 | |
208 | 208 | $wpinv_options = $current_options; |
209 | 209 | |
210 | - update_option( 'wpinv_settings', $current_options ); |
|
210 | + update_option('wpinv_settings', $current_options); |
|
211 | 211 | } |
212 | 212 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | +if (!defined('ABSPATH')) { |
|
5 | 5 | exit; |
6 | 6 | } |
7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @since 1.0.0 |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
42 | 42 | |
43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if ($_by_profile_id) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
49 | + if (empty($_sub)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
57 | + return $this->setup_subscription($_id_or_object); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
63 | 63 | * @since 1.0.0 |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
66 | + private function setup_subscription($id_or_object = 0) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
68 | + if (empty($id_or_object)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if (is_numeric($id_or_object)) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get($id_or_object); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif (is_object($id_or_object)) { |
|
77 | 77 | |
78 | 78 | $sub = $id_or_object; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
82 | + if (empty($sub)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
86 | + foreach ($sub as $key => $value) { |
|
87 | 87 | $this->$key = $value; |
88 | 88 | } |
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata($this->customer_id); |
|
91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
94 | 94 | |
95 | 95 | return $this; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @since 1.0.0 |
102 | 102 | */ |
103 | - public function __get( $key ) { |
|
103 | + public function __get($key) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if (method_exists($this, 'get_' . $key)) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func(array($this, 'get_' . $key)); |
|
108 | 108 | |
109 | 109 | } else { |
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param array $data Array of attributes for a subscription |
122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
123 | 123 | */ |
124 | - public function create( $data = array() ) { |
|
124 | + public function create($data = array()) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
126 | + if ($this->id != 0) { |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | 'profile_id' => '', |
143 | 143 | ); |
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args($data, $defaults); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
150 | 150 | |
151 | 151 | // Force an active subscription to expired if expiration date is in the past |
152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action('wpinv_subscription_pre_create', $args); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription($id); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param array $args Array of fields to update |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public function update( $args = array() ) { |
|
174 | + public function update($args = array()) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update($this->id, $args); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
179 | 179 | |
180 | 180 | return $ret; |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | public function delete() { |
191 | - return $this->subs_db->delete( $this->id ); |
|
191 | + return $this->subs_db->delete($this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | * @return array |
209 | 209 | */ |
210 | 210 | public function get_child_payments() { |
211 | - $payments = get_posts( array( |
|
212 | - 'post_parent' => (int) $this->parent_payment_id, |
|
211 | + $payments = get_posts(array( |
|
212 | + 'post_parent' => (int)$this->parent_payment_id, |
|
213 | 213 | 'posts_per_page' => '999', |
214 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
214 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
215 | 215 | 'orderby' => 'ID', |
216 | 216 | 'order' => 'DESC', |
217 | 217 | 'post_type' => 'wpi_invoice' |
218 | - ) ); |
|
218 | + )); |
|
219 | 219 | |
220 | 220 | return $payments; |
221 | 221 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function get_total_payments() { |
230 | 230 | $child_payments = $this->get_child_payments(); |
231 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
231 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
232 | 232 | |
233 | - if ( 'pending' != $this->status ) { |
|
233 | + if ('pending' != $this->status) { |
|
234 | 234 | $total_payments++; |
235 | 235 | } |
236 | 236 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | public function get_times_billed() { |
247 | 247 | $times_billed = (int)$this->get_total_payments(); |
248 | 248 | |
249 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
249 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
250 | 250 | $times_billed--; |
251 | 251 | } |
252 | 252 | |
@@ -260,51 +260,51 @@ discard block |
||
260 | 260 | * @param array $args Array of values for the payment, including amount and transaction ID |
261 | 261 | * @return bool |
262 | 262 | */ |
263 | - public function add_payment( $args = array() ) { |
|
264 | - if ( ! $this->parent_payment_id ) { |
|
263 | + public function add_payment($args = array()) { |
|
264 | + if (!$this->parent_payment_id) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - $args = wp_parse_args( $args, array( |
|
268 | + $args = wp_parse_args($args, array( |
|
269 | 269 | 'amount' => '', |
270 | 270 | 'transaction_id' => '', |
271 | 271 | 'gateway' => '' |
272 | - ) ); |
|
272 | + )); |
|
273 | 273 | |
274 | - if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) { |
|
274 | + if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
278 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
279 | - if ( empty( $parent_invoice->ID ) ) { |
|
278 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
279 | + if (empty($parent_invoice->ID)) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | 283 | $invoice = new WPInv_Invoice(); |
284 | - $invoice->set( 'post_type', 'wpi_invoice' ); |
|
285 | - $invoice->set( 'parent_invoice', $this->parent_payment_id ); |
|
286 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
287 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
288 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
289 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
290 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
291 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
292 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
293 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
294 | - $invoice->set( 'address', $parent_invoice->address ); |
|
295 | - $invoice->set( 'city', $parent_invoice->city ); |
|
296 | - $invoice->set( 'country', $parent_invoice->country ); |
|
297 | - $invoice->set( 'state', $parent_invoice->state ); |
|
298 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
299 | - $invoice->set( 'company', $parent_invoice->company ); |
|
300 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
301 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
302 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
303 | - |
|
304 | - if ( empty( $args['gateway'] ) ) { |
|
305 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
284 | + $invoice->set('post_type', 'wpi_invoice'); |
|
285 | + $invoice->set('parent_invoice', $this->parent_payment_id); |
|
286 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
287 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
288 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
289 | + $invoice->set('ip', $parent_invoice->ip); |
|
290 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
291 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
292 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
293 | + $invoice->set('phone', $parent_invoice->phone); |
|
294 | + $invoice->set('address', $parent_invoice->address); |
|
295 | + $invoice->set('city', $parent_invoice->city); |
|
296 | + $invoice->set('country', $parent_invoice->country); |
|
297 | + $invoice->set('state', $parent_invoice->state); |
|
298 | + $invoice->set('zip', $parent_invoice->zip); |
|
299 | + $invoice->set('company', $parent_invoice->company); |
|
300 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
301 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
302 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
303 | + |
|
304 | + if (empty($args['gateway'])) { |
|
305 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
306 | 306 | } else { |
307 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
307 | + $invoice->set('gateway', $args['gateway']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | // increase the earnings for each item in the subscription |
313 | 313 | $items = $recurring_details['cart_details']; |
314 | 314 | |
315 | - if ( $items ) { |
|
315 | + if ($items) { |
|
316 | 316 | $add_items = array(); |
317 | 317 | $cart_details = array(); |
318 | 318 | |
319 | - foreach ( $items as $item ) { |
|
319 | + foreach ($items as $item) { |
|
320 | 320 | $add_item = array(); |
321 | 321 | $add_item['id'] = $item['id']; |
322 | 322 | $add_item['quantity'] = $item['quantity']; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | } |
328 | 328 | |
329 | - $invoice->set( 'items', $add_items ); |
|
329 | + $invoice->set('items', $add_items); |
|
330 | 330 | $invoice->cart_details = $cart_details; |
331 | 331 | } |
332 | 332 | |
@@ -336,29 +336,29 @@ discard block |
||
336 | 336 | $tax = $recurring_details['tax']; |
337 | 337 | $discount = $recurring_details['discount']; |
338 | 338 | |
339 | - if ( $discount > 0 ) { |
|
340 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
339 | + if ($discount > 0) { |
|
340 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
341 | 341 | } |
342 | 342 | |
343 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
344 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
345 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
346 | - $invoice->total = wpinv_round_amount( $total ); |
|
343 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
344 | + $invoice->tax = wpinv_round_amount($tax); |
|
345 | + $invoice->discount = wpinv_round_amount($discount); |
|
346 | + $invoice->total = wpinv_round_amount($total); |
|
347 | 347 | |
348 | - $invoice = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args ); |
|
348 | + $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args); |
|
349 | 349 | |
350 | 350 | $invoice->save(); |
351 | - $invoice->update_meta( '_wpinv_subscription_id', $this->id ); |
|
351 | + $invoice->update_meta('_wpinv_subscription_id', $this->id); |
|
352 | 352 | |
353 | - if ( !empty( $invoice->ID ) ) { |
|
354 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
353 | + if (!empty($invoice->ID)) { |
|
354 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
355 | 355 | sleep(1); |
356 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
356 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
358 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
359 | 359 | |
360 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
361 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] ); |
|
360 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
361 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']); |
|
362 | 362 | |
363 | 363 | return $invoice->ID; |
364 | 364 | } |
@@ -374,12 +374,12 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function get_transaction_id() { |
376 | 376 | |
377 | - if( empty( $this->transaction_id ) ) { |
|
377 | + if (empty($this->transaction_id)) { |
|
378 | 378 | |
379 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
379 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
380 | 380 | |
381 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | - $this->set_transaction_id( $txn_id ); |
|
381 | + if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) { |
|
382 | + $this->set_transaction_id($txn_id); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | } |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @since 1.0.0.4 |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
397 | + public function set_transaction_id($txn_id = '') { |
|
398 | + $this->update(array('transaction_id' => $txn_id)); |
|
399 | 399 | $this->transaction_id = $txn_id; |
400 | 400 | } |
401 | 401 | |
@@ -411,35 +411,35 @@ discard block |
||
411 | 411 | |
412 | 412 | |
413 | 413 | // Determine what date to use as the start for the new expiration calculation |
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
414 | + if ($expires > current_time('timestamp') && $this->is_active()) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | 418 | } else { |
419 | 419 | |
420 | - $base_date = current_time( 'timestamp' ); |
|
420 | + $base_date = current_time('timestamp'); |
|
421 | 421 | |
422 | 422 | } |
423 | 423 | |
424 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
424 | + $last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date)); |
|
425 | 425 | |
426 | 426 | |
427 | 427 | $frequency = isset($this->frequency) ? $this->frequency : 1; |
428 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
428 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date)); |
|
429 | 429 | |
430 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
430 | + if (date('j', $base_date) == $last_day && 'day' != $this->period) { |
|
431 | + $expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days')); |
|
432 | 432 | } |
433 | 433 | |
434 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
434 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this); |
|
435 | 435 | |
436 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
436 | + do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this); |
|
437 | 437 | |
438 | 438 | $this->status = 'active'; |
439 | 439 | $times_billed = $this->get_times_billed(); |
440 | 440 | |
441 | 441 | // Complete subscription if applicable |
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
442 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
443 | 443 | $this->complete(); |
444 | 444 | $this->status = 'completed'; |
445 | 445 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | 'status' => $this->status, |
450 | 450 | ); |
451 | 451 | |
452 | - $this->subs_db->update( $this->id, $args ); |
|
452 | + $this->subs_db->update($this->id, $args); |
|
453 | 453 | |
454 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
454 | + do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this); |
|
455 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function complete() { |
468 | 468 | |
469 | 469 | // Only mark a subscription as complete if it's not already cancelled. |
470 | - if ( 'cancelled' === $this->status ) { |
|
470 | + if ('cancelled' === $this->status) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | 'status' => 'completed' |
476 | 476 | ); |
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if ($this->subs_db->update($this->id, $args)) { |
|
479 | 479 | |
480 | 480 | $this->status = 'completed'; |
481 | 481 | |
482 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
482 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -494,15 +494,15 @@ discard block |
||
494 | 494 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
495 | 495 | * @return void |
496 | 496 | */ |
497 | - public function expire( $check_expiration = false ) { |
|
497 | + public function expire($check_expiration = false) { |
|
498 | 498 | |
499 | 499 | $expiration = $this->expiration; |
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if ($check_expiration) { |
|
502 | 502 | |
503 | 503 | // check_expiration() updates $this->expiration so compare to $expiration above |
504 | 504 | |
505 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
505 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
506 | 506 | |
507 | 507 | return false; // Do not mark as expired since real expiration date is in the future |
508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | 'status' => 'expired' |
514 | 514 | ); |
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if ($this->subs_db->update($this->id, $args)) { |
|
517 | 517 | |
518 | 518 | $this->status = 'expired'; |
519 | 519 | |
520 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
520 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
521 | 521 | |
522 | 522 | } |
523 | 523 | |
@@ -535,11 +535,11 @@ discard block |
||
535 | 535 | 'status' => 'failing' |
536 | 536 | ); |
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if ($this->subs_db->update($this->id, $args)) { |
|
539 | 539 | |
540 | 540 | $this->status = 'failing'; |
541 | 541 | |
542 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
542 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
543 | 543 | |
544 | 544 | |
545 | 545 | } |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return void |
554 | 554 | */ |
555 | 555 | public function cancel() { |
556 | - if ( 'cancelled' === $this->status ) { |
|
556 | + if ('cancelled' === $this->status) { |
|
557 | 557 | return; // Already cancelled |
558 | 558 | } |
559 | 559 | |
@@ -561,20 +561,20 @@ discard block |
||
561 | 561 | 'status' => 'cancelled' |
562 | 562 | ); |
563 | 563 | |
564 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
565 | - if ( is_user_logged_in() ) { |
|
566 | - $userdata = get_userdata( get_current_user_id() ); |
|
564 | + if ($this->subs_db->update($this->id, $args)) { |
|
565 | + if (is_user_logged_in()) { |
|
566 | + $userdata = get_userdata(get_current_user_id()); |
|
567 | 567 | $user = $userdata->display_name; |
568 | 568 | } else { |
569 | - $user = __( 'gateway', 'invoicing' ); |
|
569 | + $user = __('gateway', 'invoicing'); |
|
570 | 570 | } |
571 | 571 | |
572 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $user ); |
|
573 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
572 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $user); |
|
573 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
574 | 574 | |
575 | 575 | $this->status = 'cancelled'; |
576 | 576 | |
577 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
577 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | */ |
590 | 590 | public function can_cancel() { |
591 | 591 | $ret = false; |
592 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
592 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
593 | 593 | $ret = true; |
594 | 594 | } |
595 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
595 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | public function get_cancellable_statuses() { |
606 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
606 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -614,9 +614,9 @@ discard block |
||
614 | 614 | */ |
615 | 615 | public function get_cancel_url() { |
616 | 616 | |
617 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
617 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
618 | 618 | |
619 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
619 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public function can_renew() { |
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
633 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | */ |
642 | 642 | public function get_renew_url() { |
643 | 643 | |
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
644 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
645 | 645 | |
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
646 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * @return bool |
654 | 654 | */ |
655 | 655 | public function can_update() { |
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
656 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | */ |
665 | 665 | public function get_update_url() { |
666 | 666 | |
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
667 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
668 | 668 | |
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
669 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | |
680 | 680 | $ret = false; |
681 | 681 | |
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
682 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
683 | 683 | $ret = true; |
684 | 684 | } |
685 | 685 | |
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
686 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
687 | 687 | |
688 | 688 | } |
689 | 689 | |
@@ -697,26 +697,26 @@ discard block |
||
697 | 697 | |
698 | 698 | $ret = false; |
699 | 699 | |
700 | - if ( $this->status == 'expired' ) { |
|
700 | + if ($this->status == 'expired') { |
|
701 | 701 | |
702 | 702 | $ret = true; |
703 | 703 | |
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
704 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
705 | 705 | |
706 | 706 | $ret = false; |
707 | 707 | $expiration = $this->get_expiration_time(); |
708 | 708 | |
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
709 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
710 | 710 | $ret = true; |
711 | 711 | |
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
712 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
713 | 713 | $this->expire(); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
717 | 717 | } |
718 | 718 | |
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
719 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
720 | 720 | |
721 | 721 | } |
722 | 722 | |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | * @return int |
738 | 738 | */ |
739 | 739 | public function get_expiration_time() { |
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
740 | + return strtotime($this->expiration, current_time('timestamp')); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | */ |
762 | 762 | public function get_status_label() { |
763 | 763 | |
764 | - switch( $this->get_status() ) { |
|
764 | + switch ($this->get_status()) { |
|
765 | 765 | case 'active' : |
766 | - $status = __( 'Active', 'invoicing' ); |
|
766 | + $status = __('Active', 'invoicing'); |
|
767 | 767 | break; |
768 | 768 | |
769 | 769 | case 'cancelled' : |
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
770 | + $status = __('Cancelled', 'invoicing'); |
|
771 | 771 | break; |
772 | 772 | |
773 | 773 | case 'expired' : |
774 | - $status = __( 'Expired', 'invoicing' ); |
|
774 | + $status = __('Expired', 'invoicing'); |
|
775 | 775 | break; |
776 | 776 | |
777 | 777 | case 'pending' : |
778 | - $status = __( 'Pending', 'invoicing' ); |
|
778 | + $status = __('Pending', 'invoicing'); |
|
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'failing' : |
782 | - $status = __( 'Failing', 'invoicing' ); |
|
782 | + $status = __('Failing', 'invoicing'); |
|
783 | 783 | break; |
784 | 784 | |
785 | 785 | case 'trialling' : |
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
786 | + $status = __('Trialling', 'invoicing'); |
|
787 | 787 | break; |
788 | 788 | |
789 | 789 | case 'completed' : |
790 | - $status = __( 'Completed', 'invoicing' ); |
|
790 | + $status = __('Completed', 'invoicing'); |
|
791 | 791 | break; |
792 | 792 | |
793 | 793 | default: |
794 | - $status = ucfirst( $this->get_status() ); |
|
794 | + $status = ucfirst($this->get_status()); |
|
795 | 795 | break; |
796 | 796 | } |
797 | 797 | |
@@ -806,51 +806,51 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function get_status_label_html() { |
808 | 808 | |
809 | - switch( $get_status = $this->get_status() ) { |
|
809 | + switch ($get_status = $this->get_status()) { |
|
810 | 810 | case 'active' : |
811 | - $status = __( 'Active', 'invoicing' ); |
|
811 | + $status = __('Active', 'invoicing'); |
|
812 | 812 | $class = 'label-info'; |
813 | 813 | break; |
814 | 814 | |
815 | 815 | case 'cancelled' : |
816 | - $status = __( 'Cancelled', 'invoicing' ); |
|
816 | + $status = __('Cancelled', 'invoicing'); |
|
817 | 817 | $class = 'label-danger'; |
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'expired' : |
821 | - $status = __( 'Expired', 'invoicing' ); |
|
821 | + $status = __('Expired', 'invoicing'); |
|
822 | 822 | $class = 'label-default'; |
823 | 823 | break; |
824 | 824 | |
825 | 825 | case 'pending' : |
826 | - $status = __( 'Pending', 'invoicing' ); |
|
826 | + $status = __('Pending', 'invoicing'); |
|
827 | 827 | $class = 'label-primary'; |
828 | 828 | break; |
829 | 829 | |
830 | 830 | case 'failing' : |
831 | - $status = __( 'Failing', 'invoicing' ); |
|
831 | + $status = __('Failing', 'invoicing'); |
|
832 | 832 | $class = 'label-danger'; |
833 | 833 | break; |
834 | 834 | |
835 | 835 | case 'trialling' : |
836 | - $status = __( 'Trialling', 'invoicing' ); |
|
836 | + $status = __('Trialling', 'invoicing'); |
|
837 | 837 | $class = 'label-info'; |
838 | 838 | break; |
839 | 839 | |
840 | 840 | case 'completed' : |
841 | - $status = __( 'Completed', 'invoicing' ); |
|
841 | + $status = __('Completed', 'invoicing'); |
|
842 | 842 | $class = 'label-success'; |
843 | 843 | break; |
844 | 844 | |
845 | 845 | default: |
846 | - $status = ucfirst( $this->get_status() ); |
|
846 | + $status = ucfirst($this->get_status()); |
|
847 | 847 | $class = 'label-default'; |
848 | 848 | break; |
849 | 849 | } |
850 | 850 | |
851 | 851 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
852 | 852 | |
853 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
853 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -860,18 +860,18 @@ discard block |
||
860 | 860 | * @param string $txn_id The transaction ID from the merchant processor |
861 | 861 | * @return bool |
862 | 862 | */ |
863 | - public function payment_exists( $txn_id = '' ) { |
|
863 | + public function payment_exists($txn_id = '') { |
|
864 | 864 | global $wpdb; |
865 | 865 | |
866 | - if ( empty( $txn_id ) ) { |
|
866 | + if (empty($txn_id)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
870 | - $txn_id = esc_sql( $txn_id ); |
|
870 | + $txn_id = esc_sql($txn_id); |
|
871 | 871 | |
872 | - $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
872 | + $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
873 | 873 | |
874 | - if ( $purchase != null ) { |
|
874 | + if ($purchase != null) { |
|
875 | 875 | return true; |
876 | 876 | } |
877 | 877 |
@@ -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,132 +24,132 @@ 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 Credit Card / Debit 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 Credit Card / Debit 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' ); |
|
143 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
144 | 144 | |
145 | 145 | function wpinv_is_worldpay_valid_for_use() { |
146 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ))); |
|
146 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'))); |
|
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_check_worldpay_currency_support( $gateway_list ) { |
|
150 | - if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) { |
|
151 | - unset( $gateway_list['worldpay'] ); |
|
149 | +function wpinv_check_worldpay_currency_support($gateway_list) { |
|
150 | + if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) { |
|
151 | + unset($gateway_list['worldpay']); |
|
152 | 152 | } |
153 | 153 | return $gateway_list; |
154 | 154 | } |
155 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 ); |
|
156 | 155 | \ No newline at end of file |
156 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1); |
|
157 | 157 | \ 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]', |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | 'multiple' => false, |
367 | 367 | 'show_option_all' => false, |
368 | 368 | 'show_option_none' => false |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | ?> |
371 | 371 | </td> |
372 | 372 | </tr> |
373 | 373 | <?php } ?> |
374 | 374 | <tr> |
375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
376 | - <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> |
|
376 | + <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 | 377 | </td> |
378 | 378 | </tr> |
379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
385 | 385 | echo $content; |
386 | 386 | } |
387 | 387 | |
388 | -function wpinv_vat_number_callback( $args ) { |
|
388 | +function wpinv_vat_number_callback($args) { |
|
389 | 389 | global $wpinv_euvat; |
390 | 390 | |
391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
393 | 393 | |
394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
397 | 397 | |
398 | - $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 ) ) . '"/>'; |
|
399 | - $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>'; |
|
398 | + $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)) . '"/>'; |
|
399 | + $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>'; |
|
400 | 400 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
401 | - $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>'; |
|
402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
401 | + $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>'; |
|
402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
403 | 403 | |
404 | 404 | echo $html; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
408 | 408 | global $wpinv_options; |
409 | 409 | |
410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
412 | 412 | |
413 | - $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 ) ) . '" />'; |
|
414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $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>'; |
|
413 | + $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)) . '" />'; |
|
414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $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>'; |
|
417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
418 | 418 | echo $html; |
419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | <?php |
422 | 422 | } |
423 | 423 | |
424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
425 | 425 | global $wpinv_options, $wpinv_euvat; |
426 | 426 | |
427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
428 | 428 | |
429 | 429 | $options = array(); |
430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
430 | + if (function_exists('geoip_country_code_by_name')) { |
|
431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
435 | 435 | |
436 | - if ( !function_exists( 'bcadd' ) ) { |
|
437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
436 | + if (!function_exists('bcadd')) { |
|
437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
438 | 438 | } else { |
439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
440 | 440 | } |
441 | 441 | |
442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
446 | + if (function_exists('simplexml_load_file')) { |
|
447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
448 | 448 | } |
449 | 449 | |
450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
451 | + $options['default'] = __('Auto', 'invoicing'); |
|
452 | 452 | |
453 | - $html = wpinv_html_select( array( |
|
453 | + $html = wpinv_html_select(array( |
|
454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
455 | 455 | 'selected' => $value, |
456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -462,23 +462,23 @@ discard block |
||
462 | 462 | )); |
463 | 463 | |
464 | 464 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
465 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
465 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
466 | 466 | $desc .= '<p>'; |
467 | - if ( empty( $geoip2_message ) ) { |
|
468 | - if ( $geoip2_database ) { |
|
467 | + if (empty($geoip2_message)) { |
|
468 | + if ($geoip2_database) { |
|
469 | 469 | $last_updated = ''; |
470 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
471 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
472 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
470 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
471 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
472 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
473 | 473 | } |
474 | - $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>'; |
|
474 | + $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>'; |
|
475 | 475 | } else { |
476 | - $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' ); |
|
476 | + $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'); |
|
477 | 477 | } |
478 | 478 | } else { |
479 | 479 | $desc .= $geoip2_message; |
480 | 480 | } |
481 | - $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>'; |
|
481 | + $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>'; |
|
482 | 482 | $desc .= '</label>'; |
483 | 483 | |
484 | 484 | $html .= $desc; |
@@ -7,44 +7,44 @@ 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 | -add_action( 'init', 'wpinv_register_post_types', 1 ); |
|
14 | +add_action('init', 'wpinv_register_post_types', 1); |
|
15 | 15 | function wpinv_register_post_types() { |
16 | 16 | $labels = array( |
17 | - 'name' => _x( 'Invoices', 'post type general name', 'invoicing' ), |
|
18 | - 'singular_name' => _x( 'Invoice', 'post type singular name', 'invoicing' ), |
|
19 | - 'menu_name' => _x( 'Invoices', 'admin menu', 'invoicing' ), |
|
20 | - 'name_admin_bar' => _x( 'Invoice', 'add new on admin bar', 'invoicing' ), |
|
21 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
22 | - 'add_new_item' => __( 'Add New Invoice', 'invoicing' ), |
|
23 | - 'new_item' => __( 'New Invoice', 'invoicing' ), |
|
24 | - 'edit_item' => __( 'Edit Invoice', 'invoicing' ), |
|
25 | - 'view_item' => __( 'View Invoice', 'invoicing' ), |
|
26 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
27 | - 'search_items' => __( 'Search Invoices', 'invoicing' ), |
|
28 | - 'parent_item_colon' => __( 'Parent Invoices:', 'invoicing' ), |
|
29 | - 'not_found' => __( 'No invoices found.', 'invoicing' ), |
|
30 | - 'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' ) |
|
17 | + 'name' => _x('Invoices', 'post type general name', 'invoicing'), |
|
18 | + 'singular_name' => _x('Invoice', 'post type singular name', 'invoicing'), |
|
19 | + 'menu_name' => _x('Invoices', 'admin menu', 'invoicing'), |
|
20 | + 'name_admin_bar' => _x('Invoice', 'add new on admin bar', 'invoicing'), |
|
21 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
22 | + 'add_new_item' => __('Add New Invoice', 'invoicing'), |
|
23 | + 'new_item' => __('New Invoice', 'invoicing'), |
|
24 | + 'edit_item' => __('Edit Invoice', 'invoicing'), |
|
25 | + 'view_item' => __('View Invoice', 'invoicing'), |
|
26 | + 'all_items' => __('Invoices', 'invoicing'), |
|
27 | + 'search_items' => __('Search Invoices', 'invoicing'), |
|
28 | + 'parent_item_colon' => __('Parent Invoices:', 'invoicing'), |
|
29 | + 'not_found' => __('No invoices found.', 'invoicing'), |
|
30 | + 'not_found_in_trash' => __('No invoices found in trash.', 'invoicing') |
|
31 | 31 | ); |
32 | - $labels = apply_filters( 'wpinv_labels', $labels ); |
|
32 | + $labels = apply_filters('wpinv_labels', $labels); |
|
33 | 33 | |
34 | 34 | $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico'; |
35 | - $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon ); |
|
35 | + $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon); |
|
36 | 36 | |
37 | 37 | $cap_type = 'wpi_invoice'; |
38 | 38 | $args = array( |
39 | 39 | 'labels' => $labels, |
40 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
40 | + 'description' => __('This is where invoices are stored.', 'invoicing'), |
|
41 | 41 | 'public' => true, |
42 | 42 | 'can_export' => true, |
43 | 43 | '_builtin' => false, |
44 | 44 | 'publicly_queryable' => true, |
45 | 45 | 'exclude_from_search'=> true, |
46 | 46 | 'show_ui' => true, |
47 | - 'show_in_menu' => current_user_can( 'manage_invoicing' ) ? 'wpinv' : true, |
|
47 | + 'show_in_menu' => current_user_can('manage_invoicing') ? 'wpinv' : true, |
|
48 | 48 | 'show_in_nav_menus' => false, |
49 | 49 | 'query_var' => false, |
50 | 50 | 'rewrite' => true, |
@@ -69,39 +69,39 @@ discard block |
||
69 | 69 | 'has_archive' => false, |
70 | 70 | 'hierarchical' => false, |
71 | 71 | 'menu_position' => null, |
72 | - 'supports' => array( 'title', 'author' ), |
|
72 | + 'supports' => array('title', 'author'), |
|
73 | 73 | 'menu_icon' => 'dashicons-media-spreadsheet', |
74 | 74 | ); |
75 | 75 | |
76 | - $args = apply_filters( 'wpinv_register_post_type_invoice', $args ); |
|
76 | + $args = apply_filters('wpinv_register_post_type_invoice', $args); |
|
77 | 77 | |
78 | - register_post_type( 'wpi_invoice', $args ); |
|
78 | + register_post_type('wpi_invoice', $args); |
|
79 | 79 | |
80 | 80 | $items_labels = array( |
81 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
82 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
83 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
84 | - 'add_new' => _x( 'Add New', 'wpi_item', 'invoicing' ), |
|
85 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
86 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
87 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
88 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
89 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
90 | - 'search_items' => __( 'Search Items', 'invoicing' ), |
|
81 | + 'name' => _x('Items', 'post type general name', 'invoicing'), |
|
82 | + 'singular_name' => _x('Item', 'post type singular name', 'invoicing'), |
|
83 | + 'menu_name' => _x('Items', 'admin menu', 'invoicing'), |
|
84 | + 'add_new' => _x('Add New', 'wpi_item', 'invoicing'), |
|
85 | + 'add_new_item' => __('Add New Item', 'invoicing'), |
|
86 | + 'new_item' => __('New Item', 'invoicing'), |
|
87 | + 'edit_item' => __('Edit Item', 'invoicing'), |
|
88 | + 'view_item' => __('View Item', 'invoicing'), |
|
89 | + 'all_items' => __('Items', 'invoicing'), |
|
90 | + 'search_items' => __('Search Items', 'invoicing'), |
|
91 | 91 | 'parent_item_colon' => '', |
92 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
93 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
92 | + 'not_found' => __('No items found.', 'invoicing'), |
|
93 | + 'not_found_in_trash' => __('No items found in trash.', 'invoicing') |
|
94 | 94 | ); |
95 | - $items_labels = apply_filters( 'wpinv_items_labels', $items_labels ); |
|
95 | + $items_labels = apply_filters('wpinv_items_labels', $items_labels); |
|
96 | 96 | |
97 | 97 | $cap_type = 'wpi_item'; |
98 | 98 | $invoice_item_args = array( |
99 | 99 | 'labels' => $items_labels, |
100 | 100 | 'public' => false, |
101 | 101 | 'show_ui' => true, |
102 | - 'show_in_menu' => current_user_can( 'manage_invoicing' ) ? 'wpinv' : false, |
|
102 | + 'show_in_menu' => current_user_can('manage_invoicing') ? 'wpinv' : false, |
|
103 | 103 | 'show_in_nav_menus' => false, |
104 | - 'supports' => array( 'title', 'excerpt' ), |
|
104 | + 'supports' => array('title', 'excerpt'), |
|
105 | 105 | 'register_meta_box_cb' => 'wpinv_register_item_meta_boxes', |
106 | 106 | 'rewrite' => false, |
107 | 107 | 'query_var' => false, |
@@ -125,40 +125,40 @@ discard block |
||
125 | 125 | ), |
126 | 126 | 'can_export' => true, |
127 | 127 | ); |
128 | - $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args ); |
|
128 | + $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args); |
|
129 | 129 | |
130 | - register_post_type( 'wpi_item', $invoice_item_args ); |
|
130 | + register_post_type('wpi_item', $invoice_item_args); |
|
131 | 131 | |
132 | 132 | $labels = array( |
133 | - 'name' => _x( 'Discounts', 'post type general name', 'invoicing' ), |
|
134 | - 'singular_name' => _x( 'Discount', 'post type singular name', 'invoicing' ), |
|
135 | - 'menu_name' => _x( 'Discounts', 'admin menu', 'invoicing' ), |
|
136 | - 'name_admin_bar' => _x( 'Discount', 'add new on admin bar', 'invoicing' ), |
|
137 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
138 | - 'add_new_item' => __( 'Add New Discount', 'invoicing' ), |
|
139 | - 'new_item' => __( 'New Discount', 'invoicing' ), |
|
140 | - 'edit_item' => __( 'Edit Discount', 'invoicing' ), |
|
141 | - 'view_item' => __( 'View Discount', 'invoicing' ), |
|
142 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
143 | - 'search_items' => __( 'Search Discounts', 'invoicing' ), |
|
144 | - 'parent_item_colon' => __( 'Parent Discounts:', 'invoicing' ), |
|
145 | - 'not_found' => __( 'No discounts found.', 'invoicing' ), |
|
146 | - 'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' ) |
|
133 | + 'name' => _x('Discounts', 'post type general name', 'invoicing'), |
|
134 | + 'singular_name' => _x('Discount', 'post type singular name', 'invoicing'), |
|
135 | + 'menu_name' => _x('Discounts', 'admin menu', 'invoicing'), |
|
136 | + 'name_admin_bar' => _x('Discount', 'add new on admin bar', 'invoicing'), |
|
137 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
138 | + 'add_new_item' => __('Add New Discount', 'invoicing'), |
|
139 | + 'new_item' => __('New Discount', 'invoicing'), |
|
140 | + 'edit_item' => __('Edit Discount', 'invoicing'), |
|
141 | + 'view_item' => __('View Discount', 'invoicing'), |
|
142 | + 'all_items' => __('Discounts', 'invoicing'), |
|
143 | + 'search_items' => __('Search Discounts', 'invoicing'), |
|
144 | + 'parent_item_colon' => __('Parent Discounts:', 'invoicing'), |
|
145 | + 'not_found' => __('No discounts found.', 'invoicing'), |
|
146 | + 'not_found_in_trash' => __('No discounts found in trash.', 'invoicing') |
|
147 | 147 | ); |
148 | - $labels = apply_filters( 'wpinv_discounts_labels', $labels ); |
|
148 | + $labels = apply_filters('wpinv_discounts_labels', $labels); |
|
149 | 149 | |
150 | 150 | $cap_type = 'wpi_discount'; |
151 | 151 | |
152 | 152 | $args = array( |
153 | 153 | 'labels' => $labels, |
154 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
154 | + 'description' => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'), |
|
155 | 155 | 'public' => false, |
156 | 156 | 'can_export' => true, |
157 | 157 | '_builtin' => false, |
158 | 158 | 'publicly_queryable' => false, |
159 | 159 | 'exclude_from_search'=> true, |
160 | 160 | 'show_ui' => true, |
161 | - 'show_in_menu' => current_user_can( 'manage_invoicing' ) ? 'wpinv' : false, |
|
161 | + 'show_in_menu' => current_user_can('manage_invoicing') ? 'wpinv' : false, |
|
162 | 162 | 'query_var' => false, |
163 | 163 | 'rewrite' => false, |
164 | 164 | 'capability_type' => $cap_type, |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ), |
182 | 182 | 'has_archive' => false, |
183 | 183 | 'hierarchical' => false, |
184 | - 'supports' => array( 'title', 'excerpt' ), |
|
184 | + 'supports' => array('title', 'excerpt'), |
|
185 | 185 | 'register_meta_box_cb' => 'wpinv_register_discount_meta_boxes', |
186 | 186 | 'show_in_nav_menus' => false, |
187 | 187 | 'show_in_admin_bar' => true, |
@@ -189,107 +189,107 @@ discard block |
||
189 | 189 | 'menu_position' => null, |
190 | 190 | ); |
191 | 191 | |
192 | - $args = apply_filters( 'wpinv_register_post_type_discount', $args ); |
|
192 | + $args = apply_filters('wpinv_register_post_type_discount', $args); |
|
193 | 193 | |
194 | - register_post_type( 'wpi_discount', $args ); |
|
194 | + register_post_type('wpi_discount', $args); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | function wpinv_get_default_labels() { |
198 | 198 | $defaults = array( |
199 | - 'singular' => __( 'Invoice', 'invoicing' ), |
|
200 | - 'plural' => __( 'Invoices', 'invoicing' ) |
|
199 | + 'singular' => __('Invoice', 'invoicing'), |
|
200 | + 'plural' => __('Invoices', 'invoicing') |
|
201 | 201 | ); |
202 | 202 | |
203 | - return apply_filters( 'wpinv_default_invoices_name', $defaults ); |
|
203 | + return apply_filters('wpinv_default_invoices_name', $defaults); |
|
204 | 204 | } |
205 | 205 | |
206 | -function wpinv_get_label_singular( $lowercase = false ) { |
|
206 | +function wpinv_get_label_singular($lowercase = false) { |
|
207 | 207 | $defaults = wpinv_get_default_labels(); |
208 | 208 | |
209 | - return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
209 | + return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular']; |
|
210 | 210 | } |
211 | 211 | |
212 | -function wpinv_get_label_plural( $lowercase = false ) { |
|
212 | +function wpinv_get_label_plural($lowercase = false) { |
|
213 | 213 | $defaults = wpinv_get_default_labels(); |
214 | 214 | |
215 | - return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
215 | + return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural']; |
|
216 | 216 | } |
217 | 217 | |
218 | -function wpinv_change_default_title( $title ) { |
|
219 | - if ( !is_admin() ) { |
|
218 | +function wpinv_change_default_title($title) { |
|
219 | + if (!is_admin()) { |
|
220 | 220 | $label = wpinv_get_label_singular(); |
221 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
221 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
222 | 222 | return $title; |
223 | 223 | } |
224 | 224 | |
225 | 225 | $screen = get_current_screen(); |
226 | 226 | |
227 | - if ( 'wpi_invoice' == $screen->post_type ) { |
|
227 | + if ('wpi_invoice' == $screen->post_type) { |
|
228 | 228 | $label = wpinv_get_label_singular(); |
229 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
229 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | return $title; |
233 | 233 | } |
234 | -add_filter( 'enter_title_here', 'wpinv_change_default_title' ); |
|
234 | +add_filter('enter_title_here', 'wpinv_change_default_title'); |
|
235 | 235 | |
236 | 236 | function wpinv_register_post_status() { |
237 | - register_post_status( 'wpi-pending', array( |
|
238 | - 'label' => _x( 'Pending', 'Invoice status', 'invoicing' ), |
|
237 | + register_post_status('wpi-pending', array( |
|
238 | + 'label' => _x('Pending', 'Invoice status', 'invoicing'), |
|
239 | 239 | 'public' => true, |
240 | 240 | 'exclude_from_search' => true, |
241 | 241 | 'show_in_admin_all_list' => true, |
242 | 242 | 'show_in_admin_status_list' => true, |
243 | - 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing' ) |
|
244 | - ) ); |
|
245 | - register_post_status( 'wpi-processing', array( |
|
246 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
243 | + 'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing') |
|
244 | + )); |
|
245 | + register_post_status('wpi-processing', array( |
|
246 | + 'label' => _x('Processing', 'Invoice status', 'invoicing'), |
|
247 | 247 | 'public' => true, |
248 | 248 | 'exclude_from_search' => true, |
249 | 249 | 'show_in_admin_all_list' => true, |
250 | 250 | 'show_in_admin_status_list' => true, |
251 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
252 | - ) ); |
|
253 | - register_post_status( 'wpi-onhold', array( |
|
254 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
251 | + 'label_count' => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing') |
|
252 | + )); |
|
253 | + register_post_status('wpi-onhold', array( |
|
254 | + 'label' => _x('On Hold', 'Invoice status', 'invoicing'), |
|
255 | 255 | 'public' => true, |
256 | 256 | 'exclude_from_search' => true, |
257 | 257 | 'show_in_admin_all_list' => true, |
258 | 258 | 'show_in_admin_status_list' => true, |
259 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
260 | - ) ); |
|
261 | - register_post_status( 'wpi-cancelled', array( |
|
262 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
259 | + 'label_count' => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing') |
|
260 | + )); |
|
261 | + register_post_status('wpi-cancelled', array( |
|
262 | + 'label' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
263 | 263 | 'public' => true, |
264 | 264 | 'exclude_from_search' => true, |
265 | 265 | 'show_in_admin_all_list' => true, |
266 | 266 | 'show_in_admin_status_list' => true, |
267 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
268 | - ) ); |
|
269 | - register_post_status( 'wpi-refunded', array( |
|
270 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
267 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing') |
|
268 | + )); |
|
269 | + register_post_status('wpi-refunded', array( |
|
270 | + 'label' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
271 | 271 | 'public' => true, |
272 | 272 | 'exclude_from_search' => true, |
273 | 273 | 'show_in_admin_all_list' => true, |
274 | 274 | 'show_in_admin_status_list' => true, |
275 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
276 | - ) ); |
|
277 | - register_post_status( 'wpi-failed', array( |
|
278 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
275 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing') |
|
276 | + )); |
|
277 | + register_post_status('wpi-failed', array( |
|
278 | + 'label' => _x('Failed', 'Invoice status', 'invoicing'), |
|
279 | 279 | 'public' => true, |
280 | 280 | 'exclude_from_search' => true, |
281 | 281 | 'show_in_admin_all_list' => true, |
282 | 282 | 'show_in_admin_status_list' => true, |
283 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
284 | - ) ); |
|
285 | - register_post_status( 'wpi-renewal', array( |
|
286 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
283 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing') |
|
284 | + )); |
|
285 | + register_post_status('wpi-renewal', array( |
|
286 | + 'label' => _x('Renewal', 'Invoice status', 'invoicing'), |
|
287 | 287 | 'public' => true, |
288 | 288 | 'exclude_from_search' => true, |
289 | 289 | 'show_in_admin_all_list' => true, |
290 | 290 | 'show_in_admin_status_list' => true, |
291 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
292 | - ) ); |
|
291 | + 'label_count' => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing') |
|
292 | + )); |
|
293 | 293 | } |
294 | -add_action( 'init', 'wpinv_register_post_status', 10 ); |
|
294 | +add_action('init', 'wpinv_register_post_status', 10); |
|
295 | 295 |
@@ -1,13 +1,13 @@ 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_paypal_cc_form', '__return_false' ); |
|
6 | -add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
|
5 | +add_action('wpinv_paypal_cc_form', '__return_false'); |
|
6 | +add_filter('wpinv_paypal_support_subscription', '__return_true'); |
|
7 | 7 | |
8 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
8 | +function wpinv_process_paypal_payment($purchase_data) { |
|
9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | // Collect payment data |
@@ -25,30 +25,30 @@ discard block |
||
25 | 25 | ); |
26 | 26 | |
27 | 27 | // Record the pending payment |
28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
29 | 29 | |
30 | 30 | // Check payment |
31 | - if ( ! $invoice ) { |
|
31 | + if (!$invoice) { |
|
32 | 32 | // Record the error |
33 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
33 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
34 | 34 | // Problems? send back |
35 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
35 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
36 | 36 | } else { |
37 | 37 | // Only send to PayPal if the pending payment is created successfully |
38 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
38 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
39 | 39 | |
40 | 40 | // Get the success url |
41 | - $return_url = add_query_arg( array( |
|
41 | + $return_url = add_query_arg(array( |
|
42 | 42 | 'payment-confirm' => 'paypal', |
43 | 43 | 'invoice-id' => $invoice->ID |
44 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
44 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
45 | 45 | |
46 | 46 | // Get the PayPal redirect uri |
47 | - $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?'; |
|
47 | + $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?'; |
|
48 | 48 | |
49 | 49 | // Setup PayPal arguments |
50 | 50 | $paypal_args = array( |
51 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
51 | + 'business' => wpinv_get_option('paypal_email', false), |
|
52 | 52 | 'email' => $invoice->get_email(), |
53 | 53 | 'first_name' => $invoice->get_first_name(), |
54 | 54 | 'last_name' => $invoice->get_last_name(), |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | 'shipping' => '0', |
58 | 58 | 'no_note' => '1', |
59 | 59 | 'currency_code' => wpinv_get_currency(), |
60 | - 'charset' => get_bloginfo( 'charset' ), |
|
60 | + 'charset' => get_bloginfo('charset'), |
|
61 | 61 | 'custom' => $invoice->ID, |
62 | 62 | 'rm' => '2', |
63 | 63 | 'return' => $return_url, |
64 | - 'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ), |
|
64 | + 'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID), |
|
65 | 65 | 'notify_url' => $listener_url, |
66 | - 'cbt' => get_bloginfo( 'name' ), |
|
66 | + 'cbt' => get_bloginfo('name'), |
|
67 | 67 | 'bn' => 'WPInvoicing_SP', |
68 | 68 | 'lc' => 'US', // this will force paypal site to english |
69 | - 'landing_page' => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
69 | + 'landing_page' => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | $paypal_args['address1'] = $invoice->get_address(); |
@@ -80,57 +80,57 @@ discard block |
||
80 | 80 | 'upload' => '1' |
81 | 81 | ); |
82 | 82 | |
83 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
83 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
84 | 84 | |
85 | 85 | // Add cart items |
86 | 86 | $i = 1; |
87 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
88 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
87 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
88 | + foreach ($purchase_data['cart_details'] as $item) { |
|
89 | 89 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
90 | - $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 ); |
|
90 | + $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2); |
|
91 | 91 | |
92 | - if ( $item_amount <= 0 ) { |
|
92 | + if ($item_amount <= 0) { |
|
93 | 93 | $item_amount = 0; |
94 | 94 | } |
95 | 95 | |
96 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
97 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
98 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
99 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
100 | - $paypal_args['discount_amount_' . $i ] = wpinv_sanitize_amount( $item['discount'], 2 ); |
|
96 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
97 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
98 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
99 | + $paypal_args['amount_' . $i] = $item_amount; |
|
100 | + $paypal_args['discount_amount_' . $i] = wpinv_sanitize_amount($item['discount'], 2); |
|
101 | 101 | |
102 | 102 | $i++; |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Add taxes to the cart |
107 | - if ( wpinv_use_taxes() ) { |
|
108 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 ); |
|
107 | + if (wpinv_use_taxes()) { |
|
108 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2); |
|
109 | 109 | } |
110 | 110 | |
111 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
111 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
112 | 112 | |
113 | 113 | // Build query |
114 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
114 | + $paypal_redirect .= http_build_query($paypal_args); |
|
115 | 115 | |
116 | 116 | // Fix for some sites that encode the entities |
117 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
117 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
118 | 118 | |
119 | 119 | // Get rid of cart contents |
120 | 120 | wpinv_empty_cart(); |
121 | 121 | |
122 | 122 | // Redirect to PayPal |
123 | - wp_redirect( $paypal_redirect ); |
|
123 | + wp_redirect($paypal_redirect); |
|
124 | 124 | exit; |
125 | 125 | } |
126 | 126 | } |
127 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
127 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
128 | 128 | |
129 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
130 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
131 | - $item = new WPInv_Item( $item_id ); |
|
129 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
130 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
131 | + $item = new WPInv_Item($item_id); |
|
132 | 132 | |
133 | - if ( empty( $item ) ) { |
|
133 | + if (empty($item)) { |
|
134 | 134 | return $paypal_args; |
135 | 135 | } |
136 | 136 | |
@@ -138,25 +138,25 @@ discard block |
||
138 | 138 | $interval = $item->get_recurring_interval(); |
139 | 139 | $bill_times = (int)$item->get_recurring_limit(); |
140 | 140 | |
141 | - $initial_amount = wpinv_sanitize_amount( $invoice->get_total(), 2 ); |
|
142 | - $recurring_amount = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 ); |
|
141 | + $initial_amount = wpinv_sanitize_amount($invoice->get_total(), 2); |
|
142 | + $recurring_amount = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2); |
|
143 | 143 | |
144 | 144 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
145 | 145 | $paypal_args['sra'] = '1'; |
146 | 146 | $paypal_args['src'] = '1'; |
147 | 147 | |
148 | 148 | // Set item description |
149 | - $item_name = sprintf( '[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name( array( 'id' => $item->ID ) ) ); |
|
150 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) ); |
|
149 | + $item_name = sprintf('[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name(array('id' => $item->ID))); |
|
150 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8')); |
|
151 | 151 | |
152 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
152 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
153 | 153 | $paypal_args['a1'] = $initial_amount; |
154 | 154 | $paypal_args['p1'] = $item->get_trial_interval(); |
155 | 155 | $paypal_args['t1'] = $item->get_trial_period(); |
156 | 156 | |
157 | 157 | // Set the recurring amount |
158 | 158 | $paypal_args['a3'] = $recurring_amount; |
159 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
159 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
160 | 160 | $paypal_args['a1'] = $initial_amount; |
161 | 161 | $paypal_args['p1'] = $interval; |
162 | 162 | $paypal_args['t1'] = $period; |
@@ -164,63 +164,63 @@ discard block |
||
164 | 164 | // Set the recurring amount |
165 | 165 | $paypal_args['a3'] = $recurring_amount; |
166 | 166 | |
167 | - if ( $bill_times > 1 ) { |
|
167 | + if ($bill_times > 1) { |
|
168 | 168 | $bill_times--; |
169 | 169 | } |
170 | 170 | } else { |
171 | - $paypal_args['a3'] = $initial_amount; |
|
171 | + $paypal_args['a3'] = $initial_amount; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | $paypal_args['p3'] = $interval; |
175 | 175 | $paypal_args['t3'] = $period; |
176 | 176 | |
177 | - if ( $bill_times > 1 ) { |
|
177 | + if ($bill_times > 1) { |
|
178 | 178 | // Make sure it's not over the max of 52 |
179 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
179 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Remove cart items |
183 | 183 | $i = 1; |
184 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
185 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
186 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
187 | - unset( $paypal_args['item_number_' . $i] ); |
|
184 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
185 | + foreach ($purchase_data['cart_details'] as $item) { |
|
186 | + if (isset($paypal_args['item_number_' . $i])) { |
|
187 | + unset($paypal_args['item_number_' . $i]); |
|
188 | 188 | } |
189 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
190 | - unset( $paypal_args['item_name_' . $i] ); |
|
189 | + if (isset($paypal_args['item_name_' . $i])) { |
|
190 | + unset($paypal_args['item_name_' . $i]); |
|
191 | 191 | } |
192 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
193 | - unset( $paypal_args['quantity_' . $i] ); |
|
192 | + if (isset($paypal_args['quantity_' . $i])) { |
|
193 | + unset($paypal_args['quantity_' . $i]); |
|
194 | 194 | } |
195 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
196 | - unset( $paypal_args['amount_' . $i] ); |
|
195 | + if (isset($paypal_args['amount_' . $i])) { |
|
196 | + unset($paypal_args['amount_' . $i]); |
|
197 | 197 | } |
198 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
199 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
198 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
199 | + unset($paypal_args['discount_amount_' . $i]); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | $i++; |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
207 | - unset( $paypal_args['tax_cart'] ); |
|
206 | + if (isset($paypal_args['tax_cart'])) { |
|
207 | + unset($paypal_args['tax_cart']); |
|
208 | 208 | } |
209 | 209 | |
210 | - if ( isset( $paypal_args['upload'] ) ) { |
|
211 | - unset( $paypal_args['upload'] ); |
|
210 | + if (isset($paypal_args['upload'])) { |
|
211 | + unset($paypal_args['upload']); |
|
212 | 212 | } |
213 | 213 | |
214 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
214 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | return $paypal_args; |
218 | 218 | } |
219 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
219 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
220 | 220 | |
221 | 221 | function wpinv_process_paypal_ipn() { |
222 | 222 | // Check the request method is POST |
223 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
223 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
224 | 224 | return; |
225 | 225 | } |
226 | 226 | |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | $post_data = ''; |
229 | 229 | |
230 | 230 | // Fallback just in case post_max_size is lower than needed |
231 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
232 | - $post_data = file_get_contents( 'php://input' ); |
|
231 | + if (ini_get('allow_url_fopen')) { |
|
232 | + $post_data = file_get_contents('php://input'); |
|
233 | 233 | } else { |
234 | 234 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
235 | - ini_set( 'post_max_size', '12M' ); |
|
235 | + ini_set('post_max_size', '12M'); |
|
236 | 236 | } |
237 | 237 | // Start the encoded data collection with notification command |
238 | 238 | $encoded_data = 'cmd=_notify-validate'; |
@@ -241,43 +241,43 @@ discard block |
||
241 | 241 | $arg_separator = wpinv_get_php_arg_separator_output(); |
242 | 242 | |
243 | 243 | // Verify there is a post_data |
244 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
244 | + if ($post_data || strlen($post_data) > 0) { |
|
245 | 245 | // Append the data |
246 | - $encoded_data .= $arg_separator.$post_data; |
|
246 | + $encoded_data .= $arg_separator . $post_data; |
|
247 | 247 | } else { |
248 | 248 | // Check if POST is empty |
249 | - if ( empty( $_POST ) ) { |
|
249 | + if (empty($_POST)) { |
|
250 | 250 | // Nothing to do |
251 | 251 | return; |
252 | 252 | } else { |
253 | 253 | // Loop through each POST |
254 | - foreach ( $_POST as $key => $value ) { |
|
254 | + foreach ($_POST as $key => $value) { |
|
255 | 255 | // Encode the value and append the data |
256 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
256 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | 261 | // Convert collected post data to an array |
262 | - parse_str( $encoded_data, $encoded_data_array ); |
|
262 | + parse_str($encoded_data, $encoded_data_array); |
|
263 | 263 | |
264 | - foreach ( $encoded_data_array as $key => $value ) { |
|
265 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
266 | - $new_key = str_replace( '&', '&', $key ); |
|
267 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
264 | + foreach ($encoded_data_array as $key => $value) { |
|
265 | + if (false !== strpos($key, 'amp;')) { |
|
266 | + $new_key = str_replace('&', '&', $key); |
|
267 | + $new_key = str_replace('amp;', '&', $new_key); |
|
268 | 268 | |
269 | - unset( $encoded_data_array[ $key ] ); |
|
270 | - $encoded_data_array[ $new_key ] = $value; |
|
269 | + unset($encoded_data_array[$key]); |
|
270 | + $encoded_data_array[$new_key] = $value; |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Get the PayPal redirect uri |
275 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
275 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
276 | 276 | |
277 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
277 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
278 | 278 | // Validate the IPN |
279 | 279 | |
280 | - $remote_post_vars = array( |
|
280 | + $remote_post_vars = array( |
|
281 | 281 | 'method' => 'POST', |
282 | 282 | 'timeout' => 45, |
283 | 283 | 'redirection' => 5, |
@@ -295,21 +295,21 @@ discard block |
||
295 | 295 | ); |
296 | 296 | |
297 | 297 | // Get response |
298 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
298 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
299 | 299 | |
300 | - if ( is_wp_error( $api_response ) ) { |
|
301 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
300 | + if (is_wp_error($api_response)) { |
|
301 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
302 | 302 | return; // Something went wrong |
303 | 303 | } |
304 | 304 | |
305 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
306 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
305 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
306 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
307 | 307 | return; // Response not okay |
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Check if $post_data_array has been populated |
312 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
312 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
313 | 313 | return; |
314 | 314 | |
315 | 315 | $defaults = array( |
@@ -317,265 +317,265 @@ discard block |
||
317 | 317 | 'payment_status' => '' |
318 | 318 | ); |
319 | 319 | |
320 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
320 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
321 | 321 | |
322 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
322 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
323 | 323 | |
324 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
325 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
324 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
325 | + wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__); |
|
326 | 326 | |
327 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
327 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
328 | 328 | // Allow PayPal IPN types to be processed separately |
329 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
329 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
330 | 330 | } else { |
331 | 331 | // Fallback to web accept just in case the txn_type isn't present |
332 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
332 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
333 | 333 | } |
334 | 334 | exit; |
335 | 335 | } |
336 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
336 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
337 | 337 | |
338 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
339 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
338 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
339 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
340 | 340 | return; |
341 | 341 | } |
342 | 342 | |
343 | - if( empty( $invoice_id ) ) { |
|
343 | + if (empty($invoice_id)) { |
|
344 | 344 | return; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // Collect payment details |
348 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
348 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
349 | 349 | $paypal_amount = $data['mc_gross']; |
350 | - $payment_status = strtolower( $data['payment_status'] ); |
|
351 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
352 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
353 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
350 | + $payment_status = strtolower($data['payment_status']); |
|
351 | + $currency_code = strtolower($data['mc_currency']); |
|
352 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
353 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
354 | 354 | |
355 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
355 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
356 | 356 | return; // this isn't a PayPal standard IPN |
357 | 357 | } |
358 | 358 | |
359 | 359 | // Verify payment recipient |
360 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
361 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
362 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
363 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
360 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
361 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
362 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
363 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true); |
|
364 | 364 | return; |
365 | 365 | } |
366 | 366 | |
367 | 367 | // Verify payment currency |
368 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
369 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
370 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
371 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
368 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
369 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
370 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
371 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true); |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | |
375 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
375 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
376 | 376 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
377 | 377 | // No email associated with purchase, so store from PayPal |
378 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
378 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
379 | 379 | |
380 | 380 | // Setup and store the customer's details |
381 | 381 | $user_info = array( |
382 | 382 | 'user_id' => '-1', |
383 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
384 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
385 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
383 | + 'email' => sanitize_text_field($data['payer_email']), |
|
384 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
385 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
386 | 386 | 'discount' => '', |
387 | 387 | ); |
388 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
389 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
390 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
391 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
392 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
388 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
389 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
390 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
391 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
392 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
393 | 393 | |
394 | 394 | $payment_meta['user_info'] = $user_info; |
395 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
395 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
396 | 396 | } |
397 | 397 | |
398 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
398 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
399 | 399 | // Process a refund |
400 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
400 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
401 | 401 | } else { |
402 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
402 | + if (get_post_status($invoice_id) == 'publish') { |
|
403 | 403 | return; // Only paid payments once |
404 | 404 | } |
405 | 405 | |
406 | 406 | // Retrieve the total purchase amount (before PayPal) |
407 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
407 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
408 | 408 | |
409 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
409 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
410 | 410 | // The prices don't match |
411 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
412 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
413 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
411 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
412 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
413 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true); |
|
414 | 414 | return; |
415 | 415 | } |
416 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
416 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
417 | 417 | // Purchase keys don't match |
418 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
419 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
420 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
418 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
419 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
420 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true); |
|
421 | 421 | return; |
422 | 422 | } |
423 | 423 | |
424 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
425 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
426 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
427 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
428 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
424 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
425 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
426 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
427 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
428 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
429 | 429 | // Look for possible pending reasons, such as an echeck |
430 | 430 | $note = ''; |
431 | 431 | |
432 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
432 | + switch (strtolower($data['pending_reason'])) { |
|
433 | 433 | case 'echeck' : |
434 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
434 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
435 | 435 | break; |
436 | 436 | |
437 | 437 | case 'address' : |
438 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
438 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
439 | 439 | break; |
440 | 440 | |
441 | 441 | case 'intl' : |
442 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
442 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
443 | 443 | break; |
444 | 444 | |
445 | 445 | case 'multi-currency' : |
446 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
446 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
447 | 447 | break; |
448 | 448 | |
449 | 449 | case 'paymentreview' : |
450 | 450 | case 'regulatory_review' : |
451 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
451 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
452 | 452 | break; |
453 | 453 | |
454 | 454 | case 'unilateral' : |
455 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
455 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
456 | 456 | break; |
457 | 457 | |
458 | 458 | case 'upgrade' : |
459 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
459 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
460 | 460 | break; |
461 | 461 | |
462 | 462 | case 'verify' : |
463 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
463 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
464 | 464 | break; |
465 | 465 | |
466 | 466 | case 'other' : |
467 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
467 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
468 | 468 | break; |
469 | 469 | } |
470 | 470 | |
471 | - if ( ! empty( $note ) ) { |
|
472 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
471 | + if (!empty($note)) { |
|
472 | + wpinv_insert_payment_note($invoice_id, $note, '', '', true); |
|
473 | 473 | } |
474 | 474 | } else { |
475 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
475 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true); |
|
476 | 476 | } |
477 | 477 | } |
478 | 478 | } |
479 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
479 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
480 | 480 | |
481 | 481 | // Process PayPal subscription sign ups |
482 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
482 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
483 | 483 | |
484 | 484 | // Process PayPal subscription payments |
485 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
485 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
486 | 486 | |
487 | 487 | // Process PayPal subscription cancellations |
488 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
488 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
489 | 489 | |
490 | 490 | // Process PayPal subscription end of term notices |
491 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
491 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
492 | 492 | |
493 | 493 | // Process PayPal payment failed |
494 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
494 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
495 | 495 | |
496 | 496 | |
497 | 497 | /** |
498 | 498 | * Process the subscription started IPN. |
499 | 499 | */ |
500 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
501 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
502 | - if( empty( $parent_invoice_id ) ) { |
|
500 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
501 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
502 | + if (empty($parent_invoice_id)) { |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
507 | - if ( empty( $invoice ) ) { |
|
506 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
507 | + if (empty($invoice)) { |
|
508 | 508 | return; |
509 | 509 | } |
510 | 510 | |
511 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
512 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true); |
|
513 | - if ( !empty( $ipn_data['txn_id'] ) ) { |
|
514 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
511 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
512 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true); |
|
513 | + if (!empty($ipn_data['txn_id'])) { |
|
514 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
518 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
519 | - if ( false === $subscription ) { |
|
518 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
519 | + if (false === $subscription) { |
|
520 | 520 | return; |
521 | 521 | } |
522 | 522 | |
523 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
523 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
524 | 524 | sleep(1); |
525 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
526 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
525 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
526 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
527 | 527 | |
528 | 528 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
529 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
530 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
531 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
529 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
530 | + $created = date_i18n('Y-m-d H:i:s'); |
|
531 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
532 | 532 | |
533 | 533 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
534 | - $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
534 | + $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
538 | 538 | * Process the subscription payment received IPN. |
539 | 539 | */ |
540 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
541 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
540 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
541 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
542 | 542 | |
543 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
544 | - if ( empty( $parent_invoice ) ) { |
|
543 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
544 | + if (empty($parent_invoice)) { |
|
545 | 545 | return; |
546 | 546 | } |
547 | 547 | |
548 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
549 | - if ( false === $subscription ) { |
|
548 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
549 | + if (false === $subscription) { |
|
550 | 550 | return; |
551 | 551 | } |
552 | 552 | |
553 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
553 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
554 | 554 | $times_billed = $subscription->get_times_billed(); |
555 | - $signup_date = strtotime( $subscription->created ); |
|
556 | - $today = date( 'Ynd', $signup_date ) == date( 'Ynd', strtotime( $ipn_data['payment_date'] ) ); |
|
555 | + $signup_date = strtotime($subscription->created); |
|
556 | + $today = date('Ynd', $signup_date) == date('Ynd', strtotime($ipn_data['payment_date'])); |
|
557 | 557 | |
558 | 558 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
559 | - if ( (empty($times_billed) || $today) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
560 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
559 | + if ((empty($times_billed) || $today) && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
560 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
561 | 561 | sleep(1); |
562 | 562 | |
563 | 563 | // This is the very first payment |
564 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
565 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
564 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
565 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
566 | 566 | return; |
567 | 567 | } |
568 | 568 | |
569 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
569 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
570 | 570 | return; // Payment already recorded |
571 | 571 | } |
572 | 572 | |
573 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
573 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
574 | 574 | |
575 | 575 | // verify details |
576 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
576 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
577 | 577 | // the currency code is invalid |
578 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
578 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
579 | 579 | return; |
580 | 580 | } |
581 | 581 | |
@@ -585,11 +585,11 @@ discard block |
||
585 | 585 | 'gateway' => 'paypal' |
586 | 586 | ); |
587 | 587 | |
588 | - $invoice_id = $subscription->add_payment( $args ); |
|
588 | + $invoice_id = $subscription->add_payment($args); |
|
589 | 589 | |
590 | - if ( $invoice_id > 0 ) { |
|
591 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
592 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
590 | + if ($invoice_id > 0) { |
|
591 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
592 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
593 | 593 | |
594 | 594 | $subscription->renew(); |
595 | 595 | } |
@@ -598,10 +598,10 @@ discard block |
||
598 | 598 | /** |
599 | 599 | * Process the subscription canceled IPN. |
600 | 600 | */ |
601 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
602 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
601 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
602 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
603 | 603 | |
604 | - if( false === $subscription ) { |
|
604 | + if (false === $subscription) { |
|
605 | 605 | return; |
606 | 606 | } |
607 | 607 | |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | /** |
612 | 612 | * Process the subscription expired IPN. |
613 | 613 | */ |
614 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
615 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
614 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
615 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
616 | 616 | |
617 | - if( false === $subscription ) { |
|
617 | + if (false === $subscription) { |
|
618 | 618 | return; |
619 | 619 | } |
620 | 620 | |
@@ -624,40 +624,40 @@ discard block |
||
624 | 624 | /** |
625 | 625 | * Process the subscription payment failed IPN. |
626 | 626 | */ |
627 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
628 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
627 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
628 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
629 | 629 | |
630 | - if( false === $subscription ) { |
|
630 | + if (false === $subscription) { |
|
631 | 631 | return; |
632 | 632 | } |
633 | 633 | |
634 | 634 | $subscription->failing(); |
635 | 635 | |
636 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
636 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
640 | 640 | * Retrieve the subscription this IPN notice is for. |
641 | 641 | */ |
642 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
643 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
642 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
643 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
644 | 644 | |
645 | - if( empty( $parent_invoice_id ) ) { |
|
645 | + if (empty($parent_invoice_id)) { |
|
646 | 646 | return false; |
647 | 647 | } |
648 | 648 | |
649 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
650 | - if ( empty( $invoice ) ) { |
|
649 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
650 | + if (empty($invoice)) { |
|
651 | 651 | return false; |
652 | 652 | } |
653 | 653 | |
654 | - $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true ); |
|
654 | + $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true); |
|
655 | 655 | |
656 | - if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) { |
|
657 | - $subscription = wpinv_get_subscription( $parent_invoice_id ); |
|
656 | + if (!(!empty($subscription) && $subscription->id > 0)) { |
|
657 | + $subscription = wpinv_get_subscription($parent_invoice_id); |
|
658 | 658 | |
659 | - if ( ! empty( $subscription ) && $subscription->id > 0 ) { |
|
660 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
659 | + if (!empty($subscription) && $subscription->id > 0) { |
|
660 | + $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
661 | 661 | } else { |
662 | 662 | return false; |
663 | 663 | } |
@@ -667,46 +667,46 @@ discard block |
||
667 | 667 | |
668 | 668 | } |
669 | 669 | |
670 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
670 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
671 | 671 | // Collect payment details |
672 | 672 | |
673 | - if( empty( $invoice_id ) ) { |
|
673 | + if (empty($invoice_id)) { |
|
674 | 674 | return; |
675 | 675 | } |
676 | 676 | |
677 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
677 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
678 | 678 | return; // Only refund payments once |
679 | 679 | } |
680 | 680 | |
681 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
681 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
682 | 682 | $refund_amount = $data['mc_gross'] * -1; |
683 | 683 | |
684 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
684 | + do_action('wpinv_paypal_refund_request', $data, $invoice_id); |
|
685 | 685 | |
686 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
687 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
686 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
687 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float)$refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
688 | 688 | |
689 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
689 | + do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount); |
|
690 | 690 | |
691 | 691 | return; // This is a partial refund |
692 | 692 | } |
693 | 693 | |
694 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
695 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
696 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
694 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
695 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
696 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
697 | 697 | |
698 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
698 | + do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id); |
|
699 | 699 | } |
700 | 700 | |
701 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
702 | - if ( is_ssl() || ! $ssl_check ) { |
|
701 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
702 | + if (is_ssl() || !$ssl_check) { |
|
703 | 703 | $protocol = 'https://'; |
704 | 704 | } else { |
705 | 705 | $protocol = 'http://'; |
706 | 706 | } |
707 | 707 | |
708 | 708 | // Check the current payment mode |
709 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
709 | + if (wpinv_is_test_mode('paypal')) { |
|
710 | 710 | // Test mode |
711 | 711 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
712 | 712 | } else { |
@@ -714,120 +714,120 @@ discard block |
||
714 | 714 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
715 | 715 | } |
716 | 716 | |
717 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
717 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
718 | 718 | } |
719 | 719 | |
720 | -function wpinv_paypal_success_page_content( $content ) { |
|
720 | +function wpinv_paypal_success_page_content($content) { |
|
721 | 721 | global $wpi_invoice; |
722 | 722 | |
723 | 723 | $session = wpinv_get_checkout_session(); |
724 | 724 | |
725 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
725 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
726 | 726 | return $content; |
727 | 727 | } |
728 | 728 | |
729 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
729 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
730 | 730 | |
731 | - if ( empty( $invoice_id ) ) { |
|
731 | + if (empty($invoice_id)) { |
|
732 | 732 | return $content; |
733 | 733 | } |
734 | 734 | |
735 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
735 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
736 | 736 | |
737 | - if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) { |
|
737 | + if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) { |
|
738 | 738 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
739 | 739 | ob_start(); |
740 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
740 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
741 | 741 | $content = ob_get_clean(); |
742 | 742 | } |
743 | 743 | |
744 | 744 | return $content; |
745 | 745 | } |
746 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
746 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
747 | 747 | |
748 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
748 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
749 | 749 | $transaction_id = ''; |
750 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
750 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
751 | 751 | |
752 | - foreach ( $notes as $note ) { |
|
753 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
752 | + foreach ($notes as $note) { |
|
753 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
754 | 754 | $transaction_id = $match[1]; |
755 | 755 | continue; |
756 | 756 | } |
757 | 757 | } |
758 | 758 | |
759 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
759 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
760 | 760 | } |
761 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
761 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
762 | 762 | |
763 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
764 | - if ( $transaction_id == $invoice_id ) { |
|
763 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
764 | + if ($transaction_id == $invoice_id) { |
|
765 | 765 | $transaction_link = $transaction_id; |
766 | 766 | } else { |
767 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
767 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
768 | 768 | $mode = $invoice->mode; |
769 | 769 | } else { |
770 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
770 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
774 | 774 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id; |
775 | 775 | |
776 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
776 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
777 | 777 | } |
778 | 778 | |
779 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice ); |
|
779 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice); |
|
780 | 780 | } |
781 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
781 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
782 | 782 | |
783 | -function wpinv_paypal_profile_id_link( $profile_id, $subscription ) { |
|
783 | +function wpinv_paypal_profile_id_link($profile_id, $subscription) { |
|
784 | 784 | $link = $profile_id; |
785 | 785 | |
786 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
787 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
786 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
787 | + $invoice = wpinv_get_invoice($invoice_id); |
|
788 | 788 | |
789 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
789 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
790 | 790 | $mode = $invoice->mode; |
791 | 791 | } else { |
792 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
792 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
796 | 796 | $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id; |
797 | 797 | |
798 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
798 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
799 | 799 | } |
800 | 800 | |
801 | - return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription ); |
|
801 | + return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription); |
|
802 | 802 | } |
803 | -add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 ); |
|
803 | +add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2); |
|
804 | 804 | |
805 | -function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) { |
|
806 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
807 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
805 | +function wpinv_paypal_transaction_id_link($transaction_id, $subscription) { |
|
806 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
807 | + $invoice = wpinv_get_invoice($invoice_id); |
|
808 | 808 | |
809 | - if ( ! empty( $invoice ) ) { |
|
810 | - return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
809 | + if (!empty($invoice)) { |
|
810 | + return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
811 | 811 | } |
812 | 812 | } |
813 | 813 | |
814 | 814 | return $transaction_id; |
815 | 815 | } |
816 | -add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 ); |
|
816 | +add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2); |
|
817 | 817 | |
818 | 818 | function wpinv_is_paypal_valid_for_use() { |
819 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) ); |
|
819 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'))); |
|
820 | 820 | } |
821 | 821 | |
822 | -function wpinv_check_paypal_currency_support( $gateway_list ) { |
|
823 | - if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) { |
|
824 | - unset( $gateway_list['paypal'] ); |
|
822 | +function wpinv_check_paypal_currency_support($gateway_list) { |
|
823 | + if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) { |
|
824 | + unset($gateway_list['paypal']); |
|
825 | 825 | } |
826 | 826 | return $gateway_list; |
827 | 827 | } |
828 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 ); |
|
828 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1); |
|
829 | 829 | |
830 | -function wpinv_gateway_paypal_button_label( $label ) { |
|
831 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
830 | +function wpinv_gateway_paypal_button_label($label) { |
|
831 | + return __('Proceed to PayPal', 'invoicing'); |
|
832 | 832 | } |
833 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
834 | 833 | \ No newline at end of file |
834 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
835 | 835 | \ No newline at end of file |
@@ -6,31 +6,31 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5 |
8 | 8 | { |
9 | - public static $files = array ( |
|
9 | + public static $files = array( |
|
10 | 10 | '24583d3588ebda5228dd453cfaa070da' => __DIR__ . '/..' . '/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php', |
11 | 11 | ); |
12 | 12 | |
13 | - public static $prefixLengthsPsr4 = array ( |
|
13 | + public static $prefixLengthsPsr4 = array( |
|
14 | 14 | 'C' => |
15 | - array ( |
|
15 | + array( |
|
16 | 16 | 'Composer\\Installers\\' => 20, |
17 | 17 | ), |
18 | 18 | ); |
19 | 19 | |
20 | - public static $prefixDirsPsr4 = array ( |
|
20 | + public static $prefixDirsPsr4 = array( |
|
21 | 21 | 'Composer\\Installers\\' => |
22 | - array ( |
|
22 | + array( |
|
23 | 23 | 0 => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers', |
24 | 24 | ), |
25 | 25 | ); |
26 | 26 | |
27 | - public static $classMap = array ( |
|
27 | + public static $classMap = array( |
|
28 | 28 | 'WP_Super_Duper' => __DIR__ . '/..' . '/ayecode/wp-super-duper/wp-super-duper.php', |
29 | 29 | ); |
30 | 30 | |
31 | 31 | public static function getInitializer(ClassLoader $loader) |
32 | 32 | { |
33 | - return \Closure::bind(function () use ($loader) { |
|
33 | + return \Closure::bind(function() use ($loader) { |
|
34 | 34 | $loader->prefixLengthsPsr4 = ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5::$prefixLengthsPsr4; |
35 | 35 | $loader->prefixDirsPsr4 = ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5::$prefixDirsPsr4; |
36 | 36 | $loader->classMap = ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5::$classMap; |