/** * Make prepaid credit card payloads for any payments * remaining in the list * @param Mage_Sales_Model_Order $order * @param IPaymentContainer $paymentContainer * @param SplObjectStorage $processedPayments */ public function addPaymentsToPayload(Mage_Sales_Model_Order $order, IPaymentContainer $paymentContainer, SplObjectStorage $processedPayments) { foreach ($order->getAllPayments() as $payment) { if ($this->_shouldIgnorePayment($payment, $processedPayments)) { continue; } $iterable = $paymentContainer->getPayments(); $payload = $iterable->getEmptyCreditCardPayment(); $additionalInfo = new Varien_Object($payment->getAdditionalInformation()); $payload->setOrderId($order->getIncrementId())->setTenderType($additionalInfo->getTenderType())->setAccountUniqueId($this->_getAccountUniqueId($payment))->setPanIsToken($additionalInfo->getPanIsToken())->setPaymentRequestId($additionalInfo->getRequestId())->setCreateTimestamp($this->_getAsDateTime($payment->getCreatedAt()))->setAmount($payment->getAmountAuthorized())->setBankAuthorizationCode($additionalInfo->getBankAuthorizationCode())->setResponseCode($additionalInfo->getResponseCode())->setCVV2ResponseCode($additionalInfo->getCvv2ResponseCode())->setAVSResponseCode($additionalInfo->getAvsResponseCode())->setPhoneResponseCode($additionalInfo->getPhoneResponseCode())->setNameResponseCode($additionalInfo->getNameResponseCode())->setEmailResponseCode($additionalInfo->getEmailResponseCode())->setAmountAuthorized($additionalInfo->getAmountAuthorized())->setExpirationDate($this->_getExpirationDateTime($payment))->setExtendedAuthDescription($additionalInfo->getExtendedAuthDescription())->setExtendedAuthReasonCode($additionalInfo->getExtendedAuthReasonCode())->setIssueNumber($additionalInfo->getIssueNumber())->setAuthenticationAvailable($additionalInfo->getAuthenticationAvailable())->setAuthenticationStatus($additionalInfo->getAuthenticationStatus())->setCavvUcaf($additionalInfo->getCavvUcaf())->setTransactionId($additionalInfo->getTransactionId())->setECI($additionalInfo->getECI())->setPayerAuthenticationResponse($additionalInfo->getPayerAuthenticationResponse())->setPurchasePlanCode($additionalInfo->getPurchasePlanCode())->setPurchasePlanDescription($additionalInfo->getPurchasePlanDescription()); if ($additionalInfo->getStartDate()) { // prevent death by type error if getStartDate returns null $payload->setStartDate($this->_getAsDateTime($additionalInfo->getStartDate())); } // add the new payload $iterable->OffsetSet($payload, $payload); // put the payment in the processed payments set $processedPayments->attach($payment); } }
/** * Set split_tender_id to quote payment if neeeded * * @param Varien_Object $response * @param Mage_Sales_Model_Order_Payment $payment * @return bool */ protected function _processPartialAuthorizationResponse($response, $orderPayment) { if (!$response->getSplitTenderId()) { return false; } $quotePayment = $orderPayment->getOrder()->getQuote()->getPayment(); $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED); $exceptionMessage = null; try { switch ($response->getResponseCode()) { case self::RESPONSE_CODE_APPROVED: $this->_registerCard($response, $orderPayment); $this->_clearAssignedData($quotePayment); $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS); return true; case self::RESPONSE_CODE_HELD: if ($response->getResponseReasonCode() != self::RESPONSE_REASON_CODE_PARTIAL_APPROVE) { return false; } if ($this->getCardsStorage($orderPayment)->getCardsCount() + 1 >= self::PARTIAL_AUTH_CARDS_LIMIT) { $this->cancelPartialAuthorization($orderPayment); $this->_clearAssignedData($quotePayment); $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_CARDS_LIMIT_EXCEEDED); $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation()); $exceptionMessage = Mage::helper('paygate')->__('You have reached the maximum number of credit card allowed to be used for the payment.'); break; } $orderPayment->setAdditionalInformation($this->_splitTenderIdKey, $response->getSplitTenderId()); $this->_registerCard($response, $orderPayment); $this->_clearAssignedData($quotePayment); $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS); $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation()); $exceptionMessage = null; break; case self::RESPONSE_CODE_DECLINED: case self::RESPONSE_CODE_ERROR: $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED); $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation()); $exceptionMessage = $this->_wrapGatewayError($response->getResponseReasonText()); break; default: $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED); $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation()); $exceptionMessage = $this->_wrapGatewayError(Mage::helper('paygate')->__('Payment partial authorization error.')); } } catch (Exception $e) { $exceptionMessage = $e->getMessage(); } throw new Mage_Payment_Model_Info_Exception($exceptionMessage); }
public function getLicenseInfo($licensekey, $extensionName, $domain) { $licensekey = trim($licensekey); // check license for old license key if ($oldLicenseInfo = $this->_decrypt($licensekey)) { $license = Mage::getModel('magenotification/license')->loadByLicenseExtension($licensekey, $extensionName); if (!$license->getId()) { // Request first time when using old license key try { $xmlRpc = new Zend_XmlRpc_Client(self::SERVER_URL . 'api/xmlrpc/'); $session = $xmlRpc->call('login', array('username' => self::WEBSERVICE_USER, 'password' => self::WEBSERVICE_PASS)); $result = $xmlRpc->call('call', array('sessionId' => $session, 'apiPath' => 'licensemanager.active', 'args' => array($licensekey, $extensionName, $domain))); $dataObject = new Varien_Object($result); } catch (Exception $e) { return new Varien_Object(array('response_code' => 101)); } $license->setResponseCode($dataObject->getResponseCode())->setDomains($dataObject->getDomains()); if ($dataObject->getActivatedTime()) { $license->setActiveAt(substr($dataObject->getActivatedTime(), 0, 10)); } else { $license->setActiveAt(now(true)); } try { $license->setSumCode($this->_getSumCode($license)); $license->save(); } catch (Exception $e) { } return $dataObject; } $result = new Varien_Object($license->getData()); $result->addData(array('users' => 1, 'created_time' => date('Y-m-d H:m:s', $oldLicenseInfo['created_time']), 'activated_time' => $license->getActiveAt(), 'type' => $oldLicenseInfo['type'], 'status' => 1, 'expired_time' => $oldLicenseInfo['expired_time'])); if ($license->getSumCode() != $this->_getSumCode($license)) { try { $license->setResponseCode(self::GENERAL_ERROR); $license->setSumCode($this->_getSumCode($license))->save(); } catch (Exception $e) { } } elseif ($result->getType() == self::TRIAL_VERSION && $license->getResponseCode() > self::LIMITED_DOMAIN_ERROR) { $expiredTime = strtotime($license->getActiveAt()) + (int) $result->getExpiredTime() * 24 * 3600; if ($expiredTime < time()) { try { $license->setResponseCode(self::EXPIRED_TRIAL_LICENSE_KEY_ERROR); $license->setSumCode($this->_getSumCode($license))->save(); } catch (Exception $e) { } } } return $result->setResponseCode($license->getResponseCode()); } // check new license key if ($licenseInfo = $this->_newkeyDecrypt($licensekey, $extensionName, $domain)) { $license = Mage::getModel('magenotification/license')->loadByLicenseExtension($licensekey, $extensionName); if (!$license->getId()) { $license->setActiveAt(now(true))->setDomains($licenseInfo->getDomains()); $responseCode = self::NEW_DOMAIN_SUCCESS; $licenseDomain = strlen($domain) > 38 ? substr($domain, 0, 38) : $domain; if ($licenseDomain != $licenseInfo->getDomains()) { $responseCode = self::LIMITED_DOMAIN_ERROR; } try { $license->setResponseCode($responseCode); $license->setSumCode($this->_getSumCode($license))->save(); } catch (Exception $e) { } } $result = new Varien_Object($license->getData()); $createdTime = $licenseInfo->getCreatedDate() ? $licenseInfo->getCreatedDate() : $license->getActiveAt(); $result->addData(array('users' => 1, 'created_time' => date('Y-m-d H:m:s', strtotime($createdTime)), 'activated_time' => $license->getActiveAt(), 'type' => $this->getOldLicenseType($licenseInfo->getType()), 'status' => 1, 'expired_time' => $licenseInfo->getExpiredTime())); if ($license->getSumCode() != $this->_getSumCode($license)) { try { $license->setResponseCode(self::GENERAL_ERROR); $license->setSumCode($this->_getSumCode($license))->save(); } catch (Exception $e) { } } elseif (($result->getType() == self::TRIAL_VERSION || $result->getType() == self::DEVELOPMENT) && $license->getResponseCode() > self::LIMITED_DOMAIN_ERROR) { $expiredTime = strtotime($license->getActiveAt()) + (int) $result->getExpiredTime() * 24 * 3600; if ($expiredTime < time()) { try { $license->setResponseCode(self::EXPIRED_TRIAL_LICENSE_KEY_ERROR); $license->setSumCode($this->_getSumCode($license))->save(); } catch (Exception $e) { } } } return $result->setResponseCode($license->getResponseCode()); } return new Varien_Object(array('response_code' => self::GENERAL_ERROR)); }
/** * 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; }