Example #1
0
def payment_status(request, payment_attempt):

    if payment_attempt.status.lower() in ('paid', 'in verification'):
        #payment_attempt.order.confirm(request)
        utils.clear_cart(request, payment_attempt.order)
        confirmed_orders_in_session = request.session.get(
            'confirmed_orders', [])
        confirmed_orders_in_session.append(payment_attempt.order.id)
        request.session['confirmed_orders'] = confirmed_orders_in_session
        if utils.is_franchise(request):
            return HttpResponseRedirect('/orders/%s/confirmation' %
                                        payment_attempt.order.id)

        elif utils.is_cc(request):
            return HttpResponseRedirect(
                request.path.replace('book',
                                     '%s/booked' % payment_attempt.order.id))

        elif request.path.startswith('/w/'):
            return HttpResponseRedirect(
                request.path.replace(
                    'process_payment',
                    '%s/confirmation' % payment_attempt.order.id))
        else:
            return HttpResponseRedirect('/orders/%s/confirmation' %
                                        payment_attempt.order.id)
    else:
        if payment_attempt.status.lower() == 'rejected':
            order = payment_attempt.order
            delta_oi = []
            order_items = order.get_order_items(
                request, exclude=dict(state__in=['cancelled', 'bundle_item']))
            for item in order_items:
                delta_oi.append({
                    'order_item': item,
                    'qty': item.qty,
                    'amount': item.payable_amount()
                })
            order.update_inventory(request, action='add', delta=delta_oi)

        if payment_attempt.response == '!YM':
            request.session[
                'failed_payment'] = 'Sorry, your transaction is authorized but could not be processed due to incorrect billing address/pin code entered. The authorized amount will be reversed automatically in your card account. For more details please call your bank.'
        else:
            request.session[
                'failed_payment'] = 'Your payment got Rejected/Cancelled. Please try again with another card'

        payment_log.info(" Payment Failed Client is %s " % request.client)

        if utils.is_franchise(request):
            return HttpResponseRedirect('/orders/shipping')

        elif utils.is_cc(request):
            return HttpResponseRedirect(request.path)

        elif utils.is_future_ecom(payment_attempt.order.client):
            request.session['http_referer'] = 'payment_status'
            return HttpResponseRedirect('/orders/payment_mode/')
        else:
            return HttpResponseRedirect('/orders/shipping')
Example #2
0
def payment_status(request,payment_attempt):
    
    if payment_attempt.status.lower() in ('paid', 'in verification'):
        #payment_attempt.order.confirm(request)
        utils.clear_cart(request, payment_attempt.order)
        confirmed_orders_in_session = request.session.get(
                'confirmed_orders', [])
        confirmed_orders_in_session.append(payment_attempt.order.id)
        request.session['confirmed_orders'] = confirmed_orders_in_session
        if utils.is_franchise(request):
            return HttpResponseRedirect('/orders/%s/confirmation' % payment_attempt.order.id)
        
        elif utils.is_cc(request):
            return HttpResponseRedirect(request.path.replace('book',
                '%s/booked' % payment_attempt.order.id))
        
        elif request.path.startswith('/w/'):
            return HttpResponseRedirect(request.path.replace(
                'process_payment','%s/confirmation' % payment_attempt.order.id))
        else:
            return HttpResponseRedirect('/orders/%s/confirmation' % payment_attempt.order.id)
    else:
        if payment_attempt.status.lower() == 'rejected':
            order = payment_attempt.order
            delta_oi = []
            order_items = order.get_order_items(request, exclude=dict(state__in=['cancelled','bundle_item']))
            for item in order_items:
                delta_oi.append({'order_item':item, 'qty':item.qty, 'amount':item.payable_amount()})
            order.update_inventory(request, action='add', delta=delta_oi)

        if payment_attempt.response == '!YM':
            request.session['failed_payment'] = 'Sorry, your transaction is authorized but could not be processed due to incorrect billing address/pin code entered. The authorized amount will be reversed automatically in your card account. For more details please call your bank.'
        else:
            request.session['failed_payment'] = 'Your payment got Rejected/Cancelled. Please try again with another card'
        
        payment_log.info(" Payment Failed Client is %s " % request.client)
        
        if utils.is_franchise(request):
            return HttpResponseRedirect('/orders/shipping')
        
        elif utils.is_cc(request):
            return HttpResponseRedirect(request.path)
        
        elif utils.is_future_ecom(payment_attempt.order.client):
                request.session['http_referer'] = 'payment_status'
                return HttpResponseRedirect('/orders/payment_mode/')
        else:
            return HttpResponseRedirect('/orders/shipping')
