Monday, August 18, 2008

EPDQ Integration \\\

EPDQ Integration

Document Date: 16th July, 2008


(1) Code for the checkout page, from where the payment gateway is to be called for:

#region Generate EPDQ
public void Generate_EPDQ(int Booking_Id, float Total)
{
string clientid = ConfigurationManager.AppSettings["clientid"];
string password = ConfigurationManager.AppSettings["password"];
string chargetype = ConfigurationManager.AppSettings["chargetype"]; // Text string indicating the chargetype specified for the transaction.
string currencycodeGBP = ConfigurationManager.AppSettings["currencycodeGBP"];
string currencycodeEuro = ConfigurationManager.AppSettings["currencycodeEuro"];
string Encryption_URL = ConfigurationManager.AppSettings["Encryption_URL"];
string Postdata = "clientid=" + clientid + "&password=" + password + "&oid=" + Booking_Id + "&chargetype=" + chargetype + "¤cycode=[currencycode]&total=" + Total;

//The Following Creates the WebClient Object
WebClient Web = new WebClient();

//The Header Content Type is then set
Web.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

//if (rad_euro.Checked)
//{
// Postdata = Postdata.Replace("[currencycode]", currencycodeEuro);
//}
//else if (rad_Pound.Checked)
//{
// Postdata = Postdata.Replace("[currencycode]", currencycodeGBP);
//}
Postdata = Postdata.Replace("[currencycode]", currencycodeGBP);

//PostData is then declared as data type Byte and populated with the post data
Byte[] PostData = Encoding.ASCII.GetBytes(Postdata);

//The Web object is then used to upload the postdata to the Encryption URL and the response is stored in the Response variable
Byte[] Response = Web.UploadData(Encryption_URL, "POST", PostData);

//The response from the post is then converted from Type Byte to String and stored in the session variable
Session["Response"] = (Encoding.ASCII.GetString(Response));
div_Payment.InnerHtml = "";
//+ "\n" + Session["Response"] +
//div_Payment.InnerHtml;

}
#endregion



(2) Code for the callback [Thankyou] page :
#region Page_Load
protected void Page_Load(object sender, EventArgs e)
{
CheckPaymentResponse();
}
#endregion

#region CheckPaymentResponse
public void CheckPaymentResponse()
{
if (Request.QueryString != null)
{
if (Request.QueryString.Keys.Count > 0)
{
if (Request["oid"] != null)
{
if (Request["oid"].ToString() != "")
{
DataRow drmail = null;
int oid = int.Parse(Request["oid"].ToString());
drmail=DAL.Booking.GetMailDetails(oid);
if (drmail != null)
{
if (drmail.ItemArray.Length > 0)
{
string FromEmail = ConfigurationManager.AppSettings["FromEmail"].ToString();
string MailBCC = ConfigurationManager.AppSettings["BookingBCC"].ToString();
Mail.SendMail(FromEmail, drmail["propertytitle"].ToString(), drmail["Email"].ToString(), drmail["mailtext"].ToString(), "Booking detail for " + drmail["propertytitle"].ToString(),"",MailBCC);
}
}
}
}
}
}
string Paymentchk = "";
Paymentchk = Request.Url.ToString() + "
";
Paymentchk += Request.ServerVariables["request_method"] + "
";
Paymentchk += Request.Form["transactionstatus"] + "
";
Paymentchk += Request.Form["Oid"] + "
";
Paymentchk += Request.Form["total"] + "
";
Paymentchk += Request.Form["Clientid"] + "
";
Paymentchk += Request.Form["chargetype"] + "
";
Paymentchk += Request.Form["datetime"] + "
";
Paymentchk += Request.Form["ecistatus"] + "
";
Paymentchk += Request.Form["cardprefix"] + "
";
div_paymentchk.InnerHtml = Paymentchk;

if (Request.ServerVariables["request_method"].ToLower() == "post")
{
if (Request.Form["transactionstatus"].ToLower() == "success")
{
td_Failure.Visible = false;
td_success.Visible = true;
int orderid = int.Parse(Request.Form["Oid"].ToString()); //Text string containing the order identification number. If a value was not supplied in your originating request, a unique order number will be generated by ePDQ. Size: Up to 36 characters
int check = DAL.Booking.UpdateOrderStatusToPaid(orderid);

//PLACE MAIL SEND CODE

/*Request.Form["transactionstatus"]; //Success,DECLINED
Request.Form["total"]; //Total numeric value presented for authorisation. Range: 1.00 to 999999999.00 Size: Up to 12 characters
Request.Form["Clientid"]; //Numeric client id (also known as your Store ID) assigned by Barclaycard Business . This is different to your merchant id and terminal id.
Request.Form["chargetype"]; //Text string indicating the chargetype specified for the transaction. (Either Auth or PreAuth).
Request.Form["datetime"]; //Text string indicating when the order was submitted by the ePDQ CPI checkout. The date will always be in this format. e.g. Jan 23 2005 15:45:51
Request.Form["ecistatus"]; //The Internet Authentication response. Only provided if you are enrolled in Internet Authentication and the transaction was Visa or MasterCard.
Request.Form["cardprefix"]; //First digit of the supplied card number. Only provided if you are enrolled in Internet Authentication and the transaction was Visa or MasterCard.*/
}
else
{
//Response.Redirect("failure.aspx", false);
td_Failure.Visible = true;
td_success.Visible = false;
}
}
else
{
//Response.Redirect("failure.aspx", false);
td_Failure.Visible = true;
td_success.Visible = false;
}
}
#endregion


(3)Js to be placed on the aspx page from where the payment gateway is to be called:

function loadEPDQ()
{
var payment_URL = '<%= ConfigurationManager.AppSettings["Payment_URL"] %>';
document.form1.method= "POST";
document.form1.action= payment_URL ;
document.form1.submit();
}


Is the div on whose innerHTML, the above js will be registered.
This can be viewed in the function GenerateEPDQ in point (1).

(4) Hidden fields to be placed on the aspx page from where the payment gateway is to be called:

<%= Session["Response"] %>








Note: These input fields should be placed above the “div_Payment” div.


(5) Web.config keys














Note:
- the page url should be completely in lowercase
- the hidden fields should not be within the ajax

No comments: