Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Validate_CreditCard Class Reference
Inheritance diagram for Zend_Validate_CreditCard:
Zend_Validate_Abstract Zend_Validate_Interface

Public Member Functions

 __construct ($options=array())
 
 getType ()
 
 setType ($type)
 
 addType ($type)
 
 getService ()
 
 setService ($service)
 
 isValid ($value)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 

Data Fields

const ALL = 'All'
 
const AMERICAN_EXPRESS = 'American_Express'
 
const UNIONPAY = 'Unionpay'
 
const DINERS_CLUB = 'Diners_Club'
 
const DINERS_CLUB_US = 'Diners_Club_US'
 
const DISCOVER = 'Discover'
 
const JCB = 'JCB'
 
const LASER = 'Laser'
 
const MAESTRO = 'Maestro'
 
const MASTERCARD = 'Mastercard'
 
const SOLO = 'Solo'
 
const VISA = 'Visa'
 
const CHECKSUM = 'creditcardChecksum'
 
const CONTENT = 'creditcardContent'
 
const INVALID = 'creditcardInvalid'
 
const LENGTH = 'creditcardLength'
 
const PREFIX = 'creditcardPrefix'
 
const SERVICE = 'creditcardService'
 
const SERVICEFAILURE = 'creditcardServiceFailure'
 

Protected Attributes

 $_messageTemplates
 
 $_cardLength
 
 $_cardType
 
 $_type = array()
 
 $_service
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 33 of file CreditCard.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = array())

Constructor

Parameters
string | array | Zend_Config$optionsOPTIONAL Type of CCI to allow

Definition at line 141 of file CreditCard.php.

142  {
143  if ($options instanceof Zend_Config) {
144  $options = $options->toArray();
145  } else if (!is_array($options)) {
146  $options = func_get_args();
147  $temp['type'] = array_shift($options);
148  if (!empty($options)) {
149  $temp['service'] = array_shift($options);
150  }
151 
152  $options = $temp;
153  }
154 
155  if (!array_key_exists('type', $options)) {
156  $options['type'] = self::ALL;
157  }
158 
159  $this->setType($options['type']);
160  if (array_key_exists('service', $options)) {
161  $this->setService($options['service']);
162  }
163  }

Member Function Documentation

◆ addType()

addType (   $type)

Adds a CCI to be accepted by validation

Parameters
string | array$typeType to allow for validation
Returns
Zend_Validate_CreditCard Provides a fluent interface

Definition at line 193 of file CreditCard.php.

194  {
195  if (is_string($type)) {
196  $type = array($type);
197  }
198 
199  foreach($type as $typ) {
200  if (defined('self::' . strtoupper($typ)) && !in_array($typ, $this->_type)) {
201  $this->_type[] = $typ;
202  }
203 
204  if (($typ == self::ALL)) {
205  $this->_type = array_keys($this->_cardLength);
206  }
207  }
208 
209  return $this;
210  }
$type
Definition: item.phtml:13

◆ getService()

getService ( )

Returns the actual set service

Returns
callback

Definition at line 217 of file CreditCard.php.

218  {
219  return $this->_service;
220  }

◆ getType()

getType ( )

Returns a list of accepted CCIs

Returns
array

Definition at line 170 of file CreditCard.php.

171  {
172  return $this->_type;
173  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)

Parameters
string$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 248 of file CreditCard.php.

