Ejemplo n.º 1
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}");
            }
        }
Ejemplo n.º 2
0
        bool WaitForCard(
            ActiveXConnectAPI api,
            string requiredFlag,
            string ExpectedCardCurrency,
            out string lastFourDigits,
            out string errorText)
        {
            errorText      = null;
            lastFourDigits = null;

            ConsoleGui.Info("*** Please insert card");
            while (true)
            {
                if (!ProcessEventsUntil(api, "OnCard", 30))
                {
                    errorText = "Timeout waiting for card to be inserted into device";
                    return(false);
                }

                if (ContainsFlag(api.Flags, requiredFlag))
                {
                    ConsoleGui.Ok("CARD is payment card");
                    break;
                }
                else
                {
                    ConsoleGui.Warning("Not payment card. Probably it's loyalty/discount card, so calculate discount/loyalty points here... and wait for next CARD event");
                }
            }

            if (api.CurrencyCode != ExpectedCardCurrency)
            {
                errorText = $"Currency mismatch. Expecting:{ExpectedCardCurrency} reveiced:[{api.CurrencyCode}]";
                return(false);
            }

            if (ContainsFlag(api.Flags, "ReqLastFourDigits"))
            {
                lastFourDigits = ConsoleGui.EnterValue <string>("Please enter last 4 digits of the card");
            }

            return(true);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public long Authorize(long amount, string documentNr, string currencyCode, out string errorText, out string operationID)
        {
            errorText   = null;
            operationID = null;

            ActiveXConnectAPI a = GetAPI();

            if (a == null)
            {
                errorText = "Failed to load API library";
                return(0);
            }

            ConsoleGui.Info("*** Please insert card");
            while (true)
            {
                if (!ProcessEventsUntil(a, "OnCard", 30))
                {
                    errorText = "Timeout waiting for card to be inserted into device";
                    return(0);
                }

                if (ContainsFlag(a.Flags, "AllowAuthorize"))
                {
                    ConsoleGui.Ok("CARD is payment card");
                    break;
                }
                else
                {
                    ConsoleGui.Warning("This is not payment card, most probably it's loyalty/discount card, so calculate discount/loyalty points here... and wait for next CARD event");
                }
            }

            if (a.CurrencyCode != currencyCode)
            {
                errorText = String.Format("Currency '{0}' code is not supported", a.CurrencyCode);
                return(0);
            }

            string lastFourDigits = null;

            if (ContainsFlag(a.Flags, "ReqLastFourDigits"))
            {
                lastFourDigits = ConsoleGui.EnterValue <string>("Please enter last 4 digits of the card");
            }

            ConsoleGui.Info("calling Authorize() method...");
            a.Authorize(amount, 0, documentNr, lastFourDigits);

            if (!ProcessEventsUntil(a, "OnAuthorizeResult", 100))
            {
                errorText = "Timeout waiting for OnAuthorizeResult";
                return(0);
            }

            if (a.OperationResult != "OK")
            {
                errorText = a.Text;
                return(0);
            }

            operationID = a.OperationID;

            if (a.AmountAuthorized == 0)
            {
                errorText = "Authorization declined";
            }

            return(a.AmountAuthorized);
        }
Ejemplo n.º 5
0
        public void Run()
        {
            var choice = "";

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("---------------------------");
                Console.WriteLine("    Main Menu");
                Console.WriteLine("---------------------------");
                Console.WriteLine(" 1. New tender");
                Console.WriteLine(" 2. Void transaction");
                Console.WriteLine(" 3. Close day");
                Console.WriteLine(" 4. GSM purchase");
                Console.WriteLine(" 5. Partial void");
                Console.WriteLine(" 6. PreAuthorization");
                Console.WriteLine(" 7. Increment PreAuthorization");
                Console.WriteLine(" 8. Complete PreAuthorization");
                Console.WriteLine(" 9. Get PreAuthorization state");
                Console.WriteLine(" X. Exit");
                Console.WriteLine("");

                choice = ConsoleGui.EnterValue <string>("Select a task").ToUpper();
                switch (choice)
                {
                case "Q":
                case "X":
                case "QUIT":
                case "EXIT":
                    return;

                case "1":
                {
                    NewTender();

                    ConsoleGui.Info("Trying to close document that was used for tender...");
                    bool result = AttemptToCloseUnclosedDocuments();
                    // we ignore result because it will not be error if it fails because
                    // document will be closed after next purchase or before close day
                }
                break;

                case "2":
                    PerformVoid();
                    break;

                case "3":
                    CloseDay();
                    break;

                case "4":
                    GsmPurchase();
                    break;

                case "5":
                    PerformVoidPartial();
                    break;

                case "6":
                    NewTenderPreAuthorize();
                    break;

                case "7":
                    PreIncrementGui();
                    break;

                case "8":
                    PreCompleteGui();
                    break;

                case "9":
                    PerformGetTranState();
                    break;

                case "LIST DOC":
                    PickDocuments();
                    break;


                case "LIST DOC ALL":
                    PickDocuments(ShowCloseds: true);
                    break;

                case "LIST":
                case "LIST TRAN":
                {
                    PickTransaction(ShowClosedDocs: true, ShowVoidedTrans: true);
                    break;
                }

                case "?":
                case "H":
                case "HELP":
                    Help();
                    break;

                default:
                    ConsoleGui.Warning("Unknown option");
                    break;
                }
            }
        }