/** * Return commno data for *all* transactions. * @return array Data */ public function _getGeneralTrnData(Varien_Object $payment, $adminParams = array()) { $order = $payment->getOrder(); $quoteObj = $this->_getQuote(); $vendorTxCode = $this->_getTrnVendorTxCode(); if ($payment->getCcNumber()) { $vendorTxCode .= $this->_cleanString(substr($payment->getCcOwner(), 0, 10)); } $payment->setVendorTxCode($vendorTxCode); $request = new Varien_Object(); $request->setVPSProtocol((string) $this->getVpsProtocolVersion($this->getConfigData('mode')))->setReferrerID($this->getConfigData('referrer_id'))->setVendor($this->getConfigData('vendor'))->setVendorTxCode($vendorTxCode); $request->setClientIPAddress($this->getClientIp()); if ($payment->getIntegra()) { //Server if (is_array($adminParams) && !empty($adminParams)) { $confParam = isset($adminParams['order']['send_confirmation']) ? '&e=' . (int) $adminParams['order']['send_confirmation'] : ''; if (isset($adminParams['order']['account']['email'])) { $confParam .= '&l=' . urlencode($adminParams['order']['account']['email']); } if (isset($adminParams['order']['account']['group_id'])) { $confParam .= '&g=' . $adminParams['order']['account']['group_id']; } } else { $confParam = ''; } $this->getSageSuiteSession()->setLastVendorTxCode($vendorTxCode); $request->setIntegration($payment->getIntegra()); $request->setData('notification_URL', $this->getNotificationUrl() . '&vtxc=' . $vendorTxCode . $confParam); $request->setData('success_URL', $this->getSuccessUrl()); $request->setData('redirect_URL', $this->getRedirectUrl()); $request->setData('failure_URL', $this->getFailureUrl()); } if ($this->_getIsAdminOrder()) { $request->setAccountType('M'); } if ($payment->getAmountOrdered()) { $this->_setRequestCurrencyAmount($request, $quoteObj); } if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setBillingAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setBillingSurname($this->ss($billing->getLastname(), 20))->setBillingFirstnames($this->ss($billing->getFirstname(), 20))->setBillingPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setBillingAddress1($this->ss($billing->getStreet(1), 100))->setBillingAddress2($this->ss($billing->getStreet(2), 100))->setBillingCity($this->ss($billing->getCity(), 40))->setBillingCountry($billing->getCountry())->setContactNumber(substr($this->_cphone($billing->getTelephone()), 0, 20)); if ($billing->getCountry() == 'US') { $request->setBillingState($billing->getRegionCode()); } $request->setCustomerEMail($billing->getEmail()); } if (!$request->getDescription()) { $request->setDescription('.'); } $shipping = $order->getShippingAddress(); if (!$quoteObj->isVirtual()) { $request->setDeliveryAddress($shipping->getStreet(1) . ' ' . $shipping->getCity() . ' ' . $shipping->getRegion() . ' ' . $shipping->getCountry())->setDeliverySurname($this->ss($shipping->getLastname(), 20))->setDeliveryFirstnames($this->ss($shipping->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($shipping->getPostcode(), 10)))->setDeliveryAddress1($this->ss($shipping->getStreet(1), 100))->setDeliveryAddress2($this->ss($shipping->getStreet(2), 100))->setDeliveryCity($this->ss($shipping->getCity(), 40))->setDeliveryCountry($shipping->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($shipping->getTelephone())), 20)); if ($shipping->getCountry() == 'US') { $request->setDeliveryState($shipping->getRegionCode()); } } else { #If the cart only has virtual products, I need to put an shipping address to Sage Pay. #Then the billing address will be the shipping address to $request->setDeliveryAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setDeliverySurname($this->ss($billing->getLastname(), 20))->setDeliveryFirstnames($this->ss($billing->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setDeliveryAddress1($this->ss($billing->getStreet(1), 100))->setDeliveryAddress2($this->ss($billing->getStreet(2), 100))->setDeliveryCity($this->ss($billing->getCity(), 40))->setDeliveryCountry($billing->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($billing->getTelephone())), 20)); if ($billing->getCountry() == 'US') { $request->setDeliveryState($billing->getRegionCode()); } } } if ($payment->getCcNumber()) { $request->setCardNumber($payment->getCcNumber())->setExpiryDate(sprintf('%02d%02d', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), strlen($payment->getCcExpYear()) - 2)))->setCardType($payment->getCcType())->setCV2($payment->getCcCid())->setCardHolder($payment->getCcOwner()); if ($payment->getCcIssue()) { $request->setIssueNumber($payment->getCcIssue()); } if ($payment->getCcStartMonth() && $payment->getCcStartYear()) { $request->setStartDate(sprintf('%02d%02d', $payment->getCcStartMonth(), substr($payment->getCcStartYear(), strlen($payment->getCcStartYear()) - 2))); } } $basket = Mage::helper('sagepaysuite')->getSagePayBasket($quoteObj, false); if (!empty($basket)) { if ($basket[0] == "<") { $request->setBasketXML($basket); } else { $request->setBasket($basket); } } if (!$request->getDeliveryPostCode()) { $request->setDeliveryPostCode('000'); } if (!$request->getBillingPostCode()) { $request->setBillingPostCode('000'); } return $request; }
protected function _buildRequest(Varien_Object $payment) { $order = $payment->getOrder(); $vendorTxCode = $this->_getTrnVendorTxCode(); $payment->setVendorTxCode($vendorTxCode); $_mode = $payment->getRequestMode() ? $payment->getRequestMode() : $this->getConfigData('mode'); $request = Mage::getModel('sagepaysuite/sagepaysuite_request')->setVPSProtocol($this->getVpsProtocolVersion($_mode))->setMode($_mode)->setReferrerID($this->getConfigData('referrer_id'))->setTxType($payment->getAnetTransType())->setInternalTxtype($payment->getAnetTransType())->setVendor($payment->getRequestVendor() ? $payment->getRequestVendor() : $this->getConfigData('vendor'))->setVendorTxCode($vendorTxCode)->setDescription($this->ss($payment->getCcOwner() ? $payment->getCcOwner() : '.', 100))->setClientIPAddress($this->getClientIp()); //basket $force_xml = false; if ($order->getPayment()->getMethodInstance()->getCode() == 'sagepaypaypal' && Mage::getStoreConfig('payment/sagepaypaypal/force_basketxml_paypal') == TRUE) { //force XML for paypal $force_xml = true; } $basket = Mage::helper('sagepaysuite')->getSagePayBasket($this->_getQuote(), $force_xml); if (!empty($basket)) { if ($basket[0] == "<") { $request->setBasketXML($basket); } else { $request->setBasket($basket); } } if ($request->getToken()) { $request->setData('store_token', 1); } if ($this->_getIsAdminOrder()) { $request->setAccountType('M'); } if ($payment->getAmountOrdered()) { $this->_setRequestCurrencyAmount($request, $this->_getQuote()); } else { Sage_Log::log('No amount on payment'); Mage::throwException('No amount on payment'); } if (!empty($order)) { //set billing address $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setBillingAddress($this->ss($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry(), 100))->setBillingSurname($this->ss($billing->getLastname(), 20))->setBillingFirstnames($this->ss($billing->getFirstname(), 20))->setBillingPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setBillingAddress1($this->ss($billing->getStreet(1), 100))->setBillingAddress2($this->ss($billing->getStreet(2), 100))->setBillingCity($this->ss($billing->getCity(), 40))->setBillingCountry($billing->getCountry())->setCustomerName($this->ss($billing->getFirstname() . ' ' . $billing->getLastname(), 100))->setContactNumber(substr($this->_cphone($billing->getTelephone()), 0, 20))->setContactFax($billing->getFax()); //billing state $billing_state = $billing->getRegionCode(); Mage::log($billing_state); if (!is_null($billing_state) && strlen($billing_state) > 2) { $billing_state = substr($billing_state, 0, 2); } if (!empty($billing_state)) { $request->setBillingState($billing_state); } Mage::log($billing_state); $request->setCustomerEMail($this->ss($billing->getEmail(), 255)); } //set shipping address if (!$order->getIsVirtual()) { $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $request->setDeliveryAddress($shipping->getStreet(1) . ' ' . $shipping->getCity() . ' ' . $shipping->getRegion() . ' ' . $shipping->getCountry())->setDeliverySurname($this->ss($shipping->getLastname(), 20))->setDeliveryFirstnames($this->ss($shipping->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($shipping->getPostcode(), 10)))->setDeliveryAddress1($this->ss($shipping->getStreet(1), 100))->setDeliveryAddress2($this->ss($shipping->getStreet(2), 100))->setDeliveryCity($this->ss($shipping->getCity(), 40))->setDeliveryCountry($shipping->getCountry()); //shipping state $shipping_state = $shipping->getRegionCode(); if (!is_null($shipping_state) && strlen($shipping_state) > 2) { $shipping_state = substr($shipping_state, 0, 2); } if (!empty($shipping_state)) { $request->setDeliveryState($shipping_state); } } } else { #If the cart only has virtual products, I need to put an shipping address to Sage Pay. #Then the billing address will be the shipping address to $request->setDeliveryAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setDeliverySurname($this->ss($billing->getLastname(), 20))->setDeliveryFirstnames($this->ss($billing->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setDeliveryAddress1($this->ss($billing->getStreet(1), 100))->setDeliveryAddress2($this->ss($billing->getStreet(2), 100))->setDeliveryCity($billing->getCity())->setDeliveryCountry($billing->getCountry()); //shipping state $shipping_state = $billing->getRegionCode(); if (!is_null($shipping_state) && strlen($shipping_state) > 2) { $shipping_state = substr($shipping_state, 0, 2); } if (!empty($shipping_state)) { $request->setDeliveryState($shipping_state); } } } if ($payment->getCcNumber()) { $request->setCardNumber($payment->getCcNumber())->setExpiryDate(sprintf('%02d%02d', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), strlen($payment->getCcExpYear()) - 2)))->setCardType($payment->getCcType())->setCV2($payment->getCcCid())->setCardHolder($payment->getCcOwner())->setNickname($payment->getCcNickname()); if ($payment->getCcIssue()) { $request->setIssueNumber($payment->getCcIssue()); } if ($payment->getCcStartMonth() && $payment->getCcStartYear()) { $request->setStartDate(sprintf('%02d%02d', $payment->getCcStartMonth(), substr($payment->getCcStartYear(), strlen($payment->getCcStartYear()) - 2))); } } else { if ($payment->getCcType() && $payment->getCcType() == parent::CARD_TYPE_PAYPAL) { $request->setCardType($payment->getCcType()); $request->setPayPalCallbackURL($this->_getPayPalCallbackUrl()); } } if (Mage::getSingleton('admin/session')->isLoggedIn() || $this->isMobile()) { $request->setApply3DSecure('2'); } else { if ($this->_isMultishippingCheckout()) { $request->setApply3DSecure('2'); } else { $request->setApply3DSecure($this->getConfigData('secure3d')); } } if ($request->getAccountType() != 'M' && $this->_forceCardChecking($payment->getCcType()) === true) { $request->setApply3DSecure('3'); } $request->setData('ApplyAVSCV2', $this->getConfigData('avscv2')); if ($payment->getCcGiftaid() == 1 || $payment->getCcGiftaid() == 'on') { $request->setData('GiftAidPayment', 1); } if (!$request->getDeliveryPostCode()) { $request->setDeliveryPostCode('000'); } if (!$request->getBillingPostCode()) { $request->setBillingPostCode('000'); } //Set to CreateToken if needed if ($this->_createToken() or $payment->getRemembertoken()) { if (!$request->setCreateToken(1, $payment->getCcNumber(), $request->getExpiryDate(), $payment->getCcType())) { $message = Mage::helper('sagepaysuite')->__('Credit card could not be saved for future use. You already have this card attached to your account or you have reached your account\'s maximum card storage capacity.'); Mage::getSingleton('core/session')->addWarning($message); } } $request->setWebsite(Mage::app()->getStore()->getWebsite()->getName()); //surcharge XML if (Mage::helper('sagepaysuite')->surchargesModuleEnabled() == true) { $surchargeXML = $this->getSurchargeXml($this->_getQuote()); if (!is_null($surchargeXML)) { $request->setSurchargeXML($surchargeXML); } } $customerXML = $this->getCustomerXml($this->_getQuote()); if (!is_null($customerXML)) { $request->setCustomerXML($customerXML); } //Skip PostCode and Address Validation for overseas orders if ((int) Mage::getStoreConfig('payment/sagepaysuite/apply_AVSCV2') === 1) { if ($this->_SageHelper()->isOverseasOrder($billing->getCountry())) { $request->setData('ApplyAVSCV2', 2); } } return $request; }
/** * Create new AccessCode * @param Varien_Object $billing * @param Varien_Object $infoInstance * @param string $method * @param null $request * @return Eway_Rapid31_Model_Response */ public function createAccessCode(Varien_Object $billing, Varien_Object $infoInstance, $method = 'AccessCodes', $request = null) { // Empty Varien_Object's data $tokenCustomerID = $request->get('TokenCustomerID'); $this->unsetData(); $customerParam = Mage::getModel('ewayrapid/field_customer'); $customerParam->setTokenCustomerID($tokenCustomerID)->setTitle($billing->getPrefix())->setFirstName($billing->getFirstname())->setLastName($billing->getLastname())->setCompanyName($billing->getCompany())->setJobDescription($billing->getJobDescription())->setStreet1($billing->getStreet1())->setStreet2($billing->getStreet2())->setCity($billing->getCity())->setState($billing->getRegion())->setPostalCode($billing->getPostcode())->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))->setEmail($billing->getEmail())->setPhone($billing->getTelephone())->setMobile($billing->getMobile())->setComments('')->setFax($billing->getFax())->setUrl(''); $returnUrl = Mage::getBaseUrl() . '/ewayrapid/mycards/saveToken?ccType=' . $infoInstance->getCcType() . '&expYear=' . $infoInstance->getCcExpYear(); if ($request->get('is_default') == 'on') { $returnUrl .= '&is_default=on'; } if ($infoInstance->getCcStartMonth()) { $returnUrl .= '&startMonth=' . $infoInstance->getCcStartMonth(); } if ($infoInstance->getCcStartYear()) { $returnUrl .= '&startYear=' . $infoInstance->getCcStartYear(); } if ($infoInstance->getCcIssueNumber()) { $returnUrl .= '&issueNumber=' . $infoInstance->getCcIssueNumber(); } // Binding address on url param $returnUrl .= '&street1=' . base64_encode($billing->getStreet1()) . '&street2=' . base64_encode($billing->getStreet2()); $tokenId = $request->get('token_id'); if (!empty($tokenId)) { // ID token customer will be defined to update $returnUrl = $returnUrl . '&token_id=' . $tokenId; } $this->setCustomer($customerParam); $this->setRedirectUrl($returnUrl); $this->setCancelUrl($returnUrl); $this->setMethod(!empty($tokenCustomerID) ? 'UpdateTokenCustomer' : 'CreateTokenCustomer'); $this->setCustomerIP($_SERVER["REMOTE_ADDR"]); $this->setDeviceID(''); $this->setTransactionType("Purchase"); $this->setCustomerReadOnly(true); // Create new access code //$formMethod = !empty($tokenCustomerID) ? 'PUT' : 'POST'; $response = $this->_doRapidAPI($method); return $response; }
protected function _buildRequest(Varien_Object $payment) { $order = $payment->getOrder(); $vendorTxCode = $this->_getTrnVendorTxCode(); $payment->setVendorTxCode($vendorTxCode); $request = Mage::getModel('sagepaysuite/sagepaysuite_request')->setVPSProtocol($this->getVpsProtocolVersion())->setMode($payment->getRequestMode() ? $payment->getRequestMode() : $this->getConfigData('mode'))->setReferrerID($this->getConfigData('referrer_id'))->setTxType($payment->getAnetTransType())->setInternalTxtype($payment->getAnetTransType())->setVendor($payment->getRequestVendor() ? $payment->getRequestVendor() : $this->getConfigData('vendor'))->setVendorTxCode($vendorTxCode)->setDescription($this->ss($payment->getCcOwner() ? $payment->getCcOwner() : '.', 100))->setClientIPAddress($this->getClientIp()); if ($this->getSendBasket()) { $request->setBasket($this->_getBasketContents($this->_getQuote())); } if ($request->getToken()) { $request->setData('store_token', 1); } if ($this->_getIsAdminOrder()) { $request->setAccountType('M'); } if ($payment->getAmountOrdered()) { $this->_setRequestCurrencyAmount($request, $this->_getQuote()); } else { Mage::throwException('No amount on payment'); Ebizmarts_SagePaySuite_Log::w('No amount on payment'); } if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setBillingAddress($this->ss($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry(), 100))->setBillingSurname($this->ss($billing->getLastname(), 20))->setBillingFirstnames($this->ss($billing->getFirstname(), 20))->setBillingPostCode($this->ss($billing->getPostcode(), 10))->setBillingAddress1($this->ss($billing->getStreet(1), 100))->setBillingAddress2($this->ss($billing->getStreet(2), 100))->setBillingCity($this->ss($billing->getCity(), 40))->setBillingCountry($billing->getCountry())->setCustomerName($this->ss($billing->getLastname() . ' ' . $billing->getFirstname(), 100))->setContactNumber(substr($this->_cphone($billing->getTelephone()), 0, 20))->setContactFax($billing->getFax()); if ($billing->getCountry() == 'US') { $request->setBillingState($billing->getRegionCode()); } $request->setCustomerEMail($this->ss($billing->getEmail(), 255)); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $request->setDeliveryAddress($shipping->getStreet(1) . ' ' . $shipping->getCity() . ' ' . $shipping->getRegion() . ' ' . $shipping->getCountry())->setDeliverySurname($this->ss($shipping->getLastname(), 20))->setDeliveryFirstnames($this->ss($shipping->getFirstname(), 20))->setDeliveryPostCode($this->ss($shipping->getPostcode(), 10))->setDeliveryAddress1($this->ss($shipping->getStreet(1), 100))->setDeliveryAddress2($this->ss($shipping->getStreet(2), 100))->setDeliveryCity($this->ss($shipping->getCity(), 40))->setDeliveryCountry($shipping->getCountry()); if ($shipping->getCountry() == 'US') { $request->setDeliveryState($shipping->getRegionCode()); } } else { #If the cart only has virtual products, I need to put an shipping address to Sage Pay. #Then the billing address will be the shipping address to $request->setDeliveryAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setDeliverySurname($this->ss($billing->getLastname(), 20))->setDeliveryFirstnames($this->ss($billing->getFirstname(), 20))->setDeliveryPostCode($this->ss($billing->getPostcode(), 10))->setDeliveryAddress1($this->ss($billing->getStreet(1), 100))->setDeliveryAddress2($this->ss($billing->getStreet(2), 100))->setDeliveryCity($billing->getCity())->setDeliveryCountry($billing->getCountry()); if ($billing->getCountry() == 'US') { $request->setDeliveryState($billing->getRegionCode()); } } } if ($payment->getCcNumber()) { $request->setCardNumber($payment->getCcNumber())->setExpiryDate(sprintf('%02d%02d', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), strlen($payment->getCcExpYear()) - 2)))->setCardType($payment->getCcType())->setCV2($payment->getCcCid())->setCardHolder($payment->getCcOwner()); if ($payment->getCcIssue()) { $request->setIssueNumber($payment->getCcIssue()); } if ($payment->getCcStartMonth() && $payment->getCcStartYear()) { $request->setStartDate(sprintf('%02d%02d', $payment->getCcStartMonth(), substr($payment->getCcStartYear(), strlen($payment->getCcStartYear()) - 2))); } } else { if ($payment->getCcType() && $payment->getCcType() == parent::CARD_TYPE_PAYPAL) { $request->setCardType($payment->getCcType()); $request->setPayPalCallbackURL($this->_getPayPalCallbackUrl()); } } if (Mage::getSingleton('admin/session')->isLoggedIn() || $this->isMobile()) { $request->setApply3DSecure('2'); } else { if ($this->_isMultishippingCheckout()) { $request->setApply3DSecure('2'); } else { $request->setApply3DSecure($this->getConfigData('secure3d')); } } if ($request->getAccountType() != 'M' && $this->_forceCardChecking($payment->getCcType()) === true) { $request->setApply3DSecure('3'); } $request->setData('ApplyAVSCV2', $this->getConfigData('avscv2')); if ($payment->getCcGiftaid() == 1 || $payment->getCcGiftaid() == 'on') { $request->setData('GiftAidPayment', 1); } if (!$request->getDeliveryPostCode()) { $request->setDeliveryPostCode('000'); } if (!$request->getBillingPostCode()) { $request->setBillingPostCode('000'); } return $request; }
/** * Return commno data for *all* transactions. * @return array Data */ public function _getGeneralTrnData(Varien_Object $payment) { $order = $payment->getOrder(); $quoteObj = $this->_getQuote(); $vendorTxCode = $this->_getTrnVendorTxCode(); if ($payment->getCcNumber()) { $vendorTxCode .= $this->_cleanString(substr($payment->getCcOwner(), 0, 10)); } $payment->setVendorTxCode($vendorTxCode); $request = new Varien_Object(); $request->setVPSProtocol('2.23')->setReferrerID($this->getConfigData('referrer_id'))->setVendor($this->getConfigData('vendor'))->setVendorTxCode($vendorTxCode); $request->setClientIPAddress($this->getClientIp()); if ($payment->getIntegra()) { $this->getSageSuiteSession()->setLastVendorTxCode($vendorTxCode); $request->setIntegration($payment->getIntegra()); $request->setData('notification_URL', $this->getNotificationUrl() . '&vtxc=' . $vendorTxCode); $request->setData('success_URL', $this->getSuccessUrl()); $request->setData('redirect_URL', $this->getRedirectUrl()); $request->setData('failure_URL', $this->getFailureUrl()); } if ($this->_getIsAdminOrder()) { $request->setAccountType('M'); } if ($payment->getAmountOrdered()) { $from = $order->getOrderCurrencyCode(); if ((string) $this->getConfigData('trncurrency') == 'store') { $request->setAmount($this->formatAmount($quoteObj->getGrandTotal(), $quoteObj->getQuoteCurrencyCode())); $request->setCurrency($quoteObj->getQuoteCurrencyCode()); } else { $request->setAmount($this->formatAmount($quoteObj->getBaseGrandTotal(), $quoteObj->getBaseCurrencyCode())); $request->setCurrency($quoteObj->getBaseCurrencyCode()); } } if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setBillingAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setBillingSurname($this->ss($billing->getLastname(), 20))->setBillingFirstnames($this->ss($billing->getFirstname(), 20))->setBillingPostCode($this->ss($billing->getPostcode(), 10))->setBillingAddress1($this->ss($billing->getStreet(1), 100))->setBillingAddress2($this->ss($billing->getStreet(2), 100))->setBillingCity($this->ss($billing->getCity(), 40))->setBillingCountry($billing->getCountry())->setContactNumber(substr($this->_cphone($billing->getTelephone()), 0, 20)); if ($billing->getCountry() == 'US') { $request->setBillingState($billing->getRegionCode()); } $request->setCustomerEMail($billing->getEmail()); } if (!$request->getDescription()) { $request->setDescription('.'); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $request->setDeliveryAddress($shipping->getStreet(1) . ' ' . $shipping->getCity() . ' ' . $shipping->getRegion() . ' ' . $shipping->getCountry())->setDeliverySurname($this->ss($shipping->getLastname(), 20))->setDeliveryFirstnames($this->ss($shipping->getFirstname(), 20))->setDeliveryPostCode($this->ss($shipping->getPostcode(), 10))->setDeliveryAddress1($this->ss($shipping->getStreet(1), 100))->setDeliveryAddress2($this->ss($shipping->getStreet(2), 100))->setDeliveryCity($this->ss($shipping->getCity(), 40))->setDeliveryCountry($shipping->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($shipping->getTelephone())), 20)); if ($shipping->getCountry() == 'US') { $request->setDeliveryState($shipping->getRegionCode()); } } else { #If the cart only has virtual products, I need to put an shipping address to Sage Pay. #Then the billing address will be the shipping address to $request->setDeliveryAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setDeliverySurname($this->ss($billing->getLastname(), 20))->setDeliveryFirstnames($this->ss($billing->getFirstname(), 20))->setDeliveryPostCode($this->ss($billing->getPostcode(), 10))->setDeliveryAddress1($this->ss($billing->getStreet(1), 100))->setDeliveryAddress2($this->ss($billing->getStreet(2), 100))->setDeliveryCity($this->ss($billing->getCity(), 40))->setDeliveryCountry($billing->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($billing->getTelephone())), 20)); if ($billing->getCountry() == 'US') { $request->setDeliveryState($billing->getRegionCode()); } } } if ($payment->getCcNumber()) { $request->setCardNumber($payment->getCcNumber())->setExpiryDate(sprintf('%02d%02d', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), strlen($payment->getCcExpYear()) - 2)))->setCardType($payment->getCcType())->setCV2($payment->getCcCid())->setCardHolder($payment->getCcOwner()); if ($payment->getCcIssue()) { $request->setIssueNumber($payment->getCcIssue()); } if ($payment->getCcStartMonth() && $payment->getCcStartYear()) { $request->setStartDate(sprintf('%02d%02d', $payment->getCcStartMonth(), substr($payment->getCcStartYear(), strlen($payment->getCcStartYear()) - 2))); } } $totals = $shipping->getTotals(); $shippingTotal = isset($totals['shipping']) ? $totals['shipping']->getValue() : 0; if ($this->getSendBasket()) { $request->setBasket($this->_getBasketContents($quoteObj)); } if (!$request->getDeliveryPostCode()) { $request->setDeliveryPostCode('000'); } if (!$request->getBillingPostCode()) { $request->setBillingPostCode('000'); } return $request; }