第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Stripe 結賬時添加額外金額

在 Stripe 結賬時添加額外金額

收到一只叮咚 2023-11-09 22:29:12
我使用 python/Django 開發(fā)電子商務網(wǎng)站。我集成了條帶支付,其中購物車項目作為行項目動態(tài)傳遞。如果購物車價值低于 500 盧比,我會添加運費。當前使用 stripe session Api 進行結賬流程。我想將送貨費作為額外金額添加到結帳訂單項價格中。提前致謝@csrf_exemptdef createCheckoutSession(request):if request.method=='GET':    domain_url='http://localhost:8000/'    stripe.api_key= settings.STRIPE_SECRET_KEY    profile = UserProfile.objects.get(user__id=request.user.id)    try:        customer = stripe.Customer.retrieve(profile.stripe_id)        print (customer)        profile = UserProfile.objects.get(user__id=request.user.id)        checkoutSession = stripe.checkout.Session.create(        success_url =domain_url+'success?session_id={CHECKOUT_SESSION_ID}',        cancel_url =domain_url+'cancelled/',        payment_method_types = ['card'],        mode='payment',        line_items= get_line_items(request)[0],        customer= profile.stripe_id,        )        return JsonResponse({'sessionId':checkoutSession['id']})    except Exception as e:        return JsonResponse({"error":str(e)})
查看完整描述

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",

)


查看完整回答
反對 回復 2023-11-09
  • 1 回答
  • 0 關注
  • 192 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號