views:

123

answers:

3

I have a simple online product that I'm selling. I need a credit card order form.

I'm looking for a sample php based order form. A form that collects name, address, credit card, exp date, and cvv and validates that the fields (for example checks that the credit card number is in the correct format). Forget the payment gateway integration I just need the the form and validation.

Does anyone know of such a resource?

+1  A: 

Quick google search brought me to this site: http://articles.sitepoint.com/print/card-validation-class-php

Note: The article was written in 2002. So it's definitely a good starting point, but watch out for things that might have changed in php / credit cards in the past 8 years.

It looks like it has pretty good information about validating credit card numbers across different vendors (visa, mc, amex, etc.)

As for the rest of the fields, there are tons of quick validation scripts out there.

hookedonwinter
php has changed in the past 8 years? inconceivable!
TheGeekYouNeed
@TheGeek Unpossible!
deceze
+1  A: 

The "CVV" (probably the CVV2, or CSC in general) appears to be the output of a hash function that's stored by the bank, and I suspect that you'd actually have to attempt a transaction to validate it. So I suspect that hookedonwinter's answer is pretty much all you're going to be able to do without actually making a transaction. (Now there's an interesting scam - "we need to conduct an account validation to check your details, this will cost you $0.10, OK?")

Alphax
haha funny. as far as i know, you don't technically need the cvv2 / csc to make a transaction, it just helps to validate that it's legit. Not positive though.
hookedonwinter
@hookedonwinter Indeed, it seems to have been designed as an anti-fraud mechanism; contested transactions conducted without one are more likely to be resolved in favour of the cardholder, since it's supposedly "proof" that whoever conducted the transaction had physical access to the card.
Alphax
@Alphax which, of course, means they are honest and didn't just steal the card. </logic>
hookedonwinter
+1  A: 

The Luhn algorithm might be of interest to you http://en.wikipedia.org/wiki/Luhn_algorithm

It validates a credit-card number by using the checksum algorithm.

From the wiki page:

The formula verifies a number against its included check digit, which is usually appended to a partial account number to generate the full account number. This account number must pass the following test:

  1. Counting from the check digit, which is the rightmost, and moving left, double the value of every second digit.
  2. Sum the digits of the products together with the undoubled digits from the original number.
  3. If the total ends in 0 (put another way, if the total modulo 10 is equal to 0), then the number is valid according to the Luhn formula; else it is not valid.

Assume an example of an account number "4992739871" that will have a check digit added, making it of the form 4992739871x:

Mike B
..but dont rely on it. Luhn digit is only intended to catch transposition errors, not validate the card number. There's a 1 in 10 chance a completely random number will pass.
PaulG
Still great to use because processors and gateways charge fees for every transaction even declined ones. This helps to minimize the false transactions.
John Conde
@PaulG I didn't intend to imply that a numbers that pass Luhn will ALWAYS be a valid credit card. It's simply a better validation test then checking the length. You must rely on the payment gateway for true validation. It might be helpful to note that 4111111111111111 is a pretty standard 'test' number as it passes Luhn.
Mike B