【问题标题】:Python/Flask Payment Integration with Stripe not working: no error与 Stripe 的 Python/Flask 支付集成不起作用:没有错误
【发布时间】:2017-02-05 17:21:54
【问题描述】:

我正在尝试在 Flask 中实现一个简单的视图来测试 Stripe 支付。但它没有连接到我的订阅计划,也没有错误可以解决。当我签入 shell 时,可发布密钥已在 Ubuntu 环境中正确设置。以下是我的观点和形式:

烧瓶:

stripe_keys = {
  'secret_key': os.environ['SECRET_KEY'],
  'publishable_key': os.environ['PUBLISHABLE_KEY']
}
stripe.api_key = stripe_keys['secret_key']

@app.route('/payments/subscribe', methods=['GET', 'POST'])
def chagrges(self):
    stripe.api_key = stripe_keys['secret_key']

    amount = 500

    customer = stripe.Customer.create(
        email='pudding_crazy@gmail.com',
        source=request.form.get['stripeToken']
    )

    charge = stripe.Charge.create(
        customer=customer.id,
        amount=amount,
        currency='usd',
        description='Standard Student Package $5'
        )

    return render_template('charge.html', amount=amount)

我的表格:

<form action="/charge" method="POST">
        <article>
        <label>
            <span>$ 5.00 Standard Package</span>
            </label>
            </article>

            <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"

            data-key=pk_test_0edgLiaV6OlWvDzipIkAC5G7
            data-description="Student Standard Package"
            data-amount="500"
            data-locale="auto">
            </script>
        </form>

我在 Stripe 帐户创建的订阅计划是:

ID:standard
Name: standard
Price: $5.00 USD/year
Trial period:No trial

请指教。

【问题讨论】:

  • 您的服务器日志记录中是否有任何错误?您是否从 Stripe 收到任何错误?如果您查看您的 Stripe Dashboard Logs,您会发现那里有任何错误吗?查看您的代码,我还建议在您的后端代码中添加一些 try-except 语句以捕获错误,stripe.com/docs/api/python#errors
  • 所有日志都显示为 200Ok。这让我很困惑
  • 如果您想为用户订阅一个计划,您需要创建一个订阅对象stripe.com/docs/subscriptions/quickstart#create-subscription,您创建的charge 对象是一次性付款

标签: python flask stripe-payments


【解决方案1】:

登录到 stripe.com 并转到仪表板。从左下角选择测试模式。单击“订阅”并在打开的窗口中进行计划。使用您在视图中提供的相同信息创建一个计划。再次订阅并转到条带仪表板。点击“主页”,您将在那里看到您的第一次购买。

【讨论】:

    【解决方案2】:

    您正在向客户创建一次性费用,此费用不会与任何订阅相关联或创建订阅。

    要启用订阅,您需要通过 API 或从条带仪表板创建计划。 然后使用 API 为该客户订阅计划

    stripe.Subscription.create(
      customer="<customer_id>",
      plan="plan_name"
    )
    

    创建订阅后,系统会自动向客户收费,即。 e.为计划中指定的订阅金额创建一个费用对象。

    【讨论】:

      猜你喜欢
      • 2021-06-13
      • 2012-10-12
      • 2014-11-28
      • 2015-12-19
      • 2023-03-03
      • 1970-01-01
      • 2015-05-19
      • 2016-12-28
      • 1970-01-01
      相关资源
      最近更新 更多