With Anvil, signing up a user for a Stripe subscription is pretty easy.
However, there doesn’t seem to be any documentation on how to cancel this subscription.
Do I basically have to set up a token and then build my Stripe form and do everything manually? Or is there a higher level method that handles this for us?
I apologise for the delay updating our documentation! If you have the Stripe customer ID, you can call anvil.stripe.get_customer() with the customer ID to get an object representing a Stripe customer. You can then call get_subscriptions() to get a list. So the following code will cancel all of a customer’s Stripe subscriptions:
def cancel_all_subscriptions(customer_id):
customer = anvil.stripe.get_customer(customer_id)
for subscription in customer.get_subscriptions():
subscription.cancel()
Yes, that is the preferred way to create a Stripe subscription. Generate a token on the client side using anvil.stripe.get_token(), then call anvil.stripe.new_customer() on the server and call new_subscription() on that customer. Here’s a more detailed description, with some sample code: