@@ -8,23 +8,23 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | function wpinv_subscriptions_page() { |
| 10 | 10 | |
| 11 | - if ( ! empty( $_GET['id'] ) ) { |
|
| 11 | + if ( ! empty( $_GET['id'] ) ) { |
|
| 12 | 12 | |
| 13 | 13 | wpinv_recurring_subscription_details(); |
| 14 | 14 | |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | |
| 17 | - } |
|
| 18 | - ?> |
|
| 17 | + } |
|
| 18 | + ?> |
|
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | |
| 21 | 21 | <h1> |
| 22 | 22 | <?php _e( 'Subscriptions', 'invoicing' ); ?> |
| 23 | 23 | </h1> |
| 24 | 24 | <?php |
| 25 | - $subscribers_table = new WPInv_Subscription_Reports_Table(); |
|
| 26 | - $subscribers_table->prepare_items(); |
|
| 27 | - ?> |
|
| 25 | + $subscribers_table = new WPInv_Subscription_Reports_Table(); |
|
| 26 | + $subscribers_table->prepare_items(); |
|
| 27 | + ?> |
|
| 28 | 28 | |
| 29 | 29 | <form id="subscribers-filter" method="get"> |
| 30 | 30 | |
@@ -47,24 +47,24 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | function wpinv_recurring_subscription_details() { |
| 49 | 49 | |
| 50 | - $render = true; |
|
| 50 | + $render = true; |
|
| 51 | 51 | |
| 52 | - if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
| 53 | - die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
| 54 | - } |
|
| 52 | + if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
| 53 | + die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 56 | + if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 57 | 57 | die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $sub_id = (int) $_GET['id']; |
|
| 61 | - $sub = new WPInv_Subscription( $sub_id ); |
|
| 60 | + $sub_id = (int) $_GET['id']; |
|
| 61 | + $sub = new WPInv_Subscription( $sub_id ); |
|
| 62 | 62 | |
| 63 | - if ( empty( $sub ) ) { |
|
| 64 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 65 | - } |
|
| 63 | + if ( empty( $sub ) ) { |
|
| 64 | + die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - ?> |
|
| 67 | + ?> |
|
| 68 | 68 | <div class="wrap"> |
| 69 | 69 | <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
| 70 | 70 | |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | </td> |
| 89 | 89 | <td> |
| 90 | 90 | <?php |
| 91 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
| 92 | - $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 93 | - $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
| 94 | - printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
| 95 | - ?> |
|
| 91 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
| 92 | + $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 93 | + $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
| 94 | + printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
| 95 | + ?> |
|
| 96 | 96 | </td> |
| 97 | 97 | </tr> |
| 98 | 98 | <tr> |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | ?> |
| 136 | 136 | <a href="<?php echo esc_url( add_query_arg( array( |
| 137 | - 'post' => $sub->product_id, |
|
| 138 | - 'action' => 'edit' |
|
| 139 | - ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
| 137 | + 'post' => $sub->product_id, |
|
| 138 | + 'action' => 'edit' |
|
| 139 | + ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
| 140 | 140 | </td> |
| 141 | 141 | </tr> |
| 142 | 142 | <tr> |
@@ -299,56 +299,56 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function wpinv_recurring_process_subscription_update() { |
| 301 | 301 | |
| 302 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 303 | - return; |
|
| 304 | - } |
|
| 302 | + if( empty( $_POST['sub_id'] ) ) { |
|
| 303 | + return; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
| 307 | - return; |
|
| 308 | - } |
|
| 306 | + if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 311 | - return; |
|
| 312 | - } |
|
| 310 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 315 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 316 | - } |
|
| 314 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 315 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
| 319 | - $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
| 320 | - $product_id = absint( $_POST['product_id'] ); |
|
| 321 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 322 | - $subscription->update( array( |
|
| 323 | - 'status' => sanitize_text_field( $_POST['status'] ), |
|
| 324 | - 'profile_id' => $profile_id, |
|
| 325 | - 'product_id' => $product_id, |
|
| 326 | - 'transaction_id' => $transaction_id, |
|
| 327 | - ) ); |
|
| 318 | + $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
| 319 | + $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
| 320 | + $product_id = absint( $_POST['product_id'] ); |
|
| 321 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 322 | + $subscription->update( array( |
|
| 323 | + 'status' => sanitize_text_field( $_POST['status'] ), |
|
| 324 | + 'profile_id' => $profile_id, |
|
| 325 | + 'product_id' => $product_id, |
|
| 326 | + 'transaction_id' => $transaction_id, |
|
| 327 | + ) ); |
|
| 328 | 328 | |
| 329 | - $status = sanitize_text_field( $_POST['status'] ); |
|
| 329 | + $status = sanitize_text_field( $_POST['status'] ); |
|
| 330 | 330 | |
| 331 | - switch( $status ) { |
|
| 331 | + switch( $status ) { |
|
| 332 | 332 | |
| 333 | - case 'cancelled' : |
|
| 333 | + case 'cancelled' : |
|
| 334 | 334 | |
| 335 | - $subscription->cancel(); |
|
| 336 | - break; |
|
| 335 | + $subscription->cancel(); |
|
| 336 | + break; |
|
| 337 | 337 | |
| 338 | - case 'expired' : |
|
| 338 | + case 'expired' : |
|
| 339 | 339 | |
| 340 | - $subscription->expire(); |
|
| 341 | - break; |
|
| 340 | + $subscription->expire(); |
|
| 341 | + break; |
|
| 342 | 342 | |
| 343 | - case 'completed' : |
|
| 343 | + case 'completed' : |
|
| 344 | 344 | |
| 345 | - $subscription->complete(); |
|
| 346 | - break; |
|
| 345 | + $subscription->complete(); |
|
| 346 | + break; |
|
| 347 | 347 | |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
| 351 | - exit; |
|
| 350 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
| 351 | + exit; |
|
| 352 | 352 | |
| 353 | 353 | } |
| 354 | 354 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 ); |
@@ -362,30 +362,30 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | function wpinv_recurring_process_subscription_deletion() { |
| 364 | 364 | |
| 365 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 366 | - return; |
|
| 367 | - } |
|
| 365 | + if( empty( $_POST['sub_id'] ) ) { |
|
| 366 | + return; |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 370 | - return; |
|
| 371 | - } |
|
| 369 | + if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 370 | + return; |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 374 | - return; |
|
| 375 | - } |
|
| 373 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 378 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 379 | - } |
|
| 377 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 378 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 381 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 382 | 382 | |
| 383 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 383 | + delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 384 | 384 | |
| 385 | - $subscription->delete(); |
|
| 385 | + $subscription->delete(); |
|
| 386 | 386 | |
| 387 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 388 | - exit; |
|
| 387 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 388 | + exit; |
|
| 389 | 389 | |
| 390 | 390 | } |
| 391 | 391 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | function wpinv_subscriptions_page() { |
| 10 | 10 | |
| 11 | - if ( ! empty( $_GET['id'] ) ) { |
|
| 11 | + if (!empty($_GET['id'])) { |
|
| 12 | 12 | |
| 13 | 13 | wpinv_recurring_subscription_details(); |
| 14 | 14 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | |
| 21 | 21 | <h1> |
| 22 | - <?php _e( 'Subscriptions', 'invoicing' ); ?> |
|
| 22 | + <?php _e('Subscriptions', 'invoicing'); ?> |
|
| 23 | 23 | </h1> |
| 24 | 24 | <?php |
| 25 | 25 | $subscribers_table = new WPInv_Subscription_Reports_Table(); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | <input type="hidden" name="post_type" value="download" /> |
| 32 | 32 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 33 | 33 | <?php $subscribers_table->views(); ?> |
| 34 | - <?php $subscribers_table->search_box( __( 'Search', 'wpinvoicing' ), 'subscriptions' ); ?> |
|
| 34 | + <?php $subscribers_table->search_box(__('Search', 'wpinvoicing'), 'subscriptions'); ?> |
|
| 35 | 35 | <?php $subscribers_table->display(); ?> |
| 36 | 36 | |
| 37 | 37 | </form> |
@@ -49,34 +49,34 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $render = true; |
| 51 | 51 | |
| 52 | - if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
| 53 | - die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
| 52 | + if (!current_user_can('manage_invoicing')) { |
|
| 53 | + die(__('You are not permitted to view this data.', 'invoicing')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 57 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 56 | + if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { |
|
| 57 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $sub_id = (int) $_GET['id']; |
|
| 61 | - $sub = new WPInv_Subscription( $sub_id ); |
|
| 60 | + $sub_id = (int)$_GET['id']; |
|
| 61 | + $sub = new WPInv_Subscription($sub_id); |
|
| 62 | 62 | |
| 63 | - if ( empty( $sub ) ) { |
|
| 64 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 63 | + if (empty($sub)) { |
|
| 64 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | ?> |
| 68 | 68 | <div class="wrap"> |
| 69 | - <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
| 69 | + <h2><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
| 70 | 70 | |
| 71 | - <?php if ( $sub ) : ?> |
|
| 71 | + <?php if ($sub) : ?> |
|
| 72 | 72 | |
| 73 | 73 | <div id="wpinv-item-card-wrapper"> |
| 74 | 74 | |
| 75 | - <?php do_action( 'wpinv_subscription_card_top', $sub ); ?> |
|
| 75 | + <?php do_action('wpinv_subscription_card_top', $sub); ?> |
|
| 76 | 76 | |
| 77 | 77 | <div class="info-wrapper item-section"> |
| 78 | 78 | |
| 79 | - <form id="edit-item-info" method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $sub->id ); ?>"> |
|
| 79 | + <form id="edit-item-info" method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . $sub->id); ?>"> |
|
| 80 | 80 | |
| 81 | 81 | <div class="item-info"> |
| 82 | 82 | |
@@ -84,124 +84,124 @@ discard block |
||
| 84 | 84 | <tbody> |
| 85 | 85 | <tr> |
| 86 | 86 | <td class="row-title"> |
| 87 | - <label for="tablecell"><?php _e( 'Billing Cycle:', 'invoicing' ); ?></label> |
|
| 87 | + <label for="tablecell"><?php _e('Billing Cycle:', 'invoicing'); ?></label> |
|
| 88 | 88 | </td> |
| 89 | 89 | <td> |
| 90 | 90 | <?php |
| 91 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
| 92 | - $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 93 | - $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
| 94 | - printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
| 91 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($sub->period, $sub->frequency); |
|
| 92 | + $billing = wpinv_price(wpinv_format_amount($sub->recurring_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)) . ' / ' . $frequency; |
|
| 93 | + $initial = wpinv_price(wpinv_format_amount($sub->initial_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)); |
|
| 94 | + printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); |
|
| 95 | 95 | ?> |
| 96 | 96 | </td> |
| 97 | 97 | </tr> |
| 98 | 98 | <tr> |
| 99 | 99 | <td class="row-title"> |
| 100 | - <label for="tablecell"><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
|
| 100 | + <label for="tablecell"><?php _e('Times Billed:', 'invoicing'); ?></label> |
|
| 101 | 101 | </td> |
| 102 | - <td><?php echo $sub->get_times_billed() . ' / ' . ( ( $sub->bill_times == 0 ) ? 'Until Cancelled' : $sub->bill_times ); ?></td> |
|
| 102 | + <td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? 'Until Cancelled' : $sub->bill_times); ?></td> |
|
| 103 | 103 | </tr> |
| 104 | 104 | <tr> |
| 105 | 105 | <td class="row-title"> |
| 106 | - <label for="tablecell"><?php _e( 'Customer:', 'invoicing' ); ?></label> |
|
| 106 | + <label for="tablecell"><?php _e('Customer:', 'invoicing'); ?></label> |
|
| 107 | 107 | </td> |
| 108 | 108 | <td> |
| 109 | - <?php $subscriber = get_userdata( $sub->customer_id ); ?> |
|
| 110 | - <a href="<?php echo esc_url( get_edit_user_link( $sub->customer_id ) ); ?>" target="_blank"><?php echo ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
| 109 | + <?php $subscriber = get_userdata($sub->customer_id); ?> |
|
| 110 | + <a href="<?php echo esc_url(get_edit_user_link($sub->customer_id)); ?>" target="_blank"><?php echo !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
| 111 | 111 | </td> |
| 112 | 112 | </tr> |
| 113 | 113 | <tr> |
| 114 | 114 | <td class="row-title"> |
| 115 | - <label for="tablecell"><?php _e( 'Initial Invoice:', 'invoicing' ); ?></label> |
|
| 115 | + <label for="tablecell"><?php _e('Initial Invoice:', 'invoicing'); ?></label> |
|
| 116 | 116 | </td> |
| 117 | 117 | <td> |
| 118 | - <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $sub->parent_payment_id ) ); ?>"><?php echo wpinv_get_invoice_number( $sub->parent_payment_id ); ?></a> <?php echo wp_sprintf( __( '( ID: %s )', 'invoicing' ), '<a title="' . esc_attr( __( 'View invoice details', 'invoicing' ) ) . '" href="' . get_edit_post_link( $sub->parent_payment_id ) . '" target="_blank">' . $sub->parent_payment_id . '</a>' ); ?></td> |
|
| 118 | + <a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($sub->parent_payment_id)); ?>"><?php echo wpinv_get_invoice_number($sub->parent_payment_id); ?></a> <?php echo wp_sprintf(__('( ID: %s )', 'invoicing'), '<a title="' . esc_attr(__('View invoice details', 'invoicing')) . '" href="' . get_edit_post_link($sub->parent_payment_id) . '" target="_blank">' . $sub->parent_payment_id . '</a>'); ?></td> |
|
| 119 | 119 | </tr> |
| 120 | 120 | <tr> |
| 121 | 121 | <td class="row-title"> |
| 122 | - <label for="tablecell"><?php _e( 'Item:', 'invoicing' ); ?></label> |
|
| 122 | + <label for="tablecell"><?php _e('Item:', 'invoicing'); ?></label> |
|
| 123 | 123 | </td> |
| 124 | 124 | <td> |
| 125 | 125 | <?php |
| 126 | - echo wpinv_item_dropdown( array( |
|
| 126 | + echo wpinv_item_dropdown(array( |
|
| 127 | 127 | 'name' => 'product_id', |
| 128 | 128 | 'id' => 'wpinv_invoice_item', |
| 129 | 129 | 'with_packages' => false, |
| 130 | 130 | 'show_recurring' => true, |
| 131 | 131 | 'selected' => $sub->product_id, |
| 132 | 132 | 'class' => 'wpinv-sub-product-id', |
| 133 | - ) ); |
|
| 133 | + )); |
|
| 134 | 134 | |
| 135 | 135 | ?> |
| 136 | - <a href="<?php echo esc_url( add_query_arg( array( |
|
| 136 | + <a href="<?php echo esc_url(add_query_arg(array( |
|
| 137 | 137 | 'post' => $sub->product_id, |
| 138 | 138 | 'action' => 'edit' |
| 139 | - ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
| 139 | + ), admin_url('post.php'))); ?>" target="_blank"><?php _e('View Item', 'invoicing'); ?></a> |
|
| 140 | 140 | </td> |
| 141 | 141 | </tr> |
| 142 | 142 | <tr> |
| 143 | 143 | <td class="row-title"> |
| 144 | - <label for="tablecell"><?php _e( 'Payment Method:', 'invoicing' ); ?></label> |
|
| 144 | + <label for="tablecell"><?php _e('Payment Method:', 'invoicing'); ?></label> |
|
| 145 | 145 | </td> |
| 146 | - <td><?php echo wpinv_get_gateway_admin_label( wpinv_get_payment_gateway( $sub->parent_payment_id ) ); ?></td> |
|
| 146 | + <td><?php echo wpinv_get_gateway_admin_label(wpinv_get_payment_gateway($sub->parent_payment_id)); ?></td> |
|
| 147 | 147 | </tr> |
| 148 | 148 | <tr> |
| 149 | 149 | <td class="row-title"> |
| 150 | - <label for="tablecell"><?php _e( 'Profile ID:', 'invoicing' ); ?></label> |
|
| 150 | + <label for="tablecell"><?php _e('Profile ID:', 'invoicing'); ?></label> |
|
| 151 | 151 | </td> |
| 152 | 152 | <td> |
| 153 | 153 | <span class="wpinv-sub-profile-id"> |
| 154 | - <?php echo apply_filters( 'wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub ); ?> |
|
| 154 | + <?php echo apply_filters('wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub); ?> |
|
| 155 | 155 | </span> |
| 156 | - <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr( $sub->profile_id ); ?>" /> |
|
| 156 | + <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr($sub->profile_id); ?>" /> |
|
| 157 | 157 | <span> – </span> |
| 158 | - <a href="#" class="wpinv-edit-sub-profile-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
| 158 | + <a href="#" class="wpinv-edit-sub-profile-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
| 159 | 159 | </td> |
| 160 | 160 | </tr> |
| 161 | 161 | <tr> |
| 162 | 162 | <td class="row-title"> |
| 163 | - <label for="tablecell"><?php _e( 'Transaction ID:', 'invoicing' ); ?></label> |
|
| 163 | + <label for="tablecell"><?php _e('Transaction ID:', 'invoicing'); ?></label> |
|
| 164 | 164 | </td> |
| 165 | 165 | <td> |
| 166 | - <span class="wpinv-sub-transaction-id"><?php echo apply_filters( 'wpinv_subscription_transaction_link_' . $sub->gateway, $sub->get_transaction_id(), $sub ); ?></span> |
|
| 167 | - <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr( $sub->get_transaction_id() ); ?>" /> |
|
| 166 | + <span class="wpinv-sub-transaction-id"><?php echo apply_filters('wpinv_subscription_transaction_link_' . $sub->gateway, $sub->get_transaction_id(), $sub); ?></span> |
|
| 167 | + <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr($sub->get_transaction_id()); ?>" /> |
|
| 168 | 168 | <span> – </span> |
| 169 | - <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
| 169 | + <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
| 170 | 170 | </td> |
| 171 | 171 | </tr> |
| 172 | 172 | <tr> |
| 173 | 173 | <td class="row-title"> |
| 174 | - <label for="tablecell"><?php _e( 'Date Created:', 'invoicing' ); ?></label> |
|
| 174 | + <label for="tablecell"><?php _e('Date Created:', 'invoicing'); ?></label> |
|
| 175 | 175 | </td> |
| 176 | - <td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->created, current_time( 'timestamp' ) ) ); ?></td> |
|
| 176 | + <td><?php echo date_i18n(get_option('date_format'), strtotime($sub->created, current_time('timestamp'))); ?></td> |
|
| 177 | 177 | </tr> |
| 178 | 178 | <tr> |
| 179 | 179 | <td class="row-title"> |
| 180 | 180 | <label for="tablecell"> |
| 181 | - <?php if( 'trialling' == $sub->status ) : ?> |
|
| 182 | - <?php _e( 'Trialling Until:', 'invoicing' ); ?> |
|
| 181 | + <?php if ('trialling' == $sub->status) : ?> |
|
| 182 | + <?php _e('Trialling Until:', 'invoicing'); ?> |
|
| 183 | 183 | <?php else: ?> |
| 184 | - <?php _e( 'Expiration Date:', 'invoicing' ); ?> |
|
| 184 | + <?php _e('Expiration Date:', 'invoicing'); ?> |
|
| 185 | 185 | <?php endif; ?> |
| 186 | 186 | </label> |
| 187 | 187 | </td> |
| 188 | 188 | <td> |
| 189 | - <span class="wpinv-sub-expiration"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->expiration, current_time( 'timestamp' ) ) ); ?></span> |
|
| 189 | + <span class="wpinv-sub-expiration"><?php echo date_i18n(get_option('date_format'), strtotime($sub->expiration, current_time('timestamp'))); ?></span> |
|
| 190 | 190 | </td> |
| 191 | 191 | </tr> |
| 192 | 192 | <tr> |
| 193 | 193 | <td class="row-title"> |
| 194 | - <label for="tablecell"><?php _e( 'Subscription Status:', 'invoicing' ); ?></label> |
|
| 194 | + <label for="tablecell"><?php _e('Subscription Status:', 'invoicing'); ?></label> |
|
| 195 | 195 | </td> |
| 196 | 196 | <td> |
| 197 | 197 | <select name="status"> |
| 198 | - <option value="pending"<?php selected( 'pending', $sub->status ); ?>><?php _e( 'Pending', 'invoicing' ); ?></option> |
|
| 199 | - <option value="active"<?php selected( 'active', $sub->status ); ?>><?php _e( 'Active', 'invoicing' ); ?></option> |
|
| 200 | - <option value="cancelled"<?php selected( 'cancelled', $sub->status ); ?>><?php _e( 'Cancelled', 'invoicing' ); ?></option> |
|
| 201 | - <option value="expired"<?php selected( 'expired', $sub->status ); ?>><?php _e( 'Expired', 'invoicing' ); ?></option> |
|
| 202 | - <option value="trialling"<?php selected( 'trialling', $sub->status ); ?>><?php _e( 'Trialling', 'invoicing' ); ?></option> |
|
| 203 | - <option value="failing"<?php selected( 'failing', $sub->status ); ?>><?php _e( 'Failing', 'invoicing' ); ?></option> |
|
| 204 | - <option value="completed"<?php selected( 'completed', $sub->status ); ?>><?php _e( 'Completed', 'invoicing' ); ?></option> |
|
| 198 | + <option value="pending"<?php selected('pending', $sub->status); ?>><?php _e('Pending', 'invoicing'); ?></option> |
|
| 199 | + <option value="active"<?php selected('active', $sub->status); ?>><?php _e('Active', 'invoicing'); ?></option> |
|
| 200 | + <option value="cancelled"<?php selected('cancelled', $sub->status); ?>><?php _e('Cancelled', 'invoicing'); ?></option> |
|
| 201 | + <option value="expired"<?php selected('expired', $sub->status); ?>><?php _e('Expired', 'invoicing'); ?></option> |
|
| 202 | + <option value="trialling"<?php selected('trialling', $sub->status); ?>><?php _e('Trialling', 'invoicing'); ?></option> |
|
| 203 | + <option value="failing"<?php selected('failing', $sub->status); ?>><?php _e('Failing', 'invoicing'); ?></option> |
|
| 204 | + <option value="completed"<?php selected('completed', $sub->status); ?>><?php _e('Completed', 'invoicing'); ?></option> |
|
| 205 | 205 | </select> |
| 206 | 206 | </td> |
| 207 | 207 | </tr> |
@@ -209,79 +209,79 @@ discard block |
||
| 209 | 209 | </table> |
| 210 | 210 | </div> |
| 211 | 211 | <div id="wpinv-sub-notices"> |
| 212 | - <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e( 'Changing the product assigned will not automatically adjust any pricing.', 'invoicing' ); ?></p></div> |
|
| 213 | - <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e( 'Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing' ); ?></p></div> |
|
| 212 | + <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e('Changing the product assigned will not automatically adjust any pricing.', 'invoicing'); ?></p></div> |
|
| 213 | + <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e('Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing'); ?></p></div> |
|
| 214 | 214 | </div> |
| 215 | 215 | <div id="item-edit-actions" class="edit-item" style="float:right; margin: 10px 0 0; display: block;"> |
| 216 | - <?php wp_nonce_field( 'wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true ); ?> |
|
| 217 | - <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e( 'Update Subscription', 'invoicing' ); ?>"/> |
|
| 218 | - <input type="hidden" name="sub_id" value="<?php echo absint( $sub->id ); ?>" /> |
|
| 219 | - <?php if( $sub->can_cancel() ) : ?> |
|
| 220 | - <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e( 'Cancel Subscription', 'invoicing' ); ?></a> |
|
| 216 | + <?php wp_nonce_field('wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true); ?> |
|
| 217 | + <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e('Update Subscription', 'invoicing'); ?>"/> |
|
| 218 | + <input type="hidden" name="sub_id" value="<?php echo absint($sub->id); ?>" /> |
|
| 219 | + <?php if ($sub->can_cancel()) : ?> |
|
| 220 | + <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e('Cancel Subscription', 'invoicing'); ?></a> |
|
| 221 | 221 | <?php endif; ?> |
| 222 | - <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e( 'Delete Subscription', 'invoicing' ); ?>"/> |
|
| 222 | + <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e('Delete Subscription', 'invoicing'); ?>"/> |
|
| 223 | 223 | </div> |
| 224 | 224 | |
| 225 | 225 | </form> |
| 226 | 226 | </div> |
| 227 | 227 | |
| 228 | - <?php do_action( 'wpinv_subscription_before_stats', $sub ); ?> |
|
| 228 | + <?php do_action('wpinv_subscription_before_stats', $sub); ?> |
|
| 229 | 229 | |
| 230 | - <?php do_action( 'wpinv_subscription_before_tables_wrapper', $sub ); ?> |
|
| 230 | + <?php do_action('wpinv_subscription_before_tables_wrapper', $sub); ?> |
|
| 231 | 231 | |
| 232 | 232 | <div id="item-tables-wrapper" class="item-section"> |
| 233 | 233 | |
| 234 | - <?php do_action( 'wpinv_subscription_before_tables', $sub ); ?> |
|
| 234 | + <?php do_action('wpinv_subscription_before_tables', $sub); ?> |
|
| 235 | 235 | |
| 236 | - <h3><?php _e( 'Renewal Payments:', 'invoicing' ); ?></h3> |
|
| 236 | + <h3><?php _e('Renewal Payments:', 'invoicing'); ?></h3> |
|
| 237 | 237 | <?php $payments = $sub->get_child_payments(); ?> |
| 238 | - <?php if ( 'manual' == $sub->gateway ) : ?> |
|
| 239 | - <p><strong><?php _e( 'Note:', 'invoicing' ); ?></strong> <?php _e( 'Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing' ); ?></p> |
|
| 238 | + <?php if ('manual' == $sub->gateway) : ?> |
|
| 239 | + <p><strong><?php _e('Note:', 'invoicing'); ?></strong> <?php _e('Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing'); ?></p> |
|
| 240 | 240 | <?php endif; ?> |
| 241 | 241 | <table class="wp-list-table widefat striped payments"> |
| 242 | 242 | <thead> |
| 243 | 243 | <tr> |
| 244 | - <th><?php _e( 'ID', 'invoicing' ); ?></th> |
|
| 245 | - <th><?php _e( 'Amount', 'invoicing' ); ?></th> |
|
| 246 | - <th><?php _e( 'Date', 'invoicing' ); ?></th> |
|
| 247 | - <th><?php _e( 'Status', 'invoicing' ); ?></th> |
|
| 248 | - <th><?php _e( 'Invoice', 'invoicing' ); ?></th> |
|
| 249 | - <th class="column-wpi_actions"><?php _e( 'Actions', 'invoicing' ); ?></th> |
|
| 244 | + <th><?php _e('ID', 'invoicing'); ?></th> |
|
| 245 | + <th><?php _e('Amount', 'invoicing'); ?></th> |
|
| 246 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 247 | + <th><?php _e('Status', 'invoicing'); ?></th> |
|
| 248 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
| 249 | + <th class="column-wpi_actions"><?php _e('Actions', 'invoicing'); ?></th> |
|
| 250 | 250 | </tr> |
| 251 | 251 | </thead> |
| 252 | 252 | <tbody> |
| 253 | - <?php if ( ! empty( $payments ) ) : ?> |
|
| 254 | - <?php foreach ( $payments as $payment ) : $invoice = wpinv_get_invoice( $payment->ID ); if ( empty( $invoice->ID ) ) continue; ?> |
|
| 253 | + <?php if (!empty($payments)) : ?> |
|
| 254 | + <?php foreach ($payments as $payment) : $invoice = wpinv_get_invoice($payment->ID); if (empty($invoice->ID)) continue; ?> |
|
| 255 | 255 | <tr> |
| 256 | 256 | <td><?php echo $payment->ID; ?></td> |
| 257 | - <td><?php echo $invoice->get_total( true ); ?></td> |
|
| 257 | + <td><?php echo $invoice->get_total(true); ?></td> |
|
| 258 | 258 | <td><?php echo $invoice->get_invoice_date(); ?></td> |
| 259 | - <td><?php echo $invoice->get_status( true ); ?></td> |
|
| 259 | + <td><?php echo $invoice->get_status(true); ?></td> |
|
| 260 | 260 | <td> |
| 261 | - <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $payment->ID ) ); ?>"><?php echo $invoice->get_number(); ?></a> |
|
| 262 | - <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
|
| 261 | + <a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($payment->ID)); ?>"><?php echo $invoice->get_number(); ?></a> |
|
| 262 | + <?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?> |
|
| 263 | 263 | </td> |
| 264 | 264 | <td class="column-wpi_actions"> |
| 265 | - <a title="<?php echo esc_attr( wp_sprintf( __( 'View details for invoice: %s', 'invoicing' ), $invoice->get_number() ) ); ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"><?php _e( 'View Details', 'invoicing' ); ?> |
|
| 265 | + <a title="<?php echo esc_attr(wp_sprintf(__('View details for invoice: %s', 'invoicing'), $invoice->get_number())); ?>" href="<?php echo get_edit_post_link($payment->ID); ?>"><?php _e('View Details', 'invoicing'); ?> |
|
| 266 | 266 | </a> |
| 267 | - <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
|
| 267 | + <?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?> |
|
| 268 | 268 | </td> |
| 269 | 269 | </tr> |
| 270 | 270 | <?php endforeach; ?> |
| 271 | 271 | <?php else: ?> |
| 272 | 272 | <tr> |
| 273 | - <td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); ?></td> |
|
| 273 | + <td colspan="5"><?php _e('No Invoices Found.', 'invoicing'); ?></td> |
|
| 274 | 274 | </tr> |
| 275 | 275 | <?php endif; ?> |
| 276 | 276 | </tbody> |
| 277 | 277 | <tfoot></tfoot> |
| 278 | 278 | </table> |
| 279 | 279 | |
| 280 | - <?php do_action( 'wpinv_subscription_after_tables', $sub ); ?> |
|
| 280 | + <?php do_action('wpinv_subscription_after_tables', $sub); ?> |
|
| 281 | 281 | |
| 282 | 282 | </div> |
| 283 | 283 | |
| 284 | - <?php do_action( 'wpinv_subscription_card_bottom', $sub ); ?> |
|
| 284 | + <?php do_action('wpinv_subscription_card_bottom', $sub); ?> |
|
| 285 | 285 | </div> |
| 286 | 286 | |
| 287 | 287 | <?php endif; ?> |
@@ -299,36 +299,36 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function wpinv_recurring_process_subscription_update() { |
| 301 | 301 | |
| 302 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 302 | + if (empty($_POST['sub_id'])) { |
|
| 303 | 303 | return; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
| 306 | + if (empty($_POST['wpinv_update_subscription'])) { |
|
| 307 | 307 | return; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 310 | + if (!current_user_can('manage_invoicing')) { |
|
| 311 | 311 | return; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 315 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 314 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
| 315 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
| 319 | - $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
| 320 | - $product_id = absint( $_POST['product_id'] ); |
|
| 321 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 322 | - $subscription->update( array( |
|
| 323 | - 'status' => sanitize_text_field( $_POST['status'] ), |
|
| 318 | + $profile_id = sanitize_text_field($_POST['profile_id']); |
|
| 319 | + $transaction_id = sanitize_text_field($_POST['transaction_id']); |
|
| 320 | + $product_id = absint($_POST['product_id']); |
|
| 321 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
| 322 | + $subscription->update(array( |
|
| 323 | + 'status' => sanitize_text_field($_POST['status']), |
|
| 324 | 324 | 'profile_id' => $profile_id, |
| 325 | 325 | 'product_id' => $product_id, |
| 326 | 326 | 'transaction_id' => $transaction_id, |
| 327 | - ) ); |
|
| 327 | + )); |
|
| 328 | 328 | |
| 329 | - $status = sanitize_text_field( $_POST['status'] ); |
|
| 329 | + $status = sanitize_text_field($_POST['status']); |
|
| 330 | 330 | |
| 331 | - switch( $status ) { |
|
| 331 | + switch ($status) { |
|
| 332 | 332 | |
| 333 | 333 | case 'cancelled' : |
| 334 | 334 | |
@@ -347,11 +347,11 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
| 350 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id)); |
|
| 351 | 351 | exit; |
| 352 | 352 | |
| 353 | 353 | } |
| 354 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 ); |
|
| 354 | +add_action('admin_init', 'wpinv_recurring_process_subscription_update', 1); |
|
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Handles subscription deletion |
@@ -362,30 +362,30 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | function wpinv_recurring_process_subscription_deletion() { |
| 364 | 364 | |
| 365 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 365 | + if (empty($_POST['sub_id'])) { |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 369 | + if (empty($_POST['wpinv_delete_subscription'])) { |
|
| 370 | 370 | return; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 373 | + if (!current_user_can('manage_invoicing')) { |
|
| 374 | 374 | return; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 378 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 377 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
| 378 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 381 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
| 382 | 382 | |
| 383 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 383 | + delete_post_meta($subscription->parent_payment_id, '_wpinv_subscription_payment'); |
|
| 384 | 384 | |
| 385 | 385 | $subscription->delete(); |
| 386 | 386 | |
| 387 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 387 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=deleted')); |
|
| 388 | 388 | exit; |
| 389 | 389 | |
| 390 | 390 | } |
| 391 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
|
| 391 | +add_action('admin_init', 'wpinv_recurring_process_subscription_deletion', 2); |
|
@@ -1,83 +1,83 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | -if ( !( $user_id = get_current_user_id() ) ) { |
|
| 6 | +if (!($user_id = get_current_user_id())) { |
|
| 7 | 7 | ?> |
| 8 | - <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div> |
|
| 8 | + <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div> |
|
| 9 | 9 | <?php |
| 10 | 10 | return; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | global $current_page; |
| 14 | -$current_page = empty( $current_page ) ? 1 : absint( $current_page ); |
|
| 15 | -$query = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true, 'orderby' => 'invoice_date' ) ); |
|
| 16 | -$user_invoices = wpinv_get_invoices( $query ); |
|
| 14 | +$current_page = empty($current_page) ? 1 : absint($current_page); |
|
| 15 | +$query = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true, 'orderby' => 'invoice_date')); |
|
| 16 | +$user_invoices = wpinv_get_invoices($query); |
|
| 17 | 17 | $has_invoices = 0 < $user_invoices->total; |
| 18 | 18 | |
| 19 | -do_action( 'wpinv_before_user_invoices', $has_invoices ); ?> |
|
| 19 | +do_action('wpinv_before_user_invoices', $has_invoices); ?> |
|
| 20 | 20 | |
| 21 | -<?php if ( $has_invoices ) { ?> |
|
| 21 | +<?php if ($has_invoices) { ?> |
|
| 22 | 22 | <table class="table table-bordered table-hover table-responsive wpi-user-invoices"> |
| 23 | 23 | <thead> |
| 24 | 24 | <tr> |
| 25 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
| 26 | - <th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th> |
|
| 25 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
| 26 | + <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th> |
|
| 27 | 27 | <?php endforeach; ?> |
| 28 | 28 | </tr> |
| 29 | 29 | </thead> |
| 30 | 30 | |
| 31 | 31 | <tbody> |
| 32 | - <?php foreach ( $user_invoices->invoices as $invoice ) { |
|
| 32 | + <?php foreach ($user_invoices->invoices as $invoice) { |
|
| 33 | 33 | ?> |
| 34 | 34 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
| 35 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
| 36 | - <td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>"> |
|
| 37 | - <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?> |
|
| 38 | - <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?> |
|
| 39 | - |
|
| 40 | - <?php elseif ( 'invoice-number' === $column_id ) : ?> |
|
| 41 | - <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>"> |
|
| 42 | - <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?> |
|
| 35 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
| 36 | + <td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>"> |
|
| 37 | + <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?> |
|
| 38 | + <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?> |
|
| 39 | + |
|
| 40 | + <?php elseif ('invoice-number' === $column_id) : ?> |
|
| 41 | + <a href="<?php echo esc_url($invoice->get_view_url()); ?>"> |
|
| 42 | + <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?> |
|
| 43 | 43 | </a> |
| 44 | 44 | |
| 45 | - <?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?> |
|
| 46 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
| 45 | + <?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?> |
|
| 46 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
| 47 | 47 | |
| 48 | - <?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?> |
|
| 49 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
| 48 | + <?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?> |
|
| 49 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
| 50 | 50 | |
| 51 | - <?php elseif ( 'invoice-status' === $column_id ) : ?> |
|
| 52 | - <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?> |
|
| 51 | + <?php elseif ('invoice-status' === $column_id) : ?> |
|
| 52 | + <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?> |
|
| 53 | 53 | |
| 54 | - <?php elseif ( 'invoice-total' === $column_id ) : ?> |
|
| 55 | - <?php echo $invoice->get_total( true ); ?> |
|
| 54 | + <?php elseif ('invoice-total' === $column_id) : ?> |
|
| 55 | + <?php echo $invoice->get_total(true); ?> |
|
| 56 | 56 | |
| 57 | - <?php elseif ( 'invoice-actions' === $column_id ) : ?> |
|
| 57 | + <?php elseif ('invoice-actions' === $column_id) : ?> |
|
| 58 | 58 | <?php |
| 59 | 59 | $actions = array( |
| 60 | 60 | 'pay' => array( |
| 61 | 61 | 'url' => $invoice->get_checkout_payment_url(), |
| 62 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
| 62 | + 'name' => __('Pay Now', 'invoicing'), |
|
| 63 | 63 | 'class' => 'btn-success' |
| 64 | 64 | ), |
| 65 | 65 | 'print' => array( |
| 66 | 66 | 'url' => $invoice->get_view_url(), |
| 67 | - 'name' => __( 'Print', 'invoicing' ), |
|
| 67 | + 'name' => __('Print', 'invoicing'), |
|
| 68 | 68 | 'class' => 'btn-primary', |
| 69 | 69 | 'attrs' => 'target="_blank"' |
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | |
| 73 | - if ( ! $invoice->needs_payment() ) { |
|
| 74 | - unset( $actions['pay'] ); |
|
| 73 | + if (!$invoice->needs_payment()) { |
|
| 74 | + unset($actions['pay']); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) { |
|
| 78 | - foreach ( $actions as $key => $action ) { |
|
| 77 | + if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) { |
|
| 78 | + foreach ($actions as $key => $action) { |
|
| 79 | 79 | $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
| 80 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
| 80 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>'; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | ?> |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | </tbody> |
| 90 | 90 | </table> |
| 91 | 91 | |
| 92 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
| 92 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
| 93 | 93 | |
| 94 | - <?php if ( 1 < $user_invoices->max_num_pages ) : ?> |
|
| 94 | + <?php if (1 < $user_invoices->max_num_pages) : ?> |
|
| 95 | 95 | <div class="invoicing-Pagination"> |
| 96 | 96 | <?php |
| 97 | 97 | $big = 999999; |
@@ -103,20 +103,20 @@ discard block |
||
| 103 | 103 | else |
| 104 | 104 | $current_page = 1; |
| 105 | 105 | |
| 106 | - echo paginate_links( array( |
|
| 107 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 106 | + echo paginate_links(array( |
|
| 107 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 108 | 108 | 'format' => '?paged=%#%', |
| 109 | - 'current' => max( 1, $current_page ), |
|
| 109 | + 'current' => max(1, $current_page), |
|
| 110 | 110 | 'total' => $user_invoices->max_num_pages, |
| 111 | - ) ); |
|
| 111 | + )); |
|
| 112 | 112 | ?> |
| 113 | 113 | </div> |
| 114 | 114 | <?php endif; ?> |
| 115 | 115 | |
| 116 | 116 | <?php } else { ?> |
| 117 | 117 | <div class="wpinv-empty alert-info"> |
| 118 | - <?php _e( 'No invoice has been made yet.', 'invoicing' ); ?> |
|
| 118 | + <?php _e('No invoice has been made yet.', 'invoicing'); ?> |
|
| 119 | 119 | </div> |
| 120 | 120 | <?php } ?> |
| 121 | 121 | |
| 122 | -<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?> |
|
| 122 | +<?php do_action('wpinv_after_user_invoices', $has_invoices); ?> |
|
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -add_action( 'wpinv_paypal_cc_form', '__return_false' ); |
|
| 6 | -add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
|
| 5 | +add_action('wpinv_paypal_cc_form', '__return_false'); |
|
| 6 | +add_filter('wpinv_paypal_support_subscription', '__return_true'); |
|
| 7 | 7 | |
| 8 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
| 9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
| 10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 8 | +function wpinv_process_paypal_payment($purchase_data) { |
|
| 9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
| 10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | // Collect payment data |
@@ -25,30 +25,30 @@ discard block |
||
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | 27 | // Record the pending payment |
| 28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
| 28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
| 29 | 29 | |
| 30 | 30 | // Check payment |
| 31 | - if ( ! $invoice ) { |
|
| 31 | + if (!$invoice) { |
|
| 32 | 32 | // Record the error |
| 33 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
| 33 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
| 34 | 34 | // Problems? send back |
| 35 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 35 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 36 | 36 | } else { |
| 37 | 37 | // Only send to PayPal if the pending payment is created successfully |
| 38 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
| 38 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
| 39 | 39 | |
| 40 | 40 | // Get the success url |
| 41 | - $return_url = add_query_arg( array( |
|
| 41 | + $return_url = add_query_arg(array( |
|
| 42 | 42 | 'payment-confirm' => 'paypal', |
| 43 | 43 | 'invoice-id' => $invoice->ID |
| 44 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
| 44 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
| 45 | 45 | |
| 46 | 46 | // Get the PayPal redirect uri |
| 47 | - $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?'; |
|
| 47 | + $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?'; |
|
| 48 | 48 | |
| 49 | 49 | // Setup PayPal arguments |
| 50 | 50 | $paypal_args = array( |
| 51 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
| 51 | + 'business' => wpinv_get_option('paypal_email', false), |
|
| 52 | 52 | 'email' => $invoice->get_email(), |
| 53 | 53 | 'first_name' => $invoice->get_first_name(), |
| 54 | 54 | 'last_name' => $invoice->get_last_name(), |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | 'shipping' => '0', |
| 58 | 58 | 'no_note' => '1', |
| 59 | 59 | 'currency_code' => wpinv_get_currency(), |
| 60 | - 'charset' => get_bloginfo( 'charset' ), |
|
| 60 | + 'charset' => get_bloginfo('charset'), |
|
| 61 | 61 | 'custom' => $invoice->ID, |
| 62 | 62 | 'rm' => '2', |
| 63 | 63 | 'return' => $return_url, |
| 64 | - 'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ), |
|
| 64 | + 'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID), |
|
| 65 | 65 | 'notify_url' => $listener_url, |
| 66 | - 'cbt' => get_bloginfo( 'name' ), |
|
| 66 | + 'cbt' => get_bloginfo('name'), |
|
| 67 | 67 | 'bn' => 'WPInvoicing_SP', |
| 68 | 68 | 'lc' => 'US', // this will force paypal site to english |
| 69 | - 'landing_page' => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
| 69 | + 'landing_page' => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | $paypal_args['address1'] = $invoice->get_address(); |
@@ -80,57 +80,57 @@ discard block |
||
| 80 | 80 | 'upload' => '1' |
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
| 83 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
| 84 | 84 | |
| 85 | 85 | // Add cart items |
| 86 | 86 | $i = 1; |
| 87 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 88 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 87 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 88 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 89 | 89 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
| 90 | - $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 ); |
|
| 90 | + $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2); |
|
| 91 | 91 | |
| 92 | - if ( $item_amount <= 0 ) { |
|
| 92 | + if ($item_amount <= 0) { |
|
| 93 | 93 | $item_amount = 0; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
| 97 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
| 98 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
| 99 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
| 100 | - $paypal_args['discount_amount_' . $i ] = wpinv_sanitize_amount( $item['discount'], 2 ); |
|
| 96 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
| 97 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
| 98 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
| 99 | + $paypal_args['amount_' . $i] = $item_amount; |
|
| 100 | + $paypal_args['discount_amount_' . $i] = wpinv_sanitize_amount($item['discount'], 2); |
|
| 101 | 101 | |
| 102 | 102 | $i++; |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Add taxes to the cart |
| 107 | - if ( wpinv_use_taxes() ) { |
|
| 108 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 ); |
|
| 107 | + if (wpinv_use_taxes()) { |
|
| 108 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
| 111 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
| 112 | 112 | |
| 113 | 113 | // Build query |
| 114 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
| 114 | + $paypal_redirect .= http_build_query($paypal_args); |
|
| 115 | 115 | |
| 116 | 116 | // Fix for some sites that encode the entities |
| 117 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
| 117 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
| 118 | 118 | |
| 119 | 119 | // Get rid of cart contents |
| 120 | 120 | wpinv_empty_cart(); |
| 121 | 121 | |
| 122 | 122 | // Redirect to PayPal |
| 123 | - wp_redirect( $paypal_redirect ); |
|
| 123 | + wp_redirect($paypal_redirect); |
|
| 124 | 124 | exit; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
| 127 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
| 128 | 128 | |
| 129 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
| 130 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
| 131 | - $item = new WPInv_Item( $item_id ); |
|
| 129 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
| 130 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
| 131 | + $item = new WPInv_Item($item_id); |
|
| 132 | 132 | |
| 133 | - if ( empty( $item ) ) { |
|
| 133 | + if (empty($item)) { |
|
| 134 | 134 | return $paypal_args; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -138,25 +138,25 @@ discard block |
||
| 138 | 138 | $interval = $item->get_recurring_interval(); |
| 139 | 139 | $bill_times = (int)$item->get_recurring_limit(); |
| 140 | 140 | |
| 141 | - $initial_amount = wpinv_sanitize_amount( $invoice->get_total(), 2 ); |
|
| 142 | - $recurring_amount = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 ); |
|
| 141 | + $initial_amount = wpinv_sanitize_amount($invoice->get_total(), 2); |
|
| 142 | + $recurring_amount = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2); |
|
| 143 | 143 | |
| 144 | 144 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 145 | 145 | $paypal_args['sra'] = '1'; |
| 146 | 146 | $paypal_args['src'] = '1'; |
| 147 | 147 | |
| 148 | 148 | // Set item description |
| 149 | - $item_name = sprintf( '[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name( array( 'id' => $item->ID ) ) ); |
|
| 150 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) ); |
|
| 149 | + $item_name = sprintf('[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name(array('id' => $item->ID))); |
|
| 150 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8')); |
|
| 151 | 151 | |
| 152 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
| 152 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
| 153 | 153 | $paypal_args['a1'] = $initial_amount; |
| 154 | 154 | $paypal_args['p1'] = $item->get_trial_interval(); |
| 155 | 155 | $paypal_args['t1'] = $item->get_trial_period(); |
| 156 | 156 | |
| 157 | 157 | // Set the recurring amount |
| 158 | 158 | $paypal_args['a3'] = $recurring_amount; |
| 159 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
| 159 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
| 160 | 160 | $paypal_args['a1'] = $initial_amount; |
| 161 | 161 | $paypal_args['p1'] = $interval; |
| 162 | 162 | $paypal_args['t1'] = $period; |
@@ -164,63 +164,63 @@ discard block |
||
| 164 | 164 | // Set the recurring amount |
| 165 | 165 | $paypal_args['a3'] = $recurring_amount; |
| 166 | 166 | |
| 167 | - if ( $bill_times > 1 ) { |
|
| 167 | + if ($bill_times > 1) { |
|
| 168 | 168 | $bill_times--; |
| 169 | 169 | } |
| 170 | 170 | } else { |
| 171 | - $paypal_args['a3'] = $initial_amount; |
|
| 171 | + $paypal_args['a3'] = $initial_amount; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $paypal_args['p3'] = $interval; |
| 175 | 175 | $paypal_args['t3'] = $period; |
| 176 | 176 | |
| 177 | - if ( $bill_times > 1 ) { |
|
| 177 | + if ($bill_times > 1) { |
|
| 178 | 178 | // Make sure it's not over the max of 52 |
| 179 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 179 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Remove cart items |
| 183 | 183 | $i = 1; |
| 184 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 185 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 186 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
| 187 | - unset( $paypal_args['item_number_' . $i] ); |
|
| 184 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 185 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 186 | + if (isset($paypal_args['item_number_' . $i])) { |
|
| 187 | + unset($paypal_args['item_number_' . $i]); |
|
| 188 | 188 | } |
| 189 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
| 190 | - unset( $paypal_args['item_name_' . $i] ); |
|
| 189 | + if (isset($paypal_args['item_name_' . $i])) { |
|
| 190 | + unset($paypal_args['item_name_' . $i]); |
|
| 191 | 191 | } |
| 192 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
| 193 | - unset( $paypal_args['quantity_' . $i] ); |
|
| 192 | + if (isset($paypal_args['quantity_' . $i])) { |
|
| 193 | + unset($paypal_args['quantity_' . $i]); |
|
| 194 | 194 | } |
| 195 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
| 196 | - unset( $paypal_args['amount_' . $i] ); |
|
| 195 | + if (isset($paypal_args['amount_' . $i])) { |
|
| 196 | + unset($paypal_args['amount_' . $i]); |
|
| 197 | 197 | } |
| 198 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
| 199 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
| 198 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
| 199 | + unset($paypal_args['discount_amount_' . $i]); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $i++; |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
| 207 | - unset( $paypal_args['tax_cart'] ); |
|
| 206 | + if (isset($paypal_args['tax_cart'])) { |
|
| 207 | + unset($paypal_args['tax_cart']); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if ( isset( $paypal_args['upload'] ) ) { |
|
| 211 | - unset( $paypal_args['upload'] ); |
|
| 210 | + if (isset($paypal_args['upload'])) { |
|
| 211 | + unset($paypal_args['upload']); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
| 214 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | return $paypal_args; |
| 218 | 218 | } |
| 219 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
| 219 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
| 220 | 220 | |
| 221 | 221 | function wpinv_process_paypal_ipn() { |
| 222 | 222 | // Check the request method is POST |
| 223 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 223 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | $post_data = ''; |
| 229 | 229 | |
| 230 | 230 | // Fallback just in case post_max_size is lower than needed |
| 231 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 232 | - $post_data = file_get_contents( 'php://input' ); |
|
| 231 | + if (ini_get('allow_url_fopen')) { |
|
| 232 | + $post_data = file_get_contents('php://input'); |
|
| 233 | 233 | } else { |
| 234 | 234 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
| 235 | - ini_set( 'post_max_size', '12M' ); |
|
| 235 | + ini_set('post_max_size', '12M'); |
|
| 236 | 236 | } |
| 237 | 237 | // Start the encoded data collection with notification command |
| 238 | 238 | $encoded_data = 'cmd=_notify-validate'; |
@@ -241,43 +241,43 @@ discard block |
||
| 241 | 241 | $arg_separator = wpinv_get_php_arg_separator_output(); |
| 242 | 242 | |
| 243 | 243 | // Verify there is a post_data |
| 244 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 244 | + if ($post_data || strlen($post_data) > 0) { |
|
| 245 | 245 | // Append the data |
| 246 | - $encoded_data .= $arg_separator.$post_data; |
|
| 246 | + $encoded_data .= $arg_separator . $post_data; |
|
| 247 | 247 | } else { |
| 248 | 248 | // Check if POST is empty |
| 249 | - if ( empty( $_POST ) ) { |
|
| 249 | + if (empty($_POST)) { |
|
| 250 | 250 | // Nothing to do |
| 251 | 251 | return; |
| 252 | 252 | } else { |
| 253 | 253 | // Loop through each POST |
| 254 | - foreach ( $_POST as $key => $value ) { |
|
| 254 | + foreach ($_POST as $key => $value) { |
|
| 255 | 255 | // Encode the value and append the data |
| 256 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 256 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Convert collected post data to an array |
| 262 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 262 | + parse_str($encoded_data, $encoded_data_array); |
|
| 263 | 263 | |
| 264 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 265 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 266 | - $new_key = str_replace( '&', '&', $key ); |
|
| 267 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 264 | + foreach ($encoded_data_array as $key => $value) { |
|
| 265 | + if (false !== strpos($key, 'amp;')) { |
|
| 266 | + $new_key = str_replace('&', '&', $key); |
|
| 267 | + $new_key = str_replace('amp;', '&', $new_key); |
|
| 268 | 268 | |
| 269 | - unset( $encoded_data_array[ $key ] ); |
|
| 270 | - $encoded_data_array[ $new_key ] = $value; |
|
| 269 | + unset($encoded_data_array[$key]); |
|
| 270 | + $encoded_data_array[$new_key] = $value; |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Get the PayPal redirect uri |
| 275 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 275 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
| 276 | 276 | |
| 277 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 277 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
| 278 | 278 | // Validate the IPN |
| 279 | 279 | |
| 280 | - $remote_post_vars = array( |
|
| 280 | + $remote_post_vars = array( |
|
| 281 | 281 | 'method' => 'POST', |
| 282 | 282 | 'timeout' => 45, |
| 283 | 283 | 'redirection' => 5, |
@@ -295,21 +295,21 @@ discard block |
||
| 295 | 295 | ); |
| 296 | 296 | |
| 297 | 297 | // Get response |
| 298 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 298 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
| 299 | 299 | |
| 300 | - if ( is_wp_error( $api_response ) ) { |
|
| 301 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 300 | + if (is_wp_error($api_response)) { |
|
| 301 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 302 | 302 | return; // Something went wrong |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 306 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 305 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
| 306 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 307 | 307 | return; // Response not okay |
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Check if $post_data_array has been populated |
| 312 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 312 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
| 313 | 313 | return; |
| 314 | 314 | |
| 315 | 315 | $defaults = array( |
@@ -317,263 +317,263 @@ discard block |
||
| 317 | 317 | 'payment_status' => '' |
| 318 | 318 | ); |
| 319 | 319 | |
| 320 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 320 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
| 321 | 321 | |
| 322 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 322 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
| 323 | 323 | |
| 324 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 324 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
| 325 | 325 | //wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
| 326 | 326 | |
| 327 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 327 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
| 328 | 328 | // Allow PayPal IPN types to be processed separately |
| 329 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 329 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
| 330 | 330 | } else { |
| 331 | 331 | // Fallback to web accept just in case the txn_type isn't present |
| 332 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 332 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
| 333 | 333 | } |
| 334 | 334 | exit; |
| 335 | 335 | } |
| 336 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
| 336 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
| 337 | 337 | |
| 338 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
| 339 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 338 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
| 339 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if( empty( $invoice_id ) ) { |
|
| 343 | + if (empty($invoice_id)) { |
|
| 344 | 344 | return; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // Collect payment details |
| 348 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 348 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
| 349 | 349 | $paypal_amount = $data['mc_gross']; |
| 350 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 351 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 352 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 353 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 350 | + $payment_status = strtolower($data['payment_status']); |
|
| 351 | + $currency_code = strtolower($data['mc_currency']); |
|
| 352 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
| 353 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
| 354 | 354 | |
| 355 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 355 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
| 356 | 356 | return; // this isn't a PayPal standard IPN |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // Verify payment recipient |
| 360 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 361 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 362 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 363 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
| 360 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
| 361 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 362 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 363 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true); |
|
| 364 | 364 | return; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | // Verify payment currency |
| 368 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 369 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 370 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 371 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 368 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
| 369 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 370 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 371 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true); |
|
| 372 | 372 | return; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 375 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
| 376 | 376 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
| 377 | 377 | // No email associated with purchase, so store from PayPal |
| 378 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 378 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
| 379 | 379 | |
| 380 | 380 | // Setup and store the customer's details |
| 381 | 381 | $user_info = array( |
| 382 | 382 | 'user_id' => '-1', |
| 383 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 384 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 385 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 383 | + 'email' => sanitize_text_field($data['payer_email']), |
|
| 384 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
| 385 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
| 386 | 386 | 'discount' => '', |
| 387 | 387 | ); |
| 388 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 389 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 390 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 391 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 392 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 388 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
| 389 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
| 390 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
| 391 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
| 392 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
| 393 | 393 | |
| 394 | 394 | $payment_meta['user_info'] = $user_info; |
| 395 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 395 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 398 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 399 | 399 | // Process a refund |
| 400 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 400 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
| 401 | 401 | } else { |
| 402 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 402 | + if (get_post_status($invoice_id) == 'publish') { |
|
| 403 | 403 | return; // Only paid payments once |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | // Retrieve the total purchase amount (before PayPal) |
| 407 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 407 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 408 | 408 | |
| 409 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 409 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 410 | 410 | // The prices don't match |
| 411 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 412 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 413 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 411 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 412 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 413 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true); |
|
| 414 | 414 | return; |
| 415 | 415 | } |
| 416 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 416 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
| 417 | 417 | // Purchase keys don't match |
| 418 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 419 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 420 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 418 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 419 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 420 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true); |
|
| 421 | 421 | return; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 425 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
| 426 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 427 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 428 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 424 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
| 425 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
| 426 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
| 427 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
| 428 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
| 429 | 429 | // Look for possible pending reasons, such as an echeck |
| 430 | 430 | $note = ''; |
| 431 | 431 | |
| 432 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
| 432 | + switch (strtolower($data['pending_reason'])) { |
|
| 433 | 433 | case 'echeck' : |
| 434 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 434 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
| 435 | 435 | break; |
| 436 | 436 | |
| 437 | 437 | case 'address' : |
| 438 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 438 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
| 439 | 439 | break; |
| 440 | 440 | |
| 441 | 441 | case 'intl' : |
| 442 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 442 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
| 443 | 443 | break; |
| 444 | 444 | |
| 445 | 445 | case 'multi-currency' : |
| 446 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 446 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
| 447 | 447 | break; |
| 448 | 448 | |
| 449 | 449 | case 'paymentreview' : |
| 450 | 450 | case 'regulatory_review' : |
| 451 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 451 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
| 452 | 452 | break; |
| 453 | 453 | |
| 454 | 454 | case 'unilateral' : |
| 455 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 455 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
| 456 | 456 | break; |
| 457 | 457 | |
| 458 | 458 | case 'upgrade' : |
| 459 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 459 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
| 460 | 460 | break; |
| 461 | 461 | |
| 462 | 462 | case 'verify' : |
| 463 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 463 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
| 464 | 464 | break; |
| 465 | 465 | |
| 466 | 466 | case 'other' : |
| 467 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 467 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
| 468 | 468 | break; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - if ( ! empty( $note ) ) { |
|
| 472 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
| 471 | + if (!empty($note)) { |
|
| 472 | + wpinv_insert_payment_note($invoice_id, $note, '', '', true); |
|
| 473 | 473 | } |
| 474 | 474 | } else { |
| 475 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
| 475 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true); |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
| 479 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
| 480 | 480 | |
| 481 | 481 | // Process PayPal subscription sign ups |
| 482 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
| 482 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
| 483 | 483 | |
| 484 | 484 | // Process PayPal subscription payments |
| 485 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
| 485 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
| 486 | 486 | |
| 487 | 487 | // Process PayPal subscription cancellations |
| 488 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
| 488 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
| 489 | 489 | |
| 490 | 490 | // Process PayPal subscription end of term notices |
| 491 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
| 491 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
| 492 | 492 | |
| 493 | 493 | // Process PayPal payment failed |
| 494 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
| 494 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
| 495 | 495 | |
| 496 | 496 | |
| 497 | 497 | /** |
| 498 | 498 | * Process the subscription started IPN. |
| 499 | 499 | */ |
| 500 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
| 501 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 502 | - if( empty( $parent_invoice_id ) ) { |
|
| 500 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
| 501 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 502 | + if (empty($parent_invoice_id)) { |
|
| 503 | 503 | return; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 507 | - if ( empty( $invoice ) ) { |
|
| 506 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 507 | + if (empty($invoice)) { |
|
| 508 | 508 | return; |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
| 512 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true); |
|
| 513 | - if ( !empty( $ipn_data['txn_id'] ) ) { |
|
| 514 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
| 511 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
| 512 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true); |
|
| 513 | + if (!empty($ipn_data['txn_id'])) { |
|
| 514 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 519 | - if ( false === $subscription ) { |
|
| 518 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 519 | + if (false === $subscription) { |
|
| 520 | 520 | return; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 523 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 524 | 524 | sleep(1); |
| 525 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
| 526 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
| 525 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
| 526 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
| 527 | 527 | |
| 528 | 528 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
| 529 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
| 530 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
| 531 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
| 529 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
| 530 | + $created = date_i18n('Y-m-d H:i:s'); |
|
| 531 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
| 532 | 532 | |
| 533 | 533 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
| 534 | - $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
| 534 | + $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
| 538 | 538 | * Process the subscription payment received IPN. |
| 539 | 539 | */ |
| 540 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
| 541 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 540 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
| 541 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 542 | 542 | |
| 543 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 544 | - if ( empty( $parent_invoice ) ) { |
|
| 543 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 544 | + if (empty($parent_invoice)) { |
|
| 545 | 545 | return; |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 549 | - if ( false === $subscription ) { |
|
| 548 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 549 | + if (false === $subscription) { |
|
| 550 | 550 | return; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
| 553 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
| 554 | 554 | $times_billed = $subscription->get_times_billed(); |
| 555 | 555 | |
| 556 | 556 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
| 557 | - if ( empty( $times_billed ) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
| 558 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 557 | + if (empty($times_billed) && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
| 558 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 559 | 559 | sleep(1); |
| 560 | 560 | |
| 561 | 561 | // This is the very first payment |
| 562 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
| 563 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
| 562 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
| 563 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
| 564 | 564 | return; |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
| 567 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
| 568 | 568 | return; // Payment already recorded |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
| 571 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
| 572 | 572 | |
| 573 | 573 | // verify details |
| 574 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
| 574 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
| 575 | 575 | // the currency code is invalid |
| 576 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
| 576 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
| 577 | 577 | return; |
| 578 | 578 | } |
| 579 | 579 | |
@@ -583,11 +583,11 @@ discard block |
||
| 583 | 583 | 'gateway' => 'paypal' |
| 584 | 584 | ); |
| 585 | 585 | |
| 586 | - $invoice_id = $subscription->add_payment( $args ); |
|
| 586 | + $invoice_id = $subscription->add_payment($args); |
|
| 587 | 587 | |
| 588 | - if ( $invoice_id > 0 ) { |
|
| 589 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
| 590 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
| 588 | + if ($invoice_id > 0) { |
|
| 589 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
| 590 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
| 591 | 591 | |
| 592 | 592 | $subscription->renew(); |
| 593 | 593 | } |
@@ -596,10 +596,10 @@ discard block |
||
| 596 | 596 | /** |
| 597 | 597 | * Process the subscription canceled IPN. |
| 598 | 598 | */ |
| 599 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
| 600 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 599 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
| 600 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 601 | 601 | |
| 602 | - if( false === $subscription ) { |
|
| 602 | + if (false === $subscription) { |
|
| 603 | 603 | return; |
| 604 | 604 | } |
| 605 | 605 | |
@@ -609,10 +609,10 @@ discard block |
||
| 609 | 609 | /** |
| 610 | 610 | * Process the subscription expired IPN. |
| 611 | 611 | */ |
| 612 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
| 613 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 612 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
| 613 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 614 | 614 | |
| 615 | - if( false === $subscription ) { |
|
| 615 | + if (false === $subscription) { |
|
| 616 | 616 | return; |
| 617 | 617 | } |
| 618 | 618 | |
@@ -622,40 +622,40 @@ discard block |
||
| 622 | 622 | /** |
| 623 | 623 | * Process the subscription payment failed IPN. |
| 624 | 624 | */ |
| 625 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
| 626 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 625 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
| 626 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 627 | 627 | |
| 628 | - if( false === $subscription ) { |
|
| 628 | + if (false === $subscription) { |
|
| 629 | 629 | return; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | $subscription->failing(); |
| 633 | 633 | |
| 634 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
| 634 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
| 638 | 638 | * Retrieve the subscription this IPN notice is for. |
| 639 | 639 | */ |
| 640 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
| 641 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 640 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
| 641 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 642 | 642 | |
| 643 | - if( empty( $parent_invoice_id ) ) { |
|
| 643 | + if (empty($parent_invoice_id)) { |
|
| 644 | 644 | return false; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 648 | - if ( empty( $invoice ) ) { |
|
| 647 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 648 | + if (empty($invoice)) { |
|
| 649 | 649 | return false; |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true ); |
|
| 652 | + $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true); |
|
| 653 | 653 | |
| 654 | - if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) { |
|
| 655 | - $subscription = wpinv_get_subscription( $parent_invoice_id ); |
|
| 654 | + if (!(!empty($subscription) && $subscription->id > 0)) { |
|
| 655 | + $subscription = wpinv_get_subscription($parent_invoice_id); |
|
| 656 | 656 | |
| 657 | - if ( ! empty( $subscription ) && $subscription->id > 0 ) { |
|
| 658 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
| 657 | + if (!empty($subscription) && $subscription->id > 0) { |
|
| 658 | + $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
| 659 | 659 | } else { |
| 660 | 660 | return false; |
| 661 | 661 | } |
@@ -665,46 +665,46 @@ discard block |
||
| 665 | 665 | |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
| 668 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
| 669 | 669 | // Collect payment details |
| 670 | 670 | |
| 671 | - if( empty( $invoice_id ) ) { |
|
| 671 | + if (empty($invoice_id)) { |
|
| 672 | 672 | return; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 675 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
| 676 | 676 | return; // Only refund payments once |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 679 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 680 | 680 | $refund_amount = $data['mc_gross'] * -1; |
| 681 | 681 | |
| 682 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
| 682 | + do_action('wpinv_paypal_refund_request', $data, $invoice_id); |
|
| 683 | 683 | |
| 684 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 685 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 684 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 685 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float)$refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
| 686 | 686 | |
| 687 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
| 687 | + do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount); |
|
| 688 | 688 | |
| 689 | 689 | return; // This is a partial refund |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 693 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
| 694 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 692 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
| 693 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
| 694 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
| 695 | 695 | |
| 696 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
| 696 | + do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
| 700 | - if ( is_ssl() || ! $ssl_check ) { |
|
| 699 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
| 700 | + if (is_ssl() || !$ssl_check) { |
|
| 701 | 701 | $protocol = 'https://'; |
| 702 | 702 | } else { |
| 703 | 703 | $protocol = 'http://'; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | // Check the current payment mode |
| 707 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
| 707 | + if (wpinv_is_test_mode('paypal')) { |
|
| 708 | 708 | // Test mode |
| 709 | 709 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
| 710 | 710 | } else { |
@@ -712,120 +712,120 @@ discard block |
||
| 712 | 712 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
| 715 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | -function wpinv_paypal_success_page_content( $content ) { |
|
| 718 | +function wpinv_paypal_success_page_content($content) { |
|
| 719 | 719 | global $wpi_invoice; |
| 720 | 720 | |
| 721 | 721 | $session = wpinv_get_checkout_session(); |
| 722 | 722 | |
| 723 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
| 723 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
| 724 | 724 | return $content; |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
| 727 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
| 728 | 728 | |
| 729 | - if ( empty( $invoice_id ) ) { |
|
| 729 | + if (empty($invoice_id)) { |
|
| 730 | 730 | return $content; |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
| 733 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
| 734 | 734 | |
| 735 | - if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) { |
|
| 735 | + if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) { |
|
| 736 | 736 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
| 737 | 737 | ob_start(); |
| 738 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
| 738 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
| 739 | 739 | $content = ob_get_clean(); |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | return $content; |
| 743 | 743 | } |
| 744 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
| 744 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
| 745 | 745 | |
| 746 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
| 746 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
| 747 | 747 | $transaction_id = ''; |
| 748 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
| 748 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
| 749 | 749 | |
| 750 | - foreach ( $notes as $note ) { |
|
| 751 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
| 750 | + foreach ($notes as $note) { |
|
| 751 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
| 752 | 752 | $transaction_id = $match[1]; |
| 753 | 753 | continue; |
| 754 | 754 | } |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
| 757 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
| 758 | 758 | } |
| 759 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
| 759 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
| 760 | 760 | |
| 761 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
| 762 | - if ( $transaction_id == $invoice_id ) { |
|
| 761 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
| 762 | + if ($transaction_id == $invoice_id) { |
|
| 763 | 763 | $transaction_link = $transaction_id; |
| 764 | 764 | } else { |
| 765 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
| 765 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
| 766 | 766 | $mode = $invoice->mode; |
| 767 | 767 | } else { |
| 768 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
| 768 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
| 772 | 772 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id; |
| 773 | 773 | |
| 774 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 774 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice ); |
|
| 777 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice); |
|
| 778 | 778 | } |
| 779 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
| 779 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
| 780 | 780 | |
| 781 | -function wpinv_paypal_profile_id_link( $profile_id, $subscription ) { |
|
| 781 | +function wpinv_paypal_profile_id_link($profile_id, $subscription) { |
|
| 782 | 782 | $link = $profile_id; |
| 783 | 783 | |
| 784 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
| 785 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 784 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
| 785 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 786 | 786 | |
| 787 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
| 787 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
| 788 | 788 | $mode = $invoice->mode; |
| 789 | 789 | } else { |
| 790 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
| 790 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
| 794 | 794 | $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id; |
| 795 | 795 | |
| 796 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
| 796 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
| 797 | 797 | } |
| 798 | 798 | |
| 799 | - return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription ); |
|
| 799 | + return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription); |
|
| 800 | 800 | } |
| 801 | -add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 ); |
|
| 801 | +add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2); |
|
| 802 | 802 | |
| 803 | -function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) { |
|
| 804 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
| 805 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 803 | +function wpinv_paypal_transaction_id_link($transaction_id, $subscription) { |
|
| 804 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
| 805 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 806 | 806 | |
| 807 | - if ( ! empty( $invoice ) ) { |
|
| 808 | - return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
| 807 | + if (!empty($invoice)) { |
|
| 808 | + return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
| 809 | 809 | } |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | return $transaction_id; |
| 813 | 813 | } |
| 814 | -add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 ); |
|
| 814 | +add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2); |
|
| 815 | 815 | |
| 816 | 816 | function wpinv_is_paypal_valid_for_use() { |
| 817 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) ); |
|
| 817 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'))); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | -function wpinv_check_paypal_currency_support( $gateway_list ) { |
|
| 821 | - if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) { |
|
| 822 | - unset( $gateway_list['paypal'] ); |
|
| 820 | +function wpinv_check_paypal_currency_support($gateway_list) { |
|
| 821 | + if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) { |
|
| 822 | + unset($gateway_list['paypal']); |
|
| 823 | 823 | } |
| 824 | 824 | return $gateway_list; |
| 825 | 825 | } |
| 826 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 ); |
|
| 826 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1); |
|
| 827 | 827 | |
| 828 | -function wpinv_gateway_paypal_button_label( $label ) { |
|
| 829 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
| 828 | +function wpinv_gateway_paypal_button_label($label) { |
|
| 829 | + return __('Proceed to PayPal', 'invoicing'); |
|
| 830 | 830 | } |
| 831 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
| 832 | 831 | \ No newline at end of file |
| 832 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
| 833 | 833 | \ No newline at end of file |