Exemplo n.º 1
0
 public function getTransactionDetail($vendorTxCode)
 {
     $pwd = Mage::helper('core')->decrypt($this->_getCdata('api_password'));
     $xml_command = "<command>getTransactionDetail</command>";
     $xml_command .= "<vendor>{$this->_getCdata('vendor')}</vendor>";
     $xml_command .= "<user>{$this->_getCdata('api_username')}</user>";
     $xml_command .= "<vendortxcode>{$vendorTxCode}</vendortxcode>";
     $xml = "<vspaccess>";
     $xml .= $xml_command;
     $xml .= "<signature>" . md5($xml_command . '<password>' . $pwd . '</password>') . "</signature>";
     $xml .= "</vspaccess>";
     Ebizmarts_SagePaySuite_Log::w($xml);
     // Initialise output variable
     $output = array();
     // Open the cURL session
     $curlSession = curl_init();
     //ssl version from config
     $sslversion = Mage::getStoreConfig('payment/sagepaysuite/curl_ssl_version');
     curl_setopt($curlSession, CURLOPT_SSLVERSION, $sslversion);
     // Set the URL
     curl_setopt($curlSession, CURLOPT_URL, $this->_getAccessUrl());
     // No headers, please
     curl_setopt($curlSession, CURLOPT_HEADER, 0);
     // It's a POST request
     curl_setopt($curlSession, CURLOPT_POST, 1);
     // Set the fields for the POST
     curl_setopt($curlSession, CURLOPT_POSTFIELDS, 'XML=' . $xml);
     // Return it direct, don't print it out
     curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
     // This connection will timeout in 30 seconds
     curl_setopt($curlSession, CURLOPT_TIMEOUT, 90);
     //The next two lines must be present for the kit to work with newer version of cURL
     //You should remove them if you have any problems in earlier versions of cURL
     curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
     if (Mage::getStoreConfigFlag('payment/sagepaysuite/curl_proxy') == 1) {
         curl_setopt($curlSession, CURLOPT_PROXY, Mage::getStoreConfig('payment/sagepaysuite/curl_proxy_port'));
     }
     //Send the request and store the result in an array
     $rawresponse = curl_exec($curlSession);
     Ebizmarts_SagePaySuite_Log::w($rawresponse);
     // Check that a connection was made
     if (curl_error($curlSession)) {
         return curl_error($curlSession);
     }
     // Close the cURL session
     curl_close($curlSession);
     return trim($rawresponse);
 }
Exemplo n.º 2
0
 /**
  * Register new token card for customer before new transaction
  * @see Ebizmarts_SagePaySuite_Model_SagePayDirectPro::_postRequest
  */
 public function registerOnPayment($o)
 {
     $request = $o->getEvent()->getRequest();
     $customerSession = Mage::helper('customer')->getCustomer();
     $customerId = (int) $customerSession->getId();
     Ebizmarts_SagePaySuite_Log::w($customerId, null, 'Token.log');
     if (!$customerId) {
         return $o;
     }
     $_data = $request->getData();
     $_pdata = array('Vendor' => '', 'Currency' => '', 'CardHolder' => '', 'CardType' => '', 'CardNumber' => '', 'StartYear' => '', 'StartMonth' => '', 'ExpiryMonth' => '', 'ExpiryYear' => '', 'CV2' => '', 'IssueNumber' => '', 'ExpiryDate' => '', 'StartDate' => '');
     $rs = Mage::getModel('sagepaysuite/sagePayToken')->registerCard(array_intersect_key($_data, $_pdata));
     if (empty($rs)) {
         return $o;
     }
     Ebizmarts_SagePaySuite_Log::w($_data, null, 'SagePayToken.log');
     Ebizmarts_SagePaySuite_Log::w($rs, null, 'SagePayToken.log');
     if ($rs['Status'] == 'OK') {
         $save = Mage::getModel('sagepaysuite2/sagepaysuite_tokencard')->setToken($rs['Token'])->setStatus($rs['Status'])->setCardType($_data['CardType'])->setExpiryDate($_data['ExpiryDate'])->setStatusDetail($rs['StatusDetail'])->setProtocol('direct')->setCustomerId($customerId)->setLastFour(substr($_data['CardNumber'], -4))->save();
     } else {
         Ebizmarts_SagePaySuite_Log::w($rs, null, 'SagePayToken_Errors.log');
         #$customerSession->addError(Mage::helper('sagepaysuite')->__('Could not save credit card token: %s', $rs['StatusDetail']));
     }
 }
