예제 #1
0
function dibspayment_paywin_order_params($cart)
{
    global $wpdb;
    $order_data = array();
    $purchase_log = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $cart->sessionid . " LIMIT 1", ARRAY_A);
    $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A);
    // Set status on new order
    $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '" . get_option('dibspw_statusp') . "' WHERE `sessionid` = '" . $cart->sessionid . "' LIMIT 1;");
    // collect data for request
    $order_data['orderid'] = $purchase_log[0]['id'];
    $order_data['merchant'] = get_option('dibspw_mid');
    $order_data['amount'] = dibspayment_paywin_round($cart->total_price);
    $order_data['currency'] = $currency_code[0]['code'];
    $order_data['language'] = get_option('dibspw_lang');
    $order_data['oitypes'] = 'QUANTITY;UNITCODE;DESCRIPTION;AMOUNT;ITEMID;VATAMOUNT';
    $order_data['oinames'] = 'Qty;UnitCode;Description;Amount;ItemId;VatAmount';
    $order_data['oinames'] = 'Qty;UnitCode;Description;Amount;ItemId;VatAmount';
    $wpec_taxes_c = new wpec_taxes_controller();
    //$tax_total = $wpec_taxes_c->wpec_taxes_calculate_total();
    //get the rate for the country and region if set
    $tax_total = $wpec_taxes_c->wpec_taxes->wpec_taxes_get_rate($wpec_taxes_c->wpec_taxes_retrieve_selected_country(), $wpec_taxes_c->wpec_taxes_retrieve_region());
    // cart items
    $i = 1;
    foreach ($cart->cart_items as $oitem) {
        $tmp_price = dibspayment_paywin_round($oitem->unit_price);
        if (!empty($tmp_price)) {
            $unit_price = $oitem->unit_price;
            $tax['tax'] = 0;
            if ($wpec_taxes_c->wpec_taxes->wpec_taxes_get_enabled() && $tax_total['rate']) {
                if ($wpec_taxes_c->wpec_taxes_isincluded()) {
                    $tax = $wpec_taxes_c->wpec_taxes_calculate_included_tax($oitem);
                    $tax['tax'] = $tax['tax'] / $oitem->quantity;
                    $unit_price = $oitem->unit_price - $tax['tax'];
                } else {
                    $tax['tax'] = $unit_price * ($tax_total['rate'] / 100);
                }
            }
            $tmp_name = !empty($oitem->product_name) ? $oitem->product_name : $oitem->sku;
            if (empty($tmp_name)) {
                $tmp_name = $oitem->product_id;
            }
            $order_data['oiRow' . $i++] = dibspayment_paywin_oirow_str($oitem->quantity, dibspayment_paywin_utf8Fix(str_replace(";", "\\;", $tmp_name)), dibspayment_paywin_round($unit_price), dibspayment_paywin_utf8Fix(str_replace(";", "\\;", $oitem->product_id)), dibspayment_paywin_round($tax['tax']));
        }
        unset($tmp_price, $tmp_name);
    }
    // Shipping calculation
    if ($cart->calculate_total_shipping()) {
        $shipping_tax = 0;
        $fRate = $cart->calculate_total_shipping();
        if ($tax_total['shipping'] && $wpec_taxes_c->wpec_taxes->wpec_taxes_get_enabled()) {
            if ($wpec_taxes_c->wpec_taxes_isincluded()) {
                $shipping_tax = $wpec_taxes_c->wpec_taxes_calculate_tax($cart->calculate_total_shipping(), $tax_total['rate'], false);
                $fRate = $fRate - $shipping_tax;
            } else {
                $shipping_tax = $wpec_taxes_c->wpec_taxes_calculate_tax($cart->calculate_total_shipping(), $tax_total['rate']);
            }
        }
        $order_data['oiRow' . $i++] = dibspayment_paywin_oirow_str(1, "Shipping", dibspayment_paywin_round($fRate), "shipping_0", dibspayment_paywin_round($shipping_tax));
    }
    // Cupone if it is avaliable
    if ($cart->coupons_amount > 0) {
        $order_data['oiRow' . $i++] = dibspayment_paywin_oirow_str(1, "Coupon", -dibspayment_paywin_round($cart->coupons_amount), "coupon_0", 0);
    }
    // Address fields here..
    $aAddr = $_POST['collected_data'];
    $order_data['shippingfirstname'] = $aAddr[get_option('dibspw_form_first_name_d')];
    $order_data['shippinglastname'] = $aAddr[get_option('dibspw_form_last_name_d')];
    $order_data['shippingpostalcode'] = $aAddr[get_option('dibspw_form_post_code_d')];
    $order_data['shippingpostalplace'] = $aAddr[get_option('dibspw_form_city_d')];
    //$order_data['shippingaddress2']   = $aAddr[get_option('dibspw_form_address_d')];
    $order_data['shippingaddress'] = $aAddr[get_option('dibspw_form_country_d')] . " " . $aAddr[get_option('dibspw_form_state_d')];
    $order_data['billingfirstname'] = $aAddr[get_option('dibspw_form_first_name_b')];
    $order_data['billinglastname'] = $aAddr[get_option('dibspw_form_last_name_b')];
    $order_data['billingpostalcode'] = $aAddr[get_option('dibspw_form_post_code_b')];
    $order_data['billingpostalplace'] = $aAddr[get_option('dibspw_form_city_b')];
    $order_data['billingaddress'] = $aAddr[get_option('dibspw_form_address_b')];
    //$order_data['billingaddress']     = $aAddr[get_option('dibspw_form_country_b')]. " " .
    //                             $aAddr[get_option('dibspw_form_state_b')];
    $order_data['billingmobile'] = $aAddr[get_option('dibspw_form_phone_b')];
    $order_data['billingemail'] = $aAddr[get_option('dibspw_form_email_b')];
    $order_data['acceptreturnurl'] = get_option('siteurl') . "/?dibspw_result=success";
    $order_data['cancelreturnurl'] = site_url() . "/?dibspw_result=cancel";
    $order_data['callbackurl'] = get_option('siteurl') . "/?dibspw_result=callback";
    $order_data['s_callbackfix'] = get_option('siteurl') . "/?dibspw_result=callback";
    $order_data['s_sysmod'] = DIBS_SYSMOD;
    if (get_option('dibspw_testmode')) {
        $order_data['test'] = 1;
    }
    if (get_option('dibspw_capturenow')) {
        $order_data['capturenow'] = 1;
    }
    if (get_option('dibspw_fee')) {
        $order_data['addfee'] = 1;
    }
    $order_data['s_pid'] = $cart->sessionid;
    if (get_option('dibspw_account')) {
        $order_data['account'] = get_option('dibspw_account');
    }
    if (get_option('dibspw_paytype')) {
        $order_data['paytype'] = get_option('dibspw_paytype');
    }
    if (get_option('dibspw_pid')) {
        $order_data['s_partnerid'] = get_option('dibspw_pid');
    }
    if ($hmac = get_option('dibspw_hmac')) {
        $order_data['MAC'] = dibspayment_paywin_calc_mac($order_data, $hmac, $bUrlDecode = FALSE);
    }
    return $order_data;
}
예제 #2
0
 /**
  * save to database method
  * @access public
  *
  * @param integer purchase log id
  */
 function save_to_db($purchase_log_id)
 {
     global $wpdb, $wpsc_shipping_modules;
     $method = $this->cart->selected_shipping_method;
     $shipping = 0;
     if (!empty($method) && method_exists($wpsc_shipping_modules[$method], "get_item_shipping")) {
         $shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping($this);
     }
     if ($this->cart->has_total_shipping_discount()) {
         $shipping = 0;
     }
     $shipping = apply_filters('wpsc_item_shipping_amount_db', $shipping, $this);
     //initialize tax variables
     $tax = 0;
     $tax_rate = 0;
     //wpec_taxes - calculate product tax and add to total price
     $wpec_taxes_controller = new wpec_taxes_controller();
     if ($wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled()) {
         $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
         $tax_rate = $taxes['rate'];
         $tax = $taxes['tax'];
     }
     $wpdb->insert(WPSC_TABLE_CART_CONTENTS, array('prodid' => $this->product_id, 'name' => $this->get_title(), 'purchaseid' => $purchase_log_id, 'price' => $this->unit_price, 'pnp' => $shipping, 'tax_charged' => $tax, 'gst' => $tax_rate, 'quantity' => $this->quantity, 'donation' => $this->is_donation, 'no_shipping' => 0, 'custom_message' => $this->custom_message, 'files' => serialize($this->custom_file), 'meta' => NULL), array('%d', '%s', '%d', '%f', '%f', '%f', '%f', '%s', '%d', '%d', '%s', '%s', '%s'));
     $cart_id = $wpdb->get_var("SELECT " . $wpdb->insert_id . " AS `id` FROM `" . WPSC_TABLE_CART_CONTENTS . "` LIMIT 1");
     wpsc_update_cartmeta($cart_id, 'sku', $this->sku);
     $downloads = get_option('max_downloads');
     if ($this->is_downloadable == true) {
         $product_files = (array) get_posts(array('post_type' => 'wpsc-product-file', 'post_parent' => $this->product_id, 'numberposts' => -1, 'post_status' => 'inherit'));
         foreach ($product_files as $file) {
             // if the file is downloadable, check that the file is real
             $unique_id = sha1(uniqid(mt_rand(), true));
             $wpdb->insert(WPSC_TABLE_DOWNLOAD_STATUS, array('product_id' => $this->product_id, 'fileid' => $file->ID, 'purchid' => $purchase_log_id, 'cartid' => $cart_id, 'uniqueid' => $unique_id, 'downloads' => $downloads, 'active' => 0, 'datetime' => date('Y-m-d H:i:s')), array('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s'));
             $download_id = $wpdb->get_var("SELECT " . $wpdb->insert_id . " AS `id` FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` LIMIT 1");
             wpsc_update_meta($download_id, '_is_legacy', 'false', 'wpsc_downloads');
         }
     }
     do_action('wpsc_save_cart_item', $cart_id, $this->product_id);
 }
