public Response ParseResponse(string responseString) { dynamic responseObject = JObject.Parse(responseString); Response response = new Response { MethodType = responseObject.method, ParsedMethodType = MethodType.Unknown, Amount = responseObject.amount, Currency = responseObject.currency, //... //TODO: avs/cvv2/card/token //... TransactionStatus = responseObject.transaction_status, ParsedTransactionStatus = TransactionStatus.Unknown, ValidationStatus = responseObject.validation_status, TransactionType = responseObject.transaction_type, ParsedTransactionType = TransactionType.Unknown, TransactionId = responseObject.transaction_id, TransactionTag = responseObject.transaction_tag, BankResponseCode = responseObject.bank_resp_code, ParsedBankResponseCode = BankResponseCode.Unknown, BankMessage = responseObject.bank_message, GatewayResponseCode = responseObject.gateway_resp_code, ParsedGatewayResponseCode = GatewayResponseCode.Unknown, GatewayMessage = responseObject.gateway_message, CorrelationId = responseObject.correlation_id, ErrorMessages = new System.Collections.Generic.List <Response.ErrorMessage>() }; #region Parse error messages (if response has any) if (responseObject.Error != null && responseObject.Error.messages != null) { foreach (dynamic error in responseObject.Error.messages) { Response.ErrorMessage msg = new Response.ErrorMessage { Code = error.code, Description = error.description }; response.ErrorMessages.Add(msg); } } #endregion #region Convert response fields into an enum (if possible) if (!string.IsNullOrWhiteSpace(response.MethodType) && MethodTypeByString.ContainsKey(response.MethodType)) { response.ParsedMethodType = MethodTypeByString[response.MethodType]; } if (!string.IsNullOrWhiteSpace(response.TransactionStatus) && TransactionStatusByString.ContainsKey(response.TransactionStatus.ToLower())) { response.ParsedTransactionStatus = TransactionStatusByString[response.TransactionStatus.ToLower()]; } if (!string.IsNullOrWhiteSpace(response.TransactionType) && TransactionTypeByString.ContainsKey(response.TransactionType)) { response.ParsedTransactionType = TransactionTypeByString[response.TransactionType]; } if (!string.IsNullOrWhiteSpace(response.BankResponseCode) && BankResponseCodeByString.ContainsKey(response.BankResponseCode)) { response.ParsedBankResponseCode = BankResponseCodeByString[response.BankResponseCode]; } if (!string.IsNullOrWhiteSpace(response.GatewayResponseCode) && GatewayResponseCodeByString.ContainsKey(response.GatewayResponseCode)) { response.ParsedGatewayResponseCode = GatewayResponseCodeByString[response.GatewayResponseCode]; } #endregion return(response); }
public Response ParseResponse(string responseString) { dynamic responseObject = JObject.Parse(responseString); Response response = new Response { MethodType = responseObject.method, ParsedMethodType = MethodType.Unknown, Amount = responseObject.amount, Currency = responseObject.currency, //... //TODO: avs/cvv2/card/token //... TransactionStatus = responseObject.transaction_status, ParsedTransactionStatus = TransactionStatus.Unknown, ValidationStatus = responseObject.validation_status, TransactionType = responseObject.transaction_type, ParsedTransactionType = TransactionType.Unknown, TransactionId = responseObject.transaction_id, TransactionTag = responseObject.transaction_tag, BankResponseCode = responseObject.bank_resp_code, ParsedBankResponseCode = BankResponseCode.Unknown, BankMessage = responseObject.bank_message, GatewayResponseCode = responseObject.gateway_resp_code, ParsedGatewayResponseCode = GatewayResponseCode.Unknown, GatewayMessage = responseObject.gateway_message, CorrelationId = responseObject.correlation_id, ErrorMessages = new System.Collections.Generic.List<Response.ErrorMessage>() }; #region Parse error messages (if response has any) if (responseObject.Error != null && responseObject.Error.messages != null) { foreach (dynamic error in responseObject.Error.messages) { Response.ErrorMessage msg = new Response.ErrorMessage { Code = error.code, Description = error.description }; response.ErrorMessages.Add(msg); } } #endregion #region Convert response fields into an enum (if possible) if (!string.IsNullOrWhiteSpace(response.MethodType) && MethodTypeByString.ContainsKey(response.MethodType)) { response.ParsedMethodType = MethodTypeByString[response.MethodType]; } if (!string.IsNullOrWhiteSpace(response.TransactionStatus) && TransactionStatusByString.ContainsKey(response.TransactionStatus.ToLower())) { response.ParsedTransactionStatus = TransactionStatusByString[response.TransactionStatus.ToLower()]; } if (!string.IsNullOrWhiteSpace(response.TransactionType) && TransactionTypeByString.ContainsKey(response.TransactionType)) { response.ParsedTransactionType = TransactionTypeByString[response.TransactionType]; } if (!string.IsNullOrWhiteSpace(response.BankResponseCode) && BankResponseCodeByString.ContainsKey(response.BankResponseCode)) { response.ParsedBankResponseCode = BankResponseCodeByString[response.BankResponseCode]; } if (!string.IsNullOrWhiteSpace(response.GatewayResponseCode) && GatewayResponseCodeByString.ContainsKey(response.GatewayResponseCode)) { response.ParsedGatewayResponseCode = GatewayResponseCodeByString[response.GatewayResponseCode]; } #endregion return response; }