Example #1
0
function _wpsc_action_merchant_v3_submit_checkout($gateway_id, $log)
{
    if (!wpsc_is_payment_gateway_registered($gateway_id)) {
        return;
    }
    $gateway = wpsc_get_payment_gateway($gateway_id);
    $gateway->set_purchase_log($log);
    $gateway->process();
}
Example #2
0
    private function get_gateway_form($gateway_name)
    {
        if (!wpsc_is_payment_gateway_registered($gateway_name)) {
            return $this->get_gateway_form_legacy($gateway_name);
        }
        $payment_gateway_names = get_option('payment_gateway_names');
        $form = array();
        $output = array('name' => ' ', 'form_fields' => __('To configure a payment module select one on the left.', 'wpsc'), 'has_submit_button' => 0);
        $gateway = wpsc_get_payment_gateway($gateway_name);
        $display_name = empty($payment_gateway_names[$gateway_name]) ? $gateway->get_title() : $payment_gateway_names[$gateway_name];
        ob_start();
        ?>
		<tr>
			<td style='border-top: none;'>
				<?php 
        _e('Display Name', 'wpsc');
        ?>
			</td>
			<td style='border-top: none;'>
				<input type='text' name='user_defined_name[<?php 
        echo esc_attr($gateway_name);
        ?>
]' value='<?php 
        echo esc_attr($display_name);
        ?>
' /><br />
				<span class='small description'><?php 
        _e('The text that people see when making a purchase', 'wpsc');
        ?>
</span>
			</td>
		</tr>
		<?php 
        $gateway->setup_form();
        $output = array('name' => $gateway->get_title(), 'form_fields' => ob_get_clean(), 'has_submit_button' => 1);
        return $output;
    }
/**
 * submit checkout function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpsc_submit_checkout()
{
    global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    do_action('wpsc_before_submit_checkout');
    $_SESSION['wpsc_checkout_misc_error_messages'] = array();
    $wpsc_checkout = new wpsc_checkout();
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = $_POST['custom_gateway'];
    $options = get_option('custom_shipping_options');
    $form_validity = $wpsc_checkout->validate_forms();
    extract($form_validity);
    // extracts $is_valid and $error_messages
    if ($_POST['agree'] != 'yes') {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc');
        $is_valid = false;
    }
    $selectedCountry = $wpdb->get_results($wpdb->prepare("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode = '%s' ", $_SESSION['wpsc_delivery_country']), ARRAY_A);
    foreach ($wpsc_cart->cart_items as $cartitem) {
        if (!empty($cartitem->meta[0]['no_shipping'])) {
            continue;
        }
        $categoriesIDs = $cartitem->category_id_list;
        foreach ((array) $categoriesIDs 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($selectedCountry[0]['id'], (array) $countries)) {
                $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->product_name, $selectedCountry[0]['country']);
                $_SESSION['categoryAndShippingCountryConflict'] = $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++;
        }
    }
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        $_SESSION['wpsc_previous_selected_gateway'] = $submitted_gateway;
    } else {
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $num_items != $disregard_shipping) {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpsc');
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') != 1 && in_array('ups', (array) $options) && $_SESSION['wpsc_zipcode'] == '' && $num_items != $disregard_shipping) {
        $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed', 'wpsc');
        $is_valid = false;
    }
    if ($is_valid == true) {
        $_SESSION['categoryAndShippingCountryConflict'] = '';
        // check that the submitted gateway is in the list of selected ones
        $sessionid = mt_rand(100, 999) . time();
        $_SESSION['wpsc_sessionid'] = $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();
        $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, 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_id = $wpdb->insert_id;
        $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));
        if (get_option('permalink_structure') != '') {
            $separator = "?";
        } else {
            $separator = "&";
        }
        // submit to gateway
        if (wpsc_is_payment_gateway_registered($submitted_gateway)) {
            $gateway = wpsc_get_payment_gateway($submitted_gateway);
            $gateway->set_purchase_log(new WPSC_Purchase_Log($purchase_log_id));
            $gateway->process();
        } else {
            $current_gateway_data =& $wpsc_gateways[$submitted_gateway];
            if (isset($current_gateway_data['api_version']) && $current_gateway_data['api_version'] >= 2.0) {
                $merchant_instance = new $current_gateway_data['class_name']($purchase_log_id);
                $merchant_instance->construct_value_array();
                do_action_ref_array('wpsc_pre_submit_gateway', array(&$merchant_instance));
                $merchant_instance->submit();
            } elseif ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') {
                $gateway_used = $current_gateway_data['internalname'];
                $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $purchase_log_id));
                $current_gateway_data['function']($separator, $sessionid);
            } elseif ($current_gateway_data['internalname'] == 'google' && $current_gateway_data['internalname'] == $submitted_gateway) {
                $gateway_used = $current_gateway_data['internalname'];
                $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $purchase_log_id));
                $_SESSION['gateway'] = 'google';
                wp_redirect(get_option('shopping_cart_url'));
            }
        }
    }
}