def coupon_code(): code = request.form.get('coupon_code') if code is None: return render_json(422, {'error': _('Discount code cannot be processed.')}) coupon = Coupon.find_by_code(code) if coupon is None: return render_json(404, {'error': _('Discount code not found.')}) return render_json(200, {'data': coupon.serialize()})
def event(): if not request.json: return render_json(406, {'error': 'Mime-type is not application/json'}) if request.json.get('id') is None: return render_json(406, {'error': 'Invalid Stripe event'}) try: safe_event = PaymentEvent.retrieve(request.json.get('id')) parsed_event = Invoice.parse_from_event(safe_event) Invoice.prepare_and_save(parsed_event) except InvalidRequestError as e: # We could not parse the event. return render_json(422, {'error': str(e)}) except Exception as e: # Return a 200 because something is really wrong and we want Stripe to # stop trying to fulfill this webhook request. return render_json(200, {'error': str(e)}) return render_json(200, {'success': True})