Created
June 5, 2015 19:46
-
-
Save MichelleGlauser/8f40c75e5cd7a199ff55 to your computer and use it in GitHub Desktop.
Django StripeCouponView
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
# Stripe coupons! | |
class StripeCouponView(generic.View): | |
def get(self, request): | |
log.debug(request.GET) | |
coupon_code = request.GET.get('coupon', '') | |
api_url = 'https://api.stripe.com/v1/coupons/' + coupon_code | |
try: | |
r = requests.get(api_url, auth=(settings.STRIPE_SECRET_KEY, '')) | |
r.raise_for_status() | |
response_json = r.json() | |
if not response_json.get('is_valid', False): | |
raise Exception | |
except (requests.exceptions.HTTPError, Exception): | |
return HttpResponseNotFound('BAD request, Michelle') | |
return HttpResponse(response_json.get('percent_off', 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment