diff --git a/manage_subscriptions/views.py b/manage_subscriptions/views.py index 3fb9135..63ca3ce 100644 --- a/manage_subscriptions/views.py +++ b/manage_subscriptions/views.py @@ -731,16 +731,14 @@ def create_checkout_session(request): # Coupon Handling if coupon_code: try: - stripe_coupon = stripe.Coupon.retrieve(coupon.coupon_id) + stripe_coupon = stripe.Coupon.retrieve(coupon_code) session_data["discounts"] = [{"coupon": stripe_coupon.id}] except stripe.error.InvalidRequestError: return JsonResponse( {"error": f"Invalid coupon code: {coupon_code}"}, status=400 ) except stripe.error.StripeError as e: - return JsonResponse( - {"error": f"Stripe error: {str(e)}"}, status=400 - ) + return JsonResponse({"error": f"Stripe error: {str(e)}"}, status=400) # Create a Transaction object with status INITIATE transaction = Transaction.objects.create( @@ -776,9 +774,7 @@ def create_checkout_session(request): "name": subscription.title, "description": subscription.short_description, }, - "unit_amount": int( - subscription.amount * 100 - ), + "unit_amount": int(subscription.amount * 100), }, "quantity": 1, } diff --git a/templates/stripe_html/index.html b/templates/stripe_html/index.html index 6972ccc..d8f7a8c 100644 --- a/templates/stripe_html/index.html +++ b/templates/stripe_html/index.html @@ -566,7 +566,7 @@ .then(data => { // Creating checkout session for the selected subscription console.log("Data:", data); - console.log("Data.CouponCode:", data["coupon"]); + console.log("data.coupon.id:", data.coupon.id); fetch(stripeFinalUrl, { method: "POST", headers: {