/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @return void */ function give_process_purchase_form() { do_action('give_pre_process_purchase'); // Validate the form $_POST data $valid_data = give_purchase_form_validate_fields(); // Allow themes and plugins to hook to errors do_action('give_checkout_error_checks', $valid_data, $_POST); $is_ajax = isset($_POST['give_ajax']); // Process the login form if (isset($_POST['give_login_submit'])) { give_process_form_login(); } // Validate the user $user = give_get_purchase_form_user($valid_data); if (give_get_errors() || !$user) { if ($is_ajax) { do_action('give_ajax_checkout_errors'); give_die(); } else { return false; } } if ($is_ajax) { echo 'success'; give_die(); } // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'address' => $user['address']); $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; // Setup purchase information $purchase_data = array('price' => isset($_POST['give-amount']) ? (double) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00', 'purchase_key' => strtolower(md5($user['user_email'] . date('Y-m-d H:i:s') . $auth_key . uniqid('give', true))), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s', current_time('timestamp')), 'user_info' => stripslashes_deep($user_info), 'post_data' => $_POST, 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // Add the user data for hooks $valid_data['user'] = $user; // Allow themes and plugins to hook before the gateway do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); // If the total amount in the cart is 0, send to the manual gateway. This emulates a free purchase if (!$purchase_data['price']) { // Revert to manual $purchase_data['gateway'] = 'manual'; $_POST['give-gateway'] = 'manual'; } // Allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('give_purchase_data_before_gateway', $purchase_data, $valid_data); // Setup the data we're storing in the purchase session $session_data = $purchase_data; // Make sure credit card numbers are never stored in sessions unset($session_data['card_info']['card_number']); // Used for showing data to non logged-in users after purchase, and for other plugins needing purchase data. give_set_purchase_session($session_data); // Send info to the gateway for payment processing give_send_to_gateway($purchase_data['gateway'], $purchase_data); give_die(); }
/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @return void */ function give_process_purchase_form() { do_action('give_pre_process_purchase'); // Validate the form $_POST data $valid_data = give_purchase_form_validate_fields(); // Allow themes and plugins to hook to errors do_action('give_checkout_error_checks', $valid_data, $_POST); $is_ajax = isset($_POST['give_ajax']); // Process the login form if (isset($_POST['give_login_submit'])) { give_process_form_login(); } // Validate the user $user = give_get_purchase_form_user($valid_data); if (false === $valid_data || give_get_errors() || !$user) { if ($is_ajax) { do_action('give_ajax_checkout_errors'); give_die(); } else { return false; } } //If AJAX send back success to proceed with form submission if ($is_ajax) { echo 'success'; give_die(); } //After AJAX: Setup session if not using php_sessions if (!Give()->session->use_php_sessions()) { //Double-check that set_cookie is publicly accessible; // we're using a slightly modified class-wp-sessions.php $session_reflection = new ReflectionMethod('WP_Session', 'set_cookie'); if ($session_reflection->isPublic()) { // Manually set the cookie. Give()->session->init()->set_cookie(); } } // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'address' => $user['address']); $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; $price = isset($_POST['give-amount']) ? (double) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00'; $purchase_key = strtolower(md5($user['user_email'] . date('Y-m-d H:i:s') . $auth_key . uniqid('give', true))); // Setup purchase information $purchase_data = array('price' => $price, 'purchase_key' => $purchase_key, 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s', current_time('timestamp')), 'user_info' => stripslashes_deep($user_info), 'post_data' => $_POST, 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // Add the user data for hooks $valid_data['user'] = $user; // Allow themes and plugins to hook before the gateway do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); //Sanity check for price if (!$purchase_data['price']) { // Revert to manual $purchase_data['gateway'] = 'manual'; $_POST['give-gateway'] = 'manual'; } // Allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('give_purchase_data_before_gateway', $purchase_data, $valid_data); // Setup the data we're storing in the purchase session $session_data = $purchase_data; // Make sure credit card numbers are never stored in sessions unset($session_data['card_info']['card_number']); unset($session_data['post_data']['card_number']); // Used for showing data to non logged-in users after purchase, and for other plugins needing purchase data. give_set_purchase_session($session_data); // Send info to the gateway for payment processing give_send_to_gateway($purchase_data['gateway'], $purchase_data); give_die(); }