我的 Controller :
class ChargesController < ApplicationController
skip_before_action :verify_authenticity_token
protect_from_forgery prepend: true
def new
end
def create
# Amount in cents
@amount = 500
token = params[:stripeToken]
payment_form = params[:payment_form]
charge = Stripe::Charge.create({
:source => params[:stripeToken],
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
})
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
我的 API 请求正在处理,但都有错误。
Stripe 错误:
{
"error": {
"code": "parameter_missing",
"doc_url": "https://stripe.com/docs/error-codes/parameter-missing",
"message": "Must provide source or customer.",
"type": "invalid_request_error"
}
}
当我使用客户时,API 请求成功,但有错误。本质上是同一件事,只是想提一下以防相关。无论哪种方式,同样的问题仍然存在,并且 token 没有通过。我的所有 JavaScript 似乎都是正确的,您是否发现我的 Controller 或其他任何问题?
以防万一,这是我在 Controller 中使用客户时出现的错误:
{
"error": {
"code": "missing",
"doc_url": "https://stripe.com/docs/error-codes/missing",
"message": "Cannot charge a customer that has no active card",
"param": "card",
"type": "card_error"
}
}
怎么了?有什么建议或建议吗?
最佳答案
对于遇到类似问题的任何人..
这篇文章已经解决了这个问题:Stripe API Invalid Request: Must provide source or customer
这是由于正在开发中而不是在生产中。
我变了
:source => params[:stripeToken],
至
:source => 'tok_visa',
只要我使用 Visa(Visa 测试号码为 stripe 4242...)信用卡,它就可以在开发中使用。
我相信,一旦投入生产,就将其切换回来。目前还没有,但这就是要点。
关于javascript - Stripe::InvalidRequestError(必须提供来源或客户。):Stripe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53020026/