예제 #1
0
def edit(request):
    uid = request.session.get('user')

    if uid is None:
        return HttpResponseRedirect('/')

    user = User.objects.get(pk=uid)

    if request.method == 'POST':
        form = CardForm(request.POST)
        if form.is_valid():

            customer = stripe.Customer.retrieve(user.stripe_id)
            customer.card = form.cleaned_data['stripe_token']
            customer.save()

            user.last_4_digits = form.cleaned_data['last_4_digits']
            user.stripe_id = customer.id
            user.save()

            return HttpResponseRedirect('/')

    else:
        form = CardForm()

    return render_to_response(
        'edit.html', {
            'form': form,
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'months': range(1, 12),
            'years': range(2011, 2036)
        },
        context_instance=RequestContext(request))
예제 #2
0
def edit(request):
    uid = request.session.get('user')

    if uid is None:
        return HttpResponseRedirect('/')

    user = User.objects.get(pk=uid)

    if request.method == 'POST':
        form = CardForm(request.POST)
        if form.is_valid():
            customer = stripe.Customer.retrieve(user.stripe_id)
            customer.card = form.cleaned_data['stripe_token']
            customer.save()

            user.last_4_digits = form.cleaned_data['last_4_digits']
            user.stripe_id = customer.id
            user.save()

            return HttpResponseRedirect('/')
    else:
        form = CardForm()

    return render_to_response('edit.html', {
        'form': form,
        'publishable': settings.STRIPE_PUBLISHABLE,
        'soon': soon(),
        'months': range(1, 12),
        'years': range(2016, 2036)
    },
                              context_instance=RequestContext(request))
def select_payment(request, auction_id):
    session_card = 'auction_%s_payment' % auction_id
    # session_shipping = 'auction_%s_shipping' % auction_id

    member = request.user.get_profile()
    auction = get_object_or_404(request.user.items_won.filter(order=None), id=auction_id)
    cards = request.user.card_set.filter(deleted=False)

    id = request.POST.get('card')
    # action = request.POST.get('action')
    card = None
    if 'select' in request.POST:
        card = get_object_or_404(Card, id=id, user=request.user, deleted=False)
        request.session[session_card] = card.id
        return HttpResponseRedirect(reverse('checkout_review', args=[auction.id]))

    if request.method == 'POST':
        form = CardForm(request.POST)
        if form.is_valid():
            # data = form.cleaned_data
            card = form.save(commit=False)
            card.use = request.user
            card.save()
            request.session[session_card] = card.id
            cards = request.user.card_set.filter(deleted=False)
            form = CardForm()
    else:
        form = CardForm()

    return {
        'auction':auction,
        'form':form,
        'cards':cards,
        'card':card
    }
예제 #4
0
def edit_profile(request, id):
    profile = get_object_or_404(Profile, pk=id)
    
    if request.user.profile.id != profile.id:
        message="You are not authorised to view this page."
        return render(request, "home/custom_error.html", {"message":message})

    else:
        if request.method == "POST":
            
            profile_form = ProfileForm(request.POST, request.FILES, instance=profile)
            card_form = CardForm(request.POST)
            if profile_form.is_valid() and card_form.is_valid():
                profile = profile_form.save(commit=False)
                profile.user = request.user
                
                token=card_form.cleaned_data['stripe_id']
                customer = stripe.Customer.create(
                    source=token,
                    email=request.user.email,
                    )
                profile.stripe_id = customer.id
                profile.save()
                return redirect("user_profile")
            else:
                return render(request, "accounts/profile_form.html", {"profile_form": profile_form, "card_form": card_form, "publishable": settings.STRIPE_PUBLISHABLE_KEY})
                
                
        else:
            profile_form = ProfileForm(instance=profile)
            card_form = CardForm()
            return render(request, "accounts/profile_form.html", {"profile_form": profile_form, "card_form": card_form, "publishable": settings.STRIPE_PUBLISHABLE_KEY})
예제 #5
0
def add_profile(request):
    redirect_to = request.GET.get('next', '/')
    if request.method == "POST":
        profile_form = ProfileForm(request.POST, request.FILES)
        card_form = CardForm(request.POST)
        
        if profile_form.is_valid() and card_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.user = request.user
            
            token=card_form.cleaned_data['stripe_id']
            customer = stripe.Customer.create(
                source=token,
                email=request.user.email,
                )
            profile.stripe_id = customer.id
            profile.save()
            return redirect(redirect_to)
            
        else:
            return render(request, "accounts/profile_form.html", {"profile_form": profile_form, "card_form": card_form, "publishable": settings.STRIPE_PUBLISHABLE_KEY})
            
    else:
        card_form = CardForm()
        profile_form=ProfileForm()
        return render(request, "accounts/profile_form.html", {"profile_form": profile_form, "card_form": card_form, "publishable": settings.STRIPE_PUBLISHABLE_KEY})
예제 #6
0
def edit(request):
    uid = request.session.get("user")

    if uid is None:
        return HttpResponseRedirect("/")

    user = User.objects.get(pk=uid)

    if request.method == "POST":
        form = CardForm(request.POST)
        if form.is_valid():
            customer = stripe.Customer.retrieve(user.stripe_id)
            customer.card = form.cleaned_data["stripe_token"]
            customer.save()

            user.last_4_digits = form.cleaned_data["last_4_digits"]
            user.stripe_id = customer.id
            user.save()

            return HttpResponseRedirect("/")

    else:
        form = CardForm()

    return render_to_response(
        "payments/edit.html",
        {
            "form": form,
            "publishable": settings.STRIPE_PUBLISHABLE,
            "soon": soon(),
            "months": list(range(1, 12)),
            "years": list(range(2011, 2036)),
        },
        context_instance=RequestContext(request),
    )
def manage_payments(request, redirect_url='profile_account'):
    objects = request.user.card_set.filter(deleted=False)
    form = CardForm(request.POST or None)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.user = request.user
        instance.save()
        return HttpResponseRedirect(reverse('profile_account'))

    return {
        'form':form,
        'cards':objects,
    }