Quantcast
Viewing all articles
Browse latest Browse all 37

The First Data Global Gateway e4℠ web service API

The First Data Global Gateway e4℠ web service API is a web service that allows third-party applications to process transactions through the Global Gateway e4℠ system.

To use this API we need to create a test account on the First Data website

You can create the account by the following link :

https://firstdata.zendesk.com/entries/407571-First-Data-Global-Gateway-e4-Web-Service-API-Reference-Guide#4

 Image may be NSFW.
Clik here to view.

Once, you create the demo account you will have three terminal in your account.

Image may be NSFW.
Clik here to view.

Now , to use the Rest API you need the following things :

 GatewayId or ExactID and Password

To see the GatewayId and Password : Administration --> Terminals --> Click on any terminal --> Details and you will see the GatewayId and Password

Image may be NSFW.
Clik here to view.

to see the password click on Generate hyperlink.

KeyId and HMAC Key

For KeyId and HMAC Key go to Administration --> Terminals --> Click on terminal (from where we took the GatewayId and Password) --> API Access

Image may be NSFW.
Clik here to view.

you can generate the new key  from "Generate New Key"

GatewayURL

If you are using the demo account then GatewayUrl will be "https://api.demo.globalgatewaye4.firstdata.com/transaction/v12"

and if you are using the production account then GatewayUrl will be "https://api.globalgatewaye4.firstdata.com/transaction/v12"

you can use any version here i am taking v12.

Code for using API

Write the following code

StringBuilder string_builder = new StringBuilder();
            using (StringWriter string_writer = new StringWriter(string_builder))
            {
                using (XmlTextWriter xml_writer = new XmlTextWriter(string_writer))
                {     //build XML string
                    xml_writer.Formatting = Formatting.Indented;
                    xml_writer.WriteStartElement("Transaction");
                     xml_writer.WriteElementString("ExactID", "******-**");//Your Gateway ID
                    xml_writer.WriteElementString("Password", "********");//Password
                    xml_writer.WriteElementString("Transaction_Type", "00");
                    xml_writer.WriteElementString("DollarAmount", "0.25");
                    xml_writer.WriteElementString("Expiry_Date", "1214");
                    xml_writer.WriteElementString("CardHoldersName", "xyz");
                    xml_writer.WriteElementString("Card_Number", "4111111111111111");// demo account validate this card number
                    xml_writer.WriteElementString("VerificationStr2", "123");
                    xml_writer.WriteEndElement();
                    String xml_string = string_builder.ToString();

                    //SHA1 hash on XML string
                    ASCIIEncoding encoder = new ASCIIEncoding();
                    byte[] xml_byte = encoder.GetBytes(xml_string);
                    SHA1CryptoServiceProvider sha1_crypto = new SHA1CryptoServiceProvider();
                    string hash = BitConverter.ToString(sha1_crypto.ComputeHash(xml_byte)).Replace("-", "");
                    string hashed_content = hash.ToLower();

                    //assign values to hashing and header variables
                    string method = "POST\n";
                    string type = "application/xml\n";//REST XML
                    string time = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
                    string url = "/transaction/v12";
                    string keyID = "*****";//your key ID
                     string key = "****************************";//your Hmac key
                    string hash_data = method + type + hashed_content + "\n" + time + "\n" + url;
                    //hmac sha1 hash with key + hash_data
                    HMAC hmac_sha1 = new HMACSHA1(Encoding.UTF8.GetBytes(key)); //key
                    byte[] hmac_data = hmac_sha1.ComputeHash(Encoding.UTF8.GetBytes(hash_data)); //data
                    //base64 encode on hmac_data
                    string base64_hash = Convert.ToBase64String(hmac_data);
                    //string uri = "https://api.globalgatewaye4.firstdata.com/transaction/v12"; //production API Endpoint
                    string uri = "https://api.demo.globalgatewaye4.firstdata.com/transaction/v12";// demo api endpoint
                    //begin HttpWebRequest 
                    HttpWebRequest web_request = (HttpWebRequest)WebRequest.Create(uri);
                    web_request.Method = "POST";
                    web_request.Accept = "application/xml";
                    web_request.Headers.Add("x-gge4-date", time);
                    web_request.Headers.Add("x-gge4-content-sha1", hashed_content);
                    web_request.ContentLength = xml_string.Length;
                    web_request.ContentType = "application/xml";
                    web_request.Headers["authorization"] = "GGE4_API " + keyID + ":" + base64_hash;

                    // send request as stream
                    StreamWriter xml = null;
                    xml = new StreamWriter(web_request.GetRequestStream());
                    xml.Write(xml_string);
                    xml.Close();

                    //get response and read into string
                    string response_string;
                    try
                    {
                        HttpWebResponse web_response = (HttpWebResponse)web_request.GetResponse();
                        using (StreamReader response_stream = new StreamReader(web_response.GetResponseStream()))
                        {
                            response_string = response_stream.ReadToEnd();
                            response_stream.Close();
                        }
                        //load xml
                        XmlDocument xmldoc = new XmlDocument();
                        xmldoc.LoadXml(response_string);
                        XmlNodeList nodelist = xmldoc.SelectNodes("TransactionResult");
                      var  Retrieval_Ref_No = string.Empty;
                       var SequenceNo = string.Empty;
                       var Transaction_Approved = string.Empty;
                       var EXact_Resp_Code = string.Empty;
                      var  Bank_Message = string.Empty;
                        var BankErrorMessage = string.Empty;
                      foreach (XmlNode item1 in nodelist)
                        {
                            foreach (XmlNode item in item1.ChildNodes)
                            {
                                if (item.Name.Equals("Retrieval_Ref_No"))
                                {
                                    Retrieval_Ref_No = item.InnerText;
                                }
                                if (item.Name.Equals("SequenceNo"))
                                {
                                    SequenceNo = item.InnerText;
                                }
                                if (item.Name.Equals("Transaction_Approved"))
                                {
                                    Transaction_Approved = item.InnerText;
                                }
                                if (item.Name.Equals("EXact_Resp_Code"))
                                {
                                    EXact_Resp_Code = item.InnerText;
                                }
                                if (item.Name.Equals("Bank_Message"))
                                {
                                    Bank_Message = item.InnerText;
                                    if (Bank_Message != "Approved")
                                    {
                                        BankErrorMessage = Bank_Message;
                                    }
                                }
                            }
                        }
                        //bind XML source DataList control
                        //DataList1.DataSource = nodelist;
                        //DataList1.DataBind();

                        //output raw XML for debugging
                        //request_label.Text = web_request.Headers.ToString() + HttpUtility.HtmlEncode(xml_string);
                        //response_label.Text = web_response.Headers.ToString() + HttpUtility.HtmlEncode(response_string);

                    }
                    catch (WebException ex)
                    {
                        if (ex.Response != null)
                        {
                            using (HttpWebResponse error_response = (HttpWebResponse)ex.Response)
                            {
                                using (StreamReader reader = new StreamReader(error_response.GetResponseStream()))
                                {
                                    string remote_ex = reader.ReadToEnd();
                                    //error.Text = remote_ex;
                                }
                            }
                        }
                    }
                }
            }

 

For more detail go through the

https://firstdata.zendesk.com/entries/407571-First-Data-Global-Gateway-e4-Web-Service-API-Reference-Guide#4

 

You can download the solution from the following link :

FirstDataApi.zip (11.55 mb)


Viewing all articles
Browse latest Browse all 37

Trending Articles