def _create_and_verify_order(self, sku):
        response = self._order(sku)

        # Verify that the orders endpoint has successfully created the order
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Verify that the order data in the response is valid
        response_serializer = OrderSerializer(data=response.data)
        self.assertTrue(response_serializer.is_valid(), msg=response_serializer.errors)

        # Verify that the returned order metadata lines up with the order in the system
        expected_serializer = OrderSerializer(Order.objects.get())
        self.assertEqual(response_serializer.data, expected_serializer.data)
    def _create_and_verify_order(self, sku):
        response = self._order(sku)

        # Verify that the orders endpoint has successfully created the order
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Verify that the order data in the response is valid
        response_serializer = OrderSerializer(data=response.data)
        self.assertTrue(response_serializer.is_valid(),
                        msg=response_serializer.errors)

        # Verify that the returned order metadata lines up with the order in the system
        expected_serializer = OrderSerializer(Order.objects.get())
        self.assertEqual(response_serializer.data, expected_serializer.data)
Exemple #3
0
    def post(self, request):
        basket = request.basket

        if not request.data.get('token'):
            raise ValidationError({'error': 'token_missing'})

        try:
            billing_address = self._get_billing_address(
                request.data.get('billingContact'))
        except Exception as this_exception:
            logger.exception(
                'Failed to authorize Apple Pay payment. An error occurred while parsing the billing address.'
            )
            raise ValidationError({'error': 'billing_address_invalid'
                                   }) from this_exception

        try:
            self.handle_payment(None, basket)
        except GatewayError:
            return Response({'error': 'payment_failed'},
                            status=status.HTTP_502_BAD_GATEWAY)

        order = self.create_order(request,
                                  basket,
                                  billing_address=billing_address)
        return Response(OrderSerializer(order, context={
            'request': request
        }).data,
                        status=status.HTTP_201_CREATED)
    def test_post(self):
        """ The view should authorize and settle payment at CyberSource, and create an order. """
        data = self.generate_post_data()
        basket = create_basket(owner=self.user, site=self.site)
        basket.strategy = Selector().strategy()

        self.mock_cybersource_wsdl()
        self.mock_authorization_response(accepted=True)
        response = self.client.post(self.url, json.dumps(data), JSON)

        self.assertEqual(response.status_code, 201)
        PaymentProcessorResponse.objects.get(basket=basket)

        order = Order.objects.all().first()
        total = order.total_incl_tax
        self.assertEqual(
            response.data,
            OrderSerializer(order, context={
                'request': self.request
            }).data)
        order.payment_events.get(event_type__code='paid', amount=total)
        Source.objects.get(source_type__name=Cybersource.NAME,
                           currency=order.currency,
                           amount_allocated=total,
                           amount_debited=total,
                           label='Apple Pay')
        PaymentEvent.objects.get(event_type__name=PaymentEventTypeName.PAID,
                                 amount=total,
                                 processor_name=Cybersource.NAME)
Exemple #5
0
    def _create_and_verify_order(self, sku, shipping_event_name):
        # Ideally, we'd use Oscar's ShippingEventTypeFactory here, but it's not exposed/public.
        ShippingEventType.objects.create(name=shipping_event_name)

        response = self._order(sku=sku)

        # Verify that the orders endpoint has successfully created the order
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Verify that the order data in the response is valid
        response_serializer = OrderSerializer(data=response.data)
        self.assertTrue(response_serializer.is_valid(), msg=response_serializer.errors)

        # Verify that the returned order metadata lines up with the order in the system
        expected_serializer = OrderSerializer(Order.objects.get())
        self.assertEqual(response_serializer.data, expected_serializer.data)
Exemple #6
0
 def test_get_order(self, order_status):
     """Test all scenarios where an order should be successfully retrieved. """
     self.order.status = order_status
     self.order.save()
     response = self.client.get(self.url, HTTP_AUTHORIZATION=self.token)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data, OrderSerializer(self.order).data)
Exemple #7
0
    def _create_and_verify_order(self, sku, shipping_event_name):
        # Ideally, we'd use Oscar's ShippingEventTypeFactory here, but it's not exposed/public.
        ShippingEventType.objects.create(name=shipping_event_name)

        response = self._order(sku=sku)

        # Verify that the orders endpoint has successfully created the order
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Verify that the order data in the response is valid
        response_serializer = OrderSerializer(data=response.data)
        self.assertTrue(response_serializer.is_valid(),
                        msg=response_serializer.errors)

        # Verify that the returned order metadata lines up with the order in the system
        expected_serializer = OrderSerializer(Order.objects.get())
        self.assertEqual(response_serializer.data, expected_serializer.data)
    def assert_list_with_username_filter(self, user, order):
        """ Helper method for making assertions. """

        response = self.client.get(self.path, {'username': user.username})
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['results'][0],
            OrderSerializer(order, context={'request': RequestFactory(SERVER_NAME=self.site.domain).get('/')}).data
        )
Exemple #9
0
 def serialize_order(self, order):
     request = RequestFactory(SERVER_NAME=self.site.domain).get('/')
     return OrderSerializer(order, context={'request': request}).data
Exemple #10
0
 def test_get_order(self):
     """Test successful order retrieval."""
     response = self.client.get(self.url, HTTP_AUTHORIZATION=self.token)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data, OrderSerializer(self.order).data)