/// <summary> /// Perform an authorization process. /// </summary> /// <param name="sender">Send transaction button.</param> /// <param name="e">Click event arguments.</param> private void InitiateTransaction(object sender, RoutedEventArgs e) { // Limpa o log: this.uxLog.Items.Clear(); ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); return; } currentAuthorizer.OnStateChanged += this.OnTransactionStateChange; try { this.InitiateTransaction(); } catch (Exception ex) { Debug.WriteLine(ex.Message); this.Log("Algo deu errado."); } finally { currentAuthorizer.OnStateChanged -= this.OnTransactionStateChange; } }
/// <summary> /// Performs a forced download of pinpad tables. /// </summary> /// <param name="sender">Download tables button.</param> /// <param name="e">Click event arguments.</param> private void DownloadTables(object sender, RoutedEventArgs e) { // Limpa o log: this.uxLog.Items.Clear(); ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); return; } this.Log("Atualizando..."); bool isUpdated = currentAuthorizer.UpdateTables(1, true); if (isUpdated == true) { this.Log("Tabelas atualizadas com sucesso."); } else { this.Log("Erro ao atualizar as tabelas."); } }
/// <summary> /// Try pinpad reconnection. /// </summary> /// <param name="sender">Reconnection button.</param> /// <param name="e">Click event arguments.</param> private void Reconnect(object sender, RoutedEventArgs e) { // Limpa o log: this.uxLog.Items.Clear(); ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); return; } // Procura a porta serial que tenha um pinpad conectado e tenta estabelecer conexão com ela: bool status = currentAuthorizer.PinpadFacade.Communication.OpenPinpadConnection(); // Verifica se conseguiu se conectar: if (status == true) { this.Log("Pinpad conectado."); } else { this.Log("Pinpad desconectado."); } // Atualiza as labels da tela dos pinpads: foreach (ICardPaymentAuthorizer c in this.Authorizers) { c.PinpadFacade.Display.ShowMessage(c.PinpadMessages.MainLabel, null, DisplayPaddingType.Center); } }
/// <summary> /// Get secure PAN. /// </summary> /// <param name="sender">Get PAN button.</param> /// <param name="e">Click event arguments</param> private void GetPan(object sender, RoutedEventArgs e) { string maskedPan; // Limpa o log: this.uxLog.Items.Clear(); ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); return; } // Get PAN: AuthorizationStatus status = currentAuthorizer.GetSecurePan(out maskedPan); // Verifies if PAN was captured correctly: if (string.IsNullOrEmpty(maskedPan) == true || status != AuthorizationStatus.Approved) { this.Log("O PAN não pode ser capturado."); } else { this.Log(string.Format("PAN capturado: {0}", maskedPan)); } }
/// <summary> /// Envia a transação para a SDK da Stone. /// </summary> /// <param name="transaction">Transação a ser capturada.</param> /// <returns>Report da transação.</returns> private IAuthorizationReport SendRequest(ITransactionEntry transaction) { ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); } IAuthorizationReport response = null; try { ResponseStatus authorizationStatus; response = currentAuthorizer.Authorize(transaction, out authorizationStatus); } catch (ExpiredCardException) { this.Log("Cartão expirado."); currentAuthorizer.PromptForCardRemoval("CARTAO EXPIRADO"); return(null); } catch (CardHasChipException) { this.Log("Cartão possui chip. Insira o cartão."); currentAuthorizer.PromptForCardRemoval("CARTAO POSSUI CHIP"); return(null); } catch (InvalidConnectionException) { this.Log("Computador não está conectado a internet!"); currentAuthorizer.PromptForCardRemoval("SEM CONEXAO"); return(null); } if (response == null) { this.Log("Um erro ocorreu durante a transação."); return(null); } // Handle poi response: this.VerifyPoiResponse(response); // Loga as mensagens de request e response enviadas e recebidas do autorizador da Stone: this.LogTransaction(response); currentAuthorizer.PinpadFacade.Display.ShowMessage(this.PinpadMessages.MainLabel, null, DisplayPaddingType.Center); return(response); }
/// <summary> /// Show a brief description of the pinpad. /// </summary> /// <param name="pinpads">Pinpad to log on console.</param> public static void ShowPinpadOnConsole(this ICardPaymentAuthorizer pinpad) { ICollection <ICardPaymentAuthorizer> pinpads = new List <ICardPaymentAuthorizer>(); pinpads.Add(pinpad); Console.WriteLine( pinpads.Select(s => new { PortName = s.PinpadFacade.Communication.ConnectionName, Manufacturer = s.PinpadFacade.Infos.ManufacturerName.Replace(" ", ""), SerialNumber = s.PinpadFacade.Infos.SerialNumber.Replace(" ", "") }) .ToMarkdownTable()); }
/// <summary> /// Performs a cancellation operation. /// </summary> /// <param name="sender">Cancellation button.</param> /// <param name="e">Click event arguments.</param> private void OnCancelTransaction(object sender, RoutedEventArgs e) { // Limpa o log: this.uxLog.Items.Clear(); ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); return; } string atk = this.uxCbbxTransactions.SelectedItem.ToString(); // Verifica se um ATK válido foi selecionado: if (string.IsNullOrEmpty(atk) == true) { this.Log("Não é possivel cancelar um ATK vazio."); return; } // Seleciona a transação a ser cancelada de acordo com o ATK: IAuthorizationReport transaction = this.approvedTransactions.Where(t => t.AcquirerTransactionKey == atk).First(); // Cancela a transação: ICancellationReport cancelResult = currentAuthorizer.Cancel(transaction.AcquirerTransactionKey, transaction.Amount); if (cancelResult.WasSuccessful == true) { // Cancelamento autorizado. // Retira a transação da coleção de transação aprovadas: this.approvedTransactions.Remove(transaction); this.uxCbbxTransactions.Items.Remove(transaction.AcquirerTransactionKey); } else { // Cancelamento não autorizado: this.Log(string.Format("{0} - {1}", cancelResult.ResponseCode, cancelResult.ResponseReason)); } this.UpdateTransactions(); }
/// <summary> /// Updates pinpad screen with input labels. /// </summary> /// <param name="sender">Screen update button.</param> /// <param name="e">Click event arguments.</param> private void OnShowPinpadLabel(object sender, RoutedEventArgs e) { // Limpa o log: this.uxLog.Items.Clear(); ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); return; } DisplayPaddingType pinpadAlignment; // Define o alinhamento da mensagem a ser mostrada na tela do pinpad: switch (this.uxCbbxAlignment.Text) { case "Direita": pinpadAlignment = DisplayPaddingType.Right; break; case "Centro": pinpadAlignment = DisplayPaddingType.Center; break; default: pinpadAlignment = DisplayPaddingType.Left; break; } // Mostra a mensagom: bool status = currentAuthorizer.PinpadFacade.Display.ShowMessage(this.uxTbxLine1.Text, this.uxTbxLine2.Text, pinpadAlignment); // Atualiza o log: this.Log((status) ? "Mensagem mostrada na tela do pinpad." : "A mensagem não foi mostrada."); if (this.uxOptionWaitForKey.IsChecked == true) { PinpadKeyCode key = PinpadKeyCode.Undefined; // Espera uma tecla ser iniciada. do { key = currentAuthorizer.PinpadFacade.Keyboard.GetKey(); }while (key == PinpadKeyCode.Undefined); this.Log("Tecla <{0}> pressionada!", key); } }
/// <summary> /// Creates all pinpad messages. /// Establishes connection with the pinpad. /// </summary> public PizzaAuthorizer() { this.BoughtPizzas = new Collection <IAuthorizationReport>(); // Creates all pinpad messages: this.PizzaMachineMessages = new DisplayableMessages(); this.PizzaMachineMessages.ApprovedMessage = "Aprovado, nham!"; this.PizzaMachineMessages.DeclinedMessage = "Nao autorizada"; this.PizzaMachineMessages.InitializationMessage = "olá..."; this.PizzaMachineMessages.MainLabel = "pizza machine"; this.PizzaMachineMessages.ProcessingMessage = "assando pizza..."; // Establishes connection with the pinpad. Microtef.Platform.Desktop.DesktopInitializer.Initialize(); this.authorizer = DeviceProvider.ActivateAndGetOneOrFirst(this.StoneCode, this.PizzaMachineMessages); // Attach event to read all transaction status: this.authorizer.OnStateChanged += this.OnStatusChange; }
/// <summary> /// Verifies if the pinpad is connected or not. /// </summary> /// <param name="sender">Ping button.</param> /// <param name="e">Click event arguments.</param> private void PingPinpad(object sender, RoutedEventArgs e) { // Limpa o log: this.uxLog.Items.Clear(); ICardPaymentAuthorizer currentAuthorizer = this.GetCurrentPinpad(); if (currentAuthorizer == null) { this.Log("Selecione um pinpad."); return; } if (currentAuthorizer.PinpadFacade.Communication.Ping() == true) { this.Log("O pinpad está conectado."); currentAuthorizer.PinpadFacade.Display.ShowMessage(currentAuthorizer.PinpadMessages.MainLabel, null, DisplayPaddingType.Center); } else { this.Log("O pinpad está DESCONECTADO."); } }
private GasStationAuthorizer(ICardPaymentAuthorizer authorizer) { this.Authorizer = authorizer; }