@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if ( !defined('ABSPATH') ) { |
|
4 | 4 | die('-1'); |
5 | +} |
|
5 | 6 | |
6 | 7 | do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
7 | 8 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if ( !defined('ABSPATH') ) { |
|
4 | 4 | die('-1'); |
5 | +} |
|
5 | 6 | |
6 | 7 | do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
7 | 8 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if ( !defined('ABSPATH') ) { |
|
4 | 4 | die('-1'); |
5 | +} |
|
5 | 6 | |
6 | 7 | do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
7 | 8 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if ( !defined('ABSPATH') ) { |
|
4 | 4 | die('-1'); |
5 | +} |
|
5 | 6 | |
6 | 7 | do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
7 | 8 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,156 +1,156 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
4 | - if ( empty( $invoice ) ) { |
|
3 | +function wpinv_is_subscription_payment($invoice = '') { |
|
4 | + if (empty($invoice)) { |
|
5 | 5 | return false; |
6 | 6 | } |
7 | 7 | |
8 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
9 | - $invoice = wpinv_get_invoice( $invoice ); |
|
8 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
9 | + $invoice = wpinv_get_invoice($invoice); |
|
10 | 10 | } |
11 | 11 | |
12 | - if ( empty( $invoice ) ) { |
|
12 | + if (empty($invoice)) { |
|
13 | 13 | return false; |
14 | 14 | } |
15 | 15 | |
16 | - if ( $invoice->is_renewal() ) { |
|
16 | + if ($invoice->is_renewal()) { |
|
17 | 17 | return true; |
18 | 18 | } |
19 | 19 | |
20 | 20 | return false; |
21 | 21 | } |
22 | 22 | |
23 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
24 | - if ( empty( $invoice ) ) { |
|
23 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
24 | + if (empty($invoice)) { |
|
25 | 25 | return false; |
26 | 26 | } |
27 | 27 | |
28 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
29 | - $invoice = wpinv_get_invoice( $invoice ); |
|
28 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
29 | + $invoice = wpinv_get_invoice($invoice); |
|
30 | 30 | } |
31 | 31 | |
32 | - if ( empty( $invoice ) ) { |
|
32 | + if (empty($invoice)) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | |
36 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
36 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
37 | 37 | } |
38 | 38 | |
39 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
39 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
40 | 40 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
41 | 41 | |
42 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
43 | - $amount = __( 'Free', 'invoicing' ); |
|
42 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
43 | + $amount = __('Free', 'invoicing'); |
|
44 | 44 | $interval = $trial_interval; |
45 | 45 | $period = $trial_period; |
46 | 46 | } |
47 | 47 | |
48 | 48 | $description = ''; |
49 | - switch ( $period ) { |
|
49 | + switch ($period) { |
|
50 | 50 | case 'D' : |
51 | 51 | case 'day' : |
52 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
52 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
53 | 53 | break; |
54 | 54 | case 'W' : |
55 | 55 | case 'week' : |
56 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
56 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
57 | 57 | break; |
58 | 58 | case 'M' : |
59 | 59 | case 'month' : |
60 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
60 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
61 | 61 | break; |
62 | 62 | case 'Y' : |
63 | 63 | case 'year' : |
64 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
64 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
65 | 65 | break; |
66 | 66 | } |
67 | 67 | |
68 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
68 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
69 | 69 | } |
70 | 70 | |
71 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
71 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
72 | 72 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
73 | 73 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
74 | 74 | |
75 | 75 | $description = ''; |
76 | - switch ( $period ) { |
|
76 | + switch ($period) { |
|
77 | 77 | case 'D' : |
78 | 78 | case 'day' : |
79 | - if ( (int)$bill_times > 0 ) { |
|
80 | - if ( $interval > 1 ) { |
|
81 | - if ( $bill_times > 1 ) { |
|
82 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
79 | + if ((int)$bill_times > 0) { |
|
80 | + if ($interval > 1) { |
|
81 | + if ($bill_times > 1) { |
|
82 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
83 | 83 | } else { |
84 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
84 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
85 | 85 | } |
86 | 86 | } else { |
87 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
87 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
88 | 88 | } |
89 | 89 | } else { |
90 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
90 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
91 | 91 | } |
92 | 92 | break; |
93 | 93 | case 'W' : |
94 | 94 | case 'week' : |
95 | - if ( (int)$bill_times > 0 ) { |
|
96 | - if ( $interval > 1 ) { |
|
97 | - if ( $bill_times > 1 ) { |
|
98 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
95 | + if ((int)$bill_times > 0) { |
|
96 | + if ($interval > 1) { |
|
97 | + if ($bill_times > 1) { |
|
98 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
99 | 99 | } else { |
100 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
100 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
101 | 101 | } |
102 | 102 | } else { |
103 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
103 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
104 | 104 | } |
105 | 105 | } else { |
106 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
106 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
107 | 107 | } |
108 | 108 | break; |
109 | 109 | case 'M' : |
110 | 110 | case 'month' : |
111 | - if ( (int)$bill_times > 0 ) { |
|
112 | - if ( $interval > 1 ) { |
|
113 | - if ( $bill_times > 1 ) { |
|
114 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
111 | + if ((int)$bill_times > 0) { |
|
112 | + if ($interval > 1) { |
|
113 | + if ($bill_times > 1) { |
|
114 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
115 | 115 | } else { |
116 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
116 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
117 | 117 | } |
118 | 118 | } else { |
119 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
119 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
120 | 120 | } |
121 | 121 | } else { |
122 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
122 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
123 | 123 | } |
124 | 124 | break; |
125 | 125 | case 'Y' : |
126 | 126 | case 'year' : |
127 | - if ( (int)$bill_times > 0 ) { |
|
128 | - if ( $interval > 1 ) { |
|
129 | - if ( $bill_times > 1 ) { |
|
130 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
127 | + if ((int)$bill_times > 0) { |
|
128 | + if ($interval > 1) { |
|
129 | + if ($bill_times > 1) { |
|
130 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
131 | 131 | } else { |
132 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
132 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
133 | 133 | } |
134 | 134 | } else { |
135 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
135 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
136 | 136 | } |
137 | 137 | } else { |
138 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
138 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
139 | 139 | } |
140 | 140 | break; |
141 | 141 | } |
142 | 142 | |
143 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
143 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
144 | 144 | } |
145 | 145 | |
146 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
147 | - if ( empty( $invoice ) ) { |
|
146 | +function wpinv_subscription_payment_desc($invoice) { |
|
147 | + if (empty($invoice)) { |
|
148 | 148 | return NULL; |
149 | 149 | } |
150 | 150 | |
151 | 151 | $description = ''; |
152 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
153 | - if ( $item->has_free_trial() ) { |
|
152 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
153 | + if ($item->has_free_trial()) { |
|
154 | 154 | $trial_period = $item->get_trial_period(); |
155 | 155 | $trial_interval = $item->get_trial_interval(); |
156 | 156 | } else { |
@@ -158,45 +158,45 @@ discard block |
||
158 | 158 | $trial_interval = 0; |
159 | 159 | } |
160 | 160 | |
161 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
161 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
162 | 162 | } |
163 | 163 | |
164 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
164 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
165 | 165 | } |
166 | 166 | |
167 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
168 | - $initial_total = wpinv_round_amount( $initial ); |
|
169 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
167 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
168 | + $initial_total = wpinv_round_amount($initial); |
|
169 | + $recurring_total = wpinv_round_amount($recurring); |
|
170 | 170 | |
171 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
171 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
172 | 172 | // Free trial |
173 | 173 | } else { |
174 | - if ( $bill_times == 1 ) { |
|
174 | + if ($bill_times == 1) { |
|
175 | 175 | $recurring_total = $initial_total; |
176 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
176 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
177 | 177 | $bill_times--; |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency ); |
|
182 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency ); |
|
181 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency); |
|
182 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency); |
|
183 | 183 | |
184 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
184 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
185 | 185 | |
186 | - if ( $initial_total != $recurring_total ) { |
|
187 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
186 | + if ($initial_total != $recurring_total) { |
|
187 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
188 | 188 | |
189 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
189 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
190 | 190 | } else { |
191 | 191 | $description = $recurring; |
192 | 192 | } |
193 | 193 | |
194 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
194 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
198 | - if ( !empty( $invoice->ID ) ) { |
|
199 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
197 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
198 | + if (!empty($invoice->ID)) { |
|
199 | + wpinv_failed_invoice_notification($invoice->ID); |
|
200 | 200 | } |
201 | 201 | } |
202 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
203 | 202 | \ No newline at end of file |
203 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
204 | 204 | \ No newline at end of file |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) { |
|
6 | - if ( empty( $user ) ) { |
|
5 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC') { |
|
6 | + if (empty($user)) { |
|
7 | 7 | $user = get_current_user_id(); |
8 | 8 | } |
9 | 9 | |
10 | - if ( empty( $user ) ) { |
|
10 | + if (empty($user)) { |
|
11 | 11 | return false; |
12 | 12 | } |
13 | 13 | |
14 | - $args = apply_filters( 'wpinv_get_users_invoices_args', array( 'user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order ) ); |
|
14 | + $args = apply_filters('wpinv_get_users_invoices_args', array('user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order)); |
|
15 | 15 | |
16 | - return wpinv_get_invoices( $args ); |
|
16 | + return wpinv_get_invoices($args); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_dropdown_users( $args = '' ) { |
|
19 | +function wpinv_dropdown_users($args = '') { |
|
20 | 20 | $defaults = array( |
21 | 21 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
22 | 22 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | 'option_none_value' => -1 |
28 | 28 | ); |
29 | 29 | |
30 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
30 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
31 | 31 | |
32 | - $r = wp_parse_args( $args, $defaults ); |
|
32 | + $r = wp_parse_args($args, $defaults); |
|
33 | 33 | |
34 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
34 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
35 | 35 | |
36 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
36 | + $fields = array('ID', 'user_login', 'user_email'); |
|
37 | 37 | |
38 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
39 | - if ( 'display_name_with_login' === $show ) { |
|
38 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
39 | + if ('display_name_with_login' === $show) { |
|
40 | 40 | $fields[] = 'display_name'; |
41 | - } else if ( 'display_name_with_email' === $show ) { |
|
41 | + } else if ('display_name_with_email' === $show) { |
|
42 | 42 | $fields[] = 'display_name'; |
43 | 43 | } else { |
44 | 44 | $fields[] = $show; |
@@ -50,99 +50,99 @@ discard block |
||
50 | 50 | $show_option_none = $r['show_option_none']; |
51 | 51 | $option_none_value = $r['option_none_value']; |
52 | 52 | |
53 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
53 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
54 | 54 | |
55 | - $users = get_users( $query_args ); |
|
55 | + $users = get_users($query_args); |
|
56 | 56 | |
57 | 57 | $output = ''; |
58 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
59 | - $name = esc_attr( $r['name'] ); |
|
60 | - if ( $r['multi'] && ! $r['id'] ) { |
|
58 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
59 | + $name = esc_attr($r['name']); |
|
60 | + if ($r['multi'] && !$r['id']) { |
|
61 | 61 | $id = ''; |
62 | 62 | } else { |
63 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
63 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
64 | 64 | } |
65 | 65 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
66 | 66 | |
67 | - if ( $show_option_all ) { |
|
67 | + if ($show_option_all) { |
|
68 | 68 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
69 | 69 | } |
70 | 70 | |
71 | - if ( $show_option_none ) { |
|
72 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
73 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
71 | + if ($show_option_none) { |
|
72 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
73 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
76 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
77 | 77 | $found_selected = false; |
78 | - $r['selected'] = (int) $r['selected']; |
|
79 | - foreach ( (array) $users as $user ) { |
|
80 | - $user->ID = (int) $user->ID; |
|
81 | - if ( $user->ID === $r['selected'] ) { |
|
78 | + $r['selected'] = (int)$r['selected']; |
|
79 | + foreach ((array)$users as $user) { |
|
80 | + $user->ID = (int)$user->ID; |
|
81 | + if ($user->ID === $r['selected']) { |
|
82 | 82 | $found_selected = true; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - if ( ! $found_selected ) { |
|
87 | - $users[] = get_userdata( $r['selected'] ); |
|
86 | + if (!$found_selected) { |
|
87 | + $users[] = get_userdata($r['selected']); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - foreach ( (array) $users as $user ) { |
|
92 | - if ( 'display_name_with_login' === $show ) { |
|
91 | + foreach ((array)$users as $user) { |
|
92 | + if ('display_name_with_login' === $show) { |
|
93 | 93 | /* translators: 1: display name, 2: user_login */ |
94 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
95 | - } elseif ( 'display_name_with_email' === $show ) { |
|
94 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
95 | + } elseif ('display_name_with_email' === $show) { |
|
96 | 96 | /* translators: 1: display name, 2: user_email */ |
97 | - if ( $user->display_name == $user->user_email ) { |
|
97 | + if ($user->display_name == $user->user_email) { |
|
98 | 98 | $display = $user->display_name; |
99 | 99 | } else { |
100 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
100 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
101 | 101 | } |
102 | - } elseif ( ! empty( $user->$show ) ) { |
|
102 | + } elseif (!empty($user->$show)) { |
|
103 | 103 | $display = $user->$show; |
104 | 104 | } else { |
105 | 105 | $display = '(' . $user->user_login . ')'; |
106 | 106 | } |
107 | 107 | |
108 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
109 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
108 | + $_selected = selected($user->ID, $r['selected'], false); |
|
109 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $output .= "</select>"; |
113 | 113 | } |
114 | 114 | |
115 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
115 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
116 | 116 | |
117 | - if ( $r['echo'] ) { |
|
117 | + if ($r['echo']) { |
|
118 | 118 | echo $html; |
119 | 119 | } |
120 | 120 | return $html; |
121 | 121 | } |
122 | 122 | |
123 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
124 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
125 | - wpinv_login_user( $user_id ); |
|
123 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
124 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
125 | + wpinv_login_user($user_id); |
|
126 | 126 | } else { |
127 | - $redirect_to = wp_login_url( $redirect_to ); |
|
127 | + $redirect_to = wp_login_url($redirect_to); |
|
128 | 128 | } |
129 | 129 | |
130 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
130 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
131 | 131 | |
132 | - wp_redirect( $redirect_to ); |
|
132 | + wp_redirect($redirect_to); |
|
133 | 133 | } |
134 | 134 | |
135 | -function wpinv_login_user( $user_id ) { |
|
136 | - if ( is_user_logged_in() ) { |
|
135 | +function wpinv_login_user($user_id) { |
|
136 | + if (is_user_logged_in()) { |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - $user = get_user_by( 'id', $user_id ); |
|
140 | + $user = get_user_by('id', $user_id); |
|
141 | 141 | |
142 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
143 | - wp_set_current_user( $user_id, $user->user_login ); |
|
144 | - wp_set_auth_cookie( $user_id ); |
|
145 | - do_action( 'wp_login', $user->user_login ); |
|
142 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
143 | + wp_set_current_user($user_id, $user->user_login); |
|
144 | + wp_set_auth_cookie($user_id); |
|
145 | + do_action('wp_login', $user->user_login); |
|
146 | 146 | |
147 | 147 | return true; |
148 | 148 | } |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) { |
6 | 8 | if ( empty( $user ) ) { |
@@ -22,6 +22,9 @@ |
||
22 | 22 | add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' ); |
23 | 23 | } |
24 | 24 | |
25 | + /** |
|
26 | + * @param string[] $function |
|
27 | + */ |
|
25 | 28 | public static function shortcode_wrapper( $function, $atts = array(), $content = null, $wrapper = array( 'class' => 'wpi-g', 'before' => null, 'after' => null ) ) { |
26 | 29 | ob_start(); |
27 | 30 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -16,41 +16,41 @@ discard block |
||
16 | 16 | 'wpinv_subscriptions' => __CLASS__ . '::subscriptions', |
17 | 17 | ); |
18 | 18 | |
19 | - foreach ( $shortcodes as $shortcode => $function ) { |
|
20 | - add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); |
|
19 | + foreach ($shortcodes as $shortcode => $function) { |
|
20 | + add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function); |
|
21 | 21 | } |
22 | 22 | |
23 | - add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' ); |
|
23 | + add_shortcode('wpinv_messages', __CLASS__ . '::messages'); |
|
24 | 24 | } |
25 | 25 | |
26 | - public static function shortcode_wrapper( $function, $atts = array(), $content = null, $wrapper = array( 'class' => 'wpi-g', 'before' => null, 'after' => null ) ) { |
|
26 | + public static function shortcode_wrapper($function, $atts = array(), $content = null, $wrapper = array('class' => 'wpi-g', 'before' => null, 'after' => null)) { |
|
27 | 27 | ob_start(); |
28 | 28 | |
29 | - echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before']; |
|
30 | - call_user_func( $function, $atts, $content ); |
|
31 | - echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after']; |
|
29 | + echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before']; |
|
30 | + call_user_func($function, $atts, $content); |
|
31 | + echo empty($wrapper['after']) ? '</div>' : $wrapper['after']; |
|
32 | 32 | |
33 | 33 | return ob_get_clean(); |
34 | 34 | } |
35 | 35 | |
36 | - public static function checkout( $atts = array(), $content = null ) { |
|
37 | - return self::shortcode_wrapper( array( __CLASS__, 'checkout_output' ), $atts, $content ); |
|
36 | + public static function checkout($atts = array(), $content = null) { |
|
37 | + return self::shortcode_wrapper(array(__CLASS__, 'checkout_output'), $atts, $content); |
|
38 | 38 | } |
39 | 39 | |
40 | - public static function checkout_output( $atts = array(), $content = null ) { |
|
41 | - do_action( 'wpinv_checkout_content_before' ); |
|
42 | - echo wpinv_checkout_form( $atts, $content ); |
|
43 | - do_action( 'wpinv_checkout_content_after' ); |
|
40 | + public static function checkout_output($atts = array(), $content = null) { |
|
41 | + do_action('wpinv_checkout_content_before'); |
|
42 | + echo wpinv_checkout_form($atts, $content); |
|
43 | + do_action('wpinv_checkout_content_after'); |
|
44 | 44 | } |
45 | 45 | |
46 | - public static function messages( $atts, $content = null ) { |
|
46 | + public static function messages($atts, $content = null) { |
|
47 | 47 | ob_start(); |
48 | 48 | wpinv_print_errors(); |
49 | 49 | return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
50 | 50 | } |
51 | 51 | |
52 | - public static function history( $atts, $content = null ) { |
|
53 | - return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts ); |
|
52 | + public static function history($atts, $content = null) { |
|
53 | + return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @param array $atts |
60 | 60 | */ |
61 | - public static function history_output( $atts ) { |
|
62 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
63 | - wpinv_get_template_part( 'wpinv-invoice-history', $atts ); |
|
64 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
61 | + public static function history_output($atts) { |
|
62 | + do_action('wpinv_before_user_invoice_history'); |
|
63 | + wpinv_get_template_part('wpinv-invoice-history', $atts); |
|
64 | + do_action('wpinv_after_user_invoice_history'); |
|
65 | 65 | } |
66 | 66 | |
67 | - public static function success( $atts, $content = null ) { |
|
68 | - return self::shortcode_wrapper( array( __CLASS__, 'success_output' ), $atts, $content ); |
|
67 | + public static function success($atts, $content = null) { |
|
68 | + return self::shortcode_wrapper(array(__CLASS__, 'success_output'), $atts, $content); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -73,31 +73,31 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @param array $atts |
75 | 75 | */ |
76 | - public static function success_output( $atts, $content = null ) { |
|
77 | - do_action( 'wpinv_success_content_before' ); |
|
78 | - echo wpinv_payment_receipt( $atts, $content ); |
|
79 | - do_action( 'wpinv_success_content_after' ); |
|
76 | + public static function success_output($atts, $content = null) { |
|
77 | + do_action('wpinv_success_content_before'); |
|
78 | + echo wpinv_payment_receipt($atts, $content); |
|
79 | + do_action('wpinv_success_content_after'); |
|
80 | 80 | } |
81 | 81 | |
82 | - public static function buy( $atts, $content = null ) { |
|
83 | - $a = shortcode_atts( array( |
|
82 | + public static function buy($atts, $content = null) { |
|
83 | + $a = shortcode_atts(array( |
|
84 | 84 | 'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity |
85 | - 'title' => __( 'Buy Now', 'invoicing' ), // the button title |
|
85 | + 'title' => __('Buy Now', 'invoicing'), // the button title |
|
86 | 86 | 'post_id' => '', // any related post_id |
87 | - ), $atts ); |
|
87 | + ), $atts); |
|
88 | 88 | |
89 | - $post_id = isset( $a['post_id'] ) ? (int)$a['post_id'] : ''; |
|
89 | + $post_id = isset($a['post_id']) ? (int)$a['post_id'] : ''; |
|
90 | 90 | |
91 | 91 | $html = '<div class="wpi-buy-button-wrapper wpi-g">'; |
92 | 92 | $html .= '<button class="button button-primary wpi-buy-button" type="button" onclick="wpi_buy(this,\'' . $a['items'] . '\',' . $post_id . ');">' . $a['title'] . '</button>'; |
93 | - $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false ); |
|
93 | + $html .= wp_nonce_field('wpinv_buy_items', 'wpinv_buy_nonce', true, false); |
|
94 | 94 | $html .= '</div>'; |
95 | 95 | |
96 | 96 | return $html; |
97 | 97 | } |
98 | 98 | |
99 | - public static function subscriptions( $atts, $content = null ) { |
|
100 | - return self::shortcode_wrapper( array( __CLASS__, 'subscriptions_output' ), $atts ); |
|
99 | + public static function subscriptions($atts, $content = null) { |
|
100 | + return self::shortcode_wrapper(array(__CLASS__, 'subscriptions_output'), $atts); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @param array $atts |
107 | 107 | */ |
108 | - public static function subscriptions_output( $atts ) { |
|
109 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
110 | - wpinv_get_template_part( 'wpinv-subscriptions-history', $atts ); |
|
111 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
108 | + public static function subscriptions_output($atts) { |
|
109 | + do_action('wpinv_before_user_subscriptions'); |
|
110 | + wpinv_get_template_part('wpinv-subscriptions-history', $atts); |
|
111 | + do_action('wpinv_after_user_subscriptions'); |
|
112 | 112 | } |
113 | 113 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * Retrieves the transaction ID from the subscription |
371 | 371 | * |
372 | 372 | * @since 1.0.0 |
373 | - * @return bool |
|
373 | + * @return string |
|
374 | 374 | */ |
375 | 375 | public function get_transaction_id() { |
376 | 376 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * Stores the transaction ID for the subscription purchase |
393 | 393 | * |
394 | 394 | * @since 1.0.0.4 |
395 | - * @return bool |
|
395 | + * @return boolean|null |
|
396 | 396 | */ |
397 | 397 | public function set_transaction_id( $txn_id = '' ) { |
398 | 398 | $this->update( array( 'transaction_id' => $txn_id ) ); |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * Renews a subscription |
404 | 404 | * |
405 | 405 | * @since 1.0.0 |
406 | - * @return bool |
|
406 | + * @return boolean|null |
|
407 | 407 | */ |
408 | 408 | public function renew() { |
409 | 409 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | * |
493 | 493 | * @since 1.0.0 |
494 | 494 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
495 | - * @return void |
|
495 | + * @return false|null |
|
496 | 496 | */ |
497 | 497 | public function expire( $check_expiration = false ) { |
498 | 498 | |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * Retrieves the subscription status |
745 | 745 | * |
746 | 746 | * @since 1.0.0 |
747 | - * @return int |
|
747 | + * @return string |
|
748 | 748 | */ |
749 | 749 | public function get_status() { |
750 | 750 |
@@ -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,183 +13,183 @@ 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 | - return $ret; |
|
180 | + return $ret; |
|
181 | 181 | |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Delete the subscription |
|
186 | - * |
|
187 | - * @since 1.0.0 |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - public function delete() { |
|
191 | - return $this->subs_db->delete( $this->id ); |
|
192 | - } |
|
184 | + /** |
|
185 | + * Delete the subscription |
|
186 | + * |
|
187 | + * @since 1.0.0 |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + public function delete() { |
|
191 | + return $this->subs_db->delete( $this->id ); |
|
192 | + } |
|
193 | 193 | |
194 | 194 | /** |
195 | 195 | * Retrieves the parent payment ID |
@@ -366,185 +366,185 @@ discard block |
||
366 | 366 | return false; |
367 | 367 | } |
368 | 368 | |
369 | - /** |
|
370 | - * Retrieves the transaction ID from the subscription |
|
371 | - * |
|
372 | - * @since 1.0.0 |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function get_transaction_id() { |
|
369 | + /** |
|
370 | + * Retrieves the transaction ID from the subscription |
|
371 | + * |
|
372 | + * @since 1.0.0 |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function get_transaction_id() { |
|
376 | 376 | |
377 | - if( empty( $this->transaction_id ) ) { |
|
377 | + if( empty( $this->transaction_id ) ) { |
|
378 | 378 | |
379 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
379 | + $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
380 | 380 | |
381 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | - $this->set_transaction_id( $txn_id ); |
|
383 | - } |
|
381 | + if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | + $this->set_transaction_id( $txn_id ); |
|
383 | + } |
|
384 | 384 | |
385 | - } |
|
385 | + } |
|
386 | 386 | |
387 | - return $this->transaction_id; |
|
387 | + return $this->transaction_id; |
|
388 | 388 | |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | - /** |
|
392 | - * Stores the transaction ID for the subscription purchase |
|
393 | - * |
|
394 | - * @since 1.0.0.4 |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
399 | - $this->transaction_id = $txn_id; |
|
400 | - } |
|
391 | + /** |
|
392 | + * Stores the transaction ID for the subscription purchase |
|
393 | + * |
|
394 | + * @since 1.0.0.4 |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function set_transaction_id( $txn_id = '' ) { |
|
398 | + $this->update( array( 'transaction_id' => $txn_id ) ); |
|
399 | + $this->transaction_id = $txn_id; |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Renews a subscription |
|
404 | - * |
|
405 | - * @since 1.0.0 |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function renew() { |
|
402 | + /** |
|
403 | + * Renews a subscription |
|
404 | + * |
|
405 | + * @since 1.0.0 |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function renew() { |
|
409 | 409 | |
410 | - $expires = $this->get_expiration_time(); |
|
410 | + $expires = $this->get_expiration_time(); |
|
411 | 411 | |
412 | 412 | |
413 | - // Determine what date to use as the start for the new expiration calculation |
|
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
413 | + // Determine what date to use as the start for the new expiration calculation |
|
414 | + if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | - } else { |
|
418 | + } else { |
|
419 | 419 | |
420 | - $base_date = current_time( 'timestamp' ); |
|
420 | + $base_date = current_time( 'timestamp' ); |
|
421 | 421 | |
422 | - } |
|
422 | + } |
|
423 | 423 | |
424 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
424 | + $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
425 | 425 | |
426 | 426 | |
427 | - $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
428 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
427 | + $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
428 | + $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
429 | 429 | |
430 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
432 | - } |
|
430 | + if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | + $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
432 | + } |
|
433 | 433 | |
434 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
434 | + $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
435 | 435 | |
436 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
436 | + do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
437 | 437 | |
438 | - $this->status = 'active'; |
|
439 | - $times_billed = $this->get_times_billed(); |
|
438 | + $this->status = 'active'; |
|
439 | + $times_billed = $this->get_times_billed(); |
|
440 | 440 | |
441 | - // Complete subscription if applicable |
|
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
443 | - $this->complete(); |
|
444 | - $this->status = 'completed'; |
|
445 | - } |
|
441 | + // Complete subscription if applicable |
|
442 | + if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
443 | + $this->complete(); |
|
444 | + $this->status = 'completed'; |
|
445 | + } |
|
446 | 446 | |
447 | - $args = array( |
|
448 | - 'expiration' => $expiration, |
|
449 | - 'status' => $this->status, |
|
450 | - ); |
|
447 | + $args = array( |
|
448 | + 'expiration' => $expiration, |
|
449 | + 'status' => $this->status, |
|
450 | + ); |
|
451 | 451 | |
452 | 452 | $this->subs_db->update( $this->id, $args ); |
453 | 453 | |
454 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
454 | + do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | + do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
456 | 456 | |
457 | - } |
|
457 | + } |
|
458 | 458 | |
459 | - /** |
|
460 | - * Marks a subscription as completed |
|
461 | - * |
|
462 | - * Subscription is completed when the number of payments matches the billing_times field |
|
463 | - * |
|
464 | - * @since 1.0.0 |
|
465 | - * @return void |
|
466 | - */ |
|
467 | - public function complete() { |
|
459 | + /** |
|
460 | + * Marks a subscription as completed |
|
461 | + * |
|
462 | + * Subscription is completed when the number of payments matches the billing_times field |
|
463 | + * |
|
464 | + * @since 1.0.0 |
|
465 | + * @return void |
|
466 | + */ |
|
467 | + public function complete() { |
|
468 | 468 | |
469 | - // Only mark a subscription as complete if it's not already cancelled. |
|
470 | - if ( 'cancelled' === $this->status ) { |
|
471 | - return; |
|
472 | - } |
|
469 | + // Only mark a subscription as complete if it's not already cancelled. |
|
470 | + if ( 'cancelled' === $this->status ) { |
|
471 | + return; |
|
472 | + } |
|
473 | 473 | |
474 | - $args = array( |
|
475 | - 'status' => 'completed' |
|
476 | - ); |
|
474 | + $args = array( |
|
475 | + 'status' => 'completed' |
|
476 | + ); |
|
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
479 | 479 | |
480 | - $this->status = 'completed'; |
|
480 | + $this->status = 'completed'; |
|
481 | 481 | |
482 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
482 | + do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
483 | 483 | |
484 | - } |
|
484 | + } |
|
485 | 485 | |
486 | - } |
|
486 | + } |
|
487 | 487 | |
488 | - /** |
|
489 | - * Marks a subscription as expired |
|
490 | - * |
|
491 | - * Subscription is completed when the billing times is reached |
|
492 | - * |
|
493 | - * @since 1.0.0 |
|
494 | - * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
495 | - * @return void |
|
496 | - */ |
|
497 | - public function expire( $check_expiration = false ) { |
|
488 | + /** |
|
489 | + * Marks a subscription as expired |
|
490 | + * |
|
491 | + * Subscription is completed when the billing times is reached |
|
492 | + * |
|
493 | + * @since 1.0.0 |
|
494 | + * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
495 | + * @return void |
|
496 | + */ |
|
497 | + public function expire( $check_expiration = false ) { |
|
498 | 498 | |
499 | - $expiration = $this->expiration; |
|
499 | + $expiration = $this->expiration; |
|
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if( $check_expiration ) { |
|
502 | 502 | |
503 | - // check_expiration() updates $this->expiration so compare to $expiration above |
|
503 | + // check_expiration() updates $this->expiration so compare to $expiration above |
|
504 | 504 | |
505 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
505 | + if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
506 | 506 | |
507 | - return false; // Do not mark as expired since real expiration date is in the future |
|
508 | - } |
|
507 | + return false; // Do not mark as expired since real expiration date is in the future |
|
508 | + } |
|
509 | 509 | |
510 | - } |
|
510 | + } |
|
511 | 511 | |
512 | - $args = array( |
|
513 | - 'status' => 'expired' |
|
514 | - ); |
|
512 | + $args = array( |
|
513 | + 'status' => 'expired' |
|
514 | + ); |
|
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
517 | 517 | |
518 | - $this->status = 'expired'; |
|
518 | + $this->status = 'expired'; |
|
519 | 519 | |
520 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
520 | + do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
521 | 521 | |
522 | - } |
|
522 | + } |
|
523 | 523 | |
524 | - } |
|
524 | + } |
|
525 | 525 | |
526 | - /** |
|
527 | - * Marks a subscription as failing |
|
528 | - * |
|
529 | - * @since 2.4.2 |
|
530 | - * @return void |
|
531 | - */ |
|
532 | - public function failing() { |
|
526 | + /** |
|
527 | + * Marks a subscription as failing |
|
528 | + * |
|
529 | + * @since 2.4.2 |
|
530 | + * @return void |
|
531 | + */ |
|
532 | + public function failing() { |
|
533 | 533 | |
534 | - $args = array( |
|
535 | - 'status' => 'failing' |
|
536 | - ); |
|
534 | + $args = array( |
|
535 | + 'status' => 'failing' |
|
536 | + ); |
|
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
539 | 539 | |
540 | - $this->status = 'failing'; |
|
540 | + $this->status = 'failing'; |
|
541 | 541 | |
542 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
542 | + do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
543 | 543 | |
544 | 544 | |
545 | - } |
|
545 | + } |
|
546 | 546 | |
547 | - } |
|
547 | + } |
|
548 | 548 | |
549 | 549 | /** |
550 | 550 | * Marks a subscription as cancelled |
@@ -578,22 +578,22 @@ discard block |
||
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
581 | - /** |
|
582 | - * Determines if subscription can be cancelled |
|
583 | - * |
|
584 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
585 | - * that can be cancelled with a profile ID through the merchant processor |
|
586 | - * |
|
587 | - * @since 1.0.0 |
|
588 | - * @return bool |
|
589 | - */ |
|
590 | - public function can_cancel() { |
|
581 | + /** |
|
582 | + * Determines if subscription can be cancelled |
|
583 | + * |
|
584 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
585 | + * that can be cancelled with a profile ID through the merchant processor |
|
586 | + * |
|
587 | + * @since 1.0.0 |
|
588 | + * @return bool |
|
589 | + */ |
|
590 | + public function can_cancel() { |
|
591 | 591 | $ret = false; |
592 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
592 | + if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
593 | 593 | $ret = true; |
594 | 594 | } |
595 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
596 | - } |
|
595 | + return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
596 | + } |
|
597 | 597 | |
598 | 598 | /** |
599 | 599 | * Returns an array of subscription statuses that can be cancelled |
@@ -606,197 +606,197 @@ discard block |
||
606 | 606 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
607 | 607 | } |
608 | 608 | |
609 | - /** |
|
610 | - * Retrieves the URL to cancel subscription |
|
611 | - * |
|
612 | - * @since 1.0.0 |
|
613 | - * @return string |
|
614 | - */ |
|
615 | - public function get_cancel_url() { |
|
609 | + /** |
|
610 | + * Retrieves the URL to cancel subscription |
|
611 | + * |
|
612 | + * @since 1.0.0 |
|
613 | + * @return string |
|
614 | + */ |
|
615 | + public function get_cancel_url() { |
|
616 | 616 | |
617 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
617 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
618 | 618 | |
619 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
620 | - } |
|
619 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
620 | + } |
|
621 | 621 | |
622 | - /** |
|
623 | - * Determines if subscription can be manually renewed |
|
624 | - * |
|
625 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
626 | - * that can be renewed manually |
|
627 | - * |
|
628 | - * @since 2.5 |
|
629 | - * @return bool |
|
630 | - */ |
|
631 | - public function can_renew() { |
|
622 | + /** |
|
623 | + * Determines if subscription can be manually renewed |
|
624 | + * |
|
625 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
626 | + * that can be renewed manually |
|
627 | + * |
|
628 | + * @since 2.5 |
|
629 | + * @return bool |
|
630 | + */ |
|
631 | + public function can_renew() { |
|
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Retrieves the URL to renew a subscription |
|
638 | - * |
|
639 | - * @since 2.5 |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function get_renew_url() { |
|
643 | - |
|
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
645 | - |
|
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Determines if subscription can have their payment method updated |
|
651 | - * |
|
652 | - * @since 1.0.0 |
|
653 | - * @return bool |
|
654 | - */ |
|
655 | - public function can_update() { |
|
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Retrieves the URL to update subscription |
|
661 | - * |
|
662 | - * @since 1.0.0 |
|
663 | - * @return void |
|
664 | - */ |
|
665 | - public function get_update_url() { |
|
666 | - |
|
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
668 | - |
|
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Determines if subscription is active |
|
674 | - * |
|
675 | - * @since 1.0.0 |
|
676 | - * @return void |
|
677 | - */ |
|
678 | - public function is_active() { |
|
679 | - |
|
680 | - $ret = false; |
|
681 | - |
|
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
683 | - $ret = true; |
|
684 | - } |
|
685 | - |
|
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Determines if subscription is expired |
|
692 | - * |
|
693 | - * @since 1.0.0 |
|
694 | - * @return void |
|
695 | - */ |
|
696 | - public function is_expired() { |
|
697 | - |
|
698 | - $ret = false; |
|
699 | - |
|
700 | - if ( $this->status == 'expired' ) { |
|
701 | - |
|
702 | - $ret = true; |
|
703 | - |
|
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
705 | - |
|
706 | - $ret = false; |
|
707 | - $expiration = $this->get_expiration_time(); |
|
708 | - |
|
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
710 | - $ret = true; |
|
711 | - |
|
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
713 | - $this->expire(); |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - } |
|
718 | - |
|
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
720 | - |
|
721 | - } |
|
722 | - |
|
723 | - /** |
|
724 | - * Retrieves the expiration date |
|
725 | - * |
|
726 | - * @since 1.0.0 |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function get_expiration() { |
|
730 | - return $this->expiration; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Retrieves the expiration date in a timestamp |
|
735 | - * |
|
736 | - * @since 1.0.0 |
|
737 | - * @return int |
|
738 | - */ |
|
739 | - public function get_expiration_time() { |
|
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Retrieves the subscription status |
|
745 | - * |
|
746 | - * @since 1.0.0 |
|
747 | - * @return int |
|
748 | - */ |
|
749 | - public function get_status() { |
|
750 | - |
|
751 | - // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
752 | - $this->is_expired(); |
|
753 | - return $this->status; |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Retrieves the subscription status label |
|
758 | - * |
|
759 | - * @since 1.0.0 |
|
760 | - * @return int |
|
761 | - */ |
|
762 | - public function get_status_label() { |
|
763 | - |
|
764 | - switch( $this->get_status() ) { |
|
765 | - case 'active' : |
|
766 | - $status = __( 'Active', 'invoicing' ); |
|
767 | - break; |
|
768 | - |
|
769 | - case 'cancelled' : |
|
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
771 | - break; |
|
772 | - |
|
773 | - case 'expired' : |
|
774 | - $status = __( 'Expired', 'invoicing' ); |
|
775 | - break; |
|
776 | - |
|
777 | - case 'pending' : |
|
778 | - $status = __( 'Pending', 'invoicing' ); |
|
779 | - break; |
|
780 | - |
|
781 | - case 'failing' : |
|
782 | - $status = __( 'Failing', 'invoicing' ); |
|
783 | - break; |
|
784 | - |
|
785 | - case 'trialling' : |
|
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
787 | - break; |
|
788 | - |
|
789 | - case 'completed' : |
|
790 | - $status = __( 'Completed', 'invoicing' ); |
|
791 | - break; |
|
792 | - |
|
793 | - default: |
|
794 | - $status = ucfirst( $this->get_status() ); |
|
795 | - break; |
|
796 | - } |
|
797 | - |
|
798 | - return $status; |
|
799 | - } |
|
633 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Retrieves the URL to renew a subscription |
|
638 | + * |
|
639 | + * @since 2.5 |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function get_renew_url() { |
|
643 | + |
|
644 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
645 | + |
|
646 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Determines if subscription can have their payment method updated |
|
651 | + * |
|
652 | + * @since 1.0.0 |
|
653 | + * @return bool |
|
654 | + */ |
|
655 | + public function can_update() { |
|
656 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Retrieves the URL to update subscription |
|
661 | + * |
|
662 | + * @since 1.0.0 |
|
663 | + * @return void |
|
664 | + */ |
|
665 | + public function get_update_url() { |
|
666 | + |
|
667 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
668 | + |
|
669 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Determines if subscription is active |
|
674 | + * |
|
675 | + * @since 1.0.0 |
|
676 | + * @return void |
|
677 | + */ |
|
678 | + public function is_active() { |
|
679 | + |
|
680 | + $ret = false; |
|
681 | + |
|
682 | + if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
683 | + $ret = true; |
|
684 | + } |
|
685 | + |
|
686 | + return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Determines if subscription is expired |
|
692 | + * |
|
693 | + * @since 1.0.0 |
|
694 | + * @return void |
|
695 | + */ |
|
696 | + public function is_expired() { |
|
697 | + |
|
698 | + $ret = false; |
|
699 | + |
|
700 | + if ( $this->status == 'expired' ) { |
|
701 | + |
|
702 | + $ret = true; |
|
703 | + |
|
704 | + } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
705 | + |
|
706 | + $ret = false; |
|
707 | + $expiration = $this->get_expiration_time(); |
|
708 | + |
|
709 | + if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
710 | + $ret = true; |
|
711 | + |
|
712 | + if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
713 | + $this->expire(); |
|
714 | + } |
|
715 | + } |
|
716 | + |
|
717 | + } |
|
718 | + |
|
719 | + return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
720 | + |
|
721 | + } |
|
722 | + |
|
723 | + /** |
|
724 | + * Retrieves the expiration date |
|
725 | + * |
|
726 | + * @since 1.0.0 |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function get_expiration() { |
|
730 | + return $this->expiration; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Retrieves the expiration date in a timestamp |
|
735 | + * |
|
736 | + * @since 1.0.0 |
|
737 | + * @return int |
|
738 | + */ |
|
739 | + public function get_expiration_time() { |
|
740 | + return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Retrieves the subscription status |
|
745 | + * |
|
746 | + * @since 1.0.0 |
|
747 | + * @return int |
|
748 | + */ |
|
749 | + public function get_status() { |
|
750 | + |
|
751 | + // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
752 | + $this->is_expired(); |
|
753 | + return $this->status; |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Retrieves the subscription status label |
|
758 | + * |
|
759 | + * @since 1.0.0 |
|
760 | + * @return int |
|
761 | + */ |
|
762 | + public function get_status_label() { |
|
763 | + |
|
764 | + switch( $this->get_status() ) { |
|
765 | + case 'active' : |
|
766 | + $status = __( 'Active', 'invoicing' ); |
|
767 | + break; |
|
768 | + |
|
769 | + case 'cancelled' : |
|
770 | + $status = __( 'Cancelled', 'invoicing' ); |
|
771 | + break; |
|
772 | + |
|
773 | + case 'expired' : |
|
774 | + $status = __( 'Expired', 'invoicing' ); |
|
775 | + break; |
|
776 | + |
|
777 | + case 'pending' : |
|
778 | + $status = __( 'Pending', 'invoicing' ); |
|
779 | + break; |
|
780 | + |
|
781 | + case 'failing' : |
|
782 | + $status = __( 'Failing', 'invoicing' ); |
|
783 | + break; |
|
784 | + |
|
785 | + case 'trialling' : |
|
786 | + $status = __( 'Trialling', 'invoicing' ); |
|
787 | + break; |
|
788 | + |
|
789 | + case 'completed' : |
|
790 | + $status = __( 'Completed', 'invoicing' ); |
|
791 | + break; |
|
792 | + |
|
793 | + default: |
|
794 | + $status = ucfirst( $this->get_status() ); |
|
795 | + break; |
|
796 | + } |
|
797 | + |
|
798 | + return $status; |
|
799 | + } |
|
800 | 800 | |
801 | 801 | /** |
802 | 802 | * Retrieves the subscription status label |
@@ -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,11 +171,11 @@ 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 | 180 | return $ret; |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | public function delete() { |
191 | - return $this->subs_db->delete( $this->id ); |
|
191 | + return $this->subs_db->delete($this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | * @return array |
209 | 209 | */ |
210 | 210 | public function get_child_payments() { |
211 | - $payments = get_posts( array( |
|
212 | - 'post_parent' => (int) $this->parent_payment_id, |
|
211 | + $payments = get_posts(array( |
|
212 | + 'post_parent' => (int)$this->parent_payment_id, |
|
213 | 213 | 'posts_per_page' => '999', |
214 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
214 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
215 | 215 | 'orderby' => 'ID', |
216 | 216 | 'order' => 'DESC', |
217 | 217 | 'post_type' => 'wpi_invoice' |
218 | - ) ); |
|
218 | + )); |
|
219 | 219 | |
220 | 220 | return $payments; |
221 | 221 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function get_total_payments() { |
230 | 230 | $child_payments = $this->get_child_payments(); |
231 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
231 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
232 | 232 | |
233 | - if ( 'pending' != $this->status ) { |
|
233 | + if ('pending' != $this->status) { |
|
234 | 234 | $total_payments++; |
235 | 235 | } |
236 | 236 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | public function get_times_billed() { |
247 | 247 | $times_billed = (int)$this->get_total_payments(); |
248 | 248 | |
249 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
249 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
250 | 250 | $times_billed--; |
251 | 251 | } |
252 | 252 | |
@@ -260,51 +260,51 @@ discard block |
||
260 | 260 | * @param array $args Array of values for the payment, including amount and transaction ID |
261 | 261 | * @return bool |
262 | 262 | */ |
263 | - public function add_payment( $args = array() ) { |
|
264 | - if ( ! $this->parent_payment_id ) { |
|
263 | + public function add_payment($args = array()) { |
|
264 | + if (!$this->parent_payment_id) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - $args = wp_parse_args( $args, array( |
|
268 | + $args = wp_parse_args($args, array( |
|
269 | 269 | 'amount' => '', |
270 | 270 | 'transaction_id' => '', |
271 | 271 | 'gateway' => '' |
272 | - ) ); |
|
272 | + )); |
|
273 | 273 | |
274 | - if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) { |
|
274 | + if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
278 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
279 | - if ( empty( $parent_invoice->ID ) ) { |
|
278 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
279 | + if (empty($parent_invoice->ID)) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | 283 | $invoice = new WPInv_Invoice(); |
284 | - $invoice->set( 'post_type', 'wpi_invoice' ); |
|
285 | - $invoice->set( 'parent_invoice', $this->parent_payment_id ); |
|
286 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
287 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
288 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
289 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
290 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
291 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
292 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
293 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
294 | - $invoice->set( 'address', $parent_invoice->address ); |
|
295 | - $invoice->set( 'city', $parent_invoice->city ); |
|
296 | - $invoice->set( 'country', $parent_invoice->country ); |
|
297 | - $invoice->set( 'state', $parent_invoice->state ); |
|
298 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
299 | - $invoice->set( 'company', $parent_invoice->company ); |
|
300 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
301 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
302 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
303 | - |
|
304 | - if ( empty( $args['gateway'] ) ) { |
|
305 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
284 | + $invoice->set('post_type', 'wpi_invoice'); |
|
285 | + $invoice->set('parent_invoice', $this->parent_payment_id); |
|
286 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
287 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
288 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
289 | + $invoice->set('ip', $parent_invoice->ip); |
|
290 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
291 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
292 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
293 | + $invoice->set('phone', $parent_invoice->phone); |
|
294 | + $invoice->set('address', $parent_invoice->address); |
|
295 | + $invoice->set('city', $parent_invoice->city); |
|
296 | + $invoice->set('country', $parent_invoice->country); |
|
297 | + $invoice->set('state', $parent_invoice->state); |
|
298 | + $invoice->set('zip', $parent_invoice->zip); |
|
299 | + $invoice->set('company', $parent_invoice->company); |
|
300 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
301 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
302 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
303 | + |
|
304 | + if (empty($args['gateway'])) { |
|
305 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
306 | 306 | } else { |
307 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
307 | + $invoice->set('gateway', $args['gateway']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | // increase the earnings for each item in the subscription |
313 | 313 | $items = $recurring_details['cart_details']; |
314 | 314 | |
315 | - if ( $items ) { |
|
315 | + if ($items) { |
|
316 | 316 | $add_items = array(); |
317 | 317 | $cart_details = array(); |
318 | 318 | |
319 | - foreach ( $items as $item ) { |
|
319 | + foreach ($items as $item) { |
|
320 | 320 | $add_item = array(); |
321 | 321 | $add_item['id'] = $item['id']; |
322 | 322 | $add_item['quantity'] = $item['quantity']; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | } |
328 | 328 | |
329 | - $invoice->set( 'items', $add_items ); |
|
329 | + $invoice->set('items', $add_items); |
|
330 | 330 | $invoice->cart_details = $cart_details; |
331 | 331 | } |
332 | 332 | |
@@ -336,29 +336,29 @@ discard block |
||
336 | 336 | $tax = $recurring_details['tax']; |
337 | 337 | $discount = $recurring_details['discount']; |
338 | 338 | |
339 | - if ( $discount > 0 ) { |
|
340 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
339 | + if ($discount > 0) { |
|
340 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
341 | 341 | } |
342 | 342 | |
343 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
344 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
345 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
346 | - $invoice->total = wpinv_round_amount( $total ); |
|
343 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
344 | + $invoice->tax = wpinv_round_amount($tax); |
|
345 | + $invoice->discount = wpinv_round_amount($discount); |
|
346 | + $invoice->total = wpinv_round_amount($total); |
|
347 | 347 | |
348 | - $invoice = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args ); |
|
348 | + $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args); |
|
349 | 349 | |
350 | 350 | $invoice->save(); |
351 | - $invoice->update_meta( '_wpinv_subscription_id', $this->id ); |
|
351 | + $invoice->update_meta('_wpinv_subscription_id', $this->id); |
|
352 | 352 | |
353 | - if ( !empty( $invoice->ID ) ) { |
|
354 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
353 | + if (!empty($invoice->ID)) { |
|
354 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
355 | 355 | sleep(1); |
356 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
356 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
358 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
359 | 359 | |
360 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
361 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] ); |
|
360 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
361 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']); |
|
362 | 362 | |
363 | 363 | return $invoice->ID; |
364 | 364 | } |
@@ -374,12 +374,12 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function get_transaction_id() { |
376 | 376 | |
377 | - if( empty( $this->transaction_id ) ) { |
|
377 | + if (empty($this->transaction_id)) { |
|
378 | 378 | |
379 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
379 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
380 | 380 | |
381 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | - $this->set_transaction_id( $txn_id ); |
|
381 | + if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) { |
|
382 | + $this->set_transaction_id($txn_id); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | } |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @since 1.0.0.4 |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
397 | + public function set_transaction_id($txn_id = '') { |
|
398 | + $this->update(array('transaction_id' => $txn_id)); |
|
399 | 399 | $this->transaction_id = $txn_id; |
400 | 400 | } |
401 | 401 | |
@@ -411,35 +411,35 @@ discard block |
||
411 | 411 | |
412 | 412 | |
413 | 413 | // Determine what date to use as the start for the new expiration calculation |
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
414 | + if ($expires > current_time('timestamp') && $this->is_active()) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | 418 | } else { |
419 | 419 | |
420 | - $base_date = current_time( 'timestamp' ); |
|
420 | + $base_date = current_time('timestamp'); |
|
421 | 421 | |
422 | 422 | } |
423 | 423 | |
424 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
424 | + $last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date)); |
|
425 | 425 | |
426 | 426 | |
427 | 427 | $frequency = isset($this->frequency) ? $this->frequency : 1; |
428 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
428 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date)); |
|
429 | 429 | |
430 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
430 | + if (date('j', $base_date) == $last_day && 'day' != $this->period) { |
|
431 | + $expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days')); |
|
432 | 432 | } |
433 | 433 | |
434 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
434 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this); |
|
435 | 435 | |
436 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
436 | + do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this); |
|
437 | 437 | |
438 | 438 | $this->status = 'active'; |
439 | 439 | $times_billed = $this->get_times_billed(); |
440 | 440 | |
441 | 441 | // Complete subscription if applicable |
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
442 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
443 | 443 | $this->complete(); |
444 | 444 | $this->status = 'completed'; |
445 | 445 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | 'status' => $this->status, |
450 | 450 | ); |
451 | 451 | |
452 | - $this->subs_db->update( $this->id, $args ); |
|
452 | + $this->subs_db->update($this->id, $args); |
|
453 | 453 | |
454 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
454 | + do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this); |
|
455 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function complete() { |
468 | 468 | |
469 | 469 | // Only mark a subscription as complete if it's not already cancelled. |
470 | - if ( 'cancelled' === $this->status ) { |
|
470 | + if ('cancelled' === $this->status) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | 'status' => 'completed' |
476 | 476 | ); |
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if ($this->subs_db->update($this->id, $args)) { |
|
479 | 479 | |
480 | 480 | $this->status = 'completed'; |
481 | 481 | |
482 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
482 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -494,15 +494,15 @@ discard block |
||
494 | 494 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
495 | 495 | * @return void |
496 | 496 | */ |
497 | - public function expire( $check_expiration = false ) { |
|
497 | + public function expire($check_expiration = false) { |
|
498 | 498 | |
499 | 499 | $expiration = $this->expiration; |
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if ($check_expiration) { |
|
502 | 502 | |
503 | 503 | // check_expiration() updates $this->expiration so compare to $expiration above |
504 | 504 | |
505 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
505 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
506 | 506 | |
507 | 507 | return false; // Do not mark as expired since real expiration date is in the future |
508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | 'status' => 'expired' |
514 | 514 | ); |
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if ($this->subs_db->update($this->id, $args)) { |
|
517 | 517 | |
518 | 518 | $this->status = 'expired'; |
519 | 519 | |
520 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
520 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
521 | 521 | |
522 | 522 | } |
523 | 523 | |
@@ -535,11 +535,11 @@ discard block |
||
535 | 535 | 'status' => 'failing' |
536 | 536 | ); |
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if ($this->subs_db->update($this->id, $args)) { |
|
539 | 539 | |
540 | 540 | $this->status = 'failing'; |
541 | 541 | |
542 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
542 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
543 | 543 | |
544 | 544 | |
545 | 545 | } |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return void |
554 | 554 | */ |
555 | 555 | public function cancel() { |
556 | - if ( 'cancelled' === $this->status ) { |
|
556 | + if ('cancelled' === $this->status) { |
|
557 | 557 | return; // Already cancelled |
558 | 558 | } |
559 | 559 | |
@@ -561,20 +561,20 @@ discard block |
||
561 | 561 | 'status' => 'cancelled' |
562 | 562 | ); |
563 | 563 | |
564 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
565 | - if ( is_user_logged_in() ) { |
|
566 | - $userdata = get_userdata( get_current_user_id() ); |
|
564 | + if ($this->subs_db->update($this->id, $args)) { |
|
565 | + if (is_user_logged_in()) { |
|
566 | + $userdata = get_userdata(get_current_user_id()); |
|
567 | 567 | $user = $userdata->display_name; |
568 | 568 | } else { |
569 | - $user = __( 'gateway', 'invoicing' ); |
|
569 | + $user = __('gateway', 'invoicing'); |
|
570 | 570 | } |
571 | 571 | |
572 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $user ); |
|
573 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
572 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $user); |
|
573 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
574 | 574 | |
575 | 575 | $this->status = 'cancelled'; |
576 | 576 | |
577 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
577 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | */ |
590 | 590 | public function can_cancel() { |
591 | 591 | $ret = false; |
592 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
592 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
593 | 593 | $ret = true; |
594 | 594 | } |
595 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
595 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | public function get_cancellable_statuses() { |
606 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
606 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -614,9 +614,9 @@ discard block |
||
614 | 614 | */ |
615 | 615 | public function get_cancel_url() { |
616 | 616 | |
617 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
617 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
618 | 618 | |
619 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
619 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public function can_renew() { |
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
633 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | */ |
642 | 642 | public function get_renew_url() { |
643 | 643 | |
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
644 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
645 | 645 | |
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
646 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * @return bool |
654 | 654 | */ |
655 | 655 | public function can_update() { |
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
656 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | */ |
665 | 665 | public function get_update_url() { |
666 | 666 | |
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
667 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
668 | 668 | |
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
669 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | |
680 | 680 | $ret = false; |
681 | 681 | |
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
682 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
683 | 683 | $ret = true; |
684 | 684 | } |
685 | 685 | |
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
686 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
687 | 687 | |
688 | 688 | } |
689 | 689 | |
@@ -697,26 +697,26 @@ discard block |
||
697 | 697 | |
698 | 698 | $ret = false; |
699 | 699 | |
700 | - if ( $this->status == 'expired' ) { |
|
700 | + if ($this->status == 'expired') { |
|
701 | 701 | |
702 | 702 | $ret = true; |
703 | 703 | |
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
704 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
705 | 705 | |
706 | 706 | $ret = false; |
707 | 707 | $expiration = $this->get_expiration_time(); |
708 | 708 | |
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
709 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
710 | 710 | $ret = true; |
711 | 711 | |
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
712 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
713 | 713 | $this->expire(); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
717 | 717 | } |
718 | 718 | |
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
719 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
720 | 720 | |
721 | 721 | } |
722 | 722 | |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | * @return int |
738 | 738 | */ |
739 | 739 | public function get_expiration_time() { |
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
740 | + return strtotime($this->expiration, current_time('timestamp')); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | */ |
762 | 762 | public function get_status_label() { |
763 | 763 | |
764 | - switch( $this->get_status() ) { |
|
764 | + switch ($this->get_status()) { |
|
765 | 765 | case 'active' : |
766 | - $status = __( 'Active', 'invoicing' ); |
|
766 | + $status = __('Active', 'invoicing'); |
|
767 | 767 | break; |
768 | 768 | |
769 | 769 | case 'cancelled' : |
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
770 | + $status = __('Cancelled', 'invoicing'); |
|
771 | 771 | break; |
772 | 772 | |
773 | 773 | case 'expired' : |
774 | - $status = __( 'Expired', 'invoicing' ); |
|
774 | + $status = __('Expired', 'invoicing'); |
|
775 | 775 | break; |
776 | 776 | |
777 | 777 | case 'pending' : |
778 | - $status = __( 'Pending', 'invoicing' ); |
|
778 | + $status = __('Pending', 'invoicing'); |
|
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'failing' : |
782 | - $status = __( 'Failing', 'invoicing' ); |
|
782 | + $status = __('Failing', 'invoicing'); |
|
783 | 783 | break; |
784 | 784 | |
785 | 785 | case 'trialling' : |
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
786 | + $status = __('Trialling', 'invoicing'); |
|
787 | 787 | break; |
788 | 788 | |
789 | 789 | case 'completed' : |
790 | - $status = __( 'Completed', 'invoicing' ); |
|
790 | + $status = __('Completed', 'invoicing'); |
|
791 | 791 | break; |
792 | 792 | |
793 | 793 | default: |
794 | - $status = ucfirst( $this->get_status() ); |
|
794 | + $status = ucfirst($this->get_status()); |
|
795 | 795 | break; |
796 | 796 | } |
797 | 797 | |
@@ -806,51 +806,51 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function get_status_label_html() { |
808 | 808 | |
809 | - switch( $get_status = $this->get_status() ) { |
|
809 | + switch ($get_status = $this->get_status()) { |
|
810 | 810 | case 'active' : |
811 | - $status = __( 'Active', 'invoicing' ); |
|
811 | + $status = __('Active', 'invoicing'); |
|
812 | 812 | $class = 'label-info'; |
813 | 813 | break; |
814 | 814 | |
815 | 815 | case 'cancelled' : |
816 | - $status = __( 'Cancelled', 'invoicing' ); |
|
816 | + $status = __('Cancelled', 'invoicing'); |
|
817 | 817 | $class = 'label-danger'; |
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'expired' : |
821 | - $status = __( 'Expired', 'invoicing' ); |
|
821 | + $status = __('Expired', 'invoicing'); |
|
822 | 822 | $class = 'label-default'; |
823 | 823 | break; |
824 | 824 | |
825 | 825 | case 'pending' : |
826 | - $status = __( 'Pending', 'invoicing' ); |
|
826 | + $status = __('Pending', 'invoicing'); |
|
827 | 827 | $class = 'label-primary'; |
828 | 828 | break; |
829 | 829 | |
830 | 830 | case 'failing' : |
831 | - $status = __( 'Failing', 'invoicing' ); |
|
831 | + $status = __('Failing', 'invoicing'); |
|
832 | 832 | $class = 'label-danger'; |
833 | 833 | break; |
834 | 834 | |
835 | 835 | case 'trialling' : |
836 | - $status = __( 'Trialling', 'invoicing' ); |
|
836 | + $status = __('Trialling', 'invoicing'); |
|
837 | 837 | $class = 'label-info'; |
838 | 838 | break; |
839 | 839 | |
840 | 840 | case 'completed' : |
841 | - $status = __( 'Completed', 'invoicing' ); |
|
841 | + $status = __('Completed', 'invoicing'); |
|
842 | 842 | $class = 'label-success'; |
843 | 843 | break; |
844 | 844 | |
845 | 845 | default: |
846 | - $status = ucfirst( $this->get_status() ); |
|
846 | + $status = ucfirst($this->get_status()); |
|
847 | 847 | $class = 'label-default'; |
848 | 848 | break; |
849 | 849 | } |
850 | 850 | |
851 | 851 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
852 | 852 | |
853 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
853 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -860,18 +860,18 @@ discard block |
||
860 | 860 | * @param string $txn_id The transaction ID from the merchant processor |
861 | 861 | * @return bool |
862 | 862 | */ |
863 | - public function payment_exists( $txn_id = '' ) { |
|
863 | + public function payment_exists($txn_id = '') { |
|
864 | 864 | global $wpdb; |
865 | 865 | |
866 | - if ( empty( $txn_id ) ) { |
|
866 | + if (empty($txn_id)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
870 | - $txn_id = esc_sql( $txn_id ); |
|
870 | + $txn_id = esc_sql($txn_id); |
|
871 | 871 | |
872 | - $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
872 | + $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
873 | 873 | |
874 | - if ( $purchase != null ) { |
|
874 | + if ($purchase != null) { |
|
875 | 875 | return true; |
876 | 876 | } |
877 | 877 |
@@ -29,16 +29,16 @@ |
||
29 | 29 | <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions"> |
30 | 30 | <thead> |
31 | 31 | <tr> |
32 | - <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th> |
|
33 | - <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th> |
|
34 | - <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th> |
|
35 | - <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th> |
|
36 | - <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th> |
|
37 | - <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th> |
|
38 | - <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th> |
|
39 | - <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th> |
|
40 | - <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th> |
|
41 | - <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th> |
|
32 | + <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th> |
|
33 | + <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th> |
|
34 | + <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th> |
|
35 | + <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th> |
|
36 | + <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th> |
|
37 | + <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th> |
|
38 | + <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th> |
|
39 | + <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th> |
|
40 | + <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th> |
|
41 | + <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th> |
|
42 | 42 | </tr> |
43 | 43 | </thead> |
44 | 44 |