private void PerformGetTranState() { string errorText; ConsoleGui.Info($"\n*** GETTRANSTATE"); var selectedObjects = PickTransaction( Prompt: "Select transaction", ShowClosedDocs: true, PreAuthOnly: true ); var document = selectedObjects.SelectedDocument; var transaction = selectedObjects.SelectedTransaction; if (transaction == null) { ConsoleGui.Warning("No transaction selected"); return; } ConsoleGui.Info($"Selected {document.DocumentNr} (Amount:{transaction.AmountAuthorized} OperationId:{transaction.OperationID})"); ConsoleGui.Info($"Calling GetTranState method..."); if (API.GetTranState(transaction.OperationID, transaction.Cryptogram, out errorText, out var state, out var resultCryptogram)) { if (!"Undefined".Equals(state)) { transaction.State = state; } transaction.Cryptogram = resultCryptogram; DocumentManager.SaveDocumentToFile(document); ConsoleGui.Ok($"Transaction state: {state}"); }
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}"); } }
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); }
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"); }
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); }
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(); }
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}"); } }
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); }