Create stripe customer if not exists

This commit is contained in:
M.Ravi 2017-10-08 21:01:25 +02:00
parent b44948b277
commit 8b36d9cba4

View file

@ -591,9 +591,13 @@ class OrderConfirmationView(DetailView):
try: try:
custom_user = CustomUser.objects.get( custom_user = CustomUser.objects.get(
email=user.get('email')) email=user.get('email'))
customer = StripeCustomer.objects.filter( stripe_customer = StripeCustomer.objects.filter(
user_id=custom_user.id).first() user_id=custom_user.id).first()
stripe_customer_id = customer.id if stripe_customer is None:
stripe_customer = StripeCustomer.objects.create(
user=custom_user, stripe_id=stripe_api_cus_id
)
stripe_customer_id = stripe_customer.id
except CustomUser.DoesNotExist: except CustomUser.DoesNotExist:
logger.debug( logger.debug(
"Customer {} does not exist.".format(user.get('email'))) "Customer {} does not exist.".format(user.get('email')))