Exemplo n.º 1
0
function fn_get_aup_rates($code, $weight_data, $location, &$auth, $shipping_settings, $package_info, $origination)
{
    if ($shipping_settings['aup_enabled'] != 'Y') {
        return false;
    }
    $weight = $weight_data['full_pounds'] * 453.6;
    //Registered Post International: price as Air Mail, plus $5, weight limit of 2kg.
    if ($code == 'RPI' && $weight > 2000) {
        return array('error' => fn_get_lang_var('illegal_item_weight'));
    }
    $request = array('Pickup_Postcode' => $origination['zipcode'], 'Destination_Postcode' => $location['zipcode'], 'Country' => $location['country'], 'Weight' => $weight, 'Length' => $shipping_settings['aup']['length'] * 10, 'Width' => $shipping_settings['aup']['width'] * 10, 'Height' => $shipping_settings['aup']['height'] * 10, 'Service_type' => $code == 'RPI' ? 'AIR' : $code, 'Quantity' => 1);
    list($header, $result) = fn_http_request('GET', 'http://drc.edeliver.com.au/ratecalc.asp', $request);
    if (!empty($result)) {
        $result = explode("\n", $result);
        if (preg_match("/charge=([\\d\\.]+)/i", $result[0], $matches)) {
            if (!empty($matches[1])) {
                $cost = (double) trim($matches[1]);
                if ($code == 'RPI') {
                    $cost += (double) $shipping_settings['aup']['rpi_fee'];
                }
                if ($shipping_settings['aup']['use_delivery_confirmation'] == 'Y') {
                    $cost += $code == 'STANDARD' || $code == 'EXPRESS' ? (double) $shipping_settings['aup']['delivery_confirmation_cost'] : (double) $shipping_settings['aup']['delivery_confirmation_international_cost'];
                }
                return array('cost' => $cost);
            } else {
                if (defined('SHIPPING_DEBUG') && preg_match("/err_msg=([\\w ]*)/i", $result[2], $matches)) {
                    return array('error' => $matches[1]);
                }
            }
        }
    }
    return false;
}
Exemplo n.º 2
0
/**
 * Check if mod_rewrite is active and clean up templates cache
 */
function fn_settings_actions_addons_seo(&$new_value, $old_value)
{
    if ($new_value == 'A') {
        $result = fn_http_request('GET', Registry::get('config.http_location') . '/catalog.html?version');
        if (strpos($result[0]['RESPONSE'], '200 OK') === false) {
            $new_value = 'D';
            fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('warning_seo_urls_disabled'));
        }
    }
    fn_rm(DIR_COMPILED . 'customer');
    return true;
}
Exemplo n.º 3
0
function fn_google_anaylitics_send($account, $order_info, $refuse = false)
{
    $_uwv = '1';
    $url = "http://www.google-analytics.com/__utm.gif";
    $sign = $refuse == true ? '-' : '';
    $cookies = fn_google_analytics_cookies();
    // Transaction request
    // http://www.google-analytics.com/__utm.gif?utmwv=1&utmt=tran&utmn=262780020&utmtid=80&utmtto=3.96&utmttx=0&utmtsp=0.00&utmtci=Boston&utmtrg=MA&utmtco=United%20States&utmac=ASSASAS&utmcc=__utma%3D81851599.2062069588.1182951649.1183008786.1183012376.3%3B%2B__utmb%3D81851599%3B%2B__utmc%3D81851599%3B%2B__utmz%3D81851599.1182951649.1.1.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B
    $transaction = array('utmwv' => $_uwv, 'utmt' => 'tran', 'utmn' => rand(0, 2147483647), 'utmtid' => $order_info['order_id'], 'utmtto' => $sign . $order_info['total'], 'utmttx' => $order_info['tax_subtotal'], 'utmtsp' => $order_info['shipping_cost'], 'utmtci' => $order_info['b_city'], 'utmtrg' => $order_info['b_state'], 'utmtco' => $order_info['b_country_descr'], 'utmac' => $account, 'utmcc' => $cookies);
    list(, $result) = fn_http_request('GET', $url, $transaction);
    // Items request
    //http://www.google-analytics.com/__utm.gif?utmwv=1&utmt=item&utmn=812678190&utmtid=80&utmipc=B00078MG5M&utmipn=100%25%20Cotton%20Adult%2FYouth%20Beefy%20T-Shirt%20by%20Hanes%20(Style%23%205180)&utmipr=4.50&utmiqt=1&utmac=ASSASAS&utmcc=
    foreach ($order_info['items'] as $item) {
        $cat_id = db_get_field("SELECT category_id FROM ?:products_categories WHERE product_id = ?i AND link_type = 'M'", $item['product_id']);
        $i = array('utmwv' => $_uwv, 'utmt' => 'item', 'utmn' => rand(0, 2147483647), 'utmtid' => $order_info['order_id'], 'utmipc' => $item['product_code'], 'utmipn' => $item['product'], 'utmiva' => fn_get_category_name($cat_id, $order_info['lang_code']), 'utmipr' => $sign . fn_format_price($item['subtotal'] / $item['amount']), 'utmiqt' => $item['amount'], 'utmac' => $account, 'utmcc' => $cookies);
        list(, $result) = fn_http_request('GET', $url, $i);
    }
}
Exemplo n.º 4
0
 function get_data($url)
 {
     if (is_numeric($url)) {
         return new FetchedDataURL($this->content[$url], array(), "");
     } else {
         if (substr($url, 0, 8) == 'file:///') {
             $url = substr($url, 10);
             if (defined('IS_WINDOWS')) {
                 $url = substr($url, 1);
             }
         }
         if (strpos($url, Registry::get('config.http_location')) === 0) {
             $file = str_replace(Registry::get('config.http_location'), DIR_ROOT, $url);
         } elseif (strpos($url, Registry::get('config.https_location')) === 0) {
             $file = str_replace(Registry::get('config.https_location'), DIR_ROOT, $url);
         }
         if (!empty($file) && file_exists($file)) {
             $result = fn_get_contents($file);
         } else {
             list(, $result) = fn_http_request('GET', $url);
         }
         return new FetchedDataURL($result, array(), "");
     }
 }
Exemplo n.º 5
0
function fn_send_sms_notification($body)
{
    $access_data = fn_get_sms_auth_data();
    $to = Registry::get('addons.sms_notifications.phone_number');
    if (fn_is_empty($access_data) || empty($to)) {
        return false;
    }
    $concat = Registry::get('addons.sms_notifications.clickatel_concat');
    //get the last symbol
    if (!empty($concat)) {
        $concat = intval($concat[strlen($concat) - 1]);
    }
    if (!in_array($concat, array('1', '2', '3'))) {
        $concat = 1;
    }
    $data = array('user' => $access_data['login'], 'password' => $access_data['password'], 'api_id' => $access_data['api_id'], 'to' => $to, 'concat' => $concat);
    $unicode = Registry::get('addons.sms_notifications.clickatel_unicode') == 'Y' ? 1 : 0;
    $sms_length = $unicode ? SMS_NOTIFICATIONS_SMS_LENGTH_UNICODE : SMS_NOTIFICATIONS_SMS_LENGTH;
    if ($concat > 1) {
        $sms_length *= $concat;
        $sms_length -= $concat * SMS_NOTIFICATIONS_SMS_LENGTH_CONCAT;
        // If a message is concatenated, it reduces the number of characters contained in each message by 7
    }
    $body = html_entity_decode($body, ENT_QUOTES);
    $body = fn_substr($body, 0, $sms_length);
    if ($unicode) {
        $data['unicode'] = '1';
        $body = fn_convert_encoding('UTF-8', 'UCS-2', $body);
        $codes = '';
        for ($i = 0; $i < strlen($body); $i++) {
            $codes .= sprintf('%02X', ord($body[$i]));
        }
        $body = $codes;
        $body = urlencode($body);
    }
    $data['text'] = $body;
    fn_http_request('GET', 'http://api.clickatell.com/http/sendmsg', $data);
}
Exemplo n.º 6
0
/**
 * Get file contents from local or remote filesystem
 *
 * @param string $location file location
 * @param string $base_dir
 * @return string $result
 */
