示例#1
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST)
        card = request.POST.get('credit_card_number')
        month = request.POST.get('credit_card_expiration_month')
        year = request.POST.get('credit_card_expiration_year')
        cvv = request.POST.get('credit_card_cvc')
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        plan = UserSubscriptions.objects.get(user=request.user)
        amount = int(plan.plan.price)
        if form.is_valid():
            # stripe = get_gateway("stripe")
            braintree = get_gateway("braintree_payments")
            credit_card = CreditCard(first_name=first_name, last_name=last_name, month=month, year=year,
                             number=card,
                             verification_value=cvv)
            # resp = stripe.purchase(int(amount), credit_card)
            resp = braintree.purchase(10, credit_card)
            print "resposne", resp['status']
            payment = Payment()
            payment.user = request.user
            payment.payment_type = "0"
            payment.amount = amount
            payment.plan = plan.plan.title
            payment.date = datetime.date.today()
            payment.save()
            return redirect('/accounts/update-profile/')

        else:
            print "error", form.errors
        return render_to_response(self.template_name, {'form': form}, context_instance=RequestContext(request))
示例#2
0
def checkout(request):
    print "sdsdd"
    template_name = 'accounts/thank-you.html'
    site = Site.objects.get(pk=1)
    plan = UserSubscriptions.objects.get(user=request.user)
    payment = Payment()
    payment.user = request.user
    payment.payment_type = "1"
    payment.amount = plan.plan.price
    payment.plan = plan.plan.title
    payment.date = datetime.date.today()
    payment.save()
    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": plan.plan.price,
        "item_name": plan.plan.title,
        "invoice": int(randint(100,99999)),
        "notify_url": "https://%s"%(site.name) + reverse('custom_ipn'),
        "return_url": "http://192.168.43.148:8000/accounts/myplan/",
        "cancel_return": "http://%s"%(site.name) ,

    }
    # Create the instance.
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form}

    # form1 = CreditCardForm()
    # context = {"form": form,"course":course,"form1":form1,'name':name,'discount':discount,'message':message}
    return render(request, template_name, context)
    return render_to_response(template_name, context_instance=RequestContext(request))