Exemplo n.º 1
0
def fake_checkout(request, order_id):

    order = get_object_or_404(Order, pk=order_id)

    # DOUBLE CHECK THE ORDER HAS 100% DISCOUNT
    # if not order.discount or order.discount.discount_value < 1:
    #    return HttpResponseRedirect(reverse('order_confirm'))

    # ORGANISE THE ORDER AS IF IT HAD BEEN PAID LIKE NORMAL
    order.status = Order.STATUS_PAID
    order.date_paid = datetime.now()
    order.notes = "100% discount order, not paid via paypal."
    order.save()

    from emailer.views import _payment_success

    _payment_success(order)

    # NOW CREATE A CUSTOMER PACKAGE
    from logistics.views import _create_customer_package

    _create_customer_package(order)

    from shop.utils import _empty_basket

    _empty_basket(request)

    return HttpResponseRedirect(reverse("order_complete"))
Exemplo n.º 2
0
def show_me_the_money(sender, **kwargs):
    ipn_obj = sender
    order = get_object_or_404(Order, invoice_id=ipn_obj.invoice)

    # PREVENTS DUPLICATES
    if order.status == Order.STATUS_PAID or order.status == Order.STATUS_PAYMENT_FLAGGED:
        return

    # UPDATE THE ORDER DETAILS
    order.status = Order.STATUS_PAID
    order.date_paid = ipn_obj.payment_date
    order.is_paid = True
    order.save()

    # IF THERE WAS A SINGLE USE DISCOUNT, UPDATE IT
    if order.discount:
        if order.discount.single_use == True:
            order.discount.is_active = False
            order.discount.save()

    # SEND THE EMAILS
    if ipn_obj.flag == True:
        from emailer.views import _payment_flagged
        _payment_flagged(order)
    else:
        from emailer.views import _payment_success
        _payment_success(order)

    # NOW CREATE A CUSTOMER PACKAGE
    from logistics.views import _create_customer_package
    _create_customer_package(order)
Exemplo n.º 3
0
def fake_checkout(request, order_id):

    order = get_object_or_404(Order, pk=order_id)

    # DOUBLE CHECK THE ORDER HAS 100% DISCOUNT
    #if not order.discount or order.discount.discount_value < 1:
    #    return HttpResponseRedirect(reverse('order_confirm'))

    # ORGANISE THE ORDER AS IF IT HAD BEEN PAID LIKE NORMAL
    order.status = Order.STATUS_PAID
    order.date_paid = datetime.now()
    order.notes = '100% discount order, not paid via paypal.'
    order.save()

    from emailer.views import _payment_success
    _payment_success(order)

    # NOW CREATE A CUSTOMER PACKAGE
    from logistics.views import _create_customer_package
    _create_customer_package(order)

    from shop.utils import _empty_basket
    _empty_basket(request)

    return HttpResponseRedirect(reverse('order_complete'))
Exemplo n.º 4
0
def show_me_the_money(sender, **kwargs):
    ipn_obj = sender
    order = get_object_or_404(Order, invoice_id=ipn_obj.invoice)
    
    # PREVENTS DUPLICATES
    if order.status == Order.STATUS_PAID or order.status == Order.STATUS_PAYMENT_FLAGGED:
        return
    
    # UPDATE THE ORDER DETAILS
    order.status = Order.STATUS_PAID
    order.date_paid = ipn_obj.payment_date
    order.is_paid = True
    order.save()
    
    
    # IF THERE WAS A SINGLE USE DISCOUNT, UPDATE IT
    if order.discount:
        if order.discount.single_use == True:
            order.discount.is_active = False
            order.discount.save()
    
    # SEND THE EMAILS
    if ipn_obj.flag == True:
        from emailer.views import _payment_flagged
        _payment_flagged(order)
    else:
        from emailer.views import _payment_success 
        _payment_success(order)
        
            
    # NOW CREATE A CUSTOMER PACKAGE
    from logistics.views import _create_customer_package
    _create_customer_package(order)