예제 #3
0
 /**
  * save to database method
  * @access public
  *
  * @param integer purchase log id
  */
 function save_to_db($purchase_log_id)
 {
     global $wpdb, $wpsc_shipping_modules;
     $method = $this->cart->selected_shipping_method;
     $shipping = 0;
     if (!empty($method) && method_exists($wpsc_shipping_modules[$method], "get_item_shipping")) {
         $shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping($this);
     }
     if ($this->cart->has_total_shipping_discount()) {
         $shipping = 0;
     }
     //initialize tax variables
     $tax = 0;
     $tax_rate = 0;
     //wpec_taxes - calculate product tax and add to total price
     $wpec_taxes_controller = new wpec_taxes_controller();
     if ($wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled()) {
         $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
         $tax_rate = $taxes['rate'];
         $tax = $taxes['tax'];
     }
     $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSC_TABLE_CART_CONTENTS . "` (\n         `prodid`, `name`, `purchaseid`,  `price`, `pnp`,\n         `tax_charged`, `gst`, `quantity`, `donation`,\n         `no_shipping`, `custom_message`, `files`, `meta`\n      ) VALUES ('%d', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '0', '%s', '%s', NULL)", $this->product_id, $this->product_name, $purchase_log_id, $this->unit_price, (double) $shipping, (double) $tax, (double) $tax_rate, $this->quantity, $this->is_donation, $this->custom_message, serialize($this->custom_file)));
     $cart_id = $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `" . WPSC_TABLE_CART_CONTENTS . "` LIMIT 1");
     wpsc_update_cartmeta($cart_id, 'sku', $this->sku);
     $downloads = get_option('max_downloads');
     if ($this->is_downloadable == true) {
         $product_files = (array) get_posts(array('post_type' => 'wpsc-product-file', 'post_parent' => $this->product_id, 'numberposts' => -1, 'post_status' => 'inherit'));
         foreach ($product_files as $file) {
             // if the file is downloadable, check that the file is real
             $unique_id = sha1(uniqid(mt_rand(), true));
             $wpdb->query("INSERT INTO `" . WPSC_TABLE_DOWNLOAD_STATUS . "` (\n               `product_id` , `fileid` ,\n               `purchid` , `cartid`,\n               `uniqueid`, `downloads`,\n               `active` , `datetime`\n            ) VALUES (\n               '{$this->product_id}', '{$file->ID}',\n               '{$purchase_log_id}', '{$cart_id}',\n               '{$unique_id}', '{$downloads}',\n               '0', NOW()\n            );");
             $download_id = $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` LIMIT 1");
             wpsc_update_meta($download_id, '_is_legacy', 'false', 'wpsc_downloads');
         }
     }
     do_action('wpsc_save_cart_item', $cart_id, $this->product_id);
 }