Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

System.ArgumentNullException: Value cannot be null. Parameter name: hostname at System.Net.Sockets.TcpClient..ctor

$
0
0

Hi Team,

I run a 2-payment transaction code  for stripe platform and i getting following error :-

System.ArgumentNullException: Value cannot be null. Parameter name: hostname at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port) at ASP.cs_sock_2party_aspx.Page_Load(Object sender, EventArgs e) in d:\certifications\MCSD\codes\practicals\Payment\2party payment\CS_Sock_2party.aspx:line 497

Can anyone help, I am very new for payments implementation

HTML CODE<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><head><title>ASP.NET (C#) Sockets Sockets Example</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'><style type='text/css'><!--
        H1       { font-family:Arial,sans-serif; font-size:20pt; color:#08185A; font-weight:600; margin-bottom:0.1em}
        H2       { font-family:Arial,sans-serif; font-size:14pt; color:#08185A; font-weight:100; margin-top:0.1em}
        H2.co    { font-family:Arial,sans-serif; font-size:24pt; color:#08185A; margin-top:0.1em; margin-bottom:0.1em; font-weight:100}
        H3.co    { font-family:Arial,sans-serif; font-size:16pt; color:#FFFFFF; margin-top:0.1em; margin-bottom:0.1em; font-weight:100}
        BODY     { font-family:Verdana,Arial,sans-serif; font-size:10pt; color:#08185A background-color:#FFFFFF }
        TH       { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A; font-weight:bold; background-color:#CED7EF; padding-top:0.5em; padding-bottom:0.5em}
        TR       { height:25px; }
        .shade   { height:25px; background-color:#CED7EF }
        .title   { height:25px; background-color:#0074C4 }
        TD       { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A }
        P        { font-family:Verdana,Arial,sans-serif; font-size:10pt; color:#FFFFFF }
        P.blue   { font-family:Verdana,Arial,sans-serif; font-size:7pt;  color:#08185A }
        P.red    { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#FF0066 }
        P.green  { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#00AA00 }
        DIV.bl   { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#0074C4 }
        LI       { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#FF0066 }
        INPUT    { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A; background-color:#CED7EF; font-weight:bold }
        SELECT   { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A; background-color:#CED7EF; font-weight:bold; width:300 }
        TEXTAREA { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A; background-color:#CED7EF; font-weight:normal; scrollbar-arrow-color:#08185A; scrollbar-base-color:#CED7EF }
        A:link   { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A }
        A:visited{ font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A }
        A:hover  { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#FF0000 }
        A:active { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#FF0000 }
        --></style></head><body><!-- start branding table --><table width='100%' border='2' cellpadding='2' bgcolor='#0074C4'><tr><td bgcolor='#CED7EF' width='90%'><h2 class='co'>&nbsp;Payment Client 3.1 Example</h2></td><td bgcolor='#0074C4' align='center'><h3 class='co'>Dialect<br>Solutions</h3></td></tr></table><!-- end branding table --><!-- The "Pay Now!" button submits the form and gives control to the form 'action' parameter --><form action="./CS_Sock_2party.aspx" method="post"><input type="hidden" name="Title" value="ASP.NET 2-Party Basic Transaction"><center><h1>ASP.NET (C#) Sockets Sockets 2-Party Basic Transaction</h1><br/></center><!-- get user input --><table align="center" border="0" width="80%"><tr class="title"><td colspan="2"><p><strong>&nbsp;Sockets Configuration Data</strong></p></td></tr><tr>    <td align="right"><strong><em>Host IP Address: </em></strong></td><td><p class="blue"><input name="HostName" value="127.0.0.1"> Check to output socket commands. <input type='checkbox' name="DebugOn" value='1'></p></td></tr><tr class="shade"><td align="right"><strong><em>Host Port Number: </em></strong></td><td><input name="Port" maxlength="10" value="9050"></td></tr><tr><td colspan="2">&nbsp;<hr width="75%">&nbsp;</td></tr><tr class="title"><td colspan="2"><p><strong>&nbsp;Required 2-Party Transaction Fields</strong></p></td></tr><tr>    <td align="right"><strong><em>Merchant Transaction Reference: </em></strong></td><td><input name = "MerchTxnRef" maxlength="40" value=""></td></tr><tr class="shade">    <td align="right"><strong><i>Merchant ID: </i></strong></td><td><input name = "MerchantID" maxlength="16" value=""></td></tr><tr><td align="right"><strong><i>OrderInfo: </i></strong></td><td><input name="OrderInfo" maxlength="13" value=""></td></tr><tr class="shade"><td align="right"><i><strong>Purchase Amount: </strong><br><font size='1'>(Cents, pence, yen, etc.)</font> </i></td><td><input name = "PurchaseAmount"  maxlength="10" value="100"></td></tr><tr>    <td align="right"><strong><i>Credit Card No:</i></strong> </td><td><input name = "Ecom_Payment_Card_Number" maxlength="25" value=""></td></tr><tr class="shade">    <td align="right"><strong><i>Credit Card Expiry Month (MM): </i></strong></td><td><input name = "Ecom_Payment_Card_Month" maxlength="2" value=""></td></tr><tr>    <td align="right"><strong><i>Credit Card Expiry Year (YYYY): </i></strong></td><td><input name = "Ecom_Payment_Card_Year" maxlength="4" value=""></td></tr><tr>    <td colspan="2">&nbsp;</td></tr><tr>    <td>&nbsp;</td> <td><input type="submit" NAME="SubButL" value="Pay Now!"></td></tr><tr><td colspan="2">&nbsp;<hr width="75%">&nbsp;</td></tr><tr class="title"><td colspan="2"><p><strong>&nbsp;Required Card Security Code Field</strong></p></td></tr><tr>    <td align="right"><strong><em>Card Security Code: </em></strong></td><td><input name = "Ecom_Card_Security_Code" maxlength="4" value=""></td></tr><tr><td colspan="2">&nbsp;<hr width="75%">&nbsp;</td></tr><tr class="title"><td colspan="2" height="25"><p><strong>&nbsp;Optional Card Security Code Set Check Level Field</strong></p></td></tr><tr>    <td colspan="2" height="25" align="center"><strong><u>Note</u>:</strong> Not all systems accept this field. Please check with your Payment Provider.</td></tr><tr class="shade">    <td align="right"><strong><em>Minimum Acceptable CSC: </em></strong></td><td><select name="CSCLevel"><option SELECTED value="">Don't send any value to Payment Server, use default value.</option><option value="M">M = Exact code match</option><option value="S">S = Merchant indicates CSC not present on card, (2-Party Only)</option><option value="P">P = Code not processed</option><option value="U">U = Card issuer is not registered and/or certified</option><option value="N">N = Code invalid or not matched</option></select></td></tr><tr><td colspan="2">&nbsp;<hr width="75%">&nbsp;</td></tr><tr class="title"><td colspan="2"><p><strong>&nbsp;Optional Ticket Number Field</strong></p></td></tr><tr><td align="right"><strong><i>TicketNo: </i></strong></td><td><input type="text" name="TicketNo" maxlength="15"></td></tr><tr><td colspan="2"><br/><hr width="75%"></td></tr><tr><td colspan="2"><p class='blue'><strong><em><u>Note</u>:</em></strong><br/> 
        Any information passed through the customer's browser 
        can potentially be modified by the customer, or even by third parties to 
        fraudulently alter the transaction data. Therefore all transactional 
        information should <strong>not</strong> be passed through the browser in
        a way that could potentially be modified (e.g. hidden form fields). 
        Transaction data should only be accepted once from a browser at the 
        point of input, and then kept in a way that does not allow others 
        to modify it (e.g. database, server session, etc.). Any transaction 
        information displayed to a customer, such as amount, should be passed 
        only as display information and the actual transactional data should be 
        retrieved from the secure source last thing at the point of processing 
        the transaction.</p><p class='blue'>Fields like return links back to the order page (AgainLink), 
        titles, sockets' data, and any other non-transactional 
        information are only included here in the example for information purposes. 
        They do not apply to the transaction and should not be included in production 
        code orders.</p></td></tr><tr>    <td width="45%">&nbsp;</td><td width="55%">&nbsp;</td></tr></table></form></body></html>


aspx code

<%@ Page Language="C#" %><!DOCTYPE HTML PUBLIC '-'W3C'DTD HTML 4.01 Transitional'EN'><html><head><script language="C#" runat="server">

/*2 party payment on stripe*/
// Declare the global variables
private System.Net.Sockets.TcpClient socket;
private System.Net.Sockets.NetworkStream ns;

// Exception message value
private string exception = "No Exception Returned";
private string socketCommands = "<u>Payment Client Socket Commands</u><br/><br/>";


// _________________________________________________________________________

/**
* This method uses the QSIResponseCode retrieved from the Digital Receipt
* and returns an appropriate description.
*
* @param vResponseCode string containing the QSIResponseCode
*
* @return description string containing the appropriate description
*
*/
private string getResponseDescription(string vResponseCode)
{

    string result = "";

    if (vResponseCode == null || String.Compare(vResponseCode,"null",true) == 0 || vResponseCode.Equals(""))
    {
        result = "null response";
    }
    else
    {

        switch (vResponseCode)
        {
            case "0" : result = "Transaction Successful"; break;
            case "1" : result = "Transaction Declined"; break;
            case "2" : result = "Bank Declined Transaction"; break;
            case "3" : result = "No Reply from Bank"; break;
            case "4" : result = "Expired Card"; break;
            case "5" : result = "Insufficient Funds"; break;
            case "6" : result = "Error Communicating with Bank"; break;
            case "7" : result = "Payment Server detected an error"; break;
            case "8" : result = "Transaction Type Not Supported"; break;
            case "9" : result = "Bank declined transaction (Do not contact Bank)"; break;
            case "A" : result = "Transaction Aborted"; break;
            case "B" : result = "Transaction Declined - Contact the Bank"; break;
            case "C" : result = "Transaction Cancelled"; break;
            case "D" : result = "Deferred transaction has been received and is awaiting processing"; break;
            case "F" : result = "3-D Secure Authentication failed"; break;
            case "I" : result = "Card Security Code verification failed"; break;
            case "L" : result = "Shopping Transaction Locked (Please try the transaction again later)"; break;
            case "N" : result = "Cardholder is not enrolled in Authentication scheme"; break;
            case "P" : result = "Transaction has been received by the Payment Adaptor and is being processed"; break;
            case "R" : result = "Transaction was not processed - Reached limit of retry attempts allowed"; break;
            case "S" : result = "Duplicate SessionID"; break;
            case "T" : result = "Address Verification Failed"; break;
            case "U" : result = "Card Security Code Failed"; break;
            case "V" : result = "Address Verification and Card Security Code Failed"; break;
            default  : result = "Unable to be determined"; break;
        }
    }
    return result;
}


// _________________________________________________________________________

/**
* This function uses the AVS Result Code retrieved from the Digital
* Receipt and returns an appropriate description for this code.
*
* @param vAVSResultCode String containing the AVS Result Code
* @return description String containing the appropriate description
*/
private string displayAVSResponse(string vAVSResultCode)
{
    string result = "";

    if (vAVSResultCode != null && !vAVSResultCode.Equals(""))
    {

        if (String.Compare(vAVSResultCode,"Unsupported",true) == 0)
        {
            result = "AVS not supported or there was no AVS data provided";
        }
        else
        {
            switch (vAVSResultCode)
            {
                case "X" : result = "Exact match - address and 9 digit ZIP/postal code"; break;
                case "Y" : result = "Exact match - address and 5 digit ZIP/postal code"; break;
                case "S" : result = "Service not supported or address not verified (international transaction)"; break;
                case "G" : result = "Issuer does not participate in AVS (international transaction)"; break;
                case "A" : result = "Address match only"; break;
                case "W" : result = "9 digit ZIP/postal code matched, Address not Matched"; break;
                case "Z" : result = "5 digit ZIP/postal code matched, Address not Matched"; break;
                case "R" : result = "Issuer system is unavailable"; break;
                case "U" : result = "Address unavailable or not verified"; break;
                case "E" : result = "Address and ZIP/postal code not provided"; break;
                case "N" : result = "Address and ZIP/postal code not matched"; break;
                case "0" : result = "AVS not requested"; break;
                default  : result = "Unable to be determined"; break;
            }
        }
    }
    else
    {
        result = "null response";
    }
    return result;
}

//______________________________________________________________________________

/**
* This function uses the CSC Result Code retrieved from the Digital
* Receipt and returns an appropriate description for this code.
*
* @param vCSCResultCode string containing the CSC Result Code
* @return description string containing the appropriate description
*/
private string displayCSCResponse(string vCSCResultCode)
{

    string result = "";
    if (vCSCResultCode != null && !vCSCResultCode.Equals(""))
    {

        if (String.Compare(vCSCResultCode,"Unsupported",true) == 0)
        {
            result = "CSC not supported or there was no CSC data provided";
        }
        else
        {

            switch (vCSCResultCode)
            {
                case "M" : result = "Exact code match"; break;
                case "S" : result = "Merchant has indicated that CSC is not present on the card (MOTO situation)"; break;
                case "P" : result = "Code not processed"; break;
                case "U" : result = "Card issuer is not registered and/or certified"; break;
                case "N" : result = "Code invalid or not matched"; break;
                default: result = "Unable to be determined"; break;
            }
        }
    }
    else
    {
        result = "null response";
    }
    return result;
}

// _________________________________________________________________________

/**
 * This method sends the command to the Payment Client and retrieves the
 * response for the main body of the example. If an error is encountered
 * an error page is displayed and an Exception containing with the message
 * "Error Displayed" is thrown back to the main body of the example to
 * notify it of the error.
 *
 * @param command String that will be sent to the Payment Client Socket
 * @param debug a boolean value to sent socket output to screen
 *
 * @return cmdString String containing the Payment Client response
 *
 * @throws Exception Exception with the message "Error Displayed" is thrown
 * if an error is encountered and displayed.
 *
 */
private string sendCommand(string command, bool debug)
{
	try
	{
        // this code outputs socket commands to screen if debug is enabled
		// the output screen data is put through a filter to replace particular
		// data characters so they will display correctly in a HTML page
		if (debug)
        {
			string sendData = command.Replace(" ", "&nbsp;");
            sendData = sendData.Replace("<", "&lt;");
			sendData = sendData.Replace(">", "&gt;");
			sendData = sendData.Replace("\n", "<br/>");

            socketCommands += "<font color='#FF0066'>Sent: " + sendData + "</font><br/>";
		}

        /*
         * Send Data
         * ---------
         * We are performing a command to the Payment Client, the
         * command is terminated with a newline (linefeed) character.
         * We must add this character to the request data so that the
         * Payment Client sockets listener konws when it has received
         * all the data.
         */
        byte[] SendBuffer = new byte[command.Length+1];
        SendBuffer = System.Text.Encoding.ASCII.GetBytes(command+"\n");
        ns.Write(SendBuffer, 0, SendBuffer.Length);

        /*
         * Receive Data
         * ------------
         * The command will return a String terminated with a newline
         * (linefeed) character.
         */
        string TextResponse = "";
        int BytesRead = 0;
        bool ContinueReading = true;
        while (ContinueReading)
        {
            byte[] ReceiveBuffer = new byte[socket.ReceiveBufferSize];
            BytesRead = ns.Read(ReceiveBuffer, 0, ReceiveBuffer.Length);

            // Store the received data to the TextResponse variable
            TextResponse = TextResponse + System.Text.Encoding.ASCII.GetString(ReceiveBuffer, 0, BytesRead);

            /*
            *  Check for a newline (linefeed) character to see if we
            * need to keep reading from the socket as the stream
            * buffer may have filled before we got the complete data.
            * We may have to read again. We know when we have all the
            * data as the Payment Client will terminate it's response
            * with a newline (linefeed) character. If for any reason
            * the message is malformed and we start to get into an
            * infinite loop, the buffer should empty so we can detect
            * this by checking for an empty buffer
            *  i.e.TextResponse = ""
            */
            if (TextResponse.EndsWith("\n") || TextResponse.Equals(""))
            {
                ContinueReading = false;
            }
        }
        // Flush the stream to ensure it is empty before another
        // command is run.
        ns.Flush();

        // this code outputs socket commands to screen if debug is enabled
		if (debug)
        {
            socketCommands += "<font color='#008800'>Recd: " + TextResponse.TrimEnd('\n') + "</font><br/><br/>";
		}

        /*
         *  Return the response
         * -------------------
         * Use TrimEnd to remove the terminating newline (linefeed) or
         * carriage return characters to stop the text wrapping
         * unexpectedly as it is just a terminating character for the
         * socket response so that we know when the complete response has
         * been received.
         */
        return TextResponse.TrimEnd('\n');
    }
    catch (Exception ex2)
    {
        // There was an error
        exception = "(53) Socket Encounted Exception - sent: '" + command + "'<br/>Message: " + ex2.Message;
        if (ex2.StackTrace.Length > 0)
        {
            Label_StackTrace.Text = ex2.ToString();
            Panel_StackTrace.Visible = true;
        }
		return "(53) Socket Encounted Exception - sent: '" + command;
    }
}

// _________________________________________________________________________


private string closeSocket()
{
    // Use the following code to close the socket
    try
    {
        ns.Close();
        socket.Close();
        return "1";
    }
    catch (Exception ex)
    {
        exception = ex.Message;
        if (ex.StackTrace.Length > 0)
        {
            Label_StackTrace.Text = ex.ToString();
            Panel_StackTrace.Visible = true;
        }
        return "(53) Socket Encounted Exception on closing.";
    }
}

// _________________________________________________________________________

private void Page_Load(object sender, System.EventArgs e)
{

    // Define Static Constants
    // ***********************

    // This is the time that the example will allow for the socket to complete
    // sending a command to the Payment Client in milliseconds
    int SHORT_SOCKET_TIMEOUT =  500;
    int LONG_SOCKET_TIMEOUT  = 5000;

    /** This is the status character in the response that indicates that a
    command was run successfully */
    string OK = "1";

    // Initialisation
    // ==============

    /* *******************************************
    * Define Variables
    * *******************************************/

    Panel_Debug.Visible      = false;
    Panel_Receipt.Visible    = false;
    Panel_Error.Visible      = false;
    Panel_StackTrace.Visible = false;

    // socket response data
    string cmdResponse  = "";
    // error message value
    string message = "";
    // error exists flag
    bool errorExists = false;

    /* The following fields are the input fields for the command, please
    * refer to the Payment Client Reference Guide for more information on
    * the fields.
    */
    string orderInfo      = "";
    string merchantID     = "";
    string purchaseAmount = "";
    string merchTxnRef    = "";

    // receipt variables
    string txnResponseCode = "";
    string receiptNo       = "";
    string qsiResponseCode = "";
    string acqResponseCode = "";
    string authorizeID     = "";
    string batchNo         = "";
    string transactionNr   = "";
    string cardType        = "";
    string avsAddress      = "";
    string avsCity         = "";
    string avsState        = "";
    string avsZip          = "";
    string avsCountryCode  = "";
    string avsResultCode   = "";
    string avsAcqRespCode  = "";
    string avsRequestCode  = "";
    string cscResultCode   = "";
    string cscAcqRespCode  = "";
    string cscRequestCode  = "";
    string receiptKeys     = "";

    // *******************************************
    // START OF MAIN PROGRAM
    // *******************************************

   //   if debug = true then sockets information output to screen
   //   if debug = false then NO sockets information output to screen
   bool debug = false;
   
   try
   {

       // this debug parameter simply allows the user to see the sockets
       // commands going to/from the Payment Client socket listener.
       // This is not required for production code.
       string getDebug = Page.Request.Form["DebugOn"];

       if (getDebug != null && getDebug == "1")
       {
           debug = true;
       }
       else
       {
           getDebug = "0";
       }

       // Payment Client IP number
       String payClientIP    = Page.Request.Form["HostName"];
       // Payment Client Port number
       String portNo = Page.Request.Form["Port"];

       // check for valid parameters
       int payClientPort = 0;
       if (portNo!=null && portNo.Length>0 && payClientIP!=null && payClientIP.Length>0)
       {
            payClientPort = int.Parse(portNo);
       }
       else
       {
            message = "(44) Invalid HostName or Port. Hostname=" + payClientIP + " Port=" + portNo;
            errorExists = true;
       }

        // Step 1 - Connect to the Payment Client
        // **************************************
        // set a flag to indicate if a socket created
        bool socketCreated  = false;

        try
        {
            // Create a socket and set the properties that you want
            socket = new System.Net.Sockets.TcpClient(payClientIP, payClientPort);

            // Set the socket timeout value to short value for the initial
            socket.ReceiveTimeout = SHORT_SOCKET_TIMEOUT;
            socket.SendTimeout = SHORT_SOCKET_TIMEOUT;

            // Get a Netwrok Stream to read and write to the Socket
            ns = socket.GetStream();
            socketCreated = true;

        }
        catch (Exception ex)
        {
            // Display an error page as the socket connection failed
            message = "(45) Failed to create a socket connection to Payment Client - host:" + payClientIP + " port:" + payClientPort;
            exception = ex.Message;
            if (ex.StackTrace.Length > 0)
            {
               Label_StackTrace.Text = ex.ToString();
               Panel_StackTrace.Visible = true;
            }
            errorExists = true;
        }

        // Step 2 - Test the Payment Client object was created successfully
        // ****************************************************************
        // Test the communication to the Payment Client using an "echo"
        if (!errorExists)
        {
            cmdResponse = sendCommand("1,Test", debug);
            if (!cmdResponse.StartsWith(OK))
            {
               // a socket error has occurred
               // The echo command failed because the status character was not "1".
               message= cmdResponse;
               errorExists = true;
            }
            else
            {
                // correct status present, check for correct echo value returned
                if (cmdResponse.Substring(2) != "echo:Test")
                {
                   // Display an error page as the communication
                   // to the Payment Client failed
                   // The response should be "echo:" followed by the text that
                   // was send as the data in the echo command.
                   message = "(5) Socket connection to Payment Client has not connected correctly - echo test failed - should be: '1,echo:Test', but received: '" + cmdResponse;
                   errorExists = true;
                }
            }
        }

        // Step 3 - Prepare to Generate and Send Digital Order
        // ***************************************************
        // The extra details are not accepted by the
        // sendMOTODigitalOrder() method and so we must add them
        // explicitly here for inclusion in the DO creation.
        // Adding the supplementary data to the DO is done using the
        //"addDigitalOrderField" command

        // add MerchTxnRef
        if (!errorExists)
        {
           merchTxnRef = Page.Request.Form["MerchTxnRef"];
           if (merchTxnRef != null && merchTxnRef.Length > 0)
           {
               cmdResponse = sendCommand("7,MerchTxnRef," + merchTxnRef, debug);
               if (!cmdResponse.StartsWith(OK))
               {
                   // Display an Error Page
                   message = "(6) Failed to add supplementary data - MerchTxnRef, received:" + cmdResponse;
                   errorExists = true;
               }
           }
        }

        // add Card Number
        if (!errorExists)
        {
           cmdResponse = sendCommand("7,CardNum," + Page.Request.Form["Ecom_Payment_Card_Number"], debug);
           if (!cmdResponse.StartsWith(OK))
           {
               // Display an Error Page
               message = "(6) Failed to add supplementary data - CardNum, received:" + cmdResponse;
               errorExists = true;
           }
        }

        // add Card Expiry - format YYMM
        string cardMonth = Page.Request.Form["Ecom_Payment_Card_Month"];
        string cardYear  = Page.Request.Form["Ecom_Payment_Card_Year"];

        // We have the expiry month and year, but the Payment Client requires
        // a 4 digit expiry year/month (YYMM). We construct this from the
        // information we already have.
        string cardExpiry = null;
        if (cardYear != null && cardYear.Length > 2)
        {
           cardExpiry = cardYear.Substring(cardYear.Length - 2) + cardMonth;
        }
        else
        {
           cardExpiry = cardYear + cardMonth;
        }

        if (!errorExists)
        {
           cmdResponse = sendCommand("7,CardExp," + cardExpiry, debug);
           if (!cmdResponse.StartsWith(OK))
           {
               // Display an Error Page
               message = "(6) Failed to add supplementary data - CardExp, received:" + cmdResponse;
               errorExists = true;
           }
        }


        // add ticket number
        if (!errorExists)
        {
           string ticketNo = Page.Request.Form["TicketNo"];
           if (ticketNo != null && ticketNo.Length > 0)
           {
               cmdResponse = sendCommand("7,TicketNo," + ticketNo, debug);
               if (!cmdResponse.StartsWith(OK))
               {
                   // Display an Error Page
                   message = "(6) Failed to add supplementary data - TicketNo, received:" + cmdResponse;
                   errorExists = true;
               }
           }
        }

        // Step 4 - Generate and Send Digital Order (& receive DR)
        // *******************************************************
        // Create and send the Digital Order
        // (This primary command also receives the Digital receipt)
        if (!errorExists)
        {
            // Set the socket timeout value to long value for the primary
            // command as it sends and receives data to the Payment Server.
            // All other commands only work locally with the Payment Client
            socket.ReceiveTimeout = LONG_SOCKET_TIMEOUT;

            orderInfo      = Page.Request.Form["OrderInfo"];
            merchantID     = Page.Request.Form["MerchantID"];
            purchaseAmount = Page.Request.Form["PurchaseAmount"];

            cmdResponse = sendCommand("6,"+ orderInfo +","+ merchantID +","+ purchaseAmount +",en,", debug);
            if (!cmdResponse.StartsWith(OK))
            {
               // Retrieve the Payment Client Error (There may be none to get)
               cmdResponse = sendCommand("4,PaymentClient.Error", debug);
               if (cmdResponse.StartsWith(OK))
               {
                   exception = cmdResponse.Substring(2);
               }
               // Display an Error Page as the Digital Order was not processed
               message = "(11) Digital Order has not created correctly - sendMOTODigitalOrder(" + orderInfo +","+ merchantID + ","+ purchaseAmount +",en,) failed";
               errorExists = true;
            }
        }

        // Step 5 - Check the DR to see if there is a valid result
        // *******************************************************
        // Use the "nextResult" command to check if the DR contains a result
        if (!errorExists)
        {
           // Set the socket timeout value back to the short value for the
           // following supplementary commands
           socket.ReceiveTimeout = SHORT_SOCKET_TIMEOUT;

           cmdResponse = sendCommand("5,", debug);
           if (!cmdResponse.StartsWith(OK))
           {
               // Retrieve the Payment Client Error (There may be none to get)
               cmdResponse = sendCommand("4,PaymentClient.Error", debug);
               if (cmdResponse.StartsWith(OK))
               {
                   exception = cmdResponse.Substring(2);
               }
               // Display an Error as the DR doesn't contain a valid result
               message = "(12) No Results for Digital Receipt";
               errorExists = true;
           }
       }

       // Step 6 - Get the result data from the Digital Receipt
       // *****************************************************
       // Get the QSI Response Code for the transaction
       // Extract the available Digital Receipt fields
       if (!errorExists)
       {
           cmdResponse = sendCommand("4,DigitalReceipt.QSIResponseCode", debug);
           if (!cmdResponse.StartsWith(OK))
           {
               // Display an Error Page as no QSIResponseCode
               message = "(23) No result for this field: 'DigitalReceipt.QSIResponseCode'";
               errorExists = true;
           }
           else
           {
               qsiResponseCode = cmdResponse.Substring(2);
           }
       }

       // Check if the result contains an error message
       if (!errorExists)
       {
           if (qsiResponseCode != "null" && qsiResponseCode != "0")
           {
               // check if an error returned from the Payment Client
               cmdResponse = sendCommand("4,DigitalReceipt.ERROR", debug);
               if (cmdResponse.StartsWith(OK))
               {
                   // The response is an error message so display an Error Page
                   message = "(24) Error message returned from Payment Server - QSIResponseCode=" + qsiResponseCode;
                   exception = cmdResponse.Substring(2);
                   errorExists = true;
               }
           }
       }

       // Use the "getAvailableFieldKeys" command to obtain a list of keys available
       // within the Payment Client Hash table containing the receipt results.
       // This is a local command that only communicates to the Payment Client and
       // nothing is sent to the Payment Server. The keys will not be used or displayed here.
       if (!errorExists)
       {
           cmdResponse = sendCommand("33,", debug);
           if (!cmdResponse.StartsWith(OK))
           {
               receiptKeys = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";
               receiptKeys = receiptKeys.Replace(",", "<br/>");
           }
       }


       // Extract the available Digital Receipt fields
       // The example retrieves the OrderInfo, MerchantID,
       // and Amount values, which should be the same as the values sent.
       // In a production system the sent values and the receive
       // values could be checked to make sure they are the same.
       if (!errorExists)
       {
           cmdResponse = sendCommand("4,DigitalReceipt.MerchTxnRef", debug);
           merchTxnRef = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.MerchantId", debug);
           merchantID = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.OrderInfo", debug);
           orderInfo = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.PurchaseAmountInteger", debug);
           purchaseAmount = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.ReceiptNo", debug);
           receiptNo = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.AcqResponseCode", debug);
           acqResponseCode = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.AuthorizeId", debug);
           authorizeID = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.BatchNo", debug);
           batchNo = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.TransactionNo", debug);
           transactionNr = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";

           cmdResponse = sendCommand("4,DigitalReceipt.CardType", debug);
           cardType = cmdResponse.StartsWith(OK) ? cmdResponse.Substring(2) : "Unknown";
       }

       // Step 7 - We are finished with the Payment Client so tidy up
       // ***********************************************************
       // close the socket C#
       if (socketCreated)
       {
           string socketClosed = closeSocket();
           if (socketClosed != "1")
           {
               message =  socketClosed;
               errorExists = true;
           }
       }
   }
   catch (Exception ex2)
   {
       message = "(51) Exception encountered.";
       exception = ex2.Message;
       if (ex2.StackTrace.Length > 0)
       {
           Label_StackTrace.Text = ex2.ToString();
           Panel_StackTrace.Visible = true;
       }
       errorExists = true;
   }

    // *******************************************
    // END OF MAIN PROGRAM
    // *******************************************


    // FINISH TRANSACTION - Process the Digital Receipt Data
    // *****************************************************
    // For the purposes of demonstration, we simply display the Result
    // fields on a web page.

    /* The URL link for the receipt to do another transaction.
    * Note: This is ONLY used for this example and is not required for
    * production code.
    */
    Label_AgainLink.Text = "<a href=\"" + Page.Request.ServerVariables["HTTP_REFERER"] + "\">Another Transaction</a>";

    // set the appropriate title and output results
    string receiptTitle = Page.Request.Form["Title"];

    if (!errorExists)
    {
        receiptTitle += " Receipt Page";
        Panel_Receipt.Visible = true;

        Label_TxnResponseCode.Text     = qsiResponseCode;
        Label_TxnResponseCodeDesc.Text = getResponseDescription(qsiResponseCode);
        Label_AcqResponseCode.Text     = acqResponseCode;
        Label_TransactionNo.Text       = transactionNr;
        Label_ReceiptNo.Text           = receiptNo;
        Label_AuthorizeID.Text         = authorizeID;
        Label_BatchNo.Text             = batchNo;
        Label_CardType.Text            = cardType;
    }
    else
    {
        receiptTitle += " Error Page";
        Panel_Error.Visible = true;

        // set error fields
        Label_ErrorMessage.Text = message;
        Label_Exception.Text    = exception;
    }
    // set common fields
    Label_Title.Text       = receiptTitle;
    Label_MerchTxnRef.Text = merchTxnRef;
    Label_MerchantID.Text  = merchantID;
    Label_OrderInfo.Text   = orderInfo;
    Label_Amount.Text      = purchaseAmount;

    // output socket commands to the screen
    if (debug)
    {
        Panel_Debug.Visible = true;
        Label_Debug.Text    = socketCommands;
    }
}
</script>
<title>Example Transaction</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<style type='text/css'>
    <!--
    h1       { font-family:Arial,sans-serif; font-size:20pt; font-weight:600; margin-bottom:0.1em; color:#08185A;}
    h2       { font-family:Arial,sans-serif; font-size:14pt; font-weight:100; margin-top:0.1em; color:#08185A;}
    h2.co    { font-family:Arial,sans-serif; font-size:24pt; font-weight:100; margin-top:0.1em; margin-bottom:0.1em; color:#08185A}
    h3       { font-family:Arial,sans-serif; font-size:16pt; font-weight:100; margin-top:0.1em; margin-bottom:0.1em; color:#08185A}
    h3.co    { font-family:Arial,sans-serif; font-size:16pt; font-weight:100; margin-top:0.1em; margin-bottom:0.1em; color:#FFFFFF}
    body     { font-family:Verdana,Arial,sans-serif; font-size:10pt; background-color:#FFFFFF; color:#08185A}
    th       { font-family:Verdana,Arial,sans-serif; font-size:8pt; font-weight:bold; background-color:#CED7EF; padding-top:0.5em; padding-bottom:0.5em;  color:#08185A}
    tr       { height:25px; }
    .shade   { height:25px; background-color:#CED7EF }
    .title   { height:25px; background-color:#0074C4 }
    td       { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A }
    td.red   { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#FF0066 }
    td.green { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#008800 }
    p        { font-family:Verdana,Arial,sans-serif; font-size:10pt; color:#FFFFFF }
    p.blue   { font-family:Verdana,Arial,sans-serif; font-size:7pt;  color:#08185A }
    p.red    { font-family:Verdana,Arial,sans-serif; font-size:7pt;  color:#FF0066 }
    p.green  { font-family:Verdana,Arial,sans-serif; font-size:7pt;  color:#008800 }
    div.bl   { font-family:Verdana,Arial,sans-serif; font-size:7pt;  color:#0074C4 }
    div.red  { font-family:Verdana,Arial,sans-serif; font-size:7pt;  color:#FF0066 }
    li       { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#FF0066 }
    input    { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A; background-color:#CED7EF; font-weight:bold }
    select   { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A; background-color:#CED7EF; font-weight:bold; }
    textarea { font-family:Verdana,Arial,sans-serif; font-size:8pt;  color:#08185A; background-color:#CED7EF; font-weight:normal; scrollbar-arrow-color:#08185A; scrollbar-base-color:#CED7EF }
    -->
</style>
</head>
<body>
<!-- only display these next fields if debug enabled -->
<asp:Panel id="Panel_Debug" runat=server>
<table>
    <tr>
        <td><asp:Label id=Label_Debug runat="server"/></td>
    </tr>
</table>
</asp:Panel>

<!-- start branding table -->
<table width='100%' border='2' cellpadding='2' class='title'>
    <tr>
        <td class='shade' width='90%'><h2 class='co'>&nbsp;Payment Client 3.1 Example</h2></td>
        <td class='title' align='center'><h3 class='co'>Dialect<br>Solutions</h3></td>
    </tr>
</table>
<!-- end branding table -->

<h1 align="center"><asp:Label id=Label_Title runat="server"/></h1>

<form runat=server>
<table align="center" border="0" width="70%">
    
    <tr class="title">
        <td colspan="2"><p><strong>&nbsp;Transaction Receipt Fields</strong></p></td>
    </tr>
    <tr>
        <td align="right"><strong><em>MerchTxnRef: </em></strong></td>
        <td><asp:Label id=Label_MerchTxnRef runat="server"/></td>
    </tr>
    <tr class="shade">
        <td align="right"><strong><em>Merchant ID: </em></strong></td>
        <td><asp:Label id=Label_MerchantID runat="server"/></td>
    </tr>
    <tr>
        <td align="right"><strong><em>OrderInfo: </em></strong></td>
        <td><asp:Label id=Label_OrderInfo runat="server"/></td>
    </tr>
    <tr class="shade">
        <td align="right"><strong><em>Transaction Amount: </em></strong></td>
        <td><asp:Label id=Label_Amount runat="server"/></td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <div class='bl'>Fields above are the primary request values.<hr>Fields below are receipt data fields.</div>
        </td>
    </tr>
<!-- only display these next fields if not an error -->
<asp:Panel id="Panel_Receipt" runat=server>
    <tr class="shade">
        <td align="right"><strong><em>QSI Response Code: </em></strong></td>
        <td><asp:Label id=Label_TxnResponseCode runat="server"/></td>
    </tr>
    <tr>
        <td align="right"><strong><em>QSI Response Code Description: </em></strong></td>
        <td><asp:Label id=Label_TxnResponseCodeDesc runat="server"/></td>
    </tr>
    <tr class="shade">
        <td align="right"><strong><em>Acquirer Response Code: </em></strong></td>
        <td><asp:Label id=Label_AcqResponseCode runat="server"/></td>
    </tr>
    <tr>
        <td align="right"><strong><em>Shopping Transaction Number: </em></strong></td>
        <td><asp:Label id=Label_TransactionNo runat="server"/></td>
    </tr>
    <tr class="shade">
        <td align="right"><strong><em>Receipt Number: </em></strong></td>
        <td><asp:Label id=Label_ReceiptNo runat="server"/></td>
    </tr>
    <tr>
        <td align="right"><strong><em>Authorization ID: </em></strong></td>
        <td><asp:Label id=Label_AuthorizeID runat="server"/></td>
    </tr>
    <tr class="shade">
        <td align="right"><strong><em>Batch Number for this transaction: </em></strong></td>
        <td><asp:Label id=Label_BatchNo runat="server"/></td>
    </tr>
    <tr>
        <td align="right"><strong><em>Card Type: </em></strong></td>
        <td><asp:Label id=Label_CardType runat="server"/></td>
    </tr>
</asp:Panel>
<!-- only display these next fields if an error condition exists-->
<asp:Panel id="Panel_Error" runat=server>
    <tr class="title">
        <td colspan="2"><p><strong>&nbsp;Error in Processing the Data</strong></p></td>
    </tr>
    <tr>
        <td align='right'><em><strong>Error Description: </strong></em></td>
        <td><asp:Label id=Label_ErrorMessage runat="server"/></td>
    </tr>
    <tr class="shade">
        <td align='right'><em><strong>Exception: </strong></em></td>
        <td><asp:Label id=Label_Exception runat="server"/></td>
    </tr>
</asp:Panel>
<!-- only display these next fields if an stacktrace output exists-->
<asp:Panel id="Panel_StackTrace" runat=server>
    <tr>
        <td align="right"><strong><em>Exception Stack Trace: </em></strong></td>
        <td><asp:Label id=Label_StackTrace runat="server"/></td>
    </tr>
</asp:Panel>
    <tr>
        <td width="50%">&nbsp;</td>
        <td width="50%">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="2" align="center"><asp:Label id=Label_AgainLink runat="server"/></td>
    </tr>

</table>
</form>
</body>
</html>


(String hostname, Int32 port) at ASP.cs_sock_2party_aspx.Page_Load(Object sender, EventArgs e) in d:\certifications\MCSD\codes\practicals\Payment\2party payment\CS_Sock_2party.aspx:line 497

Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>