BP_STAMP Validation

This code is intended to be used to validate the value of the BP_STAMP that's returned after a transaction. This value is used as a security check to ensure that the response received from a transaction is authentic and has not been altered in any way.

The following sample code calls a routine from our Code Library.
Download BluePay.php
Or, download via GitHub

/*
* BluePay C#.NET Sample code.
*
* This code sample reads the values from a BP10emu redirect
* and authenticates the message using the the BP_STAMP
* provided in the response. Point the REDIRECT_URL of your
* BP10emu request to the URI prefix specified below.
*/

using System;
using BluePayLibrary;
using System.Collections.Specialized;
using System.Web;
using System.Net;
using System.IO;
using System.Text;

namespace GetData
{
    class ValidateBPStamp
    {
        public static void Main()
        {
            string accountID = "Merchant's Account ID Here";
            string secretKey = "Merchant's Secret Key Here";
            string mode = "TEST";
            string prefix = "Merchant's Target URI Prefix Here" // Set the listener URI (and port if necessary)

            HttpListener listener = new HttpListener();
            listener.Prefixes.Add(prefix);

            try
            {
                // Listen for incoming data
                listener.Start();
            }
            catch (HttpListenerException)
            {
                return;
            }
            while (listener.IsListening)
            {
                var context = listener.GetContext();
                NameValueCollection responsePairs = context.Request.QueryString;
                string msg;
                if (responsePairs["BP_STAMP"] != null) // Check whether BP_STAMP is provided
                {
                    BluePay bp = new BluePay
                    (
                       accountID,
                       secretKey,
                       mode
                    );
                   
                    string bpStampString = "";
                    string[] defSeparator = new string[] { " " };
                    string[] bpStampFields = responsePairs["BP_STAMP_DEF"].Split(defSeparator, StringSplitOptions.RemoveEmptyEntries); // Split BP_STAMP_DEF on whitespace
                    foreach (string field in bpStampFields)
                    {
                        bpStampString += responsePairs[field]; // Concatenate values used to calculate expected BP_STAMP
                    }
                    string expectedStamp = bp.GenerateTPS(bpStampString, responsePairs["TPS_HASH_TYPE"]); // Calculate expected BP_STAMP using hash function specified in response
                    if (expectedStamp == responsePairs["BP_STAMP"]) // Compare expected BP_STAMP with received BP_STAMP
                    {
                        // Validate BP_STAMP and reads the response results
                        msg = "VALID BP_STAMP: TRUE\n";
                        foreach (string key in responsePairs)
                        {
                            msg += (key + ": " + responsePairs[key] + "\n");
                        }
                    }
                    else
                    {
                        msg = "ERROR: BP_STAMP VALUES DO NOT MATCH\n";
                    }
                } else
                {
                    msg = "ERROR: BP_STAMP NOT FOUND. CHECK MESSAGE & RESPONSEVERSION";
                }
                context.Response.ContentLength64 = Encoding.UTF8.GetByteCount(msg);
                context.Response.StatusCode = 200;
                using (Stream stream = context.Response.OutputStream)
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(msg);
                    }
                }
            }
            listener.Close();
        }
    }
}

Can’t find what you’re
looking for? We can help.

Contact 800-350-2684 for Integration Support.

  • Microsoft Gold Partner Badge
  • Susan G. Komen for the Cure Supporter
  • 2018 American Business Awards Gold Stevie® Winner Badge for Best Payment and Electronic Commerce Solution
  • 2018 CNP Awards Customer Choice Winner Badge for Best E-Commerce Platform/Gateway
  • Best in Biz Awards 2018 Silver Winner Badge for Business Development Department of the Year
  • TSG Gateway Awards 2019 BluePay
BluePay Processing, LLC is a registered ISO of Wells Fargo Bank, N.A., Concord, CA, 94524 U.S.A.
BluePay Canada ULC, is a Registered ISO/MSP of Peoples Trust Company, Vancouver, Canada.