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