def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get('plan', 2)) plan = PLANS[plan - 1][0] error = None if request.method == 'POST': zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data['email'] user.save() try: customer = stripe.Customer.create( **{ 'card': zebra_form.cleaned_data['stripe_token'], 'plan': zebra_form.cleaned_data['plan'], 'email': user.email, 'description': user.username, }) except stripe.CardError: error = "This card was declined." else: user.profile.strip_4_digits = zebra_form.cleaned_data[ 'last_4_digits'] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium( ) # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response('reader/paypal_return.xhtml', {}, context_instance=RequestContext(request)) new_user_queue_count = RNewUserQueue.user_count() new_user_queue_position = RNewUserQueue.user_position(request.user.pk) new_user_queue_behind = 0 if new_user_queue_position >= 0: new_user_queue_behind = new_user_queue_count - new_user_queue_position new_user_queue_position -= 1 logging.user(request, "~BM~FBLoading Stripe form") return render_to_response('profile/stripe_form.xhtml', { 'zebra_form': zebra_form, 'publishable': settings.STRIPE_PUBLISHABLE, 'success_updating': success_updating, 'new_user_queue_count': new_user_queue_count - 1, 'new_user_queue_position': new_user_queue_position, 'new_user_queue_behind': new_user_queue_behind, 'error': error, }, context_instance=RequestContext(request))
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get('plan', 2)) plan = PLANS[plan-1][0] error = None if request.method == 'POST': zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data['email'] user.save() try: customer = stripe.Customer.create(**{ 'card': zebra_form.cleaned_data['stripe_token'], 'plan': zebra_form.cleaned_data['plan'], 'email': user.email, 'description': user.username, }) except stripe.CardError: error = "This card was declined." else: user.profile.strip_4_digits = zebra_form.cleaned_data['last_4_digits'] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium() # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response('reader/paypal_return.xhtml', {}, context_instance=RequestContext(request)) new_user_queue_count = RNewUserQueue.user_count() new_user_queue_position = RNewUserQueue.user_position(request.user.pk) new_user_queue_behind = 0 if new_user_queue_position >= 0: new_user_queue_behind = new_user_queue_count - new_user_queue_position new_user_queue_position -= 1 logging.user(request, "~BM~FBLoading Stripe form") return render_to_response('profile/stripe_form.xhtml', { 'zebra_form': zebra_form, 'publishable': settings.STRIPE_PUBLISHABLE, 'success_updating': success_updating, 'new_user_queue_count': new_user_queue_count - 1, 'new_user_queue_position': new_user_queue_position, 'new_user_queue_behind': new_user_queue_behind, 'error': error, }, context_instance=RequestContext(request) )
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get("plan", 2)) plan = PLANS[plan - 1][0] if request.method == "POST": zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data["email"] user.save() customer = stripe.Customer.create( **{ "card": zebra_form.cleaned_data["stripe_token"], "plan": zebra_form.cleaned_data["plan"], "email": user.email, "description": user.username, } ) user.profile.strip_4_digits = zebra_form.cleaned_data["last_4_digits"] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium() # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response("reader/paypal_return.xhtml", {}, context_instance=RequestContext(request)) new_user_queue_count = RNewUserQueue.user_count() new_user_queue_position = RNewUserQueue.user_position(request.user.pk) new_user_queue_behind = 0 if new_user_queue_position >= 0: new_user_queue_behind = new_user_queue_count - new_user_queue_position new_user_queue_position -= 1 logging.user(request, "~BM~FBLoading Stripe form") return render_to_response( "profile/stripe_form.xhtml", { "zebra_form": zebra_form, "publishable": settings.STRIPE_PUBLISHABLE, "success_updating": success_updating, "new_user_queue_count": new_user_queue_count - 1, "new_user_queue_position": new_user_queue_position, "new_user_queue_behind": new_user_queue_behind, }, context_instance=RequestContext(request), )
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get('plan', 2)) plan = PLANS[plan - 1][0] if request.method == 'POST': zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data['email'] user.save() customer = stripe.Customer.create( **{ 'card': zebra_form.cleaned_data['stripe_token'], 'plan': zebra_form.cleaned_data['plan'], 'email': user.email, 'description': user.username, }) user.profile.strip_4_digits = zebra_form.cleaned_data[ 'last_4_digits'] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium( ) # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response('reader/paypal_return.xhtml', {}, context_instance=RequestContext(request)) logging.user(request, "~BM~FBLoading Stripe form") return render_to_response('profile/stripe_form.xhtml', { 'zebra_form': zebra_form, 'publishable': settings.STRIPE_PUBLISHABLE, 'success_updating': success_updating, }, context_instance=RequestContext(request))
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get('plan', 2)) plan = PLANS[plan-1][0] if request.method == 'POST': zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data['email'] user.save() customer = stripe.Customer.create(**{ 'card': zebra_form.cleaned_data['stripe_token'], 'plan': zebra_form.cleaned_data['plan'], 'email': user.email, 'description': user.username, }) user.profile.strip_4_digits = zebra_form.cleaned_data['last_4_digits'] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium() # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response('reader/paypal_return.xhtml', {}, context_instance=RequestContext(request)) logging.user(request, "~BM~FBLoading Stripe form") return render_to_response('profile/stripe_form.xhtml', { 'zebra_form': zebra_form, 'publishable': settings.STRIPE_PUBLISHABLE, 'success_updating': success_updating, }, context_instance=RequestContext(request) )
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get("plan", 2)) plan = PLANS[plan - 1][0] if request.method == "POST": zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data["email"] user.save() customer = stripe.Customer.create( **{ "card": zebra_form.cleaned_data["stripe_token"], "plan": zebra_form.cleaned_data["plan"], "email": user.email, "description": user.username, } ) user.profile.strip_4_digits = zebra_form.cleaned_data["last_4_digits"] user.profile.stripe_id = customer.id user.profile.save() success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response("reader/paypal_return.xhtml", {}, context_instance=RequestContext(request)) return render_to_response( "profile/stripe_form.xhtml", {"zebra_form": zebra_form, "publishable": settings.STRIPE_PUBLISHABLE, "success_updating": success_updating}, context_instance=RequestContext(request), )
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = PLANS[0][0] renew = is_true(request.GET.get('renew', False)) error = None if request.method == 'POST': zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data['email'] user.save() customer = None current_premium = ( user.profile.is_premium and user.profile.premium_expire and user.profile.premium_expire > datetime.datetime.now()) # Are they changing their existing card? if user.profile.stripe_id: customer = stripe.Customer.retrieve(user.profile.stripe_id) try: card = customer.sources.create( source=zebra_form.cleaned_data['stripe_token']) except stripe.error.CardError: error = "This card was declined." else: customer.default_card = card.id customer.save() user.profile.strip_4_digits = zebra_form.cleaned_data[ 'last_4_digits'] user.profile.save() user.profile.activate_premium( ) # TODO: Remove, because webhooks are slow success_updating = True else: try: customer = stripe.Customer.create( **{ 'source': zebra_form.cleaned_data['stripe_token'], 'plan': zebra_form.cleaned_data['plan'], 'email': user.email, 'description': user.username, }) except stripe.error.CardError: error = "This card was declined." else: user.profile.strip_4_digits = zebra_form.cleaned_data[ 'last_4_digits'] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium( ) # TODO: Remove, because webhooks are slow success_updating = True # Check subscription to ensure latest plan, otherwise cancel it and subscribe if success_updating and customer and customer.subscriptions.total_count == 1: subscription = customer.subscriptions.data[0] if subscription['plan']['id'] != "newsblur-premium-36": for sub in customer.subscriptions: sub.delete() customer = stripe.Customer.retrieve(user.profile.stripe_id) if success_updating and customer and customer.subscriptions.total_count == 0: params = dict(customer=customer.id, items=[ { "plan": "newsblur-premium-36", }, ]) premium_expire = user.profile.premium_expire if current_premium and premium_expire: if premium_expire < (datetime.datetime.now() + datetime.timedelta(days=365)): params[ 'billing_cycle_anchor'] = premium_expire.strftime( '%s') params['trial_end'] = premium_expire.strftime('%s') stripe.Subscription.create(**params) else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render(request, 'reader/paypal_return.xhtml') new_user_queue_count = RNewUserQueue.user_count() new_user_queue_position = RNewUserQueue.user_position(request.user.pk) new_user_queue_behind = 0 if new_user_queue_position >= 0: new_user_queue_behind = new_user_queue_count - new_user_queue_position new_user_queue_position -= 1 immediate_charge = True if user.profile.premium_expire and user.profile.premium_expire > datetime.datetime.now( ): immediate_charge = False logging.user(request, "~BM~FBLoading Stripe form") return render( request, 'profile/stripe_form.xhtml', { 'zebra_form': zebra_form, 'publishable': settings.STRIPE_PUBLISHABLE, 'success_updating': success_updating, 'new_user_queue_count': new_user_queue_count - 1, 'new_user_queue_position': new_user_queue_position, 'new_user_queue_behind': new_user_queue_behind, 'renew': renew, 'immediate_charge': immediate_charge, 'error': error, })
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get("plan", 2)) plan = PLANS[plan - 1][0] error = None if request.method == "POST": zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data["email"] user.save() current_premium = ( user.profile.is_premium and user.profile.premium_expire and user.profile.premium_expire > datetime.datetime.now() ) # Are they changing their existing card? if user.profile.stripe_id and current_premium: customer = stripe.Customer.retrieve(user.profile.stripe_id) try: card = customer.cards.create(card=zebra_form.cleaned_data["stripe_token"]) except stripe.CardError: error = "This card was declined." else: customer.default_card = card.id customer.save() success_updating = True else: try: customer = stripe.Customer.create( **{ "card": zebra_form.cleaned_data["stripe_token"], "plan": zebra_form.cleaned_data["plan"], "email": user.email, "description": user.username, } ) except stripe.CardError: error = "This card was declined." else: user.profile.strip_4_digits = zebra_form.cleaned_data["last_4_digits"] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium() # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response("reader/paypal_return.xhtml", {}, context_instance=RequestContext(request)) new_user_queue_count = RNewUserQueue.user_count() new_user_queue_position = RNewUserQueue.user_position(request.user.pk) new_user_queue_behind = 0 if new_user_queue_position >= 0: new_user_queue_behind = new_user_queue_count - new_user_queue_position new_user_queue_position -= 1 logging.user(request, "~BM~FBLoading Stripe form") return render_to_response( "profile/stripe_form.xhtml", { "zebra_form": zebra_form, "publishable": settings.STRIPE_PUBLISHABLE, "success_updating": success_updating, "new_user_queue_count": new_user_queue_count - 1, "new_user_queue_position": new_user_queue_position, "new_user_queue_behind": new_user_queue_behind, "error": error, }, context_instance=RequestContext(request), )
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get('plan', 2)) plan = PLANS[plan-1][0] renew = is_true(request.GET.get('renew', False)) error = None if request.method == 'POST': zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data['email'] user.save() grace_period = datetime.datetime.now() - datetime.timedelta(days=30) current_premium = (user.profile.is_premium and user.profile.premium_expire and user.profile.premium_expire > grace_period) # Are they changing their existing card? if user.profile.stripe_id and current_premium: customer = stripe.Customer.retrieve(user.profile.stripe_id) try: card = customer.cards.create(card=zebra_form.cleaned_data['stripe_token']) except stripe.CardError: error = "This card was declined." else: customer.default_card = card.id customer.save() success_updating = True else: try: customer = stripe.Customer.create(**{ 'card': zebra_form.cleaned_data['stripe_token'], 'plan': zebra_form.cleaned_data['plan'], 'email': user.email, 'description': user.username, }) except stripe.CardError: error = "This card was declined." else: user.profile.strip_4_digits = zebra_form.cleaned_data['last_4_digits'] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium() # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response('reader/paypal_return.xhtml', {}, context_instance=RequestContext(request)) new_user_queue_count = RNewUserQueue.user_count() new_user_queue_position = RNewUserQueue.user_position(request.user.pk) new_user_queue_behind = 0 if new_user_queue_position >= 0: new_user_queue_behind = new_user_queue_count - new_user_queue_position new_user_queue_position -= 1 immediate_charge = True if user.profile.premium_expire and user.profile.premium_expire > datetime.datetime.now(): immediate_charge = False logging.user(request, "~BM~FBLoading Stripe form") return render_to_response('profile/stripe_form.xhtml', { 'zebra_form': zebra_form, 'publishable': settings.STRIPE_PUBLISHABLE, 'success_updating': success_updating, 'new_user_queue_count': new_user_queue_count - 1, 'new_user_queue_position': new_user_queue_position, 'new_user_queue_behind': new_user_queue_behind, 'renew': renew, 'immediate_charge': immediate_charge, 'error': error, }, context_instance=RequestContext(request) )
def stripe_form(request): user = request.user success_updating = False stripe.api_key = settings.STRIPE_SECRET plan = int(request.GET.get('plan', 2)) plan = PLANS[plan - 1][0] renew = is_true(request.GET.get('renew', False)) error = None if request.method == 'POST': zebra_form = StripePlusPaymentForm(request.POST, email=user.email) if zebra_form.is_valid(): user.email = zebra_form.cleaned_data['email'] user.save() grace_period = datetime.datetime.now() - datetime.timedelta( days=30) current_premium = (user.profile.is_premium and user.profile.premium_expire and user.profile.premium_expire > grace_period) # Are they changing their existing card? if user.profile.stripe_id and current_premium: customer = stripe.Customer.retrieve(user.profile.stripe_id) try: card = customer.cards.create( card=zebra_form.cleaned_data['stripe_token']) except stripe.CardError: error = "This card was declined." else: customer.default_card = card.id customer.save() success_updating = True else: try: customer = stripe.Customer.create( **{ 'card': zebra_form.cleaned_data['stripe_token'], 'plan': zebra_form.cleaned_data['plan'], 'email': user.email, 'description': user.username, }) except stripe.CardError: error = "This card was declined." else: user.profile.strip_4_digits = zebra_form.cleaned_data[ 'last_4_digits'] user.profile.stripe_id = customer.id user.profile.save() user.profile.activate_premium( ) # TODO: Remove, because webhooks are slow success_updating = True else: zebra_form = StripePlusPaymentForm(email=user.email, plan=plan) if success_updating: return render_to_response('reader/paypal_return.xhtml', {}, context_instance=RequestContext(request)) new_user_queue_count = RNewUserQueue.user_count() new_user_queue_position = RNewUserQueue.user_position(request.user.pk) new_user_queue_behind = 0 if new_user_queue_position >= 0: new_user_queue_behind = new_user_queue_count - new_user_queue_position new_user_queue_position -= 1 immediate_charge = True if user.profile.premium_expire and user.profile.premium_expire > datetime.datetime.now( ): immediate_charge = False logging.user(request, "~BM~FBLoading Stripe form") return render_to_response('profile/stripe_form.xhtml', { 'zebra_form': zebra_form, 'publishable': settings.STRIPE_PUBLISHABLE, 'success_updating': success_updating, 'new_user_queue_count': new_user_queue_count - 1, 'new_user_queue_position': new_user_queue_position, 'new_user_queue_behind': new_user_queue_behind, 'renew': renew, 'immediate_charge': immediate_charge, 'error': error, }, context_instance=RequestContext(request))