Exemplo n.º 3
0
 public function successAction()
 {
     $_r = $this->getRequest();
     Sage_Log::log($_r->getPost(), null, 'SagePaySuite_FORM_Callback.log');
     if ($_r->getParam('crypt') && $_r->getParam('vtxc')) {
         $strDecoded = $this->getFormModel()->decrypt($_r->getParam('crypt'));
         $token = Mage::helper('sagepaysuite/form')->getToken($strDecoded);
         Ebizmarts_SagePaySuite_Log::w($token, null, 'SagePaySuite_FORM_Callback.log');
         $db = Mage::helper('sagepaysuite')->arrayKeysToUnderscore($token);
         # Add data to DB transaction
         $trn = $this->_getTransaction()->loadByVendorTxCode($_r->getParam('vtxc'));
         $trn->addData($db);
         if (isset($db['post_code_result'])) {
             $trn->setPostcodeResult($db['post_code_result']);
         }
         if (isset($db['cv2_result'])) {
             $trn->setCv2result($db['cv2_result']);
         }
         if (isset($db['3_d_secure_status'])) {
             $trn->setThreedSecureStatus($db['3_d_secure_status']);
         }
         if (isset($db['last4_digits'])) {
             $trn->setLastFourDigits($db['last4_digits']);
         }
         if (isset($db['gift_aid'])) {
             $trn->setGiftAid($db['gift_aid']);
         }
         $trn->save();
         Mage::register('sageserverpost', new Varien_Object($token));
         if (strtoupper($trn->getTxType()) == 'PAYMENT') {
             Mage::getSingleton('sagepaysuite/session')->setInvoicePayment(true);
         }
         $this->getOnepage()->getQuote()->collectTotals();
         $this->getOnepage()->saveOrder();
         Mage::helper('sagepaysuite/checkout')->deleteQuote();
         $this->_redirect('checkout/onepage/success');
         return;
     }
     $this->_redirect('/');
     return;
 }
