【问题标题】:How to use python stripe payment confirmed payment to access a webpage如何使用python条带支付确认支付访问网页
【发布时间】:2018-05-31 17:04:26
【问题描述】:

我有一个订阅计划的应用程序路径,我想阻止尚未确认使用条带付款的客户访问它,例如我有一个 10 美元的计划,任何在 24 小时内支付 10 美元的人都可以访问该页面

@app.route('/plan10', methods=['POST'])
def plan10():

customer = stripe.Customer.create(
    email=request.form['stripeEmail'],   source=request.form['stripeToken'])

charge = stripe.Charge.create(
    customer=customer.id,
    amount=1000,
    currency='usd',
    description='The Product'
)

return redirect(url_for('basicplan'))

这个想法是通过使用 python 和烧瓶键入 www.example.com/basicplan 来停止访问页面 basicplan 而无需付费

对于登录我们可以做

@app.route(/plan)
@login_required
def plan():
   return render_template(plan.html)

现在我想停止为尚未使用 stripe 付费的客户使用 python 和烧瓶提供任何帮助

【问题讨论】:

    标签: python flask stripe-payments


    【解决方案1】:

    您可以将您从 Stripe 获得的费用 ID[0] 保存在 plan10 方法中,并将其与您登录的用户类 [1] 一起存储。然后当有人登录时,您可以检查他们是否有费用(表明他们已经付款)。

    您还可以使用 Stripe API 检查收费状态以进行额外检查:

    charge = stripe.Charge.retrieve(user.savedChargeId)
    if(charge.status == "succeeded"){
      # allow access
    }else{
      # deny access
    }
    

    [0] - https://stripe.com/docs/api/python#charge_object-id

    [1] - https://flask-login.readthedocs.io/en/latest/#your-user-class

    [2] - https://stripe.com/docs/api/python#charge_object-status

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 2020-10-14
      • 2018-04-11
      • 2016-06-13
      • 2015-01-21
      • 2020-12-24
      • 2015-12-26
      相关资源
      最近更新 更多