コード例 #1
0
ファイル: tests.py プロジェクト: juderino/jelly-roll
def make_test_order(country, state):
    c = Contact(first_name="Gift", last_name="Tester", 
        role="Customer", email="*****@*****.**")
    c.save()
    if not isinstance(country, Country):
        country = Country.objects.get(iso2_code__iexact = country)
    ad = AddressBook(contact=c, description="home",
        street1 = "test", state=state, city="Portland",
        country = country, is_default_shipping=True,
        is_default_billing=True)
    ad.save()
    site = Site.objects.get_current()
    o = Order(contact=c, shipping_cost=Decimal('0.00'), site=site)
    o.save()

    p = Product.objects.get(slug='GIFT10')
    price = p.unit_price
    log.debug("creating with price: %s", price)
    item1 = OrderItem(order=o, product=p, quantity=2,
        unit_price=price, line_item_price=price*2)
    item1.save()

    detail = OrderItemDetail(name = 'email', value='*****@*****.**', sort_order=0, item=item1)
    detail.save()
    detail = OrderItemDetail(name = 'message', value='hello there', sort_order=0, item=item1)
    detail.save()

    return o
コード例 #2
0
ファイル: tests.py プロジェクト: juderino/jelly-roll
    def setUp(self):
        self.US = Country.objects.get(iso2_code__iexact = 'US')
        self.site = Site.objects.get_current()
        tax = config_get('TAX','MODULE')
        tax.update('satchmo.tax.modules.no')
        c = Contact(first_name="Jim", last_name="Tester", 
            role="Customer", email="*****@*****.**")
        c.save()
        ad = AddressBook(contact=c, description="home",
            street1 = "test", state="OR", city="Portland",
            country = self.US, is_default_shipping=True,
            is_default_billing=True)
        ad.save()
        o = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site)
        o.save()
        small = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site)
        small.save()

        p = Product.objects.get(slug='neat-book-soft')
        price = p.unit_price
        item1 = OrderItem(order=o, product=p, quantity=1,
            unit_price=price, line_item_price=price)
        item1.save()
        
        item1s = OrderItem(order=small, product=p, quantity=1,
            unit_price=price, line_item_price=price)
        item1s.save()
        
        p = Product.objects.get(slug='neat-book-hard')
        price = p.unit_price
        item2 = OrderItem(order=o, product=p, quantity=1,
            unit_price=price, line_item_price=price)
        item2.save()
        self.order = o
        self.small = small
コード例 #3
0
ファイル: utils.py プロジェクト: ToeKnee/jelly-roll
def update_orderitems(new_order, cart, update=False):
    """Update the order with all cart items, first removing all items if this
    is an update.
    """
    if update:
        new_order.remove_all_items()
    else:
        # have to save first, or else we can't add orderitems
        new_order.save()

    # Add all the items in the cart to the order
    for item in cart.cartitem_set.all():
        new_order_item = OrderItem(
            order=new_order,
            product=item.product,
            quantity=item.quantity,
            unit_price=item.unit_price,
            line_item_price=item.line_total,
        )

        update_orderitem_for_subscription(new_order_item, item)
        update_orderitem_details(new_order_item, item)

        # Send a signal after copying items
        # External applications can copy their related objects using this
        satchmo_post_copy_item_to_order.send(cart,
                                             cartitem=item,
                                             order=new_order,
                                             orderitem=new_order_item)

    new_order.recalculate_total()
コード例 #4
0
ファイル: tests.py プロジェクト: ToeKnee/jelly-roll
def make_test_order(country, state):
    c = Contact(first_name="Gift",
                last_name="Tester",
                role="Customer",
                email="*****@*****.**")
    c.save()
    if not isinstance(country, Country):
        country = Country.objects.get(iso2_code__iexact=country)
    ad = AddressBook(
        contact=c,
        description="home",
        street1="test",
        state=state,
        city="Portland",
        country=country,
        is_default_shipping=True,
        is_default_billing=True,
    )
    ad.save()
    o = Order(contact=c, shipping_cost=Decimal("0.00"))
    o.save()

    p = Product.objects.get(slug="GIFT10")
    price = p.unit_price
    log.debug("creating with price: %s", price)
    item1 = OrderItem(order=o,
                      product=p,
                      quantity=2,
                      unit_price=price,
                      line_item_price=price * 2)
    item1.save()

    detail = OrderItemDetail(name="email",
                             value="*****@*****.**",
                             sort_order=0,
                             item=item1)
    detail.save()
    detail = OrderItemDetail(name="message",
                             value="hello there",
                             sort_order=0,
                             item=item1)
    detail.save()

    return o
