如何在Python / Flask中使用条带webhook识别客户

时间:2017-04-05 03:13:51

标签: python flask stripe-payments webhooks

我创建了一些计划并将Stripe subscription.id和customer id保存到我的数据库中。现在我正在创建webhook以接收JSON数据以更新到期以及是否和其他几个字段。现在我只需要弄清楚如何根据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数据更新更新包的“日期”。请帮忙。

1 个答案:

答案 0 :(得分:1)

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

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

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