Exemplo n.º 5
0
def order_confirm(request):

    try:
        order = get_object_or_404(Order, id=request.session['ORDER_ID'])
    except:
        problem = _(
            "You don't have any items in your basket, so you can't process an order!"
        )
        return _render(request, 'shop/order-problem.html', locals())

    shopper = order.owner
    order.basket = Basket.objects.get(id=request.session['BASKET_ID'])
    order.save()

    basket = _get_basket_value(request)

    amount_in_cents = int(float(basket['total_price']) *
                          100)  # for stupid stripe...

    # THIS HANDLES STRIPE
    if request.method == 'POST':

        stripe.api_key = settings.STRIPE_SECRET_KEY
        token = request.POST['stripeToken']

        try:
            charge = stripe.Charge.create(
                amount=amount_in_cents,
                currency=basket['currency'].code.lower(),
                card=token,
                description=order.owner.user.email)

            # UPDATE THE ORDER DETAILS
            order.status = Order.STATUS_PAID
            order.date_paid = datetime.now()
            order.save()

            # IF THERE WAS A SINGLE USE DISCOUNT, UPDATE IT
            if order.discount:
                if order.discount.single_use == True:
                    order.discount.is_active = False
                    order.discount.save()

            from emailer.views import _payment_success
            _payment_success(order)

            # NOW CREATE A CUSTOMER PACKAGE
            from logistics.views import _create_customer_package
            _create_customer_package(order)

            return HttpResponseRedirect(
                reverse('order_complete', args=[order.hashkey]))
        except stripe.CardError, e:

            # do we need to do something here like show an error message?!

            pass
Exemplo n.º 6
0
def order_confirm(request):

    try:
        order = get_object_or_404(Order, id=request.session["ORDER_ID"])
    except:
        problem = _("You don't have any items in your basket, so you can't process an order!")
        return _render(request, "shop/order-problem.html", locals())

    shopper = order.owner
    order.basket = Basket.objects.get(id=request.session["BASKET_ID"])
    order.save()

    basket = _get_basket_value(request)

    amount_in_cents = int(float(basket["total_price"]) * 100)  # for stupid stripe...

    # THIS HANDLES STRIPE
    if request.method == "POST":

        stripe.api_key = settings.STRIPE_SECRET_KEY
        token = request.POST["stripeToken"]

        try:
            charge = stripe.Charge.create(
                amount=amount_in_cents,
                currency=basket["currency"].code.lower(),
                card=token,
                description=order.owner.user.email,
            )

            # UPDATE THE ORDER DETAILS
            order.status = Order.STATUS_PAID
            order.date_paid = datetime.now()
            order.save()

            # IF THERE WAS A SINGLE USE DISCOUNT, UPDATE IT
            if order.discount:
                if order.discount.single_use == True:
                    order.discount.is_active = False
                    order.discount.save()

            from emailer.views import _payment_success

            _payment_success(order)

            # NOW CREATE A CUSTOMER PACKAGE
            from logistics.views import _create_customer_package

            _create_customer_package(order)

            return HttpResponseRedirect(reverse("order_complete", args=[order.hashkey]))
        except stripe.CardError, e:

            # do we need to do something here like show an error message?!

            pass
Exemplo n.º 7
0
    def test_monthly_orders(self):
        shopper = Shopper.objects.all()[0]
        address = Address.objects.all()[0]
        basket = Basket.objects.all()[0]
        up = UniqueProduct.objects.get(parent_product__slug='iron-buddha',
                                       is_active=True,
                                       weight=100,
                                       currency__code='GBP')
        basket_item = BasketItem.objects.create(item=up,
                                                quantity=2,
                                                basket=basket,
                                                monthly_order=True,
                                                months=12)

        order = Order.objects.create(
            date_paid=datetime.now(),
            date_confirmed=datetime.now(),
            address=address,
            owner=shopper,
            invoice_id='FAKE123',
            status=Order.STATUS_PAID,
        )

        order.items.add(basket_item)
        order.save()

        # FIRST - create a customer package
        _create_customer_package(order)

        # CHECK - WE SHOULD HAVE 12 SEPARATE PACKAGES
        months = 12
        customer_packages = CustomerPackage.objects.filter(order=order).count()
        self.assertEqual(customer_packages, months)

        # CHECK - WE SHOULD HAVE 11 PACKAGES ARRIVING AFTER THIS MONTH
        from logistics.views import add_months
        next_month = add_months(datetime.now(), 1)
        cp_after_this_month = CustomerPackage.objects.filter(
            order=order, shipping_due_date__gte=next_month).count()
        self.assertEqual(cp_after_this_month, 11)

        # CHECK - THERE SHOULD BE 24 IRON BUDDHA WAREHOUSE ITEMS BOUND UP TO THIS ORDER
        items = WarehouseItem.objects.filter(
            package__order=order,
            unique_product__parent_product__slug='iron-buddha').count()
        self.assertEqual(items, 24)
