def pytools_lp(request): user = request.user slug = 'pytools' if user.is_authenticated: user_facade.visit_client_landing_page(user, source=request.GET.get( 'utm_source', default='unknown')) data = {'name': user.first_name, 'email': user.email} form = facade.ContactForm(data) else: form = facade.ContactForm() user_creation = user.date_joined if user.is_authenticated else now() is_promotion_season = payment_facade.is_on_pytools_promotion_season( user_creation) payment_item_config = facade.find_payment_item_config(slug) payment_form_config = payment_item_config.default_config price_float = payment_item_config.price / 100 installments = payment_form_config.max_installments price_installment = payment_form_config.calculate_amount( payment_item_config.price, installments) / installments price_installment /= 100 _, promotion_end_date = payment_facade.calculate_pytools_promotion_interval( ) return render( request, 'checkout/pytools_lp.html', { 'contact_form': form, 'slug': slug, 'payment_item_config': payment_item_config, 'price_float': price_float, 'price_installment': price_installment, 'is_promotion_season': is_promotion_season, 'promotion_end_date': promotion_end_date, 'is_promotion_expired': False, })
def get_context_data(self, *args, **kwargs): payment_item_config = facade.find_payment_item_config( 'treinamento-devpro-masterclass-oto') user = self.request.user if user.is_authenticated: data = {'name': user.first_name, 'email': user.email} form = facade.ContactForm(data) else: form = facade.ContactForm() ctx = super().get_context_data(*args, **kwargs) ctx['payment_item_config'] = payment_item_config ctx['contact_form'] = form return ctx
def webdev_landing_page(request): payment_item_config = facade.find_payment_item_config('webdev') user = request.user if user.is_authenticated: data = {'name': user.first_name, 'email': user.email, 'phone': ''} form = facade.ContactForm(data) else: form = facade.ContactForm() ctx = { 'payment_item_config': payment_item_config, 'contact_form': form, } return render(request, 'checkout/webdev_landing_page.html', ctx)
def _render_with_webdev_and_first_day_discounts( request, client_discount_slug, first_day_discount_slug, promotion_end_date, template_name='checkout/bootcamp_lp_subscription_open.html'): user_domain.visit_member_landing_page(request.user, source=request.GET.get( 'utm_source', default='unknown')) has_client_discount = True data = {'name': request.user.first_name, 'email': request.user.email} form = facade.ContactForm(data) has_first_day_discount = True no_discount_item_config = facade.find_payment_item_config('bootcamp') first_day_discount_item_config = facade.find_payment_item_config( first_day_discount_slug) first_day_discount = no_discount_item_config.price - first_day_discount_item_config.price client_discount_item_config = facade.find_payment_item_config( client_discount_slug) payment_item_config = client_discount_item_config client_discount = no_discount_item_config.price - client_discount_item_config.price - first_day_discount return _render_bootcamp_lp(client_discount, first_day_discount, form, has_client_discount, has_first_day_discount, no_discount_item_config, payment_item_config, promotion_end_date, request, template_name)
def bootcamp_lp_d3_webdev(request): user = request.user has_discount = checkout_facade.has_35_percent_discount( ) or checkout_facade.has_50_percent_discount() is_debug = bool(request.GET.get('debug', False)) if not is_debug and (has_discount or not (checkout_facade.is_launch_open() and is_webdev(user))): return _redirect_to_bootcamp_lp(request) user_domain.visit_member_landing_page(request.user, source=request.GET.get( 'utm_source', default='unknown')) has_client_discount = True data = {'name': request.user.first_name, 'email': request.user.email} form = facade.ContactForm(data) has_first_day_discount = False no_discount_item_config = facade.find_payment_item_config('bootcamp') first_day_discount = 0 client_discount_item_config = facade.find_payment_item_config( 'bootcamp-webdev') promotion_end_date = checkout_facade.launch_datetime_finish payment_item_config = client_discount_item_config client_discount = no_discount_item_config.price - client_discount_item_config.price - first_day_discount return _render_bootcamp_lp(client_discount, first_day_discount, form, has_client_discount, has_first_day_discount, no_discount_item_config, payment_item_config, promotion_end_date, request, 'checkout/bootcamp_lp_d3.html')
def bootcamp_lp_d3(request): user = request.user has_discount = checkout_facade.has_35_percent_discount( ) or checkout_facade.has_50_percent_discount() or is_webdev(user) is_debug = bool(request.GET.get('debug', False)) if not is_debug and ((not checkout_facade.is_launch_open()) or has_discount): return _redirect_to_bootcamp_lp(request) if request.user.is_authenticated: user_domain.visit_member_landing_page(request.user, source=request.GET.get( 'utm_source', default='unknown')) form = facade.ContactForm() payment_item_config = no_discount_item_config = facade.find_payment_item_config( 'bootcamp') first_day_discount = 0 client_discount = 0 has_first_day_discount = False has_client_discount = False promotion_end_date = checkout_facade.launch_datetime_finish return _render_bootcamp_lp(client_discount, first_day_discount, form, has_client_discount, has_first_day_discount, no_discount_item_config, payment_item_config, promotion_end_date, request, 'checkout/bootcamp_lp_d3.html')
def webdev_landing_page_oto(request): payment_item_config = facade.find_payment_item_config('webdev-oto') user = request.user if user.is_authenticated: data = {'name': user.first_name, 'email': user.email} form = facade.ContactForm(data) else: form = facade.ContactForm() ctx = { 'payment_item_config': payment_item_config, 'contact_form': form, 'countdown_limit': request.user.date_joined + timedelta(seconds=30 * 60) } return render(request, 'checkout/webdev_landing_page_oto.html', ctx)
def contact_info(request, slug): payment_item = facade.get_payment_item(slug) if not facade.is_payment_config_item_available(payment_item, request): return redirect( reverse('django_pagarme:unavailable', kwargs={'slug': slug})) if request.method == 'GET': user = request.user if user.is_authenticated: try: payment_profile = facade.get_user_payment_profile(user.id) except facade.UserPaymentProfileDoesNotExist: form = facade.ContactForm({ 'name': user.first_name, 'email': user.email }) else: form = facade.ContactForm({ 'name': payment_profile.name, 'email': payment_profile.email, 'phone': payment_profile.phone }) else: form = facade.ContactForm() ctx = {'contact_form': form, 'slug': slug} return render(request, 'django_pagarme/contact_form.html', ctx) dct = {key: request.POST[key] for key in 'name phone email'.split()} dct['payment_item_slug'] = slug try: dct = facade.validate_and_inform_contact_info(user=request.user, **dct) except facade.InvalidContactData as e: ctx = {'contact_form': e.contact_form, 'slug': slug} resp = render(request, 'django_pagarme/contact_form_errors.html', ctx, status=400) return resp else: path = reverse('django_pagarme:pagarme', kwargs={'slug': slug}) dct['open_modal'] = 'true' query_string = urlencode(dct) return redirect(f'{path}?{query_string}')
def _no_wevdev_discount(request, discount_slug, promotion_end_date): if request.user.is_authenticated: user_facade.visit_member_landing_page(request.user, source=request.GET.get('utm_source', default='unknown')) form = facade.ContactForm() payment_item_config = facade.find_payment_item_config(discount_slug) no_discount_item_config = facade.find_payment_item_config('bootcamp') first_day_discount = no_discount_item_config.price - payment_item_config.price client_discount = 0 has_first_day_discount = True has_client_discount = False return _render_bootcamp_lp(client_discount, first_day_discount, form, has_client_discount, has_first_day_discount, no_discount_item_config, payment_item_config, promotion_end_date, request)
def _webdev_landing_page_50_off(request, template_name, seconds_to_show_full_page=90): payment_item_config = facade.find_payment_item_config('webdev-oto') user = request.user if user.is_authenticated: data = {'name': user.first_name, 'email': user.email} form = facade.ContactForm(data) else: form = facade.ContactForm() countdown_limit = request.user.date_joined + timedelta(days=5) is_promotion_expired = timezone.now() > countdown_limit if request.GET.get('debug') is not None: is_promotion_expired = False ctx = { 'payment_item_config': payment_item_config, 'contact_form': form, 'countdown_limit': countdown_limit, 'is_promotion_expired': is_promotion_expired, 'seconds_to_show_full_page': seconds_to_show_full_page } return render(request, template_name, ctx)
def pytools_oto_lp(request): is_debug = bool(request.GET.get('debug', False)) user = request.user if not (user.is_authenticated or is_debug): return HttpResponseRedirect(reverse('checkout:pytools_lp')) slug = 'pytools-oto' if user.is_authenticated: user_facade.visit_client_landing_page(user, source=request.GET.get( 'utm_source', default='unknown')) data = {'name': user.first_name, 'email': user.email} form = facade.ContactForm(data) else: form = facade.ContactForm() countdown_limit = payment_facade.calculate_oto_expires_datetime( user.date_joined) if not is_debug else now() is_promotion_expired = not ( is_debug or payment_facade.is_on_pytools_oto_season(user.date_joined)) payment_item_config = facade.find_payment_item_config(slug) payment_form_config = payment_item_config.default_config price_float = payment_item_config.price / 100 installments = payment_form_config.max_installments price_installment = payment_form_config.calculate_amount( payment_item_config.price, installments) / installments price_installment /= 100 return render( request, 'checkout/pytools_oto_lp.html', { 'contact_form': form, 'slug': slug, 'payment_item_config': payment_item_config, 'price_float': price_float, 'price_installment': price_installment, 'is_promotion_expired': is_promotion_expired, 'countdown_limit': countdown_limit, })
def contact_info(request, slug): if request.method == 'GET': form = facade.ContactForm() ctx = {'contact_form': form, 'slug': slug} return render(request, 'django_pagarme/contact_form.html', ctx) dct = {key: request.POST[key] for key in 'name phone email'.split()} dct['payment_item_slug'] = slug try: dct = facade.validate_and_inform_contact_info(user=request.user, **dct) except facade.InvalidContactData as e: ctx = {'contact_form': e.contact_form, 'slug': slug} resp = render(request, 'django_pagarme/contact_form_errors.html', ctx, status=400) return resp else: path = reverse('django_pagarme:pagarme', kwargs={'slug': slug}) dct['open_modal'] = 'true' query_string = urlencode(dct) return redirect(f'{path}?{query_string}')
def membership_lp(request): user = request.user if request.method == 'POST': form = WaitingForm(request.POST) if form.is_valid(): source = request.GET.get('utm_source', default='unknown') data = form.cleaned_data if user.is_authenticated: user_facade.subscribe_to_waiting_list(request.user, data['phone'], source) else: user_facade.subscribe_anonymous_user_to_waiting_list( data['email'], data['first_name'], data['phone'], source) return redirect(reverse('checkout:waiting_list_ty')) else: return render(request, 'checkout/membership_lp_subscription_closed.html', {'form': form}) if user.is_authenticated: user_facade.visit_member_landing_page(request.user, source=request.GET.get( 'utm_source', default='unknown')) is_debug = bool(request.GET.get('debug', False)) should_show_closed_subscription_page = not ( is_debug or checkout_facade.is_launch_open()) if should_show_closed_subscription_page: form = checkout_forms.WaitingForm() return render(request, 'checkout/membership_lp_subscription_closed.html', {'form': form}) has_client_discount = False if user.is_authenticated: has_client_discount = is_client(user) data = {'name': user.first_name, 'email': user.email} form = facade.ContactForm(data) else: form = facade.ContactForm() has_first_day_discount = checkout_facade.is_launch_first_day_discount( ) or is_debug no_discount_item_config = facade.find_payment_item_config('membership') payment_item_config = no_discount_item_config client_discount = 0 first_day_discount = 0 client_discount_slug = 'membership-client' if has_first_day_discount: first_day_discount_item_config = facade.find_payment_item_config( 'membership-first-day') payment_item_config = first_day_discount_item_config first_day_discount = no_discount_item_config.price - first_day_discount_item_config.price if has_client_discount: client_discount_slug = 'membership-client-first-day' if has_client_discount: client_discount_item_config = facade.find_payment_item_config( client_discount_slug) payment_item_config = client_discount_item_config client_discount = no_discount_item_config.price - client_discount_item_config.price - first_day_discount login_url = reverse('two_factor:login') redirect_path = reverse('checkout:membership_lp') qs = urlencode({'utm_source': request.GET.get('utm_source', 'unknown')}) redirect_url = f'{redirect_path}?{qs}' qs = urlencode({'next': redirect_url}) login_url = f'{login_url}?{qs}' promotion_end_date = (checkout_facade.discount_datetime_limit if has_first_day_discount else checkout_facade.launch_datetime_finish) # Seconds to milliseconds https://stackoverflow.com/questions/5022447/converting-date-from-python-to-javascript promotion_end_date_milliseconds = int( time.mktime(promotion_end_date.timetuple())) * 1000 context = { 'launch_datetime_finish': checkout_facade.launch_datetime_finish, 'discount_datetime_limit': checkout_facade.discount_datetime_limit, 'payment_item_config': payment_item_config, 'contact_form': form, 'login_url': login_url, 'has_first_day_discount': has_first_day_discount, 'has_client_discount': has_client_discount, 'client_discount': client_discount, 'first_day_discount': first_day_discount, 'promotion_end_date': promotion_end_date, 'promotion_end_date_milliseconds': promotion_end_date_milliseconds, 'no_discount_item_config': no_discount_item_config, } return render(request, 'checkout/membership_lp_subscription_open.html', context)