From 8b36d9cba4acf4effc9967bb5f00ba61ea905bc8 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 8 Oct 2017 21:01:25 +0200 Subject: [PATCH] Create stripe customer if not exists --- datacenterlight/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 6eb35624..16872aa2 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -591,9 +591,13 @@ class OrderConfirmationView(DetailView): try: custom_user = CustomUser.objects.get( email=user.get('email')) - customer = StripeCustomer.objects.filter( + stripe_customer = StripeCustomer.objects.filter( 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: logger.debug( "Customer {} does not exist.".format(user.get('email')))