def handle(self, *args, **options): User = get_user_model() for user in User.objects.filter(customer__isnull=True): # Only non-superusers if not user.is_superuser and (user.username != "AnonymousUser"): Customer.create(user=user) print "Created customer for {0}".format(user.email)
def create_email_user(self): pw = self.cleaned_data['password'] new_user = User.objects.create_user(self.cleaned_data['email'], self.cleaned_data['email'], pw) new_user.first_name = self.cleaned_data['first_name'] new_user.save() c = Customer() c.user = new_user c.preferred_name = self.cleaned_data['first_name'] c.save() return c, pw
def create_customer(email, passwd, first, last, staff=False, superuser=False): u = User.objects.create_user(username=email, email=email, password=passwd) u.first_name = first u.last_name = last u.is_staff = staff u.is_superuser = superuser u.is_active = True u.save() c = Customer() c.user = u c.save() return c
def set_new_user_plan(user, default_plan='free'): "Sets the the default plan of the user to the Starter (Free) plan." Customer.create(user=user) try: current_plan = user.customer.current_subscription.plan except CurrentSubscription.DoesNotExist: # It should enter here by default on normal execution. current_plan = default_plan try: user.customer.subscribe(current_plan) except stripe.StripeError, e: return e.message
def create_customer(request): form = StripeTokenForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest() card = form.cleaned_data['id'] customer = Customer.create(request.user, card=card, charge_immediately=False) return {}
def obj_create(self, bundle, **kwargs): try: customer = bundle.request.user.customer except ObjectDoesNotExist: customer = Customer.create(bundle.request.user) customer.update_card(bundle.data["stripe_token"]) customer.subscribe(bundle.data["plan_type"])
def handle(self, *args, **options): for user in User.objects.filter(customer__isnull=True): trial_days = None if TRIAL_PERIOD_FOR_USER_CALLBACK: trial_days = TRIAL_PERIOD_FOR_USER_CALLBACK(user) cus = Customer.create(user=user) if DEFAULT_PLAN and trial_days: cus.purchase(plan=DEFAULT_PLAN, trial_days=trial_days) print "Created customer for %s" % user.email
def save(self, **kwargs): # try: try: customer = self.user.customer except ObjectDoesNotExist: customer = Customer.create(self.user) finally: if self.cleaned_data["stripe_token"] not in [None, ""]: customer.update_card(self.cleaned_data["stripe_token"]) customer.subscribe(self.cleaned_data["plan"])
def subscribe_ajax(request): """""" stripe_token = request.POST.get("stripe_token") plan_id = request.POST.get("plan_id", None) try: customer = request.user.customer except ObjectDoesNotExist: customer = Customer.create(request.user) customer.update_card(stripe_token) customer.subscribe(plan_id) messages.success(request, 'Votre abonnement est maintenant activé.') return JSONResponse({'message': 'Abonnement réussi'})
def subscribe_ajax(request): """""" stripe_token = request.POST.get("stripe_token") plan_id = request.POST.get("plan_id", None) try: customer = request.user.customer except ObjectDoesNotExist: customer = Customer.create(request.user) customer.update_card(stripe_token) customer.subscribe(plan_id) messages.success(request, 'Your subscription is now active.') return JSONResponse({'message': 'Subscription successful'})
def subscribe(request): if 'terms' in request.POST: bfcust = request.user BigFanAcct = request.session['BigFanAcct'] customer = Customer.create(bfcust, charge_immediately=False) customer.update_card(request.POST.get("stripeToken")) bfcust.add1 = request.POST['address1'] bfcust.add2 = request.POST['address2'] bfcust.city = request.POST['city'] bfcust.state = request.POST['state'] bfcust.zipcode = request.POST['zipcode'] try: coupon = request.POST['coupon'].lower() stripe.Coupon.retrieve(coupon) except stripe.StripeError as e: coupon=None bfcust.save() try: if 'autorenew' in request.POST: if coupon: customer.subscribe(BigFanAcct.bfname.product.product_name, coupon=coupon) else: customer.subscribe(BigFanAcct.bfname.product.product_name) bfemail = BigFanAcct.bfname.bfname + "@" + BigFanAcct.bfname.domain.domain_name message = "Congratulations, you have successfully registered email address, " + bfemail + "." + "\nYou will soon receive verfication that your BigFanMail email address is ready to use.\nIf you have any questions, please email us at [email protected] .\n\nBigFanMail Support" acctemail = EmailMessage('New Account', message, '*****@*****.**', [BigFanAcct.customer.email_address], settings.ADMINS, headers = {}) acctemail.send() BigFanName = request.session['BigFanObj'] BigFanName.save() #BigFanAnswer = request.session['BigFanAnswer'] #BigFanAnswer.save() BigFanAcct.bfname = BigFanName BigFanAcct.offer_code = request.POST['coupon'] BigFanAcct.auto_renew = True BigFanAcct.save() request.session['BigFanAcct'] = BigFanAcct else: customer.charge(decimal.Decimal(BigFanAcct.bfname.product.price), description="BigFanAcct.bfname.product.description") except stripe.StripeError as e: try: data = {} data["error"] = e.args[0] except IndexError: data["error"] = "Unknown error" return render(request, 'registration/creditcard.html', {}) # return _ajax_response(request, "payments/_subscribe_form.html", **data) # return render(request, 'registration/registration_complete.html', {}) return redirect('/register/get_host_password/', permanent=True) else: return render(request, 'registration/creditcard.html', {})
def subscribe(request, form_class=PlanForm): data = {"plans": settings.PAYMENTS_PLANS} form = form_class(request.POST) if form.is_valid(): try: try: customer = request.user.customer except ObjectDoesNotExist: customer = Customer.create(request.user) customer.update_card(request.POST.get("stripe_token")) customer.subscribe(form.cleaned_data["plan"]) data["form"] = form_class() data["location"] = reverse("payments_history") except stripe.StripeError, e: data["form"] = form data["error"] = e.message
def sign_up(request): if request.method == 'POST': try: try: customer = request.user.customer except ObjectDoesNotExist: customer = Customer.create(request.user) customer.update_card(request.POST.get("stripeToken")) # TODO: get to 1.0 so we can start charging for reals! customer.subscribe('free', trial_days=14) except stripe.StripeError, e: # At least one error is known: # Your card was declined. Your request was in test mode, but # used a non test card. For a list of valid test cards, # visit: https://stripe.com/docs/testing print "ERROR:", e # All good! Goto thankyou? return HttpResponseRedirect("/")
def subscribe(request, form_class=PlanForm): data = {"plans": settings.PAYMENTS_PLANS} form = form_class(request.POST) if form.is_valid(): try: try: customer = request.user.customer except ObjectDoesNotExist: customer = Customer.create(request.user) customer.update_card(request.POST.get("stripe_token")) customer.subscribe(form.cleaned_data["plan"]) data["form"] = form_class() data["location"] = reverse("payments_history") except stripe.StripeError as e: data["form"] = form try: data["error"] = e.args[0] except IndexError: data["error"] = "Unknown error" else: data["error"] = form.errors data["form"] = form return _ajax_response(request, "payments/_subscribe_form.html", **data)
def subscribe(request, form_class=PlanForm): data = {"plans": settings.PAYMENTS_PLANS} form = form_class(request.POST) if form.is_valid(): try: try: customer = request.user.customer except ObjectDoesNotExist: customer = Customer.create(request.user) customer.update_card(request.POST.get("stripe_token")) customer.subscribe(form.cleaned_data["plan"]) data["form"] = form_class() data["location"] = reverse("payments_history") except stripe.StripeError as e: print e data["form"] = form try: data["error"] = e.args[0] except IndexError: data["error"] = "Unknown error" else: data["error"] = form.errors data["form"] = form return _ajax_response(request, "payment/_subscribe_form.html", **data)
def test_get_customer(self, CreateMock): CreateMock.return_value = Customer() customer = get_customer(self.user) self.assertIsInstance(customer, Customer)
def get_customer(self): try: return self.request.user.customer except: return Customer.create(self.request.user)
def handle(self, *args, **options): for user in User.objects.filter(customer__isnull=True): Customer.create(user=user) print "Created customer for {0}".format(user.email)
def get_customer(user): try: return user.customer except: return Customer.create(user)