【发布时间】: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