Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A simple class to help you easily create stripe tokens for testing purposes.
import stripe
from config import settings
class StripeCardTokenGenerator:
def __init__(self, card_type="normal"):
stripe.api_key = settings.STRIPE_API_KEY
self.card_type = card_type
self.card_number = {
"normal": 4242424242424242,
"card_declined": 4000000000000002,
"incorrect_number": 4242424242424241,
"expired_card": 4000000000000069,
"processing_error": 4000000000000119,
"incorrect_cvc": 4000000000000127,
"fails_all_charges": 4000000000000341,
"visa_debit": 4000056655665556
self.card = {
"number": self.card_number,
"exp_month": 12,
"exp_year": 2015,
"cvc": 123
def create_stripe_card_token(self):
token = stripe.Token.create(card=self.card).id
print stripe.api_key
print token
return token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment