-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Adding documentation for the CardScheme validation. #2054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
CardScheme | ||
========== | ||
|
||
.. versionadded:: 2.2 | ||
The CardScheme validation is new in Symfony 2.2. | ||
|
||
This constraint ensures that a credit card number is valid for a given credit card | ||
company. It can be used to validate the number before trying to initiate a payment | ||
through a payment gateway. | ||
|
||
+----------------+--------------------------------------------------------------------------+ | ||
| Applies to | :ref:`property or method<validation-property-target>` | | ||
+----------------+--------------------------------------------------------------------------+ | ||
| Options | - `schemes`_ | | ||
| | - `message`_ | | ||
+----------------+--------------------------------------------------------------------------+ | ||
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\CardScheme` | | ||
+----------------+--------------------------------------------------------------------------+ | ||
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\CardSchemeValidator` | | ||
+----------------+--------------------------------------------------------------------------+ | ||
|
||
Basic Usage | ||
----------- | ||
|
||
To use the CardScheme validator, simply apply it to a property or method on an | ||
object that will contain a credit card number. | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# src/Acme/SubscriptionBundle/Resources/config/validation.yml | ||
Acme\SubscriptionBundle\Entity\Transaction: | ||
properties: | ||
cardNumber: | ||
- CardScheme: | ||
schemes: [VISA] | ||
message: You credit card number is invalid. | ||
|
||
.. code-block:: xml | ||
|
||
<!-- src/Acme/SubscriptionBundle/Resources/config/validation.xml --> | ||
<class name="Acme\SubscriptionBundle\Entity\Transaction"> | ||
<property name="cardNumber"> | ||
<constraint name="CardScheme"> | ||
<option name="schemes"> | ||
<value>VISA</value> | ||
</option> | ||
<option name="message">You credit card number is invalid.</option> | ||
</constraint> | ||
</property> | ||
</class> | ||
|
||
.. code-block:: php-annotations | ||
|
||
// src/Acme/SubscriptionBundle/Entity/Transaction.php | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Transaction | ||
{ | ||
/** | ||
* @Assert\CardScheme(schemes = {"VISA"}, message = "You credit card number is invalid.") | ||
*/ | ||
protected $cardNumber; | ||
} | ||
|
||
.. code-block:: php | ||
|
||
// src/Acme/SubscriptionBundle/Entity/Transaction.php | ||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
use Symfony\Component\Validator\Constraints\CardScheme; | ||
|
||
class Transaction | ||
{ | ||
protected $cardNumber; | ||
|
||
public static function loadValidatorMetadata(ClassMetadata $metadata) | ||
{ | ||
$metadata->addPropertyConstraint('cardSchema', new CardScheme(array( | ||
'schemes' => array( | ||
'VISA' | ||
), | ||
'message' => 'You credit card number is invalid.', | ||
))); | ||
} | ||
} | ||
|
||
Available Options | ||
----------------- | ||
|
||
schemes | ||
------- | ||
|
||
**type**: ``array`` | ||
|
||
The name of the number scheme used to validate the credit card number. Valid values are: | ||
|
||
* AMEX | ||
* CHINA_UNIONPAY | ||
* DINERS | ||
* DISCOVER | ||
* INSTAPAYMENT | ||
* JCB | ||
* LASER | ||
* MAESTRO | ||
* MASTERCARD | ||
* VISA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you'll use these strings in your code, wrap each of them with the double-tick:
|
||
|
||
For more information about the used schemes, see `Wikipedia`_. | ||
|
||
message | ||
~~~~~~~ | ||
|
||
**type**: ``string`` **default**: ``Unsupported card type or invalid card number`` | ||
|
||
The default message supplied when the value does not pass the CardScheme check. | ||
|
||
.. _`Wikipedia`: http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention here that this option is required