PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.4.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.4.1
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
← All changes | includes/Admin/DB.php +207 -111 2.1.1 → 2.4.1 View file →
@@ -19,8 +19,16 @@
19 19 * @since 0.0.1
20 20 */
21 21 class DB {
22 22
23 + /**
24 + * Helper's counting rule (an unconfirmed pre-2.4.0 `no_payment_required` row is not counted; a
25 + * confirmed one adds 0), aliased so the two deprecated queries below spell it `self::…` exactly
26 + * as Pro's AnalyticsModel copies do (AnalyticsModelParityTest compares the bodies).
27 + */
28 + private const COUNTED_ROW_SQL = Helper::COUNTED_ROW_SQL;
29 + private const COUNTABLE_AMOUNT_SQL = Helper::COUNTABLE_AMOUNT_SQL;
30 +
23 31 public static function get_table_name() {
24 32 global $wpdb;
25 33
26 34 $table = "{$wpdb->prefix}better_payment";
@@ -78,15 +86,40 @@
78 86 'better_payment_settings_payment_paystack_live_public' => '',
79 87 'better_payment_settings_payment_paystack_live_secret' => '',
80 88 'better_payment_settings_payment_paystack_test_public' => '',
81 89 'better_payment_settings_payment_paystack_test_secret' => '',
90 +
91 + // AI Assistant (Campaign Builder). See includes/AI/.
92 + 'better_payment_settings_ai_enabled' => '',
93 + 'better_payment_settings_ai_provider' => 'openai',
94 + 'better_payment_settings_ai_model' => '',
95 + 'better_payment_settings_ai_image_model' => '',
96 + 'better_payment_settings_ai_temperature' => '0.7',
97 + 'better_payment_settings_ai_max_tokens' => '4096',
98 + 'better_payment_settings_ai_system_prompt' => '',
99 + 'better_payment_settings_ai_api_key_openai' => '',
100 + 'better_payment_settings_ai_api_key_claude' => '',
101 + 'better_payment_settings_ai_api_key_gemini' => '',
102 + 'better_payment_settings_ai_api_key_openrouter' => '',
103 +
104 + // E-commerce > Subscription. Booleans follow the 'yes'/'no' string
105 + // convention used across this settings array.
106 + 'better_payment_settings_ecommerce_subscription_renewal_process' => 'auto',
107 + 'better_payment_settings_ecommerce_subscription_stripe_auto_renew' => 'yes',
108 + 'better_payment_settings_ecommerce_subscription_auto_renewal_toggle' => 'yes',
109 + 'better_payment_settings_ecommerce_subscription_myaccount_tab' => 'yes',
110 + 'better_payment_settings_ecommerce_subscription_active_role' => 'subscriber',
111 + 'better_payment_settings_ecommerce_subscription_inactive_role' => 'customer',
82 112 ));
83 113 }
84 114 /**
85 115 * Get all settings value from options table.
86 116 *
117 + * Returns the full settings array when $name is empty, otherwise the single
118 + * value for that key (which may be a string, array, etc.).
119 + *
87 120 * @param string $name
88 - * @return array
121 + * @return mixed
89 122 * @since 0.0.1
90 123 */
91 124 public static function get_settings($name = '')
92 125 {
@@ -123,11 +156,43 @@
123 156 return update_option('better_payment_settings', $value);
124 157 }
125 158
126 159 /**
160 + * The UTC `payment_date` bounds for a date range picked in site time.
161 + *
162 + * The admin date filter sends whole days (`Y-m-d`), picked on the site's
163 + * calendar. Compared as-is, `BETWEEN '2026-10-11' AND '2026-10-11'` matched
164 + * only rows at exactly midnight — so the last day of every range was dropped
165 + * — and the days were UTC days, not the site's. A day bound is widened to the
166 + * whole site day (00:00:00 – 23:59:59) and converted to UTC, which is how
167 + * `payment_date` is stored. A bound that already carries a time is passed
168 + * through unchanged.
169 + *
170 + * @since 2.4.1
171 + *
172 + * @param string $from Lower bound.
173 + * @param string $to Upper bound.
174 + * @return string[] [ from, to ].
175 + */
176 + public static function payment_date_range( $from, $to ) {
177 + $from = trim( (string) $from );
178 + $to = trim( (string) $to );
179 +
180 + if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $from ) ) {
181 + $from = get_gmt_from_date( $from . ' 00:00:00', 'Y-m-d H:i:s' );
182 + }
183 +
184 + if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $to ) ) {
185 + $to = get_gmt_from_date( $to . ' 23:59:59', 'Y-m-d H:i:s' );
186 + }
187 +
188 + return array( $from, $to );
189 + }
190 +
191 + /**
127 192 * Get all transactions from better payment table.
128 193 *
129 - * @param string $args
194 + * @param array|string $args Filters, as wp_parse_args() reads them (every caller passes an array).
130 195 * @return array
131 196 * @since 0.0.1
132 197 */
133 198 public static function get_transactions($args = [], $count_only=0, $version = 'v1', $fetchNull = 0, $transaction_type = '')
@@ -188,10 +253,21 @@
188 253 $statuses_by_transaction_type = array();
189 254
190 255 if( !empty($transaction_type) ){
191 256 $statuses_by_types = $better_payment_helper_obj->transaction_statuses_with_type_v2();
192 - $statuses_by_transaction_type = isset($statuses_by_types[$transaction_type]['statuses']) ? $statuses_by_types[$transaction_type]['statuses'] : $defaults['status'];
193 - $status = '';
257 + $transaction_type = is_string( $transaction_type ) ? $transaction_type : 'all';
258 +
259 + if ( 'null' === $transaction_type ) {
260 + // The count twin of `status=null` below.
261 + $status = 'null';
262 + $transaction_type = '';
263 + } else {
264 + // An unknown type is every row, as an unknown `status` is. It used to fall back to the
265 + // string 'all' and fatal in array_map() below.
266 + $transaction_type = isset( $statuses_by_types[ $transaction_type ] ) ? $transaction_type : 'all';
267 + $statuses_by_transaction_type = $statuses_by_types[ $transaction_type ]['statuses'];
268 + $status = '';
269 + }
194 270 }
195 271
196 272 $whereQuery = '';
197 273
@@ -225,19 +301,37 @@
225 301
226 302 $statuses = array_map(function($status) {
227 303 return "'" . esc_sql($status) . "'";
228 304 }, $statuses_by_type);
229 -
305 +
230 306 $statuses = implode(',', $statuses);
231 -
232 - $nullDataQuery = $fetchNull ? " OR status IS NULL " : '';
233 - $whereQuery .= " AND ( status IN ( $statuses ) " . esc_sql($nullDataQuery) . " ) ";
307 +
308 + $bucket = $transaction_type ? $transaction_type : $status;
309 +
310 + // NULL is the incomplete bucket's own status (PayPal's pending sentinel): `IN ()`
311 + // cannot match it, so the Incomplete tab always ORs it in and lists the rows its
312 + // total and stat card count.
313 + $nullDataQuery = ( $fetchNull || 'incomplete' === $bucket ) ? " OR status IS NULL " : '';
314 +
315 + // The counting rule, for the tabs: an unconfirmed pre-2.4.0 `no_payment_required`
316 + // row is in no count, so it is listed under Incomplete, never Completed, as
317 + // Helper::transaction_status_type() labels it. A confirmed one stays Completed;
318 + // `refunded` is unchanged. Helper constants only (no request data, no `%`).
319 + $unconfirmed_sql = 'incomplete' === $bucket ? ' OR ' . Helper::UNCONFIRMED_LEGACY_SQL . ' ' : '';
320 + $counted_sql = 'completed' === $bucket ? ' AND ' . Helper::COUNTED_ROW_SQL . ' ' : '';
321 +
322 + // `all` is every row, as the All tab's list is: its `IN ()` list would leave NULL and
323 + // unlisted statuses out of the total.
324 + if ( 'all' !== $bucket ) {
325 + $whereQuery .= " AND ( status IN ( $statuses ) " . esc_sql($nullDataQuery) . $unconfirmed_sql . " ) " . $counted_sql;
326 + }
234 327 }
235 328 }
236 329 }
237 330
238 331 if( $args['payment_date_from'] != '' && $args['payment_date_to'] != ''){
239 - $whereQuery .= $wpdb->prepare(" AND payment_date BETWEEN %s AND %s", $args['payment_date_from'], $args['payment_date_to']);
332 + $range = self::payment_date_range( $args['payment_date_from'], $args['payment_date_to'] );
333 + $whereQuery .= $wpdb->prepare(" AND payment_date BETWEEN %s AND %s", $range[0], $range[1]);
240 334 }
241 335
242 336 if($count_only === 1){
243 337 if($valid_search_text){
@@ -310,40 +404,11 @@
310 404
311 405 /**
312 406 * Get transactions analytics
313 407 *
314 - * @return int
408 + * @return array<string, mixed>
315 409 * @since 0.0.1
316 410 */
317 - public static function get_transactions_analytics($filtered_transactions = array())
318 - {
319 - global $wpdb;
320 - $transaction_analytics = [];
321 -
322 - $table = self::get_table_name();
323 - $better_payment_db_obj = new DB();
324 -
325 - $total_transactions = $better_payment_db_obj->get_transactions_amount_by_statuses(array(), '', '', 'count', 1, $filtered_transactions );
326 -
327 - $completed_statuses = $better_payment_db_obj->allowed_statuses('completed', 'v2');
328 - $completed_transactions = $better_payment_db_obj->get_transactions_amount_by_statuses( $completed_statuses, '', '', 'count', 0, $filtered_transactions );
329 -
330 - $incomplete_statuses = $better_payment_db_obj->allowed_statuses('incomplete', 'v2');
331 - $incomplete_transactions = $better_payment_db_obj->get_transactions_amount_by_statuses( $incomplete_statuses, '', '', 'count', 1, $filtered_transactions );
332 -
333 - $transaction_analytics['total_transactions'] = $total_transactions;
334 - $transaction_analytics['completed_transactions'] = $completed_transactions;
335 - $transaction_analytics['incomplete_transactions'] = $incomplete_transactions;
336 -
337 - return $transaction_analytics;
338 - }
339 -
340 - /**
341 - * Get transactions analytics
342 - *
343 - * @return int
344 - * @since 0.0.1
345 - */
346 411 public static function get_transactions_analytics_dashboard($filtered_transactions = array())
347 412 {
348 413 global $wpdb;
349 414 $transaction_analytics = [];
@@ -417,35 +482,15 @@
417 482 return $item;
418 483 }
419 484
420 485 /**
421 - * Get transaction details from better payment table.
422 - *
423 - * @param string $args
424 - * @return object
425 - * @since 0.0.1
426 - */
427 - public static function get_transactions_by_email($email)
428 - {
429 - global $wpdb;
430 -
431 - $table = self::get_table_name();
432 - $email = sanitize_text_field($email);
433 -
434 - $item = $wpdb->get_results(
435 - $wpdb->prepare(
436 - "SELECT * FROM $table WHERE email = %s order by payment_date DESC",
437 - $email
438 - )
439 - );
440 -
441 - return $item;
442 - }
443 -
444 - /**
445 486 * Get analytics counts and amounts for a specific user via a single SQL aggregate query.
446 487 * Returns the same shape as get_transactions_analytics_dashboard() without loading all rows.
447 488 *
489 + * An unconfirmed pre-2.4.0 `no_payment_required` row is left out of every figure; a confirmed
490 + * one counts as completed and adds 0 to the amounts (Helper::COUNTED_ROW_SQL /
491 + * Helper::COUNTABLE_AMOUNT_SQL).
492 + *
448 493 * @param string $email
449 494 * @return array
450 495 */
451 496 public static function get_user_analytics_by_email( $email ) {
@@ -453,25 +498,30 @@
453 498 $table = self::get_table_name();
454 499 $email = sanitize_text_field( $email );
455 500 $ffi_like = '%' . $wpdb->esc_like( '"' . $email . '"' ) . '%';
456 501
502 + // Helper constants only: no request data, and no `%` for prepare() to misread.
503 + $countable_amount = 'CAST(' . Helper::COUNTABLE_AMOUNT_SQL . ' AS DECIMAL(10,2))';
504 + $completed = "status IN ('paid','Completed','completed','success','" . Helper::LEGACY_FREE_CHECKOUT_STATUS . "')";
505 + $counted_row = Helper::COUNTED_ROW_SQL;
506 +
457 507 $row = $wpdb->get_row(
458 508 $wpdb->prepare(
459 509 "SELECT
460 510 COUNT(*) AS total_count,
461 - SUM(CAST(amount AS DECIMAL(10,2))) AS total_amount,
462 - SUM(CASE WHEN status IN ('paid','Completed','completed','success')
511 + SUM({$countable_amount}) AS total_amount,
512 + SUM(CASE WHEN {$completed}
463 513 THEN 1 ELSE 0 END) AS completed_count,
464 - SUM(CASE WHEN status IN ('paid','Completed','completed','success')
465 - THEN CAST(amount AS DECIMAL(10,2)) ELSE 0 END) AS completed_amount,
466 - SUM(CASE WHEN status IN ('pending','Pending','unpaid','incomplete','Incomplete') OR status IS NULL
514 + SUM(CASE WHEN {$completed}
515 + THEN {$countable_amount} ELSE 0 END) AS completed_amount,
516 + SUM(CASE WHEN status IN ('pending','Pending','unpaid','incomplete','Incomplete','failed') OR status IS NULL
467 517 THEN 1 ELSE 0 END) AS incomplete_count,
468 - SUM(CASE WHEN status IN ('pending','Pending','unpaid','incomplete','Incomplete') OR status IS NULL
518 + SUM(CASE WHEN status IN ('pending','Pending','unpaid','incomplete','Incomplete','failed') OR status IS NULL
469 519 THEN CAST(amount AS DECIMAL(10,2)) ELSE 0 END) AS incomplete_amount,
470 520 SUM(CASE WHEN status = 'refunded' THEN 1 ELSE 0 END) AS refunded_count,
471 521 SUM(CASE WHEN status = 'refunded'
472 522 THEN CAST(amount AS DECIMAL(10,2)) ELSE 0 END) AS refunded_amount
473 - FROM $table WHERE ( email = %s OR form_fields_info LIKE %s )",
523 + FROM $table WHERE ( email = %s OR form_fields_info LIKE %s ) AND {$counted_row}",
474 524 $email,
475 525 $ffi_like
476 526 )
477 527 );
@@ -516,11 +566,19 @@
516 566 $page = max( 1, intval( $args['page'] ) );
517 567 $per_page = max( 1, intval( $args['per_page'] ) );
518 568 $offset = ( $page - 1 ) * $per_page;
519 569
520 - $type_where = '';
521 - if ( 'subscriptions' === $args['type'] ) {
522 - $type_where = " AND form_fields_info LIKE '%\"subscription_id\"%'";
570 + $type_where = self::user_transactions_type_where( (string) $args['type'] );
571 + if ( null === $type_where ) {
572 + // Nothing defines this row type (e.g. 'subscriptions' without Pro): answer
573 + // with no rows, never with every row the user owns.
574 + return [
575 + 'transactions' => [],
576 + 'total' => 0,
577 + 'pages' => 1,
578 + 'page' => $page,
579 + 'per_page' => $per_page,
580 + ];
523 581 }
524 582
525 583 // Match rows where the email column is set directly OR where the email
526 584 // appears as a quoted value inside the serialized form_fields_info blob.
@@ -558,8 +616,32 @@
558 616 ];
559 617 }
560 618
561 619 /**
620 + * The SQL condition narrowing get_user_transactions_paginated() to a row type.
621 + *
622 + * 'transactions' (or no type) is every row the user owns. Every other type is
623 + * defined by `better_payment/db/user_transactions_type_where` ($where, $type),
624 + * which starts from null: Pro supplies the 'subscriptions' condition for its
625 + * recurring and split payments. A type nobody defines returns null, and the
626 + * caller answers with no rows.
627 + *
628 + * @since 2.4.0
629 + *
630 + * @param string $type Requested row type.
631 + * @return string|null SQL fragment starting with " AND", '' for all rows, null for none.
632 + */
633 + private static function user_transactions_type_where( string $type ) {
634 + if ( '' === $type || 'transactions' === $type ) {
635 + return '';
636 + }
637 +
638 + $where = apply_filters( 'better_payment/db/user_transactions_type_where', null, $type );
639 +
640 + return is_string( $where ) ? $where : null;
641 + }
642 +
643 + /**
562 644 * Delete a transaction
563 645 *
564 646 * @param int $id
565 647 *
@@ -604,8 +686,17 @@
604 686
605 687 /**
606 688 * Get transactions amount
607 689 *
690 + * Lite never calls this; Better Payment Pro <= 1.4.3's AnalyticsModel does, and
691 + * tests/Unit/ProCouplingContractTest.php pins it. Pro 1.4.4 carries its own copy
692 + * (better-payment-pro/includes/Models/AnalyticsModel.php).
693 + *
694 + * @deprecated 2.4.0 A fatal guard only: Pro 1.4.3 is unsupported since
695 + * ProCompatibility::MIN_PRO_VERSION 1.4.4, but a site that updates Lite
696 + * first must not fatal on Pro's Analytics screen. Delete once no
697 + * supported site can run Pro 1.4.3.
698 + *
608 699 * @return array
609 700 * @since 0.0.1
610 701 */
611 702 public function get_transactions_by_statuses($statuses = array(), $payment_date_from = '', $payment_date_to = '', $fetchNull=0) {
@@ -630,17 +721,17 @@
630 721 $statuses = implode(',', $statuses);
631 722
632 723 if(!empty($payment_date_from) && !empty($payment_date_to)){
633 724 $amount = $wpdb->get_results(
634 - "SELECT amount, payment_date, email FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ") AND payment_date BETWEEN '" . esc_sql($payment_date_from) . "' AND '" . esc_sql($payment_date_to) . "'"
725 + "SELECT " . self::COUNTABLE_AMOUNT_SQL . " AS amount, payment_date, email FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ") AND " . self::COUNTED_ROW_SQL . " AND payment_date BETWEEN '" . esc_sql($payment_date_from) . "' AND '" . esc_sql($payment_date_to) . "'"
635 726 );
636 727 } else if(!empty($payment_date_from) && empty($payment_date_to)){
637 728 $amount = $wpdb->get_results(
638 - "SELECT amount, payment_date, email FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ") AND payment_date >= '" . esc_sql($payment_date_from) . "'"
729 + "SELECT " . self::COUNTABLE_AMOUNT_SQL . " AS amount, payment_date, email FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ") AND " . self::COUNTED_ROW_SQL . " AND payment_date >= '" . esc_sql($payment_date_from) . "'"
639 730 );
640 731 } else {
641 732 $amount = $wpdb->get_results(
642 - "SELECT amount, payment_date, email FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . " )"
733 + "SELECT " . self::COUNTABLE_AMOUNT_SQL . " AS amount, payment_date, email FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . " ) AND " . self::COUNTED_ROW_SQL
643 734 );
644 735 }
645 736
646 737 return $amount;
@@ -648,15 +739,17 @@
648 739
649 740 /**
650 741 * Get transactions amount
651 742 *
652 - * @return array
743 + * Lite's caller, get_transactions_analytics_dashboard(), always passes
744 + * $filtered_transactions and is answered from that array. Without it the answer
745 + * comes from SQL, which only Better Payment Pro <= 1.4.3's AnalyticsModel asks
746 + * for — see transactions_amount_by_statuses_query().
747 + *
748 + * @return mixed
653 749 * @since 0.0.1
654 750 */
655 751 public function get_transactions_amount_by_statuses($statuses = array(), $payment_date_from = '', $payment_date_to = '', $count_or_amount = 'amount', $fetchNull=0, $filtered_transactions = array() ) {
656 - global $wpdb;
657 -
658 - $table = DB::get_table_name();
659 752 $allowed_statuses = $this->allowed_statuses('all', 'v2');
660 753
661 754 $nullDataQuery = $fetchNull ? " OR status IS NULL " : '';
662 755
@@ -678,13 +771,19 @@
678 771 $filtered_transactions_by_statuses = array();
679 772 $filtered_transactions_amount = 0;
680 773
681 774 foreach($filtered_transactions as $filtered_transaction) {
775 + // Helper's counting rule, as the SQL copies below apply it: an unconfirmed pre-2.4.0
776 + // free checkout is no transaction to count, and a confirmed one adds 0.
777 + if ( Helper::is_unconfirmed_legacy_free_checkout( $filtered_transaction ) ) {
778 + continue;
779 + }
780 +
682 781 if( in_array($filtered_transaction->status, $statuses_original) ) {
683 782 $filtered_transactions_by_statuses[] = $filtered_transaction->id;
684 - $filtered_transactions_amount += ! empty( $filtered_transaction->amount ) ? floatval( $filtered_transaction->amount ) : 0;
783 + $filtered_transactions_amount += Helper::countable_amount( $filtered_transaction );
685 784 }
686 - }
785 + }
687 786
688 787 if($count_or_amount == 'count'){
689 788 $filtered_transactions_by_statuses_count = count($filtered_transactions_by_statuses);
690 789 return $filtered_transactions_by_statuses_count;
@@ -694,11 +793,34 @@
694 793 return $filtered_transactions_amount;
695 794 }
696 795 }
697 796
797 + return $this->transactions_amount_by_statuses_query( $statuses, $nullDataQuery, $payment_date_from, $payment_date_to, $count_or_amount );
798 + }
799 +
800 + /**
801 + * The SQL count or sum behind get_transactions_amount_by_statuses() when no
802 + * filtered transactions are passed.
803 + *
804 + * @deprecated 2.4.0 A fatal guard only, for Better Payment Pro <= 1.4.3 (see
805 + * get_transactions_by_statuses()). Pro 1.4.4 carries its own copy in
806 + * better-payment-pro/includes/Models/AnalyticsModel.php.
807 + *
808 + * @param string $statuses Quoted, comma-separated statuses for IN().
809 + * @param string $nullDataQuery " OR status IS NULL " or ''.
810 + * @param string $payment_date_from Lower payment_date bound.
811 + * @param string $payment_date_to Upper payment_date bound.
812 + * @param string $count_or_amount 'count' or 'amount'.
813 + * @return mixed
814 + */
815 + private function transactions_amount_by_statuses_query( $statuses, $nullDataQuery, $payment_date_from, $payment_date_to, $count_or_amount ) {
816 + global $wpdb;
817 +
818 + $table = DB::get_table_name();
819 +
698 820 if($count_or_amount == 'count') {
699 821 $count = (int) $wpdb->get_var(
700 - "SELECT count(id) FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . " )"
822 + "SELECT count(id) FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . " ) AND " . self::COUNTED_ROW_SQL
701 823 );
702 824
703 825 return $count;
704 826 }
@@ -704,44 +826,18 @@
704 826 }
705 827
706 828 if(!empty($payment_date_from) && !empty($payment_date_to)){
707 829 $amount = $wpdb->get_var(
708 - "SELECT sum(amount) FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ") AND payment_date BETWEEN '" . esc_sql($payment_date_from) . "' AND '" . esc_sql($payment_date_to) . "'"
830 + "SELECT sum(" . self::COUNTABLE_AMOUNT_SQL . ") FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ") AND " . self::COUNTED_ROW_SQL . " AND payment_date BETWEEN '" . esc_sql($payment_date_from) . "' AND '" . esc_sql($payment_date_to) . "'"
709 831 );
710 832 }else {
711 833 $amount = $wpdb->get_var(
712 834 // #TODO Amount based on filtered transactions
713 - "SELECT sum(amount) FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ")"
835 + "SELECT sum(" . self::COUNTABLE_AMOUNT_SQL . ") FROM $table WHERE ( status IN (" . $statuses . ") " . esc_sql($nullDataQuery) . ") AND " . self::COUNTED_ROW_SQL
714 836 );
715 837 }
716 838
717 839 return $amount;
718 - }
719 -
720 - public static function search_transactions($items, $search_text, $offset, $per_page){
721 - $filtered_items = array();
722 - $search_text = str_replace('%', '', $search_text);
723 -
724 - if(count($items) > 0){
725 - $filtered_items = array_filter($items, function($item) use ($search_text){
726 - $form_fields_info = maybe_unserialize($item->form_fields_info);
727 -
728 - if(
729 - isset($form_fields_info['first_name']) && stripos($form_fields_info['first_name'], $search_text) !== false
730 - || isset($form_fields_info['last_name']) && stripos($form_fields_info['last_name'], $search_text) !== false
731 - || isset($form_fields_info['primary_first_name']) && stripos($form_fields_info['primary_first_name'], $search_text) !== false
732 - || isset($form_fields_info['primary_last_name']) && stripos($form_fields_info['primary_last_name'], $search_text) !== false
733 - || isset($form_fields_info['email']) && stripos($form_fields_info['email'], $search_text) !== false
734 - || isset($form_fields_info['primary_email']) && stripos($form_fields_info['primary_email'], $search_text) !== false
735 - ){
736 - return true;
737 - }
738 -
739 - });
740 -
741 - }
742 -
743 - return $filtered_items;
744 840 }
745 841
746 842 public static function mark_as_completed($id)
747 843 {