我正在尝试从 VB 网站进行条带支付工作。我知道,我知道,“我应该使用 C#”。我不能,因为该站点已经在 VB 中。我对此无能为力。
无论如何,我已经弄清楚了大部分:
- 用户单击具有有效信息的提交按钮
- 表单提交给 Stripe
- Stripe 发回一个令牌
- jQuery ajax 函数将数据发布到捐赠/按条支付
我的 Global.asax.vb 中有这行代码
routes.MapRoute("pay-by-stripe", "donate/pay-by-stripe", New With{.controller = "Dynamic", .action = "PayByStripe"})
所以我在动态控制器中的 PayByStripe 函数如下所示:
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
我在 STR_Response 行收到 400 错误请求错误:
Dim STR_Response As String = Encoding.ASCII.GetString(OBJ_Webclient.UploadValues(STR_Stripe_API_URL, OBJ_Transaction))
我是 VB 和 Stripe 菜鸟,不知道这意味着什么。我现在的主要理论是,这是因为我没有 /donate/pay-by-stripe/ 页面,但我不知道如果我创建它我什至会放在那里。
任何帮助都会很棒!