@@ -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 | * |
@@ -14,31 +14,31 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Class constructor. |
16 | 16 | */ |
17 | - public function __construct(){ |
|
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' ) ); |
|
33 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ) ); |
|
32 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription')); |
|
33 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription')); |
|
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->get_id() ? $subscription : wpinv_get_subscription( $invoice ); |
|
62 | + return $subscription->get_id() ? $subscription : wpinv_get_subscription($invoice); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,16 +67,16 @@ 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 | - $subscription = $this->get_invoice_subscription( $invoice ); |
|
72 | + $subscription = $this->get_invoice_subscription($invoice); |
|
73 | 73 | |
74 | 74 | // Abort if the subscription is missing or not active. |
75 | - if ( empty( $subscription ) || ! $subscription->is_active() ) { |
|
75 | + if (empty($subscription) || !$subscription->is_active()) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | |
79 | - $subscription->set_status( 'pending' ); |
|
79 | + $subscription->set_status('pending'); |
|
80 | 80 | $subscription->save(); |
81 | 81 | |
82 | 82 | } |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | * @param string $from |
89 | 89 | * @param string $to |
90 | 90 | */ |
91 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
91 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
92 | 92 | |
93 | 93 | $gateway = $subscription->get_gateway(); |
94 | 94 | |
95 | - if ( ! empty( $gateway ) ) { |
|
96 | - $gateway = sanitize_key( $gateway ); |
|
97 | - $from = sanitize_key( $from ); |
|
98 | - $to = sanitize_key( $to ); |
|
99 | - do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from ); |
|
95 | + if (!empty($gateway)) { |
|
96 | + $gateway = sanitize_key($gateway); |
|
97 | + $from = sanitize_key($from); |
|
98 | + $to = sanitize_key($to); |
|
99 | + do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @deprecated |
110 | 110 | * @return mixed|string|void |
111 | 111 | */ |
112 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
113 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
112 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
113 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,29 +120,29 @@ discard block |
||
120 | 120 | * @since 1.0.0 |
121 | 121 | * @return void |
122 | 122 | */ |
123 | - public function user_cancel_single_subscription( $data ) { |
|
123 | + public function user_cancel_single_subscription($data) { |
|
124 | 124 | |
125 | 125 | // Ensure there is a subscription to cancel. |
126 | - if ( empty( $data['subscription'] ) ) { |
|
126 | + if (empty($data['subscription'])) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | 129 | |
130 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
130 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
131 | 131 | |
132 | 132 | // Ensure that it exists and that it belongs to the current user. |
133 | - if ( ! $subscription->get_id() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
134 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
133 | + if (!$subscription->get_id() || $subscription->get_customer_id() != get_current_user_id()) { |
|
134 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
135 | 135 | |
136 | 136 | // Can it be cancelled. |
137 | - } else if ( ! $subscription->can_cancel() ) { |
|
138 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
137 | + } else if (!$subscription->can_cancel()) { |
|
138 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
139 | 139 | |
140 | 140 | |
141 | 141 | // Cancel it. |
142 | 142 | } else { |
143 | 143 | |
144 | 144 | $subscription->cancel(); |
145 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
145 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $redirect = add_query_arg( |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | ) |
153 | 153 | ); |
154 | 154 | |
155 | - wp_safe_redirect( esc_url( $redirect ) ); |
|
155 | + wp_safe_redirect(esc_url($redirect)); |
|
156 | 156 | exit; |
157 | 157 | |
158 | 158 | } |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | * @param WPInv_Invoice $invoice |
165 | 165 | * @since 1.0.0 |
166 | 166 | */ |
167 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
167 | + public function maybe_create_invoice_subscription($invoice) { |
|
168 | 168 | |
169 | 169 | // Abort if it is not recurring. |
170 | - if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
170 | + if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | 174 | $subscription = new WPInv_Subscription(); |
175 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
175 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
176 | 176 | |
177 | 177 | } |
178 | 178 | |
@@ -183,25 +183,25 @@ discard block |
||
183 | 183 | * @param WPInv_Invoice $invoice |
184 | 184 | * @since 1.0.19 |
185 | 185 | */ |
186 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
186 | + public function maybe_update_invoice_subscription($invoice) { |
|
187 | 187 | |
188 | 188 | // Do not process renewals. |
189 | - if ( $invoice->is_renewal() ) { |
|
189 | + if ($invoice->is_renewal()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | 193 | // (Maybe) create a new subscription. |
194 | - $subscription = $this->get_invoice_subscription( $invoice ); |
|
195 | - if ( empty( $subscription ) ) { |
|
196 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
194 | + $subscription = $this->get_invoice_subscription($invoice); |
|
195 | + if (empty($subscription)) { |
|
196 | + return $this->maybe_create_invoice_subscription($invoice); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | // Abort if an invoice is paid and already has a subscription. |
200 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
200 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
204 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
205 | 205 | |
206 | 206 | } |
207 | 207 | |
@@ -213,55 +213,55 @@ discard block |
||
213 | 213 | * @param WPInv_Invoice $invoice |
214 | 214 | * @since 1.0.19 |
215 | 215 | */ |
216 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
216 | + public function update_invoice_subscription($subscription, $invoice) { |
|
217 | 217 | |
218 | 218 | // Delete the subscription if an invoice is free or nolonger recurring. |
219 | - if ( $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
219 | + if ($invoice->is_free() || !$invoice->is_recurring()) { |
|
220 | 220 | return $subscription->delete(); |
221 | 221 | } |
222 | 222 | |
223 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
224 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
225 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
226 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
227 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
228 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
223 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
224 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
225 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
226 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
227 | + $subscription->set_date_created(current_time('mysql')); |
|
228 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
229 | 229 | |
230 | 230 | // Get the recurring item and abort if it does not exist. |
231 | - $subscription_item = $invoice->get_recurring( true ); |
|
232 | - if ( ! $subscription_item->get_id() ) { |
|
231 | + $subscription_item = $invoice->get_recurring(true); |
|
232 | + if (!$subscription_item->get_id()) { |
|
233 | 233 | $invoice->set_subscription_id(0); |
234 | 234 | $invoice->save(); |
235 | 235 | return $subscription->delete(); |
236 | 236 | } |
237 | 237 | |
238 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
239 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
240 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
241 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
238 | + $subscription->set_product_id($subscription_item->get_id()); |
|
239 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
240 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
241 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
242 | 242 | |
243 | 243 | // Calculate the next renewal date. |
244 | - $period = $subscription_item->get_recurring_period( true ); |
|
244 | + $period = $subscription_item->get_recurring_period(true); |
|
245 | 245 | $interval = $subscription_item->get_recurring_interval(); |
246 | 246 | |
247 | 247 | // If the subscription item has a trial period... |
248 | - if ( $subscription_item->has_free_trial() ) { |
|
249 | - $period = $subscription_item->get_trial_period( true ); |
|
248 | + if ($subscription_item->has_free_trial()) { |
|
249 | + $period = $subscription_item->get_trial_period(true); |
|
250 | 250 | $interval = $subscription_item->get_trial_interval(); |
251 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
252 | - $subscription->set_status( 'trialling' ); |
|
251 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
252 | + $subscription->set_status('trialling'); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
256 | - if ( $invoice->has_free_trial() ) { |
|
257 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
258 | - $subscription->set_status( 'trialling' ); |
|
256 | + if ($invoice->has_free_trial()) { |
|
257 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
258 | + $subscription->set_status('trialling'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | // Calculate the next renewal date. |
262 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
262 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
263 | 263 | |
264 | - $subscription->set_next_renewal_date( $expiration ); |
|
264 | + $subscription->set_next_renewal_date($expiration); |
|
265 | 265 | return $subscription->save(); |
266 | 266 | |
267 | 267 | } |
@@ -272,21 +272,21 @@ discard block |
||
272 | 272 | * @param array $data |
273 | 273 | * @since 1.0.19 |
274 | 274 | */ |
275 | - public function admin_update_single_subscription( $args ) { |
|
275 | + public function admin_update_single_subscription($args) { |
|
276 | 276 | |
277 | 277 | // Ensure the subscription exists and that a status has been given. |
278 | - if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) { |
|
278 | + if (empty($args['subscription_id']) || empty($args['subscription_status'])) { |
|
279 | 279 | return; |
280 | 280 | } |
281 | 281 | |
282 | 282 | // Retrieve the subscriptions. |
283 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
283 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
284 | 284 | |
285 | - if ( $subscription->get_id() ) { |
|
285 | + if ($subscription->get_id()) { |
|
286 | 286 | |
287 | - $subscription->set_status( $args['subscription_status'] ); |
|
287 | + $subscription->set_status($args['subscription_status']); |
|
288 | 288 | $subscription->save(); |
289 | - getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) ); |
|
289 | + getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing')); |
|
290 | 290 | |
291 | 291 | } |
292 | 292 | |
@@ -298,27 +298,27 @@ discard block |
||
298 | 298 | * @param array $data |
299 | 299 | * @since 1.0.19 |
300 | 300 | */ |
301 | - public function admin_renew_single_subscription( $args ) { |
|
301 | + public function admin_renew_single_subscription($args) { |
|
302 | 302 | |
303 | 303 | // Ensure the subscription exists and that a status has been given. |
304 | - if ( empty( $args['id'] ) ) { |
|
304 | + if (empty($args['id'])) { |
|
305 | 305 | return; |
306 | 306 | } |
307 | 307 | |
308 | 308 | // Retrieve the subscriptions. |
309 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
309 | + $subscription = new WPInv_Subscription($args['id']); |
|
310 | 310 | |
311 | - if ( $subscription->get_id() ) { |
|
311 | + if ($subscription->get_id()) { |
|
312 | 312 | |
313 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
313 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
314 | 314 | |
315 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
315 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
316 | 316 | |
317 | - if ( ! $subscription->add_payment( $args ) ) { |
|
318 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
317 | + if (!$subscription->add_payment($args)) { |
|
318 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
319 | 319 | } else { |
320 | 320 | $subscription->renew(); |
321 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
321 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | wp_safe_redirect( |
@@ -341,20 +341,20 @@ discard block |
||
341 | 341 | * @param array $data |
342 | 342 | * @since 1.0.19 |
343 | 343 | */ |
344 | - public function admin_delete_single_subscription( $args ) { |
|
344 | + public function admin_delete_single_subscription($args) { |
|
345 | 345 | |
346 | 346 | // Ensure the subscription exists and that a status has been given. |
347 | - if ( empty( $args['id'] ) ) { |
|
347 | + if (empty($args['id'])) { |
|
348 | 348 | return; |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Retrieve the subscriptions. |
352 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
352 | + $subscription = new WPInv_Subscription($args['id']); |
|
353 | 353 | |
354 | - if ( $subscription->delete() ) { |
|
355 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
354 | + if ($subscription->delete()) { |
|
355 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
356 | 356 | } else { |
357 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
357 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | $redirected = wp_safe_redirect( |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | ) |
368 | 368 | ); |
369 | 369 | |
370 | - if ( $redirected ) { |
|
370 | + if ($redirected) { |
|
371 | 371 | exit; |
372 | 372 | } |
373 | 373 | |
@@ -380,10 +380,10 @@ discard block |
||
380 | 380 | * @param WPInv_Item $item |
381 | 381 | * @param WPInv_Invoice $invoice |
382 | 382 | */ |
383 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
383 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
384 | 384 | |
385 | 385 | // Fetch item subscription. |
386 | - $args = array( |
|
386 | + $args = array( |
|
387 | 387 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
388 | 388 | 'item_in' => $item->get_id(), |
389 | 389 | 'number' => 1, |
@@ -391,13 +391,13 @@ discard block |
||
391 | 391 | 'fields' => 'id', |
392 | 392 | ); |
393 | 393 | |
394 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
394 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
395 | 395 | $subscription = $subscription->get_results(); |
396 | 396 | |
397 | 397 | // In case we found a match... |
398 | - if ( ! empty( $subscription ) ) { |
|
399 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
400 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'getpaid-license-manager' ) . '</a>'; |
|
398 | + if (!empty($subscription)) { |
|
399 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
400 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'getpaid-license-manager') . '</a>'; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | 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 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler'); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_unslash($_POST); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal'); |
|
60 | + wp_die('Invoice not paid via PayPal', 500); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status']); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type']); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN' ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN'); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type']); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice'); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
100 | + wpinv_error_log('Could not retrieve the associated invoice.'); |
|
101 | + wp_die('Could not retrieve the associated invoice.', 500); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function validate_ipn() { |
108 | 108 | |
109 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
109 | + wpinv_error_log('Validating PayPal IPN response'); |
|
110 | 110 | |
111 | 111 | // Retrieve the associated invoice. |
112 | - $posted = wp_unslash( $_POST ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
112 | + $posted = wp_unslash($_POST); |
|
113 | + $invoice = $this->get_ipn_invoice($posted); |
|
114 | 114 | |
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Validate the IPN. |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | // Post back to get a response. |
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
134 | 134 | |
135 | 135 | // Check to see if the request was valid. |
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
141 | + if (is_wp_error($response)) { |
|
142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @param string $currency currency to validate. |
156 | 156 | */ |
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
160 | 160 | |
161 | 161 | /* translators: %s: currency code. */ |
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
165 | 165 | } |
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency'); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * @param float $amount amount to validate. |
175 | 175 | */ |
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
178 | 178 | |
179 | 179 | /* translators: %s: Amount. */ |
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
183 | 183 | } |
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount'); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
192 | 192 | * @param string $receiver_email Email to validate. |
193 | 193 | */ |
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
199 | 199 | |
200 | 200 | /* translators: %s: email address . */ |
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
204 | 204 | } |
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
206 | + wpinv_error_log('Validated PayPal Email'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,68 +212,68 @@ discard block |
||
212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
213 | 213 | * @param array $posted Posted data. |
214 | 214 | */ |
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
216 | 216 | |
217 | 217 | // Collect payment details |
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
218 | + $payment_status = strtolower($posted['payment_status']); |
|
219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
223 | 223 | |
224 | 224 | // Update the transaction id. |
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
225 | + if (!empty($posted['txn_id'])) { |
|
226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
227 | 227 | $invoice->save(); |
228 | 228 | } |
229 | 229 | |
230 | 230 | // Process a refund. |
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
235 | + if (!$invoice->is_refunded()) { |
|
236 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
237 | 237 | } |
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
239 | + return wpinv_error_log($posted['reason_code']); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // Process payments. |
243 | - if ( $payment_status == 'completed' ) { |
|
243 | + if ($payment_status == 'completed') { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
245 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
246 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.'); |
|
247 | 247 | } |
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
250 | 250 | |
251 | 251 | $note = ''; |
252 | 252 | |
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
253 | + if (!empty($posted['mc_fee'])) { |
|
254 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
257 | + if (!empty($posted['payer_status'])) { |
|
258 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
259 | 259 | } |
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
261 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
262 | + return wpinv_error_log('Invoice marked as paid.'); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Pending payments. |
267 | - if ( $payment_status == 'pending' ) { |
|
267 | + if ($payment_status == 'pending') { |
|
268 | 268 | |
269 | 269 | /* translators: %s: pending reason. */ |
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
271 | 271 | |
272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
272 | + return wpinv_error_log('Invoice marked as "payment held".'); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /* translators: %s: payment status. */ |
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param WPInv_Invoice $invoice Invoice object. |
284 | 284 | * @param array $posted Posted data. |
285 | 285 | */ |
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
286 | + protected function ipn_txn_cart($invoice, $posted) { |
|
287 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -293,40 +293,40 @@ discard block |
||
293 | 293 | * @param WPInv_Invoice $invoice Invoice object. |
294 | 294 | * @param array $posted Posted data. |
295 | 295 | */ |
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
296 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
297 | 297 | |
298 | - wpinv_error_log( 'Processing subscription signup' ); |
|
298 | + wpinv_error_log('Processing subscription signup'); |
|
299 | 299 | |
300 | 300 | // Make sure the invoice has a subscription. |
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
303 | + if (empty($subscription)) { |
|
304 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Validate the IPN. |
308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
308 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
309 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
310 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
311 | 311 | |
312 | 312 | // Activate the subscription. |
313 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
314 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
315 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
316 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
313 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
314 | + $subscription->set_date_created(current_time('mysql')); |
|
315 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
316 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
317 | 317 | $subscription->activate(); |
318 | 318 | |
319 | 319 | // Set the transaction id. |
320 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
321 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
320 | + if (!empty($posted['txn_id'])) { |
|
321 | + $invoice->set_transaction_id($posted['txn_id']); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | // Update the payment status. |
325 | 325 | $invoice->mark_paid(); |
326 | 326 | |
327 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
327 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
328 | 328 | |
329 | - wpinv_error_log( 'Subscription started.' ); |
|
329 | + wpinv_error_log('Subscription started.'); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -335,27 +335,27 @@ discard block |
||
335 | 335 | * @param WPInv_Invoice $invoice Invoice object. |
336 | 336 | * @param array $posted Posted data. |
337 | 337 | */ |
338 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
338 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
339 | 339 | |
340 | 340 | // Make sure the invoice has a subscription. |
341 | - $subscription = wpinv_get_subscription( $invoice ); |
|
341 | + $subscription = wpinv_get_subscription($invoice); |
|
342 | 342 | |
343 | - if ( empty( $subscription ) ) { |
|
344 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
343 | + if (empty($subscription)) { |
|
344 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | // Abort if this is the first payment. |
348 | - if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
349 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
348 | + if (date('Ynd', $subscription->get_time_created()) == date('Ynd', strtotime($posted['payment_date']))) { |
|
349 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
350 | 350 | $invoice->save(); |
351 | 351 | return; |
352 | 352 | } |
353 | 353 | |
354 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
354 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id()); |
|
355 | 355 | |
356 | 356 | // Abort if the payment is already recorded. |
357 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
358 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
357 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
358 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed'); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | $args = array( |
@@ -363,17 +363,17 @@ discard block |
||
363 | 363 | 'gateway' => $this->id, |
364 | 364 | ); |
365 | 365 | |
366 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
366 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
367 | 367 | |
368 | - if ( empty( $invoice ) ) { |
|
368 | + if (empty($invoice)) { |
|
369 | 369 | return; |
370 | 370 | } |
371 | 371 | |
372 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
372 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
373 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
374 | 374 | |
375 | 375 | $subscription->renew(); |
376 | - wpinv_error_log( 'Subscription renewed.' ); |
|
376 | + wpinv_error_log('Subscription renewed.'); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -382,18 +382,18 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @param WPInv_Invoice $invoice Invoice object. |
384 | 384 | */ |
385 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
385 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
386 | 386 | |
387 | 387 | // Make sure the invoice has a subscription. |
388 | - $subscription = wpinv_get_subscription( $invoice ); |
|
388 | + $subscription = wpinv_get_subscription($invoice); |
|
389 | 389 | |
390 | - if ( empty( $subscription ) ) { |
|
391 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
390 | + if (empty($subscription)) { |
|
391 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
392 | 392 | } |
393 | 393 | |
394 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
394 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id()); |
|
395 | 395 | $subscription->cancel(); |
396 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
396 | + wpinv_error_log('Subscription cancelled.'); |
|
397 | 397 | |
398 | 398 | } |
399 | 399 | |
@@ -403,18 +403,18 @@ discard block |
||
403 | 403 | * @param WPInv_Invoice $invoice Invoice object. |
404 | 404 | * @param array $posted Posted data. |
405 | 405 | */ |
406 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
406 | + protected function ipn_txn_subscr_eot($invoice) { |
|
407 | 407 | |
408 | 408 | // Make sure the invoice has a subscription. |
409 | - $subscription = wpinv_get_subscription( $invoice ); |
|
409 | + $subscription = wpinv_get_subscription($invoice); |
|
410 | 410 | |
411 | - if ( empty( $subscription ) ) { |
|
412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
411 | + if (empty($subscription)) { |
|
412 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
413 | 413 | } |
414 | 414 | |
415 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
415 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id()); |
|
416 | 416 | $subscription->complete(); |
417 | - wpinv_error_log( 'Subscription completed.' ); |
|
417 | + wpinv_error_log('Subscription completed.'); |
|
418 | 418 | |
419 | 419 | } |
420 | 420 | |
@@ -424,18 +424,18 @@ discard block |
||
424 | 424 | * @param WPInv_Invoice $invoice Invoice object. |
425 | 425 | * @param array $posted Posted data. |
426 | 426 | */ |
427 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
427 | + protected function ipn_txn_subscr_failed($invoice) { |
|
428 | 428 | |
429 | 429 | // Make sure the invoice has a subscription. |
430 | - $subscription = wpinv_get_subscription( $invoice ); |
|
430 | + $subscription = wpinv_get_subscription($invoice); |
|
431 | 431 | |
432 | - if ( empty( $subscription ) ) { |
|
433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
432 | + if (empty($subscription)) { |
|
433 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
434 | 434 | } |
435 | 435 | |
436 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
436 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id()); |
|
437 | 437 | $subscription->failing(); |
438 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
438 | + wpinv_error_log('Subscription marked as failing.'); |
|
439 | 439 | |
440 | 440 | } |
441 | 441 |
@@ -9,14 +9,14 @@ 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 | -do_action( 'getpaid_before_single_subscription', $subscription ); |
|
19 | +do_action('getpaid_before_single_subscription', $subscription); |
|
20 | 20 | |
21 | 21 | ?> |
22 | 22 | |
@@ -28,44 +28,44 @@ discard block |
||
28 | 28 | |
29 | 29 | </style> |
30 | 30 | |
31 | -<h2 class="mb-1 h4"><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
31 | +<h2 class="mb-1 h4"><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
32 | 32 | <table class="table table-bordered"> |
33 | 33 | <tbody> |
34 | 34 | |
35 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
35 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
36 | 36 | |
37 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
37 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
38 | 38 | |
39 | 39 | <th class="w-25" style="font-weight: 500;"> |
40 | - <?php echo sanitize_text_field( $label ); ?> |
|
40 | + <?php echo sanitize_text_field($label); ?> |
|
41 | 41 | </th> |
42 | 42 | |
43 | 43 | <td class="w-75"> |
44 | 44 | <?php |
45 | 45 | |
46 | - switch ( $key ) { |
|
46 | + switch ($key) { |
|
47 | 47 | |
48 | 48 | case 'status': |
49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
49 | + echo sanitize_text_field($subscription->get_status_label()); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'start_date': |
53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
53 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_date_created())); |
|
54 | 54 | break; |
55 | 55 | |
56 | 56 | case 'expiry_date': |
57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
57 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
58 | 58 | break; |
59 | 59 | |
60 | 60 | case 'initial_amount': |
61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
61 | + echo wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency()); |
|
62 | 62 | |
63 | - if ( $subscription->has_trial_period() ) { |
|
63 | + if ($subscription->has_trial_period()) { |
|
64 | 64 | |
65 | 65 | echo "<small class='text-muted'> "; |
66 | 66 | printf( |
67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
67 | + _x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
68 | + sanitize_text_field($subscription->get_trial_period()) |
|
69 | 69 | ); |
70 | 70 | echo '</small>'; |
71 | 71 | |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | break; |
75 | 75 | |
76 | 76 | case 'recurring_amount': |
77 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
77 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
78 | + $amount = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()); |
|
79 | + echo strtolower("<strong style='font-weight: 500;'>$amount</strong> / $frequency"); |
|
80 | 80 | break; |
81 | 81 | |
82 | 82 | case 'item': |
83 | - $item = get_post( $subscription->get_product_id() ); |
|
83 | + $item = get_post($subscription->get_product_id()); |
|
84 | 84 | |
85 | - if ( ! empty( $item ) ) { |
|
86 | - echo esc_html( get_the_title( $item ) ); |
|
85 | + if (!empty($item)) { |
|
86 | + echo esc_html(get_the_title($item)); |
|
87 | 87 | } else { |
88 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
88 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | break; |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | case 'payments': |
94 | 94 | |
95 | 95 | $max_activations = (int) $subscription->get_bill_times(); |
96 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
96 | + echo (int) $subscription->get_times_billed() . ' / ' . (empty($max_activations) ? "∞" : $max_activations); |
|
97 | 97 | |
98 | 98 | break; |
99 | 99 | |
100 | 100 | } |
101 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
101 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
102 | 102 | |
103 | 103 | ?> |
104 | 104 | </td> |
@@ -110,24 +110,24 @@ discard block |
||
110 | 110 | </tbody> |
111 | 111 | </table> |
112 | 112 | |
113 | -<h2 class='mt-5 mb-1 h4'><?php _e( 'Subscription Invoices', 'invoicing' ); ?></h2> |
|
113 | +<h2 class='mt-5 mb-1 h4'><?php _e('Subscription Invoices', 'invoicing'); ?></h2> |
|
114 | 114 | |
115 | -<?php echo getpaid_admin_subscription_invoice_details_metabox( $subscription ); ?> |
|
115 | +<?php echo getpaid_admin_subscription_invoice_details_metabox($subscription); ?> |
|
116 | 116 | |
117 | 117 | <span class="form-text"> |
118 | 118 | |
119 | 119 | <?php |
120 | - if ( $subscription->can_cancel() ) { |
|
120 | + if ($subscription->can_cancel()) { |
|
121 | 121 | printf( |
122 | 122 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
123 | - esc_url( $subscription->get_cancel_url() ), |
|
124 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | - __( 'Cancel Subscription', 'invoicing' ) |
|
123 | + esc_url($subscription->get_cancel_url()), |
|
124 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
125 | + __('Cancel Subscription', 'invoicing') |
|
126 | 126 | ); |
127 | 127 | } |
128 | 128 | |
129 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
129 | + do_action('getpaid-single-subscription-page-actions', $subscription); |
|
130 | 130 | ?> |
131 | 131 | |
132 | - <a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
|
132 | + <a href="<?php echo esc_url(get_permalink((int) wpinv_get_option('invoice_subscription_page'))); ?>" class="btn btn-secondary btn-sm"><?php _e('Go Back', 'invoicing'); ?></a> |
|
133 | 133 | </span> |
134 | 134 | \ No newline at end of file |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * @package GetPaid |
16 | 16 | */ |
17 | 17 | |
18 | -defined( 'ABSPATH' ) || exit; |
|
18 | +defined('ABSPATH') || exit; |
|
19 | 19 | |
20 | 20 | // Define constants. |
21 | -if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
21 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
22 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
23 | 23 | } |
24 | 24 | |
25 | -if ( ! defined( 'WPINV_VERSION' ) ) { |
|
26 | - define( 'WPINV_VERSION', '1.1.0' ); |
|
25 | +if (!defined('WPINV_VERSION')) { |
|
26 | + define('WPINV_VERSION', '1.1.0'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | -if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
|
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
30 | +if (!class_exists('WPInv_Plugin', false)) { |
|
31 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | function getpaid() { |
41 | 41 | |
42 | - if ( empty( $GLOBALS['invoicing'] ) ) { |
|
42 | + if (empty($GLOBALS['invoicing'])) { |
|
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 |