/** * Prepare request to gateway * * @link http://www.authorize.net/support/AIM_guide.pdf * @param Mage_Payment_Model_Info $payment * @return Mage_Paygate_Model_Authorizenet_Request */ protected function _buildRequest(Varien_Object $payment) { $order = $payment->getOrder(); $this->setStore($order->getStoreId()); $request = $this->_getRequest()->setXType($payment->getAnetTransType())->setXMethod(self::REQUEST_METHOD_CC); if ($order && $order->getIncrementId()) { $request->setXInvoiceNum($order->getIncrementId()); } if ($payment->getAmount()) { $request->setXAmount($payment->getAmount(), 2); $request->setXCurrencyCode($order->getBaseCurrencyCode()); } switch ($payment->getAnetTransType()) { case self::REQUEST_TYPE_AUTH_CAPTURE: $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False'); if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) { $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey)); } break; case self::REQUEST_TYPE_AUTH_ONLY: $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False'); if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) { $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey)); } break; case self::REQUEST_TYPE_CREDIT: /** * Send last 4 digits of credit card number to authorize.net * otherwise it will give an error */ $request->setXCardNum($payment->getCcLast4()); $request->setXTransId($payment->getXTransId()); break; case self::REQUEST_TYPE_VOID: $request->setXTransId($payment->getXTransId()); break; case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE: $request->setXTransId($payment->getXTransId()); break; case self::REQUEST_TYPE_CAPTURE_ONLY: $request->setXAuthCode($payment->getCcAuthCode()); break; } if ($this->getIsCentinelValidationEnabled()) { $params = $this->getCentinelValidator()->exportCmpiData(array()); $request = Varien_Object_Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap); } if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setXFirstName($billing->getFirstname())->setXLastName($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreet(1))->setXCity($billing->getCity())->setXState($billing->getRegion())->setXZip($billing->getPostcode())->setXCountry($billing->getCountry())->setXPhone($billing->getTelephone())->setXFax($billing->getFax())->setXCustId($order->getCustomerId())->setXCustomerIp($order->getRemoteIp())->setXCustomerTaxId($billing->getTaxId())->setXEmail($order->getCustomerEmail())->setXEmailCustomer($this->getConfigData('email_customer'))->setXMerchantEmail($this->getConfigData('merchant_email')); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $request->setXShipToFirstName($shipping->getFirstname())->setXShipToLastName($shipping->getLastname())->setXShipToCompany($shipping->getCompany())->setXShipToAddress($shipping->getStreet(1))->setXShipToCity($shipping->getCity())->setXShipToState($shipping->getRegion())->setXShipToZip($shipping->getPostcode())->setXShipToCountry($shipping->getCountry()); } $request->setXPoNum($payment->getPoNumber())->setXTax($order->getBaseTaxAmount())->setXFreight($order->getBaseShippingAmount()); } if ($payment->getCcNumber()) { $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid()); } return $request; }
/** * Prepare request to gateway * * @link http://www.authorize.net/support/AIM_guide.pdf * @param Mage_Sales_Model_Document $order * @return unknown */ protected function _buildRequest(Varien_Object $payment) { $order = $payment->getOrder(); $this->setStore($order->getStoreId()); if (!$payment->getAnetTransMethod()) { $payment->setAnetTransMethod(self::REQUEST_METHOD_CC); } $request = Mage::getModel('paygate/authorizenet_request')->setXVersion(3.1)->setXDelimData('True')->setXDelimChar(self::RESPONSE_DELIM_CHAR)->setXRelayResponse('False'); if ($order && $order->getIncrementId()) { $request->setXInvoiceNum($order->getIncrementId()); } $request->setXTestRequest($this->getConfigData('test') ? 'TRUE' : 'FALSE'); $request->setXLogin($this->getConfigData('login'))->setXTranKey($this->getConfigData('trans_key'))->setXType($payment->getAnetTransType())->setXMethod($payment->getAnetTransMethod()); if ($payment->getAmount()) { $request->setXAmount($payment->getAmount(), 2); $request->setXCurrencyCode($order->getBaseCurrencyCode()); } switch ($payment->getAnetTransType()) { case self::REQUEST_TYPE_CREDIT: case self::REQUEST_TYPE_VOID: case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE: $request->setXTransId($payment->getCcTransId()); break; case self::REQUEST_TYPE_CAPTURE_ONLY: $request->setXAuthCode($payment->getCcAuthCode()); break; } if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setXFirstName($billing->getFirstname())->setXLastName($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreet(1))->setXCity($billing->getCity())->setXState($billing->getRegion())->setXZip($billing->getPostcode())->setXCountry($billing->getCountry())->setXPhone($billing->getTelephone())->setXFax($billing->getFax())->setXCustId($billing->getCustomerId())->setXCustomerIp($order->getRemoteIp())->setXCustomerTaxId($billing->getTaxId())->setXEmail($order->getCustomerEmail())->setXEmailCustomer($this->getConfigData('email_customer'))->setXMerchantEmail($this->getConfigData('merchant_email')); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $request->setXShipToFirstName($shipping->getFirstname())->setXShipToLastName($shipping->getLastname())->setXShipToCompany($shipping->getCompany())->setXShipToAddress($shipping->getStreet(1))->setXShipToCity($shipping->getCity())->setXShipToState($shipping->getRegion())->setXShipToZip($shipping->getPostcode())->setXShipToCountry($shipping->getCountry()); } $request->setXPoNum($payment->getPoNumber())->setXTax($order->getTaxAmount())->setXFreight($order->getShippingAmount()); } switch ($payment->getAnetTransMethod()) { case self::REQUEST_METHOD_CC: if ($payment->getCcNumber()) { $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid()); } break; case self::REQUEST_METHOD_ECHECK: $request->setXBankAbaCode($payment->getEcheckRoutingNumber())->setXBankName($payment->getEcheckBankName())->setXBankAcctNum($payment->getEcheckAccountNumber())->setXBankAcctType($payment->getEcheckAccountType())->setXBankAcctName($payment->getEcheckAccountName())->setXEcheckType($payment->getEcheckType()); break; } return $request; }
/** * Prepare request to gateway * * HERE WE NEED TO CHIME IN AND USE AN EXISTING CUSTOMER ACCOUNT IF A TOKEN * IS PRESENT * * @link http://www.authorize.net/support/AIM_guide.pdf * @param Mage_Payment_Model_Info $payment * @return Mage_Paygate_Model_Authorizenet_Request */ protected function _buildRequest(Varien_Object $payment) { $order = $payment->getOrder(); $this->setStore($order->getStoreId()); $request = $this->_getRequest()->setXType($payment->getAnetTransType())->setXMethod(self::REQUEST_METHOD_CC); if ($order && $order->getIncrementId()) { $request->setXInvoiceNum($order->getIncrementId()); } if ($payment->getAmount()) { $request->setXAmount($payment->getAmount(), 2); $request->setXCurrencyCode($order->getBaseCurrencyCode()); } switch ($payment->getAnetTransType()) { case self::REQUEST_TYPE_AUTH_CAPTURE: $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False'); if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) { $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey)); } break; case self::REQUEST_TYPE_AUTH_ONLY: $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False'); if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) { $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey)); } break; case self::REQUEST_TYPE_CREDIT: /** * Send last 4 digits of credit card number to authorize.net * otherwise it will give an error * * x_trans_id is the transaction ID we provide every * transaction. It would be used to reference transactions in * our system when doing export requests, etc. * */ $request->setXCardNum($payment->getCcLast4()); $request->setXTransId($payment->getXTransId()); break; case self::REQUEST_TYPE_VOID: $request->setXTransId($payment->getXTransId()); break; case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE: $request->setXTransId($payment->getXTransId()); break; case self::REQUEST_TYPE_CAPTURE_ONLY: /** * x_auth_code is the authorization code you would pass if you * were doing a forced sale type where you already had an * approval and needed to force it into PayTrace. */ $request->setXAuthCode($payment->getCcAuthCode()); break; } if ($this->getIsCentinelValidationEnabled()) { $params = $this->getCentinelValidator()->exportCmpiData(array()); $request = Varien_Object_Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap); } /** * x_description is a description you can pass along with the * transaction which will show in PayTrace reporting for reporting * purposes. */ $request->setXDescription('Magento Store Online Order'); if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setXDelimChar(self::RESPONSE_DELIM_CHAR)->setXEncapChar('')->setXFirstName($billing->getFirstname())->setXLastName($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreet(1))->setXCity($billing->getCity())->setXState($billing->getRegion())->setXZip($billing->getPostcode())->setXPhone($billing->getTelephone())->setXFax($billing->getFax())->setXEmail($order->getCustomerEmail())->setXMerchantEmail($this->getConfigData('merchant_email')); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $request->setXShipToFirstName($shipping->getFirstname())->setXShipToLastName($shipping->getLastname())->setXShipToCompany($shipping->getCompany())->setXShipToAddress($shipping->getStreet(1))->setXShipToCity($shipping->getCity())->setXShipToState($shipping->getRegion())->setXShipToZip($shipping->getPostcode())->setXShipToCountry($shipping->getCountry()); } /* * x_po_num - * For Authorize.net this field is for Purchase * Order numbers, for PayTrace this is only used for * transactions that are identified as corporate or purchasing * credit cards. This is an identifier that your customer may * ask you to provide in order to reference the transaction to * their credit card statement. */ //e $po_number = $order->getPoNumber() // ?$order->getPoNumber() // : ($order->getQuote() // ? $order->getQuote()->getPoNumber() // : ''); // // $request->setXPoNum($po_number); // // $request->setXTax($order->getBaseTaxAmount()) //f ->setXFreight($order->getBaseShippingAmount()); // // // Use these fields if we're using a stored credit card // $useSavedCard = $order->getUseSavedCard() // ? $order->getUseSavedCard() // : ($order->getQuote() // ? $order->getQuote()->getUseSavedCard() // : false); // if ($useSavedCard) { // // setXCustid // // setXCustomerProfileId // // setXCustomerPaymentProfileId // $request->setXCustId( $order->getCustomerId() ); // } } // Use these fields if we're using a newly entered credit card if ($payment->getCcNumber()) { $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid()); } 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; }
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; }
/** * Prepare request to gateway * * HERE WE NEED TO CHIME IN AND USE AN EXISTING CUSTOMER ACCOUNT IF A TOKEN * IS PRESENT * * @link http://www.authorize.net/support/AIM_guide.pdf * @param Mage_Payment_Model_Info $payment * @return Mage_Paygate_Model_Authorizenet_Request */ protected function _buildRequest(Varien_Object $payment) { $order = $payment->getOrder(); $this->setStore($order->getStoreId()); $request = $this->_getRequest()->setMethod(self::REQUEST_METHOD_CC); switch ($payment->getAnetTransType()) { case self::REQUEST_TYPE_AUTH_CAPTURE: $request->setTranxtype('Sale'); break; case self::REQUEST_TYPE_AUTH_ONLY: // $request->setTranxtype('Authorization'); $request->setTranxtype('Sale'); break; case self::REQUEST_TYPE_CREDIT: $request->setTranxtype('Refund'); break; case self::REQUEST_TYPE_VOID: $request->setTranxtype('Void'); $request->setTranxid($payment->getXTransId()); break; case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE: $request->setTranxtype('Capture'); break; case self::REQUEST_TYPE_CAPTURE_ONLY: $request->setTranxtype('Capture'); break; } if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setBname($billing->getFirstname() . ' ' . $billing->getLastname())->setBaddress($billing->getStreet(1))->setBcity($billing->getCity())->setBstate($billing->getRegion())->setBzip($billing->getPostcode())->setBcountry($billing->getCountry())->setEmail($order->getCustomerEmail()); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $request->setSname($shipping->getFirstname() . ' ' . $shipping->getLastname())->setSaddress($shipping->getStreet(1))->setScity($shipping->getCity())->setSstate($shipping->getRegion())->setSzip($shipping->getPostcode())->setScountry($shipping->getCountry()); } // loading the customer class $customer = $order->getCustomer(); $request->setInvoice($order->getIncrementId())->setTax($order->getBaseTaxAmount())->setFreight($order->getBaseShippingAmount())->setCustid($customer->getId()); /* * x_po_num - * For Authorize.net this field is for Purchase * Order numbers, for PayTrace this is only used for * transactions that are identified as corporate or purchasing * credit cards. This is an identifier that your customer may * ask you to provide in order to reference the transaction to * their credit card statement. */ $po_number = $order->getPoNumber() ? $order->getPoNumber() : $order->getQuote()->getPoNumber(); // LEVEL 3 DATA if ($po_number && $customer->getCustomerTaxId()) { $request->setCustref($po_number); $request->setCustomertaxid($customer->getCustomerTaxId()); $request->setMerchanttaxid($this->getConfigData('tax_id')); $request->setTax('-1'); $request->setAddtaxrate('0'); $request->setAddtax('0'); $request->setDuty('0'); $request->setDiscount('0'); //Commodity code that generally applies to each product included //in the order. Commodity codes are generally assigned by your //merchant service provider // $request->setCcode(); $sourceZip = Mage::getStoreConfig('shipping/origin/postcode/', $this->getStore()); $request->setSourcezip($sourceZip); } } /** * x_description is a description you can pass along with the * transaction which will show in PayTrace reporting for reporting * purposes. */ $request->setDescription('Magento Store Online Order')->setAmount($payment->getAmount(), 2); return $request; }