Skip to content

Commit

Permalink
UnboundLocalError for customer var
Browse files Browse the repository at this point in the history
  • Loading branch information
ramibch committed Jan 1, 2024
1 parent 7b47713 commit bf7e389
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ def process_stripe_event(sender, instance, created, **kwargs):

plan_id = int(instance.data["object"]["metadata"]["plan_id"])
user_id = int(instance.data["object"]["metadata"]["user_id"])
customer_id = int(instance.data["object"]["metadata"][customer_key])
# customer_id = int(instance.data["object"]["metadata"][customer_key])

try:
user = User.objects.get(id=user_id)
plan = PremiumPlan.objects.get(id=plan_id)
customer = Customer.objects.get(id=customer_id)
# customer = Customer.objects.get(id=customer_id)
except (User.DoesNotExist, PremiumPlan.DoesNotExist, Customer.DoesNotExist):
pass

userplan = UserPremiumPlan.objects.create(plan=plan, user=user, customer=customer)
# customer=customer not saving because it produces this error:
# UnboundLocalError at /stripe/webhook/ cannot access local variable 'customer' where it is not associated with a value
userplan = UserPremiumPlan.objects.create(plan=plan, user=user)

subject = "Nice CV | " + _("Welcome")
body = _(
Expand Down

0 comments on commit bf7e389

Please sign in to comment.