コード例 #1
0
 def move(self, request, *args, **kwargs):
     """
     Given the primary key of the item, we query the latest transaction, than create a new transaction
     based on it's next state.  Note: by saving the transaction, the item state will be updated as well.
     :param request: The Request object
     :param args: Arguments
     :param kwargs: Key word arguments
     :return: Response
     """
     trans = Transaction.get_active_transaction(kwargs['id'])
     return self.move_transaction(trans)
コード例 #2
0
ファイル: admin.py プロジェクト: xuru/routable
    def refund(self, request, obj):
        """
        Refund a payment that is in error

        :param request: The request
        :param obj: The Item in question
        :return: None
        """
        trans = Transaction.get_active_transaction(obj.id)
        if trans.status != Transaction.STATUS_ERROR:
            self.message_user(
                request,
                "The active transaction for item {} is not in an error state and cannot be refunded"
                .format(obj.id),
                level=messages.ERROR)
        else:
            obj.refund()
コード例 #3
0
 def error(self, request, *args, **kwargs):
     """
     Create an error transaction if the latest transaction is being processed and it's location is 'routable'
     :param request: The Request object
     :param args: Arguments
     :param kwargs: Key word arguments
     :return: Response
     """
     trans = Transaction.get_active_transaction(kwargs['id'])
     if trans.status != Transaction.STATUS_PROCESSING or trans.location != Transaction.LOCATION_ROUTABLE:
         return Response(data={
             "status":
             "error",
             "details":
             "Transactions not in correct state: [{}, {}]".format(
                 trans.status, trans.location)
         },
                         status=status.HTTP_400_BAD_REQUEST)
     trans.item.error()
     return Response(self.get_serializer(trans.item).data)