| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | /** |
| 12 | 12 | * @return array |
| 13 | 13 | */ |
| 14 | 14 | public function get_defaults() { |
| 15 | - $values = array( | |
| 15 | + return array( | |
| 16 | 16 | 'receipt_id' => array( |
| 17 | 17 | 'sanitize' => 'sanitize_text_field', |
| 18 | 18 | 'default' => '', |
| 19 | 19 | ), |
| @@ -65,9 +65,8 @@ | ||
| 65 | 65 | 'sanitize' => 'sanitize_text_field', |
| 66 | 66 | 'default' => null, |
| 67 | 67 | ), |
| 68 | 68 | ); |
| 69 | - return $values; | |
| 70 | 69 | } |
| 71 | 70 | |
| 72 | 71 | /** |
| 73 | 72 | * Gets payments statistic data. |
| @@ -73,10 +72,11 @@ | ||
| 73 | 72 | * Gets payments statistic data. |
| 74 | 73 | * |
| 75 | 74 | * @since 6.7 |
| 76 | 75 | * |
| 77 | - * @param string $from_date From date. | |
| 78 | - * @param string $to_date To date. | |
| 76 | + * @param string|null $from_date From date. | |
| 77 | + * @param string|null $to_date To date. | |
| 78 | + * | |
| 79 | 79 | * @return array Contains `count` and `total`. |
| 80 | 80 | */ |
| 81 | 81 | public function get_payments_stats( $from_date = null, $to_date = null ) { |
| 82 | 82 | $data = array( |
| @@ -88,22 +88,26 @@ | ||
| 88 | 88 | return $data; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $where = array(); |
| 92 | + | |
| 92 | 93 | if ( null !== $from_date ) { |
| 93 | 94 | $where['created_at >'] = $from_date; |
| 94 | 95 | } |
| 96 | + | |
| 95 | 97 | if ( null !== $to_date ) { |
| 96 | 98 | $where['created_at <'] = $to_date . ' 23:59:59'; |
| 97 | 99 | } |
| 98 | 100 | |
| 101 | + $db_version = get_option( $this->db_opt_name ); | |
| 102 | + | |
| 99 | 103 | // Do not collect test payment, this is a new feature of Stripe lite. |
| 100 | - if ( 6 <= get_option( $this->db_opt_name ) ) { | |
| 104 | + if ( 6 <= $db_version ) { | |
| 101 | 105 | $where['test'] = array( null, 0 ); |
| 102 | 106 | } |
| 103 | 107 | |
| 104 | 108 | // If only Paypal is used, and the DB isn't migrated (to version 4), use `completed` column instead of `status`. |
| 105 | - if ( 4 > get_option( $this->db_opt_name ) && FrmDb::db_column_exists( $this->table_name, 'completed' ) ) { | |
| 109 | + if ( 4 > $db_version && FrmDb::db_column_exists( $this->table_name, 'completed' ) ) { | |
| 106 | 110 | $where['completed'] = 1; |
| 107 | 111 | } else { |
| 108 | 112 | $where['status'] = 'complete'; |
| 109 | 113 | } |
| @@ -125,12 +129,14 @@ | ||
| 125 | 129 | * |
| 126 | 130 | * @since 6.7 |
| 127 | 131 | * |
| 128 | 132 | * @param object[] $payments Array of payment objects. |
| 133 | + * | |
| 129 | 134 | * @return array Return array of total amount for each currency. |
| 130 | 135 | */ |
| 131 | 136 | private function get_payment_total_data( $payments ) { |
| 132 | 137 | $data = array(); |
| 138 | + | |
| 133 | 139 | foreach ( $payments as $payment ) { |
| 134 | 140 | list( $amount, $currency ) = FrmTransLiteAppHelper::get_amount_and_currency_from_payment( $payment ); |
| 135 | 141 | |
| 136 | 142 | if ( ! isset( $data[ $currency ] ) ) { |