/** * Redirect the customer to PayMate's site to enter their payment details */ public function TransferToProvider() { $payMateUsername = trim($this->GetValue("username")); $payMateCurrency = $this->GetValue("currency"); if ($this->GetValue("testmode") == "YES") { $payMateURL = sprintf("https://www.paymate.com.au/PayMate/TestExpressPayment?mid=%s", $payMateUsername); } else { $payMateURL = sprintf("https://www.paymate.com/PayMate/ExpressPayment?mid=%s", $payMateUsername); } $billingDetails = $this->GetBillingDetails(); $hiddenFields = array('currency' => $payMateCurrency, 'amt' => $this->GetGatewayAmount(), 'amt_editable' => 'N', 'ref' => $_COOKIE['SHOP_ORDER_TOKEN'], 'return' => $GLOBALS['ShopPathSSL'] . '/finishorder.php', 'popup' => 'false', 'pmt_contact_firstname' => $billingDetails['ordbillfirstname'], 'pmt_contact_surname' => $billingDetails['ordbilllastname'], 'pmt_sender_email' => $billingDetails['ordbillemail'], 'pmt_contact_phone' => $billingDetails['ordbillphone'], 'pmt_country' => GetCountryISO2ByName($billingDetails['ordbillcountry']), 'regindi_address1' => $billingDetails['ordbillstreet1'], 'regindi_address2' => $billingDetails['ordbillstreet2'], 'regindi_pcode' => $billingDetails['ordbillzip'], 'regindi_sub' => $billingDetails['ordbillsuburb'], 'regindi_state' => $billingDetails['ordbillstate']); $this->RedirectToProvider($payMateURL, $hiddenFields); }
public function GetServiceQuotes() { $QuoteList = array(); // Set the Royal Mail-specific variables $this->_origincountry = GetCountryISO2ByName(GetConfig('CompanyCountry')); $this->_originzip = GetConfig('CompanyZip'); $this->_destcountry = $this->_destination_country['country_iso']; $this->_destzip = $this->_destination_zip; // Get the selected delivery types $delivery_types = $this->GetValue("deliverytypes"); if (!is_array($delivery_types) && $delivery_types != "") { $delivery_types = array($delivery_types); } foreach ($delivery_types as $delivery_type) { // Only perform lookups for quotes we can fetch - so don't bother trying for quotes for local services when shipping internationally if (in_array($delivery_type, $this->internationalTypes)) { if ($this->_origincountry == $this->_destcountry) { continue; } } else { if ($this->_origincountry != $this->_destcountry) { continue; } } $this->_deliverytype = $delivery_type; // Next actually retrieve the quote $err = ""; $result = $this->GetQuote($err); // Was it a valid quote? if (is_object($result)) { $QuoteList[] = $result; // Invalid quote, log the error } else { foreach ($this->GetErrors() as $error) { $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('shipping', $this->GetName()), $this->_deliverytypes[$delivery_type] . ": " . GetLang('ShippingQuoteError'), $error); } $this->ResetErrors(); } } return $QuoteList; }
/** * Generates the private key and certificate used by iDeal * * @return bool True on success, false on failure */ private function GenerateKeyAndCertificate() { if (file_exists($this->_keyFile) && file_exists($this->_certFile)) { return false; } // Create the keypair if (($key = openssl_pkey_new()) === false) { // could not create key $this->SetError(GetLang('IdealCantCreateKeyPair')); return false; } if (file_exists($this->_keyFile)) { if (!unlink($this->_keyFile)) { // could not delete old key file $this->SetError(GetLang('IdealCantDeleteKeyFile', array("keyFile" => $this->_keyFile))); return false; } } // export our key if (!openssl_pkey_export_to_file($key, $this->_keyFile, GetConfig('EncryptionToken'))) { // could not export key $this->SetError(GetLang('IdealCantExportKey')); return false; } chmod($this->_keyFile, ISC_WRITEABLE_FILE_PERM); $dn = array( "countryName" => GetCountryISO2ByName(GetConfig('CompanyCountry')), "stateOrProvinceName" => GetConfig('CompanyState'), "localityName" => GetConfig('CompanyCity'), "organizationName" => GetConfig('CompanyName'), "organizationalUnitName" => GetConfig('CompanyName'), "commonName" => GetConfig('CompanyName'), "emailAddress" => GetConfig('AdminEmail') ); // create our certificate if (($csr = openssl_csr_new($dn, $key)) === false) { // could not create cert $this->SetError(GetLang('IdealCantCreateCert')); return false; } // self sign our certificate if (($sscert = openssl_csr_sign($csr, null, $key, 3650)) === false) { // could not sign cert $this->SetError(GetLang('IdealCantSignCert')); return false; } if (file_exists($this->_certFile)) { if (!unlink($this->_certFile)) { // could not delete old cert file $this->SetError(GetLang('IdealCantDeleteCertFile', array("certFile" => $this->_certFile))); return false; } } // export certificate to file if (!openssl_x509_export_to_file($sscert, $this->_certFile)) { // could not export cert $this->SetError(GetLang('IdealCantExportCert')); return false; } chmod($this->_certFile, ISC_WRITEABLE_FILE_PERM); return true; }
/** * Format an address for display in the control panel for an order or shipment. * * @param array An array of details about the address. * @param boolean Set to false to not include a flag image for the address country. * @return string The generated HTML of the formatted address. */ public function BuildOrderAddressDetails($address, $includeFlag = true) { if (!isset($address['countrycode'])) { $address['countrycode'] = GetCountryISO2ByName($address['shipcountry']); } $countryFlag = ''; if ($includeFlag && $address['countrycode'] != '' && file_exists(ISC_BASE_PATH . "/lib/flags/" . strtolower($address['countrycode']) . ".gif")) { $countryFlag = "\n\t\t\t\t\t \n\t\t\t\t\t<img src=\"" . GetConfig('AppPath') . "/lib/flags/" . strtolower($address['countrycode']) . ".gif\" style=\"vertical-align: middle;\" alt=\"\" />\n\t\t\t\t"; } $addressPieces = array(isc_html_escape($address['shipfirstname']) . ' ' . isc_html_escape($address['shiplastname']), isc_html_escape($address['shipcompany']), isc_html_escape($address['shipaddress1']), isc_html_escape($address['shipaddress2']), trim(isc_html_escape($address['shipcity'] . ', ' . $address['shipstate'] . ' ' . $address['shipzip']), ', '), isc_html_escape($address['shipcountry']) . $countryFlag); $addressDetails = ''; foreach ($addressPieces as $piece) { if (!trim($piece)) { continue; } else { if ($addressDetails) { $addressDetails .= '<br />'; } } $addressDetails .= $piece; } return $addressDetails; }
/** * Handle extra data on first go * * Method will handle the extra data that gets sent on the first go * * @access private * @return void */ private function handleFirstGo() { $importSessData = array( "QBXML_VERSION" => (float)($this->soapObj->qbXMLMajorVers . "." . $this->soapObj->qbXMLMinorVers), "CLIENT_COUNTRY" => $this->soapObj->qbXMLCountry, "COMPANY_DATA" => $this->soapObj->strHCPResponse ); /** * Use the store country as a fallback if the $this->soapObj->qbXMLCountry variable is empty */ if (trim($this->soapObj->qbXMLCountry) == '') { $importSessData["CLIENT_COUNTRY"] = GetCountryISO2ByName(GetConfig("CompanyCountry")); } $this->accounting->setImportSessionValue("CompanyData", $importSessData); }
/** * Parse the order data * * Method will parse the order data to be inserted into the database * * @access private * @param array &$input The referenced input data * @param array &$parsed The referneced array to store the parsed information in * @return NULL */ private function parsedata(&$input, &$parsed) { // Load the shipping address if we don't have a custom one if (array_key_exists('shippingaddressid', $input) && isId($input['shippingaddressid'])) { $input['shippingaddress'] = $GLOBALS['ISC_CLASS_ACCOUNT']->GetShippingAddress($input['shippingaddressid']); } // Load the billing address if we don't have a custom one if (array_key_exists('billingaddressid', $input) && isId($input['billingaddressid'])) { $input['billingaddress'] = $GLOBALS['ISC_CLASS_ACCOUNT']->GetShippingAddress($input['billingaddressid']); } // If we don't have a shipping address for this order then it's a digital order - we need to set up an empty // array with the address fields if (!isset($input['shippingaddress'])) { $input['shippingaddress'] = array('shipfirstname' => '', 'shiplastname' => '', 'shipaddress1' => '', 'shipaddress2' => '', 'shipcity' => '', 'shipstate' => '', 'shipzip' => '', 'shipcountry' => '', 'shipcountryid' => '', 'shipstateid' => '', 'shipcompany' => ''); } if (!isset($input['ordstatus'])) { $input['ordstatus'] = 0; } if (!isset($input['orddate'])) { $input['orddate'] = time(); } // Get the amount that went through the payment gateway if (array_key_exists('gatewayamount', $input)) { $orderGatewayAmount = $input['gatewayamount']; } else { $orderGatewayAmount = 0; } // Get the amount of store credit that was used if (array_key_exists('storecreditamount', $input)) { $orderStoreCreditAmount = $input['storecreditamount']; } else { $orderStoreCreditAmount = 0; } // Get the amount used from any gift certificates if (array_key_exists('giftcertificateamount', $input)) { $orderGiftCertificateAmount = $input['giftcertificateamount']; } else { $orderGiftCertificateAmount = 0; } $providerName = ''; $providerId = ''; // Order was paid for entirely with gift certificates if ($input['paymentmethod'] == "giftcertificate") { $providerName = "giftcertificate"; $providerid = ''; } else { if ($input['paymentmethod'] == "storecredit") { $providerName = 'storecredit'; $providerId = ''; } else { if ($input['gatewayamount'] > 0) { if (GetModuleById('checkout', $provider, $input['paymentmethod']) && is_object($provider)) { $providerName = $provider->GetDisplayName(); $providerId = $provider->GetId(); } else { $providerId = $input['paymentmethod']; $providerName = $input['paymentmethodname']; } } else { $providerName = ''; $providerId = ''; } } } // Get the customer ID if (!array_key_exists('customerid', $input)) { $GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER'); $input['customerid'] = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerIdByToken($input['customertoken']); } // Loop through all of the products in this order to see if they're entirely // gift certificates $onlyGiftCertificates = true; foreach ($input['products'] as $product) { if (isset($product['type']) && $product['type'] != 'giftcertificate') { $onlyGiftCertificates = false; } } // Fetch the country codes for the billing and shipping addresses $billingCountryCode = GetCountryISO2ByName($input['billingaddress']['shipcountry']); $shippingCountryCode = ''; if (isset($input['shippingaddress']['shipcountry'])) { $shippingCountryCode = GetCountryISO2ByName($input['shippingaddress']['shipcountry']); } $ipCountryName = ''; $ipCountryCode = ''; if (!array_key_exists('geoipcountry', $input) && !array_key_exists('geoipcountrycode', $input)) { // Attempt to determine the GeoIP location based on their IP address require_once ISC_BASE_PATH . "/lib/geoip/geoip.php"; $gi = geoip_open(ISC_BASE_PATH . "/lib/geoip/GeoIP.dat", GEOIP_STANDARD); $ipCountryCode = geoip_country_code_by_addr($gi, GetIP()); // If we get the country, look up the country name as well if ($ipCountryCode) { $ipCountryName = geoip_country_name_by_addr($gi, GetIP()); } } if (!isset($input['vendorid'])) { $input['vendorid'] = 0; } if (!array_key_exists('extraInfo', $input)) { $input['extraInfo'] = array(); } if (array_key_exists('giftcertificates', $input) && is_array($input['giftcertificates'])) { $input['extraInfo']['giftcertificates'] = $input['giftcertificates']; } if (!array_key_exists('ordshippingzoneid', $input)) { $input['ordshippingzoneid'] = 0; } if (!array_key_exists('ordshippingzone', $input)) { $input['ordshippingzone'] = ''; } if (array_key_exists('shipemail', $input['billingaddress'])) { $input["ordbillemail"] = $input['billingaddress']['shipemail']; } else { if (!isset($input['ordbillemail'])) { $input['ordbillemail'] = ''; } } if (array_key_exists('shipphone', $input['billingaddress'])) { $input["ordbillphone"] = $input['billingaddress']['shipphone']; } else { $input['ordbillphone'] = ''; } if (isset($input['shippingaddress']) && is_array($input['shippingaddress']) && array_key_exists('shipemail', $input['shippingaddress'])) { $input["ordshipemail"] = $input['shippingaddress']['shipemail']; } else { if (!isset($input['ordshipemail'])) { $input["ordshipemail"] = ''; } } if (isset($input['shippingaddress']) && is_array($input['shippingaddress']) && array_key_exists('shipphone', $input['shippingaddress'])) { $input["ordshipphone"] = $input['shippingaddress']['shipphone']; } else { $input['ordshipphone'] = ''; } if (!isset($input['shippingcost']) || $input['shippingcost'] == '') { $input['shippingcost'] = 0; } if (!isset($input['handlingcost']) || $input['handlingcost'] == '') { $input['handlingcost'] = 0; } // If we don't have a billing or shipping email address but we have a customer, fetch & use the email address // from the customer if ((!$input['ordbillemail'] || !$input['ordshipemail']) && $input['customerid']) { $query = "\n\t\t\t\tSELECT custconemail\n\t\t\t\tFROM [|PREFIX|]customers\n\t\t\t\tWHERE customerid='" . (int) $input['customerid'] . "'\n\t\t\t"; $email = $GLOBALS['ISC_CLASS_DB']->FetchOne($query); foreach (array('ordbillemail', 'ordshipemail') as $field) { if (!$input[$field]) { $input[$field] = $email; } } } // If we don't have a billing or shipping phone but we have a customer, fetch & use the phone // from the customer if ((!$input['ordbillphone'] || !$input['ordshipphone']) && $input['customerid']) { $query = "\n\t\t\t\tSELECT custconphone\n\t\t\t\tFROM [|PREFIX|]customers\n\t\t\t\tWHERE customerid='" . (int) $input['customerid'] . "'\n\t\t\t"; $phone = $GLOBALS['ISC_CLASS_DB']->FetchOne($query); foreach (array('ordbillphone', 'ordshipphone') as $field) { if (!$input[$field]) { $input[$field] = $phone; } } } // Determine the actual number of items in this order $totalNumItems = 0; foreach ($input['products'] as $product) { $totalNumItems += $product['quantity']; } $defaultCurrency = GetDefaultCurrency(); $parsed = array('ordtoken' => $input['pending_token'], 'ordvendorid' => $input['vendorid'], 'ordcustid' => $input['customerid'], 'orddate' => $input['orddate'], 'ordsubtotal' => $input['itemtotal'], 'ordtaxtotal' => $input['taxcost'], 'ordtaxrate' => $input['taxrate'], 'ordtaxname' => $input['taxname'], 'ordtotalincludestax' => $input['totalincludestax'], 'ordshipcost' => $input['shippingcost'], 'ordshipmethod' => $input['shippingprovider'], 'ordershipmodule' => $input['shippingmodule'], 'ordhandlingcost' => $input['handlingcost'], 'ordtotalamount' => $input['totalcost'], 'ordgatewayamount' => $orderGatewayAmount, 'ordstorecreditamount' => $orderStoreCreditAmount, 'ordgiftcertificateamount' => $orderGiftCertificateAmount, 'ordstatus' => $input['ordstatus'], 'ordtotalqty' => $totalNumItems, 'orderpaymentmethod' => $providerName, 'orderpaymentmodule' => $providerId, 'ordbillfirstname' => $input['billingaddress']['shipfirstname'], 'ordbilllastname' => $input['billingaddress']['shiplastname'], 'ordbillcompany' => $input['billingaddress']['shipcompany'], 'ordbillstreet1' => $input['billingaddress']['shipaddress1'], 'ordbillstreet2' => $input['billingaddress']['shipaddress2'], 'ordbillsuburb' => $input['billingaddress']['shipcity'], 'ordbillstate' => $input['billingaddress']['shipstate'], 'ordbillzip' => $input['billingaddress']['shipzip'], 'ordbillcountry' => $input['billingaddress']['shipcountry'], 'ordshipfirstname' => $input['shippingaddress']['shipfirstname'], 'ordshiplastname' => $input['shippingaddress']['shiplastname'], 'ordshipcompany' => $input['shippingaddress']['shipcompany'], 'ordshipstreet1' => $input['shippingaddress']['shipaddress1'], 'ordshipstreet2' => $input['shippingaddress']['shipaddress2'], 'ordshipsuburb' => $input['shippingaddress']['shipcity'], 'ordshipstate' => $input['shippingaddress']['shipstate'], 'ordshipzip' => $input['shippingaddress']['shipzip'], 'ordshipcountry' => $input['shippingaddress']['shipcountry'], 'ordbillcountryid' => (int) $input['billingaddress']['shipcountryid'], 'ordbillstateid' => (int) $input['billingaddress']['shipstateid'], 'ordshipcountryid' => (int) $input['shippingaddress']['shipcountryid'], 'ordshipstateid' => (int) $input['shippingaddress']['shipstateid'], 'ordisdigital' => $input['isdigitalorder'], 'ordonlygiftcerts' => (int) $onlyGiftCertificates, 'extrainfo' => serialize($input['extraInfo']), 'ordbillcountrycode' => $billingCountryCode, 'ordshipcountrycode' => $shippingCountryCode, 'ordgeoipcountry' => $ipCountryName, 'ordgeoipcountrycode' => $ipCountryCode, 'ordcurrencyid' => (int) $input['currencyid'], 'orddefaultcurrencyid' => (int) $defaultCurrency['currencyid'], 'ordcurrencyexchangerate' => $input['currencyexchangerate'], 'ordshippingzoneid' => $input['ordshippingzoneid'], 'ordshippingzone' => $input['ordshippingzone'], 'ordbillemail' => $input['ordbillemail'], 'ordbillphone' => $input['ordbillphone'], 'ordshipemail' => $input['ordshipemail'], 'ordshipphone' => $input['ordshipphone']); $parsed['ordcustmessage'] = ''; if (isset($input['ordercomments'])) { $parsed['ordcustmessage'] = $input['ordercomments']; } $parsed['ordnotes'] = ''; if (isset($input['ordnotes'])) { $parsed['ordnotes'] = $input['ordnotes']; } $parsed['ordtrackingno'] = ''; if (isset($input['ordtrackingno'])) { $parsed['ordtrackingno'] = $input['ordtrackingno']; } $parsed['ordipaddress'] = ''; if (isset($input['ipaddress'])) { $parsed['ordipaddress'] = $input['ipaddress']; } if (isset($input['ordformsessionid']) && isId($input['ordformsessionid'])) { $parsed['ordformsessionid'] = $input['ordformsessionid']; } }
/** * Generate the XML to be sent to UPS to calculate shipping quotes. * * @return string The generated XML. */ private function GenerateRateXML() { $shipFromCity = GetConfig('CompanyCity'); $shipFromState = GetStateISO2ByName(GetConfig('CompanyState')); $shipFromZip = GetConfig('CompanyZip'); $shipFromCountry = GetCountryISO2ByName(GetConfig('CompanyCountry')); // Build the XML for the shipping quote $xml = new SimpleXMLElement("<AccessRequest xml:lang='en-US'/>"); $xml->addChild('AccessLicenseNumber', $this->GetValue('accesslicenseno')); $xml->addChild('UserId', $this->GetValue('accessuserid')); $xml->addChild('Password', $this->GetValue('accesspassword')); $accessRequest = $xml->asXML(); $xml = new SimpleXMLElement('<RatingServiceSelectionRequest/>'); $request = $xml->addChild('Request'); // Add in the transaction reference $transRef = $request->addChild('TransactionReference'); $transRef->addChild('CustomerContext', 'Rating and Service'); $transRef->addChild('XpciVersion', '1.0'); $request->addChild('RequestAction', 'Rate'); $request->addChild('RequestOption', 'Shop'); // Add in the pickup type we'll be using $xml->addChild('PickupType')->addChild('Code', $this->GetValue('pickuptypes')); // Provide information about the shipment $shipment = $xml->addChild('Shipment'); // Add the information about the shipper $shipper = $shipment->addChild('Shipper'); $shipperNumber = $this->GetValue('upsaccount'); if ($shipperNumber) { $shipper->addChild('ShipperNumber', $shipperNumber); } $address = $shipper->addChild('Address'); $address->addChild('City', $shipFromCity); $address->addChild('StateProvinceCode', $shipFromState); $address->addChild('PostalCode', $shipFromZip); $address->addChild('CountryCode', $shipFromCountry); // Now add the information about the destination address $address = $shipment->addChild('ShipTo')->addChild('Address'); //$address->addChild('City', 'Sydney'); if ($this->_destination_state['state_iso']) { $state = $this->_destination_state['state_iso']; } else { $state = $this->_destination_state['state_name']; } $address->addChild('StateProvinceCode', $state); $address->addChild('PostalCode', $this->_destination_zip); $address->addChild('CountryCode', $this->_destination_country['country_iso']); // Add in the location we're shipping from $shipFrom = $shipment->addChild('ShipFrom'); $address = $shipFrom->addChild('Address'); $address->addChild('City', $shipFromCity); $address->addChild('StateProvinceCode', $shipFromState); $address->addChild('PostalCode', $shipFromZip); $address->addChild('CountryCode', $shipFromCountry); // Add in the package information $package = $shipment->addChild('Package'); $package->addChild('PackagingType')->addChild('Code', $this->GetValue('packagingtype')); $packageWeight = $package->addChild('PackageWeight'); switch (strtolower($shipFromCountry)) { case 'us': case 'lr': case 'mm': $weightCode = 'LBS'; $dimensionsCode = 'IN'; break; default: $weightCode = 'KGS'; $dimensionsCode = 'CM'; } $packageWeight->addChild('UnitOfMeasurement')->addChild('Code', $weightCode); $weight = ConvertWeight($this->_weight, $weightCode); if ($weightCode == 'LBS' && $weight < 0.1) { $weight = 0.1; } $packageWeight->addChild('Weight', $weight); $shipmentDimensions = $this->GetCombinedShipDimensions(); if ($shipmentDimensions['width'] + $shipmentDimensions['height'] + $shipmentDimensions['length'] > 0) { $dimensions = $package->addChild('Dimensions'); $dimensions->addChild('UnitsOfMeasurement')->addChild('Code', $dimensionsCode); $dimensions->addChild('Length', number_format(ConvertLength($shipmentDimensions['length'], $dimensionsCode), 2, '.', '')); $dimensions->addChild('Width', number_format(ConvertLength($shipmentDimensions['width'], $dimensionsCode), 2, '.', '')); $dimensions->addChild('Height', number_format(ConvertLength($shipmentDimensions['height'], $dimensionsCode), 2, '.', '')); } $combinedXML = $accessRequest . $xml->asXML(); //print_R($combinedXML); return $combinedXML; }
public function GetServiceQuotes() { $QuoteList = array(); // Set the FedEx-specific variables $this->_origincountry = GetCountryISO2ByName(GetConfig('CompanyCountry')); $this->_originzip = GetConfig('CompanyZip'); $this->_destcountry = $this->_destination_country['country_iso']; $this->_destzip = $this->_destination_zip; $this->_deststate = $this->_destination_state['state_iso']; $this->_dropofftype = $this->GetValue("dropofftype"); $this->_accountno = $this->GetValue("accountno"); $this->_meterno = $this->GetValue("meterno"); $this->_packagingtype = $this->GetValue("packagingtype"); $this->_ratetype = $this->GetValue("ratetype"); // Return all available FedEx service types $services = $this->GetValue("service"); if (!is_array($services) && $services != "") { $services = array($services); } // Return all available FedEx delivery types $delivery_types = $this->GetValue("carriercode"); if (!is_array($delivery_types) && $delivery_types != "") { $delivery_types = array($delivery_types); } // Loop through each service using each delivery type foreach ($services as $service) { // Only perform lookups for quotes we can fetch - so don't bother trying for quotes for local services when shipping internationally if (in_array($service, $this->_internationalservices)) { if ($this->_origincountry == $this->_destcountry) { continue; } } else { if ($this->_origincountry != $this->_destcountry && $this->_destcountry != "US" && $this->_destcountry != "AU") { continue; } } foreach ($delivery_types as $delivery_type) { $this->_deliverytype = $delivery_type; $this->_carriercode = $delivery_type; $this->_service = $service; // Next actually retrieve the quote $err = ""; $result = $this->GetQuote($err); // Was it a valid quote? if (is_object($result)) { $QuoteList[] = $result; // Invalid quote, log the error } else { foreach ($this->GetErrors() as $error) { $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('shipping', $this->GetName()), $this->_servicetypes[$service] . " / " . $this->_deliverytypes[$delivery_type] . ": " . GetLang('ShippingQuoteError'), $error); } $this->ResetErrors(); } } } return $QuoteList; }
/** * Redirect the customer to PayMate's site to enter their payment details */ public function TransferToProvider() { $payMateCurrency = ''; $defaultCurrency = GetDefaultCurrency(); if (isset($defaultCurrency['currencycode']) && trim($defaultCurrency['currencycode']) !== '') { $payMateCurrency = $defaultCurrency['currencycode']; } // Default the default currency code to AUD if we have none or if we have an unsupported one if ($payMateCurrency == '' || !$this->checkSupportedCurrencies($payMateCurrency)) { $payMateCurrency = 'AUD'; } $payMateUsername = trim($this->GetValue("username")); if($this->GetValue("testmode") == "YES") { $payMateURL = sprintf("https://www.paymate.com.au/PayMate/TestExpressPayment?mid=%s", $payMateUsername); } else { $payMateURL = sprintf("https://www.paymate.com/PayMate/ExpressPayment?mid=%s", $payMateUsername); } $billingDetails = $this->GetBillingDetails(); $hiddenFields = array( 'currency' => $payMateCurrency, 'amt' => $this->GetGatewayAmount(), 'amt_editable' => 'N', 'ref' => $_COOKIE['SHOP_ORDER_TOKEN'], 'return' => $GLOBALS['ShopPathSSL'].'/finishorder.php', 'popup' => 'false', // Customer details 'pmt_contact_firstname' => $billingDetails['ordbillfirstname'], 'pmt_contact_surname' => $billingDetails['ordbilllastname'], 'pmt_sender_email' => $billingDetails['ordbillemail'], 'pmt_contact_phone' => $billingDetails['ordbillphone'], 'pmt_country' => GetCountryISO2ByName($billingDetails['ordbillcountry']), 'regindi_address1' => $billingDetails['ordbillstreet1'], 'regindi_address2' => $billingDetails['ordbillstreet2'], 'regindi_pcode' => $billingDetails['ordbillzip'], 'regindi_sub' => $billingDetails['ordbillsuburb'], 'regindi_state' => $billingDetails['ordbillstate'] ); $this->RedirectToProvider($payMateURL, $hiddenFields); }
public function GetServiceQuotes() { $QuoteList = array(); // Set the Intershipper-specific variables $this->_username = $this->GetValue("username"); $this->_password = $this->GetValue("password"); $this->_originzip = GetConfig('CompanyZip'); $this->_origincountry = GetCountryISO2ByName(GetConfig('CompanyCountry')); $this->_shipclasses = $this->GetValue("shipclasses"); $this->_destinationtype = $this->GetValue("destinationtype"); $this->_shippingmethod = $this->GetValue("shippingmethod"); $this->_packingmethod = $this->GetValue("packingmethod"); $this->_packagingtype = $this->GetValue("packagingtype"); $this->_sort = $this->GetValue("sort"); $this->_destcountry = $this->_destination_country['country_iso']; $this->_destzip = $this->_destination_zip; $this->_carriers = $this->GetValue("carriers"); // Next actually retrieve the quote $err = ""; $result = $this->GetQuote($err); // Was it a valid quote? if ($err == "") { // Split up each quote and return them separately foreach ($result as $quote) { $shipper_quote = array(new ISC_SHIPPING_QUOTE($this->GetId(), $this->GetDisplayName(), $quote->getprice(), $quote->getdesc(), $quote->gettransit())); array_push($QuoteList, $shipper_quote); } } else { $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('shipping', $this->GetName()), GetLang('ShippingQuoteError'), $result['error']); } return $QuoteList; }
public function GetServiceQuotes() { $QuoteList = array(); // Set the UPS-specific variables $this->_origincountry = GetCountryISO2ByName(GetConfig('CompanyCountry')); $this->_originzip = GetConfig('CompanyZip'); $this->_destcountry = $this->_destination_country['country_iso']; $this->_destzip = $this->_destination_zip; $this->_shippingrate = $this->GetValue("shippingrate"); $this->_packagingtype = $this->GetValue("packagingtype"); if ($this->_destination_rescom == "COM") { $this->_destination = "2"; } else { $this->_destination = "1"; } // Convert the weight to pounds $this->_weight = ConvertWeight($this->_weight, 'pounds'); // Return quotes for all available UPS service types $services = $this->GetValue("deliverytypes"); if (!is_array($services) && $services != "") { $services = array($services); } foreach ($services as $service) { // Set the service type $this->_deliverytype = $service; // Next actually retrieve the quote $err = ""; $result = $this->GetQuote($err); // Was it a valid quote? if (is_object($result)) { array_push($QuoteList, $result); // Invalid quote, log the error } else { foreach ($this->GetErrors() as $error) { $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('shipping', $this->GetName()), $this->_deliverytypes[$service] . ": " . GetLang('ShippingQuoteError'), $error); } $this->ResetErrors(); } } return $QuoteList; }
/** * Insert/Update the node with the response record * * Method will insert/update the node with the response record * * @access protected * @param array $responseData The reponse data from QB * @param array $nodeData The optional node data array. If set then update, else insert * @return int The new or updtaed node ID on success, FALSE on error */ protected function syncResponseRecord2Store($responseData, $nodeData=false) { if (!is_array($responseData)) { $xargs = func_get_args(); throw new QBException("Invalid arguments when syncing order record from QB", $xargs); } /** * Get our stored customer ID if we have one */ $customerId = $this->getCustomer4Order($responseData["TxnID"]); /** * Get the customer ListID and find the matching customer ID if we can. We need to have a customer ListID */ if (is_null($customerId)) { if (!isset($responseData["CustomerRef"]["ListID"])) { throw new QBException("Unable to find customer ListID when syncing orders", $responseData); } $customerRef = $this->accounting->getReference("customer", '', $responseData["CustomerRef"]["ListID"], '', false); /** * If we don't have a reference then use the existing customer ID if we have one */ if (!is_array($customerRef)) { if (is_array($nodeData) && array_key_exists("ordcustid", $nodeData) && isId($nodeData["ordcustid"])) { $customerId = $nodeData["ordcustid"]; /** * Else if we do have a nodeData but no customer ID then its a guest checkout */ } else if (is_array($nodeData) && (!array_key_exists("ordcustid", $nodeData) || !isId($nodeData["ordcustid"]))) { $customerId = ''; /** * Else it is a new customer which we do not have a record for */ } else { $lastKid = end($this->spool["children"]); if ($lastKid["nodeType"] == "customer" && $lastKid["service"] == "query") { /** * If we couldn't find the record then error out */ if ($lastKid["errNo"] > 0) { throw new QBException("Unable to find customer when syncing orders from QB", $responseData["CustomerRef"]["ListID"]); } /** * Check to see if this is an anonymous customer (guest checkout). If so then don't create a customer record */ if ($this->accounting->isCustomerGuestCheckout($lastKid["response"])) { $customerId = ''; /** * Else it is a real customer so create it */ } else { $customerId = $this->customerSyncAPI->syncResponseRecord2Store($lastKid["response"]); if (!isId($customerId)) { throw new QBException("Unable to create customer record when syncing orders from QB", $lastKid["response"]); } $referenceDataSetup = $this->customerSyncAPI->referenceDataSetup; $referenceDataExternalKey = $this->customerSyncAPI->referenceDataExternalKey; $referenceReturn = $this->setReferenceDataStatically("customer", $customerId, $lastKid["response"], '', $referenceDataSetup, $referenceDataExternalKey); if (isId($referenceReturn)) { $customerRef = $this->accounting->getReference("customer", $referenceReturn, '', '', false); } } } else { $childRequestData = array( "ListID" => $responseData["CustomerRef"]["ListID"] ); return $this->execChildService("customer", "query", $childRequestData); } } /** * Else we have the customer but not the order yet */ } else if (is_array($customerRef)) { $customerId = $customerRef["accountingrefnodeid"]; /** * Else we got no customer */ } else { $customerId = ''; } /** * Save the customer ID for this order */ $this->setCustomer2Order($responseData["TxnID"], $customerId); } /** * If we have a custom ID then get the customer record as we'll need it later on */ $customerNodeData = ''; if (isId($customerId)) { $customerNodeData = $this->customerAPI->get($customerId); } if ($this->accounting->getValue("orderoption") == "order") { $salesLineRetTag = "SalesOrderLineRet"; } else { $salesLineRetTag = "SalesReceiptLineRet"; } /** * OK, we got the customer, now we need to get all the products */ if (!isset($responseData[$salesLineRetTag]) || !is_array($responseData[$salesLineRetTag]) || empty($responseData[$salesLineRetTag])) { throw new QBException("Missing/Invalid product array when syncing orders", array("tag" => $salesLineRetTag, "response" => $responseData)); } /** * Set aside some vars for shipping costs and the tax component */ $productSubTotal = 0; $shippingCost = 0; $taxCost = 0; /** * Sanatize it */ if (!isset($responseData[$salesLineRetTag][0])) { $responseData[$salesLineRetTag] = array($responseData[$salesLineRetTag]); } foreach ($responseData[$salesLineRetTag] as $product) { /** * Check to see if we have already recorded this product */ if ($this->checkProductListId4Order($responseData["TxnID"], $product["ItemRef"]["ListID"])) { continue; } /** * OK, we haven't done this one yet so lets do it. If we have any kids then deal with them first */ $lastKid = end($this->spool["children"]); if ($lastKid["service"] == "query" && ($lastKid["nodeType"] == "product" || $lastKid["nodeType"] == "productvariation")) { /** * If we couldn't find the record then error out */ if ($lastKid["errNo"] > 0) { throw new QBException("Unable to find product when syncing orders from QB", $product["ItemRef"]["ListID"]); } /** * Else try to add in this product/variation */ if ($lastKid["nodeType"] == "productvariation") { $productFatcory =& $this->productVariationSyncAPI; } else { $productFatcory =& $this->productSyncAPI; } $productData = $productFatcory->searchNodeByDB($lastKid["response"]); $productId = $productFatcory->syncResponseRecord2Store($lastKid["response"], $productData); /** * Dam! We can't add it. Error out of here as we really needed that product for the order */ if (!isId($productId)) { throw new QBException("Unable to create product/variation record when syncing orders from QB", $lastKid["response"]); } /** * Set the reference for this product */ $referenceDataSetup = $productFatcory->referenceDataSetup; $referenceDataExternalKey = $productFatcory->referenceDataExternalKey; $this->setReferenceDataStatically($lastKid["nodeType"], $productId, $lastKid["response"], '', $referenceDataSetup, $referenceDataExternalKey); } /** * There aren't any query kids so try and find the reference for this product/variation/other product */ $checkTypes = array("product", "productvariation", "prerequisite"); $productRef = ""; $productType = ""; foreach ($checkTypes as $checkType) { $productRef = $this->accounting->getReference($checkType, '', $product["ItemRef"]["ListID"], '', false); if (is_array($productRef)) { $productType = $checkType; break; } } /** * Check to see if this is a prerequisite (shipping & tax costs) */ if ($productType == "prerequisite") { switch (isc_strtolower(trim($productRef["accountingrefvalue"]["Type"]))) { case "shipping": $cost = ($product["Quantity"] * $product["Rate"]); break; case "tax": $cost = ($product["Quantity"] * $product["Rate"]); break; } $productNodeData = array( "Type" => isc_strtolower(trim($productRef["accountingrefvalue"]["Type"])), "Cost" => $cost ); $this->setProductListId2Order($responseData["TxnID"], $product["ItemRef"]["ListID"], $productType, $productNodeData, $product); /** * We don't want to insert this in the order_products table */ continue; } /** * OK, prerequisites are done, now for the rest. If no reference then send out a query child */ if (!is_array($productRef)) { if ($this->accounting->isProductVariationShortName($product["ItemRef"]["FullName"])) { $productType = "productvariation"; } else { $productType = "product"; } $childRequestData = array( "ListID" => $product["ItemRef"]["ListID"] ); return $this->execChildService($productType, "query", $childRequestData); } /** * Must have a reference by now */ if (!is_array($productRef)) { throw new QBException("Unable to find product reference when syncing order ID: " . $this->spool["nodeId"], $responseData); } $prodNodeData = ''; if ($productType == "productvariation") { $prodNodeData = $this->productVariationAPI->get($productRef["accountingrefnodeid"]); } else { $prodNodeData = $this->productAPI->get($productRef["accountingrefnodeid"]); } /** * If no prodNodeData then no go */ if (!is_array($prodNodeData)) { throw new QBException("Unable to find " . $productType . " node data when syncing order ID: " . $this->spool["nodeId"], array("order" => $responseData, "prodNodeId" => $productRef["accountingrefnodeid"])); } /** * Lastly, save this product to our tmp cache */ $this->setProductListId2Order($responseData["TxnID"], $product["ItemRef"]["ListID"], $productType, $prodNodeData, $product); } /** * OK, now retrieve all our product from our tmp cache to build the products for this order */ $products = array(); $taxCost = $shippingCost = 0; $cacheProducts = $this->getProductListIds4Order($responseData["TxnID"]); if (!is_array($cacheProducts) || empty($cacheProducts)) { throw new QBException("Empty product cache array when syncing order ID: " . $this->spool["nodeId"], $responseData); } foreach ($cacheProducts as $productListId => $product) { /** * Add up our stored shipping and tax costs if we have any */ if ($product["productType"] == "prerequisite") { switch (isc_strtolower(trim($product["productNodeData"]["Type"]))) { case "shipping": $shippingCost = $product["productNodeData"]["Cost"]; break; case "tax": $taxCost = $product["productNodeData"]["Cost"]; break; } continue; } $prodCode = ''; $prodVariationId = 0; $prodOptions = array(); if ($product["productType"] == "productvariation") { $prodCode = $product["productNodeData"]["vcsku"]; $prodVariationId = $product["productNodeData"]["combinationid"]; $prodOptions = $product["productNodeData"]["prodvariationarray"]; } if (trim($prodCode) == '') { $prodCode = $product["productNodeData"]["prodcode"]; } $products[] = array( "product_id" => $product["productNodeData"]["productid"], "product_name" => $product["productNodeData"]["prodname"], "product_code" => $prodCode, "quantity" => max(1, $product["productResponse"]["Quantity"]), "product_price" => $product["productResponse"]["Rate"], "original_price" => $product["productResponse"]["Rate"], "variation_id" => $prodVariationId, "options" => $prodOptions ); /** * Check to see if this is an existing product in an already existing order */ if (is_array($nodeData) && isset($nodeData["products"]) && is_array($nodeData["products"])) { foreach ($nodeData["products"] as $existingProduct) { if ($existingProduct["productid"] == $product["productNodeData"]["productid"] && isset($existingProduct["prodorderid"])) { $products[count($products)-1]["existing_order_product"] = $existingProduct["prodorderid"]; } } } /** * Add up our sub total */ $productSubTotal += $product["productResponse"]["Amount"]; } /** * OK, we have all the products and the customer details. Now for the actual order details */ $savedata = array( "ordcustid" => $customerId, "subtotal_ex_tax" => $productSubTotal, "total_tax" => $taxCost, "shipping_cost_ex_tax" => $shippingCost, "total_inc_tax" => ($productSubTotal + $taxCost + $shippingCost), "products" => $products ); if (isset($responseData["Memo"])) { $savedata["ordnotes"] = $responseData["Memo"]; } /** * Add in the addresses */ $addressMap = array( "shipaddress1" => "Addr1", "shipaddress2" => "Addr2", "shipcity" => "City", "shipstate" => "State", "shipzip" => "PostalCode", "shipcountry" => "Country" ); foreach (array("BillAddress", "ShipAddress") as $addressType) { if (!array_key_exists($addressType, $responseData) || !is_array($responseData[$addressType])) { $responseData[$addressType] = array(); } if ($addressType == "BillAddress") { $addressKey = "billingaddress"; } else { $addressKey = "shippingaddress"; } $savedata[$addressKey] = array(); foreach ($addressMap as $columnName => $refKey) { if (!isset($responseData[$addressType][$refKey]) && !is_array($nodeData)) { $responseData[$addressType][$refKey] = ''; } if (isset($responseData[$addressType][$refKey])) { $savedata[$addressKey][$columnName] = $responseData[$addressType][$refKey]; } } /** * Find the country and state IDs */ $countryId = $this->getCountryId(@$savedata[$addressKey]["shipcountry"], $properCountryName); $stateId = ''; if (isId($countryId) && trim(@$savedata[$addressKey]["shipstate"]) !== '') { $savedata[$addressKey]["shipcountry"] = $properCountryName; $stateId = $this->getStateId($savedata[$addressKey]["shipstate"], $countryId, $properStateName); if (!isId($stateId)) { $stateId = ''; } else if (trim($properStateName) !== '') { $savedata[$addressKey]["shipstate"] = $properStateName; } } else { $countryId = ''; } if (is_array($nodeData) || !isId($stateId)) { $savedata[$addressKey]["shipstateid"] = $stateId; } if (is_array($nodeData) || !isId($countryId)) { $savedata[$addressKey]["shipcountryid"] = $countryId; } /** * Fill in the name. Use whatever QB gave us regardless */ $customerName = @$responseData["CustomerRef"]["FullName"]; if ($this->accounting->isCustomerShortName($customerName)) { $tmpName = $this->accounting->qbCustomerShortName2CustomerNameId($customerName); if (is_array($tmpName) && array_key_exists("customername", $tmpName)) { $customerName = $tmpName["customername"]; } } else if ($this->accounting->isCustomerGuestShortName($customerName)) { $tmpName = $this->accounting->qbCustomerGuestShortName2CustomerGuestNameId($customerName); if (is_array($tmpName) && array_key_exists("customerguestname", $tmpName)) { $customerName = $tmpName["customerguestname"]; } } $nameParts = explode(" ", $customerName); if (count($nameParts) > 2) { $firstName = implode(" ", array_slice($nameParts, 0, count($nameParts)-1)); $lastName = $nameParts[count($nameParts)-1]; } else if (count($nameParts) == 1) { $firstName = $nameParts[0]; $lastName = ""; } else { $firstName = $nameParts[0]; $lastName = $nameParts[1]; } $savedata[$addressKey]["shipfirstname"] = $firstName; $savedata[$addressKey]["shiplastname"] = $lastName; /** * Set something to each field if it is NULL as the database can't handle NULL values for this schema */ foreach ($savedata[$addressKey] as $addKey => $addVal) { if (is_null($addVal)) { $savedata[$addressKey][$addKey] = ''; } } } /** * If we don't have a $nodeData then we can still fill in some blanks */ if (!is_array($nodeData)) { $savedata["ordtoken"] = GenerateOrderToken(); $savedata["ordstatus"] = ORDER_STATUS_COMPLETED; $savedata["orderpaymentmodule"] = "manual"; $savedata["orderpaymentmethod"] = GetLang("QuickBooksDefaultPaymentName"); $savedata["total_inc_tax"] = $savedata["totalcost"]; $savedata["handling_cost_ex_tax"] = 0; $savedata["handling_cost_inc_tax"] = 0; if (isset($savedata["billingaddress"]["shipcountry"])) { $savedata["ordgeoipcountry"] = $savedata["billingaddress"]["shipcountry"]; $savedata["ordgeoipcountrycode"] = GetCountryISO2ByName($savedata["billingaddress"]["shipcountry"]); } if (is_array($customerNodeData)) { $savedata["ordbillemail"] = $customerNodeData["custconemail"]; $savedata["ordbillphone"] = $customerNodeData["custconphone"]; $savedata["ordshipemail"] = $customerNodeData["custconemail"]; $savedata["ordshipphone"] = $customerNodeData["custconphone"]; } } else { $savedata["orderid"] = $nodeData["orderid"]; } /** * Alright, we have EVERYTHING, now create/update EVERYTHING */ $orderId = false; if (is_array($nodeData)) { /** * Reset the inventory levels before we update it */ if ($this->accounting->getValue("invlevels") !== ACCOUNTING_QUICKBOOKS_TYPE_QUICKBOOKS) { UpdateInventoryOnReturn($savedata["orderid"]); /* /lib/orders.php */ } if ($this->entityAPI->edit($savedata) !== false) { $orderId = $savedata["orderid"]; } /** * Now sync back the inventory levels */ if ($this->accounting->getValue("invlevels") !== ACCOUNTING_QUICKBOOKS_TYPE_QUICKBOOKS) { DecreaseInventoryFromOrder($orderId); } } else { $orderId = $this->entityAPI->add($savedata); /** * Sync up the inventory levels as each order is marked as completed */ if ($this->accounting->getValue("invlevels") !== ACCOUNTING_QUICKBOOKS_TYPE_QUICKBOOKS) { DecreaseInventoryFromOrder($orderId); } } if (!isId($orderId)) { $this->accounting->logError("ORDER DATA", array("SaveData" => $savedata, "NodeData" => $nodeData, "DB" => $GLOBALS["ISC_CLASS_DB"]->GetError())); throw new QBException("Cannot save order record with data from QB", array("SaveData" => $savedata, "NodeData" => $nodeData, "DB" => $GLOBALS["ISC_CLASS_DB"]->GetError())); } return $orderId; }