Transaction Notification

This code steps you through the basics of configuring Web Hooks to handle data that gets posted to a URL that's associated with your BluePay Platform Account. When you're using this code in "test mode," only test transactions are returned.

The following sample code calls a routine from our Code Library.
Download BluePay.cs

/*
* BluePay C#.NET Sample code.
*
* This code sample shows a very based approach
* on handling data that is posted to a script running
* a merchant's server after a transaction is processed
* through their BluePay gateway account.
*/

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

namespace BP
{
    class Trans_Notify
    {
        public Trans_Notify()
        {
        }

        public static void Main()
        {

            HttpListener listener = new HttpListener();
            string secretKey = "";
            string response = "";

            try
            {
                // Listen for incoming data
                listener.Start();
            }
            catch (HttpListenerException)
            {
                return;
            }
            while (listener.IsListening)
            {
                var context = listener.GetContext();
                var body = new StreamReader(context.Request.InputStream).ReadToEnd();

                byte[] b = Encoding.UTF8.GetBytes("ACK");

                // Return HTTP Status of 200 to BluePay
                context.Response.StatusCode = 200;
                context.Response.KeepAlive = false;
                context.Response.ContentLength64 = b.Length;

                var output = context.Response.OutputStream;
                output.Write(b, 0, b.Length);

                // Get Reponse
                using (StreamReader reader = new StreamReader(output))
                {
                    response = reader.ReadToEnd();
                }
                context.Response.Close();
            }
            listener.Close();
            NameValueCollection vals = HttpUtility.ParseQueryString(response);

            // Parse data into a NVP collection
            string transID = vals["trans_id"];
            string transStatus = vals["trans_stats"];
            string transType = vals["trans_type"];
            string amount = vals["amount"];
            string batchID = vals["batch_id"];
            string batchStatus = vals["batch_status"];
            string totalCount = vals["total_count"];
            string totalAmount = vals["total_amount"];
            string batchUploadID = vals["batch_upload_id"];
            string rebillID = vals["rebill_id"];
            string rebillAmount = vals["rebill_amount"];
            string rebillStatus = vals["rebill_status"];

            // calculate the expected BP_STAMP
            string bpStamp = BluePayPayment.calcTransNotifyTPS(secretKey,
                vals["trans_id"],
                vals["trans_stats"],
                vals["trans_type"],
                vals["amount"],
                vals["batch_id"],
                vals["batch_status"],
                vals["total_count"],
                vals["total_amount"],
                vals["batch_upload_id"],
                vals["rebill_id"],
                vals["rebill_amount"],
                vals["rebill_status"]);

            // Output data if the expected BP_STAMP matches the actual BP_STAMP
            if (bpStamp == vals["BP_STAMP"]) {
                Console.Write("Transaction ID: " + transID);
            Console.Write("Transaction Status: " + transStatus);
            Console.Write("Transaction Type: " + transType);
            Console.Write("Transaction Amount: " + amount);
            Console.Write("Rebill ID: " + rebillID);
            Console.Write("Rebill Amount: " + rebillAmount);
            Console.Write("Rebill Status: " + rebillStatus);
    } else {
                Console.Write("ERROR IN RECEIVING DATA FROM BLUEPAY");
    }
        }
    }
}
BluePay Processing, LLC is a registered ISO of Wells Fargo Bank, N.A., Walnut Creek, CA, U.S.A.
BluePay Canada ULC, is a Registered ISO/MSP of Peoples Trust Company, Vancouver, Canada.