Ejemplo n.º 1
0
 /**
  * Processing the transaction using the hosted payment form integration 
  *
  * @param Varien_Object $payment
  * @param unknown_type $amount
  */
 public function _runHostedPaymentTransaction(Varien_Object $payment, $amount)
 {
     $takePaymentInStoreBaseCurrency = $this->getConfigData('takePaymentInStoreBaseCurrency');
     $session = Mage::getSingleton('checkout/session');
     $nVersion = $this->getVersion();
     $szMerchantID = $this->getConfigData('merchantid');
     $szPassword = $this->getConfigData('password');
     $szPreSharedKey = $this->getConfigData('presharedkey');
     $hmHashMethod = $this->getConfigData('hashmethod');
     $boCV2Mandatory = 'false';
     $boAddress1Mandatory = 'false';
     $boCityMandatory = 'false';
     $boPostCodeMandatory = 'false';
     $boStateMandatory = 'false';
     $boCountryMandatory = 'false';
     $rdmResultdeliveryMethod = $this->getConfigData('resultdeliverymethod');
     $szServerResultURL = '';
     // set to always true to display the result on the Hosted Payment Form
     $boPaymentFormDisplaysResult = '';
     switch ($rdmResultdeliveryMethod) {
         case Cardsave_Cardsaveonlinepayments_Model_Source_ResultDeliveryMethod::RESULT_DELIVERY_METHOD_POST:
             $szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/callbackhostedpayment', array('_secure' => true));
             break;
         case Cardsave_Cardsaveonlinepayments_Model_Source_ResultDeliveryMethod::RESULT_DELIVERY_METHOD_SERVER:
             $szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/callbackhostedpayment', array('_secure' => true));
             $szServerResultURL = Mage::getUrl('cardsaveonlinepayments/payment/serverresult', array('_secure' => true));
             $boPaymentFormDisplaysResult = 'true';
             break;
         case Cardsave_Cardsaveonlinepayments_Model_Source_ResultDeliveryMethod::RESULT_DELIVERY_METHOD_SERVER_PULL:
             $szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/serverpullresult', array('_secure' => true));
             break;
     }
     $order = $payment->getOrder();
     $billingAddress = $order->getBillingAddress();
     $iclISOCurrencyList = CSV_ISOCurrencies::getISOCurrencyList();
     $iclISOCountryList = CSV_ISOCountries::getISOCountryList();
     $cookie = Mage::getSingleton('core/cookie');
     $arCookieArray = $cookie->get();
     $arCookieKeysArray = array_keys($arCookieArray);
     $nKeysArrayLength = count($arCookieKeysArray);
     $szCookiePath = $cookie->getPath();
     $szCookieDomain = $cookie->getDomain();
     $szServerResultURLCookieVariables = '';
     $szServerResultURLFormVariables = '';
     $szServerResultURLQueryStringVariables = '';
     //ServerResutlURLCookieVariables string format: cookie1=123&path=/&domain=www.domain.com@@cookie2=456&path=/&domain=www.domain.com
     for ($nCount = 0; $nCount < $nKeysArrayLength; $nCount++) {
         $szEncodedCookieValue = urlencode($arCookieArray[$arCookieKeysArray[$nCount]]);
         $szServerResultURLCookieVariables .= $arCookieKeysArray[$nCount] . "=" . $szEncodedCookieValue . "&path=" . $szCookiePath . "&domain=" . $szCookieDomain;
         if ($nCount < $nKeysArrayLength - 1) {
             $szServerResultURLCookieVariables .= "@@";
         }
     }
     if (!$takePaymentInStoreBaseCurrency) {
         // Take payment in order currency
         $szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode();
         if ($szCurrencyShort != '' && $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency)) {
             $nCurrencyCode = $icISOCurrency->getISOCode();
         }
         // Calculate amount
         $power = pow(10, $icISOCurrency->getExponent());
         $nAmount = round($order->getGrandTotal() * $power, 0);
     } else {
         // Take payment in site base currency
         //$szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode();
         $szCurrencyShort = $order->getBaseCurrencyCode();
         if ($szCurrencyShort != '' && $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency)) {
             $nCurrencyCode = $icISOCurrency->getISOCode();
         }
         // Calculate amount
         $nAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
     }
     $szISO2CountryCode = $billingAddress->getCountry();
     $szCountryShort = $this->_getISO3Code($szISO2CountryCode);
     if ($iclISOCountryList->getISOCountry($szCountryShort, $icISOCountry)) {
         $nCountryCode = $icISOCountry->getISOCode();
     }
     $szOrderID = $payment->getOrder()->increment_id;
     //date time with 2008-12-01 14:12:00 +01:00 format
     $szTransactionDateTime = date('Y-m-d H:i:s P');
     $szOrderDescription = '';
     //$szTransactionType = "SALE";
     $paymentAction = $this->getConfigData('payment_action');
     if ($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE) {
         $szTransactionType = "SALE";
     } else {
         if ($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE) {
             $szTransactionType = "PREAUTH";
         } else {
             Mage::throwException('Unknown payment action: ' . $paymentAction);
         }
     }
     $szCustomerName = $billingAddress->getfirstname();
     if ($billingAddress->getfirstname()) {
         $szCustomerName = $szCustomerName . ' ' . $billingAddress->getlastname();
     }
     $szAddress1 = $billingAddress->getStreet1();
     $szAddress2 = $billingAddress->getStreet2();
     $szAddress3 = $billingAddress->getStreet3();
     $szAddress4 = $billingAddress->getStreet4();
     $szCity = $billingAddress->getCity();
     $szState = $billingAddress->getRegion();
     $szPostCode = $billingAddress->getPostcode();
     if ($this->getConfigData('cv2mandatory')) {
         $boCV2Mandatory = 'true';
     }
     if ($this->getConfigData('address1mandatory')) {
         $boAddress1Mandatory = 'true';
     }
     if ($this->getConfigData('citymandatory')) {
         $boCityMandatory = 'true';
     }
     if ($this->getConfigData('postcodemandatory')) {
         $boPostCodeMandatory = 'true';
     }
     if ($this->getConfigData('statemandatory')) {
         $boStateMandatory = 'true';
     }
     if ($this->getConfigData('countrymandatory')) {
         $boCountryMandatory = 'true';
     }
     if ($this->getConfigData('paymentformdisplaysresult')) {
         $boPaymentFormDisplaysResult = 'true';
     }
     $szHashDigest = CSV_PaymentFormHelper::calculateHashDigest($szMerchantID, $szPassword, $hmHashMethod, $szPreSharedKey, $nAmount, $nCurrencyCode, $szOrderID, $szTransactionType, $szTransactionDateTime, $szCallbackURL, $szOrderDescription, $szCustomerName, $szAddress1, $szAddress2, $szAddress3, $szAddress4, $szCity, $szState, $szPostCode, $nCountryCode, $boCV2Mandatory, $boAddress1Mandatory, $boCityMandatory, $boPostCodeMandatory, $boStateMandatory, $boCountryMandatory, $rdmResultdeliveryMethod, $szServerResultURL, $boPaymentFormDisplaysResult, $szServerResultURLCookieVariables, $szServerResultURLFormVariables, $szServerResultURLQueryStringVariables);
     $session->setHashdigest($szHashDigest)->setMerchantid($szMerchantID)->setAmount($nAmount)->setCurrencycode($nCurrencyCode)->setOrderid($szOrderID)->setTransactiontype($szTransactionType)->setTransactiondatetime($szTransactionDateTime)->setCallbackurl($szCallbackURL)->setOrderdescription($szOrderDescription)->setCustomername($szCustomerName)->setAddress1($szAddress1)->setAddress2($szAddress2)->setAddress3($szAddress3)->setAddress4($szAddress4)->setCity($szCity)->setState($szState)->setPostcode($szPostCode)->setCountrycode($nCountryCode)->setCv2mandatory($boCV2Mandatory)->setAddress1mandatory($boAddress1Mandatory)->setCitymandatory($boCityMandatory)->setPostcodemandatory($boPostCodeMandatory)->setStatemandatory($boStateMandatory)->setCountrymandatory($boCountryMandatory)->setResultdeliverymethod($rdmResultdeliveryMethod)->setServerresulturl($szServerResultURL)->setPaymentformdisplaysresult($boPaymentFormDisplaysResult)->setServerresulturlcookievariables($szServerResultURLCookieVariables)->setServerresulturlformvariables($szServerResultURLFormVariables)->setServerresulturlquerystringvariables($szServerResultURLQueryStringVariables);
     $session->setRedirectionmethod('_runRedirectedPaymentComplete');
     $payment->getOrder()->setIsHostedPaymentPending(true);
     /* serve out a dummy CrossReference as the TransactionId - this need to be done to enable the "Refund" button 
        in the Magento CreditMemo internal refund mechanism */
     $payment->setTransactionId($szOrderID . "_" . date('YmdHis'));
 }