Browse Source

Add card exists method

master
PCoder 3 years ago
parent
commit
ba9961a01a
  1. 24
      stripe_utils.py

24
stripe_utils.py

@ -73,6 +73,30 @@ class StripeUtils(object):
def __init__(self):
self.stripe = stripe
@handleStripeError
def card_exists(self, customer, cc_number, exp_month, exp_year, cvc):
token_obj = stripe.Token.create(
card={
'number': cc_number,
'exp_month': exp_month,
'exp_year': exp_year,
'cvc': cvc,
},
)
cards = stripe.Customer.list_sources(
customer,
limit=20,
object='card'
)
for card in cards.data:
if (card.fingerprint == token_obj.card.fingerprint and
int(card.exp_month) == int(exp_month) and
int(card.exp_year) == int(exp_year)
):
return True
return False
def get_stripe_customer_from_email(self, email):
customer = stripe.Customer.list(limit=1, email=email)
return customer.data[0] if len(customer.data) == 1 else None

Loading…
Cancel
Save