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 JCB
29: */
30: class Mage_Centinel_Model_State_Jcb 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: //Test cases 5-9
51: if (!$this->getIsModeStrict() && $this->_isLookupSoftSuccessful()) {
52: return true;
53: }
54:
55: $paResStatus = $this->getAuthenticatePaResStatus();
56: $eciFlag = $this->getAuthenticateEciFlag();
57: $xid = $this->getAuthenticateXid();
58: $cavv = $this->getAuthenticateCavv();
59: $errorNo = $this->getAuthenticateErrorNo();
60: $signatureVerification = $this->getAuthenticateSignatureVerification();
61:
62: //Test cases 1-4, 10-11
63: if ($this->_isLookupStrictSuccessful()) {
64:
65: if ($paResStatus == 'Y' && $eciFlag == '05' && $xid != '' && $cavv != '' && $errorNo == '0') {
66: //Test case 1
67: if ($signatureVerification == 'Y') {
68: return true;
69: }
70: //Test case 2
71: if ($signatureVerification == 'N') {
72: return false;
73: }
74: }
75:
76: //Test case 3
77: if ($paResStatus == 'N' && $signatureVerification == 'Y' && $eciFlag == '07' &&
78: $xid != '' && $cavv == '' && $errorNo == '0') {
79: return false;
80: }
81:
82: //Test case 4
83: if ($paResStatus == 'U' && $signatureVerification == 'Y' && $eciFlag == '07' &&
84: $xid != '' && $cavv == '' && $errorNo == '0') {
85: if ($this->getIsModeStrict()) {
86: return false;
87: } else {
88: return true;
89: }
90: }
91:
92: //Test case 5
93: if ($paResStatus == 'U' && $signatureVerification == 'Y' && $eciFlag == '07' &&
94: $xid != '' && $cavv == '' && $errorNo == '0') {
95: if ($this->getIsModeStrict()) {
96: return false;
97: } else {
98: return true;
99: }
100: }
101:
102: //Test case 10
103: if ($paResStatus == '' && $signatureVerification == '' && $eciFlag == '07' &&
104: $xid == '' && $cavv == '' && $errorNo != '0') {
105: return false;
106: }
107:
108: //Test case 11
109: if ($paResStatus == 'A' && $signatureVerification == 'Y' && $eciFlag == '06' &&
110: $xid != '' && $cavv != '' && $errorNo == '0') {
111: return true;
112: }
113: }
114:
115: return false;
116: }
117:
118: /**
119: * Analyse lookup`s results. If lookup is strict successful return true
120: *
121: * @return bool
122: */
123: protected function _isLookupStrictSuccessful()
124: {
125: //Test cases 1-4, 6, 10-11
126: if ($this->getLookupEnrolled() == 'Y' &&
127: $this->getLookupAcsUrl() != '' &&
128: $this->getLookupPayload() != '' &&
129: $this->getLookupErrorNo() == '0') {
130: return true;
131: }
132: return false;
133: }
134:
135: /**
136: * Analyse lookup`s results. If lookup is soft successful return true
137: *
138: * @return bool
139: */
140: protected function _isLookupSoftSuccessful()
141: {
142: $acsUrl = $this->getLookupAcsUrl();
143: $payload = $this->getLookupPayload();
144: $errorNo = $this->getLookupErrorNo();
145: $enrolled = $this->getLookupEnrolled();
146:
147: //Test cases 5
148: if ($enrolled == '' && $acsUrl == '' && $payload == '' && $errorNo == '0') {
149: return true;
150: }
151:
152: //Test case 7
153: if ($enrolled == 'U' && $acsUrl == '' && $payload == '' && $errorNo == '0') {
154: return true;
155: }
156:
157: //Test cases 8,9
158: if ($enrolled == 'U' && $acsUrl == '' && $payload == '' && $errorNo != '0') {
159: return true;
160: }
161:
162: return false;
163: }
164: }
165: