actions.php
8 years ago
class-payments-table.php
8 years ago
payments-history.php
8 years ago
view-payment-details.php
8 years ago
class-payments-table.php
1036 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Payment History Table Class |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Admin/Payments |
| 7 | * @copyright Copyright (c) 2016, Give |
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | * @since 1.0 |
| 10 | */ |
| 11 | |
| 12 | // Exit if accessed directly. |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | // Load WP_List_Table if not loaded. |
| 18 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 19 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Give_Payment_History_Table Class |
| 24 | * |
| 25 | * Renders the Payment History table on the Payment History page |
| 26 | * |
| 27 | * @since 1.0 |
| 28 | */ |
| 29 | class Give_Payment_History_Table extends WP_List_Table { |
| 30 | |
| 31 | /** |
| 32 | * Number of results to show per page |
| 33 | * |
| 34 | * @var string |
| 35 | * @since 1.0 |
| 36 | */ |
| 37 | public $per_page = 30; |
| 38 | |
| 39 | /** |
| 40 | * URL of this page |
| 41 | * |
| 42 | * @var string |
| 43 | * @since 1.0.1 |
| 44 | */ |
| 45 | public $base_url; |
| 46 | |
| 47 | /** |
| 48 | * Total number of payments |
| 49 | * |
| 50 | * @var int |
| 51 | * @since 1.0 |
| 52 | */ |
| 53 | public $total_count; |
| 54 | |
| 55 | /** |
| 56 | * Total number of complete payments |
| 57 | * |
| 58 | * @var int |
| 59 | * @since 1.0 |
| 60 | */ |
| 61 | public $complete_count; |
| 62 | |
| 63 | /** |
| 64 | * Total number of pending payments |
| 65 | * |
| 66 | * @var int |
| 67 | * @since 1.0 |
| 68 | */ |
| 69 | public $pending_count; |
| 70 | |
| 71 | /** |
| 72 | * Total number of processing payments |
| 73 | * |
| 74 | * @var int |
| 75 | * @since 1.8.9 |
| 76 | */ |
| 77 | public $processing_count; |
| 78 | |
| 79 | /** |
| 80 | * Total number of refunded payments |
| 81 | * |
| 82 | * @var int |
| 83 | * @since 1.0 |
| 84 | */ |
| 85 | public $refunded_count; |
| 86 | |
| 87 | /** |
| 88 | * Total number of failed payments |
| 89 | * |
| 90 | * @var int |
| 91 | * @since 1.0 |
| 92 | */ |
| 93 | public $failed_count; |
| 94 | |
| 95 | /** |
| 96 | * Total number of revoked payments |
| 97 | * |
| 98 | * @var int |
| 99 | * @since 1.0 |
| 100 | */ |
| 101 | public $revoked_count; |
| 102 | |
| 103 | /** |
| 104 | * Total number of cancelled payments |
| 105 | * |
| 106 | * @var int |
| 107 | * @since 1.4 |
| 108 | */ |
| 109 | public $cancelled_count; |
| 110 | |
| 111 | /** |
| 112 | * Total number of abandoned payments |
| 113 | * |
| 114 | * @var int |
| 115 | * @since 1.6 |
| 116 | */ |
| 117 | public $abandoned_count; |
| 118 | |
| 119 | /** |
| 120 | * Total number of pre-approved payments |
| 121 | * |
| 122 | * @var int |
| 123 | * @since 1.8.13 |
| 124 | */ |
| 125 | public $preapproval_count; |
| 126 | |
| 127 | /** |
| 128 | * Get things started. |
| 129 | * |
| 130 | * @since 1.0 |
| 131 | * @uses Give_Payment_History_Table::get_payment_counts() |
| 132 | * @see WP_List_Table::__construct() |
| 133 | */ |
| 134 | public function __construct() { |
| 135 | |
| 136 | // Set parent defaults. |
| 137 | parent::__construct( |
| 138 | array( |
| 139 | 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
| 140 | 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
| 141 | 'ajax' => false, // Does this table support ajax? |
| 142 | ) |
| 143 | ); |
| 144 | |
| 145 | $this->process_bulk_action(); |
| 146 | $this->get_payment_counts(); |
| 147 | $this->base_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Add donation search filter. |
| 152 | * |
| 153 | * @return void |
| 154 | */ |
| 155 | public function advanced_filters() { |
| 156 | $start_date = isset( $_GET['start-date'] ) ? give_clean( $_GET['start-date'] ) : null; |
| 157 | $end_date = isset( $_GET['end-date'] ) ? give_clean( $_GET['end-date'] ) : null; |
| 158 | $status = isset( $_GET['status'] ) ? give_clean( $_GET['status'] ) : ''; |
| 159 | $donor = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : ''; |
| 160 | $search = isset( $_GET['s'] ) ? give_clean( $_GET['s'] ) : ''; |
| 161 | $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; |
| 162 | ?> |
| 163 | <div id="give-payment-filters" class="give-filters"> |
| 164 | <?php $this->search_box( __( 'Search', 'give' ), 'give-payments' ); ?> |
| 165 | <div id="give-payment-date-filters"> |
| 166 | <div class="give-filter give-filter-half"> |
| 167 | <label for="start-date" |
| 168 | class="give-start-date-label"><?php _e( 'Start Date', 'give' ); ?></label> |
| 169 | <input type="text" id="start-date" name="start-date" class="give_datepicker" |
| 170 | value="<?php echo $start_date; ?>" placeholder="mm/dd/yyyy"/> |
| 171 | </div> |
| 172 | <div class="give-filter give-filter-half"> |
| 173 | <label for="end-date" class="give-end-date-label"><?php _e( 'End Date', 'give' ); ?></label> |
| 174 | <input type="text" id="end-date" name="end-date" class="give_datepicker" |
| 175 | value="<?php echo $end_date; ?>" placeholder="mm/dd/yyyy"/> |
| 176 | </div> |
| 177 | </div> |
| 178 | <div id="give-payment-form-filter" class="give-filter"> |
| 179 | <label for="give-donation-forms-filter" |
| 180 | class="give-donation-forms-filter-label"><?php _e( 'Form', 'give' ); ?></label> |
| 181 | <?php |
| 182 | // Filter Donations by Donation Forms. |
| 183 | echo Give()->html->forms_dropdown( |
| 184 | array( |
| 185 | 'name' => 'form_id', |
| 186 | 'id' => 'give-donation-forms-filter', |
| 187 | 'class' => 'give-donation-forms-filter', |
| 188 | 'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection. |
| 189 | 'chosen' => true, |
| 190 | 'number' => - 1, |
| 191 | ) |
| 192 | ); |
| 193 | ?> |
| 194 | </div> |
| 195 | |
| 196 | <?php |
| 197 | /** |
| 198 | * Action to add hidden fields and HTML in Payment search. |
| 199 | * |
| 200 | * @since 1.8.18 |
| 201 | */ |
| 202 | do_action( 'give_payment_table_advanced_filters' ); |
| 203 | |
| 204 | |
| 205 | if ( ! empty( $status ) ) { |
| 206 | echo sprintf( '<input type="hidden" name="status" value="%s"/>', esc_attr( $status ) ); |
| 207 | } |
| 208 | |
| 209 | if ( ! empty( $donor ) ) { |
| 210 | echo sprintf( '<input type="hidden" name="donor" value="%s"/>', absint( $donor ) ); |
| 211 | } |
| 212 | ?> |
| 213 | |
| 214 | <div class="give-filter"> |
| 215 | <?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?> |
| 216 | <?php |
| 217 | // Clear active filters button. |
| 218 | if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor ) || ! empty( $search ) || ! empty( $status ) || ! empty( $form_id ) ) : |
| 219 | ?> |
| 220 | <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>" |
| 221 | class="button give-clear-filters-button"><?php _e( 'Clear Filters', 'give' ); ?></a> |
| 222 | <?php endif; ?> |
| 223 | </div> |
| 224 | </div> |
| 225 | |
| 226 | <?php |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Show the search field |
| 231 | * |
| 232 | * @param string $text Label for the search box. |
| 233 | * @param string $input_id ID of the search box. |
| 234 | * |
| 235 | * @since 1.0 |
| 236 | * @access public |
| 237 | * |
| 238 | * @return void |
| 239 | */ |
| 240 | public function search_box( $text, $input_id ) { |
| 241 | if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | $input_id = $input_id . '-search-input'; |
| 246 | |
| 247 | if ( ! empty( $_REQUEST['orderby'] ) ) { |
| 248 | echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
| 249 | } |
| 250 | if ( ! empty( $_REQUEST['order'] ) ) { |
| 251 | echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
| 252 | } |
| 253 | ?> |
| 254 | <div class="give-filter give-filter-search" role="search"> |
| 255 | <?php |
| 256 | /** |
| 257 | * Fires in the payment history search box. |
| 258 | * |
| 259 | * Allows you to add new elements before the search box. |
| 260 | * |
| 261 | * @since 1.7 |
| 262 | */ |
| 263 | do_action( 'give_payment_history_search' ); |
| 264 | ?> |
| 265 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
| 266 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/> |
| 267 | <?php submit_button( $text, 'button', false, false, array( |
| 268 | 'ID' => 'search-submit', |
| 269 | ) ); ?><br/> |
| 270 | </div> |
| 271 | <?php |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Retrieve the view types |
| 276 | * |
| 277 | * @access public |
| 278 | * @since 1.0 |
| 279 | * |
| 280 | * @return array $views All the views available |
| 281 | */ |
| 282 | public function get_views() { |
| 283 | |
| 284 | $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
| 285 | $views = array(); |
| 286 | $tabs = array( |
| 287 | 'all' => array( |
| 288 | 'total_count', |
| 289 | __( 'All', 'give' ), |
| 290 | ), |
| 291 | 'publish' => array( |
| 292 | 'complete_count', |
| 293 | __( 'Completed', 'give' ), |
| 294 | ), |
| 295 | 'pending' => array( |
| 296 | 'pending_count', |
| 297 | __( 'Pending', 'give' ), |
| 298 | ), |
| 299 | 'processing' => array( |
| 300 | 'processing_count', |
| 301 | __( 'Processing', 'give' ), |
| 302 | ), |
| 303 | 'refunded' => array( |
| 304 | 'refunded_count', |
| 305 | __( 'Refunded', 'give' ), |
| 306 | ), |
| 307 | 'revoked' => array( |
| 308 | 'revoked_count', |
| 309 | __( 'Revoked', 'give' ), |
| 310 | ), |
| 311 | 'failed' => array( |
| 312 | 'failed_count', |
| 313 | __( 'Failed', 'give' ), |
| 314 | ), |
| 315 | 'cancelled' => array( |
| 316 | 'cancelled_count', |
| 317 | __( 'Cancelled', 'give' ), |
| 318 | ), |
| 319 | 'abandoned' => array( |
| 320 | 'abandoned_count', |
| 321 | __( 'Abandoned', 'give' ), |
| 322 | ), |
| 323 | 'preapproval' => array( |
| 324 | 'preapproval_count', |
| 325 | __( 'Preapproval Pending', 'give' ), |
| 326 | ), |
| 327 | ); |
| 328 | |
| 329 | /** |
| 330 | * Remove Query from Args of the URL that are being pass to Donation Status. |
| 331 | * |
| 332 | * @since 1.8.18 |
| 333 | */ |
| 334 | $args = (array) apply_filters( 'give_payments_table_status_remove_query_arg', array( 'paged', '_wpnonce', '_wp_http_referer' ) ); |
| 335 | |
| 336 | // Build URL. |
| 337 | $staus_url = remove_query_arg( $args ); |
| 338 | |
| 339 | foreach ( $tabs as $key => $tab ) { |
| 340 | $count_key = $tab[0]; |
| 341 | $name = $tab[1]; |
| 342 | $count = $this->$count_key; |
| 343 | |
| 344 | /** |
| 345 | * Filter can be used to show all the status inside the donation tabs. |
| 346 | * |
| 347 | * Filter can be used to show all the status inside the donation submenu tabs return true to show all the tab. |
| 348 | * |
| 349 | * @param string $key Current view tab value. |
| 350 | * @param int $count Number of donation inside the tab. |
| 351 | * |
| 352 | * @since 1.8.12 |
| 353 | */ |
| 354 | if ( 'all' === $key || $key === $current || apply_filters( 'give_payments_table_show_all_status', 0 < $count, $key, $count ) ) { |
| 355 | |
| 356 | $staus_url = 'all' === $key ? |
| 357 | add_query_arg( array( 'status' => false ), $staus_url ) : |
| 358 | add_query_arg( array( 'status' => $key ), $staus_url ); |
| 359 | |
| 360 | $views[ $key ] = sprintf( |
| 361 | '<a href="%s"%s>%s <span class="count">(%s)</span></a>', |
| 362 | esc_url( $staus_url ), |
| 363 | ( ( 'all' === $key && empty( $current ) ) ) ? ' class="current"' : ( $current == $key ? 'class="current"' : '' ), |
| 364 | $name, |
| 365 | $count |
| 366 | ); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Filter the donation listing page views. |
| 372 | * |
| 373 | * @since 1.0 |
| 374 | * |
| 375 | * @param array $views |
| 376 | * @param Give_Payment_History_Table |
| 377 | */ |
| 378 | return apply_filters( 'give_payments_table_views', $views, $this ); |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Retrieve the table columns |
| 383 | * |
| 384 | * @access public |
| 385 | * @since 1.0 |
| 386 | * |
| 387 | * @return array $columns Array of all the list table columns |
| 388 | */ |
| 389 | public function get_columns() { |
| 390 | $columns = array( |
| 391 | 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text. |
| 392 | 'donation' => __( 'Donation', 'give' ), |
| 393 | 'donation_form' => __( 'Donation Form', 'give' ), |
| 394 | 'status' => __( 'Status', 'give' ), |
| 395 | 'date' => __( 'Date', 'give' ), |
| 396 | 'amount' => __( 'Amount', 'give' ), |
| 397 | ); |
| 398 | |
| 399 | if ( current_user_can( 'view_give_payments' ) ) { |
| 400 | $columns['details'] = __( 'Details', 'give' ); |
| 401 | } |
| 402 | |
| 403 | return apply_filters( 'give_payments_table_columns', $columns ); |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Retrieve the table's sortable columns |
| 408 | * |
| 409 | * @access public |
| 410 | * @since 1.0 |
| 411 | * |
| 412 | * @return array Array of all the sortable columns |
| 413 | */ |
| 414 | public function get_sortable_columns() { |
| 415 | $columns = array( |
| 416 | 'donation' => array( 'ID', true ), |
| 417 | 'donation_form' => array( 'donation_form', false ), |
| 418 | 'status' => array( 'status', false ), |
| 419 | 'amount' => array( 'amount', false ), |
| 420 | 'date' => array( 'date', false ), |
| 421 | ); |
| 422 | |
| 423 | return apply_filters( 'give_payments_table_sortable_columns', $columns ); |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Gets the name of the primary column. |
| 428 | * |
| 429 | * @since 1.5 |
| 430 | * @access protected |
| 431 | * |
| 432 | * @return string Name of the primary column. |
| 433 | */ |
| 434 | protected function get_primary_column_name() { |
| 435 | return 'donation'; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * This function renders most of the columns in the list table. |
| 440 | * |
| 441 | * @param Give_Payment $payment Payment ID. |
| 442 | * @param string $column_name The name of the column. |
| 443 | * |
| 444 | * @access public |
| 445 | * @since 1.0 |
| 446 | * |
| 447 | * @return string Column Name |
| 448 | */ |
| 449 | public function column_default( $payment, $column_name ) { |
| 450 | |
| 451 | $single_donation_url = esc_url( add_query_arg( 'id', $payment->ID, admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details' ) ) ); |
| 452 | $row_actions = $this->get_row_actions( $payment ); |
| 453 | $value = ''; |
| 454 | |
| 455 | switch ( $column_name ) { |
| 456 | case 'donation' : |
| 457 | $serial_code = Give()->seq_donation_number->get_serial_code( $payment ); |
| 458 | if ( current_user_can( 'view_give_payments' ) ) { |
| 459 | $value = Give()->tooltips->render_link( array( |
| 460 | 'label' => sprintf( __( 'View Donation %s', 'give' ), $serial_code ), |
| 461 | 'tag_content' => $serial_code, |
| 462 | 'link' => $single_donation_url, |
| 463 | ) ); |
| 464 | } else { |
| 465 | $value = $serial_code; |
| 466 | } |
| 467 | |
| 468 | $value .= sprintf( |
| 469 | ' %1$s %2$s<br>', |
| 470 | __( 'by', 'give' ), |
| 471 | $this->get_donor( $payment ) |
| 472 | ); |
| 473 | |
| 474 | $value .= $this->get_donor_email( $payment ); |
| 475 | $value .= $this->row_actions( $row_actions ); |
| 476 | break; |
| 477 | |
| 478 | case 'amount': |
| 479 | $value = give_donation_amount( $payment, true ); |
| 480 | $value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) ); |
| 481 | break; |
| 482 | |
| 483 | case 'donation_form': |
| 484 | $form_title = empty( $payment->form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $payment->form_id ) : $payment->form_title; |
| 485 | $value = '<a href="' . admin_url( 'post.php?post=' . $payment->form_id . '&action=edit' ) . '">' . $form_title . '</a>'; |
| 486 | $level = give_get_donation_form_title( |
| 487 | $payment, |
| 488 | array( |
| 489 | 'only_level' => true, |
| 490 | ) |
| 491 | ); |
| 492 | |
| 493 | if ( ! empty( $level ) ) { |
| 494 | $value .= $level; |
| 495 | } |
| 496 | |
| 497 | break; |
| 498 | |
| 499 | case 'date': |
| 500 | $date = strtotime( $payment->date ); |
| 501 | $value = date_i18n( give_date_format(), $date ); |
| 502 | break; |
| 503 | |
| 504 | case 'status': |
| 505 | $value = $this->get_payment_status( $payment ); |
| 506 | break; |
| 507 | |
| 508 | |
| 509 | case 'details' : |
| 510 | if ( current_user_can( 'view_give_payments' ) ) { |
| 511 | $value = Give()->tooltips->render_link( array( |
| 512 | 'label' => sprintf( __( 'View Donation #%s', 'give' ), $payment->ID ), |
| 513 | 'tag_content' => '<span class="dashicons dashicons-visibility"></span>', |
| 514 | 'link' => $single_donation_url, |
| 515 | 'attributes' => array( |
| 516 | 'class' => 'give-payment-details-link button button-small', |
| 517 | ), |
| 518 | ) ); |
| 519 | |
| 520 | $value = "<div class=\"give-payment-details-link-wrap\">{$value}</div>"; |
| 521 | } |
| 522 | break; |
| 523 | |
| 524 | default: |
| 525 | $value = isset( $payment->$column_name ) ? $payment->$column_name : ''; |
| 526 | break; |
| 527 | |
| 528 | }// End switch(). |
| 529 | |
| 530 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, $column_name ); |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Get donor email html. |
| 535 | * |
| 536 | * @param object $payment Contains all the data of the payment. |
| 537 | * |
| 538 | * @access public |
| 539 | * @since 1.0 |
| 540 | * |
| 541 | * @return string Data shown in the Email column |
| 542 | */ |
| 543 | public function get_donor_email( $payment ) { |
| 544 | |
| 545 | $email = give_get_payment_user_email( $payment->ID ); |
| 546 | |
| 547 | if ( empty( $email ) ) { |
| 548 | $email = __( '(unknown)', 'give' ); |
| 549 | } |
| 550 | |
| 551 | |
| 552 | $value = Give()->tooltips->render_link( array( |
| 553 | 'link' => "mailto:{$email}", |
| 554 | 'label' => __( 'Email donor', 'give' ), |
| 555 | 'tag_content' => $email, |
| 556 | ) ); |
| 557 | |
| 558 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' ); |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Get Row Actions |
| 563 | * |
| 564 | * @param object $payment Payment Data. |
| 565 | * |
| 566 | * @since 1.6 |
| 567 | * |
| 568 | * @return array $actions |
| 569 | */ |
| 570 | function get_row_actions( $payment ) { |
| 571 | |
| 572 | $actions = array(); |
| 573 | $email = give_get_payment_user_email( $payment->ID ); |
| 574 | |
| 575 | // Add search term string back to base URL. |
| 576 | $search_terms = ( isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '' ); |
| 577 | if ( ! empty( $search_terms ) ) { |
| 578 | $this->base_url = add_query_arg( 's', $search_terms, $this->base_url ); |
| 579 | } |
| 580 | |
| 581 | if ( give_is_payment_complete( $payment->ID ) && ! empty( $email ) ) { |
| 582 | |
| 583 | $actions['email_links'] = sprintf( |
| 584 | '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( |
| 585 | add_query_arg( |
| 586 | array( |
| 587 | 'give-action' => 'email_links', |
| 588 | 'purchase_id' => $payment->ID, |
| 589 | ), $this->base_url |
| 590 | ), 'give_payment_nonce' |
| 591 | ), sprintf( __( 'Resend Donation %s Receipt', 'give' ), $payment->ID ), __( 'Resend Receipt', 'give' ) |
| 592 | ); |
| 593 | |
| 594 | } |
| 595 | |
| 596 | if ( current_user_can( 'view_give_payments' ) ) { |
| 597 | $actions['delete'] = sprintf( |
| 598 | '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>', |
| 599 | wp_nonce_url( |
| 600 | add_query_arg( |
| 601 | array( |
| 602 | 'give-action' => 'delete_payment', |
| 603 | 'purchase_id' => $payment->ID, |
| 604 | ), $this->base_url |
| 605 | ), 'give_donation_nonce' |
| 606 | ), sprintf( __( 'Delete Donation %s', 'give' ), $payment->ID ), __( 'Delete', 'give' ) |
| 607 | ); |
| 608 | } |
| 609 | |
| 610 | return apply_filters( 'give_payment_row_actions', $actions, $payment ); |
| 611 | } |
| 612 | |
| 613 | |
| 614 | /** |
| 615 | * Get payment status html. |
| 616 | * |
| 617 | * @since 1.0 |
| 618 | * @access public |
| 619 | * |
| 620 | * @param Give_Payment $payment Contains all the data of the payment. |
| 621 | * |
| 622 | * @return string Data shown in the Email column |
| 623 | */ |
| 624 | function get_payment_status( $payment ) { |
| 625 | $value = sprintf( |
| 626 | '<div class="give-donation-status status-%1$s"><span class="give-donation-status-icon"></span> %2$s</div>', |
| 627 | $payment->status, |
| 628 | give_get_payment_status( $payment, true ) |
| 629 | ); |
| 630 | |
| 631 | if ( $payment->mode == 'test' ) { |
| 632 | $value .= Give()->tooltips->render_span( array( |
| 633 | 'label' => __( 'This donation was made in test mode.', 'give' ), |
| 634 | 'tag_content' => __( 'Test', 'give' ), |
| 635 | 'attributes' => array( |
| 636 | 'class' => 'give-item-label give-item-label-orange give-test-mode-transactions-label', |
| 637 | ), |
| 638 | |
| 639 | |
| 640 | ) ); |
| 641 | } |
| 642 | |
| 643 | if ( true === $payment->import && true === (bool) apply_filters( 'give_payment_show_importer_label', false ) ) { |
| 644 | $value .= sprintf( |
| 645 | ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="%1$s">%2$s</span>', |
| 646 | __( 'This donation was imported.', 'give' ), |
| 647 | __( 'Import', 'give' ) |
| 648 | ); |
| 649 | } |
| 650 | |
| 651 | return $value; |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Get checkbox html. |
| 656 | * |
| 657 | * @param object $payment Contains all the data for the checkbox column. |
| 658 | * |
| 659 | * @access public |
| 660 | * @since 1.0 |
| 661 | * |
| 662 | * @return string Displays a checkbox. |
| 663 | */ |
| 664 | public function column_cb( $payment ) { |
| 665 | return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID ); |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Get payment ID html. |
| 670 | * |
| 671 | * @param object $payment Contains all the data for the checkbox column. |
| 672 | * |
| 673 | * @access public |
| 674 | * @since 1.0 |
| 675 | * |
| 676 | * @return string Displays a checkbox. |
| 677 | */ |
| 678 | public function get_payment_id( $payment ) { |
| 679 | return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>'; |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * Get donor html. |
| 684 | * |
| 685 | * @param object $payment Contains all the data of the payment. |
| 686 | * |
| 687 | * @access public |
| 688 | * @since 1.0 |
| 689 | * |
| 690 | * @return string Data shown in the User column |
| 691 | */ |
| 692 | public function get_donor( $payment ) { |
| 693 | |
| 694 | $donor_id = give_get_payment_donor_id( $payment->ID ); |
| 695 | $donor_billing_name = give_get_donor_name_by( $payment->ID, 'donation' ); |
| 696 | $donor_name = give_get_donor_name_by( $donor_id, 'donor' ); |
| 697 | |
| 698 | $value = ''; |
| 699 | if ( ! empty( $donor_id ) ) { |
| 700 | |
| 701 | // Check whether the donor name and WP_User name is same or not. |
| 702 | if ( sanitize_title( $donor_billing_name ) !== sanitize_title( $donor_name ) ) { |
| 703 | $value .= $donor_billing_name . ' ('; |
| 704 | } |
| 705 | |
| 706 | $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id" ) ) . '">' . $donor_name . '</a>'; |
| 707 | |
| 708 | // Check whether the donor name and WP_User name is same or not. |
| 709 | if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
| 710 | $value .= ')'; |
| 711 | } |
| 712 | } else { |
| 713 | $email = give_get_payment_user_email( $payment->ID ); |
| 714 | $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ) . '">' . __( '(donor missing)', 'give' ) . '</a>'; |
| 715 | } |
| 716 | |
| 717 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' ); |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * Retrieve the bulk actions |
| 722 | * |
| 723 | * @access public |
| 724 | * @since 1.0 |
| 725 | * |
| 726 | * @return array $actions Array of the bulk actions |
| 727 | */ |
| 728 | public function get_bulk_actions() { |
| 729 | $actions = array( |
| 730 | 'delete' => __( 'Delete', 'give' ), |
| 731 | 'set-status-publish' => __( 'Set To Completed', 'give' ), |
| 732 | 'set-status-pending' => __( 'Set To Pending', 'give' ), |
| 733 | 'set-status-processing' => __( 'Set To Processing', 'give' ), |
| 734 | 'set-status-refunded' => __( 'Set To Refunded', 'give' ), |
| 735 | 'set-status-revoked' => __( 'Set To Revoked', 'give' ), |
| 736 | 'set-status-failed' => __( 'Set To Failed', 'give' ), |
| 737 | 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ), |
| 738 | 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ), |
| 739 | 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ), |
| 740 | 'resend-receipt' => __( 'Resend Email Receipts', 'give' ), |
| 741 | ); |
| 742 | |
| 743 | return apply_filters( 'give_payments_table_bulk_actions', $actions ); |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Process the bulk actions |
| 748 | * |
| 749 | * @access public |
| 750 | * @since 1.0 |
| 751 | * |
| 752 | * @return void |
| 753 | */ |
| 754 | public function process_bulk_action() { |
| 755 | $ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false; |
| 756 | $action = $this->current_action(); |
| 757 | |
| 758 | if ( ! is_array( $ids ) ) { |
| 759 | $ids = array( $ids ); |
| 760 | } |
| 761 | |
| 762 | if ( empty( $action ) ) { |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | foreach ( $ids as $id ) { |
| 767 | |
| 768 | // Detect when a bulk action is being triggered. |
| 769 | switch ( $this->current_action() ) { |
| 770 | |
| 771 | case 'delete': |
| 772 | give_delete_donation( $id ); |
| 773 | break; |
| 774 | |
| 775 | case 'set-status-publish': |
| 776 | give_update_payment_status( $id, 'publish' ); |
| 777 | break; |
| 778 | |
| 779 | case 'set-status-pending': |
| 780 | give_update_payment_status( $id, 'pending' ); |
| 781 | break; |
| 782 | |
| 783 | case 'set-status-processing': |
| 784 | give_update_payment_status( $id, 'processing' ); |
| 785 | break; |
| 786 | |
| 787 | case 'set-status-refunded': |
| 788 | give_update_payment_status( $id, 'refunded' ); |
| 789 | break; |
| 790 | case 'set-status-revoked': |
| 791 | give_update_payment_status( $id, 'revoked' ); |
| 792 | break; |
| 793 | |
| 794 | case 'set-status-failed': |
| 795 | give_update_payment_status( $id, 'failed' ); |
| 796 | break; |
| 797 | |
| 798 | case 'set-status-cancelled': |
| 799 | give_update_payment_status( $id, 'cancelled' ); |
| 800 | break; |
| 801 | |
| 802 | case 'set-status-abandoned': |
| 803 | give_update_payment_status( $id, 'abandoned' ); |
| 804 | break; |
| 805 | |
| 806 | case 'set-status-preapproval': |
| 807 | give_update_payment_status( $id, 'preapproval' ); |
| 808 | break; |
| 809 | |
| 810 | case 'resend-receipt': |
| 811 | /** |
| 812 | * Fire the action |
| 813 | * |
| 814 | * @since 2.0 |
| 815 | */ |
| 816 | do_action( 'give_donation-receipt_email_notification', $id ); |
| 817 | break; |
| 818 | }// End switch(). |
| 819 | |
| 820 | /** |
| 821 | * Fires after triggering bulk action on payments table. |
| 822 | * |
| 823 | * @param int $id The ID of the payment. |
| 824 | * @param string $current_action The action that is being triggered. |
| 825 | * |
| 826 | * @since 1.7 |
| 827 | */ |
| 828 | do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() ); |
| 829 | }// End foreach(). |
| 830 | |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * Retrieve the payment counts |
| 835 | * |
| 836 | * @access public |
| 837 | * @since 1.0 |
| 838 | * |
| 839 | * @return object |
| 840 | */ |
| 841 | public function get_payment_counts() { |
| 842 | |
| 843 | $args = array(); |
| 844 | |
| 845 | if ( isset( $_GET['user'] ) ) { |
| 846 | $args['user'] = urldecode( $_GET['user'] ); |
| 847 | } elseif ( isset( $_GET['donor'] ) ) { |
| 848 | $args['donor'] = absint( $_GET['donor'] ); |
| 849 | } elseif ( isset( $_GET['s'] ) ) { |
| 850 | $is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false; |
| 851 | if ( $is_user ) { |
| 852 | $args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) ); |
| 853 | unset( $args['s'] ); |
| 854 | } else { |
| 855 | $args['s'] = sanitize_text_field( $_GET['s'] ); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | if ( ! empty( $_GET['start-date'] ) ) { |
| 860 | $args['start-date'] = urldecode( $_GET['start-date'] ); |
| 861 | } |
| 862 | |
| 863 | if ( ! empty( $_GET['end-date'] ) ) { |
| 864 | $args['end-date'] = urldecode( $_GET['end-date'] ); |
| 865 | } |
| 866 | |
| 867 | $args['form_id'] = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
| 868 | $args['gateway'] = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null; |
| 869 | |
| 870 | $payment_count = give_count_payments( $args ); |
| 871 | $this->complete_count = $payment_count->publish; |
| 872 | $this->pending_count = $payment_count->pending; |
| 873 | $this->processing_count = $payment_count->processing; |
| 874 | $this->refunded_count = $payment_count->refunded; |
| 875 | $this->failed_count = $payment_count->failed; |
| 876 | $this->revoked_count = $payment_count->revoked; |
| 877 | $this->cancelled_count = $payment_count->cancelled; |
| 878 | $this->abandoned_count = $payment_count->abandoned; |
| 879 | $this->preapproval_count = $payment_count->preapproval; |
| 880 | |
| 881 | foreach ( $payment_count as $count ) { |
| 882 | $this->total_count += $count; |
| 883 | } |
| 884 | |
| 885 | return $payment_count; |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Retrieve all the data for all the payments. |
| 890 | * |
| 891 | * @access public |
| 892 | * @since 1.0 |
| 893 | * |
| 894 | * @return array objects in array containing all the data for the payments |
| 895 | */ |
| 896 | public function payments_data() { |
| 897 | |
| 898 | $per_page = $this->per_page; |
| 899 | $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID'; |
| 900 | $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; |
| 901 | $user = isset( $_GET['user'] ) ? $_GET['user'] : null; |
| 902 | $donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null; |
| 903 | $status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys(); |
| 904 | $meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null; |
| 905 | $year = isset( $_GET['year'] ) ? $_GET['year'] : null; |
| 906 | $month = isset( $_GET['m'] ) ? $_GET['m'] : null; |
| 907 | $day = isset( $_GET['day'] ) ? $_GET['day'] : null; |
| 908 | $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null; |
| 909 | $start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
| 910 | $end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : $start_date; |
| 911 | $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
| 912 | $gateway = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null; |
| 913 | |
| 914 | $args = array( |
| 915 | 'output' => 'payments', |
| 916 | 'number' => $per_page, |
| 917 | 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, |
| 918 | 'orderby' => $orderby, |
| 919 | 'order' => $order, |
| 920 | 'user' => $user, |
| 921 | 'donor' => $donor, |
| 922 | 'status' => $status, |
| 923 | 'meta_key' => $meta_key, |
| 924 | 'year' => $year, |
| 925 | 'month' => $month, |
| 926 | 'day' => $day, |
| 927 | 's' => $search, |
| 928 | 'start_date' => $start_date, |
| 929 | 'gateway' => $gateway, |
| 930 | 'end_date' => $end_date, |
| 931 | 'give_forms' => $form_id, |
| 932 | ); |
| 933 | |
| 934 | if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) { |
| 935 | $args['search_in_notes'] = true; |
| 936 | $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) ); |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * Filter to modify payment table argument. |
| 941 | * |
| 942 | * @since 1.8.18 |
| 943 | */ |
| 944 | $args = (array) apply_filters( 'give_payment_table_payments_query', $args ); |
| 945 | |
| 946 | $p_query = new Give_Payments_Query( $args ); |
| 947 | |
| 948 | return $p_query->get_payments(); |
| 949 | |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * Setup the final data for the table |
| 954 | * |
| 955 | * @access public |
| 956 | * @since 1.0 |
| 957 | * @uses Give_Payment_History_Table::get_columns() |
| 958 | * @uses Give_Payment_History_Table::get_sortable_columns() |
| 959 | * @uses Give_Payment_History_Table::payments_data() |
| 960 | * @uses WP_List_Table::get_pagenum() |
| 961 | * @uses WP_List_Table::set_pagination_args() |
| 962 | * |
| 963 | * @return void |
| 964 | */ |
| 965 | public function prepare_items() { |
| 966 | |
| 967 | wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) ); |
| 968 | |
| 969 | $columns = $this->get_columns(); |
| 970 | $hidden = array(); // No hidden columns. |
| 971 | $sortable = $this->get_sortable_columns(); |
| 972 | $data = $this->payments_data(); |
| 973 | $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
| 974 | |
| 975 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
| 976 | |
| 977 | switch ( $status ) { |
| 978 | case 'publish': |
| 979 | $total_items = $this->complete_count; |
| 980 | break; |
| 981 | case 'pending': |
| 982 | $total_items = $this->pending_count; |
| 983 | break; |
| 984 | case 'processing': |
| 985 | $total_items = $this->processing_count; |
| 986 | break; |
| 987 | case 'refunded': |
| 988 | $total_items = $this->refunded_count; |
| 989 | break; |
| 990 | case 'failed': |
| 991 | $total_items = $this->failed_count; |
| 992 | break; |
| 993 | case 'revoked': |
| 994 | $total_items = $this->revoked_count; |
| 995 | break; |
| 996 | case 'cancelled': |
| 997 | $total_items = $this->cancelled_count; |
| 998 | break; |
| 999 | case 'abandoned': |
| 1000 | $total_items = $this->abandoned_count; |
| 1001 | break; |
| 1002 | case 'preapproval': |
| 1003 | $total_items = $this->preapproval_count; |
| 1004 | break; |
| 1005 | case 'any': |
| 1006 | $total_items = $this->total_count; |
| 1007 | break; |
| 1008 | default: |
| 1009 | // Retrieve the count of the non-default-Give status. |
| 1010 | $count = wp_count_posts( 'give_payment' ); |
| 1011 | $total_items = isset( $count->{$status} ) ? $count->{$status} : 0; |
| 1012 | break; |
| 1013 | } |
| 1014 | |
| 1015 | $this->items = $data; |
| 1016 | |
| 1017 | /** |
| 1018 | * Filter to modify total count of the pagination. |
| 1019 | * |
| 1020 | * @since 1.8.19 |
| 1021 | */ |
| 1022 | $total_items = (int) apply_filters( 'give_payment_table_pagination_total_count', $total_items, $this ); |
| 1023 | |
| 1024 | $this->set_pagination_args( |
| 1025 | array( |
| 1026 | 'total_items' => $total_items, |
| 1027 | // We have to calculate the total number of items. |
| 1028 | 'per_page' => $this->per_page, |
| 1029 | // We have to determine how many items to show on a page. |
| 1030 | 'total_pages' => ceil( $total_items / $this->per_page ), |
| 1031 | // We have to calculate the total number of pages. |
| 1032 | ) |
| 1033 | ); |
| 1034 | } |
| 1035 | } |
| 1036 |