Stripe :: InvalidRequestError(必须提供来源或客户。):Stripe

时间:2018-10-27 08:21:56

标签: javascript ruby-on-rails stripe-payments

http://jsfiddle.net/e8wjyb35/

我的控制器:

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请求正在处理,都出错。

条带错误:

{
  "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请求成功,但是有错误。本质上是同一件事,只是想提一下它是否相关。无论哪种方式,令牌都无法通过,仍然存在相同的问题。我所有的JavaScript似乎都正确,您是否看到与此有关的任何问题,我的控制器还是其他问题?

以防万一,这是我在控制器中使用客户时出现的错误:

{
"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"
}
}

怎么了?有什么建议或建议吗?

1 个答案:

答案 0 :(得分:1)

对于遇到类似问题的任何人。

该帖子已经解决了该问题:Stripe API Invalid Request: Must provide source or customer

这是由于正在开发而不是在生产中。

我改变了

:source  => params[:stripeToken],

:source  => 'tok_visa',

只要我使用Visa(条纹4242上的Visa测试号码...)信用卡,它就可以在开发中使用。

我相信,一旦投入生产,然后再将其切换回去即可。还没有,但这就是要旨。