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; }
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; }