Acid.PuntoPagos.Sdk.Transaction.NotificationTransaction C# (CSharp) Method

NotificationTransaction() public method

Verify if the result of payment process was successful or not.
Can throw the exception if there headers "fecha" or "Autorizacion", or if the request does not contain the variables "token", "trx_id" or "monto"
public NotificationTransaction ( NameValueCollection headers, NameValueCollection @params ) : NotificationTransactionDto
headers System.Collections.Specialized.NameValueCollection Headers of Request
@params System.Collections.Specialized.NameValueCollection
return Acid.PuntoPagos.Sdk.Dtos.NotificationTransactionDto
        public NotificationTransactionDto NotificationTransaction(NameValueCollection headers, NameValueCollection @params)
        {
            _logger.Debug("Start NotificationTransaction");
            if (headers == null)
            {
                var error = new ArgumentNullException("headers", "The headers are null");
                _logger.Error("The headers are null", error);
                throw error;
            }
            if(@params == null)
            {
                var error = new ArgumentNullException("params", "The @params is null");
                _logger.Error("The @params are null", error);
                throw error;
            }
            if (headers["fecha"] == null)
            {
                var error = new ArgumentNullException("fecha", "The request not contains header 'fecha'");
                _logger.Error("The request not contains header 'fecha'", error);
                throw error;
            }
            if (headers["Autorizacion"] == null)
            {
                var error = new ArgumentNullException("Autorizacion", "The request not contains header 'Autorizacion'");
                _logger.Error("The request not contains header 'Autorizacion'", error);
                throw error;
            }

            var dateTime = headers.Get("Fecha");
            var notificationTransactionDto = new NotificationTransactionDto(@params);
            _logger.Debug(string.Format("End read data from Request, for Token {0} and TransactionId {1}",
                                        notificationTransactionDto.Token, notificationTransactionDto.TransactionId));

            if (string.IsNullOrEmpty(notificationTransactionDto.Token) || notificationTransactionDto.TransactionId == ulong.MinValue || notificationTransactionDto.Currency == null)
            {
                var error = new ArgumentNullException("token, transactionId, amount", "Some of the following variables do not exist or is empty");
                _logger.Error("Some of the following variables (token, transactionId, amount) do not exist or is empty", error);
                throw error;
            }

            var message = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}", _configuration.GetNotificationTransactionFunction(), "\n",
                                        notificationTransactionDto.Token, notificationTransactionDto.TransactionId, notificationTransactionDto.Currency, dateTime);
            _logger.Debug(string.Format("Generate message for verificate notification transaction: {0}", message));

            notificationTransactionDto.WithError = _authorization.GetAuthorizationHeader(message) != headers.Get("Autorizacion");
            _logger.Info(string.Format("The transaction with token {0} and TransactionId {1}, was {2}",
                                       notificationTransactionDto.Token, notificationTransactionDto.TransactionId,
                                       notificationTransactionDto.IsTransactionSuccessful()
                                           ? "Successful"
                                           : "Unsuccessful"));

            _logger.Debug("End NotificationTransaction");
            return notificationTransactionDto;
        }

Same methods

Transaction::NotificationTransaction ( WebRequest request ) : NotificationTransactionDto