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