Exemplo n.º 4
0
 public function getOrderPlaceRedirectUrl()
 {
     $tmp = $this->getSageSuiteSession();
     Ebizmarts_SagePaySuite_Log::w($tmp->getAcsurl() . '-' . $tmp->getEmede() . '-' . $tmp->getPareq());
     if ($tmp->getAcsurl() && $tmp->getEmede() && $tmp->getPareq()) {
         #return Mage::getUrl('sagepaydirectpro/payment/redirect', array('_secure' => true));
         return Mage::getUrl('sagepaydirectpro-3dsecure', array('_secure' => true));
     } else {
         return false;
     }
 }
 public function notifyAction()
 {
     Ebizmarts_SagePaySuite_Log::w($_POST, null, 'SagePaySuite_POST_Requests.log');
     //try {
     if (!file_exists(Mage::getBaseDir('var') . '/tmp')) {
         mkdir(Mage::getBaseDir('var') . '/tmp');
     }
     $dbtrn = $this->_trn();
     if ($dbtrn->getId() && file_exists($this->_getCheckFile())) {
         $this->_returnOk();
     }
     $request = $this->getRequest();
     $sagePayServerSession = $this->_getSagePayServerSession();
     $strVendorName = $this->getSPSModel()->getConfigData('vendor');
     $strStatus = $request->getParam('Status', '');
     $strVendorTxCode = $request->getParam('VendorTxCode', '');
     $strVPSTxId = $request->getParam('VPSTxId', '');
     $strSecurityKey = '';
     if ($sagePayServerSession->getVendorTxCode() == $strVendorTxCode && $sagePayServerSession->getVpsTxId() == $strVPSTxId) {
         $strSecurityKey = $sagePayServerSession->getSecurityKey();
         $sagePayServerSession->setVpsTxId($strVPSTxId);
     }
     $response = '';
     if (strlen($strSecurityKey) == 0) {
         $this->_returnInvalid('Security Key invalid');
     } else {
         // Mark
         if ($request->getParam('VendorTxCode')) {
             fopen($this->_getCheckFile(), 'w');
         }
         $strStatusDetail = $strTxAuthNo = $strAVSCV2 = $strAddressResult = $strPostCodeResult = $strCV2Result = $strGiftAid = $str3DSecureStatus = $strCAVV = $strAddressStatus = $strPayerStatus = $strCardType = $strPayerStatus = $strLast4Digits = $strMySignature = '';
         $strVPSSignature = $request->getParam('VPSSignature', '');
         $strStatusDetail = $request->getParam('StatusDetail', '');
         if (strlen($request->getParam('TxAuthNo', '')) > 0) {
             $strTxAuthNo = $request->getParam('TxAuthNo', '');
             $sagePayServerSession->setTxAuthNo($strTxAuthNo);
         }
         $strAVSCV2 = $request->getParam('AVSCV2', '');
         $strAddressResult = $request->getParam('AddressResult', '');
         $strPostCodeResult = $request->getParam('PostCodeResult', '');
         $strCV2Result = $request->getParam('CV2Result', '');
         $strGiftAid = $request->getParam('GiftAid', '');
         $str3DSecureStatus = $request->getParam('3DSecureStatus', '');
         $strCAVV = $request->getParam('CAVV', '');
         $strAddressStatus = $request->getParam('AddressStatus', '');
         $strPayerStatus = $request->getParam('PayerStatus', '');
         $strCardType = $request->getParam('CardType', '');
         $strLast4Digits = $request->getParam('Last4Digits', '');
         $strMessage = $strVPSTxId . $strVendorTxCode . $strStatus . $strTxAuthNo . $strVendorName . $strAVSCV2 . $strSecurityKey . $strAddressResult . $strPostCodeResult . $strCV2Result . $strGiftAid . $str3DSecureStatus . $strCAVV . $strAddressStatus . $strPayerStatus . $strCardType . $strLast4Digits;
         $strMySignature = strtoupper(md5($strMessage));
         $response = '';
         /** We can now compare our MD5 Hash signature with that from Sage Pay Server **/
         $validSignature = (int) $this->getSPSModel()->getConfigData('validate_md5') == 1 && $this->getSPSModel()->getConfigData('mode') == 'live' ? $strMySignature !== $strVPSSignature : false;
         if ($validSignature) {
             $this->_returnInvalid('Cannot match the MD5 Hash. Order might be tampered with. ' . $strStatusDetail);
         } else {
             $strDBStatus = $this->_getHRStatus($strStatus, $strStatusDetail);
             if ($strStatus == 'OK' || $strStatus == 'AUTHENTICATED' || $strStatus == 'REGISTERED') {
                 try {
                     $sagePayServerSession->setTrnhData($this->_setAdditioanlPaymentInfo($strDBStatus));
                     $sOrder = $this->_sAdminOrder();
                     if (FALSE === $sOrder || !$sOrder->getId()) {
                         $sagePayServerSession->setFailStatus($strDBStatus);
                         /** The status indicates a failure of one state or another, so send the customer to orderFailed instead **/
                         $strRedirectPage = $this->_getFailedRedirectUrl();
                         $this->_returnInvalid('Couldnot save order');
                     } else {
                         $orderId = Mage::registry('last_order_id');
                         $dbtrn->addData(Mage::helper('sagepaysuite')->arrayKeysToUnderscore($_POST))->setPostcodeResult($this->getRequest()->getPost('PostCodeResult'))->setThreedSecureStatus($this->getRequest()->getPost('3DSecureStatus'))->setLastFourDigits($this->getRequest()->getPost('Last4Digits'))->setOrderId($orderId)->save();
                         $sagePayServerSession->setSuccessStatus($strDBStatus);
                         //if ($this->ia()) {
                         $sagePayServerSession->setDummyId($sOrder->getId());
                         if ($request->getParam('e')) {
                             $sOrder->sendNewOrderEmail();
                         }
                         //}
                     }
                     Mage::getSingleton('checkout/session')->setSagePayRewInst(null)->setSagePayCustBalanceInst(null);
                     $this->_returnOk();
                 } catch (Exception $e) {
                     Mage::logException($e);
                     Mage::log($e->getMessage());
                 }
             } else {
                 $sagePayServerSession->setFailStatus($strDBStatus);
                 /** The status indicates a failure of one state or another, so send the customer to orderFailed instead **/
                 $this->_returnInvalid($strDBStatus);
             }
         }
     }
     //}} SecurityKey check
 }
Exemplo n.º 6
0
 public static function log($message, $level = null, $file = '')
 {
     Ebizmarts_SagePaySuite_Log::w($message, $level, $file);
 }
Exemplo n.º 7
0
 private function _cancel($trn)
 {
     /**
      * SecurityKey from the "Admin & Access API"
      */
     if (!$trn->getSecurityKey() && strtoupper($trn->getIntegration()) == 'FORM') {
         $this->_addSecurityKey($trn);
     }
     $data = array();
     $data['VPSProtocol'] = $trn->getVpsProtocol();
     $data['TxType'] = self::REQUEST_TYPE_CANCEL;
     $data['ReferrerID'] = $this->getConfigData('referrer_id');
     $data['Vendor'] = $trn->getVendorname();
     $data['VendorTxCode'] = $trn->getVendorTxCode();
     $data['VPSTxId'] = $trn->getVpsTxId();
     $data['SecurityKey'] = $trn->getSecurityKey();
     $result = $this->requestPost($this->getUrl('cancel', false, $this->_getIntegrationCode($trn->getIntegration()), $trn->getMode()), $data);
     if ($result['Status'] != 'OK') {
         Ebizmarts_SagePaySuite_Log::w($result['StatusDetail']);
         Mage::throwException($result['StatusDetail']);
     }
     $this->saveAction($trn->getOrderId(), $data, $result);
     $trn->setCanceled(1)->save();
 }