示例#1
0
 /**
  * Function to store the matching patch package for the currently installed VM version to the cache path
  *
  * @param array $d
  * @return boolean
  */
 function getPatchPackage(&$d)
 {
     global $vm_mainframe, $vmLogger, $mosConfig_cachepath, $VM_LANG;
     $allowed_extensions = array('gz', 'zip');
     if (empty($_FILES['uploaded_package']['tmp_name'])) {
         // retrieve the latest version number from virtuemart.net
         require_once ADMINPATH . 'version.php';
         $VMVERSION = new vmVersion();
         // This URL should return a string - the direct URL to the matching patch package
         $url = "http://virtuemart.net/index2.php?option=com_versions&catid=1&myVersion={$VMVERSION->RELEASE}&task=listpatchpackages&j=" . (vmIsJoomla('1.5') ? '1.5' : '1.0');
         $result = vmConnector::handleCommunication($url);
         if (!empty($result) && (strncmp('http://dev.virtuemart.net', $result, 25) === 0 || strncmp('http://virtuemart.net', $result, 21) === 0)) {
             $filename = basename($result);
             $doc_id_pos = strpos($filename, '?');
             if ($doc_id_pos > 0) {
                 $filename = substr($filename, 0, $doc_id_pos);
             }
             // Was the package already downloaded?
             if (file_exists($mosConfig_cachepath . '/' . $filename)) {
                 $vmLogger->info($VM_LANG->_('VM_UPDATE_PACKAGE_EXISTS') . ' ' . $mosConfig_cachepath . '/' . $filename);
             } else {
                 // If not, store it on this server
                 $patch_package = vmConnector::handleCommunication($result);
                 if (!file_put_contents($mosConfig_cachepath . '/' . $filename, $patch_package)) {
                     $vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_STORE_FAILED'));
                     return false;
                 }
             }
             // cache the location of the stored package file
             $_SESSION['vm_updatepackage'] = $mosConfig_cachepath . '/' . $filename;
         } else {
             $vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_RETRIEVE_FAILED'));
             return false;
         }
         if (vmIsXHR()) {
             $vm_mainframe->addResponseScript('parent.loadPage("' . $GLOBALS['sess']->url($_SERVER['PHP_SELF'] . '?page=admin.update_preview', false, false) . '");');
         }
         return true;
     } else {
         // make sure the file name is safe for storage.
         $filename = vmSafeFileName($_FILES['uploaded_package']['name']);
         $fileinfo = pathinfo($filename);
         if (!in_array(strtolower($fileinfo['extension']), $allowed_extensions)) {
             $vmLogger->err('An invalid patch package extension was detected. Allowed Types: ' . implode(', ', $allowed_extensions));
             return false;
         }
         // Handle the uploaded package file- the integrity validation is done in another function
         if (move_uploaded_file($_FILES['uploaded_package']['tmp_name'], $mosConfig_cachepath . '/' . $filename)) {
             $_SESSION['vm_updatepackage'] = $mosConfig_cachepath . '/' . $filename;
             if (vmIsXHR()) {
                 $vm_mainframe->addResponseScript('parent.loadPage("' . $GLOBALS['sess']->url($_SERVER['PHP_SELF'] . '?page=admin.update_preview', false, false) . '");');
             }
         } else {
             $vmLogger->err('Failed to store the uploaded patch package file.');
             return false;
         }
     }
 }
示例#2
0
 /**
  * Voids a previous transaction with Payflow Pro
  *
  * @param array $d
  * @return boolean
  */
 function void_authorization(&$d)
 {
     global $vendor_mail, $vendor_currency, $VM_LANG, $vmLogger;
     $database = new ps_DB();
     require_once CLASSPATH . "connectionTools.class.php";
     if (empty($d['order_number'])) {
         $vmLogger->err("Error: No Order Number provided.");
         return false;
     }
     /*** Get the Configuration File for authorize.net ***/
     require_once CLASSPATH . "payment/" . __CLASS__ . ".cfg.php";
     if (PFP_TYPE != 'A') {
         return true;
     }
     // Get the Account Password securely from the database
     $database->query("SELECT " . VM_DECRYPT_FUNCTION . "(payment_passkey,'" . ENCODE_KEY . "') as passkey FROM #__{vm}_payment_method WHERE payment_class='" . __CLASS__ . "'");
     $transaction = $database->record[0];
     if (empty($transaction->passkey)) {
         $vmLogger->err($VM_LANG->_('PHPSHOP_PAYMENT_ERROR'), false);
         return false;
     }
     $db = new ps_DB();
     $q = "SELECT * FROM #__{vm}_orders, #__{vm}_order_payment WHERE ";
     $q .= "order_number='" . $d['order_number'] . "' ";
     $q .= "AND #__{vm}_orders.order_id=#__{vm}_order_payment.order_id";
     $db->query($q);
     if (!$db->next_record()) {
         $vmLogger->err("Error: Order not found.");
         return false;
     }
     $expire_date = date("my", $db->f("order_payment_expire"));
     $cvv2_code = $db->f("order_payment_code");
     // DECODE Account Number
     $dbaccount = new ps_DB();
     $q = "SELECT " . VM_DECRYPT_FUNCTION . "(order_payment_number,'" . ENCODE_KEY . "')\r\n          AS account_number from #__{vm}_order_payment WHERE order_id='" . $db->f("order_id") . "'";
     $dbaccount->query($q);
     $dbaccount->next_record();
     // Get user billing information
     $dbbt = new ps_DB();
     $qt = "SELECT * FROM #__{vm}_user_info WHERE user_id='" . $db->f("user_id") . "'";
     $dbbt->query($qt);
     $dbbt->next_record();
     $user_info_id = $dbbt->f("user_info_id");
     if ($user_info_id != $db->f("user_info_id")) {
         // Get user's alternative shipping information
         $dbst = new ps_DB();
         $qt = "SELECT * FROM #__{vm}_user_info WHERE user_info_id='" . $db->f("user_info_id") . "' AND address_type='ST'";
         $dbst->query($qt);
         $dbst->next_record();
     } else {
         $dbst = $dbbt;
     }
     $tempstr = $dbaccount->f('account_number') . $db->f('order_total') . date('YmdGis');
     $request_id = md5($tempstr);
     //Authnet vars to send
     $formdata = array('PARTNER' => PFP_PARTNER, 'VENDOR' => PFP_VENDOR, 'USER' => PFP_USER, 'PWD' => $transaction->passkey, 'TEST' => PFP_TEST_REQUEST, 'AMT' => $db->f('order_total'), 'TRXTYPE' => 'V', 'TENDER' => 'C', 'CURRENCY' => $vendor_currency, 'NAME' => strtoupper(substr($dbbt->f("first_name"), 0, 15) . substr($dbbt->f("last_name"), 0, 15)), 'STREET' => substr($dbbt->f("address_1"), 0, 30), 'CITY' => substr($dbbt->f("city"), 0, 40), 'STATE' => substr($dbbt->f("state"), 0, 40), 'ZIP' => substr($dbbt->f("zip"), 0, 9), 'CUSTREF' => substr($db->f('order_number'), 0, 12), 'ORIGID' => $db->f('order_payment_trans_id'), 'ACCT' => $dbaccount->f('account_number'), 'CVV2' => $cvv2_code, 'EXPDATE' => $expire_date);
     //build the post string
     $poststring = '';
     foreach ($formdata as $key => $val) {
         $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
     }
     // strip off trailing ampersand
     $poststring = substr($poststring, 0, -1);
     if (PFP_TEST_REQUEST == 'TRUE') {
         $host = 'pilot-payflowpro.verisign.com';
     } else {
         $host = 'payflowpro.verisign.com';
     }
     $headers[] = "X-VPS-Timeout: 30";
     $headers[] = "X-VPS-VIT-OS-Name: " . PHP_OS;
     // Name of your OS
     $headers[] = "X-VPS-VIT-OS-Version: " . PHP_OS;
     // OS Version
     $headers[] = "X-VPS-VIT-Client-Type: PHP/cURL";
     // What you are using
     $headers[] = "X-VPS-VIT-Client-Version: 0.01";
     // For your info
     $headers[] = "X-VPS-VIT-Client-Architecture: x86";
     // For your info
     $headers[] = "X-VPS-VIT-Client-Certification-Id: " . PFP_CLIENT_CERTIFICATION_ID;
     // get this from Todd @ payflowintegrator@paypal.com
     $headers[] = "X-VPS-VIT-Integration-Product: " . phpversion() . "::cURL";
     // For your info, would populate with application name
     $headers[] = "X-VPS-VIT-Integration-Version: 0.01";
     // Application version
     $headers[] = "X-VPS-Request-ID: " . $request_id;
     $result = vmConnector::handleCommunication("https://{$host}:443/transaction", $poststring, $headers);
     if (!$result) {
         $vmLogger->err('The transaction could not be completed.');
         return false;
     }
     $result = strstr($result, 'RESULT');
     $valArray = explode('&', $result);
     foreach ($valArray as $val) {
         $valArray2 = explode('=', $val);
         $pfpro[$valArray2[0]] = $valArray2[1];
     }
     $vmLogger->debug('Beginning to analyse the response from ' . $host);
     $RESULT_CODE = vmGet($pfpro, 'RESULT');
     $TRANSACTION_ID = vmGet($pfpro, 'PNREF');
     $RESPMSG = vmGet($pfpro, 'RESPMSG', '');
     $CVV2MATCH = vmGet($pfpro, 'CVV2MATCH', '');
     $success = false;
     switch ($RESULT_CODE) {
         case '0':
             // Approved - Success!
             $success = true;
             $d["order_payment_log"] = $VM_LANG->_('PHPSHOP_PAYMENT_TRANSACTION_SUCCESS') . ": ";
             $d["order_payment_log"] .= $RESPMSG;
             $q = "UPDATE #__{vm}_order_payment SET ";
             $q .= "order_payment_log='" . $d["order_payment_log"] . "',";
             $q .= "order_payment_trans_id='" . $TRANSACTION_ID . "' ";
             $q .= "WHERE order_id='" . $db->f("order_id") . "' ";
             $db->query($q);
             $vmLogger->debug($d['order_payment_log']);
             break;
         default:
             $d["order_payment_log"] = payflow_pro::getResponseMsg($RESULT_CODE);
             if (!empty($d["order_payment_log"])) {
                 $vmLogger->err($d["order_payment_log"]);
             } else {
                 $vmLogger->err('An unknown Error occured while voiding the transaction.');
             }
             break;
     }
     return $success;
 }
