def show_checkout(request, template_name='checkout/checkout.html'): if cart.is_empty(request): cart_url = urlresolvers.reverse('show_cart') return HttpResponseRedirect(cart_url) if request.method == 'POST': postdata = request.POST.copy() form = CheckoutForm(postdata) if form.is_valid(): response = checkout.process(request) if postdata.get('payment_method',False) == "credit_card": order_number = response.get('order_number',0) error_message = response.get('message','') if order_number: request.session['order_number'] = order_number receipt_url = urlresolvers.reverse('checkout_receipt') return HttpResponseRedirect(receipt_url) if postdata.get('payment_method',False) == "paypal": if response: order_number = response.get('order_number',0) error_message = response.get('message','') request.session['order_number'] = order_number approval_link = response.get('approval_link',False) return HttpResponseRedirect(approval_link[0].get('href',".")) else: pass else: error_message = 'Correct the errors below' else: if request.user.is_authenticated(): user_profile = profile.retrieve(request) form = CheckoutForm(instance=user_profile) else: form = CheckoutForm() page_title = 'Checkout' return render_to_response(template_name, locals(), context_instance=RequestContext(request))
def show_checkout(request , template_name = "checkout/checkout.html" ): if cart.is_empty(request): cart_url = urlresolvers.reverse('show_cart') return HttpResponseRedirect(cart_url) if request.method == 'POST': postdata = request.POST.copy() form = CheckoutForm(postdata) if form.is_valid(): response = process1(request) order_number = response.get('order_number',0) if order_number: request.session['order_number'] = order_number receipt_url = urlresolvers.reverse('payment') return HttpResponseRedirect(receipt_url) else: error_message = 'Correct the errors below' else: if request.user.is_authenticated(): user_profile = profile.retrieve(request) form = CheckoutForm(instance = user_profile) else: form = CheckoutForm() page_title = 'Checkout' return render_to_response(template_name , locals(),context_instance = RequestContext(request))
def show_checkout(request): if cart.is_empty(request): cart_url = urlresolvers.reverse('show_cart') return HttpResponseRedirect(cart_url) if request.method == 'POST': post_data = request.POST.copy() form = CheckoutForm(post_data) if form.is_valid(): response = checkout.process(request) order_number = response.get('order_number', 0) error_message = response.get('message', '') if order_number: request.session['order_number'] = order_number receipt_url = urlresolvers.reverse('checkout_receipt') return HttpResponseRedirect(receipt_url) else: return HttpResponse(error_message) else: error_message = 'Corrige los errores abajo' else: # si la peticion es get, tratar de vincular el form con los datos del perfil del usuario if request.user.is_authenticated(): user_profile = profile.get_profile(request) form = CheckoutForm(instance=user_profile, label_suffix="") else: form = CheckoutForm(label_suffix="") page_title = 'Checkout' small_text = u"Total en el carrito" big_text = "%.2fcuc" % OrderTotal.objects.get( id=request.session['ordertotalid']).total return render_to_response('checkout/checkout.html', locals(), context_instance=RequestContext(request))
def checkout(request): if request.method == 'POST': cart = Cart(request) form = CheckoutForm(request.POST) if form.is_valid(): try: if 'email' in request.POST: update_email(request.user, request.POST.get('email')) customer = get_customer(request.user) customer.update_card(request.POST.get("stripeToken")) product = cart.items()[0].product customer.subscribe(product.plan) cart.clear() return redirect("order_confirmation") except stripe.StripeError as e: try: error = e.args[0] except IndexError: error = "unknown error" return render_to_response('godjango_cart/checkout.html', { 'cart': Cart(request), 'publishable_key': settings.STRIPE_PUBLIC_KEY, 'error': error }, context_instance=RequestContext(request)) else: return render_to_response('godjango_cart/checkout.html', { 'cart': Cart(request), 'publishable_key': settings.STRIPE_PUBLIC_KEY, 'error': "Problem with your card please try again" }, context_instance=RequestContext(request)) else: return render_to_response('godjango_cart/checkout.html', { 'cart': Cart(request), 'publishable_key': settings.STRIPE_PUBLIC_KEY }, context_instance=RequestContext(request))
def checkout(request, adId): ad = get_object_or_404(Ad, pk=adId) if request.method == 'POST': form = CheckoutForm(request.POST) if form.is_valid(): total = 0 pricing = Pricing.objects.get(pk=form.cleaned_data["pricing"]) total += pricing.price pricing_options = [] for pk in form.cleaned_data["pricing_options"]: option = PricingOptions.objects.get(pk=pk) pricing_options.append(option) total += option.price # create Payment object payment = Payment.objects.create(ad=ad, pricing=pricing) for option in pricing_options: payment.options.add(option) payment.save() # send email when done # 1. render context to email template email_template = loader.get_template('adposting/email/posting.txt') context = Context({'ad': ad}) email_contents = email_template.render(context) # 2. send email send_mail(_('Your ad will be posted shortly.'), email_contents, settings.FROM_EMAIL, [ad.user.email], fail_silently=False) item_name = _('Your ad on ') + Site.objects.get_current().name paypal_values = {'amount': total, 'item_name': item_name, 'item_number': payment.pk, 'quantity': 1} if settings.DEBUG: paypal_form = PayPalPaymentsForm(initial=paypal_values).sandbox() else: paypal_form = PayPalPaymentsForm(initial=paypal_values).rander() return render_to_response('adposting/paypal.html', {'form': paypal_form}, context_instance=RequestContext(request)) else: form = CheckoutForm() return render_to_response('adposting/checkout.html', {'ad': ad, 'form': form}, context_instance=RequestContext(request))
def show_checkout(request, template_name='checkout/checkout.html'): """if cart.is_empty(request): cart_url = urlresolvers.reverse('show_cart') return HttpResponseRedirect(cart_url)""" if request.method == 'POST': postdata = request.POST.copy() form = CheckoutForm(postdata) if form.is_valid(): response = checkout.process(request) order_number = response.get('order_number',0) error_message = response.get('message','') if order_number: request.session['order_number'] = order_number receipt_url = urlresolvers.reverse('checkout_receipt') return HttpResponseRedirect(receipt_url) else: error_message = u'Correct the errors below' else: form = CheckoutForm() page_title = 'Checkout' return render_to_response(template_name, locals(), context_instance=RequestContext(request))
def show_checkout(request, template_name='checkout/checkout.html'): if cart.is_empty(request): cart_url = urlresolvers.reverse('show_cart') return HttpResponseRedirect(cart_url) if request.method == 'POST': postdata = request.POST.copy() form = CheckoutForm(postdata) if form.is_valid(): response = checkout.process(request) if postdata.get('payment_method', False) == "credit_card": order_number = response.get('order_number', 0) error_message = response.get('message', '') if order_number: request.session['order_number'] = order_number receipt_url = urlresolvers.reverse('checkout_receipt') return HttpResponseRedirect(receipt_url) if postdata.get('payment_method', False) == "paypal": if response: order_number = response.get('order_number', 0) error_message = response.get('message', '') request.session['order_number'] = order_number approval_link = response.get('approval_link', False) return HttpResponseRedirect(approval_link[0].get( 'href', ".")) else: pass else: error_message = 'Correct the errors below' else: if request.user.is_authenticated(): user_profile = profile.retrieve(request) form = CheckoutForm(instance=user_profile) else: form = CheckoutForm() page_title = 'Checkout' return render_to_response(template_name, locals(), context_instance=RequestContext(request))