We help IT Professionals succeed at work.

Help requeired in credit card online processing

kamranYGH
kamranYGH asked
on
647 Views
Last Modified: 2012-05-05
Hi I am developing a booking system in ASP.NET with C#. I am trying to integrate online payment processing using Gateway processor. I am using streamline as Gateway. I am sending XML file to streamline server and getting error:
Cannot have multiple DOCTYPE declarations. Error processing resource 'http://localhost:50106/test/xmlTest.aspx'. Line 7

I have tesed that XML file with another system built on ASP and it works fine with that.



My method is :
private void sendRequest()
    {
 
        Uri uri = new Uri("https://secure-test.streamline-esolutions.com/jsp/merchant/xml/paymentService.jsp");
 
 
        string fileName = Server.MapPath("testedxml.xml");
        
        
        
        if (uri.Scheme == Uri.UriSchemeHttps) // Checks that uri is https protocol
        {
 
            try
            {
 
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            
 
            request.Method = WebRequestMethods.Http.Post;
            request.ContentLength = fileName.Length;
            byte[] SomeBytes = null;
            SomeBytes = System.Text.Encoding.UTF8.GetBytes(fileName.ToCharArray());
 
            request.ContentType = "application/xml; charset=UTF-8";
            request.Accept = "application/xml; charset=UTF-8";
 
            request.Credentials = new NetworkCredential("MERCHANT_ID", "merchantPWD");
            
            request.KeepAlive = false;
 
            //Create post stream 
 
            Stream RequestStream = request.GetRequestStream();
            RequestStream.Write(SomeBytes, 0, SomeBytes.Length);
 
            RequestStream.Close();
 
            //Send request and get response 
                            
 
            HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
            if (myResponse.StatusCode == HttpStatusCode.OK)
            {
 
                int ch=0;
                while ( (ch = myResponse.GetResponseStream().ReadByte()) != -1)
                {
 
                    Response.Write((char)ch);
                }
 
 
            }
            else
            {
                lblResult.Text = "Error!!";
            
            }
        }
        catch (Exception ex)
        {
            lblResult.Text = ex.Message;
        }
 
 
 
 
 
    }    
    
 
    }

Open in new window

Comment
Watch Question

I think the problem is  in your content type decleration

Try to use contentType="text/xml"; instead of "application/xml"

Author

Commented:
I have tried that already but it doesn't work
monarch is right, but your main problem is that you're only sending the gateway the *name* of your local file, not the actual contents. Do this:
string data = null;
using (System.IO.StreamReader sr = System.IO.File.OpenText(fileName))
{
    data = sr.ReadToEnd();
}
 
httpRequest.ContentLength = data.Length;
byte[] someBytes = System.Text.Encoding.UTF8.GetBytes(data);
... etc.

Open in new window

Author

Commented:
yes,   you are write i was not passing the actual contents. The order went through with streamline, but still i can't get the response xml. It displays error:
Cannot have multiple DOCTYPE declarations. Error processing resource 'http://localhost:50106/test/xmlTest.aspx'. Line 7


try
            {
 
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
 
                request.Method = WebRequestMethods.Http.Post;
 
 
                string data = null;
                using (System.IO.StreamReader sr = System.IO.File.OpenText(fileName))
                {
                    data = sr.ReadToEnd();
                }
 
                request.ContentLength = data.Length;
                byte[] SomeBytes = System.Text.Encoding.UTF8.GetBytes(data);
 
                SomeBytes = System.Text.Encoding.UTF8.GetBytes(data.ToCharArray());
 
                request.ContentType = "text/xml; charset=UTF8";
                request.Accept = "text/xml; charset=UTF8";
 
                request.Credentials = new NetworkCredential("MERCHANT_ID", "merchantPWD");
 
                request.KeepAlive = false;
 
                //Create post stream 
 
                Stream RequestStream = request.GetRequestStream();
                RequestStream.Write(SomeBytes, 0, SomeBytes.Length);
 
                RequestStream.Close();
 
                
                //Send request and get response 
                
                HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
                if (myResponse.StatusCode == HttpStatusCode.OK)
                {
                    int ch = 0;
          while ((ch = myResponse.GetResponseStream().ReadByte()) != -1)
                    {
                        Response.Write((char)ch);
                    }
                    
                }
                else
                {
                    lblResult.Text = "Error!!";
 
                }
                myResponse.Close();
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.Message;
            }

