<%@ Page Language="C#" AutoEventWireup="true" CodeFile="3DSecureLookup.aspx.cs" Inherits="Enterprise_3DSecureLookup" %> 3D Secure Enterprise Transaction

- Please confirm your order below -

 
Item Description:
Item Quantity:
Merchant Reference:
Amount:
Currency:
NOTE: This is a simulated payment process with only the required fields. As a merchant you can add any additional fields that are relevant to your payment process here (eg the 'Item Description' field on this page). Another example: You may want to retrieve postal information from the customer at the time of purchase.
 
 
Please enter your card information

Card Number:
Expiry Date (mmyyyy):
Card Security Code:
 
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using iVeri.Client; using System.Configuration; using System.Collections.Specialized; using System.Xml.Serialization; using System.IO; using System.Text; using System.Xml; public partial class Enterprise_3DSecureLookup : System.Web.UI.Page { // Common variables string baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host; string redirectURL = null; // Enterprise variables private static string Gateway = ConfigurationManager.AppSettings["Gateway"]; private static string Mode = ConfigurationManager.AppSettings["Mode"]; private static string ApplicationID = ConfigurationManager.AppSettings[Mode + "ApplicationID"]; private static string CertificateID = ConfigurationManager.AppSettings["CertificateID"]; private static string ACSRedirectUrl = ConfigurationManager.AppSettings["ACSRedirectUrl"]; private Hashtable entNVC = new Hashtable(); private Hashtable entResultNVC = new Hashtable(); bool IsValidTransaction = true; protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { Session.Clear(); // Clears any existing information to make sure the transaction is fresh this.txtMerchantReference.Value = "INV" + new Random().Next().ToString(); } else { // Default redirect URL, will change as necessary redirectURL = baseUrl + "/Enterprise/3DSecureResult.aspx"; // Create a NameValue collection of information for later use when executing enterprise ExampleUtil.AddToHash(entNVC, "MerchantReference", this.txtMerchantReference.Value); ExampleUtil.AddToHash(entNVC, "Amount", this.txtAmount.Value.Replace(".", "")); ExampleUtil.AddToHash(entNVC, "Currency", this.hiddenCurrency.Value); ExampleUtil.AddToHash(entNVC, "PAN", this.txtCardNumber.Text); ExampleUtil.AddToHash(entNVC, "ExpiryDate", txtExpiryDate.Text); ExampleUtil.AddToHash(entNVC, "CardSecurityCode", this.txtCardSecurityCode.Text); // It is recommended to use a database while transacting, but for this example viewstate and session variables will be used. // First check for Visa and Mastercards if (this.txtCardNumber.Text != "") { if ((this.txtCardNumber.Text.Substring(0, 1) == "4") || (this.txtCardNumber.Text.Substring(0, 1) == "5")) IsValidTransaction = this.ThreeDSecureCheckEnrollment(); else Session["ErrorDesc"] = "Currently only Visa and Mastercard are supported"; // SecureChannel for SSL } else // For the example the only validation is to ensure a card number is entered, merchants should // implement more rigorous validation techniques Session["ErrorDesc"] = "Card number field was not set"; // Redirect as necessary Session["Enterprise.NVC"] = entNVC; Response.Redirect(String.Concat(redirectURL, "?IsValidTransaction=", IsValidTransaction), false); } } private bool ThreeDSecureCheckEnrollment() { // Setup a Name Value collection for information to be sent to the result page NameValueCollection nvc = new NameValueCollection(); //Do the transaction iVeriServiceSoapClient soapClient = null; try { Vxml vxml = new Vxml(); vxml.Direction = Direction.Request; vxml.CertificateID = CertificateID; vxml.ProductType = "Enterprise"; vxml.ProductVersion = "iVeriWebService 1.0"; vxml.Version = "2.0"; VxmlEnquiry enquiryDetails = vxml.Enquiry = new VxmlEnquiry(); enquiryDetails.ApplicationID = ApplicationID; enquiryDetails.Mode = Mode; enquiryDetails.Command = "ThreeDSecureCheckEnrollment"; enquiryDetails.PAN = entNVC["PAN"].ToString(); enquiryDetails.ExpiryDate = entNVC["ExpiryDate"].ToString(); enquiryDetails.Amount = entNVC["Amount"].ToString(); enquiryDetails.Currency = entNVC["Currency"].ToString(); enquiryDetails.MerchantReference = entNVC["MerchantReference"].ToString(); XmlSerializer serializer = new XmlSerializer(typeof(Vxml)); StringBuilder request = new StringBuilder(); XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.Encoding = new UTF8Encoding(); writerSettings.OmitXmlDeclaration = true; using (var xmlWriter = XmlWriter.Create(request, writerSettings)) { XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add("", ""); serializer.Serialize(xmlWriter, vxml, namespaces); xmlWriter.Flush(); xmlWriter.Close(); } soapClient = new iVeriServiceSoapClient("iVeriServiceSoap"); soapClient.Open(); string responseVXML = soapClient.Execute(false, "V_XML", "3.0", request.ToString()); Vxml vxmlResponse = (serializer.Deserialize(new StringReader(responseVXML)) as Vxml); VxmlResult result = GetResult(vxmlResponse); switch (result.Status) { case "-1": ExampleUtil.AddToHash(entResultNVC, "RESULT", "UnSuccesful"); ExampleUtil.AddToHash(entResultNVC, "Code", result.Code.ToString()); ExampleUtil.AddToHash(entResultNVC, "Source", result.Source); ExampleUtil.AddToHash(entResultNVC, "Description", result.Description); // Go Directly to the Authenticate Page Session["Enterprise.ResultNVC"] = entResultNVC; redirectURL = baseUrl + "/Enterprise/3DSecureResult.aspx"; break; case "0": case "1": // Succesful / Succesful with warnings string paReq =vxmlResponse.Enquiry.ThreeDSecure_PAReq; string acsUrl = vxmlResponse.Enquiry.ThreeDSecure_ACS_URL; string requestId = vxmlResponse.Enquiry.ThreeDSecure_RequestID; //Get the 3DSecure tags if (vxmlResponse.Enquiry.CardHolderAuthenticationID != null) ExampleUtil.AddToHash(entNVC, "CardHolderAuthenticationID", vxmlResponse.Enquiry.CardHolderAuthenticationID); if (vxmlResponse.Enquiry.CardHolderAuthenticationData != null) ExampleUtil.AddToHash(entNVC, "CardHolderAuthenticationData", vxmlResponse.Enquiry.CardHolderAuthenticationData); if (vxmlResponse.Enquiry.ElectronicCommerceIndicator != null) ExampleUtil.AddToHash(entNVC, "ElectronicCommerceIndicator", vxmlResponse.Enquiry.ElectronicCommerceIndicator); if (acsUrl != null && !acsUrl.Trim().Equals("")) { //Setup maps return url ('termUrl') string termUrl = baseUrl; termUrl += "/Enterprise/3DSecureResult.aspx?IsValidTransaction=true"; Session.Add("Centinel.MD", requestId); Session.Add("Centinel.ACSURL", acsUrl); Session.Add("Centinel.Payload", paReq); Session.Add("Centinel.TermURL", termUrl); // Redirect to the ACS redirectURL = baseUrl + "/Enterprise/ACSRedirect.aspx"; // Merchant identifying data } else // Go Directly to the Authenticate Page redirectURL = baseUrl + "/Enterprise/3DSecureResult.aspx"; return true; } } catch (Exception ex) { if (entResultNVC != null) entResultNVC.Clear(); ExampleUtil.AddToHash(entResultNVC, "RESULT", "Exception Caught"); ExampleUtil.AddToHash(entResultNVC, "Source", ex.Source); ExampleUtil.AddToHash(entResultNVC, "Description", ex.Message); // Go Directly to the Authenticate Page Session["Enterprise.ResultNVC"] = entResultNVC; redirectURL = baseUrl + "/Enterprise/3DSecureResult.aspx"; } return false; } private VxmlResult GetResult(Vxml vxmlResponse) { VxmlResult result = null; if (vxmlResponse.Result != null) { result = vxmlResponse.Result; } else if (vxmlResponse.Transaction != null && vxmlResponse.Transaction.Result != null) { result = vxmlResponse.Transaction.Result; } else if (vxmlResponse.System != null && vxmlResponse.System.Result != null) { result = vxmlResponse.System.Result; } else if (vxmlResponse.Security != null && vxmlResponse.Security.Result != null) { result = vxmlResponse.Security.Result; } else if (vxmlResponse.Enquiry != null &&vxmlResponse.Enquiry.Result != null) { result = vxmlResponse.Enquiry.Result; } return result; } }