/** * Get validation message that will be displayed to user by VAT validation result object * * @param Mage_Customer_Model_Address $customerAddress * @param bool $customerGroupAutoAssignDisabled * @param Varien_Object $validationResult * @return Varien_Object */ public function getVatValidationUserMessage($customerAddress, $customerGroupAutoAssignDisabled, $validationResult) { $message = ''; $isError = true; $customerVatClass = $this->getCustomerVatClass($customerAddress->getCountryId(), $validationResult); $groupAutoAssignDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_VIV_GROUP_AUTO_ASSIGN); $willChargeTaxMessage = $this->__('You will be charged tax.'); $willNotChargeTaxMessage = $this->__('You will not be charged tax.'); if ($validationResult->getIsValid()) { $message = $this->__('Your VAT ID was successfully validated.'); $isError = false; if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) { $message .= ' ' . ($customerVatClass == self::VAT_CLASS_DOMESTIC ? $willChargeTaxMessage : $willNotChargeTaxMessage); } } else { if ($validationResult->getRequestSuccess()) { $message = sprintf($this->__('The VAT ID entered (%s) is not a valid VAT ID.') . ' ', $this->escapeHtml($customerAddress->getVatId())); if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) { $message .= $willChargeTaxMessage; } } else { $contactUsMessage = sprintf($this->__('If you believe this is an error, please contact us at %s'), Mage::getStoreConfig(self::XML_PATH_SUPPORT_EMAIL)); $message = $this->__('Your Tax ID cannot be validated.') . ' ' . (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled ? $willChargeTaxMessage . ' ' : '') . $contactUsMessage; } } $validationMessageEnvelope = new Varien_Object(); $validationMessageEnvelope->setMessage($message); $validationMessageEnvelope->setIsError($isError); return $validationMessageEnvelope; }
/** * 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; }