1 回答

TA貢獻1784條經(jīng)驗 獲得超2個贊
有幾種方法可以解決這個問題,但一種方法是通過儀表板或 API 創(chuàng)建交貨價格。然后,如果訂單項價格總和unit_amounts小于 500,則將運費添加到訂單項并將項目數(shù)組傳遞給會話創(chuàng)建調用:
# 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",
)
添加回答
舉報