示例#1
0
        public bool CloseDay(string operatorID, string operatorName)
        {
            ActiveXConnectAPI api = GetAPI();

            if (api == null)
            {
                return(false);
            }

            if (!UnlockDevice("999", "John", "", 0, ""))
            {
                ConsoleGui.Error("Failed to unlock device");
                return(false);
            }

            ConsoleGui.Info("CloseDay method called");
            api.CloseDay(operatorID, operatorName);

            if (!ProcessEventsUntil(api, "OnCloseDayResult", 130))
            {
                return(false);
            }

            string result = api.OperationResult;

            ConsoleGui.Info($"OnCloseDayResult received with result={result}");
            return(result == "OK");
        }
 static void Main(string[] args)
 {
     try
     {
         Console.WriteLine("ECR implementation example v2.0");
         ReadCliArgs(args);
         new ECR().Run();
     }
     catch (Exception ex)
     {
         ConsoleGui.Error(ex.ToString());
         Console.WriteLine("Press enter to exit...");
         Console.ReadLine();
     }
 }
示例#3
0
        private void PerformVoidPartial()
        {
            ConsoleGui.Info($"\n*** PARTIALVOID");
            var selectedItem = PickTransaction(
                Prompt: "Select transaction to be voided"
                );

            var transaction = selectedItem.SelectedTransaction;
            var document    = selectedItem.SelectedDocument;

            if (transaction == null)
            {
                ConsoleGui.Warning("No transaction selected");
                return;
            }

            var voidAmount = ConsoleGui.EnterValue <long>("Enter amount to be voided");

            if (!API.UnlockDevice("999", "John", "VOID", 0, ""))
            {
                ConsoleGui.Error("Failed to unlock device. Void will not be performed");
                return;
            }

            string errorText;

            if (API.VoidPartialTransaction(transaction.OperationID, transaction.AmountAuthorized, voidAmount, out errorText))
            {
                if (transaction.AmountAuthorized == voidAmount)
                {
                    transaction.IsVoided     = true;
                    transaction.AmountVoided = transaction.AmountAuthorized;
                }
                else
                {
                    transaction.AmountAuthorized -= voidAmount;
                    transaction.AmountVoided     += voidAmount;
                }

                DocumentManager.SaveDocumentToFile(document);

                ConsoleGui.Ok("Transaction was voided");
            }
            else
            {
                ConsoleGui.Error($"Failed to void transaction: {errorText}");
            }
        }
示例#4
0
        public bool CloseDocument(Document document)
        {
            ConsoleGui.Info($"Closing document {document.DocumentNr}");

            ActiveXConnectAPI api = GetAPI();

            if (api == null)
            {
                return(false);
            }

            var operationIdList = new List <string>();

            if (document.Transactions != null)
            {
                foreach (var i in document.Transactions)
                {
                    operationIdList.Add(i.OperationID);
                }
            }

            ConsoleGui.Info("Calling DocClosed() method...");
            api.DocClosed(document.DocumentNr, operationIdList.ToArray());

            if (!ProcessEventsUntil(api, "OnDocClosedResult", 15))
            {
                return(false);
            }

            string result = api.OperationResult;

            if (result == "OK")
            {
                ConsoleGui.Ok($"OnDocClosedResult event received with OperationResult:{result}");
            }
            else
            {
                ConsoleGui.Error($"OnDocClosedResult event received with OperationResult:{result}");
            }

            return(result == "OK");
        }
示例#5
0
        bool WaitTranState(ActiveXConnectAPI api, string DocumentNr, string OperationID, byte[] Cryptogram, out string errorText)
        {
            const int TIMEOUT_SECONDS = 100;

            errorText = null;

            if (!ProcessEventsUntil(api, "OnTranState", TIMEOUT_SECONDS))
            {
                ConsoleGui.Error("Timeout waiting for OnTranState, trying to perform GetTranState by DocumentNr...");

                ConsoleGui.Info("Calling GetTranState method...");
                api.GetTranState(DocumentNr, OperationID, Cryptogram);

                if (!ProcessEventsUntil(api, "OnTranState", TIMEOUT_SECONDS))
                {
                    errorText = "Timeout waiting for OnTranState";
                    return(false);
                }
            }
            ConsoleGui.Ok("OnTranState received");
            return(true);
        }
示例#6
0
        private void GsmPurchase()
        {
            var doc = new Document();

            // It is very important that we "save" document even before we try any GSM operation.
            // This way we can guarantee that docclosed will be sent even if computer power is lost / application crashes or some other fatal error occurs.
            DocumentManager.SaveDocumentToFile(doc);

            string errorText;

            string data = ConsoleGui.EnterValue <string>("Enter GSM barcode to be queried");

            if (API.GsmPurchase(out errorText, data, doc) <= 0)
            {
                ConsoleGui.Error("GSM purchase failed: " + errorText);
            }
            else
            {
                ConsoleGui.Ok("GSM purchase succeeded");
            }

            AttemptToCloseUnclosedDocuments();
        }
示例#7
0
        private void PerformVoid()
        {
            ConsoleGui.Info($"\n*** VOID");
            var selectedItem = PickTransaction(
                Prompt: "Select transaction"
                );

            var document    = selectedItem.SelectedDocument;
            var transaction = selectedItem.SelectedTransaction;

            if (transaction == null)
            {
                ConsoleGui.Warning("No transaction selected");
                return;
            }

            if (!API.UnlockDevice("999", "John", "VOID", 0, ""))
            {
                ConsoleGui.Error("Failed to unlock device. Void will not be performed");
                return;
            }

            string errorText;

            if (API.VoidTransaction(transaction.OperationID, out errorText))
            {
                transaction.IsVoided = true;
                DocumentManager.SaveDocumentToFile(document);

                ConsoleGui.Ok("Transaction was voided");
            }
            else
            {
                ConsoleGui.Error($"Failed to void transaction. {errorText}");
            }
        }