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