Exemple #1
0
function zen_address_format($zen, $data, $pre)
{
    $company = $data[$pre . 'company'];
    $name = isset($data[$pre . 'firstname']) ? $data[$pre . 'firstname'] . ' ' . $data[$pre . 'lastname'] : false;
    $street_address = $data[$pre . 'street_address'];
    $suburb = $data[$pre . 'suburb'];
    $city = $data[$pre . 'city'];
    $postcode = $data[$pre . 'postcode'];
    if (not_null($data[$pre . 'state'])) {
        $state = $data[$pre . 'state'];
    } else {
        if (not_null($data[$pre . 'zone_id'])) {
            $state = zen_get_zone_code_from_id($zen, $data[$pre . 'zone_id']);
        }
    }
    if (isset($data[$pre . 'country_id'])) {
        $country = zen_get_country($zen, $data[$pre . 'country_id']);
    } else {
        $country = $data[$pre . 'country'];
    }
    $ret = '';
    if (not_null($company)) {
        $ret .= $company . "\n";
    }
    $ret .= $name . "\n" . $street_address . "\n";
    if (not_null($suburb)) {
        $ret .= $suburb . "\n";
    }
    if (not_null($city)) {
        $ret .= $city;
    }
    if (not_null($state)) {
        $ret .= ", " . zen_get_zone_code($zen, $state);
    }
    if (not_null($postcode)) {
        $ret .= " " . $postcode . "\n";
    } else {
        $ret .= "\n";
    }
    if (not_null($country)) {
        $ret .= $country . "\n";
    }
    return $ret;
}
 function get_extend_param()
 {
     global $order;
     // if shipping info is empty, use billing info
     if (empty($order->delivery['country'])) {
         $order->delivery = $order->billing;
     }
     // ship to country, state
     $ship_to_country = $order->delivery['country']['iso_code_2'];
     $ship_to_state = '';
     if (!in_array($ship_to_country, array('US', 'CA'))) {
         $ship_to_state = 'YT';
     } else {
         $ship_to_state = zen_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], '');
     }
     // telephone
     $telephone = $order->customer["telephone"];
     if (empty($telephone)) {
         $telephone = trim($order->billing["telephone"]);
     }
     if (empty($telephone)) {
         $telephone = trim($order->delivery["telephone"]);
     }
     // js return
     $js_return = '';
     if (isset($_SESSION['alipay_js_return'])) {
         $js_return = $_SESSION['alipay_js_return'];
     }
     $product_name = 'product total:' . $order->info['total'];
     $extend_param = array('ship_to_firstname' => $order->delivery["firstname"], 'ship_to_lastname' => $order->delivery["lastname"], 'ship_to_postalcode' => $order->delivery["postcode"], 'ship_to_phonenumber' => $order->delivery["telephone"], 'ship_to_street1' => $order->delivery['street_address'], 'ship_to_city' => $order->delivery['city'], 'ship_to_state' => $ship_to_state, 'ship_to_country' => $ship_to_country, 'ship_to_shipmethod' => 7, 'logistics_cost' => '', 'registration_name' => $order->customer["firstname"] . ' ' . $order->customer["lastname"], 'registration_email' => $order->customer['email_address'], 'registration_phone' => $telephone, 'product_name' => $product_name, 'js_return' => $js_return);
     $param_str = '';
     foreach ($extend_param as $key => $val) {
         if (!isset($val) || $val == '') {
             unset($extend_param[$key]);
         } else {
             $param_str .= $key . '^' . $val . '|';
         }
     }
     $param_str = substr($param_str, 0, -1);
     return $param_str;
 }
function zen_address_format($address_format_id, $address, $html, $boln, $eoln)
{
    global $db;
    $address_format_query = "select address_format as format\n                             from " . TABLE_ADDRESS_FORMAT . "\n                             where address_format_id = '" . (int) $address_format_id . "'";
    $address_format = $db->Execute($address_format_query);
    //$company = zen_output_string_protected($address['company']);
    if (isset($address['firstname']) && zen_not_null($address['firstname'])) {
        $firstname = zen_output_string_protected($address['firstname']);
        $lastname = zen_output_string_protected($address['lastname']);
    } elseif (isset($address['name']) && zen_not_null($address['name'])) {
        $firstname = zen_output_string_protected($address['name']);
        $lastname = '';
    } else {
        $firstname = '';
        $lastname = '';
    }
    $street = zen_output_string_protected($address['street_address']);
    $suburb = zen_output_string_protected($address['suburb']);
    $city = zen_output_string_protected($address['city']);
    $state = zen_output_string_protected($address['state']);
    $phone = ENTRY_PHONE_NUMBER . zen_output_string_protected($address['phone']);
    if (isset($address['country_id']) && zen_not_null($address['country_id'])) {
        $country = zen_get_country_name($address['country_id']);
        if (isset($address['zone_id']) && zen_not_null($address['zone_id'])) {
            $state = zen_get_zone_code($address['country_id'], $address['zone_id'], $state);
        }
    } elseif (isset($address['country']) && zen_not_null($address['country'])) {
        if (is_array($address['country'])) {
            $country = zen_output_string_protected($address['country']['countries_name']);
        } else {
            $country = zen_output_string_protected($address['country']);
        }
    } else {
        $country = '';
    }
    $postcode = zen_output_string_protected($address['postcode']);
    $zip = $postcode;
    if ($html) {
        // HTML Mode
        $HR = '<hr />';
        $hr = '<hr />';
        if ($boln == '' && $eoln == "\n") {
            // Values not specified, use rational defaults
            $CR = '<br />';
            $cr = '<br />';
            $eoln = $cr;
        } else {
            // Use values supplied
            $CR = $eoln . $boln;
            $cr = $CR;
        }
    } else {
        // Text Mode
        $CR = $eoln;
        $cr = $CR;
        $HR = '----------------------------------------';
        $hr = '----------------------------------------';
    }
    $statecomma = '';
    $streets = $street;
    if ($suburb != '') {
        $streets = $street . ',' . $suburb;
    }
    if ($country == '') {
        if (is_array($address['country'])) {
            $country = zen_output_string_protected($address['country']['countries_name']);
        } else {
            $country = zen_output_string_protected($address['country']);
        }
    }
    if ($state != '') {
        $statecomma = $state . ', ';
    }
    $fmt = $address_format->fields['format'];
    eval("\$address_out = \"{$fmt}\";");
    return $address_out;
}
Exemple #4
0
 /**
  * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
  * This sends the data to the payment gateway for processing.
  * (These are hidden fields on the checkout confirmation page)
  *
  * @return string
  */
 function process_button()
 {
     global $db, $order, $currencies, $currency;
     $this->totalsum = $order->info['total'];
     // save the session stuff permanently in case paypal loses the session
     $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . session_id() . "'");
     $sql = "insert into " . TABLE_PAYPAL_SESSION . " (session_id, saved_session, expiry) values (\r\n            '" . session_id() . "',\r\n            '" . base64_encode(serialize($_SESSION)) . "',\r\n            '" . (time() + 1 * 60 * 60 * 24 * 2) . "')";
     $db->Execute($sql);
     if (MODULE_PAYMENT_PAYPAL_CURRENCY == 'Selected Currency') {
         $my_currency = $_SESSION['currency'];
     } else {
         $my_currency = substr(MODULE_PAYMENT_PAYPAL_CURRENCY, 5);
     }
     if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD', 'AUD'))) {
         $my_currency = 'USD';
     }
     $telephone = preg_replace('/\\D/', '', $order->customer['telephone']);
     $process_button_string = zen_draw_hidden_field('business', MODULE_PAYMENT_PAYPAL_BUSINESS_ID) . zen_draw_hidden_field('cmd', '_ext-enter') . zen_draw_hidden_field('return', zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL')) . zen_draw_hidden_field('cancel_return', zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')) . zen_draw_hidden_field('notify_url', zen_href_link('ipn_main_handler.php', '', 'SSL', false, false, true)) . zen_draw_hidden_field('rm', MODULE_PAYMENT_PAYPAL_RM) . zen_draw_hidden_field('currency_code', $my_currency) . zen_draw_hidden_field('bn', 'zencart') . zen_draw_hidden_field('mrb', 'R-6C7952342H795591R') . zen_draw_hidden_field('pal', '9E82WJBKKGPLQ') . zen_draw_hidden_field('cbt', MODULE_PAYMENT_PAYPAL_CBT) . zen_draw_hidden_field('image_url', MODULE_PAYMENT_PAYPAL_IMAGE_URL) . zen_draw_hidden_field('page_style', MODULE_PAYMENT_PAYPAL_PAGE_STYLE) . zen_draw_hidden_field('item_name', STORE_NAME) . zen_draw_hidden_field('item_number', '1') . zen_draw_hidden_field('lc', $order->customer['country']['iso_code_2']) . zen_draw_hidden_field('amount', number_format($this->totalsum * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency))) . zen_draw_hidden_field('shipping', '0.00') . zen_draw_hidden_field('custom', zen_session_name() . '=' . zen_session_id()) . zen_draw_hidden_field('upload', sizeof($order->products)) . zen_draw_hidden_field('redirect_cmd', '_xclick') . zen_draw_hidden_field('first_name', $order->customer['lastname']) . zen_draw_hidden_field('last_name', $order->customer['firstname']) . zen_draw_hidden_field('address1', $order->customer['street_address']) . zen_draw_hidden_field('city', $order->customer['city']) . zen_draw_hidden_field('state', zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['zone_id'])) . zen_draw_hidden_field('zip', $order->customer['postcode']) . zen_draw_hidden_field('country', $order->customer['country']['iso_code_2']) . zen_draw_hidden_field('email', $order->customer['email_address']) . zen_draw_hidden_field('night_phone_a', substr($telephone, 0, 3)) . zen_draw_hidden_field('night_phone_b', substr($telephone, 3, 3)) . zen_draw_hidden_field('night_phone_c', substr($telephone, 6, 4)) . zen_draw_hidden_field('day_phone_a', substr($telephone, 0, 3)) . zen_draw_hidden_field('day_phone_b', substr($telephone, 3, 3)) . zen_draw_hidden_field('day_phone_c', substr($telephone, 6, 4)) . zen_draw_hidden_field('paypal_order_id', $paypal_order_id);
     return $process_button_string;
 }
 function quote($pShipHash = array())
 {
     /* FedEx integration starts */
     global $gBitCustomer, $order;
     require_once dirname(__FILE__) . '/fedex-common.php5';
     ini_set("soap.wsdl_cache_enabled", "0");
     $shippingWeight = !empty($pShipHash['shipping_weight']) && $pShipHash['shipping_weight'] > 1 ? $pShipHash['shipping_weight'] : 1;
     $shippingNumBoxes = !empty($pShipHash['shipping_num_boxes']) ? $pShipHash['shipping_num_boxes'] : 1;
     $client = new SoapClient(dirname(__FILE__) . "/RateService_v10.wsdl", array('trace' => 1));
     $this->types = array();
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_INTERNATIONAL_PRIORITY == 'true') {
         $this->types['INTERNATIONAL_PRIORITY'] = array('code' => 'FEDEX_INTERNATIONAL_PRIORITY', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_EXPRESS_HANDLING_FEE);
         $this->types['EUROPE_FIRST_INTERNATIONAL_PRIORITY'] = array('code' => 'FEDEX_EUROPE_FIRST_INTERNATIONAL_PRIORITY', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_EXPRESS_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_INTERNATIONAL_ECONOMY == 'true') {
         $this->types['INTERNATIONAL_ECONOMY'] = array('code' => 'FEDEX_INTERNATIONAL_ECONOMY', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_EXPRESS_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_STANDARD_OVERNIGHT == 'true') {
         $this->types['STANDARD_OVERNIGHT'] = array('code' => 'FEDEX_STANDARD_OVERNIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_FIRST_OVERNIGHT == 'true') {
         $this->types['FIRST_OVERNIGHT'] = array('code' => 'FEDEX_FIRST_OVERNIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_PRIORITY_OVERNIGHT == 'true') {
         $this->types['PRIORITY_OVERNIGHT'] = array('code' => 'FEDEX_PRIORITY_OVERNIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_2DAY == 'true') {
         $this->types['FEDEX_2_DAY'] = array('code' => 'FEDEX_2_DAY', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
     }
     // because FEDEX_GROUND also is returned for Canadian Addresses, we need to check if the country matches the store country and whether international ground is enabled
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_GROUND == 'true' && $order->delivery['country']['countries_id'] == STORE_COUNTRY || MODULE_SHIPPING_FEDEX_WEB_SERVICES_GROUND == 'true' && $order->delivery['country']['countries_id'] != STORE_COUNTRY && MODULE_SHIPPING_FEDEX_WEB_SERVICES_INTERNATIONAL_GROUND == 'true') {
         $this->types['FEDEX_GROUND'] = array('code' => 'FEDEX_GROUND', 'icon' => '', 'handling_fee' => $order->delivery['country']['countries_id'] == STORE_COUNTRY ? MODULE_SHIPPING_FEDEX_WEB_SERVICES_HANDLING_FEE : MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_HANDLING_FEE);
         $this->types['GROUND_HOME_DELIVERY'] = array('code' => 'FEDEX_GROUND_HOME_DELIVERY', 'icon' => '', 'handling_fee' => $order->delivery['country']['countries_id'] == STORE_COUNTRY ? MODULE_SHIPPING_FEDEX_WEB_SERVICES_HANDLING_FEE : MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_INTERNATIONAL_GROUND == 'true') {
         $this->types['INTERNATIONAL_GROUND'] = array('code' => 'FEDEX_INTERNATIONAL_GROUND', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_SAVER == 'true') {
         $this->types['FEDEX_EXPRESS_SAVER'] = array('code' => 'FEDEX_EXPRESS_SAVER', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_FREIGHT == 'true') {
         $this->types['FEDEX_FREIGHT'] = array('code' => 'FEDEX_FREIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
         $this->types['FEDEX_NATIONAL_FREIGHT'] = array('code' => 'FEDEX_NATIONAL_FREIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
         $this->types['FEDEX_1_DAY_FREIGHT'] = array('code' => 'FEDEX_1_DAY_FREIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
         $this->types['FEDEX_2_DAY_FREIGHT'] = array('code' => 'FEDEX_2_DAY_FREIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
         $this->types['FEDEX_3_DAY_FREIGHT'] = array('code' => 'FEDEX_3_DAY_FREIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_EXPRESS_HANDLING_FEE);
         $this->types['INTERNATIONAL_ECONOMY_FREIGHT'] = array('code' => 'FEDEX_INTERNATIONAL_ECONOMY_FREIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_EXPRESS_HANDLING_FEE);
         $this->types['INTERNATIONAL_PRIORITY_FREIGHT'] = array('code' => 'FEDEX_INTERNATIONAL_PRIORITY_FREIGHT', 'icon' => '', 'handling_fee' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_INT_EXPRESS_HANDLING_FEE);
     }
     // customer details
     $street_address = !empty($order->delivery['street_address']) ? $order->delivery['street_address'] : '';
     $street_address2 = !empty($order->delivery['suburb']) ? $order->delivery['suburb'] : '';
     $city = !empty($order->delivery['city']) ? $order->delivery['city'] : '';
     if ($stateLookup = BitBase::getParameter($order->delivery, 'zone_id', BitBase::getParameter($order->delivery, 'state'))) {
         $stateCode = zen_get_zone_code($order->delivery['country']['countries_id'], $stateLookup, '');
         if ($stateCode == "QC") {
             $stateCode = "PQ";
             // is this needed? been here forever
         }
     }
     $postcode = str_replace(array(' ', '-'), '', $order->delivery['postcode']);
     $country_id = $order->delivery['country']['countries_iso_code_2'];
     if (is_object($order)) {
         $totals = $order->subtotal;
     } elseif (is_object($gBitCustomer->mCart)) {
         $totals = $gBitCustomer->mCart->show_total();
     }
     $this->_setInsuranceValue($totals);
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_KEY, 'Password' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_PWD));
     $request['ClientDetail'] = array('AccountNumber' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_ACT_NUM, 'MeterNumber' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_METER_NUM);
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v10 using PHP ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '10', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = $this->_setDropOff();
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     //if (zen_not_null($method) && in_array($method, $this->types)) {
     //$request['RequestedShipment']['ServiceType'] = $method; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
     //}
     $request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING';
     // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
     $request['RequestedShipment']['TotalInsuredValue'] = array('Amount' => $this->insurance, 'Currency' => DEFAULT_CURRENCY);
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_KEY, 'Password' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_PWD));
     $request['ClientDetail'] = array('AccountNumber' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_ACT_NUM, 'MeterNumber' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_METER_NUM);
     $request['RequestedShipment']['Shipper'] = array('Address' => array('StreetLines' => array(MODULE_SHIPPING_FEDEX_WEB_SERVICES_ADDRESS_1, MODULE_SHIPPING_FEDEX_WEB_SERVICES_ADDRESS_2), 'City' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_CITY, 'StateOrProvinceCode' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_STATE, 'PostalCode' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_POSTAL, 'CountryCode' => $this->country));
     $request['RequestedShipment']['Recipient'] = array('Address' => array('StreetLines' => array(utf8_encode($street_address), utf8_encode($street_address2)), 'City' => utf8_encode($city), 'PostalCode' => $postcode, 'CountryCode' => $country_id, 'Residential' => empty($order->delivery['company'])));
     //customer county code
     if (!empty($stateCode) && in_array($country_id, array('US', 'CA'))) {
         $request['RequestedShipment']['Recipient']['StateOrProvinceCode'] = $stateCode;
     }
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_ACT_NUM, 'CountryCode' => $this->country));
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
     $request['RequestedShipment']['RequestedPackageLineItems'] = array();
     $dimensions_failed = false;
     // check for ready to ship field
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_READY_TO_SHIP == 'true') {
         // Not fixed for bitcommerce
         $products = $gBitCustomer->mCart->get_products();
         $packages = array('default' => 0);
         $new_shipping_num_boxes = 0;
         foreach ($products as $product) {
             $dimensions_query = "SELECT products_length, products_width, products_height, products_ready_to_ship, products_dim_type FROM " . TABLE_PRODUCTS . " \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE products_id = " . (int) $product['id'] . " \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND products_length > 0 \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND products_width > 0\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND products_height > 0 \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t LIMIT 1;";
             $dimensions = $this->mDb->query($dimensions_query);
             if ($dimensions->RecordCount() > 0 && $dimensions->fields['products_ready_to_ship'] == 1) {
                 for ($i = 1; $i <= $product['quantity']; $i++) {
                     $packages[] = array('weight' => $product['weight'], 'length' => $dimensions->fields['products_length'], 'width' => $dimensions->fields['products_width'], 'height' => $dimensions->fields['products_height'], 'units' => strtoupper($dimensions->fields['products_dim_type']));
                 }
             } else {
                 $packages['default'] += $product['weight'] * $product['quantity'];
             }
         }
         if (count($packages) > 1) {
             $za_tare_array = preg_split("/[:,]/", SHIPPING_BOX_WEIGHT);
             $zc_tare_percent = $za_tare_array[0];
             $zc_tare_weight = $za_tare_array[1];
             $za_large_array = preg_split("/[:,]/", SHIPPING_BOX_PADDING);
             $zc_large_percent = $za_large_array[0];
             $zc_large_weight = $za_large_array[1];
         }
         foreach ($packages as $id => $values) {
             if ($id === 'default') {
                 // divide the weight by the max amount to be shipped (can be done inside loop as this occurance should only ever happen once
                 // note $values is not an array
                 if ($values == 0) {
                     continue;
                 }
                 $shippingNumBoxes = ceil((double) $values / (double) SHIPPING_MAX_WEIGHT);
                 if ($shippingNumBoxes < 1) {
                     $shippingNumBoxes = 1;
                 }
                 $shippingWeight = round((double) $values / $shippingNumBoxes, 2);
                 // 2 decimal places max
                 for ($i = 0; $i < $shippingNumBoxes; $i++) {
                     $new_shipping_num_boxes++;
                     if (SHIPPING_MAX_WEIGHT <= $shippingWeight) {
                         $shippingWeight = $shippingWeight + $shippingWeight * ($zc_large_percent / 100) + $zc_large_weight;
                     } else {
                         $shippingWeight = $shippingWeight + $shippingWeight * ($zc_tare_percent / 100) + $zc_tare_weight;
                     }
                     if ($shippingWeight <= 0) {
                         $shippingWeight = 0.1;
                     }
                     $new_shipping_weight += $shippingWeight;
                     $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $shippingWeight, 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT), 'GroupPackageCount' => 1);
                 }
             } else {
                 // note $values is an array
                 $new_shipping_num_boxes++;
                 if ($values['weight'] <= 0) {
                     $values['weight'] = 0.1;
                 }
                 $new_shipping_weight += $values['weight'];
                 $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $values['weight'], 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT), 'Dimensions' => array('Length' => $values['length'], 'Width' => $values['width'], 'Height' => $values['height'], 'Units' => $values['units']), 'GroupPackageCount' => 1);
             }
         }
         $shippingNumBoxes = $new_shipping_num_boxes;
         $shippingWeight = round($new_shipping_weight / $shippingNumBoxes, 2);
     } else {
         if ($shippingWeight == 0) {
             $shippingWeight = 0.1;
         }
         for ($i = 0; $i < $shippingNumBoxes; $i++) {
             $request['RequestedShipment']['RequestedPackageLineItems'][] = array('Weight' => array('Value' => $shippingWeight, 'Units' => MODULE_SHIPPING_FEDEX_WEB_SERVICES_WEIGHT), 'GroupPackageCount' => 1);
         }
     }
     $request['RequestedShipment']['PackageCount'] = $shippingNumBoxes;
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_SATURDAY == 'true') {
         $request['RequestedShipment']['ServiceOptionType'] = 'SATURDAY_DELIVERY';
     }
     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_SIGNATURE_OPTION >= 0 && $totals >= MODULE_SHIPPING_FEDEX_WEB_SERVICES_SIGNATURE_OPTION) {
         $request['RequestedShipment']['SpecialServicesRequested'] = 'SIGNATURE_OPTION';
     }
     try {
         $response = $client->getRates($request);
         if (!empty($response) && ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR' && !empty($response->RateReplyDetails))) {
             if (is_object($response->RateReplyDetails)) {
                 $response->RateReplyDetails = get_object_vars($response->RateReplyDetails);
             }
             //echo '<pre>';
             //print_r($response->RateReplyDetails);
             //echo '</pre>';
             switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
                 case 0:
                     $show_box_weight = '';
                     break;
                 case 1:
                     $show_box_weight = ' (' . $shippingNumBoxes . ' ' . TEXT_SHIPPING_BOXES . ')';
                     break;
                 case 2:
                     $show_box_weight = ' (' . number_format($shippingWeight * $shippingNumBoxes, 2) . tra('lbs') . ')';
                     break;
                 default:
                     $show_box_weight = ' (' . $shippingNumBoxes . ' x ' . number_format($shippingWeight, 2) . tra('lbs') . ')';
                     break;
             }
             $this->quotes = array('id' => $this->code, 'module' => $this->title, 'info' => $this->info(), 'weight' => $show_box_weight);
             $methods = array();
             foreach ($response->RateReplyDetails as $rateReply) {
                 if (array_key_exists($rateReply->ServiceType, $this->types) && (empty($pShipHash['method']) || str_replace('_', '', $rateReply->ServiceType) == $pShipHash['method'])) {
                     $cost = NULL;
                     if (MODULE_SHIPPING_FEDEX_WEB_SERVICES_RATES == 'LIST') {
                         foreach ($rateReply->RatedShipmentDetails as $ShipmentRateDetail) {
                             if ($ShipmentRateDetail->ShipmentRateDetail->RateType == 'PAYOR_LIST_PACKAGE') {
                                 $cost = $ShipmentRateDetail->ShipmentRateDetail->TotalNetCharge->Amount;
                                 $cost = (double) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                             }
                         }
                     } else {
                         $cost = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
                         $cost = (double) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                     }
                     $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType), 'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))), 'cost' => $cost + (strpos($this->types[$rateReply->ServiceType]['handling_fee'], '%') ? $cost * (double) $this->types[$rateReply->ServiceType]['handling_fee'] / 100 : (double) $this->types[$rateReply->ServiceType]['handling_fee']), 'code' => $this->types[$rateReply->ServiceType]['code']);
                 }
             }
             $this->quotes['methods'] = $methods;
             if ($this->tax_class > 0) {
                 $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['countries_id'], $order->delivery['zone_id']);
             }
         } else {
             $message = '';
             if (is_array($response->Notifications)) {
                 foreach ($response->Notifications as $notification) {
                     $message .= tra($notification->Severity) . ': ' . tra($notification->Message);
                 }
             } elseif (is_object($response->Notifications)) {
                 $message .= tra($response->Notifications->Severity) . ': ' . tra($response->Notifications->Message);
             }
         }
     } catch (Exception $e) {
         $message = $e->getMessage();
     }
     if (!empty($message)) {
         $this->quotes = array('module' => $this->title, 'error' => $message);
     }
     if (!empty($this->icon)) {
         $this->quotes['icon'] = $this->icon;
     }
     return $this->quotes;
 }
Exemple #6
0
 /**
  * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
  * This sends the data to the payment gateway for processing.
  * (These are hidden fields on the checkout confirmation page)
  *
  * @return string
  */
 function process_button()
 {
     global $db, $order, $currencies, $currency;
     $options = array();
     $optionsCore = array();
     $optionsPhone = array();
     $optionsShip = array();
     $optionsLineItems = array();
     $optionsAggregate = array();
     $optionsTrans = array();
     $buttonArray = array();
     // save the session stuff permanently in case paypal loses the session
     $_SESSION['ppipn_key_to_remove'] = session_id();
     $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'");
     $sql = "insert into " . TABLE_PAYPAL_SESSION . " (session_id, saved_session, expiry) values (\n            '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "',\n            '" . base64_encode(serialize($_SESSION)) . "',\n            '" . (time() + 1 * 60 * 60 * 24 * 2) . "')";
     $db->Execute($sql);
     $my_currency = select_pp_currency();
     $this->transaction_currency = $my_currency;
     $this->totalsum = $order->info['total'] = zen_round($order->info['total'], 2);
     $this->transaction_amount = zen_round($this->totalsum * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
     $telephone = preg_replace('/\\D/', '', $order->customer['telephone']);
     if ($telephone != '') {
         $optionsPhone['H_PhoneNumber'] = $telephone;
         if (in_array($order->customer['country']['iso_code_2'], array('US', 'CA'))) {
             $optionsPhone['night_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['night_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['night_phone_c'] = substr($telephone, 6, 4);
             $optionsPhone['day_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['day_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['day_phone_c'] = substr($telephone, 6, 4);
         } else {
             $optionsPhone['night_phone_b'] = $telephone;
             $optionsPhone['day_phone_b'] = $telephone;
         }
     }
     $optionsCore = array('lc' => $this->getLanguageCode(), 'charset' => CHARSET, 'page_style' => MODULE_PAYMENT_PAYPAL_PAGE_STYLE, 'custom' => zen_session_name() . '=' . zen_session_id(), 'business' => MODULE_PAYMENT_PAYPAL_BUSINESS_ID, 'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL'), 'cancel_return' => zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'), 'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'), 'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL', false, false, true), 'redirect_cmd' => '_xclick', 'rm' => 2, 'bn' => 'CNZcart_Cart_EC', 'mrb' => 'R-4DM17246PS436904F', 'pal' => 'GR5QUVVL9AFGN');
     $optionsCust = array('first_name' => replace_accents($order->customer['firstname']), 'last_name' => replace_accents($order->customer['lastname']), 'address1' => replace_accents($order->customer['street_address']), 'city' => replace_accents($order->customer['city']), 'state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['state']), 'zip' => $order->customer['postcode'], 'country' => $order->customer['country']['iso_code_2'], 'email' => $order->customer['email_address']);
     // address line 2 is optional
     if ($order->customer['suburb'] != '') {
         $optionsCust['address2'] = $order->customer['suburb'];
     }
     // different format for Japanese address layout:
     if ($order->customer['country']['iso_code_2'] == 'JP') {
         $optionsCust['zip'] = substr($order->customer['postcode'], 0, 3) . '-' . substr($order->customer['postcode'], 3);
     }
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED == 2) {
         $optionsCust = array('first_name' => replace_accents($order->delivery['firstname'] != '' ? $order->delivery['firstname'] : $order->billing['firstname']), 'last_name' => replace_accents($order->delivery['lastname'] != '' ? $order->delivery['lastname'] : $order->billing['lastname']), 'address1' => replace_accents($order->delivery['street_address'] != '' ? $order->delivery['street_address'] : $order->billing['street_address']), 'city' => replace_accents($order->delivery['city'] != '' ? $order->delivery['city'] : $order->billing['city']), 'state' => $order->delivery['country']['id'] != '' ? zen_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']) : zen_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], $order->billing['state']), 'zip' => $order->delivery['postcode'] != '' ? $order->delivery['postcode'] : $order->billing['postcode'], 'country' => $order->delivery['country']['title'] != '' ? $order->delivery['country']['title'] : $order->billing['country']['title'], 'country_code' => $order->delivery['country']['iso_code_2'] != '' ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2'], 'email' => $order->customer['email_address']);
         if ($order->delivery['suburb'] != '') {
             $optionsCust['address2'] = $order->delivery['suburb'];
         }
         if ($order->delivery['country']['iso_code_2'] == 'JP') {
             $optionsCust['zip'] = substr($order->delivery['postcode'], 0, 3) . '-' . substr($order->delivery['postcode'], 3);
         }
     }
     $optionsShip['no_shipping'] = MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED;
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE == '1') {
         $optionsShip['address_override'] = MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE;
     }
     // prepare cart contents details where possible
     if (MODULE_PAYMENT_PAYPAL_DETAILED_CART == 'Yes') {
         $optionsLineItems = ipn_getLineItemDetails($my_currency);
     }
     if (sizeof($optionsLineItems) > 0) {
         $optionsLineItems['cmd'] = '_cart';
         // $optionsLineItems['num_cart_items'] = sizeof($order->products);
         if (isset($optionsLineItems['shipping'])) {
             $optionsLineItems['shipping_1'] = $optionsLineItems['shipping'];
             unset($optionsLineItems['shipping']);
         }
         unset($optionsLineItems['subtotal']);
         // if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode
         if (!isset($optionsLineItems['item_name_1']) || $optionsLineItems['creditsExist'] == TRUE) {
             $optionsLineItems = array();
         }
         // if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array();
         // debug:
         // ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch or credits applied, and thus bypassed): ' . "\n" . print_r($optionsLineItems, true));
         unset($optionsLineItems['creditsExist']);
     }
     $optionsAggregate = array('cmd' => '_ext-enter', 'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE, 'item_number' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_ITEMNUM, 'amount' => number_format($this->transaction_amount, $currencies->get_decimal_places($my_currency)), 'shipping' => '0.00');
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax'] = '0.00';
     }
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax_cart'] = '0.00';
     }
     $optionsTrans = array('upload' => (int) (sizeof($order->products) > 0), 'currency_code' => $my_currency);
     // if line-item info is invalid, use aggregate:
     if (sizeof($optionsLineItems) > 0) {
         $optionsAggregate = $optionsLineItems;
     }
     if (defined('MODULE_PAYMENT_PAYPAL_LOGO_IMAGE')) {
         $optionsCore['cpp_logo_image'] = urlencode(MODULE_PAYMENT_LOGO_IMAGE);
     }
     if (defined('MODULE_PAYMENT_PAYPAL_CART_BORDER_COLOR')) {
         $optionsCore['cpp_cart_border_color'] = MODULE_PAYMENT_PAYPAL_CART_BORDER_COLOR;
     }
     // prepare submission
     $options = array_merge($optionsCore, $optionsCust, $optionsPhone, $optionsShip, $optionsTrans, $optionsAggregate);
     // ipn_debug_email('Keys for submission: ' . print_r($options, true));
     // build the button fields
     foreach ($options as $name => $value) {
         // remove quotation marks
         $value = str_replace('"', '', $value);
         // check for invalid chars
         if (preg_match('/[^a-zA-Z_0-9]/', $name)) {
             ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')');
             break;
         }
         // do we need special handling for & and = symbols?
         // if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);
         $buttonArray[] = zen_draw_hidden_field($name, $value);
     }
     $process_button_string = "\n" . implode("\n", $buttonArray) . "\n";
     $_SESSION['paypal_transaction_info'] = array($this->transaction_amount, $this->transaction_currency);
     return $process_button_string;
 }
function zen_address_format($address_format_id, $address, $html, $boln, $eoln)
{
    global $db;
    $address_format = $db->Execute("select address_format as format\n                             from " . TABLE_ADDRESS_FORMAT . "\n                             where address_format_id = '" . (int) $address_format_id . "'");
    $company = zen_output_string_protected($address['company']);
    if (isset($address['firstname']) && zen_not_null($address['firstname'])) {
        $firstname = zen_output_string_protected($address['firstname']);
        $lastname = zen_output_string_protected($address['lastname']);
    } elseif (isset($address['name']) && zen_not_null($address['name'])) {
        $firstname = zen_output_string_protected($address['name']);
        $lastname = '';
    } else {
        $firstname = '';
        $lastname = '';
    }
    $street = zen_output_string_protected($address['street_address']);
    $suburb = zen_output_string_protected($address['suburb']);
    $city = zen_output_string_protected($address['city']);
    $state = zen_output_string_protected($address['state']);
    $telephone = zen_output_string_protected($address['telephone']);
    $fax = zen_output_string_protected($address['fax']);
    if (isset($address['country_id']) && zen_not_null($address['country_id'])) {
        $country = zen_get_country_name($address['country_id']);
        if (isset($address['zone_id']) && zen_not_null($address['zone_id'])) {
            $state = zen_get_zone_code($address['country_id'], $address['zone_id'], $state);
        }
    } elseif (isset($address['country']) && zen_not_null($address['country'])) {
        $country = zen_output_string_protected($address['country']);
    } else {
        $country = '';
    }
    $postcode = zen_output_string_protected($address['postcode']);
    $zip = $postcode;
    if ($html) {
        // HTML Mode
        $HR = '<hr>';
        $hr = '<hr>';
        if ($boln == '' && $eoln == "\n") {
            // Values not specified, use rational defaults
            $CR = '<br>';
            $cr = '<br>';
            $eoln = $cr;
        } else {
            // Use values supplied
            $CR = $eoln . $boln;
            $cr = $CR;
        }
    } else {
        // Text Mode
        $CR = $eoln;
        $cr = $CR;
        $HR = '----------------------------------------';
        $hr = '----------------------------------------';
    }
    $statecomma = '';
    $streets = $street;
    $state = zen_convert_to_zone_name_m17n($state) . ' ';
    if ($suburb != '') {
        $streets = $street . $cr . $suburb;
    }
    if ($country == '') {
        $country = zen_output_string_protected($address['country']);
    }
    if ($state != '') {
        $statecomma = $state . ', ';
    }
    if ($telephone != '') {
        $telephone = ENTRY_TELEPHONE_NUMBER . $telephone;
    }
    if ($fax != '') {
        $fax = ENTRY_FAX_NUMBER . $fax;
    }
    $fmt = $address_format->fields['format'];
    eval("\$address = \"{$fmt}\";");
    if (ACCOUNT_COMPANY == 'true' && zen_not_null($company)) {
        $address = $company . $cr . $address;
    }
    return $address;
}
Exemple #8
0
 function process_button()
 {
     global $db, $order, $currencies, $order_totals;
     $extend_param = '';
     $extend_param .= 'SHIP_TO_FIRSTNAME^' . ($order->customer['firstname'] == '' ? 'none' : $order->customer['firstname']);
     $extend_param .= '|SHIP_TO_LASTNAME^' . ($order->customer['lastname'] == '' ? 'none' : $order->customer['lastname']);
     $extend_param .= '|SHIP_TO_POSTALCODE^' . ($order->customer['postcode'] == '' ? '0' : $order->customer['postcode']);
     //---------------
     //$extend_param .='|JS_RETURN^'."<script type='text/javascript' src='http://irds.alipay.com/merchant/merchant.js'></script>";
     //---------------
     $extend_param .= '|SHIP_TO_PHONENUMBER^' . preg_replace('/\\D/', '', $order->customer['telephone']);
     $extend_param .= '|SHIP_TO_STREET1^' . ($order->customer['street_address'] == '' ? 'none' : $order->customer['street_address']);
     $extend_param .= '|SHIP_TO_CITY^' . ($order->customer['city'] == '' ? 'none' : $order->customer['city']);
     $extend_param .= '|SHIP_TO_STATE^' . zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['state']);
     //$extend_param .='|SHIP_TO_STATE^US-AL'; //vincent test,hard code
     $extend_param .= '|SHIP_TO_COUNTRY^' . $order->customer['country']['iso_code_2'];
     //$extend_param .='|SHIP_TO_COUNTRY^US'; //vincent test,hard code
     $extend_param .= '|SHIP_TO_SHIPMETHOD^EMS';
     $extend_param .= '|LOGISTICS_COST^0.00';
     $extend_param .= '|REGISTRATION_NAME^' . $order->customer['firstname'] . $order->customer['lastname'];
     $extend_param .= '|REGISTRATION_EMAIL^' . ($order->customer['email_address'] == '' ? 'none' : $order->customer['email_address']);
     $extend_param .= '|REGISTRATION_PHONE^' . preg_replace('/\\D/', '', $order->customer['telephone'] == '' ? 'none' : $order->customer['telephone']);
     $alipay_body = '';
     for ($i = 0; $i < sizeof($order->products); $i++) {
         $alipay_body = $order->products[$i]["name"] . "+" . $alipay_body;
     }
     $alipay_body = substr($alipay_body, 0, -1);
     if (strlen($alipay_body) < 250) {
         $alipay_body = substr($alipay_body, 0, strlen($alipay_body));
     } else {
         $alipay_body = substr($alipay_body, 250);
     }
     $alipay_body = str_replace(PHP_EOL, ' ', $alipay_body);
     $order->info['payment_method'] = MODULE_PAYMENT_ALIPAY_TEXT_CATALOG_TITLE;
     $order->info['payment_module_code'] = 'alipay';
     $insert_id = '';
     if (!isset($_SESSION['alipay_insert_id'])) {
         $insert_id = $order->create($order_totals, 2);
         $order->create_add_products($insert_id);
         $_SESSION['alipay_insert_id'] = $insert_id;
         $_SESSION['alipay_body'] = $alipay_body;
         $_SESSION['alipay_fee'] = $order->info['total'];
     } else {
         if ($_SESSION['alipay_body'] == $alipay_body && $_SESSION['alipay_fee'] == $order->info['total']) {
             $insert_id = $_SESSION['alipay_insert_id'];
         } else {
             $insert_id = $order->create($order_totals, 2);
             $order->create_add_products($insert_id);
             $_SESSION['alipay_insert_id'] = $insert_id;
             $_SESSION['alipay_body'] = $alipay_body;
             $_SESSION['alipay_fee'] = $order->info['total'];
         }
     }
     $order->info['payment_method'] = null;
     $order->info['payment_module_code'] = null;
     $extend_param .= '|product_name^' . $alipay_body;
     $extend_param = str_replace(PHP_EOL, ' ', $extend_param);
     $parameter = array('service' => 'alipay.trade.direct.forcard.pay', 'default_bank' => $_POST['alicardtype'], 'currency' => $order->info['currency'], 'extend_param' => $extend_param, '_input_charset' => 'utf-8', 'partner' => MODULE_PAYMENT_ALIPAY_PARTNER, 'seller_id' => MODULE_PAYMENT_ALIPAY_SELLER, 'return_url' => zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL'), 'notify_url' => zen_href_link('alipay_notify.php', '', 'SSL', false, false, true), "show_url" => zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'), 'out_trade_no' => $insert_id, 'subject' => 'order #' . $insert_id . ' from ' . STORE_NAME, 'body' => $alipay_body, "total_fee" => number_format($order->info['total'] * $currencies->get_value($order->info['currency']), '2', '.', ''));
     if ($_POST['alicardtype'] == 'boc-jcb') {
         unset($parameter['currency']);
         $value_cny = $currencies->get_value('CNY');
         if ($value_cny == 0) {
             $parameter['total_fee'] = '0.00';
         } else {
             $parameter['total_fee'] = number_format($order->info['total'] * $value_cny, '2', '.', '');
         }
     }
     $security_code = MODULE_PAYMENT_ALIPAY_MD5KEY;
     $mysign = $this->sign($parameter, $security_code);
     $fields = $this->arg_sort($parameter);
     $fields['sign_type'] = 'MD5';
     $fields['sign'] = $mysign;
     $process_button_string = '';
     while (list($key, $val) = each($fields)) {
         $process_button_string .= zen_draw_hidden_field($key, $val);
     }
     return $process_button_string;
 }
Exemple #9
0
 function quote()
 {
     global $shipping_weight, $shipping_num_boxes;
     global $order;
     global $a_sagawaex_time;
     global $cart;
     global $db;
     $this->quotes = array('id' => $this->code, 'module' => $this->title);
     if (zen_not_null($this->icon)) {
         $this->quotes['icon'] = zen_image($this->icon, $this->title);
     }
     $country_id = $order->delivery['country']['id'];
     $zone_id = $order->delivery['zone_id'];
     if (in_array($country_id, $this->sagawaex_countries_nbr)) {
         $zoneinfo = $db->Execute("SELECT zone_code FROM " . TABLE_ZONES . " WHERE zone_id = '" . $zone_id . "'");
         $a_zonevalues = $zoneinfo->fields;
         $s_zone_code = $a_zonevalues['zone_code'];
         // 送料が条件によって無料になってしまう(ここではtotalではなくsubtotalを確認すべき)
         if (MODULE_SHIPPING_SAGAWAEX_FREE_SHIPPING != 'True' || (int) $order->info['subtotal'] < (int) MODULE_SHIPPING_SAGAWAEX_OVER) {
             include DIR_WS_CLASSES . '_sagawaex.php';
             $rate = new _SagawaEx($this->code, MODULE_SHIPPING_SAGAWAEX_TEXT_WAY_NORMAL, zen_get_zone_code(STORE_COUNTRY, STORE_ZONE, 0), STORE_COUNTRY);
             //STORE_ORIGIN_ZONE, STORE_ORIGIN_COUNTRY);
             $rate->SetDest($s_zone_code, $this->sagawaex_countries[$country_id]);
             $rate->SetWeight($shipping_weight);
             $tmpQuote = $rate->GetQuote();
             // id, title, cost | error
             if (isset($tmpQuote['error'])) {
                 $this->quotes['error'] = $tmpQuote['error'];
             } else {
                 $this->quotes['module'] = $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'kg)';
                 $tmpQuote['cost'] *= $shipping_num_boxes;
                 // 送料ディスカウント
                 if (defined('MODULE_SHIPPING_SAGAWAEX_DISCOUNT') && 0 < (int) MODULE_SHIPPING_SAGAWAEX_DISCOUNT) {
                     $tmpQuote['cost'] -= (int) ($tmpQuote['cost'] * MODULE_SHIPPING_SAGAWAEX_DISCOUNT / 100);
                 }
                 // 手数料
                 $tmpQuote['cost'] += MODULE_SHIPPING_SAGAWAEX_HANDLING;
             }
         } else {
             $tmpQuote = array('id' => $this->code, 'title' => MODULE_SHIPPING_SAGAWAEX_TEXT_WAY_NORMAL, 'cost' => 0);
         }
         if (!isset($tmpQuote['error'])) {
             // 配送時刻指定
             $timespec = $this->get_timespec();
             $tmpQuote['option'] = TEXT_TIME_SPECIFY . zen_draw_pull_down_menu('sagawaex_timespec', $a_sagawaex_time, $timespec);
             $tmpQuote['timespec'] = $timespec;
         }
         $this->quotes['methods'][] = $tmpQuote;
         if ($this->tax_class > 0) {
             $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $country_id, $zone_id);
         }
     } else {
         $this->quotes['error'] = MODULE_SHIPPING_SAGAWAEX_TEXT_NOTAVAILABLE;
     }
     return $this->quotes;
 }
Exemple #10
0
function zen_address_format($address_format_id, $address, $html, $boln, $eoln)
{
    global $gBitDb;
    $address_format_query = "select `address_format` as `format`\n                             from " . TABLE_ADDRESS_FORMAT . "\n                             where `address_format_id` = '" . (int) $address_format_id . "'";
    $address_format = $gBitDb->query($address_format_query);
    $company = zen_output_string_protected($address['company']);
    if (!empty($address['firstname'])) {
        $firstname = zen_output_string_protected($address['firstname']);
        $lastname = zen_output_string_protected($address['lastname']);
    } elseif (!empty($address['name'])) {
        $firstname = zen_output_string_protected($address['name']);
        $lastname = '';
    } else {
        $firstname = '';
        $lastname = '';
    }
    $street = zen_output_string_protected($address['street_address']);
    $suburb = zen_output_string_protected($address['suburb']);
    $city = zen_output_string_protected($address['city']);
    $state = zen_output_string_protected($address['state']);
    $telephone = isset($address['telephone']) ? zen_output_string_protected($address['telephone']) : NULL;
    if (!empty($address['country_id'])) {
        $country = zen_get_country_name($address['country_id']);
        if (!empty($address['zone_id'])) {
            $state = zen_get_zone_code($address['country_id'], $address['zone_id'], $state);
        }
    } elseif (!empty($address['country'])) {
        if (is_array($address['country'])) {
            $country = zen_output_string_protected($address['country']['countries_name']);
        } else {
            $country = zen_output_string_protected($address['country']);
        }
    } else {
        $country = '';
    }
    $postcode = zen_output_string_protected($address['postcode']);
    $zip = $postcode;
    if ($html) {
        // HTML Mode
        $HR = '<hr />';
        $hr = '<hr />';
        if (empty($boln) && $eoln == "\n") {
            // Values not specified, use rational defaults
            $CR = '<br />';
            $cr = '<br />';
            $eoln = $cr;
        } else {
            // Use values supplied
            $CR = $eoln . $boln;
            $cr = $CR;
        }
    } else {
        // Text Mode
        $CR = $eoln;
        $cr = $CR;
        $HR = '----------------------------------------';
        $hr = '----------------------------------------';
    }
    $statecomma = '';
    $streets = $street;
    if ($suburb != '') {
        $streets = $street . $cr . $suburb;
    }
    if (empty($country)) {
        if (is_array($address['country'])) {
            $country = zen_output_string_protected($address['country']['countries_name']);
        } else {
            $country = zen_output_string_protected($address['country']);
        }
    }
    if ($state != '') {
        $statecomma = $state . ', ';
    }
    $fmt = $address_format->fields['format'];
    eval("\$address_out = \"{$fmt}\";");
    if (!empty($telephone)) {
        $address_out .= $cr . $telephone;
    }
    if (ACCOUNT_COMPANY == 'true' && zen_not_null($company)) {
        $address_out = $company . $cr . $address_out;
    }
    return $address_out;
}
Exemple #11
0
 /**
  * Get quote from shipping provider's API:
  *
  * @param string $method
  * @return array of quotation results
  */
 function quote($pShipHash = array())
 {
     global $order, $handling_cp;
     $shippingWeight = !empty($pShipHash['shipping_weight']) && $pShipHash['shipping_weight'] > 0.1 ? $pShipHash['shipping_weight'] : 0.1;
     $shippingNumBoxes = !empty($pShipHash['shipping_num_boxes']) ? $pShipHash['shipping_num_boxes'] : 1;
     // will round to 2 decimals 9.112 becomes 9.11 thus a product can be 0.1 of a KG
     $shippingWeight = round($shippingWeight, 2);
     $ret = array();
     if ($shippingWeight < MODULE_SHIPPING_PUROLATOR_MAXWEIGHT) {
         $ret = array('id' => $this->code, 'module' => $this->title, 'icon' => $this->icon);
         $country_name = zen_get_countries(STORE_COUNTRY, true);
         $this->_purolatorOrigin(SHIPPING_ORIGIN_ZIP, $country_name['countries_iso_code_2']);
         if (strlen($order->delivery['state']) > 2 && $order->delivery['zone_id'] > 0) {
             $state_name = zen_get_zone_code($order->delivery['country_id'], $order->delivery['zone_id'], '');
             $order->delivery['state'] = $state_name;
         }
         $this->_purolatorDest($order->delivery['city'], $order->delivery['state'], $order->delivery['country']['countries_iso_code_2'], $order->delivery['postcode']);
         /** Purpose : Creates a SOAP Client in Non-WSDL mode with the appropriate authentication and
          *		   header information
          * */
         require_once dirname(__FILE__) . '/nusoap/nusoap.php';
         //Set the parameters for the Non-WSDL mode SOAP communication with your Development/Production credentials
         $this->client = new nusoap_client(HTTP_SERVER . "/EstimatingService.wsdl", 'wsdl');
         $this->client->setCredentials($this->key, $this->pass, 'basic');
         //if($this->client->getError()) echo '<!--Auth Error: '.$this->client->getError().'-->'; //commented, used to test for authorisation errors
         //Define the SOAP Envelope Headers
         $handheader = '<ns1:RequestContext xmlns:ns1="' . $this->uri . '"><ns1:Version>1.0</ns1:Version><ns1:Language>' . $this->language . '</ns1:Language><ns1:GroupID>xxx</ns1:GroupID><ns1:RequestReference>Rating Example</ns1:RequestReference></ns1:RequestContext>';
         //Apply the SOAP Header to your client
         $this->client->setHeaders($handheader);
         //if($this->client->getError()) echo PHP_EOL.'<!--Header Error: '.$this->client->getError().'-->'. PHP_EOL;  //commented, used to test for header errors
         $params = array("BillingAccountNumber" => $this->acct_num, "SenderPostalCode" => $this->_purolatorOriginPostalCode, "ReceiverAddress" => array("City" => '', "Province" => $this->dest_province, "Country" => $this->dest_country, "PostalCode" => $this->dest_zip), "PackageType" => $this->packaging, "TotalWeight" => array("Value" => $shippingWeight, "WeightUnit" => "lb"));
         //Execute the request and capture the response
         $this->response = $this->client->call('GetQuickEstimate', array('GetQuickEstimateRequest' => $params));
         //  echo PHP_EOL.'<!--'; print_r($params); echo '-->'. PHP_EOL; // for testing. Prints out the entire send in a comment.
         //start error checkin module (ya, I know it's overkill)
         /*
          if ($this->client->fault) {
          echo '<!--Fault: ';
          print_r($result);
          echo '-->';
          } else {
          // Check for errors
          $err = $this->client->getError();
          if ($err) {
          // Display the error
          echo '<!--Error: ' . $err . '-->';
          } else {
          //Success! Display the result
          echo PHP_EOL.'<!--Success: ';
          print_r($this->response);
          echo '-->'. PHP_EOL;
          }
          }
          if($this->client->getError()) {
          echo '<!-- Debug:';
          print_r($this->client->getDebug());
          echo '-->';
          }
         */
         // end error checking module
         if (!$this->client->fault && ($purolatorQuote = $this->_parserResult($this->response))) {
             $ret['weight'] = $shippingWeight . ' Lb / ' . round($shippingWeight / 2.2) . ' Kg';
             $methods = array();
             for ($i = 0; $i < sizeof($purolatorQuote); $i++) {
                 list($type, $cost) = each($purolatorQuote[$i]);
                 $type = html_entity_decode($type);
                 if ($method == '' || $method == $type) {
                     $methods[] = array('id' => $type, 'title' => $type, 'cost' => MODULE_SHIPPING_PUROLATOR_HANDLING + $cost);
                 }
             }
             if ($this->tax_class > 0) {
                 $ret['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             }
             $ret['methods'] = $methods;
         } else {
             $errmsg = tra('An unknown error occured with the Purolator shipping calculations.');
         }
         $errmsg .= ' ' . tra('If you prefer to use Canada Post as your shipping method, please <a href="mailto:' . STORE_OWNER_EMAIL_ADDRESS . '">send us an email</a>.');
         $ret['error'] = $errmsg;
     }
     return $ret;
 }
Exemple #12
0
 /**
  * Get quote from shipping provider's API:
  *
  * @param string $method
  * @return array of quotation results
  */
 function quote($pShipHash = array())
 {
     global $order, $total_weight, $boxcount, $handling_cp;
     $shippingWeight = !empty($pShipHash['shipping_weight']) && $pShipHash['shipping_weight'] > 0.1 ? $pShipHash['shipping_weight'] : 0.1;
     $shippingNumBoxes = !empty($pShipHash['shipping_num_boxes']) ? $pShipHash['shipping_num_boxes'] : 1;
     // will round to 2 decimals 9.112 becomes 9.11 thus a product can be 0.1 of a KG
     $shippingWeight = round($shippingWeight, 2);
     $country_name = zen_get_countries(STORE_COUNTRY, true);
     $this->_canadapostOrigin(SHIPPING_ORIGIN_ZIP, $country_name['countries_iso_code_2']);
     if (!zen_not_null($order->delivery['state']) && $order->delivery['zone_id'] > 0) {
         $state_name = zen_get_zone_code($order->delivery['country_id'], $order->delivery['zone_id'], '');
         $order->delivery['state'] = $state_name;
     }
     $strXml = '<?xml version="1.0" ?>';
     // set package configuration.
     $strXml .= "<eparcel>\n";
     $strXml .= "\t<language>" . $this->language . "</language>\n";
     $strXml .= "\t<ratesAndServicesRequest>\n";
     $strXml .= "\t\t<merchantCPCID>" . $this->CPCID . "</merchantCPCID>\n";
     $strXml .= "\t\t<fromPostalCode>" . $this->_canadapostOriginPostalCode . "</fromPostalCode>\n";
     $strXml .= "\t\t<turnAroundTime>" . $this->turnaround_time . "</turnAroundTime>\n";
     $strXml .= "\t\t<itemsPrice>" . (string) $this->items_price . "</itemsPrice>\n";
     // add items information.
     $itemXml = '';
     for ($i = 0; $i < $pShipHash['shipping_num_boxes']; $i++) {
         $itemXml .= "\t<item>\n";
         $itemXml .= "\t\t<quantity>1</quantity>\n";
         $itemXml .= "\t\t<weight>" . $shippingWeight / $shippingNumBoxes . "</weight>\n";
         /*
         			if ($this->item_dim_type[$i] == 'in') //convert to centimeters
         			{
         				$itemXml .= "		<length>" . ($this->item_length[$i] * (254 / 100)) . "</length>\n";
         				$itemXml .= "		<width>" . ($this->item_width[$i] * (254 / 100)) . "</width>\n";
         				$itemXml .= "		<height>" . ($this->item_height[$i] * (254 / 100)) . "</height>\n";
         			} else {
         */
         $itemXml .= "\t\t<length>5</length>\n";
         $itemXml .= "\t\t<width>5</width>\n";
         $itemXml .= "\t\t<height>5</height>\n";
         //			}
         $itemXml .= "\t\t<description>Goods</description>\n";
         // Not sure what this means at the moment
         //			if ($this->item_ready_to_ship[$i] == '1') {
         //				$itemXml .= "		<readyToShip/>\n";
         //			}
         $itemXml .= "\t</item>\n";
     }
     if ($itemXml) {
         $strXml .= "\t<lineItems>\n" . $itemXml . "\n\t</lineItems>\n";
     }
     // add destination information.
     $strXml .= "\t <city>" . $order->delivery['city'] . "</city>\n";
     $strXml .= "\t <provOrState>" . $order->delivery['state'] . "</provOrState>\n";
     $strXml .= "\t <country>" . $order->delivery['country']['countries_iso_code_2'] . "</country>\n";
     $strXml .= "\t <postalCode>" . str_replace(' ', '', $order->delivery['postcode']) . "</postalCode>\n";
     $strXml .= "\t</ratesAndServicesRequest>\n";
     $strXml .= "</eparcel>\n";
     $ret = array('id' => $this->code, 'module' => $this->title, 'icon' => $this->icon);
     //printf("\n\n<!--\n%s\n-->\n\n",$strXml); //debug xml
     $resultXml = $this->_sendToHost($this->server, $this->port, 'POST', '', $strXml);
     if ($resultXml && ($canadapostQuote = $this->_parserResult($resultXml))) {
         if ($this->lettermail_available && $shippingWeight <= $this->lettermail_max_weight) {
             /* Select the correct rate table based on destination country */
             switch ($order->delivery['country']['iso_code_2']) {
                 case 'CA':
                     $table_cost = preg_split("/[:,]/", constant('MODULE_SHIPPING_CANADAPOST_LETTERMAIL_CAN'));
                     $lettermailName = "Lettermail";
                     $lettermailDelivery = sprintf("estimated %d-%d business days", round($this->turnaround_time / 24 + 2), round($this->turnaround_time / 24 + 4));
                     //factor in turnaround time
                     break;
                 case 'US':
                     $table_cost = preg_split("/[:,]/", constant('MODULE_SHIPPING_CANADAPOST_LETTERMAIL_USA'));
                     $lettermailName = "U.S.A Letter-post";
                     $lettermailDelivery = "up to 2 weeks";
                     break;
                 default:
                     $table_cost = preg_split("/[:,]/", constant('MODULE_SHIPPING_CANADAPOST_LETTERMAIL_INTL'));
                     //Use overseas rate if not Canada or US
                     $lettermailName = "INTL Letter-post";
                     $lettermailDelivery = "up to 2 weeks";
             }
             for ($i = 0; $i < sizeof($table_cost); $i += 2) {
                 if (round($shippingWeight, 3) <= $table_cost[$i]) {
                     $lettermailCost = $table_cost[$i + 1];
                     break;
                 }
             }
             if (!empty($lettermailCost)) {
                 $canadapostQuote[] = array('name' => $lettermailName, 'cost' => $lettermailCost, 'delivery' => $lettermailDelivery);
             }
         }
         if (!empty($canadapostQuote) && is_array($canadapostQuote)) {
             $methods = array();
             foreach ($canadapostQuote as $quoteCode => $quote) {
                 if (empty($pShipHash['method']) || $quoteCode == $pShipHash['method']) {
                     $method = array('id' => $quote['code'], 'code' => $quote['code'], 'title' => $quote['name'], 'delivery' => $quote['delivery'], 'cost' => $quote['cost']);
                     if ($this->cp_online_handling == true) {
                         $method['cost'] += $this->handling_cp;
                     } else {
                         $method['cost'] += (double) MODULE_SHIPPING_CANADAPOST_SHIPPING_HANDLING;
                     }
                     $methods[] = $method;
                 }
             }
             if ($this->tax_class > 0) {
                 $ret['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             }
             $ret['methods'] = $methods;
         } else {
             $errmsg = $canadapostQuote;
         }
     } else {
         $errmsg = tra('There was no response from the Canada Post shipping estimate server.');
     }
     if (!empty($errmsg)) {
         $errmsg .= ' ' . tra('If you prefer to use Canada Post as your shipping method, please contact <strong><a href="mailto:' . STORE_OWNER_EMAIL_ADDRESS . '">send us an email</a></strong>.');
         $ret['error'] = $errmsg;
     }
     return $ret;
 }
Exemple #13
0
 /**
  * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
  * This sends the data to the payment gateway for processing.
  * (These are hidden fields on the checkout confirmation page)
  *
  * @return string
  */
 function process_button()
 {
     global $db, $order, $currencies, $currency;
     $options = array();
     $optionsCore = array();
     $optionsPhone = array();
     $optionsShip = array();
     $optionsLineItems = array();
     $optionsAggregate = array();
     $optionsTrans = array();
     $buttonArray = array();
     //$_SESSION['coupons']['price']   $ot_coupon->deduction
     $this->totalsum = $order->info['total'] - $_SESSION['coupons']['price'];
     // save the session stuff permanently in case paypal loses the session
     $_SESSION['ppipn_key_to_remove'] = session_id();
     $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'");
     $sql = "insert into " . TABLE_PAYPAL_SESSION . " (session_id, saved_session, expiry) values (\n            '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "',\n            '" . base64_encode(serialize($_SESSION)) . "',\n            '" . (time() + 1 * 60 * 60 * 24 * 2) . "')";
     $db->Execute($sql);
     $my_currency = select_pp_currency();
     $this->transaction_currency = $my_currency;
     $this->transaction_amount = $this->totalsum * $currencies->get_value($my_currency);
     $this->subtotal = $order->info['subtotal'] * $currencies->get_value($my_currency) - $_SESSION['coupons']['price'];
     $this->shipping_cost = $order->info['shipping_cost'];
     // * $currencies->get_value($my_currency)
     //$this->shipping_cost = ($this->transaction_amount - $this->subtotal);
     $telephone = preg_replace('/\\D/', '', $order->customer['telephone']);
     if ($telephone != '') {
         $optionsPhone['H_PhoneNumber'] = $telephone;
         if (in_array($order->customer['country']['iso_code_2'], array('US', 'CA'))) {
             $optionsPhone['night_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['night_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['night_phone_c'] = substr($telephone, 6, 4);
             $optionsPhone['day_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['day_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['day_phone_c'] = substr($telephone, 6, 4);
         } else {
             $optionsPhone['night_phone_b'] = $telephone;
             $optionsPhone['day_phone_b'] = $telephone;
         }
     }
     $optionsCore = array('charset' => CHARSET, 'lc' => $order->customer['country']['iso_code_2'], 'page_style' => MODULE_PAYMENT_PAYPAL_PAGE_STYLE, 'custom' => zen_session_name() . '=' . zen_session_id(), 'business' => MODULE_PAYMENT_PAYPAL_BUSINESS_ID, 'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL'), 'cancel_return' => zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'), 'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL', false, false, true), 'redirect_cmd' => '_xclick', 'rm' => 2, 'bn' => 'Zhongtuo_Cart_EC_C2', 'mrb' => 'R-4DM17246PS436904F', 'pal' => 'GR5QUVVL9AFGN', 'os1' => $_SESSION['paypal_product_id']);
     $optionsCust = array('first_name' => replace_accents($order->customer['firstname']), 'last_name' => replace_accents($order->customer['lastname']), 'address1' => replace_accents($order->customer['street_address']), 'city' => replace_accents($order->customer['city']), 'state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['zone_id']), 'zip' => $order->customer['postcode'], 'country' => $order->customer['country']['iso_code_2'], 'email' => $order->customer['email_address']);
     if ($order->customer['suburb'] != '') {
         $optionsCust['address2'] = $order->customer['suburb'];
     }
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED == 2) {
         $optionsCust = array('address_name' => replace_accents($order->customer['firstname'] . ' ' . $order->customer['lastname']), 'address_street' => replace_accents($order->customer['street_address']), 'address_city' => replace_accents($order->customer['city']), 'address_state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['zone_id']), 'address_zip' => $order->customer['postcode'], 'address_country' => $order->customer['country']['title'], 'address_country_code' => $order->customer['country']['iso_code_2'], 'payer_email' => $order->customer['email_address']);
     }
     $optionsShip = array('no_shipping' => 0);
     if (MODULE_PAYMENT_PAYPAL_DETAILED_CART == 'Yes') {
         $optionsLineItems = ipn_getLineItemDetails();
     }
     if (sizeof($optionsLineItems) > 0) {
         $optionsLineItems['cmd'] = '_cart';
         //      $optionsLineItems['num_cart_items'] = sizeof($order->products);
         if (isset($optionsLineItems['shipping'])) {
             $optionsLineItems['shipping_1'] = $optionsLineItems['shipping'];
             unset($optionsLineItems['shipping']);
         }
         if (isset($optionsLineItems['handling'])) {
             $optionsLineItems['handling_1'] = $optionsLineItems['handling'];
             unset($optionsLineItems['handling']);
         }
         unset($optionsLineItems['subtotal']);
         // if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode
         if (!isset($optionsLineItems['item_name_1'])) {
             $optionsLineItems = array();
         }
         //if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array();
         ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch, and thus bypassed): ' . "\n" . print_r($optionsLineItems, true));
     }
     /** 提交购买的商品名称到 PAYPAL **/
     /*for ($i=0, $n=sizeof($order->products), $k=1; $i<$n; $i++, $k++) {
     		$product_names = $product_names . $order->products[$i]['name'] . " ; ";
     	}*/
     //global $orders_id;
     //$paypal_order_id = $_SESSION['paypal_order_no']; //zen_get_order_no($orders_id);
     $count_amount_total = number_format($this->subtotal, $currencies->get_decimal_places($my_currency));
     $count_shipping_total = number_format($this->wl_check_price($this->shipping_cost, $_SESSION['currency']), $currencies->get_decimal_places($my_currency));
     $count_amount_shipping = $count_amount_total + $count_shipping_total;
     if (!empty($_POST['cot_gv']) && $_POST['cot_gv'] > 0 && $_POST['cot_gv'] < $count_amount_shipping) {
         if ($_POST['cot_gv'] < $count_amount_total) {
             $paypal_amount_number = $count_amount_total - $_POST['cot_gv'];
             $paypal_shipping_number = $count_shipping_total;
         } elseif ($_POST['cot_gv'] < $count_shipping_total) {
             $paypal_amount_number = $count_amount_total;
             $paypal_shipping_number = $count_shipping_total - $_POST['cot_gv'];
         } else {
             $paypal_amount_number = 0.01;
             $paypal_shipping_number = $count_shipping_total - ($_POST['cot_gv'] - $count_amount_total) - 0.01;
         }
     } else {
         $paypal_amount_number = $count_amount_total;
         $paypal_shipping_number = $count_shipping_total;
     }
     $optionsAggregate = array('cmd' => '_ext-enter', 'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE . "#" . $_SESSION['paypal_no'], 'amount' => $paypal_amount_number, 'shipping' => $paypal_shipping_number, 'paypal_order_id' => $paypal_order_id);
     //var_dump($optionsAggregate);
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax'] = '0.00';
     }
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax_cart'] = '0.00';
     }
     $optionsTrans = array('upload' => (int) (sizeof($order->products) > 0), 'currency_code' => $my_currency);
     // if line-item info is invalid, use aggregate:
     if (sizeof($optionsLineItems) > 0) {
         $optionsAggregate = $optionsLineItems;
     }
     // prepare submission
     $options = array_merge($optionsCore, $optionsCust, $optionsPhone, $optionsShip, $optionsTrans, $optionsAggregate);
     ipn_debug_email('Keys for submission: ' . print_r($options, true));
     // build the button fields
     foreach ($options as $name => $value) {
         // remove quotation marks
         $value = str_replace('"', '', $value);
         // check for invalid chars
         if (preg_match('/[^a-zA-Z_0-9]/', $name)) {
             ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')');
             break;
         }
         // do we need special handling for & and = symbols?
         //if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);
         $buttonArray[] = zen_draw_hidden_field($name, $value);
     }
     $process_button_string = implode("\n", $buttonArray) . "\n";
     $_SESSION['paypal_transaction_info'] = array($this->transaction_amount, $this->transaction_currency);
     return $process_button_string;
 }
Exemple #14
0
                     } else {
                         $Gshipping = new GoogleFlatRateShipping($shipping_name, $shipping_price);
                         $Gshipping->AddShippingRestrictions($Gfilter);
                         $Gcart->AddShipping($Gshipping);
                     }
                 }
             }
         } else {
             $shipping_config_errors .= $key . " (ignored)<br />";
         }
     }
 }
 if (MODULE_PAYMENT_GOOGLECHECKOUT_CARRIER_CALCULATED_ENABLED == 'True' && !$free_shipping) {
     $Gshipping = new GoogleCarrierCalculatedShipping('Carrier_shipping');
     $country_code = defined('SHIPPING_ORIGIN_COUNTRY') ? SHIPPING_ORIGIN_COUNTRY : STORE_COUNTRY;
     $zone_name = zen_get_zone_code($country_code, STORE_ZONE, '');
     $countries_array = zen_get_countries(SHIPPING_ORIGIN_COUNTRY, true);
     $ship_from = new GoogleShipFrom('Store_origin', '', $countries_array['countries_iso_code_2'], SHIPPING_ORIGIN_ZIP, $zone_name);
     $GSPackage = new GoogleShippingPackage($ship_from, 1, 1, 1, 'IN');
     $Gshipping->addShippingPackage($GSPackage);
     $carriers_config = explode(', ', MODULE_PAYMENT_GOOGLECHECKOUT_CARRIER_CALCULATED);
     //    print_r($carriers_config);die;
     foreach ($googlepayment->cc_shipping_methods_names as $CCSCode => $CCSName) {
         foreach ($googlepayment->cc_shipping_methods[$CCSCode] as $type => $methods) {
             foreach ($methods as $method => $method_name) {
                 $values = explode('|', compare($CCSCode . $method . $type, $carriers_config, "_CCS:", '0|0|0'));
                 if ($values[0] != '0') {
                     $CCSoption = new GoogleCarrierCalculatedShippingOption($values[0], $CCSName, $method, $values[1], $values[2], 'REGULAR_PICKUP');
                     $Gshipping->addCarrierCalculatedShippingOptions($CCSoption);
                 }
             }