/**
  * Fill out the request payload with payment data and update the API request
  * body with the complete request.
  * @param Api\IBidirectionalApi $api
  * @param Varien_Object         $payment Most likely a Mage_Sales_Model_Order_Payment
  * @return self
  */
 protected function _prepareApiRequest(Api\IBidirectionalApi $api, Varien_Object $payment)
 {
     $request = $api->getRequestBody();
     $order = $payment->getOrder();
     $billingAddress = $order->getBillingAddress();
     $shippingAddress = $order->getShippingAddress() ?: $billingAddress;
     $request->setIsEncrypted($this->_isUsingClientSideEncryption)->setRequestId($this->_coreHelper->generateRequestId('CCA-'))->setOrderId($order->getIncrementId())->setPanIsToken(false)->setCardNumber($payment->getCcNumber())->setExpirationDate($this->_coreHelper->getNewDateTime(sprintf('%s-%s', $payment->getCcExpYear(), $payment->getCcExpMonth())))->setCardSecurityCode($payment->getCcCid())->setAmount($payment->getBaseAmountAuthorized())->setCurrencyCode(Mage::app()->getStore()->getBaseCurrencyCode())->setEmail($order->getCustomerEmail())->setIp($this->_httpHelper->getRemoteAddr())->setBillingFirstName($billingAddress->getFirstname())->setBillingLastName($billingAddress->getLastname())->setBillingPhone($billingAddress->getTelephone())->setBillingLines($billingAddress->getStreet(-1))->setBillingCity($billingAddress->getCity())->setBillingMainDivision($billingAddress->getRegionCode())->setBillingCountryCode($billingAddress->getCountry())->setBillingPostalCode($billingAddress->getPostcode())->setShipToFirstName($shippingAddress->getFirstname())->setShipToLastName($shippingAddress->getLastname())->setShipToPhone($shippingAddress->getTelephone())->setShipToLines($shippingAddress->getStreet(-1))->setShipToCity($shippingAddress->getCity())->setShipToMainDivision($shippingAddress->getRegionCode())->setShipToCountryCode($shippingAddress->getCountry())->setShipToPostalCode($shippingAddress->getPostcode())->setIsRequestToCorrectCVVOrAVSError($this->_getIsCorrectionNeededForPayment($payment));
     return $this;
 }
Example #2
0
 /**
  * Void the payment transaction
  *
  * @param Mage_Sale_Model_Order_Payment $payment
  * @return Mage_Cybersource_Model_Soap
  */
 public function void(Varien_Object $payment)
 {
     $error = false;
     if ($payment->getParentTransactionId() && $payment->getCybersourceToken()) {
         $soapClient = $this->getSoapApi();
         $this->iniRequest();
         $ccAuthReversalService = new stdClass();
         $ccAuthReversalService->run = "true";
         $ccAuthReversalService->authRequestID = $payment->getParentTransactionId();
         $ccAuthReversalService->authRequestToken = $payment->getCybersourceToken();
         $this->_request->ccAuthReversalService = $ccAuthReversalService;
         $purchaseTotals = new stdClass();
         $purchaseTotals->currency = $payment->getOrder()->getBaseCurrencyCode();
         $purchaseTotals->grandTotalAmount = $payment->getBaseAmountAuthorized();
         $this->_request->purchaseTotals = $purchaseTotals;
         try {
             $result = $soapClient->runTransaction($this->_request);
             if ($result->reasonCode == self::RESPONSE_CODE_SUCCESS) {
                 $payment->setTransactionId($result->requestID)->setCybersourceToken($result->requestToken)->setIsTransactionClosed(1);
             } else {
                 $error = Mage::helper('cybersource')->__('There is an error in processing the payment. Please try again or contact us.');
             }
         } catch (Exception $e) {
             Mage::throwException(Mage::helper('cybersource')->__('Gateway request error: %s', $e->getMessage()));
         }
     } else {
         $error = Mage::helper('cybersource')->__('Invalid transaction id or token');
     }
     if ($error !== false) {
         Mage::throwException($error);
     }
     return $this;
 }