A simple class to help you easily create stripe tokens for testing purposes.
This file contains 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
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 | |
}[card_type] | |
self.card = { | |
"number": self.card_number, | |
"exp_month": 12, | |
"exp_year": 2015, | |
"cvc": 123 | |
} | |
self.create_stripe_card_token() | |
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