/// <summary> /// Sends the encrypted card number to Tokenex for tokenization /// </summary> /// <returns>Token ID</returns> public string Tokenize(string encryptedValue) { //create our client var client = new TokenServicesClient(); //create our token action var action = new TokenizeFromEncryptedValueAction(); action.APIKey = APIKey; action.TokenExID = TokenExID; action.EcryptedData = encryptedValue; action.TokenScheme = TokenTypeEnum.fourTOKENfour; //call to Tokenize Method var result = client.TokenizeFromEncryptedValue(action); if (result.Success) { return(result.Token); } else { return(""); } }
/// <summary> /// Performs a Process Transaction request on First Data Gateway. /// </summary> /// <param name="request"></param> /// <returns></returns> public Response PerformAuthRequest(Request request) { //create our client TokenServicesClient client = new TokenServicesClient(); //create our token action ProcessTransationAction action = new ProcessTransationAction(); //your tokenex credentials action.APIKey = APIKey; action.TokenExID = TokenExID; //is the TransactionRequest json or xml; action.TransactionRequestFormat = TransactionRequestFormatEnum.XML; //what type of transaction we are performing action.TransactionType = TransactionTypeEnum.Authorize; //Get xml request string requestXML = RequestGenerator.GetAuthorizationRequest(request); requestXML = requestXML.Replace("[GATEWAYNAME]", GatewayName); requestXML = requestXML.Replace("[LOGIN]", GatewayLogin); requestXML = requestXML.Replace("[PASSWORD]", GatewayPassword); action.TransactionRequest = requestXML; //call the web service ResultOfProcessTransaction result = client.ProcessTransaction(action); //Generate and populate response object Response response = new Response(); response.GatewayRequestRaw = requestXML; response.GatewayResponseRaw = GetRawResponse(result); Dictionary <string, string> resultsparam = result.Params; //if our call was a success, save authorization code if (resultsparam.ContainsKey("transaction_tag")) { response.TransactionID = resultsparam["transaction_tag"].PadLeft(10, '0');; } // response.TransactionID = result.ReferenceNumber; response.AuthCode = result.Authorization; if (result.Success) { bool authApproved = false; try { if (resultsparam.ContainsKey("transaction_approved")) { authApproved = Convert.ToBoolean(resultsparam["transaction_approved"]); } if (authApproved) { response.ResponseType = TransactionResponseType.Approved; } else { response.ResponseType = TransactionResponseType.Denied; } } catch (Exception e) { response.ResponseType = TransactionResponseType.Error; response.ReasonText = e.InnerException.ToString(); } } else if (!string.IsNullOrEmpty(result.Error)) { response.ResponseType = TransactionResponseType.Error; response.ReasonText = result.Error; } else { response.ResponseType = TransactionResponseType.Denied; response.ReasonText = result.Error; } return(response); }