Example #3
0
def switch_franchise_permissions(request, franchise_id):
    error = ''
    is_active = 'no_action'
    if 'req_status' in request.GET:
        req_status = request.GET.get('req_status')
        if utils.is_franchise(request) and 'is_network' in request.session and request.session['is_network'] and 'network' in request.session :
            try:
                franchise = Franchise.objects.select_related('franchise').get(id=franchise_id, network = request.session['network'])
                
                if franchise.is_active and req_status == 'deactivate':
                    franchise = Franchise.objects.filter(id=franchise_id).update(is_active= False)
                    is_active = 'deactivated'
                elif not franchise.is_active and req_status == 'activate':
                    franchise = Franchise.objects.filter(id=franchise_id).update(is_active= True)
                    is_active = 'activated'
            except:
                error= 'No such ICW exists'
        else:
            error= 'You do not have an access'
    else:
        error = 'Not sure whether to activate or deactivate. Please try later.'

    if error:
        ajax_response = dict(status='failed', error=error)
    else:
        ajax_response = dict(status='success', is_active=is_active)
    return HttpResponse(simplejson.dumps(ajax_response))
Example #4
0
File: home.py Project: daasara/riba
def login(request,
          template_name='registration/login.html',
          redirect_field_name=REDIRECT_FIELD_NAME,
          authentication_form=AuthenticationForm):
    """Displays the login form and handles the login action."""
    redirect_to = request.REQUEST.get(redirect_field_name, '')

    error = ''
    if request.method == "POST":
        form = authentication_form(data=request.POST)
        if form.is_valid():
            #Franchise-network e.g. Itz
            if utils.is_franchise(request):
                profile = utils.get_user_profile(form.get_user())
                if not profile:
                    error = "No profile found related to this email"
                elif not is_valid_franchise(profile):
                    error = "You do not have rights to access this interface. Please request your manager to get the rights."
                #else:
                #    perm = 'auth.access_franchise'
                #    if profile and not profile.user.has_perm(perm):
                #        error = 'You do not have rights to access Franchise interface. Please request your manager to get the rights OR Add permissions through admin to this user but dont make superuser.'
            elif utils.is_cc(request):
                #profile = utils.get_profile_by_email_or_phone(form.get_user())
                profile = utils.get_user_profile(form.get_user())
                perm = (request.client.type == 'store'
                        ) and 'auth.access_store' or 'auth.access_callcenter'
                if profile and not profile.user.has_perm(perm):
                    error = 'You do not have rights to access this interface. Please request your manager to get the rights.'
            #Sellers Hub:
            elif utils.is_platform(request):
                profile = utils.get_user_profile(form.get_user())
                perm1 = 'users.access_ppd'
                perm2 = 'users.access_ifs'
                if profile and not (profile.user.has_perm(perm1)
                                    or profile.user.has_perm(perm2)):
                    error = 'You do not have rights to access this interface. Please request your manager to get the rights.'
            if not error:
                if utils.is_platform(request) and profile:
                    redirect_to = "/home"
                # Light security check -- make sure redirect_to isn't garbage.
                if not redirect_to or ' ' in redirect_to:
                    redirect_to = settings.LOGIN_REDIRECT_URL

                # Heavier security check -- redirects to http://example.com should
                # not be allowed, but things like /view/?param=http://example.com
                # should be allowed. This regex checks if there is a '//' *before* a
                # question mark.
                elif '//' in redirect_to and re.match(r'[^\?]*//',
                                                      redirect_to):
                    redirect_to = settings.LOGIN_REDIRECT_URL
                # Okay, security checks complete. Log the user in.
                auth_login(request, form.get_user())
                if utils.is_platform(request):
                    profile = utils.get_user_profile(request.user)
                    sellers = profile.managed_accounts.filter(
                        client=request.client.client)
                    request.session['all_sellers'] = sellers
                    request.session['seller'] = [sellers[0]]

                if request.session.test_cookie_worked():
                    request.session.delete_test_cookie()
                return HttpResponseRedirect(redirect_to)

    else:
        form = authentication_form(request)

    request.session.set_test_cookie()
    if Site._meta.installed:
        current_site = Site.objects.get_current()
    else:
        current_site = RequestSite(request)
    return render_to_response(template_name, {
        'error': error,
        'form': form,
        'redirect_field_name': redirect_to,
        'site': current_site,
        'site_name': current_site.name,
    },
                              context_instance=RequestContext(request))
