Add card exists method
This commit is contained in:
parent
0359eb22f9
commit
ba9961a01a
1 changed files with 24 additions and 0 deletions
|
@ -73,6 +73,30 @@ class StripeUtils(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.stripe = stripe
|
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):
|
def get_stripe_customer_from_email(self, email):
|
||||||
customer = stripe.Customer.list(limit=1, email=email)
|
customer = stripe.Customer.list(limit=1, email=email)
|
||||||
return customer.data[0] if len(customer.data) == 1 else None
|
return customer.data[0] if len(customer.data) == 1 else None
|
||||||
|
|
Loading…
Reference in a new issue