Stefan Hornburg (Racke) > Data-Transpose-0.0007 > Data::Transpose::Validator::CreditCard

Download:
Data-Transpose-0.0007.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source   Latest Release: Data-Transpose-0.0010

NAME ^

Data::Transpose::Validator::CreditCard - Validator for CC numbers

SYNOPSIS ^

From inside Data::Transpose::Validator

  $dtv->prepare(
                cc_number => {
                              validator => {
                                            class => 'CreditCard',
                                            options => {
                                                        types => [ "visa card",
                                                                  "mastercard",
                                                                  "American Express card",
                                                                  "Discover card" ],
                                                        country => 'DE',
                                                       },
                                           },
                              required => 1,
                             },
                cc_month => {
                             validator => {
                                           class => 'NumericRange',
                                           options => {
                                                       min => 1,
                                                       max => 12,
                                                      },
                                          },
                             required => 1,
                            },
                cc_year => {
                            validator => {
                                          class => 'NumericRange',
                                          options => {
                                                      min => 2013,
                                                      max => 2023,
                                                     },
                                         },
                            required => 1,
                           }
               );
  my $form = {
              cc_number => ' 4111111111111111 ',
              cc_month => '12',
              cc_year => '2014',
             };
  
  my $clean = $dtv->transpose($form);
  
  ok($clean, "validation ok");

Or, as stand-alone module:

  my $v = Data::Transpose::Validator::CreditCard->new(country => 'DE',
                                                      types => ["visa card",
                                                                "mastercard"]);
  ok($v->is_valid("4111111111111111"));
  ok(!$v->is_valid("4111111111111112"));

DESCRIPTION ^

This module wraps Business::CreditCard to validate a credit card number.

new(country => 'de', types => ['VISA card', 'MasterCard', ... ])

Constructor. The options as the following:

country

Two letters country code (for card type detection purposes). Defaults to "US" (as per Business::CreditCard defaults).

types

List of accepted CC type. The string is case insensitive, but must match the following recognized types. It's unclear how much reliable is this, so use with caution. Recognized types:

  American Express card
  BankCard
  China Union Pay
  Discover card
  Isracard
  JCB
  Laser
  MasterCard
  Solo
  Switch
  VISA card

is_valid

Check with ref if the argument is a valid credit card and return it on success (without whitespace).

test_cc_numbers

For testing (and validation) purposes, this method returns an hashref with the test credit card numbers for each provider (as listed by Business::CreditCard::cardtype()).

syntax highlighting: