@@ -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( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ), 5 ); |
|
33 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ), 5 ); |
|
32 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription'), 5); |
|
33 | + add_action('getpaid_update_invoice', 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,33 +127,33 @@ 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() ) { |
|
141 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
140 | + if (!$subscription->exists() || $subscription->get_customer_id() != get_current_user_id()) { |
|
141 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
142 | 142 | |
143 | 143 | // Can it be cancelled. |
144 | - } elseif ( ! $subscription->can_cancel() ) { |
|
145 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
144 | + } elseif (!$subscription->can_cancel()) { |
|
145 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
146 | 146 | |
147 | 147 | // Cancel it. |
148 | 148 | } else { |
149 | 149 | |
150 | 150 | $subscription->cancel(); |
151 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
151 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
152 | 152 | } |
153 | 153 | |
154 | - $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce' ) ); |
|
154 | + $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce')); |
|
155 | 155 | |
156 | - wp_safe_redirect( $redirect ); |
|
156 | + wp_safe_redirect($redirect); |
|
157 | 157 | exit; |
158 | 158 | |
159 | 159 | } |
@@ -165,41 +165,41 @@ discard block |
||
165 | 165 | * @param WPInv_Invoice $invoice |
166 | 166 | * @since 1.0.0 |
167 | 167 | */ |
168 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
168 | + public function maybe_create_invoice_subscription($invoice) { |
|
169 | 169 | global $getpaid_subscriptions_skip_invoice_update; |
170 | 170 | |
171 | 171 | // Abort if it is not recurring. |
172 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
172 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Either group the subscriptions or only process a single suscription. |
177 | - if ( getpaid_should_group_subscriptions( $invoice ) ) { |
|
177 | + if (getpaid_should_group_subscriptions($invoice)) { |
|
178 | 178 | |
179 | 179 | $subscription_groups = array(); |
180 | 180 | $is_first = true; |
181 | 181 | |
182 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
183 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, 0, $is_first ); |
|
182 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
183 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, 0, $is_first); |
|
184 | 184 | |
185 | - if ( $is_first ) { |
|
185 | + if ($is_first) { |
|
186 | 186 | $getpaid_subscriptions_skip_invoice_update = true; |
187 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
187 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
188 | 188 | $invoice->save(); |
189 | 189 | $getpaid_subscriptions_skip_invoice_update = false; |
190 | 190 | } |
191 | 191 | |
192 | - $is_first = false; |
|
192 | + $is_first = false; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | // Cache subscription groups. |
196 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
196 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
197 | 197 | return true; |
198 | 198 | |
199 | 199 | } |
200 | 200 | |
201 | 201 | $subscription = new WPInv_Subscription(); |
202 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
202 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -214,46 +214,46 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @since 2.3.0 |
216 | 216 | */ |
217 | - public function create_invoice_subscription_group( $totals, $invoice, $subscription_id = 0, $is_first = false ) { |
|
217 | + public function create_invoice_subscription_group($totals, $invoice, $subscription_id = 0, $is_first = false) { |
|
218 | 218 | |
219 | - $subscription = new WPInv_Subscription( (int) $subscription_id ); |
|
219 | + $subscription = new WPInv_Subscription((int) $subscription_id); |
|
220 | 220 | $initial_amt = $totals['initial_total']; |
221 | 221 | $recurring_amt = $totals['recurring_total']; |
222 | 222 | $fees = array(); |
223 | 223 | |
224 | 224 | // Maybe add recurring fees. |
225 | - if ( $is_first ) { |
|
225 | + if ($is_first) { |
|
226 | 226 | |
227 | - foreach ( $invoice->get_fees() as $i => $fee ) { |
|
228 | - if ( ! empty( $fee['recurring_fee'] ) ) { |
|
229 | - $initial_amt += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
230 | - $recurring_amt += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
231 | - $fees[ $i ] = $fee; |
|
227 | + foreach ($invoice->get_fees() as $i => $fee) { |
|
228 | + if (!empty($fee['recurring_fee'])) { |
|
229 | + $initial_amt += wpinv_sanitize_amount($fee['initial_fee']); |
|
230 | + $recurring_amt += wpinv_sanitize_amount($fee['recurring_fee']); |
|
231 | + $fees[$i] = $fee; |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
237 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
238 | - $subscription->set_initial_amount( $initial_amt ); |
|
239 | - $subscription->set_recurring_amount( $recurring_amt ); |
|
240 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
241 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
242 | - $subscription->set_product_id( $totals['item_id'] ); |
|
243 | - $subscription->set_period( $totals['period'] ); |
|
244 | - $subscription->set_frequency( $totals['interval'] ); |
|
245 | - $subscription->set_bill_times( $totals['recurring_limit'] ); |
|
246 | - $subscription->set_next_renewal_date( $totals['renews_on'] ); |
|
236 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
237 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
238 | + $subscription->set_initial_amount($initial_amt); |
|
239 | + $subscription->set_recurring_amount($recurring_amt); |
|
240 | + $subscription->set_date_created(current_time('mysql')); |
|
241 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
242 | + $subscription->set_product_id($totals['item_id']); |
|
243 | + $subscription->set_period($totals['period']); |
|
244 | + $subscription->set_frequency($totals['interval']); |
|
245 | + $subscription->set_bill_times($totals['recurring_limit']); |
|
246 | + $subscription->set_next_renewal_date($totals['renews_on']); |
|
247 | 247 | |
248 | 248 | // Trial periods. |
249 | - if ( ! empty( $totals['trialling'] ) ) { |
|
250 | - $subscription->set_trial_period( $totals['trialling'] ); |
|
251 | - $subscription->set_status( 'trialling' ); |
|
249 | + if (!empty($totals['trialling'])) { |
|
250 | + $subscription->set_trial_period($totals['trialling']); |
|
251 | + $subscription->set_status('trialling'); |
|
252 | 252 | |
253 | 253 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
254 | - } elseif ( empty( $initial_amt ) ) { |
|
255 | - $subscription->set_trial_period( $totals['interval'] . ' ' . $totals['period'] ); |
|
256 | - $subscription->set_status( 'trialling' ); |
|
254 | + } elseif (empty($initial_amt)) { |
|
255 | + $subscription->set_trial_period($totals['interval'] . ' ' . $totals['period']); |
|
256 | + $subscription->set_status('trialling'); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | $subscription->save(); |
@@ -271,86 +271,86 @@ discard block |
||
271 | 271 | * @param WPInv_Invoice $invoice |
272 | 272 | * @since 1.0.19 |
273 | 273 | */ |
274 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
274 | + public function maybe_update_invoice_subscription($invoice) { |
|
275 | 275 | global $getpaid_subscriptions_skip_invoice_update; |
276 | 276 | |
277 | 277 | // Avoid infinite loops. |
278 | - if ( ! empty( $getpaid_subscriptions_skip_invoice_update ) ) { |
|
278 | + if (!empty($getpaid_subscriptions_skip_invoice_update)) { |
|
279 | 279 | return; |
280 | 280 | } |
281 | 281 | |
282 | 282 | // Do not process renewals. |
283 | - if ( $invoice->is_renewal() ) { |
|
283 | + if ($invoice->is_renewal()) { |
|
284 | 284 | return; |
285 | 285 | } |
286 | 286 | |
287 | 287 | // Delete existing subscriptions if available and the invoice is not recurring. |
288 | - if ( ! $invoice->is_recurring() ) { |
|
289 | - $this->delete_invoice_subscriptions( $invoice ); |
|
288 | + if (!$invoice->is_recurring()) { |
|
289 | + $this->delete_invoice_subscriptions($invoice); |
|
290 | 290 | return; |
291 | 291 | } |
292 | 292 | |
293 | 293 | // Fetch existing subscriptions. |
294 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
294 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
295 | 295 | |
296 | 296 | // Create new ones if no existing subscriptions. |
297 | - if ( empty( $subscriptions ) ) { |
|
298 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
297 | + if (empty($subscriptions)) { |
|
298 | + return $this->maybe_create_invoice_subscription($invoice); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | // Abort if an invoice is paid and already has a subscription. |
302 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
302 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
303 | 303 | return; |
304 | 304 | } |
305 | 305 | |
306 | - $is_grouped = is_array( $subscriptions ); |
|
307 | - $should_group = getpaid_should_group_subscriptions( $invoice ); |
|
306 | + $is_grouped = is_array($subscriptions); |
|
307 | + $should_group = getpaid_should_group_subscriptions($invoice); |
|
308 | 308 | |
309 | 309 | // Ensure that the subscriptions are only grouped if there are more than 1 recurring items. |
310 | - if ( $is_grouped != $should_group ) { |
|
311 | - $this->delete_invoice_subscriptions( $invoice ); |
|
312 | - delete_post_meta( $invoice->get_id(), 'getpaid_subscription_groups' ); |
|
313 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
310 | + if ($is_grouped != $should_group) { |
|
311 | + $this->delete_invoice_subscriptions($invoice); |
|
312 | + delete_post_meta($invoice->get_id(), 'getpaid_subscription_groups'); |
|
313 | + return $this->maybe_create_invoice_subscription($invoice); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | // If there is only one recurring item... |
317 | - if ( ! $is_grouped ) { |
|
318 | - return $this->update_invoice_subscription( $subscriptions, $invoice ); |
|
317 | + if (!$is_grouped) { |
|
318 | + return $this->update_invoice_subscription($subscriptions, $invoice); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // Process subscription groups. |
322 | - $current_groups = getpaid_get_invoice_subscription_groups( $invoice->get_id() ); |
|
322 | + $current_groups = getpaid_get_invoice_subscription_groups($invoice->get_id()); |
|
323 | 323 | $subscription_groups = array(); |
324 | 324 | $is_first = true; |
325 | 325 | |
326 | 326 | // Create new subscription groups. |
327 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
328 | - $subscription_id = isset( $current_groups[ $group_key ] ) ? $current_groups[ $group_key ]['subscription_id'] : 0; |
|
329 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, $subscription_id, $is_first ); |
|
327 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
328 | + $subscription_id = isset($current_groups[$group_key]) ? $current_groups[$group_key]['subscription_id'] : 0; |
|
329 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, $subscription_id, $is_first); |
|
330 | 330 | |
331 | - if ( $is_first && $invoice->get_subscription_id() !== $subscription_groups[ $group_key ]['subscription_id'] ) { |
|
331 | + if ($is_first && $invoice->get_subscription_id() !== $subscription_groups[$group_key]['subscription_id']) { |
|
332 | 332 | $getpaid_subscriptions_skip_invoice_update = true; |
333 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
333 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
334 | 334 | $invoice->save(); |
335 | 335 | $getpaid_subscriptions_skip_invoice_update = false; |
336 | 336 | } |
337 | 337 | |
338 | - $is_first = false; |
|
338 | + $is_first = false; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | // Delete non-existent subscription groups. |
342 | - foreach ( $current_groups as $group_key => $data ) { |
|
343 | - if ( ! isset( $subscription_groups[ $group_key ] ) ) { |
|
344 | - $subscription = new WPInv_Subscription( (int) $data['subscription_id'] ); |
|
342 | + foreach ($current_groups as $group_key => $data) { |
|
343 | + if (!isset($subscription_groups[$group_key])) { |
|
344 | + $subscription = new WPInv_Subscription((int) $data['subscription_id']); |
|
345 | 345 | |
346 | - if ( $subscription->exists() ) { |
|
347 | - $subscription->delete( true ); |
|
346 | + if ($subscription->exists()) { |
|
347 | + $subscription->delete(true); |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | 352 | // Cache subscription groups. |
353 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
353 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
354 | 354 | return true; |
355 | 355 | |
356 | 356 | } |
@@ -360,20 +360,20 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @param WPInv_Invoice $invoice |
362 | 362 | */ |
363 | - public function delete_invoice_subscriptions( $invoice ) { |
|
363 | + public function delete_invoice_subscriptions($invoice) { |
|
364 | 364 | |
365 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
365 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
366 | 366 | |
367 | - if ( empty( $subscriptions ) ) { |
|
367 | + if (empty($subscriptions)) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - if ( ! is_array( $subscriptions ) ) { |
|
372 | - $subscriptions = array( $subscriptions ); |
|
371 | + if (!is_array($subscriptions)) { |
|
372 | + $subscriptions = array($subscriptions); |
|
373 | 373 | } |
374 | 374 | |
375 | - foreach ( $subscriptions as $subscription ) { |
|
376 | - $subscription->delete( true ); |
|
375 | + foreach ($subscriptions as $subscription) { |
|
376 | + $subscription->delete(true); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | } |
@@ -386,57 +386,57 @@ discard block |
||
386 | 386 | * @param WPInv_Invoice $invoice |
387 | 387 | * @since 1.0.19 |
388 | 388 | */ |
389 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
389 | + public function update_invoice_subscription($subscription, $invoice) { |
|
390 | 390 | |
391 | 391 | // Delete the subscription if an invoice is free or nolonger recurring. |
392 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
392 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) { |
|
393 | 393 | return $subscription->delete(); |
394 | 394 | } |
395 | 395 | |
396 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
397 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
398 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
399 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
400 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
401 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
396 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
397 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
398 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
399 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
400 | + $subscription->set_date_created(current_time('mysql')); |
|
401 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
402 | 402 | |
403 | 403 | // Get the recurring item and abort if it does not exist. |
404 | - $subscription_item = $invoice->get_recurring( true ); |
|
405 | - if ( ! $subscription_item->get_id() ) { |
|
406 | - $invoice->set_subscription_id( 0 ); |
|
404 | + $subscription_item = $invoice->get_recurring(true); |
|
405 | + if (!$subscription_item->get_id()) { |
|
406 | + $invoice->set_subscription_id(0); |
|
407 | 407 | $invoice->save(); |
408 | 408 | return $subscription->delete(); |
409 | 409 | } |
410 | 410 | |
411 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
412 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
413 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
414 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
411 | + $subscription->set_product_id($subscription_item->get_id()); |
|
412 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
413 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
414 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
415 | 415 | |
416 | 416 | // Calculate the next renewal date. |
417 | - $period = $subscription_item->get_recurring_period( true ); |
|
417 | + $period = $subscription_item->get_recurring_period(true); |
|
418 | 418 | $interval = $subscription_item->get_recurring_interval(); |
419 | 419 | |
420 | 420 | // If the subscription item has a trial period... |
421 | - if ( $subscription_item->has_free_trial() ) { |
|
422 | - $period = $subscription_item->get_trial_period( true ); |
|
421 | + if ($subscription_item->has_free_trial()) { |
|
422 | + $period = $subscription_item->get_trial_period(true); |
|
423 | 423 | $interval = $subscription_item->get_trial_interval(); |
424 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
425 | - $subscription->set_status( 'trialling' ); |
|
424 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
425 | + $subscription->set_status('trialling'); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
429 | - if ( $invoice->has_free_trial() ) { |
|
430 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
431 | - $subscription->set_status( 'trialling' ); |
|
429 | + if ($invoice->has_free_trial()) { |
|
430 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
431 | + $subscription->set_status('trialling'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | // Calculate the next renewal date. |
435 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
435 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
436 | 436 | |
437 | - $subscription->set_next_renewal_date( $expiration ); |
|
437 | + $subscription->set_next_renewal_date($expiration); |
|
438 | 438 | $subscription->save(); |
439 | - $invoice->set_subscription_id( $subscription->get_id() ); |
|
439 | + $invoice->set_subscription_id($subscription->get_id()); |
|
440 | 440 | return $subscription->get_id(); |
441 | 441 | |
442 | 442 | } |
@@ -447,27 +447,27 @@ discard block |
||
447 | 447 | * @param array $data |
448 | 448 | * @since 1.0.19 |
449 | 449 | */ |
450 | - public function admin_update_single_subscription( $args ) { |
|
450 | + public function admin_update_single_subscription($args) { |
|
451 | 451 | |
452 | 452 | // Ensure the subscription exists and that a status has been given. |
453 | - if ( empty( $args['subscription_id'] ) ) { |
|
453 | + if (empty($args['subscription_id'])) { |
|
454 | 454 | return; |
455 | 455 | } |
456 | 456 | |
457 | 457 | // Retrieve the subscriptions. |
458 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
458 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
459 | 459 | |
460 | - if ( $subscription->get_id() ) { |
|
460 | + if ($subscription->get_id()) { |
|
461 | 461 | |
462 | 462 | $subscription->set_props( |
463 | 463 | array( |
464 | - 'status' => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null, |
|
465 | - 'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null, |
|
464 | + 'status' => isset($args['subscription_status']) ? $args['subscription_status'] : null, |
|
465 | + 'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null, |
|
466 | 466 | ) |
467 | 467 | ); |
468 | 468 | |
469 | 469 | $subscription->save(); |
470 | - getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) ); |
|
470 | + getpaid_admin()->show_info(__('Subscription updated', 'invoicing')); |
|
471 | 471 | |
472 | 472 | } |
473 | 473 | |
@@ -479,27 +479,27 @@ discard block |
||
479 | 479 | * @param array $data |
480 | 480 | * @since 1.0.19 |
481 | 481 | */ |
482 | - public function admin_renew_single_subscription( $args ) { |
|
482 | + public function admin_renew_single_subscription($args) { |
|
483 | 483 | |
484 | 484 | // Ensure the subscription exists and that a status has been given. |
485 | - if ( empty( $args['id'] ) ) { |
|
485 | + if (empty($args['id'])) { |
|
486 | 486 | return; |
487 | 487 | } |
488 | 488 | |
489 | 489 | // Retrieve the subscriptions. |
490 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
490 | + $subscription = new WPInv_Subscription($args['id']); |
|
491 | 491 | |
492 | - if ( $subscription->get_id() ) { |
|
492 | + if ($subscription->get_id()) { |
|
493 | 493 | |
494 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
494 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
495 | 495 | |
496 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
496 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
497 | 497 | |
498 | - if ( ! $subscription->add_payment( $args ) ) { |
|
499 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
498 | + if (!$subscription->add_payment($args)) { |
|
499 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
500 | 500 | } else { |
501 | 501 | $subscription->renew(); |
502 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
502 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | wp_safe_redirect( |
@@ -522,20 +522,20 @@ discard block |
||
522 | 522 | * @param array $data |
523 | 523 | * @since 1.0.19 |
524 | 524 | */ |
525 | - public function admin_delete_single_subscription( $args ) { |
|
525 | + public function admin_delete_single_subscription($args) { |
|
526 | 526 | |
527 | 527 | // Ensure the subscription exists and that a status has been given. |
528 | - if ( empty( $args['id'] ) ) { |
|
528 | + if (empty($args['id'])) { |
|
529 | 529 | return; |
530 | 530 | } |
531 | 531 | |
532 | 532 | // Retrieve the subscriptions. |
533 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
533 | + $subscription = new WPInv_Subscription($args['id']); |
|
534 | 534 | |
535 | - if ( $subscription->delete() ) { |
|
536 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
535 | + if ($subscription->delete()) { |
|
536 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
537 | 537 | } else { |
538 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
538 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | $redirected = wp_safe_redirect( |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | ) |
549 | 549 | ); |
550 | 550 | |
551 | - if ( $redirected ) { |
|
551 | + if ($redirected) { |
|
552 | 552 | exit; |
553 | 553 | } |
554 | 554 | |
@@ -561,16 +561,16 @@ discard block |
||
561 | 561 | * @param WPInv_Item $item |
562 | 562 | * @param WPInv_Invoice $invoice |
563 | 563 | */ |
564 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
564 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
565 | 565 | |
566 | 566 | // Abort if this invoice uses subscription groups. |
567 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
568 | - if ( ! $invoice->is_recurring() || ! is_object( $subscriptions ) ) { |
|
567 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
568 | + if (!$invoice->is_recurring() || !is_object($subscriptions)) { |
|
569 | 569 | return $actions; |
570 | 570 | } |
571 | 571 | |
572 | 572 | // Fetch item subscription. |
573 | - $args = array( |
|
573 | + $args = array( |
|
574 | 574 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
575 | 575 | 'product_in' => $item->get_id(), |
576 | 576 | 'number' => 1, |
@@ -578,13 +578,13 @@ discard block |
||
578 | 578 | 'fields' => 'id', |
579 | 579 | ); |
580 | 580 | |
581 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
581 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
582 | 582 | $subscription = $subscription->get_results(); |
583 | 583 | |
584 | 584 | // In case we found a match... |
585 | - if ( ! empty( $subscription ) ) { |
|
586 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
587 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
585 | + if (!empty($subscription)) { |
|
586 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
587 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | return $actions; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
73 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,79 +100,79 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ), |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ), |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | |
142 | 142 | // In case the payment profile already exists remotely. |
143 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
144 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
145 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
146 | - return strtok( '.' ); |
|
143 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
144 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
145 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
146 | + return strtok('.'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // In case the customer profile already exists remotely. |
150 | - if ( 'E00039' == $response->get_error_code() ) { |
|
151 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
152 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
153 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
150 | + if ('E00039' == $response->get_error_code()) { |
|
151 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
152 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
153 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $response; |
157 | 157 | } |
158 | 158 | |
159 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
159 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
160 | 160 | |
161 | 161 | // Save the payment token. |
162 | - if ( $save ) { |
|
162 | + if ($save) { |
|
163 | 163 | $this->save_token( |
164 | 164 | array( |
165 | 165 | 'id' => $response->customerPaymentProfileIdList[0], |
166 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
166 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
167 | 167 | 'default' => true, |
168 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
168 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Add a note about the validation response. |
174 | 174 | $invoice->add_note( |
175 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
175 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
176 | 176 | false, |
177 | 177 | false, |
178 | 178 | true |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return string|WP_Error Profile id. |
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | 191 | */ |
192 | - public function get_customer_profile( $profile_id ) { |
|
192 | + public function get_customer_profile($profile_id) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ), |
200 | 200 | ); |
201 | 201 | |
202 | - return $this->post( $args, false ); |
|
202 | + return $this->post($args, false); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | 215 | * @return string|WP_Error Profile id. |
216 | 216 | */ |
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
217 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
220 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
221 | 221 | |
222 | 222 | // Prepare card details. |
223 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
223 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
224 | 224 | |
225 | 225 | // Authorize.NET does not support saving the same card twice. |
226 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
226 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
227 | 227 | |
228 | - if ( $cached_information ) { |
|
228 | + if ($cached_information) { |
|
229 | 229 | return $cached_information; |
230 | 230 | } |
231 | 231 | |
@@ -238,34 +238,34 @@ discard block |
||
238 | 238 | |
239 | 239 | // Billing information. |
240 | 240 | 'billTo' => array( |
241 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
242 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
243 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
244 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
245 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
246 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
247 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
241 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
242 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
243 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
244 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
245 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
246 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
247 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
248 | 248 | ), |
249 | 249 | |
250 | 250 | // Payment information. |
251 | 251 | 'payment' => $payment_information, |
252 | 252 | ), |
253 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
253 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
254 | 254 | ), |
255 | 255 | ); |
256 | 256 | |
257 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
257 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
258 | 258 | |
259 | - if ( is_wp_error( $response ) ) { |
|
259 | + if (is_wp_error($response)) { |
|
260 | 260 | |
261 | 261 | // In case the payment profile already exists remotely. |
262 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
263 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
264 | - $payment_profile_id = strtok( '.' ); |
|
265 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
262 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
263 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
264 | + $payment_profile_id = strtok('.'); |
|
265 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
266 | 266 | |
267 | 267 | // Cache payment profile id. |
268 | - $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
268 | + $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
269 | 269 | |
270 | 270 | return $payment_profile_id; |
271 | 271 | } |
@@ -274,29 +274,29 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | // Save the payment token. |
277 | - if ( $save ) { |
|
277 | + if ($save) { |
|
278 | 278 | $this->save_token( |
279 | 279 | array( |
280 | 280 | 'id' => $response->customerPaymentProfileId, |
281 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
281 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
282 | 282 | 'default' => true, |
283 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
283 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
284 | 284 | ) |
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Cache payment profile id. |
289 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
289 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
290 | 290 | |
291 | 291 | // Add a note about the validation response. |
292 | 292 | $invoice->add_note( |
293 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
293 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
294 | 294 | false, |
295 | 295 | false, |
296 | 296 | true |
297 | 297 | ); |
298 | 298 | |
299 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
299 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
300 | 300 | |
301 | 301 | return $response->customerPaymentProfileId; |
302 | 302 | } |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * @param array $payment_details. |
309 | 309 | * @return array|false Profile id. |
310 | 310 | */ |
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
311 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
312 | 312 | |
313 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
314 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
313 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
314 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
315 | 315 | |
316 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
316 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
317 | 317 | return false; |
318 | 318 | } |
319 | 319 | |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | 'getCustomerPaymentProfileRequest' => array( |
323 | 323 | 'merchantAuthentication' => $this->get_auth_params(), |
324 | 324 | 'customerProfileId' => $customer_profile, |
325 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
325 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
326 | 326 | ), |
327 | 327 | ); |
328 | 328 | |
329 | - $response = $this->post( $args, $invoice ); |
|
329 | + $response = $this->post($args, $invoice); |
|
330 | 330 | |
331 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
331 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | 341 | */ |
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
342 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
343 | 343 | |
344 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
345 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
346 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
344 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
345 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
346 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
347 | 347 | |
348 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
349 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
348 | + $cached_information[$payment_details] = $payment_profile_id; |
|
349 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return string|WP_Error Profile id. |
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | 361 | */ |
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
362 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | ), |
371 | 371 | ); |
372 | 372 | |
373 | - return $this->post( $args, false ); |
|
373 | + return $this->post($args, false); |
|
374 | 374 | |
375 | 375 | } |
376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | 384 | * @return WP_Error|object |
385 | 385 | */ |
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
386 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | ), |
404 | 404 | ), |
405 | 405 | 'order' => array( |
406 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
406 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
407 | 407 | ), |
408 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
408 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
409 | 409 | 'tax' => array( |
410 | 410 | 'amount' => $invoice->get_total_tax(), |
411 | - 'name' => __( 'TAX', 'invoicing' ), |
|
411 | + 'name' => __('TAX', 'invoicing'), |
|
412 | 412 | ), |
413 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
413 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
414 | 414 | 'customer' => array( |
415 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
416 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
415 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
416 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
417 | 417 | ), |
418 | 418 | 'customerIP' => $invoice->get_ip(), |
419 | 419 | ), |
420 | 420 | ), |
421 | 421 | ); |
422 | 422 | |
423 | - if ( 0 == $invoice->get_total_tax() ) { |
|
424 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
423 | + if (0 == $invoice->get_total_tax()) { |
|
424 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
425 | 425 | } |
426 | 426 | |
427 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
427 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
428 | 428 | |
429 | 429 | } |
430 | 430 | |
@@ -434,29 +434,29 @@ discard block |
||
434 | 434 | * @param stdClass $result Api response. |
435 | 435 | * @param WPInv_Invoice $invoice Invoice. |
436 | 436 | */ |
437 | - public function process_charge_response( $result, $invoice ) { |
|
437 | + public function process_charge_response($result, $invoice) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | 440 | $response_code = (int) $result->transactionResponse->responseCode; |
441 | 441 | |
442 | 442 | // Succeeded. |
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
443 | + if (1 == $response_code || 4 == $response_code) { |
|
444 | 444 | |
445 | 445 | // Maybe set a transaction id. |
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
446 | + if (!empty($result->transactionResponse->transId)) { |
|
447 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
448 | 448 | } |
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
452 | + if (1 == $response_code) { |
|
453 | 453 | return $invoice->mark_paid(); |
454 | 454 | } |
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
456 | + $invoice->set_status('wpi-onhold'); |
|
457 | 457 | $invoice->add_note( |
458 | 458 | sprintf( |
459 | - __( 'Held for review: %s', 'invoicing' ), |
|
459 | + __('Held for review: %s', 'invoicing'), |
|
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | 462 | ); |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
468 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
469 | 469 | |
470 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
470 | + if (!empty($result->transactionResponse->errors)) { |
|
471 | 471 | $errors = (object) $result->transactionResponse->errors; |
472 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
472 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param array $card Card details. |
482 | 482 | * @return array |
483 | 483 | */ |
484 | - public function get_payment_information( $card ) { |
|
484 | + public function get_payment_information($card) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param WPInv_Invoice $invoice Invoice. |
501 | 501 | * @return string |
502 | 502 | */ |
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
504 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
503 | + public function get_customer_profile_meta_name($invoice) { |
|
504 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -512,34 +512,34 @@ discard block |
||
512 | 512 | * @param WPInv_Invoice $invoice |
513 | 513 | * @return WP_Error|string The payment profile id |
514 | 514 | */ |
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
515 | + public function validate_submission_data($submission_data, $invoice) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
519 | 519 | |
520 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
521 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
520 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
521 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | // Validate the payment method. |
525 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
526 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
525 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
526 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | // Are we adding a new payment method? |
530 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
530 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
531 | 531 | return $submission_data['getpaid-authorizenet-payment-method']; |
532 | 532 | } |
533 | 533 | |
534 | 534 | // Retrieve the customer profile id. |
535 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
535 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
536 | 536 | |
537 | 537 | // Create payment method. |
538 | - if ( empty( $profile_id ) ) { |
|
539 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
538 | + if (empty($profile_id)) { |
|
539 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
540 | 540 | } |
541 | 541 | |
542 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
542 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
543 | 543 | |
544 | 544 | } |
545 | 545 | |
@@ -550,32 +550,32 @@ discard block |
||
550 | 550 | * @param WPInv_Invoice $invoice Invoice. |
551 | 551 | * @return array |
552 | 552 | */ |
553 | - public function get_line_items( $invoice ) { |
|
553 | + public function get_line_items($invoice) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | - foreach ( $invoice->get_items() as $item ) { |
|
556 | + foreach ($invoice->get_items() as $item) { |
|
557 | 557 | |
558 | 558 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
559 | 559 | $items[] = array( |
560 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
561 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
562 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
563 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
560 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
561 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
562 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
563 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
564 | 564 | 'unitPrice' => (float) $amount, |
565 | 565 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
566 | 566 | ); |
567 | 567 | |
568 | 568 | } |
569 | 569 | |
570 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
570 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
571 | 571 | |
572 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
572 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
573 | 573 | |
574 | - if ( $amount > 0 ) { |
|
574 | + if ($amount > 0) { |
|
575 | 575 | $items[] = array( |
576 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
577 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
578 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
576 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
577 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
578 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
579 | 579 | 'quantity' => '1', |
580 | 580 | 'unitPrice' => (float) $amount, |
581 | 581 | 'taxable' => false, |
@@ -595,36 +595,36 @@ discard block |
||
595 | 595 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
596 | 596 | * @return array |
597 | 597 | */ |
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
598 | + public function process_payment($invoice, $submission_data, $submission) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
601 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
602 | 602 | |
603 | 603 | // Do we have an error? |
604 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
605 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
606 | - wpinv_send_back_to_checkout( $invoice ); |
|
604 | + if (is_wp_error($payment_profile_id)) { |
|
605 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
606 | + wpinv_send_back_to_checkout($invoice); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | // Save the payment method to the order. |
610 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
610 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
611 | 611 | |
612 | 612 | // Check if this is a subscription or not. |
613 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
614 | - if ( ! empty( $subscriptions ) ) { |
|
615 | - $this->process_subscription( $invoice, $subscriptions ); |
|
613 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
614 | + if (!empty($subscriptions)) { |
|
615 | + $this->process_subscription($invoice, $subscriptions); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | // If it is free, send to the success page. |
619 | - if ( ! $invoice->needs_payment() ) { |
|
619 | + if (!$invoice->needs_payment()) { |
|
620 | 620 | $invoice->mark_paid(); |
621 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
621 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | // Charge the payment profile. |
625 | - $this->process_initial_payment( $invoice ); |
|
625 | + $this->process_initial_payment($invoice); |
|
626 | 626 | |
627 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
627 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
@@ -635,23 +635,23 @@ discard block |
||
635 | 635 | * |
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | 637 | */ |
638 | - protected function process_initial_payment( $invoice ) { |
|
638 | + protected function process_initial_payment($invoice) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
640 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
641 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
642 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
643 | 643 | |
644 | 644 | // Do we have an error? |
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
645 | + if (is_wp_error($result)) { |
|
646 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
647 | + wpinv_send_back_to_checkout($invoice); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Process the response. |
651 | - $this->process_charge_response( $result, $invoice ); |
|
651 | + $this->process_charge_response($result, $invoice); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
653 | + if (wpinv_get_errors()) { |
|
654 | + wpinv_send_back_to_checkout($invoice); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | } |
@@ -662,30 +662,30 @@ discard block |
||
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | 664 | */ |
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
665 | + public function process_subscription($invoice, $subscriptions) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | - if ( (float) $invoice->get_total() > 0 ) { |
|
669 | - $this->process_initial_payment( $invoice ); |
|
668 | + if ((float) $invoice->get_total() > 0) { |
|
669 | + $this->process_initial_payment($invoice); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
673 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
673 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
674 | 674 | |
675 | - foreach ( $subscriptions as $subscription ) { |
|
676 | - if ( $subscription->exists() ) { |
|
677 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
678 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
675 | + foreach ($subscriptions as $subscription) { |
|
676 | + if ($subscription->exists()) { |
|
677 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
678 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
679 | 679 | |
680 | - $subscription->set_next_renewal_date( $expiry ); |
|
681 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
682 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
680 | + $subscription->set_next_renewal_date($expiry); |
|
681 | + $subscription->set_date_created(current_time('mysql')); |
|
682 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
683 | 683 | $subscription->activate(); |
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Redirect to the success page. |
688 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
688 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
689 | 689 | |
690 | 690 | } |
691 | 691 | |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | * |
696 | 696 | * @param WPInv_Subscription $subscription |
697 | 697 | */ |
698 | - public function maybe_renew_subscription( $subscription ) { |
|
698 | + public function maybe_renew_subscription($subscription) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
702 | - $this->renew_subscription( $subscription ); |
|
701 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
702 | + $this->renew_subscription($subscription); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | } |
@@ -709,28 +709,28 @@ discard block |
||
709 | 709 | * |
710 | 710 | * @param WPInv_Subscription $subscription |
711 | 711 | */ |
712 | - public function renew_subscription( $subscription ) { |
|
712 | + public function renew_subscription($subscription) { |
|
713 | 713 | |
714 | 714 | // Generate the renewal invoice. |
715 | 715 | $new_invoice = $subscription->create_payment(); |
716 | 716 | $old_invoice = $subscription->get_parent_payment(); |
717 | 717 | |
718 | - if ( empty( $new_invoice ) ) { |
|
719 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
718 | + if (empty($new_invoice)) { |
|
719 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
720 | 720 | $subscription->failing(); |
721 | 721 | return; |
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
725 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
726 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
727 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
728 | 728 | |
729 | 729 | // Do we have an error? |
730 | - if ( is_wp_error( $result ) ) { |
|
730 | + if (is_wp_error($result)) { |
|
731 | 731 | |
732 | 732 | $old_invoice->add_note( |
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
733 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
734 | 734 | true, |
735 | 735 | false, |
736 | 736 | true |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | } |
742 | 742 | |
743 | 743 | // Process the response. |
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
744 | + $this->process_charge_response($result, $new_invoice); |
|
745 | 745 | |
746 | - if ( wpinv_get_errors() ) { |
|
746 | + if (wpinv_get_errors()) { |
|
747 | 747 | |
748 | 748 | $old_invoice->add_note( |
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
749 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
750 | 750 | true, |
751 | 751 | false, |
752 | 752 | true |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | |
757 | 757 | } |
758 | 758 | |
759 | - $subscription->add_payment( array(), $new_invoice ); |
|
759 | + $subscription->add_payment(array(), $new_invoice); |
|
760 | 760 | $subscription->renew(); |
761 | 761 | } |
762 | 762 | |
@@ -767,33 +767,33 @@ discard block |
||
767 | 767 | * @param GetPaid_Form_Item[] $items |
768 | 768 | * @return WPInv_Invoice |
769 | 769 | */ |
770 | - public function process_addons( $invoice, $items ) { |
|
770 | + public function process_addons($invoice, $items) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
774 | 774 | $getpaid_authorize_addons = array(); |
775 | - foreach ( $items as $item ) { |
|
775 | + foreach ($items as $item) { |
|
776 | 776 | |
777 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
777 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
778 | 778 | $getpaid_authorize_addons[] = $item; |
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
782 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
782 | + if (empty($getpaid_authorize_addons)) { |
|
783 | 783 | return; |
784 | 784 | } |
785 | 785 | |
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
788 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
789 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
790 | 790 | |
791 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
792 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
793 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
791 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
792 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
793 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
794 | 794 | |
795 | - if ( is_wp_error( $result ) ) { |
|
796 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
795 | + if (is_wp_error($result)) { |
|
796 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
797 | 797 | return; |
798 | 798 | } |
799 | 799 | |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | * @param array $args |
807 | 807 | * @return array |
808 | 808 | */ |
809 | - public function filter_addons_request( $args ) { |
|
809 | + public function filter_addons_request($args) { |
|
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
812 | 812 | $total = 0; |
813 | 813 | |
814 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
814 | + foreach ($getpaid_authorize_addons as $addon) { |
|
815 | 815 | $total += $addon->get_sub_total(); |
816 | 816 | } |
817 | 817 | |
818 | 818 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
819 | 819 | |
820 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
821 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
820 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
821 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | return $args; |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | public function sandbox_notice() { |
832 | 832 | |
833 | 833 | return sprintf( |
834 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
834 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
835 | 835 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
836 | 836 | '</a>' |
837 | 837 | ); |
@@ -843,42 +843,42 @@ discard block |
||
843 | 843 | * |
844 | 844 | * @param array $admin_settings |
845 | 845 | */ |
846 | - public function admin_settings( $admin_settings ) { |
|
846 | + public function admin_settings($admin_settings) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
850 | - implode( ', ', $this->currencies ) |
|
849 | + __('Supported Currencies: %s', 'invoicing'), |
|
850 | + implode(', ', $this->currencies) |
|
851 | 851 | ); |
852 | 852 | |
853 | 853 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
854 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
854 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
855 | 855 | |
856 | 856 | $admin_settings['authorizenet_login_id'] = array( |
857 | 857 | 'type' => 'text', |
858 | 858 | 'id' => 'authorizenet_login_id', |
859 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
860 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
859 | + 'name' => __('API Login ID', 'invoicing'), |
|
860 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
861 | 861 | ); |
862 | 862 | |
863 | 863 | $admin_settings['authorizenet_transaction_key'] = array( |
864 | 864 | 'type' => 'text', |
865 | 865 | 'id' => 'authorizenet_transaction_key', |
866 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
866 | + 'name' => __('Transaction Key', 'invoicing'), |
|
867 | 867 | ); |
868 | 868 | |
869 | 869 | $admin_settings['authorizenet_signature_key'] = array( |
870 | 870 | 'type' => 'text', |
871 | 871 | 'id' => 'authorizenet_signature_key', |
872 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
873 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
872 | + 'name' => __('Signature Key', 'invoicing'), |
|
873 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
874 | 874 | ); |
875 | 875 | |
876 | 876 | $admin_settings['authorizenet_ipn_url'] = array( |
877 | 877 | 'type' => 'ipn_url', |
878 | 878 | 'id' => 'authorizenet_ipn_url', |
879 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
879 | + 'name' => __('Webhook URL', 'invoicing'), |
|
880 | 880 | 'std' => $this->notify_url, |
881 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
881 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
882 | 882 | 'custom' => 'authorizenet', |
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Bank transfer Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
44 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
45 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
42 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
43 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
44 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
45 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
48 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
49 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
50 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
51 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
52 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + public function process_payment($invoice, $submission_data, $submission) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
67 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
68 | 68 | |
69 | 69 | // Set it as pending payment. |
70 | - if ( ! $invoice->needs_payment() ) { |
|
70 | + if (!$invoice->needs_payment()) { |
|
71 | 71 | $invoice->mark_paid(); |
72 | - } elseif ( ! $invoice->is_paid() ) { |
|
73 | - $invoice->set_status( 'wpi-onhold' ); |
|
72 | + } elseif (!$invoice->is_paid()) { |
|
73 | + $invoice->set_status('wpi-onhold'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Save it. |
77 | 77 | $invoice->save(); |
78 | 78 | |
79 | 79 | // Send to the success page. |
80 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
80 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -86,17 +86,17 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WPInv_Invoice $invoice Invoice. |
88 | 88 | */ |
89 | - public function thankyou_page( $invoice ) { |
|
89 | + public function thankyou_page($invoice) { |
|
90 | 90 | |
91 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
91 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
92 | 92 | |
93 | 93 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
94 | 94 | |
95 | - if ( ! empty( $this->instructions ) ) { |
|
96 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
95 | + if (!empty($this->instructions)) { |
|
96 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
97 | 97 | } |
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details($invoice); |
|
100 | 100 | |
101 | 101 | echo '</div>'; |
102 | 102 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | * @param string $email_type Email format: plain text or HTML. |
112 | 112 | * @param bool $sent_to_admin Sent to admin. |
113 | 113 | */ |
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
114 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
117 | 117 | |
118 | 118 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ($this->instructions) { |
|
121 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details($invoice); |
|
125 | 125 | |
126 | 126 | echo '</div>'; |
127 | 127 | |
@@ -134,50 +134,50 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Invoice $invoice Invoice. |
136 | 136 | */ |
137 | - protected function bank_details( $invoice ) { |
|
137 | + protected function bank_details($invoice) { |
|
138 | 138 | |
139 | 139 | // Get the invoice country and country $locale. |
140 | 140 | $country = $invoice->get_country(); |
141 | 141 | $locale = $this->get_country_locale(); |
142 | 142 | |
143 | 143 | // Get sortcode label in the $locale array and use appropriate one. |
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
144 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
148 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
149 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
150 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
151 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
152 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
147 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
148 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
149 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
150 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
151 | + 'iban' => __('IBAN', 'invoicing'), |
|
152 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
153 | 153 | 'sort_code' => $sortcode, |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $bank_info = array(); |
157 | 157 | |
158 | - foreach ( $bank_fields as $field => $label ) { |
|
159 | - $value = $this->get_option( $field ); |
|
158 | + foreach ($bank_fields as $field => $label) { |
|
159 | + $value = $this->get_option($field); |
|
160 | 160 | |
161 | - if ( ! empty( $value ) ) { |
|
162 | - $bank_info[ $field ] = array( |
|
161 | + if (!empty($value)) { |
|
162 | + $bank_info[$field] = array( |
|
163 | 163 | 'label' => $label, |
164 | 164 | 'value' => $value, |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info ); |
|
169 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info); |
|
170 | 170 | |
171 | - if ( empty( $bank_info ) ) { |
|
171 | + if (empty($bank_info)) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'))) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | 177 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . "</td></tr>" . PHP_EOL; |
|
179 | + foreach ($bank_info as $key => $data) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . "</td></tr>" . PHP_EOL; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | echo '</table>'; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function get_country_locale() { |
193 | 193 | |
194 | - if ( empty( $this->locale ) ) { |
|
194 | + if (empty($this->locale)) { |
|
195 | 195 | |
196 | 196 | // Locale information to be used - only those that are not 'Sort Code'. |
197 | 197 | $this->locale = apply_filters( |
@@ -199,42 +199,42 @@ discard block |
||
199 | 199 | array( |
200 | 200 | 'AU' => array( |
201 | 201 | 'sortcode' => array( |
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
202 | + 'label' => __('BSB', 'invoicing'), |
|
203 | 203 | ), |
204 | 204 | ), |
205 | 205 | 'CA' => array( |
206 | 206 | 'sortcode' => array( |
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
207 | + 'label' => __('Bank transit number', 'invoicing'), |
|
208 | 208 | ), |
209 | 209 | ), |
210 | 210 | 'IN' => array( |
211 | 211 | 'sortcode' => array( |
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
212 | + 'label' => __('IFSC', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | ), |
215 | 215 | 'IT' => array( |
216 | 216 | 'sortcode' => array( |
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
217 | + 'label' => __('Branch sort', 'invoicing'), |
|
218 | 218 | ), |
219 | 219 | ), |
220 | 220 | 'NZ' => array( |
221 | 221 | 'sortcode' => array( |
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | + 'label' => __('Bank code', 'invoicing'), |
|
223 | 223 | ), |
224 | 224 | ), |
225 | 225 | 'SE' => array( |
226 | 226 | 'sortcode' => array( |
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
227 | + 'label' => __('Bank code', 'invoicing'), |
|
228 | 228 | ), |
229 | 229 | ), |
230 | 230 | 'US' => array( |
231 | 231 | 'sortcode' => array( |
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
232 | + 'label' => __('Routing number', 'invoicing'), |
|
233 | 233 | ), |
234 | 234 | ), |
235 | 235 | 'ZA' => array( |
236 | 236 | 'sortcode' => array( |
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
237 | + 'label' => __('Branch code', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | ), |
240 | 240 | ) |
@@ -251,51 +251,51 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param array $admin_settings |
253 | 253 | */ |
254 | - public function admin_settings( $admin_settings ) { |
|
254 | + public function admin_settings($admin_settings) { |
|
255 | 255 | |
256 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
256 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | 261 | // Get sortcode label in the $locale array and use appropriate one. |
262 | 262 | $country = wpinv_default_billing_country(); |
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
263 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
264 | 264 | |
265 | 265 | $admin_settings['bank_transfer_ac_name'] = array( |
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
268 | + 'name' => __('Account Name', 'invoicing'), |
|
269 | 269 | ); |
270 | 270 | |
271 | 271 | $admin_settings['bank_transfer_ac_no'] = array( |
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
274 | + 'name' => __('Account Number', 'invoicing'), |
|
275 | 275 | ); |
276 | 276 | |
277 | 277 | $admin_settings['bank_transfer_bank_name'] = array( |
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
280 | + 'name' => __('Bank Name', 'invoicing'), |
|
281 | 281 | ); |
282 | 282 | |
283 | 283 | $admin_settings['bank_transfer_ifsc'] = array( |
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
286 | + 'name' => __('IFSC Code', 'invoicing'), |
|
287 | 287 | ); |
288 | 288 | |
289 | 289 | $admin_settings['bank_transfer_iban'] = array( |
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
292 | + 'name' => __('IBAN', 'invoicing'), |
|
293 | 293 | ); |
294 | 294 | |
295 | 295 | $admin_settings['bank_transfer_bic'] = array( |
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
298 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
299 | 299 | ); |
300 | 300 | |
301 | 301 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | |
307 | 307 | $admin_settings['bank_transfer_info'] = array( |
308 | 308 | 'id' => 'bank_transfer_info', |
309 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
310 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
309 | + 'name' => __('Instructions', 'invoicing'), |
|
310 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
311 | 311 | 'type' => 'textarea', |
312 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
312 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
313 | 313 | 'cols' => 50, |
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param GetPaid_Form_Item[] $items |
325 | 325 | * @return WPInv_Invoice |
326 | 326 | */ |
327 | - public function process_addons( $invoice, $items ) { |
|
327 | + public function process_addons($invoice, $items) { |
|
328 | 328 | |
329 | - foreach ( $items as $item ) { |
|
330 | - $invoice->add_item( $item ); |
|
329 | + foreach ($items as $item) { |
|
330 | + $invoice->add_item($item); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @param WPInv_Subscription $subscription |
342 | 342 | */ |
343 | - public function maybe_renew_subscription( $subscription ) { |
|
343 | + public function maybe_renew_subscription($subscription) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
346 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
347 | 347 | $subscription->create_payment(); |
348 | 348 | } |
349 | 349 | |
@@ -355,41 +355,41 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function invoice_paid( $invoice ) { |
|
358 | + public function invoice_paid($invoice) { |
|
359 | 359 | |
360 | 360 | // Abort if not paid by bank transfer. |
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
361 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Is it a parent payment? |
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
366 | + if (0 == $invoice->get_parent_id()) { |
|
367 | 367 | |
368 | 368 | // (Maybe) activate subscriptions. |
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
370 | 370 | |
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
371 | + if (!empty($subscriptions)) { |
|
372 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
373 | 373 | |
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
374 | + foreach ($subscriptions as $subscription) { |
|
375 | + if ($subscription->exists()) { |
|
376 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
377 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
378 | 378 | |
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
379 | + $subscription->set_next_renewal_date($expiry); |
|
380 | + $subscription->set_date_created(current_time('mysql')); |
|
381 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
382 | 382 | $subscription->activate(); |
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
389 | 389 | |
390 | 390 | // Renew the subscription. |
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
391 | + if ($subscription && $subscription->exists()) { |
|
392 | + $subscription->add_payment(array(), $invoice); |
|
393 | 393 | $subscription->renew(); |
394 | 394 | } |
395 | 395 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
42 | + $this->title = __('Test Gateway', 'invoicing'); |
|
43 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
44 | 44 | |
45 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
45 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,32 +54,32 @@ discard block |
||
54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
61 | 61 | |
62 | 62 | // (Maybe) activate subscriptions. |
63 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
63 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
64 | 64 | |
65 | - if ( ! empty( $subscriptions ) ) { |
|
66 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
65 | + if (!empty($subscriptions)) { |
|
66 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
67 | 67 | |
68 | - foreach ( $subscriptions as $subscription ) { |
|
69 | - if ( $subscription->exists() ) { |
|
70 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
71 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
68 | + foreach ($subscriptions as $subscription) { |
|
69 | + if ($subscription->exists()) { |
|
70 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
71 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
72 | 72 | |
73 | - $subscription->set_next_renewal_date( $expiry ); |
|
74 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
75 | - $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
73 | + $subscription->set_next_renewal_date($expiry); |
|
74 | + $subscription->set_date_created(current_time('mysql')); |
|
75 | + $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
76 | 76 | $subscription->activate(); |
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Send to the success page. |
82 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
82 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
83 | 83 | |
84 | 84 | } |
85 | 85 | |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | */ |
92 | - public function maybe_renew_subscription( $subscription ) { |
|
92 | + public function maybe_renew_subscription($subscription) { |
|
93 | 93 | |
94 | 94 | // Ensure its our subscription && it's active. |
95 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
95 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
96 | 96 | |
97 | 97 | // Renew the subscription. |
98 | 98 | $subscription->add_payment( |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | * @param GetPaid_Form_Item[] $items |
116 | 116 | * @return WPInv_Invoice |
117 | 117 | */ |
118 | - public function process_addons( $invoice, $items ) { |
|
118 | + public function process_addons($invoice, $items) { |
|
119 | 119 | |
120 | - foreach ( $items as $item ) { |
|
121 | - $invoice->add_item( $item ); |
|
120 | + foreach ($items as $item) { |
|
121 | + $invoice->add_item($item); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | $invoice->recalculate_total(); |
@@ -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 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
69 | 69 | * @param bool $deprecated |
70 | 70 | */ |
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
71 | + function __construct($subscription = 0, $deprecated = false) { |
|
72 | 72 | |
73 | - parent::__construct( $subscription ); |
|
73 | + parent::__construct($subscription); |
|
74 | 74 | |
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | - $this->set_id( $subscription_id ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
75 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
76 | + $this->set_id($subscription); |
|
77 | + } elseif ($subscription instanceof self) { |
|
78 | + $this->set_id($subscription->get_id()); |
|
79 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
80 | + $this->set_id($subscription_id); |
|
81 | + } elseif (!empty($subscription->id)) { |
|
82 | + $this->set_id($subscription->id); |
|
83 | 83 | } else { |
84 | - $this->set_object_read( true ); |
|
84 | + $this->set_object_read(true); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // Load the datastore. |
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
89 | 89 | |
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
90 | + if ($this->get_id() > 0) { |
|
91 | + $this->data_store->read($this); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
103 | 103 | * @since 1.0.19 |
104 | 104 | * @return int |
105 | 105 | */ |
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | 109 | // Trim the value. |
110 | - $value = trim( $value ); |
|
110 | + $value = trim($value); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
112 | + if (empty($value)) { |
|
113 | 113 | return 0; |
114 | 114 | } |
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
116 | + if ('invoice_id' == $field) { |
|
117 | 117 | $field = 'parent_payment_id'; |
118 | 118 | } |
119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
125 | 125 | ); |
126 | 126 | |
127 | 127 | // Ensure a field has been passed. |
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
128 | + if (empty($field) || !in_array($field, $fields)) { |
|
129 | 129 | return 0; |
130 | 130 | } |
131 | 131 | |
132 | 132 | // Maybe retrieve from the cache. |
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
134 | + if (!empty($subscription_id)) { |
|
135 | 135 | return $subscription_id; |
136 | 136 | } |
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
140 | 140 | $subscription_id = (int) $wpdb->get_var( |
141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
144 | + if (empty($subscription_id)) { |
|
145 | 145 | return 0; |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Update the cache with our data. |
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
150 | 150 | |
151 | 151 | return $subscription_id; |
152 | 152 | } |
@@ -155,17 +155,17 @@ discard block |
||
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
158 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
159 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
160 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
161 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Checks if a subscription key is set. |
166 | 166 | */ |
167 | - public function _isset( $key ) { |
|
168 | - return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
167 | + public function _isset($key) { |
|
168 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /* |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | * @param string $context View or edit context. |
191 | 191 | * @return int |
192 | 192 | */ |
193 | - public function get_customer_id( $context = 'view' ) { |
|
194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
193 | + public function get_customer_id($context = 'view') { |
|
194 | + return (int) $this->get_prop('customer_id', $context); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * @param string $context View or edit context. |
202 | 202 | * @return WP_User|false WP_User object on success, false on failure. |
203 | 203 | */ |
204 | - public function get_customer( $context = 'view' ) { |
|
205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
204 | + public function get_customer($context = 'view') { |
|
205 | + return get_userdata($this->get_customer_id($context)); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @param string $context View or edit context. |
213 | 213 | * @return int |
214 | 214 | */ |
215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
215 | + public function get_parent_invoice_id($context = 'view') { |
|
216 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param string $context View or edit context. |
224 | 224 | * @return int |
225 | 225 | */ |
226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
227 | - return $this->get_parent_invoice_id( $context ); |
|
226 | + public function get_parent_payment_id($context = 'view') { |
|
227 | + return $this->get_parent_invoice_id($context); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @since 1.0.0 |
234 | 234 | * @return int |
235 | 235 | */ |
236 | - public function get_original_payment_id( $context = 'view' ) { |
|
237 | - return $this->get_parent_invoice_id( $context ); |
|
236 | + public function get_original_payment_id($context = 'view') { |
|
237 | + return $this->get_parent_invoice_id($context); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param string $context View or edit context. |
245 | 245 | * @return WPInv_Invoice |
246 | 246 | */ |
247 | - public function get_parent_invoice( $context = 'view' ) { |
|
248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
247 | + public function get_parent_invoice($context = 'view') { |
|
248 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | * @param string $context View or edit context. |
256 | 256 | * @return WPInv_Invoice |
257 | 257 | */ |
258 | - public function get_parent_payment( $context = 'view' ) { |
|
259 | - return $this->get_parent_invoice( $context ); |
|
258 | + public function get_parent_payment($context = 'view') { |
|
259 | + return $this->get_parent_invoice($context); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @param string $context View or edit context. |
267 | 267 | * @return int |
268 | 268 | */ |
269 | - public function get_product_id( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
269 | + public function get_product_id($context = 'view') { |
|
270 | + return (int) $this->get_prop('product_id', $context); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @param string $context View or edit context. |
278 | 278 | * @return WPInv_Item |
279 | 279 | */ |
280 | - public function get_product( $context = 'view' ) { |
|
281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
280 | + public function get_product($context = 'view') { |
|
281 | + return new WPInv_Item($this->get_product_id($context)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * @param string $context View or edit context. |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - public function get_gateway( $context = 'view' ) { |
|
294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
293 | + public function get_gateway($context = 'view') { |
|
294 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | * @param string $context View or edit context. |
302 | 302 | * @return string |
303 | 303 | */ |
304 | - public function get_period( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'period', $context ); |
|
304 | + public function get_period($context = 'view') { |
|
305 | + return $this->get_prop('period', $context); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * @param string $context View or edit context. |
313 | 313 | * @return int |
314 | 314 | */ |
315 | - public function get_frequency( $context = 'view' ) { |
|
316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
315 | + public function get_frequency($context = 'view') { |
|
316 | + return (int) $this->get_prop('frequency', $context); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string $context View or edit context. |
324 | 324 | * @return float |
325 | 325 | */ |
326 | - public function get_initial_amount( $context = 'view' ) { |
|
327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
326 | + public function get_initial_amount($context = 'view') { |
|
327 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | * @param string $context View or edit context. |
335 | 335 | * @return float |
336 | 336 | */ |
337 | - public function get_recurring_amount( $context = 'view' ) { |
|
338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
337 | + public function get_recurring_amount($context = 'view') { |
|
338 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | * @param string $context View or edit context. |
346 | 346 | * @return int |
347 | 347 | */ |
348 | - public function get_bill_times( $context = 'view' ) { |
|
349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
348 | + public function get_bill_times($context = 'view') { |
|
349 | + return (int) $this->get_prop('bill_times', $context); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | * @param string $context View or edit context. |
357 | 357 | * @return string |
358 | 358 | */ |
359 | - public function get_transaction_id( $context = 'view' ) { |
|
360 | - return $this->get_prop( 'transaction_id', $context ); |
|
359 | + public function get_transaction_id($context = 'view') { |
|
360 | + return $this->get_prop('transaction_id', $context); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | * @param string $context View or edit context. |
368 | 368 | * @return string |
369 | 369 | */ |
370 | - public function get_created( $context = 'view' ) { |
|
371 | - return $this->get_prop( 'created', $context ); |
|
370 | + public function get_created($context = 'view') { |
|
371 | + return $this->get_prop('created', $context); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | * @param string $context View or edit context. |
379 | 379 | * @return string |
380 | 380 | */ |
381 | - public function get_date_created( $context = 'view' ) { |
|
382 | - return $this->get_created( $context ); |
|
381 | + public function get_date_created($context = 'view') { |
|
382 | + return $this->get_created($context); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | */ |
391 | 391 | public function get_time_created() { |
392 | 392 | $created = $this->get_date_created(); |
393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
393 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | * @param string $context View or edit context. |
401 | 401 | * @return string |
402 | 402 | */ |
403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
404 | - $date = $this->get_date_created( $context ); |
|
403 | + public function get_date_created_gmt($context = 'view') { |
|
404 | + $date = $this->get_date_created($context); |
|
405 | 405 | |
406 | - if ( $date ) { |
|
407 | - $date = get_gmt_from_date( $date ); |
|
406 | + if ($date) { |
|
407 | + $date = get_gmt_from_date($date); |
|
408 | 408 | } |
409 | 409 | return $date; |
410 | 410 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return string |
418 | 418 | */ |
419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'expiration', $context ); |
|
419 | + public function get_next_renewal_date($context = 'view') { |
|
420 | + return $this->get_prop('expiration', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return string |
429 | 429 | */ |
430 | - public function get_expiration( $context = 'view' ) { |
|
431 | - return $this->get_next_renewal_date( $context ); |
|
430 | + public function get_expiration($context = 'view') { |
|
431 | + return $this->get_next_renewal_date($context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | public function get_expiration_time() { |
441 | 441 | $expiration = $this->get_expiration(); |
442 | 442 | |
443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | - return current_time( 'timestamp' ); |
|
443 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
444 | + return current_time('timestamp'); |
|
445 | 445 | } |
446 | 446 | |
447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
447 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
448 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -455,11 +455,11 @@ discard block |
||
455 | 455 | * @param string $context View or edit context. |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | - $date = $this->get_next_renewal_date( $context ); |
|
458 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
459 | + $date = $this->get_next_renewal_date($context); |
|
460 | 460 | |
461 | - if ( $date ) { |
|
462 | - $date = get_gmt_from_date( $date ); |
|
461 | + if ($date) { |
|
462 | + $date = get_gmt_from_date($date); |
|
463 | 463 | } |
464 | 464 | return $date; |
465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
471 | 471 | * @param string $context View or edit context. |
472 | 472 | * @return string |
473 | 473 | */ |
474 | - public function get_trial_period( $context = 'view' ) { |
|
475 | - return $this->get_prop( 'trial_period', $context ); |
|
474 | + public function get_trial_period($context = 'view') { |
|
475 | + return $this->get_prop('trial_period', $context); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | * @param string $context View or edit context. |
483 | 483 | * @return string |
484 | 484 | */ |
485 | - public function get_status( $context = 'view' ) { |
|
486 | - return $this->get_prop( 'status', $context ); |
|
485 | + public function get_status($context = 'view') { |
|
486 | + return $this->get_prop('status', $context); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | * @param string $context View or edit context. |
494 | 494 | * @return string |
495 | 495 | */ |
496 | - public function get_profile_id( $context = 'view' ) { |
|
497 | - return $this->get_prop( 'profile_id', $context ); |
|
496 | + public function get_profile_id($context = 'view') { |
|
497 | + return $this->get_prop('profile_id', $context); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /* |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | * @since 1.0.19 |
510 | 510 | * @param int $value The customer's id. |
511 | 511 | */ |
512 | - public function set_customer_id( $value ) { |
|
513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
512 | + public function set_customer_id($value) { |
|
513 | + $this->set_prop('customer_id', (int) $value); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
519 | 519 | * @since 1.0.19 |
520 | 520 | * @param int $value The parent invoice id. |
521 | 521 | */ |
522 | - public function set_parent_invoice_id( $value ) { |
|
523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
522 | + public function set_parent_invoice_id($value) { |
|
523 | + $this->set_prop('parent_payment_id', (int) $value); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | * @since 1.0.19 |
530 | 530 | * @param int $value The parent invoice id. |
531 | 531 | */ |
532 | - public function set_parent_payment_id( $value ) { |
|
533 | - $this->set_parent_invoice_id( $value ); |
|
532 | + public function set_parent_payment_id($value) { |
|
533 | + $this->set_parent_invoice_id($value); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | * @since 1.0.19 |
540 | 540 | * @param int $value The parent invoice id. |
541 | 541 | */ |
542 | - public function set_original_payment_id( $value ) { |
|
543 | - $this->set_parent_invoice_id( $value ); |
|
542 | + public function set_original_payment_id($value) { |
|
543 | + $this->set_parent_invoice_id($value); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @since 1.0.19 |
550 | 550 | * @param int $value The subscription product id. |
551 | 551 | */ |
552 | - public function set_product_id( $value ) { |
|
553 | - $this->set_prop( 'product_id', (int) $value ); |
|
552 | + public function set_product_id($value) { |
|
553 | + $this->set_prop('product_id', (int) $value); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | * @since 1.0.19 |
560 | 560 | * @param string $value The renewal period. |
561 | 561 | */ |
562 | - public function set_period( $value ) { |
|
563 | - $this->set_prop( 'period', $value ); |
|
562 | + public function set_period($value) { |
|
563 | + $this->set_prop('period', $value); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | * @since 1.0.19 |
570 | 570 | * @param int $value The subscription frequency. |
571 | 571 | */ |
572 | - public function set_frequency( $value ) { |
|
573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
572 | + public function set_frequency($value) { |
|
573 | + $value = empty($value) ? 1 : (int) $value; |
|
574 | + $this->set_prop('frequency', absint($value)); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | * @since 1.0.19 |
581 | 581 | * @param float $value The initial subcription amount. |
582 | 582 | */ |
583 | - public function set_initial_amount( $value ) { |
|
584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
583 | + public function set_initial_amount($value) { |
|
584 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | * @since 1.0.19 |
591 | 591 | * @param float $value The recurring subcription amount. |
592 | 592 | */ |
593 | - public function set_recurring_amount( $value ) { |
|
594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | + public function set_recurring_amount($value) { |
|
594 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | * @since 1.0.19 |
601 | 601 | * @param int $value Bill times. |
602 | 602 | */ |
603 | - public function set_bill_times( $value ) { |
|
604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
603 | + public function set_bill_times($value) { |
|
604 | + $this->set_prop('bill_times', (int) $value); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -610,8 +610,8 @@ discard block |
||
610 | 610 | * @since 1.0.19 |
611 | 611 | * @param string $value Bill times. |
612 | 612 | */ |
613 | - public function set_transaction_id( $value ) { |
|
614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
613 | + public function set_transaction_id($value) { |
|
614 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -620,15 +620,15 @@ discard block |
||
620 | 620 | * @since 1.0.19 |
621 | 621 | * @param string $value strtotime compliant date. |
622 | 622 | */ |
623 | - public function set_created( $value ) { |
|
624 | - $date = strtotime( $value ); |
|
623 | + public function set_created($value) { |
|
624 | + $date = strtotime($value); |
|
625 | 625 | |
626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
626 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
627 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | |
631 | - $this->set_prop( 'created', '' ); |
|
631 | + $this->set_prop('created', ''); |
|
632 | 632 | |
633 | 633 | } |
634 | 634 | |
@@ -638,8 +638,8 @@ discard block |
||
638 | 638 | * @since 1.0.19 |
639 | 639 | * @param string $value strtotime compliant date. |
640 | 640 | */ |
641 | - public function set_date_created( $value ) { |
|
642 | - $this->set_created( $value ); |
|
641 | + public function set_date_created($value) { |
|
642 | + $this->set_created($value); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
@@ -648,15 +648,15 @@ discard block |
||
648 | 648 | * @since 1.0.19 |
649 | 649 | * @param string $value strtotime compliant date. |
650 | 650 | */ |
651 | - public function set_next_renewal_date( $value ) { |
|
652 | - $date = strtotime( $value ); |
|
651 | + public function set_next_renewal_date($value) { |
|
652 | + $date = strtotime($value); |
|
653 | 653 | |
654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
654 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
655 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
656 | 656 | return; |
657 | 657 | } |
658 | 658 | |
659 | - $this->set_prop( 'expiration', '' ); |
|
659 | + $this->set_prop('expiration', ''); |
|
660 | 660 | |
661 | 661 | } |
662 | 662 | |
@@ -666,8 +666,8 @@ discard block |
||
666 | 666 | * @since 1.0.19 |
667 | 667 | * @param string $value strtotime compliant date. |
668 | 668 | */ |
669 | - public function set_expiration( $value ) { |
|
670 | - $this->set_next_renewal_date( $value ); |
|
669 | + public function set_expiration($value) { |
|
670 | + $this->set_next_renewal_date($value); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -676,8 +676,8 @@ discard block |
||
676 | 676 | * @since 1.0.19 |
677 | 677 | * @param string $value trial period e.g 1 year. |
678 | 678 | */ |
679 | - public function set_trial_period( $value ) { |
|
680 | - $this->set_prop( 'trial_period', $value ); |
|
679 | + public function set_trial_period($value) { |
|
680 | + $this->set_prop('trial_period', $value); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -686,22 +686,22 @@ discard block |
||
686 | 686 | * @since 1.0.19 |
687 | 687 | * @param string $new_status New subscription status. |
688 | 688 | */ |
689 | - public function set_status( $new_status ) { |
|
689 | + public function set_status($new_status) { |
|
690 | 690 | |
691 | 691 | // Abort if this is not a valid status; |
692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
692 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
693 | 693 | return; |
694 | 694 | } |
695 | 695 | |
696 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
697 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
696 | + $old_status = !empty($this->status_transition['from']) ? $this->status_transition['from'] : $this->get_status(); |
|
697 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
698 | 698 | $this->status_transition = array( |
699 | 699 | 'from' => $old_status, |
700 | 700 | 'to' => $new_status, |
701 | 701 | ); |
702 | 702 | } |
703 | 703 | |
704 | - $this->set_prop( 'status', $new_status ); |
|
704 | + $this->set_prop('status', $new_status); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | /** |
@@ -710,8 +710,8 @@ discard block |
||
710 | 710 | * @since 1.0.19 |
711 | 711 | * @param string $value the remote profile id. |
712 | 712 | */ |
713 | - public function set_profile_id( $value ) { |
|
714 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
713 | + public function set_profile_id($value) { |
|
714 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /* |
@@ -729,8 +729,8 @@ discard block |
||
729 | 729 | * @param string|array String or array of strings to check for. |
730 | 730 | * @return bool |
731 | 731 | */ |
732 | - public function has_status( $status ) { |
|
733 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
732 | + public function has_status($status) { |
|
733 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | /** |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | */ |
741 | 741 | public function has_trial_period() { |
742 | 742 | $period = $this->get_trial_period(); |
743 | - return ! empty( $period ); |
|
743 | + return !empty($period); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | * @return bool |
750 | 750 | */ |
751 | 751 | public function is_active() { |
752 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
752 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | * @return bool |
759 | 759 | */ |
760 | 760 | public function is_expired() { |
761 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
761 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('timestamp')); |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | /** |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | */ |
769 | 769 | public function is_last_renewal() { |
770 | 770 | $max_bills = $this->get_bill_times(); |
771 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
771 | + return !empty($max_bills) && $max_bills <= $this->get_times_billed(); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /* |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | /** |
784 | 784 | * Backwards compatibilty. |
785 | 785 | */ |
786 | - public function create( $data = array() ) { |
|
786 | + public function create($data = array()) { |
|
787 | 787 | |
788 | 788 | // Set the properties. |
789 | - if ( is_array( $data ) ) { |
|
790 | - $this->set_props( $data ); |
|
789 | + if (is_array($data)) { |
|
790 | + $this->set_props($data); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | // Save the item. |
@@ -798,8 +798,8 @@ discard block |
||
798 | 798 | /** |
799 | 799 | * Backwards compatibilty. |
800 | 800 | */ |
801 | - public function update( $args = array() ) { |
|
802 | - return $this->create( $args ); |
|
801 | + public function update($args = array()) { |
|
802 | + return $this->create($args); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
@@ -808,12 +808,12 @@ discard block |
||
808 | 808 | * @since 1.0.0 |
809 | 809 | * @return WP_Post[] |
810 | 810 | */ |
811 | - public function get_child_payments( $hide_pending = true ) { |
|
811 | + public function get_child_payments($hide_pending = true) { |
|
812 | 812 | |
813 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
813 | + $statuses = array('publish', 'wpi-processing', 'wpi-renewal'); |
|
814 | 814 | |
815 | - if ( ! $hide_pending ) { |
|
816 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
815 | + if (!$hide_pending) { |
|
816 | + $statuses = array_keys(wpinv_get_invoice_statuses()); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | return get_posts( |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @return int |
836 | 836 | */ |
837 | 837 | public function get_total_payments() { |
838 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
838 | + return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id()); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | public function get_times_billed() { |
848 | 848 | $times_billed = $this->get_total_payments(); |
849 | 849 | |
850 | - if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) { |
|
850 | + if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) { |
|
851 | 851 | $times_billed--; |
852 | 852 | } |
853 | 853 | |
@@ -862,48 +862,48 @@ discard block |
||
862 | 862 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
863 | 863 | * @return bool |
864 | 864 | */ |
865 | - public function add_payment( $args = array(), $invoice = false ) { |
|
865 | + public function add_payment($args = array(), $invoice = false) { |
|
866 | 866 | |
867 | 867 | // Process each payment once. |
868 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
868 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | |
872 | 872 | // Are we creating a new invoice? |
873 | - if ( empty( $invoice ) ) { |
|
873 | + if (empty($invoice)) { |
|
874 | 874 | $invoice = $this->create_payment(); |
875 | 875 | |
876 | - if ( empty( $invoice ) ) { |
|
876 | + if (empty($invoice)) { |
|
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | } |
880 | 880 | |
881 | - $invoice->set_status( 'wpi-renewal' ); |
|
881 | + $invoice->set_status('wpi-renewal'); |
|
882 | 882 | |
883 | 883 | // Maybe set a transaction id. |
884 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
885 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
884 | + if (!empty($args['transaction_id'])) { |
|
885 | + $invoice->set_transaction_id($args['transaction_id']); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | // Set the completed date. |
889 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
889 | + $invoice->set_completed_date(current_time('mysql')); |
|
890 | 890 | |
891 | 891 | // And the gateway. |
892 | - if ( ! empty( $args['gateway'] ) ) { |
|
893 | - $invoice->set_gateway( $args['gateway'] ); |
|
892 | + if (!empty($args['gateway'])) { |
|
893 | + $invoice->set_gateway($args['gateway']); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | $invoice->save(); |
897 | 897 | |
898 | - if ( ! $invoice->exists() ) { |
|
898 | + if (!$invoice->exists()) { |
|
899 | 899 | return false; |
900 | 900 | } |
901 | 901 | |
902 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
903 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
904 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
902 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
903 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
904 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
905 | 905 | |
906 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
906 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
907 | 907 | |
908 | 908 | return $invoice->get_id(); |
909 | 909 | } |
@@ -918,41 +918,41 @@ discard block |
||
918 | 918 | |
919 | 919 | $parent_invoice = $this->get_parent_payment(); |
920 | 920 | |
921 | - if ( ! $parent_invoice->exists() ) { |
|
921 | + if (!$parent_invoice->exists()) { |
|
922 | 922 | return false; |
923 | 923 | } |
924 | 924 | |
925 | 925 | // Duplicate the parent invoice. |
926 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
927 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
928 | - $invoice->set_subscription_id( $this->get_id() ); |
|
929 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
926 | + $invoice = getpaid_duplicate_invoice($parent_invoice); |
|
927 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
928 | + $invoice->set_subscription_id($this->get_id()); |
|
929 | + $invoice->set_remote_subscription_id($this->get_profile_id()); |
|
930 | 930 | |
931 | 931 | // Set invoice items. |
932 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
933 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
932 | + $subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id()); |
|
933 | + $allowed_items = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']); |
|
934 | 934 | $invoice_items = array(); |
935 | 935 | |
936 | - foreach ( $invoice->get_items() as $item ) { |
|
937 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
936 | + foreach ($invoice->get_items() as $item) { |
|
937 | + if (in_array($item->get_id(), $allowed_items)) { |
|
938 | 938 | $invoice_items[] = $item; |
939 | 939 | } |
940 | 940 | } |
941 | 941 | |
942 | - $invoice->set_items( $invoice_items ); |
|
942 | + $invoice->set_items($invoice_items); |
|
943 | 943 | |
944 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
945 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
944 | + if (!empty($subscription_group['fees'])) { |
|
945 | + $invoice->set_fees($subscription_group['fees']); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | // Maybe recalculate discount (Pre-GetPaid Fix). |
949 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
950 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
951 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
949 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
950 | + if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) { |
|
951 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | $invoice->recalculate_total(); |
955 | - $invoice->set_status( 'wpi-pending' ); |
|
955 | + $invoice->set_status('wpi-pending'); |
|
956 | 956 | $invoice->save(); |
957 | 957 | |
958 | 958 | return $invoice->exists() ? $invoice : false; |
@@ -967,20 +967,20 @@ discard block |
||
967 | 967 | public function renew() { |
968 | 968 | |
969 | 969 | // Complete subscription if applicable |
970 | - if ( $this->is_last_renewal() ) { |
|
970 | + if ($this->is_last_renewal()) { |
|
971 | 971 | return $this->complete(); |
972 | 972 | } |
973 | 973 | |
974 | 974 | // Calculate new expiration |
975 | 975 | $frequency = $this->get_frequency(); |
976 | 976 | $period = $this->get_period(); |
977 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
977 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
978 | 978 | |
979 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
980 | - $this->set_status( 'active' ); |
|
979 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
980 | + $this->set_status('active'); |
|
981 | 981 | $this->save(); |
982 | 982 | |
983 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
983 | + do_action('getpaid_subscription_renewed', $this); |
|
984 | 984 | |
985 | 985 | return $this->get_id(); |
986 | 986 | } |
@@ -996,11 +996,11 @@ discard block |
||
996 | 996 | public function complete() { |
997 | 997 | |
998 | 998 | // Only mark a subscription as complete if it's not already cancelled. |
999 | - if ( $this->has_status( 'cancelled' ) ) { |
|
999 | + if ($this->has_status('cancelled')) { |
|
1000 | 1000 | return false; |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - $this->set_status( 'completed' ); |
|
1003 | + $this->set_status('completed'); |
|
1004 | 1004 | return $this->save(); |
1005 | 1005 | |
1006 | 1006 | } |
@@ -1012,14 +1012,14 @@ discard block |
||
1012 | 1012 | * @param bool $check_expiration |
1013 | 1013 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
1014 | 1014 | */ |
1015 | - public function expire( $check_expiration = false ) { |
|
1015 | + public function expire($check_expiration = false) { |
|
1016 | 1016 | |
1017 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1017 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
1018 | 1018 | // Do not mark as expired since real expiration date is in the future |
1019 | 1019 | return false; |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $this->set_status( 'expired' ); |
|
1022 | + $this->set_status('expired'); |
|
1023 | 1023 | return $this->save(); |
1024 | 1024 | |
1025 | 1025 | } |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | * @return int Subscription id. |
1032 | 1032 | */ |
1033 | 1033 | public function failing() { |
1034 | - $this->set_status( 'failing' ); |
|
1034 | + $this->set_status('failing'); |
|
1035 | 1035 | return $this->save(); |
1036 | 1036 | } |
1037 | 1037 | |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | * @return int Subscription id. |
1043 | 1043 | */ |
1044 | 1044 | public function cancel() { |
1045 | - $this->set_status( 'cancelled' ); |
|
1045 | + $this->set_status('cancelled'); |
|
1046 | 1046 | return $this->save(); |
1047 | 1047 | } |
1048 | 1048 | |
@@ -1053,7 +1053,7 @@ discard block |
||
1053 | 1053 | * @return bool |
1054 | 1054 | */ |
1055 | 1055 | public function can_cancel() { |
1056 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1056 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | * @return array |
1065 | 1065 | */ |
1066 | 1066 | public function get_cancellable_statuses() { |
1067 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
1067 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | /** |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * @return string |
1075 | 1075 | */ |
1076 | 1076 | public function get_cancel_url() { |
1077 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1078 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1077 | + $url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url()); |
|
1078 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1086,10 +1086,10 @@ discard block |
||
1086 | 1086 | */ |
1087 | 1087 | public function get_view_url() { |
1088 | 1088 | |
1089 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1090 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1089 | + $url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
1090 | + $url = add_query_arg('subscription', $this->get_id(), $url); |
|
1091 | 1091 | |
1092 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1092 | + return apply_filters('getpaid_get_subscription_view_url', $url, $this); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
@@ -1102,7 +1102,7 @@ discard block |
||
1102 | 1102 | * @return bool |
1103 | 1103 | */ |
1104 | 1104 | public function can_renew() { |
1105 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1105 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | /** |
@@ -1121,7 +1121,7 @@ discard block |
||
1121 | 1121 | ), |
1122 | 1122 | 'getpaid-nonce' |
1123 | 1123 | ); |
1124 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1124 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | /** |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | * @return bool |
1132 | 1132 | */ |
1133 | 1133 | public function can_update() { |
1134 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1134 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | /** |
@@ -1147,7 +1147,7 @@ discard block |
||
1147 | 1147 | 'subscription_id' => $this->get_id(), |
1148 | 1148 | ) |
1149 | 1149 | ); |
1150 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1150 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
1157 | 1157 | * @return string |
1158 | 1158 | */ |
1159 | 1159 | public function get_status_label() { |
1160 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1160 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
1161 | 1161 | } |
1162 | 1162 | |
1163 | 1163 | /** |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | */ |
1169 | 1169 | public function get_status_class() { |
1170 | 1170 | $statuses = getpaid_get_subscription_status_classes(); |
1171 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
1171 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark'; |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | /** |
@@ -1179,9 +1179,9 @@ discard block |
||
1179 | 1179 | */ |
1180 | 1180 | public function get_status_label_html() { |
1181 | 1181 | |
1182 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1183 | - $class = esc_attr( $this->get_status_class() ); |
|
1184 | - $status = sanitize_html_class( $this->get_status() ); |
|
1182 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
1183 | + $class = esc_attr($this->get_status_class()); |
|
1184 | + $status = sanitize_html_class($this->get_status()); |
|
1185 | 1185 | |
1186 | 1186 | return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
1187 | 1187 | } |
@@ -1193,9 +1193,9 @@ discard block |
||
1193 | 1193 | * @param string $txn_id The transaction ID from the merchant processor |
1194 | 1194 | * @return bool |
1195 | 1195 | */ |
1196 | - public function payment_exists( $txn_id = '' ) { |
|
1197 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1198 | - return ! empty( $invoice_id ); |
|
1196 | + public function payment_exists($txn_id = '') { |
|
1197 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
1198 | + return !empty($invoice_id); |
|
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | /** |
@@ -1207,35 +1207,35 @@ discard block |
||
1207 | 1207 | // Reset status transition variable. |
1208 | 1208 | $this->status_transition = false; |
1209 | 1209 | |
1210 | - if ( $status_transition ) { |
|
1210 | + if ($status_transition) { |
|
1211 | 1211 | try { |
1212 | 1212 | |
1213 | 1213 | // Fire a hook for the status change. |
1214 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1215 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1214 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
1215 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
1216 | 1216 | |
1217 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1217 | + if (!empty($status_transition['from'])) { |
|
1218 | 1218 | |
1219 | 1219 | /* translators: 1: old subscription status 2: new subscription status */ |
1220 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1220 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
1221 | 1221 | |
1222 | 1222 | // Note the transition occurred. |
1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1223 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1224 | 1224 | |
1225 | 1225 | // Fire another hook. |
1226 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1227 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1226 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
1227 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
1228 | 1228 | |
1229 | 1229 | } else { |
1230 | 1230 | /* translators: %s: new invoice status */ |
1231 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1231 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
1232 | 1232 | |
1233 | 1233 | // Note the transition occurred. |
1234 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1234 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1235 | 1235 | |
1236 | 1236 | } |
1237 | - } catch ( Exception $e ) { |
|
1238 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1237 | + } catch (Exception $e) { |
|
1238 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
1239 | 1239 | } |
1240 | 1240 | } |
1241 | 1241 | |
@@ -1261,7 +1261,7 @@ discard block |
||
1261 | 1261 | */ |
1262 | 1262 | public function activate() { |
1263 | 1263 | $status = 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
1264 | - $this->set_status( $status ); |
|
1264 | + $this->set_status($status); |
|
1265 | 1265 | return $this->save(); |
1266 | 1266 | } |
1267 | 1267 |
@@ -9,58 +9,58 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
14 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
15 | 15 | |
16 | 16 | // Display errors and notices. |
17 | 17 | wpinv_print_errors(); |
18 | 18 | |
19 | -$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_invoice_id() ); |
|
20 | -$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
19 | +$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_invoice_id()); |
|
20 | +$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
21 | 21 | |
22 | -do_action( 'getpaid_before_single_subscription', $subscription, $subscription_groups ); |
|
22 | +do_action('getpaid_before_single_subscription', $subscription, $subscription_groups); |
|
23 | 23 | |
24 | 24 | ?> |
25 | 25 | |
26 | -<h2 class="mb-1 h4"><?php esc_html_e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
26 | +<h2 class="mb-1 h4"><?php esc_html_e('Subscription Details', 'invoicing'); ?></h2> |
|
27 | 27 | <table class="table table-bordered"> |
28 | 28 | <tbody> |
29 | 29 | |
30 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
30 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
31 | 31 | |
32 | - <tr class="getpaid-subscription-meta-<?php echo esc_attr( $key ); ?>"> |
|
32 | + <tr class="getpaid-subscription-meta-<?php echo esc_attr($key); ?>"> |
|
33 | 33 | |
34 | 34 | <th class="font-weight-bold" style="width: 35%"> |
35 | - <?php echo esc_html( $label ); ?> |
|
35 | + <?php echo esc_html($label); ?> |
|
36 | 36 | </th> |
37 | 37 | |
38 | 38 | <td style="width: 65%"> |
39 | 39 | <?php |
40 | 40 | |
41 | - switch ( $key ) { |
|
41 | + switch ($key) { |
|
42 | 42 | |
43 | 43 | case 'status': |
44 | - echo esc_html( $subscription->get_status_label() ); |
|
44 | + echo esc_html($subscription->get_status_label()); |
|
45 | 45 | break; |
46 | 46 | |
47 | 47 | case 'start_date': |
48 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
48 | + echo esc_html(getpaid_format_date_value($subscription->get_date_created())); |
|
49 | 49 | break; |
50 | 50 | |
51 | 51 | case 'expiry_date': |
52 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
52 | + echo esc_html(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
53 | 53 | break; |
54 | 54 | |
55 | 55 | case 'initial_amount': |
56 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + echo wp_kses_post(wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency())); |
|
57 | 57 | |
58 | - if ( $subscription->has_trial_period() ) { |
|
58 | + if ($subscription->has_trial_period()) { |
|
59 | 59 | |
60 | 60 | echo "<small class='text-muted'> "; |
61 | 61 | printf( |
62 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
63 | - esc_html( $subscription->get_trial_period() ) |
|
62 | + esc_html_x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
63 | + esc_html($subscription->get_trial_period()) |
|
64 | 64 | ); |
65 | 65 | echo '</small>'; |
66 | 66 | |
@@ -69,29 +69,29 @@ discard block |
||
69 | 69 | break; |
70 | 70 | |
71 | 71 | case 'recurring_amount': |
72 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
73 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
74 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
72 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
73 | + $amount = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
74 | + echo wp_kses_post(strtolower("<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>")); |
|
75 | 75 | break; |
76 | 76 | |
77 | 77 | case 'item': |
78 | - if ( empty( $subscription_group ) ) { |
|
79 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
78 | + if (empty($subscription_group)) { |
|
79 | + echo wp_kses_post(WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id())); |
|
80 | 80 | } else { |
81 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
82 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
81 | + $markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
82 | + echo wp_kses_post(implode(' | ', $markup)); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | break; |
86 | 86 | |
87 | 87 | case 'payments': |
88 | 88 | $max_activations = (int) $subscription->get_bill_times(); |
89 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
89 | + echo ((int) $subscription->get_times_billed()) . ' / ' . (empty($max_activations) ? '∞' : (int) $max_activations); |
|
90 | 90 | |
91 | 91 | break; |
92 | 92 | |
93 | 93 | } |
94 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
94 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
95 | 95 | |
96 | 96 | ?> |
97 | 97 | </td> |
@@ -103,34 +103,34 @@ discard block |
||
103 | 103 | </tbody> |
104 | 104 | </table> |
105 | 105 | |
106 | -<?php if ( ! empty( $subscription_group ) ) : ?> |
|
107 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Subscription Items', 'invoicing' ); ?></h2> |
|
108 | - <?php getpaid_admin_subscription_item_details_metabox( $subscription ); ?> |
|
106 | +<?php if (!empty($subscription_group)) : ?> |
|
107 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Subscription Items', 'invoicing'); ?></h2> |
|
108 | + <?php getpaid_admin_subscription_item_details_metabox($subscription); ?> |
|
109 | 109 | <?php endif; ?> |
110 | 110 | |
111 | -<h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Invoices', 'invoicing' ); ?></h2> |
|
111 | +<h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Invoices', 'invoicing'); ?></h2> |
|
112 | 112 | |
113 | -<?php echo wp_kses_post( getpaid_admin_subscription_invoice_details_metabox( $subscription ) ); ?> |
|
113 | +<?php echo wp_kses_post(getpaid_admin_subscription_invoice_details_metabox($subscription)); ?> |
|
114 | 114 | |
115 | -<?php if ( 1 < count( $subscription_groups ) ) : ?> |
|
116 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Subscriptions', 'invoicing' ); ?></h2> |
|
117 | - <?php getpaid_admin_subscription_related_subscriptions_metabox( $subscription ); ?> |
|
115 | +<?php if (1 < count($subscription_groups)) : ?> |
|
116 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Subscriptions', 'invoicing'); ?></h2> |
|
117 | + <?php getpaid_admin_subscription_related_subscriptions_metabox($subscription); ?> |
|
118 | 118 | <?php endif; ?> |
119 | 119 | |
120 | 120 | <span class="form-text"> |
121 | 121 | |
122 | 122 | <?php |
123 | - if ( $subscription->can_cancel() ) { |
|
123 | + if ($subscription->can_cancel()) { |
|
124 | 124 | printf( |
125 | 125 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
126 | - esc_url( $subscription->get_cancel_url() ), |
|
127 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
128 | - esc_html__( 'Cancel Subscription', 'invoicing' ) |
|
126 | + esc_url($subscription->get_cancel_url()), |
|
127 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
128 | + esc_html__('Cancel Subscription', 'invoicing') |
|
129 | 129 | ); |
130 | 130 | } |
131 | 131 | |
132 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
132 | + do_action('getpaid-single-subscription-page-actions', $subscription); |
|
133 | 133 | ?> |
134 | 134 | |
135 | - <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
|
135 | + <a href="<?php echo esc_url(getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')))); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e('Go Back', 'invoicing'); ?></a> |
|
136 | 136 | </span> |