Server side stripe payments

Hi @shopinthewoods,

Calling stripe_customer.charge on the server side returns a dictionary similar to the Stripe Charge object. Charges are identified by a unique, random ID, and you can access attributes of the Charge object as you would a normal dict. The status attribute tells you if the transaction has succeeded, and will return either succeeded , pending , or failed. For example:

# In a Server Module:
@anvil.server.callable
def charge_user(token, email):
  stripe_customer = anvil.stripe.new_customer(email, token)
  charge = stripe_customer.charge(amount=999, currency="USD")
  print("ID: {}, Status: {}".format(charge['id'], charge['status']))

This will print out the charge id and status for each payment taken on the server.

2 Likes