//Define a command object for populating command parametersPK_PaymentKey_Activate_Command PK_Command =
new PK_PaymentKey_Activate_Command();
//Build the command to send to the PaymentKeys Application FrameworkPK_Command.command =
"paymentkey.activate";
PK_Command.version =
"1.0";
PK_Command.api_call_id = Guid.NewGuid.ToString;
PK_Command.paymentkey =
"v1111_00000_00000_00000.pk";
//Serialize the command objectSystem.Web.Script.Serialization.JavaScriptSerializer serializer =
new System.Web.Script.Serialization.JavaScriptSerializer();
string api_call = serializer.Serialize(PK_Command);
//Create HMACSHA1 signature hash for the JSON command string using the GatewayCodeSystem.Security.Cryptography.
HMACSHA1 sha1 =
new System.Security.Cryptography.
HMACSHA1();
// Specify the GatewayCode secret keysha1.Key = System.Text.
Encoding.UTF8.GetBytes(
"PK_Demo");
// Convert the JSON command string to a byte arraybyte[] byteArray = System.Text.
Encoding.UTF8.GetBytes(api_call);
// Generate the hash signaturestring api_sig = Convert.ToBase64String(sha1.ComputeHash(byteArray));
//Submit the REST-based HTTP Request to the PaymentKeys Application Framework gatewaystring PostURL =
"https://www.paymentkeys.com/api.rest/appserver";
HttpWebRequest http_request = (HttpWebRequest)WebRequest.Create(PostURL);
// Define the data to postStringBuilder postData =
new StringBuilder();
postData.Append("api_KeyID=PaymentKeys_Demo.pk");
postData.Append("&api_sig=" + Server.UrlEncode(api_sig));
postData.Append("&api_call=" + Server.UrlEncode(api_call));
postData.Append("&api_output=json");
// Encode the post data into a byte arraySystem.Text.
UTF8Encoding encodedData =
new System.Text.
UTF8Encoding();
byte[] postData_byteArray = encodedData.GetBytes(postData.ToString);
// Set http request headershttp_request.Method =
"POST";
http_request.ContentType =
"application/x-www-form-urlencoded";
http_request.ContentLength = postData_byteArray.Length;
// Stream the post data to the PaymentKeys application gatewayStream request_stream = http_request.GetRequestStream();
request_stream.Write(postData_byteArray, 0, postData_byteArray.Length);
request_stream.Close();
// Process the responseHttpWebResponse http_response =
null;
StreamReader response_stream = null;
string JSON_Response = string.Empty;
try{
http_response = (HttpWebResponse)http_request.GetResponse();
response_stream = new StreamReader(http_response.GetResponseStream(), Encoding.UTF8);
JSON_Response = response_stream.ReadToEnd();
}
catch (WebException Ex)
{
//Handle http communication errors here
}
finally
{
if ((http_response != null))
{
http_response.Close();
http_response = null;
}
}
//Deserialize JSON response string into response objectif (!(JSON_Response ==
string.Empty))
{
PK_PaymentKeyAdmin_Response PK_Response = default(PK_PaymentKeyAdmin_Response);
PK_Response = serializer.Deserialize
(JSON_Response);//Parse the Response per your application and policy rules
switch (PK_Response.status)
{
case ...
}