How can i modify this generic hander to recieve json response from api.
below is the json response sent by the api upon successfull transaction
below is the api code when the user enters the phone it will be executed and after the user has finished the transaction it will send a json reponse to the URL indicating whether the transaction was successful or not as indicated above . My biggest problem is how i can modify this generic hander to recieve this reponse from the API of the service provider so that i can know whether the transaction has been successful.
below is the
api example
below is the json response sent by the api upon successfull transaction
Code:
{"status": "SUCCESSFUL", "msisdn": "256782123456", "initiation_date": "2019-10-21 09:03:03","completion_date": "2019-10-21 09:03:22", "amount": 20000, "receipt_number": "1587906379","reference_code": "c1a943f6-3f1aa162-95434a95-ef93f253-1aa43dc7"}
below is the
api example
Code:
Dim Subscriptiondetails As Map
Subscriptiondetails.Initialize
Subscriptiondetails.put("username","ggg")
Subscriptiondetails.put("password", "ggg")
Subscriptiondetails.put("api","depositmobilemoney")
Subscriptiondetails.put("msisdn","256782911364")
Subscriptiondetails.put("amount",1000)
Subscriptiondetails.put("narration","Subscription")
Subscriptiondetails.put("reference","sbscr")
'Subscriptiondetails.put("status_notification_url","URl")
Subscriptiondetails.put("status_notification_url","needed generic handler here to recieve reponse posted by the api")
'Depends on json library
Dim json As JSONGenerator
json.Initialize(Subscriptiondetails)
Dim content As String = json.ToString
'Depends on okHttputils library
Dim client As HttpJob
client.Initialize("",Me)
client.PostString("https://payments-dev.blink.co.ug/api/",content)
client.GetRequest.SetContentType("application/json") 'set the header as json
client.GetRequest.SetContentEncoding("UTF8") 'set encoding as utf8
Wait For Jobdone(client As HttpJob)
If client.Success Then
Dim Resultd As String = client.GetString
Dim data As JSONParser
data.Initialize(Resultd)
Dim product As Map = data.NextObject 'I suspect the response is a json object
Dim y As String = product.Get("status")
Dim z As String = product.Get("error")
Dim w As String = product.Get("reference_code")
If y = "PENDING" And z = "false" Then
MsgboxAsync("Hey!, Yr subscription IS BEING WORKED UPON THANK YOU","Alright")
End If
End If
End If
End If
End If
End If
Code:
<%@ WebHandler Language="VB" Class="HandlerVB" %>
Imports System
Imports System.Web
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Web.Script.Serialization
Public Class HandlerVB : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim callback As String = context.Request.QueryString("callback")
' Dim customerId As String = 0
' Integer.TryParse(context.Request.QueryString("customerId"), customerId)
Dim json As String = Me.GetCustomersJSON()
If Not String.IsNullOrEmpty(callback) Then
json = String.Format("{0}({1});", callback, json)
End If
context.Response.ContentType = "text/json"
context.Response.Write(json)
End Sub
Private Function GetCustomersJSON() As String
Dim customers As New List(Of Object)()
Using conn As New SqlConnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using cmd As New SqlCommand()
cmd.CommandText = "SELECT * FROM CheckVersionNo"
' cmd.Parameters.AddWithValue("@CustomerId", customerId)
cmd.Connection = conn
conn.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
customers.Add(New With {
.CurrentVersion = sdr("CurrentVersion"),
.ReleaseDate = sdr("ReleaseDate")})
End While
End Using
conn.Close()
End Using
Return (New JavaScriptSerializer().Serialize(customers))
End Using
End Function
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class