@@ -5,237 +5,237 @@ |
||
5 | 5 | |
6 | 6 | abstract class Wpinv_DB { |
7 | 7 | |
8 | - /** |
|
9 | - * The name of our database table |
|
10 | - * |
|
11 | - * @access public |
|
12 | - * @since 1.0.0 |
|
13 | - */ |
|
14 | - public $table_name; |
|
15 | - |
|
16 | - /** |
|
17 | - * The version of our database table |
|
18 | - * |
|
19 | - * @access public |
|
20 | - * @since 1.0.0 |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * The name of the primary column |
|
26 | - * |
|
27 | - * @access public |
|
28 | - * @since 1.0.0 |
|
29 | - */ |
|
30 | - public $primary_key; |
|
31 | - |
|
32 | - /** |
|
33 | - * Get things started |
|
34 | - * |
|
35 | - * @access public |
|
36 | - * @since 1.0.0 |
|
37 | - */ |
|
38 | - public function __construct() {} |
|
39 | - |
|
40 | - /** |
|
41 | - * Whitelist of columns |
|
42 | - * |
|
43 | - * @access public |
|
44 | - * @since 1.0.0 |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function get_columns() { |
|
48 | - return array(); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Default column values |
|
53 | - * |
|
54 | - * @access public |
|
55 | - * @since 1.0.0 |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function get_column_defaults() { |
|
59 | - return array(); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Retrieve a row by the primary key |
|
64 | - * |
|
65 | - * @access public |
|
66 | - * @since 1.0.0 |
|
67 | - * @return object |
|
68 | - */ |
|
69 | - public function get( $row_id ) { |
|
70 | - global $wpdb; |
|
71 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Retrieve a row by a specific column / value |
|
76 | - * |
|
77 | - * @access public |
|
78 | - * @since 1.0.0 |
|
79 | - * @return object |
|
80 | - */ |
|
81 | - public function get_by( $column, $row_id ) { |
|
82 | - global $wpdb; |
|
83 | - $column = esc_sql( $column ); |
|
84 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Retrieve a specific column's value by the primary key |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @since 1.0.0 |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function get_column( $column, $row_id ) { |
|
95 | - global $wpdb; |
|
96 | - $column = esc_sql( $column ); |
|
97 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Retrieve a specific column's value by the the specified column / value |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @since 1.0.0 |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function get_column_by( $column, $column_where, $column_value ) { |
|
108 | - global $wpdb; |
|
109 | - $column_where = esc_sql( $column_where ); |
|
110 | - $column = esc_sql( $column ); |
|
111 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Insert a new row |
|
116 | - * |
|
117 | - * @access public |
|
118 | - * @since 1.0.0 |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function insert( $data, $type = '' ) { |
|
122 | - global $wpdb; |
|
123 | - |
|
124 | - // Set default values |
|
125 | - $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
126 | - |
|
127 | - do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
128 | - |
|
129 | - // Initialise column format array |
|
130 | - $column_formats = $this->get_columns(); |
|
131 | - |
|
132 | - // Force fields to lower case |
|
133 | - $data = array_change_key_case( $data ); |
|
134 | - |
|
135 | - // White list columns |
|
136 | - $data = array_intersect_key( $data, $column_formats ); |
|
137 | - |
|
138 | - // Reorder $column_formats to match the order of columns given in $data |
|
139 | - $data_keys = array_keys( $data ); |
|
140 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
141 | - |
|
142 | - $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
143 | - $wpdb_insert_id = $wpdb->insert_id; |
|
144 | - |
|
145 | - do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
146 | - |
|
147 | - return $wpdb_insert_id; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Update a row |
|
152 | - * |
|
153 | - * @access public |
|
154 | - * @since 1.0.0 |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function update( $row_id, $data = array(), $where = '' ) { |
|
158 | - |
|
159 | - global $wpdb; |
|
160 | - |
|
161 | - // Row ID must be positive integer |
|
162 | - $row_id = absint( $row_id ); |
|
163 | - |
|
164 | - if( empty( $row_id ) ) { |
|
165 | - return false; |
|
166 | - } |
|
167 | - |
|
168 | - if( empty( $where ) ) { |
|
169 | - $where = $this->primary_key; |
|
170 | - } |
|
171 | - |
|
172 | - // Initialise column format array |
|
173 | - $column_formats = $this->get_columns(); |
|
174 | - |
|
175 | - // Force fields to lower case |
|
176 | - $data = array_change_key_case( $data ); |
|
177 | - |
|
178 | - // White list columns |
|
179 | - $data = array_intersect_key( $data, $column_formats ); |
|
180 | - |
|
181 | - // Reorder $column_formats to match the order of columns given in $data |
|
182 | - $data_keys = array_keys( $data ); |
|
183 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
184 | - |
|
185 | - if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - return true; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Delete a row identified by the primary key |
|
194 | - * |
|
195 | - * @access public |
|
196 | - * @since 1.0.0 |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function delete( $row_id = 0 ) { |
|
200 | - |
|
201 | - global $wpdb; |
|
202 | - |
|
203 | - // Row ID must be positive integer |
|
204 | - $row_id = absint( $row_id ); |
|
205 | - |
|
206 | - if( empty( $row_id ) ) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
211 | - return false; |
|
212 | - } |
|
213 | - |
|
214 | - return true; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Check if the given table exists |
|
219 | - * |
|
220 | - * @since 2.4 |
|
221 | - * @param string $table The table name |
|
222 | - * @return bool If the table name exists |
|
223 | - */ |
|
224 | - public function table_exists( $table ) { |
|
225 | - global $wpdb; |
|
226 | - $table = sanitize_text_field( $table ); |
|
227 | - |
|
228 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Check if the table was ever installed |
|
233 | - * |
|
234 | - * @since 2.4 |
|
235 | - * @return bool Returns if the customers table was installed and upgrade routine run |
|
236 | - */ |
|
237 | - public function installed() { |
|
238 | - return $this->table_exists( $this->table_name ); |
|
239 | - } |
|
8 | + /** |
|
9 | + * The name of our database table |
|
10 | + * |
|
11 | + * @access public |
|
12 | + * @since 1.0.0 |
|
13 | + */ |
|
14 | + public $table_name; |
|
15 | + |
|
16 | + /** |
|
17 | + * The version of our database table |
|
18 | + * |
|
19 | + * @access public |
|
20 | + * @since 1.0.0 |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * The name of the primary column |
|
26 | + * |
|
27 | + * @access public |
|
28 | + * @since 1.0.0 |
|
29 | + */ |
|
30 | + public $primary_key; |
|
31 | + |
|
32 | + /** |
|
33 | + * Get things started |
|
34 | + * |
|
35 | + * @access public |
|
36 | + * @since 1.0.0 |
|
37 | + */ |
|
38 | + public function __construct() {} |
|
39 | + |
|
40 | + /** |
|
41 | + * Whitelist of columns |
|
42 | + * |
|
43 | + * @access public |
|
44 | + * @since 1.0.0 |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function get_columns() { |
|
48 | + return array(); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Default column values |
|
53 | + * |
|
54 | + * @access public |
|
55 | + * @since 1.0.0 |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function get_column_defaults() { |
|
59 | + return array(); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Retrieve a row by the primary key |
|
64 | + * |
|
65 | + * @access public |
|
66 | + * @since 1.0.0 |
|
67 | + * @return object |
|
68 | + */ |
|
69 | + public function get( $row_id ) { |
|
70 | + global $wpdb; |
|
71 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Retrieve a row by a specific column / value |
|
76 | + * |
|
77 | + * @access public |
|
78 | + * @since 1.0.0 |
|
79 | + * @return object |
|
80 | + */ |
|
81 | + public function get_by( $column, $row_id ) { |
|
82 | + global $wpdb; |
|
83 | + $column = esc_sql( $column ); |
|
84 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Retrieve a specific column's value by the primary key |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @since 1.0.0 |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function get_column( $column, $row_id ) { |
|
95 | + global $wpdb; |
|
96 | + $column = esc_sql( $column ); |
|
97 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Retrieve a specific column's value by the the specified column / value |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @since 1.0.0 |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function get_column_by( $column, $column_where, $column_value ) { |
|
108 | + global $wpdb; |
|
109 | + $column_where = esc_sql( $column_where ); |
|
110 | + $column = esc_sql( $column ); |
|
111 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Insert a new row |
|
116 | + * |
|
117 | + * @access public |
|
118 | + * @since 1.0.0 |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function insert( $data, $type = '' ) { |
|
122 | + global $wpdb; |
|
123 | + |
|
124 | + // Set default values |
|
125 | + $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
126 | + |
|
127 | + do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
128 | + |
|
129 | + // Initialise column format array |
|
130 | + $column_formats = $this->get_columns(); |
|
131 | + |
|
132 | + // Force fields to lower case |
|
133 | + $data = array_change_key_case( $data ); |
|
134 | + |
|
135 | + // White list columns |
|
136 | + $data = array_intersect_key( $data, $column_formats ); |
|
137 | + |
|
138 | + // Reorder $column_formats to match the order of columns given in $data |
|
139 | + $data_keys = array_keys( $data ); |
|
140 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
141 | + |
|
142 | + $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
143 | + $wpdb_insert_id = $wpdb->insert_id; |
|
144 | + |
|
145 | + do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
146 | + |
|
147 | + return $wpdb_insert_id; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Update a row |
|
152 | + * |
|
153 | + * @access public |
|
154 | + * @since 1.0.0 |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function update( $row_id, $data = array(), $where = '' ) { |
|
158 | + |
|
159 | + global $wpdb; |
|
160 | + |
|
161 | + // Row ID must be positive integer |
|
162 | + $row_id = absint( $row_id ); |
|
163 | + |
|
164 | + if( empty( $row_id ) ) { |
|
165 | + return false; |
|
166 | + } |
|
167 | + |
|
168 | + if( empty( $where ) ) { |
|
169 | + $where = $this->primary_key; |
|
170 | + } |
|
171 | + |
|
172 | + // Initialise column format array |
|
173 | + $column_formats = $this->get_columns(); |
|
174 | + |
|
175 | + // Force fields to lower case |
|
176 | + $data = array_change_key_case( $data ); |
|
177 | + |
|
178 | + // White list columns |
|
179 | + $data = array_intersect_key( $data, $column_formats ); |
|
180 | + |
|
181 | + // Reorder $column_formats to match the order of columns given in $data |
|
182 | + $data_keys = array_keys( $data ); |
|
183 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
184 | + |
|
185 | + if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + return true; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Delete a row identified by the primary key |
|
194 | + * |
|
195 | + * @access public |
|
196 | + * @since 1.0.0 |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function delete( $row_id = 0 ) { |
|
200 | + |
|
201 | + global $wpdb; |
|
202 | + |
|
203 | + // Row ID must be positive integer |
|
204 | + $row_id = absint( $row_id ); |
|
205 | + |
|
206 | + if( empty( $row_id ) ) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
211 | + return false; |
|
212 | + } |
|
213 | + |
|
214 | + return true; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Check if the given table exists |
|
219 | + * |
|
220 | + * @since 2.4 |
|
221 | + * @param string $table The table name |
|
222 | + * @return bool If the table name exists |
|
223 | + */ |
|
224 | + public function table_exists( $table ) { |
|
225 | + global $wpdb; |
|
226 | + $table = sanitize_text_field( $table ); |
|
227 | + |
|
228 | + return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Check if the table was ever installed |
|
233 | + * |
|
234 | + * @since 2.4 |
|
235 | + * @return bool Returns if the customers table was installed and upgrade routine run |
|
236 | + */ |
|
237 | + public function installed() { |
|
238 | + return $this->table_exists( $this->table_name ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | function wpinv_can_checkout() { |
33 | - $can_checkout = true; // Always true for now |
|
33 | + $can_checkout = true; // Always true for now |
|
34 | 34 | |
35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
35 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function wpinv_get_success_page_uri() { |
39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
40 | - $page_id = absint( $page_id ); |
|
39 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
40 | + $page_id = absint( $page_id ); |
|
41 | 41 | |
42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
42 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function wpinv_get_history_page_uri() { |
46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
47 | - $page_id = absint( $page_id ); |
|
46 | + $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
47 | + $page_id = absint( $page_id ); |
|
48 | 48 | |
49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
49 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | function wpinv_is_success_page() { |
53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
53 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
54 | + $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
55 | 55 | |
56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
56 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_invoice_history_page() { |
60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
61 | - $ret = $ret ? is_page( $ret ) : false; |
|
62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
60 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
61 | + $ret = $ret ? is_page( $ret ) : false; |
|
62 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | function wpinv_is_subscriptions_history_page() { |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | function wpinv_send_to_success_page( $args = null ) { |
72 | - $redirect = wpinv_get_success_page_uri(); |
|
72 | + $redirect = wpinv_get_success_page_uri(); |
|
73 | 73 | |
74 | 74 | if ( !empty( $args ) ) { |
75 | 75 | // Check for backward compatibility |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | function wpinv_send_to_failed_page( $args = null ) { |
92 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
92 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
93 | 93 | |
94 | 94 | if ( !empty( $args ) ) { |
95 | 95 | // Check for backward compatibility |
@@ -109,72 +109,72 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | function wpinv_get_checkout_uri( $args = array() ) { |
112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
112 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
114 | 114 | |
115 | - if ( !empty( $args ) ) { |
|
116 | - // Check for backward compatibility |
|
117 | - if ( is_string( $args ) ) |
|
118 | - $args = str_replace( '?', '', $args ); |
|
115 | + if ( !empty( $args ) ) { |
|
116 | + // Check for backward compatibility |
|
117 | + if ( is_string( $args ) ) |
|
118 | + $args = str_replace( '?', '', $args ); |
|
119 | 119 | |
120 | - $args = wp_parse_args( $args ); |
|
120 | + $args = wp_parse_args( $args ); |
|
121 | 121 | |
122 | - $uri = add_query_arg( $args, $uri ); |
|
123 | - } |
|
122 | + $uri = add_query_arg( $args, $uri ); |
|
123 | + } |
|
124 | 124 | |
125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
126 | 126 | |
127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
128 | 128 | |
129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | - } |
|
129 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | + } |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | function wpinv_send_back_to_checkout( $args = array() ) { |
137 | - $redirect = wpinv_get_checkout_uri(); |
|
137 | + $redirect = wpinv_get_checkout_uri(); |
|
138 | 138 | |
139 | - if ( ! empty( $args ) ) { |
|
140 | - // Check for backward compatibility |
|
141 | - if ( is_string( $args ) ) |
|
142 | - $args = str_replace( '?', '', $args ); |
|
139 | + if ( ! empty( $args ) ) { |
|
140 | + // Check for backward compatibility |
|
141 | + if ( is_string( $args ) ) |
|
142 | + $args = str_replace( '?', '', $args ); |
|
143 | 143 | |
144 | - $args = wp_parse_args( $args ); |
|
144 | + $args = wp_parse_args( $args ); |
|
145 | 145 | |
146 | - $redirect = add_query_arg( $args, $redirect ); |
|
147 | - } |
|
146 | + $redirect = add_query_arg( $args, $redirect ); |
|
147 | + } |
|
148 | 148 | |
149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
150 | - exit; |
|
149 | + wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
150 | + exit; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | function wpinv_get_success_page_url( $query_string = null ) { |
154 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
155 | - $success_page = get_permalink( $success_page ); |
|
154 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
155 | + $success_page = get_permalink( $success_page ); |
|
156 | 156 | |
157 | - if ( $query_string ) |
|
158 | - $success_page .= $query_string; |
|
157 | + if ( $query_string ) |
|
158 | + $success_page .= $query_string; |
|
159 | 159 | |
160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
160 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
164 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
165 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
166 | 166 | |
167 | - if ( $extras ) |
|
168 | - $uri .= $extras; |
|
167 | + if ( $extras ) |
|
168 | + $uri .= $extras; |
|
169 | 169 | |
170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
170 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_is_failed_transaction_page() { |
174 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
175 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
174 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
175 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
176 | 176 | |
177 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
177 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -22,6 +22,9 @@ |
||
22 | 22 | add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' ); |
23 | 23 | } |
24 | 24 | |
25 | + /** |
|
26 | + * @param string[] $function |
|
27 | + */ |
|
25 | 28 | public static function shortcode_wrapper( $function, $atts = array(), $content = null, $wrapper = array( 'class' => 'wpi-g', 'before' => null, 'after' => null ) ) { |
26 | 29 | ob_start(); |
27 | 30 |
@@ -83,6 +83,9 @@ discard block |
||
83 | 83 | return $value; |
84 | 84 | } |
85 | 85 | |
86 | + /** |
|
87 | + * @param string $key |
|
88 | + */ |
|
86 | 89 | public function set( $key, $value ) { |
87 | 90 | $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
88 | 91 | |
@@ -921,6 +924,9 @@ discard block |
||
921 | 924 | return $removed; |
922 | 925 | } |
923 | 926 | |
927 | + /** |
|
928 | + * @param string $key |
|
929 | + */ |
|
924 | 930 | public function remove_fee_by( $key, $value, $global = false ) { |
925 | 931 | $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
926 | 932 | 'index', 'label', 'amount', 'type', |
@@ -1381,6 +1387,9 @@ discard block |
||
1381 | 1387 | return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
1382 | 1388 | } |
1383 | 1389 | |
1390 | + /** |
|
1391 | + * @return boolean |
|
1392 | + */ |
|
1384 | 1393 | public function get_discounts( $array = false ) { |
1385 | 1394 | $discounts = $this->discounts; |
1386 | 1395 | if ( $array && $discounts ) { |
@@ -1389,6 +1398,9 @@ discard block |
||
1389 | 1398 | return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
1390 | 1399 | } |
1391 | 1400 | |
1401 | + /** |
|
1402 | + * @return string |
|
1403 | + */ |
|
1392 | 1404 | public function get_discount( $currency = false, $dash = false ) { |
1393 | 1405 | if ( !empty( $this->discounts ) ) { |
1394 | 1406 | global $ajax_cart_details; |
@@ -1491,10 +1503,16 @@ discard block |
||
1491 | 1503 | return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
1492 | 1504 | } |
1493 | 1505 | |
1506 | + /** |
|
1507 | + * @return string |
|
1508 | + */ |
|
1494 | 1509 | public function get_user_info() { |
1495 | 1510 | return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
1496 | 1511 | } |
1497 | 1512 | |
1513 | + /** |
|
1514 | + * @return string |
|
1515 | + */ |
|
1498 | 1516 | public function get_email() { |
1499 | 1517 | return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
1500 | 1518 | } |
@@ -1537,6 +1555,9 @@ discard block |
||
1537 | 1555 | return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
1538 | 1556 | } |
1539 | 1557 | |
1558 | + /** |
|
1559 | + * @return string |
|
1560 | + */ |
|
1540 | 1561 | public function get_created_date() { |
1541 | 1562 | return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
1542 | 1563 | } |
@@ -1555,6 +1576,9 @@ discard block |
||
1555 | 1576 | return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
1556 | 1577 | } |
1557 | 1578 | |
1579 | + /** |
|
1580 | + * @return string |
|
1581 | + */ |
|
1558 | 1582 | public function get_invoice_date( $formatted = true ) { |
1559 | 1583 | $date_completed = $this->completed_date; |
1560 | 1584 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
@@ -31,6 +31,9 @@ discard block |
||
31 | 31 | return apply_filters( 'wpinv_get_ip', $ip ); |
32 | 32 | } |
33 | 33 | |
34 | +/** |
|
35 | + * @return string |
|
36 | + */ |
|
34 | 37 | function wpinv_get_user_agent() { |
35 | 38 | if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
36 | 39 | $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
@@ -41,6 +44,9 @@ discard block |
||
41 | 44 | return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
42 | 45 | } |
43 | 46 | |
47 | +/** |
|
48 | + * @param integer $decimals |
|
49 | + */ |
|
44 | 50 | function wpinv_sanitize_amount( $amount, $decimals = NULL ) { |
45 | 51 | $is_negative = false; |
46 | 52 | $thousands_sep = wpinv_thousands_separator(); |
@@ -79,6 +85,9 @@ discard block |
||
79 | 85 | } |
80 | 86 | add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
81 | 87 | |
88 | +/** |
|
89 | + * @param integer $decimals |
|
90 | + */ |
|
82 | 91 | function wpinv_round_amount( $amount, $decimals = NULL ) { |
83 | 92 | if ( $decimals === NULL ) { |
84 | 93 | $decimals = wpinv_decimals(); |
@@ -298,6 +307,9 @@ discard block |
||
298 | 307 | return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
299 | 308 | } |
300 | 309 | |
310 | +/** |
|
311 | + * @return string |
|
312 | + */ |
|
301 | 313 | function wpinv_currency_position() { |
302 | 314 | $position = wpinv_get_option( 'currency_position', 'left' ); |
303 | 315 | |
@@ -556,6 +568,9 @@ discard block |
||
556 | 568 | return $price; |
557 | 569 | } |
558 | 570 | |
571 | +/** |
|
572 | + * @return string |
|
573 | + */ |
|
559 | 574 | function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
560 | 575 | $thousands_sep = wpinv_thousands_separator(); |
561 | 576 | $decimal_sep = wpinv_decimal_separator(); |
@@ -606,6 +621,9 @@ discard block |
||
606 | 621 | return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
607 | 622 | } |
608 | 623 | |
624 | +/** |
|
625 | + * @return string |
|
626 | + */ |
|
609 | 627 | function wpinv_get_file_extension( $str ) { |
610 | 628 | $parts = explode( '.', $str ); |
611 | 629 | return end( $parts ); |
@@ -810,6 +828,9 @@ discard block |
||
810 | 828 | return strlen( $str ); |
811 | 829 | } |
812 | 830 | |
831 | +/** |
|
832 | + * @param string $str |
|
833 | + */ |
|
813 | 834 | function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
814 | 835 | if ( function_exists( 'mb_strtolower' ) ) { |
815 | 836 | return mb_strtolower( $str, $encoding ); |
@@ -818,6 +839,9 @@ discard block |
||
818 | 839 | return strtolower( $str ); |
819 | 840 | } |
820 | 841 | |
842 | +/** |
|
843 | + * @param string $str |
|
844 | + */ |
|
821 | 845 | function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
822 | 846 | if ( function_exists( 'mb_strtoupper' ) ) { |
823 | 847 | return mb_strtoupper( $str, $encoding ); |
@@ -895,7 +919,7 @@ discard block |
||
895 | 919 | * |
896 | 920 | * @param string $str The string being decoded. |
897 | 921 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
898 | - * @return string The width of string. |
|
922 | + * @return integer The width of string. |
|
899 | 923 | */ |
900 | 924 | function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
901 | 925 | if ( function_exists( 'mb_strwidth' ) ) { |
@@ -946,6 +970,11 @@ discard block |
||
946 | 970 | return $period; |
947 | 971 | } |
948 | 972 | |
973 | +/** |
|
974 | + * @param integer $calendar |
|
975 | + * @param string $month |
|
976 | + * @param string $year |
|
977 | + */ |
|
949 | 978 | function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
950 | 979 | if ( function_exists( 'cal_days_in_month' ) ) { |
951 | 980 | return cal_days_in_month( $calendar, $month, $year ); |
@@ -488,6 +488,9 @@ discard block |
||
488 | 488 | return $invoice->get_description(); |
489 | 489 | } |
490 | 490 | |
491 | +/** |
|
492 | + * @return string |
|
493 | + */ |
|
491 | 494 | function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
492 | 495 | $invoice = new WPInv_Invoice( $invoice_id ); |
493 | 496 | return $invoice->get_currency(); |
@@ -521,6 +524,9 @@ discard block |
||
521 | 524 | return $invoice->get_gateway_title(); |
522 | 525 | } |
523 | 526 | |
527 | +/** |
|
528 | + * @return string |
|
529 | + */ |
|
524 | 530 | function wpinv_get_payment_transaction_id( $invoice_id ) { |
525 | 531 | $invoice = new WPInv_Invoice( $invoice_id ); |
526 | 532 | |
@@ -616,6 +622,9 @@ discard block |
||
616 | 622 | return $invoice->get_total( $currency ); |
617 | 623 | } |
618 | 624 | |
625 | +/** |
|
626 | + * @return string |
|
627 | + */ |
|
619 | 628 | function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
620 | 629 | $invoice = new WPInv_Invoice( $invoice_id ); |
621 | 630 | |
@@ -626,6 +635,9 @@ discard block |
||
626 | 635 | return $date_created; |
627 | 636 | } |
628 | 637 | |
638 | +/** |
|
639 | + * @return string |
|
640 | + */ |
|
629 | 641 | function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
630 | 642 | $invoice = new WPInv_Invoice( $invoice_id ); |
631 | 643 |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * Retrieves the transaction ID from the subscription |
371 | 371 | * |
372 | 372 | * @since 1.0.0 |
373 | - * @return bool |
|
373 | + * @return string |
|
374 | 374 | */ |
375 | 375 | public function get_transaction_id() { |
376 | 376 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * Stores the transaction ID for the subscription purchase |
393 | 393 | * |
394 | 394 | * @since 1.0.0.4 |
395 | - * @return bool |
|
395 | + * @return boolean|null |
|
396 | 396 | */ |
397 | 397 | public function set_transaction_id( $txn_id = '' ) { |
398 | 398 | $this->update( array( 'transaction_id' => $txn_id ) ); |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * Renews a subscription |
404 | 404 | * |
405 | 405 | * @since 1.0.0 |
406 | - * @return bool |
|
406 | + * @return boolean|null |
|
407 | 407 | */ |
408 | 408 | public function renew() { |
409 | 409 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | * |
493 | 493 | * @since 1.0.0 |
494 | 494 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
495 | - * @return void |
|
495 | + * @return false|null |
|
496 | 496 | */ |
497 | 497 | public function expire( $check_expiration = false ) { |
498 | 498 | |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * Retrieves the subscription status |
745 | 745 | * |
746 | 746 | * @since 1.0.0 |
747 | - * @return int |
|
747 | + * @return string |
|
748 | 748 | */ |
749 | 749 | public function get_status() { |
750 | 750 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
5 | - exit; |
|
5 | + exit; |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -13,183 +13,183 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class WPInv_Subscription { |
15 | 15 | |
16 | - private $subs_db; |
|
16 | + private $subs_db; |
|
17 | + |
|
18 | + public $id = 0; |
|
19 | + public $customer_id = 0; |
|
20 | + public $period = ''; |
|
21 | + public $initial_amount = ''; |
|
22 | + public $recurring_amount = ''; |
|
23 | + public $bill_times = 0; |
|
24 | + public $transaction_id = ''; |
|
25 | + public $parent_payment_id = 0; |
|
26 | + public $product_id = 0; |
|
27 | + public $created = '0000-00-00 00:00:00'; |
|
28 | + public $expiration = '0000-00-00 00:00:00'; |
|
29 | + public $trial_period = ''; |
|
30 | + public $status = 'pending'; |
|
31 | + public $profile_id = ''; |
|
32 | + public $gateway = ''; |
|
33 | + public $customer; |
|
17 | 34 | |
18 | - public $id = 0; |
|
19 | - public $customer_id = 0; |
|
20 | - public $period = ''; |
|
21 | - public $initial_amount = ''; |
|
22 | - public $recurring_amount = ''; |
|
23 | - public $bill_times = 0; |
|
24 | - public $transaction_id = ''; |
|
25 | - public $parent_payment_id = 0; |
|
26 | - public $product_id = 0; |
|
27 | - public $created = '0000-00-00 00:00:00'; |
|
28 | - public $expiration = '0000-00-00 00:00:00'; |
|
29 | - public $trial_period = ''; |
|
30 | - public $status = 'pending'; |
|
31 | - public $profile_id = ''; |
|
32 | - public $gateway = ''; |
|
33 | - public $customer; |
|
34 | - |
|
35 | - /** |
|
36 | - * Get us started |
|
37 | - * |
|
38 | - * @since 1.0.0 |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
35 | + /** |
|
36 | + * Get us started |
|
37 | + * |
|
38 | + * @since 1.0.0 |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
42 | 42 | |
43 | - $this->subs_db = new WPInv_Subscriptions_DB; |
|
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 ) ) { |
|
50 | - return false; |
|
51 | - } |
|
49 | + if( empty( $_sub ) ) { |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | |
53 | - $_id_or_object = $_sub; |
|
53 | + $_id_or_object = $_sub; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
58 | - } |
|
57 | + return $this->setup_subscription( $_id_or_object ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Setup the subscription object |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
60 | + /** |
|
61 | + * Setup the subscription object |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + private function setup_subscription( $id_or_object = 0 ) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
69 | - return false; |
|
70 | - } |
|
68 | + if( empty( $id_or_object ) ) { |
|
69 | + return false; |
|
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 | - $sub = $id_or_object; |
|
78 | + $sub = $id_or_object; |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
83 | - return false; |
|
84 | - } |
|
82 | + if( empty( $sub ) ) { |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
87 | - $this->$key = $value; |
|
88 | - } |
|
86 | + foreach( $sub as $key => $value ) { |
|
87 | + $this->$key = $value; |
|
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 | - return $this; |
|
96 | - } |
|
95 | + return $this; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Magic __get function to dispatch a call to retrieve a private property |
|
100 | - * |
|
101 | - * @since 1.0.0 |
|
102 | - */ |
|
103 | - public function __get( $key ) { |
|
98 | + /** |
|
99 | + * Magic __get function to dispatch a call to retrieve a private property |
|
100 | + * |
|
101 | + * @since 1.0.0 |
|
102 | + */ |
|
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 | - } else { |
|
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 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Creates a subscription |
|
119 | - * |
|
120 | - * @since 1.0.0 |
|
121 | - * @param array $data Array of attributes for a subscription |
|
122 | - * @return mixed false if data isn't passed and class not instantiated for creation |
|
123 | - */ |
|
124 | - public function create( $data = array() ) { |
|
117 | + /** |
|
118 | + * Creates a subscription |
|
119 | + * |
|
120 | + * @since 1.0.0 |
|
121 | + * @param array $data Array of attributes for a subscription |
|
122 | + * @return mixed false if data isn't passed and class not instantiated for creation |
|
123 | + */ |
|
124 | + public function create( $data = array() ) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
127 | - return false; |
|
128 | - } |
|
126 | + if ( $this->id != 0 ) { |
|
127 | + return false; |
|
128 | + } |
|
129 | 129 | |
130 | - $defaults = array( |
|
131 | - 'customer_id' => 0, |
|
132 | - 'frequency' => '', |
|
133 | - 'period' => '', |
|
134 | - 'initial_amount' => '', |
|
135 | - 'recurring_amount' => '', |
|
136 | - 'bill_times' => 0, |
|
137 | - 'parent_payment_id' => 0, |
|
138 | - 'product_id' => 0, |
|
139 | - 'created' => '', |
|
140 | - 'expiration' => '', |
|
141 | - 'status' => '', |
|
142 | - 'profile_id' => '', |
|
143 | - ); |
|
130 | + $defaults = array( |
|
131 | + 'customer_id' => 0, |
|
132 | + 'frequency' => '', |
|
133 | + 'period' => '', |
|
134 | + 'initial_amount' => '', |
|
135 | + 'recurring_amount' => '', |
|
136 | + 'bill_times' => 0, |
|
137 | + 'parent_payment_id' => 0, |
|
138 | + 'product_id' => 0, |
|
139 | + 'created' => '', |
|
140 | + 'expiration' => '', |
|
141 | + 'status' => '', |
|
142 | + 'profile_id' => '', |
|
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 | - // Force an active subscription to expired if expiration date is in the past |
|
152 | - $args['status'] = 'expired'; |
|
151 | + // Force an active subscription to expired if expiration date is in the past |
|
152 | + $args['status'] = 'expired'; |
|
153 | 153 | |
154 | - } |
|
155 | - } |
|
154 | + } |
|
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 | |
167 | - /** |
|
168 | - * Updates a subscription |
|
169 | - * |
|
170 | - * @since 1.0.0 |
|
171 | - * @param array $args Array of fields to update |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function update( $args = array() ) { |
|
167 | + /** |
|
168 | + * Updates a subscription |
|
169 | + * |
|
170 | + * @since 1.0.0 |
|
171 | + * @param array $args Array of fields to update |
|
172 | + * @return bool |
|
173 | + */ |
|
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 | - return $ret; |
|
180 | + return $ret; |
|
181 | 181 | |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Delete the subscription |
|
186 | - * |
|
187 | - * @since 1.0.0 |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - public function delete() { |
|
191 | - return $this->subs_db->delete( $this->id ); |
|
192 | - } |
|
184 | + /** |
|
185 | + * Delete the subscription |
|
186 | + * |
|
187 | + * @since 1.0.0 |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + public function delete() { |
|
191 | + return $this->subs_db->delete( $this->id ); |
|
192 | + } |
|
193 | 193 | |
194 | 194 | /** |
195 | 195 | * Retrieves the parent payment ID |
@@ -366,185 +366,185 @@ discard block |
||
366 | 366 | return false; |
367 | 367 | } |
368 | 368 | |
369 | - /** |
|
370 | - * Retrieves the transaction ID from the subscription |
|
371 | - * |
|
372 | - * @since 1.0.0 |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function get_transaction_id() { |
|
369 | + /** |
|
370 | + * Retrieves the transaction ID from the subscription |
|
371 | + * |
|
372 | + * @since 1.0.0 |
|
373 | + * @return bool |
|
374 | + */ |
|
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 ); |
|
383 | - } |
|
381 | + if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | + $this->set_transaction_id( $txn_id ); |
|
383 | + } |
|
384 | 384 | |
385 | - } |
|
385 | + } |
|
386 | 386 | |
387 | - return $this->transaction_id; |
|
387 | + return $this->transaction_id; |
|
388 | 388 | |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | - /** |
|
392 | - * Stores the transaction ID for the subscription purchase |
|
393 | - * |
|
394 | - * @since 1.0.0.4 |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
399 | - $this->transaction_id = $txn_id; |
|
400 | - } |
|
391 | + /** |
|
392 | + * Stores the transaction ID for the subscription purchase |
|
393 | + * |
|
394 | + * @since 1.0.0.4 |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function set_transaction_id( $txn_id = '' ) { |
|
398 | + $this->update( array( 'transaction_id' => $txn_id ) ); |
|
399 | + $this->transaction_id = $txn_id; |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Renews a subscription |
|
404 | - * |
|
405 | - * @since 1.0.0 |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function renew() { |
|
402 | + /** |
|
403 | + * Renews a subscription |
|
404 | + * |
|
405 | + * @since 1.0.0 |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function renew() { |
|
409 | 409 | |
410 | - $expires = $this->get_expiration_time(); |
|
410 | + $expires = $this->get_expiration_time(); |
|
411 | 411 | |
412 | 412 | |
413 | - // Determine what date to use as the start for the new expiration calculation |
|
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
413 | + // Determine what date to use as the start for the new expiration calculation |
|
414 | + if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | - } else { |
|
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 | - $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 ) ); |
|
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 ) ); |
|
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' ) ); |
|
432 | - } |
|
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 | + } |
|
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 | - $this->status = 'active'; |
|
439 | - $times_billed = $this->get_times_billed(); |
|
438 | + $this->status = 'active'; |
|
439 | + $times_billed = $this->get_times_billed(); |
|
440 | 440 | |
441 | - // Complete subscription if applicable |
|
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
443 | - $this->complete(); |
|
444 | - $this->status = 'completed'; |
|
445 | - } |
|
441 | + // Complete subscription if applicable |
|
442 | + if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
443 | + $this->complete(); |
|
444 | + $this->status = 'completed'; |
|
445 | + } |
|
446 | 446 | |
447 | - $args = array( |
|
448 | - 'expiration' => $expiration, |
|
449 | - 'status' => $this->status, |
|
450 | - ); |
|
447 | + $args = array( |
|
448 | + 'expiration' => $expiration, |
|
449 | + 'status' => $this->status, |
|
450 | + ); |
|
451 | 451 | |
452 | 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 | |
459 | - /** |
|
460 | - * Marks a subscription as completed |
|
461 | - * |
|
462 | - * Subscription is completed when the number of payments matches the billing_times field |
|
463 | - * |
|
464 | - * @since 1.0.0 |
|
465 | - * @return void |
|
466 | - */ |
|
467 | - public function complete() { |
|
459 | + /** |
|
460 | + * Marks a subscription as completed |
|
461 | + * |
|
462 | + * Subscription is completed when the number of payments matches the billing_times field |
|
463 | + * |
|
464 | + * @since 1.0.0 |
|
465 | + * @return void |
|
466 | + */ |
|
467 | + public function complete() { |
|
468 | 468 | |
469 | - // Only mark a subscription as complete if it's not already cancelled. |
|
470 | - if ( 'cancelled' === $this->status ) { |
|
471 | - return; |
|
472 | - } |
|
469 | + // Only mark a subscription as complete if it's not already cancelled. |
|
470 | + if ( 'cancelled' === $this->status ) { |
|
471 | + return; |
|
472 | + } |
|
473 | 473 | |
474 | - $args = array( |
|
475 | - 'status' => 'completed' |
|
476 | - ); |
|
474 | + $args = array( |
|
475 | + 'status' => 'completed' |
|
476 | + ); |
|
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
479 | 479 | |
480 | - $this->status = 'completed'; |
|
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 | |
486 | - } |
|
486 | + } |
|
487 | 487 | |
488 | - /** |
|
489 | - * Marks a subscription as expired |
|
490 | - * |
|
491 | - * Subscription is completed when the billing times is reached |
|
492 | - * |
|
493 | - * @since 1.0.0 |
|
494 | - * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
495 | - * @return void |
|
496 | - */ |
|
497 | - public function expire( $check_expiration = false ) { |
|
488 | + /** |
|
489 | + * Marks a subscription as expired |
|
490 | + * |
|
491 | + * Subscription is completed when the billing times is reached |
|
492 | + * |
|
493 | + * @since 1.0.0 |
|
494 | + * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
495 | + * @return void |
|
496 | + */ |
|
497 | + public function expire( $check_expiration = false ) { |
|
498 | 498 | |
499 | - $expiration = $this->expiration; |
|
499 | + $expiration = $this->expiration; |
|
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if( $check_expiration ) { |
|
502 | 502 | |
503 | - // check_expiration() updates $this->expiration so compare to $expiration above |
|
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 | - return false; // Do not mark as expired since real expiration date is in the future |
|
508 | - } |
|
507 | + return false; // Do not mark as expired since real expiration date is in the future |
|
508 | + } |
|
509 | 509 | |
510 | - } |
|
510 | + } |
|
511 | 511 | |
512 | - $args = array( |
|
513 | - 'status' => 'expired' |
|
514 | - ); |
|
512 | + $args = array( |
|
513 | + 'status' => 'expired' |
|
514 | + ); |
|
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
517 | 517 | |
518 | - $this->status = 'expired'; |
|
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 | |
524 | - } |
|
524 | + } |
|
525 | 525 | |
526 | - /** |
|
527 | - * Marks a subscription as failing |
|
528 | - * |
|
529 | - * @since 2.4.2 |
|
530 | - * @return void |
|
531 | - */ |
|
532 | - public function failing() { |
|
526 | + /** |
|
527 | + * Marks a subscription as failing |
|
528 | + * |
|
529 | + * @since 2.4.2 |
|
530 | + * @return void |
|
531 | + */ |
|
532 | + public function failing() { |
|
533 | 533 | |
534 | - $args = array( |
|
535 | - 'status' => 'failing' |
|
536 | - ); |
|
534 | + $args = array( |
|
535 | + 'status' => 'failing' |
|
536 | + ); |
|
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
539 | 539 | |
540 | - $this->status = 'failing'; |
|
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 | + } |
|
546 | 546 | |
547 | - } |
|
547 | + } |
|
548 | 548 | |
549 | 549 | /** |
550 | 550 | * Marks a subscription as cancelled |
@@ -578,22 +578,22 @@ discard block |
||
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
581 | - /** |
|
582 | - * Determines if subscription can be cancelled |
|
583 | - * |
|
584 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
585 | - * that can be cancelled with a profile ID through the merchant processor |
|
586 | - * |
|
587 | - * @since 1.0.0 |
|
588 | - * @return bool |
|
589 | - */ |
|
590 | - public function can_cancel() { |
|
581 | + /** |
|
582 | + * Determines if subscription can be cancelled |
|
583 | + * |
|
584 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
585 | + * that can be cancelled with a profile ID through the merchant processor |
|
586 | + * |
|
587 | + * @since 1.0.0 |
|
588 | + * @return bool |
|
589 | + */ |
|
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 ); |
|
596 | - } |
|
595 | + return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
596 | + } |
|
597 | 597 | |
598 | 598 | /** |
599 | 599 | * Returns an array of subscription statuses that can be cancelled |
@@ -606,197 +606,197 @@ discard block |
||
606 | 606 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
607 | 607 | } |
608 | 608 | |
609 | - /** |
|
610 | - * Retrieves the URL to cancel subscription |
|
611 | - * |
|
612 | - * @since 1.0.0 |
|
613 | - * @return string |
|
614 | - */ |
|
615 | - public function get_cancel_url() { |
|
609 | + /** |
|
610 | + * Retrieves the URL to cancel subscription |
|
611 | + * |
|
612 | + * @since 1.0.0 |
|
613 | + * @return string |
|
614 | + */ |
|
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 ); |
|
620 | - } |
|
619 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
620 | + } |
|
621 | 621 | |
622 | - /** |
|
623 | - * Determines if subscription can be manually renewed |
|
624 | - * |
|
625 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
626 | - * that can be renewed manually |
|
627 | - * |
|
628 | - * @since 2.5 |
|
629 | - * @return bool |
|
630 | - */ |
|
631 | - public function can_renew() { |
|
622 | + /** |
|
623 | + * Determines if subscription can be manually renewed |
|
624 | + * |
|
625 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
626 | + * that can be renewed manually |
|
627 | + * |
|
628 | + * @since 2.5 |
|
629 | + * @return bool |
|
630 | + */ |
|
631 | + public function can_renew() { |
|
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Retrieves the URL to renew a subscription |
|
638 | - * |
|
639 | - * @since 2.5 |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function get_renew_url() { |
|
643 | - |
|
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
645 | - |
|
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Determines if subscription can have their payment method updated |
|
651 | - * |
|
652 | - * @since 1.0.0 |
|
653 | - * @return bool |
|
654 | - */ |
|
655 | - public function can_update() { |
|
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Retrieves the URL to update subscription |
|
661 | - * |
|
662 | - * @since 1.0.0 |
|
663 | - * @return void |
|
664 | - */ |
|
665 | - public function get_update_url() { |
|
666 | - |
|
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
668 | - |
|
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Determines if subscription is active |
|
674 | - * |
|
675 | - * @since 1.0.0 |
|
676 | - * @return void |
|
677 | - */ |
|
678 | - public function is_active() { |
|
679 | - |
|
680 | - $ret = false; |
|
681 | - |
|
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
683 | - $ret = true; |
|
684 | - } |
|
685 | - |
|
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Determines if subscription is expired |
|
692 | - * |
|
693 | - * @since 1.0.0 |
|
694 | - * @return void |
|
695 | - */ |
|
696 | - public function is_expired() { |
|
697 | - |
|
698 | - $ret = false; |
|
699 | - |
|
700 | - if ( $this->status == 'expired' ) { |
|
701 | - |
|
702 | - $ret = true; |
|
703 | - |
|
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
705 | - |
|
706 | - $ret = false; |
|
707 | - $expiration = $this->get_expiration_time(); |
|
708 | - |
|
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
710 | - $ret = true; |
|
711 | - |
|
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
713 | - $this->expire(); |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - } |
|
718 | - |
|
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
720 | - |
|
721 | - } |
|
722 | - |
|
723 | - /** |
|
724 | - * Retrieves the expiration date |
|
725 | - * |
|
726 | - * @since 1.0.0 |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function get_expiration() { |
|
730 | - return $this->expiration; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Retrieves the expiration date in a timestamp |
|
735 | - * |
|
736 | - * @since 1.0.0 |
|
737 | - * @return int |
|
738 | - */ |
|
739 | - public function get_expiration_time() { |
|
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Retrieves the subscription status |
|
745 | - * |
|
746 | - * @since 1.0.0 |
|
747 | - * @return int |
|
748 | - */ |
|
749 | - public function get_status() { |
|
750 | - |
|
751 | - // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
752 | - $this->is_expired(); |
|
753 | - return $this->status; |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Retrieves the subscription status label |
|
758 | - * |
|
759 | - * @since 1.0.0 |
|
760 | - * @return int |
|
761 | - */ |
|
762 | - public function get_status_label() { |
|
763 | - |
|
764 | - switch( $this->get_status() ) { |
|
765 | - case 'active' : |
|
766 | - $status = __( 'Active', 'invoicing' ); |
|
767 | - break; |
|
768 | - |
|
769 | - case 'cancelled' : |
|
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
771 | - break; |
|
772 | - |
|
773 | - case 'expired' : |
|
774 | - $status = __( 'Expired', 'invoicing' ); |
|
775 | - break; |
|
776 | - |
|
777 | - case 'pending' : |
|
778 | - $status = __( 'Pending', 'invoicing' ); |
|
779 | - break; |
|
780 | - |
|
781 | - case 'failing' : |
|
782 | - $status = __( 'Failing', 'invoicing' ); |
|
783 | - break; |
|
784 | - |
|
785 | - case 'trialling' : |
|
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
787 | - break; |
|
788 | - |
|
789 | - case 'completed' : |
|
790 | - $status = __( 'Completed', 'invoicing' ); |
|
791 | - break; |
|
792 | - |
|
793 | - default: |
|
794 | - $status = ucfirst( $this->get_status() ); |
|
795 | - break; |
|
796 | - } |
|
797 | - |
|
798 | - return $status; |
|
799 | - } |
|
633 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Retrieves the URL to renew a subscription |
|
638 | + * |
|
639 | + * @since 2.5 |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function get_renew_url() { |
|
643 | + |
|
644 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
645 | + |
|
646 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Determines if subscription can have their payment method updated |
|
651 | + * |
|
652 | + * @since 1.0.0 |
|
653 | + * @return bool |
|
654 | + */ |
|
655 | + public function can_update() { |
|
656 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Retrieves the URL to update subscription |
|
661 | + * |
|
662 | + * @since 1.0.0 |
|
663 | + * @return void |
|
664 | + */ |
|
665 | + public function get_update_url() { |
|
666 | + |
|
667 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
668 | + |
|
669 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Determines if subscription is active |
|
674 | + * |
|
675 | + * @since 1.0.0 |
|
676 | + * @return void |
|
677 | + */ |
|
678 | + public function is_active() { |
|
679 | + |
|
680 | + $ret = false; |
|
681 | + |
|
682 | + if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
683 | + $ret = true; |
|
684 | + } |
|
685 | + |
|
686 | + return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Determines if subscription is expired |
|
692 | + * |
|
693 | + * @since 1.0.0 |
|
694 | + * @return void |
|
695 | + */ |
|
696 | + public function is_expired() { |
|
697 | + |
|
698 | + $ret = false; |
|
699 | + |
|
700 | + if ( $this->status == 'expired' ) { |
|
701 | + |
|
702 | + $ret = true; |
|
703 | + |
|
704 | + } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
705 | + |
|
706 | + $ret = false; |
|
707 | + $expiration = $this->get_expiration_time(); |
|
708 | + |
|
709 | + if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
710 | + $ret = true; |
|
711 | + |
|
712 | + if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
713 | + $this->expire(); |
|
714 | + } |
|
715 | + } |
|
716 | + |
|
717 | + } |
|
718 | + |
|
719 | + return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
720 | + |
|
721 | + } |
|
722 | + |
|
723 | + /** |
|
724 | + * Retrieves the expiration date |
|
725 | + * |
|
726 | + * @since 1.0.0 |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function get_expiration() { |
|
730 | + return $this->expiration; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Retrieves the expiration date in a timestamp |
|
735 | + * |
|
736 | + * @since 1.0.0 |
|
737 | + * @return int |
|
738 | + */ |
|
739 | + public function get_expiration_time() { |
|
740 | + return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Retrieves the subscription status |
|
745 | + * |
|
746 | + * @since 1.0.0 |
|
747 | + * @return int |
|
748 | + */ |
|
749 | + public function get_status() { |
|
750 | + |
|
751 | + // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
752 | + $this->is_expired(); |
|
753 | + return $this->status; |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Retrieves the subscription status label |
|
758 | + * |
|
759 | + * @since 1.0.0 |
|
760 | + * @return int |
|
761 | + */ |
|
762 | + public function get_status_label() { |
|
763 | + |
|
764 | + switch( $this->get_status() ) { |
|
765 | + case 'active' : |
|
766 | + $status = __( 'Active', 'invoicing' ); |
|
767 | + break; |
|
768 | + |
|
769 | + case 'cancelled' : |
|
770 | + $status = __( 'Cancelled', 'invoicing' ); |
|
771 | + break; |
|
772 | + |
|
773 | + case 'expired' : |
|
774 | + $status = __( 'Expired', 'invoicing' ); |
|
775 | + break; |
|
776 | + |
|
777 | + case 'pending' : |
|
778 | + $status = __( 'Pending', 'invoicing' ); |
|
779 | + break; |
|
780 | + |
|
781 | + case 'failing' : |
|
782 | + $status = __( 'Failing', 'invoicing' ); |
|
783 | + break; |
|
784 | + |
|
785 | + case 'trialling' : |
|
786 | + $status = __( 'Trialling', 'invoicing' ); |
|
787 | + break; |
|
788 | + |
|
789 | + case 'completed' : |
|
790 | + $status = __( 'Completed', 'invoicing' ); |
|
791 | + break; |
|
792 | + |
|
793 | + default: |
|
794 | + $status = ucfirst( $this->get_status() ); |
|
795 | + break; |
|
796 | + } |
|
797 | + |
|
798 | + return $status; |
|
799 | + } |
|
800 | 800 | |
801 | 801 | /** |
802 | 802 | * Retrieves the subscription status label |
@@ -218,262 +218,262 @@ discard block |
||
218 | 218 | add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
219 | 219 | |
220 | 220 | function wpinv_process_paypal_ipn() { |
221 | - // Check the request method is POST |
|
222 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
223 | - return; |
|
224 | - } |
|
225 | - |
|
226 | - // Set initial post data to empty string |
|
227 | - $post_data = ''; |
|
228 | - |
|
229 | - // Fallback just in case post_max_size is lower than needed |
|
230 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
231 | - $post_data = file_get_contents( 'php://input' ); |
|
232 | - } else { |
|
233 | - // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
234 | - ini_set( 'post_max_size', '12M' ); |
|
235 | - } |
|
236 | - // Start the encoded data collection with notification command |
|
237 | - $encoded_data = 'cmd=_notify-validate'; |
|
238 | - |
|
239 | - // Get current arg separator |
|
240 | - $arg_separator = wpinv_get_php_arg_separator_output(); |
|
241 | - |
|
242 | - // Verify there is a post_data |
|
243 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
244 | - // Append the data |
|
245 | - $encoded_data .= $arg_separator.$post_data; |
|
246 | - } else { |
|
247 | - // Check if POST is empty |
|
248 | - if ( empty( $_POST ) ) { |
|
249 | - // Nothing to do |
|
250 | - return; |
|
251 | - } else { |
|
252 | - // Loop through each POST |
|
253 | - foreach ( $_POST as $key => $value ) { |
|
254 | - // Encode the value and append the data |
|
255 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - // Convert collected post data to an array |
|
261 | - parse_str( $encoded_data, $encoded_data_array ); |
|
262 | - |
|
263 | - foreach ( $encoded_data_array as $key => $value ) { |
|
264 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
265 | - $new_key = str_replace( '&', '&', $key ); |
|
266 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
267 | - |
|
268 | - unset( $encoded_data_array[ $key ] ); |
|
269 | - $encoded_data_array[ $new_key ] = $value; |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - // Get the PayPal redirect uri |
|
274 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
275 | - |
|
276 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
277 | - // Validate the IPN |
|
278 | - |
|
279 | - $remote_post_vars = array( |
|
280 | - 'method' => 'POST', |
|
281 | - 'timeout' => 45, |
|
282 | - 'redirection' => 5, |
|
283 | - 'httpversion' => '1.1', |
|
284 | - 'blocking' => true, |
|
285 | - 'headers' => array( |
|
286 | - 'host' => 'www.paypal.com', |
|
287 | - 'connection' => 'close', |
|
288 | - 'content-type' => 'application/x-www-form-urlencoded', |
|
289 | - 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
290 | - |
|
291 | - ), |
|
292 | - 'sslverify' => false, |
|
293 | - 'body' => $encoded_data_array |
|
294 | - ); |
|
295 | - |
|
296 | - // Get response |
|
297 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
298 | - |
|
299 | - if ( is_wp_error( $api_response ) ) { |
|
300 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
301 | - return; // Something went wrong |
|
302 | - } |
|
303 | - |
|
304 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
305 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
306 | - return; // Response not okay |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - // Check if $post_data_array has been populated |
|
311 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
312 | - return; |
|
313 | - |
|
314 | - $defaults = array( |
|
315 | - 'txn_type' => '', |
|
316 | - 'payment_status' => '' |
|
317 | - ); |
|
318 | - |
|
319 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
320 | - |
|
321 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
221 | + // Check the request method is POST |
|
222 | + if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
223 | + return; |
|
224 | + } |
|
225 | + |
|
226 | + // Set initial post data to empty string |
|
227 | + $post_data = ''; |
|
228 | + |
|
229 | + // Fallback just in case post_max_size is lower than needed |
|
230 | + if ( ini_get( 'allow_url_fopen' ) ) { |
|
231 | + $post_data = file_get_contents( 'php://input' ); |
|
232 | + } else { |
|
233 | + // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
234 | + ini_set( 'post_max_size', '12M' ); |
|
235 | + } |
|
236 | + // Start the encoded data collection with notification command |
|
237 | + $encoded_data = 'cmd=_notify-validate'; |
|
238 | + |
|
239 | + // Get current arg separator |
|
240 | + $arg_separator = wpinv_get_php_arg_separator_output(); |
|
241 | + |
|
242 | + // Verify there is a post_data |
|
243 | + if ( $post_data || strlen( $post_data ) > 0 ) { |
|
244 | + // Append the data |
|
245 | + $encoded_data .= $arg_separator.$post_data; |
|
246 | + } else { |
|
247 | + // Check if POST is empty |
|
248 | + if ( empty( $_POST ) ) { |
|
249 | + // Nothing to do |
|
250 | + return; |
|
251 | + } else { |
|
252 | + // Loop through each POST |
|
253 | + foreach ( $_POST as $key => $value ) { |
|
254 | + // Encode the value and append the data |
|
255 | + $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + // Convert collected post data to an array |
|
261 | + parse_str( $encoded_data, $encoded_data_array ); |
|
262 | + |
|
263 | + foreach ( $encoded_data_array as $key => $value ) { |
|
264 | + if ( false !== strpos( $key, 'amp;' ) ) { |
|
265 | + $new_key = str_replace( '&', '&', $key ); |
|
266 | + $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
267 | + |
|
268 | + unset( $encoded_data_array[ $key ] ); |
|
269 | + $encoded_data_array[ $new_key ] = $value; |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + // Get the PayPal redirect uri |
|
274 | + $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
275 | + |
|
276 | + if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
277 | + // Validate the IPN |
|
278 | + |
|
279 | + $remote_post_vars = array( |
|
280 | + 'method' => 'POST', |
|
281 | + 'timeout' => 45, |
|
282 | + 'redirection' => 5, |
|
283 | + 'httpversion' => '1.1', |
|
284 | + 'blocking' => true, |
|
285 | + 'headers' => array( |
|
286 | + 'host' => 'www.paypal.com', |
|
287 | + 'connection' => 'close', |
|
288 | + 'content-type' => 'application/x-www-form-urlencoded', |
|
289 | + 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
290 | + |
|
291 | + ), |
|
292 | + 'sslverify' => false, |
|
293 | + 'body' => $encoded_data_array |
|
294 | + ); |
|
295 | + |
|
296 | + // Get response |
|
297 | + $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
298 | + |
|
299 | + if ( is_wp_error( $api_response ) ) { |
|
300 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
301 | + return; // Something went wrong |
|
302 | + } |
|
303 | + |
|
304 | + if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
305 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
306 | + return; // Response not okay |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + // Check if $post_data_array has been populated |
|
311 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
312 | + return; |
|
313 | + |
|
314 | + $defaults = array( |
|
315 | + 'txn_type' => '', |
|
316 | + 'payment_status' => '' |
|
317 | + ); |
|
318 | + |
|
319 | + $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
320 | + |
|
321 | + $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
322 | 322 | |
323 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
324 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
325 | - |
|
326 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
327 | - // Allow PayPal IPN types to be processed separately |
|
328 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
329 | - } else { |
|
330 | - // Fallback to web accept just in case the txn_type isn't present |
|
331 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
332 | - } |
|
333 | - exit; |
|
323 | + wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
324 | + wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
325 | + |
|
326 | + if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
327 | + // Allow PayPal IPN types to be processed separately |
|
328 | + do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
329 | + } else { |
|
330 | + // Fallback to web accept just in case the txn_type isn't present |
|
331 | + do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
332 | + } |
|
333 | + exit; |
|
334 | 334 | } |
335 | 335 | add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
336 | 336 | |
337 | 337 | function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
338 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
339 | - return; |
|
340 | - } |
|
341 | - |
|
342 | - if( empty( $invoice_id ) ) { |
|
343 | - return; |
|
344 | - } |
|
345 | - |
|
346 | - // Collect payment details |
|
347 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
348 | - $paypal_amount = $data['mc_gross']; |
|
349 | - $payment_status = strtolower( $data['payment_status'] ); |
|
350 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
351 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
352 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
353 | - |
|
354 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
355 | - return; // this isn't a PayPal standard IPN |
|
356 | - } |
|
357 | - |
|
358 | - // Verify payment recipient |
|
359 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
360 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
361 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
362 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
363 | - return; |
|
364 | - } |
|
365 | - |
|
366 | - // Verify payment currency |
|
367 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
368 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
369 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
370 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
371 | - return; |
|
372 | - } |
|
373 | - |
|
374 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
375 | - // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
376 | - // No email associated with purchase, so store from PayPal |
|
377 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
378 | - |
|
379 | - // Setup and store the customer's details |
|
380 | - $user_info = array( |
|
381 | - 'user_id' => '-1', |
|
382 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
383 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
384 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
385 | - 'discount' => '', |
|
386 | - ); |
|
387 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
388 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
389 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
390 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
391 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
392 | - |
|
393 | - $payment_meta['user_info'] = $user_info; |
|
394 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
395 | - } |
|
396 | - |
|
397 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
398 | - // Process a refund |
|
399 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
400 | - } else { |
|
401 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
402 | - return; // Only paid payments once |
|
403 | - } |
|
404 | - |
|
405 | - // Retrieve the total purchase amount (before PayPal) |
|
406 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
407 | - |
|
408 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
409 | - // The prices don't match |
|
410 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
411 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
412 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
413 | - return; |
|
414 | - } |
|
415 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
416 | - // Purchase keys don't match |
|
417 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
418 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
419 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
420 | - return; |
|
421 | - } |
|
422 | - |
|
423 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
424 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
425 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
426 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
427 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
428 | - // Look for possible pending reasons, such as an echeck |
|
429 | - $note = ''; |
|
430 | - |
|
431 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
432 | - case 'echeck' : |
|
433 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
434 | - break; |
|
338 | + if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
339 | + return; |
|
340 | + } |
|
341 | + |
|
342 | + if( empty( $invoice_id ) ) { |
|
343 | + return; |
|
344 | + } |
|
345 | + |
|
346 | + // Collect payment details |
|
347 | + $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
348 | + $paypal_amount = $data['mc_gross']; |
|
349 | + $payment_status = strtolower( $data['payment_status'] ); |
|
350 | + $currency_code = strtolower( $data['mc_currency'] ); |
|
351 | + $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
352 | + $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
353 | + |
|
354 | + if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
355 | + return; // this isn't a PayPal standard IPN |
|
356 | + } |
|
357 | + |
|
358 | + // Verify payment recipient |
|
359 | + if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
360 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
361 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
362 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
363 | + return; |
|
364 | + } |
|
365 | + |
|
366 | + // Verify payment currency |
|
367 | + if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
368 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
369 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
370 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
371 | + return; |
|
372 | + } |
|
373 | + |
|
374 | + if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
375 | + // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
376 | + // No email associated with purchase, so store from PayPal |
|
377 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
378 | + |
|
379 | + // Setup and store the customer's details |
|
380 | + $user_info = array( |
|
381 | + 'user_id' => '-1', |
|
382 | + 'email' => sanitize_text_field( $data['payer_email'] ), |
|
383 | + 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
384 | + 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
385 | + 'discount' => '', |
|
386 | + ); |
|
387 | + $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
388 | + $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
389 | + $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
390 | + $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
391 | + $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
392 | + |
|
393 | + $payment_meta['user_info'] = $user_info; |
|
394 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
395 | + } |
|
396 | + |
|
397 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
398 | + // Process a refund |
|
399 | + wpinv_process_paypal_refund( $data, $invoice_id ); |
|
400 | + } else { |
|
401 | + if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
402 | + return; // Only paid payments once |
|
403 | + } |
|
404 | + |
|
405 | + // Retrieve the total purchase amount (before PayPal) |
|
406 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
407 | + |
|
408 | + if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
409 | + // The prices don't match |
|
410 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
411 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
412 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
413 | + return; |
|
414 | + } |
|
415 | + if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
416 | + // Purchase keys don't match |
|
417 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
418 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
419 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
420 | + return; |
|
421 | + } |
|
422 | + |
|
423 | + if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
424 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
425 | + wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
426 | + wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
427 | + } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
428 | + // Look for possible pending reasons, such as an echeck |
|
429 | + $note = ''; |
|
430 | + |
|
431 | + switch( strtolower( $data['pending_reason'] ) ) { |
|
432 | + case 'echeck' : |
|
433 | + $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
434 | + break; |
|
435 | 435 | |
436 | 436 | case 'address' : |
437 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
438 | - break; |
|
437 | + $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
438 | + break; |
|
439 | 439 | |
440 | 440 | case 'intl' : |
441 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
442 | - break; |
|
441 | + $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
442 | + break; |
|
443 | 443 | |
444 | 444 | case 'multi-currency' : |
445 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
446 | - break; |
|
445 | + $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
446 | + break; |
|
447 | 447 | |
448 | 448 | case 'paymentreview' : |
449 | 449 | case 'regulatory_review' : |
450 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
451 | - break; |
|
450 | + $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
451 | + break; |
|
452 | 452 | |
453 | 453 | case 'unilateral' : |
454 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
455 | - break; |
|
454 | + $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
455 | + break; |
|
456 | 456 | |
457 | 457 | case 'upgrade' : |
458 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
459 | - break; |
|
458 | + $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
459 | + break; |
|
460 | 460 | |
461 | 461 | case 'verify' : |
462 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
463 | - break; |
|
464 | - |
|
465 | - case 'other' : |
|
466 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
467 | - break; |
|
468 | - } |
|
469 | - |
|
470 | - if ( ! empty( $note ) ) { |
|
471 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
472 | - } |
|
473 | - } else { |
|
474 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
475 | - } |
|
476 | - } |
|
462 | + $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
463 | + break; |
|
464 | + |
|
465 | + case 'other' : |
|
466 | + $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
467 | + break; |
|
468 | + } |
|
469 | + |
|
470 | + if ( ! empty( $note ) ) { |
|
471 | + wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
472 | + } |
|
473 | + } else { |
|
474 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
475 | + } |
|
476 | + } |
|
477 | 477 | } |
478 | 478 | add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
479 | 479 | |
@@ -661,34 +661,34 @@ discard block |
||
661 | 661 | } |
662 | 662 | |
663 | 663 | function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
664 | - // Collect payment details |
|
664 | + // Collect payment details |
|
665 | 665 | |
666 | - if( empty( $invoice_id ) ) { |
|
667 | - return; |
|
668 | - } |
|
666 | + if( empty( $invoice_id ) ) { |
|
667 | + return; |
|
668 | + } |
|
669 | 669 | |
670 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
671 | - return; // Only refund payments once |
|
672 | - } |
|
670 | + if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
671 | + return; // Only refund payments once |
|
672 | + } |
|
673 | 673 | |
674 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
675 | - $refund_amount = $data['mc_gross'] * -1; |
|
674 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
675 | + $refund_amount = $data['mc_gross'] * -1; |
|
676 | 676 | |
677 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
677 | + do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
678 | 678 | |
679 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
680 | - 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 ); |
|
679 | + if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
680 | + 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 ); |
|
681 | 681 | |
682 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
682 | + do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
683 | 683 | |
684 | - return; // This is a partial refund |
|
685 | - } |
|
684 | + return; // This is a partial refund |
|
685 | + } |
|
686 | 686 | |
687 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
688 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
689 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
687 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
688 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
689 | + wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
690 | 690 | |
691 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
691 | + do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | function wpinv_get_paypal_redirect( $ssl_check = false ) { |
@@ -103,29 +103,29 @@ discard block |
||
103 | 103 | |
104 | 104 | function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
105 | 105 | if ( ! empty( $args ) && is_array( $args ) ) { |
106 | - extract( $args ); |
|
107 | - } |
|
106 | + extract( $args ); |
|
107 | + } |
|
108 | 108 | |
109 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
110 | - // Allow 3rd party plugin filter template file from their plugin. |
|
111 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
109 | + $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
110 | + // Allow 3rd party plugin filter template file from their plugin. |
|
111 | + $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
112 | 112 | |
113 | - if ( ! file_exists( $located ) ) { |
|
113 | + if ( ! file_exists( $located ) ) { |
|
114 | 114 | _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
115 | - return; |
|
116 | - } |
|
115 | + return; |
|
116 | + } |
|
117 | 117 | |
118 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
118 | + do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
119 | 119 | |
120 | - include( $located ); |
|
120 | + include( $located ); |
|
121 | 121 | |
122 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
122 | + do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
126 | - ob_start(); |
|
127 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
128 | - return ob_get_clean(); |
|
126 | + ob_start(); |
|
127 | + wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
128 | + return ob_get_clean(); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
@@ -155,126 +155,126 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
158 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
158 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
159 | 159 | |
160 | - // Setup possible parts |
|
161 | - $templates = array(); |
|
162 | - if ( isset( $name ) ) |
|
163 | - $templates[] = $slug . '-' . $name . '.php'; |
|
164 | - $templates[] = $slug . '.php'; |
|
160 | + // Setup possible parts |
|
161 | + $templates = array(); |
|
162 | + if ( isset( $name ) ) |
|
163 | + $templates[] = $slug . '-' . $name . '.php'; |
|
164 | + $templates[] = $slug . '.php'; |
|
165 | 165 | |
166 | - // Allow template parts to be filtered |
|
167 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
166 | + // Allow template parts to be filtered |
|
167 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
168 | 168 | |
169 | - // Return the part that is found |
|
170 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
169 | + // Return the part that is found |
|
170 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
174 | - // No file found yet |
|
175 | - $located = false; |
|
174 | + // No file found yet |
|
175 | + $located = false; |
|
176 | 176 | |
177 | - // Try to find a template file |
|
178 | - foreach ( (array)$template_names as $template_name ) { |
|
177 | + // Try to find a template file |
|
178 | + foreach ( (array)$template_names as $template_name ) { |
|
179 | 179 | |
180 | - // Continue if template is empty |
|
181 | - if ( empty( $template_name ) ) |
|
182 | - continue; |
|
180 | + // Continue if template is empty |
|
181 | + if ( empty( $template_name ) ) |
|
182 | + continue; |
|
183 | 183 | |
184 | - // Trim off any slashes from the template name |
|
185 | - $template_name = ltrim( $template_name, '/' ); |
|
184 | + // Trim off any slashes from the template name |
|
185 | + $template_name = ltrim( $template_name, '/' ); |
|
186 | 186 | |
187 | - // try locating this template file by looping through the template paths |
|
188 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
187 | + // try locating this template file by looping through the template paths |
|
188 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
189 | 189 | |
190 | - if( file_exists( $template_path . $template_name ) ) { |
|
191 | - $located = $template_path . $template_name; |
|
192 | - break; |
|
193 | - } |
|
194 | - } |
|
190 | + if( file_exists( $template_path . $template_name ) ) { |
|
191 | + $located = $template_path . $template_name; |
|
192 | + break; |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | - if( !empty( $located ) ) { |
|
197 | - break; |
|
198 | - } |
|
199 | - } |
|
196 | + if( !empty( $located ) ) { |
|
197 | + break; |
|
198 | + } |
|
199 | + } |
|
200 | 200 | |
201 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
202 | - load_template( $located, $require_once ); |
|
201 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
202 | + load_template( $located, $require_once ); |
|
203 | 203 | |
204 | - return $located; |
|
204 | + return $located; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_get_theme_template_paths() { |
208 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
208 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
209 | 209 | |
210 | - $file_paths = array( |
|
211 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
212 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
213 | - 100 => wpinv_get_templates_dir() |
|
214 | - ); |
|
210 | + $file_paths = array( |
|
211 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
212 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
213 | + 100 => wpinv_get_templates_dir() |
|
214 | + ); |
|
215 | 215 | |
216 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
216 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
217 | 217 | |
218 | - // sort the file paths based on priority |
|
219 | - ksort( $file_paths, SORT_NUMERIC ); |
|
218 | + // sort the file paths based on priority |
|
219 | + ksort( $file_paths, SORT_NUMERIC ); |
|
220 | 220 | |
221 | - return array_map( 'trailingslashit', $file_paths ); |
|
221 | + return array_map( 'trailingslashit', $file_paths ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_theme_template_dir_name() { |
225 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
225 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | function wpinv_checkout_meta_tags() { |
229 | 229 | |
230 | - $pages = array(); |
|
231 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
232 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
233 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
234 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
230 | + $pages = array(); |
|
231 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
232 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
233 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
234 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
235 | 235 | |
236 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
237 | - return; |
|
238 | - } |
|
236 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
237 | + return; |
|
238 | + } |
|
239 | 239 | |
240 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
240 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
241 | 241 | } |
242 | 242 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
243 | 243 | |
244 | 244 | function wpinv_add_body_classes( $class ) { |
245 | - $classes = (array)$class; |
|
245 | + $classes = (array)$class; |
|
246 | 246 | |
247 | - if( wpinv_is_checkout() ) { |
|
248 | - $classes[] = 'wpinv-checkout'; |
|
249 | - $classes[] = 'wpinv-page'; |
|
250 | - } |
|
247 | + if( wpinv_is_checkout() ) { |
|
248 | + $classes[] = 'wpinv-checkout'; |
|
249 | + $classes[] = 'wpinv-page'; |
|
250 | + } |
|
251 | 251 | |
252 | - if( wpinv_is_success_page() ) { |
|
253 | - $classes[] = 'wpinv-success'; |
|
254 | - $classes[] = 'wpinv-page'; |
|
255 | - } |
|
252 | + if( wpinv_is_success_page() ) { |
|
253 | + $classes[] = 'wpinv-success'; |
|
254 | + $classes[] = 'wpinv-page'; |
|
255 | + } |
|
256 | 256 | |
257 | - if( wpinv_is_failed_transaction_page() ) { |
|
258 | - $classes[] = 'wpinv-failed-transaction'; |
|
259 | - $classes[] = 'wpinv-page'; |
|
260 | - } |
|
257 | + if( wpinv_is_failed_transaction_page() ) { |
|
258 | + $classes[] = 'wpinv-failed-transaction'; |
|
259 | + $classes[] = 'wpinv-page'; |
|
260 | + } |
|
261 | 261 | |
262 | - if( wpinv_is_invoice_history_page() ) { |
|
263 | - $classes[] = 'wpinv-history'; |
|
264 | - $classes[] = 'wpinv-page'; |
|
265 | - } |
|
262 | + if( wpinv_is_invoice_history_page() ) { |
|
263 | + $classes[] = 'wpinv-history'; |
|
264 | + $classes[] = 'wpinv-page'; |
|
265 | + } |
|
266 | 266 | |
267 | - if( wpinv_is_subscriptions_history_page() ) { |
|
268 | - $classes[] = 'wpinv-subscription'; |
|
269 | - $classes[] = 'wpinv-page'; |
|
270 | - } |
|
267 | + if( wpinv_is_subscriptions_history_page() ) { |
|
268 | + $classes[] = 'wpinv-subscription'; |
|
269 | + $classes[] = 'wpinv-page'; |
|
270 | + } |
|
271 | 271 | |
272 | - if( wpinv_is_test_mode() ) { |
|
273 | - $classes[] = 'wpinv-test-mode'; |
|
274 | - $classes[] = 'wpinv-page'; |
|
275 | - } |
|
272 | + if( wpinv_is_test_mode() ) { |
|
273 | + $classes[] = 'wpinv-test-mode'; |
|
274 | + $classes[] = 'wpinv-page'; |
|
275 | + } |
|
276 | 276 | |
277 | - return array_unique( $classes ); |
|
277 | + return array_unique( $classes ); |
|
278 | 278 | } |
279 | 279 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
280 | 280 | |
@@ -1408,7 +1408,7 @@ discard block |
||
1408 | 1408 | add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
1409 | 1409 | |
1410 | 1410 | function wpinv_empty_cart_message() { |
1411 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1411 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | 1414 | /** |
@@ -1418,7 +1418,7 @@ discard block |
||
1418 | 1418 | * @return void |
1419 | 1419 | */ |
1420 | 1420 | function wpinv_empty_checkout_cart() { |
1421 | - echo wpinv_empty_cart_message(); |
|
1421 | + echo wpinv_empty_cart_message(); |
|
1422 | 1422 | } |
1423 | 1423 | add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
1424 | 1424 |