Skip to content

Instantly share code, notes, and snippets.

Last active Jul 12, 2016
What would you like to do?
Simple Flask app to back the PyDX sponshorship form. (AWS Lambda.)
import json
import logging
import requests
import urlparse
import stripe
stripe.api_key = "YOURKEYHERE"
logger = logging.getLogger()
def hook(event, context):
params = urlparse.parse_qs(event['body'])
token = params['stripeToken'][0]
amount = int(round(100.0 * float(params['amount'][0])))
desc = 'PyDX Sponsorship from ' + params['name'][0]
charge = stripe.Charge.create(amount=amount, currency='usd', source=token, description=desc, receipt_email=params['email'][0])
# notify slack
notify = {'text':
'%s successfully sent sponsorship payment of $%s' % (params['name'][0],
params['amount'][0])}, data=json.dumps(notify))
return 'Your payment has been processed!\n'
except stripe.error.CardError, e:
print 'Stripe error'
print e
return 'There was an error charging your card. It might have been declined.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment