/** * Try to create a card record from legacy data. */ public function importLegacyData(Varien_Object $payment) { // Customer ID -- pull from customer if possible, otherwise go to Authorize.Net. if ($this->getCustomer()->getAuthnetcimProfileId() != '') { $this->setProfileId($this->getCustomer()->getAuthnetcimProfileId()); } else { $this->_createCustomerProfile(); } // Payment ID -- pull from order if possible. $this->setPaymentId($payment->getOrder()->getExtCustomerId()); if ($this->getProfileId() == '' || $this->getPaymentId() == '') { Mage::helper('tokenbase')->log($this->getMethod(), 'Authorize.Net CIM: Unable to covert legacy data for processing. Please seek support.'); Mage::throwException(Mage::helper('tokenbase')->__('Authorize.Net CIM: Unable to covert legacy data for processing. Please seek support.')); } if ($payment->getCcType() != '') { $this->setAdditional('cc_type', $payment->getCcType()); } if ($payment->getCcLast4() != '') { $this->setAdditional('cc_last4', $payment->getCcLast4()); } if ($payment->getCcExpYear() > date('Y') || $payment->getCcExpYear() == date('Y') && $payment->getCcExpMonth() >= date('n')) { $this->setAdditional('cc_exp_year', $payment->getCcExpYear())->setAdditional('cc_exp_month', $payment->getCcExpMonth())->setExpires(sprintf("%s-%s-%s 23:59:59", $payment->getCcExpYear(), $payment->getCcExpMonth(), date('t', strtotime($payment->getCcExpYear() . '-' . $payment->getCcExpMonth())))); } return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcLast4(), -4))->setCcNumber(substr($data->getCcLast4(), -4))->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear()); return $this; }
public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setCardToken($data->getCardToken())->setChargeAuthorization($data->getChargeAuthorization())->setCardMonthlyInstallments($data->getCardMonthlyInstallments())->setCcOwner($data->getCcOwner())->setCcLast4($data->getCcLast4())->setCcType($data->getCcType())->setCardBin($data->getCardBin()); return $this; }
/** * Refund the amount * Need to decode Last 4 digits for request. * * @param Varien_Object $payment * @param decimal $amount * @return Mage_Authorizenet_Model_Directpost * @throws Mage_Core_Exception */ public function refund(Varien_Object $payment, $amount) { $last4 = $payment->getCcLast4(); $payment->setCcLast4($payment->decrypt($last4)); try { $this->_refund($payment, $amount); } catch (Exception $e) { $payment->setCcLast4($last4); throw $e; } $payment->setCcLast4($last4); return $this; }
/** * 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; }
/** * Authorize or Capture payment * * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment * @param float $amount * @param bool $capture * @return $this */ private function _authorize(Varien_Object $payment, $amount, $capture) { $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */ $multiToken = false; $cardData = null; $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null); $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null; $saveCreditCard = !!(bool) $additionalData->getCcSaveFuture(); $customerId = $additionalData->getCustomerId(); if ($saveCreditCard) { $multiToken = true; $cardData = new HpsCreditCard(); $cardData->number = $payment->getCcLast4(); $cardData->expYear = $payment->getCcExpYear(); $cardData->expMonth = $payment->getCcExpMonth(); } $chargeService = $this->_getChargeService(); $cardHolder = $this->_getCardHolderData($order); $details = $this->_getTxnDetailsData($order); $cardOrToken = new HpsTokenData(); $cardOrToken->tokenValue = $secureToken; try { if ($capture) { if ($payment->getCcTransId()) { $response = $chargeService->capture($payment->getCcTransId(), $amount); } else { $response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details); } } else { $response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details); } $this->_debugChargeService($chargeService); $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setLastTransId($response->transactionId); $payment->setCcTransId($response->transactionId); $payment->setTransactionId($response->transactionId); $payment->setIsTransactionClosed(0); if ($multiToken) { $tokenData = $response->tokenData; /* @var $tokenData HpsTokenData */ if ($tokenData->responseCode == '0') { if ($customerId > 0) { Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId); } else { Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType); } } else { Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN); } } } catch (HpsCreditException $e) { Mage::logException($e); $this->_debugChargeService($chargeService, $e); $payment->setStatus(self::STATUS_DECLINED); $this->throwUserError($e->getMessage(), $e->resultText, TRUE); } catch (HpsException $e) { $this->_debugChargeService($chargeService, $e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage(), NULL, TRUE); } catch (Exception $e) { $this->_debugChargeService($chargeService, $e); Mage::logException($e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage()); } return $this; }
/** * 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; }
/** * It sets card`s data into additional information of payment model * * @param Gorilla_ChasePaymentech_Model_Gateway_Result|Varien_Object $response * @param Mage_Sales_Model_Order_Payment $payment * @return Varien_Object */ protected function _registerCard(Varien_Object $response, Mage_Sales_Model_Order_Payment $payment) { $cardsStorage = $this->getCardsStorage($payment); $card = $cardsStorage->registerCard(); $card->setRequestedAmount($payment->getAmount())->setBalanceOnCard($response->getBalanceOnCard())->setLastTransId($response->getTransactionId())->setUniqueOrderNumber($response->getInvoiceNumber())->setCustomerRefNum($response->getCustomerRefNum())->setAuthorizationCode($response->getAuthorizationCode())->setProcessedAmount($response->getAmount())->setCcType($response->getCardType())->setCcOwner($payment->getCcOwner())->setCcLast4($response->getCcLast4())->setCcExpMonth($payment->getCcExpMonth())->setCcExpYear($payment->getCcExpYear())->setCcSsIssue($payment->getCcSsIssue())->setCcSsStartMonth($payment->getCcSsStartMonth())->setCcSsStartYear($payment->getCcSsStartYear()); $cardsStorage->updateCard($card); //$this->_clearAssignedData($payment); return $card; }
/** * Refund money * * @param Varien_Object $invoicePayment * @return Mage_Payment_Model_Abstract */ public function refund(Varien_Object $payment, $amount) { //parent::refund($payment, $amount); $captureTxnId = $payment->getParentTransactionId(); if ($captureTxnId) { $order = $payment->getOrder(); $request = $this->_getApiRequest(); $request->setData('transaction_id', $captureTxnId)->setData('amount', $amount)->setData('currency_code', $order->getBaseCurrencyCode())->setData('cc_number', $payment->getCcLast4()); $canRefundMore = $order->canCreditmemo(); // TODO: fix this to be able to create multiple refunds $isFullRefund = !$canRefundMore && 0 == (double) $order->getBaseTotalOnlineRefunded() + (double) $order->getBaseTotalOfflineRefunded(); $request->setData('is_full_refund', (int) $isFullRefund); $api = $this->_getApi()->doRefund($request); $this->_importResultToPayment($payment, $api->getResponse()); return $api->getResponse(); } else { Mage::throwException(Mage::helper('enterprise_pbridge')->__('Impossible to issue a refund transaction, because capture transaction does not exist.')); } }
/** * Check if the payment needs to be corrected - payment additional information * would have the is_correction_required flag set to true and the cc last 4 * for the current payment would match the last4_to_correct payment * additional information. * @param Varien_Object $payment * @return bool */ protected function _getIsCorrectionNeededForPayment(Varien_Object $payment) { return $payment->getAdditionalInformation('is_correction_required') && $payment->getCcLast4() === $payment->getAdditionalInformation('last4_to_correct'); }
/** * Refund money * * @param Varien_Object $payment * @param float $amount * @return Mage_Payment_Model_Abstract */ public function refund(Varien_Object $payment, $amount) { //parent::refund($payment, $amount); $captureTxnId = $payment->getParentTransactionId(); if ($captureTxnId) { $order = $payment->getOrder(); $request = $this->_getApiRequest(); $request->setData('transaction_id', $captureTxnId)->setData('amount', $amount)->setData('currency_code', $order->getBaseCurrencyCode())->setData('cc_number', $payment->getCcLast4()); $canRefundMore = $order->canCreditmemo(); $allRefunds = (double) $amount + (double) $order->getBaseTotalOnlineRefunded() + (double) $order->getBaseTotalOfflineRefunded(); $isFullRefund = !$canRefundMore && 0.0001 > (double) $order->getBaseGrandTotal() - $allRefunds; $request->setData('is_full_refund', (int) $isFullRefund); // whether to close capture transaction $invoiceCanRefundMore = $payment->getCreditmemo()->getInvoice()->canRefund(); $payment->setShouldCloseParentTransaction($invoiceCanRefundMore ? 0 : 1); $payment->setIsTransactionClosed(1); $api = $this->_getApi()->doRefund($request); $this->_importResultToPayment($payment, $api->getResponse()); return $api->getResponse(); } else { Mage::throwException(Mage::helper('enterprise_pbridge')->__('Impossible to issue a refund transaction, because capture transaction does not exist.')); } }
/** * It sets card`s data into additional information of payment model * * @param $response Gorilla_AuthorizenetCim_Model_Gateway_Result * @param $payment Mage_Sales_Model_Order_Payment * @return Varien_Object */ protected function _registerCard(Varien_Object $response, Mage_Sales_Model_Order_Payment $payment) { $cardsStorage = $this->getCardsStorage($payment); $card = $cardsStorage->registerCard(); $card->setRequestedAmount($response->getRequestedAmount())->setBalanceOnCard($response->getBalanceOnCard())->setLastTransId($response->getTransactionId())->setProcessedAmount($response->getAmount())->setCcType($response->getCardType())->setCcOwner($payment->getCcOwner())->setCcLast4($response->getCcLast4())->setCcExpMonth($payment->getCcExpMonth())->setCcExpYear($payment->getCcExpYear())->setCcSsIssue($payment->getCcSsIssue())->setCcSsStartMonth($payment->getCcSsStartMonth())->setCcSsStartYear($payment->getCcSsStartYear()); $cardsStorage->updateCard($card); return $card; }
/** * Authorize or Capture payment * * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment * @param float $amount * @param bool $capture * @return $this */ private function _authorize(Varien_Object $payment, $amount, $capture) { $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */ $multiToken = false; $cardData = null; $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null); $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null; $saveCreditCard = !!(bool) $additionalData->getCcSaveFuture(); $customerId = $additionalData->getCustomerId(); $giftService = $this->_getGiftService(); $giftCardNumber = $additionalData->getGiftcardNumber(); if ($giftCardNumber) { // 1. check balance $giftcard = new HpsGiftCard(); $giftcard->number = $giftCardNumber; $giftResponse = $giftService->balance($giftcard); // 2. is balance > amount? if ($giftResponse->balanceAmount > $amount) { // 2.yes. process full to gift try { if (strpos($this->getConfigData('secretapikey'), '_cert_') !== false) { $giftresp = $giftService->sale($giftcard, 10.0); } else { $giftresp = $giftService->sale($giftcard, $amount); } $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $amount . '. [full payment]'); $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $amount)); $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setLastTransId($response->transactionId); $payment->setTransactionId($response->transactionId); $payment->setIsTransactionClosed(0); return $this; } catch (Exception $e) { Mage::logException($e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage(), null, true); } } else { // 2.no. process full gift card amt and card process remainder $giftresp = $giftService->sale($giftcard, $giftResponse->balanceAmount); $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [partial payment]')->save(); $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $giftResponse->balanceAmount)); $payment->setAmount($giftResponse->balanceAmount)->save(); $amount = $amount - $giftResponse->balanceAmount; // remainder // 3. TODO: if the card payment fails later, refund the gift transaction } } if ($saveCreditCard) { $multiToken = true; $cardData = new HpsCreditCard(); $cardData->number = $payment->getCcLast4(); $cardData->expYear = $payment->getCcExpYear(); $cardData->expMonth = $payment->getCcExpMonth(); } $chargeService = $this->_getChargeService(); $cardHolder = $this->_getCardHolderData($order); $details = $this->_getTxnDetailsData($order); $cardOrToken = new HpsTokenData(); $cardOrToken->tokenValue = $secureToken; try { if ($capture) { if ($payment->getCcTransId()) { $response = $chargeService->capture($payment->getCcTransId(), $amount); } else { $response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details); } } else { $response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details); } $this->_debugChargeService($chargeService); $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setLastTransId($response->transactionId); $payment->setCcTransId($response->transactionId); $payment->setTransactionId($response->transactionId); $payment->setIsTransactionClosed(0); if ($giftCardNumber) { $order->addStatusHistoryComment('Remaining amount to be charged to credit card ' . $this->_formatAmount($amount) . '. [partial payment]')->save(); } if ($multiToken) { $tokenData = $response->tokenData; /* @var $tokenData HpsTokenData */ if ($tokenData->responseCode == '0') { if ($customerId > 0) { Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId); } else { Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType); } } else { Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN); } } } catch (HpsCreditException $e) { Mage::logException($e); $this->getFraudSettings(); $this->_debugChargeService($chargeService, $e); // refund gift (if used) if ($giftCardNumber) { $order->addStatusHistoryComment('Reversed Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [full reversal]')->save(); $giftResponse = $giftService->reverse($giftcard, $giftResponse->balanceAmount); } if ($this->_allow_fraud && $e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) { // we can skip the card saving if it fails for possible fraud there will be no token. if ($this->_email_fraud && $this->_fraud_address != '') { // EMAIL THE PEOPLE $this->sendEmail($this->_fraud_address, $this->_fraud_address, 'Suspicious order (' . $order->getIncrementId() . ') allowed', 'Hello,<br><br>Heartland has determined that you should review order ' . $order->getRealOrderId() . ' for the amount of ' . $amount . '.'); } $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setIsTransactionClosed(0); } else { $payment->setStatus(self::STATUS_ERROR); if ($e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) { $this->throwUserError($this->_fraud_text, null, true); } else { $this->throwUserError($e->getMessage(), null, true); } } } catch (HpsException $e) { $this->_debugChargeService($chargeService, $e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage(), null, true); } catch (Exception $e) { $this->_debugChargeService($chargeService, $e); Mage::logException($e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage()); } return $this; }