Beispiel #1
0
    def get(self, request, *args, **kwargs):

        if 'country' in request.GET:
            country = request.GET['country']
        else :
            ip = get_ip(request)
            if ip == '127.0.0.1':
                country = 'all'
            else:
                country = get_country_code_by_ip(ip)
        methods = get_payment_methods(country, 500)
        result = {'country': country, 'results': methods}
        response = Response(result, status=status.HTTP_200_OK)
        return response
Beispiel #2
0
    def get(self, request, *args, **kwargs):
        country = request.GET.get('country')

        if not country and not getattr(settings, 'SKIP_IP_LOOKUP', False):
            ip = get_ip(request)
            country = get_country_code_by_ip(ip)

        # Payment methods are loaded from the settings so they
        # aren't translated at run time. We need to do it manually
        methods = get_payment_methods(country=country,
                                      user=request.user,
                                      currency=request.GET.get('currency'))

        for method in methods:
            method['name'] = _(method['name'])

        result = {'country': country, 'results': methods}
        response = Response(result, status=status.HTTP_200_OK)
        return response
Beispiel #3
0
    def get_user_data(self):
        user = self.order_payment.order.user
        ip_address = get_client_ip()

        if user:
            user_data = {
                'id': user.id,
                'first_name': user.first_name or 'Unknown',
                'last_name': user.last_name or 'Unknown',
                'email': user.email,
                'ip_address': ip_address,
            }
        else:
            user_data = {
                'id': 1,
                'first_name': 'Nomen',
                'last_name': 'Nescio',
                'email': settings.CONTACT_EMAIL,
                'ip_address': ip_address
            }


        if user and hasattr(user, 'address'):

            street = user.address.line1.split(' ')
            if street[-1] and any(char.isdigit() for char in street[-1]):
                user_data['house_number'] = street.pop(-1)
                user_data['street'] = ' '.join(street)
            else:
                user_data['house_number'] = 'Unknown'
                if user.address.line1:
                    user_data['street'] = user.address.line1
                else:
                    user_data['street'] = 'Unknown'

            if user.address.postal_code:
                user_data['postal_code'] = user.address.postal_code
            else:
                user_data['postal_code'] = 'Unknown'
            if user.address.city:
                user_data['city'] = user.address.city
            else:
                user_data['city'] = 'Unknown'
            if user.address.country and hasattr(user.address.country, 'alpha2_code'):
                user_data['country'] = user.address.country.alpha2_code
            elif get_country_code_by_ip(ip_address):
                user_data['country'] = get_country_code_by_ip(ip_address)
            else:
                user_data['country'] = 'NL'
        else:
            user_data['postal_code'] = 'Unknown'
            user_data['street'] = 'Unknown'
            user_data['city'] = 'Unknown'
            country = get_country_code_by_ip(ip_address)
            if country:
                user_data['country'] = country
            else:
                user_data['country'] = 'NL'
            user_data['house_number'] = 'Unknown'

        if not user_data['country']:
            user_data['country'] = 'NL'

        user_data['company'] = ''
        user_data['kvk_number'] = ''
        user_data['vat_number'] = ''
        user_data['house_number_addition'] = ''
        user_data['state'] = ''
        return user_data