public static void ProcessTransaction(string _guid, StationNames _station, StationMatrix _matrix, OnSetDisplayMessage onComplete = null) { if (IsPassengerExists(_guid)) { PassengerData passenger = GetPassengerData(_guid); if (passenger.balance >= 13)//TODO consider replacing magic number to lowest price on matrix { if (!passenger.isOnBoard) { passenger.isOnBoard = true; passenger.stationIn = _station; SetUpdatePassengerData(_guid, passenger); StationGate.QRProcessed?.Invoke(true, "Accepted", Color.green); onComplete?.Invoke(true, passenger.name, "Welcome!, your current balance is: ", passenger.balance.ToString(), Color.green); } else { passenger.stationOut = _station; bool isSuccessful = CalculateTransaction(passenger, _matrix, passenger.stationIn, passenger.stationOut); if (isSuccessful) { passenger.isOnBoard = false; SetUpdatePassengerData(_guid, passenger); StationGate.QRProcessed?.Invoke(true, "Accepted", Color.green); onComplete?.Invoke(true, passenger.name, "Thankyou!, your current balance is: ", passenger.balance.ToString(), Color.green); } else { //TODO handle if balance is insufficient when exiting station StationGate.QRProcessed?.Invoke(false, "Denied", Color.red); onComplete?.Invoke(true, passenger.name, "Sorry your current balance is insufficient, please load at the teller: ", passenger.balance.ToString(), Color.red); } } } else { StationGate.QRProcessed?.Invoke(false, "Denied", Color.red); onComplete?.Invoke(true, passenger.name, "Sorry your current balance is insufficient, please load at the teller: ", passenger.balance.ToString(), Color.red); } } else { StationGate.QRProcessed?.Invoke(false, "Denied", Color.red); onComplete?.Invoke(true, "Unknown", "QR Code is not registered in this system", "Please register at the teller", Color.red); } }
private static bool CalculateTransaction(PassengerData _data, StationMatrix _matrix, StationNames _in, StationNames _out) { foreach (var s in _matrix.GetMatrix()[0].stationMatrices) { if (s.from.Equals(_in)) { foreach (var a in s.stationToStations) { if (a.to.Equals(_out)) { if (_data.balance >= a.price) { float price = a.price == 0? 13: a.price; //Deduct 13 if in and out is the same station _data.balance -= price; return(true); } } } } } return(false); }