function fn_get_contents($location, $base_dir = '')
{
    $result = '';
    $path = $base_dir . $location;
    if (!empty($base_dir) && !fn_check_path($path)) {
        return $result;
    }
    // Location is regular file
    if (is_file($path)) {
        $result = @file_get_contents($path);
        // Location is url
    } elseif (strpos($path, '://') !== false) {
        // Prepare url
        $path = str_replace(' ', '%20', $path);
        if (fn_get_ini_param('allow_url_fopen') == true) {
            $result = @file_get_contents($path);
        } else {
            list(, $result) = fn_http_request('GET', $path);
        }
    }
    return $result;
}
Exemplo n.º 7
0
function fn_get_can_rates($code, $weight_data, $location, &$auth, $shipping_settings, $package_info, $origination)
{
    static $cached_rates = array();
    if ($shipping_settings['can_enabled'] != 'Y') {
        return false;
    }
    $cached_rate_id = fn_generate_cached_rate_id($weight_data, $origination);
    if (!empty($cached_rates[$cached_rate_id])) {
        if (!empty($cached_rates[$cached_rate_id][$code])) {
            return array('cost' => $cached_rates[$cached_rate_id][$code]);
        } else {
            return false;
        }
    }
    $merchant_id = $shipping_settings['can']['merchant_id'];
    $length = $shipping_settings['can']['length'];
    $width = $shipping_settings['can']['width'];
    $height = $shipping_settings['can']['height'];
    $origination_postal = $origination['zipcode'];
    $destination_postal = $location['zipcode'];
    $destination_country = $location['country'];
    $destination_city = $location['city'];
    $destination_state = $location['state'];
    $total_cost = $package_info['C'];
    $weight = $weight_data['full_pounds'] * 0.4536;
    $amount = '1';
    $lang = CART_LANGUAGE == 'FR' ? 'fr' : 'en';
    $request[] = <<<XML
<?xml version="1.0" ?>
<eparcel>
\t<language>{$lang}</language>
\t<ratesAndServicesRequest>
\t\t<merchantCPCID>{$merchant_id}</merchantCPCID>
\t\t<fromPostalCode>{$origination_postal}</fromPostalCode>
\t\t<turnAroundTime> 24 </turnAroundTime>
\t\t<itemsPrice>{$total_cost}</itemsPrice>
\t\t<lineItems>
\t\t\t<item>
\t\t\t\t<quantity>{$amount}</quantity>
\t\t\t\t<weight>{$weight}</weight>
\t\t\t\t<length>{$length}</length>
\t\t\t\t<width>{$width}</width>
\t\t\t\t<height>{$height}</height>
\t\t\t\t<description>ggrtye</description>
\t\t\t\t<readyToShip/>
\t\t\t</item>
\t\t</lineItems>
\t\t<city>{$destination_city}</city>
\t\t<provOrState>{$destination_state}</provOrState>
\t\t<country>{$destination_country}</country>
\t\t<postalCode>{$destination_postal}</postalCode>
\t</ratesAndServicesRequest>
</eparcel>
XML;
    list($header, $result) = fn_http_request('POST', 'http://sellonline.canadapost.ca:30000', $request);
    $rates = fn_can_get_rates($result);
    if (empty($cached_rates[$cached_rate_id]) && !empty($rates['cost'])) {
        $cached_rates[$cached_rate_id] = $rates['cost'];
    }
    if (!empty($rates['cost'][$code])) {
        return array('cost' => $rates['cost'][$code]);
    } else {
        if (defined('SHIPPING_DEBUG')) {
            return array('error' => !empty($rates['error']) ? $rates['error'] : fn_get_lang_var('service_not_available'));
        }
    }
    return false;
}
Exemplo n.º 8
0
function fn_get_usps_rates($code, $weight_data, $location, &$auth, $shipping_settings, $package_info, $origination)
{
    static $cached_rates = array();
    if ($shipping_settings['usps_enabled'] != 'Y') {
        return false;
    }
    $cached_rate_id = fn_generate_cached_rate_id($weight_data, $origination);
    if (!empty($cached_rates[$cached_rate_id])) {
        if (!empty($cached_rates[$cached_rate_id][$code])) {
            return array('cost' => $cached_rates[$cached_rate_id][$code]);
        } else {
            return false;
        }
    }
    if ($shipping_settings['usps']['test_mode'] == 'Y') {
        $url = 'http://testing.shippingapis.com/ShippingAPI.dll';
    } else {
        $url = 'http://production.shippingapis.com/ShippingAPI.dll';
    }
    $username = $shipping_settings['usps']['username'];
    $machinable = $shipping_settings['usps']['machinable'];
    $container_priority = $shipping_settings['usps']['container_priority'];
    $container_express = $shipping_settings['usps']['container_express'];
    $mailtype = $shipping_settings['usps']['mailtype'];
    $package_size = $shipping_settings['usps']['package_size'];
    $first_class_mail_type = $shipping_settings['usps']['first_class_mail_type'];
    $pounds = $weight_data['pounds'];
    $ounces = $weight_data['ounces'];
    // The zip code should be in 5 digit format so we cut all digits after "-"
    $origination_postal = preg_replace('/-\\d*/i', '', trim($origination['zipcode']));
    $destination_postal = preg_replace('/-\\d*/i', '', trim($location['zipcode']));
    $origination_country = $origination['country'];
    $destination_country = $location['country'];
    $size_parameters = '';
    if ($package_size == 'Large') {
        $_width = $shipping_settings['usps']['priority_width'];
        $_length = $shipping_settings['usps']['priority_length'];
        $_height = $shipping_settings['usps']['priority_height'];
        $size_parameters = <<<EOT
\t\t\t<Width>{$_width}</Width>
\t\t\t<Length>{$_length}</Length>
\t\t\t<Height>{$_height}</Height>
EOT;
        if ($container_priority == 'NonRectangular') {
            $_priority_girth = $shipping_settings['usps']['priority_girth'];
            $size_parameters .= "<Girth>{$_priority_girth}</Girth>";
        }
    }
    $us_dependent_territories = array('AS', 'VI', 'PR', 'GU', 'MP', 'FM', 'MH', 'PW');
    if (in_array($destination_country, $us_dependent_territories)) {
        $destination_country = 'US';
    }
    if ($origination_country == $destination_country) {
        // Domestic rate calculation
        $query = <<<EOT
\t\t<RateV3Request USERID="{$username}">
\t\t  <Package ID="0">
\t\t\t<Service>EXPRESS</Service>
\t\t\t<ZipOrigination>{$origination_postal}</ZipOrigination>
\t\t\t<ZipDestination>{$destination_postal}</ZipDestination>
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<Container>{$container_express}</Container>
\t\t\t<Size>{$package_size}</Size>
\t\t  </Package>
\t\t  <Package ID="1">
\t\t\t<Service>FIRST CLASS</Service>
\t\t\t<FirstClassMailType>{$first_class_mail_type}</FirstClassMailType>
\t\t\t<ZipOrigination>{$origination_postal}</ZipOrigination>
\t\t\t<ZipDestination>{$destination_postal}</ZipDestination>
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<Size>{$package_size}</Size>
\t\t\t<Machinable>{$machinable}</Machinable>
\t\t  </Package>
\t\t  <Package ID="2">
\t\t\t<Service>PRIORITY</Service>
\t\t\t<ZipOrigination>{$origination_postal}</ZipOrigination>
\t\t\t<ZipDestination>{$destination_postal}</ZipDestination>
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<Container>{$container_priority}</Container>
\t\t\t<Size>{$package_size}</Size>
\t\t\t{$size_parameters}
\t\t  </Package>
\t\t  <Package ID="3">
\t\t\t<Service>PARCEL</Service>
\t\t\t<ZipOrigination>{$origination_postal}</ZipOrigination>
\t\t\t<ZipDestination>{$destination_postal}</ZipDestination>
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<Size>{$package_size}</Size>
\t\t\t<Machinable>{$machinable}</Machinable>
\t\t  </Package>
\t\t  <Package ID="4">
\t\t\t<Service>BPM</Service>
\t\t\t<ZipOrigination>{$origination_postal}</ZipOrigination>
\t\t\t<ZipDestination>{$destination_postal}</ZipDestination>
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<Size>{$package_size}</Size>
\t\t  </Package>
\t\t  <Package ID="5">
\t\t\t<Service>LIBRARY</Service>
\t\t\t<ZipOrigination>{$origination_postal}</ZipOrigination>
\t\t\t<ZipDestination>{$destination_postal}</ZipDestination>
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<Size>{$package_size}</Size>
\t\t  </Package>
\t\t  <Package ID="6">
\t\t\t<Service>MEDIA</Service>
\t\t\t<ZipOrigination>{$origination_postal}</ZipOrigination>
\t\t\t<ZipDestination>{$destination_postal}</ZipDestination>
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<Size>{$package_size}</Size>
\t\t  </Package>
\t\t</RateV3Request>
EOT;
        $get = array('API' => 'RateV3', 'XML' => $query);
        $is_domestic = true;
    } else {
        // International rate calculation
        $destination_country = fn_get_usps_country($destination_country);
        if (empty($destination_country)) {
            return false;
        }
        $query = <<<EOT
\t\t<IntlRateRequest USERID="{$username}">
\t\t  <Package ID="0">
\t\t\t<Pounds>{$pounds}</Pounds>
\t\t\t<Ounces>{$ounces}</Ounces>
\t\t\t<MailType>{$mailtype}</MailType>
\t\t\t<Country>{$destination_country}</Country>
\t\t  </Package>
\t\t</IntlRateRequest>
EOT;
        $get = array('API' => 'IntlRate', 'XML' => $query);
        $is_domestic = false;
    }
    list($header, $result) = fn_http_request('GET', $url, $get);
    $rates = fn_usps_get_rates($result, $is_domestic);
    if (empty($cached_rates[$cached_rate_id])) {
        $cached_rates[$cached_rate_id] = $rates;
    }
    if (!empty($rates[$code])) {
        return array('cost' => $rates[$code]);
    } else {
        if (defined('SHIPPING_DEBUG')) {
            return array('error' => fn_usps_get_error($result));
        }
    }
    return false;
}
Exemplo n.º 9
0
function fn_anti_fraud_place_order($order_id, &$action, &$order_status)
{
    if ($action == 'save' || defined('ORDER_MANAGEMENT')) {
        return true;
    }
    $return = array();
    $af_settings = Registry::get('addons.anti_fraud');
    if (empty($af_settings['anti_fraud_key'])) {
        return false;
    }
    $order_info = fn_get_order_info($order_id);
    if (empty($order_info['ip_address'])) {
        $return['B'][] = 'af_ip_not_found';
    }
    $risk_factor = 1;
    $request = array('license_key' => $af_settings['anti_fraud_key'], 'i' => $order_info['ip_address'], 'city' => $order_info['b_city'], 'region' => $order_info['b_state'], 'postal' => $order_info['b_zipcode'], 'country' => $order_info['b_country'], 'domain' => substr($order_info['email'], strpos($order_info['email'], '@') + 1), 'emailMD5' => $order_info['email']);
    list($header, $_result) = fn_http_request('GET', 'http://www.maxmind.com/app/ccv2r', $request);
    $result = array();
    $_result = explode(';', $_result);
    if (is_array($_result)) {
        foreach ($_result as $v) {
            $tmp = explode('=', $v);
            $result[$tmp[0]] = $tmp[1];
        }
    }
    unset($_result);
    if (!empty($result['err'])) {
        $return['B'][] = 'af_' . strtolower($result['err']);
        $risk_factor *= AF_ERROR_FACTOR;
    } else {
        // Check if order total greater than defined
        if (!empty($af_settings['anti_fraud_max_order_total']) && floatval($order_info['total']) > floatval($af_settings['anti_fraud_max_order_total'])) {
            $risk_factor *= AF_ORDER_TOTAL_FACTOR;
            $return['B'][] = 'af_big_order_total';
        }
        if (!empty($order_info['user_id'])) {
            // Check if this customer has processed orders
            $amount = db_get_field("SELECT COUNT(*) FROM ?:orders WHERE status IN ('P','C') AND user_id = ?i", $order_info['user_id']);
            if (!empty($amount)) {
                $risk_factor /= AF_COMPLETED_ORDERS_FACTOR;
                $return['G'][] = 'af_has_successfull_orders';
            }
            // Check if this customer has failed orders
            $amount = db_get_field("SELECT COUNT(*) FROM ?:orders WHERE status IN ('D','F') AND user_id = ?i", $order_info['user_id']);
            if (!empty($amount)) {
                $risk_factor *= AF_FAILED_ORDERS_FACTOR;
                $return['B'][] = 'af_has_failed_orders';
            }
        }
        if ($result['countryMatch'] == 'No') {
            $return['B'][] = 'af_country_doesnt_match';
        }
        if ($result['highRiskCountry'] == 'Yes') {
            $return['B'][] = 'af_high_risk_country';
        }
        if (!empty($af_settings['anti_fraud_safe_distance']) && intval($result['distance']) > intval($af_settings['anti_fraud_safe_distance'])) {
            $return['B'][] = 'af_long_distance';
        }
        if ($result['carderEmail'] == 'Yes') {
            $return['B'][] = 'af_carder_email';
        }
        $risk_factor += floatval($result['score']);
        if ($risk_factor > 10) {
            $risk_factor = 10;
        }
    }
    $return['risk_factor'] = $risk_factor;
    if (floatval($risk_factor) >= floatval($af_settings['anti_fraud_risk_factor'])) {
        $action = 'save';
        $order_status = 'O';
        $return['B'][] = 'af_high_risk_factor';
    } else {
        $return['G'][] = 'af_low_risk_factor';
    }
    $return = serialize($return);
    $data = array('order_id' => $order_id, 'type' => 'F', 'data' => $return);
    db_query("REPLACE INTO ?:order_data ?e", $data);
    return true;
}