1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Centinel
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Centinel Index Controller
29: *
30: * @category Mage
31: * @package Mage_Centinel
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Centinel_Adminhtml_Centinel_IndexController extends Mage_Adminhtml_Controller_Action
35: {
36: /**
37: * Process validate payment data action
38: *
39: */
40: public function validatePaymentDataAction()
41: {
42: $result = array();
43: try {
44: $paymentData = $this->getRequest()->getParam('payment');
45: $validator = $this->_getValidator();
46: if (!$validator) {
47: throw new Exception('This payment method does not have centinel validation.');
48: }
49: $validator->reset();
50: $this->_getPayment()->importData($paymentData);
51: $result['authenticationUrl'] = $validator->getAuthenticationStartUrl();
52: } catch (Mage_Core_Exception $e) {
53: $result['message'] = $e->getMessage();
54: } catch (Exception $e) {
55: Mage::logException($e);
56: $result['message'] = Mage::helper('centinel')->__('Validation failed.');
57: }
58: $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
59: }
60:
61: /**
62: * Process autentication start action
63: *
64: */
65: public function authenticationStartAction()
66: {
67: if ($validator = $this->_getValidator()) {
68: Mage::register('current_centinel_validator', $validator);
69: }
70: $this->loadLayout()->renderLayout();
71: }
72:
73: /**
74: * Process autentication complete action
75: *
76: */
77: public function authenticationCompleteAction()
78: {
79: try {
80: if ($validator = $this->_getValidator()) {
81: $request = $this->getRequest();
82:
83: $data = new Varien_Object();
84: $data->setTransactionId($request->getParam('MD'));
85: $data->setPaResPayload($request->getParam('PaRes'));
86:
87: $validator->authenticate($data);
88: Mage::register('current_centinel_validator', $validator);
89: }
90: } catch (Exception $e) {
91: Mage::register('current_centinel_validator', false);
92: }
93: $this->loadLayout()->renderLayout();
94: }
95:
96: /**
97: * Return payment model
98: *
99: * @return Mage_Sales_Model_Quote_Payment
100: */
101: private function _getPayment()
102: {
103: $model = Mage::getSingleton('adminhtml/sales_order_create');
104: return $model->getQuote()->getPayment();
105: }
106:
107: /**
108: * Return Centinel validation model
109: *
110: * @return Mage_Centinel_Model_Service
111: */
112: private function _getValidator()
113: {
114: if ($this->_getPayment()->getMethodInstance()->getIsCentinelValidationEnabled()) {
115: return $this->_getPayment()->getMethodInstance()->getCentinelValidator();
116: }
117: return false;
118: }
119: }
120:
121: