<s> from django . http import HttpResponseRedirect <EOL> from django . shortcuts import render_to_response , redirect <EOL> from django . template import RequestContext <EOL> from django . http import HttpResponse <EOL> from django . utils import simplejson <EOL> from zebra . conf import options <EOL> import stripe <EOL> stripe . api_key = options . STRIPE_SECRET <EOL> from zebra . forms import StripePaymentForm <EOL> def update ( request ) : <EOL> user = request . user <EOL> success_updating = False <EOL> if request . method == '<STR_LIT:POST>' : <EOL> zebra_form = StripePaymentForm ( request . POST ) <EOL> if zebra_form . is_valid ( ) : <EOL> customer = stripe . Customer . retrieve ( user . stripe_id ) <EOL> customer . card = zebra_form . cleaned_data [ '<STR_LIT>' ] <EOL> customer . save ( ) <EOL> profile = user . get_profile ( ) <EOL> profile . last_4_digits = zebra_form . cleaned_data [ '<STR_LIT>' ] <EOL> profile . stripe_customer_id = customer . id <EOL> profile . save ( ) <EOL> success_updating = True <EOL> else : <EOL> zebra_form = StripePaymentForm ( ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : zebra_form , <EOL> '<STR_LIT>' : options . STRIPE_PUBLISHABLE , <EOL> '<STR_LIT>' : success_updating , <EOL> } , <EOL> context_instance = RequestContext ( request ) <EOL> ) </s>
