@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | /** |
9 | 9 | * Main Subscriptions class. |
10 | 10 | * |
@@ -17,28 +17,28 @@ discard block |
||
17 | 17 | public function __construct() { |
18 | 18 | |
19 | 19 | // Fire gateway specific hooks when a subscription changes. |
20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
21 | 21 | |
22 | 22 | // De-activate a subscription whenever the invoice changes payment statuses. |
23 | - add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
24 | - add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
25 | - add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
26 | - add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
23 | + add_action('getpaid_invoice_status_wpi-refunded', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
24 | + add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
25 | + add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
26 | + add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
27 | 27 | |
28 | 28 | // Handles subscription cancelations. |
29 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
29 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
30 | 30 | |
31 | 31 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
32 | - add_action( 'wpinv_invoice_metabox_saved', array( $this, 'maybe_update_invoice_subscription' ), 5 ); |
|
33 | - add_action( 'getpaid_checkout_invoice_updated', array( $this, 'maybe_update_invoice_subscription' ), 5 ); |
|
32 | + add_action('wpinv_invoice_metabox_saved', array($this, 'maybe_update_invoice_subscription'), 5); |
|
33 | + add_action('getpaid_checkout_invoice_updated', array($this, 'maybe_update_invoice_subscription'), 5); |
|
34 | 34 | |
35 | 35 | // Handles admin subscription update actions. |
36 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
37 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
38 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
36 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
37 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
38 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
39 | 39 | |
40 | 40 | // Filter invoice item row actions. |
41 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
41 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | * @param WPInv_Invoice $invoice |
48 | 48 | * @return WPInv_Subscription|bool |
49 | 49 | */ |
50 | - public function get_invoice_subscription( $invoice ) { |
|
50 | + public function get_invoice_subscription($invoice) { |
|
51 | 51 | $subscription_id = $invoice->get_subscription_id(); |
52 | 52 | |
53 | 53 | // Fallback to the parent invoice if the child invoice has no subscription id. |
54 | - if ( empty( $subscription_id ) && $invoice->is_renewal() ) { |
|
54 | + if (empty($subscription_id) && $invoice->is_renewal()) { |
|
55 | 55 | $subscription_id = $invoice->get_parent_payment()->get_subscription_id(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Fetch the subscription. |
59 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
59 | + $subscription = new WPInv_Subscription($subscription_id); |
|
60 | 60 | |
61 | 61 | // Return subscription or use a fallback for backwards compatibility. |
62 | - return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription( $invoice ); |
|
62 | + return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription($invoice); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Invoice $invoice |
69 | 69 | */ |
70 | - public function maybe_deactivate_invoice_subscription( $invoice ) { |
|
70 | + public function maybe_deactivate_invoice_subscription($invoice) { |
|
71 | 71 | |
72 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
72 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
73 | 73 | |
74 | - if ( empty( $subscriptions ) ) { |
|
74 | + if (empty($subscriptions)) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | - if ( ! is_array( $subscriptions ) ) { |
|
79 | - $subscriptions = array( $subscriptions ); |
|
78 | + if (!is_array($subscriptions)) { |
|
79 | + $subscriptions = array($subscriptions); |
|
80 | 80 | } |
81 | 81 | |
82 | - foreach ( $subscriptions as $subscription ) { |
|
83 | - if ( $subscription->is_active() ) { |
|
84 | - $subscription->set_status( 'pending' ); |
|
82 | + foreach ($subscriptions as $subscription) { |
|
83 | + if ($subscription->is_active()) { |
|
84 | + $subscription->set_status('pending'); |
|
85 | 85 | $subscription->save(); |
86 | 86 | } |
87 | 87 | } |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | * @param string $from |
96 | 96 | * @param string $to |
97 | 97 | */ |
98 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
98 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
99 | 99 | |
100 | 100 | $gateway = $subscription->get_gateway(); |
101 | 101 | |
102 | - if ( ! empty( $gateway ) ) { |
|
103 | - $gateway = sanitize_key( $gateway ); |
|
104 | - $from = sanitize_key( $from ); |
|
105 | - $to = sanitize_key( $to ); |
|
106 | - do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from ); |
|
102 | + if (!empty($gateway)) { |
|
103 | + $gateway = sanitize_key($gateway); |
|
104 | + $from = sanitize_key($from); |
|
105 | + $to = sanitize_key($to); |
|
106 | + do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | } |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @deprecated |
117 | 117 | * @return mixed|string|void |
118 | 118 | */ |
119 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
120 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
119 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
120 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,21 +127,21 @@ discard block |
||
127 | 127 | * @since 1.0.0 |
128 | 128 | * @return void |
129 | 129 | */ |
130 | - public function user_cancel_single_subscription( $data ) { |
|
130 | + public function user_cancel_single_subscription($data) { |
|
131 | 131 | |
132 | 132 | // Ensure there is a subscription to cancel. |
133 | - if ( empty( $data['subscription'] ) ) { |
|
133 | + if (empty($data['subscription'])) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
137 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
138 | 138 | |
139 | 139 | // Ensure that it exists and that it belongs to the current user. |
140 | - if ( ! $subscription->exists() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
140 | + if (!$subscription->exists() || $subscription->get_customer_id() != get_current_user_id()) { |
|
141 | 141 | $notice = 'perm_cancel_subscription'; |
142 | 142 | |
143 | 143 | // Can it be cancelled. |
144 | - } elseif ( ! $subscription->can_cancel() ) { |
|
144 | + } elseif (!$subscription->can_cancel()) { |
|
145 | 145 | $notice = 'cannot_cancel_subscription'; |
146 | 146 | |
147 | 147 | // Cancel it. |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | 'wpinv-notice' => $notice, |
158 | 158 | ); |
159 | 159 | |
160 | - wp_safe_redirect( add_query_arg( $redirect ) ); |
|
160 | + wp_safe_redirect(add_query_arg($redirect)); |
|
161 | 161 | exit; |
162 | 162 | |
163 | 163 | } |
@@ -169,41 +169,41 @@ discard block |
||
169 | 169 | * @param WPInv_Invoice $invoice |
170 | 170 | * @since 1.0.0 |
171 | 171 | */ |
172 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
172 | + public function maybe_create_invoice_subscription($invoice) { |
|
173 | 173 | global $getpaid_subscriptions_skip_invoice_update; |
174 | 174 | |
175 | 175 | // Abort if it is not recurring. |
176 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
176 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Either group the subscriptions or only process a single suscription. |
181 | - if ( getpaid_should_group_subscriptions( $invoice ) ) { |
|
181 | + if (getpaid_should_group_subscriptions($invoice)) { |
|
182 | 182 | |
183 | 183 | $subscription_groups = array(); |
184 | 184 | $is_first = true; |
185 | 185 | |
186 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
187 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, 0, $is_first ); |
|
186 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
187 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, 0, $is_first); |
|
188 | 188 | |
189 | - if ( $is_first ) { |
|
189 | + if ($is_first) { |
|
190 | 190 | $getpaid_subscriptions_skip_invoice_update = true; |
191 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
191 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
192 | 192 | $invoice->save(); |
193 | 193 | $getpaid_subscriptions_skip_invoice_update = false; |
194 | 194 | } |
195 | 195 | |
196 | - $is_first = false; |
|
196 | + $is_first = false; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | // Cache subscription groups. |
200 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
200 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
201 | 201 | return true; |
202 | 202 | |
203 | 203 | } |
204 | 204 | |
205 | 205 | $subscription = new WPInv_Subscription(); |
206 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
206 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 | |
@@ -218,46 +218,46 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @since 2.3.0 |
220 | 220 | */ |
221 | - public function create_invoice_subscription_group( $totals, $invoice, $subscription_id = 0, $is_first = false ) { |
|
221 | + public function create_invoice_subscription_group($totals, $invoice, $subscription_id = 0, $is_first = false) { |
|
222 | 222 | |
223 | - $subscription = new WPInv_Subscription( (int) $subscription_id ); |
|
223 | + $subscription = new WPInv_Subscription((int) $subscription_id); |
|
224 | 224 | $initial_amt = $totals['initial_total']; |
225 | 225 | $recurring_amt = $totals['recurring_total']; |
226 | 226 | $fees = array(); |
227 | 227 | |
228 | 228 | // Maybe add recurring fees. |
229 | - if ( $is_first ) { |
|
229 | + if ($is_first) { |
|
230 | 230 | |
231 | - foreach ( $invoice->get_fees() as $i => $fee ) { |
|
232 | - if ( ! empty( $fee['recurring_fee'] ) ) { |
|
233 | - $initial_amt += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
234 | - $recurring_amt += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
235 | - $fees[ $i ] = $fee; |
|
231 | + foreach ($invoice->get_fees() as $i => $fee) { |
|
232 | + if (!empty($fee['recurring_fee'])) { |
|
233 | + $initial_amt += wpinv_sanitize_amount($fee['initial_fee']); |
|
234 | + $recurring_amt += wpinv_sanitize_amount($fee['recurring_fee']); |
|
235 | + $fees[$i] = $fee; |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
241 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
242 | - $subscription->set_initial_amount( $initial_amt ); |
|
243 | - $subscription->set_recurring_amount( $recurring_amt ); |
|
244 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
245 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
246 | - $subscription->set_product_id( $totals['item_id'] ); |
|
247 | - $subscription->set_period( $totals['period'] ); |
|
248 | - $subscription->set_frequency( $totals['interval'] ); |
|
249 | - $subscription->set_bill_times( $totals['recurring_limit'] ); |
|
250 | - $subscription->set_next_renewal_date( $totals['renews_on'] ); |
|
240 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
241 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
242 | + $subscription->set_initial_amount($initial_amt); |
|
243 | + $subscription->set_recurring_amount($recurring_amt); |
|
244 | + $subscription->set_date_created(current_time('mysql')); |
|
245 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
246 | + $subscription->set_product_id($totals['item_id']); |
|
247 | + $subscription->set_period($totals['period']); |
|
248 | + $subscription->set_frequency($totals['interval']); |
|
249 | + $subscription->set_bill_times($totals['recurring_limit']); |
|
250 | + $subscription->set_next_renewal_date($totals['renews_on']); |
|
251 | 251 | |
252 | 252 | // Trial periods. |
253 | - if ( ! empty( $totals['trialling'] ) ) { |
|
254 | - $subscription->set_trial_period( $totals['trialling'] ); |
|
255 | - $subscription->set_status( 'trialling' ); |
|
253 | + if (!empty($totals['trialling'])) { |
|
254 | + $subscription->set_trial_period($totals['trialling']); |
|
255 | + $subscription->set_status('trialling'); |
|
256 | 256 | |
257 | 257 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
258 | - } elseif ( empty( $initial_amt ) ) { |
|
259 | - $subscription->set_trial_period( $totals['interval'] . ' ' . $totals['period'] ); |
|
260 | - $subscription->set_status( 'trialling' ); |
|
258 | + } elseif (empty($initial_amt)) { |
|
259 | + $subscription->set_trial_period($totals['interval'] . ' ' . $totals['period']); |
|
260 | + $subscription->set_status('trialling'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | $subscription->save(); |
@@ -275,86 +275,86 @@ discard block |
||
275 | 275 | * @param WPInv_Invoice $invoice |
276 | 276 | * @since 1.0.19 |
277 | 277 | */ |
278 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
278 | + public function maybe_update_invoice_subscription($invoice) { |
|
279 | 279 | global $getpaid_subscriptions_skip_invoice_update; |
280 | 280 | |
281 | 281 | // Avoid infinite loops. |
282 | - if ( ! empty( $getpaid_subscriptions_skip_invoice_update ) ) { |
|
282 | + if (!empty($getpaid_subscriptions_skip_invoice_update)) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | |
286 | 286 | // Do not process renewals. |
287 | - if ( $invoice->is_renewal() ) { |
|
287 | + if ($invoice->is_renewal()) { |
|
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
291 | 291 | // Delete existing subscriptions if available and the invoice is not recurring. |
292 | - if ( ! $invoice->is_recurring() ) { |
|
293 | - $this->delete_invoice_subscriptions( $invoice ); |
|
292 | + if (!$invoice->is_recurring()) { |
|
293 | + $this->delete_invoice_subscriptions($invoice); |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Fetch existing subscriptions. |
298 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
298 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
299 | 299 | |
300 | 300 | // Create new ones if no existing subscriptions. |
301 | - if ( empty( $subscriptions ) ) { |
|
302 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
301 | + if (empty($subscriptions)) { |
|
302 | + return $this->maybe_create_invoice_subscription($invoice); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Abort if an invoice is paid and already has a subscription. |
306 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
306 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | - $is_grouped = is_array( $subscriptions ); |
|
311 | - $should_group = getpaid_should_group_subscriptions( $invoice ); |
|
310 | + $is_grouped = is_array($subscriptions); |
|
311 | + $should_group = getpaid_should_group_subscriptions($invoice); |
|
312 | 312 | |
313 | 313 | // Ensure that the subscriptions are only grouped if there are more than 1 recurring items. |
314 | - if ( $is_grouped != $should_group ) { |
|
315 | - $this->delete_invoice_subscriptions( $invoice ); |
|
316 | - delete_post_meta( $invoice->get_id(), 'getpaid_subscription_groups' ); |
|
317 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
314 | + if ($is_grouped != $should_group) { |
|
315 | + $this->delete_invoice_subscriptions($invoice); |
|
316 | + delete_post_meta($invoice->get_id(), 'getpaid_subscription_groups'); |
|
317 | + return $this->maybe_create_invoice_subscription($invoice); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | // If there is only one recurring item... |
321 | - if ( ! $is_grouped ) { |
|
322 | - return $this->update_invoice_subscription( $subscriptions, $invoice ); |
|
321 | + if (!$is_grouped) { |
|
322 | + return $this->update_invoice_subscription($subscriptions, $invoice); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | // Process subscription groups. |
326 | - $current_groups = getpaid_get_invoice_subscription_groups( $invoice->get_id() ); |
|
326 | + $current_groups = getpaid_get_invoice_subscription_groups($invoice->get_id()); |
|
327 | 327 | $subscription_groups = array(); |
328 | 328 | $is_first = true; |
329 | 329 | |
330 | 330 | // Create new subscription groups. |
331 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
332 | - $subscription_id = isset( $current_groups[ $group_key ] ) ? $current_groups[ $group_key ]['subscription_id'] : 0; |
|
333 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, $subscription_id, $is_first ); |
|
331 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
332 | + $subscription_id = isset($current_groups[$group_key]) ? $current_groups[$group_key]['subscription_id'] : 0; |
|
333 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, $subscription_id, $is_first); |
|
334 | 334 | |
335 | - if ( $is_first && $invoice->get_subscription_id() !== $subscription_groups[ $group_key ]['subscription_id'] ) { |
|
335 | + if ($is_first && $invoice->get_subscription_id() !== $subscription_groups[$group_key]['subscription_id']) { |
|
336 | 336 | $getpaid_subscriptions_skip_invoice_update = true; |
337 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
337 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
338 | 338 | $invoice->save(); |
339 | 339 | $getpaid_subscriptions_skip_invoice_update = false; |
340 | 340 | } |
341 | 341 | |
342 | - $is_first = false; |
|
342 | + $is_first = false; |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | // Delete non-existent subscription groups. |
346 | - foreach ( $current_groups as $group_key => $data ) { |
|
347 | - if ( ! isset( $subscription_groups[ $group_key ] ) ) { |
|
348 | - $subscription = new WPInv_Subscription( (int) $data['subscription_id'] ); |
|
346 | + foreach ($current_groups as $group_key => $data) { |
|
347 | + if (!isset($subscription_groups[$group_key])) { |
|
348 | + $subscription = new WPInv_Subscription((int) $data['subscription_id']); |
|
349 | 349 | |
350 | - if ( $subscription->exists() ) { |
|
351 | - $subscription->delete( true ); |
|
350 | + if ($subscription->exists()) { |
|
351 | + $subscription->delete(true); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Cache subscription groups. |
357 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
357 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
358 | 358 | return true; |
359 | 359 | |
360 | 360 | } |
@@ -364,20 +364,20 @@ discard block |
||
364 | 364 | * |
365 | 365 | * @param WPInv_Invoice $invoice |
366 | 366 | */ |
367 | - public function delete_invoice_subscriptions( $invoice ) { |
|
367 | + public function delete_invoice_subscriptions($invoice) { |
|
368 | 368 | |
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
370 | 370 | |
371 | - if ( empty( $subscriptions ) ) { |
|
371 | + if (empty($subscriptions)) { |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | |
375 | - if ( ! is_array( $subscriptions ) ) { |
|
376 | - $subscriptions = array( $subscriptions ); |
|
375 | + if (!is_array($subscriptions)) { |
|
376 | + $subscriptions = array($subscriptions); |
|
377 | 377 | } |
378 | 378 | |
379 | - foreach ( $subscriptions as $subscription ) { |
|
380 | - $subscription->delete( true ); |
|
379 | + foreach ($subscriptions as $subscription) { |
|
380 | + $subscription->delete(true); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | } |
@@ -390,57 +390,57 @@ discard block |
||
390 | 390 | * @param WPInv_Invoice $invoice |
391 | 391 | * @since 1.0.19 |
392 | 392 | */ |
393 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
393 | + public function update_invoice_subscription($subscription, $invoice) { |
|
394 | 394 | |
395 | 395 | // Delete the subscription if an invoice is free or nolonger recurring. |
396 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
396 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) { |
|
397 | 397 | return $subscription->delete(); |
398 | 398 | } |
399 | 399 | |
400 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
401 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
402 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
403 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
404 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
405 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
400 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
401 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
402 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
403 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
404 | + $subscription->set_date_created(current_time('mysql')); |
|
405 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
406 | 406 | |
407 | 407 | // Get the recurring item and abort if it does not exist. |
408 | - $subscription_item = $invoice->get_recurring( true ); |
|
409 | - if ( ! $subscription_item->get_id() ) { |
|
410 | - $invoice->set_subscription_id( 0 ); |
|
408 | + $subscription_item = $invoice->get_recurring(true); |
|
409 | + if (!$subscription_item->get_id()) { |
|
410 | + $invoice->set_subscription_id(0); |
|
411 | 411 | $invoice->save(); |
412 | 412 | return $subscription->delete(); |
413 | 413 | } |
414 | 414 | |
415 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
416 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
417 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
418 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
415 | + $subscription->set_product_id($subscription_item->get_id()); |
|
416 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
417 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
418 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
419 | 419 | |
420 | 420 | // Calculate the next renewal date. |
421 | - $period = $subscription_item->get_recurring_period( true ); |
|
421 | + $period = $subscription_item->get_recurring_period(true); |
|
422 | 422 | $interval = $subscription_item->get_recurring_interval(); |
423 | 423 | |
424 | 424 | // If the subscription item has a trial period... |
425 | - if ( $subscription_item->has_free_trial() ) { |
|
426 | - $period = $subscription_item->get_trial_period( true ); |
|
425 | + if ($subscription_item->has_free_trial()) { |
|
426 | + $period = $subscription_item->get_trial_period(true); |
|
427 | 427 | $interval = $subscription_item->get_trial_interval(); |
428 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
429 | - $subscription->set_status( 'trialling' ); |
|
428 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
429 | + $subscription->set_status('trialling'); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
433 | - if ( $invoice->has_free_trial() ) { |
|
434 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
435 | - $subscription->set_status( 'trialling' ); |
|
433 | + if ($invoice->has_free_trial()) { |
|
434 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
435 | + $subscription->set_status('trialling'); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | // Calculate the next renewal date. |
439 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
439 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
440 | 440 | |
441 | - $subscription->set_next_renewal_date( $expiration ); |
|
441 | + $subscription->set_next_renewal_date($expiration); |
|
442 | 442 | $subscription->save(); |
443 | - $invoice->set_subscription_id( $subscription->get_id() ); |
|
443 | + $invoice->set_subscription_id($subscription->get_id()); |
|
444 | 444 | return $subscription->get_id(); |
445 | 445 | |
446 | 446 | } |
@@ -451,27 +451,27 @@ discard block |
||
451 | 451 | * @param array $data |
452 | 452 | * @since 1.0.19 |
453 | 453 | */ |
454 | - public function admin_update_single_subscription( $args ) { |
|
454 | + public function admin_update_single_subscription($args) { |
|
455 | 455 | |
456 | 456 | // Ensure the subscription exists and that a status has been given. |
457 | - if ( empty( $args['subscription_id'] ) ) { |
|
457 | + if (empty($args['subscription_id'])) { |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // Retrieve the subscriptions. |
462 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
462 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
463 | 463 | |
464 | - if ( $subscription->get_id() ) { |
|
464 | + if ($subscription->get_id()) { |
|
465 | 465 | |
466 | 466 | $subscription->set_props( |
467 | 467 | array( |
468 | - 'status' => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null, |
|
469 | - 'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null, |
|
468 | + 'status' => isset($args['subscription_status']) ? $args['subscription_status'] : null, |
|
469 | + 'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null, |
|
470 | 470 | ) |
471 | 471 | ); |
472 | 472 | |
473 | 473 | $subscription->save(); |
474 | - getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) ); |
|
474 | + getpaid_admin()->show_info(__('Subscription updated', 'invoicing')); |
|
475 | 475 | |
476 | 476 | } |
477 | 477 | |
@@ -483,27 +483,27 @@ discard block |
||
483 | 483 | * @param array $data |
484 | 484 | * @since 1.0.19 |
485 | 485 | */ |
486 | - public function admin_renew_single_subscription( $args ) { |
|
486 | + public function admin_renew_single_subscription($args) { |
|
487 | 487 | |
488 | 488 | // Ensure the subscription exists and that a status has been given. |
489 | - if ( empty( $args['id'] ) ) { |
|
489 | + if (empty($args['id'])) { |
|
490 | 490 | return; |
491 | 491 | } |
492 | 492 | |
493 | 493 | // Retrieve the subscriptions. |
494 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
494 | + $subscription = new WPInv_Subscription($args['id']); |
|
495 | 495 | |
496 | - if ( $subscription->get_id() ) { |
|
496 | + if ($subscription->get_id()) { |
|
497 | 497 | |
498 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
498 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
499 | 499 | |
500 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
500 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
501 | 501 | |
502 | - if ( ! $subscription->add_payment( $args ) ) { |
|
503 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
502 | + if (!$subscription->add_payment($args)) { |
|
503 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
504 | 504 | } else { |
505 | 505 | $subscription->renew(); |
506 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
506 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | wp_safe_redirect( |
@@ -526,20 +526,20 @@ discard block |
||
526 | 526 | * @param array $data |
527 | 527 | * @since 1.0.19 |
528 | 528 | */ |
529 | - public function admin_delete_single_subscription( $args ) { |
|
529 | + public function admin_delete_single_subscription($args) { |
|
530 | 530 | |
531 | 531 | // Ensure the subscription exists and that a status has been given. |
532 | - if ( empty( $args['id'] ) ) { |
|
532 | + if (empty($args['id'])) { |
|
533 | 533 | return; |
534 | 534 | } |
535 | 535 | |
536 | 536 | // Retrieve the subscriptions. |
537 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
537 | + $subscription = new WPInv_Subscription($args['id']); |
|
538 | 538 | |
539 | - if ( $subscription->delete() ) { |
|
540 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
539 | + if ($subscription->delete()) { |
|
540 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
541 | 541 | } else { |
542 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
542 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | $redirected = wp_safe_redirect( |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | ) |
553 | 553 | ); |
554 | 554 | |
555 | - if ( $redirected ) { |
|
555 | + if ($redirected) { |
|
556 | 556 | exit; |
557 | 557 | } |
558 | 558 | |
@@ -565,16 +565,16 @@ discard block |
||
565 | 565 | * @param WPInv_Item $item |
566 | 566 | * @param WPInv_Invoice $invoice |
567 | 567 | */ |
568 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
568 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
569 | 569 | |
570 | 570 | // Abort if this invoice uses subscription groups. |
571 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
572 | - if ( ! $invoice->is_recurring() || ! is_object( $subscriptions ) ) { |
|
571 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
572 | + if (!$invoice->is_recurring() || !is_object($subscriptions)) { |
|
573 | 573 | return $actions; |
574 | 574 | } |
575 | 575 | |
576 | 576 | // Fetch item subscription. |
577 | - $args = array( |
|
577 | + $args = array( |
|
578 | 578 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
579 | 579 | 'product_in' => $item->get_id(), |
580 | 580 | 'number' => 1, |
@@ -582,13 +582,13 @@ discard block |
||
582 | 582 | 'fields' => 'id', |
583 | 583 | ); |
584 | 584 | |
585 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
585 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
586 | 586 | $subscription = $subscription->get_results(); |
587 | 587 | |
588 | 588 | // In case we found a match... |
589 | - if ( ! empty( $subscription ) ) { |
|
590 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
591 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
589 | + if (!empty($subscription)) { |
|
590 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
591 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | return $actions; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns the errors as html |
@@ -15,35 +15,35 @@ discard block |
||
15 | 15 | * @param bool $wrap whether or not to wrap the errors. |
16 | 16 | * @since 1.0.19 |
17 | 17 | */ |
18 | -function getpaid_get_errors_html( $clear = true, $wrap = true ) { |
|
18 | +function getpaid_get_errors_html($clear = true, $wrap = true) { |
|
19 | 19 | |
20 | 20 | $errors = ''; |
21 | - foreach ( wpinv_get_errors() as $id => $error ) { |
|
22 | - $type = 'error'; |
|
21 | + foreach (wpinv_get_errors() as $id => $error) { |
|
22 | + $type = 'error'; |
|
23 | 23 | |
24 | - if ( is_array( $error ) ) { |
|
24 | + if (is_array($error)) { |
|
25 | 25 | $type = $error['type']; |
26 | 26 | $error = $error['text']; |
27 | 27 | } |
28 | 28 | |
29 | - if ( $wrap ) { |
|
29 | + if ($wrap) { |
|
30 | 30 | |
31 | 31 | $errors .= aui()->alert( |
32 | 32 | array( |
33 | - 'content' => wp_kses_post( $error ), |
|
33 | + 'content' => wp_kses_post($error), |
|
34 | 34 | 'type' => $type, |
35 | 35 | ) |
36 | 36 | ); |
37 | 37 | |
38 | 38 | } else { |
39 | 39 | |
40 | - $id = esc_attr( $id ); |
|
41 | - $error = wp_kses_post( $error ); |
|
40 | + $id = esc_attr($id); |
|
41 | + $error = wp_kses_post($error); |
|
42 | 42 | $errors .= "<div data-code='$id'>$error</div>"; |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | - if ( $clear ) { |
|
46 | + if ($clear) { |
|
47 | 47 | wpinv_clear_errors(); |
48 | 48 | } |
49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * Prints (then clears) all available errors. |
56 | 56 | */ |
57 | 57 | function wpinv_print_errors() { |
58 | - echo wp_kses_post( getpaid_get_errors_html() ); |
|
58 | + echo wp_kses_post(getpaid_get_errors_html()); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -69,54 +69,54 @@ discard block |
||
69 | 69 | $all_errors = array( |
70 | 70 | 'perm_cancel_subscription' => array( |
71 | 71 | 'type' => 'error', |
72 | - 'text' => __( 'You do not have permission to cancel this subscription', 'invoicing' ), |
|
72 | + 'text' => __('You do not have permission to cancel this subscription', 'invoicing'), |
|
73 | 73 | ), |
74 | 74 | 'cannot_cancel_subscription' => array( |
75 | 75 | 'type' => 'error', |
76 | - 'text' => __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ), |
|
76 | + 'text' => __('This subscription cannot be cancelled as it is not active.', 'invoicing'), |
|
77 | 77 | ), |
78 | 78 | 'cancelled_subscription' => array( |
79 | 79 | 'type' => 'success', |
80 | - 'text' => __( 'Subscription cancelled successfully.', 'invoicing' ), |
|
80 | + 'text' => __('Subscription cancelled successfully.', 'invoicing'), |
|
81 | 81 | ), |
82 | 82 | 'address_updated' => array( |
83 | 83 | 'type' => 'success', |
84 | - 'text' => __( 'Address updated successfully.', 'invoicing' ), |
|
84 | + 'text' => __('Address updated successfully.', 'invoicing'), |
|
85 | 85 | ), |
86 | 86 | 'perm_delete_invoice' => array( |
87 | 87 | 'type' => 'error', |
88 | - 'text' => __( 'You do not have permission to delete this invoice', 'invoicing' ), |
|
88 | + 'text' => __('You do not have permission to delete this invoice', 'invoicing'), |
|
89 | 89 | ), |
90 | 90 | 'cannot_delete_invoice' => array( |
91 | 91 | 'type' => 'error', |
92 | - 'text' => __( 'This invoice cannot be deleted as it has already been paid.', 'invoicing' ), |
|
92 | + 'text' => __('This invoice cannot be deleted as it has already been paid.', 'invoicing'), |
|
93 | 93 | ), |
94 | 94 | 'deleted_invoice' => array( |
95 | 95 | 'type' => 'success', |
96 | - 'text' => __( 'Invoice deleted successfully.', 'invoicing' ), |
|
96 | + 'text' => __('Invoice deleted successfully.', 'invoicing'), |
|
97 | 97 | ), |
98 | 98 | 'card_declined' => array( |
99 | 99 | 'type' => 'error', |
100 | - 'text' => __( 'Your card was declined.', 'invoicing' ), |
|
100 | + 'text' => __('Your card was declined.', 'invoicing'), |
|
101 | 101 | ), |
102 | 102 | 'invalid_currency' => array( |
103 | 103 | 'type' => 'error', |
104 | - 'text' => __( 'The chosen payment gateway does not support this currency.', 'invoicing' ), |
|
104 | + 'text' => __('The chosen payment gateway does not support this currency.', 'invoicing'), |
|
105 | 105 | ), |
106 | 106 | ); |
107 | 107 | |
108 | - $errors = apply_filters( 'wpinv_errors', array() ); |
|
108 | + $errors = apply_filters('wpinv_errors', array()); |
|
109 | 109 | |
110 | - if ( isset( $_GET['wpinv-notice'] ) && isset( $all_errors[ $_GET['wpinv-notice'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
111 | - $errors[ $_GET['wpinv-notice'] ] = $all_errors[ $_GET['wpinv-notice'] ]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
110 | + if (isset($_GET['wpinv-notice']) && isset($all_errors[$_GET['wpinv-notice']])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
111 | + $errors[$_GET['wpinv-notice']] = $all_errors[$_GET['wpinv-notice']]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
112 | 112 | } |
113 | 113 | |
114 | - if ( isset( $GLOBALS['wpinv_notice'] ) && isset( $all_errors[ $GLOBALS['wpinv_notice'] ] ) ) { |
|
115 | - $errors[ $GLOBALS['wpinv_notice'] ] = $all_errors[ $GLOBALS['wpinv_notice'] ]; |
|
114 | + if (isset($GLOBALS['wpinv_notice']) && isset($all_errors[$GLOBALS['wpinv_notice']])) { |
|
115 | + $errors[$GLOBALS['wpinv_notice']] = $all_errors[$GLOBALS['wpinv_notice']]; |
|
116 | 116 | } |
117 | 117 | |
118 | - if ( isset( $GLOBALS['wpinv_custom_notice'] ) ) { |
|
119 | - $errors[ $GLOBALS['wpinv_notice']['code'] ] = $GLOBALS['wpinv_custom_notice']; |
|
118 | + if (isset($GLOBALS['wpinv_custom_notice'])) { |
|
119 | + $errors[$GLOBALS['wpinv_notice']['code']] = $GLOBALS['wpinv_custom_notice']; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | return $errors; |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | * @param string $error The error message. |
130 | 130 | * @param string $type The error type. |
131 | 131 | */ |
132 | -function wpinv_set_error( $error_id, $message = '', $type = 'error' ) { |
|
132 | +function wpinv_set_error($error_id, $message = '', $type = 'error') { |
|
133 | 133 | |
134 | - if ( ! empty( $message ) ) { |
|
134 | + if (!empty($message)) { |
|
135 | 135 | $GLOBALS['wpinv_custom_notice'] = array( |
136 | 136 | 'code' => $error_id, |
137 | 137 | 'type' => $type, |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * |
148 | 148 | */ |
149 | 149 | function wpinv_has_errors() { |
150 | - return count( wpinv_get_errors() ) > 0; |
|
150 | + return count(wpinv_get_errors()) > 0; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | */ |
157 | 157 | function wpinv_clear_errors() { |
158 | - unset( $GLOBALS['wpinv_notice'] ); |
|
158 | + unset($GLOBALS['wpinv_notice']); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | */ |
165 | 165 | function wpinv_unset_error() { |
166 | - unset( $GLOBALS['wpinv_notice'] ); |
|
166 | + unset($GLOBALS['wpinv_notice']); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | * @param string $message Message to log. |
175 | 175 | * @param string $version Version the message was added in. |
176 | 176 | */ |
177 | -function getpaid_doing_it_wrong( $function, $message, $version ) { |
|
177 | +function getpaid_doing_it_wrong($function, $message, $version) { |
|
178 | 178 | |
179 | 179 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
180 | 180 | |
181 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
182 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
183 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
181 | + if (wp_doing_ajax() || defined('REST_REQUEST')) { |
|
182 | + do_action('doing_it_wrong_run', $function, $message, $version); |
|
183 | + error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}."); |
|
184 | 184 | } else { |
185 | - _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); |
|
185 | + _doing_it_wrong(esc_html($function), wp_kses_post($message), esc_html($version)); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |
@@ -196,41 +196,41 @@ discard block |
||
196 | 196 | * @param string $line The line that contains the error. |
197 | 197 | * @param bool $exit Whether or not to exit function execution. |
198 | 198 | */ |
199 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
199 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
200 | 200 | |
201 | - if ( true === apply_filters( 'wpinv_log_errors', true ) ) { |
|
201 | + if (true === apply_filters('wpinv_log_errors', true)) { |
|
202 | 202 | |
203 | 203 | // Ensure the log is a scalar. |
204 | - if ( ! is_scalar( $log ) ) { |
|
205 | - $log = print_r( $log, true ); |
|
204 | + if (!is_scalar($log)) { |
|
205 | + $log = print_r($log, true); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // Add title. |
209 | - if ( ! empty( $title ) ) { |
|
210 | - $log = $title . ' ' . trim( $log ); |
|
209 | + if (!empty($title)) { |
|
210 | + $log = $title . ' ' . trim($log); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | // Add the file to the label. |
214 | - if ( ! empty( $file ) ) { |
|
214 | + if (!empty($file)) { |
|
215 | 215 | $log .= ' in ' . $file; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Add the line number to the label. |
219 | - if ( ! empty( $line ) ) { |
|
219 | + if (!empty($line)) { |
|
220 | 220 | $log .= ' on line ' . $line; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Log the message. |
224 | - error_log( trim( $log ) ); |
|
224 | + error_log(trim($log)); |
|
225 | 225 | |
226 | 226 | // ... and a backtrace. |
227 | - if ( false !== $title && false !== $file ) { |
|
228 | - error_log( 'Backtrace ' . wp_debug_backtrace_summary() ); |
|
227 | + if (false !== $title && false !== $file) { |
|
228 | + error_log('Backtrace ' . wp_debug_backtrace_summary()); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | // Maybe exit. |
233 | - if ( $exit ) { |
|
233 | + if ($exit) { |
|
234 | 234 | exit; |
235 | 235 | } |
236 | 236 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package GetPaid |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Generates a users select dropdown. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * @param array $args |
17 | 17 | * @see wp_dropdown_users |
18 | 18 | */ |
19 | -function wpinv_dropdown_users( $args = '' ) { |
|
19 | +function wpinv_dropdown_users($args = '') { |
|
20 | 20 | |
21 | - if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) { |
|
21 | + if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) { |
|
22 | 22 | $args['show'] = 'display_name_with_login'; |
23 | 23 | } |
24 | 24 | |
25 | - return wp_dropdown_users( $args ); |
|
25 | + return wp_dropdown_users($args); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * @return string capability to check against |
33 | 33 | * @param string $capalibilty Optional. The alternative capability to check against. |
34 | 34 | */ |
35 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
35 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
36 | 36 | |
37 | - if ( current_user_can( 'manage_options' ) ) { |
|
37 | + if (current_user_can('manage_options')) { |
|
38 | 38 | return 'manage_options'; |
39 | 39 | }; |
40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return bool |
49 | 49 | */ |
50 | 50 | function wpinv_current_user_can_manage_invoicing() { |
51 | - return current_user_can( wpinv_get_capability() ); |
|
51 | + return current_user_can(wpinv_get_capability()); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,19 +57,19 @@ discard block |
||
57 | 57 | * @since 1.0.19 |
58 | 58 | * @return int|WP_Error |
59 | 59 | */ |
60 | -function wpinv_create_user( $email, $prefix = '' ) { |
|
60 | +function wpinv_create_user($email, $prefix = '') { |
|
61 | 61 | |
62 | 62 | // Prepare user values. |
63 | - $prefix = preg_replace( '/\s+/', '', $prefix ); |
|
64 | - $prefix = empty( $prefix ) ? $email : $prefix; |
|
65 | - $args = array( |
|
66 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
63 | + $prefix = preg_replace('/\s+/', '', $prefix); |
|
64 | + $prefix = empty($prefix) ? $email : $prefix; |
|
65 | + $args = array( |
|
66 | + 'user_login' => wpinv_generate_user_name($prefix), |
|
67 | 67 | 'user_pass' => wp_generate_password(), |
68 | 68 | 'user_email' => $email, |
69 | 69 | 'role' => 'subscriber', |
70 | 70 | ); |
71 | 71 | |
72 | - return wp_insert_user( $args ); |
|
72 | + return wp_insert_user($args); |
|
73 | 73 | |
74 | 74 | } |
75 | 75 | |
@@ -79,26 +79,26 @@ discard block |
||
79 | 79 | * @since 1.0.19 |
80 | 80 | * @return bool|WP_User |
81 | 81 | */ |
82 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
82 | +function wpinv_generate_user_name($prefix = '') { |
|
83 | 83 | |
84 | 84 | // If prefix is an email, retrieve the part before the email. |
85 | - $prefix = strtok( $prefix, '@' ); |
|
86 | - $prefix = trim( $prefix, '.' ); |
|
85 | + $prefix = strtok($prefix, '@'); |
|
86 | + $prefix = trim($prefix, '.'); |
|
87 | 87 | |
88 | 88 | // Sanitize the username. |
89 | - $prefix = sanitize_user( $prefix, true ); |
|
89 | + $prefix = sanitize_user($prefix, true); |
|
90 | 90 | |
91 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
92 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
93 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
91 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
92 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
93 | + $prefix = 'gtp_' . zeroise(wp_rand(0, 9999), 4); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $username = $prefix; |
97 | 97 | $postfix = 2; |
98 | 98 | |
99 | - while ( username_exists( $username ) ) { |
|
99 | + while (username_exists($username)) { |
|
100 | 100 | $username = "{$prefix}{$postfix}"; |
101 | - $postfix ++; |
|
101 | + $postfix++; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return $username; |
@@ -115,31 +115,31 @@ discard block |
||
115 | 115 | $tabs = array( |
116 | 116 | |
117 | 117 | 'gp-invoices' => array( |
118 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
118 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
119 | 119 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
120 | 120 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
121 | 121 | ), |
122 | 122 | |
123 | 123 | 'gp-subscriptions' => array( |
124 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
124 | + 'label' => __('Subscriptions', 'invoicing'), |
|
125 | 125 | 'content' => '[wpinv_subscriptions]', |
126 | 126 | 'icon' => 'fas fa-redo', |
127 | 127 | ), |
128 | 128 | |
129 | 129 | 'gp-edit-address' => array( |
130 | - 'label' => __( 'Billing Address', 'invoicing' ), |
|
130 | + 'label' => __('Billing Address', 'invoicing'), |
|
131 | 131 | 'callback' => 'getpaid_display_address_edit_tab', |
132 | 132 | 'icon' => 'fas fa-credit-card', |
133 | 133 | ), |
134 | 134 | |
135 | 135 | ); |
136 | 136 | |
137 | - $tabs = apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
137 | + $tabs = apply_filters('getpaid_user_content_tabs', $tabs); |
|
138 | 138 | |
139 | 139 | // Make sure address editing is last on the list. |
140 | - if ( isset( $tabs['gp-edit-address'] ) ) { |
|
140 | + if (isset($tabs['gp-edit-address'])) { |
|
141 | 141 | $address = $tabs['gp-edit-address']; |
142 | - unset( $tabs['gp-edit-address'] ); |
|
142 | + unset($tabs['gp-edit-address']); |
|
143 | 143 | $tabs['gp-edit-address'] = $address; |
144 | 144 | } |
145 | 145 | |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | * @param array $tab |
154 | 154 | * @return array |
155 | 155 | */ |
156 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
156 | +function getpaid_prepare_user_content_tab($tab) { |
|
157 | 157 | |
158 | - if ( ! empty( $tab['callback'] ) ) { |
|
159 | - return call_user_func( $tab['callback'] ); |
|
158 | + if (!empty($tab['callback'])) { |
|
159 | + return call_user_func($tab['callback']); |
|
160 | 160 | } |
161 | 161 | |
162 | - if ( ! empty( $tab['content'] ) ) { |
|
163 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
162 | + if (!empty($tab['content'])) { |
|
163 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $notice = aui()->alert( |
167 | 167 | array( |
168 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
168 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
169 | 169 | 'type' => 'error', |
170 | 170 | ) |
171 | 171 | ); |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | * @param string $default |
182 | 182 | * @return array |
183 | 183 | */ |
184 | -function getpaid_get_tab_url( $tab, $default ) { |
|
184 | +function getpaid_get_tab_url($tab, $default) { |
|
185 | 185 | global $getpaid_tab_url; |
186 | 186 | |
187 | - if ( empty( $getpaid_tab_url ) ) { |
|
187 | + if (empty($getpaid_tab_url)) { |
|
188 | 188 | return $default; |
189 | 189 | } |
190 | 190 | |
191 | - return sprintf( $getpaid_tab_url, $tab ); |
|
191 | + return sprintf($getpaid_tab_url, $tab); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | */ |
201 | 201 | function getpaid_display_address_edit_tab() { |
202 | 202 | |
203 | - if ( 0 === get_current_user_id() ) { |
|
203 | + if (0 === get_current_user_id()) { |
|
204 | 204 | return '<div class="bsui">' . aui()->alert( |
205 | 205 | array( |
206 | 206 | 'type' => 'error', |
207 | - 'content' => __( 'Your must be logged in to view this section', 'invoicing' ), |
|
207 | + 'content' => __('Your must be logged in to view this section', 'invoicing'), |
|
208 | 208 | 'dismissible' => false, |
209 | 209 | ) |
210 | 210 | ) . '</div>'; |
@@ -218,19 +218,19 @@ discard block |
||
218 | 218 | |
219 | 219 | <?php |
220 | 220 | |
221 | - foreach ( getpaid_user_address_fields() as $key => $label ) { |
|
221 | + foreach (getpaid_user_address_fields() as $key => $label) { |
|
222 | 222 | |
223 | 223 | // Display the country. |
224 | - if ( 'country' == $key ) { |
|
224 | + if ('country' == $key) { |
|
225 | 225 | |
226 | 226 | aui()->select( |
227 | 227 | array( |
228 | 228 | 'options' => wpinv_get_country_list(), |
229 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
230 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
231 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
229 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
230 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
231 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
232 | 232 | 'placeholder' => $label, |
233 | - 'label' => wp_kses_post( $label ), |
|
233 | + 'label' => wp_kses_post($label), |
|
234 | 234 | 'label_type' => 'vertical', |
235 | 235 | 'class' => 'getpaid-address-field', |
236 | 236 | ), |
@@ -240,17 +240,17 @@ discard block |
||
240 | 240 | } |
241 | 241 | |
242 | 242 | // Display the state. |
243 | - elseif ( 'state' == $key ) { |
|
243 | + elseif ('state' == $key) { |
|
244 | 244 | |
245 | 245 | getpaid_get_states_select_markup( |
246 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
247 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
246 | + getpaid_get_user_address_field(get_current_user_id(), 'country'), |
|
247 | + getpaid_get_user_address_field(get_current_user_id(), 'state'), |
|
248 | 248 | $label, |
249 | 249 | $label, |
250 | 250 | '', |
251 | 251 | false, |
252 | 252 | '', |
253 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
253 | + 'getpaid_address[' . esc_attr($key) . ']', |
|
254 | 254 | true |
255 | 255 | ); |
256 | 256 | |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | |
259 | 259 | aui()->input( |
260 | 260 | array( |
261 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
262 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
261 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
262 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
263 | 263 | 'placeholder' => $label, |
264 | - 'label' => wp_kses_post( $label ), |
|
264 | + 'label' => wp_kses_post($label), |
|
265 | 265 | 'label_type' => 'vertical', |
266 | 266 | 'type' => 'text', |
267 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
267 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
268 | 268 | 'class' => 'getpaid-address-field', |
269 | 269 | ), |
270 | 270 | true |
@@ -278,32 +278,32 @@ discard block |
||
278 | 278 | 'name' => 'getpaid_address[email_cc]', |
279 | 279 | 'id' => 'wpinv-email_cc', |
280 | 280 | 'placeholder' => '[email protected], [email protected]', |
281 | - 'label' => __( 'Other email addresses', 'invoicing' ), |
|
281 | + 'label' => __('Other email addresses', 'invoicing'), |
|
282 | 282 | 'label_type' => 'vertical', |
283 | 283 | 'type' => 'text', |
284 | - 'value' => sanitize_text_field( get_user_meta( get_current_user_id(), '_wpinv_email_cc', true ) ), |
|
284 | + 'value' => sanitize_text_field(get_user_meta(get_current_user_id(), '_wpinv_email_cc', true)), |
|
285 | 285 | 'class' => 'getpaid-address-field', |
286 | - 'help_text' => __( 'Optionally provide other email addresses where we should send payment notifications', 'invoicing' ), |
|
286 | + 'help_text' => __('Optionally provide other email addresses where we should send payment notifications', 'invoicing'), |
|
287 | 287 | ), |
288 | 288 | true |
289 | 289 | ); |
290 | 290 | |
291 | - do_action( 'getpaid_display_address_edit_tab' ); |
|
291 | + do_action('getpaid_display_address_edit_tab'); |
|
292 | 292 | |
293 | 293 | aui()->input( |
294 | 294 | array( |
295 | 295 | 'name' => 'getpaid_profile_edit_submit_button', |
296 | 296 | 'id' => 'getpaid_profile_edit_submit_button', |
297 | - 'value' => __( 'Save Address', 'invoicing' ), |
|
298 | - 'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ), |
|
297 | + 'value' => __('Save Address', 'invoicing'), |
|
298 | + 'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'), |
|
299 | 299 | 'type' => 'submit', |
300 | 300 | 'class' => 'btn btn-primary btn-block submit-button', |
301 | 301 | ), |
302 | 302 | true |
303 | 303 | ); |
304 | 304 | |
305 | - wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); |
|
306 | - getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' ); |
|
305 | + wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); |
|
306 | + getpaid_hidden_field('getpaid-action', 'edit_billing_details'); |
|
307 | 307 | ?> |
308 | 308 | |
309 | 309 | </form> |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | |
314 | 314 | return ob_get_clean(); |
315 | 315 | } |
316 | -add_shortcode( 'getpaid_edit_address', 'getpaid_display_address_edit_tab' ); |
|
316 | +add_shortcode('getpaid_edit_address', 'getpaid_display_address_edit_tab'); |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Saves the billing address edit tab. |
@@ -321,30 +321,30 @@ discard block |
||
321 | 321 | * @since 2.1.4 |
322 | 322 | * @param array $data |
323 | 323 | */ |
324 | -function getpaid_save_address_edit_tab( $data ) { |
|
324 | +function getpaid_save_address_edit_tab($data) { |
|
325 | 325 | |
326 | - if ( empty( $data['getpaid_address'] ) || ! is_array( $data['getpaid_address'] ) ) { |
|
326 | + if (empty($data['getpaid_address']) || !is_array($data['getpaid_address'])) { |
|
327 | 327 | return; |
328 | 328 | } |
329 | 329 | |
330 | 330 | $data = $data['getpaid_address']; |
331 | 331 | $user_id = get_current_user_id(); |
332 | 332 | |
333 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
333 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
334 | 334 | |
335 | - if ( isset( $data[ $field ] ) ) { |
|
336 | - $value = sanitize_text_field( $data[ $field ] ); |
|
337 | - update_user_meta( $user_id, '_wpinv_' . $field, $value ); |
|
335 | + if (isset($data[$field])) { |
|
336 | + $value = sanitize_text_field($data[$field]); |
|
337 | + update_user_meta($user_id, '_wpinv_' . $field, $value); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - if ( isset( $data['email_cc'] ) ) { |
|
342 | - update_user_meta( $user_id, '_wpinv_email_cc', sanitize_text_field( $data['email_cc'] ) ); |
|
341 | + if (isset($data['email_cc'])) { |
|
342 | + update_user_meta($user_id, '_wpinv_email_cc', sanitize_text_field($data['email_cc'])); |
|
343 | 343 | } |
344 | 344 | |
345 | - wpinv_set_error( 'address_updated' ); |
|
345 | + wpinv_set_error('address_updated'); |
|
346 | 346 | } |
347 | -add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' ); |
|
347 | +add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab'); |
|
348 | 348 | |
349 | 349 | |
350 | 350 | /* |
@@ -362,27 +362,27 @@ discard block |
||
362 | 362 | * @param array $tabs |
363 | 363 | * @return array |
364 | 364 | */ |
365 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
365 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
366 | 366 | |
367 | 367 | // Abort if the integration is inactive. |
368 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
368 | + if (!getpaid_is_userswp_integration_active()) { |
|
369 | 369 | return $tabs; |
370 | 370 | } |
371 | 371 | |
372 | - $new_tabs = array(); |
|
372 | + $new_tabs = array(); |
|
373 | 373 | |
374 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
374 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
375 | 375 | |
376 | - $new_tabs[ $slug ] = array( |
|
376 | + $new_tabs[$slug] = array( |
|
377 | 377 | 'title' => $tab['label'], |
378 | 378 | 'icon' => $tab['icon'], |
379 | 379 | ); |
380 | 380 | |
381 | 381 | } |
382 | 382 | |
383 | - return array_merge( $tabs, $new_tabs ); |
|
383 | + return array_merge($tabs, $new_tabs); |
|
384 | 384 | } |
385 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
385 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
386 | 386 | |
387 | 387 | /** |
388 | 388 | * Display our UsersWP account tabs. |
@@ -391,21 +391,21 @@ discard block |
||
391 | 391 | * @param array $tabs |
392 | 392 | * @return array |
393 | 393 | */ |
394 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
394 | +function getpaid_display_userswp_account_tabs($tab) { |
|
395 | 395 | global $getpaid_tab_url; |
396 | 396 | |
397 | 397 | $our_tabs = getpaid_get_user_content_tabs(); |
398 | 398 | |
399 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
400 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
401 | - echo wp_kses( getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ), getpaid_allowed_html() ); |
|
399 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
400 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
401 | + echo wp_kses(getpaid_prepare_user_content_tab($our_tabs[$tab]), getpaid_allowed_html()); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | } |
405 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
405 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
406 | 406 | |
407 | 407 | function getpaid_allowed_html() { |
408 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
408 | + $allowed_html = wp_kses_allowed_html('post'); |
|
409 | 409 | |
410 | 410 | // form fields |
411 | 411 | $allowed_html['form'] = array( |
@@ -476,17 +476,17 @@ discard block |
||
476 | 476 | * @param string $tab Current tab. |
477 | 477 | * @return string Title. |
478 | 478 | */ |
479 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
479 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
480 | 480 | |
481 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
481 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
482 | 482 | |
483 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
484 | - return $our_tabs[ $tab ]['label']; |
|
483 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
484 | + return $our_tabs[$tab]['label']; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | return $title; |
488 | 488 | } |
489 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
489 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
490 | 490 | |
491 | 491 | /** |
492 | 492 | * Registers the UsersWP integration settings. |
@@ -495,26 +495,26 @@ discard block |
||
495 | 495 | * @param array $settings An array of integration settings. |
496 | 496 | * @return array |
497 | 497 | */ |
498 | -function getpaid_register_userswp_settings( $settings ) { |
|
498 | +function getpaid_register_userswp_settings($settings) { |
|
499 | 499 | |
500 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
500 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
501 | 501 | |
502 | 502 | $settings[] = array( |
503 | 503 | |
504 | 504 | 'id' => 'userswp', |
505 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
505 | + 'label' => __('UsersWP', 'invoicing'), |
|
506 | 506 | 'settings' => array( |
507 | 507 | |
508 | 508 | 'userswp_settings' => array( |
509 | 509 | 'id' => 'userswp_settings', |
510 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
510 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
511 | 511 | 'type' => 'header', |
512 | 512 | ), |
513 | 513 | |
514 | 514 | 'enable_userswp' => array( |
515 | 515 | 'id' => 'enable_userswp', |
516 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
517 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
516 | + 'name' => __('Enable Integration', 'invoicing'), |
|
517 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
518 | 518 | 'type' => 'checkbox', |
519 | 519 | 'std' => 1, |
520 | 520 | ), |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | |
528 | 528 | return $settings; |
529 | 529 | } |
530 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
530 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
531 | 531 | |
532 | 532 | /** |
533 | 533 | * Ovewrites the invoices history page to UsersWP. |
@@ -535,18 +535,18 @@ discard block |
||
535 | 535 | * @since 2.3.1 |
536 | 536 | * @return bool |
537 | 537 | */ |
538 | -function getpaid_userswp_overwrite_invoice_history_page( $url, $post_type ) { |
|
538 | +function getpaid_userswp_overwrite_invoice_history_page($url, $post_type) { |
|
539 | 539 | |
540 | 540 | $our_tabs = getpaid_get_user_content_tabs(); |
541 | 541 | $tab = "gp-{$post_type}s"; |
542 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
543 | - return add_query_arg( 'type', $tab, uwp_get_account_page_url() ); |
|
542 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
543 | + return add_query_arg('type', $tab, uwp_get_account_page_url()); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | return $url; |
547 | 547 | |
548 | 548 | } |
549 | -add_filter( 'wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2 ); |
|
549 | +add_filter('wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2); |
|
550 | 550 | |
551 | 551 | /** |
552 | 552 | * Checks if the integration is enabled. |
@@ -555,8 +555,8 @@ discard block |
||
555 | 555 | * @return bool |
556 | 556 | */ |
557 | 557 | function getpaid_is_userswp_integration_active() { |
558 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
559 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
558 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
559 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | /* |
@@ -574,26 +574,26 @@ discard block |
||
574 | 574 | * @param array $settings An array of integration settings. |
575 | 575 | * @return array |
576 | 576 | */ |
577 | -function getpaid_register_buddypress_settings( $settings ) { |
|
577 | +function getpaid_register_buddypress_settings($settings) { |
|
578 | 578 | |
579 | - if ( class_exists( 'BuddyPress' ) ) { |
|
579 | + if (class_exists('BuddyPress')) { |
|
580 | 580 | |
581 | 581 | $settings[] = array( |
582 | 582 | |
583 | 583 | 'id' => 'buddypress', |
584 | - 'label' => __( 'BuddyPress', 'invoicing' ), |
|
584 | + 'label' => __('BuddyPress', 'invoicing'), |
|
585 | 585 | 'settings' => array( |
586 | 586 | |
587 | 587 | 'buddypress_settings' => array( |
588 | 588 | 'id' => 'buddypress_settings', |
589 | - 'name' => '<h3>' . __( 'BuddyPress', 'invoicing' ) . '</h3>', |
|
589 | + 'name' => '<h3>' . __('BuddyPress', 'invoicing') . '</h3>', |
|
590 | 590 | 'type' => 'header', |
591 | 591 | ), |
592 | 592 | |
593 | 593 | 'enable_buddypress' => array( |
594 | 594 | 'id' => 'enable_buddypress', |
595 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
596 | - 'desc' => __( 'Display GetPaid items on BuddyPress account pages.', 'invoicing' ), |
|
595 | + 'name' => __('Enable Integration', 'invoicing'), |
|
596 | + 'desc' => __('Display GetPaid items on BuddyPress account pages.', 'invoicing'), |
|
597 | 597 | 'type' => 'checkbox', |
598 | 598 | 'std' => 1, |
599 | 599 | ), |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | |
607 | 607 | return $settings; |
608 | 608 | } |
609 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_buddypress_settings' ); |
|
609 | +add_filter('getpaid_integration_settings', 'getpaid_register_buddypress_settings'); |
|
610 | 610 | |
611 | 611 | /** |
612 | 612 | * Checks if the integration is enabled. |
@@ -615,8 +615,8 @@ discard block |
||
615 | 615 | * @return bool |
616 | 616 | */ |
617 | 617 | function getpaid_is_buddypress_integration_active() { |
618 | - $enabled = wpinv_get_option( 'enable_buddypress', 1 ); |
|
619 | - return class_exists( 'BuddyPress' ) && ! empty( $enabled ); |
|
618 | + $enabled = wpinv_get_option('enable_buddypress', 1); |
|
619 | + return class_exists('BuddyPress') && !empty($enabled); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -627,13 +627,13 @@ discard block |
||
627 | 627 | */ |
628 | 628 | function getpaid_setup_buddypress_integration() { |
629 | 629 | |
630 | - if ( getpaid_is_buddypress_integration_active() ) { |
|
630 | + if (getpaid_is_buddypress_integration_active()) { |
|
631 | 631 | require_once WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php'; |
632 | 632 | buddypress()->getpaid = new BP_GetPaid_Component(); |
633 | 633 | } |
634 | 634 | |
635 | 635 | } |
636 | -add_action( 'bp_setup_components', 'getpaid_setup_buddypress_integration' ); |
|
636 | +add_action('bp_setup_components', 'getpaid_setup_buddypress_integration'); |
|
637 | 637 | |
638 | 638 | /** |
639 | 639 | * Checks if a given user has purchased a given item. |
@@ -641,10 +641,10 @@ discard block |
||
641 | 641 | * @since 2.6.17 |
642 | 642 | * @param int $user_id The user id. |
643 | 643 | */ |
644 | -function getpaid_has_user_purchased_item( $user_id, $item_id ) { |
|
644 | +function getpaid_has_user_purchased_item($user_id, $item_id) { |
|
645 | 645 | global $wpdb; |
646 | 646 | |
647 | - if ( empty( $user_id ) ) { |
|
647 | + if (empty($user_id)) { |
|
648 | 648 | return false; |
649 | 649 | } |
650 | 650 | |
@@ -659,5 +659,5 @@ discard block |
||
659 | 659 | ) |
660 | 660 | ); |
661 | 661 | |
662 | - return ! empty( $count ); |
|
662 | + return !empty($count); |
|
663 | 663 | } |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
21 | 21 | |
22 | - if ( ! $is_object_set ) { |
|
23 | - unset( $wp_query->queried_object ); |
|
22 | + if (!$is_object_set) { |
|
23 | + unset($wp_query->queried_object); |
|
24 | 24 | } |
25 | 25 | |
26 | - if ( ! $is_object_id_set ) { |
|
27 | - unset( $wp_query->queried_object_id ); |
|
26 | + if (!$is_object_id_set) { |
|
27 | + unset($wp_query->queried_object_id); |
|
28 | 28 | } |
29 | 29 | |
30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | 34 | $can_checkout = true; // Always true for now |
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option('success_page', 0); |
|
41 | + $page_id = absint($page_id); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -49,156 +49,156 @@ discard block |
||
49 | 49 | * @param string $post_type The post type or invoice type. |
50 | 50 | * @return string The history page URL. |
51 | 51 | */ |
52 | -function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
|
53 | - $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
|
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
52 | +function wpinv_get_history_page_uri($post_type = 'wpi_invoice') { |
|
53 | + $post_type = sanitize_key(str_replace('wpi_', '', $post_type)); |
|
54 | + $page_id = wpinv_get_option("{$post_type}_history_page", 0); |
|
55 | + $page_id = absint($page_id); |
|
56 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option('success_page', false); |
|
61 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
73 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
74 | - $ret = $ret ? is_page( $ret ) : false; |
|
75 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
73 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
74 | + $ret = $ret ? is_page($ret) : false; |
|
75 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Redirects a user the success page. |
80 | 80 | */ |
81 | -function wpinv_send_to_success_page( $args = array() ) { |
|
81 | +function wpinv_send_to_success_page($args = array()) { |
|
82 | 82 | |
83 | - $args = wp_parse_args( $args ); |
|
83 | + $args = wp_parse_args($args); |
|
84 | 84 | |
85 | - if ( ! empty( $args['invoice_key'] ) ) { |
|
86 | - $invoice = wpinv_get_invoice( $args['invoice_key'] ); |
|
85 | + if (!empty($args['invoice_key'])) { |
|
86 | + $invoice = wpinv_get_invoice($args['invoice_key']); |
|
87 | 87 | |
88 | - if ( $invoice && $invoice->exists() ) { |
|
88 | + if ($invoice && $invoice->exists()) { |
|
89 | 89 | $success_page = $invoice->get_receipt_url(); |
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - if ( empty( $success_page ) ) { |
|
93 | + if (empty($success_page)) { |
|
94 | 94 | $success_page = wpinv_get_success_page_uri(); |
95 | 95 | } |
96 | 96 | |
97 | - $args['wpinv-notice'] = current( array_keys( wpinv_get_errors() ) ); |
|
97 | + $args['wpinv-notice'] = current(array_keys(wpinv_get_errors())); |
|
98 | 98 | |
99 | - $redirect = add_query_arg( $args, $success_page ); |
|
99 | + $redirect = add_query_arg($args, $success_page); |
|
100 | 100 | |
101 | - $redirect = apply_filters( 'wpinv_send_to_success_page_url', $redirect, $args, $success_page ); |
|
101 | + $redirect = apply_filters('wpinv_send_to_success_page_url', $redirect, $args, $success_page); |
|
102 | 102 | |
103 | - wp_redirect( $redirect ); |
|
103 | + wp_redirect($redirect); |
|
104 | 104 | exit; |
105 | 105 | } |
106 | 106 | |
107 | -function wpinv_send_to_failed_page( $args = null ) { |
|
107 | +function wpinv_send_to_failed_page($args = null) { |
|
108 | 108 | $redirect = wpinv_get_failed_transaction_uri(); |
109 | 109 | |
110 | - if ( ! empty( $args ) ) { |
|
110 | + if (!empty($args)) { |
|
111 | 111 | // Check for backward compatibility |
112 | - if ( is_string( $args ) ) { |
|
113 | - $args = str_replace( '?', '', $args ); |
|
112 | + if (is_string($args)) { |
|
113 | + $args = str_replace('?', '', $args); |
|
114 | 114 | } |
115 | 115 | |
116 | - $args = wp_parse_args( $args ); |
|
116 | + $args = wp_parse_args($args); |
|
117 | 117 | |
118 | - $redirect = add_query_arg( $args, $redirect ); |
|
118 | + $redirect = add_query_arg($args, $redirect); |
|
119 | 119 | } |
120 | 120 | |
121 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
121 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
122 | 122 | |
123 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
124 | - wp_redirect( $redirect ); |
|
123 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
124 | + wp_redirect($redirect); |
|
125 | 125 | exit; |
126 | 126 | } |
127 | 127 | |
128 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
129 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
130 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
128 | +function wpinv_get_checkout_uri($args = array()) { |
|
129 | + $uri = wpinv_get_option('checkout_page', false); |
|
130 | + $uri = isset($uri) ? get_permalink($uri) : null; |
|
131 | 131 | |
132 | - if ( ! empty( $args ) ) { |
|
132 | + if (!empty($args)) { |
|
133 | 133 | // Check for backward compatibility |
134 | - if ( is_string( $args ) ) { |
|
135 | - $args = str_replace( '?', '', $args ); |
|
134 | + if (is_string($args)) { |
|
135 | + $args = str_replace('?', '', $args); |
|
136 | 136 | } |
137 | 137 | |
138 | - $args = wp_parse_args( $args ); |
|
138 | + $args = wp_parse_args($args); |
|
139 | 139 | |
140 | - $uri = add_query_arg( $args, $uri ); |
|
140 | + $uri = add_query_arg($args, $uri); |
|
141 | 141 | } |
142 | 142 | |
143 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
143 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
144 | 144 | |
145 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
145 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
146 | 146 | |
147 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
148 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
147 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
148 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
149 | 149 | } |
150 | 150 | |
151 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
151 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
152 | 152 | } |
153 | 153 | |
154 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
155 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
156 | - $success_page = get_permalink( $success_page ); |
|
154 | +function wpinv_get_success_page_url($query_string = null) { |
|
155 | + $success_page = wpinv_get_option('success_page', 0); |
|
156 | + $success_page = get_permalink($success_page); |
|
157 | 157 | |
158 | - if ( $query_string ) { |
|
158 | + if ($query_string) { |
|
159 | 159 | $success_page .= $query_string; |
160 | 160 | } |
161 | 161 | |
162 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
162 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
163 | 163 | } |
164 | 164 | |
165 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
166 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
167 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
165 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
166 | + $uri = wpinv_get_option('failure_page', ''); |
|
167 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
168 | 168 | |
169 | - if ( $extras ) { |
|
169 | + if ($extras) { |
|
170 | 170 | $uri .= $extras; |
171 | 171 | } |
172 | 172 | |
173 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
173 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | function wpinv_is_failed_transaction_page() { |
177 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
178 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
177 | + $ret = wpinv_get_option('failure_page', false); |
|
178 | + $ret = isset($ret) ? is_page($ret) : false; |
|
179 | 179 | |
180 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
180 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
181 | 181 | } |
182 | 182 | |
183 | -function wpinv_transaction_query( $type = 'start' ) { |
|
183 | +function wpinv_transaction_query($type = 'start') { |
|
184 | 184 | global $wpdb; |
185 | 185 | |
186 | 186 | $wpdb->hide_errors(); |
187 | 187 | |
188 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
189 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
188 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
189 | + define('WPINV_USE_TRANSACTIONS', true); |
|
190 | 190 | } |
191 | 191 | |
192 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
193 | - switch ( $type ) { |
|
192 | + if (WPINV_USE_TRANSACTIONS) { |
|
193 | + switch ($type) { |
|
194 | 194 | case 'commit': |
195 | - $wpdb->query( 'COMMIT' ); |
|
195 | + $wpdb->query('COMMIT'); |
|
196 | 196 | break; |
197 | 197 | case 'rollback': |
198 | - $wpdb->query( 'ROLLBACK' ); |
|
198 | + $wpdb->query('ROLLBACK'); |
|
199 | 199 | break; |
200 | 200 | default: |
201 | - $wpdb->query( 'START TRANSACTION' ); |
|
201 | + $wpdb->query('START TRANSACTION'); |
|
202 | 202 | break; |
203 | 203 | } |
204 | 204 | } |
@@ -207,146 +207,146 @@ discard block |
||
207 | 207 | function wpinv_get_prefix() { |
208 | 208 | $invoice_prefix = 'INV-'; |
209 | 209 | |
210 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
210 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | function wpinv_get_business_logo() { |
214 | - $business_logo = wpinv_get_option( 'logo' ); |
|
215 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
214 | + $business_logo = wpinv_get_option('logo'); |
|
215 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_get_business_name() { |
219 | - $name = wpinv_get_option( 'store_name', wpinv_get_blogname() ); |
|
219 | + $name = wpinv_get_option('store_name', wpinv_get_blogname()); |
|
220 | 220 | |
221 | - if ( empty( $name ) ) { |
|
221 | + if (empty($name)) { |
|
222 | 222 | $name = wpinv_get_blogname(); |
223 | 223 | } |
224 | 224 | |
225 | - return apply_filters( 'wpinv_get_business_name', $name ); |
|
225 | + return apply_filters('wpinv_get_business_name', $name); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | function wpinv_get_blogname() { |
229 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
229 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | function wpinv_get_admin_email() { |
233 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
234 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
233 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
234 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | function wpinv_get_business_website() { |
238 | - $business_website = home_url( '/' ); |
|
239 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
238 | + $business_website = home_url('/'); |
|
239 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
240 | 240 | } |
241 | 241 | |
242 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
242 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
243 | 243 | $terms_text = ''; |
244 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
244 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_get_business_footer() { |
248 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
249 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
250 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
248 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
249 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
250 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | function wpinv_checkout_required_fields() { |
254 | 254 | $required_fields = array(); |
255 | 255 | |
256 | 256 | // Let payment gateways and other extensions determine if address fields should be required |
257 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
257 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
258 | 258 | |
259 | - if ( $require_billing_details ) { |
|
260 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
259 | + if ($require_billing_details) { |
|
260 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
261 | 261 | $required_fields['first_name'] = array( |
262 | 262 | 'error_id' => 'invalid_first_name', |
263 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
263 | + 'error_message' => __('Please enter your first name', 'invoicing'), |
|
264 | 264 | ); |
265 | 265 | } |
266 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
266 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
267 | 267 | $required_fields['address'] = array( |
268 | 268 | 'error_id' => 'invalid_address', |
269 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
269 | + 'error_message' => __('Please enter your address', 'invoicing'), |
|
270 | 270 | ); |
271 | 271 | } |
272 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
272 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
273 | 273 | $required_fields['city'] = array( |
274 | 274 | 'error_id' => 'invalid_city', |
275 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
275 | + 'error_message' => __('Please enter your billing city', 'invoicing'), |
|
276 | 276 | ); |
277 | 277 | } |
278 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
278 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
279 | 279 | $required_fields['state'] = array( |
280 | 280 | 'error_id' => 'invalid_state', |
281 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
281 | + 'error_message' => __('Please enter billing state / province', 'invoicing'), |
|
282 | 282 | ); |
283 | 283 | } |
284 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
284 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
285 | 285 | $required_fields['country'] = array( |
286 | 286 | 'error_id' => 'invalid_country', |
287 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
287 | + 'error_message' => __('Please select your billing country', 'invoicing'), |
|
288 | 288 | ); |
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
292 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
292 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | function wpinv_is_ssl_enforced() { |
296 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
297 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
296 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
297 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | function wpinv_schedule_event_twicedaily() { |
301 | 301 | wpinv_email_payment_reminders(); |
302 | 302 | } |
303 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
303 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
304 | 304 | |
305 | 305 | function wpinv_require_login_to_checkout() { |
306 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
307 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
306 | + $return = wpinv_get_option('login_to_checkout', false); |
|
307 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
308 | 308 | } |
309 | 309 | |
310 | -function wpinv_sequential_number_active( $type = '' ) { |
|
311 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
312 | - if ( null !== $check ) { |
|
310 | +function wpinv_sequential_number_active($type = '') { |
|
311 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
312 | + if (null !== $check) { |
|
313 | 313 | return $check; |
314 | 314 | } |
315 | 315 | |
316 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
316 | + return wpinv_get_option('sequential_invoice_number'); |
|
317 | 317 | } |
318 | 318 | |
319 | -function wpinv_switch_to_locale( $locale = null ) { |
|
319 | +function wpinv_switch_to_locale($locale = null) { |
|
320 | 320 | global $invoicing, $wpi_switch_locale; |
321 | 321 | |
322 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
323 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
322 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
323 | + $locale = empty($locale) ? get_locale() : $locale; |
|
324 | 324 | |
325 | - switch_to_locale( $locale ); |
|
325 | + switch_to_locale($locale); |
|
326 | 326 | |
327 | 327 | $wpi_switch_locale = $locale; |
328 | 328 | |
329 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
329 | + add_filter('plugin_locale', 'get_locale'); |
|
330 | 330 | |
331 | 331 | $invoicing->load_textdomain(); |
332 | 332 | |
333 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
333 | + do_action('wpinv_switch_to_locale', $locale); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | 337 | function wpinv_restore_locale() { |
338 | 338 | global $invoicing, $wpi_switch_locale; |
339 | 339 | |
340 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
340 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
341 | 341 | restore_previous_locale(); |
342 | 342 | |
343 | 343 | $wpi_switch_locale = null; |
344 | 344 | |
345 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
345 | + remove_filter('plugin_locale', 'get_locale'); |
|
346 | 346 | |
347 | 347 | $invoicing->load_textdomain(); |
348 | 348 | |
349 | - do_action( 'wpinv_restore_locale' ); |
|
349 | + do_action('wpinv_restore_locale'); |
|
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
@@ -354,26 +354,26 @@ discard block |
||
354 | 354 | * Returns the default form's id. |
355 | 355 | */ |
356 | 356 | function wpinv_get_default_payment_form() { |
357 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
357 | + $form = get_option('wpinv_default_payment_form'); |
|
358 | 358 | |
359 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
359 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
360 | 360 | $form = wp_insert_post( |
361 | 361 | array( |
362 | 362 | 'post_type' => 'wpi_payment_form', |
363 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
363 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
364 | 364 | 'post_status' => 'publish', |
365 | 365 | 'meta_input' => array( |
366 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
366 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
367 | 367 | 'wpinv_form_items' => array(), |
368 | 368 | ), |
369 | 369 | ) |
370 | 370 | ); |
371 | 371 | |
372 | - update_option( 'wpinv_default_payment_form', $form ); |
|
372 | + update_option('wpinv_default_payment_form', $form); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | // WPML support. |
376 | - $form = apply_filters( 'wpml_object_id', $form, 'wpi_payment_form', true ); |
|
376 | + $form = apply_filters('wpml_object_id', $form, 'wpi_payment_form', true); |
|
377 | 377 | return (int) $form; |
378 | 378 | } |
379 | 379 | |
@@ -382,19 +382,19 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @param int $payment_form |
384 | 384 | */ |
385 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
385 | +function getpaid_get_payment_form_elements($payment_form) { |
|
386 | 386 | |
387 | - if ( empty( $payment_form ) ) { |
|
388 | - return wpinv_get_data( 'sample-payment-form' ); |
|
387 | + if (empty($payment_form)) { |
|
388 | + return wpinv_get_data('sample-payment-form'); |
|
389 | 389 | } |
390 | 390 | |
391 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
391 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
392 | 392 | |
393 | - if ( is_array( $form_elements ) ) { |
|
393 | + if (is_array($form_elements)) { |
|
394 | 394 | return $form_elements; |
395 | 395 | } |
396 | 396 | |
397 | - return wpinv_get_data( 'sample-payment-form' ); |
|
397 | + return wpinv_get_data('sample-payment-form'); |
|
398 | 398 | |
399 | 399 | } |
400 | 400 | |
@@ -403,65 +403,65 @@ discard block |
||
403 | 403 | * |
404 | 404 | * @param int $payment_form |
405 | 405 | */ |
406 | -function gepaid_get_form_items( $id ) { |
|
407 | - $form = new GetPaid_Payment_Form( $id ); |
|
406 | +function gepaid_get_form_items($id) { |
|
407 | + $form = new GetPaid_Payment_Form($id); |
|
408 | 408 | |
409 | 409 | // Is this a default form? |
410 | - if ( $form->is_default() ) { |
|
410 | + if ($form->is_default()) { |
|
411 | 411 | return array(); |
412 | 412 | } |
413 | 413 | |
414 | - return $form->get_items( 'view', 'arrays' ); |
|
414 | + return $form->get_items('view', 'arrays'); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | 418 | * Trims each line in a paragraph. |
419 | 419 | * |
420 | 420 | */ |
421 | -function gepaid_trim_lines( $content ) { |
|
422 | - return implode( "\n", array_map( 'trim', explode( "\n", $content ) ) ); |
|
421 | +function gepaid_trim_lines($content) { |
|
422 | + return implode("\n", array_map('trim', explode("\n", $content))); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
426 | -function wpinv_add_elementor_widget_categories( $elements_manager ) { |
|
426 | +function wpinv_add_elementor_widget_categories($elements_manager) { |
|
427 | 427 | $elements_manager->add_category( |
428 | 428 | 'getpaid', |
429 | 429 | array( |
430 | - 'title' => esc_html__( 'GetPaid', 'invoicing' ), |
|
430 | + 'title' => esc_html__('GetPaid', 'invoicing'), |
|
431 | 431 | 'icon' => 'fa fa-plug', |
432 | 432 | ) |
433 | 433 | ); |
434 | 434 | } |
435 | -add_filter( 'elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories' ); |
|
435 | +add_filter('elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories'); |
|
436 | 436 | |
437 | -function wpinv_alter_elementor_widget_config( $config ) { |
|
437 | +function wpinv_alter_elementor_widget_config($config) { |
|
438 | 438 | |
439 | - if ( ! empty( $config['initial_document']['widgets'] ) ) { |
|
440 | - foreach ( $config['initial_document']['widgets'] as $key => $widget ) { |
|
441 | - if ( substr( $key, 0, 16 ) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid' ) { |
|
442 | - $config['initial_document']['widgets'][ $key ]['categories'][] = 'getpaid'; |
|
443 | - $config['initial_document']['widgets'][ $key ]['hide_on_search'] = false; |
|
444 | - $config['initial_document']['widgets'][ $key ]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
439 | + if (!empty($config['initial_document']['widgets'])) { |
|
440 | + foreach ($config['initial_document']['widgets'] as $key => $widget) { |
|
441 | + if (substr($key, 0, 16) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid') { |
|
442 | + $config['initial_document']['widgets'][$key]['categories'][] = 'getpaid'; |
|
443 | + $config['initial_document']['widgets'][$key]['hide_on_search'] = false; |
|
444 | + $config['initial_document']['widgets'][$key]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
445 | 445 | } |
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
449 | 449 | return $config; |
450 | 450 | } |
451 | -add_filter( 'elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config' ); |
|
451 | +add_filter('elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config'); |
|
452 | 452 | |
453 | 453 | function wpinv_get_report_graphs() { |
454 | 454 | |
455 | 455 | return apply_filters( |
456 | 456 | 'getpaid_report_graphs', |
457 | 457 | array( |
458 | - 'sales' => __( 'Earnings', 'invoicing' ), |
|
459 | - 'refunds' => __( 'Refunds', 'invoicing' ), |
|
460 | - 'tax' => __( 'Taxes', 'invoicing' ), |
|
461 | - 'fees' => __( 'Fees', 'invoicing' ), |
|
462 | - 'discount' => __( 'Discounts', 'invoicing' ), |
|
463 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
464 | - 'items' => __( 'Purchased Items', 'invoicing' ), |
|
458 | + 'sales' => __('Earnings', 'invoicing'), |
|
459 | + 'refunds' => __('Refunds', 'invoicing'), |
|
460 | + 'tax' => __('Taxes', 'invoicing'), |
|
461 | + 'fees' => __('Fees', 'invoicing'), |
|
462 | + 'discount' => __('Discounts', 'invoicing'), |
|
463 | + 'invoices' => __('Invoices', 'invoicing'), |
|
464 | + 'items' => __('Purchased Items', 'invoicing'), |
|
465 | 465 | ) |
466 | 466 | ); |
467 | 467 |
@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Retrieves a customer profile. |
|
186 | - * |
|
187 | - * |
|
188 | - * @param string $profile_id profile id. |
|
189 | - * @return string|WP_Error Profile id. |
|
185 | + * Retrieves a customer profile. |
|
186 | + * |
|
187 | + * |
|
188 | + * @param string $profile_id profile id. |
|
189 | + * @return string|WP_Error Profile id. |
|
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | - */ |
|
192 | - public function get_customer_profile( $profile_id ) { |
|
191 | + */ |
|
192 | + public function get_customer_profile( $profile_id ) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Creates a customer profile. |
|
208 | - * |
|
209 | - * |
|
207 | + * Creates a customer profile. |
|
208 | + * |
|
209 | + * |
|
210 | 210 | * @param string $profile_id profile id. |
211 | - * @param WPInv_Invoice $invoice Invoice. |
|
211 | + * @param WPInv_Invoice $invoice Invoice. |
|
212 | 212 | * @param array $submission_data Posted checkout fields. |
213 | 213 | * @param bool $save Whether or not to save the payment as a token. |
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | - * @return string|WP_Error Profile id. |
|
216 | - */ |
|
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
215 | + * @return string|WP_Error Profile id. |
|
216 | + */ |
|
217 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | 220 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | - * Retrieves payment details from cache. |
|
306 | - * |
|
307 | - * |
|
305 | + * Retrieves payment details from cache. |
|
306 | + * |
|
307 | + * |
|
308 | 308 | * @param array $payment_details. |
309 | - * @return array|false Profile id. |
|
310 | - */ |
|
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
309 | + * @return array|false Profile id. |
|
310 | + */ |
|
311 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
312 | 312 | |
313 | 313 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
314 | 314 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -333,13 +333,13 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Securely adds payment details to cache. |
|
337 | - * |
|
338 | - * |
|
336 | + * Securely adds payment details to cache. |
|
337 | + * |
|
338 | + * |
|
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | - */ |
|
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
341 | + */ |
|
342 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
343 | 343 | |
344 | 344 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
345 | 345 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -351,15 +351,15 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
354 | - * Retrieves a customer payment profile. |
|
355 | - * |
|
356 | - * |
|
357 | - * @param string $customer_profile_id customer profile id. |
|
354 | + * Retrieves a customer payment profile. |
|
355 | + * |
|
356 | + * |
|
357 | + * @param string $customer_profile_id customer profile id. |
|
358 | 358 | * @param string $payment_profile_id payment profile id. |
359 | - * @return string|WP_Error Profile id. |
|
359 | + * @return string|WP_Error Profile id. |
|
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | - */ |
|
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
361 | + */ |
|
362 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -375,15 +375,15 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | - * Charges a customer payment profile. |
|
379 | - * |
|
378 | + * Charges a customer payment profile. |
|
379 | + * |
|
380 | 380 | * @param string $customer_profile_id customer profile id. |
381 | 381 | * @param string $payment_profile_id payment profile id. |
382 | - * @param WPInv_Invoice $invoice Invoice. |
|
382 | + * @param WPInv_Invoice $invoice Invoice. |
|
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | - * @return WP_Error|object |
|
385 | - */ |
|
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
384 | + * @return WP_Error|object |
|
385 | + */ |
|
386 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -429,41 +429,41 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
432 | - * Processes a customer charge. |
|
433 | - * |
|
432 | + * Processes a customer charge. |
|
433 | + * |
|
434 | 434 | * @param stdClass $result Api response. |
435 | - * @param WPInv_Invoice $invoice Invoice. |
|
436 | - */ |
|
437 | - public function process_charge_response( $result, $invoice ) { |
|
435 | + * @param WPInv_Invoice $invoice Invoice. |
|
436 | + */ |
|
437 | + public function process_charge_response( $result, $invoice ) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
440 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
441 | 441 | |
442 | - // Succeeded. |
|
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
442 | + // Succeeded. |
|
443 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
444 | 444 | |
445 | - // Maybe set a transaction id. |
|
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | - } |
|
445 | + // Maybe set a transaction id. |
|
446 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | + } |
|
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
453 | - return $invoice->mark_paid(); |
|
454 | - } |
|
452 | + if ( 1 == $response_code ) { |
|
453 | + return $invoice->mark_paid(); |
|
454 | + } |
|
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
457 | - $invoice->add_note( |
|
456 | + $invoice->set_status( 'wpi-onhold' ); |
|
457 | + $invoice->add_note( |
|
458 | 458 | sprintf( |
459 | 459 | __( 'Held for review: %s', 'invoicing' ), |
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | - ); |
|
462 | + ); |
|
463 | 463 | |
464 | - return $invoice->save(); |
|
464 | + return $invoice->save(); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | 468 | wpinv_set_error( 'card_declined' ); |
469 | 469 | |
@@ -475,13 +475,13 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | - * Returns payment information. |
|
479 | - * |
|
480 | - * |
|
481 | - * @param array $card Card details. |
|
482 | - * @return array |
|
483 | - */ |
|
484 | - public function get_payment_information( $card ) { |
|
478 | + * Returns payment information. |
|
479 | + * |
|
480 | + * |
|
481 | + * @param array $card Card details. |
|
482 | + * @return array |
|
483 | + */ |
|
484 | + public function get_payment_information( $card ) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -494,25 +494,25 @@ discard block |
||
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
497 | - * Returns the customer profile meta name. |
|
498 | - * |
|
499 | - * |
|
500 | - * @param WPInv_Invoice $invoice Invoice. |
|
501 | - * @return string |
|
502 | - */ |
|
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
497 | + * Returns the customer profile meta name. |
|
498 | + * |
|
499 | + * |
|
500 | + * @param WPInv_Invoice $invoice Invoice. |
|
501 | + * @return string |
|
502 | + */ |
|
503 | + public function get_customer_profile_meta_name( $invoice ) { |
|
504 | 504 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
508 | - * Validates the submitted data. |
|
509 | - * |
|
510 | - * |
|
511 | - * @param array $submission_data Posted checkout fields. |
|
508 | + * Validates the submitted data. |
|
509 | + * |
|
510 | + * |
|
511 | + * @param array $submission_data Posted checkout fields. |
|
512 | 512 | * @param WPInv_Invoice $invoice |
513 | - * @return WP_Error|string The payment profile id |
|
514 | - */ |
|
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
513 | + * @return WP_Error|string The payment profile id |
|
514 | + */ |
|
515 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
@@ -544,13 +544,13 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Returns invoice line items. |
|
548 | - * |
|
549 | - * |
|
550 | - * @param WPInv_Invoice $invoice Invoice. |
|
551 | - * @return array |
|
552 | - */ |
|
553 | - public function get_line_items( $invoice ) { |
|
547 | + * Returns invoice line items. |
|
548 | + * |
|
549 | + * |
|
550 | + * @param WPInv_Invoice $invoice Invoice. |
|
551 | + * @return array |
|
552 | + */ |
|
553 | + public function get_line_items( $invoice ) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | 556 | foreach ( $invoice->get_items() as $item ) { |
@@ -587,15 +587,15 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
590 | - * Process Payment. |
|
591 | - * |
|
592 | - * |
|
593 | - * @param WPInv_Invoice $invoice Invoice. |
|
594 | - * @param array $submission_data Posted checkout fields. |
|
595 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | - * @return array |
|
597 | - */ |
|
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
590 | + * Process Payment. |
|
591 | + * |
|
592 | + * |
|
593 | + * @param WPInv_Invoice $invoice Invoice. |
|
594 | + * @param array $submission_data Posted checkout fields. |
|
595 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | + * @return array |
|
597 | + */ |
|
598 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | 601 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -628,45 +628,45 @@ discard block |
||
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
631 | - } |
|
631 | + } |
|
632 | 632 | |
633 | - /** |
|
634 | - * Processes the initial payment. |
|
635 | - * |
|
633 | + /** |
|
634 | + * Processes the initial payment. |
|
635 | + * |
|
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | - */ |
|
638 | - protected function process_initial_payment( $invoice ) { |
|
637 | + */ |
|
638 | + protected function process_initial_payment( $invoice ) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
640 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | 641 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
642 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
643 | 643 | |
644 | - // Do we have an error? |
|
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
648 | - } |
|
644 | + // Do we have an error? |
|
645 | + if ( is_wp_error( $result ) ) { |
|
646 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | + wpinv_send_back_to_checkout( $invoice ); |
|
648 | + } |
|
649 | 649 | |
650 | - // Process the response. |
|
651 | - $this->process_charge_response( $result, $invoice ); |
|
650 | + // Process the response. |
|
651 | + $this->process_charge_response( $result, $invoice ); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
655 | - } |
|
653 | + if ( wpinv_get_errors() ) { |
|
654 | + wpinv_send_back_to_checkout( $invoice ); |
|
655 | + } |
|
656 | 656 | |
657 | - } |
|
657 | + } |
|
658 | 658 | |
659 | 659 | /** |
660 | - * Processes recurring payments. |
|
661 | - * |
|
660 | + * Processes recurring payments. |
|
661 | + * |
|
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | - */ |
|
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
664 | + */ |
|
665 | + public function process_subscription( $invoice, $subscriptions ) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | 668 | if ( (float) $invoice->get_total() > 0 ) { |
669 | - $this->process_initial_payment( $invoice ); |
|
669 | + $this->process_initial_payment( $invoice ); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
@@ -684,36 +684,36 @@ discard block |
||
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | - // Redirect to the success page. |
|
687 | + // Redirect to the success page. |
|
688 | 688 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
689 | 689 | |
690 | 690 | } |
691 | 691 | |
692 | - /** |
|
693 | - * (Maybe) renews an authorize.net subscription profile. |
|
694 | - * |
|
695 | - * |
|
692 | + /** |
|
693 | + * (Maybe) renews an authorize.net subscription profile. |
|
694 | + * |
|
695 | + * |
|
696 | 696 | * @param WPInv_Subscription $subscription |
697 | - */ |
|
698 | - public function maybe_renew_subscription( $subscription ) { |
|
697 | + */ |
|
698 | + public function maybe_renew_subscription( $subscription ) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | 701 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
702 | 702 | $this->renew_subscription( $subscription ); |
703 | 703 | } |
704 | 704 | |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | 707 | /** |
708 | - * Renews a subscription. |
|
709 | - * |
|
708 | + * Renews a subscription. |
|
709 | + * |
|
710 | 710 | * @param WPInv_Subscription $subscription |
711 | - */ |
|
712 | - public function renew_subscription( $subscription ) { |
|
711 | + */ |
|
712 | + public function renew_subscription( $subscription ) { |
|
713 | 713 | |
714 | - // Generate the renewal invoice. |
|
715 | - $new_invoice = $subscription->create_payment(); |
|
716 | - $old_invoice = $subscription->get_parent_payment(); |
|
714 | + // Generate the renewal invoice. |
|
715 | + $new_invoice = $subscription->create_payment(); |
|
716 | + $old_invoice = $subscription->get_parent_payment(); |
|
717 | 717 | |
718 | 718 | if ( empty( $new_invoice ) ) { |
719 | 719 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -722,37 +722,37 @@ discard block |
||
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | - |
|
729 | - // Do we have an error? |
|
730 | - if ( is_wp_error( $result ) ) { |
|
731 | - |
|
732 | - $old_invoice->add_note( |
|
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | - true, |
|
735 | - false, |
|
736 | - true |
|
737 | - ); |
|
738 | - $subscription->failing(); |
|
739 | - return; |
|
740 | - |
|
741 | - } |
|
742 | - |
|
743 | - // Process the response. |
|
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
745 | - |
|
746 | - if ( wpinv_get_errors() ) { |
|
747 | - |
|
748 | - $old_invoice->add_note( |
|
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | - true, |
|
751 | - false, |
|
752 | - true |
|
753 | - ); |
|
754 | - $subscription->failing(); |
|
755 | - return; |
|
725 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | + |
|
729 | + // Do we have an error? |
|
730 | + if ( is_wp_error( $result ) ) { |
|
731 | + |
|
732 | + $old_invoice->add_note( |
|
733 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | + true, |
|
735 | + false, |
|
736 | + true |
|
737 | + ); |
|
738 | + $subscription->failing(); |
|
739 | + return; |
|
740 | + |
|
741 | + } |
|
742 | + |
|
743 | + // Process the response. |
|
744 | + $this->process_charge_response( $result, $new_invoice ); |
|
745 | + |
|
746 | + if ( wpinv_get_errors() ) { |
|
747 | + |
|
748 | + $old_invoice->add_note( |
|
749 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | + true, |
|
751 | + false, |
|
752 | + true |
|
753 | + ); |
|
754 | + $subscription->failing(); |
|
755 | + return; |
|
756 | 756 | |
757 | 757 | } |
758 | 758 | |
@@ -761,13 +761,13 @@ discard block |
||
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
764 | - * Processes invoice addons. |
|
765 | - * |
|
766 | - * @param WPInv_Invoice $invoice |
|
767 | - * @param GetPaid_Form_Item[] $items |
|
768 | - * @return WPInv_Invoice |
|
769 | - */ |
|
770 | - public function process_addons( $invoice, $items ) { |
|
764 | + * Processes invoice addons. |
|
765 | + * |
|
766 | + * @param WPInv_Invoice $invoice |
|
767 | + * @param GetPaid_Form_Item[] $items |
|
768 | + * @return WPInv_Invoice |
|
769 | + */ |
|
770 | + public function process_addons( $invoice, $items ) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | 788 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
789 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
790 | 790 | |
791 | 791 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
792 | 792 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -801,11 +801,11 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Processes invoice addons. |
|
805 | - * |
|
804 | + * Processes invoice addons. |
|
805 | + * |
|
806 | 806 | * @param array $args |
807 | - * @return array |
|
808 | - */ |
|
807 | + * @return array |
|
808 | + */ |
|
809 | 809 | public function filter_addons_request( $args ) { |
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
@@ -839,11 +839,11 @@ discard block |
||
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
842 | - * Filters the gateway settings. |
|
843 | - * |
|
844 | - * @param array $admin_settings |
|
845 | - */ |
|
846 | - public function admin_settings( $admin_settings ) { |
|
842 | + * Filters the gateway settings. |
|
843 | + * |
|
844 | + * @param array $admin_settings |
|
845 | + */ |
|
846 | + public function admin_settings( $admin_settings ) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | 849 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
885 | 885 | |
886 | - return $admin_settings; |
|
887 | - } |
|
886 | + return $admin_settings; |
|
887 | + } |
|
888 | 888 | |
889 | 889 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
73 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,79 +100,79 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ), |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ), |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | |
142 | 142 | // In case the payment profile already exists remotely. |
143 | - if ( 'dup_payment_profile' === $response->get_error_code() ) { |
|
144 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
145 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
146 | - return strtok( '.' ); |
|
143 | + if ('dup_payment_profile' === $response->get_error_code()) { |
|
144 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
145 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
146 | + return strtok('.'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // In case the customer profile already exists remotely. |
150 | - if ( 'E00039' === $response->get_error_code() ) { |
|
151 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
152 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
153 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
150 | + if ('E00039' === $response->get_error_code()) { |
|
151 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
152 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
153 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $response; |
157 | 157 | } |
158 | 158 | |
159 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
159 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
160 | 160 | |
161 | 161 | // Save the payment token. |
162 | - if ( $save ) { |
|
162 | + if ($save) { |
|
163 | 163 | $this->save_token( |
164 | 164 | array( |
165 | 165 | 'id' => $response->customerPaymentProfileIdList[0], |
166 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
166 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
167 | 167 | 'default' => true, |
168 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
168 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Add a note about the validation response. |
174 | 174 | $invoice->add_note( |
175 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
175 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
176 | 176 | false, |
177 | 177 | false, |
178 | 178 | true |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return string|WP_Error Profile id. |
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | 191 | */ |
192 | - public function get_customer_profile( $profile_id ) { |
|
192 | + public function get_customer_profile($profile_id) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ), |
200 | 200 | ); |
201 | 201 | |
202 | - return $this->post( $args, false ); |
|
202 | + return $this->post($args, false); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | 215 | * @return string|WP_Error Profile id. |
216 | 216 | */ |
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
217 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
220 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
221 | 221 | |
222 | 222 | // Prepare card details. |
223 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
223 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
224 | 224 | |
225 | 225 | // Authorize.NET does not support saving the same card twice. |
226 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
226 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
227 | 227 | |
228 | - if ( $cached_information ) { |
|
228 | + if ($cached_information) { |
|
229 | 229 | return $cached_information; |
230 | 230 | } |
231 | 231 | |
@@ -238,34 +238,34 @@ discard block |
||
238 | 238 | |
239 | 239 | // Billing information. |
240 | 240 | 'billTo' => array( |
241 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
242 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
243 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
244 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
245 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
246 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
247 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
241 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
242 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
243 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
244 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
245 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
246 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
247 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
248 | 248 | ), |
249 | 249 | |
250 | 250 | // Payment information. |
251 | 251 | 'payment' => $payment_information, |
252 | 252 | ), |
253 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
253 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
254 | 254 | ), |
255 | 255 | ); |
256 | 256 | |
257 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
257 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
258 | 258 | |
259 | - if ( is_wp_error( $response ) ) { |
|
259 | + if (is_wp_error($response)) { |
|
260 | 260 | |
261 | 261 | // In case the payment profile already exists remotely. |
262 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
263 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
264 | - $payment_profile_id = strtok( '.' ); |
|
265 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
262 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
263 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
264 | + $payment_profile_id = strtok('.'); |
|
265 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
266 | 266 | |
267 | 267 | // Cache payment profile id. |
268 | - $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
268 | + $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
269 | 269 | |
270 | 270 | return $payment_profile_id; |
271 | 271 | } |
@@ -274,29 +274,29 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | // Save the payment token. |
277 | - if ( $save ) { |
|
277 | + if ($save) { |
|
278 | 278 | $this->save_token( |
279 | 279 | array( |
280 | 280 | 'id' => $response->customerPaymentProfileId, |
281 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
281 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
282 | 282 | 'default' => true, |
283 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
283 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
284 | 284 | ) |
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Cache payment profile id. |
289 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
289 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
290 | 290 | |
291 | 291 | // Add a note about the validation response. |
292 | 292 | $invoice->add_note( |
293 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
293 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
294 | 294 | false, |
295 | 295 | false, |
296 | 296 | true |
297 | 297 | ); |
298 | 298 | |
299 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
299 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
300 | 300 | |
301 | 301 | return $response->customerPaymentProfileId; |
302 | 302 | } |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * @param array $payment_details. |
309 | 309 | * @return array|false Profile id. |
310 | 310 | */ |
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
311 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
312 | 312 | |
313 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
314 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
313 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
314 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
315 | 315 | |
316 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
316 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
317 | 317 | return false; |
318 | 318 | } |
319 | 319 | |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | 'getCustomerPaymentProfileRequest' => array( |
323 | 323 | 'merchantAuthentication' => $this->get_auth_params(), |
324 | 324 | 'customerProfileId' => $customer_profile, |
325 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
325 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
326 | 326 | ), |
327 | 327 | ); |
328 | 328 | |
329 | - $response = $this->post( $args, $invoice ); |
|
329 | + $response = $this->post($args, $invoice); |
|
330 | 330 | |
331 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
331 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | 341 | */ |
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
342 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
343 | 343 | |
344 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
345 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
346 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
344 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
345 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
346 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
347 | 347 | |
348 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
349 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
348 | + $cached_information[$payment_details] = $payment_profile_id; |
|
349 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return string|WP_Error Profile id. |
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | 361 | */ |
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
362 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | ), |
371 | 371 | ); |
372 | 372 | |
373 | - return $this->post( $args, false ); |
|
373 | + return $this->post($args, false); |
|
374 | 374 | |
375 | 375 | } |
376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | 384 | * @return WP_Error|object |
385 | 385 | */ |
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
386 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | ), |
404 | 404 | ), |
405 | 405 | 'order' => array( |
406 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
406 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
407 | 407 | ), |
408 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
408 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
409 | 409 | 'tax' => array( |
410 | 410 | 'amount' => $invoice->get_total_tax(), |
411 | - 'name' => __( 'TAX', 'invoicing' ), |
|
411 | + 'name' => __('TAX', 'invoicing'), |
|
412 | 412 | ), |
413 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
413 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
414 | 414 | 'customer' => array( |
415 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
416 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
415 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
416 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
417 | 417 | ), |
418 | 418 | 'customerIP' => $invoice->get_ip(), |
419 | 419 | ), |
420 | 420 | ), |
421 | 421 | ); |
422 | 422 | |
423 | - if ( 0 == $invoice->get_total_tax() ) { |
|
424 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
423 | + if (0 == $invoice->get_total_tax()) { |
|
424 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
425 | 425 | } |
426 | 426 | |
427 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
427 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
428 | 428 | |
429 | 429 | } |
430 | 430 | |
@@ -434,29 +434,29 @@ discard block |
||
434 | 434 | * @param stdClass $result Api response. |
435 | 435 | * @param WPInv_Invoice $invoice Invoice. |
436 | 436 | */ |
437 | - public function process_charge_response( $result, $invoice ) { |
|
437 | + public function process_charge_response($result, $invoice) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | 440 | $response_code = (int) $result->transactionResponse->responseCode; |
441 | 441 | |
442 | 442 | // Succeeded. |
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
443 | + if (1 == $response_code || 4 == $response_code) { |
|
444 | 444 | |
445 | 445 | // Maybe set a transaction id. |
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
446 | + if (!empty($result->transactionResponse->transId)) { |
|
447 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
448 | 448 | } |
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
452 | + if (1 == $response_code) { |
|
453 | 453 | return $invoice->mark_paid(); |
454 | 454 | } |
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
456 | + $invoice->set_status('wpi-onhold'); |
|
457 | 457 | $invoice->add_note( |
458 | 458 | sprintf( |
459 | - __( 'Held for review: %s', 'invoicing' ), |
|
459 | + __('Held for review: %s', 'invoicing'), |
|
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | 462 | ); |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | - wpinv_set_error( 'card_declined' ); |
|
468 | + wpinv_set_error('card_declined'); |
|
469 | 469 | |
470 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
470 | + if (!empty($result->transactionResponse->errors)) { |
|
471 | 471 | $errors = (object) $result->transactionResponse->errors; |
472 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
472 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param array $card Card details. |
482 | 482 | * @return array |
483 | 483 | */ |
484 | - public function get_payment_information( $card ) { |
|
484 | + public function get_payment_information($card) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param WPInv_Invoice $invoice Invoice. |
501 | 501 | * @return string |
502 | 502 | */ |
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
504 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
503 | + public function get_customer_profile_meta_name($invoice) { |
|
504 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -512,34 +512,34 @@ discard block |
||
512 | 512 | * @param WPInv_Invoice $invoice |
513 | 513 | * @return WP_Error|string The payment profile id |
514 | 514 | */ |
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
515 | + public function validate_submission_data($submission_data, $invoice) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
519 | 519 | |
520 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
521 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
520 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
521 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | // Validate the payment method. |
525 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
526 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
525 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
526 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | // Are we adding a new payment method? |
530 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
530 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
531 | 531 | return $submission_data['getpaid-authorizenet-payment-method']; |
532 | 532 | } |
533 | 533 | |
534 | 534 | // Retrieve the customer profile id. |
535 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
535 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
536 | 536 | |
537 | 537 | // Create payment method. |
538 | - if ( empty( $profile_id ) ) { |
|
539 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
538 | + if (empty($profile_id)) { |
|
539 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
540 | 540 | } |
541 | 541 | |
542 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
542 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
543 | 543 | |
544 | 544 | } |
545 | 545 | |
@@ -550,32 +550,32 @@ discard block |
||
550 | 550 | * @param WPInv_Invoice $invoice Invoice. |
551 | 551 | * @return array |
552 | 552 | */ |
553 | - public function get_line_items( $invoice ) { |
|
553 | + public function get_line_items($invoice) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | - foreach ( $invoice->get_items() as $item ) { |
|
556 | + foreach ($invoice->get_items() as $item) { |
|
557 | 557 | |
558 | 558 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
559 | 559 | $items[] = array( |
560 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
561 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
562 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
563 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
560 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
561 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
562 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
563 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
564 | 564 | 'unitPrice' => (float) $amount, |
565 | 565 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
566 | 566 | ); |
567 | 567 | |
568 | 568 | } |
569 | 569 | |
570 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
570 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
571 | 571 | |
572 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
572 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
573 | 573 | |
574 | - if ( $amount > 0 ) { |
|
574 | + if ($amount > 0) { |
|
575 | 575 | $items[] = array( |
576 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
577 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
578 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
576 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
577 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
578 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
579 | 579 | 'quantity' => '1', |
580 | 580 | 'unitPrice' => (float) $amount, |
581 | 581 | 'taxable' => false, |
@@ -595,36 +595,36 @@ discard block |
||
595 | 595 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
596 | 596 | * @return array |
597 | 597 | */ |
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
598 | + public function process_payment($invoice, $submission_data, $submission) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
601 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
602 | 602 | |
603 | 603 | // Do we have an error? |
604 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
605 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
606 | - wpinv_send_back_to_checkout( $invoice ); |
|
604 | + if (is_wp_error($payment_profile_id)) { |
|
605 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
606 | + wpinv_send_back_to_checkout($invoice); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | // Save the payment method to the order. |
610 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
610 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
611 | 611 | |
612 | 612 | // Check if this is a subscription or not. |
613 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
614 | - if ( ! empty( $subscriptions ) ) { |
|
615 | - $this->process_subscription( $invoice, $subscriptions ); |
|
613 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
614 | + if (!empty($subscriptions)) { |
|
615 | + $this->process_subscription($invoice, $subscriptions); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | // If it is free, send to the success page. |
619 | - if ( ! $invoice->needs_payment() ) { |
|
619 | + if (!$invoice->needs_payment()) { |
|
620 | 620 | $invoice->mark_paid(); |
621 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
621 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | // Charge the payment profile. |
625 | - $this->process_initial_payment( $invoice ); |
|
625 | + $this->process_initial_payment($invoice); |
|
626 | 626 | |
627 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
627 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
@@ -635,23 +635,23 @@ discard block |
||
635 | 635 | * |
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | 637 | */ |
638 | - protected function process_initial_payment( $invoice ) { |
|
638 | + protected function process_initial_payment($invoice) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
640 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
641 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
642 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
643 | 643 | |
644 | 644 | // Do we have an error? |
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
645 | + if (is_wp_error($result)) { |
|
646 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
647 | + wpinv_send_back_to_checkout($invoice); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Process the response. |
651 | - $this->process_charge_response( $result, $invoice ); |
|
651 | + $this->process_charge_response($result, $invoice); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
653 | + if (wpinv_get_errors()) { |
|
654 | + wpinv_send_back_to_checkout($invoice); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | } |
@@ -662,30 +662,30 @@ discard block |
||
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | 664 | */ |
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
665 | + public function process_subscription($invoice, $subscriptions) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | - if ( (float) $invoice->get_total() > 0 ) { |
|
669 | - $this->process_initial_payment( $invoice ); |
|
668 | + if ((float) $invoice->get_total() > 0) { |
|
669 | + $this->process_initial_payment($invoice); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
673 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
673 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
674 | 674 | |
675 | - foreach ( $subscriptions as $subscription ) { |
|
676 | - if ( $subscription->exists() ) { |
|
677 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
678 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
675 | + foreach ($subscriptions as $subscription) { |
|
676 | + if ($subscription->exists()) { |
|
677 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
678 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
679 | 679 | |
680 | - $subscription->set_next_renewal_date( $expiry ); |
|
681 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
682 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
680 | + $subscription->set_next_renewal_date($expiry); |
|
681 | + $subscription->set_date_created(current_time('mysql')); |
|
682 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
683 | 683 | $subscription->activate(); |
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Redirect to the success page. |
688 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
688 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
689 | 689 | |
690 | 690 | } |
691 | 691 | |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | * |
696 | 696 | * @param WPInv_Subscription $subscription |
697 | 697 | */ |
698 | - public function maybe_renew_subscription( $subscription ) { |
|
698 | + public function maybe_renew_subscription($subscription) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
702 | - $this->renew_subscription( $subscription ); |
|
701 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
702 | + $this->renew_subscription($subscription); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | } |
@@ -709,28 +709,28 @@ discard block |
||
709 | 709 | * |
710 | 710 | * @param WPInv_Subscription $subscription |
711 | 711 | */ |
712 | - public function renew_subscription( $subscription ) { |
|
712 | + public function renew_subscription($subscription) { |
|
713 | 713 | |
714 | 714 | // Generate the renewal invoice. |
715 | 715 | $new_invoice = $subscription->create_payment(); |
716 | 716 | $old_invoice = $subscription->get_parent_payment(); |
717 | 717 | |
718 | - if ( empty( $new_invoice ) ) { |
|
719 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
718 | + if (empty($new_invoice)) { |
|
719 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
720 | 720 | $subscription->failing(); |
721 | 721 | return; |
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
725 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
726 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
727 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
728 | 728 | |
729 | 729 | // Do we have an error? |
730 | - if ( is_wp_error( $result ) ) { |
|
730 | + if (is_wp_error($result)) { |
|
731 | 731 | |
732 | 732 | $old_invoice->add_note( |
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
733 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
734 | 734 | true, |
735 | 735 | false, |
736 | 736 | true |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | } |
742 | 742 | |
743 | 743 | // Process the response. |
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
744 | + $this->process_charge_response($result, $new_invoice); |
|
745 | 745 | |
746 | - if ( wpinv_get_errors() ) { |
|
746 | + if (wpinv_get_errors()) { |
|
747 | 747 | |
748 | 748 | $old_invoice->add_note( |
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
749 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
750 | 750 | true, |
751 | 751 | false, |
752 | 752 | true |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | |
757 | 757 | } |
758 | 758 | |
759 | - $subscription->add_payment( array(), $new_invoice ); |
|
759 | + $subscription->add_payment(array(), $new_invoice); |
|
760 | 760 | $subscription->renew(); |
761 | 761 | } |
762 | 762 | |
@@ -767,33 +767,33 @@ discard block |
||
767 | 767 | * @param GetPaid_Form_Item[] $items |
768 | 768 | * @return WPInv_Invoice |
769 | 769 | */ |
770 | - public function process_addons( $invoice, $items ) { |
|
770 | + public function process_addons($invoice, $items) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
774 | 774 | $getpaid_authorize_addons = array(); |
775 | - foreach ( $items as $item ) { |
|
775 | + foreach ($items as $item) { |
|
776 | 776 | |
777 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
777 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
778 | 778 | $getpaid_authorize_addons[] = $item; |
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
782 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
782 | + if (empty($getpaid_authorize_addons)) { |
|
783 | 783 | return; |
784 | 784 | } |
785 | 785 | |
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
788 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
789 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
790 | 790 | |
791 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
792 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
793 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
791 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
792 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
793 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
794 | 794 | |
795 | - if ( is_wp_error( $result ) ) { |
|
796 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
795 | + if (is_wp_error($result)) { |
|
796 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
797 | 797 | return; |
798 | 798 | } |
799 | 799 | |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | * @param array $args |
807 | 807 | * @return array |
808 | 808 | */ |
809 | - public function filter_addons_request( $args ) { |
|
809 | + public function filter_addons_request($args) { |
|
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
812 | 812 | $total = 0; |
813 | 813 | |
814 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
814 | + foreach ($getpaid_authorize_addons as $addon) { |
|
815 | 815 | $total += $addon->get_sub_total(); |
816 | 816 | } |
817 | 817 | |
818 | 818 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
819 | 819 | |
820 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
821 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
820 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
821 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | return $args; |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | public function sandbox_notice() { |
832 | 832 | |
833 | 833 | return sprintf( |
834 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
834 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
835 | 835 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
836 | 836 | '</a>' |
837 | 837 | ); |
@@ -843,42 +843,42 @@ discard block |
||
843 | 843 | * |
844 | 844 | * @param array $admin_settings |
845 | 845 | */ |
846 | - public function admin_settings( $admin_settings ) { |
|
846 | + public function admin_settings($admin_settings) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
850 | - implode( ', ', $this->currencies ) |
|
849 | + __('Supported Currencies: %s', 'invoicing'), |
|
850 | + implode(', ', $this->currencies) |
|
851 | 851 | ); |
852 | 852 | |
853 | 853 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
854 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
854 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
855 | 855 | |
856 | 856 | $admin_settings['authorizenet_login_id'] = array( |
857 | 857 | 'type' => 'text', |
858 | 858 | 'id' => 'authorizenet_login_id', |
859 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
860 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
859 | + 'name' => __('API Login ID', 'invoicing'), |
|
860 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
861 | 861 | ); |
862 | 862 | |
863 | 863 | $admin_settings['authorizenet_transaction_key'] = array( |
864 | 864 | 'type' => 'text', |
865 | 865 | 'id' => 'authorizenet_transaction_key', |
866 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
866 | + 'name' => __('Transaction Key', 'invoicing'), |
|
867 | 867 | ); |
868 | 868 | |
869 | 869 | $admin_settings['authorizenet_signature_key'] = array( |
870 | 870 | 'type' => 'text', |
871 | 871 | 'id' => 'authorizenet_signature_key', |
872 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
873 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
872 | + 'name' => __('Signature Key', 'invoicing'), |
|
873 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
874 | 874 | ); |
875 | 875 | |
876 | 876 | $admin_settings['authorizenet_ipn_url'] = array( |
877 | 877 | 'type' => 'ipn_url', |
878 | 878 | 'id' => 'authorizenet_ipn_url', |
879 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
879 | + 'name' => __('Webhook URL', 'invoicing'), |
|
880 | 880 | 'std' => $this->notify_url, |
881 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
881 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
882 | 882 | 'custom' => 'authorizenet', |
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Are we supporting item quantities? |
@@ -20,35 +20,35 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function wpinv_get_ip() { |
22 | 22 | |
23 | - if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { |
|
24 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); |
|
23 | + if (isset($_SERVER['HTTP_X_REAL_IP'])) { |
|
24 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP'])); |
|
25 | 25 | } |
26 | 26 | |
27 | - if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
27 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
28 | 28 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
29 | 29 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
30 | - return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); |
|
30 | + return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR'])))))); |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
34 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ); |
|
33 | + if (isset($_SERVER['HTTP_CLIENT_IP'])) { |
|
34 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP'])); |
|
35 | 35 | } |
36 | 36 | |
37 | - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
38 | - return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); |
|
37 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
38 | + return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return ''; |
42 | 42 | } |
43 | 43 | |
44 | 44 | function wpinv_get_user_agent() { |
45 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
46 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
45 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
46 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
47 | 47 | } else { |
48 | 48 | $user_agent = ''; |
49 | 49 | } |
50 | 50 | |
51 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
51 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | * @param string $amount The amount to sanitize. |
58 | 58 | * @return float |
59 | 59 | */ |
60 | -function getpaid_standardize_amount( $amount ) { |
|
60 | +function getpaid_standardize_amount($amount) { |
|
61 | 61 | |
62 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
63 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
64 | - if ( is_numeric( $amount ) ) { |
|
65 | - return floatval( $amount ); |
|
62 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
63 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
64 | + if (is_numeric($amount)) { |
|
65 | + return floatval($amount); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Cast the remaining to a float. |
69 | - return wpinv_round_amount( preg_replace( '/[^0-9\.\-]/', '', $amount ) ); |
|
69 | + return wpinv_round_amount(preg_replace('/[^0-9\.\-]/', '', $amount)); |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @param string $amount The amount to sanitize. |
77 | 77 | */ |
78 | -function getpaid_unstandardize_amount( $amount ) { |
|
79 | - return str_replace( '.', wpinv_decimal_separator(), $amount ); |
|
78 | +function getpaid_unstandardize_amount($amount) { |
|
79 | + return str_replace('.', wpinv_decimal_separator(), $amount); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param string $amount The amount to sanitize. |
86 | 86 | */ |
87 | -function wpinv_sanitize_amount( $amount ) { |
|
87 | +function wpinv_sanitize_amount($amount) { |
|
88 | 88 | |
89 | - if ( is_numeric( $amount ) ) { |
|
90 | - return floatval( $amount ); |
|
89 | + if (is_numeric($amount)) { |
|
90 | + return floatval($amount); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Separate the decimals and thousands. |
94 | - $amount = explode( wpinv_decimal_separator(), $amount ); |
|
94 | + $amount = explode(wpinv_decimal_separator(), $amount); |
|
95 | 95 | |
96 | 96 | // Remove thousands. |
97 | - $amount[0] = str_replace( wpinv_thousands_separator(), '', $amount[0] ); |
|
97 | + $amount[0] = str_replace(wpinv_thousands_separator(), '', $amount[0]); |
|
98 | 98 | |
99 | 99 | // Convert back to string. |
100 | - $amount = count( $amount ) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
100 | + $amount = count($amount) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
101 | 101 | |
102 | 102 | // Cast the remaining to a float. |
103 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
103 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
104 | 104 | |
105 | 105 | } |
106 | 106 | |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * @param float $amount |
111 | 111 | * @param float|string|int|null $decimals |
112 | 112 | */ |
113 | -function wpinv_round_amount( $amount, $decimals = null, $use_sprintf = false ) { |
|
113 | +function wpinv_round_amount($amount, $decimals = null, $use_sprintf = false) { |
|
114 | 114 | |
115 | - if ( $decimals === null ) { |
|
115 | + if ($decimals === null) { |
|
116 | 116 | $decimals = wpinv_decimals(); |
117 | 117 | } |
118 | 118 | |
119 | - if ( $use_sprintf ) { |
|
120 | - $amount = sprintf( "%.{$decimals}f", (float) $amount ); |
|
119 | + if ($use_sprintf) { |
|
120 | + $amount = sprintf("%.{$decimals}f", (float) $amount); |
|
121 | 121 | } else { |
122 | - $amount = round( (float) $amount, absint( $decimals ) ); |
|
122 | + $amount = round((float) $amount, absint($decimals)); |
|
123 | 123 | } |
124 | 124 | |
125 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
125 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -134,32 +134,32 @@ discard block |
||
134 | 134 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
135 | 135 | * @return array |
136 | 136 | */ |
137 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
137 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
138 | 138 | |
139 | 139 | $invoice_statuses = array( |
140 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
141 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
142 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
143 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
144 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
145 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
146 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
147 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
140 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
141 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
142 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
143 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
144 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
145 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
146 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
147 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | - if ( $draft ) { |
|
151 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
150 | + if ($draft) { |
|
151 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
152 | 152 | } |
153 | 153 | |
154 | - if ( $trashed ) { |
|
155 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
154 | + if ($trashed) { |
|
155 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
156 | 156 | } |
157 | 157 | |
158 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
158 | + if ($invoice instanceof WPInv_Invoice) { |
|
159 | 159 | $invoice = $invoice->get_post_type(); |
160 | 160 | } |
161 | 161 | |
162 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
162 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @param string $status The raw status |
169 | 169 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
170 | 170 | */ |
171 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
172 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
173 | - $status = isset( $statuses[ $status ] ) ? $statuses[ $status ] : $status; |
|
171 | +function wpinv_status_nicename($status, $invoice = false) { |
|
172 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
173 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
174 | 174 | |
175 | - return sanitize_text_field( $status ); |
|
175 | + return sanitize_text_field($status); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @param string $current |
182 | 182 | */ |
183 | -function wpinv_get_currency( $current = '' ) { |
|
183 | +function wpinv_get_currency($current = '') { |
|
184 | 184 | |
185 | - if ( empty( $current ) ) { |
|
186 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
185 | + if (empty($current)) { |
|
186 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
187 | 187 | } |
188 | 188 | |
189 | - return trim( strtoupper( $current ) ); |
|
189 | + return trim(strtoupper($current)); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -194,25 +194,25 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param string|null $currency The currency code. Defaults to the default currency. |
196 | 196 | */ |
197 | -function wpinv_currency_symbol( $currency = null ) { |
|
197 | +function wpinv_currency_symbol($currency = null) { |
|
198 | 198 | |
199 | 199 | // Prepare the currency. |
200 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
200 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
201 | 201 | |
202 | 202 | // Fetch all symbols. |
203 | 203 | $symbols = wpinv_get_currency_symbols(); |
204 | 204 | |
205 | 205 | // Fetch this currencies symbol. |
206 | - $currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : $currency; |
|
206 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
207 | 207 | |
208 | 208 | // Filter the symbol. |
209 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
209 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_currency_position() { |
213 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
213 | + $position = wpinv_get_option('currency_position', 'left'); |
|
214 | 214 | |
215 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
215 | + return apply_filters('wpinv_currency_position', $position); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @param $string|null $current |
222 | 222 | */ |
223 | -function wpinv_thousands_separator( $current = null ) { |
|
223 | +function wpinv_thousands_separator($current = null) { |
|
224 | 224 | |
225 | - if ( null == $current ) { |
|
226 | - $current = wpinv_get_option( 'thousands_separator', ',' ); |
|
225 | + if (null == $current) { |
|
226 | + $current = wpinv_get_option('thousands_separator', ','); |
|
227 | 227 | } |
228 | 228 | |
229 | - return trim( $current ); |
|
229 | + return trim($current); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,13 +234,13 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @param $string|null $current |
236 | 236 | */ |
237 | -function wpinv_decimal_separator( $current = null ) { |
|
237 | +function wpinv_decimal_separator($current = null) { |
|
238 | 238 | |
239 | - if ( null == $current ) { |
|
240 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
239 | + if (null == $current) { |
|
240 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
241 | 241 | } |
242 | 242 | |
243 | - return trim( $current ); |
|
243 | + return trim($current); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -248,27 +248,27 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @param $string|null $current |
250 | 250 | */ |
251 | -function wpinv_decimals( $current = null ) { |
|
251 | +function wpinv_decimals($current = null) { |
|
252 | 252 | |
253 | - if ( null == $current ) { |
|
254 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
253 | + if (null == $current) { |
|
254 | + $current = wpinv_get_option('decimals', 2); |
|
255 | 255 | } |
256 | 256 | |
257 | - return absint( $current ); |
|
257 | + return absint($current); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Retrieves a list of all supported currencies. |
262 | 262 | */ |
263 | 263 | function wpinv_get_currencies() { |
264 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
264 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | 268 | * Retrieves a list of all currency symbols. |
269 | 269 | */ |
270 | 270 | function wpinv_get_currency_symbols() { |
271 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
271 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $currency_pos = wpinv_currency_position(); |
281 | 281 | $format = '%1$s%2$s'; |
282 | 282 | |
283 | - switch ( $currency_pos ) { |
|
283 | + switch ($currency_pos) { |
|
284 | 284 | case 'left': |
285 | 285 | $format = '%1$s%2$s'; |
286 | 286 | break; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | break; |
296 | 296 | } |
297 | 297 | |
298 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
298 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | * @param string $currency Currency. |
306 | 306 | * @return string |
307 | 307 | */ |
308 | -function wpinv_the_price( $amount = 0, $currency = '' ) { |
|
309 | - echo wp_kses_post( wpinv_price( $amount, $currency ) ); |
|
308 | +function wpinv_the_price($amount = 0, $currency = '') { |
|
309 | + echo wp_kses_post(wpinv_price($amount, $currency)); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -316,25 +316,25 @@ discard block |
||
316 | 316 | * @param string $currency Currency. |
317 | 317 | * @return string |
318 | 318 | */ |
319 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
319 | +function wpinv_price($amount = 0, $currency = '') { |
|
320 | 320 | |
321 | 321 | // Backwards compatibility. |
322 | - $amount = wpinv_sanitize_amount( $amount ); |
|
322 | + $amount = wpinv_sanitize_amount($amount); |
|
323 | 323 | |
324 | 324 | // Prepare variables. |
325 | - $currency = wpinv_get_currency( $currency ); |
|
325 | + $currency = wpinv_get_currency($currency); |
|
326 | 326 | $amount = (float) $amount; |
327 | 327 | $unformatted_amount = $amount; |
328 | 328 | $negative = $amount < 0; |
329 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
330 | - $amount = wpinv_format_amount( $amount ); |
|
329 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
330 | + $amount = wpinv_format_amount($amount); |
|
331 | 331 | |
332 | 332 | // Format the amount. |
333 | 333 | $format = getpaid_get_price_format(); |
334 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
334 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
335 | 335 | |
336 | 336 | // Filter the formatting. |
337 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
337 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -345,25 +345,25 @@ discard block |
||
345 | 345 | * @param bool $calculate Whether or not to apply separators. |
346 | 346 | * @return string |
347 | 347 | */ |
348 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
348 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
349 | 349 | $thousands_sep = wpinv_thousands_separator(); |
350 | 350 | $decimal_sep = wpinv_decimal_separator(); |
351 | - $decimals = wpinv_decimals( $decimals ); |
|
352 | - $amount = wpinv_sanitize_amount( $amount ); |
|
351 | + $decimals = wpinv_decimals($decimals); |
|
352 | + $amount = wpinv_sanitize_amount($amount); |
|
353 | 353 | |
354 | - if ( $calculate ) { |
|
354 | + if ($calculate) { |
|
355 | 355 | return $amount; |
356 | 356 | } |
357 | 357 | |
358 | 358 | // Fomart the amount. |
359 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
359 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
360 | 360 | } |
361 | 361 | |
362 | -function wpinv_sanitize_key( $key ) { |
|
362 | +function wpinv_sanitize_key($key) { |
|
363 | 363 | $raw_key = $key; |
364 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
364 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
365 | 365 | |
366 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
366 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * |
372 | 372 | * @param $str the file whose extension should be retrieved. |
373 | 373 | */ |
374 | -function wpinv_get_file_extension( $str ) { |
|
375 | - $filetype = wp_check_filetype( $str ); |
|
374 | +function wpinv_get_file_extension($str) { |
|
375 | + $filetype = wp_check_filetype($str); |
|
376 | 376 | return $filetype['ext']; |
377 | 377 | } |
378 | 378 | |
@@ -381,16 +381,16 @@ discard block |
||
381 | 381 | * |
382 | 382 | * @param string $string |
383 | 383 | */ |
384 | -function wpinv_string_is_image_url( $string ) { |
|
385 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
386 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
384 | +function wpinv_string_is_image_url($string) { |
|
385 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
386 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
390 | 390 | * Returns the current URL. |
391 | 391 | */ |
392 | 392 | function wpinv_get_current_page_url() { |
393 | - return esc_url( add_query_arg( array() ) ); |
|
393 | + return esc_url(add_query_arg(array())); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,46 +400,46 @@ discard block |
||
400 | 400 | * @param string $name Constant name. |
401 | 401 | * @param mixed $value Value. |
402 | 402 | */ |
403 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
404 | - if ( ! defined( $name ) ) { |
|
405 | - define( $name, $value ); |
|
403 | +function getpaid_maybe_define_constant($name, $value) { |
|
404 | + if (!defined($name)) { |
|
405 | + define($name, $value); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | function wpinv_get_php_arg_separator_output() { |
410 | - return ini_get( 'arg_separator.output' ); |
|
410 | + return ini_get('arg_separator.output'); |
|
411 | 411 | } |
412 | 412 | |
413 | -function wpinv_rgb_from_hex( $color ) { |
|
414 | - $color = str_replace( '#', '', $color ); |
|
413 | +function wpinv_rgb_from_hex($color) { |
|
414 | + $color = str_replace('#', '', $color); |
|
415 | 415 | |
416 | 416 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
417 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
418 | - if ( empty( $color ) ) { |
|
417 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
418 | + if (empty($color)) { |
|
419 | 419 | return null; |
420 | 420 | } |
421 | 421 | |
422 | - $color = str_split( $color ); |
|
422 | + $color = str_split($color); |
|
423 | 423 | |
424 | 424 | $rgb = array(); |
425 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
426 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
427 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
425 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
426 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
427 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
428 | 428 | |
429 | 429 | return $rgb; |
430 | 430 | } |
431 | 431 | |
432 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
433 | - $base = wpinv_rgb_from_hex( $color ); |
|
432 | +function wpinv_hex_darker($color, $factor = 30) { |
|
433 | + $base = wpinv_rgb_from_hex($color); |
|
434 | 434 | $color = '#'; |
435 | 435 | |
436 | - foreach ( $base as $k => $v ) { |
|
436 | + foreach ($base as $k => $v) { |
|
437 | 437 | $amount = $v / 100; |
438 | - $amount = round( $amount * $factor ); |
|
438 | + $amount = round($amount * $factor); |
|
439 | 439 | $new_decimal = $v - $amount; |
440 | 440 | |
441 | - $new_hex_component = dechex( $new_decimal ); |
|
442 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
441 | + $new_hex_component = dechex($new_decimal); |
|
442 | + if (strlen($new_hex_component) < 2) { |
|
443 | 443 | $new_hex_component = '0' . $new_hex_component; |
444 | 444 | } |
445 | 445 | $color .= $new_hex_component; |
@@ -448,18 +448,18 @@ discard block |
||
448 | 448 | return $color; |
449 | 449 | } |
450 | 450 | |
451 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
452 | - $base = wpinv_rgb_from_hex( $color ); |
|
451 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
452 | + $base = wpinv_rgb_from_hex($color); |
|
453 | 453 | $color = '#'; |
454 | 454 | |
455 | - foreach ( $base as $k => $v ) { |
|
455 | + foreach ($base as $k => $v) { |
|
456 | 456 | $amount = 255 - $v; |
457 | 457 | $amount = $amount / 100; |
458 | - $amount = round( $amount * $factor ); |
|
458 | + $amount = round($amount * $factor); |
|
459 | 459 | $new_decimal = $v + $amount; |
460 | 460 | |
461 | - $new_hex_component = dechex( $new_decimal ); |
|
462 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
461 | + $new_hex_component = dechex($new_decimal); |
|
462 | + if (strlen($new_hex_component) < 2) { |
|
463 | 463 | $new_hex_component = '0' . $new_hex_component; |
464 | 464 | } |
465 | 465 | $color .= $new_hex_component; |
@@ -468,22 +468,22 @@ discard block |
||
468 | 468 | return $color; |
469 | 469 | } |
470 | 470 | |
471 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
472 | - $hex = str_replace( '#', '', $color ); |
|
471 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
472 | + $hex = str_replace('#', '', $color); |
|
473 | 473 | |
474 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
475 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
476 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
474 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
475 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
476 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
477 | 477 | |
478 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
478 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
479 | 479 | |
480 | 480 | return $brightness > 155 ? $dark : $light; |
481 | 481 | } |
482 | 482 | |
483 | -function wpinv_format_hex( $hex ) { |
|
484 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
483 | +function wpinv_format_hex($hex) { |
|
484 | + $hex = trim(str_replace('#', '', $hex)); |
|
485 | 485 | |
486 | - if ( strlen( $hex ) == 3 ) { |
|
486 | + if (strlen($hex) == 3) { |
|
487 | 487 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
488 | 488 | } |
489 | 489 | |
@@ -503,12 +503,12 @@ discard block |
||
503 | 503 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
504 | 504 | * @return string |
505 | 505 | */ |
506 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
507 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
508 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
506 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
507 | + if (function_exists('mb_strimwidth')) { |
|
508 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
509 | 509 | } |
510 | 510 | |
511 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
511 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
@@ -520,28 +520,28 @@ discard block |
||
520 | 520 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
521 | 521 | * @return int Returns the number of characters in string. |
522 | 522 | */ |
523 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
524 | - if ( function_exists( 'mb_strlen' ) ) { |
|
525 | - return mb_strlen( $str, $encoding ); |
|
523 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
524 | + if (function_exists('mb_strlen')) { |
|
525 | + return mb_strlen($str, $encoding); |
|
526 | 526 | } |
527 | 527 | |
528 | - return strlen( $str ); |
|
528 | + return strlen($str); |
|
529 | 529 | } |
530 | 530 | |
531 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
532 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
533 | - return mb_strtolower( $str, $encoding ); |
|
531 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
532 | + if (function_exists('mb_strtolower')) { |
|
533 | + return mb_strtolower($str, $encoding); |
|
534 | 534 | } |
535 | 535 | |
536 | - return strtolower( $str ); |
|
536 | + return strtolower($str); |
|
537 | 537 | } |
538 | 538 | |
539 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
540 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
541 | - return mb_strtoupper( $str, $encoding ); |
|
539 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
540 | + if (function_exists('mb_strtoupper')) { |
|
541 | + return mb_strtoupper($str, $encoding); |
|
542 | 542 | } |
543 | 543 | |
544 | - return strtoupper( $str ); |
|
544 | + return strtoupper($str); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -555,12 +555,12 @@ discard block |
||
555 | 555 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
556 | 556 | * @return int Returns the position of the first occurrence of search in the string. |
557 | 557 | */ |
558 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
559 | - if ( function_exists( 'mb_strpos' ) ) { |
|
560 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
558 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
559 | + if (function_exists('mb_strpos')) { |
|
560 | + return mb_strpos($str, $find, $offset, $encoding); |
|
561 | 561 | } |
562 | 562 | |
563 | - return strpos( $str, $find, $offset ); |
|
563 | + return strpos($str, $find, $offset); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -574,12 +574,12 @@ discard block |
||
574 | 574 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
575 | 575 | * @return int Returns the position of the last occurrence of search. |
576 | 576 | */ |
577 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
578 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
579 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
577 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
578 | + if (function_exists('mb_strrpos')) { |
|
579 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
580 | 580 | } |
581 | 581 | |
582 | - return strrpos( $str, $find, $offset ); |
|
582 | + return strrpos($str, $find, $offset); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | /** |
@@ -594,16 +594,16 @@ discard block |
||
594 | 594 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
595 | 595 | * @return string |
596 | 596 | */ |
597 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
598 | - if ( function_exists( 'mb_substr' ) ) { |
|
599 | - if ( null === $length ) { |
|
600 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
597 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
598 | + if (function_exists('mb_substr')) { |
|
599 | + if (null === $length) { |
|
600 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
601 | 601 | } else { |
602 | - return mb_substr( $str, $start, $length, $encoding ); |
|
602 | + return mb_substr($str, $start, $length, $encoding); |
|
603 | 603 | } |
604 | 604 | } |
605 | 605 | |
606 | - return substr( $str, $start, $length ); |
|
606 | + return substr($str, $start, $length); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -615,48 +615,48 @@ discard block |
||
615 | 615 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
616 | 616 | * @return string The width of string. |
617 | 617 | */ |
618 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
619 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
620 | - return mb_strwidth( $str, $encoding ); |
|
618 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
619 | + if (function_exists('mb_strwidth')) { |
|
620 | + return mb_strwidth($str, $encoding); |
|
621 | 621 | } |
622 | 622 | |
623 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
623 | + return wpinv_utf8_strlen($str, $encoding); |
|
624 | 624 | } |
625 | 625 | |
626 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
627 | - if ( function_exists( 'mb_strlen' ) ) { |
|
628 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
626 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
627 | + if (function_exists('mb_strlen')) { |
|
628 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
629 | 629 | $str_end = ''; |
630 | 630 | |
631 | - if ( $lower_str_end ) { |
|
632 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
631 | + if ($lower_str_end) { |
|
632 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
633 | 633 | } else { |
634 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
634 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | return $first_letter . $str_end; |
638 | 638 | } |
639 | 639 | |
640 | - return ucfirst( $str ); |
|
640 | + return ucfirst($str); |
|
641 | 641 | } |
642 | 642 | |
643 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
644 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
645 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
643 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
644 | + if (function_exists('mb_convert_case')) { |
|
645 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
646 | 646 | } |
647 | 647 | |
648 | - return ucwords( $str ); |
|
648 | + return ucwords($str); |
|
649 | 649 | } |
650 | 650 | |
651 | -function wpinv_period_in_days( $period, $unit ) { |
|
652 | - $period = absint( $period ); |
|
651 | +function wpinv_period_in_days($period, $unit) { |
|
652 | + $period = absint($period); |
|
653 | 653 | |
654 | - if ( $period > 0 ) { |
|
655 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
654 | + if ($period > 0) { |
|
655 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
656 | 656 | $period = $period * 7; |
657 | - } elseif ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
657 | + } elseif (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
658 | 658 | $period = $period * 30; |
659 | - } elseif ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
659 | + } elseif (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
660 | 660 | $period = $period * 365; |
661 | 661 | } |
662 | 662 | } |
@@ -664,14 +664,14 @@ discard block |
||
664 | 664 | return $period; |
665 | 665 | } |
666 | 666 | |
667 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
668 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
669 | - return cal_days_in_month( $calendar, $month, $year ); |
|
667 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
668 | + if (function_exists('cal_days_in_month')) { |
|
669 | + return cal_days_in_month($calendar, $month, $year); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Fallback in case the calendar extension is not loaded in PHP |
673 | 673 | // Only supports Gregorian calendar |
674 | - return gmdate( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
674 | + return gmdate('t', mktime(0, 0, 0, $month, 1, $year)); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | /** |
@@ -682,27 +682,27 @@ discard block |
||
682 | 682 | * |
683 | 683 | * @return string |
684 | 684 | */ |
685 | -function wpi_help_tip( $tip, $allow_html = false, $is_vue = false, $echo = false ) { |
|
685 | +function wpi_help_tip($tip, $allow_html = false, $is_vue = false, $echo = false) { |
|
686 | 686 | |
687 | - if ( $allow_html ) { |
|
688 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
687 | + if ($allow_html) { |
|
688 | + $tip = wpi_sanitize_tooltip($tip); |
|
689 | 689 | } else { |
690 | - $tip = strip_tags( $tip ); |
|
690 | + $tip = strip_tags($tip); |
|
691 | 691 | } |
692 | 692 | |
693 | - if ( $is_vue ) { |
|
693 | + if ($is_vue) { |
|
694 | 694 | |
695 | - if ( $echo ) { |
|
696 | - echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
695 | + if ($echo) { |
|
696 | + echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
697 | 697 | } else { |
698 | - return '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
698 | + return '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
699 | 699 | } |
700 | 700 | } |
701 | 701 | |
702 | - if ( $echo ) { |
|
703 | - echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
702 | + if ($echo) { |
|
703 | + echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
704 | 704 | } else { |
705 | - return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
705 | + return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
706 | 706 | } |
707 | 707 | } |
708 | 708 | |
@@ -714,9 +714,9 @@ discard block |
||
714 | 714 | * @param string $var |
715 | 715 | * @return string |
716 | 716 | */ |
717 | -function wpi_sanitize_tooltip( $var ) { |
|
717 | +function wpi_sanitize_tooltip($var) { |
|
718 | 718 | return wp_kses( |
719 | - html_entity_decode( $var ), |
|
719 | + html_entity_decode($var), |
|
720 | 720 | array( |
721 | 721 | 'br' => array(), |
722 | 722 | 'em' => array(), |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | */ |
740 | 740 | function wpinv_get_screen_ids() { |
741 | 741 | |
742 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
742 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
743 | 743 | |
744 | 744 | $screen_ids = array( |
745 | 745 | 'toplevel_page_' . $screen_id, |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | 'gp-setup', // setup wizard |
762 | 762 | ); |
763 | 763 | |
764 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
764 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /** |
@@ -772,14 +772,14 @@ discard block |
||
772 | 772 | * @param array|string $list List of values. |
773 | 773 | * @return array Sanitized array of values. |
774 | 774 | */ |
775 | -function wpinv_parse_list( $list ) { |
|
775 | +function wpinv_parse_list($list) { |
|
776 | 776 | |
777 | - if ( empty( $list ) ) { |
|
777 | + if (empty($list)) { |
|
778 | 778 | $list = array(); |
779 | 779 | } |
780 | 780 | |
781 | - if ( ! is_array( $list ) ) { |
|
782 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
781 | + if (!is_array($list)) { |
|
782 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | return $list; |
@@ -793,8 +793,8 @@ discard block |
||
793 | 793 | * @param string $key Type of data to fetch. |
794 | 794 | * @return mixed Fetched data. |
795 | 795 | */ |
796 | -function wpinv_get_data( $key ) { |
|
797 | - return apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
796 | +function wpinv_get_data($key) { |
|
797 | + return apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | /** |
@@ -806,10 +806,10 @@ discard block |
||
806 | 806 | * @param bool $first_empty Whether or not the first item in the list should be empty |
807 | 807 | * @return mixed Fetched data. |
808 | 808 | */ |
809 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
809 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
810 | 810 | |
811 | - if ( ! empty( $options ) && $first_empty ) { |
|
812 | - return array_merge( array( '' => '' ), $options ); |
|
811 | + if (!empty($options) && $first_empty) { |
|
812 | + return array_merge(array('' => ''), $options); |
|
813 | 813 | } |
814 | 814 | return $options; |
815 | 815 | |
@@ -821,21 +821,21 @@ discard block |
||
821 | 821 | * @param mixed $var Data to sanitize. |
822 | 822 | * @return string|array |
823 | 823 | */ |
824 | -function wpinv_clean( $var ) { |
|
824 | +function wpinv_clean($var) { |
|
825 | 825 | |
826 | - if ( is_array( $var ) ) { |
|
827 | - return array_map( 'wpinv_clean', $var ); |
|
826 | + if (is_array($var)) { |
|
827 | + return array_map('wpinv_clean', $var); |
|
828 | 828 | } |
829 | 829 | |
830 | - if ( is_object( $var ) ) { |
|
831 | - $object_vars = get_object_vars( $var ); |
|
832 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
833 | - $var->$property_name = wpinv_clean( $property_value ); |
|
830 | + if (is_object($var)) { |
|
831 | + $object_vars = get_object_vars($var); |
|
832 | + foreach ($object_vars as $property_name => $property_value) { |
|
833 | + $var->$property_name = wpinv_clean($property_value); |
|
834 | 834 | } |
835 | 835 | return $var; |
836 | 836 | } |
837 | 837 | |
838 | - return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
|
838 | + return is_string($var) ? sanitize_text_field(stripslashes($var)) : $var; |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -844,43 +844,43 @@ discard block |
||
844 | 844 | * @param string $str Data to convert. |
845 | 845 | * @return string|array |
846 | 846 | */ |
847 | -function getpaid_convert_price_string_to_options( $str ) { |
|
847 | +function getpaid_convert_price_string_to_options($str) { |
|
848 | 848 | |
849 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
850 | - $options = array(); |
|
849 | + $raw_options = array_map('trim', explode(',', $str)); |
|
850 | + $options = array(); |
|
851 | 851 | |
852 | - foreach ( $raw_options as $option ) { |
|
852 | + foreach ($raw_options as $option) { |
|
853 | 853 | |
854 | - if ( '' == $option ) { |
|
854 | + if ('' == $option) { |
|
855 | 855 | continue; |
856 | 856 | } |
857 | 857 | |
858 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
858 | + $option = array_map('trim', explode('|', $option)); |
|
859 | 859 | |
860 | 860 | $price = null; |
861 | 861 | $label = null; |
862 | 862 | |
863 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
864 | - $label = $option[0]; |
|
863 | + if (isset($option[0]) && '' != $option[0]) { |
|
864 | + $label = $option[0]; |
|
865 | 865 | } |
866 | 866 | |
867 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
867 | + if (isset($option[1]) && '' != $option[1]) { |
|
868 | 868 | $price = $option[1]; |
869 | 869 | } |
870 | 870 | |
871 | - if ( ! isset( $price ) ) { |
|
871 | + if (!isset($price)) { |
|
872 | 872 | $price = $label; |
873 | 873 | } |
874 | 874 | |
875 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
875 | + if (!isset($price) || !is_numeric($price)) { |
|
876 | 876 | continue; |
877 | 877 | } |
878 | 878 | |
879 | - if ( ! isset( $label ) ) { |
|
879 | + if (!isset($label)) { |
|
880 | 880 | $label = $price; |
881 | 881 | } |
882 | 882 | |
883 | - $options[ "$label|$price" ] = $label; |
|
883 | + $options["$label|$price"] = $label; |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | return $options; |
@@ -889,14 +889,14 @@ discard block |
||
889 | 889 | /** |
890 | 890 | * Returns the help tip. |
891 | 891 | */ |
892 | -function getpaid_get_help_tip( $tip, $additional_classes = '', $echo = false ) { |
|
892 | +function getpaid_get_help_tip($tip, $additional_classes = '', $echo = false) { |
|
893 | 893 | $classes = 'wpi-help-tip dashicons dashicons-editor-help ' . $additional_classes; |
894 | - $tip = esc_attr( $tip ); |
|
894 | + $tip = esc_attr($tip); |
|
895 | 895 | |
896 | - if ( $echo ) { |
|
897 | - echo '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
896 | + if ($echo) { |
|
897 | + echo '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
898 | 898 | } else { |
899 | - return '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
899 | + return '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | } |
@@ -904,18 +904,18 @@ discard block |
||
904 | 904 | /** |
905 | 905 | * Formats a date |
906 | 906 | */ |
907 | -function getpaid_format_date( $date, $with_time = false ) { |
|
907 | +function getpaid_format_date($date, $with_time = false) { |
|
908 | 908 | |
909 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
909 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
910 | 910 | return ''; |
911 | 911 | } |
912 | 912 | |
913 | 913 | $format = getpaid_date_format(); |
914 | 914 | |
915 | - if ( $with_time ) { |
|
915 | + if ($with_time) { |
|
916 | 916 | $format .= ' ' . getpaid_time_format(); |
917 | 917 | } |
918 | - return date_i18n( $format, strtotime( $date ) ); |
|
918 | + return date_i18n($format, strtotime($date)); |
|
919 | 919 | |
920 | 920 | } |
921 | 921 | |
@@ -924,9 +924,9 @@ discard block |
||
924 | 924 | * |
925 | 925 | * @return string |
926 | 926 | */ |
927 | -function getpaid_format_date_value( $date, $default = '—', $with_time = false ) { |
|
928 | - $date = getpaid_format_date( $date, $with_time ); |
|
929 | - return empty( $date ) ? $default : $date; |
|
927 | +function getpaid_format_date_value($date, $default = '—', $with_time = false) { |
|
928 | + $date = getpaid_format_date($date, $with_time); |
|
929 | + return empty($date) ? $default : $date; |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | /** |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | * @return string |
936 | 936 | */ |
937 | 937 | function getpaid_date_format() { |
938 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
938 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | * @return string |
945 | 945 | */ |
946 | 946 | function getpaid_time_format() { |
947 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
947 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -954,16 +954,16 @@ discard block |
||
954 | 954 | * @param integer $limit Limit size in characters. |
955 | 955 | * @return string |
956 | 956 | */ |
957 | -function getpaid_limit_length( $string, $limit ) { |
|
957 | +function getpaid_limit_length($string, $limit) { |
|
958 | 958 | $str_limit = $limit - 3; |
959 | 959 | |
960 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
961 | - if ( mb_strlen( $string ) > $limit ) { |
|
962 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
960 | + if (function_exists('mb_strimwidth')) { |
|
961 | + if (mb_strlen($string) > $limit) { |
|
962 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
963 | 963 | } |
964 | 964 | } else { |
965 | - if ( strlen( $string ) > $limit ) { |
|
966 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
965 | + if (strlen($string) > $limit) { |
|
966 | + $string = substr($string, 0, $str_limit) . '...'; |
|
967 | 967 | } |
968 | 968 | } |
969 | 969 | return $string; |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | * @since 1.0.19 |
978 | 978 | */ |
979 | 979 | function getpaid_api() { |
980 | - return getpaid()->get( 'api' ); |
|
980 | + return getpaid()->get('api'); |
|
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | * @since 1.0.19 |
988 | 988 | */ |
989 | 989 | function getpaid_post_types() { |
990 | - return getpaid()->get( 'post_types' ); |
|
990 | + return getpaid()->get('post_types'); |
|
991 | 991 | } |
992 | 992 | |
993 | 993 | /** |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | * @since 1.0.19 |
998 | 998 | */ |
999 | 999 | function getpaid_session() { |
1000 | - return getpaid()->get( 'session' ); |
|
1000 | + return getpaid()->get('session'); |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | /** |
@@ -1007,7 +1007,7 @@ discard block |
||
1007 | 1007 | * @since 1.0.19 |
1008 | 1008 | */ |
1009 | 1009 | function getpaid_notes() { |
1010 | - return getpaid()->get( 'notes' ); |
|
1010 | + return getpaid()->get('notes'); |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | /** |
@@ -1016,7 +1016,7 @@ discard block |
||
1016 | 1016 | * @return GetPaid_Admin |
1017 | 1017 | */ |
1018 | 1018 | function getpaid_admin() { |
1019 | - return getpaid()->get( 'admin' ); |
|
1019 | + return getpaid()->get('admin'); |
|
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | /** |
@@ -1026,8 +1026,8 @@ discard block |
||
1026 | 1026 | * @param string $base the base url |
1027 | 1027 | * @return string |
1028 | 1028 | */ |
1029 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
1030 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
1029 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
1030 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
@@ -1035,11 +1035,11 @@ discard block |
||
1035 | 1035 | * |
1036 | 1036 | * @return string |
1037 | 1037 | */ |
1038 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
1038 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
1039 | 1039 | |
1040 | - $post_type = get_post_type_object( $post_type ); |
|
1040 | + $post_type = get_post_type_object($post_type); |
|
1041 | 1041 | |
1042 | - if ( ! is_object( $post_type ) ) { |
|
1042 | + if (!is_object($post_type)) { |
|
1043 | 1043 | return null; |
1044 | 1044 | } |
1045 | 1045 | |
@@ -1052,18 +1052,18 @@ discard block |
||
1052 | 1052 | * |
1053 | 1053 | * @return mixed|null |
1054 | 1054 | */ |
1055 | -function getpaid_get_array_field( $array, $key, $secondary_key = null ) { |
|
1055 | +function getpaid_get_array_field($array, $key, $secondary_key = null) { |
|
1056 | 1056 | |
1057 | - if ( ! is_array( $array ) ) { |
|
1057 | + if (!is_array($array)) { |
|
1058 | 1058 | return null; |
1059 | 1059 | } |
1060 | 1060 | |
1061 | - if ( ! empty( $secondary_key ) ) { |
|
1062 | - $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array(); |
|
1063 | - return getpaid_get_array_field( $array, $key ); |
|
1061 | + if (!empty($secondary_key)) { |
|
1062 | + $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array(); |
|
1063 | + return getpaid_get_array_field($array, $key); |
|
1064 | 1064 | } |
1065 | 1065 | |
1066 | - return isset( $array[ $key ] ) ? $array[ $key ] : null; |
|
1066 | + return isset($array[$key]) ? $array[$key] : null; |
|
1067 | 1067 | |
1068 | 1068 | } |
1069 | 1069 | |
@@ -1072,12 +1072,12 @@ discard block |
||
1072 | 1072 | * |
1073 | 1073 | * @return array |
1074 | 1074 | */ |
1075 | -function getpaid_array_merge_if_empty( $args, $defaults ) { |
|
1075 | +function getpaid_array_merge_if_empty($args, $defaults) { |
|
1076 | 1076 | |
1077 | - foreach ( $defaults as $key => $value ) { |
|
1077 | + foreach ($defaults as $key => $value) { |
|
1078 | 1078 | |
1079 | - if ( empty( $args[ $key ] ) ) { |
|
1080 | - $args[ $key ] = $value; |
|
1079 | + if (empty($args[$key])) { |
|
1080 | + $args[$key] = $value; |
|
1081 | 1081 | } |
1082 | 1082 | } |
1083 | 1083 | |
@@ -1094,12 +1094,12 @@ discard block |
||
1094 | 1094 | |
1095 | 1095 | $types = get_allowed_mime_types(); |
1096 | 1096 | |
1097 | - if ( isset( $types['htm|html'] ) ) { |
|
1098 | - unset( $types['htm|html'] ); |
|
1097 | + if (isset($types['htm|html'])) { |
|
1098 | + unset($types['htm|html']); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | - if ( isset( $types['js'] ) ) { |
|
1102 | - unset( $types['js'] ); |
|
1101 | + if (isset($types['js'])) { |
|
1102 | + unset($types['js']); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | return $types; |
@@ -1107,21 +1107,21 @@ discard block |
||
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | |
1110 | -function getpaid_user_delete_invoice( $data ) { |
|
1110 | +function getpaid_user_delete_invoice($data) { |
|
1111 | 1111 | |
1112 | 1112 | // Ensure there is an invoice to delete. |
1113 | - if ( empty( $data['invoice_id'] ) ) { |
|
1113 | + if (empty($data['invoice_id'])) { |
|
1114 | 1114 | return; |
1115 | 1115 | } |
1116 | 1116 | |
1117 | - $invoice = new WPInv_Invoice( (int) $data['invoice_id'] ); |
|
1117 | + $invoice = new WPInv_Invoice((int) $data['invoice_id']); |
|
1118 | 1118 | |
1119 | 1119 | // Ensure that it exists and that it belongs to the current user. |
1120 | - if ( ! $invoice->exists() || $invoice->get_customer_id() != get_current_user_id() ) { |
|
1120 | + if (!$invoice->exists() || $invoice->get_customer_id() != get_current_user_id()) { |
|
1121 | 1121 | $notice = 'perm_delete_invoice'; |
1122 | 1122 | |
1123 | 1123 | // Can it be deleted? |
1124 | - } elseif ( ! $invoice->needs_payment() ) { |
|
1124 | + } elseif (!$invoice->needs_payment()) { |
|
1125 | 1125 | $notice = 'cannot_delete_invoice'; |
1126 | 1126 | |
1127 | 1127 | // Delete it. |
@@ -1140,8 +1140,8 @@ discard block |
||
1140 | 1140 | ) |
1141 | 1141 | ); |
1142 | 1142 | |
1143 | - wp_safe_redirect( $redirect ); |
|
1143 | + wp_safe_redirect($redirect); |
|
1144 | 1144 | exit; |
1145 | 1145 | |
1146 | 1146 | } |
1147 | -add_action( 'getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice' ); |
|
1147 | +add_action('getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice'); |
@@ -12,184 +12,184 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
133 | 117 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
138 | 125 | |
139 | - return $invoice; |
|
140 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
141 | 131 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
132 | + $invoice = $submission->get_invoice(); |
|
150 | 133 | |
151 | - $submission = $this->payment_form_submission; |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
152 | 138 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | if ( empty( $user ) ) { |
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | + $name = implode( '', array_filter( $name ) ); |
|
202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
203 | 203 | |
204 | - // (Maybe) send new user notification. |
|
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
208 | - } |
|
209 | - } |
|
204 | + // (Maybe) send new user notification. |
|
205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | 211 | if ( is_wp_error( $user ) ) { |
212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | |
215 | 215 | if ( is_numeric( $user ) ) { |
216 | 216 | return $user; |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - return $user->ID; |
|
219 | + return $user->ID; |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Prepares submission data for saving to the database. |
225 | 225 | * |
226 | - * @return array |
|
226 | + * @return array |
|
227 | 227 | */ |
228 | 228 | public function prepare_submission_data_for_saving() { |
229 | 229 | |
230 | - $submission = $this->payment_form_submission; |
|
230 | + $submission = $this->payment_form_submission; |
|
231 | 231 | |
232 | - // Prepared submission details. |
|
232 | + // Prepared submission details. |
|
233 | 233 | $prepared = array( |
234 | - 'all' => array(), |
|
235 | - 'meta' => array(), |
|
236 | - ); |
|
234 | + 'all' => array(), |
|
235 | + 'meta' => array(), |
|
236 | + ); |
|
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | - // Loop through the submitted details. |
|
241 | + // Loop through the submitted details. |
|
242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
243 | 243 | |
244 | - // Skip premade fields. |
|
244 | + // Skip premade fields. |
|
245 | 245 | if ( ! empty( $field['premade'] ) ) { |
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | - // Ensure address is provided. |
|
250 | - if ( $field['type'] == 'address' ) { |
|
249 | + // Ensure address is provided. |
|
250 | + if ( $field['type'] == 'address' ) { |
|
251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ( $field['fields'] as $address_field ) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
266 | 266 | // Handle misc fields. |
267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
268 | 268 | |
269 | - // Uploads. |
|
270 | - if ( $field['type'] === 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
269 | + // Uploads. |
|
270 | + if ( $field['type'] === 'file_upload' ) { |
|
271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | - } |
|
273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | + } |
|
276 | 276 | |
277 | - $value = array(); |
|
277 | + $value = array(); |
|
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | - $value[] = sprintf( |
|
281 | - '<a href="%s" target="_blank">%s</a>', |
|
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
284 | - ); |
|
285 | - } |
|
279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + $value[] = sprintf( |
|
281 | + '<a href="%s" target="_blank">%s</a>', |
|
282 | + esc_url_raw( $url ), |
|
283 | + esc_html( $name ) |
|
284 | + ); |
|
285 | + } |
|
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode( ' | ', $value ); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] === 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | - } else { |
|
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | - } |
|
289 | + } elseif ( $field['type'] === 'checkbox' ) { |
|
290 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | + } else { |
|
292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
@@ -298,188 +298,188 @@ discard block |
||
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | - } |
|
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | + } |
|
304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | 305 | |
306 | 306 | } |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | - return $prepared; |
|
309 | + return $prepared; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Retrieves address details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
318 | - * @param string $type |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | + * @param string $type |
|
319 | 319 | */ |
320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
321 | 321 | |
322 | - $data = $this->payment_form_submission->get_data(); |
|
323 | - $type = sanitize_key( $type ); |
|
324 | - $address = array(); |
|
325 | - $prepared = array(); |
|
322 | + $data = $this->payment_form_submission->get_data(); |
|
323 | + $type = sanitize_key( $type ); |
|
324 | + $address = array(); |
|
325 | + $prepared = array(); |
|
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
329 | - } |
|
327 | + if ( ! empty( $data[ $type ] ) ) { |
|
328 | + $address = $data[ $type ]; |
|
329 | + } |
|
330 | 330 | |
331 | - // Clean address details. |
|
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | - } |
|
331 | + // Clean address details. |
|
332 | + foreach ( $address as $key => $value ) { |
|
333 | + $key = sanitize_key( $key ); |
|
334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
335 | + $value = wpinv_clean( $value ); |
|
336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | + } |
|
338 | 338 | |
339 | - // Filter address details. |
|
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
339 | + // Filter address details. |
|
340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | 341 | |
342 | - // Remove non-whitelisted values. |
|
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
342 | + // Remove non-whitelisted values. |
|
343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
347 | + /** |
|
348 | 348 | * Prepares the billing details. |
349 | 349 | * |
350 | - * @return array |
|
351 | - * @param WPInv_Invoice $invoice |
|
350 | + * @return array |
|
351 | + * @param WPInv_Invoice $invoice |
|
352 | 352 | */ |
353 | 353 | protected function prepare_billing_info( &$invoice ) { |
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | 356 | |
357 | - // Update the invoice with the billing details. |
|
358 | - $invoice->set_props( $billing_address ); |
|
357 | + // Update the invoice with the billing details. |
|
358 | + $invoice->set_props( $billing_address ); |
|
359 | 359 | |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
362 | + /** |
|
363 | 363 | * Prepares the shipping details. |
364 | 364 | * |
365 | - * @return array |
|
366 | - * @param WPInv_Invoice $invoice |
|
365 | + * @return array |
|
366 | + * @param WPInv_Invoice $invoice |
|
367 | 367 | */ |
368 | 368 | protected function prepare_shipping_info( $invoice ) { |
369 | 369 | |
370 | - $data = $this->payment_form_submission->get_data(); |
|
370 | + $data = $this->payment_form_submission->get_data(); |
|
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | - } |
|
372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + } |
|
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | 377 | |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Confirms the submission is valid and send users to the gateway. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice |
|
384 | - * @param array $prepared_payment_form_data |
|
385 | - * @param array $shipping |
|
386 | - */ |
|
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
380 | + /** |
|
381 | + * Confirms the submission is valid and send users to the gateway. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice |
|
384 | + * @param array $prepared_payment_form_data |
|
385 | + * @param array $shipping |
|
386 | + */ |
|
387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | 388 | |
389 | - // Ensure the invoice exists. |
|
389 | + // Ensure the invoice exists. |
|
390 | 390 | if ( ! $invoice->exists() ) { |
391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
392 | 392 | } |
393 | 393 | |
394 | - // Save payment form data. |
|
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
394 | + // Save payment form data. |
|
395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | - } |
|
400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + } |
|
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | - } |
|
404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + } |
|
407 | 407 | } |
408 | 408 | |
409 | - // Save payment form data. |
|
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
409 | + // Save payment form data. |
|
410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | 411 | if ( ! empty( $shipping ) ) { |
412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - // Backwards compatibility. |
|
415 | + // Backwards compatibility. |
|
416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment( $invoice ); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout( $invoice ); |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Processes the actual payment. |
|
427 | - * |
|
428 | - * @param WPInv_Invoice $invoice |
|
429 | - */ |
|
430 | - protected function process_payment( $invoice ) { |
|
425 | + /** |
|
426 | + * Processes the actual payment. |
|
427 | + * |
|
428 | + * @param WPInv_Invoice $invoice |
|
429 | + */ |
|
430 | + protected function process_payment( $invoice ) { |
|
431 | 431 | |
432 | - // Clear any checkout errors. |
|
433 | - wpinv_clear_errors(); |
|
432 | + // Clear any checkout errors. |
|
433 | + wpinv_clear_errors(); |
|
434 | 434 | |
435 | - // No need to send free invoices to the gateway. |
|
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
438 | - } |
|
435 | + // No need to send free invoices to the gateway. |
|
436 | + if ( $invoice->is_free() ) { |
|
437 | + $this->process_free_payment( $invoice ); |
|
438 | + } |
|
439 | 439 | |
440 | - $submission = $this->payment_form_submission; |
|
440 | + $submission = $this->payment_form_submission; |
|
441 | 441 | |
442 | - // Fires before sending to the gateway. |
|
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
442 | + // Fires before sending to the gateway. |
|
443 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
444 | 444 | |
445 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | - $submission_data = $submission->get_data(); |
|
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
445 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | + $submission_data = $submission->get_data(); |
|
447 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
449 | 449 | |
450 | - // Validate the currency. |
|
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency' ); |
|
453 | - } |
|
450 | + // Validate the currency. |
|
451 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | + wpinv_set_error( 'invalid_currency' ); |
|
453 | + } |
|
454 | 454 | |
455 | - // Check to see if we have any errors. |
|
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
458 | - } |
|
455 | + // Check to see if we have any errors. |
|
456 | + if ( wpinv_get_errors() ) { |
|
457 | + wpinv_send_back_to_checkout( $invoice ); |
|
458 | + } |
|
459 | 459 | |
460 | - // Send info to the gateway for payment processing |
|
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
460 | + // Send info to the gateway for payment processing |
|
461 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
462 | 462 | |
463 | - // Backwards compatibility. |
|
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
463 | + // Backwards compatibility. |
|
464 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | - /** |
|
469 | - * Marks the invoice as paid in case the checkout is free. |
|
470 | - * |
|
471 | - * @param WPInv_Invoice $invoice |
|
472 | - */ |
|
473 | - protected function process_free_payment( $invoice ) { |
|
468 | + /** |
|
469 | + * Marks the invoice as paid in case the checkout is free. |
|
470 | + * |
|
471 | + * @param WPInv_Invoice $invoice |
|
472 | + */ |
|
473 | + protected function process_free_payment( $invoice ) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | - $invoice->mark_paid(); |
|
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
475 | + $invoice->set_gateway( 'none' ); |
|
476 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | + $invoice->mark_paid(); |
|
478 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
479 | 479 | |
480 | - } |
|
480 | + } |
|
481 | 481 | |
482 | - /** |
|
482 | + /** |
|
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 153 | // Set-up the invoice details. |
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
163 | - |
|
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
156 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
157 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
159 | + $invoice->set_taxes($submission->get_taxes()); |
|
160 | + $invoice->set_discounts($submission->get_discounts()); |
|
161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
162 | + $invoice->set_currency($submission->get_currency()); |
|
163 | + |
|
164 | + if ($submission->has_shipping()) { |
|
165 | + $invoice->set_shipping($submission->get_shipping()); |
|
166 | 166 | } |
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
169 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
171 | + if ($submission->has_discount_code()) { |
|
172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
173 | 173 | } |
174 | 174 | |
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
175 | + getpaid_maybe_add_default_address($invoice); |
|
176 | 176 | return $invoice; |
177 | 177 | } |
178 | 178 | |
@@ -185,34 +185,34 @@ discard block |
||
185 | 185 | $submission = $this->payment_form_submission; |
186 | 186 | |
187 | 187 | // If this is an existing invoice... |
188 | - if ( $submission->has_invoice() ) { |
|
188 | + if ($submission->has_invoice()) { |
|
189 | 189 | return $submission->get_invoice()->get_user_id(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | // (Maybe) create the user. |
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $user ) ) { |
|
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
202 | - $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
|
199 | + if (empty($user)) { |
|
200 | + $name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing')); |
|
201 | + $name = implode('', array_filter($name)); |
|
202 | + $user = wpinv_create_user($submission->get_billing_email(), $name); |
|
203 | 203 | |
204 | 204 | // (Maybe) send new user notification. |
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
205 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
206 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
207 | + wp_send_new_user_notifications($user, 'user'); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_wp_error( $user ) ) { |
|
212 | - wp_send_json_error( $user->get_error_message() ); |
|
211 | + if (is_wp_error($user)) { |
|
212 | + wp_send_json_error($user->get_error_message()); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( is_numeric( $user ) ) { |
|
215 | + if (is_numeric($user)) { |
|
216 | 216 | return $user; |
217 | 217 | } |
218 | 218 | |
@@ -236,72 +236,72 @@ discard block |
||
236 | 236 | ); |
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | 241 | // Loop through the submitted details. |
242 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
242 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
243 | 243 | |
244 | 244 | // Skip premade fields. |
245 | - if ( ! empty( $field['premade'] ) ) { |
|
245 | + if (!empty($field['premade'])) { |
|
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | 249 | // Ensure address is provided. |
250 | - if ( $field['type'] == 'address' ) { |
|
251 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
250 | + if ($field['type'] == 'address') { |
|
251 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ($field['fields'] as $address_field) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
255 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { |
|
256 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
263 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
262 | + if (!$submission->is_required_field_set($field)) { |
|
263 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // Handle misc fields. |
267 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
267 | + if (isset($data[$field['id']])) { |
|
268 | 268 | |
269 | 269 | // Uploads. |
270 | - if ( $field['type'] === 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + if ($field['type'] === 'file_upload') { |
|
271 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
273 | + if (count($data[$field['id']]) > $max_file_num) { |
|
274 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $value = array(); |
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
279 | + foreach ($data[$field['id']] as $url => $name) { |
|
280 | 280 | $value[] = sprintf( |
281 | 281 | '<a href="%s" target="_blank">%s</a>', |
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
282 | + esc_url_raw($url), |
|
283 | + esc_html($name) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode(' | ', $value); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] === 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
289 | + } elseif ($field['type'] === 'checkbox') { |
|
290 | + $value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
291 | 291 | } else { |
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
292 | + $value = wp_kses_post($data[$field['id']]); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
297 | - if ( isset( $field['label'] ) ) { |
|
297 | + if (isset($field['label'])) { |
|
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if (!empty($field['add_meta'])) { |
|
302 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
303 | 303 | } |
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | } |
@@ -317,30 +317,30 @@ discard block |
||
317 | 317 | * @param WPInv_Invoice $invoice |
318 | 318 | * @param string $type |
319 | 319 | */ |
320 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
320 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
321 | 321 | |
322 | 322 | $data = $this->payment_form_submission->get_data(); |
323 | - $type = sanitize_key( $type ); |
|
323 | + $type = sanitize_key($type); |
|
324 | 324 | $address = array(); |
325 | 325 | $prepared = array(); |
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
327 | + if (!empty($data[$type])) { |
|
328 | + $address = $data[$type]; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Clean address details. |
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
332 | + foreach ($address as $key => $value) { |
|
333 | + $key = sanitize_key($key); |
|
334 | + $key = str_replace('wpinv_', '', $key); |
|
335 | + $value = wpinv_clean($value); |
|
336 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Filter address details. |
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
340 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
341 | 341 | |
342 | 342 | // Remove non-whitelisted values. |
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
343 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @return array |
351 | 351 | * @param WPInv_Invoice $invoice |
352 | 352 | */ |
353 | - protected function prepare_billing_info( &$invoice ) { |
|
353 | + protected function prepare_billing_info(&$invoice) { |
|
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
356 | 356 | |
357 | 357 | // Update the invoice with the billing details. |
358 | - $invoice->set_props( $billing_address ); |
|
358 | + $invoice->set_props($billing_address); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
@@ -365,15 +365,15 @@ discard block |
||
365 | 365 | * @return array |
366 | 366 | * @param WPInv_Invoice $invoice |
367 | 367 | */ |
368 | - protected function prepare_shipping_info( $invoice ) { |
|
368 | + protected function prepare_shipping_info($invoice) { |
|
369 | 369 | |
370 | 370 | $data = $this->payment_form_submission->get_data(); |
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
372 | + if (empty($data['same-shipping-address'])) { |
|
373 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
374 | 374 | } |
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details($invoice, 'billing'); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -384,41 +384,41 @@ discard block |
||
384 | 384 | * @param array $prepared_payment_form_data |
385 | 385 | * @param array $shipping |
386 | 386 | */ |
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
387 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
388 | 388 | |
389 | 389 | // Ensure the invoice exists. |
390 | - if ( ! $invoice->exists() ) { |
|
391 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
390 | + if (!$invoice->exists()) { |
|
391 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Save payment form data. |
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
395 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
396 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
397 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
398 | + if (!empty($prepared_payment_form_data)) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
400 | + if (!empty($prepared_payment_form_data['all'])) { |
|
401 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
402 | 402 | } |
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
404 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
405 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Save payment form data. |
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | - if ( ! empty( $shipping ) ) { |
|
412 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
410 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
411 | + if (!empty($shipping)) { |
|
412 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // Backwards compatibility. |
416 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
416 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment($invoice); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout($invoice); |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
@@ -427,41 +427,41 @@ discard block |
||
427 | 427 | * |
428 | 428 | * @param WPInv_Invoice $invoice |
429 | 429 | */ |
430 | - protected function process_payment( $invoice ) { |
|
430 | + protected function process_payment($invoice) { |
|
431 | 431 | |
432 | 432 | // Clear any checkout errors. |
433 | 433 | wpinv_clear_errors(); |
434 | 434 | |
435 | 435 | // No need to send free invoices to the gateway. |
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
436 | + if ($invoice->is_free()) { |
|
437 | + $this->process_free_payment($invoice); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | $submission = $this->payment_form_submission; |
441 | 441 | |
442 | 442 | // Fires before sending to the gateway. |
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
443 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
444 | 444 | |
445 | 445 | // Allow the sumission data to be modified before it is sent to the gateway. |
446 | 446 | $submission_data = $submission->get_data(); |
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
447 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
448 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
449 | 449 | |
450 | 450 | // Validate the currency. |
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency' ); |
|
451 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
452 | + wpinv_set_error('invalid_currency'); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | // Check to see if we have any errors. |
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
456 | + if (wpinv_get_errors()) { |
|
457 | + wpinv_send_back_to_checkout($invoice); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | // Send info to the gateway for payment processing |
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
461 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
462 | 462 | |
463 | 463 | // Backwards compatibility. |
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
464 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
465 | 465 | |
466 | 466 | } |
467 | 467 | |
@@ -470,12 +470,12 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @param WPInv_Invoice $invoice |
472 | 472 | */ |
473 | - protected function process_free_payment( $invoice ) { |
|
473 | + protected function process_free_payment($invoice) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
475 | + $invoice->set_gateway('none'); |
|
476 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
477 | 477 | $invoice->mark_paid(); |
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
478 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
479 | 479 | |
480 | 480 | } |
481 | 481 | |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
486 | - public function send_redirect_response( $url ) { |
|
487 | - $url = urlencode( $url ); |
|
488 | - wp_send_json_success( $url ); |
|
486 | + public function send_redirect_response($url) { |
|
487 | + $url = urlencode($url); |
|
488 | + wp_send_json_success($url); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | } |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Current page. |
13 | -$current_page = empty( $_GET['page'] ) ? 1 : absint( $_GET['page'] ); |
|
13 | +$current_page = empty($_GET['page']) ? 1 : absint($_GET['page']); |
|
14 | 14 | |
15 | 15 | // Fires before displaying user invoices. |
16 | -do_action( 'wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type ); |
|
16 | +do_action('wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type); |
|
17 | 17 | |
18 | 18 | wpinv_print_errors(); |
19 | 19 | |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | |
22 | 22 | |
23 | 23 | <div class="table-responsive"> |
24 | - <table class="table table-bordered table-hover getpaid-user-invoices <?php echo esc_attr( $post_type ); ?>"> |
|
24 | + <table class="table table-bordered table-hover getpaid-user-invoices <?php echo esc_attr($post_type); ?>"> |
|
25 | 25 | |
26 | 26 | |
27 | 27 | <thead> |
28 | 28 | <tr> |
29 | 29 | |
30 | - <?php foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : ?> |
|
31 | - <th class="<?php echo esc_attr( $column_id ); ?> <?php echo ( ! empty( $column_name['class'] ) ? sanitize_html_class( $column_name['class'] ) : ''); ?> border-bottom-0"> |
|
32 | - <span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span> |
|
30 | + <?php foreach (wpinv_get_user_invoices_columns($post_type) as $column_id => $column_name) : ?> |
|
31 | + <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? sanitize_html_class($column_name['class']) : ''); ?> border-bottom-0"> |
|
32 | + <span class="nobr"><?php echo esc_html($column_name['title']); ?></span> |
|
33 | 33 | </th> |
34 | 34 | <?php endforeach; ?> |
35 | 35 | |
@@ -39,43 +39,43 @@ discard block |
||
39 | 39 | |
40 | 40 | |
41 | 41 | <tbody> |
42 | - <?php foreach ( $invoices->invoices as $invoice ) : ?> |
|
42 | + <?php foreach ($invoices->invoices as $invoice) : ?> |
|
43 | 43 | |
44 | - <tr class="wpinv-item wpinv-item-<?php echo esc_attr( $invoice->get_status() ); ?>"> |
|
44 | + <tr class="wpinv-item wpinv-item-<?php echo esc_attr($invoice->get_status()); ?>"> |
|
45 | 45 | <?php |
46 | 46 | |
47 | - foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : |
|
47 | + foreach (wpinv_get_user_invoices_columns($post_type) as $column_id => $column_name) : |
|
48 | 48 | |
49 | - $column_id = sanitize_html_class( $column_id ); |
|
50 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
49 | + $column_id = sanitize_html_class($column_id); |
|
50 | + $class = empty($column_name['class']) ? '' : sanitize_html_class($column_name['class']); |
|
51 | 51 | |
52 | - echo "<td class='" . esc_attr( $column_id . ' ' . $class ) . "'>"; |
|
53 | - switch ( $column_id ) { |
|
52 | + echo "<td class='" . esc_attr($column_id . ' ' . $class) . "'>"; |
|
53 | + switch ($column_id) { |
|
54 | 54 | |
55 | 55 | case 'invoice-number': |
56 | - echo wp_kses_post( wpinv_invoice_link( $invoice ) ); |
|
56 | + echo wp_kses_post(wpinv_invoice_link($invoice)); |
|
57 | 57 | break; |
58 | 58 | |
59 | 59 | case 'created-date': |
60 | - echo esc_html( getpaid_format_date_value( $invoice->get_date_created() ) ); |
|
60 | + echo esc_html(getpaid_format_date_value($invoice->get_date_created())); |
|
61 | 61 | break; |
62 | 62 | |
63 | 63 | case 'payment-date': |
64 | - if ( $invoice->needs_payment() ) { |
|
64 | + if ($invoice->needs_payment()) { |
|
65 | 65 | echo '—'; |
66 | 66 | } else { |
67 | - echo esc_html( getpaid_format_date_value( $invoice->get_date_completed() ) ); |
|
67 | + echo esc_html(getpaid_format_date_value($invoice->get_date_completed())); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | break; |
71 | 71 | |
72 | 72 | case 'invoice-status': |
73 | - echo wp_kses_post( $invoice->get_status_label_html() ); |
|
73 | + echo wp_kses_post($invoice->get_status_label_html()); |
|
74 | 74 | |
75 | 75 | break; |
76 | 76 | |
77 | 77 | case 'invoice-total': |
78 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
78 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
79 | 79 | |
80 | 80 | break; |
81 | 81 | |
@@ -84,47 +84,47 @@ discard block |
||
84 | 84 | |
85 | 85 | 'pay' => array( |
86 | 86 | 'url' => $invoice->get_checkout_payment_url(), |
87 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
87 | + 'name' => __('Pay Now', 'invoicing'), |
|
88 | 88 | 'class' => 'btn-success', |
89 | 89 | ), |
90 | 90 | |
91 | 91 | 'print' => array( |
92 | 92 | 'url' => $invoice->get_view_url(), |
93 | - 'name' => __( 'View', 'invoicing' ), |
|
93 | + 'name' => __('View', 'invoicing'), |
|
94 | 94 | 'class' => 'btn-secondary', |
95 | 95 | 'attrs' => 'target="_blank"', |
96 | 96 | ), |
97 | 97 | ); |
98 | 98 | |
99 | - if ( ! $invoice->needs_payment() ) { |
|
100 | - unset( $actions['pay'] ); |
|
99 | + if (!$invoice->needs_payment()) { |
|
100 | + unset($actions['pay']); |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $invoice->needs_payment() ) { |
|
103 | + if ($invoice->needs_payment()) { |
|
104 | 104 | $actions['delete'] = array( |
105 | - 'url' => getpaid_get_authenticated_action_url( 'delete_invoice', add_query_arg( 'invoice_id', $invoice->get_id() ) ), |
|
106 | - 'name' => __( 'Delete', 'invoicing' ), |
|
105 | + 'url' => getpaid_get_authenticated_action_url('delete_invoice', add_query_arg('invoice_id', $invoice->get_id())), |
|
106 | + 'name' => __('Delete', 'invoicing'), |
|
107 | 107 | 'class' => 'btn-danger', |
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
111 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice, $post_type ); |
|
111 | + $actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice, $post_type); |
|
112 | 112 | |
113 | - foreach ( $actions as $key => $action ) { |
|
114 | - $class = ! empty( $action['class'] ) ? sanitize_html_class( $action['class'] ) : ''; |
|
115 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . esc_attr( $class . ' ' . sanitize_html_class( $key ) ) . '" ' . ( ! empty( $action['attrs'] ) ? esc_html( $action['attrs'] ) : '' ) . '>' . esc_attr( $action['name'] ) . '</a>'; |
|
113 | + foreach ($actions as $key => $action) { |
|
114 | + $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
115 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm btn-block ' . esc_attr($class . ' ' . sanitize_html_class($key)) . '" ' . (!empty($action['attrs']) ? esc_html($action['attrs']) : '') . '>' . esc_attr($action['name']) . '</a>'; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | break; |
119 | 119 | |
120 | 120 | default: |
121 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
121 | + do_action("wpinv_user_invoices_column_$column_id", $invoice); |
|
122 | 122 | break; |
123 | 123 | |
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
127 | + do_action("wpinv_user_invoices_column_after_$column_id", $invoice); |
|
128 | 128 | |
129 | 129 | echo '</td>'; |
130 | 130 | |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | </table> |
139 | 139 | </div> |
140 | 140 | |
141 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
141 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
142 | 142 | |
143 | - <?php if ( 1 < $invoices->max_num_pages ) : ?> |
|
143 | + <?php if (1 < $invoices->max_num_pages) : ?> |
|
144 | 144 | <div class="invoicing-Pagination"> |
145 | 145 | <?php |
146 | 146 | $big = 999999; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | echo wp_kses_post( |
149 | 149 | paginate_links( |
150 | 150 | array( |
151 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
151 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
152 | 152 | 'format' => '?paged=%#%', |
153 | 153 | 'total' => $invoices->max_num_pages, |
154 | 154 | ) |
@@ -158,4 +158,4 @@ discard block |
||
158 | 158 | </div> |
159 | 159 | <?php endif; ?> |
160 | 160 | |
161 | -<?php do_action( 'wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type ); ?> |
|
161 | +<?php do_action('wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type); ?> |