在Django中使用Stripe API创建产品

问题描述 投票:0回答:1

创建我的第一个适当的网站并尝试连接Stripe进行付款。他们的API似乎不太动态(可能读错了)。试图整合他们的checkout page

我对如何一次制造多个产品感到困惑。试图遍历我的OrderItems:

def checkout(request):
    customer = request.user.customer
    order = Order.objects.get(customer=customer)
    items = order.orderitem_set.all()
    for item in items:
        stripe.Product.create(
            name = item.name
            description= item.desc
        )
        stripe.Price.create(
            product= product.id,
            unit_amount=int(order.get_cart_total),
            currency='gbp',
        )

但是在如何声明Price.create的产品ID上遇到了麻烦>

也对他们的API的这一部分感到困惑:

session = stripe.checkout.Session.create(
  payment_method_types=['card'],
  line_items=[{
    'price': '{{PRICE_ID}}',
    'quantity': 1,
  }],
  mode='payment',
  success_url='https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
  cancel_url='https://example.com/cancel',

我还没有在任何网站上托管我的网站,所以我可以将URL设置为什么? Checkout_session来自何处?无法找到关于此的最新信息,因此我很抱歉问什么可能不是一个好问题,但不确定该怎么做。谢谢!

创建我的第一个适当的网站并尝试连接Stripe进行付款。他们的API似乎不太动态(可能读错了)。尝试整合其结帐页面。我对...

python django stripe-payments e-commerce
1个回答
0
投票

使用Stripe,每个API请求都返回一个JSON响应,然后可以在相应的API资源中反序列化。这意味着,当您调用创建产品API时,您将获得Product;当您调用创建价格API时,您将获得Price

© www.soinside.com 2019 - 2024. All rights reserved.