Exemplo n.º 1
0
def create_order(request ,transaction_id):
    order = Order()
    checkout_form = CheckoutForm(request.POST , instance=order)
    order = checkout_form.save(commit=False)
    order.transaction_id = transaction_id
    order.user = None
    if request.user.is_authenticated():
        order.user = request.user
    order.status = Order.SUBMITTED
    order.save()

    # if the order saved succeeded
    if order.pk:

        cart_items =cart.get_cart_items(request)
        for ci in cart_items:
            # create order item for each cart item
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price() # now using @property
            oi.product = ci.product
            oi.save()
        # all set empty cart
        cart.deduct_quantity(request)


    # save the profile for future orders
    if request.user.is_authenticated():
        from accounts import profile
        profile.set(request)
    # return the new order object
    return order
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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)) 
Exemplo n.º 4
0
def create_order(request, transaction_id):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance = order)
    order = checkout_form.save(commit = False)
    order.transaction_id = transaction_id
    order.ip_address = request.META.get('REMOTE_ADDR')
    if request.user.is_authenticated():
        order.user = request.user
    order.status = Order.SUBMITTED
    order.save()
    # if the order save succeeded
    if order.pk:
        cart_items = shoppingcart.get_cart_items(request)
        for ci in cart_items:
            # create order item for each cart item
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price
            oi.product = ci.product
            oi.save()
        # all set, empty card
        shoppingcart.empty_cart(request)
        # save profile info for future orders
        if request.user.is_authenticated():
            from accounts import profile
            profile.set(request)
    # return the new order object
    return order
Exemplo n.º 5
0
def checkout():
    if "email" not in session:
        return redirect(url_for("signin"))
    user = User.query.filter_by(email=session["email"]).first()
    #print(user)
    if user is None:
        return redirect(url_for("signin"))
    elif user.email == "*****@*****.**":
        form = CheckoutForm()
        if request.method == "POST":
            if form.validate() == False:
                flash("All fields are required")
                return render_template("checkout.html", form=form)
            else:
                suits = Suits.query.filter(
                    Suits.suit_id == form.suiteId.data.upper()).first()
                print suits
                if suits != None:
                    suits.available = False
                    db.session.commit()

                return render_template("checkout.html", success=True)
        elif request.method == "GET":
            return render_template("checkout.html", form=form)
    else:
        return render_template("home.html")
Exemplo n.º 6
0
def create_order(request,transaction_id):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    order.transaction_id = transaction_id 
    order.ip_address = request.META.get('REMOTE_ADDR')
    order.status = Order.SUBMITTED
    order.user = None
    if request.user.is_authenticated():
        order.user = request.user 
    order.save()
    
    # if the order save succeeded 
    if order.pk:
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            # create order item for each cart item
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price() # now using @property
            oi.product = ci.product
            oi.save()
        # all set, empty cart
        cart.empty_cart(request)
        # save profile info for future orders
    if request.user.is_authenticated():
        from accounts import profile
        profile.set(request)
    # return the new order object
    return order    
     
Exemplo n.º 7
0
def create_order(request,transaction_id):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    order.transaction_id = transaction_id
    order.ip_address = request.META.get('REMOTE_ADDR')
    order.user = None
    if request.user.is_authenticated():
        order.user = request.user
    order.status = Order.SUBMITTED
    order.save()
    
    if order.pk:
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price
            oi.product = ci.product
            oi.save()
        cart.empty_cart(request)
        if request.user.is_authenticated():
            from accounts import profile
            profile.set(request)
    return order
    
Exemplo n.º 8
0
def create_order(request, order_total, transaction_id):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    order.transaction_id = transaction_id
    order.ip_address = request.META.get('REMOTE_ADDR')
    order.status = Order.SUBMITTED
    order.user = None
    # order.order_total = order_total
    order_total.purchased = True

    if request.user.is_authenticated():
        order.user = request.user
        from accounts import profile

        user_profile = profile.get_profile(request)
        # verificar si campos requeridos estan vacios, si lo estan crear un user_profile para este usuario desde
        # aqui, asi no tendria q escribirlo en el form UserProfileForm
        if not user_profile.email or not user_profile.shipping_name or user_profile.shipping_city == 0:
            profile.set_profile(request)
    order.save()
    order_total.order = order
    order_total.save()
    # if the order save succeeded
    if order.pk:
        # verificar si el usuario tuvo la promo4, para eliminarla
        try:
            promo4_id = request.session['promo4_id']
            del request.session['promo4_id']
            promo4 = Promo4.objects.get(id=promo4_id)
            promo4.active = False
            promo4.save()
        except KeyError:
            pass
        try:  # eliminar el codigo de promoion para el usuario
            promo_id = request.session['promo3_id']
            del request.session['promo3_id']
            Promo3.objects.get(id=promo_id).delete()
        except KeyError:
            pass
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            # create order item for each cart item
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price()  # now using @property
            oi.product = ci.product
            # disminuir del almacen la cant disponible para este prod
            ci.product.quantity -= ci.quantity
            ci.product.save()
            oi.save()
            # all set, empty cart
        cart.empty_cart(request)
        # utils.send_email("Leoshop", "Gracias por preferirnos", user_profile.email)
    # return the new order object
    return order
    def viewProduct(self):
        sku_code = self.code_entry.text()

        product = self.session.query(Product).filter(
            Product.sku_code == sku_code).first()

        if not product:

            QMessageBox.warning(
                self, 'خطأ فى الكود',
                '''لم يتم العثور على منتج مرتبط بهذا الكود
                          ،تأكد من صحة الكود وحاول مرة اخرى
                ''')
            return

        check_out_dialog = CheckoutForm(self.session, product)
        check_out_dialog.exec_()
Exemplo n.º 10
0
def checkout():
    current_order = Order.query.filter_by(user_id=current_user.id).filter_by(
        finished=0).first()
    if current_order is not None:
        return redirect(url_for('confirm_checkout'))
    else:
        items = session.get('cart')
        form = CheckoutForm()
        id_s = []
        count_s = []
        goods = []
        totalprice = 0
        if items is not None or []:
            for x in items:
                id_s += x.keys()
                count_s += x.values()
            i = 0
            for x in id_s:
                goods.append(Goods.query.filter_by(id=id_s[i]).first())
                i = i + 1
            i = 0
            for g in goods:
                g.__dict__['count'] = count_s[i]
                i = i + 1
                totalprice += g.price * g.count
        else:
            return render_template('cart/emptycart.html')
        if form.validate_on_submit():
            address = form.city.data + " " + form.address.data
            order = Order(user_id=current_user.id,
                          address=address,
                          fname=form.firstname.data,
                          lname=form.lastname.data,
                          payment=form.payment.data,
                          phone=form.phone.data,
                          finished=0,
                          totalprice=totalprice)
            db.session.add(order)
            db.session.commit()
            return redirect(url_for('confirm_checkout'))
    return render_template('cart/checkout.html',
                           goods=goods,
                           count=count_s,
                           totalprice=totalprice,
                           form=form)
Exemplo n.º 11
0
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))
Exemplo n.º 12
0
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))
Exemplo n.º 13
0
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))
Exemplo n.º 14
0
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))
Exemplo n.º 15
0
def checkout():
    if 'email' not in session:
        return redirect(url_for('signin'))

    user = User.query.filter_by(email=session['email']).first()

    if user is None:
        return redirect(url_for('signin'))

    form = CheckoutForm()

    courses = Course.query.filter_by(ins_id=user.uid).all()
    courseChoices = []
    for course in courses:
        courseChoices.append((course.code, course.code + '-' + course.cname))
    form.course.choices = courseChoices

    if request.method == 'POST':
        course_code = form.course.data
        course_name = Course.query.filter_by(code=course_code).first().cname
        context = buildqrjson(False, form.time.data, course_code, course_name)
        return render_template('qr.html', qrStr=context)
    return render_template('checkout.html', form=form)
Exemplo n.º 16
0
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))