1 <?php
2
3
4 namespace Mypos\IPC;
5
6
7 use Nette\Utils\DateTime;
8
9 class Card
10 {
11
12 const CARD_TYPE_MASTERCARD = 1;
13 const CARD_TYPE_MAESTRO = 2;
14 const CARD_TYPE_VISA = 3;
15 const CARD_TYPE_VISA_ELECTRON = 4;
16 const CARD_TYPE_VPAY = 5;
17 const CARD_TYPE_JCB = 6;
18
19
20 private $cardType, $cardNumber, $cardHolder, $expMM, $expYY, $cvc, $eci, $avv, $xid, $cardToken;
21
22 23 24
25 public function getCardType()
26 {
27 return $this->cardType;
28 }
29
30 31 32
33 public function setCardType($cardType)
34 {
35 $this->cardType = $cardType;
36 }
37
38 39 40
41 public function getCardNumber()
42 {
43 return $this->cardNumber;
44 }
45
46 47 48
49 public function setCardNumber($cardNumber)
50 {
51 $this->cardNumber = $cardNumber;
52 }
53
54
55 56 57
58 public function getCardHolder()
59 {
60 return $this->cardHolder;
61 }
62
63 64 65
66 public function setCardHolder($cardHolder)
67 {
68 $this->cardHolder = $cardHolder;
69 }
70
71 72 73
74 public function getExpMM()
75 {
76 return $this->expMM;
77 }
78
79 80 81
82 public function setExpMM($expMM)
83 {
84 $this->expMM = $expMM;
85 }
86
87 88 89
90 public function getExpYY()
91 {
92 return $this->expYY;
93 }
94
95 96 97
98 public function setExpYY($expYY)
99 {
100 $this->expYY = $expYY;
101 }
102
103 104 105
106 public function getCvc()
107 {
108 return $this->cvc;
109 }
110
111 112 113
114 public function setCvc($cvc)
115 {
116 $this->cvc = $cvc;
117 }
118
119 120 121
122 public function getEci()
123 {
124 return $this->eci;
125 }
126
127 128 129
130 public function setEci($eci)
131 {
132 $this->eci = $eci;
133 }
134
135 136 137
138 public function getAvv()
139 {
140 return $this->avv;
141 }
142
143 144 145
146 public function setAvv($avv)
147 {
148 $this->avv = $avv;
149 }
150
151 152 153
154 public function getXid()
155 {
156 return $this->xid;
157 }
158
159 160 161
162 public function setXid($xid)
163 {
164 $this->xid = $xid;
165 }
166
167 168 169
170 public function getCardToken()
171 {
172 return $this->cardToken;
173 }
174
175 176 177
178 public function setCardToken($cardToken)
179 {
180 $this->cardToken = $cardToken;
181 }
182
183 public function validate()
184 {
185 if ($this->getCardToken()) {
186 return true;
187 }
188
189 if ($this->getCardNumber() == null || !Helper::isValidCardNumber($this->getCardNumber())) {
190 throw new IPC_Exception('Invalid card number');
191 }
192
193 if ($this->getCvc() == null || !Helper::isValidCVC($this->getCvc())) {
194 throw new IPC_Exception('Invalid card CVC');
195 }
196
197 if ($this->getExpMM() == null || !is_numeric($this->getExpMM()) || intval($this->getExpMM()) <= 0 || intval($this->getExpMM()) > 12) {
198 throw new IPC_Exception('Invalid card expire date (MM)');
199 }
200
201 if ($this->getExpYY() == null || !is_numeric($this->getExpYY()) || intval($this->getExpYY()) < date('y')) {
202 throw new IPC_Exception('Invalid card expire date (YY)');
203 }
204 }
205
206 207 208 209
210 public function getExpDate()
211 {
212 return str_pad($this->getExpYY(), 2, 0, STR_PAD_LEFT) . str_pad($this->getExpMM(), 2, 0, STR_PAD_LEFT);
213 }
214 }