示例#3
0
 /**
  * Initializes the global currency converter array
  *
  * @return mixed
  */
 function init()
 {
     global $mosConfig_cachepath, $mosConfig_absolute_path, $vendor_currency, $vmLogger;
     if (!is_array($GLOBALS['converter_array']) && $GLOBALS['converter_array'] !== -1) {
         setlocale(LC_TIME, "en-GB");
         $now = time() + 3600;
         // Time in ECB (Germany) is GMT + 1 hour (3600 seconds)
         if (date("I")) {
             $now += 3600;
             // Adjust for daylight saving time
         }
         $weekday_now_local = gmdate('w', $now);
         // week day, important: week starts with sunday (= 0) !!
         $date_now_local = gmdate('Ymd', $now);
         $time_now_local = gmdate('Hi', $now);
         $time_ecb_update = '1415';
         if (is_writable($mosConfig_cachepath)) {
             $store_path = $mosConfig_cachepath;
         } else {
             $store_path = $mosConfig_absolute_path . "/media";
         }
         $archivefile_name = $store_path . '/daily.xml';
         $ecb_filename = $this->document_address;
         $val = '';
         if (file_exists($archivefile_name) && filesize($archivefile_name) > 0) {
             // timestamp for the Filename
             $file_datestamp = date('Ymd', filemtime($archivefile_name));
             // check if today is a weekday - no updates on weekends
             if (date('w') > 0 && date('w') < 6 && $file_datestamp != $date_now_local && $time_now_local > $time_ecb_update) {
                 $curr_filename = $ecb_filename;
             } else {
                 $curr_filename = $archivefile_name;
                 $this->last_updated = $file_datestamp;
                 $this->archive = false;
             }
         } else {
             $curr_filename = $ecb_filename;
         }
         if (!is_writable($store_path)) {
             $this->archive = false;
             $vmLogger->debug("The file {$archivefile_name} can't be created. The directory {$store_path} is not writable");
         }
         if ($curr_filename == $ecb_filename) {
             // Fetch the file from the internet
             require_once CLASSPATH . 'connectionTools.class.php';
             $contents = vmConnector::handleCommunication($curr_filename);
             $this->last_updated = date('Ymd');
         } else {
             $contents = @file_get_contents($curr_filename);
         }
         if ($contents) {
             // if archivefile does not exist
             if ($this->archive) {
                 // now write new file
                 file_put_contents($archivefile_name, $contents);
             }
             $contents = str_replace("<Cube currency='USD'", " <Cube currency='EUR' rate='1'/> <Cube currency='USD'", $contents);
             /* XML Parsing */
             require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
             $xmlDoc = new DOMIT_Lite_Document();
             if (!$xmlDoc->parseXML($contents, false, true)) {
                 $vmLogger->err('Failed to parse the Currency Converter XML document.');
                 $_SESSION['product_currency'] = $GLOBALS['product_currency'] = $vendor_currency;
                 return false;
             }
             $currency_list = $xmlDoc->getElementsByTagName("Cube");
             // Loop through the Currency List
             for ($i = 0; $i < $currency_list->getLength(); $i++) {
                 $currNode =& $currency_list->item($i);
                 $currency[$currNode->getAttribute("currency")] = $currNode->getAttribute("rate");
                 unset($currNode);
             }
             $GLOBALS['converter_array'] = $currency;
         } else {
             $GLOBALS['converter_array'] = -1;
             $vmLogger->err('Failed to retrieve the Currency Converter XML document.');
             $_SESSION['product_currency'] = $GLOBALS['product_currency'] = $vendor_currency;
             return false;
         }
     }
     return true;
 }
 function capture_payment(&$d)
 {
     global $vendor_mail, $vendor_currency, $VM_LANG, $vmLogger;
     $database = new ps_DB();
     require_once CLASSPATH . "connectionTools.class.php";
     /*CERTIFICATION
     		Visa Test Account           4007000000027
     		Amex Test Account           370000000000002
     		Master Card Test Account    6011000000000012
     		Discover Test Account       5424000000000015
     
     		$host = "certification.authorize.net";
     		$port = 443;
     		$path = "/gateway/transact.dll";
     		*/
     if (empty($d['order_number'])) {
         $vmLogger->err("Error: No Order Number provided.");
         return false;
     }
     /*** Get the Configuration File for authorize.net ***/
     require_once CLASSPATH . "payment/" . __CLASS__ . ".cfg.php";
     // Get the Transaction Key securely from the database
     $database->query("SELECT " . VM_DECRYPT_FUNCTION . "(payment_passkey,'" . ENCODE_KEY . "') as passkey FROM #__{vm}_payment_method \r\n\t\t\t\t\t\t\t\t\tWHERE payment_class='" . __CLASS__ . "' AND payment_enabled = 'Y'");
     $transaction = $database->record[0];
     if (empty($transaction->passkey)) {
         $vmLogger->err($VM_LANG->_('PHPSHOP_PAYMENT_ERROR'), false);
         return false;
     }
     $db = new ps_DB();
     $q = "SELECT * FROM #__{vm}_orders, #__{vm}_order_payment WHERE ";
     $q .= "order_number='" . $d['order_number'] . "' ";
     $q .= "AND #__{vm}_orders.order_id=#__{vm}_order_payment.order_id";
     $db->query($q);
     if (!$db->next_record()) {
         $vmLogger->err("Error: Order not found.");
         return false;
     }
     $expire_date = date("my", $db->f("order_payment_expire"));
     // DECODE Account Number
     $dbaccount = new ps_DB();
     $q = "SELECT " . VM_DECRYPT_FUNCTION . "(order_payment_number,'" . ENCODE_KEY . "')\r\n          AS account_number from #__{vm}_order_payment WHERE order_id='" . $db->f("order_id") . "'";
     $dbaccount->query($q);
     $dbaccount->next_record();
     // Get user billing information
     $dbbt = new ps_DB();
     $qt = "SELECT * FROM #__{vm}_user_info WHERE user_id='" . $db->f("user_id") . "'";
     $dbbt->query($qt);
     $dbbt->next_record();
     $user_info_id = $dbbt->f("user_info_id");
     if ($user_info_id != $db->f("user_info_id")) {
         // Get user's alternative shipping information
         $dbst = new ps_DB();
         $qt = "SELECT * FROM #__{vm}_user_info WHERE user_info_id='" . $db->f("user_info_id") . "' AND address_type='ST'";
         $dbst->query($qt);
         $dbst->next_record();
     } else {
         $dbst = $dbbt;
     }
     //Authnet vars to send
     $formdata = array('x_version' => '3.1', 'x_login' => AN_LOGIN, 'x_tran_key' => $transaction->passkey, 'x_test_request' => strtoupper(AN_TEST_REQUEST), 'x_delim_data' => 'TRUE', 'x_delim_char' => '|', 'x_relay_response' => 'FALSE', 'x_first_name' => substr($dbbt->f("first_name"), 0, 50), 'x_last_name' => substr($dbbt->f("last_name"), 0, 50), 'x_company' => substr($dbbt->f("company"), 0, 50), 'x_address' => substr($dbbt->f("address_1"), 0, 60), 'x_city' => substr($dbbt->f("city"), 0, 40), 'x_state' => substr($dbbt->f("state"), 0, 40), 'x_zip' => substr($dbbt->f("zip"), 0, 20), 'x_country' => substr($dbbt->f("country"), 0, 60), 'x_phone' => substr($dbbt->f("phone_1"), 0, 25), 'x_fax' => substr($dbbt->f("fax"), 0, 25), 'x_ship_to_first_name' => substr($dbst->f("first_name"), 0, 50), 'x_ship_to_last_name' => substr($dbst->f("last_name"), 0, 50), 'x_ship_to_company' => substr($dbst->f("company"), 0, 50), 'x_ship_to_address' => substr($dbst->f("address_1"), 0, 60), 'x_ship_to_city' => substr($dbst->f("city"), 0, 40), 'x_ship_to_state' => substr($dbst->f("state"), 0, 40), 'x_ship_to_zip' => substr($dbst->f("zip"), 0, 20), 'x_ship_to_country' => substr($dbst->f("country"), 0, 60), 'x_cust_id' => $db->f('user_id'), 'x_customer_ip' => $dbbt->f("ip_address"), 'x_customer_tax_id' => $dbbt->f("tax_id"), 'x_email' => $dbbt->f("email"), 'x_email_customer' => 'False', 'x_merchant_email' => $vendor_mail, 'x_invoice_num' => substr($d['order_number'], 0, 20), 'x_description' => '', 'x_amount' => $db->f("order_total"), 'x_currency_code' => $vendor_currency, 'x_method' => 'CC', 'x_type' => 'PRIOR_AUTH_CAPTURE', 'x_recurring_billing' => AN_RECURRING, 'x_card_num' => $dbaccount->f("account_number"), 'x_card_code' => $db->f('order_payment_code'), 'x_exp_date' => $expire_date, 'x_trans_id' => $db->f("order_payment_trans_id"), 'x_po_num' => substr($d['order_number'], 0, 20), 'x_tax' => substr($db->f('order_tax'), 0, 15), 'x_tax_exempt' => "FALSE", 'x_freight' => $db->f('order_shipping'), 'x_duty' => 0);
     //build the post string
     $poststring = '';
     foreach ($formdata as $key => $val) {
         $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
     }
     // strip off trailing ampersand
     $poststring = substr($poststring, 0, -1);
     if (defined('AN_HOSTNAME')) {
         $host = AN_HOSTNAME;
     } else {
         $host = 'secure.authorize.net';
     }
     $result = vmConnector::handleCommunication("https://{$host}:443/gateway/transact.dll", $poststring);
     if (!$result) {
         $vmLogger->err('We\'re sorry, but an error has occured when we tried to communicate with the authorize.net server. Please try again later, thank you.');
         return false;
     }
     $response = explode("|", $result);
     // Approved - Success!
     if ($response[0] == '1') {
         $d["order_payment_log"] = $VM_LANG->_('PHPSHOP_PAYMENT_TRANSACTION_SUCCESS') . ": ";
         $d["order_payment_log"] .= $response[3];
         // Catch Transaction ID
         $d["order_payment_trans_id"] = $response[6];
         $q = "UPDATE #__{vm}_order_payment SET ";
         $q .= "order_payment_log='" . $d["order_payment_log"] . "',";
         $q .= "order_payment_trans_id='" . $d["order_payment_trans_id"] . "' ";
         $q .= "WHERE order_id='" . $db->f("order_id") . "' ";
         $db->query($q);
         return True;
     } elseif ($response[0] == '2') {
         $vmLogger->err($response[3]);
         $d["order_payment_log"] = $response[3];
         // Catch Transaction ID
         $d["order_payment_trans_id"] = $response[6];
         return False;
     } elseif ($response[0] == '3') {
         $vmLogger->err($response[3]);
         $d["order_payment_log"] = $response[3];
         // Catch Transaction ID
         $d["order_payment_trans_id"] = $response[6];
         return False;
     }
 }
