/** * 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 * * @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 * * 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; }