@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wpinv_subscriptions_page() { |
| 16 | 16 | |
| 17 | - ?> |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,28 +22,28 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | - // Verify user permissions. |
|
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 25 | + // Verify user permissions. |
|
| 26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 27 | 27 | |
| 28 | - aui()->alert( |
|
| 28 | + aui()->alert( |
|
| 29 | 29 | array( |
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ), |
|
| 33 | - true |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ), |
|
| 33 | + true |
|
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | + } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 37 | 37 | |
| 38 | - // Display a single subscription. |
|
| 39 | - wpinv_recurring_subscription_details(); |
|
| 40 | - } else { |
|
| 38 | + // Display a single subscription. |
|
| 39 | + wpinv_recurring_subscription_details(); |
|
| 40 | + } else { |
|
| 41 | 41 | |
| 42 | - // Display a list of available subscriptions. |
|
| 43 | - getpaid_print_subscriptions_list(); |
|
| 44 | - } |
|
| 42 | + // Display a list of available subscriptions. |
|
| 43 | + getpaid_print_subscriptions_list(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - ?> |
|
| 46 | + ?> |
|
| 47 | 47 | |
| 48 | 48 | </div> |
| 49 | 49 | </div> |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function getpaid_print_subscriptions_list() { |
| 62 | 62 | |
| 63 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 64 | - $subscribers_table->prepare_items(); |
|
| 63 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 64 | + $subscribers_table->prepare_items(); |
|
| 65 | 65 | |
| 66 | - ?> |
|
| 66 | + ?> |
|
| 67 | 67 | <?php $subscribers_table->views(); ?> |
| 68 | 68 | <form id="subscribers-filter" class="bsui" method="get"> |
| 69 | 69 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
@@ -82,42 +82,42 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function wpinv_recurring_subscription_details() { |
| 84 | 84 | |
| 85 | - // Fetch the subscription. |
|
| 86 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 87 | - if ( ! $sub->exists() ) { |
|
| 85 | + // Fetch the subscription. |
|
| 86 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 87 | + if ( ! $sub->exists() ) { |
|
| 88 | 88 | |
| 89 | - aui()->alert( |
|
| 90 | - array( |
|
| 91 | - 'type' => 'danger', |
|
| 92 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 93 | - ), |
|
| 94 | - true |
|
| 95 | - ); |
|
| 89 | + aui()->alert( |
|
| 90 | + array( |
|
| 91 | + 'type' => 'danger', |
|
| 92 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 93 | + ), |
|
| 94 | + true |
|
| 95 | + ); |
|
| 96 | 96 | |
| 97 | - return; |
|
| 98 | - } |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - // Use metaboxes to display the subscription details. |
|
| 101 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 102 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | + // Use metaboxes to display the subscription details. |
|
| 101 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 102 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 103 | 103 | |
| 104 | - $subscription_id = $sub->get_id(); |
|
| 105 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 106 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 104 | + $subscription_id = $sub->get_id(); |
|
| 105 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 106 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 107 | 107 | |
| 108 | - if ( 1 < count( $subscription_groups ) ) { |
|
| 109 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 110 | - } |
|
| 108 | + if ( 1 < count( $subscription_groups ) ) { |
|
| 109 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - if ( ! empty( $subscription_group ) ) { |
|
| 113 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 114 | - } |
|
| 112 | + if ( ! empty( $subscription_group ) ) { |
|
| 113 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 116 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 117 | 117 | |
| 118 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 118 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 119 | 119 | |
| 120 | - ?> |
|
| 120 | + ?> |
|
| 121 | 121 | |
| 122 | 122 | <form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ) ); ?>"> |
| 123 | 123 | |
@@ -157,44 +157,44 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 159 | 159 | |
| 160 | - // Subscription items. |
|
| 161 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 162 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 163 | - |
|
| 164 | - // Prepare subscription detail columns. |
|
| 165 | - $fields = apply_filters( |
|
| 166 | - 'getpaid_subscription_admin_page_fields', |
|
| 167 | - array( |
|
| 168 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 169 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 170 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 171 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 172 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 173 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 174 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 175 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 176 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 177 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 178 | - ) |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - if ( ! $sub->is_active() ) { |
|
| 182 | - |
|
| 183 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 184 | - unset( $fields['renews_on'] ); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if ( isset( $fields['gateway'] ) ) { |
|
| 188 | - unset( $fields['gateway'] ); |
|
| 189 | - } |
|
| 160 | + // Subscription items. |
|
| 161 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 162 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 163 | + |
|
| 164 | + // Prepare subscription detail columns. |
|
| 165 | + $fields = apply_filters( |
|
| 166 | + 'getpaid_subscription_admin_page_fields', |
|
| 167 | + array( |
|
| 168 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 169 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 170 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 171 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 172 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 173 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 174 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 175 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 176 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 177 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 178 | + ) |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + if ( ! $sub->is_active() ) { |
|
| 182 | + |
|
| 183 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 184 | + unset( $fields['renews_on'] ); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if ( isset( $fields['gateway'] ) ) { |
|
| 188 | + unset( $fields['gateway'] ); |
|
| 189 | + } |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $profile_id = $sub->get_profile_id(); |
|
| 193 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 194 | - unset( $fields['profile_id'] ); |
|
| 195 | - } |
|
| 192 | + $profile_id = $sub->get_profile_id(); |
|
| 193 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 194 | + unset( $fields['profile_id'] ); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - ?> |
|
| 197 | + ?> |
|
| 198 | 198 | |
| 199 | 199 | <table class="table table-borderless" style="font-size: 14px;"> |
| 200 | 200 | <tbody> |
@@ -228,20 +228,20 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 230 | 230 | |
| 231 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 231 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 232 | 232 | |
| 233 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 234 | - if ( $user ) { |
|
| 233 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 234 | + if ( $user ) { |
|
| 235 | 235 | |
| 236 | - $username = sprintf( |
|
| 237 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 238 | - absint( $user->ID ), |
|
| 239 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 240 | - ); |
|
| 236 | + $username = sprintf( |
|
| 237 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 238 | + absint( $user->ID ), |
|
| 239 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 240 | + ); |
|
| 241 | 241 | |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - echo wp_kses_post( $username ); |
|
| 244 | + echo wp_kses_post( $username ); |
|
| 245 | 245 | } |
| 246 | 246 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 247 | 247 | |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | * @param WPInv_Subscription $subscription |
| 252 | 252 | */ |
| 253 | 253 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 254 | - $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
| 255 | - echo wp_kses_post( "<span>$amount</span>" ); |
|
| 254 | + $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
| 255 | + echo wp_kses_post( "<span>$amount</span>" ); |
|
| 256 | 256 | } |
| 257 | 257 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 258 | 258 | |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 265 | 265 | |
| 266 | - printf( |
|
| 267 | - '<a href="%s">#%s</a>', |
|
| 268 | - esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
| 269 | - absint( $subscription->get_id() ) |
|
| 270 | - ); |
|
| 266 | + printf( |
|
| 267 | + '<a href="%s">#%s</a>', |
|
| 268 | + esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
| 269 | + absint( $subscription->get_id() ) |
|
| 270 | + ); |
|
| 271 | 271 | |
| 272 | 272 | } |
| 273 | 273 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @param WPInv_Subscription $subscription |
| 279 | 279 | */ |
| 280 | 280 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 281 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 281 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 282 | 282 | } |
| 283 | 283 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
| 284 | 284 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @param WPInv_Subscription $subscription |
| 289 | 289 | */ |
| 290 | 290 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 291 | - echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
| 291 | + echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
| 292 | 292 | } |
| 293 | 293 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 294 | 294 | |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * @param WPInv_Subscription $subscription |
| 299 | 299 | */ |
| 300 | 300 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 301 | - $max_bills = $subscription->get_bill_times(); |
|
| 302 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 301 | + $max_bills = $subscription->get_bill_times(); |
|
| 302 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 303 | 303 | } |
| 304 | 304 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 305 | 305 | /** |
@@ -310,13 +310,13 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
| 312 | 312 | |
| 313 | - if ( empty( $subscription_group ) ) { |
|
| 314 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
| 315 | - return; |
|
| 316 | - } |
|
| 313 | + if ( empty( $subscription_group ) ) { |
|
| 314 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
| 315 | + return; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 319 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 318 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 319 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 320 | 320 | |
| 321 | 321 | } |
| 322 | 322 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -328,13 +328,13 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 330 | 330 | |
| 331 | - $gateway = $subscription->get_gateway(); |
|
| 331 | + $gateway = $subscription->get_gateway(); |
|
| 332 | 332 | |
| 333 | - if ( ! empty( $gateway ) ) { |
|
| 334 | - echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 335 | - } else { |
|
| 336 | - echo '—'; |
|
| 337 | - } |
|
| 333 | + if ( ! empty( $gateway ) ) { |
|
| 334 | + echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 335 | + } else { |
|
| 336 | + echo '—'; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | 339 | } |
| 340 | 340 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @param WPInv_Subscription $subscription |
| 346 | 346 | */ |
| 347 | 347 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 348 | - echo wp_kses_post( $subscription->get_status_label_html() ); |
|
| 348 | + echo wp_kses_post( $subscription->get_status_label_html() ); |
|
| 349 | 349 | } |
| 350 | 350 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 351 | 351 | |
@@ -356,27 +356,27 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 358 | 358 | |
| 359 | - $profile_id = $subscription->get_profile_id(); |
|
| 360 | - |
|
| 361 | - aui()->input( |
|
| 362 | - array( |
|
| 363 | - 'type' => 'text', |
|
| 364 | - 'id' => 'wpinv_subscription_profile_id', |
|
| 365 | - 'name' => 'wpinv_subscription_profile_id', |
|
| 366 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 367 | - 'label_type' => 'hidden', |
|
| 368 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 369 | - 'value' => esc_attr( $profile_id ), |
|
| 370 | - 'input_group_right' => '', |
|
| 371 | - 'no_wrap' => true, |
|
| 372 | - ), |
|
| 373 | - true |
|
| 374 | - ); |
|
| 375 | - |
|
| 376 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 377 | - if ( ! empty( $url ) ) { |
|
| 378 | - echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 379 | - } |
|
| 359 | + $profile_id = $subscription->get_profile_id(); |
|
| 360 | + |
|
| 361 | + aui()->input( |
|
| 362 | + array( |
|
| 363 | + 'type' => 'text', |
|
| 364 | + 'id' => 'wpinv_subscription_profile_id', |
|
| 365 | + 'name' => 'wpinv_subscription_profile_id', |
|
| 366 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 367 | + 'label_type' => 'hidden', |
|
| 368 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 369 | + 'value' => esc_attr( $profile_id ), |
|
| 370 | + 'input_group_right' => '', |
|
| 371 | + 'no_wrap' => true, |
|
| 372 | + ), |
|
| 373 | + true |
|
| 374 | + ); |
|
| 375 | + |
|
| 376 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 377 | + if ( ! empty( $url ) ) { |
|
| 378 | + echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | } |
| 382 | 382 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -388,40 +388,40 @@ discard block |
||
| 388 | 388 | */ |
| 389 | 389 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 390 | 390 | |
| 391 | - ?> |
|
| 391 | + ?> |
|
| 392 | 392 | <div class="mt-3"> |
| 393 | 393 | |
| 394 | 394 | <?php |
| 395 | - aui()->select( |
|
| 396 | - array( |
|
| 397 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 398 | - 'name' => 'subscription_status', |
|
| 399 | - 'id' => 'subscription_status_update_select', |
|
| 400 | - 'required' => true, |
|
| 401 | - 'no_wrap' => false, |
|
| 402 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 403 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 404 | - 'select2' => true, |
|
| 405 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 406 | - ), |
|
| 407 | - true |
|
| 408 | - ); |
|
| 409 | - ?> |
|
| 395 | + aui()->select( |
|
| 396 | + array( |
|
| 397 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 398 | + 'name' => 'subscription_status', |
|
| 399 | + 'id' => 'subscription_status_update_select', |
|
| 400 | + 'required' => true, |
|
| 401 | + 'no_wrap' => false, |
|
| 402 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 403 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 404 | + 'select2' => true, |
|
| 405 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 406 | + ), |
|
| 407 | + true |
|
| 408 | + ); |
|
| 409 | + ?> |
|
| 410 | 410 | |
| 411 | 411 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 412 | 412 | |
| 413 | 413 | <?php |
| 414 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 414 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 415 | 415 | |
| 416 | - $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 417 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 418 | - $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' ); |
|
| 416 | + $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 417 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 418 | + $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' ); |
|
| 419 | 419 | |
| 420 | - if ( $subscription->is_active() ) { |
|
| 421 | - echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
| 422 | - } |
|
| 420 | + if ( $subscription->is_active() ) { |
|
| 421 | + echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - echo '</div></div>'; |
|
| 424 | + echo '</div></div>'; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -432,33 +432,33 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
| 434 | 434 | |
| 435 | - $columns = apply_filters( |
|
| 436 | - 'getpaid_subscription_related_invoices_columns', |
|
| 437 | - array( |
|
| 438 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 439 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 440 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 441 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 442 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 443 | - ), |
|
| 444 | - $subscription |
|
| 445 | - ); |
|
| 446 | - |
|
| 447 | - // Prepare the invoices. |
|
| 448 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 449 | - $parent = $subscription->get_parent_invoice(); |
|
| 450 | - |
|
| 451 | - if ( $parent->exists() ) { |
|
| 452 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - $table_class = 'w-100 bg-white'; |
|
| 456 | - |
|
| 457 | - if ( ! is_admin() ) { |
|
| 458 | - $table_class = 'table table-bordered'; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - ?> |
|
| 435 | + $columns = apply_filters( |
|
| 436 | + 'getpaid_subscription_related_invoices_columns', |
|
| 437 | + array( |
|
| 438 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 439 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 440 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 441 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 442 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 443 | + ), |
|
| 444 | + $subscription |
|
| 445 | + ); |
|
| 446 | + |
|
| 447 | + // Prepare the invoices. |
|
| 448 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 449 | + $parent = $subscription->get_parent_invoice(); |
|
| 450 | + |
|
| 451 | + if ( $parent->exists() ) { |
|
| 452 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + $table_class = 'w-100 bg-white'; |
|
| 456 | + |
|
| 457 | + if ( ! is_admin() ) { |
|
| 458 | + $table_class = 'table table-bordered'; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + ?> |
|
| 462 | 462 | <div class="m-0" style="overflow: auto;"> |
| 463 | 463 | |
| 464 | 464 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -466,10 +466,10 @@ discard block |
||
| 466 | 466 | <thead> |
| 467 | 467 | <tr> |
| 468 | 468 | <?php |
| 469 | - foreach ( $columns as $key => $label ) { |
|
| 470 | - echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 471 | - } |
|
| 472 | - ?> |
|
| 469 | + foreach ( $columns as $key => $label ) { |
|
| 470 | + echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 471 | + } |
|
| 472 | + ?> |
|
| 473 | 473 | </tr> |
| 474 | 474 | </thead> |
| 475 | 475 | |
@@ -485,72 +485,72 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | <?php |
| 487 | 487 | |
| 488 | - foreach ( $payments as $payment ) : |
|
| 488 | + foreach ( $payments as $payment ) : |
|
| 489 | 489 | |
| 490 | - // Ensure that we have an invoice. |
|
| 491 | - $payment = new WPInv_Invoice( $payment ); |
|
| 490 | + // Ensure that we have an invoice. |
|
| 491 | + $payment = new WPInv_Invoice( $payment ); |
|
| 492 | 492 | |
| 493 | - // Abort if the invoice is invalid... |
|
| 494 | - if ( ! $payment->exists() ) { |
|
| 495 | - continue; |
|
| 496 | - } |
|
| 493 | + // Abort if the invoice is invalid... |
|
| 494 | + if ( ! $payment->exists() ) { |
|
| 495 | + continue; |
|
| 496 | + } |
|
| 497 | 497 | |
| 498 | - // ... or belongs to a different subscription. |
|
| 499 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 500 | - continue; |
|
| 501 | - } |
|
| 498 | + // ... or belongs to a different subscription. |
|
| 499 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 500 | + continue; |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - echo '<tr>'; |
|
| 503 | + echo '<tr>'; |
|
| 504 | 504 | |
| 505 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 505 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 506 | 506 | |
| 507 | - echo "<td class='p-2 text-left'>"; |
|
| 507 | + echo "<td class='p-2 text-left'>"; |
|
| 508 | 508 | |
| 509 | - switch ( $key ) { |
|
| 509 | + switch ( $key ) { |
|
| 510 | 510 | |
| 511 | - case 'total': |
|
| 512 | - echo '<strong>'; |
|
| 513 | - wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
| 514 | - echo '</strong>'; |
|
| 515 | - break; |
|
| 511 | + case 'total': |
|
| 512 | + echo '<strong>'; |
|
| 513 | + wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
| 514 | + echo '</strong>'; |
|
| 515 | + break; |
|
| 516 | 516 | |
| 517 | - case 'relationship': |
|
| 518 | - echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
| 519 | - break; |
|
| 517 | + case 'relationship': |
|
| 518 | + echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
| 519 | + break; |
|
| 520 | 520 | |
| 521 | - case 'date': |
|
| 522 | - echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
| 523 | - break; |
|
| 521 | + case 'date': |
|
| 522 | + echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
| 523 | + break; |
|
| 524 | 524 | |
| 525 | - case 'status': |
|
| 526 | - $status = $payment->get_status_nicename(); |
|
| 527 | - if ( is_admin() ) { |
|
| 528 | - $status = $payment->get_status_label_html(); |
|
| 529 | - } |
|
| 525 | + case 'status': |
|
| 526 | + $status = $payment->get_status_nicename(); |
|
| 527 | + if ( is_admin() ) { |
|
| 528 | + $status = $payment->get_status_label_html(); |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | - echo wp_kses_post( $status ); |
|
| 532 | - break; |
|
| 531 | + echo wp_kses_post( $status ); |
|
| 532 | + break; |
|
| 533 | 533 | |
| 534 | - case 'invoice': |
|
| 535 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 534 | + case 'invoice': |
|
| 535 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 536 | 536 | |
| 537 | - if ( ! is_admin() ) { |
|
| 538 | - $link = esc_url( $payment->get_view_url() ); |
|
| 539 | - } |
|
| 537 | + if ( ! is_admin() ) { |
|
| 538 | + $link = esc_url( $payment->get_view_url() ); |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | - $invoice = esc_html( $payment->get_number() ); |
|
| 542 | - echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
| 543 | - break; |
|
| 544 | - } |
|
| 541 | + $invoice = esc_html( $payment->get_number() ); |
|
| 542 | + echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
| 543 | + break; |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - echo '</td>'; |
|
| 546 | + echo '</td>'; |
|
| 547 | 547 | |
| 548 | - } |
|
| 548 | + } |
|
| 549 | 549 | |
| 550 | - echo '</tr>'; |
|
| 550 | + echo '</tr>'; |
|
| 551 | 551 | |
| 552 | - endforeach; |
|
| 553 | - ?> |
|
| 552 | + endforeach; |
|
| 553 | + ?> |
|
| 554 | 554 | |
| 555 | 555 | </tbody> |
| 556 | 556 | |
@@ -568,42 +568,42 @@ discard block |
||
| 568 | 568 | */ |
| 569 | 569 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
| 570 | 570 | |
| 571 | - // Fetch the subscription group. |
|
| 572 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 571 | + // Fetch the subscription group. |
|
| 572 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 573 | 573 | |
| 574 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 575 | - return; |
|
| 576 | - } |
|
| 574 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 575 | + return; |
|
| 576 | + } |
|
| 577 | 577 | |
| 578 | - // Prepare table columns. |
|
| 579 | - $columns = apply_filters( |
|
| 580 | - 'getpaid_subscription_item_details_columns', |
|
| 581 | - array( |
|
| 582 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
| 583 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 584 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 585 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 586 | - //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 587 | - 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
| 588 | - ), |
|
| 589 | - $subscription |
|
| 590 | - ); |
|
| 578 | + // Prepare table columns. |
|
| 579 | + $columns = apply_filters( |
|
| 580 | + 'getpaid_subscription_item_details_columns', |
|
| 581 | + array( |
|
| 582 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
| 583 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 584 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
| 585 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
| 586 | + //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 587 | + 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
| 588 | + ), |
|
| 589 | + $subscription |
|
| 590 | + ); |
|
| 591 | 591 | |
| 592 | - // Prepare the invoices. |
|
| 592 | + // Prepare the invoices. |
|
| 593 | 593 | |
| 594 | - $invoice = $subscription->get_parent_invoice(); |
|
| 594 | + $invoice = $subscription->get_parent_invoice(); |
|
| 595 | 595 | |
| 596 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 597 | - unset( $columns['tax'] ); |
|
| 598 | - } |
|
| 596 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 597 | + unset( $columns['tax'] ); |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - $table_class = 'w-100 bg-white'; |
|
| 600 | + $table_class = 'w-100 bg-white'; |
|
| 601 | 601 | |
| 602 | - if ( ! is_admin() ) { |
|
| 603 | - $table_class = 'table table-bordered'; |
|
| 604 | - } |
|
| 602 | + if ( ! is_admin() ) { |
|
| 603 | + $table_class = 'table table-bordered'; |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - ?> |
|
| 606 | + ?> |
|
| 607 | 607 | <div class="m-0" style="overflow: auto;"> |
| 608 | 608 | |
| 609 | 609 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -612,10 +612,10 @@ discard block |
||
| 612 | 612 | <tr> |
| 613 | 613 | <?php |
| 614 | 614 | |
| 615 | - foreach ( $columns as $key => $label ) { |
|
| 616 | - echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 617 | - } |
|
| 618 | - ?> |
|
| 615 | + foreach ( $columns as $key => $label ) { |
|
| 616 | + echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 617 | + } |
|
| 618 | + ?> |
|
| 619 | 619 | </tr> |
| 620 | 620 | </thead> |
| 621 | 621 | |
@@ -623,106 +623,106 @@ discard block |
||
| 623 | 623 | |
| 624 | 624 | <?php |
| 625 | 625 | |
| 626 | - foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
| 626 | + foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
| 627 | 627 | |
| 628 | - echo '<tr>'; |
|
| 628 | + echo '<tr>'; |
|
| 629 | 629 | |
| 630 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 630 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 631 | 631 | |
| 632 | - $class = 'text-left'; |
|
| 632 | + $class = 'text-left'; |
|
| 633 | 633 | |
| 634 | - echo "<td class='p-2 text-left'>"; |
|
| 634 | + echo "<td class='p-2 text-left'>"; |
|
| 635 | 635 | |
| 636 | - switch ( $key ) { |
|
| 636 | + switch ( $key ) { |
|
| 637 | 637 | |
| 638 | - case 'item_name': |
|
| 639 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 640 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 638 | + case 'item_name': |
|
| 639 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 640 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 641 | 641 | |
| 642 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 643 | - echo esc_html( $item_name ); |
|
| 644 | - } else { |
|
| 645 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 646 | - } |
|
| 642 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
| 643 | + echo esc_html( $item_name ); |
|
| 644 | + } else { |
|
| 645 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
| 646 | + } |
|
| 647 | 647 | |
| 648 | - break; |
|
| 648 | + break; |
|
| 649 | 649 | |
| 650 | - case 'price': |
|
| 651 | - wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
| 652 | - break; |
|
| 650 | + case 'price': |
|
| 651 | + wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
| 652 | + break; |
|
| 653 | 653 | |
| 654 | - case 'tax': |
|
| 655 | - wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 656 | - break; |
|
| 654 | + case 'tax': |
|
| 655 | + wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 656 | + break; |
|
| 657 | 657 | |
| 658 | - case 'discount': |
|
| 659 | - wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 660 | - break; |
|
| 658 | + case 'discount': |
|
| 659 | + wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 660 | + break; |
|
| 661 | 661 | |
| 662 | - case 'initial': |
|
| 663 | - wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
| 664 | - break; |
|
| 662 | + case 'initial': |
|
| 663 | + wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
| 664 | + break; |
|
| 665 | 665 | |
| 666 | - case 'recurring': |
|
| 667 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
| 668 | - break; |
|
| 666 | + case 'recurring': |
|
| 667 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
| 668 | + break; |
|
| 669 | 669 | |
| 670 | - } |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | - echo '</td>'; |
|
| 672 | + echo '</td>'; |
|
| 673 | 673 | |
| 674 | - } |
|
| 674 | + } |
|
| 675 | 675 | |
| 676 | - echo '</tr>'; |
|
| 676 | + echo '</tr>'; |
|
| 677 | 677 | |
| 678 | - endforeach; |
|
| 678 | + endforeach; |
|
| 679 | 679 | |
| 680 | - foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 680 | + foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 681 | 681 | |
| 682 | - echo '<tr>'; |
|
| 682 | + echo '<tr>'; |
|
| 683 | 683 | |
| 684 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 684 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 685 | 685 | |
| 686 | - $class = 'text-left'; |
|
| 686 | + $class = 'text-left'; |
|
| 687 | 687 | |
| 688 | - echo "<td class='p-2 text-left'>"; |
|
| 688 | + echo "<td class='p-2 text-left'>"; |
|
| 689 | 689 | |
| 690 | - switch ( $key ) { |
|
| 690 | + switch ( $key ) { |
|
| 691 | 691 | |
| 692 | - case 'item_name': |
|
| 693 | - echo esc_html( $subscription_group_fee['name'] ); |
|
| 694 | - break; |
|
| 692 | + case 'item_name': |
|
| 693 | + echo esc_html( $subscription_group_fee['name'] ); |
|
| 694 | + break; |
|
| 695 | 695 | |
| 696 | - case 'price': |
|
| 697 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 698 | - break; |
|
| 696 | + case 'price': |
|
| 697 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 698 | + break; |
|
| 699 | 699 | |
| 700 | - case 'tax': |
|
| 701 | - echo '—'; |
|
| 702 | - break; |
|
| 700 | + case 'tax': |
|
| 701 | + echo '—'; |
|
| 702 | + break; |
|
| 703 | 703 | |
| 704 | - case 'discount': |
|
| 705 | - echo '—'; |
|
| 706 | - break; |
|
| 704 | + case 'discount': |
|
| 705 | + echo '—'; |
|
| 706 | + break; |
|
| 707 | 707 | |
| 708 | - case 'initial': |
|
| 709 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 710 | - break; |
|
| 708 | + case 'initial': |
|
| 709 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 710 | + break; |
|
| 711 | 711 | |
| 712 | - case 'recurring': |
|
| 713 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
| 714 | - break; |
|
| 712 | + case 'recurring': |
|
| 713 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
| 714 | + break; |
|
| 715 | 715 | |
| 716 | - } |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - echo '</td>'; |
|
| 718 | + echo '</td>'; |
|
| 719 | 719 | |
| 720 | - } |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - echo '</tr>'; |
|
| 722 | + echo '</tr>'; |
|
| 723 | 723 | |
| 724 | - endforeach; |
|
| 725 | - ?> |
|
| 724 | + endforeach; |
|
| 725 | + ?> |
|
| 726 | 726 | |
| 727 | 727 | </tbody> |
| 728 | 728 | |
@@ -741,38 +741,38 @@ discard block |
||
| 741 | 741 | */ |
| 742 | 742 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
| 743 | 743 | |
| 744 | - // Fetch the subscription groups. |
|
| 745 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 746 | - |
|
| 747 | - if ( empty( $subscription_groups ) ) { |
|
| 748 | - return; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - // Prepare table columns. |
|
| 752 | - $columns = apply_filters( |
|
| 753 | - 'getpaid_subscription_related_subscriptions_columns', |
|
| 754 | - array( |
|
| 755 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 756 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 757 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 758 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 759 | - 'item' => __( 'Items', 'invoicing' ), |
|
| 760 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 761 | - ), |
|
| 762 | - $subscription |
|
| 763 | - ); |
|
| 764 | - |
|
| 765 | - if ( $subscription->get_status() == 'pending' ) { |
|
| 766 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - $table_class = 'w-100 bg-white'; |
|
| 770 | - |
|
| 771 | - if ( ! is_admin() ) { |
|
| 772 | - $table_class = 'table table-bordered'; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - ?> |
|
| 744 | + // Fetch the subscription groups. |
|
| 745 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 746 | + |
|
| 747 | + if ( empty( $subscription_groups ) ) { |
|
| 748 | + return; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + // Prepare table columns. |
|
| 752 | + $columns = apply_filters( |
|
| 753 | + 'getpaid_subscription_related_subscriptions_columns', |
|
| 754 | + array( |
|
| 755 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 756 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 757 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 758 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 759 | + 'item' => __( 'Items', 'invoicing' ), |
|
| 760 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 761 | + ), |
|
| 762 | + $subscription |
|
| 763 | + ); |
|
| 764 | + |
|
| 765 | + if ( $subscription->get_status() == 'pending' ) { |
|
| 766 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + $table_class = 'w-100 bg-white'; |
|
| 770 | + |
|
| 771 | + if ( ! is_admin() ) { |
|
| 772 | + $table_class = 'table table-bordered'; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + ?> |
|
| 776 | 776 | <div class="m-0" style="overflow: auto;"> |
| 777 | 777 | |
| 778 | 778 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -781,10 +781,10 @@ discard block |
||
| 781 | 781 | <tr> |
| 782 | 782 | <?php |
| 783 | 783 | |
| 784 | - foreach ( $columns as $key => $label ) { |
|
| 785 | - echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 786 | - } |
|
| 787 | - ?> |
|
| 784 | + foreach ( $columns as $key => $label ) { |
|
| 785 | + echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
| 786 | + } |
|
| 787 | + ?> |
|
| 788 | 788 | </tr> |
| 789 | 789 | </thead> |
| 790 | 790 | |
@@ -792,74 +792,74 @@ discard block |
||
| 792 | 792 | |
| 793 | 793 | <?php |
| 794 | 794 | |
| 795 | - foreach ( $subscription_groups as $subscription_group ) : |
|
| 795 | + foreach ( $subscription_groups as $subscription_group ) : |
|
| 796 | 796 | |
| 797 | - // Do not list current subscription. |
|
| 798 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 799 | - continue; |
|
| 800 | - } |
|
| 797 | + // Do not list current subscription. |
|
| 798 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 799 | + continue; |
|
| 800 | + } |
|
| 801 | 801 | |
| 802 | - // Ensure the subscription exists. |
|
| 803 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 802 | + // Ensure the subscription exists. |
|
| 803 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 804 | 804 | |
| 805 | - if ( ! $_suscription->exists() ) { |
|
| 806 | - continue; |
|
| 807 | - } |
|
| 805 | + if ( ! $_suscription->exists() ) { |
|
| 806 | + continue; |
|
| 807 | + } |
|
| 808 | 808 | |
| 809 | - echo '<tr>'; |
|
| 809 | + echo '<tr>'; |
|
| 810 | 810 | |
| 811 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 811 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 812 | 812 | |
| 813 | - $class = 'text-left'; |
|
| 813 | + $class = 'text-left'; |
|
| 814 | 814 | |
| 815 | - echo "<td class='p-2 text-left'>"; |
|
| 815 | + echo "<td class='p-2 text-left'>"; |
|
| 816 | 816 | |
| 817 | - switch ( $key ) { |
|
| 817 | + switch ( $key ) { |
|
| 818 | 818 | |
| 819 | - case 'status': |
|
| 820 | - echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
| 821 | - break; |
|
| 819 | + case 'status': |
|
| 820 | + echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
| 821 | + break; |
|
| 822 | 822 | |
| 823 | - case 'item': |
|
| 824 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 825 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 826 | - break; |
|
| 823 | + case 'item': |
|
| 824 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 825 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
| 826 | + break; |
|
| 827 | 827 | |
| 828 | - case 'renewals': |
|
| 829 | - $max_bills = $_suscription->get_bill_times(); |
|
| 830 | - echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 831 | - break; |
|
| 828 | + case 'renewals': |
|
| 829 | + $max_bills = $_suscription->get_bill_times(); |
|
| 830 | + echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
| 831 | + break; |
|
| 832 | 832 | |
| 833 | - case 'renewal_date': |
|
| 834 | - echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
| 835 | - break; |
|
| 833 | + case 'renewal_date': |
|
| 834 | + echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
| 835 | + break; |
|
| 836 | 836 | |
| 837 | - case 'start_date': |
|
| 838 | - echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
| 839 | - break; |
|
| 837 | + case 'start_date': |
|
| 838 | + echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
| 839 | + break; |
|
| 840 | 840 | |
| 841 | - case 'subscription': |
|
| 842 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 843 | - printf( |
|
| 841 | + case 'subscription': |
|
| 842 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 843 | + printf( |
|
| 844 | 844 | '%1$s#%2$s%3$s', |
| 845 | 845 | '<a href="' . esc_url( $url ) . '">', |
| 846 | 846 | '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
| 847 | - '</a>' |
|
| 847 | + '</a>' |
|
| 848 | 848 | ); |
| 849 | 849 | |
| 850 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
| 851 | - break; |
|
| 850 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
| 851 | + break; |
|
| 852 | 852 | |
| 853 | - } |
|
| 853 | + } |
|
| 854 | 854 | |
| 855 | - echo '</td>'; |
|
| 855 | + echo '</td>'; |
|
| 856 | 856 | |
| 857 | - } |
|
| 857 | + } |
|
| 858 | 858 | |
| 859 | - echo '</tr>'; |
|
| 859 | + echo '</tr>'; |
|
| 860 | 860 | |
| 861 | - endforeach; |
|
| 862 | - ?> |
|
| 861 | + endforeach; |
|
| 862 | + ?> |
|
| 863 | 863 | |
| 864 | 864 | </tbody> |
| 865 | 865 | |
@@ -126,14 +126,14 @@ |
||
| 126 | 126 | */ |
| 127 | 127 | function getpaid_doing_it_wrong( $function, $message, $version ) { |
| 128 | 128 | |
| 129 | - $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
| 130 | - |
|
| 131 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
| 132 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
| 133 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
| 134 | - } else { |
|
| 135 | - _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); |
|
| 136 | - } |
|
| 129 | + $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
| 130 | + |
|
| 131 | + if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
| 132 | + do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
| 133 | + error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
| 134 | + } else { |
|
| 135 | + _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | } |
| 139 | 139 | |
@@ -13,462 +13,462 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GetPaid_Payment_Gateway { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Set if the place checkout button should be renamed on selection. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $checkout_button_text; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Boolean whether the method is enabled. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - public $enabled = true; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Payment method id. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Payment method order. |
|
| 39 | - * |
|
| 40 | - * @var int |
|
| 41 | - */ |
|
| 42 | - public $order = 10; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Payment method title for the frontend. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $title; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Payment method description for the frontend. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $description; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gateway title. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $method_title = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gateway description. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $method_description = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Countries this gateway is allowed for. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - public $countries; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Currencies this gateway is allowed for. |
|
| 81 | - * |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 84 | - public $currencies; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Currencies this gateway is not allowed for. |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - public $exclude_currencies; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | - * |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - public $max_amount = 0; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Optional URL to view a transaction. |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $view_transaction_url = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Optional URL to view a subscription. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - public $view_subscription_url = ''; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Optional label to show for "new payment method" in the payment |
|
| 116 | - * method/token selection radio selection. |
|
| 117 | - * |
|
| 118 | - * @var string |
|
| 119 | - */ |
|
| 120 | - public $new_method_label = ''; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Contains a user's saved tokens for this gateway. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $tokens = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * An array of features that this gateway supports. |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - protected $supports = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Class constructor. |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - |
|
| 141 | - // Register gateway. |
|
| 142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | - |
|
| 144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | - |
|
| 146 | - // Add support for various features. |
|
| 147 | - foreach ( $this->supports as $feature ) { |
|
| 148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Invoice addons. |
|
| 154 | - if ( $this->supports( 'addons' ) ) { |
|
| 155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // Gateway settings. |
|
| 159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 160 | - |
|
| 161 | - // Gateway checkout fiellds. |
|
| 162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 163 | - |
|
| 164 | - // Process payment. |
|
| 165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 166 | - |
|
| 167 | - // Change the checkout button text. |
|
| 168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // Check if a gateway is valid for a given currency. |
|
| 173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 174 | - |
|
| 175 | - // Generate the transaction url. |
|
| 176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 177 | - |
|
| 178 | - // Generate the subscription url. |
|
| 179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 180 | - |
|
| 181 | - // Confirm payments. |
|
| 182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 183 | - |
|
| 184 | - // Verify IPNs. |
|
| 185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Checks if this gateway is a given gateway. |
|
| 191 | - * |
|
| 192 | - * @since 1.0.19 |
|
| 193 | - * @return bool |
|
| 194 | - */ |
|
| 195 | - public function is( $gateway ) { |
|
| 196 | - return $gateway == $this->id; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Returns a users saved tokens for this gateway. |
|
| 201 | - * |
|
| 202 | - * @since 1.0.19 |
|
| 203 | - * @return array |
|
| 204 | - */ |
|
| 205 | - public function get_tokens( $sandbox = null ) { |
|
| 206 | - |
|
| 207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 209 | - |
|
| 210 | - if ( is_array( $tokens ) ) { |
|
| 211 | - $this->tokens = $tokens; |
|
| 212 | - } |
|
| 16 | + /** |
|
| 17 | + * Set if the place checkout button should be renamed on selection. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $checkout_button_text; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Boolean whether the method is enabled. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + public $enabled = true; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Payment method id. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Payment method order. |
|
| 39 | + * |
|
| 40 | + * @var int |
|
| 41 | + */ |
|
| 42 | + public $order = 10; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Payment method title for the frontend. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $title; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Payment method description for the frontend. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $description; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gateway title. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $method_title = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gateway description. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $method_description = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Countries this gateway is allowed for. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + public $countries; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Currencies this gateway is allowed for. |
|
| 81 | + * |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | + public $currencies; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Currencies this gateway is not allowed for. |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + public $exclude_currencies; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | + * |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + public $max_amount = 0; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Optional URL to view a transaction. |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $view_transaction_url = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Optional URL to view a subscription. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + public $view_subscription_url = ''; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Optional label to show for "new payment method" in the payment |
|
| 116 | + * method/token selection radio selection. |
|
| 117 | + * |
|
| 118 | + * @var string |
|
| 119 | + */ |
|
| 120 | + public $new_method_label = ''; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Contains a user's saved tokens for this gateway. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $tokens = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * An array of features that this gateway supports. |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + protected $supports = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Class constructor. |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + |
|
| 141 | + // Register gateway. |
|
| 142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | + |
|
| 144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | + |
|
| 146 | + // Add support for various features. |
|
| 147 | + foreach ( $this->supports as $feature ) { |
|
| 148 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 149 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 150 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Invoice addons. |
|
| 154 | + if ( $this->supports( 'addons' ) ) { |
|
| 155 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // Gateway settings. |
|
| 159 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 160 | + |
|
| 161 | + // Gateway checkout fiellds. |
|
| 162 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 163 | + |
|
| 164 | + // Process payment. |
|
| 165 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 166 | + |
|
| 167 | + // Change the checkout button text. |
|
| 168 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 169 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // Check if a gateway is valid for a given currency. |
|
| 173 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 174 | + |
|
| 175 | + // Generate the transaction url. |
|
| 176 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 177 | + |
|
| 178 | + // Generate the subscription url. |
|
| 179 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 180 | + |
|
| 181 | + // Confirm payments. |
|
| 182 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 183 | + |
|
| 184 | + // Verify IPNs. |
|
| 185 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Checks if this gateway is a given gateway. |
|
| 191 | + * |
|
| 192 | + * @since 1.0.19 |
|
| 193 | + * @return bool |
|
| 194 | + */ |
|
| 195 | + public function is( $gateway ) { |
|
| 196 | + return $gateway == $this->id; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Returns a users saved tokens for this gateway. |
|
| 201 | + * |
|
| 202 | + * @since 1.0.19 |
|
| 203 | + * @return array |
|
| 204 | + */ |
|
| 205 | + public function get_tokens( $sandbox = null ) { |
|
| 206 | + |
|
| 207 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 208 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 209 | + |
|
| 210 | + if ( is_array( $tokens ) ) { |
|
| 211 | + $this->tokens = $tokens; |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( ! is_bool( $sandbox ) ) { |
|
| 216 | - return $this->tokens; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // Filter tokens. |
|
| 220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 221 | - return wp_list_filter( $this->tokens, $args ); |
|
| 222 | - |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Saves a token for this gateway. |
|
| 227 | - * |
|
| 228 | - * @since 1.0.19 |
|
| 229 | - */ |
|
| 230 | - public function save_token( $token ) { |
|
| 231 | - |
|
| 232 | - $tokens = $this->get_tokens(); |
|
| 233 | - $tokens[] = $token; |
|
| 234 | - |
|
| 235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 236 | - |
|
| 237 | - $this->tokens = $tokens; |
|
| 238 | - |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Return the title for admin screens. |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function get_method_title() { |
|
| 247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Return the description for admin screens. |
|
| 252 | - * |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public function get_method_description() { |
|
| 256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Get the success url. |
|
| 261 | - * |
|
| 262 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public function get_return_url( $invoice ) { |
|
| 266 | - |
|
| 267 | - // Payment success url |
|
| 268 | - $return_url = add_query_arg( |
|
| 269 | - array( |
|
| 270 | - 'payment-confirm' => $this->id, |
|
| 271 | - 'invoice_key' => $invoice->get_key(), |
|
| 272 | - 'utm_nooverride' => 1, |
|
| 273 | - ), |
|
| 274 | - wpinv_get_success_page_uri() |
|
| 275 | - ); |
|
| 276 | - |
|
| 277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Confirms payments when rendering the success page. |
|
| 282 | - * |
|
| 283 | - * @param string $content Success page content. |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - public function confirm_payment( $content ) { |
|
| 287 | - |
|
| 288 | - // Retrieve the invoice. |
|
| 289 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 291 | - |
|
| 292 | - // Ensure that it exists and that it is pending payment. |
|
| 293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 294 | - return $content; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Can the user view this invoice?? |
|
| 298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 299 | - return $content; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // Show payment processing indicator. |
|
| 303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Processes ipns and marks payments as complete. |
|
| 308 | - * |
|
| 309 | - * @return void |
|
| 310 | - */ |
|
| 311 | - public function verify_ipn() {} |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Processes invoice addons. |
|
| 315 | - * |
|
| 316 | - * @param WPInv_Invoice $invoice |
|
| 317 | - * @param GetPaid_Form_Item[] $items |
|
| 318 | - * @return WPInv_Invoice |
|
| 319 | - */ |
|
| 320 | - public function process_addons( $invoice, $items ) { |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 326 | - * |
|
| 327 | - * @param string $transaction_url transaction url. |
|
| 328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 329 | - * @return string transaction URL, or empty string. |
|
| 330 | - */ |
|
| 331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 332 | - |
|
| 333 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 334 | - |
|
| 335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - return $transaction_url; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 346 | - * |
|
| 347 | - * @param string $subscription_url transaction url. |
|
| 348 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 349 | - * @return string subscription URL, or empty string. |
|
| 350 | - */ |
|
| 351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 352 | - |
|
| 353 | - $profile_id = $subscription->get_profile_id(); |
|
| 354 | - |
|
| 355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 356 | - |
|
| 357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 360 | - |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $subscription_url; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Check if the gateway is available for use. |
|
| 368 | - * |
|
| 369 | - * @return bool |
|
| 370 | - */ |
|
| 371 | - public function is_available() { |
|
| 372 | - return ! empty( $this->enabled ); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Return the gateway's title. |
|
| 377 | - * |
|
| 378 | - * @return string |
|
| 379 | - */ |
|
| 380 | - public function get_title() { |
|
| 381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Return the gateway's description. |
|
| 386 | - * |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function get_description() { |
|
| 390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Process Payment. |
|
| 395 | - * |
|
| 396 | - * |
|
| 397 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 398 | - * @param array $submission_data Posted checkout fields. |
|
| 399 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 400 | - * @return void |
|
| 401 | - */ |
|
| 402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 403 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Process refund. |
|
| 409 | - * |
|
| 410 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 411 | - * a passed in amount. |
|
| 412 | - * |
|
| 413 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 414 | - * @param float $amount Refund amount. |
|
| 415 | - * @param string $reason Refund reason. |
|
| 416 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 417 | - */ |
|
| 418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Displays the payment fields, credit cards etc. |
|
| 424 | - * |
|
| 425 | - * @param int $invoice_id 0 or invoice id. |
|
| 426 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 427 | - */ |
|
| 428 | - public function payment_fields( $invoice_id, $form ) { |
|
| 429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Filters the gateway settings. |
|
| 434 | - * |
|
| 435 | - * @param array $admin_settings |
|
| 436 | - */ |
|
| 437 | - public function admin_settings( $admin_settings ) { |
|
| 438 | - return $admin_settings; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Retrieves the value of a gateway setting. |
|
| 443 | - * |
|
| 444 | - * @param string $option |
|
| 445 | - */ |
|
| 446 | - public function get_option( $option, $default = false ) { |
|
| 447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Check if a gateway supports a given feature. |
|
| 452 | - * |
|
| 453 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 454 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 455 | - * |
|
| 456 | - * @param string $feature string The name of a feature to test support for. |
|
| 457 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 458 | - * @since 1.0.19 |
|
| 459 | - */ |
|
| 460 | - public function supports( $feature ) { |
|
| 461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Returns the credit card form html. |
|
| 466 | - * |
|
| 467 | - * @param bool $save whether or not to display the save button. |
|
| 468 | - */ |
|
| 215 | + if ( ! is_bool( $sandbox ) ) { |
|
| 216 | + return $this->tokens; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // Filter tokens. |
|
| 220 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 221 | + return wp_list_filter( $this->tokens, $args ); |
|
| 222 | + |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Saves a token for this gateway. |
|
| 227 | + * |
|
| 228 | + * @since 1.0.19 |
|
| 229 | + */ |
|
| 230 | + public function save_token( $token ) { |
|
| 231 | + |
|
| 232 | + $tokens = $this->get_tokens(); |
|
| 233 | + $tokens[] = $token; |
|
| 234 | + |
|
| 235 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 236 | + |
|
| 237 | + $this->tokens = $tokens; |
|
| 238 | + |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Return the title for admin screens. |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function get_method_title() { |
|
| 247 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Return the description for admin screens. |
|
| 252 | + * |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public function get_method_description() { |
|
| 256 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Get the success url. |
|
| 261 | + * |
|
| 262 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public function get_return_url( $invoice ) { |
|
| 266 | + |
|
| 267 | + // Payment success url |
|
| 268 | + $return_url = add_query_arg( |
|
| 269 | + array( |
|
| 270 | + 'payment-confirm' => $this->id, |
|
| 271 | + 'invoice_key' => $invoice->get_key(), |
|
| 272 | + 'utm_nooverride' => 1, |
|
| 273 | + ), |
|
| 274 | + wpinv_get_success_page_uri() |
|
| 275 | + ); |
|
| 276 | + |
|
| 277 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Confirms payments when rendering the success page. |
|
| 282 | + * |
|
| 283 | + * @param string $content Success page content. |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + public function confirm_payment( $content ) { |
|
| 287 | + |
|
| 288 | + // Retrieve the invoice. |
|
| 289 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 290 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 291 | + |
|
| 292 | + // Ensure that it exists and that it is pending payment. |
|
| 293 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 294 | + return $content; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Can the user view this invoice?? |
|
| 298 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 299 | + return $content; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // Show payment processing indicator. |
|
| 303 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Processes ipns and marks payments as complete. |
|
| 308 | + * |
|
| 309 | + * @return void |
|
| 310 | + */ |
|
| 311 | + public function verify_ipn() {} |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Processes invoice addons. |
|
| 315 | + * |
|
| 316 | + * @param WPInv_Invoice $invoice |
|
| 317 | + * @param GetPaid_Form_Item[] $items |
|
| 318 | + * @return WPInv_Invoice |
|
| 319 | + */ |
|
| 320 | + public function process_addons( $invoice, $items ) { |
|
| 321 | + |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 326 | + * |
|
| 327 | + * @param string $transaction_url transaction url. |
|
| 328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 329 | + * @return string transaction URL, or empty string. |
|
| 330 | + */ |
|
| 331 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 332 | + |
|
| 333 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 334 | + |
|
| 335 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 336 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 337 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 338 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + return $transaction_url; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 346 | + * |
|
| 347 | + * @param string $subscription_url transaction url. |
|
| 348 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 349 | + * @return string subscription URL, or empty string. |
|
| 350 | + */ |
|
| 351 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 352 | + |
|
| 353 | + $profile_id = $subscription->get_profile_id(); |
|
| 354 | + |
|
| 355 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 356 | + |
|
| 357 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 358 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 359 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 360 | + |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $subscription_url; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Check if the gateway is available for use. |
|
| 368 | + * |
|
| 369 | + * @return bool |
|
| 370 | + */ |
|
| 371 | + public function is_available() { |
|
| 372 | + return ! empty( $this->enabled ); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Return the gateway's title. |
|
| 377 | + * |
|
| 378 | + * @return string |
|
| 379 | + */ |
|
| 380 | + public function get_title() { |
|
| 381 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Return the gateway's description. |
|
| 386 | + * |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function get_description() { |
|
| 390 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Process Payment. |
|
| 395 | + * |
|
| 396 | + * |
|
| 397 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 398 | + * @param array $submission_data Posted checkout fields. |
|
| 399 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 400 | + * @return void |
|
| 401 | + */ |
|
| 402 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 403 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 404 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Process refund. |
|
| 409 | + * |
|
| 410 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 411 | + * a passed in amount. |
|
| 412 | + * |
|
| 413 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 414 | + * @param float $amount Refund amount. |
|
| 415 | + * @param string $reason Refund reason. |
|
| 416 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 417 | + */ |
|
| 418 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 419 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Displays the payment fields, credit cards etc. |
|
| 424 | + * |
|
| 425 | + * @param int $invoice_id 0 or invoice id. |
|
| 426 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 427 | + */ |
|
| 428 | + public function payment_fields( $invoice_id, $form ) { |
|
| 429 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Filters the gateway settings. |
|
| 434 | + * |
|
| 435 | + * @param array $admin_settings |
|
| 436 | + */ |
|
| 437 | + public function admin_settings( $admin_settings ) { |
|
| 438 | + return $admin_settings; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Retrieves the value of a gateway setting. |
|
| 443 | + * |
|
| 444 | + * @param string $option |
|
| 445 | + */ |
|
| 446 | + public function get_option( $option, $default = false ) { |
|
| 447 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Check if a gateway supports a given feature. |
|
| 452 | + * |
|
| 453 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 454 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 455 | + * |
|
| 456 | + * @param string $feature string The name of a feature to test support for. |
|
| 457 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 458 | + * @since 1.0.19 |
|
| 459 | + */ |
|
| 460 | + public function supports( $feature ) { |
|
| 461 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Returns the credit card form html. |
|
| 466 | + * |
|
| 467 | + * @param bool $save whether or not to display the save button. |
|
| 468 | + */ |
|
| 469 | 469 | public function get_cc_form( $save = false ) { |
| 470 | 470 | |
| 471 | - ob_start(); |
|
| 471 | + ob_start(); |
|
| 472 | 472 | |
| 473 | 473 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 474 | 474 | |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | <?php |
| 530 | 530 | foreach ( $months as $key => $month ) { |
| 531 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . "</option>" . PHP_EOL; |
|
| 531 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . "</option>" . PHP_EOL; |
|
| 532 | 532 | } |
| 533 | 533 | ?> |
| 534 | 534 | |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | <?php |
| 543 | 543 | foreach ( $years as $key => $year ) { |
| 544 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . "</option>" . PHP_EOL; |
|
| 544 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . "</option>" . PHP_EOL; |
|
| 545 | 545 | } |
| 546 | 546 | ?> |
| 547 | 547 | |
@@ -559,13 +559,13 @@ discard block |
||
| 559 | 559 | 'name' => $this->id . '[cc_cvv2]', |
| 560 | 560 | 'id' => "$id_prefix-cc-cvv2", |
| 561 | 561 | 'label' => __( 'CCV', 'invoicing' ), |
| 562 | - 'label_type' => 'vertical', |
|
| 563 | - 'class' => 'form-control-sm', |
|
| 564 | - 'extra_attributes' => array( |
|
| 565 | - 'autocomplete' => 'cc-csc', |
|
| 566 | - ), |
|
| 562 | + 'label_type' => 'vertical', |
|
| 563 | + 'class' => 'form-control-sm', |
|
| 564 | + 'extra_attributes' => array( |
|
| 565 | + 'autocomplete' => 'cc-csc', |
|
| 566 | + ), |
|
| 567 | 567 | ), |
| 568 | - true |
|
| 568 | + true |
|
| 569 | 569 | ); |
| 570 | 570 | ?> |
| 571 | 571 | </div> |
@@ -574,192 +574,192 @@ discard block |
||
| 574 | 574 | |
| 575 | 575 | <?php |
| 576 | 576 | |
| 577 | - if ( $save ) { |
|
| 578 | - $this->save_payment_method_checkbox(); |
|
| 579 | - } |
|
| 577 | + if ( $save ) { |
|
| 578 | + $this->save_payment_method_checkbox(); |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | - ?> |
|
| 581 | + ?> |
|
| 582 | 582 | </div> |
| 583 | 583 | |
| 584 | 584 | </div> |
| 585 | 585 | <?php |
| 586 | 586 | |
| 587 | - return ob_get_clean(); |
|
| 587 | + return ob_get_clean(); |
|
| 588 | + |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * Displays a new payment method entry form. |
|
| 593 | + * |
|
| 594 | + * @since 1.0.19 |
|
| 595 | + */ |
|
| 596 | + public function new_payment_method_entry( $form ) { |
|
| 597 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . " . </div>"; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Grab and display our saved payment methods. |
|
| 602 | + * |
|
| 603 | + * @since 1.0.19 |
|
| 604 | + */ |
|
| 605 | + public function saved_payment_methods() { |
|
| 606 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 607 | + |
|
| 608 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 609 | + $this->get_saved_payment_method_option_html( $token ); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + $this->get_new_payment_method_option_html(); |
|
| 613 | + echo '</ul>'; |
|
| 588 | 614 | |
| 589 | 615 | } |
| 590 | 616 | |
| 591 | - /** |
|
| 592 | - * Displays a new payment method entry form. |
|
| 593 | - * |
|
| 594 | - * @since 1.0.19 |
|
| 595 | - */ |
|
| 596 | - public function new_payment_method_entry( $form ) { |
|
| 597 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . " . </div>"; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Grab and display our saved payment methods. |
|
| 602 | - * |
|
| 603 | - * @since 1.0.19 |
|
| 604 | - */ |
|
| 605 | - public function saved_payment_methods() { |
|
| 606 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 607 | - |
|
| 608 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 609 | - $this->get_saved_payment_method_option_html( $token ); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - $this->get_new_payment_method_option_html(); |
|
| 613 | - echo '</ul>'; |
|
| 614 | - |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Gets saved payment method HTML from a token. |
|
| 619 | - * |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - * @param array $token Payment Token. |
|
| 622 | - * @return string Generated payment method HTML |
|
| 623 | - */ |
|
| 624 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 625 | - |
|
| 626 | - printf( |
|
| 627 | - '<li class="getpaid-payment-method form-group"> |
|
| 617 | + /** |
|
| 618 | + * Gets saved payment method HTML from a token. |
|
| 619 | + * |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + * @param array $token Payment Token. |
|
| 622 | + * @return string Generated payment method HTML |
|
| 623 | + */ |
|
| 624 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 625 | + |
|
| 626 | + printf( |
|
| 627 | + '<li class="getpaid-payment-method form-group"> |
|
| 628 | 628 | <label> |
| 629 | 629 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 630 | 630 | <span>%3$s</span> |
| 631 | 631 | </label> |
| 632 | 632 | </li>', |
| 633 | - esc_attr( $this->id ), |
|
| 634 | - esc_attr( $token['id'] ), |
|
| 635 | - esc_html( $token['name'] ), |
|
| 636 | - checked( empty( $token['default'] ), false, false ), |
|
| 637 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
| 638 | - ); |
|
| 639 | - |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 644 | - * |
|
| 645 | - * @since 1.0.19 |
|
| 646 | - */ |
|
| 647 | - public function get_new_payment_method_option_html() { |
|
| 648 | - |
|
| 649 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 650 | - |
|
| 651 | - printf( |
|
| 652 | - '<li class="getpaid-new-payment-method"> |
|
| 633 | + esc_attr( $this->id ), |
|
| 634 | + esc_attr( $token['id'] ), |
|
| 635 | + esc_html( $token['name'] ), |
|
| 636 | + checked( empty( $token['default'] ), false, false ), |
|
| 637 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
| 638 | + ); |
|
| 639 | + |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 644 | + * |
|
| 645 | + * @since 1.0.19 |
|
| 646 | + */ |
|
| 647 | + public function get_new_payment_method_option_html() { |
|
| 648 | + |
|
| 649 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 650 | + |
|
| 651 | + printf( |
|
| 652 | + '<li class="getpaid-new-payment-method"> |
|
| 653 | 653 | <label> |
| 654 | 654 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
| 655 | 655 | <span>%2$s</span> |
| 656 | 656 | </label> |
| 657 | 657 | </li>', |
| 658 | - esc_attr( $this->id ), |
|
| 659 | - esc_html( $label ) |
|
| 660 | - ); |
|
| 661 | - |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 666 | - * |
|
| 667 | - * @since 1.0.19 |
|
| 668 | - */ |
|
| 669 | - public function save_payment_method_checkbox() { |
|
| 670 | - |
|
| 671 | - aui()->input( |
|
| 672 | - array( |
|
| 673 | - 'type' => 'checkbox', |
|
| 674 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 675 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 676 | - 'required' => false, |
|
| 677 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 678 | - 'value' => 'true', |
|
| 679 | - 'checked' => true, |
|
| 680 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 681 | - ), |
|
| 682 | - true |
|
| 683 | - ); |
|
| 684 | - |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * Registers the gateway. |
|
| 689 | - * |
|
| 690 | - * @return array |
|
| 691 | - */ |
|
| 692 | - public function register_gateway( $gateways ) { |
|
| 693 | - |
|
| 694 | - $gateways[ $this->id ] = array( |
|
| 695 | - |
|
| 696 | - 'admin_label' => $this->method_title, |
|
| 658 | + esc_attr( $this->id ), |
|
| 659 | + esc_html( $label ) |
|
| 660 | + ); |
|
| 661 | + |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 666 | + * |
|
| 667 | + * @since 1.0.19 |
|
| 668 | + */ |
|
| 669 | + public function save_payment_method_checkbox() { |
|
| 670 | + |
|
| 671 | + aui()->input( |
|
| 672 | + array( |
|
| 673 | + 'type' => 'checkbox', |
|
| 674 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 675 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 676 | + 'required' => false, |
|
| 677 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 678 | + 'value' => 'true', |
|
| 679 | + 'checked' => true, |
|
| 680 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 681 | + ), |
|
| 682 | + true |
|
| 683 | + ); |
|
| 684 | + |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * Registers the gateway. |
|
| 689 | + * |
|
| 690 | + * @return array |
|
| 691 | + */ |
|
| 692 | + public function register_gateway( $gateways ) { |
|
| 693 | + |
|
| 694 | + $gateways[ $this->id ] = array( |
|
| 695 | + |
|
| 696 | + 'admin_label' => $this->method_title, |
|
| 697 | 697 | 'checkout_label' => $this->title, |
| 698 | - 'ordering' => $this->order, |
|
| 698 | + 'ordering' => $this->order, |
|
| 699 | 699 | |
| 700 | - ); |
|
| 700 | + ); |
|
| 701 | 701 | |
| 702 | - return $gateways; |
|
| 702 | + return $gateways; |
|
| 703 | 703 | |
| 704 | - } |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | - /** |
|
| 707 | - * Checks whether or not this is a sandbox request. |
|
| 708 | - * |
|
| 709 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 710 | - * @return bool |
|
| 711 | - */ |
|
| 712 | - public function is_sandbox( $invoice = null ) { |
|
| 706 | + /** |
|
| 707 | + * Checks whether or not this is a sandbox request. |
|
| 708 | + * |
|
| 709 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 710 | + * @return bool |
|
| 711 | + */ |
|
| 712 | + public function is_sandbox( $invoice = null ) { |
|
| 713 | 713 | |
| 714 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 715 | - return $invoice->get_mode() == 'test'; |
|
| 716 | - } |
|
| 714 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 715 | + return $invoice->get_mode() == 'test'; |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - return wpinv_is_test_mode( $this->id ); |
|
| 718 | + return wpinv_is_test_mode( $this->id ); |
|
| 719 | 719 | |
| 720 | - } |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - /** |
|
| 723 | - * Renames the checkout button |
|
| 724 | - * |
|
| 725 | - * @return string |
|
| 726 | - */ |
|
| 727 | - public function rename_checkout_button() { |
|
| 728 | - return $this->checkout_button_text; |
|
| 729 | - } |
|
| 722 | + /** |
|
| 723 | + * Renames the checkout button |
|
| 724 | + * |
|
| 725 | + * @return string |
|
| 726 | + */ |
|
| 727 | + public function rename_checkout_button() { |
|
| 728 | + return $this->checkout_button_text; |
|
| 729 | + } |
|
| 730 | 730 | |
| 731 | - /** |
|
| 732 | - * Validate gateway currency |
|
| 733 | - * |
|
| 734 | - * @return bool |
|
| 735 | - */ |
|
| 736 | - public function validate_currency( $validation, $currency ) { |
|
| 731 | + /** |
|
| 732 | + * Validate gateway currency |
|
| 733 | + * |
|
| 734 | + * @return bool |
|
| 735 | + */ |
|
| 736 | + public function validate_currency( $validation, $currency ) { |
|
| 737 | 737 | |
| 738 | - // Required currencies. |
|
| 739 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 740 | - return false; |
|
| 741 | - } |
|
| 738 | + // Required currencies. |
|
| 739 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 740 | + return false; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | - // Excluded currencies. |
|
| 744 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 745 | - return false; |
|
| 746 | - } |
|
| 743 | + // Excluded currencies. |
|
| 744 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 745 | + return false; |
|
| 746 | + } |
|
| 747 | 747 | |
| 748 | - return $validation; |
|
| 749 | - } |
|
| 748 | + return $validation; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - /** |
|
| 752 | - * Displays an error |
|
| 753 | - * |
|
| 754 | - */ |
|
| 755 | - public function show_error( $code, $message, $type ) { |
|
| 751 | + /** |
|
| 752 | + * Displays an error |
|
| 753 | + * |
|
| 754 | + */ |
|
| 755 | + public function show_error( $code, $message, $type ) { |
|
| 756 | 756 | |
| 757 | - if ( is_admin() ) { |
|
| 758 | - getpaid_admin()->{"show_$type"}( $message ); |
|
| 759 | - } |
|
| 757 | + if ( is_admin() ) { |
|
| 758 | + getpaid_admin()->{"show_$type"}( $message ); |
|
| 759 | + } |
|
| 760 | 760 | |
| 761 | - wpinv_set_error( $code, $message, $type ); |
|
| 761 | + wpinv_set_error( $code, $message, $type ); |
|
| 762 | 762 | |
| 763 | - } |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | } |
@@ -12,49 +12,49 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function __construct() { |
|
| 20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
| 21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
| 22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
| 23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
| 24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
| 25 | - |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Registers the reports page. |
|
| 30 | - * |
|
| 31 | - */ |
|
| 32 | - public function register_reports_page() { |
|
| 33 | - |
|
| 34 | - add_submenu_page( |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function __construct() { |
|
| 20 | + add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
| 21 | + add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
| 22 | + add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
| 23 | + add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
| 24 | + add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
| 25 | + |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Registers the reports page. |
|
| 30 | + * |
|
| 31 | + */ |
|
| 32 | + public function register_reports_page() { |
|
| 33 | + |
|
| 34 | + add_submenu_page( |
|
| 35 | 35 | 'wpinv', |
| 36 | 36 | __( 'Reports', 'invoicing' ), |
| 37 | 37 | __( 'Reports', 'invoicing' ), |
| 38 | 38 | wpinv_get_capability(), |
| 39 | 39 | 'wpinv-reports', |
| 40 | 40 | array( $this, 'display_reports_page' ) |
| 41 | - ); |
|
| 41 | + ); |
|
| 42 | 42 | |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Displays the reports page. |
|
| 47 | - * |
|
| 48 | - */ |
|
| 49 | - public function display_reports_page() { |
|
| 45 | + /** |
|
| 46 | + * Displays the reports page. |
|
| 47 | + * |
|
| 48 | + */ |
|
| 49 | + public function display_reports_page() { |
|
| 50 | 50 | |
| 51 | - // Prepare variables. |
|
| 52 | - $tabs = $this->get_tabs(); |
|
| 53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
| 54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
| 51 | + // Prepare variables. |
|
| 52 | + $tabs = $this->get_tabs(); |
|
| 53 | + $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
| 54 | + $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
| 55 | 55 | |
| 56 | - // Display the current tab. |
|
| 57 | - ?> |
|
| 56 | + // Display the current tab. |
|
| 57 | + ?> |
|
| 58 | 58 | |
| 59 | 59 | <div class="wrap"> |
| 60 | 60 | |
@@ -63,19 +63,19 @@ discard block |
||
| 63 | 63 | <nav class="nav-tab-wrapper"> |
| 64 | 64 | |
| 65 | 65 | <?php |
| 66 | - foreach ( $tabs as $key => $label ) { |
|
| 66 | + foreach ( $tabs as $key => $label ) { |
|
| 67 | 67 | |
| 68 | - $key = sanitize_key( $key ); |
|
| 69 | - $label = esc_html( $label ); |
|
| 70 | - $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
| 71 | - $url = esc_url( |
|
| 68 | + $key = sanitize_key( $key ); |
|
| 69 | + $label = esc_html( $label ); |
|
| 70 | + $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
| 71 | + $url = esc_url( |
|
| 72 | 72 | add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | - echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
| 75 | + echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
| 76 | 76 | |
| 77 | - } |
|
| 78 | - ?> |
|
| 77 | + } |
|
| 78 | + ?> |
|
| 79 | 79 | |
| 80 | 80 | </nav> |
| 81 | 81 | |
@@ -86,82 +86,82 @@ discard block |
||
| 86 | 86 | </div> |
| 87 | 87 | <?php |
| 88 | 88 | |
| 89 | - // Wordfence loads an unsupported version of chart js on our page. |
|
| 90 | - wp_deregister_style( 'chart-js' ); |
|
| 91 | - wp_deregister_script( 'chart-js' ); |
|
| 92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
| 89 | + // Wordfence loads an unsupported version of chart js on our page. |
|
| 90 | + wp_deregister_style( 'chart-js' ); |
|
| 91 | + wp_deregister_script( 'chart-js' ); |
|
| 92 | + wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Retrieves reports page tabs. |
|
| 98 | - * |
|
| 99 | - * @return array |
|
| 100 | - */ |
|
| 101 | - public function get_tabs() { |
|
| 96 | + /** |
|
| 97 | + * Retrieves reports page tabs. |
|
| 98 | + * |
|
| 99 | + * @return array |
|
| 100 | + */ |
|
| 101 | + public function get_tabs() { |
|
| 102 | 102 | |
| 103 | - $tabs = array( |
|
| 104 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
| 105 | - 'export' => __( 'Export', 'invoicing' ), |
|
| 106 | - ); |
|
| 103 | + $tabs = array( |
|
| 104 | + 'reports' => __( 'Reports', 'invoicing' ), |
|
| 105 | + 'export' => __( 'Export', 'invoicing' ), |
|
| 106 | + ); |
|
| 107 | 107 | |
| 108 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
| 109 | - } |
|
| 108 | + return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Displays the reports tab. |
|
| 113 | - * |
|
| 114 | - */ |
|
| 115 | - public function display_reports_tab() { |
|
| 111 | + /** |
|
| 112 | + * Displays the reports tab. |
|
| 113 | + * |
|
| 114 | + */ |
|
| 115 | + public function display_reports_tab() { |
|
| 116 | 116 | |
| 117 | - $reports = new GetPaid_Reports_Report(); |
|
| 118 | - $reports->display(); |
|
| 117 | + $reports = new GetPaid_Reports_Report(); |
|
| 118 | + $reports->display(); |
|
| 119 | 119 | |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Displays the exports tab. |
|
| 124 | - * |
|
| 125 | - */ |
|
| 126 | - public function display_exports_tab() { |
|
| 122 | + /** |
|
| 123 | + * Displays the exports tab. |
|
| 124 | + * |
|
| 125 | + */ |
|
| 126 | + public function display_exports_tab() { |
|
| 127 | 127 | |
| 128 | - $exports = new GetPaid_Reports_Export(); |
|
| 129 | - $exports->display(); |
|
| 128 | + $exports = new GetPaid_Reports_Export(); |
|
| 129 | + $exports->display(); |
|
| 130 | 130 | |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Donwnloads a graph. |
|
| 135 | - * |
|
| 136 | - * @param array $args |
|
| 137 | - */ |
|
| 138 | - public function download_graph( $args ) { |
|
| 133 | + /** |
|
| 134 | + * Donwnloads a graph. |
|
| 135 | + * |
|
| 136 | + * @param array $args |
|
| 137 | + */ |
|
| 138 | + public function download_graph( $args ) { |
|
| 139 | 139 | |
| 140 | - if ( ! empty( $args['graph'] ) ) { |
|
| 141 | - $downloader = new GetPaid_Graph_Downloader(); |
|
| 142 | - $downloader->download( $args['graph'] ); |
|
| 143 | - } |
|
| 140 | + if ( ! empty( $args['graph'] ) ) { |
|
| 141 | + $downloader = new GetPaid_Graph_Downloader(); |
|
| 142 | + $downloader->download( $args['graph'] ); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Exports invoices. |
|
| 149 | - * |
|
| 150 | - * @param array $args |
|
| 151 | - */ |
|
| 152 | - public function export_invoices( $args ) { |
|
| 147 | + /** |
|
| 148 | + * Exports invoices. |
|
| 149 | + * |
|
| 150 | + * @param array $args |
|
| 151 | + */ |
|
| 152 | + public function export_invoices( $args ) { |
|
| 153 | 153 | |
| 154 | - if ( ! empty( $args['post_type'] ) ) { |
|
| 154 | + if ( ! empty( $args['post_type'] ) ) { |
|
| 155 | 155 | |
| 156 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
| 157 | - $downloader = new GetPaid_Subscription_Exporter(); |
|
| 158 | - } else { |
|
| 159 | - $downloader = new GetPaid_Invoice_Exporter(); |
|
| 160 | - } |
|
| 156 | + if ( 'subscriptions' === $args['post_type'] ) { |
|
| 157 | + $downloader = new GetPaid_Subscription_Exporter(); |
|
| 158 | + } else { |
|
| 159 | + $downloader = new GetPaid_Invoice_Exporter(); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - $downloader->export( $args['post_type'], $args ); |
|
| 163 | - } |
|
| 162 | + $downloader->export( $args['post_type'], $args ); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | } |
@@ -12,47 +12,47 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Export { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Displays the reports tab. |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function display() { |
|
| 20 | - |
|
| 21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
| 22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 23 | - $this->display_post_type_export( $post_type ); |
|
| 24 | - } |
|
| 25 | - $this->display_subscription_export(); |
|
| 26 | - echo '</div>'; |
|
| 27 | - |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Retrieves the download url. |
|
| 32 | - * |
|
| 33 | - */ |
|
| 34 | - public function get_download_url( $post_type ) { |
|
| 35 | - |
|
| 36 | - return wp_nonce_url( |
|
| 37 | - add_query_arg( |
|
| 38 | - array( |
|
| 39 | - 'getpaid-admin-action' => 'export_invoices', |
|
| 40 | - 'post_type' => urlencode( $post_type ), |
|
| 41 | - ) |
|
| 42 | - ), |
|
| 43 | - 'getpaid-nonce', |
|
| 44 | - 'getpaid-nonce' |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Displays a single post type export card. |
|
| 51 | - * |
|
| 52 | - */ |
|
| 53 | - public function display_post_type_export( $post_type ) { |
|
| 54 | - |
|
| 55 | - ?> |
|
| 15 | + /** |
|
| 16 | + * Displays the reports tab. |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function display() { |
|
| 20 | + |
|
| 21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
| 22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 23 | + $this->display_post_type_export( $post_type ); |
|
| 24 | + } |
|
| 25 | + $this->display_subscription_export(); |
|
| 26 | + echo '</div>'; |
|
| 27 | + |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Retrieves the download url. |
|
| 32 | + * |
|
| 33 | + */ |
|
| 34 | + public function get_download_url( $post_type ) { |
|
| 35 | + |
|
| 36 | + return wp_nonce_url( |
|
| 37 | + add_query_arg( |
|
| 38 | + array( |
|
| 39 | + 'getpaid-admin-action' => 'export_invoices', |
|
| 40 | + 'post_type' => urlencode( $post_type ), |
|
| 41 | + ) |
|
| 42 | + ), |
|
| 43 | + 'getpaid-nonce', |
|
| 44 | + 'getpaid-nonce' |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Displays a single post type export card. |
|
| 51 | + * |
|
| 52 | + */ |
|
| 53 | + public function display_post_type_export( $post_type ) { |
|
| 54 | + |
|
| 55 | + ?> |
|
| 56 | 56 | |
| 57 | 57 | <div class="col-12 col-md-6"> |
| 58 | 58 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | <div class="card-header"> |
| 61 | 61 | <strong> |
| 62 | 62 | <?php |
| 63 | - printf( |
|
| 64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
| 65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
| 66 | - ); |
|
| 67 | - ?> |
|
| 63 | + printf( |
|
| 64 | + esc_html__( 'Export %s', 'invoicing' ), |
|
| 65 | + esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
| 66 | + ); |
|
| 67 | + ?> |
|
| 68 | 68 | </strong> |
| 69 | 69 | </div> |
| 70 | 70 | |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
| 74 | 74 | |
| 75 | 75 | <?php |
| 76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
| 77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
| 78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
| 79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
| 80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
| 81 | - ?> |
|
| 76 | + $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
| 77 | + $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
| 78 | + $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
| 79 | + $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
| 80 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
| 81 | + ?> |
|
| 82 | 82 | |
| 83 | 83 | </form> |
| 84 | 84 | |
@@ -89,125 +89,125 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | <?php |
| 91 | 91 | |
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Generates the from date input field. |
|
| 96 | - * |
|
| 97 | - */ |
|
| 98 | - public function generate_from_date( $post_type ) { |
|
| 99 | - |
|
| 100 | - return aui()->input( |
|
| 101 | - array( |
|
| 102 | - 'name' => 'from_date', |
|
| 103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
| 104 | - 'placeholder' => 'yy-mm-dd', |
|
| 105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
| 106 | - 'label_type' => 'vertical', |
|
| 107 | - 'label_class' => 'd-block', |
|
| 108 | - 'type' => 'datepicker', |
|
| 109 | - ) |
|
| 110 | - ); |
|
| 111 | - |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Generates the to date input field. |
|
| 116 | - * |
|
| 117 | - */ |
|
| 118 | - public function generate_to_date( $post_type ) { |
|
| 119 | - |
|
| 120 | - return aui()->input( |
|
| 121 | - array( |
|
| 122 | - 'name' => 'to_date', |
|
| 123 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
| 124 | - 'placeholder' => 'yy-mm-dd', |
|
| 125 | - 'label' => __( 'To Date', 'invoicing' ), |
|
| 126 | - 'label_type' => 'vertical', |
|
| 127 | - 'label_class' => 'd-block', |
|
| 128 | - 'type' => 'datepicker', |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Generates the to post status select field. |
|
| 136 | - * |
|
| 137 | - */ |
|
| 138 | - public function generate_post_status_select( $post_type ) { |
|
| 139 | - |
|
| 140 | - if ( 'subscriptions' === $post_type ) { |
|
| 141 | - $options = getpaid_get_subscription_statuses(); |
|
| 142 | - } else { |
|
| 143 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return aui()->select( |
|
| 147 | - array( |
|
| 148 | - 'name' => 'status', |
|
| 149 | - 'id' => esc_attr( "$post_type-status" ), |
|
| 150 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
| 151 | - 'label' => __( 'Status', 'invoicing' ), |
|
| 152 | - 'label_type' => 'vertical', |
|
| 153 | - 'label_class' => 'd-block', |
|
| 154 | - 'options' => $options, |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Generates the to file type select field. |
|
| 162 | - * |
|
| 163 | - */ |
|
| 164 | - public function generate_file_type_select( $post_type ) { |
|
| 165 | - |
|
| 166 | - return aui()->select( |
|
| 167 | - array( |
|
| 168 | - 'name' => 'file_type', |
|
| 169 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
| 170 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
| 171 | - 'label' => __( 'Export File', 'invoicing' ), |
|
| 172 | - 'label_type' => 'vertical', |
|
| 173 | - 'label_class' => 'd-block', |
|
| 174 | - 'options' => array( |
|
| 175 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
| 176 | - 'xml' => __( 'XML', 'invoicing' ), |
|
| 177 | - 'json' => __( 'JSON', 'invoicing' ), |
|
| 178 | - ), |
|
| 179 | - ) |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Displays a field's markup. |
|
| 186 | - * |
|
| 187 | - */ |
|
| 188 | - public function display_markup( $markup ) { |
|
| 189 | - |
|
| 190 | - echo wp_kses( |
|
| 191 | - str_replace( |
|
| 192 | - array( |
|
| 193 | - 'form-control', |
|
| 194 | - 'custom-select', |
|
| 195 | - ), |
|
| 196 | - 'regular-text', |
|
| 197 | - $markup |
|
| 198 | - ), |
|
| 199 | - getpaid_allowed_html() |
|
| 200 | - ); |
|
| 201 | - |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Displays a subscription export card. |
|
| 206 | - * |
|
| 207 | - */ |
|
| 208 | - public function display_subscription_export() { |
|
| 209 | - |
|
| 210 | - ?> |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Generates the from date input field. |
|
| 96 | + * |
|
| 97 | + */ |
|
| 98 | + public function generate_from_date( $post_type ) { |
|
| 99 | + |
|
| 100 | + return aui()->input( |
|
| 101 | + array( |
|
| 102 | + 'name' => 'from_date', |
|
| 103 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
| 104 | + 'placeholder' => 'yy-mm-dd', |
|
| 105 | + 'label' => __( 'From Date', 'invoicing' ), |
|
| 106 | + 'label_type' => 'vertical', |
|
| 107 | + 'label_class' => 'd-block', |
|
| 108 | + 'type' => 'datepicker', |
|
| 109 | + ) |
|
| 110 | + ); |
|
| 111 | + |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Generates the to date input field. |
|
| 116 | + * |
|
| 117 | + */ |
|
| 118 | + public function generate_to_date( $post_type ) { |
|
| 119 | + |
|
| 120 | + return aui()->input( |
|
| 121 | + array( |
|
| 122 | + 'name' => 'to_date', |
|
| 123 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
| 124 | + 'placeholder' => 'yy-mm-dd', |
|
| 125 | + 'label' => __( 'To Date', 'invoicing' ), |
|
| 126 | + 'label_type' => 'vertical', |
|
| 127 | + 'label_class' => 'd-block', |
|
| 128 | + 'type' => 'datepicker', |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Generates the to post status select field. |
|
| 136 | + * |
|
| 137 | + */ |
|
| 138 | + public function generate_post_status_select( $post_type ) { |
|
| 139 | + |
|
| 140 | + if ( 'subscriptions' === $post_type ) { |
|
| 141 | + $options = getpaid_get_subscription_statuses(); |
|
| 142 | + } else { |
|
| 143 | + $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return aui()->select( |
|
| 147 | + array( |
|
| 148 | + 'name' => 'status', |
|
| 149 | + 'id' => esc_attr( "$post_type-status" ), |
|
| 150 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
| 151 | + 'label' => __( 'Status', 'invoicing' ), |
|
| 152 | + 'label_type' => 'vertical', |
|
| 153 | + 'label_class' => 'd-block', |
|
| 154 | + 'options' => $options, |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Generates the to file type select field. |
|
| 162 | + * |
|
| 163 | + */ |
|
| 164 | + public function generate_file_type_select( $post_type ) { |
|
| 165 | + |
|
| 166 | + return aui()->select( |
|
| 167 | + array( |
|
| 168 | + 'name' => 'file_type', |
|
| 169 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
| 170 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
| 171 | + 'label' => __( 'Export File', 'invoicing' ), |
|
| 172 | + 'label_type' => 'vertical', |
|
| 173 | + 'label_class' => 'd-block', |
|
| 174 | + 'options' => array( |
|
| 175 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
| 176 | + 'xml' => __( 'XML', 'invoicing' ), |
|
| 177 | + 'json' => __( 'JSON', 'invoicing' ), |
|
| 178 | + ), |
|
| 179 | + ) |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Displays a field's markup. |
|
| 186 | + * |
|
| 187 | + */ |
|
| 188 | + public function display_markup( $markup ) { |
|
| 189 | + |
|
| 190 | + echo wp_kses( |
|
| 191 | + str_replace( |
|
| 192 | + array( |
|
| 193 | + 'form-control', |
|
| 194 | + 'custom-select', |
|
| 195 | + ), |
|
| 196 | + 'regular-text', |
|
| 197 | + $markup |
|
| 198 | + ), |
|
| 199 | + getpaid_allowed_html() |
|
| 200 | + ); |
|
| 201 | + |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Displays a subscription export card. |
|
| 206 | + * |
|
| 207 | + */ |
|
| 208 | + public function display_subscription_export() { |
|
| 209 | + |
|
| 210 | + ?> |
|
| 211 | 211 | |
| 212 | 212 | <div class="col-12 col-md-6"> |
| 213 | 213 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
| 224 | 224 | |
| 225 | 225 | <?php |
| 226 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
| 227 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
| 228 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
| 229 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
| 230 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
| 231 | - ?> |
|
| 226 | + $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
| 227 | + $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
| 228 | + $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
| 229 | + $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
| 230 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
| 231 | + ?> |
|
| 232 | 232 | |
| 233 | 233 | </form> |
| 234 | 234 | |
@@ -239,6 +239,6 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | <?php |
| 241 | 241 | |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | } |
@@ -12,218 +12,218 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Graph_Downloader { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Reports_Report |
|
| 17 | - */ |
|
| 18 | - public $handler; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - $this->handler = new GetPaid_Reports_Report(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Prepares the datastore handler. |
|
| 30 | - * |
|
| 31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
| 32 | - */ |
|
| 33 | - public function prepare_handler( $graph ) { |
|
| 34 | - |
|
| 35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return new $this->handler->views[ $graph ]['class'](); |
|
| 40 | - |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Prepares the output stream. |
|
| 45 | - * |
|
| 46 | - * @return resource |
|
| 47 | - */ |
|
| 48 | - public function prepare_output() { |
|
| 49 | - |
|
| 50 | - $output = fopen( 'php://output', 'w' ); |
|
| 51 | - |
|
| 52 | - if ( false === $output ) { |
|
| 53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $output; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Prepares the file type. |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function prepare_file_type( $graph ) { |
|
| 65 | - |
|
| 66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
| 67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
| 68 | - |
|
| 69 | - header( "Content-Type:application/$file_type" ); |
|
| 70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 71 | - |
|
| 72 | - return $file_type; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Handles the actual download. |
|
| 77 | - * |
|
| 78 | - */ |
|
| 79 | - public function download( $graph ) { |
|
| 80 | - global $wpdb; |
|
| 81 | - |
|
| 82 | - $handler = $this->prepare_handler( $graph ); |
|
| 83 | - $stream = $this->prepare_output(); |
|
| 84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | - $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | - |
|
| 88 | - if ( 'csv' == $file_type ) { |
|
| 89 | - $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | - } elseif ( 'xml' == $file_type ) { |
|
| 91 | - $this->download_xml( $stats, $stream, $headers ); |
|
| 92 | - } else { |
|
| 93 | - $this->download_json( $stats, $stream, $headers ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - fclose( $stream ); |
|
| 97 | - exit; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Downloads graph as csv |
|
| 102 | - * |
|
| 103 | - * @param array $stats The stats being downloaded. |
|
| 104 | - * @param resource $stream The stream to output to. |
|
| 105 | - * @param array $headers The fields to stream. |
|
| 106 | - * @since 1.0.19 |
|
| 107 | - */ |
|
| 108 | - public function download_csv( $stats, $stream, $headers ) { |
|
| 109 | - |
|
| 110 | - // Output the csv column headers. |
|
| 111 | - fputcsv( $stream, $headers ); |
|
| 112 | - |
|
| 113 | - // Loop through |
|
| 114 | - foreach ( $stats as $stat ) { |
|
| 115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | - $row = array_map( 'maybe_serialize', $row ); |
|
| 117 | - fputcsv( $stream, $row ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Downloads graph as json |
|
| 124 | - * |
|
| 125 | - * @param array $stats The stats being downloaded. |
|
| 126 | - * @param resource $stream The stream to output to. |
|
| 127 | - * @param array $headers The fields to stream. |
|
| 128 | - * @since 1.0.19 |
|
| 129 | - */ |
|
| 130 | - public function download_json( $stats, $stream, $headers ) { |
|
| 131 | - |
|
| 132 | - $prepared = array(); |
|
| 133 | - |
|
| 134 | - // Loop through |
|
| 135 | - foreach ( $stats as $stat ) { |
|
| 136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Downloads graph as xml |
|
| 145 | - * |
|
| 146 | - * @param array $stats The stats being downloaded. |
|
| 147 | - * @param resource $stream The stream to output to. |
|
| 148 | - * @param array $headers The fields to stream. |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - */ |
|
| 151 | - public function download_xml( $stats, $stream, $headers ) { |
|
| 152 | - |
|
| 153 | - $prepared = array(); |
|
| 154 | - |
|
| 155 | - // Loop through |
|
| 156 | - foreach ( $stats as $stat ) { |
|
| 157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
| 161 | - $this->convert_array_xml( $prepared, $xml ); |
|
| 162 | - |
|
| 163 | - fwrite( $stream, $xml->asXML() ); |
|
| 164 | - |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Converts stats array to xml |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - */ |
|
| 173 | - public function convert_array_xml( $data, $xml ) { |
|
| 174 | - |
|
| 175 | - // Loop through |
|
| 176 | - foreach ( $data as $key => $value ) { |
|
| 177 | - |
|
| 178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
| 179 | - |
|
| 180 | - if ( is_array( $value ) ) { |
|
| 181 | - |
|
| 182 | - if ( is_numeric( $key ) ) { |
|
| 183 | - $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $subnode = $xml->addChild( $key ); |
|
| 187 | - $this->convert_array_xml( $value, $subnode ); |
|
| 188 | - |
|
| 189 | - } else { |
|
| 190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 191 | - } |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Reports_Report |
|
| 17 | + */ |
|
| 18 | + public $handler; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + $this->handler = new GetPaid_Reports_Report(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Prepares the datastore handler. |
|
| 30 | + * |
|
| 31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
| 32 | + */ |
|
| 33 | + public function prepare_handler( $graph ) { |
|
| 34 | + |
|
| 35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | + wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return new $this->handler->views[ $graph ]['class'](); |
|
| 40 | + |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Prepares the output stream. |
|
| 45 | + * |
|
| 46 | + * @return resource |
|
| 47 | + */ |
|
| 48 | + public function prepare_output() { |
|
| 49 | + |
|
| 50 | + $output = fopen( 'php://output', 'w' ); |
|
| 51 | + |
|
| 52 | + if ( false === $output ) { |
|
| 53 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $output; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Prepares the file type. |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function prepare_file_type( $graph ) { |
|
| 65 | + |
|
| 66 | + $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
| 67 | + $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
| 68 | + |
|
| 69 | + header( "Content-Type:application/$file_type" ); |
|
| 70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 71 | + |
|
| 72 | + return $file_type; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Handles the actual download. |
|
| 77 | + * |
|
| 78 | + */ |
|
| 79 | + public function download( $graph ) { |
|
| 80 | + global $wpdb; |
|
| 81 | + |
|
| 82 | + $handler = $this->prepare_handler( $graph ); |
|
| 83 | + $stream = $this->prepare_output(); |
|
| 84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | + $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | + |
|
| 88 | + if ( 'csv' == $file_type ) { |
|
| 89 | + $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | + } elseif ( 'xml' == $file_type ) { |
|
| 91 | + $this->download_xml( $stats, $stream, $headers ); |
|
| 92 | + } else { |
|
| 93 | + $this->download_json( $stats, $stream, $headers ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + fclose( $stream ); |
|
| 97 | + exit; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Downloads graph as csv |
|
| 102 | + * |
|
| 103 | + * @param array $stats The stats being downloaded. |
|
| 104 | + * @param resource $stream The stream to output to. |
|
| 105 | + * @param array $headers The fields to stream. |
|
| 106 | + * @since 1.0.19 |
|
| 107 | + */ |
|
| 108 | + public function download_csv( $stats, $stream, $headers ) { |
|
| 109 | + |
|
| 110 | + // Output the csv column headers. |
|
| 111 | + fputcsv( $stream, $headers ); |
|
| 112 | + |
|
| 113 | + // Loop through |
|
| 114 | + foreach ( $stats as $stat ) { |
|
| 115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | + $row = array_map( 'maybe_serialize', $row ); |
|
| 117 | + fputcsv( $stream, $row ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Downloads graph as json |
|
| 124 | + * |
|
| 125 | + * @param array $stats The stats being downloaded. |
|
| 126 | + * @param resource $stream The stream to output to. |
|
| 127 | + * @param array $headers The fields to stream. |
|
| 128 | + * @since 1.0.19 |
|
| 129 | + */ |
|
| 130 | + public function download_json( $stats, $stream, $headers ) { |
|
| 131 | + |
|
| 132 | + $prepared = array(); |
|
| 133 | + |
|
| 134 | + // Loop through |
|
| 135 | + foreach ( $stats as $stat ) { |
|
| 136 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Downloads graph as xml |
|
| 145 | + * |
|
| 146 | + * @param array $stats The stats being downloaded. |
|
| 147 | + * @param resource $stream The stream to output to. |
|
| 148 | + * @param array $headers The fields to stream. |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + */ |
|
| 151 | + public function download_xml( $stats, $stream, $headers ) { |
|
| 152 | + |
|
| 153 | + $prepared = array(); |
|
| 154 | + |
|
| 155 | + // Loop through |
|
| 156 | + foreach ( $stats as $stat ) { |
|
| 157 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
| 161 | + $this->convert_array_xml( $prepared, $xml ); |
|
| 162 | + |
|
| 163 | + fwrite( $stream, $xml->asXML() ); |
|
| 164 | + |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Converts stats array to xml |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + */ |
|
| 173 | + public function convert_array_xml( $data, $xml ) { |
|
| 174 | + |
|
| 175 | + // Loop through |
|
| 176 | + foreach ( $data as $key => $value ) { |
|
| 177 | + |
|
| 178 | + $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
| 179 | + |
|
| 180 | + if ( is_array( $value ) ) { |
|
| 181 | + |
|
| 182 | + if ( is_numeric( $key ) ) { |
|
| 183 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $subnode = $xml->addChild( $key ); |
|
| 187 | + $this->convert_array_xml( $value, $subnode ); |
|
| 188 | + |
|
| 189 | + } else { |
|
| 190 | + $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 191 | + } |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Prepares a single row for download. |
|
| 198 | - * |
|
| 199 | - * @param stdClass|array $row The row to prepare.. |
|
| 200 | - * @param array $fields The fields to stream. |
|
| 201 | - * @since 1.0.19 |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function prepare_row( $row, $fields ) { |
|
| 196 | + /** |
|
| 197 | + * Prepares a single row for download. |
|
| 198 | + * |
|
| 199 | + * @param stdClass|array $row The row to prepare.. |
|
| 200 | + * @param array $fields The fields to stream. |
|
| 201 | + * @since 1.0.19 |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function prepare_row( $row, $fields ) { |
|
| 205 | 205 | |
| 206 | - $prepared = array(); |
|
| 207 | - $row = (array) $row; |
|
| 206 | + $prepared = array(); |
|
| 207 | + $row = (array) $row; |
|
| 208 | 208 | |
| 209 | - foreach ( $fields as $field ) { |
|
| 209 | + foreach ( $fields as $field ) { |
|
| 210 | 210 | |
| 211 | - if ( $field === 'total' ) { |
|
| 212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 213 | - continue; |
|
| 214 | - } |
|
| 211 | + if ( $field === 'total' ) { |
|
| 212 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 213 | + continue; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - if ( $field === 'total_raw' ) { |
|
| 217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 218 | - continue; |
|
| 219 | - } |
|
| 216 | + if ( $field === 'total_raw' ) { |
|
| 217 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 221 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - return $prepared; |
|
| 226 | - } |
|
| 225 | + return $prepared; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | - exit; |
|
| 7 | + exit; |
|
| 8 | 8 | } |
| 9 | 9 | add_ThickBox(); |
| 10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
| 14 | 14 | <?php if ( $tabs ) { ?> |
| 15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
| 16 | 16 | <?php |
| 17 | - foreach ( $tabs as $name => $label ) { |
|
| 18 | - echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
| 19 | - } |
|
| 20 | - do_action( 'wpi_addons_tabs' ); |
|
| 21 | - ?> |
|
| 17 | + foreach ( $tabs as $name => $label ) { |
|
| 18 | + echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
| 19 | + } |
|
| 20 | + do_action( 'wpi_addons_tabs' ); |
|
| 21 | + ?> |
|
| 22 | 22 | </nav> |
| 23 | 23 | |
| 24 | 24 | <?php |
| 25 | 25 | |
| 26 | - if ( $current_tab == 'membership' ) { |
|
| 26 | + if ( $current_tab == 'membership' ) { |
|
| 27 | 27 | |
| 28 | - ?> |
|
| 28 | + ?> |
|
| 29 | 29 | |
| 30 | 30 | <div class="wpi-membership-tab-conatiner"> |
| 31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | <h2><?php esc_html_e( 'Have a membership key?', 'invoicing' ); ?></h2> |
| 37 | 37 | <p> |
| 38 | 38 | <?php |
| 39 | - $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
| 40 | - echo wp_kses_post( $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ) ); |
|
| 41 | - ?> |
|
| 39 | + $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
| 40 | + echo wp_kses_post( $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ) ); |
|
| 41 | + ?> |
|
| 42 | 42 | </p> |
| 43 | 43 | <?php } ?> |
| 44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | <div class="feature-list"> |
| 49 | 49 | <ul> |
| 50 | 50 | <?php |
| 51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
| 52 | - if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
| 53 | - foreach ( $addons as $addon ) { |
|
| 54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - ?> |
|
| 51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
| 52 | + if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
| 53 | + foreach ( $addons as $addon ) { |
|
| 54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + ?> |
|
| 58 | 58 | </ul> |
| 59 | 59 | |
| 60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | <h3><?php esc_html_e( 'Included Gateways:', 'invoicing' ); ?></h3> |
| 66 | 66 | <ul> |
| 67 | 67 | <?php |
| 68 | - if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
| 69 | - foreach ( $addons as $addon ) { |
|
| 70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - ?> |
|
| 68 | + if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
| 69 | + foreach ( $addons as $addon ) { |
|
| 70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + ?> |
|
| 74 | 74 | </ul> |
| 75 | 75 | </div> |
| 76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | <div class="testimonial-content"> |
| 82 | 82 | <div class="t-image"> |
| 83 | 83 | <?php |
| 84 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 85 | - ?> |
|
| 84 | + echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 85 | + ?> |
|
| 86 | 86 | </div> |
| 87 | 87 | <div class="t-content"> |
| 88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | <div class="testimonial-content"> |
| 102 | 102 | <div class="t-image"> |
| 103 | 103 | <?php |
| 104 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 105 | - ?> |
|
| 104 | + echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 105 | + ?> |
|
| 106 | 106 | </div> |
| 107 | 107 | <div class="t-content"> |
| 108 | 108 | <p> |
@@ -126,26 +126,26 @@ discard block |
||
| 126 | 126 | </div> |
| 127 | 127 | </div> |
| 128 | 128 | <?php |
| 129 | - } else { |
|
| 130 | - $installed_plugins = get_plugins(); |
|
| 129 | + } else { |
|
| 130 | + $installed_plugins = get_plugins(); |
|
| 131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
| 132 | - if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 133 | - //print_r($addons); |
|
| 134 | - ?> |
|
| 132 | + if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 133 | + //print_r($addons); |
|
| 134 | + ?> |
|
| 135 | 135 | <ul class="wpi-products"> |
| 136 | 136 | <?php |
| 137 | 137 | foreach ( $addons as $addon ) : |
| 138 | 138 | if ( 965 == $addon->info->id ) { |
| 139 | 139 | continue;}// don't show quote add on |
| 140 | - ?> |
|
| 140 | + ?> |
|
| 141 | 141 | <li class="wpi-product"> |
| 142 | 142 | <div class="wpi-product-title"> |
| 143 | 143 | <h3> |
| 144 | 144 | <?php |
| 145 | - if ( ! empty( $addon->info->excerpt ) ) { |
|
| 146 | - wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
| 147 | - } |
|
| 148 | - echo esc_html( $addon->info->title ); |
|
| 145 | + if ( ! empty( $addon->info->excerpt ) ) { |
|
| 146 | + wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
| 147 | + } |
|
| 148 | + echo esc_html( $addon->info->title ); |
|
| 149 | 149 | ?> |
| 150 | 150 | </h3> |
| 151 | 151 | </div> |
@@ -156,32 +156,32 @@ discard block |
||
| 156 | 156 | <?php |
| 157 | 157 | endif; |
| 158 | 158 | |
| 159 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
| 160 | - $addon->info->slug = 'getpaid-stripe-payments'; |
|
| 161 | - $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
| 165 | - echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 166 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 167 | - echo '</a>'; |
|
| 168 | - } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
| 169 | - if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
| 170 | - $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
| 171 | - } else { |
|
| 172 | - // if installed show activation link |
|
| 173 | - if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
| 174 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
| 175 | - } else { |
|
| 176 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
| 180 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 181 | - echo '</a>'; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - ?> |
|
| 159 | + if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
| 160 | + $addon->info->slug = 'getpaid-stripe-payments'; |
|
| 161 | + $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
| 165 | + echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 166 | + echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 167 | + echo '</a>'; |
|
| 168 | + } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
| 169 | + if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
| 170 | + $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
| 171 | + } else { |
|
| 172 | + // if installed show activation link |
|
| 173 | + if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
| 174 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
| 175 | + } else { |
|
| 176 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
| 180 | + echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 181 | + echo '</a>'; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + ?> |
|
| 185 | 185 | |
| 186 | 186 | </span> |
| 187 | 187 | |
@@ -189,15 +189,15 @@ discard block |
||
| 189 | 189 | <span class="wpi-product-button"> |
| 190 | 190 | <?php |
| 191 | 191 | $addon_obj->output_button( $addon ); |
| 192 | - ?> |
|
| 192 | + ?> |
|
| 193 | 193 | </span> |
| 194 | 194 | |
| 195 | 195 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
| 196 | 196 | <?php |
| 197 | 197 | endif; |
| 198 | - } |
|
| 198 | + } |
|
| 199 | 199 | } |
| 200 | - ?> |
|
| 200 | + ?> |
|
| 201 | 201 | |
| 202 | 202 | |
| 203 | 203 | <div class="clearfix" ></div> |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | <input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button> |
| 217 | 217 | <br> |
| 218 | 218 | <?php |
| 219 | - printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
| 220 | - ?> |
|
| 219 | + printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
| 220 | + ?> |
|
| 221 | 221 | </span> |
| 222 | 222 | </div> |
| 223 | 223 | |
@@ -12,38 +12,38 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission items. |
|
| 17 | - * @var GetPaid_Form_Item[] |
|
| 18 | - */ |
|
| 19 | - public $items = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission items. |
|
| 17 | + * @var GetPaid_Form_Item[] |
|
| 18 | + */ |
|
| 19 | + public $items = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $data = $submission->get_data(); |
|
| 29 | - $payment_form = $submission->get_payment_form(); |
|
| 30 | - |
|
| 31 | - // Prepare the selected items. |
|
| 32 | - $selected_items = array(); |
|
| 33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // (Maybe) set form items. |
|
| 38 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | - |
|
| 40 | - // Confirm items key. |
|
| 41 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 42 | - if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
| 43 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $items = array(); |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $data = $submission->get_data(); |
|
| 29 | + $payment_form = $submission->get_payment_form(); |
|
| 30 | + |
|
| 31 | + // Prepare the selected items. |
|
| 32 | + $selected_items = array(); |
|
| 33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // (Maybe) set form items. |
|
| 38 | + if ( isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | + |
|
| 40 | + // Confirm items key. |
|
| 41 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 42 | + if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
| 43 | + throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $items = array(); |
|
| 47 | 47 | $item_ids = array(); |
| 48 | 48 | |
| 49 | 49 | foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
@@ -69,61 +69,61 @@ discard block |
||
| 69 | 69 | $items[] = $item; |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | $payment_form->set_items( $items ); |
| 75 | 75 | |
| 76 | - } |
|
| 77 | - |
|
| 78 | - // Process each individual item. |
|
| 79 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 80 | - $this->process_item( $item, $selected_items, $submission ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - } |
|
| 76 | + } |
|
| 84 | 77 | |
| 85 | - /** |
|
| 86 | - * Process a single item. |
|
| 87 | - * |
|
| 88 | - * @param GetPaid_Form_Item $item |
|
| 89 | - * @param array $selected_items |
|
| 90 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 91 | - */ |
|
| 92 | - public function process_item( $item, $selected_items, $submission ) { |
|
| 78 | + // Process each individual item. |
|
| 79 | + foreach ( $payment_form->get_items() as $item ) { |
|
| 80 | + $this->process_item( $item, $selected_items, $submission ); |
|
| 81 | + } |
|
| 93 | 82 | |
| 94 | - // Abort if this is an optional item and it has not been selected. |
|
| 95 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 83 | + } |
|
| 98 | 84 | |
| 99 | - // (maybe) let customers change the quantities and prices. |
|
| 100 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 101 | - |
|
| 102 | - // Maybe change the quantities. |
|
| 103 | - if ( $item->allows_quantities() ) { |
|
| 104 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 105 | - } |
|
| 85 | + /** |
|
| 86 | + * Process a single item. |
|
| 87 | + * |
|
| 88 | + * @param GetPaid_Form_Item $item |
|
| 89 | + * @param array $selected_items |
|
| 90 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 91 | + */ |
|
| 92 | + public function process_item( $item, $selected_items, $submission ) { |
|
| 93 | + |
|
| 94 | + // Abort if this is an optional item and it has not been selected. |
|
| 95 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // (maybe) let customers change the quantities and prices. |
|
| 100 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 101 | + |
|
| 102 | + // Maybe change the quantities. |
|
| 103 | + if ( $item->allows_quantities() ) { |
|
| 104 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // Maybe change the price. |
|
| 108 | - if ( $item->user_can_set_their_price() ) { |
|
| 109 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 107 | + // Maybe change the price. |
|
| 108 | + if ( $item->user_can_set_their_price() ) { |
|
| 109 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 110 | 110 | |
| 111 | - if ( $item->get_minimum_price() > $price ) { |
|
| 112 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 113 | - } |
|
| 111 | + if ( $item->get_minimum_price() > $price ) { |
|
| 112 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - $item->set_price( $price ); |
|
| 115 | + $item->set_price( $price ); |
|
| 116 | 116 | |
| 117 | - } |
|
| 118 | - } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - if ( 0 == $item->get_quantity() ) { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 120 | + if ( 0 == $item->get_quantity() ) { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - // Save the item. |
|
| 125 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
| 124 | + // Save the item. |
|
| 125 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
| 126 | 126 | |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | } |
@@ -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,55 +10,55 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form 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 = 'payment_form'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'payment_form'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'payment_form'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Form Data array. This is the core form data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'status' => 'draft', |
|
| 34 | - 'version' => '', |
|
| 35 | - 'date_created' => null, |
|
| 27 | + * Form Data array. This is the core form data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'status' => 'draft', |
|
| 34 | + 'version' => '', |
|
| 35 | + 'date_created' => null, |
|
| 36 | 36 | 'date_modified' => null, |
| 37 | 37 | 'name' => '', |
| 38 | 38 | 'author' => 1, |
| 39 | 39 | 'elements' => null, |
| 40 | - 'items' => null, |
|
| 41 | - 'earned' => 0, |
|
| 42 | - 'refunded' => 0, |
|
| 43 | - 'cancelled' => 0, |
|
| 44 | - 'failed' => 0, |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Stores meta in cache for future reads. |
|
| 49 | - * |
|
| 50 | - * A group must be set to to enable caching. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - protected $cache_group = 'getpaid_forms'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
| 58 | - * |
|
| 59 | - * @var WPInv_Invoice |
|
| 60 | - */ |
|
| 61 | - public $invoice = 0; |
|
| 40 | + 'items' => null, |
|
| 41 | + 'earned' => 0, |
|
| 42 | + 'refunded' => 0, |
|
| 43 | + 'cancelled' => 0, |
|
| 44 | + 'failed' => 0, |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Stores meta in cache for future reads. |
|
| 49 | + * |
|
| 50 | + * A group must be set to to enable caching. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + protected $cache_group = 'getpaid_forms'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
| 58 | + * |
|
| 59 | + * @var WPInv_Invoice |
|
| 60 | + */ |
|
| 61 | + public $invoice = 0; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
| 68 | 68 | protected $post = null; |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
| 72 | - * |
|
| 73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
| 74 | - */ |
|
| 75 | - public function __construct( $form = 0 ) { |
|
| 76 | - parent::__construct( $form ); |
|
| 71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
| 72 | + * |
|
| 73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
| 74 | + */ |
|
| 75 | + public function __construct( $form = 0 ) { |
|
| 76 | + parent::__construct( $form ); |
|
| 77 | 77 | |
| 78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
| 79 | - $this->set_id( $form ); |
|
| 80 | - } elseif ( $form instanceof self ) { |
|
| 78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
| 79 | + $this->set_id( $form ); |
|
| 80 | + } elseif ( $form instanceof self ) { |
|
| 81 | 81 | |
| 82 | - $this->set_id( $form->get_id() ); |
|
| 83 | - $this->invoice = $form->invoice; |
|
| 82 | + $this->set_id( $form->get_id() ); |
|
| 83 | + $this->invoice = $form->invoice; |
|
| 84 | 84 | |
| 85 | - } elseif ( ! empty( $form->ID ) ) { |
|
| 86 | - $this->set_id( $form->ID ); |
|
| 87 | - } else { |
|
| 88 | - $this->set_object_read( true ); |
|
| 89 | - } |
|
| 85 | + } elseif ( ! empty( $form->ID ) ) { |
|
| 86 | + $this->set_id( $form->ID ); |
|
| 87 | + } else { |
|
| 88 | + $this->set_object_read( true ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | // Load the datastore. |
| 92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 93 | 93 | |
| 94 | - if ( $this->get_id() > 0 ) { |
|
| 94 | + if ( $this->get_id() > 0 ) { |
|
| 95 | 95 | $this->post = get_post( $this->get_id() ); |
| 96 | - $this->data_store->read( $this ); |
|
| 96 | + $this->data_store->read( $this ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | /* |
| 102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,356 +114,356 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * Get plugin version when the form was created. |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * @param string $context View or edit context. |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function get_version( $context = 'view' ) { |
|
| 124 | - return $this->get_prop( 'version', $context ); |
|
| 117 | + * Get plugin version when the form was created. |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * @param string $context View or edit context. |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function get_version( $context = 'view' ) { |
|
| 124 | + return $this->get_prop( 'version', $context ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | - * Get date when the form was created. |
|
| 129 | - * |
|
| 130 | - * @since 1.0.19 |
|
| 131 | - * @param string $context View or edit context. |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function get_date_created( $context = 'view' ) { |
|
| 135 | - return $this->get_prop( 'date_created', $context ); |
|
| 128 | + * Get date when the form was created. |
|
| 129 | + * |
|
| 130 | + * @since 1.0.19 |
|
| 131 | + * @param string $context View or edit context. |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function get_date_created( $context = 'view' ) { |
|
| 135 | + return $this->get_prop( 'date_created', $context ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | - * Get GMT date when the form was created. |
|
| 140 | - * |
|
| 141 | - * @since 1.0.19 |
|
| 142 | - * @param string $context View or edit context. |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 139 | + * Get GMT date when the form was created. |
|
| 140 | + * |
|
| 141 | + * @since 1.0.19 |
|
| 142 | + * @param string $context View or edit context. |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 146 | 146 | $date = $this->get_date_created( $context ); |
| 147 | 147 | |
| 148 | 148 | if ( $date ) { |
| 149 | 149 | $date = get_gmt_from_date( $date ); |
| 150 | 150 | } |
| 151 | - return $date; |
|
| 151 | + return $date; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | - * Get date when the form was last modified. |
|
| 156 | - * |
|
| 157 | - * @since 1.0.19 |
|
| 158 | - * @param string $context View or edit context. |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function get_date_modified( $context = 'view' ) { |
|
| 162 | - return $this->get_prop( 'date_modified', $context ); |
|
| 155 | + * Get date when the form was last modified. |
|
| 156 | + * |
|
| 157 | + * @since 1.0.19 |
|
| 158 | + * @param string $context View or edit context. |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function get_date_modified( $context = 'view' ) { |
|
| 162 | + return $this->get_prop( 'date_modified', $context ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * Get GMT date when the form was last modified. |
|
| 167 | - * |
|
| 168 | - * @since 1.0.19 |
|
| 169 | - * @param string $context View or edit context. |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 166 | + * Get GMT date when the form was last modified. |
|
| 167 | + * |
|
| 168 | + * @since 1.0.19 |
|
| 169 | + * @param string $context View or edit context. |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 173 | 173 | $date = $this->get_date_modified( $context ); |
| 174 | 174 | |
| 175 | 175 | if ( $date ) { |
| 176 | 176 | $date = get_gmt_from_date( $date ); |
| 177 | 177 | } |
| 178 | - return $date; |
|
| 178 | + return $date; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | - * Get the form name. |
|
| 183 | - * |
|
| 184 | - * @since 1.0.19 |
|
| 185 | - * @param string $context View or edit context. |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function get_name( $context = 'view' ) { |
|
| 189 | - return $this->get_prop( 'name', $context ); |
|
| 182 | + * Get the form name. |
|
| 183 | + * |
|
| 184 | + * @since 1.0.19 |
|
| 185 | + * @param string $context View or edit context. |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function get_name( $context = 'view' ) { |
|
| 189 | + return $this->get_prop( 'name', $context ); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | - * Alias of self::get_name(). |
|
| 194 | - * |
|
| 195 | - * @since 1.0.19 |
|
| 196 | - * @param string $context View or edit context. |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function get_title( $context = 'view' ) { |
|
| 200 | - return $this->get_name( $context ); |
|
| 201 | - } |
|
| 193 | + * Alias of self::get_name(). |
|
| 194 | + * |
|
| 195 | + * @since 1.0.19 |
|
| 196 | + * @param string $context View or edit context. |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function get_title( $context = 'view' ) { |
|
| 200 | + return $this->get_name( $context ); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | - * Get the owner of the form. |
|
| 205 | - * |
|
| 206 | - * @since 1.0.19 |
|
| 207 | - * @param string $context View or edit context. |
|
| 208 | - * @return int |
|
| 209 | - */ |
|
| 210 | - public function get_author( $context = 'view' ) { |
|
| 211 | - return (int) $this->get_prop( 'author', $context ); |
|
| 204 | + * Get the owner of the form. |
|
| 205 | + * |
|
| 206 | + * @since 1.0.19 |
|
| 207 | + * @param string $context View or edit context. |
|
| 208 | + * @return int |
|
| 209 | + */ |
|
| 210 | + public function get_author( $context = 'view' ) { |
|
| 211 | + return (int) $this->get_prop( 'author', $context ); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | - * Get the elements that make up the form. |
|
| 216 | - * |
|
| 217 | - * @since 1.0.19 |
|
| 218 | - * @param string $context View or edit context. |
|
| 219 | - * @return array |
|
| 220 | - */ |
|
| 221 | - public function get_elements( $context = 'view' ) { |
|
| 222 | - $elements = $this->get_prop( 'elements', $context ); |
|
| 215 | + * Get the elements that make up the form. |
|
| 216 | + * |
|
| 217 | + * @since 1.0.19 |
|
| 218 | + * @param string $context View or edit context. |
|
| 219 | + * @return array |
|
| 220 | + */ |
|
| 221 | + public function get_elements( $context = 'view' ) { |
|
| 222 | + $elements = $this->get_prop( 'elements', $context ); |
|
| 223 | 223 | |
| 224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
| 224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
| 225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - // Ensure that all required elements exist. |
|
| 229 | - $_elements = array(); |
|
| 230 | - foreach ( $elements as $element ) { |
|
| 228 | + // Ensure that all required elements exist. |
|
| 229 | + $_elements = array(); |
|
| 230 | + foreach ( $elements as $element ) { |
|
| 231 | 231 | |
| 232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
| 232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
| 233 | 233 | |
| 234 | - $_elements[] = array( |
|
| 235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 236 | - 'id' => 'gtscicd', |
|
| 237 | - 'name' => 'gtscicd', |
|
| 238 | - 'type' => 'gateway_select', |
|
| 239 | - 'premade' => true, |
|
| 234 | + $_elements[] = array( |
|
| 235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 236 | + 'id' => 'gtscicd', |
|
| 237 | + 'name' => 'gtscicd', |
|
| 238 | + 'type' => 'gateway_select', |
|
| 239 | + 'premade' => true, |
|
| 240 | 240 | |
| 241 | - ); |
|
| 241 | + ); |
|
| 242 | 242 | |
| 243 | - } |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - $_elements[] = $element; |
|
| 245 | + $_elements[] = $element; |
|
| 246 | 246 | |
| 247 | - } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | return $_elements; |
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Get the items sold via the form. |
|
| 254 | - * |
|
| 255 | - * @since 1.0.19 |
|
| 256 | - * @param string $context View or edit context. |
|
| 257 | - * @param string $return objects or arrays. |
|
| 258 | - * @return GetPaid_Form_Item[] |
|
| 259 | - */ |
|
| 260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
| 261 | - $items = $this->get_prop( 'items', $context ); |
|
| 262 | - |
|
| 263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Get the items sold via the form. |
|
| 254 | + * |
|
| 255 | + * @since 1.0.19 |
|
| 256 | + * @param string $context View or edit context. |
|
| 257 | + * @param string $return objects or arrays. |
|
| 258 | + * @return GetPaid_Form_Item[] |
|
| 259 | + */ |
|
| 260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
| 261 | + $items = $this->get_prop( 'items', $context ); |
|
| 262 | + |
|
| 263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
| 264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // Convert the items. |
|
| 268 | - $prepared = array(); |
|
| 267 | + // Convert the items. |
|
| 268 | + $prepared = array(); |
|
| 269 | 269 | |
| 270 | - foreach ( $items as $key => $value ) { |
|
| 270 | + foreach ( $items as $key => $value ) { |
|
| 271 | 271 | |
| 272 | - // Form items. |
|
| 273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
| 272 | + // Form items. |
|
| 273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
| 274 | 274 | |
| 275 | - if ( $value->can_purchase() ) { |
|
| 276 | - $prepared[] = $value; |
|
| 277 | - } |
|
| 275 | + if ( $value->can_purchase() ) { |
|
| 276 | + $prepared[] = $value; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - continue; |
|
| 279 | + continue; |
|
| 280 | 280 | |
| 281 | - } |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - // $item_id => $quantity (buy buttons) |
|
| 284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
| 285 | - $item = new GetPaid_Form_Item( $key ); |
|
| 283 | + // $item_id => $quantity (buy buttons) |
|
| 284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
| 285 | + $item = new GetPaid_Form_Item( $key ); |
|
| 286 | 286 | |
| 287 | - if ( $item->can_purchase() ) { |
|
| 287 | + if ( $item->can_purchase() ) { |
|
| 288 | 288 | |
| 289 | - $value = (float) $value; |
|
| 290 | - $item->set_quantity( $value ); |
|
| 291 | - if ( 0 == $value ) { |
|
| 292 | - $item->set_quantity( 1 ); |
|
| 293 | - $item->set_allow_quantities( true ); |
|
| 294 | - } |
|
| 289 | + $value = (float) $value; |
|
| 290 | + $item->set_quantity( $value ); |
|
| 291 | + if ( 0 == $value ) { |
|
| 292 | + $item->set_quantity( 1 ); |
|
| 293 | + $item->set_allow_quantities( true ); |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - $prepared[] = $item; |
|
| 297 | - } |
|
| 296 | + $prepared[] = $item; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - continue; |
|
| 300 | - } |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - // Items saved via payment forms editor. |
|
| 303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
| 302 | + // Items saved via payment forms editor. |
|
| 303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
| 304 | 304 | |
| 305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
| 305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
| 306 | 306 | |
| 307 | - if ( ! $item->can_purchase() ) { |
|
| 308 | - continue; |
|
| 309 | - } |
|
| 307 | + if ( ! $item->can_purchase() ) { |
|
| 308 | + continue; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - // Sub-total (Cart items). |
|
| 312 | - if ( isset( $value['subtotal'] ) ) { |
|
| 313 | - $item->set_price( $value['subtotal'] ); |
|
| 314 | - } |
|
| 311 | + // Sub-total (Cart items). |
|
| 312 | + if ( isset( $value['subtotal'] ) ) { |
|
| 313 | + $item->set_price( $value['subtotal'] ); |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - if ( isset( $value['quantity'] ) ) { |
|
| 317 | - $item->set_quantity( $value['quantity'] ); |
|
| 318 | - } |
|
| 316 | + if ( isset( $value['quantity'] ) ) { |
|
| 317 | + $item->set_quantity( $value['quantity'] ); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
| 321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
| 322 | - } |
|
| 320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
| 321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - if ( isset( $value['required'] ) ) { |
|
| 325 | - $item->set_is_required( $value['required'] ); |
|
| 326 | - } |
|
| 324 | + if ( isset( $value['required'] ) ) { |
|
| 325 | + $item->set_is_required( $value['required'] ); |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - if ( isset( $value['description'] ) ) { |
|
| 329 | - $item->set_custom_description( $value['description'] ); |
|
| 330 | - } |
|
| 328 | + if ( isset( $value['description'] ) ) { |
|
| 329 | + $item->set_custom_description( $value['description'] ); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - $prepared[] = $item; |
|
| 333 | - continue; |
|
| 332 | + $prepared[] = $item; |
|
| 333 | + continue; |
|
| 334 | 334 | |
| 335 | - } |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
| 338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 339 | - $item = new GetPaid_Form_Item( $key ); |
|
| 337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
| 338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 339 | + $item = new GetPaid_Form_Item( $key ); |
|
| 340 | 340 | |
| 341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
| 342 | - $item->set_price( $value['price'] ); |
|
| 343 | - } |
|
| 341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
| 342 | + $item->set_price( $value['price'] ); |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - if ( $item->can_purchase() ) { |
|
| 346 | - $prepared[] = $item; |
|
| 347 | - } |
|
| 345 | + if ( $item->can_purchase() ) { |
|
| 346 | + $prepared[] = $item; |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - continue; |
|
| 350 | - } |
|
| 349 | + continue; |
|
| 350 | + } |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
| 354 | - return $prepared; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $items = array(); |
|
| 358 | - foreach ( $prepared as $item ) { |
|
| 359 | - $items[] = $item->prepare_data_for_use(); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $items; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Get a single item belonging to the form. |
|
| 367 | - * |
|
| 368 | - * @since 1.0.19 |
|
| 369 | - * @param int $item_id The item id to return. |
|
| 370 | - * @return GetPaid_Form_Item|bool |
|
| 371 | - */ |
|
| 372 | - public function get_item( $item_id ) { |
|
| 373 | - |
|
| 374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
| 375 | - return false; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - foreach ( $this->get_items() as $item ) { |
|
| 379 | - if ( $item->get_id() == (int) $item_id ) { |
|
| 380 | - return $item; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - return false; |
|
| 385 | - |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Gets a single element. |
|
| 390 | - * |
|
| 391 | - * @since 1.0.19 |
|
| 392 | - * @param string $element_type The element type to return. |
|
| 393 | - * @return array|bool |
|
| 394 | - */ |
|
| 395 | - public function get_element_type( $element_type ) { |
|
| 396 | - |
|
| 397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
| 398 | - return false; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
| 402 | - |
|
| 403 | - if ( $element['type'] == $element_type ) { |
|
| 404 | - return $element; |
|
| 405 | - } |
|
| 353 | + if ( 'objects' == $return && 'view' == $context ) { |
|
| 354 | + return $prepared; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $items = array(); |
|
| 358 | + foreach ( $prepared as $item ) { |
|
| 359 | + $items[] = $item->prepare_data_for_use(); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $items; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Get a single item belonging to the form. |
|
| 367 | + * |
|
| 368 | + * @since 1.0.19 |
|
| 369 | + * @param int $item_id The item id to return. |
|
| 370 | + * @return GetPaid_Form_Item|bool |
|
| 371 | + */ |
|
| 372 | + public function get_item( $item_id ) { |
|
| 373 | + |
|
| 374 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
| 375 | + return false; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + foreach ( $this->get_items() as $item ) { |
|
| 379 | + if ( $item->get_id() == (int) $item_id ) { |
|
| 380 | + return $item; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + return false; |
|
| 385 | + |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Gets a single element. |
|
| 390 | + * |
|
| 391 | + * @since 1.0.19 |
|
| 392 | + * @param string $element_type The element type to return. |
|
| 393 | + * @return array|bool |
|
| 394 | + */ |
|
| 395 | + public function get_element_type( $element_type ) { |
|
| 396 | + |
|
| 397 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
| 398 | + return false; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
| 402 | + |
|
| 403 | + if ( $element['type'] == $element_type ) { |
|
| 404 | + return $element; |
|
| 405 | + } |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | - return false; |
|
| 409 | - |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get the total amount earned via this form. |
|
| 414 | - * |
|
| 415 | - * @since 1.0.19 |
|
| 416 | - * @param string $context View or edit context. |
|
| 417 | - * @return float |
|
| 418 | - */ |
|
| 419 | - public function get_earned( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'earned', $context ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Get the total amount refunded via this form. |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - * @param string $context View or edit context. |
|
| 428 | - * @return float |
|
| 429 | - */ |
|
| 430 | - public function get_refunded( $context = 'view' ) { |
|
| 431 | - return $this->get_prop( 'refunded', $context ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Get the total amount cancelled via this form. |
|
| 436 | - * |
|
| 437 | - * @since 1.0.19 |
|
| 438 | - * @param string $context View or edit context. |
|
| 439 | - * @return float |
|
| 440 | - */ |
|
| 441 | - public function get_cancelled( $context = 'view' ) { |
|
| 442 | - return $this->get_prop( 'cancelled', $context ); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Get the total amount failed via this form. |
|
| 447 | - * |
|
| 448 | - * @since 1.0.19 |
|
| 449 | - * @param string $context View or edit context. |
|
| 450 | - * @return float |
|
| 451 | - */ |
|
| 452 | - public function get_failed( $context = 'view' ) { |
|
| 453 | - return $this->get_prop( 'failed', $context ); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Get the currency. |
|
| 458 | - * |
|
| 459 | - * @since 1.0.19 |
|
| 460 | - * @param string $context View or edit context. |
|
| 461 | - * @return string |
|
| 462 | - */ |
|
| 463 | - public function get_currency() { |
|
| 464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
| 466 | - } |
|
| 408 | + return false; |
|
| 409 | + |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get the total amount earned via this form. |
|
| 414 | + * |
|
| 415 | + * @since 1.0.19 |
|
| 416 | + * @param string $context View or edit context. |
|
| 417 | + * @return float |
|
| 418 | + */ |
|
| 419 | + public function get_earned( $context = 'view' ) { |
|
| 420 | + return $this->get_prop( 'earned', $context ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Get the total amount refunded via this form. |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + * @param string $context View or edit context. |
|
| 428 | + * @return float |
|
| 429 | + */ |
|
| 430 | + public function get_refunded( $context = 'view' ) { |
|
| 431 | + return $this->get_prop( 'refunded', $context ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Get the total amount cancelled via this form. |
|
| 436 | + * |
|
| 437 | + * @since 1.0.19 |
|
| 438 | + * @param string $context View or edit context. |
|
| 439 | + * @return float |
|
| 440 | + */ |
|
| 441 | + public function get_cancelled( $context = 'view' ) { |
|
| 442 | + return $this->get_prop( 'cancelled', $context ); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Get the total amount failed via this form. |
|
| 447 | + * |
|
| 448 | + * @since 1.0.19 |
|
| 449 | + * @param string $context View or edit context. |
|
| 450 | + * @return float |
|
| 451 | + */ |
|
| 452 | + public function get_failed( $context = 'view' ) { |
|
| 453 | + return $this->get_prop( 'failed', $context ); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Get the currency. |
|
| 458 | + * |
|
| 459 | + * @since 1.0.19 |
|
| 460 | + * @param string $context View or edit context. |
|
| 461 | + * @return string |
|
| 462 | + */ |
|
| 463 | + public function get_currency() { |
|
| 464 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 465 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | /* |
| 469 | 469 | |-------------------------------------------------------------------------- |
@@ -476,22 +476,22 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | |
| 478 | 478 | /** |
| 479 | - * Set plugin version when the item was created. |
|
| 480 | - * |
|
| 481 | - * @since 1.0.19 |
|
| 482 | - */ |
|
| 483 | - public function set_version( $value ) { |
|
| 484 | - $this->set_prop( 'version', $value ); |
|
| 479 | + * Set plugin version when the item was created. |
|
| 480 | + * |
|
| 481 | + * @since 1.0.19 |
|
| 482 | + */ |
|
| 483 | + public function set_version( $value ) { |
|
| 484 | + $this->set_prop( 'version', $value ); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
| 488 | - * Set date when the item was created. |
|
| 489 | - * |
|
| 490 | - * @since 1.0.19 |
|
| 491 | - * @param string $value Value to set. |
|
| 488 | + * Set date when the item was created. |
|
| 489 | + * |
|
| 490 | + * @since 1.0.19 |
|
| 491 | + * @param string $value Value to set. |
|
| 492 | 492 | * @return bool Whether or not the date was set. |
| 493 | - */ |
|
| 494 | - public function set_date_created( $value ) { |
|
| 493 | + */ |
|
| 494 | + public function set_date_created( $value ) { |
|
| 495 | 495 | $date = strtotime( $value ); |
| 496 | 496 | |
| 497 | 497 | if ( $date ) { |
@@ -504,13 +504,13 @@ discard block |
||
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
| 507 | - * Set date when the item was last modified. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param string $value Value to set. |
|
| 507 | + * Set date when the item was last modified. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param string $value Value to set. |
|
| 511 | 511 | * @return bool Whether or not the date was set. |
| 512 | - */ |
|
| 513 | - public function set_date_modified( $value ) { |
|
| 512 | + */ |
|
| 513 | + public function set_date_modified( $value ) { |
|
| 514 | 514 | $date = strtotime( $value ); |
| 515 | 515 | |
| 516 | 516 | if ( $date ) { |
@@ -523,164 +523,164 @@ discard block |
||
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
| 526 | - * Set the item name. |
|
| 527 | - * |
|
| 528 | - * @since 1.0.19 |
|
| 529 | - * @param string $value New name. |
|
| 530 | - */ |
|
| 531 | - public function set_name( $value ) { |
|
| 532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Alias of self::set_name(). |
|
| 537 | - * |
|
| 538 | - * @since 1.0.19 |
|
| 539 | - * @param string $value New name. |
|
| 540 | - */ |
|
| 541 | - public function set_title( $value ) { |
|
| 542 | - $this->set_name( $value ); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Set the owner of the item. |
|
| 547 | - * |
|
| 548 | - * @since 1.0.19 |
|
| 549 | - * @param int $value New author. |
|
| 550 | - */ |
|
| 551 | - public function set_author( $value ) { |
|
| 552 | - $this->set_prop( 'author', (int) $value ); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Set the form elements. |
|
| 557 | - * |
|
| 558 | - * @since 1.0.19 |
|
| 559 | - * @sinve 2.3.4 Array values sanitized. |
|
| 560 | - * @param array $value Form elements. |
|
| 561 | - */ |
|
| 562 | - public function set_elements( $value ) { |
|
| 563 | - if ( is_array( $value ) ) { |
|
| 564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Sanitize array values. |
|
| 570 | - * |
|
| 571 | - * @param $value |
|
| 572 | - * |
|
| 573 | - * @return mixed |
|
| 574 | - */ |
|
| 575 | - public function sanitize_array_values( $value ) { |
|
| 576 | - |
|
| 577 | - // sanitize |
|
| 578 | - if ( ! empty( $value ) ) { |
|
| 579 | - |
|
| 580 | - foreach ( $value as $key => $val_arr ) { |
|
| 581 | - |
|
| 582 | - if ( is_array( $val_arr ) ) { |
|
| 583 | - // check if we have sub array items. |
|
| 584 | - $sub_arr = array(); |
|
| 585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
| 586 | - if ( is_array( $val2 ) ) { |
|
| 587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
| 588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - // we allow some html in description so we sanitize it separately. |
|
| 593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
| 594 | - |
|
| 595 | - // sanitize array elements |
|
| 596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
| 597 | - |
|
| 598 | - // add back the description if set |
|
| 599 | - if ( isset( $val_arr['description'] ) ) { |
|
| 526 | + * Set the item name. |
|
| 527 | + * |
|
| 528 | + * @since 1.0.19 |
|
| 529 | + * @param string $value New name. |
|
| 530 | + */ |
|
| 531 | + public function set_name( $value ) { |
|
| 532 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Alias of self::set_name(). |
|
| 537 | + * |
|
| 538 | + * @since 1.0.19 |
|
| 539 | + * @param string $value New name. |
|
| 540 | + */ |
|
| 541 | + public function set_title( $value ) { |
|
| 542 | + $this->set_name( $value ); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Set the owner of the item. |
|
| 547 | + * |
|
| 548 | + * @since 1.0.19 |
|
| 549 | + * @param int $value New author. |
|
| 550 | + */ |
|
| 551 | + public function set_author( $value ) { |
|
| 552 | + $this->set_prop( 'author', (int) $value ); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Set the form elements. |
|
| 557 | + * |
|
| 558 | + * @since 1.0.19 |
|
| 559 | + * @sinve 2.3.4 Array values sanitized. |
|
| 560 | + * @param array $value Form elements. |
|
| 561 | + */ |
|
| 562 | + public function set_elements( $value ) { |
|
| 563 | + if ( is_array( $value ) ) { |
|
| 564 | + $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Sanitize array values. |
|
| 570 | + * |
|
| 571 | + * @param $value |
|
| 572 | + * |
|
| 573 | + * @return mixed |
|
| 574 | + */ |
|
| 575 | + public function sanitize_array_values( $value ) { |
|
| 576 | + |
|
| 577 | + // sanitize |
|
| 578 | + if ( ! empty( $value ) ) { |
|
| 579 | + |
|
| 580 | + foreach ( $value as $key => $val_arr ) { |
|
| 581 | + |
|
| 582 | + if ( is_array( $val_arr ) ) { |
|
| 583 | + // check if we have sub array items. |
|
| 584 | + $sub_arr = array(); |
|
| 585 | + foreach ( $val_arr as $key2 => $val2 ) { |
|
| 586 | + if ( is_array( $val2 ) ) { |
|
| 587 | + $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
| 588 | + unset( $val_arr[ $key ][ $key2 ] ); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + // we allow some html in description so we sanitize it separately. |
|
| 593 | + $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
| 594 | + |
|
| 595 | + // sanitize array elements |
|
| 596 | + $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
| 597 | + |
|
| 598 | + // add back the description if set |
|
| 599 | + if ( isset( $val_arr['description'] ) ) { |
|
| 600 | 600 | $value[ $key ]['description'] = $help_text;} |
| 601 | 601 | |
| 602 | - // add back sub array items after its been sanitized. |
|
| 603 | - if ( ! empty( $sub_arr ) ) { |
|
| 604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
| 605 | - } |
|
| 606 | - } |
|
| 602 | + // add back sub array items after its been sanitized. |
|
| 603 | + if ( ! empty( $sub_arr ) ) { |
|
| 604 | + $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | 607 | } |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | - return $value; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Set the form items. |
|
| 615 | - * |
|
| 616 | - * @since 1.0.19 |
|
| 617 | - * @param array $value Form elements. |
|
| 618 | - */ |
|
| 619 | - public function set_items( $value ) { |
|
| 620 | - if ( is_array( $value ) ) { |
|
| 621 | - $this->set_prop( 'items', $value ); |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Set the total amount earned via this form. |
|
| 627 | - * |
|
| 628 | - * @since 1.0.19 |
|
| 629 | - * @param float $value Amount earned. |
|
| 630 | - */ |
|
| 631 | - public function set_earned( $value ) { |
|
| 632 | - $value = max( (float) $value, 0 ); |
|
| 633 | - $this->set_prop( 'earned', $value ); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Set the total amount refunded via this form. |
|
| 638 | - * |
|
| 639 | - * @since 1.0.19 |
|
| 640 | - * @param float $value Amount refunded. |
|
| 641 | - */ |
|
| 642 | - public function set_refunded( $value ) { |
|
| 643 | - $value = max( (float) $value, 0 ); |
|
| 644 | - $this->set_prop( 'refunded', $value ); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Set the total amount cancelled via this form. |
|
| 649 | - * |
|
| 650 | - * @since 1.0.19 |
|
| 651 | - * @param float $value Amount cancelled. |
|
| 652 | - */ |
|
| 653 | - public function set_cancelled( $value ) { |
|
| 654 | - $value = max( (float) $value, 0 ); |
|
| 655 | - $this->set_prop( 'cancelled', $value ); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * Set the total amount failed via this form. |
|
| 660 | - * |
|
| 661 | - * @since 1.0.19 |
|
| 662 | - * @param float $value Amount cancelled. |
|
| 663 | - */ |
|
| 664 | - public function set_failed( $value ) { |
|
| 665 | - $value = max( (float) $value, 0 ); |
|
| 666 | - $this->set_prop( 'failed', $value ); |
|
| 667 | - } |
|
| 610 | + return $value; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Set the form items. |
|
| 615 | + * |
|
| 616 | + * @since 1.0.19 |
|
| 617 | + * @param array $value Form elements. |
|
| 618 | + */ |
|
| 619 | + public function set_items( $value ) { |
|
| 620 | + if ( is_array( $value ) ) { |
|
| 621 | + $this->set_prop( 'items', $value ); |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * Set the total amount earned via this form. |
|
| 627 | + * |
|
| 628 | + * @since 1.0.19 |
|
| 629 | + * @param float $value Amount earned. |
|
| 630 | + */ |
|
| 631 | + public function set_earned( $value ) { |
|
| 632 | + $value = max( (float) $value, 0 ); |
|
| 633 | + $this->set_prop( 'earned', $value ); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Set the total amount refunded via this form. |
|
| 638 | + * |
|
| 639 | + * @since 1.0.19 |
|
| 640 | + * @param float $value Amount refunded. |
|
| 641 | + */ |
|
| 642 | + public function set_refunded( $value ) { |
|
| 643 | + $value = max( (float) $value, 0 ); |
|
| 644 | + $this->set_prop( 'refunded', $value ); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Set the total amount cancelled via this form. |
|
| 649 | + * |
|
| 650 | + * @since 1.0.19 |
|
| 651 | + * @param float $value Amount cancelled. |
|
| 652 | + */ |
|
| 653 | + public function set_cancelled( $value ) { |
|
| 654 | + $value = max( (float) $value, 0 ); |
|
| 655 | + $this->set_prop( 'cancelled', $value ); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * Set the total amount failed via this form. |
|
| 660 | + * |
|
| 661 | + * @since 1.0.19 |
|
| 662 | + * @param float $value Amount cancelled. |
|
| 663 | + */ |
|
| 664 | + public function set_failed( $value ) { |
|
| 665 | + $value = max( (float) $value, 0 ); |
|
| 666 | + $this->set_prop( 'failed', $value ); |
|
| 667 | + } |
|
| 668 | 668 | |
| 669 | 669 | /** |
| 670 | 670 | * Create an item. For backwards compatibilty. |
| 671 | 671 | * |
| 672 | 672 | * @deprecated |
| 673 | - * @return int item id |
|
| 673 | + * @return int item id |
|
| 674 | 674 | */ |
| 675 | 675 | public function create( $data = array() ) { |
| 676 | 676 | |
| 677 | - // Set the properties. |
|
| 678 | - if ( is_array( $data ) ) { |
|
| 679 | - $this->set_props( $data ); |
|
| 680 | - } |
|
| 677 | + // Set the properties. |
|
| 678 | + if ( is_array( $data ) ) { |
|
| 679 | + $this->set_props( $data ); |
|
| 680 | + } |
|
| 681 | 681 | |
| 682 | - // Save the item. |
|
| 683 | - return $this->save(); |
|
| 682 | + // Save the item. |
|
| 683 | + return $this->save(); |
|
| 684 | 684 | |
| 685 | 685 | } |
| 686 | 686 | |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | * Updates an item. For backwards compatibilty. |
| 689 | 689 | * |
| 690 | 690 | * @deprecated |
| 691 | - * @return int item id |
|
| 691 | + * @return int item id |
|
| 692 | 692 | */ |
| 693 | 693 | public function update( $data = array() ) { |
| 694 | 694 | return $this->create( $data ); |
@@ -704,22 +704,22 @@ discard block |
||
| 704 | 704 | */ |
| 705 | 705 | |
| 706 | 706 | /** |
| 707 | - * Checks whether this is the default payment form. |
|
| 708 | - * |
|
| 709 | - * @since 1.0.19 |
|
| 710 | - * @return bool |
|
| 711 | - */ |
|
| 707 | + * Checks whether this is the default payment form. |
|
| 708 | + * |
|
| 709 | + * @since 1.0.19 |
|
| 710 | + * @return bool |
|
| 711 | + */ |
|
| 712 | 712 | public function is_default() { |
| 713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
| 714 | 714 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
| 715 | - } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | /** |
| 718 | - * Checks whether the form is active. |
|
| 719 | - * |
|
| 720 | - * @since 1.0.19 |
|
| 721 | - * @return bool |
|
| 722 | - */ |
|
| 718 | + * Checks whether the form is active. |
|
| 719 | + * |
|
| 720 | + * @since 1.0.19 |
|
| 721 | + * @return bool |
|
| 722 | + */ |
|
| 723 | 723 | public function is_active() { |
| 724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
| 725 | 725 | |
@@ -728,81 +728,81 @@ discard block |
||
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * Checks whether the form has a given item. |
|
| 735 | - * |
|
| 736 | - * @since 1.0.19 |
|
| 737 | - * @return bool |
|
| 738 | - */ |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * Checks whether the form has a given item. |
|
| 735 | + * |
|
| 736 | + * @since 1.0.19 |
|
| 737 | + * @return bool |
|
| 738 | + */ |
|
| 739 | 739 | public function has_item( $item_id ) { |
| 740 | 740 | return false !== $this->get_item( $item_id ); |
| 741 | - } |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * Checks whether the form has a given element. |
|
| 745 | - * |
|
| 746 | - * @since 1.0.19 |
|
| 747 | - * @return bool |
|
| 748 | - */ |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * Checks whether the form has a given element. |
|
| 745 | + * |
|
| 746 | + * @since 1.0.19 |
|
| 747 | + * @return bool |
|
| 748 | + */ |
|
| 749 | 749 | public function has_element_type( $element_type ) { |
| 750 | 750 | return false !== $this->get_element_type( $element_type ); |
| 751 | - } |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * Checks whether this form is recurring or not. |
|
| 755 | - * |
|
| 756 | - * @since 1.0.19 |
|
| 757 | - * @return bool |
|
| 758 | - */ |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * Checks whether this form is recurring or not. |
|
| 755 | + * |
|
| 756 | + * @since 1.0.19 |
|
| 757 | + * @return bool |
|
| 758 | + */ |
|
| 759 | 759 | public function is_recurring() { |
| 760 | 760 | |
| 761 | - if ( ! empty( $this->invoice ) ) { |
|
| 762 | - return $this->invoice->is_recurring(); |
|
| 763 | - } |
|
| 761 | + if ( ! empty( $this->invoice ) ) { |
|
| 762 | + return $this->invoice->is_recurring(); |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | - foreach ( $this->get_items() as $item ) { |
|
| 765 | + foreach ( $this->get_items() as $item ) { |
|
| 766 | 766 | |
| 767 | - if ( $item->is_recurring() ) { |
|
| 768 | - return true; |
|
| 769 | - } |
|
| 767 | + if ( $item->is_recurring() ) { |
|
| 768 | + return true; |
|
| 769 | + } |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | return false; |
| 773 | - } |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | - /** |
|
| 776 | - * Retrieves the form's html. |
|
| 777 | - * |
|
| 778 | - * @since 1.0.19 |
|
| 779 | - */ |
|
| 775 | + /** |
|
| 776 | + * Retrieves the form's html. |
|
| 777 | + * |
|
| 778 | + * @since 1.0.19 |
|
| 779 | + */ |
|
| 780 | 780 | public function get_html( $extra_markup = '' ) { |
| 781 | 781 | |
| 782 | - // Return the HTML. |
|
| 783 | - return wpinv_get_template_html( |
|
| 784 | - 'payment-forms/form.php', |
|
| 785 | - array( |
|
| 786 | - 'form' => $this, |
|
| 787 | - 'extra_markup' => $extra_markup, |
|
| 788 | - ) |
|
| 789 | - ); |
|
| 790 | - |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Displays the payment form. |
|
| 795 | - * |
|
| 796 | - * @since 1.0.19 |
|
| 797 | - */ |
|
| 782 | + // Return the HTML. |
|
| 783 | + return wpinv_get_template_html( |
|
| 784 | + 'payment-forms/form.php', |
|
| 785 | + array( |
|
| 786 | + 'form' => $this, |
|
| 787 | + 'extra_markup' => $extra_markup, |
|
| 788 | + ) |
|
| 789 | + ); |
|
| 790 | + |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Displays the payment form. |
|
| 795 | + * |
|
| 796 | + * @since 1.0.19 |
|
| 797 | + */ |
|
| 798 | 798 | public function display( $extra_markup = '' ) { |
| 799 | - wpinv_get_template( |
|
| 800 | - 'payment-forms/form.php', |
|
| 801 | - array( |
|
| 802 | - 'form' => $this, |
|
| 803 | - 'extra_markup' => $extra_markup, |
|
| 804 | - ) |
|
| 805 | - ); |
|
| 799 | + wpinv_get_template( |
|
| 800 | + 'payment-forms/form.php', |
|
| 801 | + array( |
|
| 802 | + 'form' => $this, |
|
| 803 | + 'extra_markup' => $extra_markup, |
|
| 804 | + ) |
|
| 805 | + ); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | } |