【问题标题】:How to identify customer with stripe webhook in Python/Flask如何在 Python/Flask 中使用条带 webhook 识别客户
【发布时间】:2017-08-30 11:24:48
【问题描述】:

我创建了一些计划并将 Stripe subscription.id 和客户 ID 保存到我的数据库中。现在我正在创建 webhook 来接收 JSON 数据以更新过期和 if 以及其他一些字段。我现在需要弄清楚如何根据 webhook 的用户来过滤用户,以便我可以相应地更新模型。以下是我对 Flask 中 webhook 的看法。

@app.route('/webhooks', methods=['GET', 'POST'])
def webhook():
    event_json = json.loads(request.data)
    event = stripe.Event.retrieve(event_json['id'])
    if event.type == 'invoice.payment_succeeded':
    # Not sure how to query specific user what event is about
    invoice = event.data.object
    elif event.type == 'customer.subscription.updated':
    #or
    elif event.type == 'customer.subscription.active_until':

    subscription = event.data.object

我已经创建了 6 个计划,所有计划都运行良好,例如我可以从本地服务器中删除它,它也会自动从条带中删除。我创建了一个计划,它也被更新为条带。我只需要使用 webhook 数据更新更新包的“日期”。请帮忙。

【问题讨论】:

    标签: python flask stripe-payments webhooks


    【解决方案1】:

    https://stripe.com/docs/api#subscriptions

    https://stripe.com/docs/api#event_object

    您可以从 webhook 事件中收到的数据中找到 customer_id 和 subscription_id。可以打印数据print(event_json['data'])

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 2018-11-02
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多