You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为预构建的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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 00:39:02