Ejemplo n.º 1
0
    def test_get_seat_count(self) -> None:
        initial_count = get_seat_count(self.realm)
        user1 = UserProfile.objects.create(realm=self.realm, email='*****@*****.**', pointer=-1)
        user2 = UserProfile.objects.create(realm=self.realm, email='*****@*****.**', pointer=-1)
        self.assertEqual(get_seat_count(self.realm), initial_count + 2)

        # Test that bots aren't counted
        user1.is_bot = True
        user1.save(update_fields=['is_bot'])
        self.assertEqual(get_seat_count(self.realm), initial_count + 1)

        # Test that inactive users aren't counted
        do_deactivate_user(user2)
        self.assertEqual(get_seat_count(self.realm), initial_count)
Ejemplo n.º 2
0
    def test_get_seat_count(self) -> None:
        realm = get_realm("zulip")
        initial_count = get_seat_count(realm)
        user1 = UserProfile.objects.create(realm=realm, email='*****@*****.**', pointer=-1)
        user2 = UserProfile.objects.create(realm=realm, email='*****@*****.**', pointer=-1)
        self.assertEqual(get_seat_count(realm), initial_count + 2)

        # Test that bots aren't counted
        user1.is_bot = True
        user1.save(update_fields=['is_bot'])
        self.assertEqual(get_seat_count(realm), initial_count + 1)

        # Test that inactive users aren't counted
        do_deactivate_user(user2)
        self.assertEqual(get_seat_count(realm), initial_count)
Ejemplo n.º 3
0
def initial_upgrade(request: HttpRequest) -> HttpResponse:
    user = request.user
    if Customer.objects.filter(realm=user.realm).exists():
        return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    if request.method == 'POST':
        customer = do_create_customer_with_payment_source(user, request.POST['stripeToken'])
        # TODO: the current way this is done is subject to tampering by the user.
        seat_count = int(request.POST['seat_count'])
        if seat_count < 1:
            raise AssertionError('seat_count is less than 1')
        do_subscribe_customer_to_plan(
            customer=customer,
            stripe_plan_id=Plan.objects.get(nickname=request.POST['plan']).stripe_plan_id,
            seat_count=seat_count,
            # TODO: billing address details are passed to us in the request;
            # use that to calculate taxes.
            tax_percent=0)
        # TODO: check for errors and raise/send to frontend
        return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    context = {
        'publishable_key': STRIPE_PUBLISHABLE_KEY,
        'email': user.email,
        'seat_count': get_seat_count(user.realm),
        'plan': "Zulip Premium",
        'nickname_monthly': Plan.CLOUD_MONTHLY,
        'nickname_annual': Plan.CLOUD_ANNUAL,
    }  # type: Dict[str, Any]
    return render(request, 'zilencer/upgrade.html', context=context)
Ejemplo n.º 4
0
def initial_upgrade(request: HttpRequest) -> HttpResponse:
    if not settings.DEVELOPMENT:
        return render(request, "404.html")

    user = request.user
    error_message = ""

    if Customer.objects.filter(realm=user.realm).exists():
        return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    if request.method == 'POST':
        plan = request.POST['plan']
        if plan not in [Plan.CLOUD_ANNUAL, Plan.CLOUD_MONTHLY]:
            billing_logger.warning(
                "Tampered plan during realm upgrade. user: %s, realm: %s (%s)."
                % (user.id, user.realm.id, user.realm.string_id))
            error_message = "Something went wrong. Please contact [email protected]"
        try:
            seat_count = int(
                unsign_string(request.POST['signed_seat_count'],
                              request.POST['salt']))
        except signing.BadSignature:
            billing_logger.warning(
                "Tampered seat count during realm upgrade. user: %s, realm: %s (%s)."
                % (user.id, user.realm.id, user.realm.string_id))
            error_message = "Something went wrong. Please contact [email protected]"

        if not error_message:
            stripe_customer = do_create_customer_with_payment_source(
                user, request.POST['stripeToken'])
            do_subscribe_customer_to_plan(
                stripe_customer=stripe_customer,
                stripe_plan_id=Plan.objects.get(nickname=plan).stripe_plan_id,
                seat_count=seat_count,
                # TODO: billing address details are passed to us in the request;
                # use that to calculate taxes.
                tax_percent=0)
            # TODO: check for errors and raise/send to frontend
            return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    seat_count = get_seat_count(user.realm)
    signed_seat_count, salt = sign_string(str(seat_count))
    context = {
        'publishable_key': STRIPE_PUBLISHABLE_KEY,
        'email': user.email,
        'seat_count': seat_count,
        'signed_seat_count': signed_seat_count,
        'salt': salt,
        'plan': "Zulip Premium",
        'nickname_monthly': Plan.CLOUD_MONTHLY,
        'nickname_annual': Plan.CLOUD_ANNUAL,
        'error_message': error_message,
    }  # type: Dict[str, Any]
    return render(request, 'zilencer/upgrade.html', context=context)
