Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在期末取消客户条带订阅?_Python_Python 3.x_Stripe Payments - Fatal编程技术网

Python 如何在期末取消客户条带订阅?

Python 如何在期末取消客户条带订阅?,python,python-3.x,stripe-payments,Python,Python 3.x,Stripe Payments,我想要的功能是,如果订阅的客户取消了订阅,我想让他们使用我的服务,直到他们支付的当前期间结束 我的计划是,当他们取消时,更新他们的订阅,使其在当前期间结束时取消。我目前正在尝试用python实现代码,以更新customers subscriptions cancel_at_period_end属性,但我似乎无法让它正常工作。这就是我所拥有的: stripe_customer_obj = stripe.Customer.retrieve(current_user.stripe_customer_i

我想要的功能是,如果订阅的客户取消了订阅,我想让他们使用我的服务,直到他们支付的当前期间结束

我的计划是,当他们取消时,更新他们的订阅,使其在当前期间结束时取消。我目前正在尝试用python实现代码,以更新customers subscriptions cancel_at_period_end属性,但我似乎无法让它正常工作。这就是我所拥有的:

stripe_customer_obj = stripe.Customer.retrieve(current_user.stripe_customer_id)
stripe_customer_subscription = stripe_customer_obj.subscriptions['data'][0]

stripe.Subscription.modify(
        stripe_customer_subscription['id'],
        metadata={"cancel_at_period_end": True},
    )
当我通过以下命令打印cancel_at_period_end属性时,这运行正常:

print(stripe_customer_subscription['cancel_at_period_end'])
在我修改订阅的代码之前和之后为False。这就像我修改订阅的那一行,实际上并没有更新或保存它,即使它正在运行并且没有崩溃


如果相关(我不认为相关)-我正在尝试将cancel_at_period_end属性更新为True,以便当订阅在时段结束时被取消时,将触发一个webhook,我可以使用它更新数据库中的客户条目,从而切断他们对应用程序的访问

您的代码的问题是您在订阅对象的。这只是一个简单的键->值存储,用于存储任意数据

您只需要将作为普通参数传递。像这样:

stripe.Subscription.modify(
“sub_xxx”,
在周期结束时取消=真
)
希望这有帮助