/// <summary>
        /// Authorize Credit Card Async.
        /// </summary>
        /// <returns>ANetAuthorizeCreateTransactionResponse instance</returns>
        /// <param name="transaction">TransactionRequest.</param>
        /// <param name="refId">Reference identifier.</param>
        public async Task <ANetAuthorizeTransactionResponse> AuthorizeAsync(ANetAuthorizeTransactionRequest transaction, string refId)
        {
            var createRequest          = new ANetAuthorizeCreateTransactionRequest();
            var requestBody            = new ANetAuthorizeTransactionRequestBody();
            var merchantAuthentication = getMerchantAuthentication();

            transaction.TransactionType        = ANetTransactionType.authOnlyTransaction;
            requestBody.MerchantAuthentication = merchantAuthentication;
            requestBody.RefId = refId;
            requestBody.TransactionRequest         = transaction;
            createRequest.CreateTransactionRequest = requestBody;
            return(await authorizeAsync(createRequest));
        }
        /// <summary>
        /// Authorize Credit Card Async.
        /// </summary>
        /// <returns>ANetAuthorizeCreateTransactionResponse instance</returns>
        /// <param name="creditCard">Credit card</param>
        /// <param name="refId">Reference identifier</param>
        /// <param name="amount">Amount</param>
        public async Task <ANetAuthorizeTransactionResponse> AuthorizeAsync(ANetCreditCard creditCard, string refId, decimal amount)
        {
            var createRequest          = new ANetAuthorizeCreateTransactionRequest();
            var requestBody            = new ANetAuthorizeTransactionRequestBody();
            var merchantAuthentication = getMerchantAuthentication();
            var transaction            = new ANetAuthorizeTransactionRequest();
            var payment = new ANetPayment
            {
                CreditCard = creditCard
            };

            transaction.Payment                = payment;
            transaction.Amount                 = amount;
            transaction.TransactionType        = ANetTransactionType.authOnlyTransaction;
            requestBody.MerchantAuthentication = merchantAuthentication;
            requestBody.RefId = refId;
            requestBody.TransactionRequest         = transaction;
            createRequest.CreateTransactionRequest = requestBody;
            return(await authorizeAsync(createRequest));
        }
        private async Task <ANetAuthorizeTransactionResponse> authorizeAsync(ANetAuthorizeCreateTransactionRequest request)
        {
            var json      = JSON.SerializeObject(request);
            var strResult = await _endPoint.PostStringAsync(json).ReceiveString();

            var entity = JSON.DeserializeObject <ANetAuthorizeCreateTransactionResponse>(strResult);

            if (entity.TransactionResponse != null)
            {
                return(entity.TransactionResponse);
            }
            else
            {
                //return a new transactionResponse object with the message list
                var errorEntity = new ANetAuthorizeTransactionResponse();
                var messages    = JSON.DeserializeObject <ANetCreateResponseMessages>(strResult);
                errorEntity.ResponseCode = ANetResponseCodeType.Error;
                errorEntity.Messages     = messages.ToMessageEnumerable();
                return(errorEntity);
            }
        }