示例#5
0
 function list_rates(&$d)
 {
     global $vendor_country_2_code, $vendor_currency, $vmLogger;
     global $VM_LANG, $CURRENCY_DISPLAY, $mosConfig_absolute_path;
     $db =& new ps_DB();
     $dbv =& new ps_DB();
     $cart = $_SESSION['cart'];
     /** Read current Configuration ***/
     require_once CLASSPATH . "shipping/" . __CLASS__ . ".cfg.php";
     $q = "SELECT * FROM #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR country=country_3_code)";
     $db->query($q);
     $q = "SELECT * FROM #__{vm}_vendor WHERE vendor_id='" . $_SESSION['ps_vendor_id'] . "'";
     $dbv->query($q);
     $dbv->next_record();
     $order_weight = $d['weight'];
     $html = "";
     if ($order_weight > 0) {
         if ($order_weight < 1) {
             $order_weight = 1;
         }
         if ($order_weight > 150.0) {
             $order_weight = 150.0;
         }
         //Access code for online tools at ups.com
         $ups_access_code = UPS_ACCESS_CODE;
         //Username from registering for online tools at ups.com
         $ups_user_id = UPS_USER_ID;
         //Password from registering for online tools at ups.com
         $ups_user_password = UPS_PASSWORD;
         //Title for your request
         $request_title = "Shipping Estimate";
         //The zip that you are shipping from
         // Add ability to override vendor zip code as source ship from...
         if (Override_Source_Zip != "" or Override_Source_Zip != NULL) {
             $source_zip = Override_Source_Zip;
         } else {
             $source_zip = $dbv->f("vendor_zip");
         }
         //The zip that you are shipping to
         $dest_country = $db->f("country_2_code");
         $dest_zip = substr($db->f("zip"), 0, 5);
         // Make sure the ZIP is 5 chars long
         //LBS  = Pounds
         //KGS  = Kilograms
         $weight_measure = WEIGHT_UOM == 'KG' ? "KGS" : "LBS";
         // The XML that will be posted to UPS
         $xmlPost = "<?xml version=\"1.0\"?>";
         $xmlPost .= "<AccessRequest xml:lang=\"en-US\">";
         $xmlPost .= " <AccessLicenseNumber>" . $ups_access_code . "</AccessLicenseNumber>";
         $xmlPost .= " <UserId>" . $ups_user_id . "</UserId>";
         $xmlPost .= " <Password>" . $ups_user_password . "</Password>";
         $xmlPost .= "</AccessRequest>";
         $xmlPost .= "<?xml version=\"1.0\"?>";
         $xmlPost .= "<RatingServiceSelectionRequest xml:lang=\"en-US\">";
         $xmlPost .= " <Request>";
         $xmlPost .= "  <TransactionReference>";
         $xmlPost .= "  <CustomerContext>" . $request_title . "</CustomerContext>";
         $xmlPost .= "  <XpciVersion>1.0001</XpciVersion>";
         $xmlPost .= "  </TransactionReference>";
         $xmlPost .= "  <RequestAction>rate</RequestAction>";
         $xmlPost .= "  <RequestOption>shop</RequestOption>";
         $xmlPost .= " </Request>";
         $xmlPost .= " <PickupType>";
         $xmlPost .= "  <Code>" . UPS_PICKUP_TYPE . "</Code>";
         $xmlPost .= " </PickupType>";
         $xmlPost .= " <Shipment>";
         $xmlPost .= "  <Shipper>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $source_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$vendor_country_2_code}</CountryCode>";
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </Shipper>";
         $xmlPost .= "  <ShipTo>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $dest_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$dest_country}</CountryCode>";
         if (UPS_RESIDENTIAL == "yes") {
             $xmlPost .= "    <ResidentialAddressIndicator/>";
         }
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </ShipTo>";
         $xmlPost .= "  <ShipFrom>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $source_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$vendor_country_2_code}</CountryCode>";
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </ShipFrom>";
         // Service is only required, if the Tag "RequestOption" contains the value "rate"
         // We don't want a specific servive, but ALL Rates
         //$xmlPost .= "  <Service>";
         //$xmlPost .= "   <Code>".$shipping_type."</Code>";
         //$xmlPost .= "  </Service>";
         $xmlPost .= "  <Package>";
         $xmlPost .= "   <PackagingType>";
         $xmlPost .= "    <Code>" . UPS_PACKAGE_TYPE . "</Code>";
         $xmlPost .= "   </PackagingType>";
         $xmlPost .= "   <PackageWeight>";
         $xmlPost .= "    <UnitOfMeasurement>";
         $xmlPost .= "     <Code>" . $weight_measure . "</Code>";
         $xmlPost .= "    </UnitOfMeasurement>";
         $xmlPost .= "    <Weight>" . $order_weight . "</Weight>";
         $xmlPost .= "   </PackageWeight>";
         $xmlPost .= "  </Package>";
         $xmlPost .= " </Shipment>";
         $xmlPost .= "</RatingServiceSelectionRequest>";
         // echo htmlentities( $xmlPost );
         $upsURL = "https://www.ups.com:443/ups.app/xml/Rate";
         require_once CLASSPATH . 'connectionTools.class.php';
         $error = false;
         $xmlResult = vmConnector::handleCommunication($upsURL, $xmlPost);
         if (!$xmlResult) {
             $vmLogger->err($VM_LANG->_('PHPSHOP_INTERNAL_ERROR', false) . " UPS.com");
             $error = true;
         } else {
             /* XML Parsing */
             require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
             $xmlDoc =& new DOMIT_Lite_Document();
             $xmlDoc->parseXML($xmlResult, false, true);
             /* Let's check wether the response from UPS is Success or Failure ! */
             if (strstr($xmlResult, "Failure")) {
                 $error = true;
                 $error_code = $xmlDoc->getElementsByTagName("ErrorCode");
                 $error_code = $error_code->item(0);
                 $error_code = $error_code->getText();
                 $error_desc = $xmlDoc->getElementsByTagName("ErrorDescription");
                 $error_desc = $error_desc->item(0);
                 $error_desc = $error_desc->getText();
                 $vmLogger->err($VM_LANG->_('PHPSHOP_UPS_RESPONSE_ERROR', false) . '. ' . $VM_LANG->_('PHPSHOP_ERROR_CODE') . ": " . $error_code . ', ' . $VM_LANG->_('PHPSHOP_ERROR_DESC') . ": " . $error_desc);
             }
         }
         if ($error) {
             // Switch to StandardShipping on Error !!!
             require_once CLASSPATH . 'shipping/standard_shipping.php';
             $shipping =& new standard_shipping();
             $shipping->list_rates($d);
             return;
         }
         // retrieve the list of all "RatedShipment" Elements
         $rate_list =& $xmlDoc->getElementsByTagName("RatedShipment");
         $allservicecodes = array("UPS_Next_Day_Air", "UPS_2nd_Day_Air", "UPS_Ground", "UPS_Worldwide_Express_SM", "UPS_Worldwide_Expedited_SM", "UPS_Standard", "UPS_3_Day_Select", "UPS_Next_Day_Air_Saver", "UPS_Next_Day_Air_Early_AM", "UPS_Worldwide_Express_Plus_SM", "UPS_2nd_Day_Air_AM", "UPS_Saver", "na");
         $myservicecodes = array();
         foreach ($allservicecodes as $servicecode) {
             if (constant($servicecode) != '' || constant($servicecode) != 0) {
                 $myservicecodes[] = constant($servicecode);
             }
         }
         if (DEBUG) {
             echo "Cart Contents: " . $order_weight . " " . $weight_measure . "<br><br>\n";
             echo "XML Post: <br>";
             echo "<textarea cols='80'>" . $xmlPost . "</textarea>";
             echo "<br>";
             echo "XML Result: <br>";
             echo "<textarea cols='80' rows='10'>" . $xmlResult . "</textarea>";
             echo "<br>";
         }
         // Loop through the rate List
         for ($i = 0; $i < $rate_list->getLength(); $i++) {
             $currNode =& $rate_list->item($i);
             if (in_array($currNode->childNodes[0]->getText(), $myservicecodes)) {
                 $e = 0;
                 // First Element: Service Code
                 $shipment[$i]["ServiceCode"] = $currNode->childNodes[$e++]->getText();
                 // Second Element: BillingWeight
                 if ($currNode->childNodes[$e]->nodeName == 'RatedShipmentWarning') {
                     $e++;
                 }
                 $shipment[$i]["BillingWeight"] = $currNode->childNodes[$e++];
                 // Third Element: TransportationCharges
                 $shipment[$i]["TransportationCharges"] = $currNode->childNodes[$e++];
                 $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->getElementsByTagName("MonetaryValue");
                 $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->item(0);
                 if (is_object($shipment[$i]["TransportationCharges"])) {
                     $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->getText();
                 }
                 // Fourth Element: ServiceOptionsCharges
                 $shipment[$i]["ServiceOptionsCharges"] = $currNode->childNodes[$e++];
                 // Fifth Element: TotalCharges
                 $shipment[$i]["TotalCharges"] = $currNode->childNodes[$e++];
                 // Sixth Element: GuarenteedDaysToDelivery
                 $shipment[$i]["GuaranteedDaysToDelivery"] = $currNode->childNodes[$e++]->getText();
                 // Seventh Element: ScheduledDeliveryTime
                 $shipment[$i]["ScheduledDeliveryTime"] = $currNode->childNodes[$e++]->getText();
                 // Eighth Element: RatedPackage
                 $shipment[$i]["RatedPackage"] = $currNode->childNodes[$e++];
                 // map ServiceCode to ServiceName
                 switch ($shipment[$i]["ServiceCode"]) {
                     case "01":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air";
                         break;
                     case "02":
                         $shipment[$i]["ServiceName"] = "UPS 2nd Day Air";
                         break;
                     case "03":
                         $shipment[$i]["ServiceName"] = "UPS Ground";
                         break;
                     case "07":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Express SM";
                         break;
                     case "08":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Expedited SM";
                         break;
                     case "11":
                         $shipment[$i]["ServiceName"] = "UPS Standard";
                         break;
                     case "12":
                         $shipment[$i]["ServiceName"] = "UPS 3 Day Select";
                         break;
                     case "13":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air Saver";
                         break;
                     case "14":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air Early A.M.";
                         break;
                     case "54":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Express Plus SM";
                         break;
                     case "59":
                         $shipment[$i]["ServiceName"] = "UPS 2nd Day Air A.M.";
                         break;
                     case "64":
                         $shipment[$i]["ServiceName"] = "n/a";
                         break;
                     case "65":
                         $shipment[$i]["ServiceName"] = "UPS Saver";
                         break;
                 }
                 unset($currNode);
             }
         }
         if (!$shipment) {
             //$vmLogger->err( "Error processing the Request to UPS.com" );
             /*$vmLogger->err( "We could not find a UPS shipping rate.
             		Please make sure you have entered a valid shipping address.
             		Or choose a rate below." );
             		// Switch to StandardShipping on Error !!!
             		require_once( CLASSPATH . 'shipping/standard_shipping.php' );
             		$shipping =& new standard_shipping();
             		$shipping->list_rates( $d );*/
             return;
         }
         // UPS returns Charges in USD ONLY.
         // So we have to convert from USD to Vendor Currency if necessary
         if ($_SESSION['vendor_currency'] != "USD") {
             $convert = true;
         } else {
             $convert = false;
         }
         if ($_SESSION['auth']['show_price_including_tax'] != 1) {
             $taxrate = 1;
         } else {
             $taxrate = $this->get_tax_rate() + 1;
         }
         foreach ($shipment as $key => $value) {
             //Get the Fuel SurCharge rate, defined in config.
             $fsc = $value['ServiceName'] . "_FSC";
             $fsc = str_replace(" ", "_", str_replace(".", "", str_replace("/", "", $fsc)));
             $fsc = constant($fsc);
             if ($fsc == 0) {
                 $fsc_rate = 1;
             } else {
                 $fsc_rate = $fsc / 100;
                 $fsc_rate = $fsc_rate + 1;
             }
             if ($convert) {
                 $tmp = $GLOBALS['CURRENCY']->convert($value['TransportationCharges'], "USD", $vendor_currency);
                 // tmp is empty when the Vendor Currency could not be converted!!!!
                 if (!empty($tmp)) {
                     $charge = $tmp;
                     // add Fuel SurCharge
                     $charge *= $fsc_rate;
                     // add Handling Fee
                     $charge += UPS_HANDLING_FEE;
                     $charge *= $taxrate;
                     $value['TransportationCharges'] = $CURRENCY_DISPLAY->getFullValue($tmp);
                 } else {
                     $charge = $value['TransportationCharges'] + intval(UPS_HANDLING_FEE);
                     // add Fuel SurCharge
                     $charge *= $fsc_rate;
                     // add Handling Fee
                     $charge += UPS_HANDLING_FEE;
                     $charge *= $taxrate;
                     $value['TransportationCharges'] = $value['TransportationCharges'] . " USD";
                 }
             } else {
                 $charge = $charge_unrated = $value['TransportationCharges'];
                 // add Fuel SurCharge
                 $charge *= $fsc_rate;
                 // add Handling Fee
                 $charge += UPS_HANDLING_FEE;
                 $charge *= $taxrate;
                 $value['TransportationCharges'] = $CURRENCY_DISPLAY->getFullValue($charge);
             }
             $shipping_rate_id = urlencode(__CLASS__ . "|UPS|" . $value['ServiceName'] . "|" . $charge);
             $checked = @$d["shipping_rate_id"] == $value ? "checked=\"checked\"" : "";
             if (count($shipment) == 1) {
                 $checked = "checked=\"checked\"";
             }
             $html .= '<label for="' . $shipping_rate_id . '">' . "\n<input type=\"radio\" name=\"shipping_rate_id\" {$checked} value=\"{$shipping_rate_id}\" id=\"{$shipping_rate_id}\" />\n";
             $_SESSION[$shipping_rate_id] = 1;
             $html .= $value['ServiceName'] . ' ';
             $html .= "<strong>(" . $value['TransportationCharges'] . ")</strong>";
             if (DEBUG) {
                 $html .= " - " . $VM_LANG->_('PHPSHOP_PRODUCT_FORM_WEIGHT') . ": " . $order_weight . " " . $weight_measure . ", " . $VM_LANG->_('PHPSHOP_RATE_FORM_VALUE') . ": [[" . $charge_unrated . "(" . $fsc_rate . ")]+" . UPS_HANDLING_FEE . "](" . $taxrate . ")]";
             }
             // DELIVERY QUOTE
             if (Show_Delivery_Days_Quote == 1) {
                 if (!empty($value['GuaranteedDaysToDelivery'])) {
                     $html .= "&nbsp;&nbsp;-&nbsp;&nbsp;" . $value['GuaranteedDaysToDelivery'] . " " . $VM_LANG->_('PHPSHOP_UPS_SHIPPING_GUARANTEED_DAYS');
                 }
             }
             if (Show_Delivery_ETA_Quote == 1) {
                 if (!empty($value['ScheduledDeliveryTime'])) {
                     $html .= "&nbsp;(ETA:&nbsp;" . $value['ScheduledDeliveryTime'] . ")";
                 }
             }
             if (Show_Delivery_Warning == 1 && !empty($value['RatedShipmentWarning'])) {
                 $html .= "</label><br/>\n&nbsp;&nbsp;&nbsp;*&nbsp;<em>" . $value['RatedShipmentWarning'] . "</em>\n";
             }
             $html .= "<br />\n";
         }
     }
     echo $html;
     //DEBUG
     if (DEBUG) {
         /*
         echo "My Services: <br>";
         print_r($myservicecodes);
         echo "<br>";
         echo "All Services: <br>";
         print_r($allservicecodes);
         echo "<br>";
         echo "XML Result: <br>";
         echo "<textarea cols='80' rows='10'>".$xmlResult."</textarea>";
         echo "<br>";
         */
     }
     return true;
 }
