<%
'------------------------------------------------------------------------------
' mod 010628 - a3
' mod 020829 - a3
sUser = "YOUR MERCHANTCODE"
sPass = "PASSWORD"
sURL = "https://secure-test.bibit.com/jsp/merchant/xml/paymentService.jsp"
'(1) Aviansh
sXML = makeXMLorder '< This simple XMl String returned from Function below>
call XML2Bibit(sXML)
sub XML2Bibit(sXML)'That String is Passed to subroutine
Response.Write "<PRE>" & server.HTMLEncode(sXML) & "</pre><BR>sending XML... <HR>" ' check what you're sending
Response.flush
'Send the XML--------------------------------------------------------------
'(2)Avinash
'U can use Webresponse and webrequest Insted of Msxml2.ServerXMlHttp
'http://www.netomatix.com/Development/XmlWebRequest.aspx
Set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP") ' the MS parser HTTP component
' use ServerXMLHTTP - Check http://support.microsoft.com/support/kb/articles/Q237/9/06.ASP
' if you get 'Err = Access is denied.' then try Msxml2.XMLHTTP (less reliable)
if err then
Response.Write "Err = " & err.description & "<BR>"
Response.Write "Send Status : " & xmlhttp.status & "<BR>"
Response.End
end if
Response.Write "Send Status (200 = OK) : <B>" & xmlhttp.status & "</b><BR>"
'Response.write "Headers :" & "<BR>" & xmlhttp.getAllResponseHeaders
'(3)Aviansh
'It is Just taking info in and parsing Which u can do easly in step 2
sUrl = ParseResponse(xmlhttp.responseText)
if instr(sUrl,"ERROR") then
Response.Write sURL
Response.Write "<BR>Error received from Bibit :"
Response.Write "<BR><PRE>" & server.htmlencode(xmlhttp.responseText)
else
Response.Write "<BR>Redirect URL : <A HREF=" & sUrl & ">" & sUrl & "</A>"
'Response.redirect url ' go to BIBIT payment selection page
end if
end sub
'------------------------------------------------------------------------------
function ParseResponse(sXML)
Set xmldoc = CreateObject("msxml2.domdocument")
xmldoc.async = False : xmldoc.validateOnParse = true
xmldoc.setProperty "ServerHTTPRequest", true ' may not be needed - see http://support.microsoft.com/support/kb/articles/Q281/1/42.ASP
If Not xmldoc.loadxml(sXML) Then
tmp = "ERROR - XML load failed ! <BR>"
tmp = tmp & "errorcode : " & xmldoc.parseError.errorcode & ", " & xmldoc.parseError.reason & "<BR>"
tmp = tmp & "srctext : " & xmldoc.parseError.srctext & "<BR>"
tmp = tmp & "url : " &xmldoc.parseError.url & "<BR><BR>"
tmp = tmp & "XML received : " & Server.HTMLEncode(sXML)
ParseResponse = tmp
else
Set oCurrNode = xmldoc.documentElement.selectSingleNode("/paymentService/reply/orderStatus/reference")
if oCurrNode is nothing then
ParseResponse = "ERROR - no redirect URL in answer from Bibit"
else
ParseResponse = oCurrNode.text
end if
end if
end function
'------------------------------------------------------------------------------
function makeXMLorder() ' Create a simple test order, change to your needs
xml = "<?xml version='1.0'?>" & vbCRLF
xml = xml & "<!DOCTYPE paymentService PUBLIC '-//Bibit/DTD Bibit PaymentService v1//EN' 'http://dtd.bibit.com/paymentService_v1.dtd'>" & vbCRLF
xml = xml & "<paymentService version='1.0' merchantCode='" & sUser & "'>" & vbCRLF
xml = xml & "<submit>" & vbCRLF
xml = xml & "<order orderCode= 'A" & "-" & datepart("s",now) & "'>" & vbCRLF
xml = xml & "<description>TESTORDER</description>" & vbCRLF
xml = xml & "<amount exponent='2' currencyCode='EUR' value='100'/>" & vbCRLF
xml = xml & "<orderContent><![CDATA[" & request("REMOTE_ADDR") & "]]></orderContent>" & vbCRLF
xml = xml & "<paymentMethodMask><include code='ALL'/></paymentMethodMask>" & vbCRLF
xml = xml & "<shopper><shopperEmailAddress>user@yourdomain.com</shopperEmailAddress></shopper>" & vbCRLF
xml = xml & "</order>" & vbCRLF
xml = xml & "</submit>" & vbCRLF
xml = xml & "</paymentService>"
makeXMLorder = xml
end function
%>
Thanks
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.IO;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LoadPage();
}
public void LoadPage()
{
// mod 010628 - a3
// mod 020829 - a3
string sUser = "YOUR MERCHANTCODE";
string sPass = "PASSWORD";
string sXML = "";
public string makeXMLorder(string sUser)
{
string xml = "";
xml = "<?xml version='1.0'?>";
xml = xml + "<!DOCTYPE paymentService PUBLIC '-//Bibit/DTD Bibit PaymentService v1//EN' 'http://dtd.bibit.com/paymentService_v1.dtd'>";
xml = xml + "<paymentService version='1.0' merchantCode='" + sUser + "'>";
xml = xml + "<submit>";
xml = xml + "<order orderCode= 'A-" + DateTime.Now.ToString() + "'>";
xml = xml + "<description>TESTORDER</description>";
xml = xml + "<amount exponent='2' currencyCode='EUR' value='100'/>";
xml = xml + "<orderContent><![CDATA[" + Request.ServerVariables["REMOTE_ADDR"] + "]]></orderContent>";
xml = xml + "<paymentMethodMask><include code='ALL'/></paymentMethodMask>";
xml = xml + "<shopper><shopperEmailAddress>user@yourdomain.com</shopperEmailAddress></shopper>";
xml = xml + "</order>";
xml = xml + "</submit>";
xml = xml + "</paymentService>";
return xml;
}
}
}
Thanks
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
Irianna
Member
8 Points
41 Posts
WorldPay C# Code anyone?
Dec 07, 2009 01:36 PM|LINK
Hi folks,
Sorry to ask this, i've been rattling my brains over this for a few days now with very little success so thought i'd ask here.
I'm trying to get WorldPay on my .net site, but they dont supply a C# code for it, they only give ASP for it :(
http://www.rbsworldpay.com/support/kb/gg/examples/asp_test_example.txt
I've seen a few posts on this site about WorldPay but not with a copy of the code in C# unfortunatly.
Dont suppose anyone is able to help me with this?
Thanks, Iri
WorldPay
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: WorldPay C# Code anyone?
Dec 08, 2009 12:08 PM|LINK
Hi
I explaing the Logic ...
Just Read (1)Aviansh,(2)Aviansh,(3)Aviansh
<%
'------------------------------------------------------------------------------
' mod 010628 - a3
' mod 020829 - a3
sUser = "YOUR MERCHANTCODE"
sPass = "PASSWORD"
sURL = "https://secure-test.bibit.com/jsp/merchant/xml/paymentService.jsp"
'(1) Aviansh
sXML = makeXMLorder '< This simple XMl String returned from Function below>
call XML2Bibit(sXML)
'================================================================================
sub XML2Bibit(sXML)'That String is Passed to subroutine
Response.Write "<PRE>" & server.HTMLEncode(sXML) & "</pre><BR>sending XML... <HR>" ' check what you're sending
Response.flush
'Send the XML--------------------------------------------------------------
'(2)Avinash
'U can use Webresponse and webrequest Insted of Msxml2.ServerXMlHttp
'http://www.netomatix.com/Development/XmlWebRequest.aspx
Set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP") ' the MS parser HTTP component
' use ServerXMLHTTP - Check http://support.microsoft.com/support/kb/articles/Q237/9/06.ASP
' if you get 'Err = Access is denied.' then try Msxml2.XMLHTTP (less reliable)
xmlhttp.Open "POST",sURL, false, sUser, sPass
xmlhttp.setRequestHeader "Content-Type", "text/xml"
on error resume next
xmlhttp.Send(sXML)
if err then
Response.Write "Err = " & err.description & "<BR>"
Response.Write "Send Status : " & xmlhttp.status & "<BR>"
Response.End
end if
Response.Write "Send Status (200 = OK) : <B>" & xmlhttp.status & "</b><BR>"
'Response.write "Headers :" & "<BR>" & xmlhttp.getAllResponseHeaders
'(3)Aviansh
'It is Just taking info in and parsing Which u can do easly in step 2
sUrl = ParseResponse(xmlhttp.responseText)
if instr(sUrl,"ERROR") then
Response.Write sURL
Response.Write "<BR>Error received from Bibit :"
Response.Write "<BR><PRE>" & server.htmlencode(xmlhttp.responseText)
else
Response.Write "<BR>Redirect URL : <A HREF=" & sUrl & ">" & sUrl & "</A>"
'Response.redirect url ' go to BIBIT payment selection page
end if
end sub
'------------------------------------------------------------------------------
function ParseResponse(sXML)
Set xmldoc = CreateObject("msxml2.domdocument")
xmldoc.async = False : xmldoc.validateOnParse = true
xmldoc.setProperty "ServerHTTPRequest", true ' may not be needed - see http://support.microsoft.com/support/kb/articles/Q281/1/42.ASP
If Not xmldoc.loadxml(sXML) Then
tmp = "ERROR - XML load failed ! <BR>"
tmp = tmp & "errorcode : " & xmldoc.parseError.errorcode & ", " & xmldoc.parseError.reason & "<BR>"
tmp = tmp & "srctext : " & xmldoc.parseError.srctext & "<BR>"
tmp = tmp & "url : " &xmldoc.parseError.url & "<BR><BR>"
tmp = tmp & "XML received : " & Server.HTMLEncode(sXML)
ParseResponse = tmp
else
Set oCurrNode = xmldoc.documentElement.selectSingleNode("/paymentService/reply/orderStatus/reference")
if oCurrNode is nothing then
ParseResponse = "ERROR - no redirect URL in answer from Bibit"
else
ParseResponse = oCurrNode.text
end if
end if
end function
'------------------------------------------------------------------------------
function makeXMLorder() ' Create a simple test order, change to your needs
xml = "<?xml version='1.0'?>" & vbCRLF
xml = xml & "<!DOCTYPE paymentService PUBLIC '-//Bibit/DTD Bibit PaymentService v1//EN' 'http://dtd.bibit.com/paymentService_v1.dtd'>" & vbCRLF
xml = xml & "<paymentService version='1.0' merchantCode='" & sUser & "'>" & vbCRLF
xml = xml & "<submit>" & vbCRLF
xml = xml & "<order orderCode= 'A" & "-" & datepart("s",now) & "'>" & vbCRLF
xml = xml & "<description>TESTORDER</description>" & vbCRLF
xml = xml & "<amount exponent='2' currencyCode='EUR' value='100'/>" & vbCRLF
xml = xml & "<orderContent><![CDATA[" & request("REMOTE_ADDR") & "]]></orderContent>" & vbCRLF
xml = xml & "<paymentMethodMask><include code='ALL'/></paymentMethodMask>" & vbCRLF
xml = xml & "<shopper><shopperEmailAddress>user@yourdomain.com</shopperEmailAddress></shopper>" & vbCRLF
xml = xml & "</order>" & vbCRLF
xml = xml & "</submit>" & vbCRLF
xml = xml & "</paymentService>"
makeXMLorder = xml
end function
%>
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
Irianna
Member
8 Points
41 Posts
Re: WorldPay C# Code anyone?
Dec 08, 2009 12:36 PM|LINK
Thanks alot.
I'll give that a blast but i think thats well beyond my current skill level :)
Irianna
Member
8 Points
41 Posts
Re: WorldPay C# Code anyone?
Dec 15, 2009 01:59 PM|LINK
After lots of struggling, I give up with it :(
Thanks for your help though!
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: WorldPay C# Code anyone?
Dec 15, 2009 03:53 PM|LINK
Chk the sample code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.IO;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LoadPage();
}
public void LoadPage()
{
// mod 010628 - a3
// mod 020829 - a3
string sUser = "YOUR MERCHANTCODE";
string sPass = "PASSWORD";
string sXML = "";
string sURL = "https://secure-test.bibit.com/jsp/merchant/xml/paymentService.jsp";
sXML = makeXMLorder(sUser);
XML2Bibit(sXML, sURL, sUser, sPass);
}
public void XML2Bibit(string sXML,string sURL,string sUser,string sPass)
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "";
postData += sXML;
byte[] data = encoding.GetBytes("" + postData + "," + sUser + "," + sPass);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create( sURL );
myRequest.Method = "POST";
myRequest.ContentType = "text/xml";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
}
public string makeXMLorder(string sUser)
{
string xml = "";
xml = "<?xml version='1.0'?>";
xml = xml + "<!DOCTYPE paymentService PUBLIC '-//Bibit/DTD Bibit PaymentService v1//EN' 'http://dtd.bibit.com/paymentService_v1.dtd'>";
xml = xml + "<paymentService version='1.0' merchantCode='" + sUser + "'>";
xml = xml + "<submit>";
xml = xml + "<order orderCode= 'A-" + DateTime.Now.ToString() + "'>";
xml = xml + "<description>TESTORDER</description>";
xml = xml + "<amount exponent='2' currencyCode='EUR' value='100'/>";
xml = xml + "<orderContent><![CDATA[" + Request.ServerVariables["REMOTE_ADDR"] + "]]></orderContent>";
xml = xml + "<paymentMethodMask><include code='ALL'/></paymentMethodMask>";
xml = xml + "<shopper><shopperEmailAddress>user@yourdomain.com</shopperEmailAddress></shopper>";
xml = xml + "</order>";
xml = xml + "</submit>";
xml = xml + "</paymentService>";
return xml;
}
}
}
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
Irianna
Member
8 Points
41 Posts
Re: WorldPay C# Code anyone?
Feb 08, 2010 09:29 AM|LINK
Thanks for the post - sorry for the delay in replying - How do I make that work with a form which asks for name, invoice number etc?
Thanks in advance,
Iri
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: WorldPay C# Code anyone?
Feb 08, 2010 09:40 AM|LINK
Modify the makeXMLorder() method with other paramter
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
Irianna
Member
8 Points
41 Posts
Re: WorldPay C# Code anyone?
Feb 08, 2010 09:44 AM|LINK
Sorry for my increadable stupidity on this one, but would this work?
public void btnSend_Click(object sender, EventArgs e)
?
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: WorldPay C# Code anyone?
Feb 08, 2010 09:46 AM|LINK
use..
LoadPage();
above method under click event.
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
Irianna
Member
8 Points
41 Posts
Re: WorldPay C# Code anyone?
Feb 08, 2010 09:55 AM|LINK
Lost me there sorry.
So something like
public void btnSend_Click(object sender, EventArgs e)
{
LoadPage();
}
public string makeXMLorder(string sUser)
{
?