#skarlettskwrl

1 messages · Page 1 of 1 (latest)

pallid nestBOT
zealous stream
#

Hello

#

What do you see in your browser console when this happens?

eternal coral
#

`cs_test_a13yWAr5Usd2LyFj3lSCPhIkC2R5B2icv1IB44v5Pu9gZCSMXRADhTczD2

[{'price_data': {'currency': 'cad', 'product_data': {'name': 'Cash Gift Card'}, 'unit_amount': 2500}, 'quantity': 1}]

fullJSON {
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 2500,
"amount_total": 2500,
"automatic_tax": {
"enabled": false,
"liability": null,
"status": null
},
"billing_address_collection": null,
"cancel_url": "http://127.0.0.1:8000/payment_cancel/",
"client_reference_id": null,
"client_secret": null,
"consent": null,
"consent_collection": null,
"created": 1706130096,
"currency": "cad",
"currency_conversion": null,
"custom_fields": [],
"custom_text": {
"after_submit": null,
"shipping_address": null,
"submit": null,
"terms_of_service_acceptance": null
},
"customer": null,
"customer_creation": "if_required",
"customer_details": null,
"customer_email": null,
"expires_at": 1706216496,
"id": "cs_test_a13yWAr5Usd2LyFj3lSCPhIkC2R5B2icv1IB44v5Pu9gZCSMXRADhTczD2",
"invoice": null,
"invoice_creation": {
"enabled": false,
"invoice_data": {
"account_tax_ids": null,
"custom_fields": null,
"description": null,
"footer": null,
"issuer": null,
"metadata": {},
"rendering_options": null
}
},
"livemode": false,
"locale": null,
"metadata": {},
"mode": "payment",
"object": "checkout.session",
"payment_intent": null,
"payment_link": null,
"payment_method_collection": "if_required",
"payment_method_configuration_details": null,
"payment_method_options": {},
"payment_method_types": [
"card"
],
"payment_status": "unpaid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"setup_intent": null,
"shipping_address_collection": null,
"shipping_cost": null,
"shipping_details": null,
"shipping_options": [],
"status": "open",
"submit_type": null,
"subscription": null,
"success_url": "http://127.0.0.1:8000/payment_success/",
"total_details": {
"amount_discount": 0,
"amount_shipping": 0,
"amount_tax": 0
},
"ui_mode": "hosted",
"url": "https://checkout.stripe.com/c/pay/cs_test_a13yWAr5Usd2LyFj3lSCPhIkC2R5B2icv1IB44v5Pu9gZCSMXRADhTczD2#fidkdWxOYHwnPyd1blpxYHZxWjA0ST1hYGtHcUFrQXZBcUpIRnxicFdsRnd2Rk1sY1ZydH9Ld0Y1VUt2VlY2NTZmVFdVY0J2R2RVTHRWaHRuY2JCTHJ8Q0FJSGpicH1OX0FVVWZkX0FrYlQyNTUwQ1RiTm08XCcpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl"`
}
http://127.0.0.1:8000/create-checkout/

zealous stream
#

Looks like you are just returning the Checkout Session object to your frontend instead of redirecting the customer to the url?

#

Can you show me your backend code?

eternal coral
#

this is the relevant view
@method_decorator(csrf_exempt, name='dispatch')
`class CheckoutSessionView(View):
def post(self, request):
# Load data from the POST request
if request.body:
data = json.loads(request.body.decode('utf-8'))
cart_items = data.get('cartItems', [])

        stripe.api_key = settings.STRIPE_SECRET_KEY  

        stripe_items = []
        for item in cart_items:
            if item['gc-type'] == 'cash':
                # Assuming 'gc-cash' holds the amount for the cash gift card
                amount = int(item['gc-cash']) * 100  # Convert dollars to cents
                stripe_items.append({
                    'price_data': {
                        'currency': 'cad',
                        'product_data': {'name': 'Cash Gift Card'},
                        'unit_amount': amount,
                    },
                    'quantity': 1,
                })
            elif item['gc-type'] == 'voucher':
                # Assuming 'gc-price' holds the price for the voucher
                amount = int(item['gc-price']) * 100  # Convert dollars to cents
                stripe_items.append({
                    'price_data': {
                        'currency': 'cad',
                        'product_data': {'name': f"Voucher for {item['gc-service']}"},
                        'unit_amount': amount,
                    },
                    'quantity': 1,
                })

        if not stripe_items:
            return JsonResponse({'error': 'No valid items in cart'}, status=400)

        # Create the Stripe checkout session
        try:
            checkout_session = stripe.checkout.Session.create(
                payment_method_types=['card'],
                line_items=stripe_items,
                mode='payment',
                success_url=request.build_absolute_uri('/payment_success/'),
                cancel_url=request.build_absolute_uri('/payment_cancel/'),
            )
            print(checkout_session.url)
            print('\n')
            print(checkout_session.id)
            print('\n')
            print(stripe_items)
            print('\n')
            print('fullJSON', checkout_session)
            print('\n ......')
            
            # return redirect(checkout_session.url, code=303)
            return JsonResponse({'sessionId': checkout_session.id})
            # return JsonResponse({'url': checkout_session.url})
        
        except Exception as e:
            return JsonResponse({'error': str(e)}, status=500)`
zealous stream
#

See when you do return JsonResponse({'sessionId': checkout_session.id})

#

That indicates you are just sending that JSON back to your frontend

#

You need to actually redirect

#

Likely your commented out code: # return redirect(checkout_session.url, code=303)

eternal coral
#

i did try that commented line and it yielded the same results

#

maybe theres also an issue on my frontend?

zealous stream
#

I mean nothing should happen on your frontend except the page being redirected to the Checkout Session after this code runs

#

I'd recommend testing again with that code commented back in

pallid nestBOT