Beispiel #1
0
    def test_fulfillment_error_order_basket(self):
        """ Test fulfillment error order basket is fulfilled when called for basket."""
        basket = self._dummy_order_data(status=ORDER.FULFILLMENT_ERROR)

        assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
        order = Order.objects.get(basket=basket)
        self.assertEqual(order.status, ORDER.COMPLETE)
Beispiel #2
0
    def test_order_exist_exception(self):
        basket = create_basket(site=self.site)
        basket.status = 'Frozen'
        basket.save()
        card_number = '4111111111111111'
        response = {
            'req_card_number': card_number,
            'req_card_type': CARD_TYPES['visa']['cybersource_code']
        }
        PaymentProcessorResponse.objects.create(basket=basket,
                                                transaction_id='abc',
                                                processor_name='cybersource',
                                                response=response)

        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        total = OrderTotalCalculator().calculate(basket, shipping_charge)
        number = OrderNumberGenerator().order_number(basket)
        with transaction.atomic():
            OrderCreator().place_order(order_number=number,
                                       user=basket.owner,
                                       basket=basket,
                                       shipping_address=None,
                                       shipping_method=shipping_method,
                                       shipping_charge=shipping_charge,
                                       billing_address=None,
                                       total=total)

            basket.set_as_submitted()

        assert not FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
Beispiel #3
0
    def post(self, request, *args, **kwargs):  # pylint: disable=unused-argument
        action = request.POST.get('action')

        if action:
            logger.info(
                'User [%s] executed action [%s] on the management view.',
                request.user, action)

        if action == 'refund_basket_transactions':
            basket_ids = self._parse_basket_ids(request.POST.get('basket_ids'))
            success_count, failure_count = refund_basket_transactions(
                request.site, basket_ids)
            msg = 'Finished refunding basket transactions. [{success_count}] transactions were successfully refunded.' \
                  ' [{failure_count}] attempts failed.'.format(success_count=success_count,
                                                               failure_count=failure_count)
            messages.add_message(request, messages.INFO, msg)
        elif action == 'fulfill':
            basket_ids = self._parse_basket_ids(request.POST.get('basket_ids'))
            for basket_id in basket_ids:
                fulfilled = FulfillFrozenBaskets().fulfill_basket(
                    basket_id=basket_id, site=request.site)
                if fulfilled:
                    logger.info('Fulfilled basket [%s].', basket_id)
                else:
                    logger.info('Unable to fulfill basket [%d]', basket_id)
        else:
            messages.add_message(
                request, messages.ERROR,
                _('{action} is not a valid action.').format(action=action))

        return self.get(request)
Beispiel #4
0
    def test_no_successful_transaction(self):
        """ Test utility when basket have no successful payment processor response."""
        basket = create_basket(site=self.site)
        basket.status = 'Frozen'
        basket.save()

        assert not FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
Beispiel #5
0
    def test_when_unable_to_fulfill_basket(self):
        """ Test returns false when unable to fulfill basket."""
        basket = self._dummy_basket_data()

        with mock.patch(
                'ecommerce.extensions.checkout.mixins.EdxOrderPlacementMixin.handle_order_placement',
                side_effect=Exception):
            assert not FulfillFrozenBaskets().fulfill_basket(
                basket.id, self.site)
Beispiel #6
0
 def test_multiple_transactions(self):
     """ Test utility against multiple payment processor responses."""
     basket = self._dummy_basket_data()
     PaymentProcessorResponse.objects.create(
         basket=basket,
         transaction_id='abc',
         processor_name='cybersource',
         response={u'decision': u'ACCEPT'})
     assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
Beispiel #7
0
    def test_when_unable_to_fulfill_order(self):
        """ Test returns false when unable to complete fulfillment of order. """
        basket = self._dummy_order_data(status=ORDER.FULFILLMENT_ERROR)

        with mock.patch(
                'ecommerce.extensions.order.processing.EventHandler.handle_shipping_event',
                return_value='pumpkins'):
            assert not FulfillFrozenBaskets().fulfill_basket(
                basket.id, self.site)
        order = Order.objects.get(basket=basket)
        self.assertEqual(order.is_fulfillable, True)
Beispiel #8
0
    def test_multiple_transactions(self):
        basket = create_basket(site=self.site)
        basket.status = 'Frozen'
        basket.save()
        PaymentProcessorResponse.objects.create(basket=basket,
                                                transaction_id='abc',
                                                processor_name='cybersource')
        PaymentProcessorResponse.objects.create(basket=basket,
                                                transaction_id='PAY-123',
                                                processor_name='paypal')

        assert not FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