コード例 #5
0
def make_test_order(country, state, include_non_taxed=False):
    warnings.warn(
        "make_test_order is deprecated - Use TestOrderFactory instead",
        DeprecationWarning,
    )
    c = Contact(first_name="Tax",
                last_name="Tester",
                role="Customer",
                email="*****@*****.**")
    c.save()
    if not isinstance(country, Country):
        country = Country.objects.get(iso2_code__iexact=country)

    ad = AddressBook(
        contact=c,
        description="home",
        street1="test",
        state=state,
        city="Portland",
        country=country,
        is_default_shipping=True,
        is_default_billing=True,
    )
    ad.save()
    o = Order(contact=c, shipping_cost=Decimal("10.00"))
    o.save()

    p = Product.objects.get(slug="dj-rocks-s-b")
    price = p.unit_price
    item1 = OrderItem(order=o,
                      product=p,
                      quantity=5,
                      unit_price=price,
                      line_item_price=price * 5)
    item1.save()

    if include_non_taxed:
        p = Product.objects.get(slug="neat-book-hard")
        price = p.unit_price
        item2 = OrderItem(order=o,
                          product=p,
                          quantity=1,
                          unit_price=price,
                          line_item_price=price)
        item2.save()

    return o
コード例 #6
0
ファイル: test_shop.py プロジェクト: ToeKnee/jelly-roll
def make_test_order(country, state, include_non_taxed=False, site=None):
    warnings.warn(
        "make_test_order is deprecated - Use TestOrderFactory instead",
        DeprecationWarning,
    )
    if not site:
        site = Site.objects.get_current()
    c = Contact(
        first_name="Tax", last_name="Tester", role="Customer", email="*****@*****.**"
    )
    c.save()
    if not isinstance(country, Country):
        country = Country.objects.get(iso2_code__iexact=country)

    ad = AddressBook(
        contact=c,
        description="home",
        street1="test",
        state=state,
        city="Portland",
        country=country,
        is_default_shipping=True,
        is_default_billing=True,
    )
    ad.save()
    o = Order(contact=c, shipping_cost=Decimal("10.00"), site=site)
    o.save()

    p = Product.objects.get(slug="dj-rocks-s-b")
    price = p.unit_price
    item1 = OrderItem(
        order=o, product=p, quantity=5, unit_price=price, line_item_price=price * 5
    )
    item1.save()

    if include_non_taxed:
        p = Product.objects.get(slug="neat-book-hard")
        price = p.unit_price
        item2 = OrderItem(
            order=o, product=p, quantity=1, unit_price=price, line_item_price=price
        )
        item2.save()

    return o
コード例 #7
0
ファイル: cron.py プロジェクト: jimmcgaw/levicci
def cron_rebill(request=None):
    """Rebill customers with expiring recurring subscription products
    This can either be run via a url with GET key authentication or
    directly from a shell script.
    """
    #TODO: support re-try billing for failed transactions

    if request is not None:
        if not config_value('PAYMENT', 'ALLOW_URL_REBILL'):
            return bad_or_missing(request, _("Feature is not enabled."))
        if 'key' not in request.GET or request.GET['key'] != config_value('PAYMENT','CRON_KEY'):
            return HttpResponse("Authentication Key Required")

    expiring_subscriptions = OrderItem.objects.filter(expire_date__gte=datetime.now()).order_by('order', 'id', 'expire_date')
    for item in expiring_subscriptions:
        if item.product.is_subscription:#TODO - need to add support for products with trial but non-recurring
            if item.product.subscriptionproduct.recurring_times and item.product.subscriptionproduct.recurring_times + item.product.subscriptionproduct.get_trial_terms().count() == OrderItem.objects.filter(order=item.order, product=item.product).count():
                continue
            if item.expire_date == datetime.date(datetime.now()) and item.completed:
                if item.id == OrderItem.objects.filter(product=item.product, order=item.order).order_by('-id')[0].id:
                    #bill => add orderitem, recalculate total, porocess card
                    new_order_item = OrderItem(order=item.order, product=item.product, quantity=item.quantity, unit_price=item.unit_price, line_item_price=item.line_item_price)
                    #if product is recurring, set subscription end
                    if item.product.subscriptionproduct.recurring:
                        new_order_item.expire_date = item.product.subscriptionproduct.calc_expire_date()
                    #check if product has 2 or more trial periods and if the last one paid was a trial or a regular payment.
                    ordercount = item.order.orderitem_set.all().count()
                    if item.product.subscriptionproduct.get_trial_terms().count() > 1 and item.unit_price == item.product.subscriptionproduct.get_trial_terms(ordercount - 1).price:
                        new_order_item.unit_price = item.product.subscriptionproduct.get_trial.terms(ordercount).price
                        new_order_item.line_item_price = new_order_item.quantity * new_order_item.unit_price
                        new_order_item.expire_date = item.product.subscriptionproduct.get_trial_terms(ordercount).calc_expire_date()
                    new_order_item.save()
                    item.order.recalculate_total()
#                    if new_order_item.product.subscriptionproduct.is_shippable == 3:
#                        item.order.total = item.order.total - item.order.shipping_cost
#                        item.order.save()
                    payments = item.order.payments.all()[0]
                    #list of ipn based payment modules.  Include processors that use 3rd party recurring billing.
                    ipn_based = ['PAYPAL']
                    if not payments.payment in ipn_based and item.order.balance > 0:
                        #run card
                        #Do the credit card processing here & if successful, execute the success_handler
                        from satchmo.configuration import config_get_group
                        payment_module = config_get_group('PAYMENT_%s' % payments.payment)
                        credit_processor = payment_module.MODULE.load_module('processor')
                        processor = credit_processor.PaymentProcessor(payment_module)
                        processor.prepareData(item.order)
                        results, reason_code, msg = processor.process()
        
                        log.info("""Processing %s recurring transaction with %s
                            Order #%i
                            Results=%s
                            Response=%s
                            Reason=%s""", payment_module.LABEL.value, payment_module.KEY.value, item.order.id, results, reason_code, msg)

                        if results:
                            #success handler
                            item.order.add_status(status='Pending', notes = "Subscription Renewal Order successfully submitted")
                            new_order_item.completed = True
                            new_order_item.save()
                            orderpayment = OrderPayment(order=item.order, amount=item.order.balance, payment=unicode(payment_module.KEY.value))
                            orderpayment.save()
    return HttpResponse()
コード例 #8
0
def cron_rebill(request=None):
    """Rebill customers with expiring recurring subscription products
    This can either be run via a url with GET key authentication or
    directly from a shell script.
    """
    #TODO: support re-try billing for failed transactions

    if request is not None:
        if not config_value('PAYMENT', 'ALLOW_URL_REBILL'):
            return bad_or_missing(request, _("Feature is not enabled."))
        if 'key' not in request.GET or request.GET['key'] != config_value(
                'PAYMENT', 'CRON_KEY'):
            return HttpResponse("Authentication Key Required")

    expiring_subscriptions = OrderItem.objects.filter(
        expire_date__gte=datetime.now()).order_by('order', 'id', 'expire_date')
    for item in expiring_subscriptions:
        if item.product.is_subscription:  #TODO - need to add support for products with trial but non-recurring
            if item.product.subscriptionproduct.recurring_times and item.product.subscriptionproduct.recurring_times + item.product.subscriptionproduct.get_trial_terms(
            ).count() == OrderItem.objects.filter(
                    order=item.order, product=item.product).count():
                continue
            if item.expire_date == datetime.date(
                    datetime.now()) and item.completed:
                if item.id == OrderItem.objects.filter(
                        product=item.product,
                        order=item.order).order_by('-id')[0].id:
                    #bill => add orderitem, recalculate total, porocess card
                    new_order_item = OrderItem(
                        order=item.order,
                        product=item.product,
                        quantity=item.quantity,
                        unit_price=item.unit_price,
                        line_item_price=item.line_item_price)
                    #if product is recurring, set subscription end
                    if item.product.subscriptionproduct.recurring:
                        new_order_item.expire_date = item.product.subscriptionproduct.calc_expire_date(
                        )
                    #check if product has 2 or more trial periods and if the last one paid was a trial or a regular payment.
                    ordercount = item.order.orderitem_set.all().count()
                    if item.product.subscriptionproduct.get_trial_terms(
                    ).count(
                    ) > 1 and item.unit_price == item.product.subscriptionproduct.get_trial_terms(
                            ordercount - 1).price:
                        new_order_item.unit_price = item.product.subscriptionproduct.get_trial.terms(
                            ordercount).price
                        new_order_item.line_item_price = new_order_item.quantity * new_order_item.unit_price
                        new_order_item.expire_date = item.product.subscriptionproduct.get_trial_terms(
                            ordercount).calc_expire_date()
                    new_order_item.save()
                    item.order.recalculate_total()
                    #                    if new_order_item.product.subscriptionproduct.is_shippable == 3:
                    #                        item.order.total = item.order.total - item.order.shipping_cost
                    #                        item.order.save()
                    payments = item.order.payments.all()[0]
                    #list of ipn based payment modules.  Include processors that use 3rd party recurring billing.
                    ipn_based = ['PAYPAL']
                    if not payments.payment in ipn_based and item.order.balance > 0:
                        #run card
                        #Do the credit card processing here & if successful, execute the success_handler
                        from satchmo.configuration import config_get_group
                        payment_module = config_get_group('PAYMENT_%s' %
                                                          payments.payment)
                        credit_processor = payment_module.MODULE.load_module(
                            'processor')
                        processor = credit_processor.PaymentProcessor(
                            payment_module)
                        processor.prepareData(item.order)
                        results, reason_code, msg = processor.process()

                        log.info(
                            """Processing %s recurring transaction with %s
                            Order #%i
                            Results=%s
                            Response=%s
                            Reason=%s""", payment_module.LABEL.value,
                            payment_module.KEY.value, item.order.id, results,
                            reason_code, msg)

                        if results:
                            #success handler
                            item.order.add_status(
                                status='Pending',
                                notes=
                                "Subscription Renewal Order successfully submitted"
                            )
                            new_order_item.completed = True
                            new_order_item.save()
                            orderpayment = OrderPayment(
                                order=item.order,
                                amount=item.order.balance,
                                payment=unicode(payment_module.KEY.value))
                            orderpayment.save()
    return HttpResponse()
コード例 #9
0
    def setUp(self):
        self.US = Country.objects.get(iso2_code__iexact='US')
        self.site = Site.objects.get_current()
        tax = config_get('TAX', 'MODULE')
        tax.update('satchmo.tax.modules.no')
        c = Contact(first_name="Jim",
                    last_name="Tester",
                    role="Customer",
                    email="*****@*****.**")
        c.save()
        ad = AddressBook(contact=c,
                         description="home",
                         street1="test",
                         state="OR",
                         city="Portland",
                         country=self.US,
                         is_default_shipping=True,
                         is_default_billing=True)
        ad.save()
        o = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site)
        o.save()
        small = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site)
        small.save()

        p = Product.objects.get(slug='neat-book-soft')
        price = p.unit_price
        item1 = OrderItem(order=o,
                          product=p,
                          quantity=1,
                          unit_price=price,
                          line_item_price=price)
        item1.save()

        item1s = OrderItem(order=small,
                           product=p,
                           quantity=1,
                           unit_price=price,
                           line_item_price=price)
        item1s.save()

        p = Product.objects.get(slug='neat-book-hard')
        price = p.unit_price
        item2 = OrderItem(order=o,
                          product=p,
                          quantity=1,
                          unit_price=price,
                          line_item_price=price)
        item2.save()
        self.order = o
        self.small = small