Imports System.Configuration
Imports System.Web.Security
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Reflection
Private _WebServiceUrl As String = ConfigurationManager.AppSettings("PaymentExpress.PxPay")
Private _PxPayUserId As String
Private _PxPayKey As String
Public Sub New(ByVal PxPayUserId As String, ByVal PxPayKey As String)
_PxPayUserId = PxPayUserId
Public Function ProcessResponse(ByVal result As String) As ResponseOutput
Dim myResult As ResponseOutput = New ResponseOutput(SubmitXml(ProcessResponseXml(result)))
Public Function GenerateRequest(ByVal input As RequestInput) As RequestOutput
Dim result As RequestOutput = New RequestOutput(SubmitXml(GenerateRequestXml(input)))
Private Function SubmitXml(ByVal InputXml As String) As String
Dim webReq As HttpWebRequest = CType(WebRequest.Create(_WebServiceUrl), HttpWebRequest)
reqBytes = System.Text.Encoding.UTF8.GetBytes(InputXml)
webReq.ContentType = "application/x-www-form-urlencoded"
webReq.ContentLength = reqBytes.Length
Dim requestStream As Stream = webReq.GetRequestStream()
requestStream.Write(reqBytes, 0, reqBytes.Length)
Dim webResponse As HttpWebResponse = CType(webReq.GetResponse(), HttpWebResponse)
Using sr As StreamReader = New StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.ASCII)
Private Function GenerateRequestXml(ByVal input As RequestInput) As String
Dim sw As StringWriter = New StringWriter()
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.NewLineOnAttributes = False
settings.OmitXmlDeclaration = True
Using writer As XmlWriter = XmlWriter.Create(sw, settings)
writer.WriteStartDocument()
writer.WriteStartElement("GenerateRequest")
writer.WriteElementString("PxPayUserId", _PxPayUserId)
writer.WriteElementString("PxPayKey", _PxPayKey)
Dim properties As PropertyInfo() = input.[GetType]().GetProperties()
For Each prop As PropertyInfo In properties
Dim val As String = CStr(prop.GetValue(input, Nothing))
If val IsNot Nothing OrElse val <> String.Empty Then
writer.WriteElementString(prop.Name, val)
writer.WriteEndDocument()
Private Function ProcessResponseXml(ByVal result As String) As String
Dim sw As StringWriter = New StringWriter()
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.NewLineOnAttributes = False
settings.OmitXmlDeclaration = True
Using writer As XmlWriter = XmlWriter.Create(sw, settings)
writer.WriteStartDocument()
writer.WriteStartElement("ProcessResponse")
writer.WriteElementString("PxPayUserId", _PxPayUserId)
writer.WriteElementString("PxPayKey", _PxPayKey)
writer.WriteElementString("Response", result)
writer.WriteEndDocument()
Public Class RequestInput
Private _AmountInput As String
Private _BillingId As String
Private _CurrencyInput As String
Private _DpsBillingId As String
Private _DpsTxnRef As String
Private _EmailAddress As String
Private _EnableAddBillCard As String
Private _MerchantReference As String
Private _TxnData1 As String
Private _TxnData2 As String
Private _TxnData3 As String
Private _TxnType As String
Private _UrlFail As String
Private _UrlSuccess As String
Public Property AmountInput As String
Set(ByVal value As String)
Public Property BillingId As String
Set(ByVal value As String)
Public Property CurrencyInput As String
Set(ByVal value As String)
Public Property DpsBillingId As String
Set(ByVal value As String)
Public Property DpsTxnRef As String
Set(ByVal value As String)
Public Property EmailAddress As String
Set(ByVal value As String)
Public Property EnableAddBillCard As String
Return _EnableAddBillCard
Set(ByVal value As String)
_EnableAddBillCard = value
Public Property MerchantReference As String
Return _MerchantReference
Set(ByVal value As String)
_MerchantReference = value
Public Property TxnData1 As String
Set(ByVal value As String)
Public Property TxnData2 As String
Set(ByVal value As String)
Public Property TxnData3 As String
Set(ByVal value As String)
Public Property TxnType As String
Set(ByVal value As String)
Public Property TxnId As String
Set(ByVal value As String)
Public Property UrlFail As String
Set(ByVal value As String)
Public Property UrlSuccess As String
Set(ByVal value As String)
Public Property Opt As String
Set(ByVal value As String)
Public Class RequestOutput
Public Sub New(ByVal Xml As String)
Public Property valid As String
Set(ByVal value As String)
Public Property URI As String
Set(ByVal value As String)
Public ReadOnly Property Url As String
Return _URI.Replace("&", "&")
Private Sub SetProperty()
Dim reader As XmlReader = XmlReader.Create(New StringReader(_Xml))
If reader.NodeType = XmlNodeType.Element Then
prop = Me.[GetType]().GetProperty(reader.Name)
If prop IsNot Nothing Then
Me.[GetType]().GetProperty(reader.Name).SetValue(Me, reader.ReadString(), System.Reflection.BindingFlags.[Default], Nothing, Nothing, Nothing)
If reader.HasAttributes Then
For count As Integer = 0 To reader.AttributeCount - 1
reader.MoveToAttribute(count)
prop = Me.[GetType]().GetProperty(reader.Name)
If prop IsNot Nothing Then
Me.[GetType]().GetProperty(reader.Name).SetValue(Me, reader.Value, System.Reflection.BindingFlags.[Default], Nothing, Nothing, Nothing)
Public Class ResponseOutput
Public Sub New(ByVal Xml As String)
Private _AmountSettlement As String
Private _AuthCode As String
Private _CardName As String
Private _CardNumber As String
Private _DateExpiry As String
Private _DpsTxnRef As String
Private _Success As String
Private _ResponseText As String
Private _DpsBillingId As String
Private _CardHolderName As String
Private _CurrencySettlement As String
Private _TxnData1 As String
Private _TxnData2 As String
Private _TxnData3 As String
Private _TxnType As String
Private _CurrencyInput As String
Private _MerchantReference As String
Private _ClientInfo As String
Private _EmailAddress As String
Private _BillingId As String
Private _TxnMac As String
Public Property valid As String
Set(ByVal value As String)
Public Property AmountSettlement As String
Set(ByVal value As String)
_AmountSettlement = value
Public Property AuthCode As String
Set(ByVal value As String)
Public Property CardName As String
Set(ByVal value As String)
Public Property CardNumber As String
Set(ByVal value As String)
Public Property DateExpiry As String
Set(ByVal value As String)
Public Property DpsTxnRef As String
Set(ByVal value As String)
Public Property Success As String
Set(ByVal value As String)
Public Property ResponseText As String
Set(ByVal value As String)
Public Property DpsBillingId As String
Set(ByVal value As String)
Public Property CardHolderName As String
Set(ByVal value As String)
Public Property CurrencySettlement As String
Return _CurrencySettlement
Set(ByVal value As String)
_CurrencySettlement = value
Public Property TxnData1 As String
Set(ByVal value As String)
Public Property TxnData2 As String
Set(ByVal value As String)
Public Property TxnData3 As String
Set(ByVal value As String)
Public Property TxnType As String
Set(ByVal value As String)
Public Property CurrencyInput As String
Set(ByVal value As String)
Public Property MerchantReference As String
Return _MerchantReference
Set(ByVal value As String)
_MerchantReference = value
Public Property ClientInfo As String
Set(ByVal value As String)
Public Property TxnId As String
Set(ByVal value As String)
Public Property EmailAddress As String
Set(ByVal value As String)
Public Property BillingId As String
Set(ByVal value As String)
Public Property TxnMac As String
Set(ByVal value As String)
Private Sub SetProperty()
Dim reader As XmlReader = XmlReader.Create(New StringReader(_Xml))
If reader.NodeType = XmlNodeType.Element Then
prop = Me.[GetType]().GetProperty(reader.Name)
If prop IsNot Nothing Then
Me.[GetType]().GetProperty(reader.Name).SetValue(Me, reader.ReadString(), System.Reflection.BindingFlags.[Default], Nothing, Nothing, Nothing)
If reader.HasAttributes Then
For count As Integer = 0 To reader.AttributeCount - 1
reader.MoveToAttribute(count)
prop = Me.[GetType]().GetProperty(reader.Name)
If prop IsNot Nothing Then
Me.[GetType]().GetProperty(reader.Name).SetValue(Me, reader.Value, System.Reflection.BindingFlags.[Default], Nothing, Nothing, Nothing)