Open in new window

1. Remove this line, it is redundant:

    SomeBytes = System.Text.Encoding.UTF8.GetBytes(data.ToCharArray());
 
2. What is the "it" when you say "it displays error"?

3. Streams are stateful objects, you have to close them when you're done.  A better version of lines 37 to 46 is:

      using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
      using (Stream responseStream = response.GetResponseStream())
      using (StreamReader sr = new System.IO.StreamReader(responseStream))
      {
            Response.Write(sr.ReadToEnd());
      }

4. A DOCTYPE declaration is a component of an XML file, we need to see the contents of testedxml.xml.
5. Also remove

    myResponse.Close();

Author

Commented:
I have updated my code as you told.
"it displays error" means the .aspx page displays error msg when this method is called to send xml to stramline.

Full msg is :
------------------------------------------------------------------------------------------------------------------------------
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


Cannot have multiple DOCTYPE declarations. Error processing resource 'http://localhost:50106/test/xmlTest.aspx'. Line 7, P...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&...
 
------------------------------------------------------------------------------------------------------------------------------
I am trying to place an xml direct order to streamline and they send xml reply in response. I am attaching testedxml (order request) and the possible reply xml.


testedxml:
 
<?xml version="1.0"?> 
	<!DOCTYPE paymentService PUBLIC "-//Bibit/DTD Bibit PaymentService v1//EN" "http://dtd.bibit.com/paymentService_v1.dtd">		
	<paymentService version="1.0" merchantCode="MERCHANT_ID">
	<submit>
	<order orderCode="CCT0009">
	<description>Holiday</description>
	<amount exponent="2" currencyCode="GBP" value="100"/>
	<orderContent><![CDATA[Order test by Kamran]]></orderContent>
	<paymentDetails>
	<ECMC-SSL>
	<cardNumber>5545678912345648</cardNumber>
	<expiryDate><date month="12" year="2010"/></expiryDate>
	<cardHolderName>Kamran</cardHolderName>
	<cvc>414</cvc>
	<cardAddress>
	<address>
	<firstName>Kamran</firstName>
	<lastName>Test</lastName>
	<street>47A Queensbridge Rd</street>
	<houseName>0</houseName>
	<houseNumber>0</houseNumber>
	<houseNumberExtension>0</houseNumberExtension>
	<postalCode>CB94BQ</postalCode>
	<city>Cambridge</city>
	<state>Essex</state>
	<countryCode>GB</countryCode>
	<telephoneNumber>01234567890</telephoneNumber>
	</address>
	</cardAddress>
	</ECMC-SSL>
	<session shopperIPAddress="123.123.123.123" id="02l5ui8ib1"/>
	</paymentDetails>
	
	<shopper><shopperEmailAddress>jshopper@myprovider.int</shopperEmailAddress></shopper>
	</order> 
	</submit>
	</paymentService>
 
 
Possible reply:
 
<?xml version="1.0"?>
<!DOCTYPE paymentService PUBLIC "-//Streamline-esolutions//DTD Streamlineesolutions
PaymentService v1//EN"
"http://dtd.streamline-esolutions.com/paymentService_v1.dtd">
<paymentService merchantCode="MYMERCHANT" version="1.4">
<reply>
<orderStatus orderCode="T0211010">
<payment>
<paymentMethod>VISA-SSL</paymentMethod>
<amount value="1400" currencyCode="GBP" exponent="2"
debitCreditIndicator="credit"/>
<lastEvent>AUTHORISED</lastEvent>
<CVCResultCode description="APPROVED"/>
<balance accountType="IN_PROCESS_AUTHORISED">
<amount value="1400" currencyCode="GBP" exponent="2"
debitCreditIndicator="credit"/>
</balance>
<cardNumber>4444********1111</cardNumber>
<riskScore value="0"/>
</payment>
</orderStatus>
</reply>
</paymentService>

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
It's working fine now. Thanks for all your support.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.