SecurePay-VB (PA)

Imports System
Imports System.IO
Imports System.Net
Imports System.Text

Partial Class _Default
   Inherits System.Web.UI.Page

   Public CheckoutId As String = ""

   Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
       CheckoutId = prepareCheckout()
   End Sub

   Public Function prepareCheckout() As String
       Dim url As String = "https://test.oppwa.com/v1/checkouts"
       Dim data As String = "authentication.userId=8a8294184f45ce7e014f4b1d16cc12df" +
           "&authentication.password=j3zCJ2ENaD" +
           "&authentication.entityId=8a8294184f45ce7e014f4b1d16bd12db" +
           "&paymentType=PA" +
           "&amount=499.99" +
           "&currency=RSD"

       Dim request As WebRequest = WebRequest.Create(url)
       request.Method = "POST"
       Dim byteArray As Byte() = Encoding.UTF8.GetBytes(data)
       request.ContentType = "application/x-www-form-urlencoded"
       request.ContentLength = byteArray.Length
       Dim dataStream As Stream = request.GetRequestStream()
       dataStream.Write(byteArray, 0, byteArray.Length)
       dataStream.Close()
       Dim webresponse As WebResponse = request.GetResponse()
       dataStream = webresponse.GetResponseStream()
       Dim reader As New StreamReader(dataStream)
       Dim response As String = reader.ReadToEnd()
       reader.Close()
       dataStream.Close()
       webresponse.Close()
       Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer()
       Dim dict As Dictionary(Of String, Object) = jss.Deserialize(Of Dictionary(Of String, Object))(response)

       Return dict("id")
   End Function

End Class