249  {
250  $this->_setValue($value);
251 
252  if (!is_string($value)) {
253  $this->_error(self::INVALID, $value);
254  return false;
255  }
256 
257  if (!ctype_digit($value)) {
258  $this->_error(self::CONTENT, $value);
259  return false;
260  }
261 
262  $length = strlen($value);
263  $types = $this->getType();
264  $foundp = false;
265  $foundl = false;
266  foreach ($types as $type) {
267  foreach ($this->_cardType[$type] as $prefix) {
268  if (substr($value, 0, strlen($prefix)) == $prefix) {
269  $foundp = true;
270  if (in_array($length, $this->_cardLength[$type])) {
271  $foundl = true;
272  break 2;
273  }
274  }
275  }
276  }
277 
278  if ($foundp == false){
279  $this->_error(self::PREFIX, $value);
280  return false;
281  }
282 
283  if ($foundl == false) {
284  $this->_error(self::LENGTH, $value);
285  return false;
286  }
287 
288  $sum = 0;
289  $weight = 2;
290 
291  for ($i = $length - 2; $i >= 0; $i--) {
292  $digit = $weight * $value[$i];
293  $sum += floor($digit / 10) + $digit % 10;
294  $weight = $weight % 2 + 1;
295  }
296 
297  if ((10 - $sum % 10) % 10 != $value[$length - 1]) {
298  $this->_error(self::CHECKSUM, $value);
299  return false;
300  }
301 
302  if (!empty($this->_service)) {
303  try {
304  #require_once 'Zend/Validate/Callback.php';
305  $callback = new Zend_Validate_Callback($this->_service);
306  $callback->setOptions($this->_type);
307  if (!$callback->isValid($value)) {
308  $this->_error(self::SERVICE, $value);
309  return false;
310  }
311  } catch (Zend_Exception $e) {
312  $this->_error(self::SERVICEFAILURE, $value);
313  return false;
314  }
315  }
316 
317  return true;
318  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$type
Definition: item.phtml:13
$prefix
Definition: name.phtml:25
$value
Definition: gender.phtml:16
$i
Definition: gallery.phtml:31

◆ setService()

setService (   $service)

Sets a new callback for service validation

Parameters
mixed$service
Exceptions
Zend_Validate_Exception
Returns
$this

Definition at line 229 of file CreditCard.php.

230  {
231  if (!is_callable($service)) {
232  #require_once 'Zend/Validate/Exception.php';
233  throw new Zend_Validate_Exception('Invalid callback given');
234  }
235 
236  $this->_service = $service;
237  return $this;
238  }

◆ setType()

setType (   $type)

Sets CCIs which are accepted by validation

Parameters
string | array$typeType to allow for validation
Returns
Zend_Validate_CreditCard Provides a fluent interface

Definition at line 181 of file CreditCard.php.

182  {
183  $this->_type = array();
184  return $this->addType($type);
185  }
$type
Definition: item.phtml:13

Field Documentation

◆ $_cardLength

$_cardLength
protected
Initial value:
= array(
self::AMERICAN_EXPRESS => array(15),
self::DINERS_CLUB => array(14),
self::DINERS_CLUB_US => array(16),
self::DISCOVER => array(16),
self::JCB => array(16),
self::LASER => array(16, 17, 18, 19),
self::MAESTRO => array(12, 13, 14, 15, 16, 17, 18, 19),
self::MASTERCARD => array(16),
self::SOLO => array(16, 18, 19),
self::UNIONPAY => array(16, 17, 18, 19),
self::VISA => array(16),
)

Definition at line 81 of file CreditCard.php.

◆ $_cardType

$_cardType
protected
Initial value:
= array(
self::AMERICAN_EXPRESS => array('34', '37'),
self::DINERS_CLUB => array('300', '301', '302', '303', '304', '305', '36'),
self::DINERS_CLUB_US => array('54', '55'),
self::DISCOVER => array('6011', '622126', '622127', '622128', '622129', '62213',
'62214', '62215', '62216', '62217', '62218', '62219',
'6222', '6223', '6224', '6225', '6226', '6227', '6228',
'62290', '62291', '622920', '622921', '622922', '622923',
'622924', '622925', '644', '645', '646', '647', '648',
'649', '65'),
self::JCB => array('3528', '3529', '353', '354', '355', '356', '357', '358'),
self::LASER => array('6304', '6706', '6771', '6709'),
self::MAESTRO => array('5018', '5020', '5038', '6304', '6759', '6761', '6763'),
self::MASTERCARD => array('51', '52', '53', '54', '55'),
self::SOLO => array('6334', '6767'),
self::UNIONPAY => array('622126', '622127', '622128', '622129', '62213', '62214',
'62215', '62216', '62217', '62218', '62219', '6222', '6223',
'6224', '6225', '6226', '6227', '6228', '62290', '62291',
'622920', '622921', '622922', '622923', '622924', '622925'),
self::VISA => array('4'),
)

Definition at line 100 of file CreditCard.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::CHECKSUM => "'%value%' seems to contain an invalid checksum",
self::CONTENT => "'%value%' must contain only digits",
self::INVALID => "Invalid type given. String expected",
self::LENGTH => "'%value%' contains an invalid amount of digits",
self::PREFIX => "'%value%' is not from an allowed institute",
self::SERVICE => "'%value%' seems to be an invalid creditcard number",
self::SERVICEFAILURE => "An exception has been raised while validating '%value%'",
)

Definition at line 66 of file CreditCard.php.

◆ $_service

$_service
protected

Definition at line 134 of file CreditCard.php.

◆ $_type

$_type = array()
protected

Definition at line 127 of file CreditCard.php.

◆ ALL

const ALL = 'All'

Definition at line 40 of file CreditCard.php.

◆ AMERICAN_EXPRESS

const AMERICAN_EXPRESS = 'American_Express'

Definition at line 41 of file CreditCard.php.

◆ CHECKSUM

const CHECKSUM = 'creditcardChecksum'

Definition at line 53 of file CreditCard.php.

◆ CONTENT

const CONTENT = 'creditcardContent'

Definition at line 54 of file CreditCard.php.

◆ DINERS_CLUB

const DINERS_CLUB = 'Diners_Club'

Definition at line 43 of file CreditCard.php.

◆ DINERS_CLUB_US

const DINERS_CLUB_US = 'Diners_Club_US'

Definition at line 44 of file CreditCard.php.

◆ DISCOVER

const DISCOVER = 'Discover'

Definition at line 45 of file CreditCard.php.

◆ INVALID

const INVALID = 'creditcardInvalid'

Definition at line 55 of file CreditCard.php.

◆ JCB

const JCB = 'JCB'

Definition at line 46 of file CreditCard.php.

◆ LASER

const LASER = 'Laser'

Definition at line 47 of file CreditCard.php.

◆ LENGTH

const LENGTH = 'creditcardLength'

Definition at line 56 of file CreditCard.php.

◆ MAESTRO

const MAESTRO = 'Maestro'

Definition at line 48 of file CreditCard.php.

◆ MASTERCARD

const MASTERCARD = 'Mastercard'

Definition at line 49 of file CreditCard.php.

◆ PREFIX

const PREFIX = 'creditcardPrefix'

Definition at line 57 of file CreditCard.php.

◆ SERVICE

const SERVICE = 'creditcardService'

Definition at line 58 of file CreditCard.php.

◆ SERVICEFAILURE

const SERVICEFAILURE = 'creditcardServiceFailure'

Definition at line 59 of file CreditCard.php.

◆ SOLO

const SOLO = 'Solo'

Definition at line 50 of file CreditCard.php.

◆ UNIONPAY

const UNIONPAY = 'Unionpay'

Definition at line 42 of file CreditCard.php.

◆ VISA

const VISA = 'Visa'

Definition at line 51 of file CreditCard.php.


The documentation for this class was generated from the following file: