-
-
Save swenson/dad13ff2527cf9f007f1 to your computer and use it in GitHub Desktop.
Simple Flask app to back the PyDX sponshorship form. (AWS Lambda.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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