简体   繁体   English

使用Flask获取用户更改Stripe中的计划的日期

[英]Get date a user changed the plan they are on in Stripe using Flask

Working with Stripe and trying to set some basic info into the metadata field. 使用Stripe并尝试在元数据字段中设置一些基本信息。 I have two plans created, a paid and free. 我创建了两个计划,一个付费计划和一个免费计划。 The free plan is used when a customer cancels. 客户取消时将使用免费计划。 Many of these customers have been changed through Stripe Dashboard already so using a webhook will not work. 其中许多客户已经通过Stripe Dashboard进行了更改,因此无法使用Webhook。

With this code I am able to get all customers on a specific plan and show that in metadata. 通过此代码,我可以使所有客户制定特定计划,并在元数据中显示该计划。 The problem is that the .created date gives me the date the customer was created and not the date the plan was changed. 问题在于.created日期给我的是创建客户的日期,而不是计划的更改日期。 If I change the plan in dashboard by adding a new plan and deleting the old one (from that customer) I can use the time the old plan was unsubscribed. 如果我通过添加新计划并删除旧计划(从该客户那里)来更改仪表板中的计划,则可以使用取消旧计划的时间。 But the option in the dashboard to change plan does something different and there is no unsubscribe. 但是仪表板中用于更改计划的选项会有所不同,并且没有退订。 My app is a connected account creating charges on other stripe accounts that have a dashboard of their own, so just not using the change plan button is not an option. 我的应用程序是一个已关联的帐户,它在具有自己的仪表板的其他条带化帐户上创建费用,因此不选择不使用更改计划按钮。 Here is the code that gets the plan and created date. 这是获取计划和创建日期的代码。

canceled=stripe.Subscription.list(
plan='plan_Elm8GW7mwgDj5S',
stripe_account=stripe_keys['acct_num'],
)
for cancel in canceled.auto_paging_iter():


    customer_id=cancel.customer
    cd=cancel.created
    canceled_date=datetime.datetime.fromtimestamp(cd).strftime('%m-%d-%Y')
    stripe.Customer.modify(
    customer_id,
    stripe_account=stripe_keys['acct_num'],
    metadata={'Status': 'Canceled',
    'Canceled On': canceled_date}

    )

thank you! 谢谢!

You can use the API to list events . 您可以使用API 列出事件 You can specify the type of event to retrieve just those events, and look at the creation time of the event to know when it occurred. 您可以指定事件的type以仅检索那些事件,并查看事件的创建时间以了解事件的发生时间。

It sounds like you want to focus on the customer.subscription.created event and then look at those events for subscriptions using the free plan. 听起来您想专注于customer.subscription.created事件,然后使用免费计划查看那些事件以进行订阅。 There are also other customer.subscription.* events for updates, deletions, and trials ending. 还有其他customer.subscription.*事件用于更新,删除和试用结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM