1 回答
TA贡献1784条经验 获得超2个赞
有几种方法可以解决这个问题,但一种方法是通过仪表板或 API 创建交货价格。然后,如果订单项价格总和unit_amounts小于 500,则将运费添加到订单项并将项目数组传递给会话创建调用:
# The shipping price ID
shipping_price = "price_xxx"
# Base price
price = stripe.Price.retrieve(
"price_yyy",
)
# If there are more than one item you can iterate over items and sum the unit_amounts
items = [
{
"price": price.id,
"quantity": 1,
},
]
# For simplicity I assume there is only one price being charged, for summing, iterate over the items
if(price.unit_amount < 500):
items.append({
"price": shipping_price,
"quantity": 1,
})
stripe.checkout.Session.create(
success_url="https://example.com/success",
cancel_url="https://example.com/cancel",
payment_method_types=["card"],
line_items=items,
mode="payment",
)
添加回答
举报