Hi,
Thanks for navigating the corners of this with us! stripe.checkout.subscribe()
is pretty limited. If you want to do more advanced things, I would suggest calling stripe.checkout.get_token()
. This returns a tuple of the Stripe token and a dictionary of user information (by default it’s just the email address, but other billing info also turns up here). Eg:
token, user_details = stripe.checkout.get_token(amount=999, currency="GBP", title="My Product")
You then have a choice of two approaches. First, you can use Anvil’s server-side Stripe utilities, which are available in the anvil.stripe
package:
new_customer = anvil.stripe.new_customer(email_address, token)
print new_customer['id'] # You can read any of the JSON keys in a Stripe Customer object
sub = new_customer.new_subscription("my-plan-id")
# You can also retrieve customers, and get either full subscription
# objects or just a list of plan IDs they are subscribed to
existing_customer = anvil.stripe.get_customer("cust-id-XXXXXX")
if "my_plan" in existing_customer.get_subscription_ids():
print "You are subscribed to my_plan!"
Alternatively, you can use this token with the standard server-side stripe
package (in the Full Python 2.7 and 3.6 runtimes). (You may need to pass raw=True
to get_token()
to get a token that is directly associated with your account rather than with Anvil.)
I’ve just re-upped our TODO list item for “improve our Stripe documentation”! Thankfully, it is at least all in the autocompleter.