/** * Test Pending without Affecting Stats */ public function test_pending_without_affecting_stats() { add_filter('give_decrease_earnings_on_undo', '__return_false'); add_filter('give_decrease_sales_on_undo', '__return_false'); add_filter('give_decrease_customer_value_on_pending', '__return_false'); add_filter('give_decrease_customer_purchase_count_on_pending', '__return_false'); add_filter('give_decrease_store_earnings_on_pending', '__return_false'); $payment = new Give_Payment($this->_payment_id); $payment->status = 'complete'; $payment->save(); $customer = new Give_Customer($payment->customer_id); $form = new Give_Donate_Form($payment->form_id); $customer_sales = $customer->purchase_count; $customer_earnings = $customer->purchase_value; $form_sales = $form->sales; $form_earnings = $form->earnings; $site_earnings = give_get_total_earnings(); $site_sales = give_get_total_sales(); $payment->status = 'pending'; $payment->save(); wp_cache_flush(); $payment = new Give_Payment($this->_payment_id); $this->assertEmpty($payment->completed_date); $customer = new Give_Customer($payment->customer_id); $form = new Give_Donate_Form($payment->form_id); $this->assertEquals($customer_earnings, $customer->purchase_value); $this->assertEquals($customer_sales, $customer->purchase_count); $this->assertEquals($form_earnings, $form->earnings); $this->assertEquals($form_sales, $form->sales); $this->assertEquals($site_earnings, give_get_total_earnings()); // Store sales are based off 'publish' & 'revoked' status. So it reduces this count $this->assertEquals($site_sales - 1, give_get_total_sales()); remove_filter('give_decrease_earnings_on_undo', '__return_false'); remove_filter('give_decrease_sales_on_undo', '__return_false'); remove_filter('give_decrease_customer_value_on_pending', '__return_false'); remove_filter('give_decrease_customer_purchase_count_on_pending', '__return_false'); remove_filter('give_decrease_store_earnings_on_pending', '__return_false '); }
/** * Generate the default earnings stats returned by the 'stats' endpoint * * @access private * @since 1.1 * @return array default earnings statistics */ private function get_default_earnings_stats() { // Default earnings return $earnings = array(); $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); $earnings['earnings']['totals'] = give_get_total_earnings(); return $earnings; }
/** * Decrease the Total Earnings * * @since 1.0 * * @param $amount int The amount you would like to decrease the total earnings by. * * @return float $total Total earnings */ function give_decrease_total_earnings($amount = 0) { $total = give_get_total_earnings(); $total -= $amount; if ($total < 0) { $total = 0; } update_option('give_earnings_total', $total); return $total; }