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" | |
slack_hook = 'YOURSLACKHOOKURLHERE' | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
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] | |
try: | |
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])} | |
requests.post(slack_hook, 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