Exemplo n.º 1
0
    def test_card_invalid_request(self):
        token = {'token': 'invalid'}
        registration = self.event.get_registration(self.abakus_user)
        chain(
            async_payment.s(registration.id, token), registration_payment_save.s(registration.id)
        ).delay()

        registration.refresh_from_db()
        self.assertEqual(registration.charge_status, 'invalid_request_error')
Exemplo n.º 2
0
    def test_card_incorrect_cvc(self):
        token = create_token('4000000000000127', '123')
        registration = self.event.get_registration(self.abakus_user)
        with self.assertRaises(stripe.error.StripeError):
            chain(
                async_payment.s(registration.id, token),
                registration_payment_save.s(registration.id)
            ).delay()

        registration.refresh_from_db()
        self.assertEqual(registration.charge_status, 'incorrect_cvc')
Exemplo n.º 3
0
    def test_card_declined(self):
        token = create_token("4000000000000002", "123")
        registration = self.event.get_registration(self.abakus_user)
        with self.assertRaises(stripe.error.StripeError):
            chain(
                async_payment.s(registration.id, token),
                registration_payment_save.s(registration.id),
            ).delay()

        registration.refresh_from_db()
        self.assertEqual(registration.charge_status, "card_declined")
Exemplo n.º 4
0
    def payment(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        event_id = self.kwargs.get('pk', None)
        event = Event.objects.get(id=event_id)
        registration = event.get_registration(request.user)

        if not event.is_priced or not event.use_stripe:
            raise PermissionDenied()

        if registration.has_paid():
            raise APIPaymentExists()
        registration.charge_status = constants.PAYMENT_PENDING
        registration.save()
        chain(
            async_payment.s(registration.id, serializer.data['token']),
            registration_payment_save.s(registration.id)
        ).delay()
        payment_serializer = RegistrationPaymentReadSerializer(
            registration, context={'request': request}
        )
        return Response(data=payment_serializer.data, status=status.HTTP_202_ACCEPTED)