@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wpinv_subscriptions_page() { |
16 | 16 | |
17 | - ?> |
|
17 | + ?> |
|
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,28 +22,28 @@ discard block |
||
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | - // Verify user permissions. |
|
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
25 | + // Verify user permissions. |
|
26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
27 | 27 | |
28 | - aui()->alert( |
|
28 | + aui()->alert( |
|
29 | 29 | array( |
30 | - 'type' => 'danger', |
|
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | - ), |
|
33 | - true |
|
30 | + 'type' => 'danger', |
|
31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | + ), |
|
33 | + true |
|
34 | 34 | ); |
35 | 35 | |
36 | - } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
36 | + } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
37 | 37 | |
38 | - // Display a single subscription. |
|
39 | - wpinv_recurring_subscription_details(); |
|
40 | - } else { |
|
38 | + // Display a single subscription. |
|
39 | + wpinv_recurring_subscription_details(); |
|
40 | + } else { |
|
41 | 41 | |
42 | - // Display a list of available subscriptions. |
|
43 | - getpaid_print_subscriptions_list(); |
|
44 | - } |
|
42 | + // Display a list of available subscriptions. |
|
43 | + getpaid_print_subscriptions_list(); |
|
44 | + } |
|
45 | 45 | |
46 | - ?> |
|
46 | + ?> |
|
47 | 47 | |
48 | 48 | </div> |
49 | 49 | </div> |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | */ |
61 | 61 | function getpaid_print_subscriptions_list() { |
62 | 62 | |
63 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
64 | - $subscribers_table->prepare_items(); |
|
63 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
64 | + $subscribers_table->prepare_items(); |
|
65 | 65 | |
66 | - ?> |
|
66 | + ?> |
|
67 | 67 | <?php $subscribers_table->views(); ?> |
68 | 68 | <form id="subscribers-filter" class="bsui" method="get"> |
69 | 69 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
@@ -82,42 +82,42 @@ discard block |
||
82 | 82 | */ |
83 | 83 | function wpinv_recurring_subscription_details() { |
84 | 84 | |
85 | - // Fetch the subscription. |
|
86 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
87 | - if ( ! $sub->exists() ) { |
|
85 | + // Fetch the subscription. |
|
86 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
87 | + if ( ! $sub->exists() ) { |
|
88 | 88 | |
89 | - aui()->alert( |
|
90 | - array( |
|
91 | - 'type' => 'danger', |
|
92 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
93 | - ), |
|
94 | - true |
|
95 | - ); |
|
89 | + aui()->alert( |
|
90 | + array( |
|
91 | + 'type' => 'danger', |
|
92 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
93 | + ), |
|
94 | + true |
|
95 | + ); |
|
96 | 96 | |
97 | - return; |
|
98 | - } |
|
97 | + return; |
|
98 | + } |
|
99 | 99 | |
100 | - // Use metaboxes to display the subscription details. |
|
101 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
102 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | + // Use metaboxes to display the subscription details. |
|
101 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
102 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
103 | 103 | |
104 | - $subscription_id = $sub->get_id(); |
|
105 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
106 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
104 | + $subscription_id = $sub->get_id(); |
|
105 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
106 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
107 | 107 | |
108 | - if ( 1 < count( $subscription_groups ) ) { |
|
109 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
110 | - } |
|
108 | + if ( 1 < count( $subscription_groups ) ) { |
|
109 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
110 | + } |
|
111 | 111 | |
112 | - if ( ! empty( $subscription_group ) ) { |
|
113 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
114 | - } |
|
112 | + if ( ! empty( $subscription_group ) ) { |
|
113 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
114 | + } |
|
115 | 115 | |
116 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
116 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
117 | 117 | |
118 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
118 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
119 | 119 | |
120 | - ?> |
|
120 | + ?> |
|
121 | 121 | |
122 | 122 | <form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ) ); ?>"> |
123 | 123 | |
@@ -157,49 +157,49 @@ discard block |
||
157 | 157 | */ |
158 | 158 | function getpaid_admin_subscription_details_metabox( $sub ) { |
159 | 159 | |
160 | - // Subscription items. |
|
161 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
162 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
163 | - |
|
164 | - // Prepare subscription detail columns. |
|
165 | - $fields = apply_filters( |
|
166 | - 'getpaid_subscription_admin_page_fields', |
|
167 | - array( |
|
168 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
169 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
170 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
171 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
172 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
173 | - 'renewals' => __( 'Collected Payments', 'invoicing' ), |
|
174 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
175 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
176 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
177 | - 'status' => __( 'Status', 'invoicing' ), |
|
178 | - ) |
|
179 | - ); |
|
180 | - |
|
181 | - if ( ! $sub->is_active() ) { |
|
182 | - |
|
183 | - if ( isset( $fields['renews_on'] ) ) { |
|
184 | - unset( $fields['renews_on'] ); |
|
185 | - } |
|
186 | - |
|
187 | - if ( isset( $fields['gateway'] ) ) { |
|
188 | - unset( $fields['gateway'] ); |
|
189 | - } |
|
190 | - } elseif ( $sub->is_last_renewal() ) { |
|
191 | - |
|
192 | - if ( isset( $fields['renews_on'] ) ) { |
|
193 | - $fields['renews_on'] = __( 'End Date', 'invoicing' ); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - $profile_id = $sub->get_profile_id(); |
|
198 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
199 | - unset( $fields['profile_id'] ); |
|
200 | - } |
|
201 | - |
|
202 | - ?> |
|
160 | + // Subscription items. |
|
161 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
162 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
163 | + |
|
164 | + // Prepare subscription detail columns. |
|
165 | + $fields = apply_filters( |
|
166 | + 'getpaid_subscription_admin_page_fields', |
|
167 | + array( |
|
168 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
169 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
170 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
171 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
172 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
173 | + 'renewals' => __( 'Collected Payments', 'invoicing' ), |
|
174 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
175 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
176 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
177 | + 'status' => __( 'Status', 'invoicing' ), |
|
178 | + ) |
|
179 | + ); |
|
180 | + |
|
181 | + if ( ! $sub->is_active() ) { |
|
182 | + |
|
183 | + if ( isset( $fields['renews_on'] ) ) { |
|
184 | + unset( $fields['renews_on'] ); |
|
185 | + } |
|
186 | + |
|
187 | + if ( isset( $fields['gateway'] ) ) { |
|
188 | + unset( $fields['gateway'] ); |
|
189 | + } |
|
190 | + } elseif ( $sub->is_last_renewal() ) { |
|
191 | + |
|
192 | + if ( isset( $fields['renews_on'] ) ) { |
|
193 | + $fields['renews_on'] = __( 'End Date', 'invoicing' ); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + $profile_id = $sub->get_profile_id(); |
|
198 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
199 | + unset( $fields['profile_id'] ); |
|
200 | + } |
|
201 | + |
|
202 | + ?> |
|
203 | 203 | |
204 | 204 | <table class="table table-borderless" style="font-size: 14px;"> |
205 | 205 | <tbody> |
@@ -233,20 +233,20 @@ discard block |
||
233 | 233 | */ |
234 | 234 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
235 | 235 | |
236 | - $username = __( '(Missing User)', 'invoicing' ); |
|
236 | + $username = __( '(Missing User)', 'invoicing' ); |
|
237 | 237 | |
238 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
239 | - if ( $user ) { |
|
238 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
239 | + if ( $user ) { |
|
240 | 240 | |
241 | - $username = sprintf( |
|
242 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
243 | - absint( $user->ID ), |
|
244 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
245 | - ); |
|
241 | + $username = sprintf( |
|
242 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
243 | + absint( $user->ID ), |
|
244 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
245 | + ); |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - echo wp_kses_post( $username ); |
|
249 | + echo wp_kses_post( $username ); |
|
250 | 250 | } |
251 | 251 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
252 | 252 | |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | * @param WPInv_Subscription $subscription |
257 | 257 | */ |
258 | 258 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
259 | - $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
260 | - echo wp_kses_post( "<span>$amount</span>" ); |
|
259 | + $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
260 | + echo wp_kses_post( "<span>$amount</span>" ); |
|
261 | 261 | } |
262 | 262 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
263 | 263 | |
@@ -268,11 +268,11 @@ discard block |
||
268 | 268 | */ |
269 | 269 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
270 | 270 | |
271 | - printf( |
|
272 | - '<a href="%s">#%s</a>', |
|
273 | - esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
274 | - absint( $subscription->get_id() ) |
|
275 | - ); |
|
271 | + printf( |
|
272 | + '<a href="%s">#%s</a>', |
|
273 | + esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
274 | + absint( $subscription->get_id() ) |
|
275 | + ); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
@@ -284,24 +284,24 @@ discard block |
||
284 | 284 | */ |
285 | 285 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
286 | 286 | |
287 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
288 | - aui()->input( |
|
289 | - array( |
|
290 | - 'type' => 'text', |
|
291 | - 'id' => 'wpinv_subscription_date_created', |
|
292 | - 'name' => 'wpinv_subscription_date_created', |
|
293 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
294 | - 'label_type' => 'hidden', |
|
295 | - 'placeholder' => 'YYYY-MM-DD', |
|
296 | - 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
297 | - 'no_wrap' => true, |
|
298 | - 'size' => 'sm', |
|
299 | - ), |
|
300 | - true |
|
301 | - ); |
|
302 | - } else { |
|
303 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
304 | - } |
|
287 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
288 | + aui()->input( |
|
289 | + array( |
|
290 | + 'type' => 'text', |
|
291 | + 'id' => 'wpinv_subscription_date_created', |
|
292 | + 'name' => 'wpinv_subscription_date_created', |
|
293 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
294 | + 'label_type' => 'hidden', |
|
295 | + 'placeholder' => 'YYYY-MM-DD', |
|
296 | + 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
297 | + 'no_wrap' => true, |
|
298 | + 'size' => 'sm', |
|
299 | + ), |
|
300 | + true |
|
301 | + ); |
|
302 | + } else { |
|
303 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
304 | + } |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
@@ -313,24 +313,24 @@ discard block |
||
313 | 313 | */ |
314 | 314 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
315 | 315 | |
316 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
317 | - aui()->input( |
|
318 | - array( |
|
319 | - 'type' => 'text', |
|
320 | - 'id' => 'wpinv_subscription_expiration', |
|
321 | - 'name' => 'wpinv_subscription_expiration', |
|
322 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
323 | - 'label_type' => 'hidden', |
|
324 | - 'placeholder' => 'YYYY-MM-DD', |
|
325 | - 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
326 | - 'no_wrap' => true, |
|
327 | - 'size' => 'sm', |
|
328 | - ), |
|
329 | - true |
|
330 | - ); |
|
331 | - } else { |
|
332 | - echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
333 | - } |
|
316 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
317 | + aui()->input( |
|
318 | + array( |
|
319 | + 'type' => 'text', |
|
320 | + 'id' => 'wpinv_subscription_expiration', |
|
321 | + 'name' => 'wpinv_subscription_expiration', |
|
322 | + 'label' => __( 'Renews On', 'invoicing' ), |
|
323 | + 'label_type' => 'hidden', |
|
324 | + 'placeholder' => 'YYYY-MM-DD', |
|
325 | + 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
326 | + 'no_wrap' => true, |
|
327 | + 'size' => 'sm', |
|
328 | + ), |
|
329 | + true |
|
330 | + ); |
|
331 | + } else { |
|
332 | + echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
333 | + } |
|
334 | 334 | } |
335 | 335 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
336 | 336 | |
@@ -341,32 +341,32 @@ discard block |
||
341 | 341 | */ |
342 | 342 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
343 | 343 | |
344 | - $max_bills = $subscription->get_bill_times(); |
|
345 | - $times_billed = (int) $subscription->get_times_billed(); |
|
346 | - |
|
347 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_bill_times_change' ) ) { |
|
348 | - aui()->input( |
|
349 | - array( |
|
350 | - 'type' => 'number', |
|
351 | - 'id' => 'wpinv_subscription_max_bill_times', |
|
352 | - 'name' => 'wpinv_subscription_max_bill_times', |
|
353 | - 'label' => __( 'Maximum bill times', 'invoicing' ), |
|
354 | - 'label_type' => 'hidden', |
|
355 | - 'placeholder' => __( 'Unlimited', 'invoicing' ), |
|
356 | - 'value' => empty( $max_bills ) ? '' : (int) $max_bills, |
|
357 | - 'no_wrap' => true, |
|
358 | - 'size' => 'sm', |
|
359 | - 'input_group_left' => sprintf( |
|
360 | - // translators: %d: Number of times billed |
|
361 | - __( '%d of', 'invoicing' ), |
|
362 | - $times_billed |
|
363 | - ), |
|
364 | - ), |
|
365 | - true |
|
366 | - ); |
|
367 | - } else { |
|
368 | - echo esc_html( $times_billed ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
369 | - } |
|
344 | + $max_bills = $subscription->get_bill_times(); |
|
345 | + $times_billed = (int) $subscription->get_times_billed(); |
|
346 | + |
|
347 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_bill_times_change' ) ) { |
|
348 | + aui()->input( |
|
349 | + array( |
|
350 | + 'type' => 'number', |
|
351 | + 'id' => 'wpinv_subscription_max_bill_times', |
|
352 | + 'name' => 'wpinv_subscription_max_bill_times', |
|
353 | + 'label' => __( 'Maximum bill times', 'invoicing' ), |
|
354 | + 'label_type' => 'hidden', |
|
355 | + 'placeholder' => __( 'Unlimited', 'invoicing' ), |
|
356 | + 'value' => empty( $max_bills ) ? '' : (int) $max_bills, |
|
357 | + 'no_wrap' => true, |
|
358 | + 'size' => 'sm', |
|
359 | + 'input_group_left' => sprintf( |
|
360 | + // translators: %d: Number of times billed |
|
361 | + __( '%d of', 'invoicing' ), |
|
362 | + $times_billed |
|
363 | + ), |
|
364 | + ), |
|
365 | + true |
|
366 | + ); |
|
367 | + } else { |
|
368 | + echo esc_html( $times_billed ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
369 | + } |
|
370 | 370 | } |
371 | 371 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
372 | 372 | |
@@ -378,13 +378,13 @@ discard block |
||
378 | 378 | */ |
379 | 379 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
380 | 380 | |
381 | - if ( empty( $subscription_group ) ) { |
|
382 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
383 | - return; |
|
384 | - } |
|
381 | + if ( empty( $subscription_group ) ) { |
|
382 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
383 | + return; |
|
384 | + } |
|
385 | 385 | |
386 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
387 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
386 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
387 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -396,13 +396,13 @@ discard block |
||
396 | 396 | */ |
397 | 397 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
398 | 398 | |
399 | - $gateway = $subscription->get_gateway(); |
|
399 | + $gateway = $subscription->get_gateway(); |
|
400 | 400 | |
401 | - if ( ! empty( $gateway ) ) { |
|
402 | - echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
403 | - } else { |
|
404 | - echo '—'; |
|
405 | - } |
|
401 | + if ( ! empty( $gateway ) ) { |
|
402 | + echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
403 | + } else { |
|
404 | + echo '—'; |
|
405 | + } |
|
406 | 406 | |
407 | 407 | } |
408 | 408 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @param WPInv_Subscription $subscription |
414 | 414 | */ |
415 | 415 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
416 | - echo wp_kses_post( $subscription->get_status_label_html() ); |
|
416 | + echo wp_kses_post( $subscription->get_status_label_html() ); |
|
417 | 417 | } |
418 | 418 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
419 | 419 | |
@@ -424,28 +424,28 @@ discard block |
||
424 | 424 | */ |
425 | 425 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
426 | 426 | |
427 | - $profile_id = $subscription->get_profile_id(); |
|
428 | - |
|
429 | - aui()->input( |
|
430 | - array( |
|
431 | - 'type' => 'text', |
|
432 | - 'id' => 'wpinv_subscription_profile_id', |
|
433 | - 'name' => 'wpinv_subscription_profile_id', |
|
434 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
435 | - 'label_type' => 'hidden', |
|
436 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
437 | - 'value' => esc_attr( $profile_id ), |
|
438 | - 'input_group_right' => '', |
|
439 | - 'no_wrap' => true, |
|
440 | - 'size' => 'sm', |
|
441 | - ), |
|
442 | - true |
|
443 | - ); |
|
444 | - |
|
445 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
446 | - if ( ! empty( $url ) ) { |
|
447 | - echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
448 | - } |
|
427 | + $profile_id = $subscription->get_profile_id(); |
|
428 | + |
|
429 | + aui()->input( |
|
430 | + array( |
|
431 | + 'type' => 'text', |
|
432 | + 'id' => 'wpinv_subscription_profile_id', |
|
433 | + 'name' => 'wpinv_subscription_profile_id', |
|
434 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
435 | + 'label_type' => 'hidden', |
|
436 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
437 | + 'value' => esc_attr( $profile_id ), |
|
438 | + 'input_group_right' => '', |
|
439 | + 'no_wrap' => true, |
|
440 | + 'size' => 'sm', |
|
441 | + ), |
|
442 | + true |
|
443 | + ); |
|
444 | + |
|
445 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
446 | + if ( ! empty( $url ) ) { |
|
447 | + echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
448 | + } |
|
449 | 449 | |
450 | 450 | } |
451 | 451 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -457,40 +457,40 @@ discard block |
||
457 | 457 | */ |
458 | 458 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
459 | 459 | |
460 | - ?> |
|
460 | + ?> |
|
461 | 461 | <div class="mt-3"> |
462 | 462 | |
463 | 463 | <?php |
464 | - aui()->select( |
|
465 | - array( |
|
466 | - 'options' => getpaid_get_subscription_statuses(), |
|
467 | - 'name' => 'subscription_status', |
|
468 | - 'id' => 'subscription_status_update_select', |
|
469 | - 'required' => true, |
|
470 | - 'no_wrap' => false, |
|
471 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
472 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
473 | - 'select2' => true, |
|
474 | - 'value' => $subscription->get_status( 'edit' ), |
|
475 | - ), |
|
476 | - true |
|
477 | - ); |
|
478 | - ?> |
|
464 | + aui()->select( |
|
465 | + array( |
|
466 | + 'options' => getpaid_get_subscription_statuses(), |
|
467 | + 'name' => 'subscription_status', |
|
468 | + 'id' => 'subscription_status_update_select', |
|
469 | + 'required' => true, |
|
470 | + 'no_wrap' => false, |
|
471 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
472 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
473 | + 'select2' => true, |
|
474 | + 'value' => $subscription->get_status( 'edit' ), |
|
475 | + ), |
|
476 | + true |
|
477 | + ); |
|
478 | + ?> |
|
479 | 479 | |
480 | 480 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
481 | 481 | |
482 | 482 | <?php |
483 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
483 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
484 | 484 | |
485 | - $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
486 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
487 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
485 | + $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
486 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
487 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
488 | 488 | |
489 | - if ( $subscription->is_active() ) { |
|
490 | - echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
491 | - } |
|
489 | + if ( $subscription->is_active() ) { |
|
490 | + echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
491 | + } |
|
492 | 492 | |
493 | - echo '</div></div>'; |
|
493 | + echo '</div></div>'; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -501,33 +501,33 @@ discard block |
||
501 | 501 | */ |
502 | 502 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
503 | 503 | |
504 | - $columns = apply_filters( |
|
505 | - 'getpaid_subscription_related_invoices_columns', |
|
506 | - array( |
|
507 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
508 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
509 | - 'date' => __( 'Date', 'invoicing' ), |
|
510 | - 'status' => __( 'Status', 'invoicing' ), |
|
511 | - 'total' => __( 'Total', 'invoicing' ), |
|
512 | - ), |
|
513 | - $subscription |
|
514 | - ); |
|
515 | - |
|
516 | - // Prepare the invoices. |
|
517 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
518 | - $parent = $subscription->get_parent_invoice(); |
|
519 | - |
|
520 | - if ( $parent->exists() ) { |
|
521 | - $payments = array_merge( array( $parent ), $payments ); |
|
522 | - } |
|
523 | - |
|
524 | - $table_class = 'w-100 bg-white'; |
|
525 | - |
|
526 | - if ( ! is_admin() ) { |
|
527 | - $table_class = 'table table-bordered'; |
|
528 | - } |
|
529 | - |
|
530 | - ?> |
|
504 | + $columns = apply_filters( |
|
505 | + 'getpaid_subscription_related_invoices_columns', |
|
506 | + array( |
|
507 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
508 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
509 | + 'date' => __( 'Date', 'invoicing' ), |
|
510 | + 'status' => __( 'Status', 'invoicing' ), |
|
511 | + 'total' => __( 'Total', 'invoicing' ), |
|
512 | + ), |
|
513 | + $subscription |
|
514 | + ); |
|
515 | + |
|
516 | + // Prepare the invoices. |
|
517 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
518 | + $parent = $subscription->get_parent_invoice(); |
|
519 | + |
|
520 | + if ( $parent->exists() ) { |
|
521 | + $payments = array_merge( array( $parent ), $payments ); |
|
522 | + } |
|
523 | + |
|
524 | + $table_class = 'w-100 bg-white'; |
|
525 | + |
|
526 | + if ( ! is_admin() ) { |
|
527 | + $table_class = 'table table-bordered'; |
|
528 | + } |
|
529 | + |
|
530 | + ?> |
|
531 | 531 | <div class="m-0" style="overflow: auto;"> |
532 | 532 | |
533 | 533 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -535,10 +535,10 @@ discard block |
||
535 | 535 | <thead> |
536 | 536 | <tr> |
537 | 537 | <?php |
538 | - foreach ( $columns as $key => $label ) { |
|
539 | - echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
540 | - } |
|
541 | - ?> |
|
538 | + foreach ( $columns as $key => $label ) { |
|
539 | + echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
540 | + } |
|
541 | + ?> |
|
542 | 542 | </tr> |
543 | 543 | </thead> |
544 | 544 | |
@@ -554,72 +554,72 @@ discard block |
||
554 | 554 | |
555 | 555 | <?php |
556 | 556 | |
557 | - foreach ( $payments as $payment ) : |
|
557 | + foreach ( $payments as $payment ) : |
|
558 | 558 | |
559 | - // Ensure that we have an invoice. |
|
560 | - $payment = new WPInv_Invoice( $payment ); |
|
559 | + // Ensure that we have an invoice. |
|
560 | + $payment = new WPInv_Invoice( $payment ); |
|
561 | 561 | |
562 | - // Abort if the invoice is invalid... |
|
563 | - if ( ! $payment->exists() ) { |
|
564 | - continue; |
|
565 | - } |
|
562 | + // Abort if the invoice is invalid... |
|
563 | + if ( ! $payment->exists() ) { |
|
564 | + continue; |
|
565 | + } |
|
566 | 566 | |
567 | - // ... or belongs to a different subscription. |
|
568 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
569 | - continue; |
|
570 | - } |
|
567 | + // ... or belongs to a different subscription. |
|
568 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
569 | + continue; |
|
570 | + } |
|
571 | 571 | |
572 | - echo '<tr>'; |
|
572 | + echo '<tr>'; |
|
573 | 573 | |
574 | - foreach ( array_keys( $columns ) as $key ) { |
|
574 | + foreach ( array_keys( $columns ) as $key ) { |
|
575 | 575 | |
576 | - echo "<td class='p-2 text-left'>"; |
|
576 | + echo "<td class='p-2 text-left'>"; |
|
577 | 577 | |
578 | - switch ( $key ) { |
|
578 | + switch ( $key ) { |
|
579 | 579 | |
580 | - case 'total': |
|
581 | - echo '<strong>'; |
|
582 | - wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
583 | - echo '</strong>'; |
|
584 | - break; |
|
580 | + case 'total': |
|
581 | + echo '<strong>'; |
|
582 | + wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
583 | + echo '</strong>'; |
|
584 | + break; |
|
585 | 585 | |
586 | - case 'relationship': |
|
587 | - echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
588 | - break; |
|
586 | + case 'relationship': |
|
587 | + echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
588 | + break; |
|
589 | 589 | |
590 | - case 'date': |
|
591 | - echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
592 | - break; |
|
590 | + case 'date': |
|
591 | + echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
592 | + break; |
|
593 | 593 | |
594 | - case 'status': |
|
595 | - $status = $payment->get_status_nicename(); |
|
596 | - if ( is_admin() ) { |
|
597 | - $status = $payment->get_status_label_html(); |
|
598 | - } |
|
594 | + case 'status': |
|
595 | + $status = $payment->get_status_nicename(); |
|
596 | + if ( is_admin() ) { |
|
597 | + $status = $payment->get_status_label_html(); |
|
598 | + } |
|
599 | 599 | |
600 | - echo wp_kses_post( $status ); |
|
601 | - break; |
|
600 | + echo wp_kses_post( $status ); |
|
601 | + break; |
|
602 | 602 | |
603 | - case 'invoice': |
|
604 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
603 | + case 'invoice': |
|
604 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
605 | 605 | |
606 | - if ( ! is_admin() ) { |
|
607 | - $link = esc_url( $payment->get_view_url() ); |
|
608 | - } |
|
606 | + if ( ! is_admin() ) { |
|
607 | + $link = esc_url( $payment->get_view_url() ); |
|
608 | + } |
|
609 | 609 | |
610 | - $invoice = esc_html( $payment->get_number() ); |
|
611 | - echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
612 | - break; |
|
613 | - } |
|
610 | + $invoice = esc_html( $payment->get_number() ); |
|
611 | + echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
612 | + break; |
|
613 | + } |
|
614 | 614 | |
615 | - echo '</td>'; |
|
615 | + echo '</td>'; |
|
616 | 616 | |
617 | - } |
|
617 | + } |
|
618 | 618 | |
619 | - echo '</tr>'; |
|
619 | + echo '</tr>'; |
|
620 | 620 | |
621 | - endforeach; |
|
622 | - ?> |
|
621 | + endforeach; |
|
622 | + ?> |
|
623 | 623 | |
624 | 624 | </tbody> |
625 | 625 | |
@@ -637,42 +637,42 @@ discard block |
||
637 | 637 | */ |
638 | 638 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
639 | 639 | |
640 | - // Fetch the subscription group. |
|
641 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
640 | + // Fetch the subscription group. |
|
641 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
642 | 642 | |
643 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
644 | - return; |
|
645 | - } |
|
643 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
644 | + return; |
|
645 | + } |
|
646 | 646 | |
647 | - // Prepare table columns. |
|
648 | - $columns = apply_filters( |
|
649 | - 'getpaid_subscription_item_details_columns', |
|
650 | - array( |
|
651 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
652 | - 'price' => __( 'Price', 'invoicing' ), |
|
653 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
654 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
655 | - //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
656 | - 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
657 | - ), |
|
658 | - $subscription |
|
659 | - ); |
|
647 | + // Prepare table columns. |
|
648 | + $columns = apply_filters( |
|
649 | + 'getpaid_subscription_item_details_columns', |
|
650 | + array( |
|
651 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
652 | + 'price' => __( 'Price', 'invoicing' ), |
|
653 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
654 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
655 | + //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
656 | + 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
657 | + ), |
|
658 | + $subscription |
|
659 | + ); |
|
660 | 660 | |
661 | - // Prepare the invoices. |
|
661 | + // Prepare the invoices. |
|
662 | 662 | |
663 | - $invoice = $subscription->get_parent_invoice(); |
|
663 | + $invoice = $subscription->get_parent_invoice(); |
|
664 | 664 | |
665 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
666 | - unset( $columns['tax'] ); |
|
667 | - } |
|
665 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
666 | + unset( $columns['tax'] ); |
|
667 | + } |
|
668 | 668 | |
669 | - $table_class = 'w-100 bg-white'; |
|
669 | + $table_class = 'w-100 bg-white'; |
|
670 | 670 | |
671 | - if ( ! is_admin() ) { |
|
672 | - $table_class = 'table table-bordered'; |
|
673 | - } |
|
671 | + if ( ! is_admin() ) { |
|
672 | + $table_class = 'table table-bordered'; |
|
673 | + } |
|
674 | 674 | |
675 | - ?> |
|
675 | + ?> |
|
676 | 676 | <div class="m-0" style="overflow: auto;"> |
677 | 677 | |
678 | 678 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -681,10 +681,10 @@ discard block |
||
681 | 681 | <tr> |
682 | 682 | <?php |
683 | 683 | |
684 | - foreach ( $columns as $key => $label ) { |
|
685 | - echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
686 | - } |
|
687 | - ?> |
|
684 | + foreach ( $columns as $key => $label ) { |
|
685 | + echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
686 | + } |
|
687 | + ?> |
|
688 | 688 | </tr> |
689 | 689 | </thead> |
690 | 690 | |
@@ -692,106 +692,106 @@ discard block |
||
692 | 692 | |
693 | 693 | <?php |
694 | 694 | |
695 | - foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
695 | + foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
696 | 696 | |
697 | - echo '<tr>'; |
|
697 | + echo '<tr>'; |
|
698 | 698 | |
699 | - foreach ( array_keys( $columns ) as $key ) { |
|
699 | + foreach ( array_keys( $columns ) as $key ) { |
|
700 | 700 | |
701 | - $class = 'text-left'; |
|
701 | + $class = 'text-left'; |
|
702 | 702 | |
703 | - echo "<td class='p-2 text-left'>"; |
|
703 | + echo "<td class='p-2 text-left'>"; |
|
704 | 704 | |
705 | - switch ( $key ) { |
|
705 | + switch ( $key ) { |
|
706 | 706 | |
707 | - case 'item_name': |
|
708 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
709 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
707 | + case 'item_name': |
|
708 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
709 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
710 | 710 | |
711 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
712 | - echo esc_html( $item_name ); |
|
713 | - } else { |
|
714 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
715 | - } |
|
711 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
712 | + echo esc_html( $item_name ); |
|
713 | + } else { |
|
714 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
715 | + } |
|
716 | 716 | |
717 | - break; |
|
717 | + break; |
|
718 | 718 | |
719 | - case 'price': |
|
720 | - wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
721 | - break; |
|
719 | + case 'price': |
|
720 | + wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
721 | + break; |
|
722 | 722 | |
723 | - case 'tax': |
|
724 | - wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
725 | - break; |
|
723 | + case 'tax': |
|
724 | + wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
725 | + break; |
|
726 | 726 | |
727 | - case 'discount': |
|
728 | - wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
729 | - break; |
|
727 | + case 'discount': |
|
728 | + wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
729 | + break; |
|
730 | 730 | |
731 | - case 'initial': |
|
732 | - wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
733 | - break; |
|
731 | + case 'initial': |
|
732 | + wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
733 | + break; |
|
734 | 734 | |
735 | - case 'recurring': |
|
736 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
737 | - break; |
|
735 | + case 'recurring': |
|
736 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
737 | + break; |
|
738 | 738 | |
739 | - } |
|
739 | + } |
|
740 | 740 | |
741 | - echo '</td>'; |
|
741 | + echo '</td>'; |
|
742 | 742 | |
743 | - } |
|
743 | + } |
|
744 | 744 | |
745 | - echo '</tr>'; |
|
745 | + echo '</tr>'; |
|
746 | 746 | |
747 | - endforeach; |
|
747 | + endforeach; |
|
748 | 748 | |
749 | - foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
749 | + foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
750 | 750 | |
751 | - echo '<tr>'; |
|
751 | + echo '<tr>'; |
|
752 | 752 | |
753 | - foreach ( array_keys( $columns ) as $key ) { |
|
753 | + foreach ( array_keys( $columns ) as $key ) { |
|
754 | 754 | |
755 | - $class = 'text-left'; |
|
755 | + $class = 'text-left'; |
|
756 | 756 | |
757 | - echo "<td class='p-2 text-left'>"; |
|
757 | + echo "<td class='p-2 text-left'>"; |
|
758 | 758 | |
759 | - switch ( $key ) { |
|
759 | + switch ( $key ) { |
|
760 | 760 | |
761 | - case 'item_name': |
|
762 | - echo esc_html( $subscription_group_fee['name'] ); |
|
763 | - break; |
|
761 | + case 'item_name': |
|
762 | + echo esc_html( $subscription_group_fee['name'] ); |
|
763 | + break; |
|
764 | 764 | |
765 | - case 'price': |
|
766 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
767 | - break; |
|
765 | + case 'price': |
|
766 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
767 | + break; |
|
768 | 768 | |
769 | - case 'tax': |
|
770 | - echo '—'; |
|
771 | - break; |
|
769 | + case 'tax': |
|
770 | + echo '—'; |
|
771 | + break; |
|
772 | 772 | |
773 | - case 'discount': |
|
774 | - echo '—'; |
|
775 | - break; |
|
773 | + case 'discount': |
|
774 | + echo '—'; |
|
775 | + break; |
|
776 | 776 | |
777 | - case 'initial': |
|
778 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
779 | - break; |
|
777 | + case 'initial': |
|
778 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
779 | + break; |
|
780 | 780 | |
781 | - case 'recurring': |
|
782 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
783 | - break; |
|
781 | + case 'recurring': |
|
782 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
783 | + break; |
|
784 | 784 | |
785 | - } |
|
785 | + } |
|
786 | 786 | |
787 | - echo '</td>'; |
|
787 | + echo '</td>'; |
|
788 | 788 | |
789 | - } |
|
789 | + } |
|
790 | 790 | |
791 | - echo '</tr>'; |
|
791 | + echo '</tr>'; |
|
792 | 792 | |
793 | - endforeach; |
|
794 | - ?> |
|
793 | + endforeach; |
|
794 | + ?> |
|
795 | 795 | |
796 | 796 | </tbody> |
797 | 797 | |
@@ -810,38 +810,38 @@ discard block |
||
810 | 810 | */ |
811 | 811 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
812 | 812 | |
813 | - // Fetch the subscription groups. |
|
814 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
815 | - |
|
816 | - if ( empty( $subscription_groups ) ) { |
|
817 | - return; |
|
818 | - } |
|
819 | - |
|
820 | - // Prepare table columns. |
|
821 | - $columns = apply_filters( |
|
822 | - 'getpaid_subscription_related_subscriptions_columns', |
|
823 | - array( |
|
824 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
825 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
826 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
827 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
828 | - 'item' => __( 'Items', 'invoicing' ), |
|
829 | - 'status' => __( 'Status', 'invoicing' ), |
|
830 | - ), |
|
831 | - $subscription |
|
832 | - ); |
|
833 | - |
|
834 | - if ( $subscription->get_status() == 'pending' ) { |
|
835 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
836 | - } |
|
837 | - |
|
838 | - $table_class = 'w-100 bg-white'; |
|
839 | - |
|
840 | - if ( ! is_admin() ) { |
|
841 | - $table_class = 'table table-bordered'; |
|
842 | - } |
|
843 | - |
|
844 | - ?> |
|
813 | + // Fetch the subscription groups. |
|
814 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
815 | + |
|
816 | + if ( empty( $subscription_groups ) ) { |
|
817 | + return; |
|
818 | + } |
|
819 | + |
|
820 | + // Prepare table columns. |
|
821 | + $columns = apply_filters( |
|
822 | + 'getpaid_subscription_related_subscriptions_columns', |
|
823 | + array( |
|
824 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
825 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
826 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
827 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
828 | + 'item' => __( 'Items', 'invoicing' ), |
|
829 | + 'status' => __( 'Status', 'invoicing' ), |
|
830 | + ), |
|
831 | + $subscription |
|
832 | + ); |
|
833 | + |
|
834 | + if ( $subscription->get_status() == 'pending' ) { |
|
835 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
836 | + } |
|
837 | + |
|
838 | + $table_class = 'w-100 bg-white'; |
|
839 | + |
|
840 | + if ( ! is_admin() ) { |
|
841 | + $table_class = 'table table-bordered'; |
|
842 | + } |
|
843 | + |
|
844 | + ?> |
|
845 | 845 | <div class="m-0" style="overflow: auto;"> |
846 | 846 | |
847 | 847 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -850,10 +850,10 @@ discard block |
||
850 | 850 | <tr> |
851 | 851 | <?php |
852 | 852 | |
853 | - foreach ( $columns as $key => $label ) { |
|
854 | - echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
855 | - } |
|
856 | - ?> |
|
853 | + foreach ( $columns as $key => $label ) { |
|
854 | + echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
855 | + } |
|
856 | + ?> |
|
857 | 857 | </tr> |
858 | 858 | </thead> |
859 | 859 | |
@@ -861,74 +861,74 @@ discard block |
||
861 | 861 | |
862 | 862 | <?php |
863 | 863 | |
864 | - foreach ( $subscription_groups as $subscription_group ) : |
|
864 | + foreach ( $subscription_groups as $subscription_group ) : |
|
865 | 865 | |
866 | - // Do not list current subscription. |
|
867 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
868 | - continue; |
|
869 | - } |
|
866 | + // Do not list current subscription. |
|
867 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
868 | + continue; |
|
869 | + } |
|
870 | 870 | |
871 | - // Ensure the subscription exists. |
|
872 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
871 | + // Ensure the subscription exists. |
|
872 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
873 | 873 | |
874 | - if ( ! $_suscription->exists() ) { |
|
875 | - continue; |
|
876 | - } |
|
874 | + if ( ! $_suscription->exists() ) { |
|
875 | + continue; |
|
876 | + } |
|
877 | 877 | |
878 | - echo '<tr>'; |
|
878 | + echo '<tr>'; |
|
879 | 879 | |
880 | - foreach ( array_keys( $columns ) as $key ) { |
|
880 | + foreach ( array_keys( $columns ) as $key ) { |
|
881 | 881 | |
882 | - $class = 'text-left'; |
|
882 | + $class = 'text-left'; |
|
883 | 883 | |
884 | - echo "<td class='p-2 text-left'>"; |
|
884 | + echo "<td class='p-2 text-left'>"; |
|
885 | 885 | |
886 | - switch ( $key ) { |
|
886 | + switch ( $key ) { |
|
887 | 887 | |
888 | - case 'status': |
|
889 | - echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
890 | - break; |
|
888 | + case 'status': |
|
889 | + echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
890 | + break; |
|
891 | 891 | |
892 | - case 'item': |
|
893 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
894 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
895 | - break; |
|
892 | + case 'item': |
|
893 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
894 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
895 | + break; |
|
896 | 896 | |
897 | - case 'renewals': |
|
898 | - $max_bills = $_suscription->get_bill_times(); |
|
899 | - echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
900 | - break; |
|
897 | + case 'renewals': |
|
898 | + $max_bills = $_suscription->get_bill_times(); |
|
899 | + echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
900 | + break; |
|
901 | 901 | |
902 | - case 'renewal_date': |
|
903 | - echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
904 | - break; |
|
902 | + case 'renewal_date': |
|
903 | + echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
904 | + break; |
|
905 | 905 | |
906 | - case 'start_date': |
|
907 | - echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
908 | - break; |
|
906 | + case 'start_date': |
|
907 | + echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
908 | + break; |
|
909 | 909 | |
910 | - case 'subscription': |
|
911 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
912 | - printf( |
|
910 | + case 'subscription': |
|
911 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
912 | + printf( |
|
913 | 913 | '%1$s#%2$s%3$s', |
914 | 914 | '<a href="' . esc_url( $url ) . '">', |
915 | 915 | '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
916 | - '</a>' |
|
916 | + '</a>' |
|
917 | 917 | ); |
918 | 918 | |
919 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
920 | - break; |
|
919 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
920 | + break; |
|
921 | 921 | |
922 | - } |
|
922 | + } |
|
923 | 923 | |
924 | - echo '</td>'; |
|
924 | + echo '</td>'; |
|
925 | 925 | |
926 | - } |
|
926 | + } |
|
927 | 927 | |
928 | - echo '</tr>'; |
|
928 | + echo '</tr>'; |
|
929 | 929 | |
930 | - endforeach; |
|
931 | - ?> |
|
930 | + endforeach; |
|
931 | + ?> |
|
932 | 932 | |
933 | 933 | </tbody> |
934 | 934 |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'manual'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( |
28 | 28 | 'subscription', |
29 | 29 | 'addons', |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | ); |
35 | 35 | |
36 | 36 | /** |
37 | - * Payment method order. |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - public $order = 11; |
|
37 | + * Payment method order. |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + public $order = 11; |
|
42 | 42 | |
43 | 43 | /** |
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | 47 | parent::__construct(); |
48 | 48 | |
49 | 49 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -53,15 +53,15 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * Process Payment. |
|
57 | - * |
|
58 | - * |
|
59 | - * @param WPInv_Invoice $invoice Invoice. |
|
60 | - * @param array $submission_data Posted checkout fields. |
|
61 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
56 | + * Process Payment. |
|
57 | + * |
|
58 | + * |
|
59 | + * @param WPInv_Invoice $invoice Invoice. |
|
60 | + * @param array $submission_data Posted checkout fields. |
|
61 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
65 | 65 | |
66 | 66 | // Mark it as paid. |
67 | 67 | $invoice->mark_paid(); |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * (Maybe) renews a manual subscription profile. |
|
95 | - * |
|
96 | - * |
|
94 | + * (Maybe) renews a manual subscription profile. |
|
95 | + * |
|
96 | + * |
|
97 | 97 | * @param WPInv_Subscription $subscription |
98 | - */ |
|
99 | - public function maybe_renew_subscription( $subscription ) { |
|
98 | + */ |
|
99 | + public function maybe_renew_subscription( $subscription ) { |
|
100 | 100 | |
101 | 101 | // Ensure its our subscription && it's active. |
102 | 102 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
@@ -116,13 +116,13 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | - * Processes invoice addons. |
|
120 | - * |
|
121 | - * @param WPInv_Invoice $invoice |
|
122 | - * @param GetPaid_Form_Item[] $items |
|
123 | - * @return WPInv_Invoice |
|
124 | - */ |
|
125 | - public function process_addons( $invoice, $items ) { |
|
119 | + * Processes invoice addons. |
|
120 | + * |
|
121 | + * @param WPInv_Invoice $invoice |
|
122 | + * @param GetPaid_Form_Item[] $items |
|
123 | + * @return WPInv_Invoice |
|
124 | + */ |
|
125 | + public function process_addons( $invoice, $items ) { |
|
126 | 126 | |
127 | 127 | foreach ( $items as $item ) { |
128 | 128 | $invoice->add_item( $item ); |
@@ -13,47 +13,47 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( |
|
28 | - 'subscription', |
|
29 | - 'addons', |
|
30 | - 'single_subscription_group', |
|
31 | - 'multiple_subscription_groups', |
|
32 | - 'subscription_date_change', |
|
33 | - 'subscription_bill_times_change', |
|
34 | - ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( |
|
28 | + 'subscription', |
|
29 | + 'addons', |
|
30 | + 'single_subscription_group', |
|
31 | + 'multiple_subscription_groups', |
|
32 | + 'subscription_date_change', |
|
33 | + 'subscription_bill_times_change', |
|
34 | + ); |
|
35 | + |
|
36 | + /** |
|
37 | + * Payment method order. |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + public $order = 8; |
|
35 | 42 | |
36 | 43 | /** |
37 | - * Payment method order. |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - public $order = 8; |
|
42 | - |
|
43 | - /** |
|
44 | - * Bank transfer instructions. |
|
45 | - */ |
|
46 | - public $instructions; |
|
47 | - |
|
48 | - /** |
|
49 | - * Locale array. |
|
50 | - */ |
|
51 | - public $locale; |
|
44 | + * Bank transfer instructions. |
|
45 | + */ |
|
46 | + public $instructions; |
|
52 | 47 | |
53 | 48 | /** |
54 | - * Class constructor. |
|
55 | - */ |
|
56 | - public function __construct() { |
|
49 | + * Locale array. |
|
50 | + */ |
|
51 | + public $locale; |
|
52 | + |
|
53 | + /** |
|
54 | + * Class constructor. |
|
55 | + */ |
|
56 | + public function __construct() { |
|
57 | 57 | parent::__construct(); |
58 | 58 | |
59 | 59 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -61,24 +61,24 @@ discard block |
||
61 | 61 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
62 | 62 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
63 | 63 | |
64 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
69 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
64 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
69 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | - * Process Payment. |
|
75 | - * |
|
76 | - * @param WPInv_Invoice $invoice Invoice. |
|
77 | - * @param array $submission_data Posted checkout fields. |
|
78 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
74 | + * Process Payment. |
|
75 | + * |
|
76 | + * @param WPInv_Invoice $invoice Invoice. |
|
77 | + * @param array $submission_data Posted checkout fields. |
|
78 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
82 | 82 | |
83 | 83 | // Add a transaction id. |
84 | 84 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -99,66 +99,66 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | - * Output for the order received page. |
|
103 | - * |
|
104 | - * @param WPInv_Invoice $invoice Invoice. |
|
105 | - */ |
|
106 | - public function thankyou_page( $invoice ) { |
|
102 | + * Output for the order received page. |
|
103 | + * |
|
104 | + * @param WPInv_Invoice $invoice Invoice. |
|
105 | + */ |
|
106 | + public function thankyou_page( $invoice ) { |
|
107 | 107 | |
108 | 108 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
109 | 109 | |
110 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
110 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
111 | 111 | |
112 | 112 | if ( ! empty( $this->instructions ) ) { |
113 | 113 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | - $this->bank_details( $invoice ); |
|
116 | + $this->bank_details( $invoice ); |
|
117 | 117 | |
118 | - echo '</div>'; |
|
118 | + echo '</div>'; |
|
119 | 119 | |
120 | 120 | } |
121 | 121 | |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | 124 | /** |
125 | - * Add content to the WPI emails. |
|
126 | - * |
|
127 | - * @param WPInv_Invoice $invoice Invoice. |
|
128 | - * @param string $email_type Email format: plain text or HTML. |
|
129 | - * @param bool $sent_to_admin Sent to admin. |
|
130 | - */ |
|
131 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
125 | + * Add content to the WPI emails. |
|
126 | + * |
|
127 | + * @param WPInv_Invoice $invoice Invoice. |
|
128 | + * @param string $email_type Email format: plain text or HTML. |
|
129 | + * @param bool $sent_to_admin Sent to admin. |
|
130 | + */ |
|
131 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
132 | 132 | |
133 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
133 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
134 | 134 | |
135 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
135 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
136 | 136 | |
137 | - if ( $this->instructions ) { |
|
138 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
137 | + if ( $this->instructions ) { |
|
138 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
139 | 139 | } |
140 | 140 | |
141 | - $this->bank_details( $invoice ); |
|
141 | + $this->bank_details( $invoice ); |
|
142 | 142 | |
143 | - echo '</div>'; |
|
143 | + echo '</div>'; |
|
144 | 144 | |
145 | - } |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | - * Get bank details and place into a list format. |
|
151 | - * |
|
152 | - * @param WPInv_Invoice $invoice Invoice. |
|
153 | - */ |
|
154 | - protected function bank_details( $invoice ) { |
|
150 | + * Get bank details and place into a list format. |
|
151 | + * |
|
152 | + * @param WPInv_Invoice $invoice Invoice. |
|
153 | + */ |
|
154 | + protected function bank_details( $invoice ) { |
|
155 | 155 | |
156 | - // Get the invoice country and country $locale. |
|
157 | - $country = $invoice->get_country(); |
|
158 | - $locale = $this->get_country_locale(); |
|
156 | + // Get the invoice country and country $locale. |
|
157 | + $country = $invoice->get_country(); |
|
158 | + $locale = $this->get_country_locale(); |
|
159 | 159 | |
160 | - // Get sortcode label in the $locale array and use appropriate one. |
|
161 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
160 | + // Get sortcode label in the $locale array and use appropriate one. |
|
161 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
162 | 162 | |
163 | 163 | $bank_fields = array( |
164 | 164 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | |
178 | 178 | if ( ! empty( $value ) ) { |
179 | 179 | $bank_info[ $field ] = array( |
180 | - 'label' => $label, |
|
181 | - 'value' => $value, |
|
182 | - ); |
|
180 | + 'label' => $label, |
|
181 | + 'value' => $value, |
|
182 | + ); |
|
183 | 183 | } |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | 186 | $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
187 | 187 | |
@@ -189,139 +189,139 @@ discard block |
||
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
192 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
192 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
193 | + |
|
194 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
195 | + |
|
196 | + foreach ( $bank_info as $key => $data ) { |
|
197 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
198 | + } |
|
199 | + |
|
200 | + echo '</table>'; |
|
201 | + |
|
202 | + } |
|
193 | 203 | |
194 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
204 | + /** |
|
205 | + * Get country locale if localized. |
|
206 | + * |
|
207 | + * @return array |
|
208 | + */ |
|
209 | + public function get_country_locale() { |
|
210 | + |
|
211 | + if ( empty( $this->locale ) ) { |
|
212 | + |
|
213 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
214 | + $this->locale = apply_filters( |
|
215 | + 'getpaid_get_bank_transfer_locale', |
|
216 | + array( |
|
217 | + 'AU' => array( |
|
218 | + 'sortcode' => array( |
|
219 | + 'label' => __( 'BSB', 'invoicing' ), |
|
220 | + ), |
|
221 | + ), |
|
222 | + 'CA' => array( |
|
223 | + 'sortcode' => array( |
|
224 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
225 | + ), |
|
226 | + ), |
|
227 | + 'IN' => array( |
|
228 | + 'sortcode' => array( |
|
229 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
230 | + ), |
|
231 | + ), |
|
232 | + 'IT' => array( |
|
233 | + 'sortcode' => array( |
|
234 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
235 | + ), |
|
236 | + ), |
|
237 | + 'NZ' => array( |
|
238 | + 'sortcode' => array( |
|
239 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
240 | + ), |
|
241 | + ), |
|
242 | + 'SE' => array( |
|
243 | + 'sortcode' => array( |
|
244 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
245 | + ), |
|
246 | + ), |
|
247 | + 'US' => array( |
|
248 | + 'sortcode' => array( |
|
249 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
250 | + ), |
|
251 | + ), |
|
252 | + 'ZA' => array( |
|
253 | + 'sortcode' => array( |
|
254 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
255 | + ), |
|
256 | + ), |
|
257 | + ) |
|
258 | + ); |
|
195 | 259 | |
196 | - foreach ( $bank_info as $key => $data ) { |
|
197 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
198 | - } |
|
260 | + } |
|
199 | 261 | |
200 | - echo '</table>'; |
|
262 | + return $this->locale; |
|
201 | 263 | |
202 | 264 | } |
203 | 265 | |
204 | 266 | /** |
205 | - * Get country locale if localized. |
|
206 | - * |
|
207 | - * @return array |
|
208 | - */ |
|
209 | - public function get_country_locale() { |
|
210 | - |
|
211 | - if ( empty( $this->locale ) ) { |
|
212 | - |
|
213 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
214 | - $this->locale = apply_filters( |
|
215 | - 'getpaid_get_bank_transfer_locale', |
|
216 | - array( |
|
217 | - 'AU' => array( |
|
218 | - 'sortcode' => array( |
|
219 | - 'label' => __( 'BSB', 'invoicing' ), |
|
220 | - ), |
|
221 | - ), |
|
222 | - 'CA' => array( |
|
223 | - 'sortcode' => array( |
|
224 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
225 | - ), |
|
226 | - ), |
|
227 | - 'IN' => array( |
|
228 | - 'sortcode' => array( |
|
229 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
230 | - ), |
|
231 | - ), |
|
232 | - 'IT' => array( |
|
233 | - 'sortcode' => array( |
|
234 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
235 | - ), |
|
236 | - ), |
|
237 | - 'NZ' => array( |
|
238 | - 'sortcode' => array( |
|
239 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
240 | - ), |
|
241 | - ), |
|
242 | - 'SE' => array( |
|
243 | - 'sortcode' => array( |
|
244 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
245 | - ), |
|
246 | - ), |
|
247 | - 'US' => array( |
|
248 | - 'sortcode' => array( |
|
249 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
250 | - ), |
|
251 | - ), |
|
252 | - 'ZA' => array( |
|
253 | - 'sortcode' => array( |
|
254 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
255 | - ), |
|
256 | - ), |
|
257 | - ) |
|
258 | - ); |
|
259 | - |
|
260 | - } |
|
261 | - |
|
262 | - return $this->locale; |
|
263 | - |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Filters the gateway settings. |
|
268 | - * |
|
269 | - * @param array $admin_settings |
|
270 | - */ |
|
271 | - public function admin_settings( $admin_settings ) { |
|
267 | + * Filters the gateway settings. |
|
268 | + * |
|
269 | + * @param array $admin_settings |
|
270 | + */ |
|
271 | + public function admin_settings( $admin_settings ) { |
|
272 | 272 | |
273 | 273 | $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
274 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
274 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
275 | 275 | |
276 | - $locale = $this->get_country_locale(); |
|
276 | + $locale = $this->get_country_locale(); |
|
277 | 277 | |
278 | - // Get sortcode label in the $locale array and use appropriate one. |
|
279 | - $country = wpinv_default_billing_country(); |
|
280 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
278 | + // Get sortcode label in the $locale array and use appropriate one. |
|
279 | + $country = wpinv_default_billing_country(); |
|
280 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
281 | 281 | |
282 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
282 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
283 | 283 | 'type' => 'text', |
284 | 284 | 'id' => 'bank_transfer_ac_name', |
285 | 285 | 'name' => __( 'Account Name', 'invoicing' ), |
286 | - ); |
|
286 | + ); |
|
287 | 287 | |
288 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
288 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
289 | 289 | 'type' => 'text', |
290 | 290 | 'id' => 'bank_transfer_ac_no', |
291 | 291 | 'name' => __( 'Account Number', 'invoicing' ), |
292 | - ); |
|
292 | + ); |
|
293 | 293 | |
294 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
294 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
295 | 295 | 'type' => 'text', |
296 | 296 | 'id' => 'bank_transfer_bank_name', |
297 | 297 | 'name' => __( 'Bank Name', 'invoicing' ), |
298 | - ); |
|
298 | + ); |
|
299 | 299 | |
300 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
300 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
301 | 301 | 'type' => 'text', |
302 | 302 | 'id' => 'bank_transfer_ifsc', |
303 | 303 | 'name' => __( 'IFSC Code', 'invoicing' ), |
304 | - ); |
|
304 | + ); |
|
305 | 305 | |
306 | - $admin_settings['bank_transfer_iban'] = array( |
|
306 | + $admin_settings['bank_transfer_iban'] = array( |
|
307 | 307 | 'type' => 'text', |
308 | 308 | 'id' => 'bank_transfer_iban', |
309 | 309 | 'name' => __( 'IBAN', 'invoicing' ), |
310 | - ); |
|
310 | + ); |
|
311 | 311 | |
312 | - $admin_settings['bank_transfer_bic'] = array( |
|
312 | + $admin_settings['bank_transfer_bic'] = array( |
|
313 | 313 | 'type' => 'text', |
314 | 314 | 'id' => 'bank_transfer_bic', |
315 | 315 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
316 | - ); |
|
316 | + ); |
|
317 | 317 | |
318 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
319 | - 'type' => 'text', |
|
320 | - 'id' => 'bank_transfer_sort_code', |
|
321 | - 'name' => $sortcode, |
|
322 | - ); |
|
318 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
319 | + 'type' => 'text', |
|
320 | + 'id' => 'bank_transfer_sort_code', |
|
321 | + 'name' => $sortcode, |
|
322 | + ); |
|
323 | 323 | |
324 | - $admin_settings['bank_transfer_info'] = array( |
|
324 | + $admin_settings['bank_transfer_info'] = array( |
|
325 | 325 | 'id' => 'bank_transfer_info', |
326 | 326 | 'name' => __( 'Instructions', 'invoicing' ), |
327 | 327 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -331,17 +331,17 @@ discard block |
||
331 | 331 | 'rows' => 5, |
332 | 332 | ); |
333 | 333 | |
334 | - return $admin_settings; |
|
335 | - } |
|
334 | + return $admin_settings; |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * Processes invoice addons. |
|
339 | - * |
|
340 | - * @param WPInv_Invoice $invoice |
|
341 | - * @param GetPaid_Form_Item[] $items |
|
342 | - * @return WPInv_Invoice |
|
343 | - */ |
|
344 | - public function process_addons( $invoice, $items ) { |
|
337 | + /** |
|
338 | + * Processes invoice addons. |
|
339 | + * |
|
340 | + * @param WPInv_Invoice $invoice |
|
341 | + * @param GetPaid_Form_Item[] $items |
|
342 | + * @return WPInv_Invoice |
|
343 | + */ |
|
344 | + public function process_addons( $invoice, $items ) { |
|
345 | 345 | |
346 | 346 | foreach ( $items as $item ) { |
347 | 347 | $invoice->add_item( $item ); |
@@ -349,67 +349,67 @@ discard block |
||
349 | 349 | |
350 | 350 | $invoice->recalculate_total(); |
351 | 351 | $invoice->save(); |
352 | - } |
|
352 | + } |
|
353 | 353 | |
354 | - /** |
|
355 | - * (Maybe) renews a bank transfer subscription profile. |
|
356 | - * |
|
357 | - * |
|
354 | + /** |
|
355 | + * (Maybe) renews a bank transfer subscription profile. |
|
356 | + * |
|
357 | + * |
|
358 | 358 | * @param WPInv_Subscription $subscription |
359 | - */ |
|
360 | - public function maybe_renew_subscription( $subscription ) { |
|
359 | + */ |
|
360 | + public function maybe_renew_subscription( $subscription ) { |
|
361 | 361 | |
362 | 362 | // Ensure its our subscription && it's active. |
363 | 363 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
364 | - $subscription->create_payment(); |
|
364 | + $subscription->create_payment(); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | - /** |
|
370 | - * Process a bank transfer payment. |
|
371 | - * |
|
372 | - * |
|
369 | + /** |
|
370 | + * Process a bank transfer payment. |
|
371 | + * |
|
372 | + * |
|
373 | 373 | * @param WPInv_Invoice $invoice |
374 | - */ |
|
375 | - public function invoice_paid( $invoice ) { |
|
376 | - |
|
377 | - // Abort if not paid by bank transfer. |
|
378 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
379 | - return; |
|
380 | - } |
|
381 | - |
|
382 | - // Is it a parent payment? |
|
383 | - if ( 0 == $invoice->get_parent_id() ) { |
|
384 | - |
|
385 | - // (Maybe) activate subscriptions. |
|
386 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
387 | - |
|
388 | - if ( ! empty( $subscriptions ) ) { |
|
389 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
390 | - |
|
391 | - foreach ( $subscriptions as $subscription ) { |
|
392 | - if ( $subscription->exists() ) { |
|
393 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
394 | - $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
395 | - |
|
396 | - $subscription->set_next_renewal_date( $expiry ); |
|
397 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
398 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
399 | - $subscription->activate(); |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
403 | - } else { |
|
404 | - |
|
405 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
406 | - |
|
407 | - // Renew the subscription. |
|
408 | - if ( $subscription && $subscription->exists() ) { |
|
409 | - $subscription->add_payment( array(), $invoice ); |
|
410 | - $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
411 | - } |
|
412 | - } |
|
374 | + */ |
|
375 | + public function invoice_paid( $invoice ) { |
|
376 | + |
|
377 | + // Abort if not paid by bank transfer. |
|
378 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
379 | + return; |
|
380 | + } |
|
381 | + |
|
382 | + // Is it a parent payment? |
|
383 | + if ( 0 == $invoice->get_parent_id() ) { |
|
384 | + |
|
385 | + // (Maybe) activate subscriptions. |
|
386 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
387 | + |
|
388 | + if ( ! empty( $subscriptions ) ) { |
|
389 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
390 | + |
|
391 | + foreach ( $subscriptions as $subscription ) { |
|
392 | + if ( $subscription->exists() ) { |
|
393 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
394 | + $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
395 | + |
|
396 | + $subscription->set_next_renewal_date( $expiry ); |
|
397 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
398 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
399 | + $subscription->activate(); |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | + } else { |
|
404 | + |
|
405 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
406 | + |
|
407 | + // Renew the subscription. |
|
408 | + if ( $subscription && $subscription->exists() ) { |
|
409 | + $subscription->add_payment( array(), $invoice ); |
|
410 | + $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
411 | + } |
|
412 | + } |
|
413 | 413 | |
414 | 414 | } |
415 | 415 |
@@ -14,64 +14,64 @@ |
||
14 | 14 | * @return array|mixed|string|string[] |
15 | 15 | */ |
16 | 16 | function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) { |
17 | - global $aui_bs5; |
|
17 | + global $aui_bs5; |
|
18 | 18 | |
19 | - if ( $aui_bs5 ) { |
|
19 | + if ( $aui_bs5 ) { |
|
20 | 20 | |
21 | - $convert = array( |
|
22 | - 'ml-' => 'ms-', |
|
23 | - 'mr-' => 'me-', |
|
24 | - 'pl-' => 'ps-', |
|
25 | - 'pr-' => 'pe-', |
|
26 | - ' form-row' => ' row', |
|
27 | - ' embed-responsive-item' => '', |
|
28 | - ' embed-responsive' => ' ratio', |
|
29 | - '-1by1' => '-1x1', |
|
30 | - '-4by3' => '-4x3', |
|
31 | - '-16by9' => '-16x9', |
|
32 | - '-21by9' => '-21x9', |
|
33 | - 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
34 | - ' badge-' => ' text-bg-', |
|
35 | - 'form-group' => 'mb-3', |
|
36 | - 'custom-select' => 'form-select', |
|
37 | - 'float-left' => 'float-start', |
|
38 | - 'float-right' => 'float-end', |
|
39 | - 'text-left' => 'text-start', |
|
40 | - 'text-sm-left' => 'text-sm-start', |
|
41 | - 'text-md-left' => 'text-md-start', |
|
42 | - 'text-lg-left' => 'text-lg-start', |
|
43 | - 'text-right' => 'text-end', |
|
44 | - 'text-sm-right' => 'text-sm-end', |
|
45 | - 'text-md-right' => 'text-md-end', |
|
46 | - 'text-lg-right' => 'text-lg-end', |
|
47 | - 'border-right' => 'border-end', |
|
48 | - 'border-left' => 'border-start', |
|
49 | - 'font-weight-' => 'fw-', |
|
50 | - 'btn-block' => 'w-100', |
|
51 | - 'rounded-left' => 'rounded-start', |
|
52 | - 'rounded-right' => 'rounded-end', |
|
53 | - 'font-italic' => 'fst-italic', |
|
21 | + $convert = array( |
|
22 | + 'ml-' => 'ms-', |
|
23 | + 'mr-' => 'me-', |
|
24 | + 'pl-' => 'ps-', |
|
25 | + 'pr-' => 'pe-', |
|
26 | + ' form-row' => ' row', |
|
27 | + ' embed-responsive-item' => '', |
|
28 | + ' embed-responsive' => ' ratio', |
|
29 | + '-1by1' => '-1x1', |
|
30 | + '-4by3' => '-4x3', |
|
31 | + '-16by9' => '-16x9', |
|
32 | + '-21by9' => '-21x9', |
|
33 | + 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
34 | + ' badge-' => ' text-bg-', |
|
35 | + 'form-group' => 'mb-3', |
|
36 | + 'custom-select' => 'form-select', |
|
37 | + 'float-left' => 'float-start', |
|
38 | + 'float-right' => 'float-end', |
|
39 | + 'text-left' => 'text-start', |
|
40 | + 'text-sm-left' => 'text-sm-start', |
|
41 | + 'text-md-left' => 'text-md-start', |
|
42 | + 'text-lg-left' => 'text-lg-start', |
|
43 | + 'text-right' => 'text-end', |
|
44 | + 'text-sm-right' => 'text-sm-end', |
|
45 | + 'text-md-right' => 'text-md-end', |
|
46 | + 'text-lg-right' => 'text-lg-end', |
|
47 | + 'border-right' => 'border-end', |
|
48 | + 'border-left' => 'border-start', |
|
49 | + 'font-weight-' => 'fw-', |
|
50 | + 'btn-block' => 'w-100', |
|
51 | + 'rounded-left' => 'rounded-start', |
|
52 | + 'rounded-right' => 'rounded-end', |
|
53 | + 'font-italic' => 'fst-italic', |
|
54 | 54 | |
55 | 55 | // 'custom-control custom-checkbox' => 'form-check', |
56 | - // data |
|
57 | - ' data-toggle=' => ' data-bs-toggle=', |
|
58 | - 'data-ride=' => 'data-bs-ride=', |
|
59 | - 'data-controlnav=' => 'data-bs-controlnav=', |
|
60 | - 'data-slide=' => 'data-bs-slide=', |
|
61 | - 'data-slide-to=' => 'data-bs-slide-to=', |
|
62 | - 'data-target=' => 'data-bs-target=', |
|
63 | - 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
64 | - 'class="close"' => 'class="btn-close"', |
|
65 | - '<span aria-hidden="true">×</span>' => '', |
|
66 | - ); |
|
67 | - $output = str_replace( |
|
68 | - array_keys( $convert ), |
|
69 | - array_values( $convert ), |
|
70 | - $output |
|
71 | - ); |
|
72 | - } |
|
56 | + // data |
|
57 | + ' data-toggle=' => ' data-bs-toggle=', |
|
58 | + 'data-ride=' => 'data-bs-ride=', |
|
59 | + 'data-controlnav=' => 'data-bs-controlnav=', |
|
60 | + 'data-slide=' => 'data-bs-slide=', |
|
61 | + 'data-slide-to=' => 'data-bs-slide-to=', |
|
62 | + 'data-target=' => 'data-bs-target=', |
|
63 | + 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
64 | + 'class="close"' => 'class="btn-close"', |
|
65 | + '<span aria-hidden="true">×</span>' => '', |
|
66 | + ); |
|
67 | + $output = str_replace( |
|
68 | + array_keys( $convert ), |
|
69 | + array_values( $convert ), |
|
70 | + $output |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - return $output; |
|
74 | + return $output; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | 64 | } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | $types = wpinv_get_discount_types(); |
122 | 122 | |
123 | 123 | foreach ( $types as $name => $type ) { |
124 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
124 | + echo '<option value="' . esc_attr( $name ) . '"'; |
|
125 | 125 | |
126 | - if ( isset( $_GET['discount_type'] ) ) { |
|
127 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
126 | + if ( isset( $_GET['discount_type'] ) ) { |
|
127 | + selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
128 | 128 | } |
129 | 129 | |
130 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
130 | + echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
131 | 131 | } |
132 | 132 | ?> |
133 | 133 | </select> |
@@ -154,15 +154,15 @@ discard block |
||
154 | 154 | // Filter vat rule type |
155 | 155 | if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
156 | 156 | $meta_query[] = array( |
157 | - 'key' => '_wpi_discount_type', |
|
158 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
159 | - 'compare' => '=', |
|
160 | - ); |
|
161 | - } |
|
157 | + 'key' => '_wpi_discount_type', |
|
158 | + 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
159 | + 'compare' => '=', |
|
160 | + ); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | if ( ! empty( $meta_query ) ) { |
164 | 164 | $vars['meta_query'] = $meta_query; |
165 | - } |
|
165 | + } |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | return $vars; |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( |
28 | 28 | 'subscription', |
29 | 29 | 'sandbox', |
@@ -36,44 +36,44 @@ discard block |
||
36 | 36 | ); |
37 | 37 | |
38 | 38 | /** |
39 | - * Payment method order. |
|
40 | - * |
|
41 | - * @var int |
|
42 | - */ |
|
39 | + * Payment method order. |
|
40 | + * |
|
41 | + * @var int |
|
42 | + */ |
|
43 | 43 | public $order = 4; |
44 | 44 | |
45 | 45 | /** |
46 | - * Endpoint for requests from Authorize.net. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $notify_url; |
|
51 | - |
|
52 | - /** |
|
53 | - * Endpoint for requests to Authorize.net. |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
46 | + * Endpoint for requests from Authorize.net. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $notify_url; |
|
51 | + |
|
52 | + /** |
|
53 | + * Endpoint for requests to Authorize.net. |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | 57 | protected $endpoint; |
58 | 58 | |
59 | 59 | /** |
60 | - * Currencies this gateway is allowed for. |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
60 | + * Currencies this gateway is allowed for. |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
65 | 65 | |
66 | 66 | /** |
67 | - * URL to view a transaction. |
|
68 | - * |
|
69 | - * @var string |
|
70 | - */ |
|
67 | + * URL to view a transaction. |
|
68 | + * |
|
69 | + * @var string |
|
70 | + */ |
|
71 | 71 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
72 | 72 | |
73 | 73 | /** |
74 | - * Class constructor. |
|
75 | - */ |
|
76 | - public function __construct() { |
|
74 | + * Class constructor. |
|
75 | + */ |
|
76 | + public function __construct() { |
|
77 | 77 | |
78 | 78 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
79 | 79 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Displays the payment method select field. |
|
89 | - * |
|
90 | - * @param int $invoice_id 0 or invoice id. |
|
91 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
92 | - */ |
|
88 | + * Displays the payment method select field. |
|
89 | + * |
|
90 | + * @param int $invoice_id 0 or invoice id. |
|
91 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
92 | + */ |
|
93 | 93 | public function payment_fields( $invoice_id, $form ) { |
94 | 94 | |
95 | 95 | // Let the user select a payment method. |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * Creates a customer profile. |
|
104 | - * |
|
105 | - * |
|
106 | - * @param WPInv_Invoice $invoice Invoice. |
|
103 | + * Creates a customer profile. |
|
104 | + * |
|
105 | + * |
|
106 | + * @param WPInv_Invoice $invoice Invoice. |
|
107 | 107 | * @param array $submission_data Posted checkout fields. |
108 | 108 | * @param bool $save Whether or not to save the payment as a token. |
109 | 109 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
110 | - * @return string|WP_Error Payment profile id. |
|
111 | - */ |
|
112 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
110 | + * @return string|WP_Error Payment profile id. |
|
111 | + */ |
|
112 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
113 | 113 | |
114 | 114 | // Remove non-digits from the number |
115 | 115 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * Retrieves a customer profile. |
|
195 | - * |
|
196 | - * |
|
197 | - * @param string $profile_id profile id. |
|
198 | - * @return string|WP_Error Profile id. |
|
194 | + * Retrieves a customer profile. |
|
195 | + * |
|
196 | + * |
|
197 | + * @param string $profile_id profile id. |
|
198 | + * @return string|WP_Error Profile id. |
|
199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
200 | - */ |
|
201 | - public function get_customer_profile( $profile_id ) { |
|
200 | + */ |
|
201 | + public function get_customer_profile( $profile_id ) { |
|
202 | 202 | |
203 | 203 | // Generate args. |
204 | 204 | $args = array( |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | - * Creates a customer profile. |
|
217 | - * |
|
218 | - * |
|
216 | + * Creates a customer profile. |
|
217 | + * |
|
218 | + * |
|
219 | 219 | * @param string $profile_id profile id. |
220 | - * @param WPInv_Invoice $invoice Invoice. |
|
220 | + * @param WPInv_Invoice $invoice Invoice. |
|
221 | 221 | * @param array $submission_data Posted checkout fields. |
222 | 222 | * @param bool $save Whether or not to save the payment as a token. |
223 | 223 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
224 | - * @return string|WP_Error Profile id. |
|
225 | - */ |
|
226 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
224 | + * @return string|WP_Error Profile id. |
|
225 | + */ |
|
226 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
227 | 227 | |
228 | 228 | // Remove non-digits from the number |
229 | 229 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
314 | - * Retrieves payment details from cache. |
|
315 | - * |
|
316 | - * |
|
314 | + * Retrieves payment details from cache. |
|
315 | + * |
|
316 | + * |
|
317 | 317 | * @param array $payment_details. |
318 | - * @return array|false Profile id. |
|
319 | - */ |
|
320 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
318 | + * @return array|false Profile id. |
|
319 | + */ |
|
320 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
321 | 321 | |
322 | 322 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
323 | 323 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -342,13 +342,13 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
345 | - * Securely adds payment details to cache. |
|
346 | - * |
|
347 | - * |
|
345 | + * Securely adds payment details to cache. |
|
346 | + * |
|
347 | + * |
|
348 | 348 | * @param array $payment_details. |
349 | 349 | * @param string $payment_profile_id. |
350 | - */ |
|
351 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
350 | + */ |
|
351 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
352 | 352 | |
353 | 353 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
354 | 354 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -360,15 +360,15 @@ discard block |
||
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
363 | - * Retrieves a customer payment profile. |
|
364 | - * |
|
365 | - * |
|
366 | - * @param string $customer_profile_id customer profile id. |
|
363 | + * Retrieves a customer payment profile. |
|
364 | + * |
|
365 | + * |
|
366 | + * @param string $customer_profile_id customer profile id. |
|
367 | 367 | * @param string $payment_profile_id payment profile id. |
368 | - * @return string|WP_Error Profile id. |
|
368 | + * @return string|WP_Error Profile id. |
|
369 | 369 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
370 | - */ |
|
371 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
370 | + */ |
|
371 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
372 | 372 | |
373 | 373 | // Generate args. |
374 | 374 | $args = array( |
@@ -384,15 +384,15 @@ discard block |
||
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
387 | - * Charges a customer payment profile. |
|
388 | - * |
|
387 | + * Charges a customer payment profile. |
|
388 | + * |
|
389 | 389 | * @param string $customer_profile_id customer profile id. |
390 | 390 | * @param string $payment_profile_id payment profile id. |
391 | - * @param WPInv_Invoice $invoice Invoice. |
|
391 | + * @param WPInv_Invoice $invoice Invoice. |
|
392 | 392 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
393 | - * @return WP_Error|object |
|
394 | - */ |
|
395 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
393 | + * @return WP_Error|object |
|
394 | + */ |
|
395 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
396 | 396 | |
397 | 397 | // Generate args. |
398 | 398 | $args = array( |
@@ -438,43 +438,43 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
441 | - * Processes a customer charge. |
|
442 | - * |
|
441 | + * Processes a customer charge. |
|
442 | + * |
|
443 | 443 | * @param stdClass $result Api response. |
444 | - * @param WPInv_Invoice $invoice Invoice. |
|
445 | - */ |
|
446 | - public function process_charge_response( $result, $invoice ) { |
|
444 | + * @param WPInv_Invoice $invoice Invoice. |
|
445 | + */ |
|
446 | + public function process_charge_response( $result, $invoice ) { |
|
447 | 447 | |
448 | 448 | wpinv_clear_errors(); |
449 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
449 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
450 | 450 | |
451 | 451 | $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true ); |
452 | 452 | |
453 | - // Succeeded. |
|
454 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
453 | + // Succeeded. |
|
454 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
455 | 455 | |
456 | - // Maybe set a transaction id. |
|
457 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
458 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
459 | - } |
|
456 | + // Maybe set a transaction id. |
|
457 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
458 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
459 | + } |
|
460 | 460 | |
461 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
461 | + $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
462 | 462 | |
463 | - if ( 1 == $response_code ) { |
|
464 | - return $invoice->mark_paid(); |
|
465 | - } |
|
463 | + if ( 1 == $response_code ) { |
|
464 | + return $invoice->mark_paid(); |
|
465 | + } |
|
466 | 466 | |
467 | - $invoice->set_status( 'wpi-onhold' ); |
|
468 | - $invoice->add_note( |
|
467 | + $invoice->set_status( 'wpi-onhold' ); |
|
468 | + $invoice->add_note( |
|
469 | 469 | sprintf( |
470 | 470 | __( 'Held for review: %s', 'invoicing' ), |
471 | 471 | $result->transactionResponse->messages->message[0]->description |
472 | 472 | ) |
473 | - ); |
|
473 | + ); |
|
474 | 474 | |
475 | - return $invoice->save(); |
|
475 | + return $invoice->save(); |
|
476 | 476 | |
477 | - } |
|
477 | + } |
|
478 | 478 | |
479 | 479 | wpinv_set_error( 'card_declined' ); |
480 | 480 | |
@@ -486,13 +486,13 @@ discard block |
||
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
489 | - * Returns payment information. |
|
490 | - * |
|
491 | - * |
|
492 | - * @param array $card Card details. |
|
493 | - * @return array |
|
494 | - */ |
|
495 | - public function get_payment_information( $card ) { |
|
489 | + * Returns payment information. |
|
490 | + * |
|
491 | + * |
|
492 | + * @param array $card Card details. |
|
493 | + * @return array |
|
494 | + */ |
|
495 | + public function get_payment_information( $card ) { |
|
496 | 496 | return array( |
497 | 497 | |
498 | 498 | 'creditCard' => array( |
@@ -505,25 +505,25 @@ discard block |
||
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
508 | - * Returns the customer profile meta name. |
|
509 | - * |
|
510 | - * |
|
511 | - * @param WPInv_Invoice $invoice Invoice. |
|
512 | - * @return string |
|
513 | - */ |
|
514 | - public function get_customer_profile_meta_name( $invoice ) { |
|
508 | + * Returns the customer profile meta name. |
|
509 | + * |
|
510 | + * |
|
511 | + * @param WPInv_Invoice $invoice Invoice. |
|
512 | + * @return string |
|
513 | + */ |
|
514 | + public function get_customer_profile_meta_name( $invoice ) { |
|
515 | 515 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
519 | - * Validates the submitted data. |
|
520 | - * |
|
521 | - * |
|
522 | - * @param array $submission_data Posted checkout fields. |
|
519 | + * Validates the submitted data. |
|
520 | + * |
|
521 | + * |
|
522 | + * @param array $submission_data Posted checkout fields. |
|
523 | 523 | * @param WPInv_Invoice $invoice |
524 | - * @return WP_Error|string The payment profile id |
|
525 | - */ |
|
526 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
524 | + * @return WP_Error|string The payment profile id |
|
525 | + */ |
|
526 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
527 | 527 | |
528 | 528 | // Validate authentication details. |
529 | 529 | $auth = $this->get_auth_params(); |
@@ -555,13 +555,13 @@ discard block |
||
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Returns invoice line items. |
|
559 | - * |
|
560 | - * |
|
561 | - * @param WPInv_Invoice $invoice Invoice. |
|
562 | - * @return array |
|
563 | - */ |
|
564 | - public function get_line_items( $invoice ) { |
|
558 | + * Returns invoice line items. |
|
559 | + * |
|
560 | + * |
|
561 | + * @param WPInv_Invoice $invoice Invoice. |
|
562 | + * @return array |
|
563 | + */ |
|
564 | + public function get_line_items( $invoice ) { |
|
565 | 565 | $items = array(); |
566 | 566 | |
567 | 567 | foreach ( $invoice->get_items() as $item ) { |
@@ -598,15 +598,15 @@ discard block |
||
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
601 | - * Process Payment. |
|
602 | - * |
|
603 | - * |
|
604 | - * @param WPInv_Invoice $invoice Invoice. |
|
605 | - * @param array $submission_data Posted checkout fields. |
|
606 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
607 | - * @return array |
|
608 | - */ |
|
609 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
601 | + * Process Payment. |
|
602 | + * |
|
603 | + * |
|
604 | + * @param WPInv_Invoice $invoice Invoice. |
|
605 | + * @param array $submission_data Posted checkout fields. |
|
606 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
607 | + * @return array |
|
608 | + */ |
|
609 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
610 | 610 | |
611 | 611 | // Validate the submitted data. |
612 | 612 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -639,45 +639,45 @@ discard block |
||
639 | 639 | |
640 | 640 | exit; |
641 | 641 | |
642 | - } |
|
642 | + } |
|
643 | 643 | |
644 | - /** |
|
645 | - * Processes the initial payment. |
|
646 | - * |
|
644 | + /** |
|
645 | + * Processes the initial payment. |
|
646 | + * |
|
647 | 647 | * @param WPInv_Invoice $invoice Invoice. |
648 | - */ |
|
649 | - protected function process_initial_payment( $invoice ) { |
|
648 | + */ |
|
649 | + protected function process_initial_payment( $invoice ) { |
|
650 | 650 | |
651 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
651 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
652 | 652 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
653 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
653 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
654 | 654 | |
655 | - // Do we have an error? |
|
656 | - if ( is_wp_error( $result ) ) { |
|
657 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
658 | - wpinv_send_back_to_checkout( $invoice ); |
|
659 | - } |
|
655 | + // Do we have an error? |
|
656 | + if ( is_wp_error( $result ) ) { |
|
657 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
658 | + wpinv_send_back_to_checkout( $invoice ); |
|
659 | + } |
|
660 | 660 | |
661 | - // Process the response. |
|
662 | - $this->process_charge_response( $result, $invoice ); |
|
661 | + // Process the response. |
|
662 | + $this->process_charge_response( $result, $invoice ); |
|
663 | 663 | |
664 | - if ( wpinv_get_errors() ) { |
|
665 | - wpinv_send_back_to_checkout( $invoice ); |
|
666 | - } |
|
664 | + if ( wpinv_get_errors() ) { |
|
665 | + wpinv_send_back_to_checkout( $invoice ); |
|
666 | + } |
|
667 | 667 | |
668 | - } |
|
668 | + } |
|
669 | 669 | |
670 | 670 | /** |
671 | - * Processes recurring payments. |
|
672 | - * |
|
671 | + * Processes recurring payments. |
|
672 | + * |
|
673 | 673 | * @param WPInv_Invoice $invoice Invoice. |
674 | 674 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
675 | - */ |
|
676 | - public function process_subscription( $invoice, $subscriptions ) { |
|
675 | + */ |
|
676 | + public function process_subscription( $invoice, $subscriptions ) { |
|
677 | 677 | |
678 | 678 | // Check if there is an initial amount to charge. |
679 | 679 | if ( (float) $invoice->get_total() > 0 ) { |
680 | - $this->process_initial_payment( $invoice ); |
|
680 | + $this->process_initial_payment( $invoice ); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | // Activate the subscriptions. |
@@ -695,36 +695,36 @@ discard block |
||
695 | 695 | } |
696 | 696 | } |
697 | 697 | |
698 | - // Redirect to the success page. |
|
698 | + // Redirect to the success page. |
|
699 | 699 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
700 | 700 | |
701 | 701 | } |
702 | 702 | |
703 | - /** |
|
704 | - * (Maybe) renews an authorize.net subscription profile. |
|
705 | - * |
|
706 | - * |
|
703 | + /** |
|
704 | + * (Maybe) renews an authorize.net subscription profile. |
|
705 | + * |
|
706 | + * |
|
707 | 707 | * @param WPInv_Subscription $subscription |
708 | - */ |
|
709 | - public function maybe_renew_subscription( $subscription ) { |
|
708 | + */ |
|
709 | + public function maybe_renew_subscription( $subscription ) { |
|
710 | 710 | |
711 | 711 | // Ensure its our subscription && it's active. |
712 | 712 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
713 | 713 | $this->renew_subscription( $subscription ); |
714 | 714 | } |
715 | 715 | |
716 | - } |
|
716 | + } |
|
717 | 717 | |
718 | 718 | /** |
719 | - * Renews a subscription. |
|
720 | - * |
|
719 | + * Renews a subscription. |
|
720 | + * |
|
721 | 721 | * @param WPInv_Subscription $subscription |
722 | - */ |
|
723 | - public function renew_subscription( $subscription ) { |
|
722 | + */ |
|
723 | + public function renew_subscription( $subscription ) { |
|
724 | 724 | |
725 | - // Generate the renewal invoice. |
|
726 | - $new_invoice = $subscription->create_payment(); |
|
727 | - $old_invoice = $subscription->get_parent_payment(); |
|
725 | + // Generate the renewal invoice. |
|
726 | + $new_invoice = $subscription->create_payment(); |
|
727 | + $old_invoice = $subscription->get_parent_payment(); |
|
728 | 728 | |
729 | 729 | if ( empty( $new_invoice ) ) { |
730 | 730 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -733,37 +733,37 @@ discard block |
||
733 | 733 | } |
734 | 734 | |
735 | 735 | // Charge the payment method. |
736 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
737 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
738 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
739 | - |
|
740 | - // Do we have an error? |
|
741 | - if ( is_wp_error( $result ) ) { |
|
742 | - |
|
743 | - $old_invoice->add_note( |
|
744 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
745 | - true, |
|
746 | - false, |
|
747 | - true |
|
748 | - ); |
|
749 | - $subscription->failing(); |
|
750 | - return; |
|
751 | - |
|
752 | - } |
|
753 | - |
|
754 | - // Process the response. |
|
755 | - $this->process_charge_response( $result, $new_invoice ); |
|
756 | - |
|
757 | - if ( wpinv_get_errors() ) { |
|
758 | - |
|
759 | - $old_invoice->add_note( |
|
760 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
761 | - true, |
|
762 | - false, |
|
763 | - true |
|
764 | - ); |
|
765 | - $subscription->failing(); |
|
766 | - return; |
|
736 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
737 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
738 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
739 | + |
|
740 | + // Do we have an error? |
|
741 | + if ( is_wp_error( $result ) ) { |
|
742 | + |
|
743 | + $old_invoice->add_note( |
|
744 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
745 | + true, |
|
746 | + false, |
|
747 | + true |
|
748 | + ); |
|
749 | + $subscription->failing(); |
|
750 | + return; |
|
751 | + |
|
752 | + } |
|
753 | + |
|
754 | + // Process the response. |
|
755 | + $this->process_charge_response( $result, $new_invoice ); |
|
756 | + |
|
757 | + if ( wpinv_get_errors() ) { |
|
758 | + |
|
759 | + $old_invoice->add_note( |
|
760 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
761 | + true, |
|
762 | + false, |
|
763 | + true |
|
764 | + ); |
|
765 | + $subscription->failing(); |
|
766 | + return; |
|
767 | 767 | |
768 | 768 | } |
769 | 769 | |
@@ -776,13 +776,13 @@ discard block |
||
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
779 | - * Processes invoice addons. |
|
780 | - * |
|
781 | - * @param WPInv_Invoice $invoice |
|
782 | - * @param GetPaid_Form_Item[] $items |
|
783 | - * @return WPInv_Invoice |
|
784 | - */ |
|
785 | - public function process_addons( $invoice, $items ) { |
|
779 | + * Processes invoice addons. |
|
780 | + * |
|
781 | + * @param WPInv_Invoice $invoice |
|
782 | + * @param GetPaid_Form_Item[] $items |
|
783 | + * @return WPInv_Invoice |
|
784 | + */ |
|
785 | + public function process_addons( $invoice, $items ) { |
|
786 | 786 | |
787 | 787 | global $getpaid_authorize_addons; |
788 | 788 | |
@@ -801,7 +801,7 @@ discard block |
||
801 | 801 | $invoice->recalculate_total(); |
802 | 802 | |
803 | 803 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
804 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
804 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
805 | 805 | |
806 | 806 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
807 | 807 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -816,11 +816,11 @@ discard block |
||
816 | 816 | } |
817 | 817 | |
818 | 818 | /** |
819 | - * Processes invoice addons. |
|
820 | - * |
|
819 | + * Processes invoice addons. |
|
820 | + * |
|
821 | 821 | * @param array $args |
822 | - * @return array |
|
823 | - */ |
|
822 | + * @return array |
|
823 | + */ |
|
824 | 824 | public function filter_addons_request( $args ) { |
825 | 825 | |
826 | 826 | global $getpaid_authorize_addons; |
@@ -854,11 +854,11 @@ discard block |
||
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
857 | - * Filters the gateway settings. |
|
858 | - * |
|
859 | - * @param array $admin_settings |
|
860 | - */ |
|
861 | - public function admin_settings( $admin_settings ) { |
|
857 | + * Filters the gateway settings. |
|
858 | + * |
|
859 | + * @param array $admin_settings |
|
860 | + */ |
|
861 | + public function admin_settings( $admin_settings ) { |
|
862 | 862 | |
863 | 863 | $currencies = sprintf( |
864 | 864 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | 'readonly' => true, |
899 | 899 | ); |
900 | 900 | |
901 | - return $admin_settings; |
|
902 | - } |
|
901 | + return $admin_settings; |
|
902 | + } |
|
903 | 903 | |
904 | 904 | } |
@@ -15,125 +15,125 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => '', |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | - * |
|
68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | - * @param bool $deprecated |
|
70 | - */ |
|
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | - |
|
73 | - parent::__construct( $subscription ); |
|
74 | - |
|
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | - $this->set_id( $subscription_id ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
83 | - } else { |
|
84 | - $this->set_object_read( true ); |
|
85 | - } |
|
86 | - |
|
87 | - // Load the datastore. |
|
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | - |
|
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | - * |
|
99 | - * |
|
100 | - * @static |
|
101 | - * @param string $value |
|
102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | - * @since 1.0.19 |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => '', |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | + * |
|
68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | + * @param bool $deprecated |
|
70 | + */ |
|
71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | + |
|
73 | + parent::__construct( $subscription ); |
|
74 | + |
|
75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | + $this->set_id( $subscription ); |
|
77 | + } elseif ( $subscription instanceof self ) { |
|
78 | + $this->set_id( $subscription->get_id() ); |
|
79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | + $this->set_id( $subscription_id ); |
|
81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
82 | + $this->set_id( $subscription->id ); |
|
83 | + } else { |
|
84 | + $this->set_object_read( true ); |
|
85 | + } |
|
86 | + |
|
87 | + // Load the datastore. |
|
88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | + |
|
90 | + if ( $this->get_id() > 0 ) { |
|
91 | + $this->data_store->read( $this ); |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | + * |
|
99 | + * |
|
100 | + * @static |
|
101 | + * @param string $value |
|
102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | + * @since 1.0.19 |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - // Trim the value. |
|
110 | - $value = trim( $value ); |
|
109 | + // Trim the value. |
|
110 | + $value = trim( $value ); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
113 | - return 0; |
|
114 | - } |
|
112 | + if ( empty( $value ) ) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
117 | - $field = 'parent_payment_id'; |
|
118 | - } |
|
116 | + if ( 'invoice_id' == $field ) { |
|
117 | + $field = 'parent_payment_id'; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // Valid fields. |
121 | 121 | $fields = array( |
122 | - 'parent_payment_id', |
|
123 | - 'transaction_id', |
|
124 | - 'profile_id', |
|
125 | - ); |
|
126 | - |
|
127 | - // Ensure a field has been passed. |
|
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - // Maybe retrieve from the cache. |
|
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
135 | - return $subscription_id; |
|
136 | - } |
|
122 | + 'parent_payment_id', |
|
123 | + 'transaction_id', |
|
124 | + 'profile_id', |
|
125 | + ); |
|
126 | + |
|
127 | + // Ensure a field has been passed. |
|
128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + // Maybe retrieve from the cache. |
|
133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | + if ( ! empty( $subscription_id ) ) { |
|
135 | + return $subscription_id; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,42 +141,42 @@ discard block |
||
141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
145 | - return 0; |
|
146 | - } |
|
144 | + if ( empty( $subscription_id ) ) { |
|
145 | + return 0; |
|
146 | + } |
|
147 | 147 | |
148 | - // Update the cache with our data. |
|
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
148 | + // Update the cache with our data. |
|
149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
150 | 150 | |
151 | - return $subscription_id; |
|
152 | - } |
|
151 | + return $subscription_id; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
154 | + /** |
|
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - $caches = array( |
|
159 | - 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | - 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | - 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | - 'getpaid_subscriptions' => $this->get_id(), |
|
163 | - ); |
|
164 | - |
|
165 | - foreach ( $caches as $cache => $value ) { |
|
166 | - if ( '' !== $value && false !== $value ) { |
|
167 | - wp_cache_delete( $value, $cache ); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
158 | + $caches = array( |
|
159 | + 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | + 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | + 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | + 'getpaid_subscriptions' => $this->get_id(), |
|
163 | + ); |
|
164 | + |
|
165 | + foreach ( $caches as $cache => $value ) { |
|
166 | + if ( '' !== $value && false !== $value ) { |
|
167 | + wp_cache_delete( $value, $cache ); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | 173 | * Checks if a subscription key is set. |
174 | 174 | */ |
175 | 175 | public function _isset( $key ) { |
176 | 176 | return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - /* |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | CRUD methods |
182 | 182 | |-------------------------------------------------------------------------- |
@@ -185,544 +185,544 @@ discard block |
||
185 | 185 | | |
186 | 186 | */ |
187 | 187 | |
188 | - /* |
|
188 | + /* |
|
189 | 189 | |-------------------------------------------------------------------------- |
190 | 190 | | Getters |
191 | 191 | |-------------------------------------------------------------------------- |
192 | 192 | */ |
193 | 193 | |
194 | - /** |
|
195 | - * Get customer id. |
|
196 | - * |
|
197 | - * @since 1.0.19 |
|
198 | - * @param string $context View or edit context. |
|
199 | - * @return int |
|
200 | - */ |
|
201 | - public function get_customer_id( $context = 'view' ) { |
|
202 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Get customer information. |
|
207 | - * |
|
208 | - * @since 1.0.19 |
|
209 | - * @param string $context View or edit context. |
|
210 | - * @return WP_User|false WP_User object on success, false on failure. |
|
211 | - */ |
|
212 | - public function get_customer( $context = 'view' ) { |
|
213 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Get parent invoice id. |
|
218 | - * |
|
219 | - * @since 1.0.19 |
|
220 | - * @param string $context View or edit context. |
|
221 | - * @return int |
|
222 | - */ |
|
223 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Alias for self::get_parent_invoice_id(). |
|
229 | - * |
|
230 | - * @since 1.0.19 |
|
231 | - * @param string $context View or edit context. |
|
232 | - * @return int |
|
233 | - */ |
|
194 | + /** |
|
195 | + * Get customer id. |
|
196 | + * |
|
197 | + * @since 1.0.19 |
|
198 | + * @param string $context View or edit context. |
|
199 | + * @return int |
|
200 | + */ |
|
201 | + public function get_customer_id( $context = 'view' ) { |
|
202 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Get customer information. |
|
207 | + * |
|
208 | + * @since 1.0.19 |
|
209 | + * @param string $context View or edit context. |
|
210 | + * @return WP_User|false WP_User object on success, false on failure. |
|
211 | + */ |
|
212 | + public function get_customer( $context = 'view' ) { |
|
213 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Get parent invoice id. |
|
218 | + * |
|
219 | + * @since 1.0.19 |
|
220 | + * @param string $context View or edit context. |
|
221 | + * @return int |
|
222 | + */ |
|
223 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Alias for self::get_parent_invoice_id(). |
|
229 | + * |
|
230 | + * @since 1.0.19 |
|
231 | + * @param string $context View or edit context. |
|
232 | + * @return int |
|
233 | + */ |
|
234 | 234 | public function get_parent_payment_id( $context = 'view' ) { |
235 | 235 | return $this->get_parent_invoice_id( $context ); |
236 | - } |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Alias for self::get_parent_invoice_id(). |
|
240 | + * |
|
241 | + * @since 1.0.0 |
|
242 | + * @return int |
|
243 | + */ |
|
244 | + public function get_original_payment_id( $context = 'view' ) { |
|
245 | + return $this->get_parent_invoice_id( $context ); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Get parent invoice. |
|
250 | + * |
|
251 | + * @since 1.0.19 |
|
252 | + * @param string $context View or edit context. |
|
253 | + * @return WPInv_Invoice |
|
254 | + */ |
|
255 | + public function get_parent_invoice( $context = 'view' ) { |
|
256 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Alias for self::get_parent_invoice(). |
|
261 | + * |
|
262 | + * @since 1.0.19 |
|
263 | + * @param string $context View or edit context. |
|
264 | + * @return WPInv_Invoice |
|
265 | + */ |
|
266 | + public function get_parent_payment( $context = 'view' ) { |
|
267 | + return $this->get_parent_invoice( $context ); |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Get subscription's product id. |
|
272 | + * |
|
273 | + * @since 1.0.19 |
|
274 | + * @param string $context View or edit context. |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + public function get_product_id( $context = 'view' ) { |
|
278 | + return (int) $this->get_prop( 'product_id', $context ); |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Get the subscription product. |
|
283 | + * |
|
284 | + * @since 1.0.19 |
|
285 | + * @param string $context View or edit context. |
|
286 | + * @return WPInv_Item |
|
287 | + */ |
|
288 | + public function get_product( $context = 'view' ) { |
|
289 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Get parent invoice's gateway. |
|
294 | + * |
|
295 | + * Here for backwards compatibility. |
|
296 | + * |
|
297 | + * @since 1.0.19 |
|
298 | + * @param string $context View or edit context. |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public function get_gateway( $context = 'view' ) { |
|
302 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Get the period of a renewal. |
|
307 | + * |
|
308 | + * @since 1.0.19 |
|
309 | + * @param string $context View or edit context. |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function get_period( $context = 'view' ) { |
|
313 | + return $this->get_prop( 'period', $context ); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Get number of periods each renewal is valid for. |
|
318 | + * |
|
319 | + * @since 1.0.19 |
|
320 | + * @param string $context View or edit context. |
|
321 | + * @return int |
|
322 | + */ |
|
323 | + public function get_frequency( $context = 'view' ) { |
|
324 | + return (int) $this->get_prop( 'frequency', $context ); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Get the initial amount for the subscription. |
|
329 | + * |
|
330 | + * @since 1.0.19 |
|
331 | + * @param string $context View or edit context. |
|
332 | + * @return float |
|
333 | + */ |
|
334 | + public function get_initial_amount( $context = 'view' ) { |
|
335 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Get the recurring amount for the subscription. |
|
340 | + * |
|
341 | + * @since 1.0.19 |
|
342 | + * @param string $context View or edit context. |
|
343 | + * @return float |
|
344 | + */ |
|
345 | + public function get_recurring_amount( $context = 'view' ) { |
|
346 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Get number of times that this subscription can be renewed. |
|
351 | + * |
|
352 | + * @since 1.0.19 |
|
353 | + * @param string $context View or edit context. |
|
354 | + * @return int |
|
355 | + */ |
|
356 | + public function get_bill_times( $context = 'view' ) { |
|
357 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Get transaction id of this subscription's parent invoice. |
|
362 | + * |
|
363 | + * @since 1.0.19 |
|
364 | + * @param string $context View or edit context. |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function get_transaction_id( $context = 'view' ) { |
|
368 | + return $this->get_prop( 'transaction_id', $context ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the date that the subscription was created. |
|
373 | + * |
|
374 | + * @since 1.0.19 |
|
375 | + * @param string $context View or edit context. |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function get_created( $context = 'view' ) { |
|
379 | + return $this->get_prop( 'created', $context ); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Alias for self::get_created(). |
|
384 | + * |
|
385 | + * @since 1.0.19 |
|
386 | + * @param string $context View or edit context. |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_date_created( $context = 'view' ) { |
|
390 | + return $this->get_created( $context ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Retrieves the creation date in a timestamp |
|
395 | + * |
|
396 | + * @since 1.0.0 |
|
397 | + * @return int |
|
398 | + */ |
|
399 | + public function get_time_created() { |
|
400 | + $created = $this->get_date_created(); |
|
401 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Get GMT date when the subscription was created. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + * @param string $context View or edit context. |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public function get_date_created_gmt( $context = 'view' ) { |
|
412 | + $date = $this->get_date_created( $context ); |
|
413 | + |
|
414 | + if ( $date ) { |
|
415 | + $date = get_gmt_from_date( $date ); |
|
416 | + } |
|
417 | + return $date; |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Get the date that the subscription will renew. |
|
422 | + * |
|
423 | + * @since 1.0.19 |
|
424 | + * @param string $context View or edit context. |
|
425 | + * @return string |
|
426 | + */ |
|
427 | + public function get_next_renewal_date( $context = 'view' ) { |
|
428 | + return $this->get_prop( 'expiration', $context ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Alias for self::get_next_renewal_date(). |
|
433 | + * |
|
434 | + * @since 1.0.19 |
|
435 | + * @param string $context View or edit context. |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function get_expiration( $context = 'view' ) { |
|
439 | + return $this->get_next_renewal_date( $context ); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Retrieves the expiration date in a timestamp |
|
444 | + * |
|
445 | + * @since 1.0.0 |
|
446 | + * @return int |
|
447 | + */ |
|
448 | + public function get_expiration_time() { |
|
449 | + $expiration = $this->get_expiration(); |
|
450 | + |
|
451 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | + return current_time( 'timestamp' ); |
|
453 | + } |
|
454 | + |
|
455 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Get GMT date when the subscription will renew. |
|
461 | + * |
|
462 | + * @since 1.0.19 |
|
463 | + * @param string $context View or edit context. |
|
464 | + * @return string |
|
465 | + */ |
|
466 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
467 | + $date = $this->get_next_renewal_date( $context ); |
|
468 | + |
|
469 | + if ( $date ) { |
|
470 | + $date = get_gmt_from_date( $date ); |
|
471 | + } |
|
472 | + return $date; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Get the subscription's trial period. |
|
477 | + * |
|
478 | + * @since 1.0.19 |
|
479 | + * @param string $context View or edit context. |
|
480 | + * @return string |
|
481 | + */ |
|
482 | + public function get_trial_period( $context = 'view' ) { |
|
483 | + return $this->get_prop( 'trial_period', $context ); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Get the subscription's status. |
|
488 | + * |
|
489 | + * @since 1.0.19 |
|
490 | + * @param string $context View or edit context. |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function get_status( $context = 'view' ) { |
|
494 | + return $this->get_prop( 'status', $context ); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Get the subscription's profile id. |
|
499 | + * |
|
500 | + * @since 1.0.19 |
|
501 | + * @param string $context View or edit context. |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function get_profile_id( $context = 'view' ) { |
|
505 | + return $this->get_prop( 'profile_id', $context ); |
|
506 | + } |
|
507 | + |
|
508 | + /* |
|
509 | + |-------------------------------------------------------------------------- |
|
510 | + | Setters |
|
511 | + |-------------------------------------------------------------------------- |
|
512 | + */ |
|
513 | + |
|
514 | + /** |
|
515 | + * Set customer id. |
|
516 | + * |
|
517 | + * @since 1.0.19 |
|
518 | + * @param int $value The customer's id. |
|
519 | + */ |
|
520 | + public function set_customer_id( $value ) { |
|
521 | + $this->set_prop( 'customer_id', (int) $value ); |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Set parent invoice id. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int $value The parent invoice id. |
|
529 | + */ |
|
530 | + public function set_parent_invoice_id( $value ) { |
|
531 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * Alias for self::set_parent_invoice_id(). |
|
536 | + * |
|
537 | + * @since 1.0.19 |
|
538 | + * @param int $value The parent invoice id. |
|
539 | + */ |
|
540 | + public function set_parent_payment_id( $value ) { |
|
541 | + $this->set_parent_invoice_id( $value ); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Alias for self::set_parent_invoice_id(). |
|
546 | + * |
|
547 | + * @since 1.0.19 |
|
548 | + * @param int $value The parent invoice id. |
|
549 | + */ |
|
550 | + public function set_original_payment_id( $value ) { |
|
551 | + $this->set_parent_invoice_id( $value ); |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Set subscription's product id. |
|
556 | + * |
|
557 | + * @since 1.0.19 |
|
558 | + * @param int $value The subscription product id. |
|
559 | + */ |
|
560 | + public function set_product_id( $value ) { |
|
561 | + $this->set_prop( 'product_id', (int) $value ); |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Set the period of a renewal. |
|
566 | + * |
|
567 | + * @since 1.0.19 |
|
568 | + * @param string $value The renewal period. |
|
569 | + */ |
|
570 | + public function set_period( $value ) { |
|
571 | + $this->set_prop( 'period', $value ); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Set number of periods each renewal is valid for. |
|
576 | + * |
|
577 | + * @since 1.0.19 |
|
578 | + * @param int $value The subscription frequency. |
|
579 | + */ |
|
580 | + public function set_frequency( $value ) { |
|
581 | + $value = empty( $value ) ? 1 : (int) $value; |
|
582 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Set the initial amount for the subscription. |
|
587 | + * |
|
588 | + * @since 1.0.19 |
|
589 | + * @param float $value The initial subcription amount. |
|
590 | + */ |
|
591 | + public function set_initial_amount( $value ) { |
|
592 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Set the recurring amount for the subscription. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + * @param float $value The recurring subcription amount. |
|
600 | + */ |
|
601 | + public function set_recurring_amount( $value ) { |
|
602 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set number of times that this subscription can be renewed. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param int $value Bill times. |
|
610 | + */ |
|
611 | + public function set_bill_times( $value ) { |
|
612 | + $this->set_prop( 'bill_times', (int) $value ); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Get transaction id of this subscription's parent invoice. |
|
617 | + * |
|
618 | + * @since 1.0.19 |
|
619 | + * @param string $value Bill times. |
|
620 | + */ |
|
621 | + public function set_transaction_id( $value ) { |
|
622 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Set date when this subscription started. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param string $value strtotime compliant date. |
|
630 | + */ |
|
631 | + public function set_created( $value ) { |
|
632 | + $date = strtotime( $value ); |
|
633 | + |
|
634 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
635 | + $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
636 | + return; |
|
637 | + } |
|
638 | + |
|
639 | + $this->set_prop( 'created', '' ); |
|
640 | + |
|
641 | + } |
|
237 | 642 | |
238 | - /** |
|
239 | - * Alias for self::get_parent_invoice_id(). |
|
643 | + /** |
|
644 | + * Alias for self::set_created(). |
|
240 | 645 | * |
241 | - * @since 1.0.0 |
|
242 | - * @return int |
|
646 | + * @since 1.0.19 |
|
647 | + * @param string $value strtotime compliant date. |
|
243 | 648 | */ |
244 | - public function get_original_payment_id( $context = 'view' ) { |
|
245 | - return $this->get_parent_invoice_id( $context ); |
|
649 | + public function set_date_created( $value ) { |
|
650 | + $this->set_created( $value ); |
|
246 | 651 | } |
247 | 652 | |
248 | - /** |
|
249 | - * Get parent invoice. |
|
250 | - * |
|
251 | - * @since 1.0.19 |
|
252 | - * @param string $context View or edit context. |
|
253 | - * @return WPInv_Invoice |
|
254 | - */ |
|
255 | - public function get_parent_invoice( $context = 'view' ) { |
|
256 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Alias for self::get_parent_invoice(). |
|
261 | - * |
|
262 | - * @since 1.0.19 |
|
263 | - * @param string $context View or edit context. |
|
264 | - * @return WPInv_Invoice |
|
265 | - */ |
|
266 | - public function get_parent_payment( $context = 'view' ) { |
|
267 | - return $this->get_parent_invoice( $context ); |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Get subscription's product id. |
|
272 | - * |
|
273 | - * @since 1.0.19 |
|
274 | - * @param string $context View or edit context. |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - public function get_product_id( $context = 'view' ) { |
|
278 | - return (int) $this->get_prop( 'product_id', $context ); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Get the subscription product. |
|
283 | - * |
|
284 | - * @since 1.0.19 |
|
285 | - * @param string $context View or edit context. |
|
286 | - * @return WPInv_Item |
|
287 | - */ |
|
288 | - public function get_product( $context = 'view' ) { |
|
289 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Get parent invoice's gateway. |
|
294 | - * |
|
295 | - * Here for backwards compatibility. |
|
296 | - * |
|
297 | - * @since 1.0.19 |
|
298 | - * @param string $context View or edit context. |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public function get_gateway( $context = 'view' ) { |
|
302 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Get the period of a renewal. |
|
307 | - * |
|
308 | - * @since 1.0.19 |
|
309 | - * @param string $context View or edit context. |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function get_period( $context = 'view' ) { |
|
313 | - return $this->get_prop( 'period', $context ); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Get number of periods each renewal is valid for. |
|
318 | - * |
|
319 | - * @since 1.0.19 |
|
320 | - * @param string $context View or edit context. |
|
321 | - * @return int |
|
322 | - */ |
|
323 | - public function get_frequency( $context = 'view' ) { |
|
324 | - return (int) $this->get_prop( 'frequency', $context ); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Get the initial amount for the subscription. |
|
329 | - * |
|
330 | - * @since 1.0.19 |
|
331 | - * @param string $context View or edit context. |
|
332 | - * @return float |
|
333 | - */ |
|
334 | - public function get_initial_amount( $context = 'view' ) { |
|
335 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Get the recurring amount for the subscription. |
|
340 | - * |
|
341 | - * @since 1.0.19 |
|
342 | - * @param string $context View or edit context. |
|
343 | - * @return float |
|
344 | - */ |
|
345 | - public function get_recurring_amount( $context = 'view' ) { |
|
346 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Get number of times that this subscription can be renewed. |
|
351 | - * |
|
352 | - * @since 1.0.19 |
|
353 | - * @param string $context View or edit context. |
|
354 | - * @return int |
|
355 | - */ |
|
356 | - public function get_bill_times( $context = 'view' ) { |
|
357 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Get transaction id of this subscription's parent invoice. |
|
362 | - * |
|
363 | - * @since 1.0.19 |
|
364 | - * @param string $context View or edit context. |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function get_transaction_id( $context = 'view' ) { |
|
368 | - return $this->get_prop( 'transaction_id', $context ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the date that the subscription was created. |
|
373 | - * |
|
374 | - * @since 1.0.19 |
|
375 | - * @param string $context View or edit context. |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function get_created( $context = 'view' ) { |
|
379 | - return $this->get_prop( 'created', $context ); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Alias for self::get_created(). |
|
384 | - * |
|
385 | - * @since 1.0.19 |
|
386 | - * @param string $context View or edit context. |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_date_created( $context = 'view' ) { |
|
390 | - return $this->get_created( $context ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Retrieves the creation date in a timestamp |
|
395 | - * |
|
396 | - * @since 1.0.0 |
|
397 | - * @return int |
|
398 | - */ |
|
399 | - public function get_time_created() { |
|
400 | - $created = $this->get_date_created(); |
|
401 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Get GMT date when the subscription was created. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - * @param string $context View or edit context. |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public function get_date_created_gmt( $context = 'view' ) { |
|
412 | - $date = $this->get_date_created( $context ); |
|
653 | + /** |
|
654 | + * Set the date that the subscription will renew. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @param string $value strtotime compliant date. |
|
658 | + */ |
|
659 | + public function set_next_renewal_date( $value ) { |
|
660 | + $date = strtotime( $value ); |
|
413 | 661 | |
414 | - if ( $date ) { |
|
415 | - $date = get_gmt_from_date( $date ); |
|
662 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
663 | + $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
664 | + return; |
|
416 | 665 | } |
417 | - return $date; |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Get the date that the subscription will renew. |
|
422 | - * |
|
423 | - * @since 1.0.19 |
|
424 | - * @param string $context View or edit context. |
|
425 | - * @return string |
|
426 | - */ |
|
427 | - public function get_next_renewal_date( $context = 'view' ) { |
|
428 | - return $this->get_prop( 'expiration', $context ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Alias for self::get_next_renewal_date(). |
|
433 | - * |
|
434 | - * @since 1.0.19 |
|
435 | - * @param string $context View or edit context. |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function get_expiration( $context = 'view' ) { |
|
439 | - return $this->get_next_renewal_date( $context ); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Retrieves the expiration date in a timestamp |
|
444 | - * |
|
445 | - * @since 1.0.0 |
|
446 | - * @return int |
|
447 | - */ |
|
448 | - public function get_expiration_time() { |
|
449 | - $expiration = $this->get_expiration(); |
|
450 | - |
|
451 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | - return current_time( 'timestamp' ); |
|
453 | - } |
|
454 | - |
|
455 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Get GMT date when the subscription will renew. |
|
461 | - * |
|
462 | - * @since 1.0.19 |
|
463 | - * @param string $context View or edit context. |
|
464 | - * @return string |
|
465 | - */ |
|
466 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
467 | - $date = $this->get_next_renewal_date( $context ); |
|
468 | 666 | |
469 | - if ( $date ) { |
|
470 | - $date = get_gmt_from_date( $date ); |
|
471 | - } |
|
472 | - return $date; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Get the subscription's trial period. |
|
477 | - * |
|
478 | - * @since 1.0.19 |
|
479 | - * @param string $context View or edit context. |
|
480 | - * @return string |
|
481 | - */ |
|
482 | - public function get_trial_period( $context = 'view' ) { |
|
483 | - return $this->get_prop( 'trial_period', $context ); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Get the subscription's status. |
|
488 | - * |
|
489 | - * @since 1.0.19 |
|
490 | - * @param string $context View or edit context. |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function get_status( $context = 'view' ) { |
|
494 | - return $this->get_prop( 'status', $context ); |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * Get the subscription's profile id. |
|
499 | - * |
|
500 | - * @since 1.0.19 |
|
501 | - * @param string $context View or edit context. |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function get_profile_id( $context = 'view' ) { |
|
505 | - return $this->get_prop( 'profile_id', $context ); |
|
506 | - } |
|
507 | - |
|
508 | - /* |
|
509 | - |-------------------------------------------------------------------------- |
|
510 | - | Setters |
|
511 | - |-------------------------------------------------------------------------- |
|
512 | - */ |
|
667 | + $this->set_prop( 'expiration', '' ); |
|
513 | 668 | |
514 | - /** |
|
515 | - * Set customer id. |
|
516 | - * |
|
517 | - * @since 1.0.19 |
|
518 | - * @param int $value The customer's id. |
|
519 | - */ |
|
520 | - public function set_customer_id( $value ) { |
|
521 | - $this->set_prop( 'customer_id', (int) $value ); |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Set parent invoice id. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int $value The parent invoice id. |
|
529 | - */ |
|
530 | - public function set_parent_invoice_id( $value ) { |
|
531 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Alias for self::set_parent_invoice_id(). |
|
536 | - * |
|
537 | - * @since 1.0.19 |
|
538 | - * @param int $value The parent invoice id. |
|
539 | - */ |
|
540 | - public function set_parent_payment_id( $value ) { |
|
541 | - $this->set_parent_invoice_id( $value ); |
|
542 | - } |
|
669 | + } |
|
543 | 670 | |
544 | - /** |
|
545 | - * Alias for self::set_parent_invoice_id(). |
|
671 | + /** |
|
672 | + * Alias for self::set_next_renewal_date(). |
|
546 | 673 | * |
547 | 674 | * @since 1.0.19 |
548 | - * @param int $value The parent invoice id. |
|
675 | + * @param string $value strtotime compliant date. |
|
549 | 676 | */ |
550 | - public function set_original_payment_id( $value ) { |
|
551 | - $this->set_parent_invoice_id( $value ); |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Set subscription's product id. |
|
556 | - * |
|
557 | - * @since 1.0.19 |
|
558 | - * @param int $value The subscription product id. |
|
559 | - */ |
|
560 | - public function set_product_id( $value ) { |
|
561 | - $this->set_prop( 'product_id', (int) $value ); |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Set the period of a renewal. |
|
566 | - * |
|
567 | - * @since 1.0.19 |
|
568 | - * @param string $value The renewal period. |
|
569 | - */ |
|
570 | - public function set_period( $value ) { |
|
571 | - $this->set_prop( 'period', $value ); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Set number of periods each renewal is valid for. |
|
576 | - * |
|
577 | - * @since 1.0.19 |
|
578 | - * @param int $value The subscription frequency. |
|
579 | - */ |
|
580 | - public function set_frequency( $value ) { |
|
581 | - $value = empty( $value ) ? 1 : (int) $value; |
|
582 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Set the initial amount for the subscription. |
|
587 | - * |
|
588 | - * @since 1.0.19 |
|
589 | - * @param float $value The initial subcription amount. |
|
590 | - */ |
|
591 | - public function set_initial_amount( $value ) { |
|
592 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Set the recurring amount for the subscription. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - * @param float $value The recurring subcription amount. |
|
600 | - */ |
|
601 | - public function set_recurring_amount( $value ) { |
|
602 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set number of times that this subscription can be renewed. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param int $value Bill times. |
|
610 | - */ |
|
611 | - public function set_bill_times( $value ) { |
|
612 | - $this->set_prop( 'bill_times', (int) $value ); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Get transaction id of this subscription's parent invoice. |
|
617 | - * |
|
618 | - * @since 1.0.19 |
|
619 | - * @param string $value Bill times. |
|
620 | - */ |
|
621 | - public function set_transaction_id( $value ) { |
|
622 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set date when this subscription started. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param string $value strtotime compliant date. |
|
630 | - */ |
|
631 | - public function set_created( $value ) { |
|
632 | - $date = strtotime( $value ); |
|
677 | + public function set_expiration( $value ) { |
|
678 | + $this->set_next_renewal_date( $value ); |
|
679 | + } |
|
633 | 680 | |
634 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
635 | - $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
681 | + /** |
|
682 | + * Set the subscription's trial period. |
|
683 | + * |
|
684 | + * @since 1.0.19 |
|
685 | + * @param string $value trial period e.g 1 year. |
|
686 | + */ |
|
687 | + public function set_trial_period( $value ) { |
|
688 | + $this->set_prop( 'trial_period', $value ); |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Set the subscription's status. |
|
693 | + * |
|
694 | + * @since 1.0.19 |
|
695 | + * @param string $new_status New subscription status. |
|
696 | + */ |
|
697 | + public function set_status( $new_status ) { |
|
698 | + |
|
699 | + // Abort if this is not a valid status; |
|
700 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
636 | 701 | return; |
637 | 702 | } |
638 | 703 | |
639 | - $this->set_prop( 'created', '' ); |
|
640 | - |
|
641 | - } |
|
704 | + $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | + $this->status_transition = array( |
|
707 | + 'from' => $old_status, |
|
708 | + 'to' => $new_status, |
|
709 | + ); |
|
710 | + } |
|
642 | 711 | |
643 | - /** |
|
644 | - * Alias for self::set_created(). |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - * @param string $value strtotime compliant date. |
|
648 | - */ |
|
649 | - public function set_date_created( $value ) { |
|
650 | - $this->set_created( $value ); |
|
712 | + $this->set_prop( 'status', $new_status ); |
|
651 | 713 | } |
652 | 714 | |
653 | - /** |
|
654 | - * Set the date that the subscription will renew. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @param string $value strtotime compliant date. |
|
658 | - */ |
|
659 | - public function set_next_renewal_date( $value ) { |
|
660 | - $date = strtotime( $value ); |
|
715 | + /** |
|
716 | + * Set the subscription's (remote) profile id. |
|
717 | + * |
|
718 | + * @since 1.0.19 |
|
719 | + * @param string $value the remote profile id. |
|
720 | + */ |
|
721 | + public function set_profile_id( $value ) { |
|
722 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | + } |
|
661 | 724 | |
662 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
663 | - $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
664 | - return; |
|
665 | - } |
|
666 | - |
|
667 | - $this->set_prop( 'expiration', '' ); |
|
668 | - |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Alias for self::set_next_renewal_date(). |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - * @param string $value strtotime compliant date. |
|
676 | - */ |
|
677 | - public function set_expiration( $value ) { |
|
678 | - $this->set_next_renewal_date( $value ); |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Set the subscription's trial period. |
|
683 | - * |
|
684 | - * @since 1.0.19 |
|
685 | - * @param string $value trial period e.g 1 year. |
|
686 | - */ |
|
687 | - public function set_trial_period( $value ) { |
|
688 | - $this->set_prop( 'trial_period', $value ); |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Set the subscription's status. |
|
693 | - * |
|
694 | - * @since 1.0.19 |
|
695 | - * @param string $new_status New subscription status. |
|
696 | - */ |
|
697 | - public function set_status( $new_status ) { |
|
698 | - |
|
699 | - // Abort if this is not a valid status; |
|
700 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
701 | - return; |
|
702 | - } |
|
703 | - |
|
704 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | - $this->status_transition = array( |
|
707 | - 'from' => $old_status, |
|
708 | - 'to' => $new_status, |
|
709 | - ); |
|
710 | - } |
|
711 | - |
|
712 | - $this->set_prop( 'status', $new_status ); |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Set the subscription's (remote) profile id. |
|
717 | - * |
|
718 | - * @since 1.0.19 |
|
719 | - * @param string $value the remote profile id. |
|
720 | - */ |
|
721 | - public function set_profile_id( $value ) { |
|
722 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | - } |
|
724 | - |
|
725 | - /* |
|
725 | + /* |
|
726 | 726 | |-------------------------------------------------------------------------- |
727 | 727 | | Boolean methods |
728 | 728 | |-------------------------------------------------------------------------- |
@@ -731,55 +731,55 @@ discard block |
||
731 | 731 | | |
732 | 732 | */ |
733 | 733 | |
734 | - /** |
|
734 | + /** |
|
735 | 735 | * Checks if the subscription has a given status. |
736 | - * |
|
737 | - * @param string|array String or array of strings to check for. |
|
738 | - * @return bool |
|
736 | + * |
|
737 | + * @param string|array String or array of strings to check for. |
|
738 | + * @return bool |
|
739 | 739 | */ |
740 | 740 | public function has_status( $status ) { |
741 | 741 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
742 | - } |
|
742 | + } |
|
743 | 743 | |
744 | - /** |
|
744 | + /** |
|
745 | 745 | * Checks if the subscription has a trial period. |
746 | - * |
|
747 | - * @return bool |
|
746 | + * |
|
747 | + * @return bool |
|
748 | 748 | */ |
749 | 749 | public function has_trial_period() { |
750 | - $period = $this->get_trial_period(); |
|
750 | + $period = $this->get_trial_period(); |
|
751 | 751 | return ! empty( $period ); |
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Is the subscription active? |
|
756 | - * |
|
757 | - * @return bool |
|
758 | - */ |
|
759 | - public function is_active() { |
|
760 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | - } |
|
762 | - |
|
763 | - /** |
|
764 | - * Is the subscription expired? |
|
765 | - * |
|
766 | - * @return bool |
|
767 | - */ |
|
768 | - public function is_expired() { |
|
769 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Is this the last renewals? |
|
774 | - * |
|
775 | - * @return bool |
|
776 | - */ |
|
777 | - public function is_last_renewal() { |
|
778 | - $max_bills = $this->get_bill_times(); |
|
779 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | - } |
|
781 | - |
|
782 | - /* |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Is the subscription active? |
|
756 | + * |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | + public function is_active() { |
|
760 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Is the subscription expired? |
|
765 | + * |
|
766 | + * @return bool |
|
767 | + */ |
|
768 | + public function is_expired() { |
|
769 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Is this the last renewals? |
|
774 | + * |
|
775 | + * @return bool |
|
776 | + */ |
|
777 | + public function is_last_renewal() { |
|
778 | + $max_bills = $this->get_bill_times(); |
|
779 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | + } |
|
781 | + |
|
782 | + /* |
|
783 | 783 | |-------------------------------------------------------------------------- |
784 | 784 | | Additional methods |
785 | 785 | |-------------------------------------------------------------------------- |
@@ -788,27 +788,27 @@ discard block |
||
788 | 788 | | |
789 | 789 | */ |
790 | 790 | |
791 | - /** |
|
792 | - * Backwards compatibilty. |
|
793 | - */ |
|
794 | - public function create( $data = array() ) { |
|
791 | + /** |
|
792 | + * Backwards compatibilty. |
|
793 | + */ |
|
794 | + public function create( $data = array() ) { |
|
795 | 795 | |
796 | - // Set the properties. |
|
797 | - if ( is_array( $data ) ) { |
|
798 | - $this->set_props( $data ); |
|
799 | - } |
|
796 | + // Set the properties. |
|
797 | + if ( is_array( $data ) ) { |
|
798 | + $this->set_props( $data ); |
|
799 | + } |
|
800 | 800 | |
801 | - // Save the item. |
|
802 | - return $this->save(); |
|
801 | + // Save the item. |
|
802 | + return $this->save(); |
|
803 | 803 | |
804 | - } |
|
804 | + } |
|
805 | 805 | |
806 | - /** |
|
807 | - * Backwards compatibilty. |
|
808 | - */ |
|
809 | - public function update( $args = array() ) { |
|
810 | - return $this->create( $args ); |
|
811 | - } |
|
806 | + /** |
|
807 | + * Backwards compatibilty. |
|
808 | + */ |
|
809 | + public function update( $args = array() ) { |
|
810 | + return $this->create( $args ); |
|
811 | + } |
|
812 | 812 | |
813 | 813 | /** |
814 | 814 | * Retrieve renewal payments for a subscription |
@@ -818,22 +818,22 @@ discard block |
||
818 | 818 | */ |
819 | 819 | public function get_child_payments( $hide_pending = true ) { |
820 | 820 | |
821 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
821 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
822 | 822 | |
823 | - if ( ! $hide_pending ) { |
|
824 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | - } |
|
823 | + if ( ! $hide_pending ) { |
|
824 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | + } |
|
826 | 826 | |
827 | 827 | return get_posts( |
828 | - array( |
|
829 | - 'post_parent' => $this->get_parent_payment_id(), |
|
830 | - 'numberposts' => -1, |
|
831 | - 'post_status' => $statuses, |
|
832 | - 'orderby' => 'ID', |
|
833 | - 'order' => 'ASC', |
|
834 | - 'post_type' => 'wpi_invoice', |
|
835 | - ) |
|
836 | - ); |
|
828 | + array( |
|
829 | + 'post_parent' => $this->get_parent_payment_id(), |
|
830 | + 'numberposts' => -1, |
|
831 | + 'post_status' => $statuses, |
|
832 | + 'orderby' => 'ID', |
|
833 | + 'order' => 'ASC', |
|
834 | + 'post_type' => 'wpi_invoice', |
|
835 | + ) |
|
836 | + ); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @return int |
844 | 844 | */ |
845 | 845 | public function get_total_payments() { |
846 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
846 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -867,192 +867,192 @@ discard block |
||
867 | 867 | * |
868 | 868 | * @since 2.4 |
869 | 869 | * @param array $args Array of values for the payment, including amount and transaction ID |
870 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
870 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
871 | 871 | * @return bool |
872 | 872 | */ |
873 | 873 | public function add_payment( $args = array(), $invoice = false ) { |
874 | 874 | |
875 | - // Process each payment once. |
|
875 | + // Process each payment once. |
|
876 | 876 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | - // Are we creating a new invoice? |
|
881 | - if ( empty( $invoice ) ) { |
|
882 | - $invoice = $this->create_payment( false ); |
|
880 | + // Are we creating a new invoice? |
|
881 | + if ( empty( $invoice ) ) { |
|
882 | + $invoice = $this->create_payment( false ); |
|
883 | 883 | |
884 | - if ( empty( $invoice ) ) { |
|
885 | - return false; |
|
886 | - } |
|
887 | - } |
|
884 | + if ( empty( $invoice ) ) { |
|
885 | + return false; |
|
886 | + } |
|
887 | + } |
|
888 | 888 | |
889 | - // Maybe set a transaction id. |
|
890 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | - } |
|
889 | + // Maybe set a transaction id. |
|
890 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | + } |
|
893 | 893 | |
894 | - // Set the completed date. |
|
895 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
894 | + // Set the completed date. |
|
895 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
896 | 896 | |
897 | - // And the gateway. |
|
898 | - if ( ! empty( $args['gateway'] ) ) { |
|
899 | - $invoice->set_gateway( $args['gateway'] ); |
|
900 | - } |
|
897 | + // And the gateway. |
|
898 | + if ( ! empty( $args['gateway'] ) ) { |
|
899 | + $invoice->set_gateway( $args['gateway'] ); |
|
900 | + } |
|
901 | 901 | |
902 | - $invoice->set_status( 'wpi-renewal' ); |
|
903 | - $invoice->save(); |
|
902 | + $invoice->set_status( 'wpi-renewal' ); |
|
903 | + $invoice->save(); |
|
904 | 904 | |
905 | - if ( ! $invoice->exists() ) { |
|
906 | - return false; |
|
907 | - } |
|
905 | + if ( ! $invoice->exists() ) { |
|
906 | + return false; |
|
907 | + } |
|
908 | 908 | |
909 | - return $this->after_add_payment( $invoice ); |
|
910 | - } |
|
909 | + return $this->after_add_payment( $invoice ); |
|
910 | + } |
|
911 | 911 | |
912 | 912 | public function after_add_payment( $invoice ) { |
913 | 913 | |
914 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
915 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
914 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
915 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
916 | 916 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
917 | 917 | |
918 | 918 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
919 | 919 | |
920 | 920 | return $invoice->get_id(); |
921 | - } |
|
921 | + } |
|
922 | 922 | |
923 | - /** |
|
923 | + /** |
|
924 | 924 | * Creates a new invoice and returns it. |
925 | 925 | * |
926 | 926 | * @since 1.0.19 |
927 | - * @param bool $save Whether we should save the invoice. |
|
927 | + * @param bool $save Whether we should save the invoice. |
|
928 | 928 | * @return WPInv_Invoice|bool |
929 | 929 | */ |
930 | 930 | public function create_payment( $save = true ) { |
931 | 931 | |
932 | - $parent_invoice = $this->get_parent_payment(); |
|
933 | - |
|
934 | - if ( ! $parent_invoice->exists() ) { |
|
935 | - return false; |
|
936 | - } |
|
937 | - |
|
938 | - // Duplicate the parent invoice. |
|
939 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
940 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
941 | - $invoice->set_subscription_id( $this->get_id() ); |
|
942 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
943 | - |
|
944 | - // Set invoice items. |
|
945 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
946 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
947 | - $invoice_items = array(); |
|
948 | - |
|
949 | - foreach ( $invoice->get_items() as $item ) { |
|
950 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
951 | - $invoice_items[] = $item; |
|
952 | - } |
|
953 | - } |
|
954 | - |
|
955 | - $invoice->set_items( $invoice_items ); |
|
956 | - |
|
957 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
958 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
959 | - } |
|
960 | - |
|
961 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
962 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
963 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
964 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
965 | - } |
|
966 | - |
|
967 | - $invoice->recalculate_total(); |
|
968 | - $invoice->set_status( 'wpi-pending' ); |
|
969 | - |
|
970 | - if ( ! $save ) { |
|
971 | - return $invoice; |
|
972 | - } |
|
973 | - |
|
974 | - $invoice->save(); |
|
975 | - |
|
976 | - return $invoice->exists() ? $invoice : false; |
|
977 | - } |
|
978 | - |
|
979 | - /** |
|
980 | - * Renews or completes a subscription |
|
981 | - * |
|
982 | - * @since 1.0.0 |
|
983 | - * @return int The subscription's id |
|
984 | - */ |
|
985 | - public function renew( $calculate_from = null ) { |
|
986 | - |
|
987 | - // Complete subscription if applicable |
|
988 | - if ( $this->is_last_renewal() ) { |
|
989 | - return $this->complete(); |
|
990 | - } |
|
991 | - |
|
992 | - // Calculate new expiration |
|
993 | - $frequency = $this->get_frequency(); |
|
994 | - $period = $this->get_period(); |
|
995 | - $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
996 | - $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
997 | - |
|
998 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
999 | - $this->set_status( 'active' ); |
|
1000 | - $this->save(); |
|
1001 | - |
|
1002 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
1003 | - |
|
1004 | - return $this->get_id(); |
|
1005 | - } |
|
1006 | - |
|
1007 | - /** |
|
1008 | - * Marks a subscription as completed |
|
1009 | - * |
|
1010 | - * Subscription is completed when the number of payments matches the billing_times field |
|
1011 | - * |
|
1012 | - * @since 1.0.0 |
|
1013 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1014 | - */ |
|
1015 | - public function complete() { |
|
1016 | - |
|
1017 | - // Only mark a subscription as complete if it's not already cancelled. |
|
1018 | - if ( $this->has_status( 'cancelled' ) ) { |
|
1019 | - return false; |
|
1020 | - } |
|
1021 | - |
|
1022 | - $this->set_status( 'completed' ); |
|
1023 | - return $this->save(); |
|
1024 | - |
|
1025 | - } |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Marks a subscription as expired |
|
1029 | - * |
|
1030 | - * @since 1.0.0 |
|
1031 | - * @param bool $check_expiration |
|
1032 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1033 | - */ |
|
1034 | - public function expire( $check_expiration = false ) { |
|
1035 | - |
|
1036 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1037 | - // Do not mark as expired since real expiration date is in the future |
|
1038 | - return false; |
|
1039 | - } |
|
1040 | - |
|
1041 | - $this->set_status( 'expired' ); |
|
1042 | - return $this->save(); |
|
1043 | - |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Marks a subscription as failing |
|
1048 | - * |
|
1049 | - * @since 2.4.2 |
|
1050 | - * @return int Subscription id. |
|
1051 | - */ |
|
1052 | - public function failing() { |
|
1053 | - $this->set_status( 'failing' ); |
|
1054 | - return $this->save(); |
|
1055 | - } |
|
932 | + $parent_invoice = $this->get_parent_payment(); |
|
933 | + |
|
934 | + if ( ! $parent_invoice->exists() ) { |
|
935 | + return false; |
|
936 | + } |
|
937 | + |
|
938 | + // Duplicate the parent invoice. |
|
939 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
940 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
941 | + $invoice->set_subscription_id( $this->get_id() ); |
|
942 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
943 | + |
|
944 | + // Set invoice items. |
|
945 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
946 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
947 | + $invoice_items = array(); |
|
948 | + |
|
949 | + foreach ( $invoice->get_items() as $item ) { |
|
950 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
951 | + $invoice_items[] = $item; |
|
952 | + } |
|
953 | + } |
|
954 | + |
|
955 | + $invoice->set_items( $invoice_items ); |
|
956 | + |
|
957 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
958 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
959 | + } |
|
960 | + |
|
961 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
962 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
963 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
964 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
965 | + } |
|
966 | + |
|
967 | + $invoice->recalculate_total(); |
|
968 | + $invoice->set_status( 'wpi-pending' ); |
|
969 | + |
|
970 | + if ( ! $save ) { |
|
971 | + return $invoice; |
|
972 | + } |
|
973 | + |
|
974 | + $invoice->save(); |
|
975 | + |
|
976 | + return $invoice->exists() ? $invoice : false; |
|
977 | + } |
|
978 | + |
|
979 | + /** |
|
980 | + * Renews or completes a subscription |
|
981 | + * |
|
982 | + * @since 1.0.0 |
|
983 | + * @return int The subscription's id |
|
984 | + */ |
|
985 | + public function renew( $calculate_from = null ) { |
|
986 | + |
|
987 | + // Complete subscription if applicable |
|
988 | + if ( $this->is_last_renewal() ) { |
|
989 | + return $this->complete(); |
|
990 | + } |
|
991 | + |
|
992 | + // Calculate new expiration |
|
993 | + $frequency = $this->get_frequency(); |
|
994 | + $period = $this->get_period(); |
|
995 | + $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
996 | + $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
997 | + |
|
998 | + $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
999 | + $this->set_status( 'active' ); |
|
1000 | + $this->save(); |
|
1001 | + |
|
1002 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
1003 | + |
|
1004 | + return $this->get_id(); |
|
1005 | + } |
|
1006 | + |
|
1007 | + /** |
|
1008 | + * Marks a subscription as completed |
|
1009 | + * |
|
1010 | + * Subscription is completed when the number of payments matches the billing_times field |
|
1011 | + * |
|
1012 | + * @since 1.0.0 |
|
1013 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1014 | + */ |
|
1015 | + public function complete() { |
|
1016 | + |
|
1017 | + // Only mark a subscription as complete if it's not already cancelled. |
|
1018 | + if ( $this->has_status( 'cancelled' ) ) { |
|
1019 | + return false; |
|
1020 | + } |
|
1021 | + |
|
1022 | + $this->set_status( 'completed' ); |
|
1023 | + return $this->save(); |
|
1024 | + |
|
1025 | + } |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Marks a subscription as expired |
|
1029 | + * |
|
1030 | + * @since 1.0.0 |
|
1031 | + * @param bool $check_expiration |
|
1032 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1033 | + */ |
|
1034 | + public function expire( $check_expiration = false ) { |
|
1035 | + |
|
1036 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1037 | + // Do not mark as expired since real expiration date is in the future |
|
1038 | + return false; |
|
1039 | + } |
|
1040 | + |
|
1041 | + $this->set_status( 'expired' ); |
|
1042 | + return $this->save(); |
|
1043 | + |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Marks a subscription as failing |
|
1048 | + * |
|
1049 | + * @since 2.4.2 |
|
1050 | + * @return int Subscription id. |
|
1051 | + */ |
|
1052 | + public function failing() { |
|
1053 | + $this->set_status( 'failing' ); |
|
1054 | + return $this->save(); |
|
1055 | + } |
|
1056 | 1056 | |
1057 | 1057 | /** |
1058 | 1058 | * Marks a subscription as cancelled |
@@ -1061,19 +1061,19 @@ discard block |
||
1061 | 1061 | * @return int Subscription id. |
1062 | 1062 | */ |
1063 | 1063 | public function cancel() { |
1064 | - $this->set_status( 'cancelled' ); |
|
1065 | - return $this->save(); |
|
1064 | + $this->set_status( 'cancelled' ); |
|
1065 | + return $this->save(); |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | - /** |
|
1069 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1070 | - * |
|
1071 | - * @since 1.0.0 |
|
1072 | - * @return bool |
|
1073 | - */ |
|
1074 | - public function can_cancel() { |
|
1075 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1076 | - } |
|
1068 | + /** |
|
1069 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1070 | + * |
|
1071 | + * @since 1.0.0 |
|
1072 | + * @return bool |
|
1073 | + */ |
|
1074 | + public function can_cancel() { |
|
1075 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1076 | + } |
|
1077 | 1077 | |
1078 | 1078 | /** |
1079 | 1079 | * Returns an array of subscription statuses that can be cancelled |
@@ -1086,109 +1086,109 @@ discard block |
||
1086 | 1086 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - /** |
|
1090 | - * Retrieves the URL to cancel subscription |
|
1091 | - * |
|
1092 | - * @since 1.0.0 |
|
1093 | - * @return string |
|
1094 | - */ |
|
1095 | - public function get_cancel_url() { |
|
1096 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1097 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1098 | - } |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Retrieves the URL to view a subscription |
|
1102 | - * |
|
1103 | - * @since 1.0.19 |
|
1104 | - * @return string |
|
1105 | - */ |
|
1106 | - public function get_view_url() { |
|
1107 | - |
|
1108 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1109 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1110 | - |
|
1111 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1112 | - } |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * Determines if subscription can be manually renewed |
|
1116 | - * |
|
1117 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1118 | - * that can be renewed manually |
|
1119 | - * |
|
1120 | - * @since 2.5 |
|
1121 | - * @return bool |
|
1122 | - */ |
|
1123 | - public function can_renew() { |
|
1124 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1125 | - } |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * Retrieves the URL to renew a subscription |
|
1129 | - * |
|
1130 | - * @since 2.5 |
|
1131 | - * @return string |
|
1132 | - */ |
|
1133 | - public function get_renew_url() { |
|
1134 | - $url = wp_nonce_url( |
|
1089 | + /** |
|
1090 | + * Retrieves the URL to cancel subscription |
|
1091 | + * |
|
1092 | + * @since 1.0.0 |
|
1093 | + * @return string |
|
1094 | + */ |
|
1095 | + public function get_cancel_url() { |
|
1096 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1097 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1098 | + } |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Retrieves the URL to view a subscription |
|
1102 | + * |
|
1103 | + * @since 1.0.19 |
|
1104 | + * @return string |
|
1105 | + */ |
|
1106 | + public function get_view_url() { |
|
1107 | + |
|
1108 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1109 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1110 | + |
|
1111 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1112 | + } |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * Determines if subscription can be manually renewed |
|
1116 | + * |
|
1117 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1118 | + * that can be renewed manually |
|
1119 | + * |
|
1120 | + * @since 2.5 |
|
1121 | + * @return bool |
|
1122 | + */ |
|
1123 | + public function can_renew() { |
|
1124 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1125 | + } |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * Retrieves the URL to renew a subscription |
|
1129 | + * |
|
1130 | + * @since 2.5 |
|
1131 | + * @return string |
|
1132 | + */ |
|
1133 | + public function get_renew_url() { |
|
1134 | + $url = wp_nonce_url( |
|
1135 | 1135 | add_query_arg( |
1136 | 1136 | array( |
1137 | - 'getpaid-action' => 'renew_subscription', |
|
1138 | - 'sub_id' => $this->get_id, |
|
1137 | + 'getpaid-action' => 'renew_subscription', |
|
1138 | + 'sub_id' => $this->get_id, |
|
1139 | 1139 | ) |
1140 | 1140 | ), |
1141 | 1141 | 'getpaid-nonce' |
1142 | 1142 | ); |
1143 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1144 | - } |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Determines if subscription can have their payment method updated |
|
1148 | - * |
|
1149 | - * @since 1.0.0 |
|
1150 | - * @return bool |
|
1151 | - */ |
|
1152 | - public function can_update() { |
|
1153 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1154 | - } |
|
1155 | - |
|
1156 | - /** |
|
1157 | - * Retrieves the URL to update subscription |
|
1158 | - * |
|
1159 | - * @since 1.0.0 |
|
1160 | - * @return string |
|
1161 | - */ |
|
1162 | - public function get_update_url() { |
|
1163 | - $url = add_query_arg( |
|
1143 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1144 | + } |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * Determines if subscription can have their payment method updated |
|
1148 | + * |
|
1149 | + * @since 1.0.0 |
|
1150 | + * @return bool |
|
1151 | + */ |
|
1152 | + public function can_update() { |
|
1153 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1154 | + } |
|
1155 | + |
|
1156 | + /** |
|
1157 | + * Retrieves the URL to update subscription |
|
1158 | + * |
|
1159 | + * @since 1.0.0 |
|
1160 | + * @return string |
|
1161 | + */ |
|
1162 | + public function get_update_url() { |
|
1163 | + $url = add_query_arg( |
|
1164 | 1164 | array( |
1165 | - 'action' => 'update', |
|
1166 | - 'subscription_id' => $this->get_id(), |
|
1165 | + 'action' => 'update', |
|
1166 | + 'subscription_id' => $this->get_id(), |
|
1167 | 1167 | ) |
1168 | 1168 | ); |
1169 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1170 | - } |
|
1171 | - |
|
1172 | - /** |
|
1173 | - * Retrieves the subscription status label |
|
1174 | - * |
|
1175 | - * @since 1.0.0 |
|
1176 | - * @return string |
|
1177 | - */ |
|
1178 | - public function get_status_label() { |
|
1179 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1180 | - } |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Retrieves the subscription status class |
|
1184 | - * |
|
1185 | - * @since 1.0.19 |
|
1186 | - * @return string |
|
1187 | - */ |
|
1188 | - public function get_status_class() { |
|
1189 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1190 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1191 | - } |
|
1169 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1170 | + } |
|
1171 | + |
|
1172 | + /** |
|
1173 | + * Retrieves the subscription status label |
|
1174 | + * |
|
1175 | + * @since 1.0.0 |
|
1176 | + * @return string |
|
1177 | + */ |
|
1178 | + public function get_status_label() { |
|
1179 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1180 | + } |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Retrieves the subscription status class |
|
1184 | + * |
|
1185 | + * @since 1.0.19 |
|
1186 | + * @return string |
|
1187 | + */ |
|
1188 | + public function get_status_class() { |
|
1189 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1190 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1191 | + } |
|
1192 | 1192 | |
1193 | 1193 | /** |
1194 | 1194 | * Retrieves the subscription status label |
@@ -1198,11 +1198,11 @@ discard block |
||
1198 | 1198 | */ |
1199 | 1199 | public function get_status_label_html() { |
1200 | 1200 | |
1201 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1202 | - $class = esc_attr( $this->get_status_class() ); |
|
1203 | - $status = sanitize_html_class( $this->get_status() ); |
|
1201 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1202 | + $class = esc_attr( $this->get_status_class() ); |
|
1203 | + $status = sanitize_html_class( $this->get_status() ); |
|
1204 | 1204 | |
1205 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1205 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | /** |
@@ -1213,75 +1213,75 @@ discard block |
||
1213 | 1213 | * @return bool |
1214 | 1214 | */ |
1215 | 1215 | public function payment_exists( $txn_id = '' ) { |
1216 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1216 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1217 | 1217 | return ! empty( $invoice_id ); |
1218 | - } |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * Handle the status transition. |
|
1222 | - */ |
|
1223 | - protected function status_transition() { |
|
1224 | - $status_transition = $this->status_transition; |
|
1225 | - |
|
1226 | - // Reset status transition variable. |
|
1227 | - $this->status_transition = false; |
|
1228 | - |
|
1229 | - if ( $status_transition ) { |
|
1230 | - try { |
|
1231 | - |
|
1232 | - // Fire a hook for the status change. |
|
1233 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1234 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1235 | - |
|
1236 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1237 | - |
|
1238 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1239 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1240 | - |
|
1241 | - // Note the transition occurred. |
|
1242 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1243 | - |
|
1244 | - // Fire another hook. |
|
1245 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1246 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1247 | - |
|
1248 | - } else { |
|
1249 | - /* translators: %s: new invoice status */ |
|
1250 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1251 | - |
|
1252 | - // Note the transition occurred. |
|
1253 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1254 | - |
|
1255 | - } |
|
1256 | - } catch ( Exception $e ) { |
|
1257 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1258 | - } |
|
1259 | - } |
|
1260 | - |
|
1261 | - } |
|
1262 | - |
|
1263 | - /** |
|
1264 | - * Save data to the database. |
|
1265 | - * |
|
1266 | - * @since 1.0.19 |
|
1267 | - * @return int subscription ID |
|
1268 | - */ |
|
1269 | - public function save() { |
|
1270 | - parent::save(); |
|
1271 | - $this->status_transition(); |
|
1272 | - return $this->get_id(); |
|
1273 | - } |
|
1274 | - |
|
1275 | - /** |
|
1276 | - * Activates a subscription. |
|
1277 | - * |
|
1278 | - * @since 1.0.19 |
|
1279 | - * @return int subscription ID |
|
1280 | - */ |
|
1281 | - public function activate() { |
|
1282 | - $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1283 | - $this->set_status( $status ); |
|
1284 | - return $this->save(); |
|
1285 | - } |
|
1218 | + } |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * Handle the status transition. |
|
1222 | + */ |
|
1223 | + protected function status_transition() { |
|
1224 | + $status_transition = $this->status_transition; |
|
1225 | + |
|
1226 | + // Reset status transition variable. |
|
1227 | + $this->status_transition = false; |
|
1228 | + |
|
1229 | + if ( $status_transition ) { |
|
1230 | + try { |
|
1231 | + |
|
1232 | + // Fire a hook for the status change. |
|
1233 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1234 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1235 | + |
|
1236 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1237 | + |
|
1238 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1239 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1240 | + |
|
1241 | + // Note the transition occurred. |
|
1242 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1243 | + |
|
1244 | + // Fire another hook. |
|
1245 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1246 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1247 | + |
|
1248 | + } else { |
|
1249 | + /* translators: %s: new invoice status */ |
|
1250 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1251 | + |
|
1252 | + // Note the transition occurred. |
|
1253 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1254 | + |
|
1255 | + } |
|
1256 | + } catch ( Exception $e ) { |
|
1257 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1258 | + } |
|
1259 | + } |
|
1260 | + |
|
1261 | + } |
|
1262 | + |
|
1263 | + /** |
|
1264 | + * Save data to the database. |
|
1265 | + * |
|
1266 | + * @since 1.0.19 |
|
1267 | + * @return int subscription ID |
|
1268 | + */ |
|
1269 | + public function save() { |
|
1270 | + parent::save(); |
|
1271 | + $this->status_transition(); |
|
1272 | + return $this->get_id(); |
|
1273 | + } |
|
1274 | + |
|
1275 | + /** |
|
1276 | + * Activates a subscription. |
|
1277 | + * |
|
1278 | + * @since 1.0.19 |
|
1279 | + * @return int subscription ID |
|
1280 | + */ |
|
1281 | + public function activate() { |
|
1282 | + $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1283 | + $this->set_status( $status ); |
|
1284 | + return $this->save(); |
|
1285 | + } |
|
1286 | 1286 | |
1287 | 1287 | } |
@@ -11,187 +11,187 @@ |
||
11 | 11 | */ |
12 | 12 | class GetPaid_Data_Store { |
13 | 13 | |
14 | - /** |
|
15 | - * Contains an instance of the data store class that we are working with. |
|
16 | - * |
|
17 | - * @var GetPaid_Data_Store |
|
18 | - */ |
|
19 | - private $instance = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * Contains an array of default supported data stores. |
|
23 | - * Format of object name => class name. |
|
24 | - * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | - * You can also pass something like item-<type> for item stores and |
|
26 | - * that type will be used first when available, if a store is requested like |
|
27 | - * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | - * Ran through `getpaid_data_stores`. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $stores = array( |
|
33 | - 'item' => 'GetPaid_Item_Data_Store', |
|
34 | - 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | - 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | - 'invoice' => 'GetPaid_Invoice_Data_Store', |
|
37 | - 'subscription' => 'GetPaid_Subscription_Data_Store', |
|
38 | - 'customer' => 'GetPaid_Customer_Data_Store', |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * Contains the name of the current data store's class name. |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - private $current_class_name = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * The object type this store works with. |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - private $object_type = ''; |
|
54 | - |
|
55 | - /** |
|
56 | - * Tells GetPaid_Data_Store which object |
|
57 | - * store we want to work with. |
|
58 | - * |
|
59 | - * @param string $object_type Name of object. |
|
60 | - */ |
|
61 | - public function __construct( $object_type ) { |
|
62 | - $this->object_type = $object_type; |
|
63 | - $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
64 | - |
|
65 | - // If this object type can't be found, check to see if we can load one |
|
66 | - // level up (so if item-type isn't found, we try item). |
|
67 | - if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
68 | - $pieces = explode( '-', $object_type ); |
|
69 | - $object_type = $pieces[0]; |
|
70 | - } |
|
71 | - |
|
72 | - if ( array_key_exists( $object_type, $this->stores ) ) { |
|
73 | - $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
74 | - if ( is_object( $store ) ) { |
|
75 | - $this->current_class_name = get_class( $store ); |
|
76 | - $this->instance = $store; |
|
77 | - } else { |
|
78 | - if ( ! class_exists( $store ) ) { |
|
79 | - throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
80 | - } |
|
81 | - $this->current_class_name = $store; |
|
82 | - $this->instance = new $store(); |
|
83 | - } |
|
84 | - } else { |
|
85 | - throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Only store the object type to avoid serializing the data store instance. |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function __sleep() { |
|
95 | - return array( 'object_type' ); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Re-run the constructor with the object type. |
|
100 | - * |
|
101 | - * @throws Exception When validation fails. |
|
102 | - */ |
|
103 | - public function __wakeup() { |
|
104 | - $this->__construct( $this->object_type ); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Loads a data store. |
|
109 | - * |
|
110 | - * @param string $object_type Name of object. |
|
111 | - * |
|
112 | - * @since 1.0.19 |
|
113 | - * @throws Exception When validation fails. |
|
114 | - * @return GetPaid_Data_Store |
|
115 | - */ |
|
116 | - public static function load( $object_type ) { |
|
117 | - return new GetPaid_Data_Store( $object_type ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Returns the class name of the current data store. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function get_current_class_name() { |
|
127 | - return $this->current_class_name; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Returns the object type of the current data store. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_object_type() { |
|
137 | - return $this->object_type; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Reads an object from the data store. |
|
142 | - * |
|
143 | - * @since 1.0.19 |
|
144 | - * @param GetPaid_Data $data GetPaid data instance. |
|
145 | - */ |
|
146 | - public function read( &$data ) { |
|
147 | - $this->instance->read( $data ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Create an object in the data store. |
|
152 | - * |
|
153 | - * @since 1.0.19 |
|
154 | - * @param GetPaid_Data $data GetPaid data instance. |
|
155 | - */ |
|
156 | - public function create( &$data ) { |
|
157 | - $this->instance->create( $data ); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Update an object in the data store. |
|
162 | - * |
|
163 | - * @since 1.0.19 |
|
164 | - * @param GetPaid_Data $data GetPaid data instance. |
|
165 | - */ |
|
166 | - public function update( &$data ) { |
|
167 | - $this->instance->update( $data ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Delete an object from the data store. |
|
172 | - * |
|
173 | - * @since 1.0.19 |
|
174 | - * @param GetPaid_Data $data GetPaid data instance. |
|
175 | - * @param array $args Array of args to pass to the delete method. |
|
176 | - */ |
|
177 | - public function delete( &$data, $args = array() ) { |
|
178 | - $this->instance->delete( $data, $args ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Data stores can define additional function. This passes |
|
183 | - * through to the instance if that function exists. |
|
184 | - * |
|
185 | - * @since 1.0.19 |
|
186 | - * @param string $method Method. |
|
187 | - * @return mixed |
|
188 | - */ |
|
189 | - public function __call( $method, $parameters ) { |
|
190 | - if ( is_callable( array( $this->instance, $method ) ) ) { |
|
191 | - $object = array_shift( $parameters ); |
|
192 | - $parameters = array_merge( array( &$object ), $parameters ); |
|
193 | - return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
194 | - } |
|
195 | - } |
|
14 | + /** |
|
15 | + * Contains an instance of the data store class that we are working with. |
|
16 | + * |
|
17 | + * @var GetPaid_Data_Store |
|
18 | + */ |
|
19 | + private $instance = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * Contains an array of default supported data stores. |
|
23 | + * Format of object name => class name. |
|
24 | + * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | + * You can also pass something like item-<type> for item stores and |
|
26 | + * that type will be used first when available, if a store is requested like |
|
27 | + * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | + * Ran through `getpaid_data_stores`. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $stores = array( |
|
33 | + 'item' => 'GetPaid_Item_Data_Store', |
|
34 | + 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | + 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | + 'invoice' => 'GetPaid_Invoice_Data_Store', |
|
37 | + 'subscription' => 'GetPaid_Subscription_Data_Store', |
|
38 | + 'customer' => 'GetPaid_Customer_Data_Store', |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * Contains the name of the current data store's class name. |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + private $current_class_name = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * The object type this store works with. |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + private $object_type = ''; |
|
54 | + |
|
55 | + /** |
|
56 | + * Tells GetPaid_Data_Store which object |
|
57 | + * store we want to work with. |
|
58 | + * |
|
59 | + * @param string $object_type Name of object. |
|
60 | + */ |
|
61 | + public function __construct( $object_type ) { |
|
62 | + $this->object_type = $object_type; |
|
63 | + $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
64 | + |
|
65 | + // If this object type can't be found, check to see if we can load one |
|
66 | + // level up (so if item-type isn't found, we try item). |
|
67 | + if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
68 | + $pieces = explode( '-', $object_type ); |
|
69 | + $object_type = $pieces[0]; |
|
70 | + } |
|
71 | + |
|
72 | + if ( array_key_exists( $object_type, $this->stores ) ) { |
|
73 | + $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
74 | + if ( is_object( $store ) ) { |
|
75 | + $this->current_class_name = get_class( $store ); |
|
76 | + $this->instance = $store; |
|
77 | + } else { |
|
78 | + if ( ! class_exists( $store ) ) { |
|
79 | + throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
80 | + } |
|
81 | + $this->current_class_name = $store; |
|
82 | + $this->instance = new $store(); |
|
83 | + } |
|
84 | + } else { |
|
85 | + throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Only store the object type to avoid serializing the data store instance. |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function __sleep() { |
|
95 | + return array( 'object_type' ); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Re-run the constructor with the object type. |
|
100 | + * |
|
101 | + * @throws Exception When validation fails. |
|
102 | + */ |
|
103 | + public function __wakeup() { |
|
104 | + $this->__construct( $this->object_type ); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Loads a data store. |
|
109 | + * |
|
110 | + * @param string $object_type Name of object. |
|
111 | + * |
|
112 | + * @since 1.0.19 |
|
113 | + * @throws Exception When validation fails. |
|
114 | + * @return GetPaid_Data_Store |
|
115 | + */ |
|
116 | + public static function load( $object_type ) { |
|
117 | + return new GetPaid_Data_Store( $object_type ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Returns the class name of the current data store. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function get_current_class_name() { |
|
127 | + return $this->current_class_name; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Returns the object type of the current data store. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_object_type() { |
|
137 | + return $this->object_type; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Reads an object from the data store. |
|
142 | + * |
|
143 | + * @since 1.0.19 |
|
144 | + * @param GetPaid_Data $data GetPaid data instance. |
|
145 | + */ |
|
146 | + public function read( &$data ) { |
|
147 | + $this->instance->read( $data ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Create an object in the data store. |
|
152 | + * |
|
153 | + * @since 1.0.19 |
|
154 | + * @param GetPaid_Data $data GetPaid data instance. |
|
155 | + */ |
|
156 | + public function create( &$data ) { |
|
157 | + $this->instance->create( $data ); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Update an object in the data store. |
|
162 | + * |
|
163 | + * @since 1.0.19 |
|
164 | + * @param GetPaid_Data $data GetPaid data instance. |
|
165 | + */ |
|
166 | + public function update( &$data ) { |
|
167 | + $this->instance->update( $data ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Delete an object from the data store. |
|
172 | + * |
|
173 | + * @since 1.0.19 |
|
174 | + * @param GetPaid_Data $data GetPaid data instance. |
|
175 | + * @param array $args Array of args to pass to the delete method. |
|
176 | + */ |
|
177 | + public function delete( &$data, $args = array() ) { |
|
178 | + $this->instance->delete( $data, $args ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Data stores can define additional function. This passes |
|
183 | + * through to the instance if that function exists. |
|
184 | + * |
|
185 | + * @since 1.0.19 |
|
186 | + * @param string $method Method. |
|
187 | + * @return mixed |
|
188 | + */ |
|
189 | + public function __call( $method, $parameters ) { |
|
190 | + if ( is_callable( array( $this->instance, $method ) ) ) { |
|
191 | + $object = array_shift( $parameters ); |
|
192 | + $parameters = array_merge( array( &$object ), $parameters ); |
|
193 | + return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
194 | + } |
|
195 | + } |
|
196 | 196 | |
197 | 197 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,196 +15,196 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Customer_Data_Store { |
17 | 17 | |
18 | - /* |
|
18 | + /* |
|
19 | 19 | |-------------------------------------------------------------------------- |
20 | 20 | | CRUD Methods |
21 | 21 | |-------------------------------------------------------------------------- |
22 | 22 | */ |
23 | 23 | |
24 | - /** |
|
25 | - * Method to create a new customer in the database. |
|
26 | - * |
|
27 | - * @param GetPaid_Customer $customer customer object. |
|
28 | - */ |
|
29 | - public function create( &$customer ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $values = array(); |
|
33 | - $formats = array(); |
|
34 | - |
|
35 | - $fields = self::get_database_fields(); |
|
36 | - unset( $fields['id'] ); |
|
37 | - |
|
38 | - foreach ( $fields as $key => $format ) { |
|
39 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | - $formats[] = $format; |
|
41 | - } |
|
42 | - |
|
43 | - $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | - |
|
45 | - if ( $result ) { |
|
46 | - $customer->set_id( $wpdb->insert_id ); |
|
47 | - $customer->apply_changes(); |
|
48 | - $customer->clear_cache(); |
|
49 | - do_action( 'getpaid_new_customer', $customer ); |
|
50 | - return true; |
|
51 | - } |
|
52 | - |
|
53 | - return false; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Method to read a customer from the database. |
|
58 | - * |
|
59 | - * @param GetPaid_Customer $customer customer object. |
|
60 | - * |
|
61 | - */ |
|
62 | - public function read( &$customer ) { |
|
63 | - global $wpdb; |
|
64 | - |
|
65 | - $customer->set_defaults(); |
|
66 | - |
|
67 | - if ( ! $customer->get_id() ) { |
|
68 | - $customer->last_error = 'Invalid customer.'; |
|
69 | - $customer->set_id( 0 ); |
|
70 | - return false; |
|
71 | - } |
|
72 | - |
|
73 | - // Maybe retrieve from the cache. |
|
74 | - $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | - |
|
76 | - // If not found, retrieve from the db. |
|
77 | - if ( false === $raw_customer ) { |
|
78 | - |
|
79 | - $raw_customer = $wpdb->get_row( |
|
80 | - $wpdb->prepare( |
|
81 | - "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | - $customer->get_id() |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - // Update the cache with our data |
|
87 | - wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - if ( ! $raw_customer ) { |
|
92 | - $raw_customer->last_error = 'Invalid customer.'; |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - // Loop through raw customer fields. |
|
97 | - foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | - $customer->set( $key, $value ); |
|
99 | - } |
|
100 | - |
|
101 | - $customer->set_object_read( true ); |
|
102 | - do_action( 'getpaid_read_customer', $customer ); |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Method to update a customer in the database. |
|
108 | - * |
|
109 | - * @param GetPaid_Customer $customer Customer object. |
|
110 | - */ |
|
111 | - public function update( &$customer ) { |
|
112 | - global $wpdb; |
|
113 | - |
|
114 | - do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | - |
|
116 | - $changes = $customer->get_changes(); |
|
117 | - $values = array(); |
|
118 | - $format = array(); |
|
119 | - |
|
120 | - foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | - if ( array_key_exists( $key, $changes ) ) { |
|
122 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | - $formats[] = $format; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - if ( empty( $values ) ) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $wpdb->update( |
|
132 | - $wpdb->prefix . 'getpaid_customers', |
|
133 | - $values, |
|
134 | - array( |
|
135 | - 'id' => $customer->get_id(), |
|
136 | - ), |
|
137 | - $formats, |
|
138 | - '%d' |
|
139 | - ); |
|
140 | - |
|
141 | - // Apply the changes. |
|
142 | - $customer->apply_changes(); |
|
143 | - |
|
144 | - // Delete cache. |
|
145 | - $customer->clear_cache(); |
|
146 | - |
|
147 | - // Fire a hook. |
|
148 | - do_action( 'getpaid_update_customer', $customer ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Method to delete a customer from the database. |
|
154 | - * |
|
155 | - * @param GetPaid_Customer $customer |
|
156 | - */ |
|
157 | - public function delete( &$customer ) { |
|
158 | - global $wpdb; |
|
159 | - |
|
160 | - do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | - |
|
162 | - $wpdb->delete( |
|
163 | - $wpdb->prefix . 'getpaid_customers', |
|
164 | - array( |
|
165 | - 'id' => $customer->get_id(), |
|
166 | - ), |
|
167 | - '%d' |
|
168 | - ); |
|
169 | - |
|
170 | - // Delete cache. |
|
171 | - $customer->clear_cache(); |
|
172 | - |
|
173 | - // Fire a hook. |
|
174 | - do_action( 'getpaid_delete_customer', $customer ); |
|
175 | - |
|
176 | - $customer->set_id( 0 ); |
|
177 | - } |
|
178 | - |
|
179 | - /* |
|
24 | + /** |
|
25 | + * Method to create a new customer in the database. |
|
26 | + * |
|
27 | + * @param GetPaid_Customer $customer customer object. |
|
28 | + */ |
|
29 | + public function create( &$customer ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $values = array(); |
|
33 | + $formats = array(); |
|
34 | + |
|
35 | + $fields = self::get_database_fields(); |
|
36 | + unset( $fields['id'] ); |
|
37 | + |
|
38 | + foreach ( $fields as $key => $format ) { |
|
39 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | + $formats[] = $format; |
|
41 | + } |
|
42 | + |
|
43 | + $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | + |
|
45 | + if ( $result ) { |
|
46 | + $customer->set_id( $wpdb->insert_id ); |
|
47 | + $customer->apply_changes(); |
|
48 | + $customer->clear_cache(); |
|
49 | + do_action( 'getpaid_new_customer', $customer ); |
|
50 | + return true; |
|
51 | + } |
|
52 | + |
|
53 | + return false; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Method to read a customer from the database. |
|
58 | + * |
|
59 | + * @param GetPaid_Customer $customer customer object. |
|
60 | + * |
|
61 | + */ |
|
62 | + public function read( &$customer ) { |
|
63 | + global $wpdb; |
|
64 | + |
|
65 | + $customer->set_defaults(); |
|
66 | + |
|
67 | + if ( ! $customer->get_id() ) { |
|
68 | + $customer->last_error = 'Invalid customer.'; |
|
69 | + $customer->set_id( 0 ); |
|
70 | + return false; |
|
71 | + } |
|
72 | + |
|
73 | + // Maybe retrieve from the cache. |
|
74 | + $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | + |
|
76 | + // If not found, retrieve from the db. |
|
77 | + if ( false === $raw_customer ) { |
|
78 | + |
|
79 | + $raw_customer = $wpdb->get_row( |
|
80 | + $wpdb->prepare( |
|
81 | + "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | + $customer->get_id() |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + // Update the cache with our data |
|
87 | + wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + if ( ! $raw_customer ) { |
|
92 | + $raw_customer->last_error = 'Invalid customer.'; |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + // Loop through raw customer fields. |
|
97 | + foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | + $customer->set( $key, $value ); |
|
99 | + } |
|
100 | + |
|
101 | + $customer->set_object_read( true ); |
|
102 | + do_action( 'getpaid_read_customer', $customer ); |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Method to update a customer in the database. |
|
108 | + * |
|
109 | + * @param GetPaid_Customer $customer Customer object. |
|
110 | + */ |
|
111 | + public function update( &$customer ) { |
|
112 | + global $wpdb; |
|
113 | + |
|
114 | + do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | + |
|
116 | + $changes = $customer->get_changes(); |
|
117 | + $values = array(); |
|
118 | + $format = array(); |
|
119 | + |
|
120 | + foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | + if ( array_key_exists( $key, $changes ) ) { |
|
122 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | + $formats[] = $format; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + if ( empty( $values ) ) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $wpdb->update( |
|
132 | + $wpdb->prefix . 'getpaid_customers', |
|
133 | + $values, |
|
134 | + array( |
|
135 | + 'id' => $customer->get_id(), |
|
136 | + ), |
|
137 | + $formats, |
|
138 | + '%d' |
|
139 | + ); |
|
140 | + |
|
141 | + // Apply the changes. |
|
142 | + $customer->apply_changes(); |
|
143 | + |
|
144 | + // Delete cache. |
|
145 | + $customer->clear_cache(); |
|
146 | + |
|
147 | + // Fire a hook. |
|
148 | + do_action( 'getpaid_update_customer', $customer ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Method to delete a customer from the database. |
|
154 | + * |
|
155 | + * @param GetPaid_Customer $customer |
|
156 | + */ |
|
157 | + public function delete( &$customer ) { |
|
158 | + global $wpdb; |
|
159 | + |
|
160 | + do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | + |
|
162 | + $wpdb->delete( |
|
163 | + $wpdb->prefix . 'getpaid_customers', |
|
164 | + array( |
|
165 | + 'id' => $customer->get_id(), |
|
166 | + ), |
|
167 | + '%d' |
|
168 | + ); |
|
169 | + |
|
170 | + // Delete cache. |
|
171 | + $customer->clear_cache(); |
|
172 | + |
|
173 | + // Fire a hook. |
|
174 | + do_action( 'getpaid_delete_customer', $customer ); |
|
175 | + |
|
176 | + $customer->set_id( 0 ); |
|
177 | + } |
|
178 | + |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | Additional Methods |
182 | 182 | |-------------------------------------------------------------------------- |
183 | 183 | */ |
184 | - public static function get_database_fields() { |
|
185 | - |
|
186 | - $fields = array( |
|
187 | - 'id' => '%d', |
|
188 | - 'user_id' => '%d', |
|
189 | - 'email' => '%s', |
|
190 | - 'email_cc' => '%s', |
|
191 | - 'status' => '%s', |
|
192 | - 'purchase_value' => '%f', |
|
193 | - 'purchase_count' => '%d', |
|
194 | - 'date_created' => '%s', |
|
195 | - 'date_modified' => '%s', |
|
196 | - 'uuid' => '%s', |
|
197 | - ); |
|
198 | - |
|
199 | - // Add address fields. |
|
200 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | - |
|
202 | - // Skip id, user_id and email. |
|
203 | - if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
204 | - $fields[ $field ] = '%s'; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - return $fields; |
|
209 | - } |
|
184 | + public static function get_database_fields() { |
|
185 | + |
|
186 | + $fields = array( |
|
187 | + 'id' => '%d', |
|
188 | + 'user_id' => '%d', |
|
189 | + 'email' => '%s', |
|
190 | + 'email_cc' => '%s', |
|
191 | + 'status' => '%s', |
|
192 | + 'purchase_value' => '%f', |
|
193 | + 'purchase_count' => '%d', |
|
194 | + 'date_created' => '%s', |
|
195 | + 'date_modified' => '%s', |
|
196 | + 'uuid' => '%s', |
|
197 | + ); |
|
198 | + |
|
199 | + // Add address fields. |
|
200 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | + |
|
202 | + // Skip id, user_id and email. |
|
203 | + if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
204 | + $fields[ $field ] = '%s'; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + return $fields; |
|
209 | + } |
|
210 | 210 | } |