Passed
Push — master ( b0f301...f4ec69 )
by Brian
04:48
created
includes/admin/subscriptions.php 1 patch
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains functions that display the subscriptions admin page.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Render the Subscriptions page
@@ -17,22 +17,22 @@  discard block
 block discarded – undo
17 17
 	?>
18 18
 
19 19
 	<div class="wrap">
20
-		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
20
+		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
21 21
 		<div class="bsui">
22 22
 
23 23
 			<?php
24 24
 
25 25
 				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
26
+				if (!wpinv_current_user_can_manage_invoicing()) {
27 27
 
28 28
 					echo aui()->alert(
29 29
 						array(
30 30
 							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
31
+							'content' => __('You are not permitted to view this page.', 'invoicing'),
32 32
 						)
33 33
 					);
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+				} else if (!empty($_GET['id']) && is_numeric($_GET['id'])) {
36 36
 
37 37
 					// Display a single subscription.
38 38
 					wpinv_recurring_subscription_details();
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83 83
 	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->get_id() ) {
84
+	$sub = new WPInv_Subscription((int) $_GET['id']);
85
+	if (!$sub->get_id()) {
86 86
 
87 87
 		echo aui()->alert(
88 88
 			array(
89 89
 				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
90
+				'content' => __('Subscription not found.', 'invoicing'),
91 91
 			)
92 92
 		);
93 93
 
@@ -95,31 +95,31 @@  discard block
 block discarded – undo
95 95
 	}
96 96
 
97 97
 	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
98
+	add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal');
99
+	add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side');
100
+	add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced');
101
+	do_action('getpaid_admin_single_subscription_register_metabox', $sub);
102 102
 
103 103
 	?>
104 104
 
105
-		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
105
+		<form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>">
106 106
 
107
-			<?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?>
108
-			<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
109
-			<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
107
+			<?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?>
108
+			<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
109
+			<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
110 110
 			<input type="hidden" name="getpaid-admin-action" value="update_single_subscription" />
111
-			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" />
111
+			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" />
112 112
 
113 113
 			<div id="poststuff">
114 114
 				<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
115 115
 
116 116
 					<div id="postbox-container-1" class="postbox-container">
117
-						<?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?>
117
+						<?php do_meta_boxes(get_current_screen(), 'side', $sub); ?>
118 118
 					</div>
119 119
 
120 120
 					<div id="postbox-container-2" class="postbox-container">
121
-						<?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?>
122
-						<?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?>
121
+						<?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?>
122
+						<?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?>
123 123
 					</div>
124 124
 
125 125
 				</div>
@@ -138,40 +138,40 @@  discard block
 block discarded – undo
138 138
  *
139 139
  * @param WPInv_Subscription $sub
140 140
  */
141
-function getpaid_admin_subscription_details_metabox( $sub ) {
141
+function getpaid_admin_subscription_details_metabox($sub) {
142 142
 
143 143
 	// Prepare subscription detail columns.
144 144
 	$fields = apply_filters(
145 145
 		'getpaid_subscription_admin_page_fields',
146 146
 		array(
147
-			'subscription'   => __( 'Subscription', 'invoicing' ),
148
-			'customer'       => __( 'Customer', 'invoicing' ),
149
-			'amount'         => __( 'Amount', 'invoicing' ),
150
-			'start_date'     => __( 'Start Date', 'invoicing' ),
151
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
-			'renewals'       => __( 'Payments', 'invoicing' ),
153
-			'item'           => __( 'Item', 'invoicing' ),
154
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
155
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
-			'status'         => __( 'Status', 'invoicing' ),
147
+			'subscription'   => __('Subscription', 'invoicing'),
148
+			'customer'       => __('Customer', 'invoicing'),
149
+			'amount'         => __('Amount', 'invoicing'),
150
+			'start_date'     => __('Start Date', 'invoicing'),
151
+			'renews_on'      => __('Next Payment', 'invoicing'),
152
+			'renewals'       => __('Payments', 'invoicing'),
153
+			'item'           => __('Item', 'invoicing'),
154
+			'gateway'        => __('Payment Method', 'invoicing'),
155
+			'profile_id'     => __('Profile ID', 'invoicing'),
156
+			'status'         => __('Status', 'invoicing'),
157 157
 		)
158 158
 	);
159 159
 
160
-	if ( ! $sub->is_active() ) {
160
+	if (!$sub->is_active()) {
161 161
 
162
-		if ( isset( $fields['renews_on'] ) ) {
163
-			unset( $fields['renews_on'] );
162
+		if (isset($fields['renews_on'])) {
163
+			unset($fields['renews_on']);
164 164
 		}
165 165
 
166
-		if ( isset( $fields['gateway'] ) ) {
167
-			unset( $fields['gateway'] );
166
+		if (isset($fields['gateway'])) {
167
+			unset($fields['gateway']);
168 168
 		}
169 169
 		
170 170
 	}
171 171
 
172 172
 	$profile_id = $sub->get_profile_id();
173
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
-		unset( $fields['profile_id'] );
173
+	if (empty($profile_id) && isset($fields['profile_id'])) {
174
+		unset($fields['profile_id']);
175 175
 	}
176 176
 
177 177
 	?>
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 		<table class="table table-borderless" style="font-size: 14px;">
180 180
 			<tbody>
181 181
 
182
-				<?php foreach ( $fields as $key => $label ) : ?>
182
+				<?php foreach ($fields as $key => $label) : ?>
183 183
 
184
-					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>">
184
+					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>">
185 185
 
186 186
 						<th class="w-25" style="font-weight: 500;">
187
-							<?php echo sanitize_text_field( $label ); ?>
187
+							<?php echo sanitize_text_field($label); ?>
188 188
 						</th>
189 189
 
190 190
 						<td class="w-75 text-muted">
191
-							<?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub ); ?>
191
+							<?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub); ?>
192 192
 						</td>
193 193
 
194 194
 					</tr>
@@ -206,131 +206,131 @@  discard block
 block discarded – undo
206 206
  *
207 207
  * @param WPInv_Subscription $subscription
208 208
  */
209
-function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
209
+function getpaid_admin_subscription_metabox_display_customer($subscription) {
210 210
 
211
-	$username = __( '(Missing User)', 'invoicing' );
211
+	$username = __('(Missing User)', 'invoicing');
212 212
 
213
-	$user = get_userdata( $subscription->get_customer_id() );
214
-	if ( $user ) {
213
+	$user = get_userdata($subscription->get_customer_id());
214
+	if ($user) {
215 215
 
216 216
 		$username = sprintf(
217 217
 			'<a href="user-edit.php?user_id=%s">%s</a>',
218
-			absint( $user->ID ),
219
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
218
+			absint($user->ID),
219
+			!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
220 220
 		);
221 221
 
222 222
 	}
223 223
 
224 224
 	echo  $username;
225 225
 }
226
-add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
226
+add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer');
227 227
 
228 228
 /**
229 229
  * Displays the subscription amount.
230 230
  *
231 231
  * @param WPInv_Subscription $subscription
232 232
  */
233
-function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
234
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
233
+function getpaid_admin_subscription_metabox_display_amount($subscription) {
234
+	$amount = sanitize_text_field(getpaid_get_formatted_subscription_amount($subscription));
235 235
 	echo "<span>$amount</span>";
236 236
 }
237
-add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
237
+add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount');
238 238
 
239 239
 /**
240 240
  * Displays the subscription id.
241 241
  *
242 242
  * @param WPInv_Subscription $subscription
243 243
  */
244
-function getpaid_admin_subscription_metabox_display_id( $subscription ) {
245
-	echo  '#' . absint( $subscription->get_id() );
244
+function getpaid_admin_subscription_metabox_display_id($subscription) {
245
+	echo  '#' . absint($subscription->get_id());
246 246
 }
247
-add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
247
+add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id');
248 248
 
249 249
 /**
250 250
  * Displays the subscription renewal date.
251 251
  *
252 252
  * @param WPInv_Subscription $subscription
253 253
  */
254
-function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
255
-	echo getpaid_format_date_value( $subscription->get_date_created() );
254
+function getpaid_admin_subscription_metabox_display_start_date($subscription) {
255
+	echo getpaid_format_date_value($subscription->get_date_created());
256 256
 }
257
-add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
257
+add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date');
258 258
 
259 259
 /**
260 260
  * Displays the subscription renewal date.
261 261
  *
262 262
  * @param WPInv_Subscription $subscription
263 263
  */
264
-function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
265
-	echo getpaid_format_date_value( $subscription->get_expiration() );
264
+function getpaid_admin_subscription_metabox_display_renews_on($subscription) {
265
+	echo getpaid_format_date_value($subscription->get_expiration());
266 266
 }
267
-add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
267
+add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on');
268 268
 
269 269
 /**
270 270
  * Displays the subscription renewal count.
271 271
  *
272 272
  * @param WPInv_Subscription $subscription
273 273
  */
274
-function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
274
+function getpaid_admin_subscription_metabox_display_renewals($subscription) {
275 275
 	$max_bills = $subscription->get_bill_times();
276
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
276
+	echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
277 277
 }
278
-add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
278
+add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals');
279 279
 /**
280 280
  * Displays the subscription item.
281 281
  *
282 282
  * @param WPInv_Subscription $subscription
283 283
  */
284
-function getpaid_admin_subscription_metabox_display_item( $subscription ) {
284
+function getpaid_admin_subscription_metabox_display_item($subscription) {
285 285
 
286
-	$item = get_post( $subscription->get_product_id() );
286
+	$item = get_post($subscription->get_product_id());
287 287
 
288
-	if ( ! empty( $item ) ) {
289
-		$link = get_edit_post_link( $item );
290
-		$link = esc_url( $link );
291
-		$name = esc_html( get_the_title( $item ) );
288
+	if (!empty($item)) {
289
+		$link = get_edit_post_link($item);
290
+		$link = esc_url($link);
291
+		$name = esc_html(get_the_title($item));
292 292
 		echo "<a href='$link'>$name</a>";
293 293
 	} else {
294
-		echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
294
+		echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id());
295 295
 	}
296 296
 
297 297
 }
298
-add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' );
298
+add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item');
299 299
 
300 300
 /**
301 301
  * Displays the subscription gateway.
302 302
  *
303 303
  * @param WPInv_Subscription $subscription
304 304
  */
305
-function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
305
+function getpaid_admin_subscription_metabox_display_gateway($subscription) {
306 306
 
307 307
 	$gateway = $subscription->get_gateway();
308 308
 
309
-	if ( ! empty( $gateway ) ) {
310
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
309
+	if (!empty($gateway)) {
310
+		echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway));
311 311
 	} else {
312 312
 		echo "&mdash;";
313 313
 	}
314 314
 
315 315
 }
316
-add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
316
+add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway');
317 317
 
318 318
 /**
319 319
  * Displays the subscription status.
320 320
  *
321 321
  * @param WPInv_Subscription $subscription
322 322
  */
323
-function getpaid_admin_subscription_metabox_display_status( $subscription ) {
323
+function getpaid_admin_subscription_metabox_display_status($subscription) {
324 324
 	echo $subscription->get_status_label_html();
325 325
 }
326
-add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
326
+add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status');
327 327
 
328 328
 /**
329 329
  * Displays the subscription profile id.
330 330
  *
331 331
  * @param WPInv_Subscription $subscription
332 332
  */
333
-function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
333
+function getpaid_admin_subscription_metabox_display_profile_id($subscription) {
334 334
 
335 335
 	$profile_id = $subscription->get_profile_id();
336 336
 
@@ -339,32 +339,32 @@  discard block
 block discarded – undo
339 339
 			'type'        => 'text',
340 340
 			'id'          => 'wpinv_subscription_profile_id',
341 341
 			'name'        => 'wpinv_subscription_profile_id',
342
-			'label'       => __( 'Profile Id', 'invoicing' ),
342
+			'label'       => __('Profile Id', 'invoicing'),
343 343
 			'label_type'  => 'hidden',
344
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
345
-			'value'       => sanitize_text_field( $profile_id ),
344
+			'placeholder' => __('Profile Id', 'invoicing'),
345
+			'value'       => sanitize_text_field($profile_id),
346 346
 			'input_group_right' => '',
347 347
 			'no_wrap'     => true,
348 348
 		)
349 349
 	);
350 350
 
351
-	echo str_ireplace( 'form-control', 'regular-text', $input );
351
+	echo str_ireplace('form-control', 'regular-text', $input);
352 352
 
353
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
354
-	if ( ! empty( $url ) ) {
355
-		$url = esc_url_raw( $url );
356
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
353
+	$url = apply_filters('getpaid_remote_subscription_profile_url', '', $subscription);
354
+	if (!empty($url)) {
355
+		$url = esc_url_raw($url);
356
+		echo '&nbsp;<a href="' . $url . '" title="' . __('View in Gateway', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
357 357
 	}
358 358
 
359 359
 }
360
-add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
360
+add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id');
361 361
 
362 362
 /**
363 363
  * Displays the subscriptions update metabox.
364 364
  * 
365 365
  * @param WPInv_Subscription $subscription
366 366
  */
367
-function getpaid_admin_subscription_update_metabox( $subscription ) {
367
+function getpaid_admin_subscription_update_metabox($subscription) {
368 368
 
369 369
 	?>
370 370
 	<div class="mt-3">
@@ -377,10 +377,10 @@  discard block
 block discarded – undo
377 377
 					'id'               => 'subscription_status_update_select',
378 378
 					'required'         => true,
379 379
 					'no_wrap'          => false,
380
-					'label'            => __( 'Subscription Status', 'invoicing' ),
381
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
380
+					'label'            => __('Subscription Status', 'invoicing'),
381
+					'help_text'        => __('Updating the status will trigger related actions and hooks', 'invoicing'),
382 382
 					'select2'          => true,
383
-					'value'            => $subscription->get_status( 'edit' ),
383
+					'value'            => $subscription->get_status('edit'),
384 384
 				)
385 385
 			);
386 386
 		?>
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
389 389
 	
390 390
 		<?php
391
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
391
+			submit_button(__('Update', 'invoicing'), 'primary', 'submit', false);
392 392
 
393
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
394
-			$anchor = __( 'Renew Subscription', 'invoicing' );
395
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
393
+			$url    = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce'));
394
+			$anchor = __('Renew Subscription', 'invoicing');
395
+			$title  = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing');
396 396
 
397
-			if ( $subscription->is_active() ) {
397
+			if ($subscription->is_active()) {
398 398
 				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
399 399
 			}
400 400
 
@@ -406,31 +406,31 @@  discard block
 block discarded – undo
406 406
  * 
407 407
  * @param WPInv_Subscription $subscription
408 408
  */
409
-function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
409
+function getpaid_admin_subscription_invoice_details_metabox($subscription) {
410 410
 
411 411
 	$columns = apply_filters(
412 412
 		'getpaid_subscription_related_invoices_columns',
413 413
 		array(
414
-			'invoice'      => __( 'Invoice', 'invoicing' ),
415
-			'relationship' => __( 'Relationship', 'invoicing' ),
416
-			'date'         => __( 'Date', 'invoicing' ),
417
-			'status'       => __( 'Status', 'invoicing' ),
418
-			'total'        => __( 'Total', 'invoicing' ),
414
+			'invoice'      => __('Invoice', 'invoicing'),
415
+			'relationship' => __('Relationship', 'invoicing'),
416
+			'date'         => __('Date', 'invoicing'),
417
+			'status'       => __('Status', 'invoicing'),
418
+			'total'        => __('Total', 'invoicing'),
419 419
 		),
420 420
 		$subscription
421 421
 	);
422 422
 
423 423
 	// Prepare the invoices.
424
-	$payments = $subscription->get_child_payments( ! is_admin() );
424
+	$payments = $subscription->get_child_payments(!is_admin());
425 425
 	$parent   = $subscription->get_parent_invoice();
426 426
 
427
-	if ( $parent->get_id() ) {
428
-		$payments = array_merge( array( $parent ), $payments );
427
+	if ($parent->get_id()) {
428
+		$payments = array_merge(array($parent), $payments);
429 429
 	}
430 430
 	
431 431
 	$table_class = 'w-100 bg-white';
432 432
 
433
-	if ( ! is_admin() ) {
433
+	if (!is_admin()) {
434 434
 		$table_class = 'table table-bordered table-striped';
435 435
 	}
436 436
 
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 				<thead>
443 443
 					<tr>
444 444
 						<?php
445
-							foreach ( $columns as $key => $label ) {
446
-								$key   = esc_attr( $key );
447
-								$label = sanitize_text_field( $label );
445
+							foreach ($columns as $key => $label) {
446
+								$key   = esc_attr($key);
447
+								$label = sanitize_text_field($label);
448 448
 
449 449
 								echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>";
450 450
 							}
@@ -454,50 +454,50 @@  discard block
 block discarded – undo
454 454
 
455 455
 				<tbody>
456 456
 
457
-					<?php if ( empty( $payments ) ) : ?>
457
+					<?php if (empty($payments)) : ?>
458 458
 						<tr>
459 459
 							<td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted">
460
-								<?php _e( 'This subscription has no invoices.', 'invoicing' ); ?>
460
+								<?php _e('This subscription has no invoices.', 'invoicing'); ?>
461 461
 							</td>
462 462
 						</tr>
463 463
 					<?php endif; ?>
464 464
 
465 465
 					<?php
466 466
 
467
-						foreach( $payments as $payment ) :
467
+						foreach ($payments as $payment) :
468 468
 
469 469
 							// Ensure that we have an invoice.
470
-							$payment = new WPInv_Invoice( $payment );
470
+							$payment = new WPInv_Invoice($payment);
471 471
 
472 472
 							// Abort if the invoice is invalid.
473
-							if ( ! $payment->get_id() ) {
473
+							if (!$payment->get_id()) {
474 474
 								continue;
475 475
 							}
476 476
 
477 477
 							echo '<tr>';
478 478
 
479
-								foreach ( array_keys( $columns ) as $key ) {
479
+								foreach (array_keys($columns) as $key) {
480 480
 
481 481
 									echo '<td class="p-2 text-left">';
482 482
 
483
-										switch( $key ) {
483
+										switch ($key) {
484 484
 
485 485
 											case 'total':
486
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
486
+												echo '<strong>' . wpinv_price($payment->get_total(), $payment->get_currency()) . '</strong>';
487 487
 												break;
488 488
 
489 489
 											case 'relationship':
490
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
490
+												echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing');
491 491
 												break;
492 492
 
493 493
 											case 'date':
494
-												echo getpaid_format_date_value( $payment->get_date_created() );
494
+												echo getpaid_format_date_value($payment->get_date_created());
495 495
 												break;
496 496
 
497 497
 											case 'status':
498 498
 
499 499
 												$status = $payment->get_status_nicename();
500
-												if ( is_admin() ) {
500
+												if (is_admin()) {
501 501
 													$status = $payment->get_status_label_html();
502 502
 												}
503 503
 
@@ -505,13 +505,13 @@  discard block
 block discarded – undo
505 505
 												break;
506 506
 
507 507
 											case 'invoice':
508
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
508
+												$link = esc_url(get_edit_post_link($payment->get_id()));
509 509
 
510
-												if ( ! is_admin() ) {
511
-													$link = esc_url( $payment->get_view_url() );
510
+												if (!is_admin()) {
511
+													$link = esc_url($payment->get_view_url());
512 512
 												}
513 513
 
514
-												$invoice = sanitize_text_field( $payment->get_number() );
514
+												$invoice = sanitize_text_field($payment->get_number());
515 515
 												echo "<a href='$link'>$invoice</a>";
516 516
 												break;
517 517
 										}
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway-ipn-handler.php 1 patch
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
43 43
 	 */
44 44
 	public function verify_ipn() {
45 45
 
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
46
+		wpinv_error_log('GetPaid PayPal IPN Handler', false);
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', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
58
+		if ($this->id != $invoice->get_gateway()) {
59
+			wpinv_error_log('Aborting, Invoice was not paid via PayPal', false);
60
+			wp_die('Invoice not paid via PayPal', 200);
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'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
66
+		wpinv_error_log('Payment status:' . $posted['payment_status'], false);
67
+		wpinv_error_log('IPN Type:' . $posted['txn_type'], false);
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', false );
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', false);
72
+			wp_die('Processed', 200);
73 73
 		}
74 74
 
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
75
+		wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false);
76
+		wp_die('Unsupported IPN type', 200);
77 77
 
78 78
 	}
79 79
 
@@ -83,22 +83,22 @@  discard block
 block discarded – undo
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', false );
88
+		wpinv_error_log('Retrieving PayPal IPN Response Invoice', false);
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(), false );
93
+			if ($invoice->exists()) {
94
+				wpinv_error_log('Found invoice #' . $invoice->get_number(), false);
95 95
 				return $invoice;
96 96
 			}
97 97
 
98 98
 		}
99 99
 
100
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
100
+		wpinv_error_log('Could not retrieve the associated invoice.', false);
101
+		wp_die('Could not retrieve the associated invoice.', 200);
102 102
 	}
103 103
 
104 104
 	/**
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
 	 */
107 107
 	protected function validate_ipn() {
108 108
 
109
-		wpinv_error_log( 'Validating PayPal IPN response', false );
109
+		wpinv_error_log('Validating PayPal IPN response', false);
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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', false );
206
+		wpinv_error_log('Validated PayPal Email', false);
207 207
 	}
208 208
 
209 209
 	/**
@@ -212,68 +212,68 @@  discard block
 block discarded – undo
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'], false );
239
+			return wpinv_error_log($posted['reason_code'], false);
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.', false );
245
+			if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) {
246
+				return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false);
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.', false );
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.', false);
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".', false );
272
+			return wpinv_error_log('Invoice marked as "payment held".', false);
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
 block discarded – undo
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
 block discarded – undo
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', false );
298
+		wpinv_error_log('Processing subscription signup', false);
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', false );
303
+		if (empty($subscription)) {
304
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
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.', false );
329
+		wpinv_error_log('Subscription started.', false);
330 330
 	}
331 331
 
332 332
 	/**
@@ -335,20 +335,20 @@  discard block
 block discarded – undo
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', false );
343
+		if (empty($subscription)) {
344
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
345 345
 		}
346 346
 
347 347
 		// Abort if this is the first payment.
348
-		if ( ( $invoice->is_paid() && date( 'Ynd', strtotime( $invoice->get_date_completed() ) ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) || date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) {
348
+		if (($invoice->is_paid() && date('Ynd', strtotime($invoice->get_date_completed())) == date('Ynd', strtotime($posted['payment_date']))) || date('Ynd', $subscription->get_time_created()) == date('Ynd', strtotime($posted['payment_date']))) {
349 349
 
350
-			if ( ! empty( $posted['txn_id'] ) ) {
351
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );
350
+			if (!empty($posted['txn_id'])) {
351
+				$invoice->set_transaction_id(sanitize_text_field($posted['txn_id']));
352 352
 				$invoice->mark_paid();
353 353
 				$invoice->save();
354 354
 			}
@@ -356,11 +356,11 @@  discard block
 block discarded – undo
356 356
 			return;
357 357
 		}
358 358
 
359
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
359
+		wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false);
360 360
 
361 361
 		// Abort if the payment is already recorded.
362
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
363
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
362
+		if (wpinv_get_id_by_transaction_id($posted['txn_id'])) {
363
+			return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false);
364 364
 		}
365 365
 
366 366
 		$args = array(
@@ -368,17 +368,17 @@  discard block
 block discarded – undo
368 368
 			'gateway'        => $this->id,
369 369
 		);
370 370
 
371
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
371
+		$invoice = wpinv_get_invoice($subscription->add_payment($args));
372 372
 
373
-		if ( empty( $invoice ) ) {
373
+		if (empty($invoice)) {
374 374
 			return;
375 375
 		}
376 376
 
377
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
378
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
377
+		$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
378
+		$invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
379 379
 
380 380
 		$subscription->renew();
381
-		wpinv_error_log( 'Subscription renewed.', false );
381
+		wpinv_error_log('Subscription renewed.', false);
382 382
 
383 383
 	}
384 384
 
@@ -387,18 +387,18 @@  discard block
 block discarded – undo
387 387
 	 *
388 388
 	 * @param WPInv_Invoice $invoice  Invoice object.
389 389
 	 */
390
-	protected function ipn_txn_subscr_cancel( $invoice ) {
390
+	protected function ipn_txn_subscr_cancel($invoice) {
391 391
 
392 392
 		// Make sure the invoice has a subscription.
393
-		$subscription = wpinv_get_subscription( $invoice );
393
+		$subscription = wpinv_get_subscription($invoice);
394 394
 
395
-		if ( empty( $subscription ) ) {
396
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
395
+		if (empty($subscription)) {
396
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
397 397
 		}
398 398
 
399
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
399
+		wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false);
400 400
 		$subscription->cancel();
401
-		wpinv_error_log( 'Subscription cancelled.', false );
401
+		wpinv_error_log('Subscription cancelled.', false);
402 402
 
403 403
 	}
404 404
 
@@ -408,18 +408,18 @@  discard block
 block discarded – undo
408 408
 	 * @param WPInv_Invoice $invoice  Invoice object.
409 409
 	 * @param array    $posted Posted data.
410 410
 	 */
411
-	protected function ipn_txn_subscr_eot( $invoice ) {
411
+	protected function ipn_txn_subscr_eot($invoice) {
412 412
 
413 413
 		// Make sure the invoice has a subscription.
414
-		$subscription = wpinv_get_subscription( $invoice );
414
+		$subscription = wpinv_get_subscription($invoice);
415 415
 
416
-		if ( empty( $subscription ) ) {
417
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
416
+		if (empty($subscription)) {
417
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
418 418
 		}
419 419
 
420
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
420
+		wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false);
421 421
 		$subscription->complete();
422
-		wpinv_error_log( 'Subscription completed.', false );
422
+		wpinv_error_log('Subscription completed.', false);
423 423
 
424 424
 	}
425 425
 
@@ -429,18 +429,18 @@  discard block
 block discarded – undo
429 429
 	 * @param WPInv_Invoice $invoice  Invoice object.
430 430
 	 * @param array    $posted Posted data.
431 431
 	 */
432
-	protected function ipn_txn_subscr_failed( $invoice ) {
432
+	protected function ipn_txn_subscr_failed($invoice) {
433 433
 
434 434
 		// Make sure the invoice has a subscription.
435
-		$subscription = wpinv_get_subscription( $invoice );
435
+		$subscription = wpinv_get_subscription($invoice);
436 436
 
437
-		if ( empty( $subscription ) ) {
438
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
437
+		if (empty($subscription)) {
438
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
439 439
 		}
440 440
 
441
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
441
+		wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false);
442 442
 		$subscription->failing();
443
-		wpinv_error_log( 'Subscription marked as failing.', false );
443
+		wpinv_error_log('Subscription marked as failing.', false);
444 444
 
445 445
 	}
446 446
 
@@ -450,18 +450,18 @@  discard block
 block discarded – undo
450 450
 	 * @param WPInv_Invoice $invoice  Invoice object.
451 451
 	 * @param array    $posted Posted data.
452 452
 	 */
453
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
453
+	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) {
454 454
 
455 455
 		// Make sure the invoice has a subscription.
456
-		$subscription = wpinv_get_subscription( $invoice );
456
+		$subscription = wpinv_get_subscription($invoice);
457 457
 
458
-		if ( empty( $subscription ) ) {
459
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
458
+		if (empty($subscription)) {
459
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
460 460
 		}
461 461
 
462
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
462
+		wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false);
463 463
 		$subscription->cancel();
464
-		wpinv_error_log( 'Subscription cancelled.', false );
464
+		wpinv_error_log('Subscription cancelled.', false);
465 465
 	}
466 466
 
467 467
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Spacing   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Abstaract Payment Gateway class.
@@ -139,55 +139,55 @@  discard block
 block discarded – undo
139 139
 	public function __construct() {
140 140
 
141 141
 		// Register gateway.
142
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
142
+		add_filter('wpinv_payment_gateways', array($this, 'register_gateway'));
143 143
 
144
-		$this->enabled = wpinv_is_gateway_active( $this->id );
144
+		$this->enabled = wpinv_is_gateway_active($this->id);
145 145
 
146 146
 		// Enable Subscriptions.
147
-		if ( $this->supports( 'subscription' ) ) {
148
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
147
+		if ($this->supports('subscription')) {
148
+			add_filter("wpinv_{$this->id}_support_subscription", '__return_true');
149 149
 		}
150 150
 
151 151
 		// Enable sandbox.
152
-		if ( $this->supports( 'sandbox' ) ) {
153
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
152
+		if ($this->supports('sandbox')) {
153
+			add_filter("wpinv_{$this->id}_supports_sandbox", '__return_true');
154 154
 		}
155 155
 
156 156
 		// Invoice addons.
157
-		if ( $this->supports( 'addons' ) ) {
158
-			add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
157
+		if ($this->supports('addons')) {
158
+			add_filter("getpaid_{$this->id}_supports_addons", '__return_true');
159
+			add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2);
160 160
 		}
161 161
 
162 162
 		// Gateway settings.
163
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
163
+		add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings'));
164 164
 		
165 165
 
166 166
 		// Gateway checkout fiellds.
167
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
167
+		add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2);
168 168
 
169 169
 		// Process payment.
170
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
170
+		add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3);
171 171
 
172 172
 		// Change the checkout button text.
173
-		if ( ! empty( $this->checkout_button_text ) ) {
174
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
173
+		if (!empty($this->checkout_button_text)) {
174
+			add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button'));
175 175
 		}
176 176
 
177 177
 		// Check if a gateway is valid for a given currency.
178
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
178
+		add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2);
179 179
 
180 180
 		// Generate the transaction url.
181
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
181
+		add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2);
182 182
 
183 183
 		// Generate the subscription url.
184
-		add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
184
+		add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2);
185 185
 
186 186
 		// Confirm payments.
187
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
187
+		add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2);
188 188
 
189 189
 		// Verify IPNs.
190
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
190
+		add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn'));
191 191
 
192 192
 	}
193 193
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 * @since 1.0.19
198 198
 	 * @return bool
199 199
 	 */
200
-	public function is( $gateway ) {
200
+	public function is($gateway) {
201 201
 		return $gateway == $this->id;
202 202
 	}
203 203
 
@@ -207,23 +207,23 @@  discard block
 block discarded – undo
207 207
 	 * @since 1.0.19
208 208
 	 * @return array
209 209
 	 */
210
-	public function get_tokens( $sandbox = null ) {
210
+	public function get_tokens($sandbox = null) {
211 211
 
212
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
212
+		if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) {
213
+			$tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true);
214 214
 
215
-			if ( is_array( $tokens ) ) {
215
+			if (is_array($tokens)) {
216 216
 				$this->tokens = $tokens;
217 217
 			}
218 218
 
219 219
 		}
220 220
 
221
-		if ( ! is_bool( $sandbox ) ) {
221
+		if (!is_bool($sandbox)) {
222 222
 			return $this->tokens;
223 223
 		}
224 224
 
225
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
-		return wp_list_filter( $this->tokens, $args );
225
+		$args = array('type' => $sandbox ? 'sandbox' : 'live');
226
+		return wp_list_filter($this->tokens, $args);
227 227
 
228 228
 	}
229 229
 
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 	 *
233 233
 	 * @since 1.0.19
234 234
 	 */
235
-	public function save_token( $token ) {
235
+	public function save_token($token) {
236 236
 
237 237
 		$tokens   = $this->get_tokens();
238 238
 		$tokens[] = $token;
239 239
 
240
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
240
+		update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens);
241 241
 
242 242
 		$this->tokens = $tokens;
243 243
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * @return string
250 250
 	 */
251 251
 	public function get_method_title() {
252
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
252
+		return apply_filters('getpaid_gateway_method_title', $this->method_title, $this);
253 253
 	}
254 254
 
255 255
 	/**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	 * @return string
259 259
 	 */
260 260
 	public function get_method_description() {
261
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
261
+		return apply_filters('getpaid_gateway_method_description', $this->method_description, $this);
262 262
 	}
263 263
 
264 264
 	/**
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @param WPInv_Invoice $invoice Invoice object.
268 268
 	 * @return string
269 269
 	 */
270
-	public function get_return_url( $invoice ) {
270
+	public function get_return_url($invoice) {
271 271
 
272 272
 		// Payment success url
273 273
 		$return_url = add_query_arg(
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 			wpinv_get_success_page_uri()
280 280
 		);
281 281
 
282
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
282
+		return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this);
283 283
 	}
284 284
 
285 285
 	/**
@@ -288,24 +288,24 @@  discard block
 block discarded – undo
288 288
 	 * @param string $content Success page content.
289 289
 	 * @return string
290 290
 	 */
291
-	public function confirm_payment( $content ) {
291
+	public function confirm_payment($content) {
292 292
 
293 293
 		// Retrieve the invoice.
294 294
 		$invoice_id = getpaid_get_current_invoice_id();
295
-		$invoice    = wpinv_get_invoice( $invoice_id );
295
+		$invoice    = wpinv_get_invoice($invoice_id);
296 296
 
297 297
 		// Ensure that it exists and that it is pending payment.
298
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
298
+		if (empty($invoice_id) || !$invoice->needs_payment()) {
299 299
 			return $content;
300 300
 		}
301 301
 
302 302
 		// Can the user view this invoice??
303
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
303
+		if (!wpinv_user_can_view_invoice($invoice)) {
304 304
 			return $content;
305 305
 		}
306 306
 
307 307
 		// Show payment processing indicator.
308
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
308
+		return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice'));
309 309
 	}
310 310
 
311 311
 	/**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @param GetPaid_Form_Item[] $items
323 323
 	 * @return WPInv_Invoice
324 324
 	 */
325
-	public function process_addons( $invoice, $items ) {
325
+	public function process_addons($invoice, $items) {
326 326
 
327 327
 	}
328 328
 
@@ -333,14 +333,14 @@  discard block
 block discarded – undo
333 333
 	 * @param WPInv_Invoice $invoice Invoice object.
334 334
 	 * @return string transaction URL, or empty string.
335 335
 	 */
336
-	public function filter_transaction_url( $transaction_url, $invoice ) {
336
+	public function filter_transaction_url($transaction_url, $invoice) {
337 337
 
338
-		$transaction_id  = $invoice->get_transaction_id();
338
+		$transaction_id = $invoice->get_transaction_id();
339 339
 
340
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
340
+		if (!empty($this->view_transaction_url) && !empty($transaction_id)) {
341
+			$transaction_url = sprintf($this->view_transaction_url, $transaction_id);
342
+			$replace         = $this->is_sandbox($invoice) ? 'sandbox' : '';
343
+			$transaction_url = str_replace('{sandbox}', $replace, $transaction_url);
344 344
 		}
345 345
 
346 346
 		return $transaction_url;
@@ -353,15 +353,15 @@  discard block
 block discarded – undo
353 353
 	 * @param WPInv_Subscription $subscription Subscription objectt.
354 354
 	 * @return string subscription URL, or empty string.
355 355
 	 */
356
-	public function generate_subscription_url( $subscription_url, $subscription ) {
356
+	public function generate_subscription_url($subscription_url, $subscription) {
357 357
 
358
-		$profile_id      = $subscription->get_profile_id();
358
+		$profile_id = $subscription->get_profile_id();
359 359
 
360
-		if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
360
+		if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) {
361 361
 
362
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
-			$replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
364
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
362
+			$subscription_url = sprintf($this->view_subscription_url, $profile_id);
363
+			$replace          = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : '';
364
+			$subscription_url = str_replace('{sandbox}', $replace, $subscription_url);
365 365
 
366 366
 		}
367 367
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 	 * @return bool
375 375
 	 */
376 376
 	public function is_available() {
377
-		return ! empty( $this->enabled );
377
+		return !empty($this->enabled);
378 378
 	}
379 379
 
380 380
 	/**
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 	 * @return string
384 384
 	 */
385 385
 	public function get_title() {
386
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
386
+		return apply_filters('getpaid_gateway_title', $this->title, $this);
387 387
 	}
388 388
 
389 389
 	/**
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	 * @return string
393 393
 	 */
394 394
 	public function get_description() {
395
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
395
+		return apply_filters('getpaid_gateway_description', $this->description, $this);
396 396
 	}
397 397
 
398 398
 	/**
@@ -404,9 +404,9 @@  discard block
 block discarded – undo
404 404
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405 405
 	 * @return void
406 406
 	 */
407
-	public function process_payment( $invoice, $submission_data, $submission ) {
407
+	public function process_payment($invoice, $submission_data, $submission) {
408 408
 		// Process the payment then either redirect to the success page or the gateway.
409
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
409
+		do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission);
410 410
 	}
411 411
 
412 412
 	/**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $reason Refund reason.
421 421
 	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
422 422
 	 */
423
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
423
+	public function process_refund($invoice, $amount = null, $reason = '') {
424
+		return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason);
425 425
 	}
426 426
 
427 427
 	/**
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
 	 * @param int $invoice_id 0 or invoice id.
431 431
 	 * @param GetPaid_Payment_Form $form Current payment form.
432 432
 	 */
433
-	public function payment_fields( $invoice_id, $form ) {
434
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
433
+	public function payment_fields($invoice_id, $form) {
434
+		do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form);
435 435
 	}
436 436
 
437 437
 	/**
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	 * 
440 440
 	 * @param array $admin_settings
441 441
 	 */
442
-	public function admin_settings( $admin_settings ) {
442
+	public function admin_settings($admin_settings) {
443 443
 		return $admin_settings;
444 444
 	}
445 445
 
@@ -448,8 +448,8 @@  discard block
 block discarded – undo
448 448
 	 * 
449 449
 	 * @param string $option
450 450
 	 */
451
-	public function get_option( $option, $default = false ) {
452
-		return wpinv_get_option( $this->id . '_' . $option, $default );
451
+	public function get_option($option, $default = false) {
452
+		return wpinv_get_option($this->id . '_' . $option, $default);
453 453
 	}
454 454
 
455 455
 	/**
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 	 * @return bool True if the gateway supports the feature, false otherwise.
463 463
 	 * @since 1.0.19
464 464
 	 */
465
-	public function supports( $feature ) {
466
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
465
+	public function supports($feature) {
466
+		return apply_filters('getpaid_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this);
467 467
 	}
468 468
 
469 469
 	/**
@@ -471,36 +471,36 @@  discard block
 block discarded – undo
471 471
 	 * 
472 472
 	 * @param bool $save whether or not to display the save button.
473 473
 	 */
474
-    public function get_cc_form( $save = false ) {
474
+    public function get_cc_form($save = false) {
475 475
 
476 476
 		ob_start();
477 477
 
478
-        $id_prefix = esc_attr( uniqid( $this->id ) );
478
+        $id_prefix = esc_attr(uniqid($this->id));
479 479
 
480 480
         $months = array(
481
-            '01' => __( 'January', 'invoicing' ),
482
-            '02' => __( 'February', 'invoicing' ),
483
-            '03' => __( 'March', 'invoicing' ),
484
-            '04' => __( 'April', 'invoicing' ),
485
-            '05' => __( 'May', 'invoicing' ),
486
-            '06' => __( 'June', 'invoicing' ),
487
-            '07' => __( 'July', 'invoicing' ),
488
-            '08' => __( 'August', 'invoicing' ),
489
-            '09' => __( 'September', 'invoicing' ),
490
-            '10' => __( 'October', 'invoicing' ),
491
-            '11' => __( 'November', 'invoicing' ),
492
-            '12' => __( 'December', 'invoicing' ),
481
+            '01' => __('January', 'invoicing'),
482
+            '02' => __('February', 'invoicing'),
483
+            '03' => __('March', 'invoicing'),
484
+            '04' => __('April', 'invoicing'),
485
+            '05' => __('May', 'invoicing'),
486
+            '06' => __('June', 'invoicing'),
487
+            '07' => __('July', 'invoicing'),
488
+            '08' => __('August', 'invoicing'),
489
+            '09' => __('September', 'invoicing'),
490
+            '10' => __('October', 'invoicing'),
491
+            '11' => __('November', 'invoicing'),
492
+            '12' => __('December', 'invoicing'),
493 493
         );
494 494
 
495
-        $year  = (int) date( 'Y', current_time( 'timestamp' ) );
495
+        $year  = (int) date('Y', current_time('timestamp'));
496 496
         $years = array();
497 497
 
498
-        for ( $i = 0; $i <= 10; $i++ ) {
499
-            $years[ $year + $i ] = $year + $i;
498
+        for ($i = 0; $i <= 10; $i++) {
499
+            $years[$year + $i] = $year + $i;
500 500
         }
501 501
 
502 502
         ?>
503
-            <div class="<?php echo esc_attr( $this->id );?>-cc-form getpaid-cc-form mt-1">
503
+            <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1">
504 504
 
505 505
 
506 506
                 <div class="getpaid-cc-card-inner">
@@ -509,14 +509,14 @@  discard block
 block discarded – undo
509 509
                         <div class="col-12">
510 510
 
511 511
 							<div class="form-group">
512
-								<label for="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>"><?php _e( 'Card number', 'invoicing' ); ?></label>
512
+								<label for="<?php echo esc_attr("$id_prefix-cc-number") ?>"><?php _e('Card number', 'invoicing'); ?></label>
513 513
 								<div class="input-group input-group-sm">
514 514
 									<div class="input-group-prepend ">
515 515
 										<span class="input-group-text">
516 516
 											<i class="fa fa-credit-card"></i>
517 517
 										</span>
518 518
 									</div>
519
-									<input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ) ?>authorizenet[cc_number]" id="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>" class="form-control form-control-sm" autocomplete="cc-number">
519
+									<input type="text" name="<?php echo esc_attr($this->id . '[cc_number]') ?>authorizenet[cc_number]" id="<?php echo esc_attr("$id_prefix-cc-number") ?>" class="form-control form-control-sm" autocomplete="cc-number">
520 520
 								</div>
521 521
 							</div>
522 522
 
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 
525 525
                         <div class="col-12">
526 526
                             <div class="form-group">
527
-                                <label><?php _e( 'Expiration', 'invoicing' ); ?></label>
527
+                                <label><?php _e('Expiration', 'invoicing'); ?></label>
528 528
                                 <div class="form-row">
529 529
 
530 530
                                     <div class="col">
531
-                                        <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id );?>[cc_expire_month]">
532
-                                            <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option>
531
+                                        <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]">
532
+                                            <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option>
533 533
 
534 534
                                             <?php
535
-                                                foreach ( $months as $key => $month ) {
536
-                                                    $key   = esc_attr( $key );
537
-                                                    $month = wpinv_clean( $month );
535
+                                                foreach ($months as $key => $month) {
536
+                                                    $key   = esc_attr($key);
537
+                                                    $month = wpinv_clean($month);
538 538
                                                     echo "<option value='$key'>$month</option>" . PHP_EOL;
539 539
                                                 }
540 540
                                             ?>
@@ -543,13 +543,13 @@  discard block
 block discarded – undo
543 543
                                     </div>
544 544
 
545 545
                                     <div class="col">
546
-                                        <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id );?>[cc_expire_year]">
547
-                                            <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option>
546
+                                        <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]">
547
+                                            <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option>
548 548
 
549 549
                                             <?php
550
-                                                foreach ( $years as $key => $year ) {
551
-                                                    $key   = esc_attr( $key );
552
-                                                    $year  = wpinv_clean( $year );
550
+                                                foreach ($years as $key => $year) {
551
+                                                    $key   = esc_attr($key);
552
+                                                    $year  = wpinv_clean($year);
553 553
                                                     echo "<option value='$key'>$year</option>" . PHP_EOL;
554 554
                                                 }
555 555
                                             ?>
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
                                     array(
568 568
                                         'name'              => $this->id . '[cc_cvv2]',
569 569
                                         'id'                => "$id_prefix-cc-cvv2",
570
-                                        'label'             => __( 'CCV', 'invoicing' ),
570
+                                        'label'             => __('CCV', 'invoicing'),
571 571
 										'label_type'        => 'vertical',
572 572
 										'class'             => 'form-control-sm',
573 573
 										'extra_attributes'  => array(
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 					
583 583
 					<?php
584 584
 
585
-						if ( $save ) {
585
+						if ($save) {
586 586
 							echo $this->save_payment_method_checkbox();
587 587
 						}
588 588
 
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 	 *
602 602
 	 * @since 1.0.19
603 603
 	 */
604
-	public function new_payment_method_entry( $form ) {
604
+	public function new_payment_method_entry($form) {
605 605
 		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
606 606
 	}
607 607
 
@@ -611,16 +611,16 @@  discard block
 block discarded – undo
611 611
 	 * @since 1.0.19
612 612
 	 */
613 613
 	public function saved_payment_methods() {
614
-		$html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
614
+		$html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">';
615 615
 
616
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
617
-			$html .= $this->get_saved_payment_method_option_html( $token );
616
+		foreach ($this->get_tokens($this->is_sandbox()) as $token) {
617
+			$html .= $this->get_saved_payment_method_option_html($token);
618 618
 		}
619 619
 
620 620
 		$html .= $this->get_new_payment_method_option_html();
621 621
 		$html .= '</ul>';
622 622
 
623
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
623
+		echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this);
624 624
 	}
625 625
 
626 626
 	/**
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 * @param  array $token Payment Token.
631 631
 	 * @return string Generated payment method HTML
632 632
 	 */
633
-	public function get_saved_payment_method_option_html( $token ) {
633
+	public function get_saved_payment_method_option_html($token) {
634 634
 
635 635
 		return sprintf(
636 636
 			'<li class="getpaid-payment-method form-group">
@@ -639,10 +639,10 @@  discard block
 block discarded – undo
639 639
 					<span>%3$s</span>
640 640
 				</label>
641 641
 			</li>',
642
-			esc_attr( $this->id ),
643
-			esc_attr( $token['id'] ),
644
-			esc_html( $token['name'] ),
645
-			checked( empty( $token['default'] ), false, false )
642
+			esc_attr($this->id),
643
+			esc_attr($token['id']),
644
+			esc_html($token['name']),
645
+			checked(empty($token['default']), false, false)
646 646
 		);
647 647
 
648 648
 	}
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 */
655 655
 	public function get_new_payment_method_option_html() {
656 656
 
657
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
657
+		$label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this);
658 658
 
659 659
 		return sprintf(
660 660
 			'<li class="getpaid-new-payment-method">
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
 					<span>%2$s</span>
664 664
 				</label>
665 665
 			</li>',
666
-			esc_attr( $this->id ),
667
-			esc_html( $label )
666
+			esc_attr($this->id),
667
+			esc_html($label)
668 668
 		);
669 669
 
670 670
 	}
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
 		return aui()->input(
680 680
 			array(
681 681
 				'type'       => 'checkbox',
682
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
683
-				'id'         => esc_attr( uniqid( $this->id ) ),
682
+				'name'       => esc_attr("getpaid-$this->id-new-payment-method"),
683
+				'id'         => esc_attr(uniqid($this->id)),
684 684
 				'required'   => false,
685
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
685
+				'label'      => esc_html__('Save payment method', 'invoicing'),
686 686
 				'value'      => 'true',
687 687
 				'checked'    => true,
688 688
 				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
@@ -696,9 +696,9 @@  discard block
 block discarded – undo
696 696
 	 *
697 697
 	 * @return array
698 698
 	 */
699
-	public function register_gateway( $gateways ) {
699
+	public function register_gateway($gateways) {
700 700
 
701
-		$gateways[ $this->id ] = array(
701
+		$gateways[$this->id] = array(
702 702
 
703 703
 			'admin_label'    => $this->method_title,
704 704
             'checkout_label' => $this->title,
@@ -716,13 +716,13 @@  discard block
 block discarded – undo
716 716
 	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
717 717
 	 * @return bool
718 718
 	 */
719
-	public function is_sandbox( $invoice = null ) {
719
+	public function is_sandbox($invoice = null) {
720 720
 
721
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
721
+		if (!empty($invoice) && !$invoice->needs_payment()) {
722 722
 			return $invoice->get_mode() == 'test';
723 723
 		}
724 724
 
725
-		return wpinv_is_test_mode( $this->id );
725
+		return wpinv_is_test_mode($this->id);
726 726
 
727 727
 	}
728 728
 
@@ -740,15 +740,15 @@  discard block
 block discarded – undo
740 740
 	 *
741 741
 	 * @return bool
742 742
 	 */
743
-	public function validate_currency( $validation, $currency ) {
743
+	public function validate_currency($validation, $currency) {
744 744
 
745 745
 		// Required currencies.
746
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
746
+		if (!empty($this->currencies) && !in_array($currency, $this->currencies)) {
747 747
 			return false;
748 748
 		}
749 749
 
750 750
 		// Excluded currencies.
751
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
751
+		if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) {
752 752
 			return false;
753 753
 		}
754 754
 
@@ -759,13 +759,13 @@  discard block
 block discarded – undo
759 759
 	 * Displays an error
760 760
 	 *
761 761
 	 */
762
-	public function show_error( $code, $message, $type ) {
762
+	public function show_error($code, $message, $type) {
763 763
 
764
-		if ( is_admin() ) {
765
-			getpaid_admin()->{"show_$type"}( $message );
764
+		if (is_admin()) {
765
+			getpaid_admin()->{"show_$type"}($message);
766 766
 		}
767 767
 
768
-		wpinv_set_error( $code, $message, $type );
768
+		wpinv_set_error($code, $message, $type);
769 769
 
770 770
 	}
771 771
 
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions.php 1 patch
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,34 +120,34 @@  discard block
 block discarded – undo
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
-        $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce' ) );
148
+        $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce'));
149 149
 
150
-        wp_safe_redirect( $redirect );
150
+        wp_safe_redirect($redirect);
151 151
         exit;
152 152
 
153 153
     }
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
      * @param       WPInv_Invoice $invoice
160 160
      * @since       1.0.0
161 161
      */
162
-    public function maybe_create_invoice_subscription( $invoice ) {
162
+    public function maybe_create_invoice_subscription($invoice) {
163 163
 
164 164
         // Abort if it is not recurring.
165
-        if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) {
165
+        if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) {
166 166
             return;
167 167
         }
168 168
 
169 169
         $subscription = new WPInv_Subscription();
170
-        return $this->update_invoice_subscription( $subscription, $invoice );
170
+        return $this->update_invoice_subscription($subscription, $invoice);
171 171
 
172 172
     }
173 173
 
@@ -178,32 +178,32 @@  discard block
 block discarded – undo
178 178
      * @param       WPInv_Invoice $invoice
179 179
      * @since       1.0.19
180 180
      */
181
-    public function maybe_update_invoice_subscription( $invoice ) {
181
+    public function maybe_update_invoice_subscription($invoice) {
182 182
 
183 183
         // Do not process renewals.
184
-        if ( $invoice->is_renewal() ) {
184
+        if ($invoice->is_renewal()) {
185 185
             return;
186 186
         }
187 187
 
188 188
         // Delete existing subscription if available and the invoice is not recurring.
189
-        if ( ! $invoice->is_recurring() ) {
190
-            $subscription = new WPInv_Subscription( $invoice->get_subscription_id() );
191
-            $subscription->delete( true );
189
+        if (!$invoice->is_recurring()) {
190
+            $subscription = new WPInv_Subscription($invoice->get_subscription_id());
191
+            $subscription->delete(true);
192 192
             return;
193 193
         }
194 194
 
195 195
         // (Maybe) create a new subscription.
196
-        $subscription = $this->get_invoice_subscription( $invoice );
197
-        if ( empty( $subscription ) ) {
198
-            return $this->maybe_create_invoice_subscription( $invoice );
196
+        $subscription = $this->get_invoice_subscription($invoice);
197
+        if (empty($subscription)) {
198
+            return $this->maybe_create_invoice_subscription($invoice);
199 199
         }
200 200
 
201 201
         // Abort if an invoice is paid and already has a subscription.
202
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
202
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
203 203
             return;
204 204
         }
205 205
 
206
-        return $this->update_invoice_subscription( $subscription, $invoice );
206
+        return $this->update_invoice_subscription($subscription, $invoice);
207 207
 
208 208
     }
209 209
 
@@ -215,57 +215,57 @@  discard block
 block discarded – undo
215 215
      * @param       WPInv_Invoice $invoice
216 216
      * @since       1.0.19
217 217
      */
218
-    public function update_invoice_subscription( $subscription, $invoice ) {
218
+    public function update_invoice_subscription($subscription, $invoice) {
219 219
 
220 220
         // Delete the subscription if an invoice is free or nolonger recurring.
221
-        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) {
221
+        if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) {
222 222
             return $subscription->delete();
223 223
         }
224 224
 
225
-        $subscription->set_customer_id( $invoice->get_customer_id() );
226
-        $subscription->set_parent_invoice_id( $invoice->get_id() );
227
-        $subscription->set_initial_amount( $invoice->get_initial_total() );
228
-        $subscription->set_recurring_amount( $invoice->get_recurring_total() );
229
-        $subscription->set_date_created( current_time( 'mysql' ) );
230
-        $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' );
225
+        $subscription->set_customer_id($invoice->get_customer_id());
226
+        $subscription->set_parent_invoice_id($invoice->get_id());
227
+        $subscription->set_initial_amount($invoice->get_initial_total());
228
+        $subscription->set_recurring_amount($invoice->get_recurring_total());
229
+        $subscription->set_date_created(current_time('mysql'));
230
+        $subscription->set_status($invoice->is_paid() ? 'active' : 'pending');
231 231
 
232 232
         // Get the recurring item and abort if it does not exist.
233
-        $subscription_item = $invoice->get_recurring( true );
234
-        if ( ! $subscription_item->get_id() ) {
233
+        $subscription_item = $invoice->get_recurring(true);
234
+        if (!$subscription_item->get_id()) {
235 235
             $invoice->set_subscription_id(0);
236 236
             $invoice->save();
237 237
             return $subscription->delete();
238 238
         }
239 239
 
240
-        $subscription->set_product_id( $subscription_item->get_id() );
241
-        $subscription->set_period( $subscription_item->get_recurring_period( true ) );
242
-        $subscription->set_frequency( $subscription_item->get_recurring_interval() );
243
-        $subscription->set_bill_times( $subscription_item->get_recurring_limit() );
240
+        $subscription->set_product_id($subscription_item->get_id());
241
+        $subscription->set_period($subscription_item->get_recurring_period(true));
242
+        $subscription->set_frequency($subscription_item->get_recurring_interval());
243
+        $subscription->set_bill_times($subscription_item->get_recurring_limit());
244 244
 
245 245
         // Calculate the next renewal date.
246
-        $period       = $subscription_item->get_recurring_period( true );
246
+        $period       = $subscription_item->get_recurring_period(true);
247 247
         $interval     = $subscription_item->get_recurring_interval();
248 248
 
249 249
         // If the subscription item has a trial period...
250
-        if ( $subscription_item->has_free_trial() ) {
251
-            $period   = $subscription_item->get_trial_period( true );
250
+        if ($subscription_item->has_free_trial()) {
251
+            $period   = $subscription_item->get_trial_period(true);
252 252
             $interval = $subscription_item->get_trial_interval();
253
-            $subscription->set_trial_period( $interval . ' ' . $period );
254
-            $subscription->set_status( 'trialling' );
253
+            $subscription->set_trial_period($interval . ' ' . $period);
254
+            $subscription->set_status('trialling');
255 255
         }
256 256
 
257 257
         // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial.
258
-        if ( $invoice->has_free_trial() ) {
259
-            $subscription->set_trial_period( $interval . ' ' . $period );
260
-            $subscription->set_status( 'trialling' );
258
+        if ($invoice->has_free_trial()) {
259
+            $subscription->set_trial_period($interval . ' ' . $period);
260
+            $subscription->set_status('trialling');
261 261
         }
262 262
 
263 263
         // Calculate the next renewal date.
264
-        $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) );
264
+        $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created())));
265 265
 
266
-        $subscription->set_next_renewal_date( $expiration );
266
+        $subscription->set_next_renewal_date($expiration);
267 267
         $subscription->save();
268
-        $invoice->set_subscription_id( $subscription->get_id() );
268
+        $invoice->set_subscription_id($subscription->get_id());
269 269
         return $subscription->get_id();
270 270
 
271 271
     }
@@ -276,27 +276,27 @@  discard block
 block discarded – undo
276 276
      * @param       array $data
277 277
      * @since       1.0.19
278 278
      */
279
-    public function admin_update_single_subscription( $args ) {
279
+    public function admin_update_single_subscription($args) {
280 280
 
281 281
         // Ensure the subscription exists and that a status has been given.
282
-        if ( empty( $args['subscription_id'] ) ) {
282
+        if (empty($args['subscription_id'])) {
283 283
             return;
284 284
         }
285 285
 
286 286
         // Retrieve the subscriptions.
287
-        $subscription = new WPInv_Subscription( $args['subscription_id'] );
287
+        $subscription = new WPInv_Subscription($args['subscription_id']);
288 288
 
289
-        if ( $subscription->get_id() ) {
289
+        if ($subscription->get_id()) {
290 290
 
291 291
             $subscription->set_props(
292 292
                 array(
293
-                    'status'     => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null,
294
-                    'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null,
293
+                    'status'     => isset($args['subscription_status']) ? $args['subscription_status'] : null,
294
+                    'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null,
295 295
                 )
296 296
             );
297 297
 
298 298
             $subscription->save();
299
-            getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) );
299
+            getpaid_admin()->show_info(__('Subscription updated', 'invoicing'));
300 300
 
301 301
         }
302 302
 
@@ -308,27 +308,27 @@  discard block
 block discarded – undo
308 308
      * @param       array $data
309 309
      * @since       1.0.19
310 310
      */
311
-    public function admin_renew_single_subscription( $args ) {
311
+    public function admin_renew_single_subscription($args) {
312 312
 
313 313
         // Ensure the subscription exists and that a status has been given.
314
-        if ( empty( $args['id'] ) ) {
314
+        if (empty($args['id'])) {
315 315
             return;
316 316
         }
317 317
 
318 318
         // Retrieve the subscriptions.
319
-        $subscription = new WPInv_Subscription( $args['id'] );
319
+        $subscription = new WPInv_Subscription($args['id']);
320 320
 
321
-        if ( $subscription->get_id() ) {
321
+        if ($subscription->get_id()) {
322 322
 
323
-            do_action( 'getpaid_admin_renew_subscription', $subscription );
323
+            do_action('getpaid_admin_renew_subscription', $subscription);
324 324
 
325
-            $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) );
325
+            $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_'));
326 326
 
327
-            if ( ! $subscription->add_payment( $args ) ) {
328
-                getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) );
327
+            if (!$subscription->add_payment($args)) {
328
+                getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing'));
329 329
             } else {
330 330
                 $subscription->renew();
331
-                getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) );
331
+                getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing'));
332 332
             } 
333 333
 
334 334
             wp_safe_redirect(
@@ -351,20 +351,20 @@  discard block
 block discarded – undo
351 351
      * @param       array $data
352 352
      * @since       1.0.19
353 353
      */
354
-    public function admin_delete_single_subscription( $args ) {
354
+    public function admin_delete_single_subscription($args) {
355 355
 
356 356
         // Ensure the subscription exists and that a status has been given.
357
-        if ( empty( $args['id'] ) ) {
357
+        if (empty($args['id'])) {
358 358
             return;
359 359
         }
360 360
 
361 361
         // Retrieve the subscriptions.
362
-        $subscription = new WPInv_Subscription( $args['id'] );
362
+        $subscription = new WPInv_Subscription($args['id']);
363 363
 
364
-        if ( $subscription->delete() ) {
365
-            getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) );
364
+        if ($subscription->delete()) {
365
+            getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing'));
366 366
         } else {
367
-            getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) );
367
+            getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing'));
368 368
         }
369 369
     
370 370
         $redirected = wp_safe_redirect(
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
             )
378 378
         );
379 379
 
380
-        if ( $redirected ) {
380
+        if ($redirected) {
381 381
             exit;
382 382
         }
383 383
 
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
      * @param WPInv_Item $item
391 391
      * @param WPInv_Invoice $invoice
392 392
      */
393
-    public function filter_invoice_line_item_actions( $actions, $item, $invoice ) {
393
+    public function filter_invoice_line_item_actions($actions, $item, $invoice) {
394 394
 
395 395
         // Fetch item subscription.
396
-        $args  = array(
396
+        $args = array(
397 397
             'invoice_in'  => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(),
398 398
             'product_in'  => $item->get_id(),
399 399
             'number'      => 1,
@@ -401,13 +401,13 @@  discard block
 block discarded – undo
401 401
             'fields'      => 'id',
402 402
         );
403 403
 
404
-        $subscription = new GetPaid_Subscriptions_Query( $args );
404
+        $subscription = new GetPaid_Subscriptions_Query($args);
405 405
         $subscription = $subscription->get_results();
406 406
 
407 407
         // In case we found a match...
408
-        if ( ! empty( $subscription ) ) {
409
-            $url                     = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) );
410
-            $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
408
+        if (!empty($subscription)) {
409
+            $url                     = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page'))));
410
+            $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>';
411 411
         }
412 412
 
413 413
         return $actions;
Please login to merge, or discard this patch.