Hi,
I’m trying to implement a stripe payment system. I successfully implemented a stripe custom form using stripe elements which captures the card information and returns the token back to my application through the HandleSpecialURL method. But I’m now having trouble getting the second part to work. Within HandleSpecialURL, I need to make a REST call using HTTPSecureSocket back to Stripe to create the charge using the token. But I can’t get any results. Even though I added event handlers for PageReceived and AuthenticationRequired, neither gets called because I think the HandleSpecialURL is ending the session before a response comes back from the secure socket call. How do I pick up the response from the Secure Socket request?
Here’s my code withing the HandleSpecialURL method,…
// Grab the key value pairs from the url string
Dim varsTemp() as String = Split(Request.Entity,"&")
dim vars as new dictionary
For i as Integer = 0 to ubound(varsTemp)
dim key as string = nthField(varsTemp(i),"=",1)
dim value as string = nthField(varsTemp(i),"=",2)
vars.value(key) = value
Next i
// Pull out token and session from url – THIS PART WORKS!
Dim stripeKey as string = “pk_test_g6do5S237ekq10r65BnxO6S0” // hard coding the test key for now
Dim stripeToken as string = vars.value(“stripeToken”)
Dim SessionID as string = vars.value(“session”)
Dim sessionContext As New WebSessionContext(Self.SessionWithIdentifier(sessionID))
// Try submitting the payment request – THIS PART DOES NOT WORK
request.print(“Trying payment request…”)
Dim req As String
Dim form As Dictionary
Dim HTTPS1 as HTTPSecureSocket = new HTTPSecureSocket
req = “https://api.stripe.com/v1/charges”
form = New Dictionary
form.Value(“amount”) = “400”
form.Value(“currency”) = “usd”
form.Value(“card”) = stripeToken
form.Value(“description”) = “Charge for test@example.com”
// Set up handlers – THESE NEVER SEEM TO GET CALLED
AddHandler HTTPS1.PageReceived, AddressOf HandlePageRecieved
AddHandler HTTPS1.AuthenticationRequired, AddressOf HandleAuthReq
HTTPS1.SetFormData(form)
HTTPS1.Secure = True
HTTPS1.SetRequestHeader(“Authorization”, “pk_test_g6do5S237ekq10r65BnxO6S0”)
HTTPS1.ConnectionType = SSLSocket.SSLv23
HTTPS1.Post(req)
return true // I believe the session is ending here, so the handlers never get triggered