未捕获的IntegrationError:无效的stripe.redirectToCheckout参数:items.0.price不是可接受的参数

问题描述

我的目标是使用react前端使用node设置条纹签出。我使用键道具映射了apiId,以遍历列表中的所有项目。但是控制台内部有集成警告,我不确定为什么。我已经将js.stripe脚本src添加到了我的html文件中,所以我不明白为什么没有进行API调用

 function checkout() {
        stripe.redirecttocheckout({
            items: items.map(item => ({
                quantity: item.quantity,price: item.apiId
            })),successUrl: "https://www.website.com/success",cancelUrl: "https://www.website.com/canceled",})
    }

    return (
        <div>
            <table>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Image</th>
                        <th>Quanity</th>
                        <th>Price</th>
                    </tr>
                </thead>

                <tbody>
                    {items.map((item) => (
                        <tr key={item.apiId}>
                            <td>{item.name}</td>
                            <td>
                                <img
                                    src={`/images/${item.apiId}.jpg`}
                                    alt={item.name}
                                    width={180}
                                />
                            </td>
                            <td>{item.quantity}</td>
                            <td>{formatPrice(item.price)}</td>
                        </tr>
                    ))}
                    <tr>
                        <td style={{ textAlign: "right" }} colSpan={3}>
                            Total:
            </td>
                        <td>{formatPrice(totalPrice(items))}</td>
                    </tr>

                    <tr>
                        <td style={{ textAlign: "right" }} colSpan={4}>
                            <button onClick={checkout}>Complete checkout</button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    )
}

解决方法

items字段仅接受SKU /计划的数组和数量。如果您使用的是价格,则要使用lineItemshttps://stripe.com/docs/js/checkout/redirect_to_checkout#stripe_checkout_redirect_to_checkout-options-lineItems