Exemplo n.º 8
0
    def test_monthly_orders(self):
        shopper = Shopper.objects.all()[0]
        address = Address.objects.all()[0]
        basket = Basket.objects.all()[0]
        up = UniqueProduct.objects.get(parent_product__slug='iron-buddha', is_active=True, weight=100, currency__code='GBP')
        basket_item = BasketItem.objects.create(item=up, quantity=2, basket=basket, monthly_order=True, months=12)
        
        order = Order.objects.create(
            date_paid=datetime.now(),
            date_confirmed=datetime.now(),
            address=address,
            owner=shopper,
            invoice_id='FAKE123',
            status=Order.STATUS_PAID,
        )
        
        order.items.add(basket_item)
        order.save()

        # FIRST - create a customer package
        _create_customer_package(order)
        
        # CHECK - WE SHOULD HAVE 12 SEPARATE PACKAGES
        months = 12
        customer_packages = CustomerPackage.objects.filter(order=order).count()
        self.assertEqual(customer_packages, months)
        
        
        # CHECK - WE SHOULD HAVE 11 PACKAGES ARRIVING AFTER THIS MONTH
        from logistics.views import add_months
        next_month = add_months(datetime.now(), 1)
        cp_after_this_month = CustomerPackage.objects.filter(order=order, shipping_due_date__gte=next_month).count()
        self.assertEqual(cp_after_this_month, 11)
        
        
        # CHECK - THERE SHOULD BE 24 IRON BUDDHA WAREHOUSE ITEMS BOUND UP TO THIS ORDER
        items = WarehouseItem.objects.filter(package__order=order, unique_product__parent_product__slug='iron-buddha').count()
        self.assertEqual(items, 24)
        
        
        
        
        
        
        
Exemplo n.º 9
0
def mark_order_as_paid(request, order_id):

    order = get_object_or_404(Order, pk=order_id)

    # UPDATE THE ORDER DETAILS
    order.status = Order.STATUS_PAID
    order.date_paid = datetime.now()
    order.save()

    # IF THERE WAS A SINGLE USE DISCOUNT, UPDATE IT
    if order.discount:
        if order.discount.single_use == True:
            order.discount.is_active = False
            order.discount.save()

    # NOW CREATE A CUSTOMER PACKAGE
    from logistics.views import _create_customer_package
    _create_customer_package(order)

    url = request.META.get('HTTP_REFERER', '/')
    return HttpResponseRedirect(url)
Exemplo n.º 10
0
def mark_order_as_paid(request, order_id):
    
    order = get_object_or_404(Order, pk=order_id)
    
    # UPDATE THE ORDER DETAILS
    order.status = Order.STATUS_PAID
    order.date_paid = datetime.now()
    order.save()


    # IF THERE WAS A SINGLE USE DISCOUNT, UPDATE IT
    if order.discount:
        if order.discount.single_use == True:
            order.discount.is_active = False
            order.discount.save()


    # NOW CREATE A CUSTOMER PACKAGE
    from logistics.views import _create_customer_package
    _create_customer_package(order)

    url = request.META.get('HTTP_REFERER','/')
    return HttpResponseRedirect(url)
Exemplo n.º 11
0
    def test_customer_package_process(self):
        """check the whole process from customer purchase to package shipped"""

        # we're going to order some Jasmine Pearls 100g, make sure a customer
        # package is created, then check that the quantity has dropped

        # IMPORTANT - we're going to order all of the available stocks in one go
        quantity = WarehouseItem.objects.filter(
            unique_product__parent_product__slug='jasmine-pearls',
            sold__isnull=True).count()

        shopper = Shopper.objects.all()[0]
        address = Address.objects.all()[0]
        basket = Basket.objects.all()[0]
        up = UniqueProduct.objects.get(parent_product__slug='jasmine-pearls',
                                       is_active=True,
                                       weight=100,
                                       currency__code='GBP')
        basket_item = BasketItem.objects.create(item=up,
                                                quantity=quantity,
                                                basket=basket)

        order = Order.objects.create(
            date_paid=datetime.now(),
            date_confirmed=datetime.now(),
            address=address,
            owner=shopper,
            invoice_id='FAKE123',
            status=Order.STATUS_PAID,
        )

        order.items.add(basket_item)
        order.save()

        total_stocks = WarehouseItem.objects.filter(
            unique_product__parent_product__slug='jasmine-pearls').count()
        available_stocks = WarehouseItem.objects.filter(
            unique_product__parent_product__slug='jasmine-pearls',
            sold__isnull=True,
            available__isnull=False).count()

        # FIRST - create a customer package
        _create_customer_package(order)

        # SECOND - total number of items shouldn't have changed - make sure this is true
        new_total_stocks = WarehouseItem.objects.filter(
            unique_product__parent_product__slug='jasmine-pearls').count()
        self.assertEqual(total_stocks, new_total_stocks)

        # THIRD - the number of available items should be 0
        new_available_stocks = WarehouseItem.objects.filter(
            unique_product__parent_product__slug='jasmine-pearls',
            sold__isnull=True).count()
        self.assertEquals(new_available_stocks, 0)

        # FOURTH - now let's try to order 1 more - it should create an extra preorder package for this customer
        basket_item = BasketItem.objects.create(item=up,
                                                quantity=1,
                                                basket=basket)
        order = Order.objects.create(
            date_paid=datetime.now(),
            date_confirmed=datetime.now(),
            address=address,
            owner=shopper,
            invoice_id='FAKE123',
            status=Order.STATUS_PAID,
        )

        order.items.add(basket_item)
        order.save()

        _create_customer_package(order)

        preorder_package = CustomerPackage.objects.filter(order=order,
                                                          is_preorder=True)
        self.assertEqual(preorder_package.count(), 1)
Exemplo n.º 12
0
    def test_customer_package_process(self):
        """check the whole process from customer purchase to package shipped"""
        
        # we're going to order some Jasmine Pearls 100g, make sure a customer
        # package is created, then check that the quantity has dropped
        
        # IMPORTANT - we're going to order all of the available stocks in one go
        quantity = WarehouseItem.objects.filter(
                unique_product__parent_product__slug='jasmine-pearls', 
                sold__isnull=True
                ).count()
                
        shopper = Shopper.objects.all()[0]
        address = Address.objects.all()[0]
        basket = Basket.objects.all()[0]
        up = UniqueProduct.objects.get(parent_product__slug='jasmine-pearls', is_active=True, weight=100, currency__code='GBP')
        basket_item = BasketItem.objects.create(item=up, quantity=quantity, basket=basket)
        
        order = Order.objects.create(
            date_paid=datetime.now(),
            date_confirmed=datetime.now(),
            address=address,
            owner=shopper,
            invoice_id='FAKE123',
            status=Order.STATUS_PAID,
        )
        
        order.items.add(basket_item)
        order.save()
        
        total_stocks = WarehouseItem.objects.filter(unique_product__parent_product__slug='jasmine-pearls').count()
        available_stocks = WarehouseItem.objects.filter(unique_product__parent_product__slug='jasmine-pearls', 
            sold__isnull=True, available__isnull=False).count()

        # FIRST - create a customer package
        _create_customer_package(order)
        
        # SECOND - total number of items shouldn't have changed - make sure this is true
        new_total_stocks = WarehouseItem.objects.filter(unique_product__parent_product__slug='jasmine-pearls').count()
        self.assertEqual(total_stocks, new_total_stocks)
        
        # THIRD - the number of available items should be 0
        new_available_stocks = WarehouseItem.objects.filter(unique_product__parent_product__slug='jasmine-pearls', sold__isnull=True).count()
        self.assertEquals(new_available_stocks, 0)
        

        # FOURTH - now let's try to order 1 more - it should create an extra preorder package for this customer
        basket_item = BasketItem.objects.create(item=up, quantity=1, basket=basket)
        order = Order.objects.create(
            date_paid=datetime.now(),
            date_confirmed=datetime.now(),
            address=address,
            owner=shopper,
            invoice_id='FAKE123',
            status=Order.STATUS_PAID,
        )
        
        order.items.add(basket_item)
        order.save()
        
        _create_customer_package(order)
        
        preorder_package = CustomerPackage.objects.filter(order=order, is_preorder=True)
        self.assertEqual(preorder_package.count(), 1)