Beispiel #9
0
    def test_success_with_paypal(self):
        """ Test basket with paypal payment basket."""
        basket = self._dummy_basket_data()

        assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)

        order = Order.objects.get(number=basket.order_number)
        assert order.status == 'Complete'

        total = basket.total_incl_tax_excl_discounts
        Source.objects.get(source_type__name=Paypal.NAME,
                           currency=order.currency,
                           amount_allocated=total,
                           amount_debited=total,
                           label='Paypal Account',
                           card_type=None)
        PaymentEvent.objects.get(event_type__name=PaymentEventTypeName.PAID,
                                 amount=total,
                                 processor_name=Paypal.NAME)
Beispiel #10
0
    def test_with_expired_voucher(self):
        """ Test creates order when called with basket with expired voucher"""
        basket = create_basket()
        product = ProductFactory(stockrecords__price_excl_tax=100,
                                 stockrecords__partner=self.partner,
                                 stockrecords__price_currency='USD')
        voucher, product = prepare_voucher(
            code='TEST101', _range=RangeFactory(products=[product]))
        self.request.user = UserFactory()
        basket.add_product(product)
        basket.vouchers.add(voucher)
        basket.status = 'Frozen'
        basket.save()

        PaymentProcessorResponse.objects.create(basket=basket,
                                                transaction_id='PAY-123',
                                                processor_name='paypal',
                                                response={'state': 'approved'})
        with mock.patch('oscar.apps.offer.applicator.Applicator.apply',
                        side_effect=ValueError):
            assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
Beispiel #11
0
    def test_success_with_cybersource(self):
        """ Test basket with cybersource payment basket."""
        product_price = 100
        percentage_discount = 10
        product = ProductFactory(stockrecords__price_excl_tax=product_price)
        voucher, product = prepare_voucher(
            _range=RangeFactory(products=[product]),
            benefit_value=percentage_discount)
        self.request.user = UserFactory()
        basket = prepare_basket(self.request, [product], voucher)
        basket.status = 'Frozen'
        basket.save()

        card_number = '4111111111111111'
        response = {
            'req_card_number': card_number,
            'req_card_type': CARD_TYPES['visa']['cybersource_code'],
            u'decision': u'ACCEPT',
        }
        PaymentProcessorResponse.objects.create(basket=basket,
                                                transaction_id='abc',
                                                processor_name='cybersource',
                                                response=response)
        assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)

        order = Order.objects.get(number=basket.order_number)
        assert order.status == 'Complete'

        total = product_price * (100 - percentage_discount) / 100.
        Source.objects.get(source_type__name=Cybersource.NAME,
                           currency=order.currency,
                           amount_allocated=total,
                           amount_debited=total,
                           label=card_number,
                           card_type='visa')
        PaymentEvent.objects.get(event_type__name=PaymentEventTypeName.PAID,
                                 amount=total,
                                 processor_name=Cybersource.NAME)
Beispiel #12
0
    def test_success_with_paypal(self):
        basket = create_basket(site=self.site)
        basket.status = 'Frozen'
        basket.save()

        PaymentProcessorResponse.objects.create(basket=basket,
                                                transaction_id='PAY-123',
                                                processor_name='paypal')
        assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)

        order = Order.objects.get(number=basket.order_number)
        assert order.status == 'Complete'

        total = basket.total_incl_tax_excl_discounts
        Source.objects.get(source_type__name=Paypal.NAME,
                           currency=order.currency,
                           amount_allocated=total,
                           amount_debited=total,
                           label='PayPal Account',
                           card_type=None)
        PaymentEvent.objects.get(event_type__name=PaymentEventTypeName.PAID,
                                 amount=total,
                                 processor_name=Paypal.NAME)
Beispiel #13
0
 def test_invalid_basket(self):
     assert not FulfillFrozenBaskets().fulfill_basket(100, self.site)
Beispiel #14
0
 def test_complete_order_basket(self):
     """ Test when basket have a fulfilled order."""
     basket = self._dummy_order_data(status=ORDER.COMPLETE)
     assert FulfillFrozenBaskets().fulfill_basket(basket.id, self.site)
Beispiel #15
0
 def test_invalid_basket(self):
     """ Test utility for invalid basket id."""
     assert not FulfillFrozenBaskets().fulfill_basket(100, self.site)