I'm trying to make a stripe payment work from a VB website. I know, I know, "I should use C#". I can't because the site is already in VB. Nothing I can do about it.
Anyway, I have most of it figured out:
- User clicks submit button with valid info
- Form submits to Stripe
- Stripe sends a token back
- A jQuery ajax function posts the data to donate/pay-by-stripe
I have this line of code in my Global.asax.vb
routes.MapRoute("pay-by-stripe", "donate/pay-by-stripe", New With{.controller = "Dynamic", .action = "PayByStripe"})
So my PayByStripe function in the Dynamic Controller looks like this:
Function PayByStripe() ''The Stripe Account API Token Dim STR_Stripe_API_Token As String = "sk_test_*****" ''The Stripe API URL Dim STR_Stripe_API_URL As [String] = "https://api.stripe.com/v1/charges" ''The Stripe Card Token Dim token As String = HttpContext.Request.Form("token") Dim description As String = HttpContext.Request.Form("description") Dim amount As Single = HttpContext.Request.Form("amount") ''Creates a Web Client Dim OBJ_Webclient As New System.Net.WebClient() ''Creates Credentials Dim OBJ_Credentials As New System.Net.NetworkCredential(STR_Stripe_API_Token, "") ''Sets the Credentials on the Web Client OBJ_Webclient.Credentials = OBJ_Credentials ''Creates a Transaction with Data that Will be Sent to Stripe ''Dim OBJ_Transaction As New System.Collections.Specialized.NameValueCollection() Dim OBJ_Transaction As NameValueCollection = New NameValueCollection() OBJ_Transaction.Add("amount", amount) OBJ_Transaction.Add("currency", "usd") OBJ_Transaction.Add("address-country", "US") OBJ_Transaction.Add("description", "") OBJ_Transaction.Add("card", token) ''The Stripe Response String Dim STR_Response As String = Encoding.ASCII.GetString(OBJ_Webclient.UploadValues(STR_Stripe_API_URL, OBJ_Transaction)) 'Response.Redirect("/donate/?transaction=success"); Return STR_Response End Function
I'm getting a 400 bad request error on the STR_Response line:
Dim STR_Response As String = Encoding.ASCII.GetString(OBJ_Webclient.UploadValues(STR_Stripe_API_URL, OBJ_Transaction))
I'm a VB and Stripe noob, and not sure what this means. My main theory now is that it's because I don't have a /donate/pay-by-stripe/ page, but I don't know what I'd even put in there if I did create it.
Any help would be great!