@@ -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,44 +157,44 @@ 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' => __( '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 | - } |
|
| 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' => __( '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 | 190 | } |
| 191 | 191 | |
| 192 | - $profile_id = $sub->get_profile_id(); |
|
| 193 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 194 | - unset( $fields['profile_id'] ); |
|
| 195 | - } |
|
| 192 | + $profile_id = $sub->get_profile_id(); |
|
| 193 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 194 | + unset( $fields['profile_id'] ); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - ?> |
|
| 197 | + ?> |
|
| 198 | 198 | |
| 199 | 199 | <table class="table table-borderless" style="font-size: 14px;"> |
| 200 | 200 | <tbody> |
@@ -228,20 +228,20 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 230 | 230 | |
| 231 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 231 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 232 | 232 | |
| 233 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 234 | - if ( $user ) { |
|
| 233 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 234 | + if ( $user ) { |
|
| 235 | 235 | |
| 236 | - $username = sprintf( |
|
| 237 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 238 | - absint( $user->ID ), |
|
| 239 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 240 | - ); |
|
| 236 | + $username = sprintf( |
|
| 237 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 238 | + absint( $user->ID ), |
|
| 239 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 240 | + ); |
|
| 241 | 241 | |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - echo wp_kses_post( $username ); |
|
| 244 | + echo wp_kses_post( $username ); |
|
| 245 | 245 | } |
| 246 | 246 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 247 | 247 | |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | * @param WPInv_Subscription $subscription |
| 252 | 252 | */ |
| 253 | 253 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 254 | - $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
| 255 | - echo wp_kses_post( "<span>$amount</span>" ); |
|
| 254 | + $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
| 255 | + echo wp_kses_post( "<span>$amount</span>" ); |
|
| 256 | 256 | } |
| 257 | 257 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 258 | 258 | |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 265 | 265 | |
| 266 | - printf( |
|
| 267 | - '<a href="%s">#%s</a>', |
|
| 268 | - esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
| 269 | - absint( $subscription->get_id() ) |
|
| 270 | - ); |
|
| 266 | + printf( |
|
| 267 | + '<a href="%s">#%s</a>', |
|
| 268 | + esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
| 269 | + absint( $subscription->get_id() ) |
|
| 270 | + ); |
|
| 271 | 271 | |
| 272 | 272 | } |
| 273 | 273 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
@@ -279,24 +279,24 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 281 | 281 | |
| 282 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 283 | - aui()->input( |
|
| 284 | - array( |
|
| 285 | - 'type' => 'text', |
|
| 286 | - 'id' => 'wpinv_subscription_date_created', |
|
| 287 | - 'name' => 'wpinv_subscription_date_created', |
|
| 288 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
| 289 | - 'label_type' => 'hidden', |
|
| 290 | - 'placeholder' => 'YYYY-MM-DD', |
|
| 291 | - 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
| 292 | - 'no_wrap' => true, |
|
| 293 | - 'size' => 'sm', |
|
| 294 | - ), |
|
| 295 | - true |
|
| 296 | - ); |
|
| 297 | - } else { |
|
| 298 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 299 | - } |
|
| 282 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 283 | + aui()->input( |
|
| 284 | + array( |
|
| 285 | + 'type' => 'text', |
|
| 286 | + 'id' => 'wpinv_subscription_date_created', |
|
| 287 | + 'name' => 'wpinv_subscription_date_created', |
|
| 288 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
| 289 | + 'label_type' => 'hidden', |
|
| 290 | + 'placeholder' => 'YYYY-MM-DD', |
|
| 291 | + 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
| 292 | + 'no_wrap' => true, |
|
| 293 | + 'size' => 'sm', |
|
| 294 | + ), |
|
| 295 | + true |
|
| 296 | + ); |
|
| 297 | + } else { |
|
| 298 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | 301 | } |
| 302 | 302 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
@@ -308,24 +308,24 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 310 | 310 | |
| 311 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 312 | - aui()->input( |
|
| 313 | - array( |
|
| 314 | - 'type' => 'text', |
|
| 315 | - 'id' => 'wpinv_subscription_expiration', |
|
| 316 | - 'name' => 'wpinv_subscription_expiration', |
|
| 317 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
| 318 | - 'label_type' => 'hidden', |
|
| 319 | - 'placeholder' => 'YYYY-MM-DD', |
|
| 320 | - 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
| 321 | - 'no_wrap' => true, |
|
| 322 | - 'size' => 'sm', |
|
| 323 | - ), |
|
| 324 | - true |
|
| 325 | - ); |
|
| 326 | - } else { |
|
| 327 | - echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
| 328 | - } |
|
| 311 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
| 312 | + aui()->input( |
|
| 313 | + array( |
|
| 314 | + 'type' => 'text', |
|
| 315 | + 'id' => 'wpinv_subscription_expiration', |
|
| 316 | + 'name' => 'wpinv_subscription_expiration', |
|
| 317 | + 'label' => __( 'Renews On', 'invoicing' ), |
|
| 318 | + 'label_type' => 'hidden', |
|
| 319 | + 'placeholder' => 'YYYY-MM-DD', |
|
| 320 | + 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
| 321 | + 'no_wrap' => true, |
|
| 322 | + 'size' => 'sm', |
|
| 323 | + ), |
|
| 324 | + true |
|
| 325 | + ); |
|
| 326 | + } else { |
|
| 327 | + echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
| 328 | + } |
|
| 329 | 329 | } |
| 330 | 330 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 331 | 331 | |
@@ -335,8 +335,8 @@ discard block |
||
| 335 | 335 | * @param WPInv_Subscription $subscription |
| 336 | 336 | */ |
| 337 | 337 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 338 | - $max_bills = $subscription->get_bill_times(); |
|
| 339 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 338 | + $max_bills = $subscription->get_bill_times(); |
|
| 339 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 340 | 340 | } |
| 341 | 341 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 342 | 342 | /** |
@@ -347,13 +347,13 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
| 349 | 349 | |
| 350 | - if ( empty( $subscription_group ) ) { |
|
| 351 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
| 352 | - return; |
|
| 353 | - } |
|
| 350 | + if ( empty( $subscription_group ) ) { |
|
| 351 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 356 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 355 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 356 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 357 | 357 | |
| 358 | 358 | } |
| 359 | 359 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -365,13 +365,13 @@ discard block |
||
| 365 | 365 | */ |
| 366 | 366 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 367 | 367 | |
| 368 | - $gateway = $subscription->get_gateway(); |
|
| 368 | + $gateway = $subscription->get_gateway(); |
|
| 369 | 369 | |
| 370 | - if ( ! empty( $gateway ) ) { |
|
| 371 | - echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 372 | - } else { |
|
| 373 | - echo '—'; |
|
| 374 | - } |
|
| 370 | + if ( ! empty( $gateway ) ) { |
|
| 371 | + echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 372 | + } else { |
|
| 373 | + echo '—'; |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | 376 | } |
| 377 | 377 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | * @param WPInv_Subscription $subscription |
| 383 | 383 | */ |
| 384 | 384 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 385 | - echo wp_kses_post( $subscription->get_status_label_html() ); |
|
| 385 | + echo wp_kses_post( $subscription->get_status_label_html() ); |
|
| 386 | 386 | } |
| 387 | 387 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 388 | 388 | |
@@ -393,28 +393,28 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 395 | 395 | |
| 396 | - $profile_id = $subscription->get_profile_id(); |
|
| 397 | - |
|
| 398 | - aui()->input( |
|
| 399 | - array( |
|
| 400 | - 'type' => 'text', |
|
| 401 | - 'id' => 'wpinv_subscription_profile_id', |
|
| 402 | - 'name' => 'wpinv_subscription_profile_id', |
|
| 403 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 404 | - 'label_type' => 'hidden', |
|
| 405 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 406 | - 'value' => esc_attr( $profile_id ), |
|
| 407 | - 'input_group_right' => '', |
|
| 408 | - 'no_wrap' => true, |
|
| 409 | - 'size' => 'sm', |
|
| 410 | - ), |
|
| 411 | - true |
|
| 412 | - ); |
|
| 413 | - |
|
| 414 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 415 | - if ( ! empty( $url ) ) { |
|
| 416 | - 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>'; |
|
| 417 | - } |
|
| 396 | + $profile_id = $subscription->get_profile_id(); |
|
| 397 | + |
|
| 398 | + aui()->input( |
|
| 399 | + array( |
|
| 400 | + 'type' => 'text', |
|
| 401 | + 'id' => 'wpinv_subscription_profile_id', |
|
| 402 | + 'name' => 'wpinv_subscription_profile_id', |
|
| 403 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 404 | + 'label_type' => 'hidden', |
|
| 405 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 406 | + 'value' => esc_attr( $profile_id ), |
|
| 407 | + 'input_group_right' => '', |
|
| 408 | + 'no_wrap' => true, |
|
| 409 | + 'size' => 'sm', |
|
| 410 | + ), |
|
| 411 | + true |
|
| 412 | + ); |
|
| 413 | + |
|
| 414 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 415 | + if ( ! empty( $url ) ) { |
|
| 416 | + 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>'; |
|
| 417 | + } |
|
| 418 | 418 | |
| 419 | 419 | } |
| 420 | 420 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -426,40 +426,40 @@ discard block |
||
| 426 | 426 | */ |
| 427 | 427 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 428 | 428 | |
| 429 | - ?> |
|
| 429 | + ?> |
|
| 430 | 430 | <div class="mt-3"> |
| 431 | 431 | |
| 432 | 432 | <?php |
| 433 | - aui()->select( |
|
| 434 | - array( |
|
| 435 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 436 | - 'name' => 'subscription_status', |
|
| 437 | - 'id' => 'subscription_status_update_select', |
|
| 438 | - 'required' => true, |
|
| 439 | - 'no_wrap' => false, |
|
| 440 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 441 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 442 | - 'select2' => true, |
|
| 443 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 444 | - ), |
|
| 445 | - true |
|
| 446 | - ); |
|
| 447 | - ?> |
|
| 433 | + aui()->select( |
|
| 434 | + array( |
|
| 435 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 436 | + 'name' => 'subscription_status', |
|
| 437 | + 'id' => 'subscription_status_update_select', |
|
| 438 | + 'required' => true, |
|
| 439 | + 'no_wrap' => false, |
|
| 440 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 441 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 442 | + 'select2' => true, |
|
| 443 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 444 | + ), |
|
| 445 | + true |
|
| 446 | + ); |
|
| 447 | + ?> |
|
| 448 | 448 | |
| 449 | 449 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 450 | 450 | |
| 451 | 451 | <?php |
| 452 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 452 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 453 | 453 | |
| 454 | - $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 455 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 456 | - $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' ); |
|
| 454 | + $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 455 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 456 | + $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' ); |
|
| 457 | 457 | |
| 458 | - if ( $subscription->is_active() ) { |
|
| 459 | - echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
| 460 | - } |
|
| 458 | + if ( $subscription->is_active() ) { |
|
| 459 | + echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
| 460 | + } |
|
| 461 | 461 | |
| 462 | - echo '</div></div>'; |
|
| 462 | + echo '</div></div>'; |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -470,33 +470,33 @@ discard block |
||
| 470 | 470 | */ |
| 471 | 471 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
| 472 | 472 | |
| 473 | - $columns = apply_filters( |
|
| 474 | - 'getpaid_subscription_related_invoices_columns', |
|
| 475 | - array( |
|
| 476 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 477 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 478 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 479 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 480 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 481 | - ), |
|
| 482 | - $subscription |
|
| 483 | - ); |
|
| 484 | - |
|
| 485 | - // Prepare the invoices. |
|
| 486 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 487 | - $parent = $subscription->get_parent_invoice(); |
|
| 488 | - |
|
| 489 | - if ( $parent->exists() ) { |
|
| 490 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - $table_class = 'w-100 bg-white'; |
|
| 494 | - |
|
| 495 | - if ( ! is_admin() ) { |
|
| 496 | - $table_class = 'table table-bordered'; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - ?> |
|
| 473 | + $columns = apply_filters( |
|
| 474 | + 'getpaid_subscription_related_invoices_columns', |
|
| 475 | + array( |
|
| 476 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 477 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 478 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 479 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 480 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 481 | + ), |
|
| 482 | + $subscription |
|
| 483 | + ); |
|
| 484 | + |
|
| 485 | + // Prepare the invoices. |
|
| 486 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 487 | + $parent = $subscription->get_parent_invoice(); |
|
| 488 | + |
|
| 489 | + if ( $parent->exists() ) { |
|
| 490 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + $table_class = 'w-100 bg-white'; |
|
| 494 | + |
|
| 495 | + if ( ! is_admin() ) { |
|
| 496 | + $table_class = 'table table-bordered'; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + ?> |
|
| 500 | 500 | <div class="m-0" style="overflow: auto;"> |
| 501 | 501 | |
| 502 | 502 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -504,10 +504,10 @@ discard block |
||
| 504 | 504 | <thead> |
| 505 | 505 | <tr> |
| 506 | 506 | <?php |
| 507 | - foreach ( $columns as $key => $label ) { |
|
| 508 | - echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 509 | - } |
|
| 510 | - ?> |
|
| 507 | + foreach ( $columns as $key => $label ) { |
|
| 508 | + echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 509 | + } |
|
| 510 | + ?> |
|
| 511 | 511 | </tr> |
| 512 | 512 | </thead> |
| 513 | 513 | |
@@ -523,72 +523,72 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | <?php |
| 525 | 525 | |
| 526 | - foreach ( $payments as $payment ) : |
|
| 526 | + foreach ( $payments as $payment ) : |
|
| 527 | 527 | |
| 528 | - // Ensure that we have an invoice. |
|
| 529 | - $payment = new WPInv_Invoice( $payment ); |
|
| 528 | + // Ensure that we have an invoice. |
|
| 529 | + $payment = new WPInv_Invoice( $payment ); |
|
| 530 | 530 | |
| 531 | - // Abort if the invoice is invalid... |
|
| 532 | - if ( ! $payment->exists() ) { |
|
| 533 | - continue; |
|
| 534 | - } |
|
| 531 | + // Abort if the invoice is invalid... |
|
| 532 | + if ( ! $payment->exists() ) { |
|
| 533 | + continue; |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | - // ... or belongs to a different subscription. |
|
| 537 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 538 | - continue; |
|
| 539 | - } |
|
| 536 | + // ... or belongs to a different subscription. |
|
| 537 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 538 | + continue; |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | - echo '<tr>'; |
|
| 541 | + echo '<tr>'; |
|
| 542 | 542 | |
| 543 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 543 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 544 | 544 | |
| 545 | - echo "<td class='p-2 text-left'>"; |
|
| 545 | + echo "<td class='p-2 text-left'>"; |
|
| 546 | 546 | |
| 547 | - switch ( $key ) { |
|
| 547 | + switch ( $key ) { |
|
| 548 | 548 | |
| 549 | - case 'total': |
|
| 550 | - echo '<strong>'; |
|
| 551 | - wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
| 552 | - echo '</strong>'; |
|
| 553 | - break; |
|
| 549 | + case 'total': |
|
| 550 | + echo '<strong>'; |
|
| 551 | + wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
| 552 | + echo '</strong>'; |
|
| 553 | + break; |
|
| 554 | 554 | |
| 555 | - case 'relationship': |
|
| 556 | - echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
| 557 | - break; |
|
| 555 | + case 'relationship': |
|
| 556 | + echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
| 557 | + break; |
|
| 558 | 558 | |
| 559 | - case 'date': |
|
| 560 | - echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
| 561 | - break; |
|
| 559 | + case 'date': |
|
| 560 | + echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
| 561 | + break; |
|
| 562 | 562 | |
| 563 | - case 'status': |
|
| 564 | - $status = $payment->get_status_nicename(); |
|
| 565 | - if ( is_admin() ) { |
|
| 566 | - $status = $payment->get_status_label_html(); |
|
| 567 | - } |
|
| 563 | + case 'status': |
|
| 564 | + $status = $payment->get_status_nicename(); |
|
| 565 | + if ( is_admin() ) { |
|
| 566 | + $status = $payment->get_status_label_html(); |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | - echo wp_kses_post( $status ); |
|
| 570 | - break; |
|
| 569 | + echo wp_kses_post( $status ); |
|
| 570 | + break; |
|
| 571 | 571 | |
| 572 | - case 'invoice': |
|
| 573 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 572 | + case 'invoice': |
|
| 573 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 574 | 574 | |
| 575 | - if ( ! is_admin() ) { |
|
| 576 | - $link = esc_url( $payment->get_view_url() ); |
|
| 577 | - } |
|
| 575 | + if ( ! is_admin() ) { |
|
| 576 | + $link = esc_url( $payment->get_view_url() ); |
|
| 577 | + } |
|
| 578 | 578 | |
| 579 | - $invoice = esc_html( $payment->get_number() ); |
|
| 580 | - echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
| 581 | - break; |
|
| 582 | - } |
|
| 579 | + $invoice = esc_html( $payment->get_number() ); |
|
| 580 | + echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
| 581 | + break; |
|
| 582 | + } |
|
| 583 | 583 | |
| 584 | - echo '</td>'; |
|
| 584 | + echo '</td>'; |
|
| 585 | 585 | |
| 586 | - } |
|
| 586 | + } |
|
| 587 | 587 | |
| 588 | - echo '</tr>'; |
|
| 588 | + echo '</tr>'; |
|
| 589 | 589 | |
| 590 | - endforeach; |
|
| 591 | - ?> |
|
| 590 | + endforeach; |
|
| 591 | + ?> |
|
| 592 | 592 | |
| 593 | 593 | </tbody> |
| 594 | 594 | |
@@ -606,42 +606,42 @@ discard block |
||
| 606 | 606 | */ |
| 607 | 607 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
| 608 | 608 | |
| 609 | - // Fetch the subscription group. |
|
| 610 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 609 | + // Fetch the subscription group. |
|
| 610 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 611 | 611 | |
| 612 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 613 | - return; |
|
| 614 | - } |
|
| 612 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 613 | + return; |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | - // Prepare table columns. |
|
| 617 | - $columns = apply_filters( |
|
| 618 | - 'getpaid_subscription_item_details_columns', |
|
| 619 | - array( |
|
| 620 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
| 621 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 622 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 623 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 624 | - //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 625 | - 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
| 626 | - ), |
|
| 627 | - $subscription |
|
| 628 | - ); |
|
| 616 | + // Prepare table columns. |
|
| 617 | + $columns = apply_filters( |
|
| 618 | + 'getpaid_subscription_item_details_columns', |
|
| 619 | + array( |
|
| 620 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
| 621 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 622 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
| 623 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
| 624 | + //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 625 | + 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
| 626 | + ), |
|
| 627 | + $subscription |
|
| 628 | + ); |
|
| 629 | 629 | |
| 630 | - // Prepare the invoices. |
|
| 630 | + // Prepare the invoices. |
|
| 631 | 631 | |
| 632 | - $invoice = $subscription->get_parent_invoice(); |
|
| 632 | + $invoice = $subscription->get_parent_invoice(); |
|
| 633 | 633 | |
| 634 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 635 | - unset( $columns['tax'] ); |
|
| 636 | - } |
|
| 634 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 635 | + unset( $columns['tax'] ); |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | - $table_class = 'w-100 bg-white'; |
|
| 638 | + $table_class = 'w-100 bg-white'; |
|
| 639 | 639 | |
| 640 | - if ( ! is_admin() ) { |
|
| 641 | - $table_class = 'table table-bordered'; |
|
| 642 | - } |
|
| 640 | + if ( ! is_admin() ) { |
|
| 641 | + $table_class = 'table table-bordered'; |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | - ?> |
|
| 644 | + ?> |
|
| 645 | 645 | <div class="m-0" style="overflow: auto;"> |
| 646 | 646 | |
| 647 | 647 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -650,10 +650,10 @@ discard block |
||
| 650 | 650 | <tr> |
| 651 | 651 | <?php |
| 652 | 652 | |
| 653 | - foreach ( $columns as $key => $label ) { |
|
| 654 | - echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 655 | - } |
|
| 656 | - ?> |
|
| 653 | + foreach ( $columns as $key => $label ) { |
|
| 654 | + echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 655 | + } |
|
| 656 | + ?> |
|
| 657 | 657 | </tr> |
| 658 | 658 | </thead> |
| 659 | 659 | |
@@ -661,106 +661,106 @@ discard block |
||
| 661 | 661 | |
| 662 | 662 | <?php |
| 663 | 663 | |
| 664 | - foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
| 664 | + foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
| 665 | 665 | |
| 666 | - echo '<tr>'; |
|
| 666 | + echo '<tr>'; |
|
| 667 | 667 | |
| 668 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 668 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 669 | 669 | |
| 670 | - $class = 'text-left'; |
|
| 670 | + $class = 'text-left'; |
|
| 671 | 671 | |
| 672 | - echo "<td class='p-2 text-left'>"; |
|
| 672 | + echo "<td class='p-2 text-left'>"; |
|
| 673 | 673 | |
| 674 | - switch ( $key ) { |
|
| 674 | + switch ( $key ) { |
|
| 675 | 675 | |
| 676 | - case 'item_name': |
|
| 677 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 678 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 676 | + case 'item_name': |
|
| 677 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 678 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 679 | 679 | |
| 680 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 681 | - echo esc_html( $item_name ); |
|
| 682 | - } else { |
|
| 683 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 684 | - } |
|
| 680 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 681 | + echo esc_html( $item_name ); |
|
| 682 | + } else { |
|
| 683 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 684 | + } |
|
| 685 | 685 | |
| 686 | - break; |
|
| 686 | + break; |
|
| 687 | 687 | |
| 688 | - case 'price': |
|
| 689 | - wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
| 690 | - break; |
|
| 688 | + case 'price': |
|
| 689 | + wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
| 690 | + break; |
|
| 691 | 691 | |
| 692 | - case 'tax': |
|
| 693 | - wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 694 | - break; |
|
| 692 | + case 'tax': |
|
| 693 | + wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 694 | + break; |
|
| 695 | 695 | |
| 696 | - case 'discount': |
|
| 697 | - wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 698 | - break; |
|
| 696 | + case 'discount': |
|
| 697 | + wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 698 | + break; |
|
| 699 | 699 | |
| 700 | - case 'initial': |
|
| 701 | - wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
| 702 | - break; |
|
| 700 | + case 'initial': |
|
| 701 | + wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
| 702 | + break; |
|
| 703 | 703 | |
| 704 | - case 'recurring': |
|
| 705 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
| 706 | - break; |
|
| 704 | + case 'recurring': |
|
| 705 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
| 706 | + break; |
|
| 707 | 707 | |
| 708 | - } |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | - echo '</td>'; |
|
| 710 | + echo '</td>'; |
|
| 711 | 711 | |
| 712 | - } |
|
| 712 | + } |
|
| 713 | 713 | |
| 714 | - echo '</tr>'; |
|
| 714 | + echo '</tr>'; |
|
| 715 | 715 | |
| 716 | - endforeach; |
|
| 716 | + endforeach; |
|
| 717 | 717 | |
| 718 | - foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 718 | + foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 719 | 719 | |
| 720 | - echo '<tr>'; |
|
| 720 | + echo '<tr>'; |
|
| 721 | 721 | |
| 722 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 722 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 723 | 723 | |
| 724 | - $class = 'text-left'; |
|
| 724 | + $class = 'text-left'; |
|
| 725 | 725 | |
| 726 | - echo "<td class='p-2 text-left'>"; |
|
| 726 | + echo "<td class='p-2 text-left'>"; |
|
| 727 | 727 | |
| 728 | - switch ( $key ) { |
|
| 728 | + switch ( $key ) { |
|
| 729 | 729 | |
| 730 | - case 'item_name': |
|
| 731 | - echo esc_html( $subscription_group_fee['name'] ); |
|
| 732 | - break; |
|
| 730 | + case 'item_name': |
|
| 731 | + echo esc_html( $subscription_group_fee['name'] ); |
|
| 732 | + break; |
|
| 733 | 733 | |
| 734 | - case 'price': |
|
| 735 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 736 | - break; |
|
| 734 | + case 'price': |
|
| 735 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 736 | + break; |
|
| 737 | 737 | |
| 738 | - case 'tax': |
|
| 739 | - echo '—'; |
|
| 740 | - break; |
|
| 738 | + case 'tax': |
|
| 739 | + echo '—'; |
|
| 740 | + break; |
|
| 741 | 741 | |
| 742 | - case 'discount': |
|
| 743 | - echo '—'; |
|
| 744 | - break; |
|
| 742 | + case 'discount': |
|
| 743 | + echo '—'; |
|
| 744 | + break; |
|
| 745 | 745 | |
| 746 | - case 'initial': |
|
| 747 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 748 | - break; |
|
| 746 | + case 'initial': |
|
| 747 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 748 | + break; |
|
| 749 | 749 | |
| 750 | - case 'recurring': |
|
| 751 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
| 752 | - break; |
|
| 750 | + case 'recurring': |
|
| 751 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
| 752 | + break; |
|
| 753 | 753 | |
| 754 | - } |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | - echo '</td>'; |
|
| 756 | + echo '</td>'; |
|
| 757 | 757 | |
| 758 | - } |
|
| 758 | + } |
|
| 759 | 759 | |
| 760 | - echo '</tr>'; |
|
| 760 | + echo '</tr>'; |
|
| 761 | 761 | |
| 762 | - endforeach; |
|
| 763 | - ?> |
|
| 762 | + endforeach; |
|
| 763 | + ?> |
|
| 764 | 764 | |
| 765 | 765 | </tbody> |
| 766 | 766 | |
@@ -779,38 +779,38 @@ discard block |
||
| 779 | 779 | */ |
| 780 | 780 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
| 781 | 781 | |
| 782 | - // Fetch the subscription groups. |
|
| 783 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 784 | - |
|
| 785 | - if ( empty( $subscription_groups ) ) { |
|
| 786 | - return; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - // Prepare table columns. |
|
| 790 | - $columns = apply_filters( |
|
| 791 | - 'getpaid_subscription_related_subscriptions_columns', |
|
| 792 | - array( |
|
| 793 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 794 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 795 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 796 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 797 | - 'item' => __( 'Items', 'invoicing' ), |
|
| 798 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 799 | - ), |
|
| 800 | - $subscription |
|
| 801 | - ); |
|
| 802 | - |
|
| 803 | - if ( $subscription->get_status() == 'pending' ) { |
|
| 804 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - $table_class = 'w-100 bg-white'; |
|
| 808 | - |
|
| 809 | - if ( ! is_admin() ) { |
|
| 810 | - $table_class = 'table table-bordered'; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - ?> |
|
| 782 | + // Fetch the subscription groups. |
|
| 783 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 784 | + |
|
| 785 | + if ( empty( $subscription_groups ) ) { |
|
| 786 | + return; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + // Prepare table columns. |
|
| 790 | + $columns = apply_filters( |
|
| 791 | + 'getpaid_subscription_related_subscriptions_columns', |
|
| 792 | + array( |
|
| 793 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 794 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 795 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 796 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 797 | + 'item' => __( 'Items', 'invoicing' ), |
|
| 798 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 799 | + ), |
|
| 800 | + $subscription |
|
| 801 | + ); |
|
| 802 | + |
|
| 803 | + if ( $subscription->get_status() == 'pending' ) { |
|
| 804 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + $table_class = 'w-100 bg-white'; |
|
| 808 | + |
|
| 809 | + if ( ! is_admin() ) { |
|
| 810 | + $table_class = 'table table-bordered'; |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + ?> |
|
| 814 | 814 | <div class="m-0" style="overflow: auto;"> |
| 815 | 815 | |
| 816 | 816 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -819,10 +819,10 @@ discard block |
||
| 819 | 819 | <tr> |
| 820 | 820 | <?php |
| 821 | 821 | |
| 822 | - foreach ( $columns as $key => $label ) { |
|
| 823 | - echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 824 | - } |
|
| 825 | - ?> |
|
| 822 | + foreach ( $columns as $key => $label ) { |
|
| 823 | + echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 824 | + } |
|
| 825 | + ?> |
|
| 826 | 826 | </tr> |
| 827 | 827 | </thead> |
| 828 | 828 | |
@@ -830,74 +830,74 @@ discard block |
||
| 830 | 830 | |
| 831 | 831 | <?php |
| 832 | 832 | |
| 833 | - foreach ( $subscription_groups as $subscription_group ) : |
|
| 833 | + foreach ( $subscription_groups as $subscription_group ) : |
|
| 834 | 834 | |
| 835 | - // Do not list current subscription. |
|
| 836 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 837 | - continue; |
|
| 838 | - } |
|
| 835 | + // Do not list current subscription. |
|
| 836 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 837 | + continue; |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - // Ensure the subscription exists. |
|
| 841 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 840 | + // Ensure the subscription exists. |
|
| 841 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 842 | 842 | |
| 843 | - if ( ! $_suscription->exists() ) { |
|
| 844 | - continue; |
|
| 845 | - } |
|
| 843 | + if ( ! $_suscription->exists() ) { |
|
| 844 | + continue; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - echo '<tr>'; |
|
| 847 | + echo '<tr>'; |
|
| 848 | 848 | |
| 849 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 849 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 850 | 850 | |
| 851 | - $class = 'text-left'; |
|
| 851 | + $class = 'text-left'; |
|
| 852 | 852 | |
| 853 | - echo "<td class='p-2 text-left'>"; |
|
| 853 | + echo "<td class='p-2 text-left'>"; |
|
| 854 | 854 | |
| 855 | - switch ( $key ) { |
|
| 855 | + switch ( $key ) { |
|
| 856 | 856 | |
| 857 | - case 'status': |
|
| 858 | - echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
| 859 | - break; |
|
| 857 | + case 'status': |
|
| 858 | + echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
| 859 | + break; |
|
| 860 | 860 | |
| 861 | - case 'item': |
|
| 862 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 863 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 864 | - break; |
|
| 861 | + case 'item': |
|
| 862 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 863 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 864 | + break; |
|
| 865 | 865 | |
| 866 | - case 'renewals': |
|
| 867 | - $max_bills = $_suscription->get_bill_times(); |
|
| 868 | - echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 869 | - break; |
|
| 866 | + case 'renewals': |
|
| 867 | + $max_bills = $_suscription->get_bill_times(); |
|
| 868 | + echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 869 | + break; |
|
| 870 | 870 | |
| 871 | - case 'renewal_date': |
|
| 872 | - echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
| 873 | - break; |
|
| 871 | + case 'renewal_date': |
|
| 872 | + echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
| 873 | + break; |
|
| 874 | 874 | |
| 875 | - case 'start_date': |
|
| 876 | - echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
| 877 | - break; |
|
| 875 | + case 'start_date': |
|
| 876 | + echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
| 877 | + break; |
|
| 878 | 878 | |
| 879 | - case 'subscription': |
|
| 880 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 881 | - printf( |
|
| 879 | + case 'subscription': |
|
| 880 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 881 | + printf( |
|
| 882 | 882 | '%1$s#%2$s%3$s', |
| 883 | 883 | '<a href="' . esc_url( $url ) . '">', |
| 884 | 884 | '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
| 885 | - '</a>' |
|
| 885 | + '</a>' |
|
| 886 | 886 | ); |
| 887 | 887 | |
| 888 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
| 889 | - break; |
|
| 888 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
| 889 | + break; |
|
| 890 | 890 | |
| 891 | - } |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | - echo '</td>'; |
|
| 893 | + echo '</td>'; |
|
| 894 | 894 | |
| 895 | - } |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - echo '</tr>'; |
|
| 897 | + echo '</tr>'; |
|
| 898 | 898 | |
| 899 | - endforeach; |
|
| 900 | - ?> |
|
| 899 | + endforeach; |
|
| 900 | + ?> |
|
| 901 | 901 | |
| 902 | 902 | </tbody> |
| 903 | 903 | |
@@ -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', '' ); |
|
| 237 | 640 | |
| 238 | - /** |
|
| 239 | - * Alias for self::get_parent_invoice_id(). |
|
| 641 | + } |
|
| 642 | + |
|
| 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,187 +867,187 @@ 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 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 910 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 909 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 910 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 911 | 911 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 912 | 912 | |
| 913 | 913 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 914 | 914 | |
| 915 | 915 | return $invoice->get_id(); |
| 916 | - } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - /** |
|
| 918 | + /** |
|
| 919 | 919 | * Creates a new invoice and returns it. |
| 920 | 920 | * |
| 921 | 921 | * @since 1.0.19 |
| 922 | - * @param bool $save Whether we should save the invoice. |
|
| 922 | + * @param bool $save Whether we should save the invoice. |
|
| 923 | 923 | * @return WPInv_Invoice|bool |
| 924 | 924 | */ |
| 925 | 925 | public function create_payment( $save = true ) { |
| 926 | 926 | |
| 927 | - $parent_invoice = $this->get_parent_payment(); |
|
| 928 | - |
|
| 929 | - if ( ! $parent_invoice->exists() ) { |
|
| 930 | - return false; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - // Duplicate the parent invoice. |
|
| 934 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 935 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 936 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 937 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 938 | - |
|
| 939 | - // Set invoice items. |
|
| 940 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 941 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 942 | - $invoice_items = array(); |
|
| 943 | - |
|
| 944 | - foreach ( $invoice->get_items() as $item ) { |
|
| 945 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 946 | - $invoice_items[] = $item; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - $invoice->set_items( $invoice_items ); |
|
| 951 | - |
|
| 952 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 953 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 957 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 958 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 959 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - $invoice->recalculate_total(); |
|
| 963 | - $invoice->set_status( 'wpi-pending' ); |
|
| 964 | - |
|
| 965 | - if ( ! $save ) { |
|
| 966 | - return $invoice; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - $invoice->save(); |
|
| 970 | - |
|
| 971 | - return $invoice->exists() ? $invoice : false; |
|
| 972 | - } |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * Renews or completes a subscription |
|
| 976 | - * |
|
| 977 | - * @since 1.0.0 |
|
| 978 | - * @return int The subscription's id |
|
| 979 | - */ |
|
| 980 | - public function renew( $calculate_from = null ) { |
|
| 981 | - |
|
| 982 | - // Complete subscription if applicable |
|
| 983 | - if ( $this->is_last_renewal() ) { |
|
| 984 | - return $this->complete(); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - // Calculate new expiration |
|
| 988 | - $frequency = $this->get_frequency(); |
|
| 989 | - $period = $this->get_period(); |
|
| 990 | - $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
| 991 | - $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
| 992 | - |
|
| 993 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
| 994 | - $this->set_status( 'active' ); |
|
| 995 | - $this->save(); |
|
| 996 | - |
|
| 997 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 998 | - |
|
| 999 | - return $this->get_id(); |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - /** |
|
| 1003 | - * Marks a subscription as completed |
|
| 1004 | - * |
|
| 1005 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 1006 | - * |
|
| 1007 | - * @since 1.0.0 |
|
| 1008 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 1009 | - */ |
|
| 1010 | - public function complete() { |
|
| 1011 | - |
|
| 1012 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 1013 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1014 | - return false; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - $this->set_status( 'completed' ); |
|
| 1018 | - return $this->save(); |
|
| 1019 | - |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * Marks a subscription as expired |
|
| 1024 | - * |
|
| 1025 | - * @since 1.0.0 |
|
| 1026 | - * @param bool $check_expiration |
|
| 1027 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1028 | - */ |
|
| 1029 | - public function expire( $check_expiration = false ) { |
|
| 1030 | - |
|
| 1031 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1032 | - // Do not mark as expired since real expiration date is in the future |
|
| 1033 | - return false; |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - $this->set_status( 'expired' ); |
|
| 1037 | - return $this->save(); |
|
| 1038 | - |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Marks a subscription as failing |
|
| 1043 | - * |
|
| 1044 | - * @since 2.4.2 |
|
| 1045 | - * @return int Subscription id. |
|
| 1046 | - */ |
|
| 1047 | - public function failing() { |
|
| 1048 | - $this->set_status( 'failing' ); |
|
| 1049 | - return $this->save(); |
|
| 1050 | - } |
|
| 927 | + $parent_invoice = $this->get_parent_payment(); |
|
| 928 | + |
|
| 929 | + if ( ! $parent_invoice->exists() ) { |
|
| 930 | + return false; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + // Duplicate the parent invoice. |
|
| 934 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 935 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 936 | + $invoice->set_subscription_id( $this->get_id() ); |
|
| 937 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 938 | + |
|
| 939 | + // Set invoice items. |
|
| 940 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 941 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 942 | + $invoice_items = array(); |
|
| 943 | + |
|
| 944 | + foreach ( $invoice->get_items() as $item ) { |
|
| 945 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 946 | + $invoice_items[] = $item; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + $invoice->set_items( $invoice_items ); |
|
| 951 | + |
|
| 952 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 953 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 957 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 958 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 959 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + $invoice->recalculate_total(); |
|
| 963 | + $invoice->set_status( 'wpi-pending' ); |
|
| 964 | + |
|
| 965 | + if ( ! $save ) { |
|
| 966 | + return $invoice; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + $invoice->save(); |
|
| 970 | + |
|
| 971 | + return $invoice->exists() ? $invoice : false; |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * Renews or completes a subscription |
|
| 976 | + * |
|
| 977 | + * @since 1.0.0 |
|
| 978 | + * @return int The subscription's id |
|
| 979 | + */ |
|
| 980 | + public function renew( $calculate_from = null ) { |
|
| 981 | + |
|
| 982 | + // Complete subscription if applicable |
|
| 983 | + if ( $this->is_last_renewal() ) { |
|
| 984 | + return $this->complete(); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + // Calculate new expiration |
|
| 988 | + $frequency = $this->get_frequency(); |
|
| 989 | + $period = $this->get_period(); |
|
| 990 | + $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
| 991 | + $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
| 992 | + |
|
| 993 | + $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
| 994 | + $this->set_status( 'active' ); |
|
| 995 | + $this->save(); |
|
| 996 | + |
|
| 997 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 998 | + |
|
| 999 | + return $this->get_id(); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * Marks a subscription as completed |
|
| 1004 | + * |
|
| 1005 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 1006 | + * |
|
| 1007 | + * @since 1.0.0 |
|
| 1008 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 1009 | + */ |
|
| 1010 | + public function complete() { |
|
| 1011 | + |
|
| 1012 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 1013 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 1014 | + return false; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + $this->set_status( 'completed' ); |
|
| 1018 | + return $this->save(); |
|
| 1019 | + |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * Marks a subscription as expired |
|
| 1024 | + * |
|
| 1025 | + * @since 1.0.0 |
|
| 1026 | + * @param bool $check_expiration |
|
| 1027 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1028 | + */ |
|
| 1029 | + public function expire( $check_expiration = false ) { |
|
| 1030 | + |
|
| 1031 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1032 | + // Do not mark as expired since real expiration date is in the future |
|
| 1033 | + return false; |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + $this->set_status( 'expired' ); |
|
| 1037 | + return $this->save(); |
|
| 1038 | + |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Marks a subscription as failing |
|
| 1043 | + * |
|
| 1044 | + * @since 2.4.2 |
|
| 1045 | + * @return int Subscription id. |
|
| 1046 | + */ |
|
| 1047 | + public function failing() { |
|
| 1048 | + $this->set_status( 'failing' ); |
|
| 1049 | + return $this->save(); |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | 1052 | /** |
| 1053 | 1053 | * Marks a subscription as cancelled |
@@ -1056,19 +1056,19 @@ discard block |
||
| 1056 | 1056 | * @return int Subscription id. |
| 1057 | 1057 | */ |
| 1058 | 1058 | public function cancel() { |
| 1059 | - $this->set_status( 'cancelled' ); |
|
| 1060 | - return $this->save(); |
|
| 1059 | + $this->set_status( 'cancelled' ); |
|
| 1060 | + return $this->save(); |
|
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - /** |
|
| 1064 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1065 | - * |
|
| 1066 | - * @since 1.0.0 |
|
| 1067 | - * @return bool |
|
| 1068 | - */ |
|
| 1069 | - public function can_cancel() { |
|
| 1070 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1071 | - } |
|
| 1063 | + /** |
|
| 1064 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1065 | + * |
|
| 1066 | + * @since 1.0.0 |
|
| 1067 | + * @return bool |
|
| 1068 | + */ |
|
| 1069 | + public function can_cancel() { |
|
| 1070 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1071 | + } |
|
| 1072 | 1072 | |
| 1073 | 1073 | /** |
| 1074 | 1074 | * Returns an array of subscription statuses that can be cancelled |
@@ -1081,109 +1081,109 @@ discard block |
||
| 1081 | 1081 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | - /** |
|
| 1085 | - * Retrieves the URL to cancel subscription |
|
| 1086 | - * |
|
| 1087 | - * @since 1.0.0 |
|
| 1088 | - * @return string |
|
| 1089 | - */ |
|
| 1090 | - public function get_cancel_url() { |
|
| 1091 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1092 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * Retrieves the URL to view a subscription |
|
| 1097 | - * |
|
| 1098 | - * @since 1.0.19 |
|
| 1099 | - * @return string |
|
| 1100 | - */ |
|
| 1101 | - public function get_view_url() { |
|
| 1102 | - |
|
| 1103 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1104 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1105 | - |
|
| 1106 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - /** |
|
| 1110 | - * Determines if subscription can be manually renewed |
|
| 1111 | - * |
|
| 1112 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1113 | - * that can be renewed manually |
|
| 1114 | - * |
|
| 1115 | - * @since 2.5 |
|
| 1116 | - * @return bool |
|
| 1117 | - */ |
|
| 1118 | - public function can_renew() { |
|
| 1119 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - /** |
|
| 1123 | - * Retrieves the URL to renew a subscription |
|
| 1124 | - * |
|
| 1125 | - * @since 2.5 |
|
| 1126 | - * @return string |
|
| 1127 | - */ |
|
| 1128 | - public function get_renew_url() { |
|
| 1129 | - $url = wp_nonce_url( |
|
| 1084 | + /** |
|
| 1085 | + * Retrieves the URL to cancel subscription |
|
| 1086 | + * |
|
| 1087 | + * @since 1.0.0 |
|
| 1088 | + * @return string |
|
| 1089 | + */ |
|
| 1090 | + public function get_cancel_url() { |
|
| 1091 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1092 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * Retrieves the URL to view a subscription |
|
| 1097 | + * |
|
| 1098 | + * @since 1.0.19 |
|
| 1099 | + * @return string |
|
| 1100 | + */ |
|
| 1101 | + public function get_view_url() { |
|
| 1102 | + |
|
| 1103 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1104 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1105 | + |
|
| 1106 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * Determines if subscription can be manually renewed |
|
| 1111 | + * |
|
| 1112 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1113 | + * that can be renewed manually |
|
| 1114 | + * |
|
| 1115 | + * @since 2.5 |
|
| 1116 | + * @return bool |
|
| 1117 | + */ |
|
| 1118 | + public function can_renew() { |
|
| 1119 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + /** |
|
| 1123 | + * Retrieves the URL to renew a subscription |
|
| 1124 | + * |
|
| 1125 | + * @since 2.5 |
|
| 1126 | + * @return string |
|
| 1127 | + */ |
|
| 1128 | + public function get_renew_url() { |
|
| 1129 | + $url = wp_nonce_url( |
|
| 1130 | 1130 | add_query_arg( |
| 1131 | 1131 | array( |
| 1132 | - 'getpaid-action' => 'renew_subscription', |
|
| 1133 | - 'sub_id' => $this->get_id, |
|
| 1132 | + 'getpaid-action' => 'renew_subscription', |
|
| 1133 | + 'sub_id' => $this->get_id, |
|
| 1134 | 1134 | ) |
| 1135 | 1135 | ), |
| 1136 | 1136 | 'getpaid-nonce' |
| 1137 | 1137 | ); |
| 1138 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - /** |
|
| 1142 | - * Determines if subscription can have their payment method updated |
|
| 1143 | - * |
|
| 1144 | - * @since 1.0.0 |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public function can_update() { |
|
| 1148 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * Retrieves the URL to update subscription |
|
| 1153 | - * |
|
| 1154 | - * @since 1.0.0 |
|
| 1155 | - * @return string |
|
| 1156 | - */ |
|
| 1157 | - public function get_update_url() { |
|
| 1158 | - $url = add_query_arg( |
|
| 1138 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + /** |
|
| 1142 | + * Determines if subscription can have their payment method updated |
|
| 1143 | + * |
|
| 1144 | + * @since 1.0.0 |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public function can_update() { |
|
| 1148 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * Retrieves the URL to update subscription |
|
| 1153 | + * |
|
| 1154 | + * @since 1.0.0 |
|
| 1155 | + * @return string |
|
| 1156 | + */ |
|
| 1157 | + public function get_update_url() { |
|
| 1158 | + $url = add_query_arg( |
|
| 1159 | 1159 | array( |
| 1160 | - 'action' => 'update', |
|
| 1161 | - 'subscription_id' => $this->get_id(), |
|
| 1160 | + 'action' => 'update', |
|
| 1161 | + 'subscription_id' => $this->get_id(), |
|
| 1162 | 1162 | ) |
| 1163 | 1163 | ); |
| 1164 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - /** |
|
| 1168 | - * Retrieves the subscription status label |
|
| 1169 | - * |
|
| 1170 | - * @since 1.0.0 |
|
| 1171 | - * @return string |
|
| 1172 | - */ |
|
| 1173 | - public function get_status_label() { |
|
| 1174 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - /** |
|
| 1178 | - * Retrieves the subscription status class |
|
| 1179 | - * |
|
| 1180 | - * @since 1.0.19 |
|
| 1181 | - * @return string |
|
| 1182 | - */ |
|
| 1183 | - public function get_status_class() { |
|
| 1184 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1185 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
| 1186 | - } |
|
| 1164 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + /** |
|
| 1168 | + * Retrieves the subscription status label |
|
| 1169 | + * |
|
| 1170 | + * @since 1.0.0 |
|
| 1171 | + * @return string |
|
| 1172 | + */ |
|
| 1173 | + public function get_status_label() { |
|
| 1174 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + /** |
|
| 1178 | + * Retrieves the subscription status class |
|
| 1179 | + * |
|
| 1180 | + * @since 1.0.19 |
|
| 1181 | + * @return string |
|
| 1182 | + */ |
|
| 1183 | + public function get_status_class() { |
|
| 1184 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1185 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
| 1186 | + } |
|
| 1187 | 1187 | |
| 1188 | 1188 | /** |
| 1189 | 1189 | * Retrieves the subscription status label |
@@ -1193,11 +1193,11 @@ discard block |
||
| 1193 | 1193 | */ |
| 1194 | 1194 | public function get_status_label_html() { |
| 1195 | 1195 | |
| 1196 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1197 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1198 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1196 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1197 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1198 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 1199 | 1199 | |
| 1200 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1200 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | /** |
@@ -1208,75 +1208,75 @@ discard block |
||
| 1208 | 1208 | * @return bool |
| 1209 | 1209 | */ |
| 1210 | 1210 | public function payment_exists( $txn_id = '' ) { |
| 1211 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1211 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1212 | 1212 | return ! empty( $invoice_id ); |
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * Handle the status transition. |
|
| 1217 | - */ |
|
| 1218 | - protected function status_transition() { |
|
| 1219 | - $status_transition = $this->status_transition; |
|
| 1220 | - |
|
| 1221 | - // Reset status transition variable. |
|
| 1222 | - $this->status_transition = false; |
|
| 1223 | - |
|
| 1224 | - if ( $status_transition ) { |
|
| 1225 | - try { |
|
| 1226 | - |
|
| 1227 | - // Fire a hook for the status change. |
|
| 1228 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1229 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1230 | - |
|
| 1231 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1232 | - |
|
| 1233 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1234 | - $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'] ) ); |
|
| 1235 | - |
|
| 1236 | - // Note the transition occurred. |
|
| 1237 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1238 | - |
|
| 1239 | - // Fire another hook. |
|
| 1240 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1241 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1242 | - |
|
| 1243 | - } else { |
|
| 1244 | - /* translators: %s: new invoice status */ |
|
| 1245 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1246 | - |
|
| 1247 | - // Note the transition occurred. |
|
| 1248 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1249 | - |
|
| 1250 | - } |
|
| 1251 | - } catch ( Exception $e ) { |
|
| 1252 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Save data to the database. |
|
| 1260 | - * |
|
| 1261 | - * @since 1.0.19 |
|
| 1262 | - * @return int subscription ID |
|
| 1263 | - */ |
|
| 1264 | - public function save() { |
|
| 1265 | - parent::save(); |
|
| 1266 | - $this->status_transition(); |
|
| 1267 | - return $this->get_id(); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * Activates a subscription. |
|
| 1272 | - * |
|
| 1273 | - * @since 1.0.19 |
|
| 1274 | - * @return int subscription ID |
|
| 1275 | - */ |
|
| 1276 | - public function activate() { |
|
| 1277 | - $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
| 1278 | - $this->set_status( $status ); |
|
| 1279 | - return $this->save(); |
|
| 1280 | - } |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * Handle the status transition. |
|
| 1217 | + */ |
|
| 1218 | + protected function status_transition() { |
|
| 1219 | + $status_transition = $this->status_transition; |
|
| 1220 | + |
|
| 1221 | + // Reset status transition variable. |
|
| 1222 | + $this->status_transition = false; |
|
| 1223 | + |
|
| 1224 | + if ( $status_transition ) { |
|
| 1225 | + try { |
|
| 1226 | + |
|
| 1227 | + // Fire a hook for the status change. |
|
| 1228 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1229 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1230 | + |
|
| 1231 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1232 | + |
|
| 1233 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1234 | + $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'] ) ); |
|
| 1235 | + |
|
| 1236 | + // Note the transition occurred. |
|
| 1237 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1238 | + |
|
| 1239 | + // Fire another hook. |
|
| 1240 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1241 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1242 | + |
|
| 1243 | + } else { |
|
| 1244 | + /* translators: %s: new invoice status */ |
|
| 1245 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1246 | + |
|
| 1247 | + // Note the transition occurred. |
|
| 1248 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1249 | + |
|
| 1250 | + } |
|
| 1251 | + } catch ( Exception $e ) { |
|
| 1252 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Save data to the database. |
|
| 1260 | + * |
|
| 1261 | + * @since 1.0.19 |
|
| 1262 | + * @return int subscription ID |
|
| 1263 | + */ |
|
| 1264 | + public function save() { |
|
| 1265 | + parent::save(); |
|
| 1266 | + $this->status_transition(); |
|
| 1267 | + return $this->get_id(); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + /** |
|
| 1271 | + * Activates a subscription. |
|
| 1272 | + * |
|
| 1273 | + * @since 1.0.19 |
|
| 1274 | + * @return int subscription ID |
|
| 1275 | + */ |
|
| 1276 | + public function activate() { |
|
| 1277 | + $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
| 1278 | + $this->set_status( $status ); |
|
| 1279 | + return $this->save(); |
|
| 1280 | + } |
|
| 1281 | 1281 | |
| 1282 | 1282 | } |