Created
June 10, 2015 18:45
-
-
Save MichelleGlauser/c4a1962eaa11fcb541b2 to your computer and use it in GitHub Desktop.
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
class StripeCouponView(generic.View): | |
def get(self, request): | |
stripe.api_key=settings.STRIPE_SECRET_KEY | |
# coupon = stripe.Coupon.retrieve("ZANAFAMILY") | |
# print coupon | |
# log.debug(request.GET) | |
# # Saves the characters after "=" as coupon_code | |
# coupon_code = request.GET.get('coupon', '') | |
if "coupon" in request.GET: | |
coupon_code = request.GET['coupon'] | |
# if stripe.Coupon.retrieve(coupon_code): | |
# coupon = stripe.Coupon.retrieve(coupon_code) | |
# if coupon['amount_off'] != null: | |
# amount_off = coupon['amount_off'] | |
# elif coupon['percent_off'] != null: | |
# percent_off = coupon['percent_off'] | |
# print "coupon_code is " + coupon_code | |
# api_url = 'https://api.stripe.com/v1/coupons/' + coupon_code | |
# try: | |
# r = requests.get(api_url, auth=(settings.STRIPE_SECRET_KEY, '')) | |
# print "MICHELLE, r is ", r | |
# 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