示例#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.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 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
			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
示例#2
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
示例#3
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
示例#4
0
def process_order(request):
    """
    Handle the callback from pesapal
    """


    tracking_id = request.GET.get('pesapal_transaction_tracking_id', '')
    reference = request.GET.get('pesapal_merchant_reference', '')
    #save this data to a model
    errors = ''
    msg = ''
    if tracking_id and reference:

        params = {
                    'pesapal_merchant_reference': reference,
                    'pesapal_transaction_tracking_id': tracking_id
                 }

        client = pesapal.PesaPal('mLrA2/J+vN3/BuB7+UNRM8CWO1ed3hh8','FT5//bhEvq5VejY0b4aeouB3jB0=',True)
        pesapal_request = client.queryPaymentStatus(params)

        url = pesapal_request.to_url()
        print url
        pesapal_response = requests.get(url)
        pesapal_response_data = pesapal_response.text
        print pesapal_response_data
        pesapal_status = pesapal_response_data.split('=')[1]
        if pesapal_status == 'COMPLETED':
            msg = 'Transaction was successful'
        else:
            msg = 'Transaction status is %s'%(pesapal_status)
        p_ref = Pesapal(tracking_id=tracking_id, reference=reference, status=pesapal_status)

        order_number = request.session.get('order_number','')
        if order_number:
            order = Order.objects.filter(id = order_number)[0]
            order_items = OrderItem.objects.filter(order =order)
            del request.session['order_number']
        else:
            cart_url = urlresolvers.reverse('show_cart')
            return HttpResponseRedirect(cart_url)

        p_ref.save()
        cart.empty_cart(request)
    else:

        errors ='You broke our servers :-('

    return render_to_response('checkout/receipt.html',locals(), context_instance=RequestContext(request))
示例#5
0
def create_order(request):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    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 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.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.fill(request)
    # mail the managers
    mail_manager_subject = '{0} has been placed!'.format(order)
    mail_manager_message = '{0} has been placed by {1}.\n\nClick here: {2}'.format(
        order, order.user if order.user else 'anonymous',
        request.build_absolute_uri(
            reverse('admin:checkout_order_change', args=(order.pk, ))))
    mail_managers(mail_manager_subject, mail_manager_message)
    # mail the customer
    if order.email:
        # FIXME: someday make templates for these emails
        mail_customer_subject = 'Thank you for placing {0}!'.format(order.name)
        mail_customer_message = '{0} was placed by you.  Click here for more details: {1}\n\nThank you for your order!\n\n{2}'.format(
            order.name, request.build_absolute_uri(order.get_absolute_url()),
            settings.SITE_NAME)
        send_mail(mail_customer_subject, mail_customer_message,
                  settings.DEFAULT_FROM_EMAIL, [order.email])
    # return the new order object
    return order
示例#6
0
文件: views.py 项目: mathuin/pyment
def show_cart(request, template_name="cart/cart.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        # someday consider a modal dialog for this
        if postdata['submit'] == 'Remove All':
            cart.empty_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
        if postdata['submit'] == 'Continue Shopping':
            return_url = cart.get_return_url(request)
            return HttpResponseRedirect(return_url)

    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    return render(request, template_name, locals())
示例#7
0
文件: views.py 项目: mathuin/pyment
def show_cart(request, template_name="cart/cart.html"):
    if request.method == "POST":
        postdata = request.POST.copy()
        if postdata["submit"] == "Remove":
            cart.remove_from_cart(request)
        # someday consider a modal dialog for this
        if postdata["submit"] == "Remove All":
            cart.empty_cart(request)
        if postdata["submit"] == "Update":
            cart.update_cart(request)
        if postdata["submit"] == "Checkout":
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
        if postdata["submit"] == "Continue Shopping":
            return_url = cart.get_return_url(request)
            return HttpResponseRedirect(return_url)

    cart_items = cart.get_cart_items(request)
    page_title = "Shopping Cart"
    return render(request, template_name, locals())
示例#8
0
def show_cart(request, template_name="cart/cart.djhtml"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        # someday consider a modal dialog for this
        if postdata['submit'] == 'Remove All':
            cart.empty_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
        if postdata['submit'] == 'Continue Shopping':
            return_url = cart.get_return_url(request)
            return HttpResponseRedirect(return_url)

    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    return render(request, template_name, locals())
示例#9
0
def create_order(request, transaction_id):
  """ if the POST to the payment gateway successfully billed the customer, create a new order
  containing each CartItem instance, save the order with the transaction ID from the gateway,
  and empty the shopping cart

  """
  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:
    """ if the order save succeeded """
    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, clear the cart
    cart.empty_cart(request)

    # save profile info for future orders
    if request.user.is_authenticated():
      from ecomstore.accounts import profile
      profile.set(request)

  return order
示例#10
0
def create_order(request, transaction_id):
    """ if the POST to the payment gateway successfully billed the customer,
    create a new order containing each CartItem instance, save the order with
    the transaction ID from the gateway, and empty the shopping cart
    """
    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 a User is authenticated, associate the order to their account
    if request.user.is_authenticated:
        order.user = request.user
    order.status = Order.SUBMITTED
    order.save()

    if order.pk:
        """ if the order save succeeded """
        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, clear the cart
        cart.empty_cart(request)

        # save profile info for future orders
        if request.user.is_authenticated:
            from accounts import profile
            profile.set(request)

    return order
示例#11
0
def create_order(request):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    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 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.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.fill(request)
    # mail the managers
    mail_manager_subject = '{0} has been placed!'.format(order)
    mail_manager_message = '{0} has been placed by {1}.\n\nClick here: {2}'.format(order, order.user if order.user else 'anonymous', request.build_absolute_uri(reverse('admin:checkout_order_change', args=(order.pk,))))
    mail_managers(mail_manager_subject, mail_manager_message)
    # mail the customer
    if order.email:
        # FIXME: someday make templates for these emails
        mail_customer_subject = 'Thank you for placing {0}!'.format(order.name)
        mail_customer_message = '{0} was placed by you.  Click here for more details: {1}\n\nThank you for your order!\n\n{2}'.format(order.name, request.build_absolute_uri(order.get_absolute_url()), settings.SITE_NAME)
        send_mail(mail_customer_subject, mail_customer_message, settings.DEFAULT_FROM_EMAIL, [order.email])
    # return the new order object
    return order
示例#12
0
def create_order(request, transaction_id):
    postdata = request.POST.copy()
    order = Order()
    checkout_form = MpesaCheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    order.billing_name = postdata['shipping_name']
    order.billing_address_1 = postdata['shipping_address_1']
    order.billing_address_2 = postdata['shipping_address_2']
    order.billing_city = postdata['shipping_city']
    order.billing_zip = postdata['shipping_zip']
    order.billing_country = postdata['shipping_country']
    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 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:
            profile.set(request)
    # return the new order object
    return order
示例#13
0
文件: views.py 项目: deusesx/VDom
def getOrder(request, type):
    categories = Category.objects.filter(is_active=True)
    brands = Brand.objects.filter(is_active=True)
    if request.method == 'POST':
        postdata = request.POST.copy()
        try:
            address = postdata.get('address')
        except:
            address = ' '
        name = postdata.get('namefield')
        phone = postdata.get('phone')
        delivery = postdata.get('delivery')
        payment = postdata.get('payment')

        # post form sends a string value
        if delivery == 'True':
            delivery = True
        else:
            delivery = False

        if payment == 'True':
            payment = True
        else:
            payment = False

        p = 0
        if int(type) == 0:
            total = cart.cart_subtotal(request)
        else:
            p = Product.objects.get(id=type)
            p.quantity -= 1
            p.save()
            total = p.price

        newOrder = Order(name=name, phone=phone, address=address, total=total, is_card_payment=payment,
                         is_delivery=delivery)
        newOrder.save()

        if int(type) == 0:
            oCart = cart.get_cart_items(request)
            for ci in oCart:
                oi = OrderItem(product=ci.product, order=newOrder, quantity=ci.quantity)
                oi.save()
                ci.product.quantity -= ci.quantity
                ci.product.save()
            cart.empty_cart(request)

        else:
            oi = OrderItem(product=p, order=newOrder, quantity=1)
            oi.save()

        context = {
            'id': newOrder.id,
            'opened': newOrder.opened_at,
            'success': True,
            'cart_distinct': 0,
            'categories': categories,
            'brands': brands,
        }

    else:
        cart_distinct = cart.cart_distinct_item_count(request)
        context = {
            'success': False,
            'cart_distinct': cart_distinct,
            'categories': categories,
            'brands': brands,
        }

    return HttpResponse(render_to_response('checkout-success.html', context, context_instance=RequestContext(request)))
示例#14
0
def create_order(request, transaction_id):
    postdata = request.POST.copy()
    CART_ID_SESSION_KEY = cart.CART_ID_SESSION_KEY
    pending = PendingMpesa.objects.filter(
        cart=request.session[CART_ID_SESSION_KEY])
    if request.user.is_authenticated:
        user_profile = profile.retrieve(request)
    else:
        user_profile = ''
    if pending.count(
    ) > 0 and request.user.is_authenticated and not request.method == 'POST' and user_profile.shipping_name != '':
        user_profile = profile.retrieve(request)
        print(user_profile.shipping_name)
        order = Order()
        # checkout_form = MpesaCheckoutForm(instance=order)
        # order = checkout_form.save(commit=False)
        order.shipping_name = user_profile.shipping_name
        order.shipping_address_1 = user_profile.shipping_address_1
        order.shipping_address_2 = user_profile.shipping_address_2
        order.shipping_city = user_profile.shipping_city
        order.shipping_zip = user_profile.shipping_zip
        order.shipping_country = user_profile.shipping_country
        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()
    else:
        order = Order()
        checkout_form = MpesaCheckoutForm(request.POST, instance=order)
        order = checkout_form.save(commit=False)
        order.billing_name = postdata['shipping_name']
        order.billing_address_1 = postdata['shipping_address_1']
        order.billing_address_2 = postdata['shipping_address_2']
        order.billing_city = postdata['shipping_city']
        order.billing_zip = postdata['shipping_zip']
        order.billing_country = postdata['shipping_country']
        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 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 and not pending_checker(request) == 0:
            profile.set(request)
    # return the new order object
    return order