private function submit_payment_method() { global $wpsc_cart; if (!$this->verify_nonce('wpsc-checkout-form-payment-method')) { return; } if (empty($_POST['wpsc_payment_method']) && !wpsc_is_free_cart()) { $this->message_collection->add(__('Please select a payment method', 'wp-e-commerce'), 'validation'); } $valid = apply_filters('_wpsc_merchant_v2_validate_payment_method', true, $this); if (!$valid) { return; } $purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id'); $purchase_log = new WPSC_Purchase_Log($purchase_log_id); $submitted_gateway = $_POST['wpsc_payment_method']; $purchase_log->set(array('gateway' => $submitted_gateway, 'base_shipping' => $wpsc_cart->calculate_base_shipping(), 'totalprice' => $wpsc_cart->calculate_total_price())); if ($this->maybe_add_guest_account() && isset($_POST['wpsc_create_account'])) { $email = wpsc_get_customer_meta('billingemail'); $user_id = wpsc_register_customer($email, $email, false); $purchase_log->set('user_ID', $user_id); wpsc_update_customer_meta('checkout_details', wpsc_get_customer_meta('checkout_details'), $user_id); update_user_meta($user_id, '_wpsc_visitor_id', wpsc_get_current_customer_id()); } $purchase_log->save(); $wpsc_cart->empty_db($purchase_log_id); $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); $wpsc_cart->log_id = $purchase_log_id; $this->wizard->completed_step('payment'); do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => isset($user_id) ? $user_id : get_current_user_id())); do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log); }
/** * Filters the custom gateway field to return an empty string if a free cart is present. * * @access private * @param string $value Custom gateway field. * * @since 3.9.0 * @return string $value */ function _wpsc_free_checkout_hidden_field($value) { if (wpsc_is_free_cart()) { $value = ''; } return $value; }
private function submit_payment_method() { global $wpsc_cart; if (!$this->verify_nonce('wpsc-checkout-form-payment-method')) { return; } if (empty($_POST['wpsc_payment_method']) && !wpsc_is_free_cart()) { $this->message_collection->add(__('Please select a payment method', 'wpsc'), 'validation'); } $valid = apply_filters('_wpsc_merchant_v2_validate_payment_method', true, $this); if (!$valid) { return; } $submitted_gateway = $_POST['wpsc_payment_method']; $purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id'); $purchase_log = new WPSC_Purchase_Log($purchase_log_id); $purchase_log->set('gateway', $submitted_gateway); $purchase_log->set(array('gateway' => $submitted_gateway, 'base_shipping' => $wpsc_cart->calculate_base_shipping(), 'totalprice' => $wpsc_cart->calculate_total_price())); $purchase_log->save(); $wpsc_cart->empty_db($purchase_log_id); $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); $wpsc_cart->log_id = $purchase_log_id; $this->wizard->completed_step('payment'); do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => get_current_user_id())); do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log); }
?> <div class="wpsc-checkout wpsc-checkout-review"> <p><strong class="wpsc-large"><?php esc_html_e('Review Your Order', 'wp-e-commerce'); ?> </strong></p> <div class="wpsc-order-preview"> <?php wpsc_checkout_order_preview(); ?> </div> <div class="wpsc-payment-method"> <?php if (!wpsc_is_free_cart()) { ?> <p class="wpsc-payment-title"><strong class="wpsc-large"><?php esc_html_e('Payment Method', 'wp-e-commerce'); ?> </strong></p> <?php } ?> <?php wpsc_checkout_payment_method_form(); ?> </div> </div>
/** * Allows users to checkout with a free cart. * * If developers or users would rather inhibit this functionality, as it was prior to 3.9.0, they can * add the following code (prior to 'init', priority 2) to a theme or plugin: * add_filter( 'wpsc_allow_free_cart_checkout', '__return_false' ); * * @since 3.9.0 * @return void */ function wpsc_allow_free_cart_checkout() { if (wpsc_is_free_cart() && apply_filters('wpsc_allow_free_cart_checkout', true)) { /* Required for compatibility with the 3.0 payment gateway API and the 2.0 theme engine */ add_filter('wpsc_payment_method_form_fields', '__return_empty_array'); /* Sets the status entered to the "Accepted Payment" status. */ add_filter('wpsc_purchase_log_insert_data', 'wpsc_free_checkout_insert_order_status'); /* Handles what a gateway would properly handle, updating the "processed" key in the database. */ add_action('wpsc_submit_checkout_gateway', 'wpsc_free_checkout_update_processed_status', 5, 2); } }
/** * submit checkout function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_submit_checkout($collected_data = true) { global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways; if ($collected_data && isset($_POST['collected_data']) && is_array($_POST['collected_data'])) { _wpsc_checkout_customer_meta_update($_POST['collected_data']); } // initialize our checkout status variable, we start be assuming // checkout is falid, until we find a reason otherwise $is_valid = true; $num_items = 0; $use_shipping = 0; $disregard_shipping = 0; do_action('wpsc_before_submit_checkout', $collected_data); $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages'); if (!is_array($error_messages)) { $error_messages = array(); } $wpsc_checkout = new wpsc_checkout(); $selected_gateways = get_option('custom_gateway_options'); $submitted_gateway = isset($_POST['custom_gateway']) ? $_POST['custom_gateway'] : ''; if ($collected_data) { $form_validity = $wpsc_checkout->validate_forms(); extract($form_validity); // extracts $is_valid and $error_messages if (wpsc_has_tnc() && (!isset($_POST['agree']) || $_POST['agree'] != 'yes')) { $error_messages[] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wp-e-commerce'); $is_valid = false; } } else { $is_valid = true; $error_messages = array(); } if (wpsc_uses_shipping()) { $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry')); $country_id = $wpsc_country->get_id(); $country_name = $wpsc_country->get_name(); foreach ($wpsc_cart->cart_items as $cartitem) { if (!empty($cartitem->meta[0]['no_shipping'])) { continue; } $category_ids = $cartitem->category_id_list; foreach ((array) $category_ids as $catid) { if (is_array($catid)) { $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category'); } else { $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category'); } if (!empty($countries) && !in_array($country_id, (array) $countries)) { $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction, please remove this product from the list below.', 'wp-e-commerce'), $cartitem->get_title(), $country_name); wpsc_update_customer_meta('category_shipping_conflict', $errormessage); $is_valid = false; } } //count number of items, and number of items using shipping $num_items++; if ($cartitem->uses_shipping != 1) { $disregard_shipping++; } else { $use_shipping++; } } } // check to see if the current gateway is in the list of available gateways if (array_search($submitted_gateway, $selected_gateways) !== false || wpsc_is_free_cart()) { wpsc_update_customer_meta('selected_gateway', $submitted_gateway); } else { $is_valid = false; } if ($collected_data) { // Test for required shipping information if (wpsc_core_shipping_enabled() && $num_items != $disregard_shipping) { // for shipping to work we need a method, option and a quote, unless we have free shipping. $shipping_discount_value = get_option('shipping_discount_value'); $is_free_shipping_enabled = get_option('shipping_discount'); $subtotal = $wpsc_cart->calculate_subtotal(); $has_free_shipping = $is_free_shipping_enabled && $shipping_discount_value > 0 && $shipping_discount_value <= $subtotal; if (!$has_free_shipping) { if (!$wpsc_cart->shipping_method_selected() || !$wpsc_cart->shipping_quote_selected()) { $error_messages[] = __('Please select one of the available shipping options, then we can process your order.', 'wp-e-commerce'); $is_valid = false; } } // if we don't have a valid zip code ( the function also checks if we need it ) we have an error if (!wpsc_have_valid_shipping_zipcode()) { wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wp-e-commerce')); $is_valid = false; } } } wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages); if ($is_valid == true) { wpsc_delete_customer_meta('category_shipping_conflict'); // check that the submitted gateway is in the list of selected ones $sessionid = mt_rand(100, 999) . time(); wpsc_update_customer_meta('checkout_session_id', $sessionid); $subtotal = $wpsc_cart->calculate_subtotal(); if ($wpsc_cart->has_total_shipping_discount() == false) { $base_shipping = $wpsc_cart->calculate_base_shipping(); } else { $base_shipping = 0; } $delivery_country = $wpsc_cart->delivery_country; $delivery_region = $wpsc_cart->delivery_region; if (wpsc_uses_shipping()) { $shipping_method = $wpsc_cart->selected_shipping_method; $shipping_option = $wpsc_cart->selected_shipping_option; } else { $shipping_method = ''; $shipping_option = ''; } if (isset($_POST['how_find_us'])) { $find_us = $_POST['how_find_us']; } else { $find_us = ''; } //keep track of tax if taxes are exclusive $wpec_taxes_controller = new wpec_taxes_controller(); if (!$wpec_taxes_controller->wpec_taxes_isincluded()) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { $tax = 0.0; $tax_percentage = 0.0; } $total = $wpsc_cart->calculate_total_price(); $args = array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage); $purchase_log = new WPSC_Purchase_Log($args); $purchase_log->save(); $purchase_log_id = $purchase_log->get('id'); //Check to ensure log row was inserted successfully if (is_null($purchase_log_id)) { $error_messages[] = __('A database error occurred while processing your request.', 'wp-e-commerce'); wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages); return; } if ($collected_data) { $wpsc_checkout->save_forms_to_db($purchase_log_id); } $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); if (!isset($our_user_id) && isset($user_ID)) { $our_user_id = $user_ID; } $wpsc_cart->log_id = $purchase_log_id; do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => $our_user_id)); do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log); } }