示例#6
0
 /**
  * Does the refunding
  * 
  * This methods needs that every transaction id is saved. Atm this does not happen, so this function does not work atm.
  * 
  * @author Max Milbers
  */
 function do_refund(&$d)
 {
     global $vendor_currency, $vmLogger, $VM_LANG;
     if (empty($d['order_number'])) {
         $vmLogger->err("Error: No Order Number provided.");
         return false;
     }
     // include the configuration file
     require_once CLASSPATH . "payment/" . __CLASS__ . ".cfg.php";
     $db = new ps_DB();
     $q = "SELECT #__{vm}_orders.order_id,order_number,order_payment_trans_id,order_total FROM #__{vm}_orders, #__{vm}_order_payment WHERE ";
     $q .= "order_number='" . $d['order_number'] . "' ";
     $q .= "AND #__{vm}_orders.order_id=#__{vm}_order_payment.order_id";
     $db->query($q);
     if (!$db->next_record() || !$db->f('order_payment_trans_id')) {
         $vmLogger->err("Error: Order or TransactionID not found.");
         return false;
     }
     $postData['method'] = 'refundCard';
     $postData['merchantUUID'] = MW_MERCHANT_UUID;
     $postData['apiKey'] = MW_API_KEY;
     $postData['transactionAmount'] = $db->f('order_total');
     $postData['transactionCurrency'] = $vendor_currency;
     $postData['transactionID'] = $db->f('order_payment_trans_id');
     $postData['refundAmount'] = $db->f('order_total');
     $postData['hash'] = ps_merchantwarrior::calculateHash($postData, $transaction->passkey);
     $poststring = '';
     foreach ($postData as $key => $val) {
         $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
     }
     if (MW_TEST_REQUEST == 'FALSE') {
         //live
         $host = 'api.merchantwarrior.com';
     } else {
         //test
         $host = 'base.merchantwarrior.com';
     }
     //Maybe unnecessary
     $headers[] = "X-VPS-Timeout: 60";
     $headers[] = "X-VPS-VIT-OS-Name: " . PHP_OS;
     // Name of your OS
     $headers[] = "X-VPS-VIT-OS-Version: " . PHP_OS;
     // OS Version
     $headers[] = "X-VPS-VIT-Client-Type: PHP/cURL";
     // What you are using
     $headers[] = "X-VPS-VIT-Client-Version: 0.01";
     // For your info
     $responseData = vmConnector::handleCommunication("https://{$host}:443/post/", $poststring, $headers);
     if (!$responseData) {
         $vmLogger->err('Unable to connect with server. The transaction could not be completed.');
         return false;
     }
     // Parse the XML and create a SimpleXMLObject+
     $result = simplexml_load_string($responseData);
     // Convert the result from a SimpleXMLObject into an array+
     $result = (array) $result;
     $parsed = ps_merchantwarrior::parseResponse($result);
     ps_merchantwarrior::loadLang();
     if (!$parsed['responseCode']) {
         $vmLogger->info($VM_LANG->_('PHPSHOP_MW_0'));
         return true;
     } else {
         $errorCode = substr($parsed['responseMessage'], 5, 3);
         $vmLogger->err($VM_LANG->_('PHPSHOP_MW_' . $parsed['responseCode']) . ' ' . $VM_LANG->_('PHPSHOP_MW_ERROR_' . $errorCode));
         return false;
     }
 }
示例#7
0
 /**
  * Retrieves a remote file
  *
  * @param string $url
  * @return mixed
  */
 function getRemoteFile($url)
 {
     @ini_set("allow_url_fopen");
     $remote_fetching = ini_get("allow_url_fopen");
     if ($remote_fetching) {
         require_once CLASSPATH . 'connectionTools.class.php';
         $tmp_file = tempnam(IMAGEPATH . "/product/", "FOO");
         $handle = fopen($tmp_file, "wb");
         if ($handle === false) {
             return false;
         }
         vmConnector::handleCommunication($url, '', array(), $handle);
         fclose($handle);
         return $tmp_file;
     } else {
         return false;
     }
 }