Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public override void ReadSettings(XmlElement settings)
 {
     _outsideStatusInformation = StatusInformationApdu.CreateFromIData(settings);
     ReceiptNr = (int)_outsideStatusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.ReceiptNr).DecodeNumber();
 }
        public ZvtStatusInformation(StatusInformationApdu statusInformation)
        {
            if (statusInformation == null)
            {
                return;
            }

            SourceApdu = statusInformation;

            var statusParam = statusInformation.FindParameter <StatusInformationResultCode>(StatusInformationApdu.StatusParameterEnum.ResultCode);

            Status = statusParam?.ResultCode;

            var amountParam = statusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.Amount);

            Amount = amountParam?.DecodeNumber();

            var traceNrParam = statusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.TraceNr);

            TraceNr = traceNrParam?.DecodeNumber();

            var originalTraceNrParam = statusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.OriginalTraceNr);

            OriginalTraceNr = originalTraceNrParam?.DecodeNumber();

            var timeParam = statusInformation.FindParameter <StatusTimeParameter>(StatusInformationApdu.StatusParameterEnum.Time);
            var dateParam = statusInformation.FindParameter <StatusDateParameter>(StatusInformationApdu.StatusParameterEnum.Date);

            if (timeParam != null && dateParam != null)
            {
                Time = new DateTime(DateTime.Now.Year, dateParam.Month, dateParam.Day, timeParam.Hour, timeParam.Minute, timeParam.Second);
            }
            else
            {
                Time = null;
            }

            var expiryDateParam = statusInformation.FindParameter <StatusExpDateParameter>(StatusInformationApdu.StatusParameterEnum.ExpiryDate);

            if (expiryDateParam != null)
            {
                int actualYear     = expiryDateParam.Year + 2000;
                int lastDayInMonth = DateTime.DaysInMonth(actualYear, expiryDateParam.Month);
                ExpirationDate = new DateTime(actualYear, expiryDateParam.Month, lastDayInMonth, 23, 59, 59);
            }
            else
            {
                ExpirationDate = null;
            }

            var terminalIdParam = statusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.TerminalId);

            TerminalId = terminalIdParam?.DecodeNumber();

            var sequenceNumberParam = statusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.SequenceNumber);

            SequencNumber = sequenceNumberParam?.DecodeNumber();

            var receiptNumberParam = statusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.ReceiptNr);

            ReceiptNr = receiptNumberParam?.DecodeNumber();

            var paymentTyperParam = statusInformation.FindParameter <StatusPaymentTypeParam>(StatusInformationApdu.StatusParameterEnum.PaymentType);

            PaymentType = paymentTyperParam?.PaymentType;

            var panEfId = statusInformation.FindParameter <StatusPanEfId>(StatusInformationApdu.StatusParameterEnum.PanEfId);

            PanEfId = panEfId?.DecodeNumberAsString();

            var cardTypeParam = statusInformation.FindParameter <SingleByteParameter>(StatusInformationApdu.StatusParameterEnum.CardType);

            if (cardTypeParam?.MyByte != null)
            {
                CardType = (ZvtCardType)cardTypeParam.MyByte;
            }

            var cardTypeIdParam = statusInformation.FindParameter <SingleByteParameter>(StatusInformationApdu.StatusParameterEnum.CardTypeID);

            CardTypeId = cardTypeIdParam?.MyByte;

            var cardTypeNameParam = statusInformation.FindParameter <AsciiLVarParameter>(StatusInformationApdu.StatusParameterEnum.CardTypeName);

            CardTypeName = cardTypeNameParam?.Text;

            var additionalTextForCcParam = statusInformation.FindParameter <AsciiLVarParameter>(StatusInformationApdu.StatusParameterEnum.AdditionalTextForCC);

            AdditionalTextForCreditCards = additionalTextForCcParam?.Text;

            var contactNumberForCcParam = statusInformation.FindParameter <AsciiFixedSizeParameter>(StatusInformationApdu.StatusParameterEnum.ContractNumberForCC);

            ContractNumberForCreditCards = contactNumberForCcParam?.Text;

            var turnOverNrParam = statusInformation.FindParameter <BCDNumberParameter>(StatusInformationApdu.StatusParameterEnum.TurnoverNr);

            TurnOverNumber = turnOverNrParam?.DecodeNumber();
        }