Acid.PuntoPagos.Sdk.Dtos.NotificationTransactionDto.IsTransactionSuccessful C# (CSharp) Method

IsTransactionSuccessful() public method

Returns if the result of transacction.

True: if Successful

False: if Unsuccessful

public IsTransactionSuccessful ( ) : bool
return bool
        public bool IsTransactionSuccessful()
        {
            return !WithError;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Verify if the result of payment process was successful or not.
        /// </summary>
        /// <param name="headers">Headers of Request</param>
        /// <param name="params">Parameters of Request</param>
        /// <returns>NotificationTransactionDto with contains result of the process and data of the payment</returns>
        /// <exception cref="ArgumentNullException">Can throw the exception if there headers "fecha" or "Autorizacion", or if the request does not contain the variables "token", "trx_id" or "monto"</exception>
        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;
        }