Ejemplo n.º 1
0
 public function setEncryptedFormat($value)
 {
     $value = EncryptedFormat::memberByValue($value)->value();
     return $this->setParameter('EncryptedFormat', $value);
 }
Ejemplo n.º 2
0
 /**
  * Model validation ensures that any data that is present in the model is
  * formatted correctly. No business logic validation is performed at this
  * level.
  *
  * @throws InvalidRequestException if validation fails.
  */
 public function validate()
 {
     if (strlen($this['CardNumber'])) {
         if (!preg_match('/^\\d{12,19}$/', $this['CardNumber'])) {
             throw new InvalidRequestException('CardNumber should have 12 to 19 digits');
         }
         if (!Helper::validateLuhn($this['CardNumber'])) {
             throw new InvalidRequestException('CardNumber is invalid');
         }
     }
     if (strlen($this['ExpirationMonth'] && strlen($this['ExpirationYear']))) {
         $time = gmmktime(0, 0, 0, $this['ExpirationMonth'], 1, $this['ExpirationYear']);
         if (gmdate('Ym', $time) < gmdate('Ym')) {
             throw new InvalidRequestException('Card has expired');
         }
     }
     if (strlen($this['Track1Data']) && !preg_match('/^.{1,76}$/', $this['Track1Data'])) {
         throw new InvalidRequestException('Track1Data should have 76 or fewer characters');
     }
     if (strlen($this['Track2Data']) && !preg_match('/^.{1,37}$/', $this['Track2Data'])) {
         throw new InvalidRequestException('Track2Data should have 37 or fewer characters');
     }
     if (strlen($this['MagneprintData']) && !preg_match('/^.{1,700}$/', $this['MagneprintData'])) {
         throw new InvalidRequestException('MagneprintData should have 700 or fewer characters');
     }
     if (strlen($this['CVV']) && !preg_match('/^\\d{1,4}$/', $this['CVV'])) {
         throw new InvalidRequestException('CVV should have 4 or fewer digits');
     }
     if (strlen($this['EncryptedTrack1Data']) && !preg_match('/^.{1,300}$/', $this['EncryptedTrack1Data'])) {
         throw new InvalidRequestException('EncryptedTrack1Data should have 300 or fewer characters');
     }
     if (strlen($this['EncryptedTrack2Data']) && !preg_match('/^.{1,200}$/', $this['EncryptedTrack2Data'])) {
         throw new InvalidRequestException('EncryptedTrack2Data should have 200 or fewer characters');
     }
     if (strlen($this['EncryptedCardData']) && !preg_match('/^.{1,200}$/', $this['EncryptedCardData'])) {
         throw new InvalidRequestException('EncryptedCardData should have 200 or fewer characters');
     }
     if (strlen($this['CardDataKeySerialNumber']) && !preg_match('/^.{1,26}$/', $this['CardDataKeySerialNumber'])) {
         throw new InvalidRequestException('CardDataKeySerialNumber should have 26 or fewer characters');
     }
     if (isset($this['EncryptedFormat'])) {
         try {
             EncryptedFormat::memberByValue($this['EncryptedFormat']);
         } catch (\Exception $e) {
             throw new InvalidRequestException('Invalid value for EncryptedFormat');
         }
     }
 }