From 7d69d8d5d41f385c8198ba288986e917ecec32ae Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 15 Oct 2017 21:45:17 +0200 Subject: [PATCH] Add get_cards_details_from_token function --- utils/stripe_utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index 8fcf0ab1..9264820d 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -1,6 +1,8 @@ import logging + import stripe from django.conf import settings + from datacenterlight.models import StripePlan stripe.api_key = settings.STRIPE_API_PRIVATE_KEY @@ -102,6 +104,18 @@ class StripeUtils(object): } 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): customers = self.stripe.Customer.all() if not customers.get('data'):