@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
9 | - exit; // Exit if accessed directly |
|
9 | + exit; // Exit if accessed directly |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | class GetPaid_Meta_Box_Invoice_Subscription { |
16 | 16 | |
17 | 17 | /** |
18 | - * Output the subscription metabox. |
|
19 | - * |
|
20 | - * @param WP_Post $post |
|
21 | - */ |
|
18 | + * Output the subscription metabox. |
|
19 | + * |
|
20 | + * @param WP_Post $post |
|
21 | + */ |
|
22 | 22 | public static function output( $post ) { |
23 | 23 | |
24 | 24 | // Fetch the invoice. |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | - * Output the subscription invoices. |
|
38 | - * |
|
39 | - * @param WP_Post $post |
|
40 | - */ |
|
37 | + * Output the subscription invoices. |
|
38 | + * |
|
39 | + * @param WP_Post $post |
|
40 | + */ |
|
41 | 41 | public static function output_invoices( $post ) { |
42 | 42 | |
43 | 43 | // Fetch the invoice. |
@@ -17,28 +17,28 @@ discard block |
||
17 | 17 | */ |
18 | 18 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
19 | 19 | |
20 | - // Do not retrieve all fields if we just want the count. |
|
21 | - if ( 'count' == $return ) { |
|
22 | - $args['fields'] = 'id'; |
|
23 | - $args['number'] = 1; |
|
24 | - } |
|
20 | + // Do not retrieve all fields if we just want the count. |
|
21 | + if ( 'count' == $return ) { |
|
22 | + $args['fields'] = 'id'; |
|
23 | + $args['number'] = 1; |
|
24 | + } |
|
25 | 25 | |
26 | - // Do not count all matches if we just want the results. |
|
27 | - if ( 'results' == $return ) { |
|
28 | - $args['count_total'] = false; |
|
29 | - } |
|
26 | + // Do not count all matches if we just want the results. |
|
27 | + if ( 'results' == $return ) { |
|
28 | + $args['count_total'] = false; |
|
29 | + } |
|
30 | 30 | |
31 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
31 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
32 | 32 | |
33 | - if ( 'results' == $return ) { |
|
34 | - return $query->get_results(); |
|
35 | - } |
|
33 | + if ( 'results' == $return ) { |
|
34 | + return $query->get_results(); |
|
35 | + } |
|
36 | 36 | |
37 | - if ( 'count' == $return ) { |
|
38 | - return $query->get_total(); |
|
39 | - } |
|
37 | + if ( 'count' == $return ) { |
|
38 | + return $query->get_total(); |
|
39 | + } |
|
40 | 40 | |
41 | - return $query; |
|
41 | + return $query; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,18 +48,18 @@ discard block |
||
48 | 48 | */ |
49 | 49 | function getpaid_get_subscription_statuses() { |
50 | 50 | |
51 | - return apply_filters( |
|
52 | - 'getpaid_get_subscription_statuses', |
|
53 | - array( |
|
54 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
55 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
56 | - 'active' => __( 'Active', 'invoicing' ), |
|
57 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
58 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
59 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
60 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
61 | - ) |
|
62 | - ); |
|
51 | + return apply_filters( |
|
52 | + 'getpaid_get_subscription_statuses', |
|
53 | + array( |
|
54 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
55 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
56 | + 'active' => __( 'Active', 'invoicing' ), |
|
57 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
58 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
59 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
60 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
61 | + ) |
|
62 | + ); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * @return string |
70 | 70 | */ |
71 | 71 | function getpaid_get_subscription_status_label( $status ) { |
72 | - $statuses = getpaid_get_subscription_statuses(); |
|
73 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
72 | + $statuses = getpaid_get_subscription_statuses(); |
|
73 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function getpaid_get_subscription_status_classes() { |
82 | 82 | |
83 | - return apply_filters( |
|
84 | - 'getpaid_get_subscription_status_classes', |
|
85 | - array( |
|
86 | - 'pending' => 'getpaid-item-status-pending', |
|
87 | - 'trialling' => 'getpaid-item-status-trial', |
|
88 | - 'active' => 'getpaid-item-status-info', |
|
89 | - 'failing' => 'getpaid-item-status-failing', |
|
90 | - 'expired' => 'getpaid-item-status-expired', |
|
91 | - 'completed' => 'getpaid-item-status-success', |
|
92 | - 'cancelled' => 'getpaid-item-status-canceled', |
|
93 | - ) |
|
94 | - ); |
|
83 | + return apply_filters( |
|
84 | + 'getpaid_get_subscription_status_classes', |
|
85 | + array( |
|
86 | + 'pending' => 'getpaid-item-status-pending', |
|
87 | + 'trialling' => 'getpaid-item-status-trial', |
|
88 | + 'active' => 'getpaid-item-status-info', |
|
89 | + 'failing' => 'getpaid-item-status-failing', |
|
90 | + 'expired' => 'getpaid-item-status-expired', |
|
91 | + 'completed' => 'getpaid-item-status-success', |
|
92 | + 'cancelled' => 'getpaid-item-status-canceled', |
|
93 | + ) |
|
94 | + ); |
|
95 | 95 | |
96 | 96 | } |
97 | 97 | |
@@ -102,15 +102,15 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function getpaid_get_subscription_status_counts( $args = array() ) { |
104 | 104 | |
105 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
106 | - $counts = array(); |
|
105 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
106 | + $counts = array(); |
|
107 | 107 | |
108 | - foreach ( $statuses as $status ) { |
|
109 | - $_args = wp_parse_args( "status=$status", $args ); |
|
110 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
111 | - } |
|
108 | + foreach ( $statuses as $status ) { |
|
109 | + $_args = wp_parse_args( "status=$status", $args ); |
|
110 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
111 | + } |
|
112 | 112 | |
113 | - return $counts; |
|
113 | + return $counts; |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | |
@@ -121,32 +121,32 @@ discard block |
||
121 | 121 | */ |
122 | 122 | function getpaid_get_subscription_periods() { |
123 | 123 | |
124 | - return apply_filters( |
|
125 | - 'getpaid_get_subscription_periods', |
|
126 | - array( |
|
124 | + return apply_filters( |
|
125 | + 'getpaid_get_subscription_periods', |
|
126 | + array( |
|
127 | 127 | |
128 | - 'day' => array( |
|
129 | - 'singular' => __( '%s day', 'invoicing' ), |
|
130 | - 'plural' => __( '%d days', 'invoicing' ), |
|
131 | - ), |
|
128 | + 'day' => array( |
|
129 | + 'singular' => __( '%s day', 'invoicing' ), |
|
130 | + 'plural' => __( '%d days', 'invoicing' ), |
|
131 | + ), |
|
132 | 132 | |
133 | - 'week' => array( |
|
134 | - 'singular' => __( '%s week', 'invoicing' ), |
|
135 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
136 | - ), |
|
133 | + 'week' => array( |
|
134 | + 'singular' => __( '%s week', 'invoicing' ), |
|
135 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
136 | + ), |
|
137 | 137 | |
138 | - 'month' => array( |
|
139 | - 'singular' => __( '%s month', 'invoicing' ), |
|
140 | - 'plural' => __( '%d months', 'invoicing' ), |
|
141 | - ), |
|
138 | + 'month' => array( |
|
139 | + 'singular' => __( '%s month', 'invoicing' ), |
|
140 | + 'plural' => __( '%d months', 'invoicing' ), |
|
141 | + ), |
|
142 | 142 | |
143 | - 'year' => array( |
|
144 | - 'singular' => __( '%s year', 'invoicing' ), |
|
145 | - 'plural' => __( '%d years', 'invoicing' ), |
|
146 | - ), |
|
143 | + 'year' => array( |
|
144 | + 'singular' => __( '%s year', 'invoicing' ), |
|
145 | + 'plural' => __( '%d years', 'invoicing' ), |
|
146 | + ), |
|
147 | 147 | |
148 | - ) |
|
149 | - ); |
|
148 | + ) |
|
149 | + ); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @return int |
158 | 158 | */ |
159 | 159 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
160 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
160 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @return string |
168 | 168 | */ |
169 | 169 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
170 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
170 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | * @return string |
179 | 179 | */ |
180 | 180 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
181 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
182 | - return strtolower( sanitize_text_field( $label ) ); |
|
181 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
182 | + return strtolower( sanitize_text_field( $label ) ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -190,22 +190,22 @@ discard block |
||
190 | 190 | */ |
191 | 191 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
192 | 192 | |
193 | - $periods = getpaid_get_subscription_periods(); |
|
194 | - $period = strtolower( $period ); |
|
193 | + $periods = getpaid_get_subscription_periods(); |
|
194 | + $period = strtolower( $period ); |
|
195 | 195 | |
196 | - if ( isset( $periods[ $period ] ) ) { |
|
197 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
198 | - } |
|
196 | + if ( isset( $periods[ $period ] ) ) { |
|
197 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
198 | + } |
|
199 | 199 | |
200 | - // Backwards compatibility. |
|
201 | - foreach ( $periods as $key => $data ) { |
|
202 | - if ( strpos( $key, $period ) === 0 ) { |
|
203 | - return sprintf( $data['singular'], $singular_prefix ); |
|
204 | - } |
|
205 | - } |
|
200 | + // Backwards compatibility. |
|
201 | + foreach ( $periods as $key => $data ) { |
|
202 | + if ( strpos( $key, $period ) === 0 ) { |
|
203 | + return sprintf( $data['singular'], $singular_prefix ); |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - // Invalid string. |
|
208 | - return ''; |
|
207 | + // Invalid string. |
|
208 | + return ''; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -217,22 +217,22 @@ discard block |
||
217 | 217 | */ |
218 | 218 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
219 | 219 | |
220 | - $periods = getpaid_get_subscription_periods(); |
|
221 | - $period = strtolower( $period ); |
|
220 | + $periods = getpaid_get_subscription_periods(); |
|
221 | + $period = strtolower( $period ); |
|
222 | 222 | |
223 | - if ( isset( $periods[ $period ] ) ) { |
|
224 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
225 | - } |
|
223 | + if ( isset( $periods[ $period ] ) ) { |
|
224 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
225 | + } |
|
226 | 226 | |
227 | - // Backwards compatibility. |
|
228 | - foreach ( $periods as $key => $data ) { |
|
229 | - if ( strpos( $key, $period ) === 0 ) { |
|
230 | - return sprintf( $data['plural'], $interval ); |
|
231 | - } |
|
232 | - } |
|
227 | + // Backwards compatibility. |
|
228 | + foreach ( $periods as $key => $data ) { |
|
229 | + if ( strpos( $key, $period ) === 0 ) { |
|
230 | + return sprintf( $data['plural'], $interval ); |
|
231 | + } |
|
232 | + } |
|
233 | 233 | |
234 | - // Invalid string. |
|
235 | - return ''; |
|
234 | + // Invalid string. |
|
235 | + return ''; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -243,50 +243,50 @@ discard block |
||
243 | 243 | */ |
244 | 244 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
245 | 245 | |
246 | - $initial = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
247 | - $recurring = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
248 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
246 | + $initial = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
247 | + $recurring = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
248 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
249 | 249 | |
250 | - // Trial periods. |
|
251 | - if ( $subscription->has_trial_period() ) { |
|
250 | + // Trial periods. |
|
251 | + if ( $subscription->has_trial_period() ) { |
|
252 | 252 | |
253 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
254 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
255 | - return sprintf( |
|
253 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
254 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
255 | + return sprintf( |
|
256 | 256 | |
257 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
258 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
259 | - $initial, |
|
260 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
261 | - $recurring, |
|
262 | - $period |
|
257 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
258 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
259 | + $initial, |
|
260 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
261 | + $recurring, |
|
262 | + $period |
|
263 | 263 | |
264 | - ); |
|
264 | + ); |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - if ( $initial != $recurring ) { |
|
268 | + if ( $initial != $recurring ) { |
|
269 | 269 | |
270 | - return sprintf( |
|
270 | + return sprintf( |
|
271 | 271 | |
272 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
273 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
274 | - $initial, |
|
275 | - $recurring, |
|
276 | - $period |
|
272 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
273 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
274 | + $initial, |
|
275 | + $recurring, |
|
276 | + $period |
|
277 | 277 | |
278 | - ); |
|
278 | + ); |
|
279 | 279 | |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - return sprintf( |
|
282 | + return sprintf( |
|
283 | 283 | |
284 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
285 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
286 | - $initial, |
|
287 | - $period |
|
284 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
285 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
286 | + $initial, |
|
287 | + $period |
|
288 | 288 | |
289 | - ); |
|
289 | + ); |
|
290 | 290 | |
291 | 291 | } |
292 | 292 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @return WPInv_Subscription|bool |
298 | 298 | */ |
299 | 299 | function getpaid_get_invoice_subscription( $invoice ) { |
300 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
300 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | * @param WPInv_Invoice $invoice |
307 | 307 | */ |
308 | 308 | function getpaid_activate_invoice_subscription( $invoice ) { |
309 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
310 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
311 | - $subscription->activate(); |
|
312 | - } |
|
309 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
310 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
311 | + $subscription->activate(); |
|
312 | + } |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * @return WPInv_Subscriptions |
319 | 319 | */ |
320 | 320 | function getpaid_subscriptions() { |
321 | - return getpaid()->get( 'subscriptions' ); |
|
321 | + return getpaid()->get( 'subscriptions' ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -336,14 +336,14 @@ discard block |
||
336 | 336 | return false; |
337 | 337 | } |
338 | 338 | |
339 | - // Fetch the invoiec subscription. |
|
340 | - $subscription = getpaid_get_subscriptions( |
|
341 | - array( |
|
342 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
343 | - 'number' => 1, |
|
344 | - ) |
|
345 | - ); |
|
339 | + // Fetch the invoiec subscription. |
|
340 | + $subscription = getpaid_get_subscriptions( |
|
341 | + array( |
|
342 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
343 | + 'number' => 1, |
|
344 | + ) |
|
345 | + ); |
|
346 | 346 | |
347 | - return empty( $subscription ) ? false : $subscription[0]; |
|
347 | + return empty( $subscription ) ? false : $subscription[0]; |
|
348 | 348 | |
349 | 349 | } |
@@ -13,36 +13,36 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email { |
14 | 14 | |
15 | 15 | /** |
16 | - * Contains the type of this notification email. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Contains the type of this notification email. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id; |
21 | 21 | |
22 | 22 | /** |
23 | - * Contains any object to use in filters. |
|
24 | - * |
|
25 | - * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | - */ |
|
23 | + * Contains any object to use in filters. |
|
24 | + * |
|
25 | + * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | + */ |
|
27 | 27 | public $object; |
28 | 28 | |
29 | 29 | /** |
30 | - * Class constructor. |
|
31 | - * |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | 32 | * @param string $id Email Type. |
33 | 33 | * @param mixed $object Optional. Associated object. |
34 | - */ |
|
35 | - public function __construct( $id, $object = false ) { |
|
34 | + */ |
|
35 | + public function __construct( $id, $object = false ) { |
|
36 | 36 | $this->id = $id; |
37 | 37 | $this->object = $object; |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * Retrieves an option |
|
42 | - * |
|
41 | + * Retrieves an option |
|
42 | + * |
|
43 | 43 | * @return mixed |
44 | - */ |
|
45 | - public function get_option( $key ) { |
|
44 | + */ |
|
45 | + public function get_option( $key ) { |
|
46 | 46 | |
47 | 47 | $key = "email_{$this->id}_$key"; |
48 | 48 | $value = wpinv_get_option( $key, null ); |
@@ -60,80 +60,80 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Retrieves the email body. |
|
64 | - * |
|
63 | + * Retrieves the email body. |
|
64 | + * |
|
65 | 65 | * @return string |
66 | - */ |
|
67 | - public function get_body() { |
|
66 | + */ |
|
67 | + public function get_body() { |
|
68 | 68 | $body = $this->get_option( 'body' ); |
69 | 69 | return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object ); |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * Retrieves the email subject. |
|
74 | - * |
|
73 | + * Retrieves the email subject. |
|
74 | + * |
|
75 | 75 | * @return string |
76 | - */ |
|
77 | - public function get_subject() { |
|
76 | + */ |
|
77 | + public function get_subject() { |
|
78 | 78 | $subject = $this->get_option( 'subject' ); |
79 | 79 | return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object ); |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | - * Retrieves the email heading. |
|
84 | - * |
|
83 | + * Retrieves the email heading. |
|
84 | + * |
|
85 | 85 | * @return string |
86 | - */ |
|
87 | - public function get_heading() { |
|
86 | + */ |
|
87 | + public function get_heading() { |
|
88 | 88 | $heading = $this->get_option( 'heading' ); |
89 | 89 | return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object ); |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | - * Checks if an email is active. |
|
94 | - * |
|
93 | + * Checks if an email is active. |
|
94 | + * |
|
95 | 95 | * @return bool |
96 | - */ |
|
97 | - public function is_active() { |
|
96 | + */ |
|
97 | + public function is_active() { |
|
98 | 98 | $is_active = ! empty( $this->get_option( 'active' ) ); |
99 | 99 | return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object ); |
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * Checks if the site's admin should receive email notifications. |
|
104 | - * |
|
103 | + * Checks if the site's admin should receive email notifications. |
|
104 | + * |
|
105 | 105 | * @return bool |
106 | - */ |
|
107 | - public function include_admin_bcc() { |
|
106 | + */ |
|
107 | + public function include_admin_bcc() { |
|
108 | 108 | $include_admin_bcc = ! empty( $this->get_option( 'admin_bcc' ) ); |
109 | 109 | return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object ); |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Checks whether this email should be sent to the customer or admin. |
|
114 | - * |
|
113 | + * Checks whether this email should be sent to the customer or admin. |
|
114 | + * |
|
115 | 115 | * @return bool |
116 | - */ |
|
117 | - public function is_admin_email() { |
|
116 | + */ |
|
117 | + public function is_admin_email() { |
|
118 | 118 | $is_admin_email = in_array( $this->id, array( 'new_invoice', 'cancelled_invoice', 'failed_invoice' ) ); |
119 | 119 | return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object ); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | - * Returns email attachments. |
|
124 | - * |
|
123 | + * Returns email attachments. |
|
124 | + * |
|
125 | 125 | * @return array |
126 | - */ |
|
127 | - public function get_attachments() { |
|
126 | + */ |
|
127 | + public function get_attachments() { |
|
128 | 128 | return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Returns an array of merge tags. |
|
133 | - * |
|
132 | + * Returns an array of merge tags. |
|
133 | + * |
|
134 | 134 | * @return array |
135 | - */ |
|
136 | - public function get_merge_tags() { |
|
135 | + */ |
|
136 | + public function get_merge_tags() { |
|
137 | 137 | |
138 | 138 | $merge_tags = array( |
139 | 139 | '{site_title}' => wpinv_get_blogname(), |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Adds merge tags to a text. |
|
148 | - * |
|
147 | + * Adds merge tags to a text. |
|
148 | + * |
|
149 | 149 | * @param string string $text |
150 | 150 | * @param array $merge_tags |
151 | 151 | * @return string |
152 | - */ |
|
153 | - public function add_merge_tags( $text, $merge_tags = array() ) { |
|
152 | + */ |
|
153 | + public function add_merge_tags( $text, $merge_tags = array() ) { |
|
154 | 154 | |
155 | 155 | foreach ( $merge_tags as $key => $value ) { |
156 | 156 | $text = str_replace( $key, $value, $text ); |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Returns the email content |
|
164 | - * |
|
163 | + * Returns the email content |
|
164 | + * |
|
165 | 165 | * @param array $merge_tags |
166 | 166 | * @param array $extra_args Extra template args |
167 | 167 | * @return string |
168 | - */ |
|
169 | - public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
168 | + */ |
|
169 | + public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
170 | 170 | |
171 | 171 | $content = wpinv_get_template_html( |
172 | 172 | "emails/wpinv-email-{$this->id}.php", |
@@ -13,38 +13,38 @@ |
||
13 | 13 | |
14 | 14 | foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
17 | - echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
16 | + $class = sanitize_html_class( $column ); |
|
17 | + echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
20 | 20 | |
21 | - switch( $column ) : |
|
21 | + switch( $column ) : |
|
22 | 22 | |
23 | - case 'subscription': |
|
24 | - $subscription_id = (int) $subscription->get_id(); |
|
25 | - $url = esc_url( $subscription->get_view_url() ); |
|
26 | - echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | - break; |
|
23 | + case 'subscription': |
|
24 | + $subscription_id = (int) $subscription->get_id(); |
|
25 | + $url = esc_url( $subscription->get_view_url() ); |
|
26 | + echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | + break; |
|
28 | 28 | |
29 | - case 'status': |
|
30 | - echo $subscription->get_status_label(); |
|
31 | - break; |
|
29 | + case 'status': |
|
30 | + echo $subscription->get_status_label(); |
|
31 | + break; |
|
32 | 32 | |
33 | - case 'renewal-date': |
|
34 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | - echo $subscription->is_active() ? $renewal : "—"; |
|
36 | - break; |
|
33 | + case 'renewal-date': |
|
34 | + $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | + echo $subscription->is_active() ? $renewal : "—"; |
|
36 | + break; |
|
37 | 37 | |
38 | - case 'amount': |
|
39 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
40 | - $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | - echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | - break; |
|
38 | + case 'amount': |
|
39 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
40 | + $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | + echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | + break; |
|
43 | 43 | |
44 | - endswitch; |
|
44 | + endswitch; |
|
45 | 45 | |
46 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
46 | + do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
47 | 47 | |
48 | - echo '</td>'; |
|
48 | + echo '</td>'; |
|
49 | 49 | |
50 | 50 | endforeach; |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ){ |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | - * Returns the API authentication params. |
|
85 | - * |
|
86 | - * |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function get_auth_params() { |
|
84 | + * Returns the API authentication params. |
|
85 | + * |
|
86 | + * |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function get_auth_params() { |
|
90 | 90 | |
91 | 91 | return array( |
92 | 92 | 'name' => $this->get_option( 'login_id' ), |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | - * Cancels a subscription remotely |
|
100 | - * |
|
101 | - * |
|
102 | - * @param WPInv_Subscription $subscription Subscription. |
|
99 | + * Cancels a subscription remotely |
|
100 | + * |
|
101 | + * |
|
102 | + * @param WPInv_Subscription $subscription Subscription. |
|
103 | 103 | * @param WPInv_Invoice $invoice Invoice. |
104 | - */ |
|
105 | - public function cancel_subscription( $subscription, $invoice ) { |
|
104 | + */ |
|
105 | + public function cancel_subscription( $subscription, $invoice ) { |
|
106 | 106 | |
107 | 107 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
108 | 108 | $this->post( |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Processes ipns. |
|
122 | - * |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function verify_ipn() { |
|
121 | + * Processes ipns. |
|
122 | + * |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function verify_ipn() { |
|
126 | 126 | |
127 | 127 | $this->maybe_process_old_ipn(); |
128 | 128 | |
129 | 129 | // Validate the IPN. |
130 | 130 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
131 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
131 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // Event type. |
@@ -167,24 +167,24 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | - * Validates IPN invoices. |
|
171 | - * |
|
170 | + * Validates IPN invoices. |
|
171 | + * |
|
172 | 172 | * @param WPInv_Invoice $invoice |
173 | 173 | * @param object $payload |
174 | - * @return void |
|
175 | - */ |
|
176 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
174 | + * @return void |
|
175 | + */ |
|
176 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
177 | 177 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
178 | 178 | exit; |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Process subscriptio IPNS. |
|
184 | - * |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - public function maybe_process_old_ipn() { |
|
183 | + * Process subscriptio IPNS. |
|
184 | + * |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + public function maybe_process_old_ipn() { |
|
188 | 188 | |
189 | 189 | $data = wp_unslash( $_POST ); |
190 | 190 | |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | - * Validates the old IPN signature. |
|
229 | + * Validates the old IPN signature. |
|
230 | 230 | * |
231 | 231 | * @param array $posted |
232 | - */ |
|
233 | - public function validate_old_ipn_signature( $posted ) { |
|
232 | + */ |
|
233 | + public function validate_old_ipn_signature( $posted ) { |
|
234 | 234 | |
235 | 235 | $signature = $this->get_option( 'signature_key' ); |
236 | 236 | if ( ! empty( $signature ) ) { |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
252 | - * Check Authorize.NET IPN validity. |
|
253 | - */ |
|
254 | - public function validate_ipn() { |
|
252 | + * Check Authorize.NET IPN validity. |
|
253 | + */ |
|
254 | + public function validate_ipn() { |
|
255 | 255 | |
256 | 256 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
257 | 257 |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | $css = getpaid_get_email_css(); |
111 | 111 | |
112 | 112 | // include css inliner |
113 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
114 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
113 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
114 | + include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | // Inline the css. |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $message = wpinv_email_style_body( $message ); |
191 | 191 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
192 | 192 | |
193 | - return $mailer->send( |
|
193 | + return $mailer->send( |
|
194 | 194 | $to, |
195 | 195 | $subject, |
196 | 196 | $message, |
@@ -117,14 +117,14 @@ |
||
117 | 117 | */ |
118 | 118 | function getpaid_doing_it_wrong( $function, $message, $version ) { |
119 | 119 | |
120 | - $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
121 | - |
|
122 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
123 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
124 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
125 | - } else { |
|
126 | - _doing_it_wrong( $function, $message, $version ); |
|
127 | - } |
|
120 | + $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
121 | + |
|
122 | + if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
123 | + do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
124 | + error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
125 | + } else { |
|
126 | + _doing_it_wrong( $function, $message, $version ); |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
130 | 130 |
@@ -13,128 +13,128 @@ |
||
13 | 13 | class GetPaid_Payment_Forms { |
14 | 14 | |
15 | 15 | /** |
16 | - * Class constructor |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | - |
|
25 | - // Sync form amount whenever invoice statuses change. |
|
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | - |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Increments a form's revenue whenever there is a payment. |
|
34 | - * |
|
35 | - * @param WPInv_Invoice $invoice |
|
36 | - */ |
|
37 | - public function increment_form_revenue( $invoice ) { |
|
38 | - |
|
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | - $form->save(); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Decreases form revenue whenever invoice payment changes. |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice |
|
51 | - */ |
|
52 | - public function decrease_form_revenue( $invoice ) { |
|
53 | - |
|
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | - $form->save(); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates a form's failed amount. |
|
64 | - * |
|
65 | - * @param WPInv_Invoice $invoice |
|
66 | - * @param string $from |
|
67 | - * @param string $to |
|
68 | - */ |
|
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | - |
|
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | - $form->save(); |
|
79 | - } |
|
80 | - |
|
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | - $form->save(); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Updates a form's refunded amount. |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice |
|
92 | - * @param string $from |
|
93 | - * @param string $to |
|
94 | - */ |
|
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | - |
|
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | - $form->save(); |
|
105 | - } |
|
106 | - |
|
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | - $form->save(); |
|
110 | - } |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Updates a form's cancelled amount. |
|
116 | - * |
|
117 | - * @param WPInv_Invoice $invoice |
|
118 | - * @param string $from |
|
119 | - * @param string $to |
|
120 | - */ |
|
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | - |
|
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | - $form->save(); |
|
131 | - } |
|
132 | - |
|
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | - $form->save(); |
|
136 | - } |
|
137 | - |
|
138 | - } |
|
16 | + * Class constructor |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | + |
|
25 | + // Sync form amount whenever invoice statuses change. |
|
26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | + |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Increments a form's revenue whenever there is a payment. |
|
34 | + * |
|
35 | + * @param WPInv_Invoice $invoice |
|
36 | + */ |
|
37 | + public function increment_form_revenue( $invoice ) { |
|
38 | + |
|
39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | + if ( $form->get_id() ) { |
|
41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | + $form->save(); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Decreases form revenue whenever invoice payment changes. |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice |
|
51 | + */ |
|
52 | + public function decrease_form_revenue( $invoice ) { |
|
53 | + |
|
54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | + if ( $form->get_id() ) { |
|
56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | + $form->save(); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates a form's failed amount. |
|
64 | + * |
|
65 | + * @param WPInv_Invoice $invoice |
|
66 | + * @param string $from |
|
67 | + * @param string $to |
|
68 | + */ |
|
69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | + |
|
71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | + if ( $form->get_id() ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if ( 'wpi-failed' == $from ) { |
|
77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | + $form->save(); |
|
79 | + } |
|
80 | + |
|
81 | + if ( 'wpi-failed' == $to ) { |
|
82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | + $form->save(); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Updates a form's refunded amount. |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice |
|
92 | + * @param string $from |
|
93 | + * @param string $to |
|
94 | + */ |
|
95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | + |
|
97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | + if ( $form->get_id() ) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + if ( 'wpi-refunded' == $from ) { |
|
103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | + $form->save(); |
|
105 | + } |
|
106 | + |
|
107 | + if ( 'wpi-refunded' == $to ) { |
|
108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | + $form->save(); |
|
110 | + } |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Updates a form's cancelled amount. |
|
116 | + * |
|
117 | + * @param WPInv_Invoice $invoice |
|
118 | + * @param string $from |
|
119 | + * @param string $to |
|
120 | + */ |
|
121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | + |
|
123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | + if ( $form->get_id() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( 'wpi-cancelled' == $from ) { |
|
129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | + $form->save(); |
|
131 | + } |
|
132 | + |
|
133 | + if ( 'wpi-cancelled' == $to ) { |
|
134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | + $form->save(); |
|
136 | + } |
|
137 | + |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
17 | 17 | |
18 | 18 | /** |
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | 23 | public static function output( $post ) { |
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Save meta box data. |
|
90 | - * |
|
91 | - * @param int $post_id |
|
92 | - */ |
|
93 | - public static function save( $post_id ) { |
|
89 | + * Save meta box data. |
|
90 | + * |
|
91 | + * @param int $post_id |
|
92 | + */ |
|
93 | + public static function save( $post_id ) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Converts an array fo form items to objects. |
|
125 | - * |
|
126 | - * @param array $items |
|
127 | - */ |
|
128 | - public static function item_to_objects( $items ) { |
|
124 | + * Converts an array fo form items to objects. |
|
125 | + * |
|
126 | + * @param array $items |
|
127 | + */ |
|
128 | + public static function item_to_objects( $items ) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 |