Example #1
0
def index(request):
    context = {}
    if request.method == 'POST':
        form = forms.BasicPurchaseForm(request.POST)
        if form.is_valid():
            cart = HiiCart.objects.create()
            if form.cleaned_data['fancypants']:
                LineItem.objects.create(cart=cart, quantity=1, **forms.PANTS)
            if form.cleaned_data['monkeybutler']:
                LineItem.objects.create(cart=cart, quantity=1, **forms.MONKEYBUTLER)
            if form.cleaned_data['subscription']:
                RecurringLineItem.objects.create(cart=cart, quantity=1, **forms.SUBSCRIPTION)
            result = cart.submit(form.cleaned_data['gateway'])
            if result.type == 'url':
                return HttpResponseRedirect(result.url)
            else:
                return HttpResponseRedirect('/paypal_redirect')
    else:
        form = forms.BasicPurchaseForm()
    p = PrettyPrinter(width=40)
    context['paypal'] = (p.pformat(settings.HIICART_SETTINGS['PAYPAL']),
                         validate_gateway('paypal'))
    context['paypal2'] = (p.pformat(settings.HIICART_SETTINGS['PAYPAL2']),
                          validate_gateway('paypal2'))
    context['paypal_adaptive'] = (p.pformat(settings.HIICART_SETTINGS['PAYPAL_ADAPTIVE']),
                                  validate_gateway('paypal_adaptive'))
    context['google'] = (p.pformat(settings.HIICART_SETTINGS['GOOGLE']),
                         validate_gateway('google'))
    context['amazon'] = (p.pformat(settings.HIICART_SETTINGS['AMAZON']),
                         validate_gateway('amazon'))
    context['form'] = form
    return render_to_response('index.html', context)
Example #2
0
def index(request):
    context = {}
    if request.method == 'POST':
        form = forms.BasicPurchaseForm(request.POST)
        if form.is_valid():
            cart = HiiCart.objects.create()
            if form.cleaned_data['fancypants']:
                LineItem.objects.create(cart=cart, quantity=1, **forms.PANTS)
            if form.cleaned_data['monkeybutler']:
                LineItem.objects.create(cart=cart,
                                        quantity=1,
                                        **forms.MONKEYBUTLER)
            if form.cleaned_data['subscription']:
                RecurringLineItem.objects.create(cart=cart,
                                                 quantity=1,
                                                 **forms.SUBSCRIPTION)
            result = cart.submit(form.cleaned_data['gateway'])
            if result.type == 'url':
                return HttpResponseRedirect(result.url)
            else:
                return HttpResponseRedirect('/paypal_redirect')
    else:
        form = forms.BasicPurchaseForm()
    p = PrettyPrinter(width=40)
    context['paypal'] = (p.pformat(settings.HIICART_SETTINGS['PAYPAL']),
                         validate_gateway('paypal'))
    context['paypal2'] = (p.pformat(settings.HIICART_SETTINGS['PAYPAL2']),
                          validate_gateway('paypal2'))
    context['paypal_adaptive'] = (p.pformat(
        settings.HIICART_SETTINGS['PAYPAL_ADAPTIVE']),
                                  validate_gateway('paypal_adaptive'))
    context['google'] = (p.pformat(settings.HIICART_SETTINGS['GOOGLE']),
                         validate_gateway('google'))
    context['amazon'] = (p.pformat(settings.HIICART_SETTINGS['AMAZON']),
                         validate_gateway('amazon'))
    context['form'] = form
    return render_to_response('index.html', context)
Example #3
0
 def clean_gateway(self):
     if validate_gateway(self.cleaned_data['gateway']) != True:
         raise forms.ValidationError('Gateway not properly set up.')
     return self.cleaned_data['gateway']
Example #4
0
 def clean_gateway(self):
     if validate_gateway(self.cleaned_data['gateway']) != True:
         raise forms.ValidationError('Gateway not properly set up.')
     return self.cleaned_data['gateway']