/** * Complete a purchase aka donation * * Performs all necessary actions to complete a purchase. * Triggered by the give_update_payment_status() function. * * @since 1.0 * * @param int $payment_id The ID number of the payment. * @param string $new_status The status of the payment, probably "publish". * @param string $old_status The status of the payment prior to being marked as "complete", probably "pending". * * @return void */ function give_complete_purchase($payment_id, $new_status, $old_status) { // Make sure that payments are only completed once if ($old_status == 'publish' || $old_status == 'complete') { return; } // Make sure the payment completion is only processed when new status is complete if ($new_status != 'publish' && $new_status != 'complete') { return; } $payment = new Give_Payment($payment_id); $creation_date = get_post_field('post_date', $payment_id, 'raw'); $payment_meta = $payment->payment_meta; $completed_date = $payment->completed_date; $user_info = $payment->user_info; $customer_id = $payment->customer_id; $amount = $payment->total; $price_id = $payment->price_id; $form_id = $payment->form_id; do_action('give_pre_complete_purchase', $payment_id); // Ensure these actions only run once, ever if (empty($completed_date)) { give_record_sale_in_log($form_id, $payment_id, $price_id, $creation_date); do_action('give_complete_form_donation', $form_id, $payment_id, $payment_meta); } // Increase the earnings for this form ID give_increase_earnings($form_id, $amount); give_increase_purchase_count($form_id); // Clear the total earnings cache delete_transient('give_earnings_total'); // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('give_earnings_this_monththis_month')); delete_transient(md5('give_earnings_todaytoday')); // Increase the donor's purchase stats $customer = new Give_Customer($customer_id); $customer->increase_purchase_count(); $customer->increase_value($amount); give_increase_total_earnings($amount); // Ensure this action only runs once ever if (empty($completed_date)) { // Save the completed date $payment->completed_date = current_time('mysql'); $payment->save(); /** * Fires after a donation successfully complete. * * @since 1.6 * * @param int $payment_id The ID of the payment. */ do_action('give_complete_purchase', $payment_id); } }
/** * Complete a purchase * * Performs all necessary actions to complete a purchase. * Triggered by the give_update_payment_status() function. * * @since 1.0 * * @param int $payment_id the ID number of the payment * @param string $new_status the status of the payment, probably "publish" * @param string $old_status the status of the payment prior to being marked as "complete", probably "pending" * * @return void */ function give_complete_purchase($payment_id, $new_status, $old_status) { if ($old_status == 'publish' || $old_status == 'complete') { return; } // Make sure that payments are only completed once // Make sure the payment completion is only processed when new status is complete if ($new_status != 'publish' && $new_status != 'complete') { return; } $payment_meta = give_get_payment_meta($payment_id); $creation_date = get_post_field('post_date', $payment_id, 'raw'); $completed_date = give_get_payment_completed_date($payment_id); $user_info = give_get_payment_meta_user_info($payment_id); $donor_id = give_get_payment_customer_id($payment_id); $amount = give_get_payment_amount($payment_id); do_action('give_pre_complete_purchase', $payment_id); $price_id = isset($_POST['give-price-id']) ? (int) $_POST['give-price-id'] : false; // Ensure these actions only run once, ever if (empty($completed_date)) { if (!give_is_test_mode() || apply_filters('give_log_test_payment_stats', false)) { give_record_sale_in_log($payment_meta['form_id'], $payment_id, $price_id, $creation_date); give_increase_purchase_count($payment_meta['form_id']); give_increase_earnings($payment_meta['form_id'], $amount); } do_action('give_complete_form_donation', $payment_meta['form_id'], $payment_id, $payment_meta); } // Clear the total earnings cache delete_transient('give_earnings_total'); // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('give_earnings_this_monththis_month')); delete_transient(md5('give_earnings_todaytoday')); // Increase the donor's purchase stats Give()->customers->increment_stats($donor_id, $amount); give_increase_total_earnings($amount); // Ensure this action only runs once ever if (empty($completed_date)) { // Save the completed date give_update_payment_meta($payment_id, '_give_completed_date', current_time('mysql')); do_action('give_complete_purchase', $payment_id); } }