@login_required(login_url='/accounts/login?next=payments/buy_now')
def buy_now(request, id):
    if (request.method == 'POST'):
        form = MakePaymentForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Charge.create(amount=int((total * 100)), currency='EUR', description=request.user.email, card=form.cleaned_data['stripe_id'])
            except stripe.error.CardError:
                messages.error(request, 'Your card was declined!')
            if customer.paid:
                messages.success(request, 'You have successfully paid')
                return redirect(reverse('all_services'))
            else:
                messages.error(request, 'Unable to take payment')
        else:
            messages.error(request, 'We were unable to take a payment with that card!')
    else:
        form = MakePaymentForm()
        services = get_object_or_404(Service, pk=id)
    args = {'form': form, 'publishable': settings.STRIPE_PUBLISHABLE, 'services': services}
    args.update(csrf(request))
    return render(request, 'pay.html', args)
@login_required(login_url='/accounts/login?next=payments/buy_now')
def buy_now(request, id):
    if (request.method == 'POST'):
        form = MakePaymentForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Charge.create(amount=int((total * 100)), currency='EUR', description=request.user.email, card=form.cleaned_data['stripe_id'])
            except stripe.error.CardError:
                messages.error(request, 'Your card was declined!')
            if customer.paid:
                messages.success(request, 'You have successfully paid')
                return redirect(reverse('all_services'))
            else:
                messages.error(request, 'Unable to take payment')
        else:
            messages.error(request, 'We were unable to take a payment with that card!')
    else:
        form = MakePaymentForm()
        services = get_object_or_404(Service, pk=id)
    args = {'form': form, 'publishable': settings.STRIPE_PUBLISHABLE, 'services': services}
    args.update(csrf(request))
    return render(request, 'pay.html', args)