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: /**
29: * 3D Secure Validation Model
30: *
31: * @category Mage
32: * @package Mage_Centinel
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Centinel_Model_Observer extends Varien_Object
36: {
37: /**
38: * Set cmpi data to payment
39: *
40: * @param Varien_Object $observer
41: * @return Mage_Centinel_Model_Observer
42: */
43: public function salesEventConvertQuoteToOrder($observer)
44: {
45: $payment = $observer->getEvent()->getQuote()->getPayment();
46:
47: if ($payment->getMethodInstance()->getIsCentinelValidationEnabled()) {
48: $to = array($payment, 'setAdditionalInformation');
49: $payment->getMethodInstance()->getCentinelValidator()->exportCmpiData($to);
50: }
51: return $this;
52: }
53:
54: /**
55: * Add cmpi data to info block
56: *
57: * @param Varien_Object $observer
58: * @return Mage_Centinel_Model_Observer
59: */
60: public function paymentInfoBlockPrepareSpecificInformation($observer)
61: {
62: if ($observer->getEvent()->getBlock()->getIsSecureMode()) {
63: return;
64: }
65:
66: $payment = $observer->getEvent()->getPayment();
67: $transport = $observer->getEvent()->getTransport();
68: $helper = Mage::helper('centinel');
69:
70: $info = array(
71: Mage_Centinel_Model_Service::CMPI_PARES,
72: Mage_Centinel_Model_Service::CMPI_ENROLLED,
73: Mage_Centinel_Model_Service::CMPI_ECI,
74: Mage_Centinel_Model_Service::CMPI_CAVV,
75: Mage_Centinel_Model_Service::CMPI_XID
76: );
77: foreach ($info as $key) {
78: if ($value = $payment->getAdditionalInformation($key)) {
79: $transport->setData($helper->getCmpiLabel($key), $helper->getCmpiValue($key, $value));
80: }
81: }
82: return $this;
83: }
84:
85: /**
86: * Add centinel logo block into payment form
87: *
88: * @param Varien_Object $observer
89: * @return Mage_Centinel_Model_Observer
90: */
91: public function paymentFormBlockToHtmlBefore($observer)
92: {
93: $paymentFormBlock = $observer->getEvent()->getBlock();
94: $method = $paymentFormBlock->getMethod();
95:
96: if ($method && $method->getIsCentinelValidationEnabled()) {
97: $paymentFormBlock->setChild(
98: 'payment.method.' . $method->getCode() . 'centinel.logo',
99: Mage::helper('centinel')->getMethodFormBlock($method)
100: );
101: }
102: return $this;
103: }
104:
105: /**
106: * Reset validation data
107: *
108: * @param Varien_Object $observer
109: * @return Mage_Centinel_Model_Observer
110: */
111: public function checkoutSubmitAllAfter($observer)
112: {
113: $method = false;
114:
115: if ($order = $observer->getEvent()->getOrder()) {
116: $method = $order->getPayment()->getMethodInstance();
117: } elseif ($orders = $observer->getEvent()->getOrders()) {
118: if ($order = array_shift($orders)) {
119: $method = $order->getPayment()->getMethodInstance();
120: }
121: }
122:
123: if ($method && $method->getIsCentinelValidationEnabled()) {
124: $method->getCentinelValidator()->reset();
125: }
126: return $this;
127: }
128:
129: /**
130: * Reset validation data
131: * @deprecated back compatibility alias for checkoutSubmitAllAfter
132: *
133: * @param Varien_Object $observer
134: * @return Mage_Centinel_Model_Observer
135: */
136: public function salesOrderPaymentPlaceEnd($observer)
137: {
138: $this->checkoutSubmitAllAfter($observer);
139: return $this;
140: }
141: }
142: