public override PaymentResult Execute()
        {
            try
            {
                PaymentResult result = new PaymentResult();
                result.Success = true;

                if (_environment.RaiseAskOpenConnection())
                {
                    _transport.OpenConnection();
                }

                ApduCollection apdus = _commandTransmitter.TransmitAPDU(_apdu);
                CheckForAbortApdu(result, apdus);
                if (result.Success)
                {
                    //Contains the result (success or failure) and much information about the transaction
                    StatusInformationApdu statusInformation = apdus.FindFirstApduOfType <StatusInformationApdu>();
                    result.Data = statusInformation;
                }

                result.PrintDocuments = _commandTransmitter.PrintDocuments;

                return(result);
            }
            finally
            {
                if (_environment.RaiseAskCloseConnection())
                {
                    _transport.CloseConnection();
                }
            }
        }
示例#2
0
        public override CommandResult Execute()
        {
            try
            {
                CommandResult result = new CommandResult();
                result.Success = true;

                if (_environment.RaiseAskOpenConnection())
                {
                    _transport.OpenConnection();
                }

                ApduCollection apdus = _commandTransmitter.TransmitAPDU(_apdu);
                CheckForAbortApdu(result, apdus);
                result.PrintDocuments = _commandTransmitter.PrintDocuments;
                return(result);
            }
            finally
            {
                if (_environment.RaiseAskCloseConnection())
                {
                    _transport.CloseConnection();
                }
            }
        }
示例#3
0
        public static bool CheckForAbortApdu(CommandResult cmdResult, ApduCollection collection)
        {
            AbortApduResponse abort = collection.FindFirstApduOfType <AbortApduResponse>();

            if (abort != null)
            {
                cmdResult.Success = false;
                cmdResult.ProtocolSpecificErrorCode        = (byte)abort.ResultCode;
                cmdResult.ProtocolSpecificErrorDescription = abort.ResultCode.ToString();
                return(true);
            }

            StatusApdu status = collection.FindFirstApduOfType <StatusApdu>();

            if (status != null && status.Status != StatusCodes.ErrorIDEnum.NoError)
            {
                cmdResult.Success = false;
                cmdResult.ProtocolSpecificErrorCode        = (byte)status.Status;
                cmdResult.ProtocolSpecificErrorDescription = status.Status.ToString();
                return(true);
            }



            return(false);
        }
示例#4
0
        public PaymentResult Execute()
        {
            if (_environment.RaiseAskOpenConnection())
            {
                _transport.OpenConnection();
            }
            ApduCollection responses = _commandTransmitter.TransmitAPDU(_apdu);

            if (_environment.RaiseAskCloseConnection())
            {
                _transport.CloseConnection();
            }

            //Contains the result (success or failure) and much information about the transaction
            StatusInformationApdu statusInformation = responses.FindFirstApduOfType <StatusInformationApdu>();

            //Completion is only sent if everything worked fine
            CompletionApduResponse completion = responses.FindFirstApduOfType <CompletionApduResponse>();

            //Abort is only sent if something went wrong
            AbortApduResponse abort = responses.FindFirstApduOfType <AbortApduResponse>();

            //If the terminal is not registered a application layer nack (0x84 XX XX) is sent
            StatusApdu status = responses.FindFirstApduOfType <StatusApdu>();

            bool   success          = true;
            int?   errorCode        = null;
            string errorDescription = "";

            if (completion == null && abort != null)
            {
                success          = false;
                errorCode        = (byte)abort.ResultCode;
                errorDescription = abort.ResultCode.ToString();
            }
            else if (statusInformation != null)
            {
                StatusInformationResultCode result = statusInformation.FindParameter <StatusInformationResultCode>(StatusInformationApdu.StatusParameterEnum.ResultCode);

                if (result.ResultCode != StatusCodes.ErrorIDEnum.NoError)
                {
                    success          = false;
                    errorCode        = (byte)result.ResultCode;
                    errorDescription = result.ResultCode.ToString();
                }
            }
            else if (status != null && status.Status != StatusCodes.ErrorIDEnum.NoError)
            {
                success          = false;
                errorCode        = (byte)status.Status;
                errorDescription = status.Status.ToString();
            }

            PaymentResult authResult = new PaymentResult(success, errorCode, errorDescription, statusInformation);

            authResult.PrintDocuments = _commandTransmitter.PrintDocuments;
            return(authResult);
        }
示例#5
0
        public void Execute()
        {
            if (_environment.RaiseAskOpenConnection())
            {
                _transport.OpenConnection();
            }
            ApduCollection responses = _commandTransmitter.TransmitAPDU(_initialisation);

            if (_environment.RaiseAskCloseConnection())
            {
                _transport.CloseConnection();
            }
        }