Example #5
0
def login(request, template_name='registration/login.html',
          redirect_field_name=REDIRECT_FIELD_NAME,
          authentication_form=AuthenticationForm):
    """Displays the login form and handles the login action."""
    redirect_to = request.REQUEST.get(redirect_field_name, '')

    error = ''
    if request.method == "POST":
        form = authentication_form(data=request.POST)
        if form.is_valid():
            #Franchise-network e.g. Itz
            if utils.is_franchise(request):
                profile = utils.get_user_profile(form.get_user())
                if not profile:
                    error = "No profile found related to this email"
                elif not is_valid_franchise(profile):
                    error = "You do not have rights to access this interface. Please request your manager to get the rights."
                #else:
                #    perm = 'auth.access_franchise'
                #    if profile and not profile.user.has_perm(perm):
                #        error = 'You do not have rights to access Franchise interface. Please request your manager to get the rights OR Add permissions through admin to this user but dont make superuser.'
            elif utils.is_cc(request):
                #profile = utils.get_profile_by_email_or_phone(form.get_user())
                profile = utils.get_user_profile(form.get_user())
                perm = (request.client.type == 'store') and 'auth.access_store' or 'auth.access_callcenter'
                if profile and not profile.user.has_perm(perm):
                    error = 'You do not have rights to access this interface. Please request your manager to get the rights.'
            #Sellers Hub:
            elif utils.is_platform(request):
                profile = utils.get_user_profile(form.get_user())
                perm1 = 'users.access_ppd'
                perm2 = 'users.access_ifs'
                if profile and not (profile.user.has_perm(perm1) or profile.user.has_perm(perm2)):
                    error = 'You do not have rights to access this interface. Please request your manager to get the rights.'
            if not error:
                if utils.is_platform(request) and profile:
                    redirect_to = "/home"
                # Light security check -- make sure redirect_to isn't garbage.
                if not redirect_to or ' ' in redirect_to:
                    redirect_to = settings.LOGIN_REDIRECT_URL

                # Heavier security check -- redirects to http://example.com should
                # not be allowed, but things like /view/?param=http://example.com
                # should be allowed. This regex checks if there is a '//' *before* a
                # question mark.
                elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to):
                    redirect_to = settings.LOGIN_REDIRECT_URL
                # Okay, security checks complete. Log the user in.
                auth_login(request, form.get_user())
                if utils.is_platform(request):
                    profile = utils.get_user_profile(request.user)
                    sellers = profile.managed_accounts.filter(client = request.client.client)
                    request.session['all_sellers'] = sellers
                    request.session['seller'] = [sellers[0]]

                if request.session.test_cookie_worked():
                    request.session.delete_test_cookie()
                return HttpResponseRedirect(redirect_to)

    else:
        form = authentication_form(request)

    request.session.set_test_cookie()
    if Site._meta.installed:
        current_site = Site.objects.get_current()
    else:
        current_site = RequestSite(request)
    return render_to_response(template_name, {
        'error': error,
        'form': form,
        'redirect_field_name': redirect_to,
        'site': current_site,
        'site_name': current_site.name,
    }, context_instance=RequestContext(request))