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: * Abstract Validation State Model for Visa
29: */
30: class Mage_Centinel_Model_State_Visa extends Mage_Centinel_Model_StateAbstract
31: {
32: /**
33: * Analyse lookup`s results. If it has require params for authenticate, return true
34: *
35: * @return bool
36: */
37: public function isAuthenticateAllowed()
38: {
39: return $this->_isLookupStrictSuccessful() && is_null($this->getAuthenticateEciFlag());
40: }
41:
42: /**
43: * Analyse authenticate`s results. If authenticate is successful return true and false if it failure
44: * Result depends from flag self::getIsModeStrict()
45: *
46: * @return bool
47: */
48: public function isAuthenticateSuccessful()
49: {
50: $paResStatus = $this->getAuthenticatePaResStatus();
51: $eciFlag = $this->getAuthenticateEciFlag();
52: $xid = $this->getAuthenticateXid();
53: $cavv = $this->getAuthenticateCavv();
54: $errorNo = $this->getAuthenticateErrorNo();
55: $signatureVerification = $this->getAuthenticateSignatureVerification();
56:
57: //Test cases 1-5, 11
58: if ($this->_isLookupStrictSuccessful()) {
59:
60: if ($paResStatus == 'Y' && $eciFlag == '05' && $xid != '' && $cavv != '' && $errorNo == '0') {
61: //Test case 1
62: if ($signatureVerification == 'Y') {
63: return true;
64: }
65: //Test case 2
66: if ($signatureVerification == 'N') {
67: return false;
68: }
69: }
70:
71: //Test case 3
72: if ($paResStatus == 'N' && $signatureVerification == 'Y' && $eciFlag == '07' &&
73: $xid != '' && $cavv == '' && $errorNo == '0') {
74: return false;
75: }
76:
77: //Test case 4
78: if ($paResStatus == 'A' && $signatureVerification == 'Y' && $eciFlag == '06' &&
79: $xid != '' && $cavv != '' && $errorNo == '0') {
80: if ($this->getIsModeStrict()) {
81: return false;
82: } else {
83: return true;
84: }
85: }
86:
87: //Test case 5
88: if ($paResStatus == 'U' && $signatureVerification == 'Y' && $eciFlag == '07' &&
89: $xid != '' && $cavv == '' && $errorNo == '0') {
90: if ($this->getIsModeStrict()) {
91: return false;
92: } else {
93: return true;
94: }
95: }
96:
97: //Test case 11
98: if ($paResStatus == 'U' && $signatureVerification == '' && $eciFlag == '07' &&
99: $xid == '' && $cavv == '' && $errorNo == '1050') {
100: if ($this->getIsModeStrict()) {
101: return false;
102: } else {
103: return true;
104: }
105: }
106:
107: }
108:
109: //Test cases 6-10
110: if (!$this->getIsModeStrict() && $this->_isLookupSoftSuccessful()) {
111: if ($paResStatus == '' && $signatureVerification == '' && $eciFlag == '' &&
112: $xid == '' && $cavv == '' && $errorNo == '0') {
113: return true;
114: } elseif ($paResStatus == false && $signatureVerification == false && $eciFlag == false &&
115: $xid == false && $cavv == false && $errorNo == false) {
116: return true;
117: }
118: }
119:
120: return false;
121: }
122:
123: /**
124: * Analyse lookup`s results. If lookup is strict successful return true
125: *
126: * @return bool
127: */
128: protected function _isLookupStrictSuccessful()
129: {
130: //Test cases 1-5, 11
131: if ($this->getLookupEnrolled() == 'Y' &&
132: $this->getLookupAcsUrl() != '' &&
133: $this->getLookupPayload() != '' &&
134: $this->getLookupErrorNo() == '0') {
135: return true;
136: }
137: return false;
138: }
139:
140: /**
141: * Analyse lookup`s results. If lookup is soft successful return true
142: *
143: * @return bool
144: */
145: protected function _isLookupSoftSuccessful()
146: {
147: $acsUrl = $this->getLookupAcsUrl();
148: $payload = $this->getLookupPayload();
149: $errorNo = $this->getLookupErrorNo();
150: $enrolled = $this->getLookupEnrolled();
151:
152: //Test cases 7,8
153: if ($acsUrl == '' && $payload == '' && $errorNo == '0' && ($enrolled == 'N' || $enrolled == 'U')) {
154: return true;
155: }
156:
157: //Test case 6
158: if ($enrolled == '' && $acsUrl == '' && $payload == '' && $errorNo == 'Timeout number') {
159: return true;
160: }
161:
162: //Test cases 9,10
163: if ($enrolled == 'U' && $acsUrl == '' && $payload == '' && $errorNo == '1001') {
164: return true;
165: }
166:
167: return false;
168: }
169: }
170: