/** * Post the request to the Soap Client in the Profile Model * * @param Mage_Payment_Model_Info $payment * @return Gorilla_ChasePaymentech_Model_Gateway_Result */ public function _postRequest($payment) { $payment->setAmount($this->_formatAmount($payment->getAmount())); /** @var $model Gorilla_ChasePaymentech_Model_Profile */ $model = Mage::getModel('chasepaymentech/profile'); switch ($payment->getChasePaymentechTransType()) { case Gorilla_ChasePaymentech_Model_Profile::TRANS_TYPE_AUTH_ONLY: case Gorilla_ChasePaymentech_Model_Profile::TRANS_TYPE_AUTH_CAPTURE: $response = $model->createOrderTransaction($payment, $this->isSavingCc()); break; case Gorilla_ChasePaymentech_Model_Profile::TRANS_TYPE_REFUND: $response = $model->createOrderTransaction($payment); // should be merged with other requests since all are same. break; case Gorilla_ChasePaymentech_Model_Profile::TRANS_TYPE_VOID: $response = $model->createReversalTransaction($payment); break; case Gorilla_ChasePaymentech_Model_Profile::TRANS_TYPE_CAPTURE: $response = $model->createMarkForCaptureTransaction($payment); break; default: $response = false; break; } /** @var $result Gorilla_ChasePaymentech_Model_Gateway_Result */ $result = Mage::getModel('chasepaymentech/gateway_result'); // Parse the direct response if ($response) { $r = (array) $response; } else { $r = false; } if ($r) { $result->setResponseCode((int) str_replace('"', '', isset($r['respCode']) ? $r['respCode'] : null))->setProcStatusCode((int) str_replace('"', '', $r['procStatus']))->setResponseReasonCode((int) str_replace('"', '', $r['procStatus']))->setResponseReasonText($r['procStatusMessage'])->setApprovalCode($r['approvalStatus'])->setAvsResultCode(isset($r['avsRespCode']) ? $r['avsRespCode'] : null)->setTransactionId($r['txRefNum'])->setTransactionRefIdx(isset($r['txRefIdx']) ? $r['txRefIdx'] : null)->setSplitTransactionId(isset($r['splitTxRefIdx']) ? $r['splitTxRefIdx'] : null)->setInvoiceNumber($r['orderID'])->setAmount($payment->getAmount())->setTransactionType(isset($r['transType']) ? $r['transType'] : null)->setCardCodeResponseCode($r['respCode'])->setCAVVResponseCode(isset($r['cvvRespCode']) ? $r['cvvRespCode'] : null)->setCardType(isset($r['cardBrand']) ? $r['cardBrand'] : null)->setRequestedAmount($payment->getAmount())->setAuthorizationCode(isset($r['authorizationCode']) ? $r['authorizationCode'] : null)->setCcLast4(substr($payment->getCcNumber(), -4))->setCustomerId($this->getCustomer()->getId())->setCustomerRefNum(isset($r['customerRefNum']) ? $r['customerRefNum'] : null); // if we used a stored credit card we need to set the customer ref number and the last 4 of the cc if ($payment->getChasePaymentechCustomerRefNum()) { $cardObj = $model->getCustomerPaymentProfile($payment->getChasePaymentechCustomerRefNum()); $result->setCustomerRefNum($cardObj->customerRefNum)->setCcLast4(substr($cardObj->ccAccountNum, -4)); } } else { if ($model->getErrorMessages()) { //Mage::log($model->getErrorMessages()); Mage::throwException(Mage::helper('paygate')->convertMessagesToMessage($model->getErrorMessages())); } else { Mage::throwException($this->_getHelper()->__('Error in payment gateway.')); } } return $result; }
/** * Perform transaction (auth, capture, etc.) * * @param Mage_Payment_Model_Info $payment * @param bool $addCustomerProfile * @return string $directResponse|bool */ public function createOrderTransaction($payment, $addCustomerProfile = false) { /** * Set the order in its own object */ $order = $payment->getOrder(); $amount = $payment->getAmount() * 100; // Must set 100.00 to 10000 per api $customerName = $order->getBillingAddress()->getFirstname() . " " . $order->getBillingAddress()->getLastname(); $street = $order->getBillingAddress()->getStreet(); $addy1 = $street[0]; $addy2 = isset($street[1]) ? $street[1] : ""; /** * Paymentech uses specific cent values to trigger specific error codes. * This can get annoying. * If we're in test mode and want to strip cents, let's get rid of them. */ $testmode = Mage::getStoreConfig(self::XML_PATH_TESTMODE); $stripcents = Mage::getStoreConfig(self::XML_PATH_STRIPCENTS); if ($testmode == 1 && $stripcents == 1) { $amount = floor($payment->getAmount()) * 100; } /** * Create the transaction request data */ /** * For split requests where we auth the second request */ /*if ($payment->getChasePaymentechTransType() == self::TRANS_TYPE_AUTH_ONLY && $payment->getSplitAuthTransId()) { $data = array( 'transType' => $payment->getChasePaymentechTransType(), 'ccAccountNum' => null, 'orderID' => $this->_getUniqueOrderId($payment, $order), 'amount' => $amount, 'txRefNum' => $payment->getSplitAuthTransId(), 'partialAuthInd' => 'Y', 'comments' => "New Order Auth" ); } else*/ if ($payment->getChasePaymentechTransType() == self::TRANS_TYPE_REFUND) { $data = array('transType' => $payment->getChasePaymentechTransType(), 'ccAccountNum' => null, 'orderID' => $this->_getUniqueOrderId($payment, $order), 'amount' => $amount > 0 ? $amount : null, 'txRefNum' => $payment->getTransId(), 'comments' => "New Order Refund"); } else { $data = array('transType' => $payment->getChasePaymentechTransType(), 'amount' => $amount, 'orderID' => $this->_getUniqueOrderId($payment, $order), 'customerRefNum' => $payment->getChasePaymentechCustomerRefNum(), 'customerName' => substr($customerName, 0, 30), 'avsName' => substr($customerName, 0, 30), 'avsAddress1' => substr($addy1, 0, 30), 'avsAddress2' => substr($addy2, 0, 30), 'avsCity' => $order->getBillingAddress()->getCity(), 'avsState' => Mage::helper('chasepaymentech')->convertStateNameToCode($order->getBillingAddress()->getRegion()), 'avsZip' => $order->getBillingAddress()->getPostcode(), 'avsCountryCode' => $order->getBillingAddress()->getCountryId(), 'avsPhone' => substr($order->getBillingAddress()->getTelephone(), 0, 14), 'customerRefNum' => ""); // Saved account - send ref num instead of card data if ($payment->getChasePaymentechCustomerRefNum()) { $additionalData = array('customerRefNum' => $payment->getChasePaymentechCustomerRefNum()); } else { $additionalData = array('ccAccountNum' => $payment->getCcNumber(), 'ccExp' => sprintf('%04d%02d', $payment->getCcExpYear(), $payment->getCcExpMonth()), 'cardBrand' => $payment->getCcType() == self::AMERICAN_EXPRESS ? self::AMERICAN_EXPRESS_VALUE : $payment->getCcType(), 'ccCardVerifyNum' => $payment->getCcCid(), 'ccCardVerifyPresenceInd' => in_array($payment->getCcType(), array('DI', 'VI')) ? 1 : null, 'addProfileFromOrder' => $addCustomerProfile ? "A" : "", 'profileOrderOverideInd' => $addCustomerProfile ? "NO" : ""); } // Merge data arrays $data = array_merge($data, $additionalData); /** * If this is a prior auth capture, void, or refund add the transaction id */ if ($payment->getChasePaymentechTransType() == self::TRANS_TYPE_CAPTURE || $payment->getChasePaymentechTransType() == self::TRANS_TYPE_REFUND) { $data['txRefNum'] = $payment->getTransId(); } /** * Send Minimum Auth Amount request, parse the response to check cvv, then send secondary, full, request. * * $0.00 Auth verification can only be used for MC and Visa so there is no $ being held - does not seem to be working * $0.01 Authorization is the least amount you can send in for all other CC. */ $true = false; if ($true && !$payment->getChasePaymentechCustomerRefNum()) { $data['transType'] = self::TRANS_TYPE_AUTH_ONLY; if (in_array($payment->getCcType(), array('MC', 'VI'))) { $data['amount'] = '000'; } else { $data['amount'] = '001'; } $soap_env = array(self::TRANS_CREATE_TRANS_REQUEST => array_merge($this->_getAuthentication(), $data)); if (!($response = $this->doCall(self::TRANS_CREATE_TRANS, $soap_env))) { return false; } $response = $response->return; //Mage::log('minimum response:'); //Mage::log($response); if ($this->_checkErrors()) { // For CLI testing //Mage::log($this->getErrorMessages()); return false; } if ($response->cvvRespCode != self::RESPONSE_CVV_MATCH) { //$this->setResponseMessages(array($this->_cvvResponses[$response->cvvRespCode])); if ($response->cvvRespCode) { $this->setErrorMessages(array($this->_cvvResponses[$response->cvvRespCode])); } else { $this->setErrorMessages(array(Mage::helper('paygate')->__('Error with payment info'))); } // For CLI testing //Mage::log($this->getErrorMessages()); return false; } // Reset the amount and trans type for full amount request $data['amount'] = $amount; $data['transType'] = $payment->getChasePaymentechTransType(); //$data['partialAuthInd'] = 'Y'; } } $soap_env = array(self::TRANS_CREATE_TRANS_REQUEST => array_merge($this->_getAuthentication(), $data)); if (!($response = $this->doCall(self::TRANS_CREATE_TRANS, $soap_env))) { return false; } $response = $response->return; //Mage::log("full response"); //Mage::log($response); $hasErrors = $this->_checkErrors(); if ($hasErrors) { // For CLI testing //Mage::log($this->getErrorMessages()); } if ($response) { if (!$hasErrors) { return $response; } else { return false; } } else { return false; } }