Example #1
0
 def post(self, *args, **kwargs):
     to = self.request.POST.get('status', '')
     if self.order.status in (Order.STATUS_PENDING, Order.STATUS_EXPIRED) and to == 'p':
         try:
             mark_order_paid(self.order, manual=True, user=self.request.user)
         except Quota.QuotaExceededException as e:
             messages.error(self.request, str(e))
         else:
             messages.success(self.request, _('The order has been marked as paid.'))
     elif self.order.status == Order.STATUS_PENDING and to == 'c':
         cancel_order(self.order, user=self.request.user)
         messages.success(self.request, _('The order has been cancelled.'))
     elif self.order.status == Order.STATUS_PAID and to == 'n':
         self.order.status = Order.STATUS_PENDING
         self.order.payment_manual = True
         self.order.save()
         self.order.log_action('pretix.event.order.unpaid', user=self.request.user)
         messages.success(self.request, _('The order has been marked as not paid.'))
     elif self.order.status == Order.STATUS_PENDING and to == 'e':
         self.order.status = Order.STATUS_EXPIRED
         self.order.save()
         self.order.log_action('pretix.event.order.expired', user=self.request.user)
         messages.success(self.request, _('The order has been marked as expired.'))
     elif self.order.status == Order.STATUS_PAID and to == 'r':
         ret = self.payment_provider.order_control_refund_perform(self.request, self.order)
         if ret:
             return redirect(ret)
     return redirect(self.get_order_url())
Example #2
0
    def mark_canceled(self, request, **kwargs):
        send_mail = request.data.get('send_email', True)
        cancellation_fee = request.data.get('cancellation_fee', None)
        if cancellation_fee:
            try:
                cancellation_fee = float(Decimal(cancellation_fee))
            except:
                cancellation_fee = None

        order = self.get_object()
        if not order.cancel_allowed():
            return Response(
                {'detail': 'The order is not allowed to be canceled.'},
                status=status.HTTP_400_BAD_REQUEST
            )

        try:
            cancel_order(
                order,
                user=request.user if request.user.is_authenticated else None,
                api_token=request.auth if isinstance(request.auth, TeamAPIToken) else None,
                device=request.auth if isinstance(request.auth, Device) else None,
                oauth_application=request.auth.application if isinstance(request.auth, OAuthAccessToken) else None,
                send_mail=send_mail,
                cancellation_fee=cancellation_fee
            )
        except OrderError as e:
            return Response(
                {'detail': str(e)},
                status=status.HTTP_400_BAD_REQUEST
            )
        return self.retrieve(request, [], **kwargs)
Example #3
0
    def test_voucher_reuse(self):
        self.quota.items.add(self.item1)
        v = Voucher.objects.create(quota=self.quota, event=self.event, valid_until=now() + timedelta(days=5))

        # use a voucher normally
        cart = CartPosition.objects.create(event=self.event, item=self.item1, price=self.item1.default_price,
                                           expires=now() + timedelta(days=3), voucher=v)
        order = perform_order(event=self.event.id, payment_provider='free', positions=[cart.id])

        # assert that the voucher cannot be reused
        cart = CartPosition.objects.create(event=self.event, item=self.item1, price=self.item1.default_price,
                                           expires=now() + timedelta(days=3), voucher=v)
        self.assertRaises(OrderError, perform_order, event=self.event.id, payment_provider='free', positions=[cart.id])

        # assert that the voucher can be re-used after cancelling the successful order
        cancel_order(order)
        cart = CartPosition.objects.create(event=self.event, item=self.item1, price=self.item1.default_price,
                                           expires=now() + timedelta(days=3), voucher=v)
        perform_order(event=self.event.id, payment_provider='free', positions=[cart.id])
Example #4
0
    def mark_canceled(self, request, **kwargs):
        send_mail = request.data.get('send_email', True)

        order = self.get_object()
        if not order.cancel_allowed():
            return Response(
                {'detail': 'The order is not allowed to be canceled.'},
                status=status.HTTP_400_BAD_REQUEST
            )

        cancel_order(
            order,
            user=request.user if request.user.is_authenticated else None,
            api_token=request.auth if isinstance(request.auth, TeamAPIToken) else None,
            device=request.auth if isinstance(request.auth, Device) else None,
            oauth_application=request.auth.application if isinstance(request.auth, OAuthAccessToken) else None,
            send_mail=send_mail
        )
        return self.retrieve(request, [], **kwargs)
Example #5
0
 def post(self, request, *args, **kwargs):
     cancel_order(self.order)
     return redirect(self.get_order_url())