@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; // Exit if accessed directly |
10 | 10 | } |
11 | 11 | |
@@ -19,27 +19,27 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @param WP_Post $post |
21 | 21 | */ |
22 | - public static function output( $post ) { |
|
22 | + public static function output($post) { |
|
23 | 23 | |
24 | 24 | //Fetch the invoice. |
25 | - $invoice = new WPInv_Invoice( $post ); |
|
25 | + $invoice = new WPInv_Invoice($post); |
|
26 | 26 | |
27 | 27 | // Ensure that it is recurring. |
28 | - if ( ! $invoice->is_recurring() ) { |
|
28 | + if (!$invoice->is_recurring()) { |
|
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
32 | 32 | // Fetch the subscription. |
33 | - $subscription = wpinv_get_subscription( $invoice ); |
|
33 | + $subscription = wpinv_get_subscription($invoice); |
|
34 | 34 | |
35 | 35 | ?> |
36 | - <?php if ( empty( $subscription ) ): ?> |
|
36 | + <?php if (empty($subscription)): ?> |
|
37 | 37 | <p class="wpi-meta-row"> |
38 | 38 | <?php |
39 | 39 | echo |
40 | 40 | wp_sprintf( |
41 | - __( 'A new subscription will be created when the customer checks out and pays the invoice. %sView all subscriptions%s', 'invoicing' ), |
|
42 | - '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', |
|
41 | + __('A new subscription will be created when the customer checks out and pays the invoice. %sView all subscriptions%s', 'invoicing'), |
|
42 | + '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', |
|
43 | 43 | '</a>' |
44 | 44 | ); |
45 | 45 | ?> |
@@ -48,30 +48,30 @@ discard block |
||
48 | 48 | return; // If no subscription. |
49 | 49 | endif; |
50 | 50 | |
51 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency ); |
|
52 | - $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
53 | - $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
54 | - $exipired = strtotime( $subscription->expiration, current_time( 'timestamp' ) ) < current_time( 'timestamp' ); |
|
51 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency); |
|
52 | + $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency; |
|
53 | + $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)); |
|
54 | + $exipired = strtotime($subscription->expiration, current_time('timestamp')) < current_time('timestamp'); |
|
55 | 55 | ?> |
56 | 56 | |
57 | - <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . esc_attr( $subscription->status ); ?>"> |
|
57 | + <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . esc_attr($subscription->status); ?>"> |
|
58 | 58 | <?php echo $invoice->is_renewal() ? _e('Renewal Invoice', 'invoicing') : _e('Recurring Invoice', 'invoicing'); ?> |
59 | 59 | </p> |
60 | 60 | |
61 | - <?php if ( ! empty( $subscription->id ) ) : ?> |
|
61 | + <?php if (!empty($subscription->id)) : ?> |
|
62 | 62 | <p class="wpi-meta-row wpi-sub-id"> |
63 | - <label><?php _e( 'Subscription ID:', 'invoicing' ); ?></label> |
|
64 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a> |
|
63 | + <label><?php _e('Subscription ID:', 'invoicing'); ?></label> |
|
64 | + <a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a> |
|
65 | 65 | </p> |
66 | 66 | <?php endif; ?> |
67 | 67 | |
68 | 68 | <p class="wpi-meta-row wpi-bill-cycle"> |
69 | - <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label> |
|
69 | + <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label> |
|
70 | 70 | <?php |
71 | 71 | |
72 | - if ( $subscription->recurring_amount != $subscription->initial_amount ) { |
|
72 | + if ($subscription->recurring_amount != $subscription->initial_amount) { |
|
73 | 73 | printf( |
74 | - _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), |
|
74 | + _x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), |
|
75 | 75 | $initial, |
76 | 76 | $billing |
77 | 77 | ); |
@@ -83,38 +83,38 @@ discard block |
||
83 | 83 | </p> |
84 | 84 | |
85 | 85 | <p class="wpi-meta-row wpi-billed-times"> |
86 | - <label><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
|
87 | - <?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->bill_times ); ?> |
|
86 | + <label><?php _e('Times Billed:', 'invoicing'); ?></label> |
|
87 | + <?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $subscription->bill_times); ?> |
|
88 | 88 | </p> |
89 | 89 | |
90 | 90 | <p class="wpi-meta-row wpi-start-date"> |
91 | - <label><?php _e( 'Start Date:', 'invoicing' ); ?></label> |
|
92 | - <?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?> |
|
91 | + <label><?php _e('Start Date:', 'invoicing'); ?></label> |
|
92 | + <?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?> |
|
93 | 93 | </p> |
94 | 94 | |
95 | 95 | <p class="wpi-meta-row wpi-end-date"> |
96 | - <label><?php echo $exipired ? __( 'Expired On:', 'invoicing' ) : __( 'Renews On:', 'invoicing' ); ?></label> |
|
97 | - <?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?> |
|
96 | + <label><?php echo $exipired ? __('Expired On:', 'invoicing') : __('Renews On:', 'invoicing'); ?></label> |
|
97 | + <?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?> |
|
98 | 98 | </p> |
99 | 99 | |
100 | - <?php if ( $subscription->status ) { ?> |
|
100 | + <?php if ($subscription->status) { ?> |
|
101 | 101 | <p class="wpi-meta-row wpi-sub-status"> |
102 | - <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
102 | + <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
103 | 103 | </p> |
104 | 104 | <?php } ?> |
105 | 105 | |
106 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
106 | + <?php if ($invoice->is_renewal()) { ?> |
|
107 | 107 | <p class="wpi-meta-row wpi-invoice-parent"> |
108 | - <label><?php _e( 'Parent Invoice:', 'invoicing'); ?></label> |
|
108 | + <label><?php _e('Parent Invoice:', 'invoicing'); ?></label> |
|
109 | 109 | <?php |
110 | 110 | $parent = $invoice->get_parent_payment(); |
111 | 111 | |
112 | - if ( $parent->get_id() ) { |
|
113 | - $parent_url = esc_url( get_edit_post_link( $parent->get_id() ) ); |
|
112 | + if ($parent->get_id()) { |
|
113 | + $parent_url = esc_url(get_edit_post_link($parent->get_id())); |
|
114 | 114 | $parent_id = $parent->get_number(); |
115 | 115 | echo "<a href='$parent_url'>$parent_id</a>"; |
116 | 116 | } else { |
117 | - echo '<del>' . __( 'Deleted', 'invoicing' ) . '</del>'; |
|
117 | + echo '<del>' . __('Deleted', 'invoicing') . '</del>'; |
|
118 | 118 | } |
119 | 119 | ?> |
120 | 120 |
@@ -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 | 60 | $sub_id = (int) $_GET['id']; |
61 | - $sub = new WPInv_Subscription( $sub_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', 'invoicing' ) : $sub->bill_times ); ?></td> |
|
102 | + <td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $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 wpi_select2', |
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" class="wpi_select2"> |
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); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | // Load WP_List_Table if not loaded |
15 | 15 | if( ! class_exists( 'WP_List_Table' ) ) { |
16 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
16 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -23,102 +23,102 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class WPInv_Subscription_Reports_Table extends WP_List_Table { |
25 | 25 | |
26 | - /** |
|
27 | - * Number of results to show per page |
|
28 | - * |
|
29 | - * @since 1.0.0 |
|
30 | - */ |
|
31 | - |
|
32 | - public $per_page = 20; |
|
33 | - public $total_count = 0; |
|
34 | - public $active_count = 0; |
|
35 | - public $pending_count = 0; |
|
36 | - public $expired_count = 0; |
|
37 | - public $completed_count = 0; |
|
38 | - public $trialling_count = 0; |
|
39 | - public $cancelled_count = 0; |
|
40 | - public $failing_count = 0; |
|
41 | - |
|
42 | - /** |
|
43 | - * Get things started |
|
44 | - * |
|
45 | - * @access private |
|
46 | - * @since 1.0.0 |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - function __construct(){ |
|
50 | - global $status, $page; |
|
51 | - |
|
52 | - // Set parent defaults |
|
53 | - parent::__construct( array( |
|
54 | - 'singular' => 'subscription', |
|
55 | - 'plural' => 'subscriptions', |
|
56 | - 'ajax' => false |
|
57 | - ) ); |
|
58 | - |
|
59 | - $this->get_subscription_counts(); |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Retrieve the view types |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @since 1.0.0 |
|
68 | - * @return array $views All the views available |
|
69 | - */ |
|
70 | - public function get_views() { |
|
71 | - |
|
72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | - $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
75 | - $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | - $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | - |
|
82 | - $views = array( |
|
83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
91 | - ); |
|
92 | - |
|
93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Show the search field |
|
98 | - * |
|
99 | - * @since 2.5 |
|
100 | - * @access public |
|
101 | - * |
|
102 | - * @param string $text Label for the search box |
|
103 | - * @param string $input_id ID of the search box |
|
104 | - * |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function search_box( $text, $input_id ) { |
|
108 | - |
|
109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
110 | - return; |
|
111 | - } |
|
112 | - |
|
113 | - $input_id = $input_id . '-search-input'; |
|
114 | - |
|
115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
117 | - } |
|
118 | - |
|
119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
121 | - } |
|
26 | + /** |
|
27 | + * Number of results to show per page |
|
28 | + * |
|
29 | + * @since 1.0.0 |
|
30 | + */ |
|
31 | + |
|
32 | + public $per_page = 20; |
|
33 | + public $total_count = 0; |
|
34 | + public $active_count = 0; |
|
35 | + public $pending_count = 0; |
|
36 | + public $expired_count = 0; |
|
37 | + public $completed_count = 0; |
|
38 | + public $trialling_count = 0; |
|
39 | + public $cancelled_count = 0; |
|
40 | + public $failing_count = 0; |
|
41 | + |
|
42 | + /** |
|
43 | + * Get things started |
|
44 | + * |
|
45 | + * @access private |
|
46 | + * @since 1.0.0 |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + function __construct(){ |
|
50 | + global $status, $page; |
|
51 | + |
|
52 | + // Set parent defaults |
|
53 | + parent::__construct( array( |
|
54 | + 'singular' => 'subscription', |
|
55 | + 'plural' => 'subscriptions', |
|
56 | + 'ajax' => false |
|
57 | + ) ); |
|
58 | + |
|
59 | + $this->get_subscription_counts(); |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Retrieve the view types |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @since 1.0.0 |
|
68 | + * @return array $views All the views available |
|
69 | + */ |
|
70 | + public function get_views() { |
|
71 | + |
|
72 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | + $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
75 | + $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | + $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | + |
|
82 | + $views = array( |
|
83 | + 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | + 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | + 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | + 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | + 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | + 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | + 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | + 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
91 | + ); |
|
92 | + |
|
93 | + return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Show the search field |
|
98 | + * |
|
99 | + * @since 2.5 |
|
100 | + * @access public |
|
101 | + * |
|
102 | + * @param string $text Label for the search box |
|
103 | + * @param string $input_id ID of the search box |
|
104 | + * |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function search_box( $text, $input_id ) { |
|
108 | + |
|
109 | + if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
110 | + return; |
|
111 | + } |
|
112 | + |
|
113 | + $input_id = $input_id . '-search-input'; |
|
114 | + |
|
115 | + if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
117 | + } |
|
118 | + |
|
119 | + if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | + echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
121 | + } |
|
122 | 122 | ?> |
123 | 123 | <p class="search-box"> |
124 | 124 | <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
@@ -127,18 +127,18 @@ discard block |
||
127 | 127 | <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
128 | 128 | </p> |
129 | 129 | <?php |
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Render most columns |
|
134 | - * |
|
135 | - * @access private |
|
136 | - * @since 1.0.0 |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - function column_default( $item, $column_name ) { |
|
140 | - return $item->$column_name; |
|
141 | - } |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Render most columns |
|
134 | + * |
|
135 | + * @access private |
|
136 | + * @since 1.0.0 |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + function column_default( $item, $column_name ) { |
|
140 | + return $item->$column_name; |
|
141 | + } |
|
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Subscription id column |
@@ -151,244 +151,244 @@ discard block |
||
151 | 151 | return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
152 | 152 | } |
153 | 153 | |
154 | - /** |
|
155 | - * Customer column |
|
156 | - * |
|
157 | - * @access private |
|
158 | - * @since 1.0.0 |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - function column_customer_id( $item ) { |
|
162 | - $subscriber = get_userdata( $item->customer_id ); |
|
163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | - |
|
165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Status column |
|
170 | - * |
|
171 | - * @access private |
|
172 | - * @since 1.0.0 |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - function column_status( $item ) { |
|
176 | - return $item->get_status_label(); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Period column |
|
181 | - * |
|
182 | - * @access private |
|
183 | - * @since 1.0.0 |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - function column_period( $item ) { |
|
187 | - |
|
188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
189 | - |
|
190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Billing Times column |
|
195 | - * |
|
196 | - * @access private |
|
197 | - * @since 1.0.0 |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - function column_bill_times( $item ) { |
|
201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $item->bill_times ); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Initial Amount column |
|
206 | - * |
|
207 | - * @access private |
|
208 | - * @since 1.0.0 |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - function column_initial_amount( $item ) { |
|
212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Renewal date column |
|
217 | - * |
|
218 | - * @access private |
|
219 | - * @since 1.0.0 |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - function column_renewal_date( $item ) { |
|
223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Payment column |
|
228 | - * |
|
229 | - * @access private |
|
230 | - * @since 1.0.0 |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - function column_parent_payment_id( $item ) { |
|
234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Product ID column |
|
239 | - * |
|
240 | - * @access private |
|
241 | - * @since 1.0.0 |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - function column_product_id( $item ) { |
|
245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Render the edit column |
|
250 | - * |
|
251 | - * @access private |
|
252 | - * @since 2.0 |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - function column_actions( $item ) { |
|
256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Retrieve the table columns |
|
262 | - * |
|
263 | - * @access private |
|
264 | - * @since 1.0.0 |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - |
|
268 | - function get_columns(){ |
|
269 | - $columns = array( |
|
270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | - 'status' => __( 'Status', 'invoicing' ), |
|
273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
280 | - ); |
|
281 | - |
|
282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Retrieve the current page number |
|
287 | - * |
|
288 | - * @access private |
|
289 | - * @since 1.0.0 |
|
290 | - * @return int |
|
291 | - */ |
|
292 | - function get_paged() { |
|
293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Retrieve the subscription counts |
|
298 | - * |
|
299 | - * @access public |
|
300 | - * @since 1.4 |
|
301 | - * @return void |
|
302 | - */ |
|
303 | - public function get_subscription_counts() { |
|
304 | - |
|
305 | - global $wp_query; |
|
306 | - |
|
307 | - $db = new WPInv_Subscriptions_DB; |
|
308 | - |
|
309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
310 | - |
|
311 | - $this->total_count = $db->count(); |
|
312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
319 | - |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Setup the final data for the table |
|
324 | - * |
|
325 | - * @access private |
|
326 | - * @since 1.0.0 |
|
327 | - * @uses $this->_column_headers |
|
328 | - * @uses $this->items |
|
329 | - * @uses $this->get_columns() |
|
330 | - * @uses $this->get_sortable_columns() |
|
331 | - * @uses $this->get_pagenum() |
|
332 | - * @uses $this->set_pagination_args() |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - function prepare_items() { |
|
336 | - |
|
337 | - $columns = $this->get_columns(); |
|
338 | - $hidden = array(); // No hidden columns |
|
339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
340 | - $sortable = $this->get_sortable_columns(); |
|
341 | - |
|
342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
343 | - |
|
344 | - $current_page = $this->get_pagenum(); |
|
345 | - |
|
346 | - $db = new WPInv_Subscriptions_DB; |
|
347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
348 | - $args = array( |
|
349 | - 'number' => $this->per_page, |
|
350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
351 | - 'search' => $search |
|
352 | - ); |
|
353 | - |
|
354 | - if ( 'any' !== $status ) { |
|
355 | - $args['status'] = $status; |
|
356 | - } |
|
357 | - |
|
358 | - $this->items = $db->get_subscriptions( $args ); |
|
359 | - |
|
360 | - switch ( $status ) { |
|
361 | - case 'active': |
|
362 | - $total_items = $this->active_count; |
|
363 | - break; |
|
364 | - case 'pending': |
|
365 | - $total_items = $this->pending_count; |
|
366 | - break; |
|
367 | - case 'expired': |
|
368 | - $total_items = $this->expired_count; |
|
369 | - break; |
|
370 | - case 'cancelled': |
|
371 | - $total_items = $this->cancelled_count; |
|
372 | - break; |
|
373 | - case 'failing': |
|
374 | - $total_items = $this->failing_count; |
|
375 | - break; |
|
376 | - case 'trialling': |
|
377 | - $total_items = $this->trialling_count; |
|
378 | - break; |
|
379 | - case 'completed': |
|
380 | - $total_items = $this->completed_count; |
|
381 | - break; |
|
382 | - case 'any': |
|
383 | - default: |
|
384 | - $total_items = $this->total_count; |
|
385 | - break; |
|
386 | - } |
|
387 | - |
|
388 | - $this->set_pagination_args( array( |
|
389 | - 'total_items' => $total_items, |
|
390 | - 'per_page' => $this->per_page, |
|
391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | - ) ); |
|
393 | - } |
|
154 | + /** |
|
155 | + * Customer column |
|
156 | + * |
|
157 | + * @access private |
|
158 | + * @since 1.0.0 |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + function column_customer_id( $item ) { |
|
162 | + $subscriber = get_userdata( $item->customer_id ); |
|
163 | + $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | + |
|
165 | + return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Status column |
|
170 | + * |
|
171 | + * @access private |
|
172 | + * @since 1.0.0 |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + function column_status( $item ) { |
|
176 | + return $item->get_status_label(); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Period column |
|
181 | + * |
|
182 | + * @access private |
|
183 | + * @since 1.0.0 |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + function column_period( $item ) { |
|
187 | + |
|
188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
189 | + |
|
190 | + return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Billing Times column |
|
195 | + * |
|
196 | + * @access private |
|
197 | + * @since 1.0.0 |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + function column_bill_times( $item ) { |
|
201 | + return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $item->bill_times ); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Initial Amount column |
|
206 | + * |
|
207 | + * @access private |
|
208 | + * @since 1.0.0 |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + function column_initial_amount( $item ) { |
|
212 | + return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Renewal date column |
|
217 | + * |
|
218 | + * @access private |
|
219 | + * @since 1.0.0 |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + function column_renewal_date( $item ) { |
|
223 | + return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Payment column |
|
228 | + * |
|
229 | + * @access private |
|
230 | + * @since 1.0.0 |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + function column_parent_payment_id( $item ) { |
|
234 | + return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Product ID column |
|
239 | + * |
|
240 | + * @access private |
|
241 | + * @since 1.0.0 |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + function column_product_id( $item ) { |
|
245 | + return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Render the edit column |
|
250 | + * |
|
251 | + * @access private |
|
252 | + * @since 2.0 |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + function column_actions( $item ) { |
|
256 | + return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Retrieve the table columns |
|
262 | + * |
|
263 | + * @access private |
|
264 | + * @since 1.0.0 |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + |
|
268 | + function get_columns(){ |
|
269 | + $columns = array( |
|
270 | + 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | + 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | + 'status' => __( 'Status', 'invoicing' ), |
|
273 | + 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | + 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | + 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | + 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | + 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | + 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | + 'actions' => __( 'Actions', 'invoicing' ), |
|
280 | + ); |
|
281 | + |
|
282 | + return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Retrieve the current page number |
|
287 | + * |
|
288 | + * @access private |
|
289 | + * @since 1.0.0 |
|
290 | + * @return int |
|
291 | + */ |
|
292 | + function get_paged() { |
|
293 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Retrieve the subscription counts |
|
298 | + * |
|
299 | + * @access public |
|
300 | + * @since 1.4 |
|
301 | + * @return void |
|
302 | + */ |
|
303 | + public function get_subscription_counts() { |
|
304 | + |
|
305 | + global $wp_query; |
|
306 | + |
|
307 | + $db = new WPInv_Subscriptions_DB; |
|
308 | + |
|
309 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
310 | + |
|
311 | + $this->total_count = $db->count(); |
|
312 | + $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | + $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | + $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | + $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | + $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | + $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | + $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
319 | + |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Setup the final data for the table |
|
324 | + * |
|
325 | + * @access private |
|
326 | + * @since 1.0.0 |
|
327 | + * @uses $this->_column_headers |
|
328 | + * @uses $this->items |
|
329 | + * @uses $this->get_columns() |
|
330 | + * @uses $this->get_sortable_columns() |
|
331 | + * @uses $this->get_pagenum() |
|
332 | + * @uses $this->set_pagination_args() |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + function prepare_items() { |
|
336 | + |
|
337 | + $columns = $this->get_columns(); |
|
338 | + $hidden = array(); // No hidden columns |
|
339 | + $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
340 | + $sortable = $this->get_sortable_columns(); |
|
341 | + |
|
342 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
343 | + |
|
344 | + $current_page = $this->get_pagenum(); |
|
345 | + |
|
346 | + $db = new WPInv_Subscriptions_DB; |
|
347 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
348 | + $args = array( |
|
349 | + 'number' => $this->per_page, |
|
350 | + 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
351 | + 'search' => $search |
|
352 | + ); |
|
353 | + |
|
354 | + if ( 'any' !== $status ) { |
|
355 | + $args['status'] = $status; |
|
356 | + } |
|
357 | + |
|
358 | + $this->items = $db->get_subscriptions( $args ); |
|
359 | + |
|
360 | + switch ( $status ) { |
|
361 | + case 'active': |
|
362 | + $total_items = $this->active_count; |
|
363 | + break; |
|
364 | + case 'pending': |
|
365 | + $total_items = $this->pending_count; |
|
366 | + break; |
|
367 | + case 'expired': |
|
368 | + $total_items = $this->expired_count; |
|
369 | + break; |
|
370 | + case 'cancelled': |
|
371 | + $total_items = $this->cancelled_count; |
|
372 | + break; |
|
373 | + case 'failing': |
|
374 | + $total_items = $this->failing_count; |
|
375 | + break; |
|
376 | + case 'trialling': |
|
377 | + $total_items = $this->trialling_count; |
|
378 | + break; |
|
379 | + case 'completed': |
|
380 | + $total_items = $this->completed_count; |
|
381 | + break; |
|
382 | + case 'any': |
|
383 | + default: |
|
384 | + $total_items = $this->total_count; |
|
385 | + break; |
|
386 | + } |
|
387 | + |
|
388 | + $this->set_pagination_args( array( |
|
389 | + 'total_items' => $total_items, |
|
390 | + 'per_page' => $this->per_page, |
|
391 | + 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | + ) ); |
|
393 | + } |
|
394 | 394 | } |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | |
9 | 9 | |
10 | 10 | // Exit if accessed directly |
11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
11 | +if (!defined('ABSPATH')) exit; |
|
12 | 12 | |
13 | 13 | |
14 | 14 | // Load WP_List_Table if not loaded |
15 | -if( ! class_exists( 'WP_List_Table' ) ) { |
|
15 | +if (!class_exists('WP_List_Table')) { |
|
16 | 16 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
17 | 17 | } |
18 | 18 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public $pending_count = 0; |
36 | 36 | public $expired_count = 0; |
37 | 37 | public $completed_count = 0; |
38 | - public $trialling_count = 0; |
|
38 | + public $trialling_count = 0; |
|
39 | 39 | public $cancelled_count = 0; |
40 | 40 | public $failing_count = 0; |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * @since 1.0.0 |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - function __construct(){ |
|
49 | + function __construct() { |
|
50 | 50 | global $status, $page; |
51 | 51 | |
52 | 52 | // Set parent defaults |
53 | - parent::__construct( array( |
|
53 | + parent::__construct(array( |
|
54 | 54 | 'singular' => 'subscription', |
55 | 55 | 'plural' => 'subscriptions', |
56 | 56 | 'ajax' => false |
57 | - ) ); |
|
57 | + )); |
|
58 | 58 | |
59 | 59 | $this->get_subscription_counts(); |
60 | 60 | |
@@ -69,28 +69,28 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function get_views() { |
71 | 71 | |
72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
72 | + $current = isset($_GET['status']) ? $_GET['status'] : ''; |
|
73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | 74 | $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
75 | 75 | $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | 77 | $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | 81 | |
82 | 82 | $views = array( |
83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
83 | + 'all' => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count), |
|
84 | + 'active' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count), |
|
85 | + 'pending' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count), |
|
86 | + 'expired' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count), |
|
87 | + 'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count), |
|
88 | + 'trialling' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count), |
|
89 | + 'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count), |
|
90 | + 'failing' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count), |
|
91 | 91 | ); |
92 | 92 | |
93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
93 | + return apply_filters('wpinv_recurring_subscriptions_table_views', $views); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -104,27 +104,27 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - public function search_box( $text, $input_id ) { |
|
107 | + public function search_box($text, $input_id) { |
|
108 | 108 | |
109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
109 | + if (empty($_REQUEST['s']) && !$this->has_items()) { |
|
110 | 110 | return; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $input_id = $input_id . '-search-input'; |
114 | 114 | |
115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
115 | + if (!empty($_REQUEST['orderby'])) { |
|
116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />'; |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
119 | + if (!empty($_REQUEST['order'])) { |
|
120 | + echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />'; |
|
121 | 121 | } |
122 | 122 | ?> |
123 | 123 | <p class="search-box"> |
124 | - <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
|
124 | + <?php do_action('wpinv_recurring_subscription_search_box'); ?> |
|
125 | 125 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
126 | 126 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
127 | - <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
|
127 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/> |
|
128 | 128 | </p> |
129 | 129 | <?php |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @since 1.0.0 |
137 | 137 | * @return string |
138 | 138 | */ |
139 | - function column_default( $item, $column_name ) { |
|
139 | + function column_default($item, $column_name) { |
|
140 | 140 | return $item->$column_name; |
141 | 141 | } |
142 | 142 | |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * @since 1.0.0 |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - function column_sub_id( $item ) { |
|
151 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
|
150 | + function column_sub_id($item) { |
|
151 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @since 1.0.0 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - function column_customer_id( $item ) { |
|
162 | - $subscriber = get_userdata( $item->customer_id ); |
|
163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
161 | + function column_customer_id($item) { |
|
162 | + $subscriber = get_userdata($item->customer_id); |
|
163 | + $customer = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | 164 | |
165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
165 | + return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>'; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @since 1.0.0 |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - function column_status( $item ) { |
|
175 | + function column_status($item) { |
|
176 | 176 | return $item->get_status_label(); |
177 | 177 | } |
178 | 178 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @since 1.0.0 |
184 | 184 | * @return string |
185 | 185 | */ |
186 | - function column_period( $item ) { |
|
186 | + function column_period($item) { |
|
187 | 187 | |
188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency); |
|
189 | 189 | |
190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
190 | + return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @since 1.0.0 |
198 | 198 | * @return string |
199 | 199 | */ |
200 | - function column_bill_times( $item ) { |
|
201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $item->bill_times ); |
|
200 | + function column_bill_times($item) { |
|
201 | + return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $item->bill_times); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @since 1.0.0 |
209 | 209 | * @return string |
210 | 210 | */ |
211 | - function column_initial_amount( $item ) { |
|
212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
211 | + function column_initial_amount($item) { |
|
212 | + return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @since 1.0.0 |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - function column_renewal_date( $item ) { |
|
223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
222 | + function column_renewal_date($item) { |
|
223 | + return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @since 1.0.0 |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - function column_parent_payment_id( $item ) { |
|
234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
233 | + function column_parent_payment_id($item) { |
|
234 | + return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>'; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * @since 1.0.0 |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - function column_product_id( $item ) { |
|
245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
244 | + function column_product_id($item) { |
|
245 | + return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>'; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @since 2.0 |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - function column_actions( $item ) { |
|
256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
255 | + function column_actions($item) { |
|
256 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>'; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @return array |
266 | 266 | */ |
267 | 267 | |
268 | - function get_columns(){ |
|
268 | + function get_columns() { |
|
269 | 269 | $columns = array( |
270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | - 'status' => __( 'Status', 'invoicing' ), |
|
273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
270 | + 'sub_id' => __('ID', 'invoicing'), |
|
271 | + 'customer_id' => __('Customer', 'invoicing'), |
|
272 | + 'status' => __('Status', 'invoicing'), |
|
273 | + 'period' => __('Billing Cycle', 'invoicing'), |
|
274 | + 'initial_amount' => __('Initial Amount', 'invoicing'), |
|
275 | + 'bill_times' => __('Times Billed', 'invoicing'), |
|
276 | + 'renewal_date' => __('Renewal Date', 'invoicing'), |
|
277 | + 'parent_payment_id' => __('Invoice', 'invoicing'), |
|
278 | + 'product_id' => __('Item', 'invoicing'), |
|
279 | + 'actions' => __('Actions', 'invoicing'), |
|
280 | 280 | ); |
281 | 281 | |
282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
282 | + return apply_filters('wpinv_report_subscription_columns', $columns); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @return int |
291 | 291 | */ |
292 | 292 | function get_paged() { |
293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
293 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -306,16 +306,16 @@ discard block |
||
306 | 306 | |
307 | 307 | $db = new WPInv_Subscriptions_DB; |
308 | 308 | |
309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
309 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
310 | 310 | |
311 | 311 | $this->total_count = $db->count(); |
312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
312 | + $this->active_count = $db->count(array('status' => 'active', 'search' => $search)); |
|
313 | + $this->pending_count = $db->count(array('status' => 'pending', 'search' => $search)); |
|
314 | + $this->expired_count = $db->count(array('status' => 'expired', 'search' => $search)); |
|
315 | + $this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search)); |
|
316 | + $this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search)); |
|
317 | + $this->completed_count = $db->count(array('status' => 'completed', 'search' => $search)); |
|
318 | + $this->failing_count = $db->count(array('status' => 'failing', 'search' => $search)); |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | |
@@ -336,28 +336,28 @@ discard block |
||
336 | 336 | |
337 | 337 | $columns = $this->get_columns(); |
338 | 338 | $hidden = array(); // No hidden columns |
339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
339 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any'; |
|
340 | 340 | $sortable = $this->get_sortable_columns(); |
341 | 341 | |
342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
342 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
343 | 343 | |
344 | 344 | $current_page = $this->get_pagenum(); |
345 | 345 | |
346 | 346 | $db = new WPInv_Subscriptions_DB; |
347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
347 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
348 | 348 | $args = array( |
349 | 349 | 'number' => $this->per_page, |
350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
350 | + 'offset' => $this->per_page * ($this->get_paged() - 1), |
|
351 | 351 | 'search' => $search |
352 | 352 | ); |
353 | 353 | |
354 | - if ( 'any' !== $status ) { |
|
354 | + if ('any' !== $status) { |
|
355 | 355 | $args['status'] = $status; |
356 | 356 | } |
357 | 357 | |
358 | - $this->items = $db->get_subscriptions( $args ); |
|
358 | + $this->items = $db->get_subscriptions($args); |
|
359 | 359 | |
360 | - switch ( $status ) { |
|
360 | + switch ($status) { |
|
361 | 361 | case 'active': |
362 | 362 | $total_items = $this->active_count; |
363 | 363 | break; |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | break; |
386 | 386 | } |
387 | 387 | |
388 | - $this->set_pagination_args( array( |
|
388 | + $this->set_pagination_args(array( |
|
389 | 389 | 'total_items' => $total_items, |
390 | 390 | 'per_page' => $this->per_page, |
391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | - ) ); |
|
391 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
392 | + )); |
|
393 | 393 | } |
394 | 394 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
5 | - exit; |
|
5 | + exit; |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -13,187 +13,187 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class WPInv_Subscription { |
15 | 15 | |
16 | - private $subs_db; |
|
16 | + private $subs_db; |
|
17 | + |
|
18 | + public $id = 0; |
|
19 | + public $customer_id = 0; |
|
20 | + public $period = ''; |
|
21 | + public $initial_amount = ''; |
|
22 | + public $recurring_amount = ''; |
|
23 | + public $bill_times = 0; |
|
24 | + public $transaction_id = ''; |
|
25 | + public $parent_payment_id = 0; |
|
26 | + public $product_id = 0; |
|
27 | + public $created = '0000-00-00 00:00:00'; |
|
28 | + public $expiration = '0000-00-00 00:00:00'; |
|
29 | + public $trial_period = ''; |
|
30 | + public $status = 'pending'; |
|
31 | + public $profile_id = ''; |
|
32 | + public $gateway = ''; |
|
33 | + public $customer; |
|
17 | 34 | |
18 | - public $id = 0; |
|
19 | - public $customer_id = 0; |
|
20 | - public $period = ''; |
|
21 | - public $initial_amount = ''; |
|
22 | - public $recurring_amount = ''; |
|
23 | - public $bill_times = 0; |
|
24 | - public $transaction_id = ''; |
|
25 | - public $parent_payment_id = 0; |
|
26 | - public $product_id = 0; |
|
27 | - public $created = '0000-00-00 00:00:00'; |
|
28 | - public $expiration = '0000-00-00 00:00:00'; |
|
29 | - public $trial_period = ''; |
|
30 | - public $status = 'pending'; |
|
31 | - public $profile_id = ''; |
|
32 | - public $gateway = ''; |
|
33 | - public $customer; |
|
34 | - |
|
35 | - /** |
|
36 | - * Get us started |
|
37 | - * |
|
38 | - * @since 1.0.0 |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
35 | + /** |
|
36 | + * Get us started |
|
37 | + * |
|
38 | + * @since 1.0.0 |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
42 | 42 | |
43 | - $this->subs_db = new WPInv_Subscriptions_DB; |
|
43 | + $this->subs_db = new WPInv_Subscriptions_DB; |
|
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if( $_by_profile_id ) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
50 | - return false; |
|
51 | - } |
|
49 | + if( empty( $_sub ) ) { |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | |
53 | - $_id_or_object = $_sub; |
|
53 | + $_id_or_object = $_sub; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
58 | - } |
|
57 | + return $this->setup_subscription( $_id_or_object ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Setup the subscription object |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
60 | + /** |
|
61 | + * Setup the subscription object |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + private function setup_subscription( $id_or_object = 0 ) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
69 | - return false; |
|
70 | - } |
|
68 | + if( empty( $id_or_object ) ) { |
|
69 | + return false; |
|
70 | + } |
|
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if( is_numeric( $id_or_object ) ) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get( $id_or_object ); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif( is_object( $id_or_object ) ) { |
|
77 | 77 | |
78 | - $sub = $id_or_object; |
|
78 | + $sub = $id_or_object; |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
83 | - return false; |
|
84 | - } |
|
82 | + if( empty( $sub ) ) { |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
87 | - $this->$key = $value; |
|
88 | - } |
|
86 | + foreach( $sub as $key => $value ) { |
|
87 | + $this->$key = $value; |
|
88 | + } |
|
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata( $this->customer_id ); |
|
91 | + $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
94 | 94 | |
95 | - return $this; |
|
96 | - } |
|
95 | + return $this; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Magic __get function to dispatch a call to retrieve a private property |
|
100 | - * |
|
101 | - * @since 1.0.0 |
|
102 | - */ |
|
103 | - public function __get( $key ) { |
|
98 | + /** |
|
99 | + * Magic __get function to dispatch a call to retrieve a private property |
|
100 | + * |
|
101 | + * @since 1.0.0 |
|
102 | + */ |
|
103 | + public function __get( $key ) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if( method_exists( $this, 'get_' . $key ) ) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func( array( $this, 'get_' . $key ) ); |
|
108 | 108 | |
109 | - } else { |
|
109 | + } else { |
|
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
112 | 112 | |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Creates a subscription |
|
119 | - * |
|
120 | - * @since 1.0.0 |
|
121 | - * @param array $data Array of attributes for a subscription |
|
122 | - * @return mixed false if data isn't passed and class not instantiated for creation |
|
123 | - */ |
|
124 | - public function create( $data = array() ) { |
|
117 | + /** |
|
118 | + * Creates a subscription |
|
119 | + * |
|
120 | + * @since 1.0.0 |
|
121 | + * @param array $data Array of attributes for a subscription |
|
122 | + * @return mixed false if data isn't passed and class not instantiated for creation |
|
123 | + */ |
|
124 | + public function create( $data = array() ) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
127 | - return false; |
|
128 | - } |
|
126 | + if ( $this->id != 0 ) { |
|
127 | + return false; |
|
128 | + } |
|
129 | 129 | |
130 | - $defaults = array( |
|
131 | - 'customer_id' => 0, |
|
132 | - 'frequency' => '', |
|
133 | - 'period' => '', |
|
134 | - 'initial_amount' => '', |
|
135 | - 'recurring_amount' => '', |
|
136 | - 'bill_times' => 0, |
|
137 | - 'parent_payment_id' => 0, |
|
138 | - 'product_id' => 0, |
|
139 | - 'created' => '', |
|
140 | - 'expiration' => '', |
|
141 | - 'status' => '', |
|
142 | - 'profile_id' => '', |
|
143 | - ); |
|
130 | + $defaults = array( |
|
131 | + 'customer_id' => 0, |
|
132 | + 'frequency' => '', |
|
133 | + 'period' => '', |
|
134 | + 'initial_amount' => '', |
|
135 | + 'recurring_amount' => '', |
|
136 | + 'bill_times' => 0, |
|
137 | + 'parent_payment_id' => 0, |
|
138 | + 'product_id' => 0, |
|
139 | + 'created' => '', |
|
140 | + 'expiration' => '', |
|
141 | + 'status' => '', |
|
142 | + 'profile_id' => '', |
|
143 | + ); |
|
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args( $data, $defaults ); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
150 | 150 | |
151 | - // Force an active subscription to expired if expiration date is in the past |
|
152 | - $args['status'] = 'expired'; |
|
151 | + // Force an active subscription to expired if expiration date is in the past |
|
152 | + $args['status'] = 'expired'; |
|
153 | 153 | |
154 | - } |
|
155 | - } |
|
154 | + } |
|
155 | + } |
|
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action( 'wpinv_subscription_pre_create', $args ); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert( $args, 'subscription' ); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription( $id ); |
|
164 | 164 | |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Updates a subscription |
|
169 | - * |
|
170 | - * @since 1.0.0 |
|
171 | - * @param array $args Array of fields to update |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function update( $args = array() ) { |
|
167 | + /** |
|
168 | + * Updates a subscription |
|
169 | + * |
|
170 | + * @since 1.0.0 |
|
171 | + * @param array $args Array of fields to update |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function update( $args = array() ) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update( $this->id, $args ); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
179 | 179 | |
180 | - if ( $ret && isset( $args['profile_id'] ) ) { |
|
181 | - update_post_meta( $this->parent_payment_id, 'subscription_id', $args['profile_id'] ); |
|
182 | - } |
|
180 | + if ( $ret && isset( $args['profile_id'] ) ) { |
|
181 | + update_post_meta( $this->parent_payment_id, 'subscription_id', $args['profile_id'] ); |
|
182 | + } |
|
183 | 183 | |
184 | - return $ret; |
|
184 | + return $ret; |
|
185 | 185 | |
186 | - } |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Delete the subscription |
|
190 | - * |
|
191 | - * @since 1.0.0 |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - public function delete() { |
|
195 | - return $this->subs_db->delete( $this->id ); |
|
196 | - } |
|
188 | + /** |
|
189 | + * Delete the subscription |
|
190 | + * |
|
191 | + * @since 1.0.0 |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + public function delete() { |
|
195 | + return $this->subs_db->delete( $this->id ); |
|
196 | + } |
|
197 | 197 | |
198 | 198 | /** |
199 | 199 | * Retrieves the parent payment ID |
@@ -262,57 +262,57 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @since 2.4 |
264 | 264 | * @param array $args Array of values for the payment, including amount and transaction ID |
265 | - * @param WPInv_Invoice $invoice |
|
265 | + * @param WPInv_Invoice $invoice |
|
266 | 266 | * @return bool |
267 | 267 | */ |
268 | 268 | public function add_payment( $args = array(), $invoice = false ) { |
269 | 269 | |
270 | - // Process each payment once. |
|
270 | + // Process each payment once. |
|
271 | 271 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
275 | - // Are we creating a new invoice? |
|
276 | - if ( empty( $invoice ) ) { |
|
277 | - $invoice = $this->create_payment(); |
|
275 | + // Are we creating a new invoice? |
|
276 | + if ( empty( $invoice ) ) { |
|
277 | + $invoice = $this->create_payment(); |
|
278 | 278 | |
279 | - if ( empty( $invoice ) ) { |
|
280 | - return false; |
|
281 | - } |
|
279 | + if ( empty( $invoice ) ) { |
|
280 | + return false; |
|
281 | + } |
|
282 | 282 | |
283 | - $invoice->set_status( 'wpi-renewal' ); |
|
283 | + $invoice->set_status( 'wpi-renewal' ); |
|
284 | 284 | |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | - // Maybe set a transaction id. |
|
288 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
289 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
290 | - } |
|
287 | + // Maybe set a transaction id. |
|
288 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
289 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
290 | + } |
|
291 | 291 | |
292 | - // Set the completed date. |
|
293 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
292 | + // Set the completed date. |
|
293 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
294 | 294 | |
295 | - // And the gateway. |
|
296 | - if ( ! empty( $args['gateway'] ) ) { |
|
297 | - $invoice->set_gateway( $args['gateway'] ); |
|
298 | - } |
|
295 | + // And the gateway. |
|
296 | + if ( ! empty( $args['gateway'] ) ) { |
|
297 | + $invoice->set_gateway( $args['gateway'] ); |
|
298 | + } |
|
299 | 299 | |
300 | - $invoice->save(); |
|
300 | + $invoice->save(); |
|
301 | 301 | |
302 | - if ( ! $invoice->get_id() ) { |
|
303 | - return 0; |
|
304 | - } |
|
302 | + if ( ! $invoice->get_id() ) { |
|
303 | + return 0; |
|
304 | + } |
|
305 | 305 | |
306 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
307 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
306 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
307 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
308 | 308 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->parent_payment_id, $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
309 | 309 | |
310 | 310 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
311 | 311 | |
312 | 312 | return $invoice->get_id(); |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
315 | + /** |
|
316 | 316 | * Creates a new invoice and returns it. |
317 | 317 | * |
318 | 318 | * @since 1.0.19 |
@@ -321,196 +321,196 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function create_payment() { |
323 | 323 | |
324 | - // Do we have a parent invoice? |
|
324 | + // Do we have a parent invoice? |
|
325 | 325 | if ( ! $this->parent_payment_id ) { |
326 | 326 | return false; |
327 | 327 | } |
328 | 328 | |
329 | - // Ensure that the parent invoice is available. |
|
329 | + // Ensure that the parent invoice is available. |
|
330 | 330 | $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
331 | 331 | if ( empty( $parent_invoice ) ) { |
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | |
335 | - // Duplicate the parent invoice. |
|
336 | - $invoice = new WPInv_Invoice(); |
|
337 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
338 | - $invoice->set_id( 0 ); |
|
339 | - $invoice->set_parent_id( $parent_invoice->get_parent() ); |
|
340 | - $invoice->set_transaction_id( '' ); |
|
341 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
342 | - $invoice->set_number( '' ); |
|
343 | - $invoice->set_completed_date( '' ); |
|
344 | - $invoice->set_status( 'wpi-pending' ); |
|
345 | - $invoice->recalculate_total(); |
|
346 | - $invoice->save(); |
|
347 | - |
|
348 | - return $invoice->get_id() ? $invoice : false; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Retrieves the transaction ID from the subscription |
|
353 | - * |
|
354 | - * @since 1.0.0 |
|
355 | - * @return bool |
|
356 | - */ |
|
357 | - public function get_transaction_id() { |
|
358 | - |
|
359 | - if( empty( $this->transaction_id ) ) { |
|
360 | - |
|
361 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
362 | - |
|
363 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
364 | - $this->set_transaction_id( $txn_id ); |
|
365 | - } |
|
366 | - |
|
367 | - } |
|
368 | - |
|
369 | - return $this->transaction_id; |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Stores the transaction ID for the subscription purchase |
|
375 | - * |
|
376 | - * @since 1.0.0.4 |
|
377 | - * @return bool |
|
378 | - */ |
|
379 | - public function set_transaction_id( $txn_id = '' ) { |
|
380 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
381 | - $this->transaction_id = $txn_id; |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Renews a subscription |
|
386 | - * |
|
387 | - * @since 1.0.0 |
|
388 | - * @return bool |
|
389 | - */ |
|
390 | - public function renew() { |
|
391 | - |
|
392 | - // Calculate new expiration |
|
393 | - $expires = $this->get_expiration_time(); |
|
394 | - $base_date = $expires > current_time( 'timestamp' ) ? $expires : current_time( 'timestamp' ); |
|
395 | - $frequency = isset( $this->frequency ) ? $this->frequency : 1; |
|
396 | - $new_expiration = strtotime( "+ {$frequency} {$this->period}", strtotime( $base_date ) ); |
|
397 | - $new_expiration = apply_filters( 'wpinv_subscription_renewal_expiration', date( 'Y-m-d H:i:s', $new_expiration ), $this->id, $this ); |
|
398 | - |
|
399 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $new_expiration, $this ); |
|
400 | - |
|
401 | - $this->status = 'active'; |
|
402 | - $times_billed = $this->get_times_billed(); |
|
403 | - |
|
404 | - // Complete subscription if applicable |
|
405 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
406 | - $this->complete(); |
|
407 | - $this->status = 'completed'; |
|
408 | - return; |
|
409 | - } |
|
410 | - |
|
411 | - $args = array( |
|
412 | - 'expiration' => $new_expiration, |
|
413 | - 'status' => $this->status, |
|
414 | - ); |
|
335 | + // Duplicate the parent invoice. |
|
336 | + $invoice = new WPInv_Invoice(); |
|
337 | + $invoice->set_props( $parent_invoice->get_data() ); |
|
338 | + $invoice->set_id( 0 ); |
|
339 | + $invoice->set_parent_id( $parent_invoice->get_parent() ); |
|
340 | + $invoice->set_transaction_id( '' ); |
|
341 | + $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
342 | + $invoice->set_number( '' ); |
|
343 | + $invoice->set_completed_date( '' ); |
|
344 | + $invoice->set_status( 'wpi-pending' ); |
|
345 | + $invoice->recalculate_total(); |
|
346 | + $invoice->save(); |
|
347 | + |
|
348 | + return $invoice->get_id() ? $invoice : false; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Retrieves the transaction ID from the subscription |
|
353 | + * |
|
354 | + * @since 1.0.0 |
|
355 | + * @return bool |
|
356 | + */ |
|
357 | + public function get_transaction_id() { |
|
358 | + |
|
359 | + if( empty( $this->transaction_id ) ) { |
|
360 | + |
|
361 | + $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
362 | + |
|
363 | + if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
364 | + $this->set_transaction_id( $txn_id ); |
|
365 | + } |
|
366 | + |
|
367 | + } |
|
368 | + |
|
369 | + return $this->transaction_id; |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Stores the transaction ID for the subscription purchase |
|
375 | + * |
|
376 | + * @since 1.0.0.4 |
|
377 | + * @return bool |
|
378 | + */ |
|
379 | + public function set_transaction_id( $txn_id = '' ) { |
|
380 | + $this->update( array( 'transaction_id' => $txn_id ) ); |
|
381 | + $this->transaction_id = $txn_id; |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Renews a subscription |
|
386 | + * |
|
387 | + * @since 1.0.0 |
|
388 | + * @return bool |
|
389 | + */ |
|
390 | + public function renew() { |
|
391 | + |
|
392 | + // Calculate new expiration |
|
393 | + $expires = $this->get_expiration_time(); |
|
394 | + $base_date = $expires > current_time( 'timestamp' ) ? $expires : current_time( 'timestamp' ); |
|
395 | + $frequency = isset( $this->frequency ) ? $this->frequency : 1; |
|
396 | + $new_expiration = strtotime( "+ {$frequency} {$this->period}", strtotime( $base_date ) ); |
|
397 | + $new_expiration = apply_filters( 'wpinv_subscription_renewal_expiration', date( 'Y-m-d H:i:s', $new_expiration ), $this->id, $this ); |
|
398 | + |
|
399 | + do_action( 'wpinv_subscription_pre_renew', $this->id, $new_expiration, $this ); |
|
400 | + |
|
401 | + $this->status = 'active'; |
|
402 | + $times_billed = $this->get_times_billed(); |
|
403 | + |
|
404 | + // Complete subscription if applicable |
|
405 | + if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
406 | + $this->complete(); |
|
407 | + $this->status = 'completed'; |
|
408 | + return; |
|
409 | + } |
|
410 | + |
|
411 | + $args = array( |
|
412 | + 'expiration' => $new_expiration, |
|
413 | + 'status' => $this->status, |
|
414 | + ); |
|
415 | 415 | |
416 | 416 | $this->subs_db->update( $this->id, $args ); |
417 | 417 | |
418 | - $this->expiration = $new_expiration; |
|
418 | + $this->expiration = $new_expiration; |
|
419 | 419 | |
420 | - do_action( 'wpinv_subscription_post_renew', $this->id, $new_expiration, $this ); |
|
421 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
420 | + do_action( 'wpinv_subscription_post_renew', $this->id, $new_expiration, $this ); |
|
421 | + do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Marks a subscription as completed |
|
427 | - * |
|
428 | - * Subscription is completed when the number of payments matches the billing_times field |
|
429 | - * |
|
430 | - * @since 1.0.0 |
|
431 | - * @return void |
|
432 | - */ |
|
433 | - public function complete() { |
|
425 | + /** |
|
426 | + * Marks a subscription as completed |
|
427 | + * |
|
428 | + * Subscription is completed when the number of payments matches the billing_times field |
|
429 | + * |
|
430 | + * @since 1.0.0 |
|
431 | + * @return void |
|
432 | + */ |
|
433 | + public function complete() { |
|
434 | 434 | |
435 | - // Only mark a subscription as complete if it's not already cancelled. |
|
436 | - if ( 'cancelled' === $this->status ) { |
|
437 | - return; |
|
438 | - } |
|
435 | + // Only mark a subscription as complete if it's not already cancelled. |
|
436 | + if ( 'cancelled' === $this->status ) { |
|
437 | + return; |
|
438 | + } |
|
439 | 439 | |
440 | - $args = array( |
|
441 | - 'status' => 'completed' |
|
442 | - ); |
|
440 | + $args = array( |
|
441 | + 'status' => 'completed' |
|
442 | + ); |
|
443 | 443 | |
444 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
444 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
445 | 445 | |
446 | - $this->status = 'completed'; |
|
446 | + $this->status = 'completed'; |
|
447 | 447 | |
448 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
448 | + do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
449 | 449 | |
450 | - } |
|
450 | + } |
|
451 | 451 | |
452 | - } |
|
452 | + } |
|
453 | 453 | |
454 | - /** |
|
455 | - * Marks a subscription as expired |
|
456 | - * |
|
457 | - * Subscription is completed when the billing times is reached |
|
458 | - * |
|
459 | - * @since 1.0.0 |
|
460 | - * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
461 | - * @return void |
|
462 | - */ |
|
463 | - public function expire( $check_expiration = false ) { |
|
454 | + /** |
|
455 | + * Marks a subscription as expired |
|
456 | + * |
|
457 | + * Subscription is completed when the billing times is reached |
|
458 | + * |
|
459 | + * @since 1.0.0 |
|
460 | + * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
461 | + * @return void |
|
462 | + */ |
|
463 | + public function expire( $check_expiration = false ) { |
|
464 | 464 | |
465 | - $expiration = $this->expiration; |
|
465 | + $expiration = $this->expiration; |
|
466 | 466 | |
467 | - if( $check_expiration ) { |
|
467 | + if( $check_expiration ) { |
|
468 | 468 | |
469 | - // check_expiration() updates $this->expiration so compare to $expiration above |
|
469 | + // check_expiration() updates $this->expiration so compare to $expiration above |
|
470 | 470 | |
471 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
471 | + if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
472 | 472 | |
473 | - return false; // Do not mark as expired since real expiration date is in the future |
|
474 | - } |
|
473 | + return false; // Do not mark as expired since real expiration date is in the future |
|
474 | + } |
|
475 | 475 | |
476 | - } |
|
476 | + } |
|
477 | 477 | |
478 | - $args = array( |
|
479 | - 'status' => 'expired' |
|
480 | - ); |
|
478 | + $args = array( |
|
479 | + 'status' => 'expired' |
|
480 | + ); |
|
481 | 481 | |
482 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
482 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
483 | 483 | |
484 | - $this->status = 'expired'; |
|
484 | + $this->status = 'expired'; |
|
485 | 485 | |
486 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
486 | + do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
487 | 487 | |
488 | - } |
|
488 | + } |
|
489 | 489 | |
490 | - } |
|
490 | + } |
|
491 | 491 | |
492 | - /** |
|
493 | - * Marks a subscription as failing |
|
494 | - * |
|
495 | - * @since 2.4.2 |
|
496 | - * @return void |
|
497 | - */ |
|
498 | - public function failing() { |
|
492 | + /** |
|
493 | + * Marks a subscription as failing |
|
494 | + * |
|
495 | + * @since 2.4.2 |
|
496 | + * @return void |
|
497 | + */ |
|
498 | + public function failing() { |
|
499 | 499 | |
500 | - $args = array( |
|
501 | - 'status' => 'failing' |
|
502 | - ); |
|
500 | + $args = array( |
|
501 | + 'status' => 'failing' |
|
502 | + ); |
|
503 | 503 | |
504 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
504 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
505 | 505 | |
506 | - $this->status = 'failing'; |
|
506 | + $this->status = 'failing'; |
|
507 | 507 | |
508 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
509 | - do_action( 'wpinv_recurring_payment_failed', $this ); |
|
508 | + do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
509 | + do_action( 'wpinv_recurring_payment_failed', $this ); |
|
510 | 510 | |
511 | - } |
|
511 | + } |
|
512 | 512 | |
513 | - } |
|
513 | + } |
|
514 | 514 | |
515 | 515 | /** |
516 | 516 | * Marks a subscription as cancelled |
@@ -544,22 +544,22 @@ discard block |
||
544 | 544 | } |
545 | 545 | } |
546 | 546 | |
547 | - /** |
|
548 | - * Determines if subscription can be cancelled |
|
549 | - * |
|
550 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
551 | - * that can be cancelled with a profile ID through the merchant processor |
|
552 | - * |
|
553 | - * @since 1.0.0 |
|
554 | - * @return bool |
|
555 | - */ |
|
556 | - public function can_cancel() { |
|
547 | + /** |
|
548 | + * Determines if subscription can be cancelled |
|
549 | + * |
|
550 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
551 | + * that can be cancelled with a profile ID through the merchant processor |
|
552 | + * |
|
553 | + * @since 1.0.0 |
|
554 | + * @return bool |
|
555 | + */ |
|
556 | + public function can_cancel() { |
|
557 | 557 | $ret = false; |
558 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
558 | + if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
559 | 559 | $ret = true; |
560 | 560 | } |
561 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
562 | - } |
|
561 | + return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
562 | + } |
|
563 | 563 | |
564 | 564 | /** |
565 | 565 | * Returns an array of subscription statuses that can be cancelled |
@@ -572,197 +572,197 @@ discard block |
||
572 | 572 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
573 | 573 | } |
574 | 574 | |
575 | - /** |
|
576 | - * Retrieves the URL to cancel subscription |
|
577 | - * |
|
578 | - * @since 1.0.0 |
|
579 | - * @return string |
|
580 | - */ |
|
581 | - public function get_cancel_url() { |
|
575 | + /** |
|
576 | + * Retrieves the URL to cancel subscription |
|
577 | + * |
|
578 | + * @since 1.0.0 |
|
579 | + * @return string |
|
580 | + */ |
|
581 | + public function get_cancel_url() { |
|
582 | 582 | |
583 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
583 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
584 | 584 | |
585 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
586 | - } |
|
585 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
586 | + } |
|
587 | 587 | |
588 | - /** |
|
589 | - * Determines if subscription can be manually renewed |
|
590 | - * |
|
591 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
592 | - * that can be renewed manually |
|
593 | - * |
|
594 | - * @since 2.5 |
|
595 | - * @return bool |
|
596 | - */ |
|
597 | - public function can_renew() { |
|
588 | + /** |
|
589 | + * Determines if subscription can be manually renewed |
|
590 | + * |
|
591 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
592 | + * that can be renewed manually |
|
593 | + * |
|
594 | + * @since 2.5 |
|
595 | + * @return bool |
|
596 | + */ |
|
597 | + public function can_renew() { |
|
598 | 598 | |
599 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * Retrieves the URL to renew a subscription |
|
604 | - * |
|
605 | - * @since 2.5 |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function get_renew_url() { |
|
609 | - |
|
610 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
611 | - |
|
612 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Determines if subscription can have their payment method updated |
|
617 | - * |
|
618 | - * @since 1.0.0 |
|
619 | - * @return bool |
|
620 | - */ |
|
621 | - public function can_update() { |
|
622 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Retrieves the URL to update subscription |
|
627 | - * |
|
628 | - * @since 1.0.0 |
|
629 | - * @return void |
|
630 | - */ |
|
631 | - public function get_update_url() { |
|
632 | - |
|
633 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
634 | - |
|
635 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * Determines if subscription is active |
|
640 | - * |
|
641 | - * @since 1.0.0 |
|
642 | - * @return void |
|
643 | - */ |
|
644 | - public function is_active() { |
|
645 | - |
|
646 | - $ret = false; |
|
647 | - |
|
648 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
649 | - $ret = true; |
|
650 | - } |
|
651 | - |
|
652 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
653 | - |
|
654 | - } |
|
655 | - |
|
656 | - /** |
|
657 | - * Determines if subscription is expired |
|
658 | - * |
|
659 | - * @since 1.0.0 |
|
660 | - * @return void |
|
661 | - */ |
|
662 | - public function is_expired() { |
|
663 | - |
|
664 | - $ret = false; |
|
665 | - |
|
666 | - if ( $this->status == 'expired' ) { |
|
667 | - |
|
668 | - $ret = true; |
|
669 | - |
|
670 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
671 | - |
|
672 | - $ret = false; |
|
673 | - $expiration = $this->get_expiration_time(); |
|
674 | - |
|
675 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
676 | - $ret = true; |
|
677 | - |
|
678 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
679 | - $this->expire(); |
|
680 | - } |
|
681 | - } |
|
682 | - |
|
683 | - } |
|
684 | - |
|
685 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
686 | - |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Retrieves the expiration date |
|
691 | - * |
|
692 | - * @since 1.0.0 |
|
693 | - * @return string |
|
694 | - */ |
|
695 | - public function get_expiration() { |
|
696 | - return $this->expiration; |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * Retrieves the expiration date in a timestamp |
|
701 | - * |
|
702 | - * @since 1.0.0 |
|
703 | - * @return int |
|
704 | - */ |
|
705 | - public function get_expiration_time() { |
|
706 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Retrieves the subscription status |
|
711 | - * |
|
712 | - * @since 1.0.0 |
|
713 | - * @return int |
|
714 | - */ |
|
715 | - public function get_status() { |
|
716 | - |
|
717 | - // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
718 | - $this->is_expired(); |
|
719 | - return $this->status; |
|
720 | - } |
|
721 | - |
|
722 | - /** |
|
723 | - * Retrieves the subscription status label |
|
724 | - * |
|
725 | - * @since 1.0.0 |
|
726 | - * @return int |
|
727 | - */ |
|
728 | - public function get_status_label() { |
|
599 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
600 | + } |
|
729 | 601 | |
730 | - switch( $this->get_status() ) { |
|
731 | - case 'active' : |
|
732 | - $status = __( 'Active', 'invoicing' ); |
|
733 | - break; |
|
602 | + /** |
|
603 | + * Retrieves the URL to renew a subscription |
|
604 | + * |
|
605 | + * @since 2.5 |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function get_renew_url() { |
|
734 | 609 | |
735 | - case 'cancelled' : |
|
736 | - $status = __( 'Cancelled', 'invoicing' ); |
|
737 | - break; |
|
738 | - |
|
739 | - case 'expired' : |
|
740 | - $status = __( 'Expired', 'invoicing' ); |
|
741 | - break; |
|
610 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
742 | 611 | |
743 | - case 'pending' : |
|
744 | - $status = __( 'Pending', 'invoicing' ); |
|
745 | - break; |
|
612 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Determines if subscription can have their payment method updated |
|
617 | + * |
|
618 | + * @since 1.0.0 |
|
619 | + * @return bool |
|
620 | + */ |
|
621 | + public function can_update() { |
|
622 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
623 | + } |
|
746 | 624 | |
747 | - case 'failing' : |
|
748 | - $status = __( 'Failing', 'invoicing' ); |
|
749 | - break; |
|
625 | + /** |
|
626 | + * Retrieves the URL to update subscription |
|
627 | + * |
|
628 | + * @since 1.0.0 |
|
629 | + * @return void |
|
630 | + */ |
|
631 | + public function get_update_url() { |
|
632 | + |
|
633 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
634 | + |
|
635 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * Determines if subscription is active |
|
640 | + * |
|
641 | + * @since 1.0.0 |
|
642 | + * @return void |
|
643 | + */ |
|
644 | + public function is_active() { |
|
645 | + |
|
646 | + $ret = false; |
|
647 | + |
|
648 | + if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
649 | + $ret = true; |
|
650 | + } |
|
651 | + |
|
652 | + return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
653 | + |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * Determines if subscription is expired |
|
658 | + * |
|
659 | + * @since 1.0.0 |
|
660 | + * @return void |
|
661 | + */ |
|
662 | + public function is_expired() { |
|
663 | + |
|
664 | + $ret = false; |
|
665 | + |
|
666 | + if ( $this->status == 'expired' ) { |
|
667 | + |
|
668 | + $ret = true; |
|
669 | + |
|
670 | + } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
671 | + |
|
672 | + $ret = false; |
|
673 | + $expiration = $this->get_expiration_time(); |
|
674 | + |
|
675 | + if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
676 | + $ret = true; |
|
677 | + |
|
678 | + if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
679 | + $this->expire(); |
|
680 | + } |
|
681 | + } |
|
682 | + |
|
683 | + } |
|
750 | 684 | |
751 | - case 'trialling' : |
|
752 | - $status = __( 'Trialling', 'invoicing' ); |
|
753 | - break; |
|
754 | - |
|
755 | - case 'completed' : |
|
756 | - $status = __( 'Completed', 'invoicing' ); |
|
757 | - break; |
|
758 | - |
|
759 | - default: |
|
760 | - $status = ucfirst( $this->get_status() ); |
|
761 | - break; |
|
762 | - } |
|
685 | + return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
763 | 686 | |
764 | - return $status; |
|
765 | - } |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Retrieves the expiration date |
|
691 | + * |
|
692 | + * @since 1.0.0 |
|
693 | + * @return string |
|
694 | + */ |
|
695 | + public function get_expiration() { |
|
696 | + return $this->expiration; |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * Retrieves the expiration date in a timestamp |
|
701 | + * |
|
702 | + * @since 1.0.0 |
|
703 | + * @return int |
|
704 | + */ |
|
705 | + public function get_expiration_time() { |
|
706 | + return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Retrieves the subscription status |
|
711 | + * |
|
712 | + * @since 1.0.0 |
|
713 | + * @return int |
|
714 | + */ |
|
715 | + public function get_status() { |
|
716 | + |
|
717 | + // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
718 | + $this->is_expired(); |
|
719 | + return $this->status; |
|
720 | + } |
|
721 | + |
|
722 | + /** |
|
723 | + * Retrieves the subscription status label |
|
724 | + * |
|
725 | + * @since 1.0.0 |
|
726 | + * @return int |
|
727 | + */ |
|
728 | + public function get_status_label() { |
|
729 | + |
|
730 | + switch( $this->get_status() ) { |
|
731 | + case 'active' : |
|
732 | + $status = __( 'Active', 'invoicing' ); |
|
733 | + break; |
|
734 | + |
|
735 | + case 'cancelled' : |
|
736 | + $status = __( 'Cancelled', 'invoicing' ); |
|
737 | + break; |
|
738 | + |
|
739 | + case 'expired' : |
|
740 | + $status = __( 'Expired', 'invoicing' ); |
|
741 | + break; |
|
742 | + |
|
743 | + case 'pending' : |
|
744 | + $status = __( 'Pending', 'invoicing' ); |
|
745 | + break; |
|
746 | + |
|
747 | + case 'failing' : |
|
748 | + $status = __( 'Failing', 'invoicing' ); |
|
749 | + break; |
|
750 | + |
|
751 | + case 'trialling' : |
|
752 | + $status = __( 'Trialling', 'invoicing' ); |
|
753 | + break; |
|
754 | + |
|
755 | + case 'completed' : |
|
756 | + $status = __( 'Completed', 'invoicing' ); |
|
757 | + break; |
|
758 | + |
|
759 | + default: |
|
760 | + $status = ucfirst( $this->get_status() ); |
|
761 | + break; |
|
762 | + } |
|
763 | + |
|
764 | + return $status; |
|
765 | + } |
|
766 | 766 | |
767 | 767 | /** |
768 | 768 | * Retrieves the subscription status label |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | * @return bool |
828 | 828 | */ |
829 | 829 | public function payment_exists( $txn_id = '' ) { |
830 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
830 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
831 | 831 | return ! empty( $invoice_id ); |
832 | 832 | } |
833 | 833 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | +if (!defined('ABSPATH')) { |
|
5 | 5 | exit; |
6 | 6 | } |
7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @since 1.0.0 |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
42 | 42 | |
43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if ($_by_profile_id) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
49 | + if (empty($_sub)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
57 | + return $this->setup_subscription($_id_or_object); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
63 | 63 | * @since 1.0.0 |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
66 | + private function setup_subscription($id_or_object = 0) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
68 | + if (empty($id_or_object)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if (is_numeric($id_or_object)) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get($id_or_object); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif (is_object($id_or_object)) { |
|
77 | 77 | |
78 | 78 | $sub = $id_or_object; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
82 | + if (empty($sub)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
86 | + foreach ($sub as $key => $value) { |
|
87 | 87 | $this->$key = $value; |
88 | 88 | } |
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata($this->customer_id); |
|
91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
94 | 94 | |
95 | 95 | return $this; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @since 1.0.0 |
102 | 102 | */ |
103 | - public function __get( $key ) { |
|
103 | + public function __get($key) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if (method_exists($this, 'get_' . $key)) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func(array($this, 'get_' . $key)); |
|
108 | 108 | |
109 | 109 | } else { |
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param array $data Array of attributes for a subscription |
122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
123 | 123 | */ |
124 | - public function create( $data = array() ) { |
|
124 | + public function create($data = array()) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
126 | + if ($this->id != 0) { |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | 'profile_id' => '', |
143 | 143 | ); |
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args($data, $defaults); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
150 | 150 | |
151 | 151 | // Force an active subscription to expired if expiration date is in the past |
152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action('wpinv_subscription_pre_create', $args); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription($id); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | * @param array $args Array of fields to update |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public function update( $args = array() ) { |
|
174 | + public function update($args = array()) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update($this->id, $args); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
179 | 179 | |
180 | - if ( $ret && isset( $args['profile_id'] ) ) { |
|
181 | - update_post_meta( $this->parent_payment_id, 'subscription_id', $args['profile_id'] ); |
|
180 | + if ($ret && isset($args['profile_id'])) { |
|
181 | + update_post_meta($this->parent_payment_id, 'subscription_id', $args['profile_id']); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return $ret; |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return bool |
193 | 193 | */ |
194 | 194 | public function delete() { |
195 | - return $this->subs_db->delete( $this->id ); |
|
195 | + return $this->subs_db->delete($this->id); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | * @return array |
213 | 213 | */ |
214 | 214 | public function get_child_payments() { |
215 | - $payments = get_posts( array( |
|
215 | + $payments = get_posts(array( |
|
216 | 216 | 'post_parent' => (int) $this->parent_payment_id, |
217 | 217 | 'posts_per_page' => '999', |
218 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
218 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
219 | 219 | 'orderby' => 'ID', |
220 | 220 | 'order' => 'DESC', |
221 | 221 | 'post_type' => 'wpi_invoice' |
222 | - ) ); |
|
222 | + )); |
|
223 | 223 | |
224 | 224 | return $payments; |
225 | 225 | } |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function get_total_payments() { |
234 | 234 | $child_payments = $this->get_child_payments(); |
235 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
235 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
236 | 236 | |
237 | - if ( 'pending' != $this->status ) { |
|
237 | + if ('pending' != $this->status) { |
|
238 | 238 | $total_payments++; |
239 | 239 | } |
240 | 240 | |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | * @return int |
249 | 249 | */ |
250 | 250 | public function get_times_billed() { |
251 | - $times_billed = (int)$this->get_total_payments(); |
|
251 | + $times_billed = (int) $this->get_total_payments(); |
|
252 | 252 | |
253 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
253 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
254 | 254 | $times_billed--; |
255 | 255 | } |
256 | 256 | |
@@ -265,49 +265,49 @@ discard block |
||
265 | 265 | * @param WPInv_Invoice $invoice |
266 | 266 | * @return bool |
267 | 267 | */ |
268 | - public function add_payment( $args = array(), $invoice = false ) { |
|
268 | + public function add_payment($args = array(), $invoice = false) { |
|
269 | 269 | |
270 | 270 | // Process each payment once. |
271 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
271 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
275 | 275 | // Are we creating a new invoice? |
276 | - if ( empty( $invoice ) ) { |
|
276 | + if (empty($invoice)) { |
|
277 | 277 | $invoice = $this->create_payment(); |
278 | 278 | |
279 | - if ( empty( $invoice ) ) { |
|
279 | + if (empty($invoice)) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | - $invoice->set_status( 'wpi-renewal' ); |
|
283 | + $invoice->set_status('wpi-renewal'); |
|
284 | 284 | |
285 | 285 | } |
286 | 286 | |
287 | 287 | // Maybe set a transaction id. |
288 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
289 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
288 | + if (!empty($args['transaction_id'])) { |
|
289 | + $invoice->set_transaction_id($args['transaction_id']); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // Set the completed date. |
293 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
293 | + $invoice->set_completed_date(current_time('mysql')); |
|
294 | 294 | |
295 | 295 | // And the gateway. |
296 | - if ( ! empty( $args['gateway'] ) ) { |
|
297 | - $invoice->set_gateway( $args['gateway'] ); |
|
296 | + if (!empty($args['gateway'])) { |
|
297 | + $invoice->set_gateway($args['gateway']); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | $invoice->save(); |
301 | 301 | |
302 | - if ( ! $invoice->get_id() ) { |
|
302 | + if (!$invoice->get_id()) { |
|
303 | 303 | return 0; |
304 | 304 | } |
305 | 305 | |
306 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
307 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
308 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->parent_payment_id, $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
306 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
307 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
308 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->parent_payment_id, $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
309 | 309 | |
310 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
310 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
311 | 311 | |
312 | 312 | return $invoice->get_id(); |
313 | 313 | } |
@@ -322,26 +322,26 @@ discard block |
||
322 | 322 | public function create_payment() { |
323 | 323 | |
324 | 324 | // Do we have a parent invoice? |
325 | - if ( ! $this->parent_payment_id ) { |
|
325 | + if (!$this->parent_payment_id) { |
|
326 | 326 | return false; |
327 | 327 | } |
328 | 328 | |
329 | 329 | // Ensure that the parent invoice is available. |
330 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
331 | - if ( empty( $parent_invoice ) ) { |
|
330 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
331 | + if (empty($parent_invoice)) { |
|
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | |
335 | 335 | // Duplicate the parent invoice. |
336 | 336 | $invoice = new WPInv_Invoice(); |
337 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
338 | - $invoice->set_id( 0 ); |
|
339 | - $invoice->set_parent_id( $parent_invoice->get_parent() ); |
|
340 | - $invoice->set_transaction_id( '' ); |
|
341 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
342 | - $invoice->set_number( '' ); |
|
343 | - $invoice->set_completed_date( '' ); |
|
344 | - $invoice->set_status( 'wpi-pending' ); |
|
337 | + $invoice->set_props($parent_invoice->get_data()); |
|
338 | + $invoice->set_id(0); |
|
339 | + $invoice->set_parent_id($parent_invoice->get_parent()); |
|
340 | + $invoice->set_transaction_id(''); |
|
341 | + $invoice->set_key($invoice->generate_key('renewal_')); |
|
342 | + $invoice->set_number(''); |
|
343 | + $invoice->set_completed_date(''); |
|
344 | + $invoice->set_status('wpi-pending'); |
|
345 | 345 | $invoice->recalculate_total(); |
346 | 346 | $invoice->save(); |
347 | 347 | |
@@ -356,12 +356,12 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public function get_transaction_id() { |
358 | 358 | |
359 | - if( empty( $this->transaction_id ) ) { |
|
359 | + if (empty($this->transaction_id)) { |
|
360 | 360 | |
361 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
361 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
362 | 362 | |
363 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
364 | - $this->set_transaction_id( $txn_id ); |
|
363 | + if (!empty($txn_id) && (int) $this->parent_payment_id !== (int) $txn_id) { |
|
364 | + $this->set_transaction_id($txn_id); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | } |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | * @since 1.0.0.4 |
377 | 377 | * @return bool |
378 | 378 | */ |
379 | - public function set_transaction_id( $txn_id = '' ) { |
|
380 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
379 | + public function set_transaction_id($txn_id = '') { |
|
380 | + $this->update(array('transaction_id' => $txn_id)); |
|
381 | 381 | $this->transaction_id = $txn_id; |
382 | 382 | } |
383 | 383 | |
@@ -391,18 +391,18 @@ discard block |
||
391 | 391 | |
392 | 392 | // Calculate new expiration |
393 | 393 | $expires = $this->get_expiration_time(); |
394 | - $base_date = $expires > current_time( 'timestamp' ) ? $expires : current_time( 'timestamp' ); |
|
395 | - $frequency = isset( $this->frequency ) ? $this->frequency : 1; |
|
396 | - $new_expiration = strtotime( "+ {$frequency} {$this->period}", strtotime( $base_date ) ); |
|
397 | - $new_expiration = apply_filters( 'wpinv_subscription_renewal_expiration', date( 'Y-m-d H:i:s', $new_expiration ), $this->id, $this ); |
|
394 | + $base_date = $expires > current_time('timestamp') ? $expires : current_time('timestamp'); |
|
395 | + $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
396 | + $new_expiration = strtotime("+ {$frequency} {$this->period}", strtotime($base_date)); |
|
397 | + $new_expiration = apply_filters('wpinv_subscription_renewal_expiration', date('Y-m-d H:i:s', $new_expiration), $this->id, $this); |
|
398 | 398 | |
399 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $new_expiration, $this ); |
|
399 | + do_action('wpinv_subscription_pre_renew', $this->id, $new_expiration, $this); |
|
400 | 400 | |
401 | 401 | $this->status = 'active'; |
402 | 402 | $times_billed = $this->get_times_billed(); |
403 | 403 | |
404 | 404 | // Complete subscription if applicable |
405 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
405 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
406 | 406 | $this->complete(); |
407 | 407 | $this->status = 'completed'; |
408 | 408 | return; |
@@ -413,12 +413,12 @@ discard block |
||
413 | 413 | 'status' => $this->status, |
414 | 414 | ); |
415 | 415 | |
416 | - $this->subs_db->update( $this->id, $args ); |
|
416 | + $this->subs_db->update($this->id, $args); |
|
417 | 417 | |
418 | 418 | $this->expiration = $new_expiration; |
419 | 419 | |
420 | - do_action( 'wpinv_subscription_post_renew', $this->id, $new_expiration, $this ); |
|
421 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
420 | + do_action('wpinv_subscription_post_renew', $this->id, $new_expiration, $this); |
|
421 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | public function complete() { |
434 | 434 | |
435 | 435 | // Only mark a subscription as complete if it's not already cancelled. |
436 | - if ( 'cancelled' === $this->status ) { |
|
436 | + if ('cancelled' === $this->status) { |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
@@ -441,11 +441,11 @@ discard block |
||
441 | 441 | 'status' => 'completed' |
442 | 442 | ); |
443 | 443 | |
444 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
444 | + if ($this->subs_db->update($this->id, $args)) { |
|
445 | 445 | |
446 | 446 | $this->status = 'completed'; |
447 | 447 | |
448 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
448 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
449 | 449 | |
450 | 450 | } |
451 | 451 | |
@@ -460,15 +460,15 @@ discard block |
||
460 | 460 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
461 | 461 | * @return void |
462 | 462 | */ |
463 | - public function expire( $check_expiration = false ) { |
|
463 | + public function expire($check_expiration = false) { |
|
464 | 464 | |
465 | 465 | $expiration = $this->expiration; |
466 | 466 | |
467 | - if( $check_expiration ) { |
|
467 | + if ($check_expiration) { |
|
468 | 468 | |
469 | 469 | // check_expiration() updates $this->expiration so compare to $expiration above |
470 | 470 | |
471 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
471 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
472 | 472 | |
473 | 473 | return false; // Do not mark as expired since real expiration date is in the future |
474 | 474 | } |
@@ -479,11 +479,11 @@ discard block |
||
479 | 479 | 'status' => 'expired' |
480 | 480 | ); |
481 | 481 | |
482 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
482 | + if ($this->subs_db->update($this->id, $args)) { |
|
483 | 483 | |
484 | 484 | $this->status = 'expired'; |
485 | 485 | |
486 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
486 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
487 | 487 | |
488 | 488 | } |
489 | 489 | |
@@ -501,12 +501,12 @@ discard block |
||
501 | 501 | 'status' => 'failing' |
502 | 502 | ); |
503 | 503 | |
504 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
504 | + if ($this->subs_db->update($this->id, $args)) { |
|
505 | 505 | |
506 | 506 | $this->status = 'failing'; |
507 | 507 | |
508 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
509 | - do_action( 'wpinv_recurring_payment_failed', $this ); |
|
508 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
509 | + do_action('wpinv_recurring_payment_failed', $this); |
|
510 | 510 | |
511 | 511 | } |
512 | 512 | |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * @return void |
520 | 520 | */ |
521 | 521 | public function cancel() { |
522 | - if ( 'cancelled' === $this->status ) { |
|
522 | + if ('cancelled' === $this->status) { |
|
523 | 523 | return; // Already cancelled |
524 | 524 | } |
525 | 525 | |
@@ -527,20 +527,20 @@ discard block |
||
527 | 527 | 'status' => 'cancelled' |
528 | 528 | ); |
529 | 529 | |
530 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
531 | - if ( is_user_logged_in() ) { |
|
532 | - $userdata = get_userdata( get_current_user_id() ); |
|
530 | + if ($this->subs_db->update($this->id, $args)) { |
|
531 | + if (is_user_logged_in()) { |
|
532 | + $userdata = get_userdata(get_current_user_id()); |
|
533 | 533 | $user = $userdata->display_name; |
534 | 534 | } else { |
535 | - $user = __( 'gateway', 'invoicing' ); |
|
535 | + $user = __('gateway', 'invoicing'); |
|
536 | 536 | } |
537 | 537 | |
538 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $user ); |
|
539 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
538 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $user); |
|
539 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
540 | 540 | |
541 | 541 | $this->status = 'cancelled'; |
542 | 542 | |
543 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
543 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
544 | 544 | } |
545 | 545 | } |
546 | 546 | |
@@ -555,10 +555,10 @@ discard block |
||
555 | 555 | */ |
556 | 556 | public function can_cancel() { |
557 | 557 | $ret = false; |
558 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
558 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
559 | 559 | $ret = true; |
560 | 560 | } |
561 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
561 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | /** |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | * @return array |
570 | 570 | */ |
571 | 571 | public function get_cancellable_statuses() { |
572 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
572 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
@@ -580,9 +580,9 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function get_cancel_url() { |
582 | 582 | |
583 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
583 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
584 | 584 | |
585 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
585 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | */ |
597 | 597 | public function can_renew() { |
598 | 598 | |
599 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
599 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -607,9 +607,9 @@ discard block |
||
607 | 607 | */ |
608 | 608 | public function get_renew_url() { |
609 | 609 | |
610 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
610 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
611 | 611 | |
612 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
612 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | /** |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | * @return bool |
620 | 620 | */ |
621 | 621 | public function can_update() { |
622 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
622 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
@@ -630,9 +630,9 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public function get_update_url() { |
632 | 632 | |
633 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
633 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
634 | 634 | |
635 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
635 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -645,11 +645,11 @@ discard block |
||
645 | 645 | |
646 | 646 | $ret = false; |
647 | 647 | |
648 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
648 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
649 | 649 | $ret = true; |
650 | 650 | } |
651 | 651 | |
652 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
652 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
653 | 653 | |
654 | 654 | } |
655 | 655 | |
@@ -663,26 +663,26 @@ discard block |
||
663 | 663 | |
664 | 664 | $ret = false; |
665 | 665 | |
666 | - if ( $this->status == 'expired' ) { |
|
666 | + if ($this->status == 'expired') { |
|
667 | 667 | |
668 | 668 | $ret = true; |
669 | 669 | |
670 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
670 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
671 | 671 | |
672 | 672 | $ret = false; |
673 | 673 | $expiration = $this->get_expiration_time(); |
674 | 674 | |
675 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
675 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
676 | 676 | $ret = true; |
677 | 677 | |
678 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
678 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
679 | 679 | $this->expire(); |
680 | 680 | } |
681 | 681 | } |
682 | 682 | |
683 | 683 | } |
684 | 684 | |
685 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
685 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
686 | 686 | |
687 | 687 | } |
688 | 688 | |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | * @return int |
704 | 704 | */ |
705 | 705 | public function get_expiration_time() { |
706 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
706 | + return strtotime($this->expiration, current_time('timestamp')); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | /** |
@@ -727,37 +727,37 @@ discard block |
||
727 | 727 | */ |
728 | 728 | public function get_status_label() { |
729 | 729 | |
730 | - switch( $this->get_status() ) { |
|
730 | + switch ($this->get_status()) { |
|
731 | 731 | case 'active' : |
732 | - $status = __( 'Active', 'invoicing' ); |
|
732 | + $status = __('Active', 'invoicing'); |
|
733 | 733 | break; |
734 | 734 | |
735 | 735 | case 'cancelled' : |
736 | - $status = __( 'Cancelled', 'invoicing' ); |
|
736 | + $status = __('Cancelled', 'invoicing'); |
|
737 | 737 | break; |
738 | 738 | |
739 | 739 | case 'expired' : |
740 | - $status = __( 'Expired', 'invoicing' ); |
|
740 | + $status = __('Expired', 'invoicing'); |
|
741 | 741 | break; |
742 | 742 | |
743 | 743 | case 'pending' : |
744 | - $status = __( 'Pending', 'invoicing' ); |
|
744 | + $status = __('Pending', 'invoicing'); |
|
745 | 745 | break; |
746 | 746 | |
747 | 747 | case 'failing' : |
748 | - $status = __( 'Failing', 'invoicing' ); |
|
748 | + $status = __('Failing', 'invoicing'); |
|
749 | 749 | break; |
750 | 750 | |
751 | 751 | case 'trialling' : |
752 | - $status = __( 'Trialling', 'invoicing' ); |
|
752 | + $status = __('Trialling', 'invoicing'); |
|
753 | 753 | break; |
754 | 754 | |
755 | 755 | case 'completed' : |
756 | - $status = __( 'Completed', 'invoicing' ); |
|
756 | + $status = __('Completed', 'invoicing'); |
|
757 | 757 | break; |
758 | 758 | |
759 | 759 | default: |
760 | - $status = ucfirst( $this->get_status() ); |
|
760 | + $status = ucfirst($this->get_status()); |
|
761 | 761 | break; |
762 | 762 | } |
763 | 763 | |
@@ -772,51 +772,51 @@ discard block |
||
772 | 772 | */ |
773 | 773 | public function get_status_label_html() { |
774 | 774 | |
775 | - switch( $get_status = $this->get_status() ) { |
|
775 | + switch ($get_status = $this->get_status()) { |
|
776 | 776 | case 'active' : |
777 | - $status = __( 'Active', 'invoicing' ); |
|
777 | + $status = __('Active', 'invoicing'); |
|
778 | 778 | $class = 'label-info'; |
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'cancelled' : |
782 | - $status = __( 'Cancelled', 'invoicing' ); |
|
782 | + $status = __('Cancelled', 'invoicing'); |
|
783 | 783 | $class = 'label-danger'; |
784 | 784 | break; |
785 | 785 | |
786 | 786 | case 'expired' : |
787 | - $status = __( 'Expired', 'invoicing' ); |
|
787 | + $status = __('Expired', 'invoicing'); |
|
788 | 788 | $class = 'label-default'; |
789 | 789 | break; |
790 | 790 | |
791 | 791 | case 'pending' : |
792 | - $status = __( 'Pending', 'invoicing' ); |
|
792 | + $status = __('Pending', 'invoicing'); |
|
793 | 793 | $class = 'label-primary'; |
794 | 794 | break; |
795 | 795 | |
796 | 796 | case 'failing' : |
797 | - $status = __( 'Failing', 'invoicing' ); |
|
797 | + $status = __('Failing', 'invoicing'); |
|
798 | 798 | $class = 'label-danger'; |
799 | 799 | break; |
800 | 800 | |
801 | 801 | case 'trialling' : |
802 | - $status = __( 'Trialling', 'invoicing' ); |
|
802 | + $status = __('Trialling', 'invoicing'); |
|
803 | 803 | $class = 'label-info'; |
804 | 804 | break; |
805 | 805 | |
806 | 806 | case 'completed' : |
807 | - $status = __( 'Completed', 'invoicing' ); |
|
807 | + $status = __('Completed', 'invoicing'); |
|
808 | 808 | $class = 'label-success'; |
809 | 809 | break; |
810 | 810 | |
811 | 811 | default: |
812 | - $status = ucfirst( $this->get_status() ); |
|
812 | + $status = ucfirst($this->get_status()); |
|
813 | 813 | $class = 'label-default'; |
814 | 814 | break; |
815 | 815 | } |
816 | 816 | |
817 | 817 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
818 | 818 | |
819 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
819 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | /** |
@@ -826,9 +826,9 @@ discard block |
||
826 | 826 | * @param string $txn_id The transaction ID from the merchant processor |
827 | 827 | * @return bool |
828 | 828 | */ |
829 | - public function payment_exists( $txn_id = '' ) { |
|
830 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
831 | - return ! empty( $invoice_id ); |
|
829 | + public function payment_exists($txn_id = '') { |
|
830 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
831 | + return !empty($invoice_id); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | } |
@@ -13,582 +13,582 @@ |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's sandbox saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $sandbox_tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
141 | - |
|
142 | - // Register gateway. |
|
143 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
144 | - |
|
145 | - // Enable Subscriptions. |
|
146 | - if ( $this->supports( 'subscription' ) ) { |
|
147 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
148 | - } |
|
149 | - |
|
150 | - // Enable sandbox. |
|
151 | - if ( $this->supports( 'sandbox' ) ) { |
|
152 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
153 | - } |
|
154 | - |
|
155 | - // Gateway settings. |
|
156 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's sandbox saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $sandbox_tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
141 | + |
|
142 | + // Register gateway. |
|
143 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
144 | + |
|
145 | + // Enable Subscriptions. |
|
146 | + if ( $this->supports( 'subscription' ) ) { |
|
147 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
148 | + } |
|
149 | + |
|
150 | + // Enable sandbox. |
|
151 | + if ( $this->supports( 'sandbox' ) ) { |
|
152 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
153 | + } |
|
154 | + |
|
155 | + // Gateway settings. |
|
156 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
157 | 157 | |
158 | 158 | |
159 | - // Gateway checkout fiellds. |
|
160 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
161 | - |
|
162 | - // Process payment. |
|
163 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
164 | - |
|
165 | - // Change the checkout button text. |
|
166 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
167 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | - } |
|
169 | - |
|
170 | - // Check if a gateway is valid for a given currency. |
|
171 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
172 | - |
|
173 | - // Generate the transaction url. |
|
174 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
175 | - |
|
176 | - // Generate the subscription url. |
|
177 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
178 | - |
|
179 | - // Confirm payments. |
|
180 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
181 | - |
|
182 | - // Verify IPNs. |
|
183 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
184 | - |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Checks if this gateway is a given gateway. |
|
189 | - * |
|
190 | - * @since 1.0.19 |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function is( $gateway ) { |
|
194 | - return $gateway == $this->id; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Returns a users saved tokens for this gateway. |
|
199 | - * |
|
200 | - * @since 1.0.19 |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public function get_tokens() { |
|
204 | - |
|
205 | - if ( count( $this->tokens ) > 0 ) { |
|
206 | - return $this->tokens; |
|
207 | - } |
|
208 | - |
|
209 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) ) { |
|
210 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
211 | - |
|
212 | - if ( is_array( $tokens ) ) { |
|
213 | - $this->tokens = $tokens; |
|
214 | - } |
|
215 | - |
|
216 | - } |
|
217 | - |
|
218 | - return $this->tokens; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Saves a token for this gateway. |
|
223 | - * |
|
224 | - * @since 1.0.19 |
|
225 | - */ |
|
226 | - public function save_token( $token ) { |
|
227 | - |
|
228 | - $tokens = $this->get_tokens(); |
|
229 | - $tokens[] = $token; |
|
230 | - |
|
231 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
232 | - |
|
233 | - $this->tokens = $tokens; |
|
234 | - |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Return the title for admin screens. |
|
239 | - * |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function get_method_title() { |
|
243 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Return the description for admin screens. |
|
248 | - * |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_method_description() { |
|
252 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Get the success url. |
|
257 | - * |
|
258 | - * @param WPInv_Invoice $invoice Invoice object. |
|
259 | - * @return string |
|
260 | - */ |
|
261 | - public function get_return_url( $invoice ) { |
|
262 | - |
|
263 | - // Payment success url |
|
264 | - $return_url = add_query_arg( |
|
265 | - array( |
|
266 | - 'payment-confirm' => $this->id, |
|
267 | - 'invoice_key' => $invoice->get_key(), |
|
268 | - 'utm_nooverride' => 1 |
|
269 | - ), |
|
270 | - wpinv_get_success_page_uri() |
|
271 | - ); |
|
272 | - |
|
273 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Confirms payments when rendering the success page. |
|
278 | - * |
|
279 | - * @param string $content Success page content. |
|
280 | - * @return string |
|
281 | - */ |
|
282 | - public function get_confirm_payment( $content ) { |
|
159 | + // Gateway checkout fiellds. |
|
160 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
161 | + |
|
162 | + // Process payment. |
|
163 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
164 | + |
|
165 | + // Change the checkout button text. |
|
166 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
167 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | + } |
|
169 | + |
|
170 | + // Check if a gateway is valid for a given currency. |
|
171 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
172 | + |
|
173 | + // Generate the transaction url. |
|
174 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
175 | + |
|
176 | + // Generate the subscription url. |
|
177 | + add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
178 | + |
|
179 | + // Confirm payments. |
|
180 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
181 | + |
|
182 | + // Verify IPNs. |
|
183 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
184 | + |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Checks if this gateway is a given gateway. |
|
189 | + * |
|
190 | + * @since 1.0.19 |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function is( $gateway ) { |
|
194 | + return $gateway == $this->id; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Returns a users saved tokens for this gateway. |
|
199 | + * |
|
200 | + * @since 1.0.19 |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public function get_tokens() { |
|
204 | + |
|
205 | + if ( count( $this->tokens ) > 0 ) { |
|
206 | + return $this->tokens; |
|
207 | + } |
|
208 | + |
|
209 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) ) { |
|
210 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
211 | + |
|
212 | + if ( is_array( $tokens ) ) { |
|
213 | + $this->tokens = $tokens; |
|
214 | + } |
|
215 | + |
|
216 | + } |
|
217 | + |
|
218 | + return $this->tokens; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Saves a token for this gateway. |
|
223 | + * |
|
224 | + * @since 1.0.19 |
|
225 | + */ |
|
226 | + public function save_token( $token ) { |
|
227 | + |
|
228 | + $tokens = $this->get_tokens(); |
|
229 | + $tokens[] = $token; |
|
230 | + |
|
231 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
232 | + |
|
233 | + $this->tokens = $tokens; |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Return the title for admin screens. |
|
239 | + * |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function get_method_title() { |
|
243 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Return the description for admin screens. |
|
248 | + * |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_method_description() { |
|
252 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Get the success url. |
|
257 | + * |
|
258 | + * @param WPInv_Invoice $invoice Invoice object. |
|
259 | + * @return string |
|
260 | + */ |
|
261 | + public function get_return_url( $invoice ) { |
|
262 | + |
|
263 | + // Payment success url |
|
264 | + $return_url = add_query_arg( |
|
265 | + array( |
|
266 | + 'payment-confirm' => $this->id, |
|
267 | + 'invoice_key' => $invoice->get_key(), |
|
268 | + 'utm_nooverride' => 1 |
|
269 | + ), |
|
270 | + wpinv_get_success_page_uri() |
|
271 | + ); |
|
272 | + |
|
273 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Confirms payments when rendering the success page. |
|
278 | + * |
|
279 | + * @param string $content Success page content. |
|
280 | + * @return string |
|
281 | + */ |
|
282 | + public function get_confirm_payment( $content ) { |
|
283 | 283 | |
284 | - // Retrieve the invoice. |
|
285 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
286 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
284 | + // Retrieve the invoice. |
|
285 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
286 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
287 | 287 | |
288 | - // Ensure that it exists and that it is pending payment. |
|
289 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
290 | - return $content; |
|
291 | - } |
|
288 | + // Ensure that it exists and that it is pending payment. |
|
289 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
290 | + return $content; |
|
291 | + } |
|
292 | 292 | |
293 | - // Can the user view this invoice?? |
|
294 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
295 | - return $content; |
|
296 | - } |
|
293 | + // Can the user view this invoice?? |
|
294 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
295 | + return $content; |
|
296 | + } |
|
297 | 297 | |
298 | - // Show payment processing indicator. |
|
299 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Processes ipns and marks payments as complete. |
|
304 | - * |
|
305 | - * @return void |
|
306 | - */ |
|
307 | - public function verify_ipn() {} |
|
308 | - |
|
309 | - /** |
|
310 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
311 | - * |
|
312 | - * @param string $transaction_url transaction url. |
|
313 | - * @param WPInv_Invoice $invoice Invoice object. |
|
314 | - * @return string transaction URL, or empty string. |
|
315 | - */ |
|
316 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
317 | - |
|
318 | - $transaction_id = $invoice->get_transaction_id(); |
|
319 | - |
|
320 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
321 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
322 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
323 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
324 | - } |
|
325 | - |
|
326 | - return $transaction_url; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
331 | - * |
|
332 | - * @param string $subscription_url transaction url. |
|
333 | - * @param WPInv_Invoice $invoice Invoice object. |
|
334 | - * @return string subscription URL, or empty string. |
|
335 | - */ |
|
336 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
337 | - |
|
338 | - $profile_id = $invoice->get_subscription_id(); |
|
339 | - |
|
340 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
341 | - |
|
342 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
343 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
344 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
345 | - |
|
346 | - } |
|
347 | - |
|
348 | - return $subscription_url; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Check if the gateway is available for use. |
|
353 | - * |
|
354 | - * @return bool |
|
355 | - */ |
|
356 | - public function is_available() { |
|
357 | - return ! empty( $this->enabled ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Return the gateway's title. |
|
362 | - * |
|
363 | - * @return string |
|
364 | - */ |
|
365 | - public function get_title() { |
|
366 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Return the gateway's description. |
|
371 | - * |
|
372 | - * @return string |
|
373 | - */ |
|
374 | - public function get_description() { |
|
375 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Process Payment. |
|
380 | - * |
|
381 | - * |
|
382 | - * @param WPInv_Invoice $invoice Invoice. |
|
383 | - * @param array $submission_data Posted checkout fields. |
|
384 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
385 | - * @return void |
|
386 | - */ |
|
387 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
388 | - // Process the payment then either redirect to the success page or the gateway. |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Process refund. |
|
393 | - * |
|
394 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
395 | - * a passed in amount. |
|
396 | - * |
|
397 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | - * @param float $amount Refund amount. |
|
399 | - * @param string $reason Refund reason. |
|
400 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
401 | - */ |
|
402 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
403 | - return false; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Displays the payment fields, credit cards etc. |
|
408 | - * |
|
409 | - * @param int $invoice_id 0 or invoice id. |
|
410 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
411 | - */ |
|
412 | - public function payment_fields( $invoice_id, $form ) {} |
|
413 | - |
|
414 | - /** |
|
415 | - * Filters the gateway settings. |
|
416 | - * |
|
417 | - * @param array $admin_settings |
|
418 | - */ |
|
419 | - public function admin_settings( $admin_settings ) { |
|
420 | - return $admin_settings; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Retrieves the value of a gateway setting. |
|
425 | - * |
|
426 | - * @param string $option |
|
427 | - */ |
|
428 | - public function get_option( $option, $default = false ) { |
|
429 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Check if a gateway supports a given feature. |
|
434 | - * |
|
435 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
436 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
437 | - * |
|
438 | - * @param string $feature string The name of a feature to test support for. |
|
439 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
440 | - * @since 1.0.19 |
|
441 | - */ |
|
442 | - public function supports( $feature ) { |
|
443 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Grab and display our saved payment methods. |
|
448 | - * |
|
449 | - * @since 1.0.19 |
|
450 | - */ |
|
451 | - public function saved_payment_methods() { |
|
452 | - $html = '<ul class="getpaid-saved-payment-methods" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '">'; |
|
453 | - |
|
454 | - foreach ( $this->get_tokens() as $token ) { |
|
455 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
456 | - } |
|
457 | - |
|
458 | - $html .= $this->get_new_payment_method_option_html(); |
|
459 | - $html .= '</ul>'; |
|
460 | - |
|
461 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Gets saved payment method HTML from a token. |
|
466 | - * |
|
467 | - * @since 1.0.19 |
|
468 | - * @param array $token Payment Token. |
|
469 | - * @return string Generated payment method HTML |
|
470 | - */ |
|
471 | - public function get_saved_payment_method_option_html( $token ) { |
|
472 | - |
|
473 | - return sprintf( |
|
474 | - '<li class="getpaid-payment-method form-group"> |
|
298 | + // Show payment processing indicator. |
|
299 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Processes ipns and marks payments as complete. |
|
304 | + * |
|
305 | + * @return void |
|
306 | + */ |
|
307 | + public function verify_ipn() {} |
|
308 | + |
|
309 | + /** |
|
310 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
311 | + * |
|
312 | + * @param string $transaction_url transaction url. |
|
313 | + * @param WPInv_Invoice $invoice Invoice object. |
|
314 | + * @return string transaction URL, or empty string. |
|
315 | + */ |
|
316 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
317 | + |
|
318 | + $transaction_id = $invoice->get_transaction_id(); |
|
319 | + |
|
320 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
321 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
322 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
323 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
324 | + } |
|
325 | + |
|
326 | + return $transaction_url; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
331 | + * |
|
332 | + * @param string $subscription_url transaction url. |
|
333 | + * @param WPInv_Invoice $invoice Invoice object. |
|
334 | + * @return string subscription URL, or empty string. |
|
335 | + */ |
|
336 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
337 | + |
|
338 | + $profile_id = $invoice->get_subscription_id(); |
|
339 | + |
|
340 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
341 | + |
|
342 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
343 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
344 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
345 | + |
|
346 | + } |
|
347 | + |
|
348 | + return $subscription_url; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Check if the gateway is available for use. |
|
353 | + * |
|
354 | + * @return bool |
|
355 | + */ |
|
356 | + public function is_available() { |
|
357 | + return ! empty( $this->enabled ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Return the gateway's title. |
|
362 | + * |
|
363 | + * @return string |
|
364 | + */ |
|
365 | + public function get_title() { |
|
366 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Return the gateway's description. |
|
371 | + * |
|
372 | + * @return string |
|
373 | + */ |
|
374 | + public function get_description() { |
|
375 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Process Payment. |
|
380 | + * |
|
381 | + * |
|
382 | + * @param WPInv_Invoice $invoice Invoice. |
|
383 | + * @param array $submission_data Posted checkout fields. |
|
384 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
385 | + * @return void |
|
386 | + */ |
|
387 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
388 | + // Process the payment then either redirect to the success page or the gateway. |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Process refund. |
|
393 | + * |
|
394 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
395 | + * a passed in amount. |
|
396 | + * |
|
397 | + * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param float $amount Refund amount. |
|
399 | + * @param string $reason Refund reason. |
|
400 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
401 | + */ |
|
402 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
403 | + return false; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Displays the payment fields, credit cards etc. |
|
408 | + * |
|
409 | + * @param int $invoice_id 0 or invoice id. |
|
410 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
411 | + */ |
|
412 | + public function payment_fields( $invoice_id, $form ) {} |
|
413 | + |
|
414 | + /** |
|
415 | + * Filters the gateway settings. |
|
416 | + * |
|
417 | + * @param array $admin_settings |
|
418 | + */ |
|
419 | + public function admin_settings( $admin_settings ) { |
|
420 | + return $admin_settings; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Retrieves the value of a gateway setting. |
|
425 | + * |
|
426 | + * @param string $option |
|
427 | + */ |
|
428 | + public function get_option( $option, $default = false ) { |
|
429 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Check if a gateway supports a given feature. |
|
434 | + * |
|
435 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
436 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
437 | + * |
|
438 | + * @param string $feature string The name of a feature to test support for. |
|
439 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
440 | + * @since 1.0.19 |
|
441 | + */ |
|
442 | + public function supports( $feature ) { |
|
443 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Grab and display our saved payment methods. |
|
448 | + * |
|
449 | + * @since 1.0.19 |
|
450 | + */ |
|
451 | + public function saved_payment_methods() { |
|
452 | + $html = '<ul class="getpaid-saved-payment-methods" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '">'; |
|
453 | + |
|
454 | + foreach ( $this->get_tokens() as $token ) { |
|
455 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
456 | + } |
|
457 | + |
|
458 | + $html .= $this->get_new_payment_method_option_html(); |
|
459 | + $html .= '</ul>'; |
|
460 | + |
|
461 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Gets saved payment method HTML from a token. |
|
466 | + * |
|
467 | + * @since 1.0.19 |
|
468 | + * @param array $token Payment Token. |
|
469 | + * @return string Generated payment method HTML |
|
470 | + */ |
|
471 | + public function get_saved_payment_method_option_html( $token ) { |
|
472 | + |
|
473 | + return sprintf( |
|
474 | + '<li class="getpaid-payment-method form-group"> |
|
475 | 475 | <label> |
476 | 476 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
477 | 477 | <span>%3$s</span> |
478 | 478 | </label> |
479 | 479 | </li>', |
480 | - esc_attr( $this->id ), |
|
481 | - esc_attr( $token['id'] ), |
|
482 | - esc_html( $token['name'] ), |
|
483 | - checked( empty( $token['default'] ), false, false ) |
|
484 | - ); |
|
480 | + esc_attr( $this->id ), |
|
481 | + esc_attr( $token['id'] ), |
|
482 | + esc_html( $token['name'] ), |
|
483 | + checked( empty( $token['default'] ), false, false ) |
|
484 | + ); |
|
485 | 485 | |
486 | - } |
|
486 | + } |
|
487 | 487 | |
488 | - /** |
|
489 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
490 | - * |
|
491 | - * @since 1.0.19 |
|
492 | - */ |
|
493 | - public function get_new_payment_method_option_html() { |
|
488 | + /** |
|
489 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
490 | + * |
|
491 | + * @since 1.0.19 |
|
492 | + */ |
|
493 | + public function get_new_payment_method_option_html() { |
|
494 | 494 | |
495 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
495 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
496 | 496 | |
497 | - return sprintf( |
|
498 | - '<li class="getpaid-new-payment-method"> |
|
497 | + return sprintf( |
|
498 | + '<li class="getpaid-new-payment-method"> |
|
499 | 499 | <label> |
500 | 500 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
501 | 501 | <span>%2$s</span> |
502 | 502 | </label> |
503 | 503 | </li>', |
504 | - esc_attr( $this->id ), |
|
505 | - esc_html( $label ) |
|
506 | - ); |
|
504 | + esc_attr( $this->id ), |
|
505 | + esc_html( $label ) |
|
506 | + ); |
|
507 | 507 | |
508 | - } |
|
508 | + } |
|
509 | 509 | |
510 | - /** |
|
511 | - * Outputs a checkbox for saving a new payment method to the database. |
|
512 | - * |
|
513 | - * @since 1.0.19 |
|
514 | - */ |
|
515 | - public function save_payment_method_checkbox() { |
|
510 | + /** |
|
511 | + * Outputs a checkbox for saving a new payment method to the database. |
|
512 | + * |
|
513 | + * @since 1.0.19 |
|
514 | + */ |
|
515 | + public function save_payment_method_checkbox() { |
|
516 | 516 | |
517 | - return sprintf( |
|
518 | - '<p class="form-group getpaid-save-payment-method"> |
|
517 | + return sprintf( |
|
518 | + '<p class="form-group getpaid-save-payment-method"> |
|
519 | 519 | <label> |
520 | 520 | <input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
521 | 521 | <span>%2$s</span> |
522 | 522 | </label> |
523 | 523 | </p>', |
524 | - esc_attr( $this->id ), |
|
525 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
526 | - ); |
|
524 | + esc_attr( $this->id ), |
|
525 | + esc_html__( 'Save payment method', 'invoicing' ) |
|
526 | + ); |
|
527 | 527 | |
528 | - } |
|
528 | + } |
|
529 | 529 | |
530 | - /** |
|
531 | - * Registers the gateway. |
|
532 | - * |
|
533 | - * @return array |
|
534 | - */ |
|
535 | - public function register_gateway( $gateways ) { |
|
530 | + /** |
|
531 | + * Registers the gateway. |
|
532 | + * |
|
533 | + * @return array |
|
534 | + */ |
|
535 | + public function register_gateway( $gateways ) { |
|
536 | 536 | |
537 | - $gateways[ $this->id ] = array( |
|
537 | + $gateways[ $this->id ] = array( |
|
538 | 538 | |
539 | - 'admin_label' => $this->method_title, |
|
539 | + 'admin_label' => $this->method_title, |
|
540 | 540 | 'checkout_label' => $this->title, |
541 | - 'ordering' => $this->order, |
|
542 | - |
|
543 | - ); |
|
544 | - |
|
545 | - return $gateways; |
|
546 | - |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * Checks whether or not this is a sandbox request. |
|
551 | - * |
|
552 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
553 | - * @return bool |
|
554 | - */ |
|
555 | - public function is_sandbox( $invoice = null ) { |
|
556 | - |
|
557 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
558 | - return $invoice->get_mode() == 'test'; |
|
559 | - } |
|
560 | - |
|
561 | - return wpinv_is_test_mode( $this->id ); |
|
562 | - |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Renames the checkout button |
|
567 | - * |
|
568 | - * @return string |
|
569 | - */ |
|
570 | - public function rename_checkout_button() { |
|
571 | - return $this->checkout_button_text; |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Validate gateway currency |
|
576 | - * |
|
577 | - * @return bool |
|
578 | - */ |
|
579 | - public function validate_currency( $validation, $currency ) { |
|
580 | - |
|
581 | - // Required currencies. |
|
582 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
583 | - return false; |
|
584 | - } |
|
585 | - |
|
586 | - // Excluded currencies. |
|
587 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
588 | - return false; |
|
589 | - } |
|
590 | - |
|
591 | - return $validation; |
|
592 | - } |
|
541 | + 'ordering' => $this->order, |
|
542 | + |
|
543 | + ); |
|
544 | + |
|
545 | + return $gateways; |
|
546 | + |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * Checks whether or not this is a sandbox request. |
|
551 | + * |
|
552 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
553 | + * @return bool |
|
554 | + */ |
|
555 | + public function is_sandbox( $invoice = null ) { |
|
556 | + |
|
557 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
558 | + return $invoice->get_mode() == 'test'; |
|
559 | + } |
|
560 | + |
|
561 | + return wpinv_is_test_mode( $this->id ); |
|
562 | + |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Renames the checkout button |
|
567 | + * |
|
568 | + * @return string |
|
569 | + */ |
|
570 | + public function rename_checkout_button() { |
|
571 | + return $this->checkout_button_text; |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Validate gateway currency |
|
576 | + * |
|
577 | + * @return bool |
|
578 | + */ |
|
579 | + public function validate_currency( $validation, $currency ) { |
|
580 | + |
|
581 | + // Required currencies. |
|
582 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
583 | + return false; |
|
584 | + } |
|
585 | + |
|
586 | + // Excluded currencies. |
|
587 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
588 | + return false; |
|
589 | + } |
|
590 | + |
|
591 | + return $validation; |
|
592 | + } |
|
593 | 593 | |
594 | 594 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Abstaract Payment Gateway class. |
@@ -137,50 +137,50 @@ discard block |
||
137 | 137 | * Class constructor. |
138 | 138 | */ |
139 | 139 | public function __construct() { |
140 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
140 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
141 | 141 | |
142 | 142 | // Register gateway. |
143 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
144 | 144 | |
145 | 145 | // Enable Subscriptions. |
146 | - if ( $this->supports( 'subscription' ) ) { |
|
147 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
146 | + if ($this->supports('subscription')) { |
|
147 | + add_filter("wpinv_{$this->id}_support_subscription", '__return_true'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | // Enable sandbox. |
151 | - if ( $this->supports( 'sandbox' ) ) { |
|
152 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
151 | + if ($this->supports('sandbox')) { |
|
152 | + add_filter("wpinv_{$this->id}_supports_sandbox", '__return_true'); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | // Gateway settings. |
156 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
156 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
157 | 157 | |
158 | 158 | |
159 | 159 | // Gateway checkout fiellds. |
160 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
160 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
161 | 161 | |
162 | 162 | // Process payment. |
163 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
163 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
164 | 164 | |
165 | 165 | // Change the checkout button text. |
166 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
167 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
166 | + if (!empty($this->checkout_button_text)) { |
|
167 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | // Check if a gateway is valid for a given currency. |
171 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
171 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
172 | 172 | |
173 | 173 | // Generate the transaction url. |
174 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
174 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
175 | 175 | |
176 | 176 | // Generate the subscription url. |
177 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
177 | + add_filter("getpaid_gateway_{$this->id}_subscription_url", array($this, 'filter_subscription_url'), 10, 2); |
|
178 | 178 | |
179 | 179 | // Confirm payments. |
180 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
180 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
181 | 181 | |
182 | 182 | // Verify IPNs. |
183 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
183 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
184 | 184 | |
185 | 185 | } |
186 | 186 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @since 1.0.19 |
191 | 191 | * @return bool |
192 | 192 | */ |
193 | - public function is( $gateway ) { |
|
193 | + public function is($gateway) { |
|
194 | 194 | return $gateway == $this->id; |
195 | 195 | } |
196 | 196 | |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function get_tokens() { |
204 | 204 | |
205 | - if ( count( $this->tokens ) > 0 ) { |
|
205 | + if (count($this->tokens) > 0) { |
|
206 | 206 | return $this->tokens; |
207 | 207 | } |
208 | 208 | |
209 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) ) { |
|
210 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | + if (is_user_logged_in() && $this->supports('tokens')) { |
|
210 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
211 | 211 | |
212 | - if ( is_array( $tokens ) ) { |
|
212 | + if (is_array($tokens)) { |
|
213 | 213 | $this->tokens = $tokens; |
214 | 214 | } |
215 | 215 | |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @since 1.0.19 |
225 | 225 | */ |
226 | - public function save_token( $token ) { |
|
226 | + public function save_token($token) { |
|
227 | 227 | |
228 | 228 | $tokens = $this->get_tokens(); |
229 | 229 | $tokens[] = $token; |
230 | 230 | |
231 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
231 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
232 | 232 | |
233 | 233 | $this->tokens = $tokens; |
234 | 234 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @return string |
241 | 241 | */ |
242 | 242 | public function get_method_title() { |
243 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
243 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @return string |
250 | 250 | */ |
251 | 251 | public function get_method_description() { |
252 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
252 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @param WPInv_Invoice $invoice Invoice object. |
259 | 259 | * @return string |
260 | 260 | */ |
261 | - public function get_return_url( $invoice ) { |
|
261 | + public function get_return_url($invoice) { |
|
262 | 262 | |
263 | 263 | // Payment success url |
264 | 264 | $return_url = add_query_arg( |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | wpinv_get_success_page_uri() |
271 | 271 | ); |
272 | 272 | |
273 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
273 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -279,24 +279,24 @@ discard block |
||
279 | 279 | * @param string $content Success page content. |
280 | 280 | * @return string |
281 | 281 | */ |
282 | - public function get_confirm_payment( $content ) { |
|
282 | + public function get_confirm_payment($content) { |
|
283 | 283 | |
284 | 284 | // Retrieve the invoice. |
285 | 285 | $invoice_id = getpaid_get_current_invoice_id(); |
286 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
286 | + $invoice = wpinv_get_invoice($invoice_id); |
|
287 | 287 | |
288 | 288 | // Ensure that it exists and that it is pending payment. |
289 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
289 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
290 | 290 | return $content; |
291 | 291 | } |
292 | 292 | |
293 | 293 | // Can the user view this invoice?? |
294 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
294 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
295 | 295 | return $content; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Show payment processing indicator. |
299 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
299 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -313,14 +313,14 @@ discard block |
||
313 | 313 | * @param WPInv_Invoice $invoice Invoice object. |
314 | 314 | * @return string transaction URL, or empty string. |
315 | 315 | */ |
316 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
316 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
317 | 317 | |
318 | - $transaction_id = $invoice->get_transaction_id(); |
|
318 | + $transaction_id = $invoice->get_transaction_id(); |
|
319 | 319 | |
320 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
321 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
322 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
323 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
320 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
321 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
322 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
323 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | return $transaction_url; |
@@ -333,15 +333,15 @@ discard block |
||
333 | 333 | * @param WPInv_Invoice $invoice Invoice object. |
334 | 334 | * @return string subscription URL, or empty string. |
335 | 335 | */ |
336 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
336 | + public function filter_subscription_url($subscription_url, $invoice) { |
|
337 | 337 | |
338 | - $profile_id = $invoice->get_subscription_id(); |
|
338 | + $profile_id = $invoice->get_subscription_id(); |
|
339 | 339 | |
340 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
340 | + if (!empty($this->view_subscription_url) && !empty($profile_id)) { |
|
341 | 341 | |
342 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
343 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
344 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
342 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
343 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
344 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
345 | 345 | |
346 | 346 | } |
347 | 347 | |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * @return bool |
355 | 355 | */ |
356 | 356 | public function is_available() { |
357 | - return ! empty( $this->enabled ); |
|
357 | + return !empty($this->enabled); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * @return string |
364 | 364 | */ |
365 | 365 | public function get_title() { |
366 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
366 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | * @return string |
373 | 373 | */ |
374 | 374 | public function get_description() { |
375 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
375 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
385 | 385 | * @return void |
386 | 386 | */ |
387 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
387 | + public function process_payment($invoice, $submission_data, $submission) { |
|
388 | 388 | // Process the payment then either redirect to the success page or the gateway. |
389 | 389 | } |
390 | 390 | |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * @param string $reason Refund reason. |
400 | 400 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
401 | 401 | */ |
402 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
402 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
403 | 403 | return false; |
404 | 404 | } |
405 | 405 | |
@@ -409,14 +409,14 @@ discard block |
||
409 | 409 | * @param int $invoice_id 0 or invoice id. |
410 | 410 | * @param GetPaid_Payment_Form $form Current payment form. |
411 | 411 | */ |
412 | - public function payment_fields( $invoice_id, $form ) {} |
|
412 | + public function payment_fields($invoice_id, $form) {} |
|
413 | 413 | |
414 | 414 | /** |
415 | 415 | * Filters the gateway settings. |
416 | 416 | * |
417 | 417 | * @param array $admin_settings |
418 | 418 | */ |
419 | - public function admin_settings( $admin_settings ) { |
|
419 | + public function admin_settings($admin_settings) { |
|
420 | 420 | return $admin_settings; |
421 | 421 | } |
422 | 422 | |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | * |
426 | 426 | * @param string $option |
427 | 427 | */ |
428 | - public function get_option( $option, $default = false ) { |
|
429 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
428 | + public function get_option($option, $default = false) { |
|
429 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -439,8 +439,8 @@ discard block |
||
439 | 439 | * @return bool True if the gateway supports the feature, false otherwise. |
440 | 440 | * @since 1.0.19 |
441 | 441 | */ |
442 | - public function supports( $feature ) { |
|
443 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
442 | + public function supports($feature) { |
|
443 | + return apply_filters('getpaid_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -449,16 +449,16 @@ discard block |
||
449 | 449 | * @since 1.0.19 |
450 | 450 | */ |
451 | 451 | public function saved_payment_methods() { |
452 | - $html = '<ul class="getpaid-saved-payment-methods" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '">'; |
|
452 | + $html = '<ul class="getpaid-saved-payment-methods" data-count="' . esc_attr(count($this->get_tokens())) . '">'; |
|
453 | 453 | |
454 | - foreach ( $this->get_tokens() as $token ) { |
|
455 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
454 | + foreach ($this->get_tokens() as $token) { |
|
455 | + $html .= $this->get_saved_payment_method_option_html($token); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | $html .= $this->get_new_payment_method_option_html(); |
459 | 459 | $html .= '</ul>'; |
460 | 460 | |
461 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
461 | + echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @param array $token Payment Token. |
469 | 469 | * @return string Generated payment method HTML |
470 | 470 | */ |
471 | - public function get_saved_payment_method_option_html( $token ) { |
|
471 | + public function get_saved_payment_method_option_html($token) { |
|
472 | 472 | |
473 | 473 | return sprintf( |
474 | 474 | '<li class="getpaid-payment-method form-group"> |
@@ -477,10 +477,10 @@ discard block |
||
477 | 477 | <span>%3$s</span> |
478 | 478 | </label> |
479 | 479 | </li>', |
480 | - esc_attr( $this->id ), |
|
481 | - esc_attr( $token['id'] ), |
|
482 | - esc_html( $token['name'] ), |
|
483 | - checked( empty( $token['default'] ), false, false ) |
|
480 | + esc_attr($this->id), |
|
481 | + esc_attr($token['id']), |
|
482 | + esc_html($token['name']), |
|
483 | + checked(empty($token['default']), false, false) |
|
484 | 484 | ); |
485 | 485 | |
486 | 486 | } |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | */ |
493 | 493 | public function get_new_payment_method_option_html() { |
494 | 494 | |
495 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
495 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
496 | 496 | |
497 | 497 | return sprintf( |
498 | 498 | '<li class="getpaid-new-payment-method"> |
@@ -501,8 +501,8 @@ discard block |
||
501 | 501 | <span>%2$s</span> |
502 | 502 | </label> |
503 | 503 | </li>', |
504 | - esc_attr( $this->id ), |
|
505 | - esc_html( $label ) |
|
504 | + esc_attr($this->id), |
|
505 | + esc_html($label) |
|
506 | 506 | ); |
507 | 507 | |
508 | 508 | } |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | <span>%2$s</span> |
522 | 522 | </label> |
523 | 523 | </p>', |
524 | - esc_attr( $this->id ), |
|
525 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
524 | + esc_attr($this->id), |
|
525 | + esc_html__('Save payment method', 'invoicing') |
|
526 | 526 | ); |
527 | 527 | |
528 | 528 | } |
@@ -532,9 +532,9 @@ discard block |
||
532 | 532 | * |
533 | 533 | * @return array |
534 | 534 | */ |
535 | - public function register_gateway( $gateways ) { |
|
535 | + public function register_gateway($gateways) { |
|
536 | 536 | |
537 | - $gateways[ $this->id ] = array( |
|
537 | + $gateways[$this->id] = array( |
|
538 | 538 | |
539 | 539 | 'admin_label' => $this->method_title, |
540 | 540 | 'checkout_label' => $this->title, |
@@ -552,13 +552,13 @@ discard block |
||
552 | 552 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
553 | 553 | * @return bool |
554 | 554 | */ |
555 | - public function is_sandbox( $invoice = null ) { |
|
555 | + public function is_sandbox($invoice = null) { |
|
556 | 556 | |
557 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
557 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
558 | 558 | return $invoice->get_mode() == 'test'; |
559 | 559 | } |
560 | 560 | |
561 | - return wpinv_is_test_mode( $this->id ); |
|
561 | + return wpinv_is_test_mode($this->id); |
|
562 | 562 | |
563 | 563 | } |
564 | 564 | |
@@ -576,15 +576,15 @@ discard block |
||
576 | 576 | * |
577 | 577 | * @return bool |
578 | 578 | */ |
579 | - public function validate_currency( $validation, $currency ) { |
|
579 | + public function validate_currency($validation, $currency) { |
|
580 | 580 | |
581 | 581 | // Required currencies. |
582 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
582 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
583 | 583 | return false; |
584 | 584 | } |
585 | 585 | |
586 | 586 | // Excluded currencies. |
587 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
587 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
588 | 588 | return false; |
589 | 589 | } |
590 | 590 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription' ); |
|
27 | + protected $supports = array('subscription'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Manual Payment', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Manual Payment', 'invoicing' ); |
|
42 | + $this->title = __('Manual Payment', 'invoicing'); |
|
43 | + $this->method_title = __('Manual Payment', 'invoicing'); |
|
44 | 44 | |
45 | - add_action( 'wpinv_renew_manual_subscription_profile', array( $this, 'renew_manual_subscription_profile' ) ); |
|
45 | + add_action('wpinv_renew_manual_subscription_profile', array($this, 'renew_manual_subscription_profile')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,16 +54,16 @@ discard block |
||
54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
61 | 61 | |
62 | 62 | // (Maybe) set recurring hooks. |
63 | - $this->start_manual_subscription_profile( $invoice ); |
|
63 | + $this->start_manual_subscription_profile($invoice); |
|
64 | 64 | |
65 | 65 | // Send to the success page. |
66 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
66 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
@@ -73,19 +73,19 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @param WPInv_Invoice $invoice Invoice. |
75 | 75 | */ |
76 | - public function start_manual_subscription_profile( $invoice ) { |
|
76 | + public function start_manual_subscription_profile($invoice) { |
|
77 | 77 | |
78 | 78 | // Retrieve the subscription. |
79 | - $subscription = wpinv_get_subscription( $invoice ); |
|
80 | - if ( empty( $subscription ) ) { |
|
79 | + $subscription = wpinv_get_subscription($invoice); |
|
80 | + if (empty($subscription)) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // Schedule an action to run when the subscription expires. |
85 | 85 | $action_id = as_schedule_single_action( |
86 | - strtotime( $subscription->expiration ), |
|
86 | + strtotime($subscription->expiration), |
|
87 | 87 | 'wpinv_renew_manual_subscription_profile', |
88 | - array( $invoice->get_id() ), |
|
88 | + array($invoice->get_id()), |
|
89 | 89 | 'invoicing' |
90 | 90 | ); |
91 | 91 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @param int $invoice_id Invoice. |
107 | 107 | */ |
108 | - public function renew_manual_subscription_profile( $invoice_id ) { |
|
108 | + public function renew_manual_subscription_profile($invoice_id) { |
|
109 | 109 | |
110 | 110 | // Retrieve the subscription. |
111 | - $subscription = wpinv_get_subscription( $invoice_id ); |
|
112 | - if ( empty( $subscription ) ) { |
|
111 | + $subscription = wpinv_get_subscription($invoice_id); |
|
112 | + if (empty($subscription)) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Abort if it is canceled or complete. |
117 | - if ( $subscription->status == 'completed' || $subscription->status == 'cancelled' ) { |
|
117 | + if ($subscription->status == 'completed' || $subscription->status == 'cancelled') { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
@@ -122,34 +122,34 @@ discard block |
||
122 | 122 | $times_billed = $subscription->get_times_billed(); |
123 | 123 | $max_bills = $subscription->bill_times; |
124 | 124 | |
125 | - if ( empty( $max_bills ) || $max_bills > $times_billed ) { |
|
125 | + if (empty($max_bills) || $max_bills > $times_billed) { |
|
126 | 126 | |
127 | 127 | // Retrieve the invoice. |
128 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
128 | + $invoice = new WPInv_Invoice($invoice_id); |
|
129 | 129 | |
130 | 130 | // Renew the subscription. |
131 | - $subscription->add_payment( array( |
|
131 | + $subscription->add_payment(array( |
|
132 | 132 | 'amount' => $subscription->recurring_amount, |
133 | 133 | 'transaction_id' => $invoice->generate_key(), |
134 | 134 | 'gateway' => $this->id |
135 | - ) ); |
|
135 | + )); |
|
136 | 136 | |
137 | 137 | } |
138 | 138 | |
139 | 139 | // Renew/Complete the subscription. |
140 | 140 | $subscription->renew(); |
141 | 141 | |
142 | - if ( 'completed' != $subscription->status ) { |
|
142 | + if ('completed' != $subscription->status) { |
|
143 | 143 | |
144 | 144 | // Schedule an action to run when the subscription expires. |
145 | 145 | $action_id = as_schedule_single_action( |
146 | - strtotime( $subscription->expiration ), |
|
146 | + strtotime($subscription->expiration), |
|
147 | 147 | 'wpinv_renew_manual_subscription_profile', |
148 | - array( $invoice_id ), |
|
148 | + array($invoice_id), |
|
149 | 149 | 'invoicing' |
150 | 150 | ); |
151 | 151 | |
152 | - $subscription->update( array( 'profile_id' => $action_id, ) ); |
|
152 | + $subscription->update(array('profile_id' => $action_id,)); |
|
153 | 153 | |
154 | 154 | } |
155 | 155 |
@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | - * Displays the credit card entry field. |
|
79 | - * |
|
80 | - * @param int $invoice_id 0 or invoice id. |
|
81 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
82 | - */ |
|
78 | + * Displays the credit card entry field. |
|
79 | + * |
|
80 | + * @param int $invoice_id 0 or invoice id. |
|
81 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
82 | + */ |
|
83 | 83 | public function payment_fields( $invoice_id, $form ) { |
84 | 84 | $id_prefix = esc_attr( uniqid( 'authorizenet' ) ); |
85 | 85 | |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | - * Creates a customer profile. |
|
203 | - * |
|
204 | - * |
|
205 | - * @param WPInv_Invoice $invoice Invoice. |
|
202 | + * Creates a customer profile. |
|
203 | + * |
|
204 | + * |
|
205 | + * @param WPInv_Invoice $invoice Invoice. |
|
206 | 206 | * @param array $submission_data Posted checkout fields. |
207 | 207 | * @param bool $save Whether or not to save the payment as a token. |
208 | 208 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
209 | - * @return string|WP_Error Payment profile id. |
|
210 | - */ |
|
211 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
209 | + * @return string|WP_Error Payment profile id. |
|
210 | + */ |
|
211 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
212 | 212 | |
213 | 213 | // Remove non-digits from the number |
214 | 214 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -275,14 +275,14 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
278 | - * Retrieves a customer profile. |
|
279 | - * |
|
280 | - * |
|
281 | - * @param string $profile_id profile id. |
|
282 | - * @return string|WP_Error Profile id. |
|
278 | + * Retrieves a customer profile. |
|
279 | + * |
|
280 | + * |
|
281 | + * @param string $profile_id profile id. |
|
282 | + * @return string|WP_Error Profile id. |
|
283 | 283 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
284 | - */ |
|
285 | - public function get_customer_profile( $profile_id ) { |
|
284 | + */ |
|
285 | + public function get_customer_profile( $profile_id ) { |
|
286 | 286 | |
287 | 287 | // Generate args. |
288 | 288 | $args = array( |
@@ -297,17 +297,17 @@ discard block |
||
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
300 | - * Creates a customer profile. |
|
301 | - * |
|
302 | - * |
|
300 | + * Creates a customer profile. |
|
301 | + * |
|
302 | + * |
|
303 | 303 | * @param string $profile_id profile id. |
304 | - * @param WPInv_Invoice $invoice Invoice. |
|
304 | + * @param WPInv_Invoice $invoice Invoice. |
|
305 | 305 | * @param array $submission_data Posted checkout fields. |
306 | 306 | * @param bool $save Whether or not to save the payment as a token. |
307 | 307 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
308 | - * @return string|WP_Error Profile id. |
|
309 | - */ |
|
310 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
308 | + * @return string|WP_Error Profile id. |
|
309 | + */ |
|
310 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
311 | 311 | |
312 | 312 | // Remove non-digits from the number |
313 | 313 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -367,15 +367,15 @@ discard block |
||
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
370 | - * Retrieves a customer payment profile. |
|
371 | - * |
|
372 | - * |
|
373 | - * @param string $customer_profile_id customer profile id. |
|
370 | + * Retrieves a customer payment profile. |
|
371 | + * |
|
372 | + * |
|
373 | + * @param string $customer_profile_id customer profile id. |
|
374 | 374 | * @param string $payment_profile_id payment profile id. |
375 | - * @return string|WP_Error Profile id. |
|
375 | + * @return string|WP_Error Profile id. |
|
376 | 376 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
377 | - */ |
|
378 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
377 | + */ |
|
378 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
379 | 379 | |
380 | 380 | // Generate args. |
381 | 381 | $args = array( |
@@ -391,15 +391,15 @@ discard block |
||
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
394 | - * Charges a customer payment profile. |
|
395 | - * |
|
394 | + * Charges a customer payment profile. |
|
395 | + * |
|
396 | 396 | * @param string $customer_profile_id customer profile id. |
397 | 397 | * @param string $payment_profile_id payment profile id. |
398 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param WPInv_Invoice $invoice Invoice. |
|
399 | 399 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
400 | - * @return WP_Error|object |
|
401 | - */ |
|
402 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
400 | + * @return WP_Error|object |
|
401 | + */ |
|
402 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
403 | 403 | |
404 | 404 | // Generate args. |
405 | 405 | $args = array( |
@@ -441,12 +441,12 @@ discard block |
||
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
444 | - * Processes a customer charge. |
|
445 | - * |
|
444 | + * Processes a customer charge. |
|
445 | + * |
|
446 | 446 | * @param stdClass $result Api response. |
447 | - * @param WPInv_Invoice $invoice Invoice. |
|
448 | - */ |
|
449 | - public function process_charge_response( $result, $invoice ) { |
|
447 | + * @param WPInv_Invoice $invoice Invoice. |
|
448 | + */ |
|
449 | + public function process_charge_response( $result, $invoice ) { |
|
450 | 450 | |
451 | 451 | wpinv_clear_errors(); |
452 | 452 | |
@@ -489,13 +489,13 @@ discard block |
||
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
492 | - * Returns payment information. |
|
493 | - * |
|
494 | - * |
|
495 | - * @param array $card Card details. |
|
496 | - * @return array |
|
497 | - */ |
|
498 | - public function get_payment_information( $card ) { |
|
492 | + * Returns payment information. |
|
493 | + * |
|
494 | + * |
|
495 | + * @param array $card Card details. |
|
496 | + * @return array |
|
497 | + */ |
|
498 | + public function get_payment_information( $card ) { |
|
499 | 499 | return array( |
500 | 500 | |
501 | 501 | 'creditCard' => array ( |
@@ -508,13 +508,13 @@ discard block |
||
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
511 | - * Returns the card name. |
|
512 | - * |
|
513 | - * |
|
514 | - * @param string $card_number Card number. |
|
515 | - * @return string |
|
516 | - */ |
|
517 | - public function get_card_name( $card_number ) { |
|
511 | + * Returns the card name. |
|
512 | + * |
|
513 | + * |
|
514 | + * @param string $card_number Card number. |
|
515 | + * @return string |
|
516 | + */ |
|
517 | + public function get_card_name( $card_number ) { |
|
518 | 518 | |
519 | 519 | switch( $card_number ) { |
520 | 520 | |
@@ -544,34 +544,34 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Returns the customer profile meta name. |
|
548 | - * |
|
549 | - * |
|
550 | - * @param WPInv_Invoice $invoice Invoice. |
|
551 | - * @return string |
|
552 | - */ |
|
553 | - public function get_customer_profile_meta_name( $invoice ) { |
|
547 | + * Returns the customer profile meta name. |
|
548 | + * |
|
549 | + * |
|
550 | + * @param WPInv_Invoice $invoice Invoice. |
|
551 | + * @return string |
|
552 | + */ |
|
553 | + public function get_customer_profile_meta_name( $invoice ) { |
|
554 | 554 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Returns the API URL. |
|
559 | - * |
|
560 | - * |
|
561 | - * @param WPInv_Invoice $invoice Invoice. |
|
562 | - * @return string |
|
563 | - */ |
|
564 | - public function get_api_url( $invoice ) { |
|
558 | + * Returns the API URL. |
|
559 | + * |
|
560 | + * |
|
561 | + * @param WPInv_Invoice $invoice Invoice. |
|
562 | + * @return string |
|
563 | + */ |
|
564 | + public function get_api_url( $invoice ) { |
|
565 | 565 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Returns the API authentication params. |
|
570 | - * |
|
571 | - * |
|
572 | - * @return array |
|
573 | - */ |
|
574 | - public function get_auth_params() { |
|
569 | + * Returns the API authentication params. |
|
570 | + * |
|
571 | + * |
|
572 | + * @return array |
|
573 | + */ |
|
574 | + public function get_auth_params() { |
|
575 | 575 | |
576 | 576 | return array( |
577 | 577 | 'name' => $this->get_option( 'login_id' ), |
@@ -581,14 +581,14 @@ discard block |
||
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
584 | - * Validates the submitted data. |
|
585 | - * |
|
586 | - * |
|
587 | - * @param array $submission_data Posted checkout fields. |
|
584 | + * Validates the submitted data. |
|
585 | + * |
|
586 | + * |
|
587 | + * @param array $submission_data Posted checkout fields. |
|
588 | 588 | * @param WPInv_Invoice $invoice |
589 | - * @return WP_Error|string The payment profile id |
|
590 | - */ |
|
591 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
589 | + * @return WP_Error|string The payment profile id |
|
590 | + */ |
|
591 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
592 | 592 | |
593 | 593 | // Validate authentication details. |
594 | 594 | $auth = $this->get_auth_params(); |
@@ -620,13 +620,13 @@ discard block |
||
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
623 | - * Returns invoice line items. |
|
624 | - * |
|
625 | - * |
|
626 | - * @param WPInv_Invoice $invoice Invoice. |
|
627 | - * @return array |
|
628 | - */ |
|
629 | - public function get_line_items( $invoice ) { |
|
623 | + * Returns invoice line items. |
|
624 | + * |
|
625 | + * |
|
626 | + * @param WPInv_Invoice $invoice Invoice. |
|
627 | + * @return array |
|
628 | + */ |
|
629 | + public function get_line_items( $invoice ) { |
|
630 | 630 | $items = array(); |
631 | 631 | |
632 | 632 | foreach ( $invoice->get_items() as $item ) { |
@@ -646,13 +646,13 @@ discard block |
||
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
649 | - * Communicates with authorize.net |
|
650 | - * |
|
651 | - * |
|
652 | - * @param array $post Data to post. |
|
649 | + * Communicates with authorize.net |
|
650 | + * |
|
651 | + * |
|
652 | + * @param array $post Data to post. |
|
653 | 653 | * @param WPInv_Invoice $invoice Invoice. |
654 | - * @return stdClass|WP_Error |
|
655 | - */ |
|
654 | + * @return stdClass|WP_Error |
|
655 | + */ |
|
656 | 656 | public function post( $post, $invoice ){ |
657 | 657 | |
658 | 658 | $url = $this->get_api_url( $invoice ); |
@@ -686,15 +686,15 @@ discard block |
||
686 | 686 | } |
687 | 687 | |
688 | 688 | /** |
689 | - * Process Payment. |
|
690 | - * |
|
691 | - * |
|
692 | - * @param WPInv_Invoice $invoice Invoice. |
|
693 | - * @param array $submission_data Posted checkout fields. |
|
694 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
695 | - * @return array |
|
696 | - */ |
|
697 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
689 | + * Process Payment. |
|
690 | + * |
|
691 | + * |
|
692 | + * @param WPInv_Invoice $invoice Invoice. |
|
693 | + * @param array $submission_data Posted checkout fields. |
|
694 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
695 | + * @return array |
|
696 | + */ |
|
697 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
698 | 698 | |
699 | 699 | // Validate the submitted data. |
700 | 700 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -743,12 +743,12 @@ discard block |
||
743 | 743 | } |
744 | 744 | |
745 | 745 | /** |
746 | - * Processes recurring payments. |
|
747 | - * |
|
746 | + * Processes recurring payments. |
|
747 | + * |
|
748 | 748 | * @param WPInv_Invoice $invoice Invoice. |
749 | 749 | * @param WPInv_Subscription $subscription Subscription. |
750 | - */ |
|
751 | - public function process_subscription( $invoice, $subscription ) { |
|
750 | + */ |
|
751 | + public function process_subscription( $invoice, $subscription ) { |
|
752 | 752 | |
753 | 753 | // Check if there is an initial amount to charge. |
754 | 754 | if ( (float) $invoice->get_total() > 0 ) { |
@@ -800,11 +800,11 @@ discard block |
||
800 | 800 | } |
801 | 801 | |
802 | 802 | /** |
803 | - * Renews a subscription. |
|
804 | - * |
|
803 | + * Renews a subscription. |
|
804 | + * |
|
805 | 805 | * @param int $invoice Invoice id. |
806 | - */ |
|
807 | - public function renew_subscription( $invoice ) { |
|
806 | + */ |
|
807 | + public function renew_subscription( $invoice ) { |
|
808 | 808 | |
809 | 809 | // Retrieve the subscription. |
810 | 810 | $subscription = wpinv_get_subscription( $invoice ); |
@@ -897,13 +897,13 @@ discard block |
||
897 | 897 | } |
898 | 898 | |
899 | 899 | /** |
900 | - * Cancels a subscription remotely |
|
901 | - * |
|
902 | - * |
|
903 | - * @param WPInv_Subscription $subscription Subscription. |
|
900 | + * Cancels a subscription remotely |
|
901 | + * |
|
902 | + * |
|
903 | + * @param WPInv_Subscription $subscription Subscription. |
|
904 | 904 | * @param WPInv_Invoice $invoice Invoice. |
905 | - */ |
|
906 | - public function cancel_subscription( $subscription, $invoice ) { |
|
905 | + */ |
|
906 | + public function cancel_subscription( $subscription, $invoice ) { |
|
907 | 907 | |
908 | 908 | if ( as_unschedule_action( 'wpinv_renew_authorizenet_subscription_profile', array( $invoice->get_id() ), 'invoicing' ) ) { |
909 | 909 | return; |
@@ -923,17 +923,17 @@ discard block |
||
923 | 923 | } |
924 | 924 | |
925 | 925 | /** |
926 | - * Processes ipns. |
|
927 | - * |
|
928 | - * @return void |
|
929 | - */ |
|
930 | - public function verify_ipn() { |
|
926 | + * Processes ipns. |
|
927 | + * |
|
928 | + * @return void |
|
929 | + */ |
|
930 | + public function verify_ipn() { |
|
931 | 931 | |
932 | 932 | $this->maybe_process_old_ipn(); |
933 | 933 | |
934 | 934 | // Validate the IPN. |
935 | 935 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
936 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
936 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | // Event type. |
@@ -981,11 +981,11 @@ discard block |
||
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
984 | - * Backwards compatibility. |
|
985 | - * |
|
986 | - * @return void |
|
987 | - */ |
|
988 | - public function maybe_process_old_ipn() { |
|
984 | + * Backwards compatibility. |
|
985 | + * |
|
986 | + * @return void |
|
987 | + */ |
|
988 | + public function maybe_process_old_ipn() { |
|
989 | 989 | |
990 | 990 | // Ensure that we are using the old subscriptions. |
991 | 991 | if ( empty( $_POST['x_subscription_id'] ) ) { |
@@ -1034,9 +1034,9 @@ discard block |
||
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | /** |
1037 | - * Check Authorize.NET IPN validity. |
|
1038 | - */ |
|
1039 | - public function validate_ipn() { |
|
1037 | + * Check Authorize.NET IPN validity. |
|
1038 | + */ |
|
1039 | + public function validate_ipn() { |
|
1040 | 1040 | |
1041 | 1041 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
1042 | 1042 | |
@@ -1081,11 +1081,11 @@ discard block |
||
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | /** |
1084 | - * Filters the gateway settings. |
|
1085 | - * |
|
1086 | - * @param array $admin_settings |
|
1087 | - */ |
|
1088 | - public function admin_settings( $admin_settings ) { |
|
1084 | + * Filters the gateway settings. |
|
1085 | + * |
|
1086 | + * @param array $admin_settings |
|
1087 | + */ |
|
1088 | + public function admin_settings( $admin_settings ) { |
|
1089 | 1089 | |
1090 | 1090 | $currencies = sprintf( |
1091 | 1091 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -1125,7 +1125,7 @@ discard block |
||
1125 | 1125 | 'readonly' => true, |
1126 | 1126 | ); |
1127 | 1127 | |
1128 | - return $admin_settings; |
|
1129 | - } |
|
1128 | + return $admin_settings; |
|
1129 | + } |
|
1130 | 1130 | |
1131 | 1131 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_filter( 'wpinv_renew_authorizenet_subscription_profile', array( $this, 'renew_subscription' ) ); |
|
73 | + add_filter('wpinv_renew_authorizenet_subscription_profile', array($this, 'renew_subscription')); |
|
74 | 74 | parent::__construct(); |
75 | 75 | } |
76 | 76 | |
@@ -80,35 +80,35 @@ discard block |
||
80 | 80 | * @param int $invoice_id 0 or invoice id. |
81 | 81 | * @param GetPaid_Payment_Form $form Current payment form. |
82 | 82 | */ |
83 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | - $id_prefix = esc_attr( uniqid( 'authorizenet' ) ); |
|
83 | + public function payment_fields($invoice_id, $form) { |
|
84 | + $id_prefix = esc_attr(uniqid('authorizenet')); |
|
85 | 85 | |
86 | 86 | $months = array( |
87 | - '01' => __( 'January', 'invoicing' ), |
|
88 | - '02' => __( 'February', 'invoicing' ), |
|
89 | - '03' => __( 'March', 'invoicing' ), |
|
90 | - '04' => __( 'April', 'invoicing' ), |
|
91 | - '05' => __( 'May', 'invoicing' ), |
|
92 | - '06' => __( 'June', 'invoicing' ), |
|
93 | - '07' => __( 'July', 'invoicing' ), |
|
94 | - '08' => __( 'August', 'invoicing' ), |
|
95 | - '09' => __( 'September', 'invoicing' ), |
|
96 | - '10' => __( 'October', 'invoicing' ), |
|
97 | - '11' => __( 'November', 'invoicing' ), |
|
98 | - '12' => __( 'December', 'invoicing' ), |
|
87 | + '01' => __('January', 'invoicing'), |
|
88 | + '02' => __('February', 'invoicing'), |
|
89 | + '03' => __('March', 'invoicing'), |
|
90 | + '04' => __('April', 'invoicing'), |
|
91 | + '05' => __('May', 'invoicing'), |
|
92 | + '06' => __('June', 'invoicing'), |
|
93 | + '07' => __('July', 'invoicing'), |
|
94 | + '08' => __('August', 'invoicing'), |
|
95 | + '09' => __('September', 'invoicing'), |
|
96 | + '10' => __('October', 'invoicing'), |
|
97 | + '11' => __('November', 'invoicing'), |
|
98 | + '12' => __('December', 'invoicing'), |
|
99 | 99 | ); |
100 | 100 | |
101 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
101 | + $year = (int) date('Y', current_time('timestamp')); |
|
102 | 102 | $years = array(); |
103 | 103 | |
104 | - for ( $i = 0; $i <= 20; $i++ ) { |
|
105 | - $years[ $year + $i ] = $year + $i; |
|
104 | + for ($i = 0; $i <= 20; $i++) { |
|
105 | + $years[$year + $i] = $year + $i; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | ?> |
109 | 109 | <div class="authorizenet-cc-form card mt-4"> |
110 | 110 | |
111 | - <div class="card-header"><?php _e( 'Card Details', 'invoicing' ) ;?></div> |
|
111 | + <div class="card-header"><?php _e('Card Details', 'invoicing'); ?></div> |
|
112 | 112 | |
113 | 113 | <div class="card-body"> |
114 | 114 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | 'type' => 'text', |
120 | 120 | 'name' => 'authorizenet[cc_owner]', |
121 | 121 | 'id' => "$id_prefix-cc-owner", |
122 | - 'label' => __( 'Full name (on the card)', 'invoicing' ), |
|
122 | + 'label' => __('Full name (on the card)', 'invoicing'), |
|
123 | 123 | 'label_type' => 'vertical', |
124 | 124 | 'input_group_left' => '<span class="input-group-text"><i class="fa fa-user"></i></span>', |
125 | 125 | ) |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | array( |
130 | 130 | 'name' => 'authorizenet[cc_number]', |
131 | 131 | 'id' => "$id_prefix-cc-number", |
132 | - 'label' => __( 'Card number', 'invoicing' ), |
|
132 | + 'label' => __('Card number', 'invoicing'), |
|
133 | 133 | 'label_type' => 'vertical', |
134 | 134 | 'input_group_left' => '<span class="input-group-text"><i class="fa fa-credit-card"></i></span>', |
135 | 135 | ) |
@@ -141,17 +141,17 @@ discard block |
||
141 | 141 | <div class="col-sm-8"> |
142 | 142 | <div class="form-group"> |
143 | 143 | <label> |
144 | - <span class="hidden-xs"><?php _e( 'Expiration', 'invoicing' ); ?></span> |
|
144 | + <span class="hidden-xs"><?php _e('Expiration', 'invoicing'); ?></span> |
|
145 | 145 | </label> |
146 | 146 | <div class="form-inline"> |
147 | 147 | |
148 | 148 | <select class="form-control" style="width:45%" name="authorizenet[cc_expire_month]"> |
149 | - <option disabled><?php _e( 'MM', 'invoicing' ); ?></option> |
|
149 | + <option disabled><?php _e('MM', 'invoicing'); ?></option> |
|
150 | 150 | |
151 | 151 | <?php |
152 | - foreach ( $months as $key => $month ) { |
|
153 | - $key = esc_attr( $key ); |
|
154 | - $month = wpinv_clean( $month ); |
|
152 | + foreach ($months as $key => $month) { |
|
153 | + $key = esc_attr($key); |
|
154 | + $month = wpinv_clean($month); |
|
155 | 155 | echo "<option value='$key'>$month</option>" . PHP_EOL; |
156 | 156 | } |
157 | 157 | ?> |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | <span style="width:10%; text-align: center"> / </span> |
162 | 162 | |
163 | 163 | <select class="form-control" style="width:45%" name="authorizenet[cc_expire_year]"> |
164 | - <option disabled><?php _e( 'YY', 'invoicing' ); ?></option> |
|
164 | + <option disabled><?php _e('YY', 'invoicing'); ?></option> |
|
165 | 165 | |
166 | 166 | <?php |
167 | - foreach ( $years as $key => $year ) { |
|
168 | - $key = esc_attr( $key ); |
|
169 | - $year = wpinv_clean( $year ); |
|
167 | + foreach ($years as $key => $year) { |
|
168 | + $key = esc_attr($key); |
|
169 | + $year = wpinv_clean($year); |
|
170 | 170 | echo "<option value='$key'>$year</option>" . PHP_EOL; |
171 | 171 | } |
172 | 172 | ?> |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | array( |
184 | 184 | 'name' => 'authorizenet[cc_cvv2]', |
185 | 185 | 'id' => "$id_prefix-cc-cvv2", |
186 | - 'label' => __( 'CCV', 'invoicing' ), |
|
186 | + 'label' => __('CCV', 'invoicing'), |
|
187 | 187 | 'label_type' => 'vertical', |
188 | 188 | ) |
189 | 189 | ); |
@@ -208,64 +208,64 @@ discard block |
||
208 | 208 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
209 | 209 | * @return string|WP_Error Payment profile id. |
210 | 210 | */ |
211 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
211 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
212 | 212 | |
213 | 213 | // Remove non-digits from the number |
214 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
214 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
215 | 215 | |
216 | 216 | // Generate args. |
217 | 217 | $args = array( |
218 | 218 | 'createCustomerProfileRequest' => array( |
219 | 219 | 'merchantAuthentication' => $this->get_auth_params(), |
220 | 220 | 'profile' => array( |
221 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
222 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
223 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
221 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
222 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
223 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
224 | 224 | 'paymentProfiles' => array( |
225 | 225 | 'customerType' => 'individual', |
226 | 226 | |
227 | 227 | // Billing information. |
228 | 228 | 'billTo' => array( |
229 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
230 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
231 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
232 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
233 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
234 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
235 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
229 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
230 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
231 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
232 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
233 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
234 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
235 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
236 | 236 | ), |
237 | 237 | |
238 | 238 | // Payment information. |
239 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
239 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
240 | 240 | ) |
241 | 241 | ), |
242 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
242 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
243 | 243 | ) |
244 | 244 | ); |
245 | -log_noptin_message( $args ); |
|
246 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
245 | +log_noptin_message($args); |
|
246 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
247 | 247 | |
248 | - if ( is_wp_error( $response ) ) { |
|
248 | + if (is_wp_error($response)) { |
|
249 | 249 | return $response; |
250 | 250 | } |
251 | - log_noptin_message( $response ); |
|
252 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
251 | + log_noptin_message($response); |
|
252 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
253 | 253 | |
254 | 254 | // Save the payment token. |
255 | - if ( $save ) { |
|
255 | + if ($save) { |
|
256 | 256 | $this->save_token( |
257 | 257 | array( |
258 | 258 | 'id' => $response->customerPaymentProfileIdList[0], |
259 | - 'name' => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
259 | + 'name' => $this->get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
260 | 260 | 'default' => true, |
261 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
261 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
262 | 262 | ) |
263 | 263 | ); |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Add a note about the validation response. |
267 | 267 | $invoice->add_note( |
268 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
268 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
269 | 269 | false, |
270 | 270 | false, |
271 | 271 | true |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return string|WP_Error Profile id. |
283 | 283 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
284 | 284 | */ |
285 | - public function get_customer_profile( $profile_id ) { |
|
285 | + public function get_customer_profile($profile_id) { |
|
286 | 286 | |
287 | 287 | // Generate args. |
288 | 288 | $args = array( |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | ) |
293 | 293 | ); |
294 | 294 | |
295 | - return $this->post( $args, false ); |
|
295 | + return $this->post($args, false); |
|
296 | 296 | |
297 | 297 | } |
298 | 298 | |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
308 | 308 | * @return string|WP_Error Profile id. |
309 | 309 | */ |
310 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
310 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
311 | 311 | |
312 | 312 | // Remove non-digits from the number |
313 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
313 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
314 | 314 | |
315 | 315 | // Generate args. |
316 | 316 | $args = array( |
@@ -321,34 +321,34 @@ discard block |
||
321 | 321 | |
322 | 322 | // Billing information. |
323 | 323 | 'billTo' => array( |
324 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
325 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
326 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
327 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
328 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
329 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
330 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
324 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
325 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
326 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
327 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
328 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
329 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
330 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
331 | 331 | ), |
332 | 332 | |
333 | 333 | // Payment information. |
334 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ) |
|
334 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']) |
|
335 | 335 | ), |
336 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
336 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
337 | 337 | ) |
338 | 338 | ); |
339 | 339 | |
340 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
340 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
341 | 341 | |
342 | - if ( is_wp_error( $response ) ) { |
|
342 | + if (is_wp_error($response)) { |
|
343 | 343 | return $response; |
344 | 344 | } |
345 | 345 | |
346 | 346 | // Save the payment token. |
347 | - if ( $save ) { |
|
347 | + if ($save) { |
|
348 | 348 | $this->save_token( |
349 | 349 | array( |
350 | 350 | 'id' => $response->customerPaymentProfileId, |
351 | - 'name' => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
351 | + 'name' => $this->get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
352 | 352 | 'default' => true |
353 | 353 | ) |
354 | 354 | ); |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | |
357 | 357 | // Add a note about the validation response. |
358 | 358 | $invoice->add_note( |
359 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
359 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
360 | 360 | false, |
361 | 361 | false, |
362 | 362 | true |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @return string|WP_Error Profile id. |
376 | 376 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
377 | 377 | */ |
378 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
378 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
379 | 379 | |
380 | 380 | // Generate args. |
381 | 381 | $args = array( |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | ) |
387 | 387 | ); |
388 | 388 | |
389 | - return $this->post( $args, false ); |
|
389 | + return $this->post($args, false); |
|
390 | 390 | |
391 | 391 | } |
392 | 392 | |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
400 | 400 | * @return WP_Error|object |
401 | 401 | */ |
402 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
402 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
403 | 403 | |
404 | 404 | // Generate args. |
405 | 405 | $args = array( |
@@ -419,24 +419,24 @@ discard block |
||
419 | 419 | ) |
420 | 420 | ), |
421 | 421 | 'order' => array( |
422 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
422 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
423 | 423 | ), |
424 | - 'lineItems' => $this->get_line_items( $invoice ), |
|
424 | + 'lineItems' => $this->get_line_items($invoice), |
|
425 | 425 | 'tax' => array( |
426 | 426 | 'amount' => $invoice->get_total_tax(), |
427 | 427 | 'name' => getpaid_tax()->get_vat_name(), |
428 | 428 | ), |
429 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
429 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
430 | 430 | 'customer' => array( |
431 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
432 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
431 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
432 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
433 | 433 | ), |
434 | 434 | 'customerIP' => $invoice->get_ip(), |
435 | 435 | ) |
436 | 436 | ) |
437 | 437 | ); |
438 | - log_noptin_message( $args ); |
|
439 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
438 | + log_noptin_message($args); |
|
439 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -446,40 +446,40 @@ discard block |
||
446 | 446 | * @param stdClass $result Api response. |
447 | 447 | * @param WPInv_Invoice $invoice Invoice. |
448 | 448 | */ |
449 | - public function process_charge_response( $result, $invoice ) { |
|
449 | + public function process_charge_response($result, $invoice) { |
|
450 | 450 | |
451 | 451 | wpinv_clear_errors(); |
452 | 452 | |
453 | - switch ( (int) $result->transactionResponse->responseCode ) { |
|
453 | + switch ((int) $result->transactionResponse->responseCode) { |
|
454 | 454 | |
455 | 455 | case 1: |
456 | 456 | case 4: |
457 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
457 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
458 | 458 | |
459 | - if ( 1 == (int) $result->transactionResponse->responseCode ) { |
|
459 | + if (1 == (int) $result->transactionResponse->responseCode) { |
|
460 | 460 | $invoice->mark_paid(); |
461 | 461 | } else { |
462 | - $invoice->set_status( 'wpi-onhold' ); |
|
462 | + $invoice->set_status('wpi-onhold'); |
|
463 | 463 | $invoice->add_note( |
464 | 464 | sprintf( |
465 | - __( 'Held for review: %s', 'invoicing' ), |
|
465 | + __('Held for review: %s', 'invoicing'), |
|
466 | 466 | $result->transactionResponse->messages->message[0]->description |
467 | 467 | ) |
468 | 468 | ); |
469 | 469 | } |
470 | 470 | |
471 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
471 | + $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
472 | 472 | $invoice->save(); |
473 | 473 | |
474 | 474 | return; |
475 | 475 | |
476 | 476 | case 2: |
477 | 477 | case 3: |
478 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
478 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
479 | 479 | |
480 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
480 | + if (!empty($result->transactionResponse->errors)) { |
|
481 | 481 | $errors = (object) $result->transactionResponse->errors; |
482 | - wpinv_set_error( $errors->error[0]->errorCode, $errors->error[0]->errorText ); |
|
482 | + wpinv_set_error($errors->error[0]->errorCode, $errors->error[0]->errorText); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | return; |
@@ -495,10 +495,10 @@ discard block |
||
495 | 495 | * @param array $card Card details. |
496 | 496 | * @return array |
497 | 497 | */ |
498 | - public function get_payment_information( $card ) { |
|
498 | + public function get_payment_information($card) { |
|
499 | 499 | return array( |
500 | 500 | |
501 | - 'creditCard' => array ( |
|
501 | + 'creditCard' => array( |
|
502 | 502 | 'cardNumber' => $card['cc_number'], |
503 | 503 | 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'], |
504 | 504 | 'cardCode' => $card['cc_cvv2'], |
@@ -514,30 +514,30 @@ discard block |
||
514 | 514 | * @param string $card_number Card number. |
515 | 515 | * @return string |
516 | 516 | */ |
517 | - public function get_card_name( $card_number ) { |
|
517 | + public function get_card_name($card_number) { |
|
518 | 518 | |
519 | - switch( $card_number ) { |
|
519 | + switch ($card_number) { |
|
520 | 520 | |
521 | - case( preg_match ( '/^4/', $card_number ) >= 1 ): |
|
522 | - return __( 'Visa', 'invoicing' ); |
|
521 | + case(preg_match('/^4/', $card_number) >= 1): |
|
522 | + return __('Visa', 'invoicing'); |
|
523 | 523 | |
524 | - case( preg_match ( '/^5[1-5]/', $card_number ) >= 1 ): |
|
525 | - return __( 'Mastercard', 'invoicing' ); |
|
524 | + case(preg_match('/^5[1-5]/', $card_number) >= 1): |
|
525 | + return __('Mastercard', 'invoicing'); |
|
526 | 526 | |
527 | - case( preg_match ( '/^3[47]/', $card_number ) >= 1 ): |
|
528 | - return __( 'Amex', 'invoicing' ); |
|
527 | + case(preg_match('/^3[47]/', $card_number) >= 1): |
|
528 | + return __('Amex', 'invoicing'); |
|
529 | 529 | |
530 | - case( preg_match ( '/^3(?:0[0-5]|[68])/', $card_number ) >= 1 ): |
|
531 | - return __( 'Diners Club', 'invoicing' ); |
|
530 | + case(preg_match('/^3(?:0[0-5]|[68])/', $card_number) >= 1): |
|
531 | + return __('Diners Club', 'invoicing'); |
|
532 | 532 | |
533 | - case( preg_match ( '/^6(?:011|5)/', $card_number ) >= 1 ): |
|
534 | - return __( 'Discover', 'invoicing' ); |
|
533 | + case(preg_match('/^6(?:011|5)/', $card_number) >= 1): |
|
534 | + return __('Discover', 'invoicing'); |
|
535 | 535 | |
536 | - case( preg_match ( '/^(?:2131|1800|35\d{3})/', $card_number ) >= 1 ): |
|
537 | - return __( 'JCB', 'invoicing' ); |
|
536 | + case(preg_match('/^(?:2131|1800|35\d{3})/', $card_number) >= 1): |
|
537 | + return __('JCB', 'invoicing'); |
|
538 | 538 | |
539 | 539 | default: |
540 | - return __( 'Card', 'invoicing' ); |
|
540 | + return __('Card', 'invoicing'); |
|
541 | 541 | break; |
542 | 542 | } |
543 | 543 | |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param WPInv_Invoice $invoice Invoice. |
551 | 551 | * @return string |
552 | 552 | */ |
553 | - public function get_customer_profile_meta_name( $invoice ) { |
|
554 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
553 | + public function get_customer_profile_meta_name($invoice) { |
|
554 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | * @param WPInv_Invoice $invoice Invoice. |
562 | 562 | * @return string |
563 | 563 | */ |
564 | - public function get_api_url( $invoice ) { |
|
565 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
564 | + public function get_api_url($invoice) { |
|
565 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -574,8 +574,8 @@ discard block |
||
574 | 574 | public function get_auth_params() { |
575 | 575 | |
576 | 576 | return array( |
577 | - 'name' => $this->get_option( 'login_id' ), |
|
578 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
577 | + 'name' => $this->get_option('login_id'), |
|
578 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
579 | 579 | ); |
580 | 580 | |
581 | 581 | } |
@@ -588,34 +588,34 @@ discard block |
||
588 | 588 | * @param WPInv_Invoice $invoice |
589 | 589 | * @return WP_Error|string The payment profile id |
590 | 590 | */ |
591 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
591 | + public function validate_submission_data($submission_data, $invoice) { |
|
592 | 592 | |
593 | 593 | // Validate authentication details. |
594 | 594 | $auth = $this->get_auth_params(); |
595 | 595 | |
596 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
597 | - return new WP_Error( 'invalid_settings', __( 'This gateway has not been set up.', 'invoicing') ); |
|
596 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
597 | + return new WP_Error('invalid_settings', __('This gateway has not been set up.', 'invoicing')); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | // Validate the payment method. |
601 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
602 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') ); |
|
601 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
602 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | // Are we adding a new payment method? |
606 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
606 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
607 | 607 | return $submission_data['getpaid-authorizenet-payment-method']; |
608 | 608 | } |
609 | 609 | |
610 | 610 | // Retrieve the customer profile id. |
611 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
611 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
612 | 612 | |
613 | 613 | // Create payment method. |
614 | - if ( empty( $profile_id ) ) { |
|
615 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
614 | + if (empty($profile_id)) { |
|
615 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
616 | 616 | } |
617 | 617 | |
618 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
618 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
619 | 619 | |
620 | 620 | } |
621 | 621 | |
@@ -626,15 +626,15 @@ discard block |
||
626 | 626 | * @param WPInv_Invoice $invoice Invoice. |
627 | 627 | * @return array |
628 | 628 | */ |
629 | - public function get_line_items( $invoice ) { |
|
629 | + public function get_line_items($invoice) { |
|
630 | 630 | $items = array(); |
631 | 631 | |
632 | - foreach ( $invoice->get_items() as $item ) { |
|
632 | + foreach ($invoice->get_items() as $item) { |
|
633 | 633 | |
634 | 634 | $items[] = array( |
635 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
636 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
637 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
635 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
636 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
637 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
638 | 638 | 'quantity' => (int) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(), |
639 | 639 | 'unitPrice' => (float) $item->get_price(), |
640 | 640 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
@@ -653,32 +653,32 @@ discard block |
||
653 | 653 | * @param WPInv_Invoice $invoice Invoice. |
654 | 654 | * @return stdClass|WP_Error |
655 | 655 | */ |
656 | - public function post( $post, $invoice ){ |
|
656 | + public function post($post, $invoice) { |
|
657 | 657 | |
658 | - $url = $this->get_api_url( $invoice ); |
|
658 | + $url = $this->get_api_url($invoice); |
|
659 | 659 | $response = wp_remote_post( |
660 | 660 | $url, |
661 | 661 | array( |
662 | 662 | 'headers' => array( |
663 | 663 | 'Content-Type' => 'application/json; charset=utf-8' |
664 | 664 | ), |
665 | - 'body' => json_encode( $post ), |
|
665 | + 'body' => json_encode($post), |
|
666 | 666 | 'method' => 'POST' |
667 | 667 | ) |
668 | 668 | ); |
669 | 669 | |
670 | - if ( is_wp_error( $response ) ) { |
|
670 | + if (is_wp_error($response)) { |
|
671 | 671 | return $response; |
672 | 672 | } |
673 | 673 | |
674 | - $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
674 | + $response = json_decode(wp_remote_retrieve_body($response)); |
|
675 | 675 | |
676 | - if ( empty( $response ) ) { |
|
677 | - return new WP_Error( 'invalid_reponse', __( 'Invalid response', 'invoicing' ) ); |
|
676 | + if (empty($response)) { |
|
677 | + return new WP_Error('invalid_reponse', __('Invalid response', 'invoicing')); |
|
678 | 678 | } |
679 | 679 | |
680 | - if ( $response->messages->resultCode == 'Error' ) { |
|
681 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
680 | + if ($response->messages->resultCode == 'Error') { |
|
681 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | return $response; |
@@ -694,49 +694,49 @@ discard block |
||
694 | 694 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
695 | 695 | * @return array |
696 | 696 | */ |
697 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
697 | + public function process_payment($invoice, $submission_data, $submission) { |
|
698 | 698 | |
699 | 699 | // Validate the submitted data. |
700 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
700 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
701 | 701 | |
702 | 702 | // Do we have an error? |
703 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
704 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
703 | + if (is_wp_error($payment_profile_id)) { |
|
704 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
705 | 705 | wpinv_send_back_to_checkout(); |
706 | 706 | } |
707 | 707 | |
708 | 708 | // Save the payment method to the order. |
709 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
709 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
710 | 710 | |
711 | 711 | // Check if this is a subscription or not. |
712 | - if ( $invoice->is_recurring() && $subscription = wpinv_get_subscription( $invoice ) ) { |
|
713 | - $this->process_subscription( $invoice, $subscription ); |
|
712 | + if ($invoice->is_recurring() && $subscription = wpinv_get_subscription($invoice)) { |
|
713 | + $this->process_subscription($invoice, $subscription); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | // If it is free, send to the success page. |
717 | - if ( ! $invoice->needs_payment() ) { |
|
717 | + if (!$invoice->needs_payment()) { |
|
718 | 718 | $invoice->mark_paid(); |
719 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
719 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | // Charge the payment profile. |
723 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
724 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
723 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
724 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
725 | 725 | |
726 | 726 | // Do we have an error? |
727 | - if ( is_wp_error( $result ) ) { |
|
728 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
727 | + if (is_wp_error($result)) { |
|
728 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
729 | 729 | wpinv_send_back_to_checkout(); |
730 | 730 | } |
731 | - log_noptin_message( $result ); |
|
731 | + log_noptin_message($result); |
|
732 | 732 | // Process the response. |
733 | - $this->process_charge_response( $result, $invoice ); |
|
733 | + $this->process_charge_response($result, $invoice); |
|
734 | 734 | |
735 | - if ( wpinv_get_errors() ) { |
|
735 | + if (wpinv_get_errors()) { |
|
736 | 736 | wpinv_send_back_to_checkout(); |
737 | 737 | } |
738 | 738 | |
739 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
739 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
740 | 740 | |
741 | 741 | exit; |
742 | 742 | |
@@ -748,40 +748,40 @@ discard block |
||
748 | 748 | * @param WPInv_Invoice $invoice Invoice. |
749 | 749 | * @param WPInv_Subscription $subscription Subscription. |
750 | 750 | */ |
751 | - public function process_subscription( $invoice, $subscription ) { |
|
751 | + public function process_subscription($invoice, $subscription) { |
|
752 | 752 | |
753 | 753 | // Check if there is an initial amount to charge. |
754 | - if ( (float) $invoice->get_total() > 0 ) { |
|
754 | + if ((float) $invoice->get_total() > 0) { |
|
755 | 755 | |
756 | 756 | // Retrieve the payment method. |
757 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
758 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
759 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
757 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
758 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
759 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
760 | 760 | |
761 | 761 | // Do we have an error? |
762 | - if ( is_wp_error( $result ) ) { |
|
763 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
762 | + if (is_wp_error($result)) { |
|
763 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
764 | 764 | wpinv_send_back_to_checkout(); |
765 | 765 | } |
766 | 766 | |
767 | 767 | // Process the response. |
768 | - $this->process_charge_response( $result, $invoice ); |
|
768 | + $this->process_charge_response($result, $invoice); |
|
769 | 769 | |
770 | - if ( wpinv_get_errors() ) { |
|
770 | + if (wpinv_get_errors()) { |
|
771 | 771 | wpinv_send_back_to_checkout(); |
772 | 772 | } |
773 | 773 | |
774 | 774 | } |
775 | 775 | |
776 | 776 | // Recalculate the new subscription expiry. |
777 | - $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created ); |
|
778 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
777 | + $duration = strtotime($subscription->expiration) - strtotime($subscription->created); |
|
778 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
779 | 779 | |
780 | 780 | // Schedule an action to run when the subscription expires. |
781 | 781 | $action_id = as_schedule_single_action( |
782 | - strtotime( $expiry ), |
|
782 | + strtotime($expiry), |
|
783 | 783 | 'wpinv_renew_authorizenet_subscription_profile', |
784 | - array( $invoice->get_id() ), |
|
784 | + array($invoice->get_id()), |
|
785 | 785 | 'invoicing' |
786 | 786 | ); |
787 | 787 | |
@@ -790,12 +790,12 @@ discard block |
||
790 | 790 | array( |
791 | 791 | 'profile_id' => $action_id, |
792 | 792 | 'status' => 'trialling' == $subscription->status ? 'trialling' : 'active', |
793 | - 'created' => current_time( 'mysql' ), |
|
793 | + 'created' => current_time('mysql'), |
|
794 | 794 | 'expiration' => $expiry, |
795 | 795 | ) |
796 | 796 | ); |
797 | 797 | |
798 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
798 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
799 | 799 | |
800 | 800 | } |
801 | 801 | |
@@ -804,45 +804,45 @@ discard block |
||
804 | 804 | * |
805 | 805 | * @param int $invoice Invoice id. |
806 | 806 | */ |
807 | - public function renew_subscription( $invoice ) { |
|
807 | + public function renew_subscription($invoice) { |
|
808 | 808 | |
809 | 809 | // Retrieve the subscription. |
810 | - $subscription = wpinv_get_subscription( $invoice ); |
|
811 | - if ( empty( $subscription ) ) { |
|
810 | + $subscription = wpinv_get_subscription($invoice); |
|
811 | + if (empty($subscription)) { |
|
812 | 812 | return; |
813 | 813 | } |
814 | 814 | |
815 | 815 | // Abort if it is canceled or complete. |
816 | - if ( $subscription->status == 'completed' || $subscription->status == 'cancelled' ) { |
|
816 | + if ($subscription->status == 'completed' || $subscription->status == 'cancelled') { |
|
817 | 817 | return; |
818 | 818 | } |
819 | 819 | |
820 | 820 | // Retrieve the invoice. |
821 | - $invoice = new WPInv_Invoice( $invoice ); |
|
821 | + $invoice = new WPInv_Invoice($invoice); |
|
822 | 822 | |
823 | 823 | // If we have not maxed out on bill times... |
824 | 824 | $times_billed = $subscription->get_times_billed(); |
825 | 825 | $max_bills = $subscription->bill_times; |
826 | 826 | |
827 | - if ( empty( $max_bills ) || $max_bills > $times_billed ) { |
|
827 | + if (empty($max_bills) || $max_bills > $times_billed) { |
|
828 | 828 | |
829 | 829 | $new_invoice = $subscription->create_payment(); |
830 | 830 | |
831 | - if ( empty( $new_invoice ) ) { |
|
832 | - $invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
831 | + if (empty($new_invoice)) { |
|
832 | + $invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
833 | 833 | $subscription->failing(); |
834 | 834 | return; |
835 | 835 | } |
836 | 836 | |
837 | 837 | // retrieve the payment method. |
838 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
839 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
840 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
838 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
839 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
840 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
841 | 841 | |
842 | 842 | // Do we have an error? |
843 | - if ( is_wp_error( $result ) ) { |
|
843 | + if (is_wp_error($result)) { |
|
844 | 844 | $invoice->add_note( |
845 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
845 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
846 | 846 | true, |
847 | 847 | false, |
848 | 848 | true |
@@ -852,12 +852,12 @@ discard block |
||
852 | 852 | } |
853 | 853 | |
854 | 854 | // Process the response. |
855 | - $this->process_charge_response( $result, $new_invoice ); |
|
855 | + $this->process_charge_response($result, $new_invoice); |
|
856 | 856 | |
857 | - if ( wpinv_get_errors() ) { |
|
857 | + if (wpinv_get_errors()) { |
|
858 | 858 | |
859 | 859 | $invoice->add_note( |
860 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
860 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
861 | 861 | true, |
862 | 862 | false, |
863 | 863 | true |
@@ -879,17 +879,17 @@ discard block |
||
879 | 879 | // Renew/Complete the subscription. |
880 | 880 | $subscription->renew(); |
881 | 881 | |
882 | - if ( 'completed' != $subscription->status ) { |
|
882 | + if ('completed' != $subscription->status) { |
|
883 | 883 | |
884 | 884 | // Schedule an action to run when the subscription expires. |
885 | 885 | $action_id = as_schedule_single_action( |
886 | - strtotime( $subscription->expiration ), |
|
886 | + strtotime($subscription->expiration), |
|
887 | 887 | 'wpinv_renew_authorizenet_subscription_profile', |
888 | - array( $invoice->get_id() ), |
|
888 | + array($invoice->get_id()), |
|
889 | 889 | 'invoicing' |
890 | 890 | ); |
891 | 891 | |
892 | - $subscription->update( array( 'profile_id' => $action_id, ) ); |
|
892 | + $subscription->update(array('profile_id' => $action_id,)); |
|
893 | 893 | |
894 | 894 | } |
895 | 895 | |
@@ -903,9 +903,9 @@ discard block |
||
903 | 903 | * @param WPInv_Subscription $subscription Subscription. |
904 | 904 | * @param WPInv_Invoice $invoice Invoice. |
905 | 905 | */ |
906 | - public function cancel_subscription( $subscription, $invoice ) { |
|
906 | + public function cancel_subscription($subscription, $invoice) { |
|
907 | 907 | |
908 | - if ( as_unschedule_action( 'wpinv_renew_authorizenet_subscription_profile', array( $invoice->get_id() ), 'invoicing' ) ) { |
|
908 | + if (as_unschedule_action('wpinv_renew_authorizenet_subscription_profile', array($invoice->get_id()), 'invoicing')) { |
|
909 | 909 | return; |
910 | 910 | } |
911 | 911 | |
@@ -932,45 +932,45 @@ discard block |
||
932 | 932 | $this->maybe_process_old_ipn(); |
933 | 933 | |
934 | 934 | // Validate the IPN. |
935 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
936 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
935 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
936 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500)); |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | // Event type. |
940 | - $posted = json_decode( file_get_contents('php://input') ); |
|
941 | - if ( empty( $posted ) ) { |
|
942 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
940 | + $posted = json_decode(file_get_contents('php://input')); |
|
941 | + if (empty($posted)) { |
|
942 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500)); |
|
943 | 943 | } |
944 | 944 | |
945 | 945 | // Process the IPN. |
946 | - $posted = (object) wp_unslash( $posted ); |
|
946 | + $posted = (object) wp_unslash($posted); |
|
947 | 947 | |
948 | 948 | // Process refunds. |
949 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
950 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
949 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
950 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
951 | 951 | |
952 | - if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) { |
|
952 | + if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) { |
|
953 | 953 | $invoice->refund(); |
954 | 954 | } |
955 | 955 | |
956 | 956 | } |
957 | 957 | |
958 | 958 | // Held funds approved. |
959 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
960 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
959 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
960 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
961 | 961 | |
962 | - if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) { |
|
963 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' )); |
|
962 | + if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) { |
|
963 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | } |
967 | 967 | |
968 | 968 | // Held funds declined. |
969 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
970 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
969 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
970 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
971 | 971 | |
972 | - if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) { |
|
973 | - $invoice->set_status( 'wpi-failed', __( 'Payment desclined', 'invoicing' ) ); |
|
972 | + if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) { |
|
973 | + $invoice->set_status('wpi-failed', __('Payment desclined', 'invoicing')); |
|
974 | 974 | $invoice->save(); |
975 | 975 | } |
976 | 976 | |
@@ -988,41 +988,41 @@ discard block |
||
988 | 988 | public function maybe_process_old_ipn() { |
989 | 989 | |
990 | 990 | // Ensure that we are using the old subscriptions. |
991 | - if ( empty( $_POST['x_subscription_id'] ) ) { |
|
991 | + if (empty($_POST['x_subscription_id'])) { |
|
992 | 992 | return; |
993 | 993 | } |
994 | 994 | |
995 | 995 | // Check validity. |
996 | - $signature = $this->get_option( 'signature_key' ); |
|
997 | - if ( ! empty( $signature ) ) { |
|
998 | - $login_id = $this->get_option( 'login_id' ); |
|
996 | + $signature = $this->get_option('signature_key'); |
|
997 | + if (!empty($signature)) { |
|
998 | + $login_id = $this->get_option('login_id'); |
|
999 | 999 | $trans_id = $_POST['x_trans_id']; |
1000 | 1000 | $amount = $_POST['x_amount']; |
1001 | - $hash = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
1001 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
1002 | 1002 | |
1003 | - if ( ! hash_equals( $hash, $_POST['x_SHA2_Hash'] ) ) { |
|
1003 | + if (!hash_equals($hash, $_POST['x_SHA2_Hash'])) { |
|
1004 | 1004 | exit; |
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | // Fetch the associated subscription. |
1010 | - $subscription = new WPInv_Subscription( $_POST['x_subscription_id'], true ); |
|
1010 | + $subscription = new WPInv_Subscription($_POST['x_subscription_id'], true); |
|
1011 | 1011 | |
1012 | 1012 | // Abort if it is missing or completed. |
1013 | - if ( empty( $subscription->id ) || $subscription->status == 'completed' ) { |
|
1013 | + if (empty($subscription->id) || $subscription->status == 'completed') { |
|
1014 | 1014 | return; |
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | // Payment status. |
1018 | - if ( 1 == $_POST['x_response_code'] ) { |
|
1018 | + if (1 == $_POST['x_response_code']) { |
|
1019 | 1019 | |
1020 | 1020 | $args = array( |
1021 | - 'transaction_id' => wpinv_clean( $_POST['x_trans_id'] ), |
|
1021 | + 'transaction_id' => wpinv_clean($_POST['x_trans_id']), |
|
1022 | 1022 | 'gateway' => $this->id |
1023 | 1023 | ); |
1024 | 1024 | |
1025 | - $subscription->add_payment( $args ); |
|
1025 | + $subscription->add_payment($args); |
|
1026 | 1026 | $subscription->renew(); |
1027 | 1027 | |
1028 | 1028 | } else { |
@@ -1038,28 +1038,28 @@ discard block |
||
1038 | 1038 | */ |
1039 | 1039 | public function validate_ipn() { |
1040 | 1040 | |
1041 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
1041 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
1042 | 1042 | |
1043 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
1043 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
1044 | 1044 | return false; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | - $signature = $this->get_option( 'signature_key' ); |
|
1047 | + $signature = $this->get_option('signature_key'); |
|
1048 | 1048 | |
1049 | - if ( empty( $signature ) ) { |
|
1050 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
1049 | + if (empty($signature)) { |
|
1050 | + wpinv_error_log('Error: You have not set a signature key'); |
|
1051 | 1051 | return false; |
1052 | 1052 | } |
1053 | 1053 | |
1054 | - $hash = hash_hmac ( 'sha512', file_get_contents('php://input'), hex2bin( $signature ) ); |
|
1054 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
1055 | 1055 | |
1056 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
1057 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
1056 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
1057 | + wpinv_error_log('Successfully validated the IPN'); |
|
1058 | 1058 | return true; |
1059 | 1059 | } |
1060 | 1060 | |
1061 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
1062 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
1061 | + wpinv_error_log('IPN hash is not valid'); |
|
1062 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
1063 | 1063 | return false; |
1064 | 1064 | |
1065 | 1065 | } |
@@ -1067,11 +1067,11 @@ discard block |
||
1067 | 1067 | /** |
1068 | 1068 | * Displays a notice on the checkout page if sandbox is enabled. |
1069 | 1069 | */ |
1070 | - public function sandbox_notice( $description, $gateway ) { |
|
1070 | + public function sandbox_notice($description, $gateway) { |
|
1071 | 1071 | |
1072 | - if ( $this->id == $gateway && wpinv_is_test_mode( $this->id ) ) { |
|
1072 | + if ($this->id == $gateway && wpinv_is_test_mode($this->id)) { |
|
1073 | 1073 | $description .= '<br>' . sprintf( |
1074 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
1074 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
1075 | 1075 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
1076 | 1076 | '</a>' |
1077 | 1077 | ); |
@@ -1085,42 +1085,42 @@ discard block |
||
1085 | 1085 | * |
1086 | 1086 | * @param array $admin_settings |
1087 | 1087 | */ |
1088 | - public function admin_settings( $admin_settings ) { |
|
1088 | + public function admin_settings($admin_settings) { |
|
1089 | 1089 | |
1090 | 1090 | $currencies = sprintf( |
1091 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
1092 | - implode( ', ', $this->currencies ) |
|
1091 | + __('Supported Currencies: %s', 'invoicing'), |
|
1092 | + implode(', ', $this->currencies) |
|
1093 | 1093 | ); |
1094 | 1094 | |
1095 | 1095 | $admin_settings['authorizenet_active']['desc'] .= $admin_settings['authorizenet_active']['desc'] . " ($currencies)"; |
1096 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
1096 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
1097 | 1097 | |
1098 | 1098 | $admin_settings['authorizenet_login_id'] = array( |
1099 | 1099 | 'type' => 'text', |
1100 | 1100 | 'id' => 'authorizenet_login_id', |
1101 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
1102 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
1101 | + 'name' => __('API Login ID', 'invoicing'), |
|
1102 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
1103 | 1103 | ); |
1104 | 1104 | |
1105 | 1105 | $admin_settings['authorizenet_transaction_key'] = array( |
1106 | 1106 | 'type' => 'text', |
1107 | 1107 | 'id' => 'authorizenet_transaction_key', |
1108 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
1108 | + 'name' => __('Transaction Key', 'invoicing'), |
|
1109 | 1109 | ); |
1110 | 1110 | |
1111 | 1111 | $admin_settings['authorizenet_signature_key'] = array( |
1112 | 1112 | 'type' => 'text', |
1113 | 1113 | 'id' => 'authorizenet_signature_key', |
1114 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
1115 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
1114 | + 'name' => __('Signature Key', 'invoicing'), |
|
1115 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
1116 | 1116 | ); |
1117 | 1117 | |
1118 | 1118 | $admin_settings['authorizenet_ipn_url'] = array( |
1119 | 1119 | 'type' => 'ipn_url', |
1120 | 1120 | 'id' => 'authorizenet_ipn_url', |
1121 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
1121 | + 'name' => __('Webhook URL', 'invoicing'), |
|
1122 | 1122 | 'std' => $this->notify_url, |
1123 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
1123 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
1124 | 1124 | 'custom' => 'authorizenet', |
1125 | 1125 | 'readonly' => true, |
1126 | 1126 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox' ); |
|
27 | + protected $supports = array('subscription', 'sandbox'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $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' ); |
|
62 | + public $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'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
103 | + public function process_payment($invoice, $submission_data, $submission) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
106 | + $paypal_redirect = $this->get_request_url($invoice); |
|
107 | 107 | |
108 | 108 | // Add a note about the request url. |
109 | 109 | $invoice->add_note( |
110 | 110 | sprintf( |
111 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
112 | - esc_url( $paypal_redirect ) |
|
111 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
112 | + esc_url($paypal_redirect) |
|
113 | 113 | ), |
114 | 114 | false, |
115 | 115 | false, |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | |
119 | 119 | // Redirect to PayPal |
120 | - wp_redirect( $paypal_redirect ); |
|
120 | + wp_redirect($paypal_redirect); |
|
121 | 121 | exit; |
122 | 122 | |
123 | 123 | } |
@@ -128,21 +128,21 @@ discard block |
||
128 | 128 | * @param WPInv_Invoice $invoice Invoice object. |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public function get_request_url( $invoice ) { |
|
131 | + public function get_request_url($invoice) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
137 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
138 | 138 | |
139 | - if ( $invoice->is_recurring() ) { |
|
139 | + if ($invoice->is_recurring()) { |
|
140 | 140 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
141 | 141 | } else { |
142 | 142 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
143 | 143 | } |
144 | 144 | |
145 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
145 | + return add_query_arg($paypal_args, $this->endpoint); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -152,25 +152,25 @@ discard block |
||
152 | 152 | * @param WPInv_Invoice $invoice Invoice object. |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - protected function get_paypal_args( $invoice ) { |
|
155 | + protected function get_paypal_args($invoice) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
158 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice); |
|
159 | 159 | |
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
160 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
161 | 161 | $force_one_line_item = true; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $paypal_args = apply_filters( |
165 | 165 | 'getpaid_paypal_args', |
166 | 166 | array_merge( |
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
167 | + $this->get_transaction_args($invoice), |
|
168 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
169 | 169 | ), |
170 | 170 | $invoice |
171 | 171 | ); |
172 | 172 | |
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
173 | + return $this->fix_request_length($invoice, $paypal_args); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | * @param WPInv_Invoice $invoice Invoice object. |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - protected function get_transaction_args( $invoice ) { |
|
182 | + protected function get_transaction_args($invoice) { |
|
183 | 183 | |
184 | 184 | return array( |
185 | 185 | 'cmd' => '_cart', |
186 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
186 | + 'business' => wpinv_get_option('paypal_email', false), |
|
187 | 187 | 'no_shipping' => '1', |
188 | 188 | 'shipping' => '0', |
189 | 189 | 'no_note' => '1', |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | 'rm' => is_ssl() ? 2 : 1, |
192 | 192 | 'upload' => 1, |
193 | 193 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
194 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
195 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
196 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
197 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
194 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
195 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
196 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
197 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
198 | 198 | 'custom' => $invoice->get_id(), |
199 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
200 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
201 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
202 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
203 | - 'cbt' => get_bloginfo( 'name' ) |
|
199 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
200 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
201 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
202 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
203 | + 'cbt' => get_bloginfo('name') |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | } |
@@ -212,30 +212,30 @@ discard block |
||
212 | 212 | * @param bool $force_one_line_item Create only one item for this invoice. |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
215 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
219 | - return $this->get_line_item_args_single_item( $invoice ); |
|
218 | + if ($force_one_line_item) { |
|
219 | + return $this->get_line_item_args_single_item($invoice); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // Send each line item individually. |
223 | 223 | $line_item_args = array(); |
224 | 224 | |
225 | 225 | // Prepare line items. |
226 | - $this->prepare_line_items( $invoice ); |
|
226 | + $this->prepare_line_items($invoice); |
|
227 | 227 | |
228 | 228 | // Add taxes to the cart |
229 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
230 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
229 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
230 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Add discount. |
234 | - if ( $invoice->get_total_discount() > 0 ) { |
|
235 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
234 | + if ($invoice->get_total_discount() > 0) { |
|
235 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge($line_item_args, $this->get_line_items()); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | * @param WPInv_Invoice $invoice Invoice object. |
246 | 246 | * @return array |
247 | 247 | */ |
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
248 | + protected function get_line_item_args_single_item($invoice) { |
|
249 | 249 | $this->delete_line_items(); |
250 | 250 | |
251 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
251 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
252 | + $this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $invoice->get_id()); |
|
253 | 253 | |
254 | 254 | return $this->get_line_items(); |
255 | 255 | } |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
275 | 275 | */ |
276 | - protected function prepare_line_items( $invoice ) { |
|
276 | + protected function prepare_line_items($invoice) { |
|
277 | 277 | $this->delete_line_items(); |
278 | 278 | |
279 | 279 | // Items. |
280 | - foreach ( $invoice->get_items() as $item ) { |
|
280 | + foreach ($invoice->get_items() as $item) { |
|
281 | 281 | $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
282 | 282 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
283 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | - $this->add_line_item( $fee, 1, $data['amount'] ); |
|
287 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
288 | + $this->add_line_item($fee, 1, $data['amount']); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
@@ -298,15 +298,15 @@ discard block |
||
298 | 298 | * @param float $amount Amount. |
299 | 299 | * @param string $item_number Item number. |
300 | 300 | */ |
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
301 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
302 | + $index = (count($this->line_items) / 4) + 1; |
|
303 | 303 | |
304 | 304 | $item = apply_filters( |
305 | 305 | 'getpaid_paypal_line_item', |
306 | 306 | array( |
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
307 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
308 | 308 | 'quantity' => (int) $quantity, |
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
309 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
310 | 310 | 'item_number' => $item_number, |
311 | 311 | ), |
312 | 312 | $item_name, |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | $item_number |
316 | 316 | ); |
317 | 317 | |
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
318 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
319 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items['amount_' . $index] = $item['amount']; |
|
323 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -332,19 +332,19 @@ discard block |
||
332 | 332 | * @param array $paypal_args Arguments sent to Paypal in the request. |
333 | 333 | * @return array |
334 | 334 | */ |
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
335 | + protected function fix_request_length($invoice, $paypal_args) { |
|
336 | 336 | $max_paypal_length = 2083; |
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
337 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
338 | 338 | |
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
339 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
340 | 340 | return $paypal_args; |
341 | 341 | } |
342 | 342 | |
343 | 343 | return apply_filters( |
344 | 344 | 'getpaid_paypal_args', |
345 | 345 | array_merge( |
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
346 | + $this->get_transaction_args($invoice), |
|
347 | + $this->get_line_item_args($invoice, true) |
|
348 | 348 | ), |
349 | 349 | $invoice |
350 | 350 | ); |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | * @param array $paypal_args PayPal args. |
358 | 358 | * @param WPInv_Invoice $invoice Invoice object. |
359 | 359 | */ |
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
360 | + public function process_subscription($paypal_args, $invoice) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | - if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
|
363 | + if (!$invoice->is_recurring() || !$subscription = wpinv_get_subscription($invoice)) { |
|
364 | 364 | return $paypal_args; |
365 | 365 | } |
366 | 366 | |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
369 | 369 | |
370 | 370 | // Subscription name. |
371 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
371 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
372 | 372 | |
373 | 373 | // Get subscription args. |
374 | - $period = strtoupper( substr( $subscription->period, 0, 1) ); |
|
374 | + $period = strtoupper(substr($subscription->period, 0, 1)); |
|
375 | 375 | $interval = (int) $subscription->frequency; |
376 | 376 | $bill_times = (int) $subscription->bill_times; |
377 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
378 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
379 | - $subscription_item = $invoice->get_recurring( true ); |
|
377 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
378 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
379 | + $subscription_item = $invoice->get_recurring(true); |
|
380 | 380 | |
381 | - if ( $subscription_item->has_free_trial() ) { |
|
381 | + if ($subscription_item->has_free_trial()) { |
|
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
@@ -388,28 +388,28 @@ discard block |
||
388 | 388 | // Trial period. |
389 | 389 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
390 | 390 | |
391 | - } else if ( $initial_amount != $recurring_amount ) { |
|
391 | + } else if ($initial_amount != $recurring_amount) { |
|
392 | 392 | |
393 | 393 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
394 | 394 | |
395 | - if ( 1 == $bill_times ) { |
|
395 | + if (1 == $bill_times) { |
|
396 | 396 | $param_number = 3; |
397 | 397 | } else { |
398 | 398 | $param_number = 1; |
399 | 399 | } |
400 | 400 | |
401 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? 0 : $initial_amount; |
|
401 | + $paypal_args['a' . $param_number] = $initial_amount ? 0 : $initial_amount; |
|
402 | 402 | |
403 | 403 | // Sign Up interval |
404 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
404 | + $paypal_args['p' . $param_number] = $interval; |
|
405 | 405 | |
406 | 406 | // Sign Up unit of duration |
407 | - $paypal_args[ 't' . $param_number ] = $period; |
|
407 | + $paypal_args['t' . $param_number] = $period; |
|
408 | 408 | |
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if (!isset($param_number) || 1 == $param_number) { |
|
413 | 413 | |
414 | 414 | // Subscription price |
415 | 415 | $paypal_args['a3'] = $recurring_amount; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
427 | 427 | |
428 | 428 | // Non-recurring payments |
429 | 429 | $paypal_args['src'] = 0; |
@@ -432,15 +432,15 @@ discard block |
||
432 | 432 | |
433 | 433 | $paypal_args['src'] = 1; |
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ($bill_times > 0) { |
|
436 | 436 | |
437 | 437 | // An initial period is being used to charge a sign-up fee |
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
438 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
439 | 439 | $bill_times--; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
443 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | $paypal_args['rm'] = 2; |
450 | 450 | |
451 | 451 | // Get rid of redudant items. |
452 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
452 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
453 | 453 | |
454 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
455 | - unset( $paypal_args[ $arg ] ); |
|
454 | + if (isset($paypal_args[$arg])) { |
|
455 | + unset($paypal_args[$arg]); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | } |
@@ -473,25 +473,25 @@ discard block |
||
473 | 473 | public function verify_ipn() { |
474 | 474 | |
475 | 475 | // Validate the IPN. |
476 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
477 | - wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); |
|
476 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
477 | + wp_die('PayPal IPN Request Failure', 'PayPal IPN', array('response' => 500)); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | // Process the IPN. |
481 | - $posted = wp_unslash( $_POST ); |
|
482 | - $invoice = wpinv_get_invoice( $posted['custom'] ); |
|
481 | + $posted = wp_unslash($_POST); |
|
482 | + $invoice = wpinv_get_invoice($posted['custom']); |
|
483 | 483 | |
484 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
484 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
485 | 485 | |
486 | - $posted['payment_status'] = strtolower( $posted['payment_status'] ); |
|
486 | + $posted['payment_status'] = strtolower($posted['payment_status']); |
|
487 | 487 | |
488 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
489 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
488 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
489 | + wpinv_error_log('Payment status:' . $posted['payment_status']); |
|
490 | 490 | |
491 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
492 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
491 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
492 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
493 | 493 | } else { |
494 | - wpinv_error_log( 'Aborting, Invalid type:' . $posted['txn_type'] ); |
|
494 | + wpinv_error_log('Aborting, Invalid type:' . $posted['txn_type']); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | } |
@@ -505,10 +505,10 @@ discard block |
||
505 | 505 | */ |
506 | 506 | public function validate_ipn() { |
507 | 507 | |
508 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
508 | + wpinv_error_log('Validating PayPal IPN response'); |
|
509 | 509 | |
510 | 510 | // Get received values from post data. |
511 | - $validate_ipn = wp_unslash( $_POST ); |
|
511 | + $validate_ipn = wp_unslash($_POST); |
|
512 | 512 | $validate_ipn['cmd'] = '_notify-validate'; |
513 | 513 | |
514 | 514 | // Send back post vars to paypal. |
@@ -522,18 +522,18 @@ discard block |
||
522 | 522 | ); |
523 | 523 | |
524 | 524 | // Post back to get a response. |
525 | - $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
525 | + $response = wp_safe_remote_post($this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
526 | 526 | |
527 | 527 | // Check to see if the request was valid. |
528 | - if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
529 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
528 | + if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
529 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
530 | 530 | return true; |
531 | 531 | } |
532 | 532 | |
533 | - if ( is_wp_error( $response ) ) { |
|
534 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
533 | + if (is_wp_error($response)) { |
|
534 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
535 | 535 | } else { |
536 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
536 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | return false; |
@@ -546,12 +546,12 @@ discard block |
||
546 | 546 | * @param WPInv_Invoice $invoice Invoice object. |
547 | 547 | * @param string $currency currency to validate. |
548 | 548 | */ |
549 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
550 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
551 | - wpinv_record_gateway_error( 'IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}" ); |
|
549 | + protected function validate_ipn_currency($invoice, $currency) { |
|
550 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
551 | + wpinv_record_gateway_error('IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}"); |
|
552 | 552 | |
553 | 553 | /* translators: %s: currency code. */ |
554 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
554 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
555 | 555 | exit; |
556 | 556 | } |
557 | 557 | } |
@@ -562,12 +562,12 @@ discard block |
||
562 | 562 | * @param WPInv_Invoice $invoice Invoice object. |
563 | 563 | * @param float $amount amount to validate. |
564 | 564 | */ |
565 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
566 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
567 | - wpinv_record_gateway_error( 'IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}" ); |
|
565 | + protected function validate_ipn_amount($invoice, $amount) { |
|
566 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
567 | + wpinv_record_gateway_error('IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}"); |
|
568 | 568 | |
569 | 569 | /* translators: %s: Amount. */ |
570 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
570 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
571 | 571 | exit; |
572 | 572 | } |
573 | 573 | } |
@@ -578,14 +578,14 @@ discard block |
||
578 | 578 | * @param WPInv_Invoice $invoice Invoice object. |
579 | 579 | * @param string $receiver_email Email to validate. |
580 | 580 | */ |
581 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
582 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
581 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
582 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
583 | 583 | |
584 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
585 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
584 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
585 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
586 | 586 | |
587 | 587 | /* translators: %s: email address . */ |
588 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
588 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
589 | 589 | exit; |
590 | 590 | } |
591 | 591 | |
@@ -597,57 +597,57 @@ discard block |
||
597 | 597 | * @param WPInv_Invoice $invoice Invoice object. |
598 | 598 | * @param array $posted Posted data. |
599 | 599 | */ |
600 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
600 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
601 | 601 | |
602 | 602 | // Collect payment details |
603 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
604 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
603 | + $payment_status = strtolower($posted['payment_status']); |
|
604 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
605 | 605 | |
606 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
607 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
606 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
607 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
608 | 608 | |
609 | 609 | // Update the transaction id. |
610 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
611 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
610 | + if (!empty($posted['txn_id'])) { |
|
611 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
612 | 612 | $invoice->save(); |
613 | 613 | } |
614 | 614 | |
615 | 615 | // Process a refund. |
616 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
616 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
617 | 617 | |
618 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
618 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
619 | 619 | |
620 | - if ( ! $invoice->is_refunded() ) { |
|
621 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
620 | + if (!$invoice->is_refunded()) { |
|
621 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | exit; |
625 | 625 | } |
626 | 626 | |
627 | 627 | // Process payments. |
628 | - if ( $payment_status == 'completed' ) { |
|
628 | + if ($payment_status == 'completed') { |
|
629 | 629 | |
630 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
631 | - wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already complete.' ); |
|
630 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
631 | + wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already complete.'); |
|
632 | 632 | exit; |
633 | 633 | } |
634 | 634 | |
635 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
635 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
636 | 636 | |
637 | - if ( 'completed' === $payment_status || 'pending' === $payment_status ) { |
|
637 | + if ('completed' === $payment_status || 'pending' === $payment_status) { |
|
638 | 638 | |
639 | 639 | $note = ''; |
640 | 640 | |
641 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
642 | - $note = sprintf( __( 'PayPal Transaction Fee %s', 'invoicing' ), wpinv_clean( $posted['mc_fee'] ) ); |
|
641 | + if (!empty($posted['mc_fee'])) { |
|
642 | + $note = sprintf(__('PayPal Transaction Fee %s', 'invoicing'), wpinv_clean($posted['mc_fee'])); |
|
643 | 643 | } |
644 | 644 | |
645 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? wpinv_clean( $posted['txn_id'] ) : '' ), $note ); |
|
645 | + $invoice->mark_paid((!empty($posted['txn_id']) ? wpinv_clean($posted['txn_id']) : ''), $note); |
|
646 | 646 | |
647 | 647 | } else { |
648 | 648 | |
649 | 649 | /* translators: %s: pending reason. */ |
650 | - $invoice->update_status( 'wpi_processing', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
650 | + $invoice->update_status('wpi_processing', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
651 | 651 | |
652 | 652 | } |
653 | 653 | |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | // Process failures. |
659 | 659 | |
660 | 660 | /* translators: %s: payment status. */ |
661 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) ); |
|
661 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), wpinv_clean($posted['payment_status']))); |
|
662 | 662 | |
663 | 663 | } |
664 | 664 | |
@@ -668,8 +668,8 @@ discard block |
||
668 | 668 | * @param WPInv_Invoice $invoice Invoice object. |
669 | 669 | * @param array $posted Posted data. |
670 | 670 | */ |
671 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
672 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
671 | + protected function ipn_txn_cart($invoice, $posted) { |
|
672 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -678,39 +678,39 @@ discard block |
||
678 | 678 | * @param WPInv_Invoice $invoice Invoice object. |
679 | 679 | * @param array $posted Posted data. |
680 | 680 | */ |
681 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
681 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
682 | 682 | |
683 | 683 | // Make sure the invoice has a subscription. |
684 | - $subscription = wpinv_get_subscription( $invoice ); |
|
684 | + $subscription = wpinv_get_subscription($invoice); |
|
685 | 685 | |
686 | - if ( empty( $subscription ) ) { |
|
687 | - wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
686 | + if (empty($subscription)) { |
|
687 | + wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | // Update the subscription ids. |
691 | 691 | $subscription->update( |
692 | 692 | array( |
693 | - 'profile_id' => sanitize_text_field( $posted['subscr_id'] ), |
|
693 | + 'profile_id' => sanitize_text_field($posted['subscr_id']), |
|
694 | 694 | ) |
695 | 695 | ); |
696 | 696 | |
697 | 697 | // Set the transaction id. |
698 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
699 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
698 | + if (!empty($posted['txn_id'])) { |
|
699 | + $invoice->set_transaction_id($posted['txn_id']); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | // Update the payment status. |
703 | 703 | $invoice->mark_paid(); |
704 | 704 | |
705 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
705 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
706 | 706 | |
707 | 707 | // Update the subscription duration. |
708 | - $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created ); |
|
708 | + $duration = strtotime($subscription->expiration) - strtotime($subscription->created); |
|
709 | 709 | $subscription->update( |
710 | 710 | array( |
711 | 711 | 'status' => 'trialling' == $subscription->status ? 'trialling' : 'active', |
712 | - 'created' => current_time( 'mysql' ), |
|
713 | - 'expiration' => date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ), |
|
712 | + 'created' => current_time('mysql'), |
|
713 | + 'expiration' => date('Y-m-d H:i:s', (current_time('timestamp') + $duration)), |
|
714 | 714 | ) |
715 | 715 | ); |
716 | 716 | |
@@ -722,25 +722,25 @@ discard block |
||
722 | 722 | * @param WPInv_Invoice $invoice Invoice object. |
723 | 723 | * @param array $posted Posted data. |
724 | 724 | */ |
725 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
725 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
726 | 726 | |
727 | 727 | // Make sure the invoice has a subscription. |
728 | - $subscription = wpinv_get_subscription( $invoice ); |
|
728 | + $subscription = wpinv_get_subscription($invoice); |
|
729 | 729 | |
730 | - if ( empty( $subscription ) ) { |
|
731 | - wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
730 | + if (empty($subscription)) { |
|
731 | + wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
732 | 732 | } |
733 | 733 | |
734 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
734 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
735 | 735 | |
736 | 736 | // Abort if the payment is already recorded. |
737 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
737 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
738 | 738 | return; |
739 | 739 | } |
740 | 740 | |
741 | 741 | // Abort if this is the first payment. |
742 | - if ( date( 'Ynd', $subscription->created ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
743 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
742 | + if (date('Ynd', $subscription->created) == date('Ynd', strtotime($posted['payment_date']))) { |
|
743 | + $invoice->set_transaction_id($posted['txn_id']); |
|
744 | 744 | $invoice->save(); |
745 | 745 | return; |
746 | 746 | } |
@@ -751,14 +751,14 @@ discard block |
||
751 | 751 | 'gateway' => $this->id, |
752 | 752 | ); |
753 | 753 | |
754 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
754 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
755 | 755 | |
756 | - if ( empty( $invoice ) ) { |
|
756 | + if (empty($invoice)) { |
|
757 | 757 | return; |
758 | 758 | } |
759 | 759 | |
760 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
761 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
760 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
761 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
762 | 762 | |
763 | 763 | $subscription->renew(); |
764 | 764 | |
@@ -770,9 +770,9 @@ discard block |
||
770 | 770 | * @param WPInv_Invoice $invoice Invoice object. |
771 | 771 | * @param array $posted Posted data. |
772 | 772 | */ |
773 | - protected function ipn_txn_subscr_cancel( $invoice, $posted ) { |
|
773 | + protected function ipn_txn_subscr_cancel($invoice, $posted) { |
|
774 | 774 | |
775 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
775 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
776 | 776 | $subscription->cancel(); |
777 | 777 | } |
778 | 778 | |
@@ -784,9 +784,9 @@ discard block |
||
784 | 784 | * @param WPInv_Invoice $invoice Invoice object. |
785 | 785 | * @param array $posted Posted data. |
786 | 786 | */ |
787 | - protected function ipn_txn_subscr_eot( $invoice, $posted ) { |
|
787 | + protected function ipn_txn_subscr_eot($invoice, $posted) { |
|
788 | 788 | |
789 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
789 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
790 | 790 | $subscription->complete(); |
791 | 791 | } |
792 | 792 | |
@@ -798,9 +798,9 @@ discard block |
||
798 | 798 | * @param WPInv_Invoice $invoice Invoice object. |
799 | 799 | * @param array $posted Posted data. |
800 | 800 | */ |
801 | - protected function ipn_txn_subscr_failed( $invoice, $posted ) { |
|
801 | + protected function ipn_txn_subscr_failed($invoice, $posted) { |
|
802 | 802 | |
803 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
803 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
804 | 804 | $subscription->failing(); |
805 | 805 | } |
806 | 806 | |
@@ -809,10 +809,10 @@ discard block |
||
809 | 809 | /** |
810 | 810 | * Displays a notice on the checkout page if sandbox is enabled. |
811 | 811 | */ |
812 | - public function sandbox_notice( $description, $gateway ) { |
|
813 | - if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) { |
|
812 | + public function sandbox_notice($description, $gateway) { |
|
813 | + if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) { |
|
814 | 814 | $description .= '<br>' . sprintf( |
815 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
815 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
816 | 816 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
817 | 817 | '</a>' |
818 | 818 | ); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' == strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $field ); |
|
29 | + if ('id' == strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($field); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return $id ? wpinv_get_item( $id ) : false; |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return $id ? wpinv_get_item($id) : false; |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->get_id() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | - $args = wp_parse_args( $args, array( |
|
58 | - 'status' => array( 'publish' ), |
|
59 | - 'limit' => get_option( 'posts_per_page' ), |
|
57 | + $args = wp_parse_args($args, array( |
|
58 | + 'status' => array('publish'), |
|
59 | + 'limit' => get_option('posts_per_page'), |
|
60 | 60 | 'page' => 1, |
61 | 61 | 'exclude' => array(), |
62 | 62 | 'orderby' => 'date', |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'meta_query' => array(), |
66 | 66 | 'return' => 'objects', |
67 | 67 | 'paginate' => false, |
68 | - ) ); |
|
68 | + )); |
|
69 | 69 | |
70 | 70 | $wp_query_args = array( |
71 | 71 | 'post_type' => 'wpi_item', |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | 'fields' => 'ids', |
76 | 76 | 'orderby' => $args['orderby'], |
77 | 77 | 'order' => $args['order'], |
78 | - 'paged' => absint( $args['page'] ), |
|
78 | + 'paged' => absint($args['page']), |
|
79 | 79 | ); |
80 | 80 | |
81 | - if ( ! empty( $args['exclude'] ) ) { |
|
82 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
81 | + if (!empty($args['exclude'])) { |
|
82 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ( ! $args['paginate' ] ) { |
|
85 | + if (!$args['paginate']) { |
|
86 | 86 | $wp_query_args['no_found_rows'] = true; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $args['search'] ) ) { |
|
89 | + if (!empty($args['search'])) { |
|
90 | 90 | $wp_query_args['s'] = $args['search']; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
94 | - $types = wpinv_parse_list( $args['type'] ); |
|
93 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
94 | + $types = wpinv_parse_list($args['type']); |
|
95 | 95 | $wp_query_args['meta_query'][] = array( |
96 | 96 | 'key' => '_wpinv_type', |
97 | - 'value' => implode( ',', $types ), |
|
97 | + 'value' => implode(',', $types), |
|
98 | 98 | 'compare' => 'IN', |
99 | 99 | ); |
100 | 100 | } |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
103 | 103 | |
104 | 104 | // Get results. |
105 | - $items = new WP_Query( $wp_query_args ); |
|
105 | + $items = new WP_Query($wp_query_args); |
|
106 | 106 | |
107 | - if ( 'objects' === $args['return'] ) { |
|
108 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
109 | - } elseif ( 'self' === $args['return'] ) { |
|
107 | + if ('objects' === $args['return']) { |
|
108 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
109 | + } elseif ('self' === $args['return']) { |
|
110 | 110 | return $items; |
111 | 111 | } else { |
112 | 112 | $return = $items->posts; |
113 | 113 | } |
114 | 114 | |
115 | - if ( $args['paginate' ] ) { |
|
115 | + if ($args['paginate']) { |
|
116 | 116 | return (object) array( |
117 | 117 | 'items' => $return, |
118 | 118 | 'total' => $items->found_posts, |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
128 | - if( empty( $item_id ) ) { |
|
127 | +function wpinv_is_free_item($item_id = 0) { |
|
128 | + if (empty($item_id)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | - $item = new WPInv_Item( $item_id ); |
|
132 | + $item = new WPInv_Item($item_id); |
|
133 | 133 | |
134 | 134 | return $item->is_free(); |
135 | 135 | } |
@@ -139,128 +139,128 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
141 | 141 | */ |
142 | -function wpinv_item_is_editable( $item = 0 ) { |
|
142 | +function wpinv_item_is_editable($item = 0) { |
|
143 | 143 | |
144 | 144 | // Fetch the item. |
145 | - $item = new WPInv_Item( $item ); |
|
145 | + $item = new WPInv_Item($item); |
|
146 | 146 | |
147 | 147 | // Check if it is editable. |
148 | 148 | return $item->is_editable(); |
149 | 149 | } |
150 | 150 | |
151 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
152 | - if( empty( $item_id ) ) { |
|
151 | +function wpinv_get_item_price($item_id = 0) { |
|
152 | + if (empty($item_id)) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - $item = new WPInv_Item( $item_id ); |
|
156 | + $item = new WPInv_Item($item_id); |
|
157 | 157 | |
158 | 158 | return $item->get_price(); |
159 | 159 | } |
160 | 160 | |
161 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
162 | - if( empty( $item_id ) ) { |
|
161 | +function wpinv_is_recurring_item($item_id = 0) { |
|
162 | + if (empty($item_id)) { |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
166 | - $item = new WPInv_Item( $item_id ); |
|
166 | + $item = new WPInv_Item($item_id); |
|
167 | 167 | |
168 | 168 | return $item->is_recurring(); |
169 | 169 | } |
170 | 170 | |
171 | -function wpinv_item_price( $item_id = 0 ) { |
|
172 | - if( empty( $item_id ) ) { |
|
171 | +function wpinv_item_price($item_id = 0) { |
|
172 | + if (empty($item_id)) { |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
176 | - $price = wpinv_get_item_price( $item_id ); |
|
177 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
176 | + $price = wpinv_get_item_price($item_id); |
|
177 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
178 | 178 | |
179 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
179 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
180 | 180 | } |
181 | 181 | |
182 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
183 | - if ( empty( $item_id ) ) { |
|
182 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
183 | + if (empty($item_id)) { |
|
184 | 184 | $item_id = get_the_ID(); |
185 | 185 | } |
186 | 186 | |
187 | - $price = wpinv_item_price( $item_id ); |
|
187 | + $price = wpinv_item_price($item_id); |
|
188 | 188 | |
189 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
189 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
190 | 190 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
191 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
191 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
192 | 192 | |
193 | - if ( $echo ) { |
|
193 | + if ($echo) { |
|
194 | 194 | echo $formatted_price; |
195 | 195 | } else { |
196 | 196 | return $formatted_price; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
201 | - if ( is_null( $amount_override ) ) { |
|
202 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
200 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
201 | + if (is_null($amount_override)) { |
|
202 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
203 | 203 | } else { |
204 | 204 | $original_price = $amount_override; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $price = $original_price; |
208 | 208 | |
209 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
209 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
210 | 210 | } |
211 | 211 | |
212 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
213 | - if( empty( $item_id ) ) { |
|
212 | +function wpinv_item_custom_singular_name($item_id) { |
|
213 | + if (empty($item_id)) { |
|
214 | 214 | return false; |
215 | 215 | } |
216 | 216 | |
217 | - $item = new WPInv_Item( $item_id ); |
|
217 | + $item = new WPInv_Item($item_id); |
|
218 | 218 | |
219 | 219 | return $item->get_custom_singular_name(); |
220 | 220 | } |
221 | 221 | |
222 | 222 | function wpinv_get_item_types() { |
223 | 223 | $item_types = array( |
224 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
225 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
224 | + 'custom' => __('Standard', 'invoicing'), |
|
225 | + 'fee' => __('Fee', 'invoicing'), |
|
226 | 226 | ); |
227 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
227 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_item_types() { |
231 | 231 | $item_types = wpinv_get_item_types(); |
232 | 232 | |
233 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
233 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
234 | 234 | } |
235 | 235 | |
236 | -function wpinv_get_item_type( $item_id ) { |
|
237 | - if( empty( $item_id ) ) { |
|
236 | +function wpinv_get_item_type($item_id) { |
|
237 | + if (empty($item_id)) { |
|
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | |
241 | - $item = new WPInv_Item( $item_id ); |
|
241 | + $item = new WPInv_Item($item_id); |
|
242 | 242 | |
243 | 243 | return $item->get_type(); |
244 | 244 | } |
245 | 245 | |
246 | -function wpinv_item_type( $item_id ) { |
|
246 | +function wpinv_item_type($item_id) { |
|
247 | 247 | $item_types = wpinv_get_item_types(); |
248 | 248 | |
249 | - $item_type = wpinv_get_item_type( $item_id ); |
|
249 | + $item_type = wpinv_get_item_type($item_id); |
|
250 | 250 | |
251 | - if ( empty( $item_type ) ) { |
|
251 | + if (empty($item_type)) { |
|
252 | 252 | $item_type = '-'; |
253 | 253 | } |
254 | 254 | |
255 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
255 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
256 | 256 | |
257 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
257 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
260 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
261 | 261 | global $wpinv_logs; |
262 | 262 | |
263 | - if ( empty( $wpinv_logs ) ) { |
|
263 | + if (empty($wpinv_logs)) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | 266 | |
@@ -269,278 +269,278 @@ discard block |
||
269 | 269 | 'log_type' => 'wpi_item' |
270 | 270 | ); |
271 | 271 | |
272 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
272 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
273 | 273 | |
274 | 274 | $log_meta = array( |
275 | 275 | 'user_info' => $user_info, |
276 | 276 | 'user_id' => $user_id, |
277 | - 'file_id' => (int)$file_id, |
|
277 | + 'file_id' => (int) $file_id, |
|
278 | 278 | 'ip' => $ip, |
279 | 279 | 'invoice_id'=> $invoice_id, |
280 | 280 | ); |
281 | 281 | |
282 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
282 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
286 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
285 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
286 | + if ('wpi_item' !== get_post_type($item_id)) |
|
287 | 287 | return; |
288 | 288 | |
289 | 289 | global $wpinv_logs; |
290 | 290 | |
291 | - if ( empty( $wpinv_logs ) ) { |
|
291 | + if (empty($wpinv_logs)) { |
|
292 | 292 | return false; |
293 | 293 | } |
294 | 294 | |
295 | 295 | // Remove all log entries related to this item |
296 | - $wpinv_logs->delete_logs( $item_id ); |
|
296 | + $wpinv_logs->delete_logs($item_id); |
|
297 | 297 | } |
298 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
298 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
299 | 299 | |
300 | -function wpinv_get_random_item( $post_ids = true ) { |
|
301 | - wpinv_get_random_items( 1, $post_ids ); |
|
300 | +function wpinv_get_random_item($post_ids = true) { |
|
301 | + wpinv_get_random_items(1, $post_ids); |
|
302 | 302 | } |
303 | 303 | |
304 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
305 | - if ( $post_ids ) { |
|
306 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
304 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
305 | + if ($post_ids) { |
|
306 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
307 | 307 | } else { |
308 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
308 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
309 | 309 | } |
310 | 310 | |
311 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
311 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
312 | 312 | |
313 | - return get_posts( $args ); |
|
313 | + return get_posts($args); |
|
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_get_item_token( $url = '' ) { |
|
316 | +function wpinv_get_item_token($url = '') { |
|
317 | 317 | $args = array(); |
318 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
319 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
318 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
319 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
320 | 320 | |
321 | - $parts = parse_url( $url ); |
|
321 | + $parts = parse_url($url); |
|
322 | 322 | $options = array(); |
323 | 323 | |
324 | - if ( isset( $parts['query'] ) ) { |
|
325 | - wp_parse_str( $parts['query'], $query_args ); |
|
324 | + if (isset($parts['query'])) { |
|
325 | + wp_parse_str($parts['query'], $query_args); |
|
326 | 326 | |
327 | - if ( ! empty( $query_args['o'] ) ) { |
|
328 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
327 | + if (!empty($query_args['o'])) { |
|
328 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
329 | 329 | |
330 | - if ( in_array( 'ip', $options ) ) { |
|
330 | + if (in_array('ip', $options)) { |
|
331 | 331 | $args['ip'] = wpinv_get_ip(); |
332 | 332 | } |
333 | 333 | |
334 | - if ( in_array( 'ua', $options ) ) { |
|
334 | + if (in_array('ua', $options)) { |
|
335 | 335 | $ua = wpinv_get_user_agent(); |
336 | - $args['user_agent'] = rawurlencode( $ua ); |
|
336 | + $args['user_agent'] = rawurlencode($ua); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
341 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
342 | 342 | |
343 | 343 | $args['secret'] = $secret; |
344 | 344 | $args['token'] = false; |
345 | 345 | |
346 | - $url = add_query_arg( $args, $url ); |
|
347 | - $parts = parse_url( $url ); |
|
346 | + $url = add_query_arg($args, $url); |
|
347 | + $parts = parse_url($url); |
|
348 | 348 | |
349 | - if ( ! isset( $parts['path'] ) ) { |
|
349 | + if (!isset($parts['path'])) { |
|
350 | 350 | $parts['path'] = ''; |
351 | 351 | } |
352 | 352 | |
353 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
353 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
354 | 354 | |
355 | 355 | return $token; |
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_validate_url_token( $url = '' ) { |
|
358 | +function wpinv_validate_url_token($url = '') { |
|
359 | 359 | $ret = false; |
360 | - $parts = parse_url( $url ); |
|
360 | + $parts = parse_url($url); |
|
361 | 361 | |
362 | - if ( isset( $parts['query'] ) ) { |
|
363 | - wp_parse_str( $parts['query'], $query_args ); |
|
362 | + if (isset($parts['query'])) { |
|
363 | + wp_parse_str($parts['query'], $query_args); |
|
364 | 364 | |
365 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
365 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
366 | 366 | 'item', |
367 | 367 | 'ttl', |
368 | 368 | 'token' |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | |
371 | 371 | $remove = array(); |
372 | 372 | |
373 | - foreach( $query_args as $key => $value ) { |
|
374 | - if( false === in_array( $key, $allowed ) ) { |
|
373 | + foreach ($query_args as $key => $value) { |
|
374 | + if (false === in_array($key, $allowed)) { |
|
375 | 375 | $remove[] = $key; |
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | - if( ! empty( $remove ) ) { |
|
380 | - $url = remove_query_arg( $remove, $url ); |
|
379 | + if (!empty($remove)) { |
|
380 | + $url = remove_query_arg($remove, $url); |
|
381 | 381 | } |
382 | 382 | |
383 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
384 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
383 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
384 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
387 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
388 | 388 | $ret = true; |
389 | 389 | } |
390 | 390 | |
391 | 391 | } |
392 | 392 | |
393 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
393 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
394 | 394 | } |
395 | 395 | |
396 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
396 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
397 | 397 | $cart_items = wpinv_get_cart_contents(); |
398 | 398 | |
399 | 399 | $ret = false; |
400 | 400 | |
401 | - if ( is_array( $cart_items ) ) { |
|
402 | - foreach ( $cart_items as $item ) { |
|
403 | - if ( $item['id'] == $item_id ) { |
|
401 | + if (is_array($cart_items)) { |
|
402 | + foreach ($cart_items as $item) { |
|
403 | + if ($item['id'] == $item_id) { |
|
404 | 404 | $ret = true; |
405 | 405 | break; |
406 | 406 | } |
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
410 | + return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
411 | 411 | } |
412 | 412 | |
413 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
413 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
414 | 414 | $tax = 0; |
415 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
416 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
417 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
415 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
416 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
417 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
418 | 418 | |
419 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
419 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
420 | 420 | } |
421 | 421 | |
422 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
422 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_cart_item_price( $item, $currency = '' ) { |
|
425 | +function wpinv_cart_item_price($item, $currency = '') { |
|
426 | 426 | |
427 | - if( empty( $currency ) ) { |
|
427 | + if (empty($currency)) { |
|
428 | 428 | $currency = wpinv_get_currency(); |
429 | 429 | } |
430 | 430 | |
431 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
432 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
433 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
431 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
432 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
433 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
434 | 434 | |
435 | - if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
436 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
435 | + if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
436 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
437 | 437 | $price += $tax; |
438 | 438 | } |
439 | 439 | |
440 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
440 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
441 | 441 | $price -= $tax; |
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | - $price = wpinv_price( wpinv_format_amount( $price ), $currency ); |
|
445 | + $price = wpinv_price(wpinv_format_amount($price), $currency); |
|
446 | 446 | |
447 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
447 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_cart_item_subtotal( $item, $currency = '' ) { |
|
450 | +function wpinv_cart_item_subtotal($item, $currency = '') { |
|
451 | 451 | |
452 | - if( empty( $currency ) ) { |
|
452 | + if (empty($currency)) { |
|
453 | 453 | $currency = wpinv_get_currency(); |
454 | 454 | } |
455 | 455 | |
456 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
457 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ), $currency ); |
|
456 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
457 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal), $currency); |
|
458 | 458 | |
459 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
459 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
460 | 460 | } |
461 | 461 | |
462 | -function wpinv_cart_item_tax( $item, $currency = '' ) { |
|
462 | +function wpinv_cart_item_tax($item, $currency = '') { |
|
463 | 463 | $tax = ''; |
464 | 464 | $tax_rate = ''; |
465 | 465 | |
466 | - if( empty( $currency ) ) { |
|
466 | + if (empty($currency)) { |
|
467 | 467 | $currency = wpinv_get_currency(); |
468 | 468 | } |
469 | 469 | |
470 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
471 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency ); |
|
472 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
473 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
470 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
471 | + $tax = wpinv_price(wpinv_format_amount($item['tax']), $currency); |
|
472 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
473 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
474 | 474 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
475 | 475 | } |
476 | 476 | |
477 | - $tax = $tax . $tax_rate; |
|
477 | + $tax = $tax . $tax_rate; |
|
478 | 478 | |
479 | - if ( $tax === '' ) { |
|
479 | + if ($tax === '') { |
|
480 | 480 | $tax = 0; // Zero tax |
481 | 481 | } |
482 | 482 | |
483 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
483 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
484 | 484 | } |
485 | 485 | |
486 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
486 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
487 | 487 | $price = 0; |
488 | 488 | |
489 | 489 | // Set custom price |
490 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
490 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
491 | 491 | $price = $cart_item['custom_price']; |
492 | 492 | } else { |
493 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
493 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
494 | 494 | |
495 | - if ( $variable_prices ) { |
|
496 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
495 | + if ($variable_prices) { |
|
496 | + $prices = wpinv_get_variable_prices($item_id); |
|
497 | 497 | |
498 | - if ( $prices ) { |
|
499 | - if( ! empty( $options ) ) { |
|
500 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
498 | + if ($prices) { |
|
499 | + if (!empty($options)) { |
|
500 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
501 | 501 | } else { |
502 | 502 | $price = false; |
503 | 503 | } |
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | - if( ! $variable_prices || false === $price ) { |
|
508 | - if($cart_item['item_price'] > 0){ |
|
507 | + if (!$variable_prices || false === $price) { |
|
508 | + if ($cart_item['item_price'] > 0) { |
|
509 | 509 | $price = $cart_item['item_price']; |
510 | 510 | } else { |
511 | 511 | // Get the standard Item price if not using variable prices |
512 | - $price = wpinv_get_item_price( $item_id ); |
|
512 | + $price = wpinv_get_item_price($item_id); |
|
513 | 513 | } |
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
518 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
517 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
518 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
519 | 519 | } |
520 | 520 | |
521 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
521 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
522 | 522 | } |
523 | 523 | |
524 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
525 | - if( isset( $item['item_number'] ) ) { |
|
526 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
524 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
525 | + if (isset($item['item_number'])) { |
|
526 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
527 | 527 | } else { |
528 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
528 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
529 | 529 | } |
530 | 530 | return $price_id; |
531 | 531 | } |
532 | 532 | |
533 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
534 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
535 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
536 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
537 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
533 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
534 | + $price_id = (int) wpinv_get_cart_item_price_id($item); |
|
535 | + $prices = wpinv_get_variable_prices($item['id']); |
|
536 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
537 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
541 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
540 | +function wpinv_get_cart_item_name($item = array()) { |
|
541 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
542 | 542 | |
543 | - if ( empty( $item_title ) ) { |
|
543 | + if (empty($item_title)) { |
|
544 | 544 | $item_title = $item['id']; |
545 | 545 | } |
546 | 546 | |
@@ -550,23 +550,23 @@ discard block |
||
550 | 550 | } |
551 | 551 | */ |
552 | 552 | |
553 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
553 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
554 | 554 | } |
555 | 555 | |
556 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
556 | +function wpinv_has_variable_prices($item_id = 0) { |
|
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
560 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
561 | 561 | $cart_items = wpinv_get_cart_contents(); |
562 | 562 | |
563 | - if ( !is_array( $cart_items ) ) { |
|
563 | + if (!is_array($cart_items)) { |
|
564 | 564 | return false; // Empty cart |
565 | 565 | } else { |
566 | - foreach ( $cart_items as $position => $item ) { |
|
567 | - if ( $item['id'] == $item_id ) { |
|
568 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
569 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
566 | + foreach ($cart_items as $position => $item) { |
|
567 | + if ($item['id'] == $item_id) { |
|
568 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
569 | + if ((int) $options['price_id'] == (int) $item['options']['price_id']) { |
|
570 | 570 | return $position; |
571 | 571 | } |
572 | 572 | } else { |
@@ -579,80 +579,80 @@ discard block |
||
579 | 579 | return false; // Not found |
580 | 580 | } |
581 | 581 | |
582 | -function wpinv_get_cart_item_quantity( $item ) { |
|
583 | - if ( wpinv_item_quantities_enabled() ) { |
|
584 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
582 | +function wpinv_get_cart_item_quantity($item) { |
|
583 | + if (wpinv_item_quantities_enabled()) { |
|
584 | + $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
585 | 585 | } else { |
586 | 586 | $quantity = 1; |
587 | 587 | } |
588 | 588 | |
589 | - if ( $quantity < 1 ) { |
|
589 | + if ($quantity < 1) { |
|
590 | 590 | $quantity = 1; |
591 | 591 | } |
592 | 592 | |
593 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
593 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
594 | 594 | } |
595 | 595 | |
596 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
597 | - if ( empty( $item ) ) { |
|
596 | +function wpinv_get_item_suffix($item, $html = true) { |
|
597 | + if (empty($item)) { |
|
598 | 598 | return NULL; |
599 | 599 | } |
600 | 600 | |
601 | - if ( is_int( $item ) ) { |
|
602 | - $item = new WPInv_Item( $item ); |
|
601 | + if (is_int($item)) { |
|
602 | + $item = new WPInv_Item($item); |
|
603 | 603 | } |
604 | 604 | |
605 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
605 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
606 | 606 | return NULL; |
607 | 607 | } |
608 | 608 | |
609 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
609 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
610 | 610 | |
611 | - if ( !$html && $suffix ) { |
|
612 | - $suffix = strip_tags( $suffix ); |
|
611 | + if (!$html && $suffix) { |
|
612 | + $suffix = strip_tags($suffix); |
|
613 | 613 | } |
614 | 614 | |
615 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
615 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
616 | 616 | } |
617 | 617 | |
618 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
619 | - if ( empty( $item ) ) { |
|
618 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
619 | + if (empty($item)) { |
|
620 | 620 | return NULL; |
621 | 621 | } |
622 | 622 | |
623 | - if ( is_int( $item ) ) { |
|
624 | - $item = new WPInv_Item( $item ); |
|
623 | + if (is_int($item)) { |
|
624 | + $item = new WPInv_Item($item); |
|
625 | 625 | } |
626 | 626 | |
627 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
627 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
628 | 628 | return NULL; |
629 | 629 | } |
630 | 630 | |
631 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
631 | + do_action('wpinv_pre_delete_item', $item); |
|
632 | 632 | |
633 | - wp_delete_post( $item->ID, $force_delete ); |
|
633 | + wp_delete_post($item->ID, $force_delete); |
|
634 | 634 | |
635 | - do_action( 'wpinv_post_delete_item', $item ); |
|
635 | + do_action('wpinv_post_delete_item', $item); |
|
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_can_delete_item( $post_id ) { |
|
638 | +function wpinv_can_delete_item($post_id) { |
|
639 | 639 | $return = wpinv_current_user_can_manage_invoicing() ? true : false; |
640 | 640 | |
641 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
641 | + if ($return && wpinv_item_in_use($post_id)) { |
|
642 | 642 | $return = false; // Don't delete item already use in invoices. |
643 | 643 | } |
644 | 644 | |
645 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
645 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | function wpinv_admin_action_delete() { |
649 | 649 | $screen = get_current_screen(); |
650 | 650 | |
651 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
651 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
652 | 652 | $post_ids = array(); |
653 | 653 | |
654 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
655 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
654 | + foreach ($_REQUEST['post'] as $post_id) { |
|
655 | + if (!wpinv_can_delete_item($post_id)) { |
|
656 | 656 | continue; |
657 | 657 | } |
658 | 658 | |
@@ -662,39 +662,39 @@ discard block |
||
662 | 662 | $_REQUEST['post'] = $post_ids; |
663 | 663 | } |
664 | 664 | } |
665 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
666 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
665 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
666 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
667 | 667 | |
668 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
669 | - if ( $post->post_type == 'wpi_item' ) { |
|
670 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
668 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
669 | + if ($post->post_type == 'wpi_item') { |
|
670 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
671 | 671 | return true; |
672 | 672 | } |
673 | 673 | } |
674 | 674 | |
675 | 675 | return $check; |
676 | 676 | } |
677 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
677 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
678 | 678 | |
679 | -function wpinv_item_in_use( $item_id ) { |
|
679 | +function wpinv_item_in_use($item_id) { |
|
680 | 680 | global $wpdb, $wpi_items_in_use; |
681 | 681 | |
682 | - if ( !$item_id > 0 ) { |
|
682 | + if (!$item_id > 0) { |
|
683 | 683 | return false; |
684 | 684 | } |
685 | 685 | |
686 | - if ( !empty( $wpi_items_in_use ) ) { |
|
687 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
686 | + if (!empty($wpi_items_in_use)) { |
|
687 | + if (isset($wpi_items_in_use[$item_id])) { |
|
688 | 688 | return $wpi_items_in_use[$item_id]; |
689 | 689 | } |
690 | 690 | } else { |
691 | 691 | $wpi_items_in_use = array(); |
692 | 692 | } |
693 | 693 | |
694 | - $statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
694 | + $statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
695 | 695 | |
696 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
697 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
696 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )"; |
|
697 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
698 | 698 | |
699 | 699 | $wpi_items_in_use[$item_id] = $in_use; |
700 | 700 | |
@@ -737,45 +737,45 @@ discard block |
||
737 | 737 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
738 | 738 | * @return bool|WP_Error|WPInv_Item |
739 | 739 | */ |
740 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
740 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
741 | 741 | |
742 | 742 | // Prepare the item. |
743 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
744 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
745 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
743 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
744 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
745 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
746 | 746 | |
747 | - if ( ! empty( $item ) ) { |
|
747 | + if (!empty($item)) { |
|
748 | 748 | $args['ID'] = $item->get_id(); |
749 | 749 | } |
750 | 750 | |
751 | 751 | } |
752 | 752 | |
753 | 753 | // Do we have an item? |
754 | - if ( ! empty( $args['ID'] ) ) { |
|
755 | - $item = new WPInv_Item( $args['ID'] ); |
|
754 | + if (!empty($args['ID'])) { |
|
755 | + $item = new WPInv_Item($args['ID']); |
|
756 | 756 | } else { |
757 | 757 | $item = new WPInv_Item(); |
758 | 758 | } |
759 | 759 | |
760 | 760 | // Do we have an error? |
761 | - if ( ! empty( $item->last_error ) ) { |
|
762 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
761 | + if (!empty($item->last_error)) { |
|
762 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | // Update item props. |
766 | - $item->set_props( $args ); |
|
766 | + $item->set_props($args); |
|
767 | 767 | |
768 | 768 | // Save the item. |
769 | 769 | $item->save(); |
770 | 770 | |
771 | 771 | // Do we have an error? |
772 | - if ( ! empty( $item->last_error ) ) { |
|
773 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
772 | + if (!empty($item->last_error)) { |
|
773 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | // Was the item saved? |
777 | - if ( ! $item->get_id() ) { |
|
778 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
777 | + if (!$item->get_id()) { |
|
778 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | return $item; |
@@ -787,14 +787,14 @@ discard block |
||
787 | 787 | * |
788 | 788 | * @see wpinv_create_item() |
789 | 789 | */ |
790 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
791 | - return wpinv_create_item( $args, $wp_error ); |
|
790 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
791 | + return wpinv_create_item($args, $wp_error); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
795 | 795 | * Sanitizes a recurring period |
796 | 796 | */ |
797 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
797 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
798 | 798 | |
799 | 799 | $periods = array( |
800 | 800 | 'D' => 'day', |
@@ -803,11 +803,11 @@ discard block |
||
803 | 803 | 'Y' => 'year', |
804 | 804 | ); |
805 | 805 | |
806 | - if ( ! isset( $periods[ $period ] ) ) { |
|
806 | + if (!isset($periods[$period])) { |
|
807 | 807 | $period = 'D'; |
808 | 808 | } |
809 | 809 | |
810 | - return $full ? $periods[ $period ] : $period; |
|
810 | + return $full ? $periods[$period] : $period; |
|
811 | 811 | |
812 | 812 | } |
813 | 813 | |
@@ -816,51 +816,51 @@ discard block |
||
816 | 816 | * |
817 | 817 | * @param WPInv_Item $item |
818 | 818 | */ |
819 | -function getpaid_item_recurring_price_help_text( $item, $currency = '' ) { |
|
819 | +function getpaid_item_recurring_price_help_text($item, $currency = '') { |
|
820 | 820 | |
821 | 821 | // Abort if it is not recurring. |
822 | - if ( ! $item->is_recurring() ) { |
|
822 | + if (!$item->is_recurring()) { |
|
823 | 823 | return ''; |
824 | 824 | } |
825 | 825 | |
826 | - $initial_price = wpinv_price( wpinv_sanitize_amount( $item->get_initial_price() ), $currency ); |
|
827 | - $recurring_price = wpinv_price( wpinv_sanitize_amount( $item->get_recurring_price() ), $currency ); |
|
828 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() ); |
|
829 | - $period = str_replace( '1 ', '', strtolower( $period ) ); |
|
826 | + $initial_price = wpinv_price(wpinv_sanitize_amount($item->get_initial_price()), $currency); |
|
827 | + $recurring_price = wpinv_price(wpinv_sanitize_amount($item->get_recurring_price()), $currency); |
|
828 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_recurring_period(), $item->get_recurring_interval()); |
|
829 | + $period = str_replace('1 ', '', strtolower($period)); |
|
830 | 830 | |
831 | 831 | // For free trial items. |
832 | - if ( $item->has_free_trial() ) { |
|
833 | - $trial_period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_trial_period(), $item->get_trial_interval() ); |
|
832 | + if ($item->has_free_trial()) { |
|
833 | + $trial_period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_trial_period(), $item->get_trial_interval()); |
|
834 | 834 | |
835 | - if ( 0 == $item->get_initial_price() ) { |
|
835 | + if (0 == $item->get_initial_price()) { |
|
836 | 836 | return sprintf( |
837 | - __( 'Free for %s then %s every %s', 'invoicing' ), |
|
838 | - strtolower( $trial_period ), |
|
837 | + __('Free for %s then %s every %s', 'invoicing'), |
|
838 | + strtolower($trial_period), |
|
839 | 839 | $recurring_price, |
840 | 840 | $period |
841 | 841 | ); |
842 | 842 | } |
843 | 843 | |
844 | 844 | return sprintf( |
845 | - __( '%s for %s then %s every %s', 'invoicing' ), |
|
845 | + __('%s for %s then %s every %s', 'invoicing'), |
|
846 | 846 | $initial_price, |
847 | - strtolower( $trial_period ), |
|
847 | + strtolower($trial_period), |
|
848 | 848 | $recurring_price, |
849 | 849 | $period |
850 | 850 | ); |
851 | 851 | |
852 | 852 | } |
853 | 853 | |
854 | - if ( $initial_price == $recurring_price ) { |
|
854 | + if ($initial_price == $recurring_price) { |
|
855 | 855 | return sprintf( |
856 | - __( '%s every %s', 'invoicing' ), |
|
856 | + __('%s every %s', 'invoicing'), |
|
857 | 857 | $recurring_price, |
858 | 858 | $period |
859 | 859 | ); |
860 | 860 | } |
861 | 861 | |
862 | 862 | return sprintf( |
863 | - __( '%s for %s then %s every %s', 'invoicing' ), |
|
863 | + __('%s for %s then %s every %s', 'invoicing'), |
|
864 | 864 | $initial_price, |
865 | 865 | $period, |
866 | 866 | $recurring_price, |
@@ -283,8 +283,9 @@ |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
286 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
287 | - return; |
|
286 | + if ( 'wpi_item' !== get_post_type( $item_id ) ) { |
|
287 | + return; |
|
288 | + } |
|
288 | 289 | |
289 | 290 | global $wpinv_logs; |
290 | 291 |