public static void LoadBalance(string _guid, float _amount, OnSetDisplayMessage onComplete = null) { if (IsPassengerExists(_guid)) { PassengerData passenger = GetPassengerData(_guid); if (_amount > 0) { passenger.balance += _amount; SetUpdatePassengerData(_guid, passenger); QRTranslator.OnLoadingBalance?.Invoke(false); StationGate.QRProcessed?.Invoke(true, "Load Success", Color.cyan); onComplete?.Invoke(true, passenger.name, "Thankyou!, your current balance is", passenger.balance.ToString(), Color.cyan); } else { StationGate.QRProcessed?.Invoke(true, "Load Failed", Color.red); onComplete?.Invoke(true, passenger.name, "Sorry invalid input amount", "Please try again", Color.red); } } else { StationGate.QRProcessed?.Invoke(true, "Denied", Color.red); onComplete?.Invoke(true, "Unknown", "QR Code is not registered in this system", "Please register at the teller", Color.red); } }
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); } }