Login

Tag "credit-card"

Snippet List

Month / Year dropdown widget

This is an adaption of [django.forms.extras.widgets.SelectDateWidget](http://code.djangoproject.com/browser/django/trunk/django/forms/extras/widgets.py#L16) which has no day dropdown - it still produces a date but with the day set to 1. Example use class myForm(forms.Form): # ... date = forms.DateField( required=False, widget=MonthYearWidget(years=xrange(2004,2010)) )

  • date
  • year
  • credit-card
  • month
Read More

Credit Card With Newforms

Alternative version of newform code for handling credit cards. Unlike the other two credit-card snippets (http://www.djangosnippets.org/snippets/764/ and http://www.djangosnippets.org/snippets/830/), this uses two drop-down boxes instead of text fields for the expiration date, which is a bit friendlier. It doesn't do as much checking as snippet #764 since we rely on the payment gateway for doing that. We only accept Mastercard, Visa, and American Express, so the validation code checks for that.

  • newforms
  • datefield
  • credit-card
  • expiration-date
Read More

Custom DateField To Handle Credit Card Exp Date. Format: MM/YY

As users would login to their accounts to update their CC info, the expiration date always threw them off. The default format for displaying a datetime.date object is >YYYY-MM-DD Obviously the expiration date on your credit card uses the MM/YY format. I finally got around to creating a custom field/widget to handle this particular piece of data. Use like so... class CustomerForm(forms.ModelForm): cc_exp = DateFieldCCEXP() class Meta: model = Customer

  • datefield
  • credit-card
  • expiration-date
Read More
Author: pjs
  • 1
  • 3

Newforms Validation of Credit Card Numbers

Some functions and newforms fields for validating credit card numbers, and their expiry dates. In my project, I have all of the credit card functions in a file called creditcards.py Just as an overview: To validate a credit card number there are a few steps: 1. Make sure the number only contains digits and spaces. `ValidateCharacters()` 2. Remove spaces so that only numbers are left. `StripToNumbers()` 3. Check that the number validates using the Luhn Checksum `ValidateLuhnChecksum()` 4. Check to see whether the number is valid for the type of card that is selected. This is annoying because you will need to look at another cleaned field before you can check this.

  • newforms
  • field
  • credit-card
  • number
  • visa
  • mastercard
Read More

5 snippets posted so far.