private void Beat(object state) { var configuration = RuntimeConfiguration.Instance; if (configuration == null) { return; } try { using (var api = new PaymentSenseRestApi()) { Alive = true; } } finally { Log.Debug($"Heartbeat status: {Alive}"); } }
/// <summary> /// Get the configuratiion data /// </summary> /// <param name="configuration"></param> /// <returns></returns> public Result Init(RuntimeConfiguration configuration) { Log.Info("Init method started..."); //initalise confguration file instance var configFile = AppConfiguration.Instance; try { if (configuration == null) { Log.Info("Can not set configuration to null."); return(ResultCode.GenericError); } if (configuration.PosNumber <= 0) { Log.Info($"Invalid PosNumber {configuration.PosNumber}."); return(ResultCode.GenericError); } using (var api = new PaymentSenseRestApi()) { RuntimeConfiguration.Instance = configuration; Heartbeat.Instance.Start(); Log.Info("Init success!"); return(ResultCode.Success); } } catch (Exception ex) { Log.Error(ex); return(ResultCode.GenericError); } finally { Log.Info("Init method finished."); } }
/// <summary> /// Payment method /// </summary> /// <param name="amount"></param> /// <returns></returns> public Result <PaymentData> Pay(int amount) { Log.Info("Pay method started..."); Log.Info($"Amount = {amount/100.0}."); Result <PaymentData> transactionResult = null; string reciept = string.Empty; try { if (File.Exists(ticketPath)) { File.Delete(ticketPath); } if (amount <= 0) { Log.Info("Invalid pay amount..."); return(ResultCode.GenericError); } var config = RuntimeConfiguration.Instance; var data = new PaymentData(); Log.Info("Calling payment driver..."); using (var api = new PaymentSenseRestApi()) { var payResult = api.Pay(amount, out TransactionDetails payResponse); Log.Info($"Pay Result: {payResult}"); // interogate the result check if payResponse not equal to null if (payResponse == null) { Log.Error("Transaction response error..."); data.Result = PaymentResult.Failed; PrintErrorTicket(data, string.Empty); return(new Result <PaymentData>((ResultCode)payResult, data: data)); } else if (payResult != DiagnosticErrMsg.OK && payResponse != null) { Log.Error($"Pay Result = {payResult} Payment Failed...See Stored Ticket"); data.Result = PaymentResult.Failed; PrintErrorTicket(data, payResponse.TransactionResult); return(new Result <PaymentData>((ResultCode)payResult, data: data)); } else { data.Result = PaymentResult.Successful; data.PaidAmount = amount; Log.Info($"paid Amount: {data.PaidAmount}"); transactionResult = new Result <PaymentData>(ResultCode.Success, data: data); Log.Info($"Payment succeeded transaction result: {transactionResult}"); CreateCustomerTicket(payResponse); data.HasClientReceipt = true; } //persist the transaction // PersistTransaction(payResponse); } return(transactionResult); } catch (Exception ex) { Log.Error(ex); return(ResultCode.GenericError); } finally { Log.Info("Pay method finished..."); } }