@@ -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,27 +22,27 @@ 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 | - echo aui()->alert( |
|
| 29 | - array( |
|
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 28 | + echo aui()->alert( |
|
| 29 | + array( |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | 36 | |
| 37 | - // Display a single subscription. |
|
| 38 | - wpinv_recurring_subscription_details(); |
|
| 39 | - } else { |
|
| 37 | + // Display a single subscription. |
|
| 38 | + wpinv_recurring_subscription_details(); |
|
| 39 | + } else { |
|
| 40 | 40 | |
| 41 | - // Display a list of available subscriptions. |
|
| 42 | - getpaid_print_subscriptions_list(); |
|
| 43 | - } |
|
| 41 | + // Display a list of available subscriptions. |
|
| 42 | + getpaid_print_subscriptions_list(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - ?> |
|
| 45 | + ?> |
|
| 46 | 46 | |
| 47 | 47 | </div> |
| 48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function getpaid_print_subscriptions_list() { |
| 61 | 61 | |
| 62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | - $subscribers_table->prepare_items(); |
|
| 62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | + $subscribers_table->prepare_items(); |
|
| 64 | 64 | |
| 65 | - ?> |
|
| 65 | + ?> |
|
| 66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
| 67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,41 +80,41 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | - // Fetch the subscription. |
|
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->exists() ) { |
|
| 83 | + // Fetch the subscription. |
|
| 84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | + if ( ! $sub->exists() ) { |
|
| 86 | 86 | |
| 87 | - echo aui()->alert( |
|
| 88 | - array( |
|
| 89 | - 'type' => 'danger', |
|
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 87 | + echo aui()->alert( |
|
| 88 | + array( |
|
| 89 | + 'type' => 'danger', |
|
| 90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - return; |
|
| 95 | - } |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // Use metaboxes to display the subscription details. |
|
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 97 | + // Use metaboxes to display the subscription details. |
|
| 98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | 100 | |
| 101 | - $subscription_id = $sub->get_id(); |
|
| 102 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 103 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 101 | + $subscription_id = $sub->get_id(); |
|
| 102 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 103 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 104 | 104 | |
| 105 | - if ( 1 < count( $subscription_groups ) ) { |
|
| 106 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 107 | - } |
|
| 105 | + if ( 1 < count( $subscription_groups ) ) { |
|
| 106 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - if ( ! empty( $subscription_group ) ) { |
|
| 110 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 111 | - } |
|
| 109 | + if ( ! empty( $subscription_group ) ) { |
|
| 110 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 113 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 114 | 114 | |
| 115 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 115 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 116 | 116 | |
| 117 | - ?> |
|
| 117 | + ?> |
|
| 118 | 118 | |
| 119 | 119 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
| 120 | 120 | |
@@ -154,45 +154,45 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 156 | 156 | |
| 157 | - // Subscription items. |
|
| 158 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 159 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 160 | - |
|
| 161 | - // Prepare subscription detail columns. |
|
| 162 | - $fields = apply_filters( |
|
| 163 | - 'getpaid_subscription_admin_page_fields', |
|
| 164 | - array( |
|
| 165 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 166 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 167 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 168 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 169 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 170 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 171 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 172 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 173 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 174 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 175 | - ) |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - if ( ! $sub->is_active() ) { |
|
| 179 | - |
|
| 180 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 181 | - unset( $fields['renews_on'] ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ( isset( $fields['gateway'] ) ) { |
|
| 185 | - unset( $fields['gateway'] ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $profile_id = $sub->get_profile_id(); |
|
| 191 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 192 | - unset( $fields['profile_id'] ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - ?> |
|
| 157 | + // Subscription items. |
|
| 158 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 159 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 160 | + |
|
| 161 | + // Prepare subscription detail columns. |
|
| 162 | + $fields = apply_filters( |
|
| 163 | + 'getpaid_subscription_admin_page_fields', |
|
| 164 | + array( |
|
| 165 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 166 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 167 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 168 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 169 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 170 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 171 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 172 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 173 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 174 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 175 | + ) |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + if ( ! $sub->is_active() ) { |
|
| 179 | + |
|
| 180 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 181 | + unset( $fields['renews_on'] ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ( isset( $fields['gateway'] ) ) { |
|
| 185 | + unset( $fields['gateway'] ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $profile_id = $sub->get_profile_id(); |
|
| 191 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 192 | + unset( $fields['profile_id'] ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + ?> |
|
| 196 | 196 | |
| 197 | 197 | <table class="table table-borderless" style="font-size: 14px;"> |
| 198 | 198 | <tbody> |
@@ -226,20 +226,20 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 228 | 228 | |
| 229 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 229 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 230 | 230 | |
| 231 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 232 | - if ( $user ) { |
|
| 231 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 232 | + if ( $user ) { |
|
| 233 | 233 | |
| 234 | - $username = sprintf( |
|
| 235 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 236 | - absint( $user->ID ), |
|
| 237 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 238 | - ); |
|
| 234 | + $username = sprintf( |
|
| 235 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 236 | + absint( $user->ID ), |
|
| 237 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 238 | + ); |
|
| 239 | 239 | |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - echo $username; |
|
| 242 | + echo $username; |
|
| 243 | 243 | } |
| 244 | 244 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 245 | 245 | |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | * @param WPInv_Subscription $subscription |
| 250 | 250 | */ |
| 251 | 251 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 252 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 253 | - echo "<span>$amount</span>"; |
|
| 252 | + $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 253 | + echo "<span>$amount</span>"; |
|
| 254 | 254 | } |
| 255 | 255 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 256 | 256 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param WPInv_Subscription $subscription |
| 261 | 261 | */ |
| 262 | 262 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 263 | - echo '#' . absint( $subscription->get_id() ); |
|
| 263 | + echo '#' . absint( $subscription->get_id() ); |
|
| 264 | 264 | } |
| 265 | 265 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
| 266 | 266 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @param WPInv_Subscription $subscription |
| 271 | 271 | */ |
| 272 | 272 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 273 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 273 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 274 | 274 | } |
| 275 | 275 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
| 276 | 276 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param WPInv_Subscription $subscription |
| 281 | 281 | */ |
| 282 | 282 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 283 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 283 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 284 | 284 | } |
| 285 | 285 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 286 | 286 | |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param WPInv_Subscription $subscription |
| 291 | 291 | */ |
| 292 | 292 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 293 | - $max_bills = $subscription->get_bill_times(); |
|
| 294 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 293 | + $max_bills = $subscription->get_bill_times(); |
|
| 294 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 295 | 295 | } |
| 296 | 296 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 297 | 297 | /** |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
| 304 | 304 | |
| 305 | - if ( empty( $subscription_group ) ) { |
|
| 306 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
| 307 | - return; |
|
| 308 | - } |
|
| 305 | + if ( empty( $subscription_group ) ) { |
|
| 306 | + echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 311 | - echo implode( ' | ', $markup ); |
|
| 310 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 311 | + echo implode( ' | ', $markup ); |
|
| 312 | 312 | |
| 313 | 313 | } |
| 314 | 314 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -320,13 +320,13 @@ discard block |
||
| 320 | 320 | */ |
| 321 | 321 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 322 | 322 | |
| 323 | - $gateway = $subscription->get_gateway(); |
|
| 323 | + $gateway = $subscription->get_gateway(); |
|
| 324 | 324 | |
| 325 | - if ( ! empty( $gateway ) ) { |
|
| 326 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 327 | - } else { |
|
| 328 | - echo "—"; |
|
| 329 | - } |
|
| 325 | + if ( ! empty( $gateway ) ) { |
|
| 326 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 327 | + } else { |
|
| 328 | + echo "—"; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | 331 | } |
| 332 | 332 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @param WPInv_Subscription $subscription |
| 338 | 338 | */ |
| 339 | 339 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 340 | - echo $subscription->get_status_label_html(); |
|
| 340 | + echo $subscription->get_status_label_html(); |
|
| 341 | 341 | } |
| 342 | 342 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 343 | 343 | |
@@ -348,29 +348,29 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 350 | 350 | |
| 351 | - $profile_id = $subscription->get_profile_id(); |
|
| 352 | - |
|
| 353 | - $input = aui()->input( |
|
| 354 | - array( |
|
| 355 | - 'type' => 'text', |
|
| 356 | - 'id' => 'wpinv_subscription_profile_id', |
|
| 357 | - 'name' => 'wpinv_subscription_profile_id', |
|
| 358 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 359 | - 'label_type' => 'hidden', |
|
| 360 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 361 | - 'value' => sanitize_text_field( $profile_id ), |
|
| 362 | - 'input_group_right' => '', |
|
| 363 | - 'no_wrap' => true, |
|
| 364 | - ) |
|
| 365 | - ); |
|
| 366 | - |
|
| 367 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
| 368 | - |
|
| 369 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 370 | - if ( ! empty( $url ) ) { |
|
| 371 | - $url = esc_url_raw( $url ); |
|
| 372 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 373 | - } |
|
| 351 | + $profile_id = $subscription->get_profile_id(); |
|
| 352 | + |
|
| 353 | + $input = aui()->input( |
|
| 354 | + array( |
|
| 355 | + 'type' => 'text', |
|
| 356 | + 'id' => 'wpinv_subscription_profile_id', |
|
| 357 | + 'name' => 'wpinv_subscription_profile_id', |
|
| 358 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 359 | + 'label_type' => 'hidden', |
|
| 360 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 361 | + 'value' => sanitize_text_field( $profile_id ), |
|
| 362 | + 'input_group_right' => '', |
|
| 363 | + 'no_wrap' => true, |
|
| 364 | + ) |
|
| 365 | + ); |
|
| 366 | + |
|
| 367 | + echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
| 368 | + |
|
| 369 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 370 | + if ( ! empty( $url ) ) { |
|
| 371 | + $url = esc_url_raw( $url ); |
|
| 372 | + echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | 375 | } |
| 376 | 376 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -382,39 +382,39 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 384 | 384 | |
| 385 | - ?> |
|
| 385 | + ?> |
|
| 386 | 386 | <div class="mt-3"> |
| 387 | 387 | |
| 388 | 388 | <?php |
| 389 | - echo aui()->select( |
|
| 390 | - array( |
|
| 391 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 392 | - 'name' => 'subscription_status', |
|
| 393 | - 'id' => 'subscription_status_update_select', |
|
| 394 | - 'required' => true, |
|
| 395 | - 'no_wrap' => false, |
|
| 396 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 397 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 398 | - 'select2' => true, |
|
| 399 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 400 | - ) |
|
| 401 | - ); |
|
| 402 | - ?> |
|
| 389 | + echo aui()->select( |
|
| 390 | + array( |
|
| 391 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 392 | + 'name' => 'subscription_status', |
|
| 393 | + 'id' => 'subscription_status_update_select', |
|
| 394 | + 'required' => true, |
|
| 395 | + 'no_wrap' => false, |
|
| 396 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 397 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 398 | + 'select2' => true, |
|
| 399 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 400 | + ) |
|
| 401 | + ); |
|
| 402 | + ?> |
|
| 403 | 403 | |
| 404 | 404 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 405 | 405 | |
| 406 | 406 | <?php |
| 407 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 407 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 408 | 408 | |
| 409 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 410 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 411 | - $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' ); |
|
| 409 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 410 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 411 | + $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' ); |
|
| 412 | 412 | |
| 413 | - if ( $subscription->is_active() ) { |
|
| 414 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 415 | - } |
|
| 413 | + if ( $subscription->is_active() ) { |
|
| 414 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - echo '</div></div>'; |
|
| 417 | + echo '</div></div>'; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -425,33 +425,33 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
| 427 | 427 | |
| 428 | - $columns = apply_filters( |
|
| 429 | - 'getpaid_subscription_related_invoices_columns', |
|
| 430 | - array( |
|
| 431 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 432 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 433 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 434 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 435 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 436 | - ), |
|
| 437 | - $subscription |
|
| 438 | - ); |
|
| 439 | - |
|
| 440 | - // Prepare the invoices. |
|
| 441 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 442 | - $parent = $subscription->get_parent_invoice(); |
|
| 443 | - |
|
| 444 | - if ( $parent->exists() ) { |
|
| 445 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - $table_class = 'w-100 bg-white'; |
|
| 449 | - |
|
| 450 | - if ( ! is_admin() ) { |
|
| 451 | - $table_class = 'table table-bordered'; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - ?> |
|
| 428 | + $columns = apply_filters( |
|
| 429 | + 'getpaid_subscription_related_invoices_columns', |
|
| 430 | + array( |
|
| 431 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 432 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 433 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 434 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 435 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 436 | + ), |
|
| 437 | + $subscription |
|
| 438 | + ); |
|
| 439 | + |
|
| 440 | + // Prepare the invoices. |
|
| 441 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 442 | + $parent = $subscription->get_parent_invoice(); |
|
| 443 | + |
|
| 444 | + if ( $parent->exists() ) { |
|
| 445 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $table_class = 'w-100 bg-white'; |
|
| 449 | + |
|
| 450 | + if ( ! is_admin() ) { |
|
| 451 | + $table_class = 'table table-bordered'; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + ?> |
|
| 455 | 455 | <div class="m-0" style="overflow: auto;"> |
| 456 | 456 | |
| 457 | 457 | <table class="<?php echo $table_class; ?>"> |
@@ -459,14 +459,14 @@ discard block |
||
| 459 | 459 | <thead> |
| 460 | 460 | <tr> |
| 461 | 461 | <?php |
| 462 | - foreach ( $columns as $key => $label ) { |
|
| 463 | - $key = esc_attr( $key ); |
|
| 464 | - $label = sanitize_text_field( $label ); |
|
| 465 | - $class = 'text-left'; |
|
| 466 | - |
|
| 467 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 468 | - } |
|
| 469 | - ?> |
|
| 462 | + foreach ( $columns as $key => $label ) { |
|
| 463 | + $key = esc_attr( $key ); |
|
| 464 | + $label = sanitize_text_field( $label ); |
|
| 465 | + $class = 'text-left'; |
|
| 466 | + |
|
| 467 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 468 | + } |
|
| 469 | + ?> |
|
| 470 | 470 | </tr> |
| 471 | 471 | </thead> |
| 472 | 472 | |
@@ -482,73 +482,73 @@ discard block |
||
| 482 | 482 | |
| 483 | 483 | <?php |
| 484 | 484 | |
| 485 | - foreach( $payments as $payment ) : |
|
| 485 | + foreach( $payments as $payment ) : |
|
| 486 | 486 | |
| 487 | - // Ensure that we have an invoice. |
|
| 488 | - $payment = new WPInv_Invoice( $payment ); |
|
| 487 | + // Ensure that we have an invoice. |
|
| 488 | + $payment = new WPInv_Invoice( $payment ); |
|
| 489 | 489 | |
| 490 | - // Abort if the invoice is invalid... |
|
| 491 | - if ( ! $payment->exists() ) { |
|
| 492 | - continue; |
|
| 493 | - } |
|
| 490 | + // Abort if the invoice is invalid... |
|
| 491 | + if ( ! $payment->exists() ) { |
|
| 492 | + continue; |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - // ... or belongs to a different subscription. |
|
| 496 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 497 | - continue; |
|
| 498 | - } |
|
| 495 | + // ... or belongs to a different subscription. |
|
| 496 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 497 | + continue; |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | - echo '<tr>'; |
|
| 500 | + echo '<tr>'; |
|
| 501 | 501 | |
| 502 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 502 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 503 | 503 | |
| 504 | - $class = 'text-left'; |
|
| 504 | + $class = 'text-left'; |
|
| 505 | 505 | |
| 506 | - echo "<td class='p-2 $class'>"; |
|
| 506 | + echo "<td class='p-2 $class'>"; |
|
| 507 | 507 | |
| 508 | - switch( $key ) { |
|
| 508 | + switch( $key ) { |
|
| 509 | 509 | |
| 510 | - case 'total': |
|
| 511 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
| 512 | - break; |
|
| 510 | + case 'total': |
|
| 511 | + echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
| 512 | + break; |
|
| 513 | 513 | |
| 514 | - case 'relationship': |
|
| 515 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 516 | - break; |
|
| 514 | + case 'relationship': |
|
| 515 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 516 | + break; |
|
| 517 | 517 | |
| 518 | - case 'date': |
|
| 519 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 520 | - break; |
|
| 518 | + case 'date': |
|
| 519 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 520 | + break; |
|
| 521 | 521 | |
| 522 | - case 'status': |
|
| 522 | + case 'status': |
|
| 523 | 523 | |
| 524 | - $status = $payment->get_status_nicename(); |
|
| 525 | - if ( is_admin() ) { |
|
| 526 | - $status = $payment->get_status_label_html(); |
|
| 527 | - } |
|
| 524 | + $status = $payment->get_status_nicename(); |
|
| 525 | + if ( is_admin() ) { |
|
| 526 | + $status = $payment->get_status_label_html(); |
|
| 527 | + } |
|
| 528 | 528 | |
| 529 | - echo $status; |
|
| 530 | - break; |
|
| 529 | + echo $status; |
|
| 530 | + break; |
|
| 531 | 531 | |
| 532 | - case 'invoice': |
|
| 533 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 532 | + case 'invoice': |
|
| 533 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 534 | 534 | |
| 535 | - if ( ! is_admin() ) { |
|
| 536 | - $link = esc_url( $payment->get_view_url() ); |
|
| 537 | - } |
|
| 535 | + if ( ! is_admin() ) { |
|
| 536 | + $link = esc_url( $payment->get_view_url() ); |
|
| 537 | + } |
|
| 538 | 538 | |
| 539 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 540 | - echo "<a href='$link'>$invoice</a>"; |
|
| 541 | - break; |
|
| 542 | - } |
|
| 539 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 540 | + echo "<a href='$link'>$invoice</a>"; |
|
| 541 | + break; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - echo '</td>'; |
|
| 544 | + echo '</td>'; |
|
| 545 | 545 | |
| 546 | - } |
|
| 546 | + } |
|
| 547 | 547 | |
| 548 | - echo '</tr>'; |
|
| 548 | + echo '</tr>'; |
|
| 549 | 549 | |
| 550 | - endforeach; |
|
| 551 | - ?> |
|
| 550 | + endforeach; |
|
| 551 | + ?> |
|
| 552 | 552 | |
| 553 | 553 | </tbody> |
| 554 | 554 | |
@@ -566,42 +566,42 @@ discard block |
||
| 566 | 566 | */ |
| 567 | 567 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
| 568 | 568 | |
| 569 | - // Fetch the subscription group. |
|
| 570 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 569 | + // Fetch the subscription group. |
|
| 570 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 571 | 571 | |
| 572 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 573 | - return; |
|
| 574 | - } |
|
| 572 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 573 | + return; |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - // Prepare table columns. |
|
| 577 | - $columns = apply_filters( |
|
| 578 | - 'getpaid_subscription_item_details_columns', |
|
| 579 | - array( |
|
| 580 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
| 581 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 582 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 583 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 584 | - 'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 585 | - 'recurring' => __( 'Recurring Amount', 'invoicing' ), |
|
| 586 | - ), |
|
| 587 | - $subscription |
|
| 588 | - ); |
|
| 576 | + // Prepare table columns. |
|
| 577 | + $columns = apply_filters( |
|
| 578 | + 'getpaid_subscription_item_details_columns', |
|
| 579 | + array( |
|
| 580 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
| 581 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 582 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
| 583 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
| 584 | + 'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 585 | + 'recurring' => __( 'Recurring Amount', 'invoicing' ), |
|
| 586 | + ), |
|
| 587 | + $subscription |
|
| 588 | + ); |
|
| 589 | 589 | |
| 590 | - // Prepare the invoices. |
|
| 590 | + // Prepare the invoices. |
|
| 591 | 591 | |
| 592 | - $invoice = $subscription->get_parent_invoice(); |
|
| 592 | + $invoice = $subscription->get_parent_invoice(); |
|
| 593 | 593 | |
| 594 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 595 | - unset( $columns['tax'] ); |
|
| 596 | - } |
|
| 594 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 595 | + unset( $columns['tax'] ); |
|
| 596 | + } |
|
| 597 | 597 | |
| 598 | - $table_class = 'w-100 bg-white'; |
|
| 598 | + $table_class = 'w-100 bg-white'; |
|
| 599 | 599 | |
| 600 | - if ( ! is_admin() ) { |
|
| 601 | - $table_class = 'table table-bordered'; |
|
| 602 | - } |
|
| 600 | + if ( ! is_admin() ) { |
|
| 601 | + $table_class = 'table table-bordered'; |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - ?> |
|
| 604 | + ?> |
|
| 605 | 605 | <div class="m-0" style="overflow: auto;"> |
| 606 | 606 | |
| 607 | 607 | <table class="<?php echo $table_class; ?>"> |
@@ -610,14 +610,14 @@ discard block |
||
| 610 | 610 | <tr> |
| 611 | 611 | <?php |
| 612 | 612 | |
| 613 | - foreach ( $columns as $key => $label ) { |
|
| 614 | - $key = esc_attr( $key ); |
|
| 615 | - $label = sanitize_text_field( $label ); |
|
| 616 | - $class = 'text-left'; |
|
| 613 | + foreach ( $columns as $key => $label ) { |
|
| 614 | + $key = esc_attr( $key ); |
|
| 615 | + $label = sanitize_text_field( $label ); |
|
| 616 | + $class = 'text-left'; |
|
| 617 | 617 | |
| 618 | - echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 619 | - } |
|
| 620 | - ?> |
|
| 618 | + echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 619 | + } |
|
| 620 | + ?> |
|
| 621 | 621 | </tr> |
| 622 | 622 | </thead> |
| 623 | 623 | |
@@ -625,106 +625,106 @@ discard block |
||
| 625 | 625 | |
| 626 | 626 | <?php |
| 627 | 627 | |
| 628 | - foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
| 628 | + foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
| 629 | 629 | |
| 630 | - echo '<tr>'; |
|
| 630 | + echo '<tr>'; |
|
| 631 | 631 | |
| 632 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 632 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 633 | 633 | |
| 634 | - $class = 'text-left'; |
|
| 634 | + $class = 'text-left'; |
|
| 635 | 635 | |
| 636 | - echo "<td class='p-2 $class'>"; |
|
| 636 | + echo "<td class='p-2 $class'>"; |
|
| 637 | 637 | |
| 638 | - switch( $key ) { |
|
| 638 | + switch( $key ) { |
|
| 639 | 639 | |
| 640 | - case 'item_name': |
|
| 641 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 642 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 640 | + case 'item_name': |
|
| 641 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 642 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 643 | 643 | |
| 644 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 645 | - echo sanitize_text_field( $item_name ); |
|
| 646 | - } else { |
|
| 647 | - printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 648 | - } |
|
| 644 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 645 | + echo sanitize_text_field( $item_name ); |
|
| 646 | + } else { |
|
| 647 | + printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - break; |
|
| 650 | + break; |
|
| 651 | 651 | |
| 652 | - case 'price': |
|
| 653 | - echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() ); |
|
| 654 | - break; |
|
| 652 | + case 'price': |
|
| 653 | + echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() ); |
|
| 654 | + break; |
|
| 655 | 655 | |
| 656 | - case 'tax': |
|
| 657 | - echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 658 | - break; |
|
| 656 | + case 'tax': |
|
| 657 | + echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 658 | + break; |
|
| 659 | 659 | |
| 660 | - case 'discount': |
|
| 661 | - echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 662 | - break; |
|
| 660 | + case 'discount': |
|
| 661 | + echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 662 | + break; |
|
| 663 | 663 | |
| 664 | - case 'initial': |
|
| 665 | - echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() ); |
|
| 666 | - break; |
|
| 664 | + case 'initial': |
|
| 665 | + echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() ); |
|
| 666 | + break; |
|
| 667 | 667 | |
| 668 | - case 'recurring': |
|
| 669 | - echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
| 670 | - break; |
|
| 668 | + case 'recurring': |
|
| 669 | + echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
| 670 | + break; |
|
| 671 | 671 | |
| 672 | - } |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | - echo '</td>'; |
|
| 674 | + echo '</td>'; |
|
| 675 | 675 | |
| 676 | - } |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | - echo '</tr>'; |
|
| 678 | + echo '</tr>'; |
|
| 679 | 679 | |
| 680 | - endforeach; |
|
| 680 | + endforeach; |
|
| 681 | 681 | |
| 682 | - foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 682 | + foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 683 | 683 | |
| 684 | - echo '<tr>'; |
|
| 684 | + echo '<tr>'; |
|
| 685 | 685 | |
| 686 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 686 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 687 | 687 | |
| 688 | - $class = 'text-left'; |
|
| 688 | + $class = 'text-left'; |
|
| 689 | 689 | |
| 690 | - echo "<td class='p-2 $class'>"; |
|
| 690 | + echo "<td class='p-2 $class'>"; |
|
| 691 | 691 | |
| 692 | - switch( $key ) { |
|
| 692 | + switch( $key ) { |
|
| 693 | 693 | |
| 694 | - case 'item_name': |
|
| 695 | - echo sanitize_text_field( $subscription_group_fee['name'] ); |
|
| 696 | - break; |
|
| 694 | + case 'item_name': |
|
| 695 | + echo sanitize_text_field( $subscription_group_fee['name'] ); |
|
| 696 | + break; |
|
| 697 | 697 | |
| 698 | - case 'price': |
|
| 699 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 700 | - break; |
|
| 698 | + case 'price': |
|
| 699 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 700 | + break; |
|
| 701 | 701 | |
| 702 | - case 'tax': |
|
| 703 | - echo "—"; |
|
| 704 | - break; |
|
| 702 | + case 'tax': |
|
| 703 | + echo "—"; |
|
| 704 | + break; |
|
| 705 | 705 | |
| 706 | - case 'discount': |
|
| 707 | - echo "—"; |
|
| 708 | - break; |
|
| 706 | + case 'discount': |
|
| 707 | + echo "—"; |
|
| 708 | + break; |
|
| 709 | 709 | |
| 710 | - case 'initial': |
|
| 711 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 712 | - break; |
|
| 710 | + case 'initial': |
|
| 711 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 712 | + break; |
|
| 713 | 713 | |
| 714 | - case 'recurring': |
|
| 715 | - echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
| 716 | - break; |
|
| 714 | + case 'recurring': |
|
| 715 | + echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
| 716 | + break; |
|
| 717 | 717 | |
| 718 | - } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | - echo '</td>'; |
|
| 720 | + echo '</td>'; |
|
| 721 | 721 | |
| 722 | - } |
|
| 722 | + } |
|
| 723 | 723 | |
| 724 | - echo '</tr>'; |
|
| 724 | + echo '</tr>'; |
|
| 725 | 725 | |
| 726 | - endforeach; |
|
| 727 | - ?> |
|
| 726 | + endforeach; |
|
| 727 | + ?> |
|
| 728 | 728 | |
| 729 | 729 | </tbody> |
| 730 | 730 | |
@@ -743,38 +743,38 @@ discard block |
||
| 743 | 743 | */ |
| 744 | 744 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
| 745 | 745 | |
| 746 | - // Fetch the subscription groups. |
|
| 747 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 748 | - |
|
| 749 | - if ( empty( $subscription_groups ) ) { |
|
| 750 | - return; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - // Prepare table columns. |
|
| 754 | - $columns = apply_filters( |
|
| 755 | - 'getpaid_subscription_related_subscriptions_columns', |
|
| 756 | - array( |
|
| 757 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 758 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 759 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 760 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 761 | - 'item' => __( 'Items', 'invoicing' ), |
|
| 762 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 763 | - ), |
|
| 764 | - $subscription |
|
| 765 | - ); |
|
| 766 | - |
|
| 767 | - if ( $subscription->get_status() == 'pending' ) { |
|
| 768 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - $table_class = 'w-100 bg-white'; |
|
| 772 | - |
|
| 773 | - if ( ! is_admin() ) { |
|
| 774 | - $table_class = 'table table-bordered'; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - ?> |
|
| 746 | + // Fetch the subscription groups. |
|
| 747 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 748 | + |
|
| 749 | + if ( empty( $subscription_groups ) ) { |
|
| 750 | + return; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + // Prepare table columns. |
|
| 754 | + $columns = apply_filters( |
|
| 755 | + 'getpaid_subscription_related_subscriptions_columns', |
|
| 756 | + array( |
|
| 757 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 758 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 759 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 760 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 761 | + 'item' => __( 'Items', 'invoicing' ), |
|
| 762 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 763 | + ), |
|
| 764 | + $subscription |
|
| 765 | + ); |
|
| 766 | + |
|
| 767 | + if ( $subscription->get_status() == 'pending' ) { |
|
| 768 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + $table_class = 'w-100 bg-white'; |
|
| 772 | + |
|
| 773 | + if ( ! is_admin() ) { |
|
| 774 | + $table_class = 'table table-bordered'; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + ?> |
|
| 778 | 778 | <div class="m-0" style="overflow: auto;"> |
| 779 | 779 | |
| 780 | 780 | <table class="<?php echo $table_class; ?>"> |
@@ -783,14 +783,14 @@ discard block |
||
| 783 | 783 | <tr> |
| 784 | 784 | <?php |
| 785 | 785 | |
| 786 | - foreach ( $columns as $key => $label ) { |
|
| 787 | - $key = esc_attr( $key ); |
|
| 788 | - $label = sanitize_text_field( $label ); |
|
| 789 | - $class = 'text-left'; |
|
| 786 | + foreach ( $columns as $key => $label ) { |
|
| 787 | + $key = esc_attr( $key ); |
|
| 788 | + $label = sanitize_text_field( $label ); |
|
| 789 | + $class = 'text-left'; |
|
| 790 | 790 | |
| 791 | - echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 792 | - } |
|
| 793 | - ?> |
|
| 791 | + echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 792 | + } |
|
| 793 | + ?> |
|
| 794 | 794 | </tr> |
| 795 | 795 | </thead> |
| 796 | 796 | |
@@ -798,74 +798,74 @@ discard block |
||
| 798 | 798 | |
| 799 | 799 | <?php |
| 800 | 800 | |
| 801 | - foreach( $subscription_groups as $subscription_group ) : |
|
| 801 | + foreach( $subscription_groups as $subscription_group ) : |
|
| 802 | 802 | |
| 803 | - // Do not list current subscription. |
|
| 804 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 805 | - continue; |
|
| 806 | - } |
|
| 803 | + // Do not list current subscription. |
|
| 804 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 805 | + continue; |
|
| 806 | + } |
|
| 807 | 807 | |
| 808 | - // Ensure the subscription exists. |
|
| 809 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 808 | + // Ensure the subscription exists. |
|
| 809 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 810 | 810 | |
| 811 | - if ( ! $_suscription->exists() ) { |
|
| 812 | - continue; |
|
| 813 | - } |
|
| 811 | + if ( ! $_suscription->exists() ) { |
|
| 812 | + continue; |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | - echo '<tr>'; |
|
| 815 | + echo '<tr>'; |
|
| 816 | 816 | |
| 817 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 817 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 818 | 818 | |
| 819 | - $class = 'text-left'; |
|
| 819 | + $class = 'text-left'; |
|
| 820 | 820 | |
| 821 | - echo "<td class='p-2 $class'>"; |
|
| 821 | + echo "<td class='p-2 $class'>"; |
|
| 822 | 822 | |
| 823 | - switch( $key ) { |
|
| 823 | + switch( $key ) { |
|
| 824 | 824 | |
| 825 | - case 'status': |
|
| 826 | - echo $_suscription->get_status_label_html(); |
|
| 827 | - break; |
|
| 825 | + case 'status': |
|
| 826 | + echo $_suscription->get_status_label_html(); |
|
| 827 | + break; |
|
| 828 | 828 | |
| 829 | - case 'item': |
|
| 830 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 831 | - echo implode( ' | ', $markup ); |
|
| 832 | - break; |
|
| 829 | + case 'item': |
|
| 830 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 831 | + echo implode( ' | ', $markup ); |
|
| 832 | + break; |
|
| 833 | 833 | |
| 834 | - case 'renewals': |
|
| 835 | - $max_bills = $_suscription->get_bill_times(); |
|
| 836 | - echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 837 | - break; |
|
| 834 | + case 'renewals': |
|
| 835 | + $max_bills = $_suscription->get_bill_times(); |
|
| 836 | + echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 837 | + break; |
|
| 838 | 838 | |
| 839 | - case 'renewal_date': |
|
| 840 | - echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
| 841 | - break; |
|
| 839 | + case 'renewal_date': |
|
| 840 | + echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
| 841 | + break; |
|
| 842 | 842 | |
| 843 | - case 'start_date': |
|
| 844 | - echo 'pending' == $_suscription->get_status() ? "—" : getpaid_format_date_value( $_suscription->get_date_created() ); |
|
| 845 | - break; |
|
| 843 | + case 'start_date': |
|
| 844 | + echo 'pending' == $_suscription->get_status() ? "—" : getpaid_format_date_value( $_suscription->get_date_created() ); |
|
| 845 | + break; |
|
| 846 | 846 | |
| 847 | - case 'subscription': |
|
| 848 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 849 | - printf( |
|
| 850 | - '%1$s#%2$s%3$s', |
|
| 851 | - '<a href="' . esc_url( $url ) . '">', |
|
| 852 | - '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
| 853 | - '</a>' |
|
| 854 | - ); |
|
| 847 | + case 'subscription': |
|
| 848 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 849 | + printf( |
|
| 850 | + '%1$s#%2$s%3$s', |
|
| 851 | + '<a href="' . esc_url( $url ) . '">', |
|
| 852 | + '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
| 853 | + '</a>' |
|
| 854 | + ); |
|
| 855 | 855 | |
| 856 | - echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
| 857 | - break; |
|
| 856 | + echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
| 857 | + break; |
|
| 858 | 858 | |
| 859 | - } |
|
| 859 | + } |
|
| 860 | 860 | |
| 861 | - echo '</td>'; |
|
| 861 | + echo '</td>'; |
|
| 862 | 862 | |
| 863 | - } |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - echo '</tr>'; |
|
| 865 | + echo '</tr>'; |
|
| 866 | 866 | |
| 867 | - endforeach; |
|
| 868 | - ?> |
|
| 867 | + endforeach; |
|
| 868 | + ?> |
|
| 869 | 869 | |
| 870 | 870 | </tbody> |
| 871 | 871 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
| 52 | 52 | $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
| 53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 53 | + $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 54 | 54 | return reset( $matching_group ); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @return WPInv_Subscription|false |
| 63 | 63 | */ |
| 64 | 64 | function getpaid_get_subscription( $subscription ) { |
| 65 | - $subscription = new WPInv_Subscription( $subscription ); |
|
| 66 | - return $subscription->exists() ? $subscription : false; |
|
| 65 | + $subscription = new WPInv_Subscription( $subscription ); |
|
| 66 | + return $subscription->exists() ? $subscription : false; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -77,28 +77,28 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
| 79 | 79 | |
| 80 | - // Do not retrieve all fields if we just want the count. |
|
| 81 | - if ( 'count' == $return ) { |
|
| 82 | - $args['fields'] = 'id'; |
|
| 83 | - $args['number'] = 1; |
|
| 84 | - } |
|
| 80 | + // Do not retrieve all fields if we just want the count. |
|
| 81 | + if ( 'count' == $return ) { |
|
| 82 | + $args['fields'] = 'id'; |
|
| 83 | + $args['number'] = 1; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // Do not count all matches if we just want the results. |
|
| 87 | - if ( 'results' == $return ) { |
|
| 88 | - $args['count_total'] = false; |
|
| 89 | - } |
|
| 86 | + // Do not count all matches if we just want the results. |
|
| 87 | + if ( 'results' == $return ) { |
|
| 88 | + $args['count_total'] = false; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 91 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 92 | 92 | |
| 93 | - if ( 'results' == $return ) { |
|
| 94 | - return $query->get_results(); |
|
| 95 | - } |
|
| 93 | + if ( 'results' == $return ) { |
|
| 94 | + return $query->get_results(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - if ( 'count' == $return ) { |
|
| 98 | - return $query->get_total(); |
|
| 99 | - } |
|
| 97 | + if ( 'count' == $return ) { |
|
| 98 | + return $query->get_total(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return $query; |
|
| 101 | + return $query; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | function getpaid_get_subscription_statuses() { |
| 110 | 110 | |
| 111 | - return apply_filters( |
|
| 112 | - 'getpaid_get_subscription_statuses', |
|
| 113 | - array( |
|
| 114 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 115 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 116 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 117 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 118 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 119 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 120 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 121 | - ) |
|
| 122 | - ); |
|
| 111 | + return apply_filters( |
|
| 112 | + 'getpaid_get_subscription_statuses', |
|
| 113 | + array( |
|
| 114 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
| 115 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 116 | + 'active' => __( 'Active', 'invoicing' ), |
|
| 117 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
| 118 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
| 119 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
| 120 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 121 | + ) |
|
| 122 | + ); |
|
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | 131 | function getpaid_get_subscription_status_label( $status ) { |
| 132 | - $statuses = getpaid_get_subscription_statuses(); |
|
| 133 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 132 | + $statuses = getpaid_get_subscription_statuses(); |
|
| 133 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -140,18 +140,18 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function getpaid_get_subscription_status_classes() { |
| 142 | 142 | |
| 143 | - return apply_filters( |
|
| 144 | - 'getpaid_get_subscription_status_classes', |
|
| 145 | - array( |
|
| 146 | - 'pending' => 'badge-dark', |
|
| 147 | - 'trialling' => 'badge-info', |
|
| 148 | - 'active' => 'badge-success', |
|
| 149 | - 'failing' => 'badge-warning', |
|
| 150 | - 'expired' => 'badge-danger', |
|
| 151 | - 'completed' => 'badge-primary', |
|
| 152 | - 'cancelled' => 'badge-secondary', |
|
| 153 | - ) |
|
| 154 | - ); |
|
| 143 | + return apply_filters( |
|
| 144 | + 'getpaid_get_subscription_status_classes', |
|
| 145 | + array( |
|
| 146 | + 'pending' => 'badge-dark', |
|
| 147 | + 'trialling' => 'badge-info', |
|
| 148 | + 'active' => 'badge-success', |
|
| 149 | + 'failing' => 'badge-warning', |
|
| 150 | + 'expired' => 'badge-danger', |
|
| 151 | + 'completed' => 'badge-primary', |
|
| 152 | + 'cancelled' => 'badge-secondary', |
|
| 153 | + ) |
|
| 154 | + ); |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | function getpaid_get_subscription_status_counts( $args = array() ) { |
| 164 | 164 | |
| 165 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 166 | - $counts = array(); |
|
| 165 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 166 | + $counts = array(); |
|
| 167 | 167 | |
| 168 | - foreach ( $statuses as $status ) { |
|
| 169 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 170 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 171 | - } |
|
| 168 | + foreach ( $statuses as $status ) { |
|
| 169 | + $_args = wp_parse_args( "status=$status", $args ); |
|
| 170 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - return $counts; |
|
| 173 | + return $counts; |
|
| 174 | 174 | |
| 175 | 175 | } |
| 176 | 176 | |
@@ -181,32 +181,32 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | function getpaid_get_subscription_periods() { |
| 183 | 183 | |
| 184 | - return apply_filters( |
|
| 185 | - 'getpaid_get_subscription_periods', |
|
| 186 | - array( |
|
| 184 | + return apply_filters( |
|
| 185 | + 'getpaid_get_subscription_periods', |
|
| 186 | + array( |
|
| 187 | 187 | |
| 188 | - 'day' => array( |
|
| 189 | - 'singular' => __( '%s day', 'invoicing' ), |
|
| 190 | - 'plural' => __( '%d days', 'invoicing' ), |
|
| 191 | - ), |
|
| 188 | + 'day' => array( |
|
| 189 | + 'singular' => __( '%s day', 'invoicing' ), |
|
| 190 | + 'plural' => __( '%d days', 'invoicing' ), |
|
| 191 | + ), |
|
| 192 | 192 | |
| 193 | - 'week' => array( |
|
| 194 | - 'singular' => __( '%s week', 'invoicing' ), |
|
| 195 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 196 | - ), |
|
| 193 | + 'week' => array( |
|
| 194 | + 'singular' => __( '%s week', 'invoicing' ), |
|
| 195 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 196 | + ), |
|
| 197 | 197 | |
| 198 | - 'month' => array( |
|
| 199 | - 'singular' => __( '%s month', 'invoicing' ), |
|
| 200 | - 'plural' => __( '%d months', 'invoicing' ), |
|
| 201 | - ), |
|
| 198 | + 'month' => array( |
|
| 199 | + 'singular' => __( '%s month', 'invoicing' ), |
|
| 200 | + 'plural' => __( '%d months', 'invoicing' ), |
|
| 201 | + ), |
|
| 202 | 202 | |
| 203 | - 'year' => array( |
|
| 204 | - 'singular' => __( '%s year', 'invoicing' ), |
|
| 205 | - 'plural' => __( '%d years', 'invoicing' ), |
|
| 206 | - ), |
|
| 203 | + 'year' => array( |
|
| 204 | + 'singular' => __( '%s year', 'invoicing' ), |
|
| 205 | + 'plural' => __( '%d years', 'invoicing' ), |
|
| 206 | + ), |
|
| 207 | 207 | |
| 208 | - ) |
|
| 209 | - ); |
|
| 208 | + ) |
|
| 209 | + ); |
|
| 210 | 210 | |
| 211 | 211 | } |
| 212 | 212 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return int |
| 218 | 218 | */ |
| 219 | 219 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
| 220 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 220 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
| 230 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 230 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
| 241 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 242 | - return strtolower( sanitize_text_field( $label ) ); |
|
| 241 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 242 | + return strtolower( sanitize_text_field( $label ) ); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -250,22 +250,22 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
| 252 | 252 | |
| 253 | - $periods = getpaid_get_subscription_periods(); |
|
| 254 | - $period = strtolower( $period ); |
|
| 253 | + $periods = getpaid_get_subscription_periods(); |
|
| 254 | + $period = strtolower( $period ); |
|
| 255 | 255 | |
| 256 | - if ( isset( $periods[ $period ] ) ) { |
|
| 257 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 258 | - } |
|
| 256 | + if ( isset( $periods[ $period ] ) ) { |
|
| 257 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // Backwards compatibility. |
|
| 261 | - foreach ( $periods as $key => $data ) { |
|
| 262 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 263 | - return sprintf( $data['singular'], $singular_prefix ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 260 | + // Backwards compatibility. |
|
| 261 | + foreach ( $periods as $key => $data ) { |
|
| 262 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 263 | + return sprintf( $data['singular'], $singular_prefix ); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // Invalid string. |
|
| 268 | - return ''; |
|
| 267 | + // Invalid string. |
|
| 268 | + return ''; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -277,22 +277,22 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
| 279 | 279 | |
| 280 | - $periods = getpaid_get_subscription_periods(); |
|
| 281 | - $period = strtolower( $period ); |
|
| 280 | + $periods = getpaid_get_subscription_periods(); |
|
| 281 | + $period = strtolower( $period ); |
|
| 282 | 282 | |
| 283 | - if ( isset( $periods[ $period ] ) ) { |
|
| 284 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 285 | - } |
|
| 283 | + if ( isset( $periods[ $period ] ) ) { |
|
| 284 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - // Backwards compatibility. |
|
| 288 | - foreach ( $periods as $key => $data ) { |
|
| 289 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 290 | - return sprintf( $data['plural'], $interval ); |
|
| 291 | - } |
|
| 292 | - } |
|
| 287 | + // Backwards compatibility. |
|
| 288 | + foreach ( $periods as $key => $data ) { |
|
| 289 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 290 | + return sprintf( $data['plural'], $interval ); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - // Invalid string. |
|
| 295 | - return ''; |
|
| 294 | + // Invalid string. |
|
| 295 | + return ''; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -303,101 +303,101 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
| 305 | 305 | |
| 306 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 307 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 308 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 309 | - $bill_times = $subscription->get_bill_times(); |
|
| 306 | + $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 307 | + $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 308 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 309 | + $bill_times = $subscription->get_bill_times(); |
|
| 310 | 310 | |
| 311 | - if ( ! empty( $bill_times ) ) { |
|
| 312 | - $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 313 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 314 | - } |
|
| 311 | + if ( ! empty( $bill_times ) ) { |
|
| 312 | + $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 313 | + $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - // Trial periods. |
|
| 317 | - if ( $subscription->has_trial_period() ) { |
|
| 316 | + // Trial periods. |
|
| 317 | + if ( $subscription->has_trial_period() ) { |
|
| 318 | 318 | |
| 319 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 320 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 319 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 320 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 321 | 321 | |
| 322 | - if ( empty( $bill_times ) ) { |
|
| 322 | + if ( empty( $bill_times ) ) { |
|
| 323 | 323 | |
| 324 | - return sprintf( |
|
| 324 | + return sprintf( |
|
| 325 | 325 | |
| 326 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 327 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 328 | - $initial, |
|
| 329 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 330 | - $recurring, |
|
| 331 | - $period |
|
| 326 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 327 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 328 | + $initial, |
|
| 329 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 330 | + $recurring, |
|
| 331 | + $period |
|
| 332 | 332 | |
| 333 | - ); |
|
| 333 | + ); |
|
| 334 | 334 | |
| 335 | - } |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - return sprintf( |
|
| 337 | + return sprintf( |
|
| 338 | 338 | |
| 339 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 340 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 341 | - $initial, |
|
| 342 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 343 | - $recurring, |
|
| 344 | - $period, |
|
| 345 | - $bill_times |
|
| 346 | - ); |
|
| 339 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 340 | + _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 341 | + $initial, |
|
| 342 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 343 | + $recurring, |
|
| 344 | + $period, |
|
| 345 | + $bill_times |
|
| 346 | + ); |
|
| 347 | 347 | |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - if ( $initial != $recurring ) { |
|
| 350 | + if ( $initial != $recurring ) { |
|
| 351 | 351 | |
| 352 | - if ( empty( $bill_times ) ) { |
|
| 352 | + if ( empty( $bill_times ) ) { |
|
| 353 | 353 | |
| 354 | - return sprintf( |
|
| 354 | + return sprintf( |
|
| 355 | 355 | |
| 356 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 357 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 358 | - $initial, |
|
| 359 | - $recurring, |
|
| 360 | - $period |
|
| 356 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 357 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 358 | + $initial, |
|
| 359 | + $recurring, |
|
| 360 | + $period |
|
| 361 | 361 | |
| 362 | - ); |
|
| 362 | + ); |
|
| 363 | 363 | |
| 364 | - } |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - return sprintf( |
|
| 366 | + return sprintf( |
|
| 367 | 367 | |
| 368 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 370 | - $initial, |
|
| 371 | - $recurring, |
|
| 372 | - $period, |
|
| 373 | - $bill_times |
|
| 368 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 369 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 370 | + $initial, |
|
| 371 | + $recurring, |
|
| 372 | + $period, |
|
| 373 | + $bill_times |
|
| 374 | 374 | |
| 375 | - ); |
|
| 375 | + ); |
|
| 376 | 376 | |
| 377 | - } |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - if ( empty( $bill_times ) ) { |
|
| 379 | + if ( empty( $bill_times ) ) { |
|
| 380 | 380 | |
| 381 | - return sprintf( |
|
| 381 | + return sprintf( |
|
| 382 | 382 | |
| 383 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 384 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 385 | - $initial, |
|
| 386 | - $period |
|
| 383 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 384 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 385 | + $initial, |
|
| 386 | + $period |
|
| 387 | 387 | |
| 388 | - ); |
|
| 388 | + ); |
|
| 389 | 389 | |
| 390 | - } |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - return sprintf( |
|
| 392 | + return sprintf( |
|
| 393 | 393 | |
| 394 | - // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 395 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 396 | - $bill_times, |
|
| 397 | - $initial, |
|
| 398 | - $period |
|
| 394 | + // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 395 | + _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 396 | + $bill_times, |
|
| 397 | + $initial, |
|
| 398 | + $period |
|
| 399 | 399 | |
| 400 | - ); |
|
| 400 | + ); |
|
| 401 | 401 | |
| 402 | 402 | } |
| 403 | 403 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * @return WPInv_Subscription|false |
| 409 | 409 | */ |
| 410 | 410 | function getpaid_get_invoice_subscription( $invoice ) { |
| 411 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 411 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | * @param WPInv_Invoice $invoice |
| 418 | 418 | */ |
| 419 | 419 | function getpaid_activate_invoice_subscription( $invoice ) { |
| 420 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 421 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 422 | - $subscription->activate(); |
|
| 423 | - } |
|
| 420 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 421 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 422 | + $subscription->activate(); |
|
| 423 | + } |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | * @return WPInv_Subscriptions |
| 430 | 430 | */ |
| 431 | 431 | function getpaid_subscriptions() { |
| 432 | - return getpaid()->get( 'subscriptions' ); |
|
| 432 | + return getpaid()->get( 'subscriptions' ); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
@@ -448,15 +448,15 @@ discard block |
||
| 448 | 448 | return false; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - // Fetch the invoice subscription. |
|
| 452 | - $subscription = getpaid_get_subscriptions( |
|
| 453 | - array( |
|
| 454 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 455 | - 'number' => 1, |
|
| 456 | - ) |
|
| 457 | - ); |
|
| 451 | + // Fetch the invoice subscription. |
|
| 452 | + $subscription = getpaid_get_subscriptions( |
|
| 453 | + array( |
|
| 454 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 455 | + 'number' => 1, |
|
| 456 | + ) |
|
| 457 | + ); |
|
| 458 | 458 | |
| 459 | - return empty( $subscription ) ? false : $subscription[0]; |
|
| 459 | + return empty( $subscription ) ? false : $subscription[0]; |
|
| 460 | 460 | |
| 461 | 461 | } |
| 462 | 462 | |
@@ -473,48 +473,48 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | function getpaid_get_recurring_item_key( $cart_item ) { |
| 475 | 475 | |
| 476 | - $cart_key = 'renews_'; |
|
| 477 | - $interval = $cart_item->get_recurring_interval(); |
|
| 478 | - $period = $cart_item->get_recurring_period( true ); |
|
| 479 | - $length = $cart_item->get_recurring_limit() * $interval; |
|
| 480 | - $trial_period = $cart_item->get_trial_period( true ); |
|
| 481 | - $trial_length = $cart_item->get_trial_interval(); |
|
| 482 | - |
|
| 483 | - // First start with the billing interval and period |
|
| 484 | - switch ( $interval ) { |
|
| 485 | - case 1 : |
|
| 486 | - if ( 'day' == $period ) { |
|
| 487 | - $cart_key .= 'daily'; |
|
| 488 | - } else { |
|
| 489 | - $cart_key .= sprintf( '%sly', $period ); |
|
| 490 | - } |
|
| 491 | - break; |
|
| 492 | - case 2 : |
|
| 493 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 494 | - break; |
|
| 495 | - case 3 : |
|
| 496 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 497 | - break; |
|
| 498 | - default: |
|
| 499 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 500 | - break; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - // Maybe add the optional maximum billing periods... |
|
| 504 | - if ( $length > 0 ) { |
|
| 505 | - $cart_key .= '_for_'; |
|
| 506 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 507 | - if ( $length > 1 ) { |
|
| 508 | - $cart_key .= 's'; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - // And an optional free trial. |
|
| 513 | - if ( $cart_item->has_free_trial() ) { |
|
| 514 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 476 | + $cart_key = 'renews_'; |
|
| 477 | + $interval = $cart_item->get_recurring_interval(); |
|
| 478 | + $period = $cart_item->get_recurring_period( true ); |
|
| 479 | + $length = $cart_item->get_recurring_limit() * $interval; |
|
| 480 | + $trial_period = $cart_item->get_trial_period( true ); |
|
| 481 | + $trial_length = $cart_item->get_trial_interval(); |
|
| 482 | + |
|
| 483 | + // First start with the billing interval and period |
|
| 484 | + switch ( $interval ) { |
|
| 485 | + case 1 : |
|
| 486 | + if ( 'day' == $period ) { |
|
| 487 | + $cart_key .= 'daily'; |
|
| 488 | + } else { |
|
| 489 | + $cart_key .= sprintf( '%sly', $period ); |
|
| 490 | + } |
|
| 491 | + break; |
|
| 492 | + case 2 : |
|
| 493 | + $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 494 | + break; |
|
| 495 | + case 3 : |
|
| 496 | + $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 497 | + break; |
|
| 498 | + default: |
|
| 499 | + $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 500 | + break; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + // Maybe add the optional maximum billing periods... |
|
| 504 | + if ( $length > 0 ) { |
|
| 505 | + $cart_key .= '_for_'; |
|
| 506 | + $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 507 | + if ( $length > 1 ) { |
|
| 508 | + $cart_key .= 's'; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + // And an optional free trial. |
|
| 513 | + if ( $cart_item->has_free_trial() ) { |
|
| 514 | + $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -525,17 +525,17 @@ discard block |
||
| 525 | 525 | */ |
| 526 | 526 | function getpaid_get_subscription_groups( $invoice ) { |
| 527 | 527 | |
| 528 | - // Generate subscription groups. |
|
| 529 | - $subscription_groups = array(); |
|
| 530 | - foreach ( $invoice->get_items() as $item ) { |
|
| 528 | + // Generate subscription groups. |
|
| 529 | + $subscription_groups = array(); |
|
| 530 | + foreach ( $invoice->get_items() as $item ) { |
|
| 531 | 531 | |
| 532 | - if ( $item->is_recurring() ) { |
|
| 533 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 534 | - } |
|
| 532 | + if ( $item->is_recurring() ) { |
|
| 533 | + $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | - } |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - return $subscription_groups; |
|
| 538 | + return $subscription_groups; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -549,57 +549,57 @@ discard block |
||
| 549 | 549 | */ |
| 550 | 550 | function getpaid_calculate_subscription_totals( $invoice ) { |
| 551 | 551 | |
| 552 | - // Generate subscription groups. |
|
| 553 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 552 | + // Generate subscription groups. |
|
| 553 | + $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 554 | 554 | |
| 555 | - // Now let's calculate the totals for each group of subscriptions |
|
| 556 | - $subscription_totals = array(); |
|
| 555 | + // Now let's calculate the totals for each group of subscriptions |
|
| 556 | + $subscription_totals = array(); |
|
| 557 | 557 | |
| 558 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 558 | + foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 559 | 559 | |
| 560 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 560 | + if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 561 | 561 | |
| 562 | - $subscription_totals[ $subscription_key ] = array( |
|
| 563 | - 'initial_total' => 0, |
|
| 564 | - 'recurring_total' => 0, |
|
| 565 | - 'items' => array(), |
|
| 566 | - 'trialling' => false, |
|
| 567 | - ); |
|
| 562 | + $subscription_totals[ $subscription_key ] = array( |
|
| 563 | + 'initial_total' => 0, |
|
| 564 | + 'recurring_total' => 0, |
|
| 565 | + 'items' => array(), |
|
| 566 | + 'trialling' => false, |
|
| 567 | + ); |
|
| 568 | 568 | |
| 569 | - } |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - /** |
|
| 572 | - * Get the totals of the group. |
|
| 573 | - * @var GetPaid_Form_Item $item |
|
| 574 | - */ |
|
| 575 | - foreach ( $items as $item ) { |
|
| 571 | + /** |
|
| 572 | + * Get the totals of the group. |
|
| 573 | + * @var GetPaid_Form_Item $item |
|
| 574 | + */ |
|
| 575 | + foreach ( $items as $item ) { |
|
| 576 | 576 | |
| 577 | - $subscription_totals[ $subscription_key ]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
| 578 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 579 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 580 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 581 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total(); |
|
| 582 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total(); |
|
| 583 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 577 | + $subscription_totals[ $subscription_key ]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
| 578 | + $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 579 | + $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 580 | + $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 581 | + $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total(); |
|
| 582 | + $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total(); |
|
| 583 | + $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 584 | 584 | |
| 585 | - // Calculate the next renewal date. |
|
| 586 | - $period = $item->get_recurring_period( true ); |
|
| 587 | - $interval = $item->get_recurring_interval(); |
|
| 585 | + // Calculate the next renewal date. |
|
| 586 | + $period = $item->get_recurring_period( true ); |
|
| 587 | + $interval = $item->get_recurring_interval(); |
|
| 588 | 588 | |
| 589 | - // If the subscription item has a trial period... |
|
| 590 | - if ( $item->has_free_trial() ) { |
|
| 591 | - $period = $item->get_trial_period( true ); |
|
| 592 | - $interval = $item->get_trial_interval(); |
|
| 593 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 594 | - } |
|
| 589 | + // If the subscription item has a trial period... |
|
| 590 | + if ( $item->has_free_trial() ) { |
|
| 591 | + $period = $item->get_trial_period( true ); |
|
| 592 | + $interval = $item->get_trial_interval(); |
|
| 593 | + $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 596 | + $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 597 | 597 | |
| 598 | - } |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - } |
|
| 600 | + } |
|
| 601 | 601 | |
| 602 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 602 | + return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -610,15 +610,15 @@ discard block |
||
| 610 | 610 | */ |
| 611 | 611 | function getpaid_should_group_subscriptions( $invoice ) { |
| 612 | 612 | |
| 613 | - $recurring_items = 0; |
|
| 613 | + $recurring_items = 0; |
|
| 614 | 614 | |
| 615 | - foreach ( $invoice->get_items() as $item ) { |
|
| 615 | + foreach ( $invoice->get_items() as $item ) { |
|
| 616 | 616 | |
| 617 | - if ( $item->is_recurring() ) { |
|
| 618 | - $recurring_items ++; |
|
| 619 | - } |
|
| 617 | + if ( $item->is_recurring() ) { |
|
| 618 | + $recurring_items ++; |
|
| 619 | + } |
|
| 620 | 620 | |
| 621 | - } |
|
| 621 | + } |
|
| 622 | 622 | |
| 623 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 623 | + return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 624 | 624 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
| 10 | 10 | class WPInv_Item extends GetPaid_Data { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Which data store to load. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 13 | + * Which data store to load. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | 17 | protected $data_store_name = 'item'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'item'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'item'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'parent_id' => 0, |
|
| 34 | - 'status' => 'draft', |
|
| 35 | - 'version' => '', |
|
| 36 | - 'date_created' => null, |
|
| 27 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'parent_id' => 0, |
|
| 34 | + 'status' => 'draft', |
|
| 35 | + 'version' => '', |
|
| 36 | + 'date_created' => null, |
|
| 37 | 37 | 'date_modified' => null, |
| 38 | 38 | 'name' => '', |
| 39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * Stores meta in cache for future reads. |
|
| 62 | - * |
|
| 63 | - * A group must be set to to enable caching. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - protected $cache_group = 'getpaid_items'; |
|
| 61 | + * Stores meta in cache for future reads. |
|
| 62 | + * |
|
| 63 | + * A group must be set to to enable caching. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + protected $cache_group = 'getpaid_items'; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
| 74 | 74 | protected $post = null; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | - * |
|
| 79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | - */ |
|
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 94 | - } else { |
|
| 95 | - $this->set_object_read( true ); |
|
| 96 | - } |
|
| 77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | + * |
|
| 79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | + */ |
|
| 81 | + public function __construct( $item = 0 ) { |
|
| 82 | + parent::__construct( $item ); |
|
| 83 | + |
|
| 84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | + $this->set_id( $item ); |
|
| 86 | + } elseif ( $item instanceof self ) { |
|
| 87 | + $this->set_id( $item->get_id() ); |
|
| 88 | + } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | + $this->set_id( $item->ID ); |
|
| 90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | + $this->set_id( $item_id ); |
|
| 92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | + $this->set_id( $item_id ); |
|
| 94 | + } else { |
|
| 95 | + $this->set_object_read( true ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 101 | + if ( $this->get_id() > 0 ) { |
|
| 102 | 102 | $this->post = get_post( $this->get_id() ); |
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read( $this ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | /* |
| 110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Get parent item ID. |
|
| 126 | - * |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @param string $context View or edit context. |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 125 | + * Get parent item ID. |
|
| 126 | + * |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @param string $context View or edit context. |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + public function get_parent_id( $context = 'view' ) { |
|
| 132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | - * Get item status. |
|
| 137 | - * |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @param string $context View or edit context. |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 136 | + * Get item status. |
|
| 137 | + * |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @param string $context View or edit context. |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function get_status( $context = 'view' ) { |
|
| 143 | + return $this->get_prop( 'status', $context ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | - * Get plugin version when the item was created. |
|
| 148 | - * |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - * @param string $context View or edit context. |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 147 | + * Get plugin version when the item was created. |
|
| 148 | + * |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + * @param string $context View or edit context. |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function get_version( $context = 'view' ) { |
|
| 154 | + return $this->get_prop( 'version', $context ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | - * Get date when the item was created. |
|
| 159 | - * |
|
| 160 | - * @since 1.0.19 |
|
| 161 | - * @param string $context View or edit context. |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 158 | + * Get date when the item was created. |
|
| 159 | + * |
|
| 160 | + * @since 1.0.19 |
|
| 161 | + * @param string $context View or edit context. |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function get_date_created( $context = 'view' ) { |
|
| 165 | + return $this->get_prop( 'date_created', $context ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * Get GMT date when the item was created. |
|
| 170 | - * |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - * @param string $context View or edit context. |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 169 | + * Get GMT date when the item was created. |
|
| 170 | + * |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + * @param string $context View or edit context. |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | 176 | $date = $this->get_date_created( $context ); |
| 177 | 177 | |
| 178 | 178 | if ( $date ) { |
| 179 | 179 | $date = get_gmt_from_date( $date ); |
| 180 | 180 | } |
| 181 | - return $date; |
|
| 181 | + return $date; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Get date when the item was last modified. |
|
| 186 | - * |
|
| 187 | - * @since 1.0.19 |
|
| 188 | - * @param string $context View or edit context. |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 185 | + * Get date when the item was last modified. |
|
| 186 | + * |
|
| 187 | + * @since 1.0.19 |
|
| 188 | + * @param string $context View or edit context. |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + public function get_date_modified( $context = 'view' ) { |
|
| 192 | + return $this->get_prop( 'date_modified', $context ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Get GMT date when the item was last modified. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 196 | + * Get GMT date when the item was last modified. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | 203 | $date = $this->get_date_modified( $context ); |
| 204 | 204 | |
| 205 | 205 | if ( $date ) { |
| 206 | 206 | $date = get_gmt_from_date( $date ); |
| 207 | 207 | } |
| 208 | - return $date; |
|
| 208 | + return $date; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | - * Get the item name. |
|
| 213 | - * |
|
| 214 | - * @since 1.0.19 |
|
| 215 | - * @param string $context View or edit context. |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 212 | + * Get the item name. |
|
| 213 | + * |
|
| 214 | + * @since 1.0.19 |
|
| 215 | + * @param string $context View or edit context. |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function get_name( $context = 'view' ) { |
|
| 219 | + return $this->get_prop( 'name', $context ); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | - * Alias of self::get_name(). |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @param string $context View or edit context. |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 223 | + * Alias of self::get_name(). |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @param string $context View or edit context. |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function get_title( $context = 'view' ) { |
|
| 230 | + return $this->get_name( $context ); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | - * Get the item description. |
|
| 235 | - * |
|
| 236 | - * @since 1.0.19 |
|
| 237 | - * @param string $context View or edit context. |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 234 | + * Get the item description. |
|
| 235 | + * |
|
| 236 | + * @since 1.0.19 |
|
| 237 | + * @param string $context View or edit context. |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function get_description( $context = 'view' ) { |
|
| 241 | + return $this->get_prop( 'description', $context ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Alias of self::get_description(). |
|
| 246 | - * |
|
| 247 | - * @since 1.0.19 |
|
| 248 | - * @param string $context View or edit context. |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 245 | + * Alias of self::get_description(). |
|
| 246 | + * |
|
| 247 | + * @since 1.0.19 |
|
| 248 | + * @param string $context View or edit context. |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function get_excerpt( $context = 'view' ) { |
|
| 252 | + return $this->get_description( $context ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | - * Alias of self::get_description(). |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - * @param string $context View or edit context. |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 256 | + * Alias of self::get_description(). |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + * @param string $context View or edit context. |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function get_summary( $context = 'view' ) { |
|
| 263 | + return $this->get_description( $context ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | - * Get the owner of the item. |
|
| 268 | - * |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @param string $context View or edit context. |
|
| 271 | - * @return int |
|
| 272 | - */ |
|
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 275 | - } |
|
| 267 | + * Get the owner of the item. |
|
| 268 | + * |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @param string $context View or edit context. |
|
| 271 | + * @return int |
|
| 272 | + */ |
|
| 273 | + public function get_author( $context = 'view' ) { |
|
| 274 | + return (int) $this->get_prop( 'author', $context ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Alias of self::get_author(). |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @param string $context View or edit context. |
|
| 282 | - * @return int |
|
| 283 | - */ |
|
| 284 | - public function get_owner( $context = 'view' ) { |
|
| 285 | - return $this->get_author( $context ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Get the price of the item. |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @param string $context View or edit context. |
|
| 293 | - * @return float |
|
| 294 | - */ |
|
| 295 | - public function get_price( $context = 'view' ) { |
|
| 277 | + /** |
|
| 278 | + * Alias of self::get_author(). |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @param string $context View or edit context. |
|
| 282 | + * @return int |
|
| 283 | + */ |
|
| 284 | + public function get_owner( $context = 'view' ) { |
|
| 285 | + return $this->get_author( $context ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Get the price of the item. |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @param string $context View or edit context. |
|
| 293 | + * @return float |
|
| 294 | + */ |
|
| 295 | + public function get_price( $context = 'view' ) { |
|
| 296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
| 297 | - } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Get the inital price of the item. |
|
| 301 | - * |
|
| 302 | - * @since 1.0.19 |
|
| 303 | - * @param string $context View or edit context. |
|
| 304 | - * @return float |
|
| 305 | - */ |
|
| 306 | - public function get_initial_price( $context = 'view' ) { |
|
| 299 | + /** |
|
| 300 | + * Get the inital price of the item. |
|
| 301 | + * |
|
| 302 | + * @since 1.0.19 |
|
| 303 | + * @param string $context View or edit context. |
|
| 304 | + * @return float |
|
| 305 | + */ |
|
| 306 | + public function get_initial_price( $context = 'view' ) { |
|
| 307 | 307 | |
| 308 | - $price = (float) $this->get_price( $context ); |
|
| 308 | + $price = (float) $this->get_price( $context ); |
|
| 309 | 309 | |
| 310 | - if ( $this->has_free_trial() ) { |
|
| 311 | - $price = 0; |
|
| 312 | - } |
|
| 310 | + if ( $this->has_free_trial() ) { |
|
| 311 | + $price = 0; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | - * Returns a formated price. |
|
| 319 | - * |
|
| 320 | - * @since 1.0.19 |
|
| 321 | - * @param string $context View or edit context. |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 318 | + * Returns a formated price. |
|
| 319 | + * |
|
| 320 | + * @since 1.0.19 |
|
| 321 | + * @param string $context View or edit context. |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | 324 | public function get_the_price() { |
| 325 | 325 | return wpinv_price( $this->get_price() ); |
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Returns the formated initial price. |
|
| 330 | - * |
|
| 331 | - * @since 1.0.19 |
|
| 332 | - * @param string $context View or edit context. |
|
| 333 | - * @return string |
|
| 334 | - */ |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Returns the formated initial price. |
|
| 330 | + * |
|
| 331 | + * @since 1.0.19 |
|
| 332 | + * @param string $context View or edit context. |
|
| 333 | + * @return string |
|
| 334 | + */ |
|
| 335 | 335 | public function get_the_initial_price() { |
| 336 | 336 | return wpinv_price( $this->get_initial_price() ); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | - * Get the VAT rule of the item. |
|
| 341 | - * |
|
| 342 | - * @since 1.0.19 |
|
| 343 | - * @param string $context View or edit context. |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function get_vat_rule( $context = 'view' ) { |
|
| 340 | + * Get the VAT rule of the item. |
|
| 341 | + * |
|
| 342 | + * @since 1.0.19 |
|
| 343 | + * @param string $context View or edit context. |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function get_vat_rule( $context = 'view' ) { |
|
| 347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | - * Get the VAT class of the item. |
|
| 352 | - * |
|
| 353 | - * @since 1.0.19 |
|
| 354 | - * @param string $context View or edit context. |
|
| 355 | - * @return string |
|
| 356 | - */ |
|
| 357 | - public function get_vat_class( $context = 'view' ) { |
|
| 351 | + * Get the VAT class of the item. |
|
| 352 | + * |
|
| 353 | + * @since 1.0.19 |
|
| 354 | + * @param string $context View or edit context. |
|
| 355 | + * @return string |
|
| 356 | + */ |
|
| 357 | + public function get_vat_class( $context = 'view' ) { |
|
| 358 | 358 | return $this->get_prop( 'vat_class', $context ); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | - * Get the type of the item. |
|
| 363 | - * |
|
| 364 | - * @since 1.0.19 |
|
| 365 | - * @param string $context View or edit context. |
|
| 366 | - * @return string |
|
| 367 | - */ |
|
| 368 | - public function get_type( $context = 'view' ) { |
|
| 362 | + * Get the type of the item. |
|
| 363 | + * |
|
| 364 | + * @since 1.0.19 |
|
| 365 | + * @param string $context View or edit context. |
|
| 366 | + * @return string |
|
| 367 | + */ |
|
| 368 | + public function get_type( $context = 'view' ) { |
|
| 369 | 369 | return $this->get_prop( 'type', $context ); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Get the custom id of the item. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $context View or edit context. |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_custom_id( $context = 'view' ) { |
|
| 373 | + * Get the custom id of the item. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $context View or edit context. |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_custom_id( $context = 'view' ) { |
|
| 380 | 380 | return $this->get_prop( 'custom_id', $context ); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
| 384 | - * Get the custom name of the item. |
|
| 385 | - * |
|
| 386 | - * @since 1.0.19 |
|
| 387 | - * @param string $context View or edit context. |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public function get_custom_name( $context = 'view' ) { |
|
| 384 | + * Get the custom name of the item. |
|
| 385 | + * |
|
| 386 | + * @since 1.0.19 |
|
| 387 | + * @param string $context View or edit context. |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public function get_custom_name( $context = 'view' ) { |
|
| 391 | 391 | return $this->get_prop( 'custom_name', $context ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
| 395 | - * Get the custom singular name of the item. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.19 |
|
| 398 | - * @param string $context View or edit context. |
|
| 399 | - * @return string |
|
| 400 | - */ |
|
| 401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 395 | + * Get the custom singular name of the item. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.19 |
|
| 398 | + * @param string $context View or edit context. |
|
| 399 | + * @return string |
|
| 400 | + */ |
|
| 401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
| 402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
| 406 | - * Checks if an item is editable.. |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - * @param string $context View or edit context. |
|
| 410 | - * @return int |
|
| 411 | - */ |
|
| 412 | - public function get_is_editable( $context = 'view' ) { |
|
| 406 | + * Checks if an item is editable.. |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + * @param string $context View or edit context. |
|
| 410 | + * @return int |
|
| 411 | + */ |
|
| 412 | + public function get_is_editable( $context = 'view' ) { |
|
| 413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
| 417 | - * Alias of self::get_is_editable(). |
|
| 418 | - * |
|
| 419 | - * @since 1.0.19 |
|
| 420 | - * @param string $context View or edit context. |
|
| 421 | - * @return int |
|
| 422 | - */ |
|
| 423 | - public function get_editable( $context = 'view' ) { |
|
| 424 | - return $this->get_is_editable( $context ); |
|
| 417 | + * Alias of self::get_is_editable(). |
|
| 418 | + * |
|
| 419 | + * @since 1.0.19 |
|
| 420 | + * @param string $context View or edit context. |
|
| 421 | + * @return int |
|
| 422 | + */ |
|
| 423 | + public function get_editable( $context = 'view' ) { |
|
| 424 | + return $this->get_is_editable( $context ); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * Checks if dynamic pricing is enabled. |
|
| 429 | - * |
|
| 430 | - * @since 1.0.19 |
|
| 431 | - * @param string $context View or edit context. |
|
| 432 | - * @return int |
|
| 433 | - */ |
|
| 434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 428 | + * Checks if dynamic pricing is enabled. |
|
| 429 | + * |
|
| 430 | + * @since 1.0.19 |
|
| 431 | + * @param string $context View or edit context. |
|
| 432 | + * @return int |
|
| 433 | + */ |
|
| 434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | - * |
|
| 441 | - * @since 1.0.19 |
|
| 442 | - * @param string $context View or edit context. |
|
| 443 | - * @return float |
|
| 444 | - */ |
|
| 445 | - public function get_minimum_price( $context = 'view' ) { |
|
| 439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | + * |
|
| 441 | + * @since 1.0.19 |
|
| 442 | + * @param string $context View or edit context. |
|
| 443 | + * @return float |
|
| 444 | + */ |
|
| 445 | + public function get_minimum_price( $context = 'view' ) { |
|
| 446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
| 450 | - * Checks if this is a recurring item. |
|
| 451 | - * |
|
| 452 | - * @since 1.0.19 |
|
| 453 | - * @param string $context View or edit context. |
|
| 454 | - * @return int |
|
| 455 | - */ |
|
| 456 | - public function get_is_recurring( $context = 'view' ) { |
|
| 450 | + * Checks if this is a recurring item. |
|
| 451 | + * |
|
| 452 | + * @since 1.0.19 |
|
| 453 | + * @param string $context View or edit context. |
|
| 454 | + * @return int |
|
| 455 | + */ |
|
| 456 | + public function get_is_recurring( $context = 'view' ) { |
|
| 457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - /** |
|
| 461 | - * Get the recurring price of the item. |
|
| 462 | - * |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - * @param string $context View or edit context. |
|
| 465 | - * @return float |
|
| 466 | - */ |
|
| 467 | - public function get_recurring_price( $context = 'view' ) { |
|
| 468 | - $price = $this->get_price( $context ); |
|
| 460 | + /** |
|
| 461 | + * Get the recurring price of the item. |
|
| 462 | + * |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + * @param string $context View or edit context. |
|
| 465 | + * @return float |
|
| 466 | + */ |
|
| 467 | + public function get_recurring_price( $context = 'view' ) { |
|
| 468 | + $price = $this->get_price( $context ); |
|
| 469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Get the formatted recurring price of the item. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - * @param string $context View or edit context. |
|
| 477 | - * @return string |
|
| 478 | - */ |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Get the formatted recurring price of the item. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + * @param string $context View or edit context. |
|
| 477 | + * @return string |
|
| 478 | + */ |
|
| 479 | 479 | public function get_the_recurring_price() { |
| 480 | 480 | return wpinv_price( $this->get_recurring_price() ); |
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Get the first renewal date (in timestamps) of the item. |
|
| 485 | - * |
|
| 486 | - * @since 1.0.19 |
|
| 487 | - * @return int |
|
| 488 | - */ |
|
| 489 | - public function get_first_renewal_date() { |
|
| 490 | - |
|
| 491 | - $periods = array( |
|
| 492 | - 'D' => 'days', |
|
| 493 | - 'W' => 'weeks', |
|
| 494 | - 'M' => 'months', |
|
| 495 | - 'Y' => 'years', |
|
| 496 | - ); |
|
| 497 | - |
|
| 498 | - $period = $this->get_recurring_period(); |
|
| 499 | - $interval = $this->get_recurring_interval(); |
|
| 500 | - |
|
| 501 | - if ( $this->has_free_trial() ) { |
|
| 502 | - $period = $this->get_trial_period(); |
|
| 503 | - $interval = $this->get_trial_interval(); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $period = $periods[ $period ]; |
|
| 507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Get the first renewal date (in timestamps) of the item. |
|
| 485 | + * |
|
| 486 | + * @since 1.0.19 |
|
| 487 | + * @return int |
|
| 488 | + */ |
|
| 489 | + public function get_first_renewal_date() { |
|
| 490 | + |
|
| 491 | + $periods = array( |
|
| 492 | + 'D' => 'days', |
|
| 493 | + 'W' => 'weeks', |
|
| 494 | + 'M' => 'months', |
|
| 495 | + 'Y' => 'years', |
|
| 496 | + ); |
|
| 497 | + |
|
| 498 | + $period = $this->get_recurring_period(); |
|
| 499 | + $interval = $this->get_recurring_interval(); |
|
| 500 | + |
|
| 501 | + if ( $this->has_free_trial() ) { |
|
| 502 | + $period = $this->get_trial_period(); |
|
| 503 | + $interval = $this->get_trial_interval(); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $period = $periods[ $period ]; |
|
| 507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
| 513 | - * Get the recurring period. |
|
| 514 | - * |
|
| 515 | - * @since 1.0.19 |
|
| 516 | - * @param bool $full Return abbreviation or in full. |
|
| 517 | - * @return string |
|
| 518 | - */ |
|
| 519 | - public function get_recurring_period( $full = false ) { |
|
| 513 | + * Get the recurring period. |
|
| 514 | + * |
|
| 515 | + * @since 1.0.19 |
|
| 516 | + * @param bool $full Return abbreviation or in full. |
|
| 517 | + * @return string |
|
| 518 | + */ |
|
| 519 | + public function get_recurring_period( $full = false ) { |
|
| 520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
| 521 | 521 | |
| 522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,58 +527,58 @@ discard block |
||
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
| 530 | - * Get the recurring interval. |
|
| 531 | - * |
|
| 532 | - * @since 1.0.19 |
|
| 533 | - * @param string $context View or edit context. |
|
| 534 | - * @return int |
|
| 535 | - */ |
|
| 536 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 538 | - return max( 1, $interval ); |
|
| 530 | + * Get the recurring interval. |
|
| 531 | + * |
|
| 532 | + * @since 1.0.19 |
|
| 533 | + * @param string $context View or edit context. |
|
| 534 | + * @return int |
|
| 535 | + */ |
|
| 536 | + public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 538 | + return max( 1, $interval ); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
| 542 | - * Get the recurring limit. |
|
| 543 | - * |
|
| 544 | - * @since 1.0.19 |
|
| 545 | - * @param string $context View or edit context. |
|
| 546 | - * @return int |
|
| 547 | - */ |
|
| 548 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 542 | + * Get the recurring limit. |
|
| 543 | + * |
|
| 544 | + * @since 1.0.19 |
|
| 545 | + * @param string $context View or edit context. |
|
| 546 | + * @return int |
|
| 547 | + */ |
|
| 548 | + public function get_recurring_limit( $context = 'view' ) { |
|
| 549 | 549 | return (int) $this->get_prop( 'recurring_limit', $context ); |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
| 553 | - * Checks if we have a free trial. |
|
| 554 | - * |
|
| 555 | - * @since 1.0.19 |
|
| 556 | - * @param string $context View or edit context. |
|
| 557 | - * @return int |
|
| 558 | - */ |
|
| 559 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 553 | + * Checks if we have a free trial. |
|
| 554 | + * |
|
| 555 | + * @since 1.0.19 |
|
| 556 | + * @param string $context View or edit context. |
|
| 557 | + * @return int |
|
| 558 | + */ |
|
| 559 | + public function get_is_free_trial( $context = 'view' ) { |
|
| 560 | 560 | return (int) $this->get_prop( 'is_free_trial', $context ); |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
| 564 | - * Alias for self::get_is_free_trial(). |
|
| 565 | - * |
|
| 566 | - * @since 1.0.19 |
|
| 567 | - * @param string $context View or edit context. |
|
| 568 | - * @return int |
|
| 569 | - */ |
|
| 570 | - public function get_free_trial( $context = 'view' ) { |
|
| 564 | + * Alias for self::get_is_free_trial(). |
|
| 565 | + * |
|
| 566 | + * @since 1.0.19 |
|
| 567 | + * @param string $context View or edit context. |
|
| 568 | + * @return int |
|
| 569 | + */ |
|
| 570 | + public function get_free_trial( $context = 'view' ) { |
|
| 571 | 571 | return $this->get_is_free_trial( $context ); |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
| 575 | - * Get the trial period. |
|
| 576 | - * |
|
| 577 | - * @since 1.0.19 |
|
| 578 | - * @param bool $full Return abbreviation or in full. |
|
| 579 | - * @return string |
|
| 580 | - */ |
|
| 581 | - public function get_trial_period( $full = false ) { |
|
| 575 | + * Get the trial period. |
|
| 576 | + * |
|
| 577 | + * @since 1.0.19 |
|
| 578 | + * @param bool $full Return abbreviation or in full. |
|
| 579 | + * @return string |
|
| 580 | + */ |
|
| 581 | + public function get_trial_period( $full = false ) { |
|
| 582 | 582 | $period = $this->get_prop( 'trial_period', 'view' ); |
| 583 | 583 | |
| 584 | 584 | if ( $full && ! is_bool( $full ) ) { |
@@ -589,104 +589,104 @@ discard block |
||
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
| 592 | - * Get the trial interval. |
|
| 593 | - * |
|
| 594 | - * @since 1.0.19 |
|
| 595 | - * @param string $context View or edit context. |
|
| 596 | - * @return int |
|
| 597 | - */ |
|
| 598 | - public function get_trial_interval( $context = 'view' ) { |
|
| 592 | + * Get the trial interval. |
|
| 593 | + * |
|
| 594 | + * @since 1.0.19 |
|
| 595 | + * @param string $context View or edit context. |
|
| 596 | + * @return int |
|
| 597 | + */ |
|
| 598 | + public function get_trial_interval( $context = 'view' ) { |
|
| 599 | 599 | return (int) $this->get_prop( 'trial_interval', $context ); |
| 600 | - } |
|
| 600 | + } |
|
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * Get the item's edit url. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - * @return string |
|
| 607 | - */ |
|
| 608 | - public function get_edit_url() { |
|
| 602 | + /** |
|
| 603 | + * Get the item's edit url. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + * @return string |
|
| 607 | + */ |
|
| 608 | + public function get_edit_url() { |
|
| 609 | 609 | return get_edit_post_link( $this->get_id(), 'edit' ); |
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * Given an item's name/custom id, it returns its id. |
|
| 614 | - * |
|
| 615 | - * |
|
| 616 | - * @static |
|
| 617 | - * @param string $value The item name or custom id. |
|
| 618 | - * @param string $field Either name or custom_id. |
|
| 619 | - * @param string $type in case you need to search for a given type. |
|
| 620 | - * @since 1.0.15 |
|
| 621 | - * @return int |
|
| 622 | - */ |
|
| 623 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 624 | - |
|
| 625 | - // Trim the value. |
|
| 626 | - $value = sanitize_text_field( $value ); |
|
| 627 | - if ( empty( $value ) ) { |
|
| 628 | - return 0; |
|
| 629 | - } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * Given an item's name/custom id, it returns its id. |
|
| 614 | + * |
|
| 615 | + * |
|
| 616 | + * @static |
|
| 617 | + * @param string $value The item name or custom id. |
|
| 618 | + * @param string $field Either name or custom_id. |
|
| 619 | + * @param string $type in case you need to search for a given type. |
|
| 620 | + * @since 1.0.15 |
|
| 621 | + * @return int |
|
| 622 | + */ |
|
| 623 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 624 | + |
|
| 625 | + // Trim the value. |
|
| 626 | + $value = sanitize_text_field( $value ); |
|
| 627 | + if ( empty( $value ) ) { |
|
| 628 | + return 0; |
|
| 629 | + } |
|
| 630 | 630 | |
| 631 | 631 | // Valid fields. |
| 632 | 632 | $fields = array( 'custom_id', 'name', 'slug' ); |
| 633 | 633 | |
| 634 | - // Ensure a field has been passed. |
|
| 635 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 636 | - return 0; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - if ( $field == 'name' ) { |
|
| 640 | - $field = 'slug'; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - // Maybe retrieve from the cache. |
|
| 644 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 645 | - if ( ! empty( $item_id ) ) { |
|
| 646 | - return $item_id; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - // Fetch from the db. |
|
| 650 | - $items = array(); |
|
| 651 | - if ( $field == 'slug' ) { |
|
| 652 | - $items = get_posts( |
|
| 653 | - array( |
|
| 654 | - 'post_type' => 'wpi_item', |
|
| 655 | - 'name' => $value, |
|
| 656 | - 'posts_per_page' => 1, |
|
| 657 | - 'post_status' => 'any', |
|
| 658 | - ) |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - if ( $field =='custom_id' ) { |
|
| 663 | - $items = get_posts( |
|
| 664 | - array( |
|
| 665 | - 'post_type' => 'wpi_item', |
|
| 666 | - 'posts_per_page' => 1, |
|
| 667 | - 'post_status' => 'any', |
|
| 668 | - 'meta_query' => array( |
|
| 669 | - array( |
|
| 670 | - 'key' => '_wpinv_type', |
|
| 671 | - 'value' => $type, |
|
| 672 | - ), |
|
| 673 | - array( |
|
| 674 | - 'key' => '_wpinv_custom_id', |
|
| 675 | - 'value' => $value, |
|
| 676 | - ) |
|
| 677 | - ) |
|
| 678 | - ) |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - if ( empty( $items ) ) { |
|
| 683 | - return 0; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - // Update the cache with our data |
|
| 687 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 688 | - |
|
| 689 | - return $items[0]->ID; |
|
| 634 | + // Ensure a field has been passed. |
|
| 635 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 636 | + return 0; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + if ( $field == 'name' ) { |
|
| 640 | + $field = 'slug'; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + // Maybe retrieve from the cache. |
|
| 644 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 645 | + if ( ! empty( $item_id ) ) { |
|
| 646 | + return $item_id; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + // Fetch from the db. |
|
| 650 | + $items = array(); |
|
| 651 | + if ( $field == 'slug' ) { |
|
| 652 | + $items = get_posts( |
|
| 653 | + array( |
|
| 654 | + 'post_type' => 'wpi_item', |
|
| 655 | + 'name' => $value, |
|
| 656 | + 'posts_per_page' => 1, |
|
| 657 | + 'post_status' => 'any', |
|
| 658 | + ) |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + if ( $field =='custom_id' ) { |
|
| 663 | + $items = get_posts( |
|
| 664 | + array( |
|
| 665 | + 'post_type' => 'wpi_item', |
|
| 666 | + 'posts_per_page' => 1, |
|
| 667 | + 'post_status' => 'any', |
|
| 668 | + 'meta_query' => array( |
|
| 669 | + array( |
|
| 670 | + 'key' => '_wpinv_type', |
|
| 671 | + 'value' => $type, |
|
| 672 | + ), |
|
| 673 | + array( |
|
| 674 | + 'key' => '_wpinv_custom_id', |
|
| 675 | + 'value' => $value, |
|
| 676 | + ) |
|
| 677 | + ) |
|
| 678 | + ) |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + if ( empty( $items ) ) { |
|
| 683 | + return 0; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + // Update the cache with our data |
|
| 687 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 688 | + |
|
| 689 | + return $items[0]->ID; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -719,52 +719,52 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | |
| 721 | 721 | /** |
| 722 | - * Set parent order ID. |
|
| 723 | - * |
|
| 724 | - * @since 1.0.19 |
|
| 725 | - */ |
|
| 726 | - public function set_parent_id( $value ) { |
|
| 727 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 728 | - return; |
|
| 729 | - } |
|
| 730 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * Sets item status. |
|
| 735 | - * |
|
| 736 | - * @since 1.0.19 |
|
| 737 | - * @param string $status New status. |
|
| 738 | - * @return array details of change. |
|
| 739 | - */ |
|
| 740 | - public function set_status( $status ) { |
|
| 722 | + * Set parent order ID. |
|
| 723 | + * |
|
| 724 | + * @since 1.0.19 |
|
| 725 | + */ |
|
| 726 | + public function set_parent_id( $value ) { |
|
| 727 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 728 | + return; |
|
| 729 | + } |
|
| 730 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * Sets item status. |
|
| 735 | + * |
|
| 736 | + * @since 1.0.19 |
|
| 737 | + * @param string $status New status. |
|
| 738 | + * @return array details of change. |
|
| 739 | + */ |
|
| 740 | + public function set_status( $status ) { |
|
| 741 | 741 | $old_status = $this->get_status(); |
| 742 | 742 | |
| 743 | 743 | $this->set_prop( 'status', $status ); |
| 744 | 744 | |
| 745 | - return array( |
|
| 746 | - 'from' => $old_status, |
|
| 747 | - 'to' => $status, |
|
| 748 | - ); |
|
| 745 | + return array( |
|
| 746 | + 'from' => $old_status, |
|
| 747 | + 'to' => $status, |
|
| 748 | + ); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
| 752 | - * Set plugin version when the item was created. |
|
| 753 | - * |
|
| 754 | - * @since 1.0.19 |
|
| 755 | - */ |
|
| 756 | - public function set_version( $value ) { |
|
| 757 | - $this->set_prop( 'version', $value ); |
|
| 752 | + * Set plugin version when the item was created. |
|
| 753 | + * |
|
| 754 | + * @since 1.0.19 |
|
| 755 | + */ |
|
| 756 | + public function set_version( $value ) { |
|
| 757 | + $this->set_prop( 'version', $value ); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
| 761 | - * Set date when the item was created. |
|
| 762 | - * |
|
| 763 | - * @since 1.0.19 |
|
| 764 | - * @param string $value Value to set. |
|
| 761 | + * Set date when the item was created. |
|
| 762 | + * |
|
| 763 | + * @since 1.0.19 |
|
| 764 | + * @param string $value Value to set. |
|
| 765 | 765 | * @return bool Whether or not the date was set. |
| 766 | - */ |
|
| 767 | - public function set_date_created( $value ) { |
|
| 766 | + */ |
|
| 767 | + public function set_date_created( $value ) { |
|
| 768 | 768 | $date = strtotime( $value ); |
| 769 | 769 | |
| 770 | 770 | if ( $date ) { |
@@ -777,13 +777,13 @@ discard block |
||
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
| 780 | - * Set date when the item was last modified. |
|
| 781 | - * |
|
| 782 | - * @since 1.0.19 |
|
| 783 | - * @param string $value Value to set. |
|
| 780 | + * Set date when the item was last modified. |
|
| 781 | + * |
|
| 782 | + * @since 1.0.19 |
|
| 783 | + * @param string $value Value to set. |
|
| 784 | 784 | * @return bool Whether or not the date was set. |
| 785 | - */ |
|
| 786 | - public function set_date_modified( $value ) { |
|
| 785 | + */ |
|
| 786 | + public function set_date_modified( $value ) { |
|
| 787 | 787 | $date = strtotime( $value ); |
| 788 | 788 | |
| 789 | 789 | if ( $date ) { |
@@ -796,115 +796,115 @@ discard block |
||
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
| 799 | - * Set the item name. |
|
| 800 | - * |
|
| 801 | - * @since 1.0.19 |
|
| 802 | - * @param string $value New name. |
|
| 803 | - */ |
|
| 804 | - public function set_name( $value ) { |
|
| 799 | + * Set the item name. |
|
| 800 | + * |
|
| 801 | + * @since 1.0.19 |
|
| 802 | + * @param string $value New name. |
|
| 803 | + */ |
|
| 804 | + public function set_name( $value ) { |
|
| 805 | 805 | $name = sanitize_text_field( $value ); |
| 806 | - $this->set_prop( 'name', $name ); |
|
| 806 | + $this->set_prop( 'name', $name ); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
| 810 | - * Alias of self::set_name(). |
|
| 811 | - * |
|
| 812 | - * @since 1.0.19 |
|
| 813 | - * @param string $value New name. |
|
| 814 | - */ |
|
| 815 | - public function set_title( $value ) { |
|
| 816 | - $this->set_name( $value ); |
|
| 810 | + * Alias of self::set_name(). |
|
| 811 | + * |
|
| 812 | + * @since 1.0.19 |
|
| 813 | + * @param string $value New name. |
|
| 814 | + */ |
|
| 815 | + public function set_title( $value ) { |
|
| 816 | + $this->set_name( $value ); |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | /** |
| 820 | - * Set the item description. |
|
| 821 | - * |
|
| 822 | - * @since 1.0.19 |
|
| 823 | - * @param string $value New description. |
|
| 824 | - */ |
|
| 825 | - public function set_description( $value ) { |
|
| 826 | - $description = wp_kses_post( $value ); |
|
| 827 | - return $this->set_prop( 'description', $description ); |
|
| 820 | + * Set the item description. |
|
| 821 | + * |
|
| 822 | + * @since 1.0.19 |
|
| 823 | + * @param string $value New description. |
|
| 824 | + */ |
|
| 825 | + public function set_description( $value ) { |
|
| 826 | + $description = wp_kses_post( $value ); |
|
| 827 | + return $this->set_prop( 'description', $description ); |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
| 831 | - * Alias of self::set_description(). |
|
| 832 | - * |
|
| 833 | - * @since 1.0.19 |
|
| 834 | - * @param string $value New description. |
|
| 835 | - */ |
|
| 836 | - public function set_excerpt( $value ) { |
|
| 837 | - $this->set_description( $value ); |
|
| 831 | + * Alias of self::set_description(). |
|
| 832 | + * |
|
| 833 | + * @since 1.0.19 |
|
| 834 | + * @param string $value New description. |
|
| 835 | + */ |
|
| 836 | + public function set_excerpt( $value ) { |
|
| 837 | + $this->set_description( $value ); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
| 841 | - * Alias of self::set_description(). |
|
| 842 | - * |
|
| 843 | - * @since 1.0.19 |
|
| 844 | - * @param string $value New description. |
|
| 845 | - */ |
|
| 846 | - public function set_summary( $value ) { |
|
| 847 | - $this->set_description( $value ); |
|
| 841 | + * Alias of self::set_description(). |
|
| 842 | + * |
|
| 843 | + * @since 1.0.19 |
|
| 844 | + * @param string $value New description. |
|
| 845 | + */ |
|
| 846 | + public function set_summary( $value ) { |
|
| 847 | + $this->set_description( $value ); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | /** |
| 851 | - * Set the owner of the item. |
|
| 852 | - * |
|
| 853 | - * @since 1.0.19 |
|
| 854 | - * @param int $value New author. |
|
| 855 | - */ |
|
| 856 | - public function set_author( $value ) { |
|
| 857 | - $this->set_prop( 'author', (int) $value ); |
|
| 858 | - } |
|
| 851 | + * Set the owner of the item. |
|
| 852 | + * |
|
| 853 | + * @since 1.0.19 |
|
| 854 | + * @param int $value New author. |
|
| 855 | + */ |
|
| 856 | + public function set_author( $value ) { |
|
| 857 | + $this->set_prop( 'author', (int) $value ); |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - /** |
|
| 861 | - * Alias of self::set_author(). |
|
| 862 | - * |
|
| 863 | - * @since 1.0.19 |
|
| 864 | - * @param int $value New author. |
|
| 865 | - */ |
|
| 866 | - public function set_owner( $value ) { |
|
| 867 | - $this->set_author( $value ); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Set the price of the item. |
|
| 872 | - * |
|
| 873 | - * @since 1.0.19 |
|
| 874 | - * @param float $value New price. |
|
| 875 | - */ |
|
| 876 | - public function set_price( $value ) { |
|
| 860 | + /** |
|
| 861 | + * Alias of self::set_author(). |
|
| 862 | + * |
|
| 863 | + * @since 1.0.19 |
|
| 864 | + * @param int $value New author. |
|
| 865 | + */ |
|
| 866 | + public function set_owner( $value ) { |
|
| 867 | + $this->set_author( $value ); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Set the price of the item. |
|
| 872 | + * |
|
| 873 | + * @since 1.0.19 |
|
| 874 | + * @param float $value New price. |
|
| 875 | + */ |
|
| 876 | + public function set_price( $value ) { |
|
| 877 | 877 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
| 881 | - * Set the VAT rule of the item. |
|
| 882 | - * |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - * @param string $value new rule. |
|
| 885 | - */ |
|
| 886 | - public function set_vat_rule( $value ) { |
|
| 881 | + * Set the VAT rule of the item. |
|
| 882 | + * |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + * @param string $value new rule. |
|
| 885 | + */ |
|
| 886 | + public function set_vat_rule( $value ) { |
|
| 887 | 887 | $this->set_prop( 'vat_rule', $value ); |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
| 891 | - * Set the VAT class of the item. |
|
| 892 | - * |
|
| 893 | - * @since 1.0.19 |
|
| 894 | - * @param string $value new class. |
|
| 895 | - */ |
|
| 896 | - public function set_vat_class( $value ) { |
|
| 891 | + * Set the VAT class of the item. |
|
| 892 | + * |
|
| 893 | + * @since 1.0.19 |
|
| 894 | + * @param string $value new class. |
|
| 895 | + */ |
|
| 896 | + public function set_vat_class( $value ) { |
|
| 897 | 897 | $this->set_prop( 'vat_class', $value ); |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
| 901 | - * Set the type of the item. |
|
| 902 | - * |
|
| 903 | - * @since 1.0.19 |
|
| 904 | - * @param string $value new item type. |
|
| 905 | - * @return string |
|
| 906 | - */ |
|
| 907 | - public function set_type( $value ) { |
|
| 901 | + * Set the type of the item. |
|
| 902 | + * |
|
| 903 | + * @since 1.0.19 |
|
| 904 | + * @param string $value new item type. |
|
| 905 | + * @return string |
|
| 906 | + */ |
|
| 907 | + public function set_type( $value ) { |
|
| 908 | 908 | |
| 909 | 909 | if ( empty( $value ) ) { |
| 910 | 910 | $value = 'custom'; |
@@ -914,132 +914,132 @@ discard block |
||
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
| 917 | - * Set the custom id of the item. |
|
| 918 | - * |
|
| 919 | - * @since 1.0.19 |
|
| 920 | - * @param string $value new custom id. |
|
| 921 | - */ |
|
| 922 | - public function set_custom_id( $value ) { |
|
| 917 | + * Set the custom id of the item. |
|
| 918 | + * |
|
| 919 | + * @since 1.0.19 |
|
| 920 | + * @param string $value new custom id. |
|
| 921 | + */ |
|
| 922 | + public function set_custom_id( $value ) { |
|
| 923 | 923 | $this->set_prop( 'custom_id', $value ); |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | /** |
| 927 | - * Set the custom name of the item. |
|
| 928 | - * |
|
| 929 | - * @since 1.0.19 |
|
| 930 | - * @param string $value new custom name. |
|
| 931 | - */ |
|
| 932 | - public function set_custom_name( $value ) { |
|
| 927 | + * Set the custom name of the item. |
|
| 928 | + * |
|
| 929 | + * @since 1.0.19 |
|
| 930 | + * @param string $value new custom name. |
|
| 931 | + */ |
|
| 932 | + public function set_custom_name( $value ) { |
|
| 933 | 933 | $this->set_prop( 'custom_name', $value ); |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
| 937 | - * Set the custom singular name of the item. |
|
| 938 | - * |
|
| 939 | - * @since 1.0.19 |
|
| 940 | - * @param string $value new custom singular name. |
|
| 941 | - */ |
|
| 942 | - public function set_custom_singular_name( $value ) { |
|
| 937 | + * Set the custom singular name of the item. |
|
| 938 | + * |
|
| 939 | + * @since 1.0.19 |
|
| 940 | + * @param string $value new custom singular name. |
|
| 941 | + */ |
|
| 942 | + public function set_custom_singular_name( $value ) { |
|
| 943 | 943 | $this->set_prop( 'custom_singular_name', $value ); |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | /** |
| 947 | - * Sets if an item is editable.. |
|
| 948 | - * |
|
| 949 | - * @since 1.0.19 |
|
| 950 | - * @param int|bool $value whether or not the item is editable. |
|
| 951 | - */ |
|
| 952 | - public function set_is_editable( $value ) { |
|
| 953 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 947 | + * Sets if an item is editable.. |
|
| 948 | + * |
|
| 949 | + * @since 1.0.19 |
|
| 950 | + * @param int|bool $value whether or not the item is editable. |
|
| 951 | + */ |
|
| 952 | + public function set_is_editable( $value ) { |
|
| 953 | + $this->set_prop( 'is_editable', (int) $value ); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
| 957 | - * Sets if dynamic pricing is enabled. |
|
| 958 | - * |
|
| 959 | - * @since 1.0.19 |
|
| 960 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 961 | - */ |
|
| 962 | - public function set_is_dynamic_pricing( $value ) { |
|
| 957 | + * Sets if dynamic pricing is enabled. |
|
| 958 | + * |
|
| 959 | + * @since 1.0.19 |
|
| 960 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 961 | + */ |
|
| 962 | + public function set_is_dynamic_pricing( $value ) { |
|
| 963 | 963 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
| 967 | - * Sets the minimum price if dynamic pricing is enabled. |
|
| 968 | - * |
|
| 969 | - * @since 1.0.19 |
|
| 970 | - * @param float $value minimum price. |
|
| 971 | - */ |
|
| 972 | - public function set_minimum_price( $value ) { |
|
| 967 | + * Sets the minimum price if dynamic pricing is enabled. |
|
| 968 | + * |
|
| 969 | + * @since 1.0.19 |
|
| 970 | + * @param float $value minimum price. |
|
| 971 | + */ |
|
| 972 | + public function set_minimum_price( $value ) { |
|
| 973 | 973 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
| 977 | - * Sets if this is a recurring item. |
|
| 978 | - * |
|
| 979 | - * @since 1.0.19 |
|
| 980 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 981 | - */ |
|
| 982 | - public function set_is_recurring( $value ) { |
|
| 977 | + * Sets if this is a recurring item. |
|
| 978 | + * |
|
| 979 | + * @since 1.0.19 |
|
| 980 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 981 | + */ |
|
| 982 | + public function set_is_recurring( $value ) { |
|
| 983 | 983 | $this->set_prop( 'is_recurring', (int) $value ); |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | /** |
| 987 | - * Set the recurring period. |
|
| 988 | - * |
|
| 989 | - * @since 1.0.19 |
|
| 990 | - * @param string $value new period. |
|
| 991 | - */ |
|
| 992 | - public function set_recurring_period( $value ) { |
|
| 987 | + * Set the recurring period. |
|
| 988 | + * |
|
| 989 | + * @since 1.0.19 |
|
| 990 | + * @param string $value new period. |
|
| 991 | + */ |
|
| 992 | + public function set_recurring_period( $value ) { |
|
| 993 | 993 | $this->set_prop( 'recurring_period', $value ); |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | /** |
| 997 | - * Set the recurring interval. |
|
| 998 | - * |
|
| 999 | - * @since 1.0.19 |
|
| 1000 | - * @param int $value recurring interval. |
|
| 1001 | - */ |
|
| 1002 | - public function set_recurring_interval( $value ) { |
|
| 997 | + * Set the recurring interval. |
|
| 998 | + * |
|
| 999 | + * @since 1.0.19 |
|
| 1000 | + * @param int $value recurring interval. |
|
| 1001 | + */ |
|
| 1002 | + public function set_recurring_interval( $value ) { |
|
| 1003 | 1003 | return $this->set_prop( 'recurring_interval', (int) $value ); |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | /** |
| 1007 | - * Get the recurring limit. |
|
| 1008 | - * @since 1.0.19 |
|
| 1009 | - * @param int $value The recurring limit. |
|
| 1010 | - * @return int |
|
| 1011 | - */ |
|
| 1012 | - public function set_recurring_limit( $value ) { |
|
| 1007 | + * Get the recurring limit. |
|
| 1008 | + * @since 1.0.19 |
|
| 1009 | + * @param int $value The recurring limit. |
|
| 1010 | + * @return int |
|
| 1011 | + */ |
|
| 1012 | + public function set_recurring_limit( $value ) { |
|
| 1013 | 1013 | $this->set_prop( 'recurring_limit', (int) $value ); |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | /** |
| 1017 | - * Checks if we have a free trial. |
|
| 1018 | - * |
|
| 1019 | - * @since 1.0.19 |
|
| 1020 | - * @param int|bool $value whether or not it has a free trial. |
|
| 1021 | - */ |
|
| 1022 | - public function set_is_free_trial( $value ) { |
|
| 1017 | + * Checks if we have a free trial. |
|
| 1018 | + * |
|
| 1019 | + * @since 1.0.19 |
|
| 1020 | + * @param int|bool $value whether or not it has a free trial. |
|
| 1021 | + */ |
|
| 1022 | + public function set_is_free_trial( $value ) { |
|
| 1023 | 1023 | $this->set_prop( 'is_free_trial', (int) $value ); |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
| 1027 | - * Set the trial period. |
|
| 1028 | - * |
|
| 1029 | - * @since 1.0.19 |
|
| 1030 | - * @param string $value trial period. |
|
| 1031 | - */ |
|
| 1032 | - public function set_trial_period( $value ) { |
|
| 1027 | + * Set the trial period. |
|
| 1028 | + * |
|
| 1029 | + * @since 1.0.19 |
|
| 1030 | + * @param string $value trial period. |
|
| 1031 | + */ |
|
| 1032 | + public function set_trial_period( $value ) { |
|
| 1033 | 1033 | $this->set_prop( 'trial_period', $value ); |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /** |
| 1037 | - * Set the trial interval. |
|
| 1038 | - * |
|
| 1039 | - * @since 1.0.19 |
|
| 1040 | - * @param int $value trial interval. |
|
| 1041 | - */ |
|
| 1042 | - public function set_trial_interval( $value ) { |
|
| 1037 | + * Set the trial interval. |
|
| 1038 | + * |
|
| 1039 | + * @since 1.0.19 |
|
| 1040 | + * @param int $value trial interval. |
|
| 1041 | + */ |
|
| 1042 | + public function set_trial_interval( $value ) { |
|
| 1043 | 1043 | $this->set_prop( 'trial_interval', $value ); |
| 1044 | 1044 | } |
| 1045 | 1045 | |
@@ -1047,17 +1047,17 @@ discard block |
||
| 1047 | 1047 | * Create an item. For backwards compatibilty. |
| 1048 | 1048 | * |
| 1049 | 1049 | * @deprecated |
| 1050 | - * @return int item id |
|
| 1050 | + * @return int item id |
|
| 1051 | 1051 | */ |
| 1052 | 1052 | public function create( $data = array() ) { |
| 1053 | 1053 | |
| 1054 | - // Set the properties. |
|
| 1055 | - if ( is_array( $data ) ) { |
|
| 1056 | - $this->set_props( $data ); |
|
| 1057 | - } |
|
| 1054 | + // Set the properties. |
|
| 1055 | + if ( is_array( $data ) ) { |
|
| 1056 | + $this->set_props( $data ); |
|
| 1057 | + } |
|
| 1058 | 1058 | |
| 1059 | - // Save the item. |
|
| 1060 | - return $this->save(); |
|
| 1059 | + // Save the item. |
|
| 1060 | + return $this->save(); |
|
| 1061 | 1061 | |
| 1062 | 1062 | } |
| 1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | * Updates an item. For backwards compatibilty. |
| 1066 | 1066 | * |
| 1067 | 1067 | * @deprecated |
| 1068 | - * @return int item id |
|
| 1068 | + * @return int item id |
|
| 1069 | 1069 | */ |
| 1070 | 1070 | public function update( $data = array() ) { |
| 1071 | 1071 | return $this->create( $data ); |
@@ -1081,93 +1081,93 @@ discard block |
||
| 1081 | 1081 | */ |
| 1082 | 1082 | |
| 1083 | 1083 | /** |
| 1084 | - * Checks whether the item has enabled dynamic pricing. |
|
| 1085 | - * |
|
| 1086 | - * @since 1.0.19 |
|
| 1087 | - * @return bool |
|
| 1088 | - */ |
|
| 1089 | - public function user_can_set_their_price() { |
|
| 1084 | + * Checks whether the item has enabled dynamic pricing. |
|
| 1085 | + * |
|
| 1086 | + * @since 1.0.19 |
|
| 1087 | + * @return bool |
|
| 1088 | + */ |
|
| 1089 | + public function user_can_set_their_price() { |
|
| 1090 | 1090 | return (bool) $this->get_is_dynamic_pricing(); |
| 1091 | - } |
|
| 1091 | + } |
|
| 1092 | 1092 | |
| 1093 | - /** |
|
| 1094 | - * Checks whether the item is recurring. |
|
| 1095 | - * |
|
| 1096 | - * @since 1.0.19 |
|
| 1097 | - * @return bool |
|
| 1098 | - */ |
|
| 1099 | - public function is_recurring() { |
|
| 1093 | + /** |
|
| 1094 | + * Checks whether the item is recurring. |
|
| 1095 | + * |
|
| 1096 | + * @since 1.0.19 |
|
| 1097 | + * @return bool |
|
| 1098 | + */ |
|
| 1099 | + public function is_recurring() { |
|
| 1100 | 1100 | return (bool) $this->get_is_recurring(); |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
| 1104 | - * Checks whether the item has a free trial. |
|
| 1105 | - * |
|
| 1106 | - * @since 1.0.19 |
|
| 1107 | - * @return bool |
|
| 1108 | - */ |
|
| 1104 | + * Checks whether the item has a free trial. |
|
| 1105 | + * |
|
| 1106 | + * @since 1.0.19 |
|
| 1107 | + * @return bool |
|
| 1108 | + */ |
|
| 1109 | 1109 | public function has_free_trial() { |
| 1110 | 1110 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1111 | 1111 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
| 1115 | - * Checks whether the item is free. |
|
| 1116 | - * |
|
| 1117 | - * @since 1.0.19 |
|
| 1118 | - * @return bool |
|
| 1119 | - */ |
|
| 1115 | + * Checks whether the item is free. |
|
| 1116 | + * |
|
| 1117 | + * @since 1.0.19 |
|
| 1118 | + * @return bool |
|
| 1119 | + */ |
|
| 1120 | 1120 | public function is_free() { |
| 1121 | 1121 | $is_free = $this->get_price() == 0; |
| 1122 | 1122 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | /** |
| 1126 | - * Checks the item status against a passed in status. |
|
| 1127 | - * |
|
| 1128 | - * @param array|string $status Status to check. |
|
| 1129 | - * @return bool |
|
| 1130 | - */ |
|
| 1131 | - public function has_status( $status ) { |
|
| 1132 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1133 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1126 | + * Checks the item status against a passed in status. |
|
| 1127 | + * |
|
| 1128 | + * @param array|string $status Status to check. |
|
| 1129 | + * @return bool |
|
| 1130 | + */ |
|
| 1131 | + public function has_status( $status ) { |
|
| 1132 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1133 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
| 1137 | - * Checks the item type against a passed in types. |
|
| 1138 | - * |
|
| 1139 | - * @param array|string $type Type to check. |
|
| 1140 | - * @return bool |
|
| 1141 | - */ |
|
| 1142 | - public function is_type( $type ) { |
|
| 1143 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1144 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1145 | - } |
|
| 1137 | + * Checks the item type against a passed in types. |
|
| 1138 | + * |
|
| 1139 | + * @param array|string $type Type to check. |
|
| 1140 | + * @return bool |
|
| 1141 | + */ |
|
| 1142 | + public function is_type( $type ) { |
|
| 1143 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1144 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1145 | + } |
|
| 1146 | 1146 | |
| 1147 | 1147 | /** |
| 1148 | - * Checks whether the item is editable. |
|
| 1149 | - * |
|
| 1150 | - * @since 1.0.19 |
|
| 1151 | - * @return bool |
|
| 1152 | - */ |
|
| 1148 | + * Checks whether the item is editable. |
|
| 1149 | + * |
|
| 1150 | + * @since 1.0.19 |
|
| 1151 | + * @return bool |
|
| 1152 | + */ |
|
| 1153 | 1153 | public function is_editable() { |
| 1154 | 1154 | $is_editable = $this->get_is_editable(); |
| 1155 | 1155 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
| 1156 | - } |
|
| 1156 | + } |
|
| 1157 | 1157 | |
| 1158 | - /** |
|
| 1159 | - * Returns an array of cart fees. |
|
| 1160 | - */ |
|
| 1161 | - public function get_fees() { |
|
| 1158 | + /** |
|
| 1159 | + * Returns an array of cart fees. |
|
| 1160 | + */ |
|
| 1161 | + public function get_fees() { |
|
| 1162 | 1162 | return array(); |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | /** |
| 1166 | - * Checks whether the item is purchasable. |
|
| 1167 | - * |
|
| 1168 | - * @since 1.0.19 |
|
| 1169 | - * @return bool |
|
| 1170 | - */ |
|
| 1166 | + * Checks whether the item is purchasable. |
|
| 1167 | + * |
|
| 1168 | + * @since 1.0.19 |
|
| 1169 | + * @return bool |
|
| 1170 | + */ |
|
| 1171 | 1171 | public function can_purchase() { |
| 1172 | 1172 | $can_purchase = $this->exists(); |
| 1173 | 1173 | |
@@ -1179,11 +1179,11 @@ discard block |
||
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | /** |
| 1182 | - * Checks whether the item supports dynamic pricing. |
|
| 1183 | - * |
|
| 1184 | - * @since 1.0.19 |
|
| 1185 | - * @return bool |
|
| 1186 | - */ |
|
| 1182 | + * Checks whether the item supports dynamic pricing. |
|
| 1183 | + * |
|
| 1184 | + * @since 1.0.19 |
|
| 1185 | + * @return bool |
|
| 1186 | + */ |
|
| 1187 | 1187 | public function supports_dynamic_pricing() { |
| 1188 | 1188 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
| 1189 | 1189 | } |
@@ -12,315 +12,315 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 34 | - ); |
|
| 35 | - |
|
| 36 | - $this->add_totals( $submission ); |
|
| 37 | - $this->add_texts( $submission ); |
|
| 38 | - $this->add_items( $submission ); |
|
| 39 | - $this->add_fees( $submission ); |
|
| 40 | - $this->add_discounts( $submission ); |
|
| 41 | - $this->add_taxes( $submission ); |
|
| 42 | - $this->add_gateways( $submission ); |
|
| 43 | - $this->add_data( $submission ); |
|
| 44 | - |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Adds totals to a response for submission refresh prices. |
|
| 49 | - * |
|
| 50 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 51 | - */ |
|
| 52 | - public function add_totals( $submission ) { |
|
| 53 | - |
|
| 54 | - $this->response = array_merge( |
|
| 55 | - $this->response, |
|
| 56 | - array( |
|
| 57 | - |
|
| 58 | - 'totals' => array( |
|
| 59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 65 | - ), |
|
| 66 | - |
|
| 67 | - 'recurring' => array( |
|
| 68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 73 | - ), |
|
| 74 | - |
|
| 75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 76 | - 'currency' => $submission->get_currency(), |
|
| 77 | - |
|
| 78 | - ) |
|
| 79 | - ); |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Adds texts to a response for submission refresh prices. |
|
| 85 | - * |
|
| 86 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 87 | - */ |
|
| 88 | - public function add_texts( $submission ) { |
|
| 89 | - |
|
| 90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 92 | - |
|
| 93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
| 94 | - |
|
| 95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 97 | - $main_item = reset( $groups ); |
|
| 98 | - |
|
| 99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 100 | - $payable = "$payable / $period"; |
|
| 101 | - } else if ( $main_item ) { |
|
| 102 | - |
|
| 103 | - $main_item = reset( $main_item ); |
|
| 104 | - |
|
| 105 | - // Calculate the next renewal date. |
|
| 106 | - $_period = $main_item->get_recurring_period( true ); |
|
| 107 | - $_interval = $main_item->get_recurring_interval(); |
|
| 108 | - |
|
| 109 | - // If the subscription item has a trial period... |
|
| 110 | - if ( $main_item->has_free_trial() ) { |
|
| 111 | - $_period = $main_item->get_trial_period( true ); |
|
| 112 | - $_interval = $main_item->get_trial_interval(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $payable = sprintf( |
|
| 116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 117 | - $submission->format_amount( $submission->get_total() ), |
|
| 118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 119 | - $period |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - $payable .= sprintf( |
|
| 123 | - '<small class="text-muted form-text">%s</small>', |
|
| 124 | - sprintf( |
|
| 125 | - __( 'First renewal on %s', 'invoicing' ), |
|
| 126 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
| 127 | - ) |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - } else { |
|
| 131 | - $payable = sprintf( |
|
| 132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 133 | - $submission->format_amount( $submission->get_total() ), |
|
| 134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 135 | - $period |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $texts = array( |
|
| 142 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 143 | - ); |
|
| 144 | - |
|
| 145 | - foreach ( $submission->get_items() as $item ) { |
|
| 146 | - $item_id = $item->get_id(); |
|
| 147 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 148 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 149 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 153 | - |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Adds items to a response for submission refresh prices. |
|
| 158 | - * |
|
| 159 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 160 | - */ |
|
| 161 | - public function add_items( $submission ) { |
|
| 162 | - |
|
| 163 | - // Add items. |
|
| 164 | - $items = array(); |
|
| 34 | + ); |
|
| 35 | + |
|
| 36 | + $this->add_totals( $submission ); |
|
| 37 | + $this->add_texts( $submission ); |
|
| 38 | + $this->add_items( $submission ); |
|
| 39 | + $this->add_fees( $submission ); |
|
| 40 | + $this->add_discounts( $submission ); |
|
| 41 | + $this->add_taxes( $submission ); |
|
| 42 | + $this->add_gateways( $submission ); |
|
| 43 | + $this->add_data( $submission ); |
|
| 44 | + |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Adds totals to a response for submission refresh prices. |
|
| 49 | + * |
|
| 50 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 51 | + */ |
|
| 52 | + public function add_totals( $submission ) { |
|
| 53 | + |
|
| 54 | + $this->response = array_merge( |
|
| 55 | + $this->response, |
|
| 56 | + array( |
|
| 57 | + |
|
| 58 | + 'totals' => array( |
|
| 59 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 65 | + ), |
|
| 66 | + |
|
| 67 | + 'recurring' => array( |
|
| 68 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 73 | + ), |
|
| 74 | + |
|
| 75 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 76 | + 'currency' => $submission->get_currency(), |
|
| 77 | + |
|
| 78 | + ) |
|
| 79 | + ); |
|
| 80 | + |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Adds texts to a response for submission refresh prices. |
|
| 85 | + * |
|
| 86 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 87 | + */ |
|
| 88 | + public function add_texts( $submission ) { |
|
| 89 | + |
|
| 90 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
| 92 | + |
|
| 93 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
| 94 | + |
|
| 95 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 97 | + $main_item = reset( $groups ); |
|
| 98 | + |
|
| 99 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 100 | + $payable = "$payable / $period"; |
|
| 101 | + } else if ( $main_item ) { |
|
| 102 | + |
|
| 103 | + $main_item = reset( $main_item ); |
|
| 104 | + |
|
| 105 | + // Calculate the next renewal date. |
|
| 106 | + $_period = $main_item->get_recurring_period( true ); |
|
| 107 | + $_interval = $main_item->get_recurring_interval(); |
|
| 108 | + |
|
| 109 | + // If the subscription item has a trial period... |
|
| 110 | + if ( $main_item->has_free_trial() ) { |
|
| 111 | + $_period = $main_item->get_trial_period( true ); |
|
| 112 | + $_interval = $main_item->get_trial_interval(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $payable = sprintf( |
|
| 116 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 117 | + $submission->format_amount( $submission->get_total() ), |
|
| 118 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 119 | + $period |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + $payable .= sprintf( |
|
| 123 | + '<small class="text-muted form-text">%s</small>', |
|
| 124 | + sprintf( |
|
| 125 | + __( 'First renewal on %s', 'invoicing' ), |
|
| 126 | + getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
| 127 | + ) |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + } else { |
|
| 131 | + $payable = sprintf( |
|
| 132 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 133 | + $submission->format_amount( $submission->get_total() ), |
|
| 134 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 135 | + $period |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $texts = array( |
|
| 142 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 143 | + ); |
|
| 165 | 144 | |
| 166 | 145 | foreach ( $submission->get_items() as $item ) { |
| 167 | - $item_id = $item->get_id(); |
|
| 168 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 169 | - } |
|
| 146 | + $item_id = $item->get_id(); |
|
| 147 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 148 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 149 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 170 | 153 | |
| 171 | - $this->response = array_merge( |
|
| 172 | - $this->response, |
|
| 173 | - array( 'items' => $items ) |
|
| 174 | - ); |
|
| 154 | + } |
|
| 175 | 155 | |
| 176 | - } |
|
| 156 | + /** |
|
| 157 | + * Adds items to a response for submission refresh prices. |
|
| 158 | + * |
|
| 159 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 160 | + */ |
|
| 161 | + public function add_items( $submission ) { |
|
| 177 | 162 | |
| 178 | - /** |
|
| 179 | - * Adds fees to a response for submission refresh prices. |
|
| 180 | - * |
|
| 181 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 182 | - */ |
|
| 183 | - public function add_fees( $submission ) { |
|
| 163 | + // Add items. |
|
| 164 | + $items = array(); |
|
| 165 | + |
|
| 166 | + foreach ( $submission->get_items() as $item ) { |
|
| 167 | + $item_id = $item->get_id(); |
|
| 168 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 169 | + } |
|
| 184 | 170 | |
| 185 | - $fees = array(); |
|
| 171 | + $this->response = array_merge( |
|
| 172 | + $this->response, |
|
| 173 | + array( 'items' => $items ) |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Adds fees to a response for submission refresh prices. |
|
| 180 | + * |
|
| 181 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 182 | + */ |
|
| 183 | + public function add_fees( $submission ) { |
|
| 184 | + |
|
| 185 | + $fees = array(); |
|
| 186 | 186 | |
| 187 | 187 | foreach ( $submission->get_fees() as $name => $data ) { |
| 188 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 189 | - } |
|
| 188 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - $this->response = array_merge( |
|
| 192 | - $this->response, |
|
| 193 | - array( 'fees' => $fees ) |
|
| 194 | - ); |
|
| 191 | + $this->response = array_merge( |
|
| 192 | + $this->response, |
|
| 193 | + array( 'fees' => $fees ) |
|
| 194 | + ); |
|
| 195 | 195 | |
| 196 | - } |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Adds discounts to a response for submission refresh prices. |
|
| 200 | - * |
|
| 201 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 202 | - */ |
|
| 203 | - public function add_discounts( $submission ) { |
|
| 198 | + /** |
|
| 199 | + * Adds discounts to a response for submission refresh prices. |
|
| 200 | + * |
|
| 201 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 202 | + */ |
|
| 203 | + public function add_discounts( $submission ) { |
|
| 204 | 204 | |
| 205 | - $discounts = array(); |
|
| 205 | + $discounts = array(); |
|
| 206 | 206 | |
| 207 | 207 | foreach ( $submission->get_discounts() as $name => $data ) { |
| 208 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 209 | - } |
|
| 208 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - $this->response = array_merge( |
|
| 212 | - $this->response, |
|
| 213 | - array( 'discounts' => $discounts ) |
|
| 214 | - ); |
|
| 211 | + $this->response = array_merge( |
|
| 212 | + $this->response, |
|
| 213 | + array( 'discounts' => $discounts ) |
|
| 214 | + ); |
|
| 215 | 215 | |
| 216 | - } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * Adds taxes to a response for submission refresh prices. |
|
| 220 | - * |
|
| 221 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 222 | - */ |
|
| 223 | - public function add_taxes( $submission ) { |
|
| 224 | - |
|
| 225 | - $taxes = array(); |
|
| 226 | - $markup = ''; |
|
| 218 | + /** |
|
| 219 | + * Adds taxes to a response for submission refresh prices. |
|
| 220 | + * |
|
| 221 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 222 | + */ |
|
| 223 | + public function add_taxes( $submission ) { |
|
| 224 | + |
|
| 225 | + $taxes = array(); |
|
| 226 | + $markup = ''; |
|
| 227 | 227 | foreach ( $submission->get_taxes() as $name => $data ) { |
| 228 | - $name = sanitize_text_field( $name ); |
|
| 229 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 230 | - $taxes[$name] = $amount; |
|
| 231 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 235 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $this->response = array_merge( |
|
| 239 | - $this->response, |
|
| 240 | - array( 'taxes' => $taxes ) |
|
| 241 | - ); |
|
| 242 | - |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Adds gateways to a response for submission refresh prices. |
|
| 247 | - * |
|
| 248 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 249 | - */ |
|
| 250 | - public function add_gateways( $submission ) { |
|
| 251 | - |
|
| 252 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 253 | - |
|
| 254 | - if ( $this->response['has_recurring'] ) { |
|
| 255 | - |
|
| 256 | - foreach ( $gateways as $i => $gateway ) { |
|
| 257 | - |
|
| 258 | - if ( |
|
| 259 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 260 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 261 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 262 | - unset( $gateways[ $i ] ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 270 | - $this->response = array_merge( |
|
| 271 | - $this->response, |
|
| 272 | - array( 'gateways' => $gateways ) |
|
| 273 | - ); |
|
| 274 | - |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Standardizes prices. |
|
| 279 | - * |
|
| 280 | - * @param int $item_id |
|
| 281 | - * @param float $item_total |
|
| 282 | - * @param string $discount_code |
|
| 283 | - * @param bool $recurring |
|
| 284 | - */ |
|
| 285 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 286 | - |
|
| 287 | - $standardadized_price = $item_total; |
|
| 288 | - |
|
| 289 | - // Do we have a $discount_code? |
|
| 290 | - if ( ! empty( $discount_code ) ) { |
|
| 291 | - |
|
| 292 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 293 | - |
|
| 294 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 295 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - return max( 0, $standardadized_price ); |
|
| 301 | - |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Adds data to a response for submission refresh prices. |
|
| 306 | - * |
|
| 307 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 308 | - */ |
|
| 309 | - public function add_data( $submission ) { |
|
| 310 | - |
|
| 311 | - $this->response = array_merge( |
|
| 312 | - $this->response, |
|
| 313 | - array( |
|
| 314 | - 'js_data' => apply_filters( |
|
| 315 | - 'getpaid_submission_js_data', |
|
| 316 | - array( |
|
| 317 | - 'is_recurring' => $this->response['has_recurring'], |
|
| 318 | - ), |
|
| 319 | - $submission |
|
| 320 | - ) |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - |
|
| 324 | - } |
|
| 228 | + $name = sanitize_text_field( $name ); |
|
| 229 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 230 | + $taxes[$name] = $amount; |
|
| 231 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 235 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $this->response = array_merge( |
|
| 239 | + $this->response, |
|
| 240 | + array( 'taxes' => $taxes ) |
|
| 241 | + ); |
|
| 242 | + |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Adds gateways to a response for submission refresh prices. |
|
| 247 | + * |
|
| 248 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 249 | + */ |
|
| 250 | + public function add_gateways( $submission ) { |
|
| 251 | + |
|
| 252 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 253 | + |
|
| 254 | + if ( $this->response['has_recurring'] ) { |
|
| 255 | + |
|
| 256 | + foreach ( $gateways as $i => $gateway ) { |
|
| 257 | + |
|
| 258 | + if ( |
|
| 259 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 260 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 261 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 262 | + unset( $gateways[ $i ] ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 270 | + $this->response = array_merge( |
|
| 271 | + $this->response, |
|
| 272 | + array( 'gateways' => $gateways ) |
|
| 273 | + ); |
|
| 274 | + |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Standardizes prices. |
|
| 279 | + * |
|
| 280 | + * @param int $item_id |
|
| 281 | + * @param float $item_total |
|
| 282 | + * @param string $discount_code |
|
| 283 | + * @param bool $recurring |
|
| 284 | + */ |
|
| 285 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 286 | + |
|
| 287 | + $standardadized_price = $item_total; |
|
| 288 | + |
|
| 289 | + // Do we have a $discount_code? |
|
| 290 | + if ( ! empty( $discount_code ) ) { |
|
| 291 | + |
|
| 292 | + $discount = new WPInv_Discount( $discount_code ); |
|
| 293 | + |
|
| 294 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 295 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + return max( 0, $standardadized_price ); |
|
| 301 | + |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Adds data to a response for submission refresh prices. |
|
| 306 | + * |
|
| 307 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 308 | + */ |
|
| 309 | + public function add_data( $submission ) { |
|
| 310 | + |
|
| 311 | + $this->response = array_merge( |
|
| 312 | + $this->response, |
|
| 313 | + array( |
|
| 314 | + 'js_data' => apply_filters( |
|
| 315 | + 'getpaid_submission_js_data', |
|
| 316 | + array( |
|
| 317 | + 'is_recurring' => $this->response['has_recurring'], |
|
| 318 | + ), |
|
| 319 | + $submission |
|
| 320 | + ) |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | 326 | } |
@@ -13,94 +13,94 @@ discard block |
||
| 13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'paypal'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 1; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Stores line items to send to PayPal. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 37 | + * Stores line items to send to PayPal. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | 41 | protected $line_items = array(); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Endpoint for requests from PayPal. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $notify_url; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Endpoint for requests to PayPal. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 44 | + * Endpoint for requests from PayPal. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $notify_url; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Endpoint for requests to PayPal. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | 55 | protected $endpoint; |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Currencies this gateway is allowed for. |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 58 | + * Currencies this gateway is allowed for. |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a transaction. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 65 | + * URL to view a transaction. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * URL to view a subscription. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 72 | + * URL to view a subscription. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Class constructor. |
|
| 80 | - */ |
|
| 81 | - public function __construct() { |
|
| 79 | + * Class constructor. |
|
| 80 | + */ |
|
| 81 | + public function __construct() { |
|
| 82 | 82 | |
| 83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
| 84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
| 85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
| 86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
| 87 | 87 | |
| 88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
| 90 | 90 | |
| 91 | 91 | parent::__construct(); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * Process Payment. |
|
| 96 | - * |
|
| 97 | - * |
|
| 98 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 99 | - * @param array $submission_data Posted checkout fields. |
|
| 100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 95 | + * Process Payment. |
|
| 96 | + * |
|
| 97 | + * |
|
| 98 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 99 | + * @param array $submission_data Posted checkout fields. |
|
| 100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 104 | 104 | |
| 105 | 105 | // Get redirect url. |
| 106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | - * Get the PayPal request URL for an invoice. |
|
| 127 | - * |
|
| 128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function get_request_url( $invoice ) { |
|
| 126 | + * Get the PayPal request URL for an invoice. |
|
| 127 | + * |
|
| 128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function get_request_url( $invoice ) { |
|
| 132 | 132 | |
| 133 | 133 | // Endpoint for this request |
| 134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 135 | 135 | |
| 136 | 136 | // Retrieve paypal args. |
| 137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
| 146 | 146 | |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * Get PayPal Args for passing to PP. |
|
| 151 | - * |
|
| 152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - protected function get_paypal_args( $invoice ) { |
|
| 150 | + * Get PayPal Args for passing to PP. |
|
| 151 | + * |
|
| 152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + protected function get_paypal_args( $invoice ) { |
|
| 156 | 156 | |
| 157 | 157 | // Whether or not to send the line items as one item. |
| 158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
| 159 | - |
|
| 160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 161 | - $force_one_line_item = true; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $paypal_args = apply_filters( |
|
| 165 | - 'getpaid_paypal_args', |
|
| 166 | - array_merge( |
|
| 167 | - $this->get_transaction_args( $invoice ), |
|
| 168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 169 | - ), |
|
| 170 | - $invoice |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
| 159 | + |
|
| 160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 161 | + $force_one_line_item = true; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $paypal_args = apply_filters( |
|
| 165 | + 'getpaid_paypal_args', |
|
| 166 | + array_merge( |
|
| 167 | + $this->get_transaction_args( $invoice ), |
|
| 168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 169 | + ), |
|
| 170 | + $invoice |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | - * Get transaction args for paypal request. |
|
| 178 | - * |
|
| 179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 180 | - * @return array |
|
| 181 | - */ |
|
| 182 | - protected function get_transaction_args( $invoice ) { |
|
| 183 | - |
|
| 184 | - return array( |
|
| 177 | + * Get transaction args for paypal request. |
|
| 178 | + * |
|
| 179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 180 | + * @return array |
|
| 181 | + */ |
|
| 182 | + protected function get_transaction_args( $invoice ) { |
|
| 183 | + |
|
| 184 | + return array( |
|
| 185 | 185 | 'cmd' => '_cart', |
| 186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
| 187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | - * Get line item args for paypal request. |
|
| 210 | - * |
|
| 211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 209 | + * Get line item args for paypal request. |
|
| 210 | + * |
|
| 211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 216 | 216 | |
| 217 | 217 | // Maybe send invoice as a single item. |
| 218 | - if ( $force_one_line_item ) { |
|
| 218 | + if ( $force_one_line_item ) { |
|
| 219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
| 235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * Get line item args for paypal request as a single line item. |
|
| 244 | - * |
|
| 245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 246 | - * @return array |
|
| 247 | - */ |
|
| 248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 249 | - $this->delete_line_items(); |
|
| 243 | + * Get line item args for paypal request as a single line item. |
|
| 244 | + * |
|
| 245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 246 | + * @return array |
|
| 247 | + */ |
|
| 248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
| 249 | + $this->delete_line_items(); |
|
| 250 | 250 | |
| 251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
| 252 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 252 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 253 | 253 | |
| 254 | - return $this->get_line_items(); |
|
| 254 | + return $this->get_line_items(); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | - * Return all line items. |
|
| 259 | - */ |
|
| 260 | - protected function get_line_items() { |
|
| 261 | - return $this->line_items; |
|
| 262 | - } |
|
| 258 | + * Return all line items. |
|
| 259 | + */ |
|
| 260 | + protected function get_line_items() { |
|
| 261 | + return $this->line_items; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | 264 | /** |
| 265 | - * Remove all line items. |
|
| 266 | - */ |
|
| 267 | - protected function delete_line_items() { |
|
| 268 | - $this->line_items = array(); |
|
| 265 | + * Remove all line items. |
|
| 266 | + */ |
|
| 267 | + protected function delete_line_items() { |
|
| 268 | + $this->line_items = array(); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
| 272 | - * Prepare line items to send to paypal. |
|
| 273 | - * |
|
| 274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 275 | - */ |
|
| 276 | - protected function prepare_line_items( $invoice ) { |
|
| 277 | - $this->delete_line_items(); |
|
| 278 | - |
|
| 279 | - // Items. |
|
| 280 | - foreach ( $invoice->get_items() as $item ) { |
|
| 281 | - $amount = $item->get_price(); |
|
| 282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 272 | + * Prepare line items to send to paypal. |
|
| 273 | + * |
|
| 274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 275 | + */ |
|
| 276 | + protected function prepare_line_items( $invoice ) { |
|
| 277 | + $this->delete_line_items(); |
|
| 278 | + |
|
| 279 | + // Items. |
|
| 280 | + foreach ( $invoice->get_items() as $item ) { |
|
| 281 | + $amount = $item->get_price(); |
|
| 282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Fees. |
| 287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | - * Add PayPal Line Item. |
|
| 295 | - * |
|
| 296 | - * @param string $item_name Item name. |
|
| 297 | - * @param float $quantity Item quantity. |
|
| 298 | - * @param float $amount Amount. |
|
| 299 | - * @param string $item_number Item number. |
|
| 300 | - */ |
|
| 301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 303 | - |
|
| 304 | - $item = apply_filters( |
|
| 305 | - 'getpaid_paypal_line_item', |
|
| 306 | - array( |
|
| 307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 308 | - 'quantity' => (float) $quantity, |
|
| 309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 310 | - 'item_number' => $item_number, |
|
| 311 | - ), |
|
| 312 | - $item_name, |
|
| 313 | - $quantity, |
|
| 314 | - $amount, |
|
| 315 | - $item_number |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 294 | + * Add PayPal Line Item. |
|
| 295 | + * |
|
| 296 | + * @param string $item_name Item name. |
|
| 297 | + * @param float $quantity Item quantity. |
|
| 298 | + * @param float $amount Amount. |
|
| 299 | + * @param string $item_number Item number. |
|
| 300 | + */ |
|
| 301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 303 | + |
|
| 304 | + $item = apply_filters( |
|
| 305 | + 'getpaid_paypal_line_item', |
|
| 306 | + array( |
|
| 307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 308 | + 'quantity' => (float) $quantity, |
|
| 309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 310 | + 'item_number' => $item_number, |
|
| 311 | + ), |
|
| 312 | + $item_name, |
|
| 313 | + $quantity, |
|
| 314 | + $amount, |
|
| 315 | + $item_number |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
| 320 | 320 | |
| 321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 322 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 322 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
| 327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
| 328 | - * |
|
| 329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 330 | - * |
|
| 331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 336 | - $max_paypal_length = 2083; |
|
| 337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 338 | - |
|
| 339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 340 | - return $paypal_args; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return apply_filters( |
|
| 344 | - 'getpaid_paypal_args', |
|
| 345 | - array_merge( |
|
| 346 | - $this->get_transaction_args( $invoice ), |
|
| 347 | - $this->get_line_item_args( $invoice, true ) |
|
| 348 | - ), |
|
| 349 | - $invoice |
|
| 350 | - ); |
|
| 327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
| 328 | + * |
|
| 329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 330 | + * |
|
| 331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 336 | + $max_paypal_length = 2083; |
|
| 337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 338 | + |
|
| 339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 340 | + return $paypal_args; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return apply_filters( |
|
| 344 | + 'getpaid_paypal_args', |
|
| 345 | + array_merge( |
|
| 346 | + $this->get_transaction_args( $invoice ), |
|
| 347 | + $this->get_line_item_args( $invoice, true ) |
|
| 348 | + ), |
|
| 349 | + $invoice |
|
| 350 | + ); |
|
| 351 | 351 | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
| 355 | - * Processes recurring invoices. |
|
| 356 | - * |
|
| 357 | - * @param array $paypal_args PayPal args. |
|
| 358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 359 | - */ |
|
| 360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 355 | + * Processes recurring invoices. |
|
| 356 | + * |
|
| 357 | + * @param array $paypal_args PayPal args. |
|
| 358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 359 | + */ |
|
| 360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
| 361 | 361 | |
| 362 | 362 | // Make sure this is a subscription. |
| 363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
| 382 | 382 | |
| 383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 384 | 384 | |
| 385 | - // Trial period length. |
|
| 386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 385 | + // Trial period length. |
|
| 386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 387 | 387 | |
| 388 | - // Trial period. |
|
| 389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 388 | + // Trial period. |
|
| 389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 390 | 390 | |
| 391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
| 392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // We have a recurring payment |
| 412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 413 | 413 | |
| 414 | - // Subscription price |
|
| 415 | - $paypal_args['a3'] = $recurring_amount; |
|
| 414 | + // Subscription price |
|
| 415 | + $paypal_args['a3'] = $recurring_amount; |
|
| 416 | 416 | |
| 417 | - // Subscription duration |
|
| 418 | - $paypal_args['p3'] = $interval; |
|
| 417 | + // Subscription duration |
|
| 418 | + $paypal_args['p3'] = $interval; |
|
| 419 | 419 | |
| 420 | - // Subscription period |
|
| 421 | - $paypal_args['t3'] = $period; |
|
| 420 | + // Subscription period |
|
| 421 | + $paypal_args['t3'] = $period; |
|
| 422 | 422 | |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Recurring payments |
| 426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 427 | 427 | |
| 428 | - // Non-recurring payments |
|
| 429 | - $paypal_args['src'] = 0; |
|
| 428 | + // Non-recurring payments |
|
| 429 | + $paypal_args['src'] = 0; |
|
| 430 | 430 | |
| 431 | - } else { |
|
| 431 | + } else { |
|
| 432 | 432 | |
| 433 | - $paypal_args['src'] = 1; |
|
| 433 | + $paypal_args['src'] = 1; |
|
| 434 | 434 | |
| 435 | - if ( $bill_times > 0 ) { |
|
| 435 | + if ( $bill_times > 0 ) { |
|
| 436 | 436 | |
| 437 | - // An initial period is being used to charge a sign-up fee |
|
| 438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 439 | - $bill_times--; |
|
| 440 | - } |
|
| 437 | + // An initial period is being used to charge a sign-up fee |
|
| 438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 439 | + $bill_times--; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | 442 | // Make sure it's not over the max of 52 |
| 443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,19 +458,19 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | return apply_filters( |
| 461 | - 'getpaid_paypal_subscription_args', |
|
| 462 | - $paypal_args, |
|
| 463 | - $invoice |
|
| 461 | + 'getpaid_paypal_subscription_args', |
|
| 462 | + $paypal_args, |
|
| 463 | + $invoice |
|
| 464 | 464 | ); |
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
| 469 | - * Processes ipns and marks payments as complete. |
|
| 470 | - * |
|
| 471 | - * @return void |
|
| 472 | - */ |
|
| 473 | - public function verify_ipn() { |
|
| 469 | + * Processes ipns and marks payments as complete. |
|
| 470 | + * |
|
| 471 | + * @return void |
|
| 472 | + */ |
|
| 473 | + public function verify_ipn() { |
|
| 474 | 474 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
| 475 | 475 | } |
| 476 | 476 | |
@@ -480,10 +480,10 @@ discard block |
||
| 480 | 480 | public function sandbox_notice() { |
| 481 | 481 | |
| 482 | 482 | return sprintf( |
| 483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 484 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 485 | - '</a>' |
|
| 486 | - ); |
|
| 483 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 484 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 485 | + '</a>' |
|
| 486 | + ); |
|
| 487 | 487 | |
| 488 | 488 | } |
| 489 | 489 | |