如何为预构建的Stripe checkout页面添加商品展示图片
Stripe预构建结账页添加商品图片的修改方法
你只需要在 line_items.price_data.product_data 配置块中新增 images 字段,传入商品图片的公开可访问URL数组即可,Stripe 预构建结账页面会自动渲染该字段对应的商品图片。
修改后的代码如下:
@bp.route('/create-checkout-session', methods=['POST']) def create_checkout_session(): stripe_session = stripe.checkout.Session.create( payment_method_types=['card'], line_items=[{ 'price_data': { 'currency': 'usd', 'product_data': { 'name': 'One Key', # 新增images字段,替换为你实际的商品图片公网地址 'images': ['https://你的商品图片公开地址.jpg'] }, 'unit_amount': 2000, }, 'quantity': 1, }], mode='payment', success_url="http://127.0.0.1:5000/sucess", cancel_url="http://127.0.0.1:5000/cancel?session_id={CHECKOUT_SESSION_ID}", ) return redirect(stripe_session.url, code=303)
补充注意事项:
- 传入的图片URL必须是公网可直接访问的资源,不能配置防盗链、访问权限校验
- 建议使用1:1比例的正方形图片,在结账页面的展示效果最佳
- 支持JPG、PNG、WebP等主流图片格式
内容的提问来源于stack exchange,提问作者Anonymous12332313
相关产品推荐
相关产品推荐

