I am having issue looping products (displaying more than one product) in stripe checkout in flask. Normally it should work. But when looping, it displays only one product instead of all the products that was looped. I don't know what am doing wrong. The codes are shown below:
@posts.route('/checkout')
def checkout():
res=Ct.query.filter_by(username = current_user.username, status='pending').order_by(Ct.id.desc()).all() #course current user intends to buy
for r in res:
te = {
'price_data': {
'currency': 'usd',
'unit_amount_decimal': total,
'product_data': {
'name': r.course,
'images': ['https://i.imgur.com/EHyR2nP.png'],
},
},
'quantity': 1,
}
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=[te,],
payment_intent_data={
'application_fee_amount': fee,
'transfer_data': {
'destination': account_id,
},
},
metadata={'order_id': '6735'},
customer_email='a@b.c',
mode='payment',
success_url=url_for('posts.processing', _external=True) + '?session_id={CHECKOUT_SESSION_ID}',
cancel_url=url_for('posts.viewcart', _external=True),
)
return jsonify(checkout_session_id=session['id'], checkout_public_key=config.get('STRIPE_PUBLIC_KEY'))