Example #1
0
 /**
  * Turn transaction results and directResponse into a usable object.
  */
 protected function _interpretTransaction($transactionResult)
 {
     /**
      * Turn the direct response string into an array, as best we can.
      */
     $directResponse = isset($transactionResult['directResponse']) ? $transactionResult['directResponse'] : '';
     if (strlen($directResponse) > 1) {
         // Strip out quotes, we don't want any.
         $directResponse = str_replace('"', '', $directResponse);
         // Use the second character as the delimiter. The first will always be the one-digit response code.
         $directResponse = explode(substr($directResponse, 1, 1), $directResponse);
     }
     if (empty($directResponse) || count($directResponse) == 0) {
         Mage::throwException(Mage::helper('tokenbase')->__('Authorize.Net CIM Gateway: Transaction failed; no direct response.'));
     }
     /**
      * Turn the array into a keyed object and infer some things.
      */
     $data = array('response_code' => (int) $directResponse[0], 'response_subcode' => (int) $directResponse[1], 'response_reason_code' => (int) $directResponse[2], 'response_reason_text' => $directResponse[3], 'approval_code' => $directResponse[4], 'auth_code' => $directResponse[4], 'avs_result_code' => $directResponse[5], 'transaction_id' => $directResponse[6], 'invoice_number' => $directResponse[7], 'description' => $directResponse[8], 'amount' => $directResponse[9], 'method' => $directResponse[10], 'transaction_type' => $directResponse[11], 'customer_id' => $directResponse[12], 'md5_hash' => $directResponse[37], 'card_code_response_code' => $directResponse[38], 'cavv_response_code' => $directResponse[39], 'acc_number' => $directResponse[50], 'card_type' => $directResponse[51], 'split_tender_id' => $directResponse[52], 'requested_amount' => $directResponse[53], 'balance_on_card' => $directResponse[54], 'profile_id' => $this->getParameter('customerProfileId'), 'payment_id' => $this->getParameter('customerPaymentProfileId'), 'is_fraud' => false, 'is_error' => false);
     $response = new Varien_Object();
     $response->setData($data);
     if ($response->getResponseCode() == 4) {
         $response->setIsFraud(true);
     }
     if (!in_array($response->getResponseReasonCode(), array(16, 54))) {
         // Response 54 is 'can't refund; txn has not settled.' 16 is 'cannot find txn' (expired). We deal with them.
         if ($transactionResult['messages']['resultCode'] != 'Ok' || in_array($response->getResponseCode(), array(2, 3)) || !in_array($response->getTransactionType(), array('credit', 'void')) && ($response->getTransactionId() == '' || $response->getAuthCode() == '')) {
             $response->setIsError(true);
             Mage::helper('tokenbase')->log($this->_code, sprintf("Transaction error: %s\n%s\n%s", $response->getResponseReasonText(), json_encode($response->getData()), $this->_log));
             Mage::throwException(Mage::helper('tokenbase')->__('Authorize.Net CIM Gateway: Transaction failed. ' . $response->getResponseReasonText()));
         }
     }
     return $response;
 }