Add card exists method

This commit is contained in:
PCoder 2019-09-14 12:28:03 +05:30
parent 0359eb22f9
commit ba9961a01a

View file

@ -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