Add get_cards_details_from_token function

This commit is contained in:
M.Ravi 2017-10-15 21:45:17 +02:00
parent 167e3589d4
commit 7d69d8d5d4

View file

@ -1,6 +1,8 @@
import logging import logging
import stripe import stripe
from django.conf import settings from django.conf import settings
from datacenterlight.models import StripePlan from datacenterlight.models import StripePlan
stripe.api_key = settings.STRIPE_API_PRIVATE_KEY stripe.api_key = settings.STRIPE_API_PRIVATE_KEY
@ -102,6 +104,18 @@ class StripeUtils(object):
} }
return card_details return card_details
@handleStripeError
def get_cards_details_from_token(self, token):
stripe_token = stripe.Token.retrieve(token)
card_details = {
'last4': stripe_token.card.last4,
'brand': stripe_token.card.brand,
'exp_month': stripe_token.card.exp_month,
'exp_year': stripe_token.card.exp_year,
'fingerprint': stripe_token.card.fingerprint
}
return card_details
def check_customer(self, id, user, token): def check_customer(self, id, user, token):
customers = self.stripe.Customer.all() customers = self.stripe.Customer.all()
if not customers.get('data'): if not customers.get('data'):