New in Symfony 2.2: Payment related validators
If you are developing an e-commerce solution based on Symfony2, you might want to validate a credit card number before sending it to your payment gateway. Doing so is very simple in Symfony 2.2 thanks to the Luhn algorithm and its implementation as a validator:
1 2 3 4 5 6 7 8 9 10 11 | // src/Acme/SubscriptionBundle/Entity/Transaction.php
use Symfony\Component\Validator\Constraints as Assert;
class Transaction
{
/**
* @Assert\Luhn(message = "Please check your credit card number.")
*/
protected $cardNumber;
}
|
You can also check the card scheme thanks to
Symfony\Component\Validator\Constraints\CardSchemeValidator
.
Comments
BTW, it would be nice to notify translators to provide translation for this new message in as many languages as possible.
It's not a Luhn validator, This validator is a number check, php implementation of Luhn algorithm can be found here http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#PHP
@Francis it is the real luhn algorithm, check : https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/LuhnValidator.php#L49
Wow, I'm loving these 'New in SF2' articles - nice way to communicate the changes without me looking for new features in change logs etc.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Kirill said on Dec 12, 2012 at 12:33 #1