Example #1
0
function _wpsc_filter_merchant_v2_payment_method_form_fields($fields)
{
    $selected_value = isset($_POST['wpsc_payment_method']) ? $_POST['wpsc_payment_method'] : '';
    if (empty($selected_value)) {
        $current_purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id');
        $purchase_log = new WPSC_Purchase_Log($current_purchase_log_id);
        $selected_value = $purchase_log->get('gateway');
    }
    $gateways = _wpsc_merchant_v2_get_active_gateways();
    if (empty($gateways)) {
        return $fields;
    }
    foreach (_wpsc_merchant_v2_get_active_gateways() as $gateway) {
        $gateway = (object) $gateway;
        $title = $gateway->name;
        if (!empty($gateway->image)) {
            $title .= ' <img src="' . $gateway->image . '" alt="' . $gateway->name . '" />';
        }
        $field = array('title' => $title, 'type' => 'radio', 'value' => $gateway->internalname, 'name' => 'wpsc_payment_method', 'checked' => $selected_value == $gateway->internalname);
        $fields[] = $field;
    }
    // check the first payment gateway by default
    if (empty($selected_value)) {
        $fields[0]['checked'] = true;
    }
    return $fields;
}
Example #2
0
 /**
  * Sets attendee data on attendee posts
  *
  * @since 4.1
  *
  * @param int $attendee_id Attendee Ticket Post ID
  * @param WPSC_Purchase_Log $purchase_log WPEC purchase log object
  * @param int $product_id WPEC Product ID
  * @param int $order_attendee_id Attendee number in submitted order
  */
 public function save_attendee_meta_to_ticket($attendee_id, $purchase_log, $product_id, $order_attendee_id)
 {
     $meta = wpsc_get_purchase_meta($purchase_log->get('id'), Tribe__Tickets_Plus__Meta::META_KEY, true);
     if (!isset($meta[$product_id])) {
         return;
     }
     if (!isset($meta[$product_id][$order_attendee_id])) {
         return;
     }
     update_post_meta($attendee_id, Tribe__Tickets_Plus__Meta::META_KEY, $meta[$product_id][$order_attendee_id]);
 }
 public function is_valid_ipn_response()
 {
     $valid = true;
     // Validate Currency
     if ($this->paypal_ipn_values['mc_currency'] !== $this->get_paypal_currency_code()) {
         $valid = false;
     }
     $purchase_log = new WPSC_Purchase_Log($this->cart_data['session_id'], 'sessionid');
     if (!$purchase_log->exists()) {
         $valid = false;
     }
     // Validate amount
     // It is worth noting, there are edge cases here that may need to be addressed via filter.
     // @link https://github.com/wp-e-commerce/WP-e-Commerce/issues/1232.
     if ($this->paypal_ipn_values['mc_gross'] != $this->convert($purchase_log->get('totalprice'))) {
         $valid = false;
     }
     return apply_filters('wpsc_paypal_standard_is_valid_ipn_response', $valid, $this);
 }
/**
 * Updates the 'processed' parameter after a new order is submitted with a free cart.
 *
 * @param  string            $gateway  Name of gateway.  In the case of a free cart, this will be empty.
 * @param  WPSC_Purchase_Log $log      WPSC_Purchase_Log object.
 * @uses   apply_filters               'wpsc_free_checkout_order_status' allows developers to change the status a free cart is saved with.
 * @since  3.9.0
 *
 */
function wpsc_free_checkout_update_processed_status($gateway, $log)
{
    wpsc_update_purchase_log_status($log->get('id'), apply_filters('wpsc_free_checkout_order_status', WPSC_Purchase_Log::ACCEPTED_PAYMENT));
    wp_safe_redirect(add_query_arg('sessionid', $log->get('sessionid'), get_option('transact_url')));
    exit;
}
 private function get_active_shipping()
 {
     if (is_null($this->ids)) {
         $this->get_all_quotes();
     }
     $current_purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id');
     $purchase_log = new WPSC_Purchase_Log($current_purchase_log_id);
     $module = $purchase_log->get('shipping_method');
     $option = $purchase_log->get('shipping_option');
     if (empty($module) || empty($option)) {
         $this->active_shipping_id = '';
         $this->active_shipping_option = '';
         $this->active_shipping_module = '';
         return;
     }
     $this->active_shipping_id = $this->ids[$module][$option];
     $this->active_shipping_option = $option;
     $this->active_shipping_module = $module;
 }
 /**
  * ExpressCheckout Shortcut Callback
  *
  * @return int
  */
 public function callback_shortcut_process()
 {
     if (!isset($_GET['payment_gateway'])) {
         return;
     }
     $payment_gateway = $_GET['payment_gateway'];
     global $wpsc_cart;
     //	Create a new PurchaseLog Object
     $purchase_log = new WPSC_Purchase_Log();
     // Create a Sessionid
     $sessionid = mt_rand(100, 999) . time();
     wpsc_update_customer_meta('checkout_session_id', $sessionid);
     $purchase_log->set(array('user_ID' => get_current_user_id(), 'date' => time(), 'plugin_version' => WPSC_VERSION, 'statusno' => '0', 'sessionid' => $sessionid));
     if (wpsc_is_tax_included()) {
         $tax = $wpsc_cart->calculate_total_tax();
         $tax_percentage = $wpsc_cart->tax_percentage;
     } else {
         $tax = 0;
         $tax_percentage = 0;
     }
     $purchase_log->set(array('wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
     // Save the purchase_log object to generate it's id
     $purchase_log->save();
     $purchase_log_id = $purchase_log->get('id');
     $wpsc_cart->log_id = $purchase_log_id;
     wpsc_update_customer_meta('current_purchase_log_id', $purchase_log_id);
     $purchase_log->set(array('gateway' => $payment_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);
     // Save an empty Form
     $form = WPSC_Checkout_Form::get();
     $fields = $form->get_fields();
     WPSC_Checkout_Form_Data::save_form($purchase_log, $fields);
     // Return Customer to Review Order Page if there is Shipping
     add_filter('wpsc_paypal_express_checkout_transact_url', array(&$this, 'review_order_url'));
     add_filter('wpsc_paypal_express_checkout_return_url', array(&$this, 'review_order_callback'));
     // Set a Temporary Option for EC Shortcut
     wpsc_update_customer_meta('esc-' . $sessionid, true);
     // Apply Checkout Actions
     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', $payment_gateway, $purchase_log);
     return $sessionid;
 }
/**
 * 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;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    do_action('wpsc_before_submit_checkout');
    $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'] : '';
    $options = get_option('custom_shipping_options');
    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.', 'wpsc');
            $is_valid = false;
        }
    } else {
        $is_valid = true;
        $error_messages = array();
    }
    $selectedCountry = $wpdb->get_results($wpdb->prepare("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode = '%s' ", wpsc_get_customer_meta('shipping_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->get_title(), $selectedCountry[0]['country']);
                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++;
        }
    }
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        wpsc_update_customer_meta('selected_gateway', $submitted_gateway);
    } else {
        $is_valid = false;
    }
    if ($collected_data) {
        if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $num_items != $disregard_shipping) {
            $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) && !wpsc_get_customer_meta('shipping_zip') && $num_items != $disregard_shipping) {
            wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wpsc'));
            $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');
        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 (get_option('wpsc_also_bought') == 1) {
            wpsc_populate_also_bought_list();
        }
        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
        $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'];
            $purchase_log->set('gateway', $gateway_used);
            $purchase_log->save();
            $current_gateway_data['function']($separator, $sessionid);
        } elseif ($current_gateway_data['internalname'] == 'google' && $current_gateway_data['internalname'] == $submitted_gateway) {
            $gateway_used = $current_gateway_data['internalname'];
            $purchase_log->set('gateway', $gateway_used);
            wpsc_update_customer_meta('google_checkout', 'google');
            wp_redirect(get_option('shopping_cart_url'));
            exit;
        }
    }
}
 /**
  * set_authcode, generaly speaking a payment gateway gives you an authcode to be able to refer back to the transaction
  * if an authcode already exsits, you can either append another (2931932839|29391839482) or replace depending on the $append flag
  * @param string $authcode
  * @param bool   $append
  * @return bool  result
  */
 function set_authcode($authcode, $append = false)
 {
     $log = new WPSC_Purchase_Log($this->purchase_id);
     $current_authcode = $log->get('authcode');
     if ($append && !empty($current_authcode)) {
         $authcode = $current_authcode . '|' . $authcode;
     }
     return $log->set('authcode', $authcode)->save();
 }
 /**
  * Save Submitted Form Fields to the wpsc_submited_form_data table.
  *
  * @param WPSC_Purchase_Log $purchase_log
  * @param array $fields
  * @return void
  */
 public static function save_form($purchase_log, $fields, $data = array())
 {
     global $wpdb;
     $log_id = $purchase_log->get('id');
     // delete previous field values
     $sql = $wpdb->prepare("DELETE FROM " . WPSC_TABLE_SUBMITTED_FORM_DATA . " WHERE log_id = %d", $log_id);
     $wpdb->query($sql);
     if (empty($data) && isset($_POST['wpsc_checkout_details'])) {
         $data = $_POST['wpsc_checkout_details'];
     }
     $customer_details = array();
     foreach ($fields as $field) {
         if ($field->type == 'heading') {
             continue;
         }
         $value = '';
         if (isset($data[$field->id])) {
             $value = wp_unslash($data[$field->id]);
         }
         $customer_details[$field->id] = $value;
         $wpdb->insert(WPSC_TABLE_SUBMITTED_FORM_DATA, array('log_id' => $log_id, 'form_id' => $field->id, 'value' => $value), array('%d', '%d', '%s'));
     }
     wpsc_save_customer_details($customer_details);
 }
 public static function sales_data_postback()
 {
     if (!isset($_REQUEST['sales_data'])) {
         return;
     }
     $data = json_decode(stripslashes($_POST['data']));
     $cart_contents = json_decode(stripslashes($_POST['cart_contents']));
     //Unset purchase log ID, since we're inserting a new one.
     $data = (array) $data;
     unset($data['id']);
     $purchase_log = new WPSC_Purchase_Log($data);
     $purchase_log->save();
     $purchase_log_id = $purchase_log->get('id');
     global $wpdb;
     //We need to update the proper product ID, name and purchase ID
     foreach ($cart_contents as $cart_item) {
         $product = new WP_Query(array('post_type' => 'wpsc-product', 'pagename' => $cart_item->slug));
         $product = $product->get_posts();
         $product = $product[0];
         $cart_item = (array) $cart_item;
         unset($cart_item['id']);
         unset($cart_item['slug']);
         $cart_item['prodid'] = $product->ID;
         $cart_item['name'] = $product->post_title;
         $cart_item['purchaseid'] = $purchase_log_id;
         $wpdb->insert(WPSC_TABLE_CART_CONTENTS, $cart_item);
     }
     die;
 }
 public function add_pushes($session_id)
 {
     $purchase = new WPSC_Purchase_Log($session_id, 'sessionid');
     $purchase_id = $purchase->get('id');
     $data = new WPSC_Checkout_Form_Data($purchase_id);
     $output = '';
     $city = $data->get('billingcity');
     $state = $data->get('billingstate');
     $country = $data->get('billingcountry');
     $state = !empty($state) ? wpsc_get_state_by_id($state, 'name') : '';
     $cart_items = $purchase->get_cart_contents();
     $total_shipping = wpsc_get_total_shipping($purchase_id);
     $total_tax = $total_price = 0;
     foreach ($cart_items as $item) {
         /* For backwards compatibility, convert objects to arrays */
         $item = (array) $item;
         $total_tax += $item['tax_charged'];
         $total_price += absint($item['quantity']) * $item['price'];
     }
     if ($this->is_theme_tracking || $this->advanced_code) {
         $output .= "<script type='text/javascript'>\n\r";
     }
     add_filter('wpsc_toggle_display_currency_code', array($this, 'remove_currency_and_html'));
     if ($this->use_universal_analytics()) {
         // Yoast GA Plugin switched to it's own object name __gaTracker - assign it to our ga object if it exists
         $output .= "var ga = typeof ga === 'undefined' && typeof __gaTracker !== 'undefined' ? __gaTracker : ga;";
         $output .= "ga('require', 'ecommerce');\n\r";
         $output .= "ga('ecommerce:addTransaction', {\n\t\t\t\t'id': '" . $purchase_id . "',                                               // Transaction ID. Required.\n\t\t\t\t'affiliation': '" . wp_specialchars_decode($this->get_site_name()) . "',  // Affiliation or store name.\n\t\t\t\t'revenue': '" . number_format($total_price, 2, '.', '') . "',             // Grand Total.\n\t\t\t\t'shipping': '" . wpsc_currency_display($total_shipping) . "',             // Shipping.\n\t\t\t\t'tax': '" . wpsc_currency_display($total_tax) . "'                        // Tax.\n\t\t\t});\n\r";
     } else {
         $output .= "\n\t\t\t\t_gaq.push(['_addTrans',\n\t\t\t\t'" . $purchase_id . "',                                     // order ID - required\n\t\t\t\t'" . wp_specialchars_decode($this->get_site_name()) . "', // affiliation or store name\n\t\t\t\t'" . number_format($total_price, 2, '.', '') . "',   // total - required\n\t\t\t\t'" . wpsc_currency_display($total_tax) . "',              // tax\n\t\t\t\t'" . wpsc_currency_display($total_shipping) . "',         // shipping\n\t\t\t\t'" . wp_specialchars_decode($city) . "',                  // city\n\t\t\t\t'" . wp_specialchars_decode($state) . "',                 // state or province\n\t\t\t\t'" . wp_specialchars_decode($country) . "'                // country\n\t\t\t]);\n\r";
     }
     remove_filter('wpsc_toggle_display_currency_code', array($this, 'remove_currency_and_html'));
     foreach ($cart_items as $item) {
         /* For backwards compatibility, convert objects to arrays */
         $item = (array) $item;
         $category = wp_get_object_terms($item['prodid'], 'wpsc_product_category', array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'all_with_object_id'));
         $item['sku'] = get_post_meta($item['prodid'], '_wpsc_sku', true);
         if (empty($item['sku'])) {
             $item['sku'] = $item['prodid'];
         }
         if ($category) {
             $item['category'] = $category[0]->name;
         } else {
             $item['category'] = '';
         }
         $item = apply_filters('wpsc_google_analytics_pushed_product', array_map('wp_specialchars_decode', $item), $item, $this);
         if ($this->use_universal_analytics()) {
             $output .= "ga('ecommerce:addItem', {" . "'id': '" . $purchase_id . "'," . "'name': '" . $item['name'] . "'," . "'sku': '" . $item['sku'] . "'," . "'category': '" . $item['category'] . "'," . "'price': '" . $item['price'] . "'," . "'quantity': '" . $item['quantity'] . "'" . "});\n\r";
         } else {
             $output .= "_gaq.push(['_addItem'," . "'" . $purchase_id . "'," . "'" . $item['sku'] . "'," . "'" . $item['name'] . "'," . "'" . $item['category'] . "'," . "'" . $item['price'] . "'," . "'" . $item['quantity'] . "']);\n\r";
             // Item Quantity
         }
     }
     if ($this->use_universal_analytics()) {
         $output .= "ga('ecommerce:send');\n\r";
     } else {
         $output .= "_gaq.push(['_trackTrans']);\n\r";
     }
     if ($this->is_theme_tracking || $this->advanced_code) {
         $output .= "</script>\n\r";
     }
     return $output;
 }
 /**
  * Adds product properties to analytics.track() when the order is completed successfully.
  *
  * @since  1.0.0
  * @access public
  *
  * @uses  func_get_args() Because our abstract class doesn't know how many parameters are passed to each hook
  *                        for each different platform, we use func_get_args().
  *
  * @return array Filtered array of name and properties for analytics.track().
  */
 public function completed_order()
 {
     $args = func_get_args();
     $track = $args[0];
     if (did_action('wpsc_transaction_results_shutdown') && isset($_GET['sessionid'])) {
         $log = new WPSC_Purchase_Log($_GET['sessionid'], 'sessionid');
         /* We like checking is_order_received(), as that's what the manual payment gateway uses. */
         if ($log->is_transaction_completed() || $log->is_order_received()) {
             $gateway_data = $log->get_gateway_data();
             $items = $log->get_cart_contents();
             $products = array();
             foreach ($items as $item) {
                 $product = array('id' => $item->prodid, 'sku' => wpsc_product_sku($item->prodid), 'name' => $item->name, 'price' => $item->price, 'quantity' => $item->quantity, 'category' => implode(', ', wp_list_pluck(wpsc_get_product_terms($item->prodid, 'wpsc_product_category'), 'name')));
                 $products[] = $product;
             }
             $track = array('event' => __('Completed Order', 'segment'), 'properties' => array('id' => $log->get('id'), 'total' => $log->get('totalprice'), 'revenue' => $gateway_data['subtotal'], 'shipping' => $gateway_data['shipping'], 'tax' => $gateway_data['tax'], 'products' => $products));
         }
     }
     return $track;
 }
function cph_wpsc_user_purchases($purchase_ids)
{
    global $wpdb;
    global $purchlogitem;
    $i = 0;
    $col_count = 4;
    //do_action( 'wpsc_pre_purchase_logs' );
    foreach ($purchase_ids as $purchase_id) {
        $alternate = "";
        $alternate_style = "";
        $i++;
        $purchlogitem = new wpsc_purchaselogs_items($purchase_id);
        //cph_purchase_log_cart_items();
        if ($i % 2 != 0) {
            $alternate = 'class="header-row alt"';
        }
        $alternate_style = 'style = "background: lightgray; font-weight: bold;"';
        $purchase_log = new WPSC_Purchase_Log($purchase_id);
        echo "<tr {$alternate} {$alternate_style} >\n\r";
        echo " <td style=\"width:25%;\" class='status processed'>";
        echo '<label>Purchase ID:</label>&nbsp;' . $purchase_id;
        echo " </td>\n\r";
        echo " <td style=\"width:25%;\" class='date'>";
        echo '<label>Date:</label>&nbsp;' . date("jS M Y", $purchase_log->get('date'));
        echo " </td>\n\r";
        echo " <td  style=\"width:25%;\" class='price'>";
        echo '<label>Total:</label>&nbsp;' . wpsc_currency_display($purchase_log->get('totalprice'), array('display_as_html' => false));
        echo " </td>\n\r";
        echo " <td style=\"width:25%;\" class='tracking'>";
        echo $purchase_log->get('track_id');
        echo " </td>\n\r";
        echo "</tr>\n\r";
        echo "<tr>\n\r";
        echo " <td colspan='{$col_count}' class='details'>\n\r";
        echo "  <div>\n\r";
        //cart contents display starts here;
        $cartsql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`= %d", $purchase_id);
        $cart_log = $wpdb->get_results($cartsql, ARRAY_A);
        $j = 0;
        if ($cart_log != null) {
            echo "<table class='logdisplay'>";
            echo "<tr class='toprow2'>";
            echo " <th class='details_name'>";
            _e('Item Name', 'wp-e-commerce');
            echo " </th>";
            echo " <th class='details_quantity'>";
            _e('Quantity', 'wp-e-commerce');
            echo " </th>";
            echo " <th class='details_price'>";
            _e('Price', 'wp-e-commerce');
            echo " </th>";
            echo " <th class='details_total'>";
            _e('Total', 'wp-e-commerce');
            echo " </th>";
            echo "</tr>";
            while (wpsc_have_purchaselog_details()) {
                wpsc_the_purchaselog_item();
                $alternate = "";
                $j++;
                if ($j % 2 != 0) {
                    $alternate = "alt";
                }
                echo "<tr class='{$alternate}'>";
                echo " <td class='details_name'>";
                echo wpsc_purchaselog_details_href();
                echo " </td>";
                echo " <td class='details_quantity'>";
                echo wpsc_purchaselog_details_quantity();
                echo " </td>";
                echo " <td class='details_price'>";
                echo wpsc_currency_display(wpsc_purchaselog_details_price());
                echo " </td>";
                echo " <td class='details_total'>";
                echo wpsc_currency_display(wpsc_purchaselog_details_total());
                echo " </td>";
                echo '</tr>';
                echo '<tr>';
                do_action('wpsc_additional_sales_item_info', $purchase_id);
                echo '</tr>';
            }
            echo "</table>";
            echo "<br />";
        }
        echo "  </div>\n\r";
        echo " </td>\n\r";
        echo "</tr>\n\r";
    }
}
Example #14
0
/**
 * 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 variab;e, 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');
    $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.', 'wpsc');
            $is_valid = false;
        }
    } else {
        $is_valid = true;
        $error_messages = array();
    }
    $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;
        }
        $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($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.', 'wpsc'), $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_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
            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.', 'wpsc');
                $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', 'wpsc'));
                $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');
        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);
    }
}
 private function import_ipn_data()
 {
     global $wpdb;
     $purchase_log = new WPSC_Purchase_Log($this->cart_data['session_id'], 'sessionid');
     if (!$purchase_log->exists()) {
         return;
     }
     // get all active form fields and organize them based on id and unique_name, because we're only
     // importing fields relevant to checkout fields that have unique name
     $form_fields_sql = "SELECT id, unique_name FROM " . WPSC_TABLE_CHECKOUT_FORMS . " WHERE active='1'";
     $form_fields_results = $wpdb->get_results($form_fields_sql);
     $form_fields = array();
     foreach ($form_fields_results as $row) {
         if (!empty($row->unique_name)) {
             $form_fields[$row->id] = $row->unique_name;
         }
     }
     $purchase_log_id = $purchase_log->get('id');
     // this defines how ipn response data will be parsed into checkout field values
     $field_mapping = array('firstname' => 'first_name', 'lastname' => 'last_name', 'country' => 'address_country_code', 'email' => 'payer_email', 'city' => 'address_city', 'address' => 'address_street', 'phone' => 'contact_phone');
     $inserts = array();
     // billing & shipping will get the same values
     foreach (array('billing', 'shipping') as $type) {
         // if the corresponding checkout field is "active", prepare the data array that will
         // get passed into $wpdb->insert()
         foreach ($field_mapping as $key => $value) {
             $unique_name = $type . $key;
             $id = array_search($unique_name, $form_fields);
             if ($id === false || !isset($this->paypal_ipn_values[$value])) {
                 continue;
             }
             $inserts[] = array('log_id' => $purchase_log_id, 'form_id' => $id, 'value' => $this->paypal_ipn_values[$value]);
         }
     }
     // loop through the prepared data array and insert them
     foreach ($inserts as $insert) {
         $wpdb->insert(WPSC_TABLE_SUBMITED_FORM_DATA, $insert, array('%d', '%d', '%s'));
     }
 }
 /**
  * Handles declined transactions from Amazon.
  *
  * On the front-end, if a transaction is declined due to an invalid payment method, the user needs
  * to be returned to the payment page to select a different method.
  *
  * If it is declined for any other reason, they're basically out of luck.
  *
  * @since  4.0
  *
  * @param  WPSC_Purchase_Log $order Current purchase log for transaction.
  * @return void
  */
 private function handle_declined_transaction($order)
 {
     $reason_code = $order->get('amazon-reason-code');
     if ('InvalidPaymentMethod' == $reason_code) {
         $message = __('Selected payment method was not valid.  Please select a valid payment method.', 'wpsc');
         $url = add_query_arg($_GET, wpsc_get_checkout_url('shipping-and-billing'));
     } else {
         $message = __('It is not currently possible to complete this transaction with Amazon Payments. Please contact the store administrator or try again later.', 'wpsc');
         $url = wpsc_get_cart_url();
     }
     WPSC_Message_Collection::get_instance()->add($message, 'error', 'main', 'flash');
     wp_safe_redirect($url);
     exit;
 }
	/**
	* submit to gateway
	*/
	public function submit() {
		global $wpdb;

		// check for missing or invalid values
		$errors = $this->validateData();

		// if there were errors, fail the transaction so that user can fix things up
		if ($errors) {
			$this->set_purchase_processed_by_purchid(1);	// failed
			//~ $this->go_to_transaction_results($this->cart_data['session_id']);
			return;
		}

		// get purchase logs
		if ($this->purchase_id > 0) {
			$purchase_logs = new WPSC_Purchase_Log($this->purchase_id);
		}
		elseif (!empty($this->session_id)) {
			$purchase_logs = new WPSC_Purchase_Log($this->session_id, 'sessionid');

			$this->purchase_id = $purchase_logs->get('id');
		}
		else {
			$this->set_error_message('No cart ID and no active session!');
			return;
		}

		// process the payment
		$isLiveSite = !get_option('eway_test');
		$useStored = get_option('wpsc_merchant_eway_stored');

		if ($useStored) {
			$eway = new EwayPaymentsStoredPayment(get_option('ewayCustomerID_id'), $isLiveSite);
		}
		else {
			$eway = new EwayPaymentsPayment(get_option('ewayCustomerID_id'), $isLiveSite);
		}

		$eway->invoiceDescription		= get_bloginfo('name');
		$eway->invoiceReference			= $this->purchase_id;								// customer invoice reference
		$eway->transactionNumber		= $this->purchase_id;								// transaction reference
		$eway->cardHoldersName			= $this->collected_gateway_data['card_name'];
		$eway->cardNumber				= $this->collected_gateway_data['card_number'];
		$eway->cardExpiryMonth			= $this->collected_gateway_data['expiry_month'];
		$eway->cardExpiryYear			= $this->collected_gateway_data['expiry_year'];
		$eway->cardVerificationNumber	= $this->collected_gateway_data['c_v_n'];
		$eway->firstName				= $this->collected_gateway_data['first_name'];
		$eway->lastName					= $this->collected_gateway_data['last_name'];
		$eway->emailAddress				= $this->collected_gateway_data['email'];
		$eway->postcode					= $this->collected_gateway_data['post_code'];

		// for Beagle (free) security
		if (get_option('wpsc_merchant_eway_beagle')) {
			$eway->customerCountryCode	= $this->collected_gateway_data['country'];
		}

		// convert wp-e-commerce country code into country name
		$country = $this->collected_gateway_data['country'] ? wpsc_get_country($this->collected_gateway_data['country']) : '';

		// aggregate street, city, state, country into a single string
		$parts = array (
			$this->collected_gateway_data['address'],
			$this->collected_gateway_data['city'],
			$this->collected_gateway_data['state'],
			$country,
		);
		$eway->address					= implode(', ', array_filter($parts, 'strlen'));

		// use cardholder name for last name if no customer name entered
		if (empty($eway->firstName) && empty($eway->lastName)) {
			$eway->lastName				= $eway->cardHoldersName;
		}

		// allow plugins/themes to modify invoice description and reference, and set option fields
		$eway->invoiceDescription		= apply_filters('wpsc_merchant_eway_invoice_desc', $eway->invoiceDescription, $this->purchase_id);
		$eway->invoiceReference			= apply_filters('wpsc_merchant_eway_invoice_ref', $eway->invoiceReference, $this->purchase_id);
		$eway->option1					= apply_filters('wpsc_merchant_eway_option1', '', $this->purchase_id);
		$eway->option2					= apply_filters('wpsc_merchant_eway_option2', '', $this->purchase_id);
		$eway->option3					= apply_filters('wpsc_merchant_eway_option3', '', $this->purchase_id);

		// if live, pass through amount exactly, but if using test site, round up to whole dollars or eWAY will fail
		$total = $purchase_logs->get('totalprice');
		$eway->amount					= $isLiveSite ? $total : ceil($total);

		try {
			$response = $eway->processPayment();

			if ($response->status) {
				// transaction was successful, so record transaction number and continue
				if ($useStored) {
					$status = 2; // WPSC_Purchase_Log::ORDER_RECEIVED
				}
				else {
					$status = 3; // WPSC_Purchase_Log::ACCEPTED_PAYMENT
				}
				$log_details = array(
					'processed'			=> $status,
					'transactid'		=> $response->transactionNumber,
					'authcode'			=> $response->authCode,
				);

				if (!empty($response->beagleScore)) {
					$log_details['notes'] = 'Beagle score: ' . $response->beagleScore;
				}

				wpsc_update_purchase_log_details($this->purchase_id, $log_details);

				$this->go_to_transaction_results($this->cart_data['session_id']);
			}
			else {
				// transaction was unsuccessful, so record transaction number and the error
				$status = 6; // WPSC_Purchase_Log::PAYMENT_DECLINED
				$this->set_error_message(nl2br(esc_html($response->error)));

				$log_details = array(
					'processed'			=> $status,
					'notes'				=> $response->error,
				);
				wpsc_update_purchase_log_details($this->purchase_id, $log_details);

				return;
			}
		}
		catch (EwayPaymentsException $e) {
			// an exception occured, so record the error
			$status = 1; // WPSC_Purchase_Log::INCOMPLETE_SALE
			$this->set_error_message(nl2br(esc_html($e->getMessage())));
			$this->set_purchase_processed_by_purchid($status);
			return;
		}

	 	exit();
	}
function wpsc_get_transaction_html_output($purchase_log)
{
    if (!is_object($purchase_log)) {
        $purchase_log = new WPSC_Purchase_Log($purchase_log);
    }
    $notification = new WPSC_Purchase_Log_Customer_HTML_Notification($purchase_log);
    $output = $notification->get_html_message();
    // see if the customer trying to view this transaction output is the person
    // who made the purchase.
    $checkout_session_id = wpsc_get_customer_meta('checkout_session_id');
    if ($checkout_session_id == $purchase_log->get('sessionid')) {
        $output = apply_filters('wpsc_get_transaction_html_output', $output, $notification);
    } else {
        $output = apply_filters('wpsc_get_transaction_unauthorized_view', __("You don't have the permission to view this page", 'wp-e-commerce'), $output, $notification);
    }
    return $output;
}
Example #19
0
function response_handler($nvpArray, $fraud, $sessionid, $data = null, $recurring = null)
{
    global $wpdb;
    $result_code = $nvpArray['RESULT'];
    //$RespMsg = 'General Error.  Please contact Customer Support.';
    //    echo ($result_code);
    if ($result_code == 1 || $result_code == 26) {
        wpsc_update_customer_meta('payflow_message', __('Account configuration issue.  Please verify your login credentials.', 'wpsc_gold_cart'));
    } else {
        if ($result_code == '0') {
            $purchase_log = new WPSC_Purchase_Log($sessionid, 'sessionid');
            $purchase_log->set('processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT);
            $purchase_log->save();
            $log_id = $purchase_log->get('id');
            if (isset($nvpArray['CVV2MATCH'])) {
                if ($nvpArray['CVV2MATCH'] != "Y") {
                    $RespMsg = __('Your billing (cvv2) information does not match. Please re-enter.', 'wpsc_gold_cart');
                }
            }
        } else {
            if ($result_code == 12) {
                $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`='{$sessionid}' LIMIT 1");
                $delete_log_form_sql = "SELECT * FROM `" . $wpdb->prefix . "cart_contents` WHERE `purchaseid`='{$log_id}'";
                $cart_content = $wpdb->get_results($delete_log_form_sql, ARRAY_A);
                /*
                foreach((array)$cart_content as $cart_item) {
                         $cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
                      }
                */
                $wpdb->query("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'");
                $wpdb->query("DELETE FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` IN ('{$log_id}')");
                $wpdb->query("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='{$log_id}' LIMIT 1");
                wpsc_update_customer_meta('payflow_message', __('Your credit card has been declined.  You may press the back button in your browser and check that you\'ve entered your card information correctly, otherwise please contact your credit card issuer.', 'wpsc_gold_cart'));
                header("Location:" . get_option('transact_url') . $seperator . "payflow=1&message=1");
            } else {
                if ($result_code == 13) {
                    $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`='{$sessionid}' LIMIT 1");
                    $delete_log_form_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'";
                    $cart_content = $wpdb->get_results($delete_log_form_sql, ARRAY_A);
                    /*
                    foreach((array)$cart_content as $cart_item) {
                       $cart_item_variations = $wpdb->query("DELETE FROM `".WPSC_TABLE_CART_ITEM_VARIATIONS."` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
                    }
                    */
                    $RespMsg = __('Invalid credit card information. Please use the back button in your browser and re-enter if you feel that you have received this message in error', 'wpsc_gold_cart');
                    wp_die($RespMsg);
                    //die before deleting cart information
                    $wpdb->query("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'");
                    $wpdb->query("DELETE FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` IN ('{$log_id}')");
                    $wpdb->query("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='{$log_id}' LIMIT 1");
                } else {
                    if ($result_code == 23 || $result_code == 24) {
                        $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`='{$sessionid}' LIMIT 1");
                        $delete_log_form_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'";
                        $cart_content = $wpdb->get_results($delete_log_form_sql, ARRAY_A);
                        /*
                              foreach((array)$cart_content as $cart_item) {
                                 $cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
                              }
                        */
                        $RespMsg = __('Invalid credit card information. Please use the back button in your browser and re-enter if you feel that you have received this message in error', 'wpsc_gold_cart');
                        wp_die($RespMsg);
                        //die before deleting cart information
                        $wpdb->query("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'");
                        $wpdb->query("DELETE FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` IN ('{$log_id}')");
                        $wpdb->query("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='{$log_id}' LIMIT 1");
                        $RespMsg = __('Invalid credit card information. Please use the back button in your browser and re-enter. If you feel that you received this message in error.', 'wpsc_gold_cart');
                    } else {
                        $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`='{$sessionid}' LIMIT 1");
                        $delete_log_form_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'";
                        $cart_content = $wpdb->get_results($delete_log_form_sql, ARRAY_A);
                        /*
                              foreach((array)$cart_content as $cart_item) {
                                 $cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
                              }
                        */
                        $wpdb->query("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'");
                        $wpdb->query("DELETE FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` IN ('{$log_id}')");
                        $wpdb->query("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='{$log_id}' LIMIT 1");
                        $RespMsg = __('Invalid credit card information. Please use the back button in your browser and re-enter. If you feel that you received this message in error.', 'wpsc_gold_cart');
                    }
                }
            }
        }
    }
    if ($fraud == 'YES') {
        if ($result_code == 125) {
            $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`='{$sessionid}' LIMIT 1");
            $delete_log_form_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'";
            $cart_content = $wpdb->get_results($delete_log_form_sql, ARRAY_A);
            /*
            foreach((array)$cart_content as $cart_item) {
                        $cart_item_variations = $wpdb->query("DELETE FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id` = '".$cart_item['id']."'", ARRAY_A);
                     }
            */
            $wpdb->query("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$log_id}'");
            $wpdb->query("DELETE FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` IN ('{$log_id}')");
            $wpdb->query("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='{$log_id}' LIMIT 1");
        } else {
            if ($result_code == 126) {
                $RespMsg = __('Your Transaction is Under Review. We will notify you via e-mail if accepted.', 'wpsc_gold_cart');
            } else {
                if ($result_code == 127) {
                    $RespMsg = __('Your Transaction is Under Review. We will notify you via e-mail if accepted.', 'wpsc_gold_cart');
                }
            }
        }
    }
    //$message=transaction_results($sessionid,false,null,$data,$result_code);
    if (get_option('permalink_structure') != '') {
        $seperator = '?';
    } else {
        $seperator = '&';
    }
    if ($result_code != 0) {
        wpsc_update_customer_meta('payflow_message', $RespMsg);
        header("Location:" . get_option('transact_url') . $seperator . "payflow=1&&sessionid=" . $sessionid . "result=" . $result_code . "&message=1");
    }
    header("Location:" . get_option('transact_url') . $seperator . "payflow=1&sessionid=" . $sessionid . "&result=" . $result_code . "&message=1");
}
Example #20
0
 private function save_shipping_and_billing_info()
 {
     global $wpsc_cart;
     // see if an existing purchase log has been set for this user
     // otherwise create one
     $purchase_log_id = (int) wpsc_get_customer_meta('current_purchase_log_id');
     if ($purchase_log_id) {
         $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
     } else {
         $purchase_log = new WPSC_Purchase_Log();
     }
     $sessionid = mt_rand(100, 999) . time();
     wpsc_update_customer_meta('checkout_session_id', $sessionid);
     $purchase_log->set(array('user_ID' => wpsc_get_current_customer_id(), 'date' => time(), 'plugin_version' => WPSC_VERSION, 'statusno' => '0', 'sessionid' => $sessionid));
     $form = WPSC_Checkout_Form::get();
     $fields = $form->get_fields();
     foreach ($fields as $field) {
         if (!array_key_exists($field->id, $_POST['wpsc_checkout_details'])) {
             continue;
         }
         $value = $_POST['wpsc_checkout_details'][$field->id];
         switch ($field->unique_name) {
             case 'billingstate':
                 wpsc_update_customer_meta('billing_region', $value);
                 $purchase_log->set('billing_region', $value);
                 break;
             case 'shippingstate':
                 wpsc_update_customer_meta('shipping_region', $value);
                 $purchase_log->set('shipping_region', $value);
                 break;
             case 'billingcountry':
                 wpsc_update_customer_meta('billing_country', $value);
                 $purchase_log->set('billing_country', $value);
                 break;
             case 'shippingcountry':
                 wpsc_update_customer_meta('shipping_country', $value);
                 $purchase_log->set('shipping_region', $value);
                 break;
             case 'shippingpostcode':
                 wpsc_update_customer_meta('shipping_zip', $value);
                 break;
         }
     }
     _wpsc_update_location();
     if (wpsc_is_tax_included()) {
         $tax = $wpsc_cart->calculate_total_tax();
         $tax_percentage = $wpsc_cart->tax_percentage;
     } else {
         $tax = 0;
         $tax_percentage = 0;
     }
     $purchase_log->set(array('wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
     $purchase_log->save();
     $wpsc_cart->log_id = $purchase_log->get('id');
     wpsc_update_customer_meta('current_purchase_log_id', $purchase_log->get('id'));
     $this->save_form($purchase_log, $fields);
     $this->init_shipping_calculator();
     if (wpsc_uses_shipping() && !$this->shipping_calculator->has_quotes) {
         $this->message_collection->add(__('Sorry but we cannot ship products to your submitted address. Please either provide another shipping address or contact the store administrator about product availability to your location.', 'wpsc'), 'error');
         return;
     }
     $this->wizard->completed_step('shipping-and-billing');
     wp_redirect(wpsc_get_checkout_url($this->wizard->pending_step));
     exit;
 }
 /**
  * go_to_transaction_results, please don't extend this without very good reason
  * go to transaction results, if this changes and you extend this, your merchant module may go to the wrong place
  */
 function go_to_transaction_results($session_id)
 {
     $purchase_log = new WPSC_Purchase_Log($this->purchase_id);
     //Now to do actions once the payment has been attempted
     switch ($purchase_log->get('processed')) {
         case WPSC_Purchase_Log::ACCEPTED_PAYMENT:
             // payment worked
             do_action('wpsc_payment_successful');
             break;
         case WPSC_Purchase_Log::INCOMPLETE_SALE:
             // payment declined
             do_action('wpsc_payment_failed');
             break;
         case WPSC_Purchase_Log::ORDER_RECEIVED:
             // something happened with the payment
             do_action('wpsc_payment_incomplete');
             break;
     }
     $transaction_url_with_sessionid = add_query_arg('sessionid', $session_id, get_option('transact_url'));
     wp_redirect($transaction_url_with_sessionid);
     exit;
     // follow the redirect with an exit, just to be sure.
 }
 /**
  * Deletes cache of a log (either by using the log ID or sessionid)
  *
  * @access public
  * @static
  * @since 3.8.9
  *
  * @param string $value The value to query
  * @param string $col Optional. Defaults to 'id'. Whether to delete cache by using
  *                    a purchase log ID or sessionid
  * @return void
  */
 public static function delete_cache($value, $col = 'id')
 {
     // this will pull from the old cache, so no worries there
     $log = new WPSC_Purchase_Log($value, $col);
     wp_cache_delete($log->get('id'), 'wpsc_purchase_logs');
     wp_cache_delete($log->get('sessionid'), 'wpsc_purchase_logs_sessionid');
     wp_cache_delete($log->get('id'), 'wpsc_purchase_log_cart_contents');
     do_action('wpsc_purchase_log_delete_cache', $log, $value, $col);
 }
function wpsc_send_admin_email($purchase_log, $force = false)
{
    if (!is_object($purchase_log)) {
        $purchase_log = new WPSC_Purchase_Log($purchase_log);
    }
    if ($purchase_log->get('email_sent') && !$force) {
        return;
    }
    $email = new WPSC_Purchase_Log_Admin_Notification($purchase_log);
    $email_sent = $email->send();
    if ($email_sent) {
        $purchase_log->set('email_sent', 1);
        $purchase_log->save();
    }
    do_action('wpsc_transaction_send_email_to_admin', $email, $email_sent);
    return $email_sent;
}
/**
 * Display Purchase Log Notes
 *
 * @return  string  Notes.
 */
function wpsc_display_purchlog_notes()
{
    global $purchlogitem;
    $purchase_log = new WPSC_Purchase_Log($purchlogitem->purchlogid);
    return $purchase_log->get('notes');
}
 function do_export_file()
 {
     global $wpdb;
     $trnsid = 1;
     $gateway_accounts = get_option('pbci_gateway_accounts', array());
     $export_accounts = get_option('pbci_export_accounts', array('sales_revenue' => 'Product Revenue', 'shipping' => 'Shipping', 'sales_tax_account' => 'Sales Tax Payable', 'sales_tax_payee' => 'Sales Tax'));
     $cust = array('NAME' => '', 'FIRSTNAME' => '', 'LASTNAME' => '', 'EMAIL' => '', 'PHONE1' => '', 'BADDR1' => '', 'BADDR2' => '', 'BADDR3' => '', 'BADDR4' => '', 'SADDR1' => '', 'SADDR2' => '', 'SADDR3' => '', 'SADDR4' => '');
     $trans = array('TRNSID' => '', 'TRNSTYPE' => '', 'DATE' => '', 'ACCNT' => '', 'AMOUNT' => '', 'NAME' => '', 'MEMO' => '', 'PAYMETH' => '');
     $spl = array('SPLID' => '', 'TRNSTYPE' => '', 'DATE' => '', 'ACCNT' => '', 'AMOUNT' => '', 'NAME' => '', 'MEMO' => '', 'INVITEM' => '', 'PRICE' => '', 'EXTRA' => '');
     $content = "";
     $cust_content = "";
     $headers = "";
     $headers .= "!CUST\tNAME\t\n";
     $headers .= "!ACCNT\tNAME\tACCNTTYPE\tEXTRA\tACCNUM\n";
     $content .= "ACCNT\t" . $export_accounts['sales_revenue'] . "\tINC\t\n";
     $content .= "ACCNT\t" . $export_accounts['shipping'] . "\tINC\t\n";
     $content .= "ACCNT\t" . $export_accounts['sales_tax_account'] . "\tOCLIAB\tSALESTAX\t2201\n";
     foreach ($gateway_accounts as $gateway => $account_name) {
         if (!empty($account_name)) {
             $content .= "ACCNT\t" . $account_name . "\tBANK\t\n";
         }
     }
     // !TRNS line
     $headers .= '!TRNS';
     foreach ($trans as $key => $value) {
         $headers .= "\t" . $key;
     }
     $headers .= "\n";
     // !SPL line
     $headers .= '!SPL';
     foreach ($spl as $key => $value) {
         $headers .= "\t" . $key;
     }
     $headers .= "\n";
     // !CUST line
     $headers .= '!CUST';
     foreach ($cust as $key => $value) {
         $headers .= "\t" . $key;
     }
     $headers .= "\n";
     // !ENDTRNS line
     //$content .= '!ENDTRNS' . "\n";
     $export_dates = array_keys($_POST['period']);
     foreach ($export_dates as $export_date) {
         $a = explode('-', $export_date);
         $year = $a[0];
         $month = $a[1];
         $sql = "SELECT ID FROM " . WPSC_TABLE_PURCHASE_LOGS . ' WHERE MONTH( FROM_UNIXTIME( date ) ) = ' . $month . ' AND YEAR( FROM_UNIXTIME( DATE ) ) = ' . $year . ' ORDER by date DESC';
         $result = $wpdb->get_col($sql, 0);
         $purchase_log_ids = array_map('intval', $result);
         $max_rows = 1;
         foreach ($purchase_log_ids as $purchase_log_id) {
             $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
             $gateway_id = $purchase_log->get('gateway');
             $data = $purchase_log->get_data();
             if (empty($gateway_accounts[$gateway_id])) {
                 continue;
             }
             // reset the transaction array back to empty
             foreach ($trans as $key => $value) {
                 $trans[$key] = '';
             }
             // reset the customer array back to empty
             foreach ($cust as $key => $value) {
                 $cust[$key] = '';
             }
             if ($purchase_log->get('processed') != WPSC_Purchase_Log::ACCEPTED_PAYMENT && $purchase_log->get('processed') != WPSC_Purchase_Log::CLOSED_ORDER) {
                 continue;
             }
             $checkout_form_data = new WPSC_Checkout_Form_Data($purchase_log_id);
             $checkout = $checkout_form_data->get_data();
             if (!isset($checkout['billingstate'])) {
                 $checkout['billingstate'] = '';
             }
             if (!isset($checkout['shippingstate'])) {
                 $checkout['shippingstate'] = '';
             }
             $timestamp = $purchase_log->get('date');
             $thedate = date('m/d/Y', $timestamp);
             foreach ($trans as $key => $value) {
                 switch ($key) {
                     case 'TRNSID':
                         $trans[$key] = $trnsid++;
                         break;
                     case 'TIMESTAMP':
                         $trans[$key] = $purchase_log->get('date');
                         break;
                     case 'TRNSTYPE':
                         $trans[$key] = 'CASH SALE';
                         break;
                     case 'DATE':
                         $trans[$key] = $thedate;
                         break;
                     case 'ACCNT':
                         $trans[$key] = $gateway_accounts[$gateway_id];
                         break;
                     case 'NAME':
                         $trans[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'AMOUNT':
                         $trans[$key] = $purchase_log->get('totalprice');
                         break;
                     case 'CLEAR':
                         $trans[$key] = 'N';
                         break;
                     case 'SHIPDATE':
                         $trans[$key] = $thedate;
                         break;
                     case 'PAYMETH':
                         $trans[$key] = $purchase_log->get('gateway_name');
                         break;
                     case 'DOCNUM':
                         $trans[$key] = $purchase_log_id;
                         break;
                     case 'MEMO':
                         $trans[$key] = 'sparkle-gear.com purchase #' . $purchase_log_id;
                         break;
                     case 'ADDR1':
                         $trans[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'ADDR2':
                         $trans[$key] = $checkout['billingaddress'];
                         break;
                     case 'ADDR3':
                         $trans[$key] = $checkout['billingcity'] . ', ' . $checkout['billingstate'] . ' ' . $checkout['billingpostcode'];
                         break;
                     case 'ADDR4':
                         $trans[$key] = $checkout['billingcountry'];
                         break;
                     case 'SHIPVIA':
                         $trans[$key] = $purchase_log->get('shipping_method_name');
                         break;
                     case 'INVTITLE':
                         $trans[$key] = 'Sparkle Gear Web Store';
                         break;
                     case 'SADDR1':
                         $trans[$key] = $checkout['shippingfirstname'] . ' ' . $checkout['shippinglastname'];
                         break;
                     case 'SADDR2':
                         $trans[$key] = $checkout['shippingaddress'];
                         break;
                     case 'SADDR3':
                         $trans[$key] = $checkout['shippingcity'] . ', ' . $checkout['shippingstate'] . ' ' . $checkout['shippingpostcode'];
                         break;
                     case 'SADDR4':
                         $trans[$key] = $checkout['billingcountry'];
                         break;
                 }
             }
             foreach ($cust as $key => $value) {
                 switch ($key) {
                     case 'NAME':
                         $cust[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'FIRSTNAME':
                         $cust[$key] = $checkout['billingfirstname'];
                         break;
                     case 'LASTNAME':
                         $cust[$key] = $checkout['billinglastname'];
                         break;
                     case 'EMAIL':
                         $cust[$key] = $checkout['billingemail'];
                         break;
                     case 'PHONE1':
                         $cust[$key] = $checkout['billingphone'];
                         break;
                     case 'BADDR1':
                         $cust[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'BADDR2':
                         $cust[$key] = $checkout['billingaddress'];
                         break;
                     case 'BADDR3':
                         $cust[$key] = $checkout['billingcity'] . ', ' . $checkout['billingstate'] . ' ' . $checkout['billingpostcode'];
                         break;
                     case 'BADDR4':
                         $cust[$key] = $checkout['billingcountry'];
                         break;
                     case 'SADDR1':
                         $cust[$key] = $checkout['shippingfirstname'] . ' ' . $checkout['shippinglastname'];
                         break;
                     case 'SADDR2':
                         $cust[$key] = $checkout['shippingaddress'];
                         break;
                     case 'SADDR3':
                         $cust[$key] = $checkout['shippingcity'] . ', ' . $checkout['shippingstate'] . ' ' . $checkout['shippingpostcode'];
                         break;
                     case 'SADDR4':
                         $cust[$key] = $checkout['billingcountry'];
                         break;
                 }
             }
             foreach ($trans as $key => $value) {
                 $trans[$key] = trim(preg_replace('/\\s+/', ' ', $value));
             }
             foreach ($cust as $key => $value) {
                 $cust[$key] = trim(preg_replace('/\\s+/', ' ', $value));
             }
             $splid = 1;
             // TRNS line
             $content .= 'TRNS';
             foreach ($trans as $key => $value) {
                 $content .= "\t" . $value;
             }
             $content .= "\n";
             $cart_contents = $purchase_log->get_cart_contents();
             foreach ($cart_contents as $cart_item) {
                 $product_id = $cart_item->prodid;
                 if ($parent_product = get_post_field('post_parent', $product_id)) {
                     $product_id = $parent_product;
                 }
                 $terms = wp_get_post_terms($product_id, 'wpsc_product_category');
                 if (!empty($terms)) {
                     foreach ($terms as $term) {
                         $invitem = $term->name;
                         if ($term->parent != 0) {
                             break;
                         }
                     }
                 } else {
                     $invitem = '';
                 }
                 /*
                 $item_name = '';
                 
                 $article = new Bling_Article( $cart_item->prodid );
                 if ( $article->check() ) {
                 	$item_name = $article->name();
                 }
                 */
                 $spl_product = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['sales_revenue'], 'AMOUNT' => -($cart_item->price * $cart_item->quantity), 'QNTY' => -$cart_item->quantity, 'PRICE' => $cart_item->price, 'NAME' => '', 'DOCNUM' => $purchase_log_id, 'MEMO' => $cart_item->name);
                 // SPL line
                 $content .= 'SPL';
                 foreach ($spl as $key => $value) {
                     $content .= "\t";
                     if (!empty($spl_product[$key])) {
                         $content .= $spl_product[$key];
                     }
                 }
                 $content .= "\n";
             }
             $spl_shipping = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['shipping'], 'AMOUNT' => -$purchase_log->get('total_shipping'), 'PRICE' => $purchase_log->get('total_shipping'), 'NAME' => '', 'DOCNUM' => $purchase_log_id, 'MEMO' => 'customer paid shipping', 'EXTRA' => '', 'QNTY' => '');
             $splid = 2;
             $spl_discount = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['sales_revenue'], 'AMOUNT' => $purchase_log->get('discount_value'), 'PRICE' => -$purchase_log->get('discount_value'), 'NAME' => '', 'DOCNUM' => $purchase_log_id, 'MEMO' => 'discount', 'EXTRA' => '', 'QNTY' => '');
             $spl_tax = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['sales_tax_account'], 'AMOUNT' => -$purchase_log->get('wpec_taxes_total'), 'PRICE' => "6.25%", 'NAME' => $export_accounts['sales_tax_payee'], 'DOCNUM' => $purchase_log_id, 'MEMO' => 'sales tax', 'EXTRA' => 'AUTOSTAX', 'QNTY' => '', 'INVITEM' => 'MA Sales/Use Tax');
             $spl_end = array('SPLID' => $trnsid++, 'EXTRA' => 'ENDGRP');
             // SPL line
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_shipping[$key])) {
                     $content .= $spl_shipping[$key];
                 }
             }
             $content .= "\n";
             // SPL line
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_tax[$key])) {
                     $content .= $spl_tax[$key];
                 }
             }
             $content .= "\n";
             // SPL line
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_discount[$key])) {
                     $content .= $spl_discount[$key];
                 }
             }
             $content .= "\n";
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_end[$key])) {
                     $content .= $spl_end[$key];
                 }
             }
             $content .= "\n";
             $splid = 3;
             $content .= 'ENDTRNS';
             $content .= "\n";
             //if ( --$max_rows == 0 )
             //	break;
             $cust_content .= 'CUST';
             foreach ($cust as $key => $value) {
                 $cust_content .= "\t" . $value;
             }
             $cust_content .= "\n";
         }
     }
     $file_name = 'download.iif';
     header('Content-Type: text/csv');
     header('Content-Disposition: inline; filename="' . $file_name . '"');
     echo $headers;
     echo $cust_content;
     echo $content;
     exit;
 }