I've integrated Django with Stripe and seems that works ok. However i have a problem by showing all products in stripe checkout page. I need to tell stripe which products we're going to buy. If i have 2 products in cart i see only one product in stripe checkout.
views.py
def payments_stripe(request):
YOUR_DOMAIN = "http://127.0.0.1:8000/orders"
print(request.body)
body = json.loads(request.body)
cart = Cart.objects.get(cart_id=_cart_id(request))
cart_items = cartItem.objects.filter(cart=cart, is_active=True)
print(cart_items)
order = Order.objects.get(cart=cart, is_ordered=False, order_number=body['orderID'])
print(order)
for cart_item in cart_items:
quantity = cart_item.quantity
print(quantity)
name = cart_item.product.name
print(name)
try:
checkout_session = stripe.checkout.Session.create(
customer_email=order.email,
billing_address_collection='auto',
payment_method_types=['card'],
line_items=[
{
'price_data': {
'currency': 'eur',
'unit_amount': int(order.order_total * 100),
'product_data': {
'name': name,
'images': ['https://i.imgur.com/EHyR2nP.png'],
},
},
'quantity': quantity,
},
],
metadata={
'order_number': body['orderID'],
'payment_method': body['payment_method'],
'cart_id': cart,
},
mode='payment',
success_url=YOUR_DOMAIN + '/success/',
cancel_url=YOUR_DOMAIN + '/cancel/',
)
return JsonResponse({'id': checkout_session.id})
except Exception as e:
return JsonResponse(error=str(e)), 403
I iterate over cart items and Iteration gives: 1 Golden Arrow 1 Silver Heart
However in Stripe dashboard i see only one product 1 Golden Arrow.
I suppose i need to create a new list. Is that right? How can i do that in my case?
Thank you