Django Stripe出错:请求req_rbqdcpSrevU8AD:必须提供源或客户

时间:2018-04-14 09:08:28

标签: python django stripe-payments

我的Stripe付款视图出现以下错误:

InvalidRequestError at /advertise/post/
Request req_rbwdcpSrc9U8AD: Must provide source or customer.

我只是复制了Stripe (Python) tutorial中的代码,所以我不确定它为什么不起作用。:

def pay(request, context):
    ad = get_object_or_404(AdvertisePost, hash=context['hash'])
    amount = ad.total_price * 100

    # Set your secret key: remember to change this to your live secret key in production
    # See your keys here: https://dashboard.stripe.com/account/apikeys
    stripe.api_key = "sk_test_exhH9odKfkT4mxzbtVxuJOBZ"

    # Token is created using Checkout or Elements!
    # Get the payment token ID submitted by the form:
    if request.method == "POST":
        token = request.POST.get('stripeToken')
        print('Token:', token) #prints None

        charge = stripe.Charge.create(
            amount=amount,
            currency='aud',
            description='Boosted Post',
            source=token,
        )

    context = {
        'amount': amount,
        'ad': ad
    }

    return render(request, 'advertising/pay.html', context)

这是我的html中的表单:

<form action="" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_8rSK99eA02ntvemImQCeV6su"
    data-amount="{{ amount }}"
    data-name="My name"
    data-description="Example charge"
    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
    data-locale="auto"
    data-currency="aud">
  </script>
</form>

知道问题是什么吗?

PS:我用它来进行一次性付款。不节省客户或类似的东西。

1 个答案:

答案 0 :(得分:0)

我通过在以下位置添加公司名称解决了相同的问题 https://dashboard.stripe.com/test/dashboard