public function validateData(Order $order, array $data) { $result = ValidationResult::create(); //TODO: validate credit card data if (!Helper::validateLuhn($data['number'])) { $result->error(_t('OnsitePaymentCheckoutComponent.CREDIT_CARD_INVALID', 'Credit card is invalid')); throw new ValidationException($result); } }
public function validateData(Order $order, array $data) { $result = new ValidationResult(); //TODO: validate credit card data if (!Helper::validateLuhn($data['number'])) { $result->error('Credit card is invalid'); throw new ValidationException($result); } }
/** * 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'); } } }
/** * Validate this credit card. If the card is invalid, InvalidCreditCardException is thrown. * * This method is called internally by gateways to avoid wasting time with an API call * when the credit card is clearly invalid. * * Generally if you want to validate the credit card yourself with custom error * messages, you should use your framework's validation library, not this method. * * @throws InvalidCreditCardException * @return void */ public function validate() { foreach (array('number', 'expiryMonth', 'expiryYear') as $key) { if (!$this->getParameter($key)) { throw new InvalidCreditCardException("The {$key} parameter is required"); } } if ($this->getExpiryDate('Ym') < gmdate('Ym')) { throw new InvalidCreditCardException('Card has expired'); } if (!Helper::validateLuhn($this->getNumber())) { throw new InvalidCreditCardException('Card number is invalid'); } if (!is_null($this->getNumber()) && !preg_match('/^\\d{12,19}$/i', $this->getNumber())) { throw new InvalidCreditCardException('Card number should have 12 to 19 digits'); } }
public function testValidateLuhnNull() { $result = Helper::validateLuhn(null); $this->assertTrue($result); }
/** * Validate this credit card. If the card is invalid, InvalidCreditCardException is thrown. * * This method is called internally by gateways to avoid wasting time with an API call * when the credit card is clearly invalid. * * Generally if you want to validate the credit card yourself with custom error * messages, you should use your framework's validation library, not this method. */ public function validate() { foreach (array('number', 'expiryMonth', 'expiryYear') as $key) { if (!$this->getParameter($key)) { throw new InvalidCreditCardException("The {$key} parameter is required"); } } if ($this->getExpiryDate('Ym') < gmdate('Ym')) { throw new InvalidCreditCardException('Card has expired'); } if (!Helper::validateLuhn($this->getNumber())) { throw new InvalidCreditCardException('Card number is invalid'); } }
public function creditCardLuhn($attribute, $params) { if (!OmnipayHelper::validateLuhn($this->{$attribute})) { $this->addError($attribute, Craft::t('Not a valid Credit Card Number')); } }