示例#6
0
        public virtual U Execute()
        {
            if (_environment.RaiseAskOpenConnection())
            {
                _transport.OpenConnection();
            }
            ApduCollection responses = _commandTransmitter.TransmitAPDU(_apdu);

            if (_environment.RaiseAskCloseConnection())
            {
                _transport.CloseConnection();
            }

            return(null);
        }
        public ApduCollection TransmitAPDU(IZvtApdu apdu)
        {
            foreach (IApduHandler apduHandler in _apduHandlers)
            {
                apduHandler.StartCommand();
            }


            _transport.Transmit(_transport.CreateTpdu(apdu));

            ApduCollection responses = new ApduCollection();

            while (true)
            {
                byte[] apduData = _transport.ReceiveResponsePacket();
                byte[] apduCopy = new byte[apduData.Length];
                Array.Copy(apduData, apduCopy, apduData.Length);
                IZvtApdu responseApdu = ApduResponse.Create(apduData);

                if (responseApdu == null)
                {
                    throw new ArgumentException("Could not retrieve response");
                }

                if (this.ResponseReceived != null)
                {
                    ResponseReceived(responseApdu);
                }

                responses.Add(responseApdu);

                CallResponseApduHandlers(apdu, responseApdu);

                if (IsCompletionPacket == null && InternalIsCompletionPacket(apdu, responseApdu))
                {
                    break;
                }
                else if (IsCompletionPacket != null && IsCompletionPacket(apdu, responseApdu))
                {
                    break;
                }
            }

            return(responses);
        }
        public override CommandResult Execute()
        {
            List <IPrintDocument> printDocuments = new List <IPrintDocument>();
            CommandResult         result         = new CommandResult();

            result.Success = true;

            try
            {
                if (_environment.RaiseAskOpenConnection())
                {
                    _transport.OpenConnection();
                }

                if (_printSystemInfo)
                {
                    ApduCollection apdus = _commandTransmitter.TransmitAPDU(_systemInfo);
                    printDocuments.AddRange(_commandTransmitter.PrintDocuments);
                    CheckForAbortApdu(result, apdus);
                }

                if (_printReport && result.Success)
                {
                    ApduCollection apdus = _commandTransmitter.TransmitAPDU(_apdu);
                    printDocuments.AddRange(_commandTransmitter.PrintDocuments);
                    CheckForAbortApdu(result, apdus);
                }
            }
            finally
            {
                if (_environment.RaiseAskCloseConnection())
                {
                    _transport.CloseConnection();
                }
            }

            result.PrintDocuments = printDocuments.ToArray();
            return(result);
        }
        public InitialisationResult Execute()
        {
            InitialisationResult result = new InitialisationResult();

            result.Success = true;

            try
            {
                if (_environment.RaiseAskOpenConnection())
                {
                    _transport.OpenConnection();
                }

                MagicResponseCommandTransmitter commandTransmitter = new MagicResponseCommandTransmitter(_transport);
                commandTransmitter.ResponseReceived += new Action <IZvtApdu>(commandTransmitter_ResponseReceived);
                commandTransmitter.StatusReceived   += new Action <IntermediateStatusApduResponse>(commandTransmitter_StatusReceived);

                ApduCollection         responses      = commandTransmitter.TransmitAPDU(_registration);
                CompletionApduResponse completionApdu = responses.FindFirstApduOfType <CompletionApduResponse>();

                if (completionApdu == null)
                {
                    throw new NotSupportedException("Did not receive Completion from RegistrationApdu");
                }

                //if statusbyte is not supplied (== null) no extra action need to be performed
                CompletionStatusByteParameter statusByte = completionApdu.FindParameter <CompletionStatusByteParameter>(CompletionApduResponse.ParameterTypeEnum.StatusByte);


                if (statusByte != null && statusByte.InitialisationNecessary)
                {
                    _log.Info("PT needs initialisation");

                    InitialisationApdu init  = new InitialisationApdu();
                    ApduCollection     apdus = commandTransmitter.TransmitAPDU(init);

                    AbortApduResponse abort = apdus.FindFirstApduOfType <AbortApduResponse>();

                    if (abort != null)
                    {
                        _log.Info("Initialisation failed with '{0}({1})'", abort.ResultCode, (byte)abort.ResultCode);

                        result.Success = false;
                        result.ProtocolSpecificErrorCode        = (byte)abort.ResultCode;
                        result.ProtocolSpecificErrorDescription = abort.ResultCode.ToString();
                    }
                }

                if (statusByte != null && statusByte.DiagnosisNecessary && result.Success)
                {
                    _log.Info("PT needs diagnosis");

                    DiagnosisApdu  diag  = new DiagnosisApdu();
                    ApduCollection apdus = commandTransmitter.TransmitAPDU(diag);

                    AbortApduResponse abort = apdus.FindFirstApduOfType <AbortApduResponse>();

                    if (abort != null)
                    {
                        _log.Fatal("Diagnosis failed with '{0}({1})'", abort.ResultCode, (byte)abort.ResultCode);

                        result.Success = false;
                        result.ProtocolSpecificErrorCode        = (byte)abort.ResultCode;
                        result.ProtocolSpecificErrorDescription = abort.ResultCode.ToString();
                    }
                }

                result.PrintDocuments = commandTransmitter.PrintDocuments;
            }
            finally
            {
                if (_environment.RaiseAskCloseConnection())
                {
                    _transport.CloseConnection();
                }
            }


            return(result);
        }