private function _paymentComplete($szPassword, $hmHashMethod, $szPreSharedKey) { $boError = false; $formVariables = array(); $model = Mage::getModel('cardsaveonlinepayments/direct'); $szOrderID = $this->getRequest()->getPost('OrderID'); $checkout = Mage::getSingleton('checkout/type_onepage'); $session = Mage::getSingleton('checkout/session'); $szPaymentProcessorResponse = ''; $order = Mage::getModel('sales/order'); $order->load(Mage::getSingleton('checkout/session')->getLastOrderId()); $nVersion = Mage::getModel('cardsaveonlinepayments/direct')->getVersion(); $boCartIsEmpty = false; try { $formVariables['HashDigest'] = $this->getRequest()->getPost('HashDigest'); $formVariables['MerchantID'] = $this->getRequest()->getPost('MerchantID'); $formVariables['StatusCode'] = $this->getRequest()->getPost('StatusCode'); $formVariables['Message'] = $this->getRequest()->getPost('Message'); $formVariables['PreviousStatusCode'] = $this->getRequest()->getPost('PreviousStatusCode'); $formVariables['PreviousMessage'] = $this->getRequest()->getPost('PreviousMessage'); $formVariables['CrossReference'] = $this->getRequest()->getPost('CrossReference'); $formVariables['Amount'] = $this->getRequest()->getPost('Amount'); $formVariables['CurrencyCode'] = $this->getRequest()->getPost('CurrencyCode'); $formVariables['OrderID'] = $this->getRequest()->getPost('OrderID'); $formVariables['TransactionType'] = $this->getRequest()->getPost('TransactionType'); $formVariables['TransactionDateTime'] = $this->getRequest()->getPost('TransactionDateTime'); $formVariables['OrderDescription'] = $this->getRequest()->getPost('OrderDescription'); $formVariables['Address1'] = $this->getRequest()->getPost('Address1'); $formVariables['Address2'] = $this->getRequest()->getPost('Address2'); $formVariables['Address3'] = $this->getRequest()->getPost('Address3'); $formVariables['Address4'] = $this->getRequest()->getPost('Address4'); $formVariables['City'] = $this->getRequest()->getPost('City'); $formVariables['State'] = $this->getRequest()->getPost('State'); $formVariables['PostCode'] = $this->getRequest()->getPost('PostCode'); $formVariables['CountryCode'] = $this->getRequest()->getPost('CountryCode'); $formVariables['AddressNumericCheckResult'] = $this->getRequest()->getPost('AddressNumericCheckResult'); $formVariables['PostCodeCheckResult'] = $this->getRequest()->getPost('PostCodeCheckResult'); $formVariables['CV2CheckResult'] = $this->getRequest()->getPost('CV2CheckResult'); $formVariables['ThreeDSecureAuthenticationCheckResult'] = $this->getRequest()->getPost('ThreeDSecureAuthenticationCheckResult'); $formVariables['CardType'] = $this->getRequest()->getPost('CardType'); $formVariables['CardClass'] = $this->getRequest()->getPost('CardClass'); $formVariables['CardIssuer'] = $this->getRequest()->getPost('CardIssuer'); $formVariables['CardIssuerCountryCode'] = $this->getRequest()->getPost('CardIssuerCountryCode'); $formVariables['EmailAddress'] = $this->getRequest()->getPost('EmailAddress'); $formVariables['PhoneNumber'] = $this->getRequest()->getPost('PhoneNumber'); if (!CSV_PaymentFormHelper::comparePaymentCompleteHashDigest($formVariables, $szPassword, $hmHashMethod, $szPreSharedKey)) { $boError = true; $szNotificationMessage = "The payment was rejected for a SECURITY reason: the incoming payment data was tampered with."; Mage::log("The Transparent Redirect transaction couldn't be completed for the following reason: [" . $szNotificationMessage . "] Form variables: " . print_r($formVariables, 1)); } else { $cardsaveOrderId = Mage::getSingleton('checkout/session')->getCardsaveonlinepaymentsOrderId(); $szOrderStatus = $order->getStatus(); if ($szOrderStatus != 'csv_paid' && $szOrderStatus != 'csv_preauth') { $checkout->saveOrderAfterRedirectedPaymentAction(false, $this->getRequest()->getPost('StatusCode'), $this->getRequest()->getPost('Message'), $this->getRequest()->getPost('PreviousStatusCode'), $this->getRequest()->getPost('PreviousMessage'), $this->getRequest()->getPost('OrderID'), $this->getRequest()->getPost('CrossReference')); } else { $boCartIsEmpty = true; $szPaymentProcessorResponse = null; // chek the StatusCode as the customer might have just clicked the BACK button and re-submitted the card details // which can cause a charge back to the merchant $szStatusCode = $this->getRequest()->getPost('StatusCode'); $szMessage = $this->getRequest()->getPost('Message'); $szPreviousStatusCode = $this->getRequest()->getPost('PreviousStatusCode'); $szPreviousMessage = $this->getRequest()->getPost('PreviousMessage'); $szOrderID = $this->getRequest()->getPost('OrderID'); $this->_fixBackButtonBug($szOrderID, $szStatusCode, $szMessage, $szPreviousStatusCode, $szPreviousMessage); } } } catch (Exception $exc) { $boError = true; $szNotificationMessage = Cardsave_Cardsaveonlinepayments_Model_Common_GlobalErrors::ERROR_183; Mage::logException($exc); } $szPaymentProcessorResponse = $session->getPaymentprocessorresponse(); if ($boError == true) { if ($szPaymentProcessorResponse != null && $szPaymentProcessorResponse != '') { $szNotificationMessage = $szNotificationMessage . '<br/>' . $szPaymentProcessorResponse; } $model->setPaymentAdditionalInformation($order->getPayment(), $this->getRequest()->getPost('CrossReference')); //$order->getPayment()->setAdditionalData("CrossReference=".$this->getRequest()->getPost('CrossReference')); if ($order) { $orderState = 'pending_payment'; $orderStatus = 'csv_failed_hosted_payment'; $order->setCustomerNote(Mage::helper('cardsaveonlinepayments')->__('Transparent Redirect Payment Failed')); $order->setState($orderState, $orderStatus, $szPaymentProcessorResponse, false); } $order->save(); Mage::getSingleton('core/session')->addError($szNotificationMessage); $this->_clearSessionVariables(); $this->_redirect('checkout/onepage/failure'); } else { // set the quote as inactive after back from paypal Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save(); if ($boCartIsEmpty == false) { // send confirmation email to customer if ($order->getId()) { $order->sendNewOrderEmail(); } $this->_updateInvoices($order, $szPaymentProcessorResponse); if ($szPaymentProcessorResponse != '') { Mage::getSingleton('core/session')->addSuccess($szPaymentProcessorResponse); } } $this->_redirect('checkout/onepage/success', array('_secure' => true)); } }
/** * Processing the transaction using the transparent redirect integration * * @param Varien_Object $payment * @param unknown_type $amount */ public function _runTransparentRedirectTransaction(Varien_Object $payment, $amount) { $takePaymentInStoreBaseCurrency = $this->getConfigData('takePaymentInStoreBaseCurrency'); $GLOBALS['m_boPayInvoice'] = false; $payment->setIsTransactionPending(true); $nVersion = $this->getVersion(); $szMerchantID = $this->getConfigData('merchantid'); $szPassword = $this->getConfigData('password'); $szPreSharedKey = $this->getConfigData('presharedkey'); $hmHashMethod = $this->getConfigData('hashmethod'); $szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/callbacktransparentredirect', array('_secure' => true)); $order = $payment->getOrder(); $billingAddress = $order->getBillingAddress(); $iclISOCurrencyList = CSV_ISOCurrencies::getISOCurrencyList(); $iclISOCountryList = CSV_ISOCountries::getISOCountryList(); $szStartDateMonth = ''; $szStartDateYear = ''; 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()); } $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); } } $szAddress1 = $billingAddress->getStreet1(); $szAddress2 = $billingAddress->getStreet2(); $szAddress3 = $billingAddress->getStreet3(); $szAddress4 = $billingAddress->getStreet4(); $szCity = $billingAddress->getCity(); $szState = $billingAddress->getRegion(); $szPostCode = $billingAddress->getPostcode(); $szISO2CountryCode = $billingAddress->getCountry(); $szCountryShort = $this->_getISO3Code($szISO2CountryCode); if ($iclISOCountryList->getISOCountry($szCountryShort, $icISOCountry)) { $nCountryCode = $icISOCountry->getISOCode(); } $szCardName = $payment->getCcOwner(); $szCardNumber = $payment->getCcNumber(); $szExpiryDateMonth = $payment->getCcExpMonth(); $szExpiryDateYear = $payment->getCcExpYear(); if ($payment->getCcSsStartMonth() != '') { $szStartDateMonth = $payment->getCcSsStartMonth(); } if ($payment->getCcSsStartYear() != '') { $szStartDateYear = $payment->getCcSsStartYear(); } $szIssueNumber = $payment->getCcSsIssue(); $szCV2 = $payment->getCcCid(); $szHashDigest = CSV_PaymentFormHelper::calculateTransparentRedirectHashDigest($szMerchantID, $szPassword, $hmHashMethod, $szPreSharedKey, $nAmount, $nCurrencyCode, $szOrderID, $szTransactionType, $szTransactionDateTime, $szCallbackURL, $szOrderDescription); Mage::getSingleton('checkout/session')->setHashdigest($szHashDigest)->setMerchantid($szMerchantID)->setAmount($nAmount)->setCurrencycode($nCurrencyCode)->setOrderid($szOrderID)->setTransactiontype($szTransactionType)->setTransactiondatetime($szTransactionDateTime)->setCallbackurl($szCallbackURL)->setOrderdescription($szOrderDescription)->setAddress1($szAddress1)->setAddress2($szAddress2)->setAddress3($szAddress3)->setAddress4($szAddress4)->setCity($szCity)->setState($szState)->setPostcode($szPostCode)->setCountrycode($nCountryCode)->setCardname($szCardName)->setCardnumber($szCardNumber)->setExpirydatemonth($szExpiryDateMonth)->setExpirydateyear($szExpiryDateYear)->setStartdatemonth($szStartDateMonth)->setStartdateyear($szStartDateYear)->setIssuenumber($szIssueNumber)->setCv2($szCV2); Mage::getSingleton('checkout/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')); }