vb.net 为什么 Stripe.com 返回错误 (402) Payment Required?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19239339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:23:41  来源:igfitidea点击:

Why does Stripe.com return error (402) Payment Required?

vb.netapistripe-payments

提问by Aaron Brown

I'm not seeing this particular error described in stripes API anywhere. Anyone know what's going on?

我没有在任何地方看到条纹 API 中描述的这个特定错误。有谁知道这是怎么回事?

Here is my VB.net code to create a customer:

这是我创建客户的 VB.net 代码:

Function CreateStripeCustomer(ByVal Token As String) As String
    ''  The Stripe Account API Token - change this for testing 
    Dim STR_Stripe_API_Token As String = "sk_test_SECRET_TEST_KEY" '<-- test secret key. Change to live later.
    ''The Stripe API URL
    Dim STR_Stripe_API_URL As String = "https://api.stripe.com/v1/customers"
    ''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, "MY_STRIPE.COM_PASSWORD")
    ''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()
    OBJ_Transaction.Add("email", "PERFECTLY_VALID_EMAIL")
    OBJ_Transaction.Add("card", "PERFECTLY VALID TOKEN RETURNED BY STRIPE.JS")
    ''The Stripe Response String
    Dim STR_Response As String = Encoding.ASCII.GetString(OBJ_Webclient.UploadValues(STR_Stripe_API_URL, OBJ_Transaction))
    Return STR_Response
End Function

The 402 "payment required" error is happening on the line:

402 "payment required" 错误就在线上发生:

Dim STR_Response As String = Encoding.ASCII.GetString(OBJ_Webclient.UploadValues(STR_Stripe_API_URL, OBJ_Transaction))

回答by mikemaccana

If you're seeing this in live, it's also possible the card number is simply incorrect, eg: if you inspect the body of the 402 response:

如果你在现场看到这个,也有可能是卡号不正确,例如:如果你检查 402 响应的正文:

enter image description here

在此处输入图片说明

回答by Aaron Brown

Well, I switched to my "LIVE" keys instead of my "TEST" keys, and that fixed it. Just wasted 3 hours of my life trying to fix this. Hope this helps somebody else.

好吧,我切换到我的“LIVE”键而不是我的“TEST”键,然后就解决了。只是浪费了我生命中的 3 个小时试图解决这个问题。希望这对其他人有帮助。

回答by Samir Seetal

The more correct answer is that you need to use the appropriate test card numbers. See https://stripe.com/docs/testing

更正确的答案是您需要使用适当的测试卡号。请参阅https://stripe.com/docs/testing

回答by Saleh Rastani

Stripe provides a test environment in which you use the test publishable/secret keys, as oppose to waiting till production. However, what seems like the down side, which is in fact very helpful is that you need to comply to Stripe's testing conditions and use their given card numbers and inputs to test different aspects of your api call.

Stripe 提供了一个测试环境,您可以在其中使用测试可发布/秘密密钥,而不是等到生产。然而,看似不利的一面,实际上非常有用的是,您需要遵守 Stripe 的测试条件并使用他们给定的卡号和输入来测试您的 api 调用的不同方面。

For example, in order to receive certain errors you can input these numbers:

例如,为了接收某些错误,您可以输入这些数字:

card_declined: Use this special card number - 4000000000000002.
incorrect_number: Use a number that fails the Luhn check, e.g. 4242424242424241.
invalid_expiry_month: Use an invalid month e.g. 13.
invalid_expiry_year: Use a year in the past e.g. 1970.
invalid_cvc: Use a two digit number e.g. 99.

For more information refer to the link that Samir posted.

有关更多信息,请参阅 Samir 发布的链接。

回答by Roman Romanenko

For iOS

对于 iOS

If you are following tutorial from Ray Wunderlich websitethe reason why error may appear is that you run your test back end (web.rb file) and after that add you TEST_SECRET_KEY.

如果您正在学习Ray Wunderlich 网站上教程,则可能出现错误的原因是您运行了测试后端(web.rb 文件),然后添加了 TEST_SECRET_KEY。

Go to the terminal click control+C, make sure you have already added your TEST_SECRET_KEY, save file and do ruby web.rb.

转到终端单击control+C,确保您已经添加了 TEST_SECRET_KEY,保存文件并执行ruby web.rb

For now, everything should work fine.

目前,一切正常。

For reference, I used this number of the card for testing: 4242 4242 4242 4242

作为参考,我用这个卡号进行测试:4242 4242 4242 4242