Exemplo n.º 1
0
        public IReversalCommand CreateReversalCommand(XmlElement settings)
        {
            ReversalCommand cmd = new ReversalCommand(_transport, this);

            cmd.Status += RaiseIntermediateStatusEvent;
            ReadSettings(cmd, settings);
            return(cmd);
        }
        /// <summary>
        /// This command reverses a payment-procedure and transfers the receipt-number of the transaction to be reversed.
        /// <list type="bullet">
        /// <item><term>Will return null if termimal is not responding after timeout.</term></item>
        /// </list>
        /// </summary>
        /// <param name="receiptNumber">Receipt-number of the transaction to be reversed.</param>
        /// <returns>Result of the reversal process. Returns null if terminal is not responding after timeout.</returns>
        public ZvtPaymentResult ReversePayment(int receiptNumber)
        {
            try {
                ReversalCommand revers = (ReversalCommand)_ZvtEnvironment.CreateReversalCommand(null);
                revers.ReceiptNr = receiptNumber;                 //(int)XmlHelper.ReadInt((XmlElement)config.DocumentElement.SelectSingleNode("Reversal"), "ReceiptNr");
                PaymentResult result = revers.Execute();

                return((result != null) ? new ZvtPaymentResult(result) : null);
            } catch (ConnectionTimeOutException e) {
                Debug.WriteLine(e.Message);
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name='args'>
        /// The command-line arguments.
        /// </param>
        public static void Main(string[] args)
        {
            LogManager.Global = new LogManager(true, new TextLogger(null, LogLevel.Everything, "Wiffzack", Starter.getFileLoggerStream()));
            //create XML file with result message
            XmlDocument resultXML = new XmlDocument();
            XmlElement  rootNode  = resultXML.CreateElement("Result");

            resultXML.AppendChild(rootNode);
            //check if the first argument is a file
            if (args == null || args.Length != 1 || !File.Exists(args[0]))
            {
                LogManager.Global.GetLogger("Wiffzack").Info("Please pass a XML configuration file as first argument!");
                XmlHelper.WriteBool(rootNode, "Success", false);
                XmlHelper.WriteInt(rootNode, "ProtocolSpecificErrorCode", -1);
                XmlHelper.WriteString(rootNode, "ProtocolSpecificErrorDescription", "Please pass a XML configuration file as first argument!");
                //save file in /tmp/result.xml
                try{
                    resultXML.Save(Starter.result);
                }catch (Exception saving) {
                    LogManager.Global.GetLogger("Wiffzack").Info("Error Saving Result");
                    LogManager.Global.GetLogger("Wiffzack").Info(saving.Message);
                }
                return;
            }
            if (args[0].Equals("?"))
            {
                LogManager.Global = new LogManager(true, new TextLogger(null, LogLevel.Everything, "Wiffzack", Console.Out));
                Console.WriteLine("reversal <config.xml>");
                printHelp();
                return;
            }

            //load the XML file
            XmlDocument config = new XmlDocument();

            try {
                config.Load(args[0]);
            }
            //if any exception occur, the XML file could not be read and thus the program stops
            catch (Exception) {
                LogManager.Global.GetLogger("Wiffzack").Info("Your XML was probably bad...");
                XmlHelper.WriteBool(rootNode, "Success", false);
                XmlHelper.WriteInt(rootNode, "ProtocolSpecificErrorCode", -2);
                XmlHelper.WriteString(rootNode, "ProtocolSpecificErrorDescription", "Your XML was probably bad.");
                //save file in /tmp/result.xml
                try{
                    resultXML.Save(Starter.result);
                }catch (Exception saving) {
                    LogManager.Global.GetLogger("Wiffzack").Info("Error Saving Result");
                    LogManager.Global.GetLogger("Wiffzack").Info(saving.Message);
                }
                return;
            }
            //initialise environment with the configuration file and execute command
            try{
                ICommandEnvironment environment = new ZVTCommandEnvironment(config.DocumentElement);
                environment.StatusReceived += new IntermediateStatusDelegate(environment_StatusReceived);
                ReversalCommand revers = (ReversalCommand)environment.CreateReversalCommand(null);
                revers.ReceiptNr = (int)XmlHelper.ReadInt((XmlElement)config.DocumentElement.SelectSingleNode("Reversal"), "ReceiptNr");
                PaymentResult result = revers.Execute();
                //create XML file with result message
                result.SerializeToXml(resultXML.DocumentElement);
                if (result.Data != null)
                {
                    result.Data.WriteXml(resultXML.DocumentElement);
                }
                //save file in /tmp/result.xml
                resultXML.Save(Starter.result);
                //debug message --> remove later
                LogManager.Global.GetLogger("Wiffzack").Info("XML file created");
            }catch (System.ArgumentException) {
                LogManager.Global.GetLogger("Wiffzack").Info("Bad Xml Argument");
                XmlHelper.WriteBool(rootNode, "Success", false);
                XmlHelper.WriteInt(rootNode, "ProtocolSpecificErrorCode", -3);
                XmlHelper.WriteString(rootNode, "ProtocolSpecificErrorDescription", "Bad Xml Argument");
                //save file in /tmp/result.xml
                try{
                    resultXML.Save(Starter.result);
                }catch (Exception saving) {
                    LogManager.Global.GetLogger("Wiffzack").Info("Error Saving Result");
                    LogManager.Global.GetLogger("Wiffzack").Info(saving.Message);
                }
                return;
            }catch (System.FormatException fe) {
                LogManager.Global.GetLogger("Wiffzack").Info("Bad Xml Argument");
                XmlHelper.WriteBool(rootNode, "Success", false);
                XmlHelper.WriteInt(rootNode, "ProtocolSpecificErrorCode", -3);
                XmlHelper.WriteString(rootNode, "ProtocolSpecificErrorDescription", fe.Message);
                //save file in /tmp/result.xml
                try{
                    resultXML.Save(Starter.result);
                }catch (Exception saving) {
                    LogManager.Global.GetLogger("Wiffzack").Info("Error Saving Result");
                    LogManager.Global.GetLogger("Wiffzack").Info(saving.Message);
                }
                return;
            }catch (System.Net.Sockets.SocketException ce) {
                LogManager.Global.GetLogger("Wiffzack").Info("Connection Error: " + ce.Message);
                XmlHelper.WriteBool(rootNode, "Success", false);
                XmlHelper.WriteInt(rootNode, "ProtocolSpecificErrorCode", -4);
                XmlHelper.WriteString(rootNode, "ProtocolSpecificErrorDescription", ce.Message);
                //save file in /tmp/result.xml
                try{
                    resultXML.Save(Starter.result);
                }catch (Exception saving) {
                    LogManager.Global.GetLogger("Wiffzack").Info("Error Saving Result");
                    LogManager.Global.GetLogger("Wiffzack").Info(saving.Message);
                }
                return;
            }catch (ConnectionTimeOutException ce) {
                LogManager.Global.GetLogger("Wiffzack").Info("Network Error:" + ce.Message);
                XmlHelper.WriteBool(rootNode, "Success", false);
                XmlHelper.WriteInt(rootNode, "ProtocolSpecificErrorCode", -150);
                XmlHelper.WriteString(rootNode, "ProtocolSpecificErrorDescription", ce.Message);
                try{
                    resultXML.Save(Starter.result);
                }catch (Exception saving) {
                    LogManager.Global.GetLogger("Wiffzack").Info("Error Saving Result");
                    LogManager.Global.GetLogger("Wiffzack").Info(saving.Message);
                }
            }catch (Exception e) {
                LogManager.Global.GetLogger("Wiffzack").Info("System Error:" + e.Message);
                XmlHelper.WriteBool(rootNode, "Success", false);
                XmlHelper.WriteInt(rootNode, "ProtocolSpecificErrorCode", -255);
                XmlHelper.WriteString(rootNode, "ProtocolSpecificErrorDescription", e.Message);
                //save file in /tmp/result.xml
                try{
                    resultXML.Save(Starter.result);
                }catch (Exception saving) {
                    LogManager.Global.GetLogger("Wiffzack").Info("Error Saving Result");
                    LogManager.Global.GetLogger("Wiffzack").Info(saving.Message);
                }
                return;
            }
        }
Exemplo n.º 4
0
 public IReversalCommand CreateReversalCommand(XmlElement settings)
 {
     ReversalCommand cmd = new ReversalCommand(_transport, this);
     cmd.Status += RaiseIntermediateStatusEvent;
     ReadSettings(cmd, settings);
     return cmd;
 }