【问题标题】:Stripe integration with Django与 Django 的条带集成
【发布时间】:2018-07-22 02:31:26
【问题描述】:

我正在关注 stripe.com 上的教程,接受它说使用以下表单并捕获它在视图中返回的 Token 的费用

条纹“结帐”表单:

<form action="{% url 'payment' %}" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_z1bxF7Bk4Rk9PZuBFHMrYZnj"
    data-amount="999"
    data-name="Demo Site"
    data-description="Example charge"
    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
    data-locale="auto">
  </script>
</form>

下一步是简单地复制并粘贴此内容,您的测试帐户应该能够接受费用 条纹视图:

def payment(request):
    # 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_BJUliYkgS5VZEKFM1UQAz9cF"

    # Token is created using Checkout or Elements!
    # Get the payment token ID submitted by the form:
    token = request.POST['stripeToken']

    charge = stripe.Charge.create(
        amount=999,
        currency='usd',
        description='Example charge',
        source=token,
    )

但是stripeToken 在表单中没有提到,并且代码因此返回错误,有人可以解释这是从哪里来的吗? (注意,示例是在 Flask 中,所以我将 token = request.form['stripeToken'] # Using Flask 更改为 token = request.POST['stripeToken'] #using Django

这两个都可以在https://stripe.com/docs/quickstart 找到(第 1 步显示“结帐”,第 2 步显示 python 代码)在此先感谢您的帮助。

【问题讨论】:

  • 你有收费模式吗?可以加入吗?
  • 或者你是否包含了条带库?

标签: python django stripe-payments


【解决方案1】:

试试

token = request.GET.get['stripeToken']

【讨论】:

  • 返回File ".../views.py", line 155, in payment token = request.POST.get['stripeToken'] TypeError: 'method' object is not subscriptable
  • 虽然这可能会回答问题,但最好添加一些关于此答案如何有助于解决问题的描述。请阅读How do I write a good answer 了解更多信息。
猜你喜欢
  • 2021-08-17
  • 2021-12-15
  • 2012-06-19
  • 2020-04-17
  • 2015-10-12
  • 2020-12-05
  • 2016-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多