我正在尝试使用 Rails 在 Stripe 中创建一次一次性充电。我收到以下错误:
Stripe::InvalidRequestError (No such token: tok_18nnwSJ6tVEvTdcVs3dNIhGs)
但是,从照片中可以清楚地看出, token 在参数中。该 token 来自 Stripe.js。
这是我的 Controller 中的代码:
Stripe.api_key = "xxxxxxxxxxx"
customer = Stripe::Customer.create(source: params[:stripeToken])
charge = Stripe::Charge.create({
:amount => 10000,
:currency => "usd",
:customer => customer.id,
:description => "Example charge"
})
我也试过:
Stripe.api_key = "xxxxxxxxxxx"
charge = Stripe::Charge.create({
:amount => 10000,
:currency => "usd",
:source => params[:stripeToken],
:description => "Example charge"
})
这也行不通。所有这些都很简单,直接来自 Stripe 站点的样板代码,知道我做错了什么吗?我对 Stripe 嵌入表单没有任何问题。
最佳答案
我的测试环境一直面临同样的问题和我一直在做的错误,我添加了 Strip 收到的 token ,就像这样一个 tok_18nnwSJ6tVEvTdcVs3dNIhGs,对于我们必须使用的测试环境' tok_visa '在来源。
这是 Stripe 提供的测试源列表。
https://stripe.com/docs/testing#cards
它为我创造了客户,如果它也帮助了其他人,请告诉我。
关于ruby-on-rails - rails/条纹 : No such token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39205423/