Ejemplo n.º 5
0
def initial_upgrade(request: HttpRequest) -> HttpResponse:
    if not settings.DEVELOPMENT:
        return render(request, "404.html")

    user = request.user
    error_message = ""

    if Customer.objects.filter(realm=user.realm).exists():
        return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    if request.method == 'POST':
        plan = request.POST['plan']
        if plan not in [Plan.CLOUD_ANNUAL, Plan.CLOUD_MONTHLY]:
            billing_logger.warning("Tampered plan during realm upgrade. user: %s, realm: %s (%s)."
                                   % (user.id, user.realm.id, user.realm.string_id))
            error_message = "Something went wrong. Please contact [email protected]"
        try:
            seat_count = int(unsign_string(request.POST['signed_seat_count'], request.POST['salt']))
        except signing.BadSignature:
            billing_logger.warning("Tampered seat count during realm upgrade. user: %s, realm: %s (%s)."
                                   % (user.id, user.realm.id, user.realm.string_id))
            error_message = "Something went wrong. Please contact [email protected]"

        if not error_message:
            stripe_customer = do_create_customer_with_payment_source(user, request.POST['stripeToken'])
            do_subscribe_customer_to_plan(
                stripe_customer=stripe_customer,
                stripe_plan_id=Plan.objects.get(nickname=plan).stripe_plan_id,
                seat_count=seat_count,
                # TODO: billing address details are passed to us in the request;
                # use that to calculate taxes.
                tax_percent=0)
            # TODO: check for errors and raise/send to frontend
            return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    seat_count = get_seat_count(user.realm)
    signed_seat_count, salt = sign_string(str(seat_count))
    context = {
        'publishable_key': STRIPE_PUBLISHABLE_KEY,
        'email': user.email,
        'seat_count': seat_count,
        'signed_seat_count': signed_seat_count,
        'salt': salt,
        'plan': "Zulip Premium",
        'nickname_monthly': Plan.CLOUD_MONTHLY,
        'nickname_annual': Plan.CLOUD_ANNUAL,
        'error_message': error_message,
    }  # type: Dict[str, Any]
    return render(request, 'zilencer/upgrade.html', context=context)
Ejemplo n.º 6
0
def initial_upgrade(request: HttpRequest) -> HttpResponse:
    if not settings.BILLING_ENABLED:
        return render(request, "404.html")

    user = request.user
    error_message = ""
    error_description = ""  # only used in tests

    customer = Customer.objects.filter(realm=user.realm).first()
    if customer is not None and customer.has_billing_relationship:
        return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    if request.method == 'POST':
        try:
            plan, seat_count = unsign_and_check_upgrade_parameters(
                user, request.POST['plan'], request.POST['signed_seat_count'],
                request.POST['salt'])
            process_initial_upgrade(user, plan, seat_count,
                                    request.POST['stripeToken'])
        except BillingError as e:
            error_message = e.message
            error_description = e.description
        except Exception as e:
            billing_logger.exception("Uncaught exception in billing: %s" %
                                     (e, ))
            error_message = BillingError.CONTACT_SUPPORT
        else:
            return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    seat_count = get_seat_count(user.realm)
    signed_seat_count, salt = sign_string(str(seat_count))
    context = {
        'publishable_key': STRIPE_PUBLISHABLE_KEY,
        'email': user.email,
        'seat_count': seat_count,
        'signed_seat_count': signed_seat_count,
        'salt': salt,
        'plan': "Zulip Premium",
        'nickname_monthly': Plan.CLOUD_MONTHLY,
        'nickname_annual': Plan.CLOUD_ANNUAL,
        'error_message': error_message,
        'cloud_monthly_price': 8,
        'cloud_annual_price': 80,
        'cloud_annual_price_per_month': 6.67,
    }  # type: Dict[str, Any]
    response = render(request, 'zilencer/upgrade.html', context=context)
    response['error_description'] = error_description
    return response
Ejemplo n.º 7
0
Archivo: views.py Proyecto: kyoki/zulip
def initial_upgrade(request: HttpRequest) -> HttpResponse:
    if not settings.BILLING_ENABLED:
        return render(request, "404.html")

    user = request.user
    error_message = ""
    error_description = ""  # only used in tests

    customer = Customer.objects.filter(realm=user.realm).first()
    if customer is not None and customer.has_billing_relationship:
        return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    if request.method == 'POST':
        try:
            plan, seat_count = unsign_and_check_upgrade_parameters(
                user, request.POST['plan'], request.POST['signed_seat_count'], request.POST['salt'])
            process_initial_upgrade(user, plan, seat_count, request.POST['stripeToken'])
        except BillingError as e:
            error_message = e.message
            error_description = e.description
        except Exception as e:
            billing_logger.exception("Uncaught exception in billing: %s" % (e,))
            error_message = BillingError.CONTACT_SUPPORT
        else:
            return HttpResponseRedirect(reverse('zilencer.views.billing_home'))

    seat_count = get_seat_count(user.realm)
    signed_seat_count, salt = sign_string(str(seat_count))
    context = {
        'publishable_key': STRIPE_PUBLISHABLE_KEY,
        'email': user.email,
        'seat_count': seat_count,
        'signed_seat_count': signed_seat_count,
        'salt': salt,
        'plan': "Zulip Premium",
        'nickname_monthly': Plan.CLOUD_MONTHLY,
        'nickname_annual': Plan.CLOUD_ANNUAL,
        'error_message': error_message,
        'cloud_monthly_price': 8,
        'cloud_annual_price': 80,
        'cloud_annual_price_per_month': 6.67,
    }  # type: Dict[str, Any]
    response = render(request, 'zilencer/upgrade.html', context=context)
    response['error_description'] = error_description
    return response