Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法向没有活动卡条的客户收费_Javascript_Ruby On Rails_Stripe Payments - Fatal编程技术网

Javascript 无法向没有活动卡条的客户收费

Javascript 无法向没有活动卡条的客户收费,javascript,ruby-on-rails,stripe-payments,Javascript,Ruby On Rails,Stripe Payments,我正在用stripe.js关闭stripe签出。当我输入一张卡片时,一切都正常,除了它永远不会通过。每当我单击“提交”时,我都会收到一个错误,显示: Cannot charge a customer that has no active card 我试过使用测试卡和真实的信用卡号,但他们都给了我同样的错误。这是我的stripe.rb: class ChargesController < ApplicationController before_action :authentic

我正在用stripe.js关闭stripe签出。当我输入一张卡片时,一切都正常,除了它永远不会通过。每当我单击“提交”时,我都会收到一个错误,显示:

Cannot charge a customer that has no active card 
我试过使用测试卡和真实的信用卡号,但他们都给了我同样的错误。这是我的stripe.rb:

class ChargesController < ApplicationController
    before_action :authenticate_user!
    def new
    end

    def create
      # Amount in cents
      @amount = 500

      customer = Stripe::Customer.create(
        :email => params[:stripeEmail],
        :source  => params[:stripeToken]
      )

      Stripe.api_key = 'sk_test_string'

charge = Stripe::Charge.create(
:amount => 1000,
:customer => customer.id,
:currency => "usd",
:card => params[:stripeToken] # replace full card details with the string token from our params
)

    rescue Stripe::CardError => e
      flash[:error] = e.message
      redirect_to new_charge_path
    end
end
但是我已经填好了卡片错误,应该可以用了。如果有帮助,我正在使用测试键

编辑2:以下是以条带形式发送的内容

id: cus_7gzOPGpAB2DMYY
object: "customer"
account_balance: 0
created: 1452402410
currency: null
default_source: null
delinquent: false
description: "Thank you"
discount: null
email: null
livemode: false
metadata:
shipping: null
sources:
    object: "list"
    data:
    has_more: false
    total_count: 0
    url: "/v1/customers/cus_7gzOPGpAB2DMYY/sources"
subscriptions:
    object: "list"
    data:
    has_more: false
    total_count: 0
    url: "/v1/customers/cus_7gzOPGpAB2DMYY/subscriptions"

我想你应该把
:card=>params[:stripeToken]
放入
Stripe::Customer.create
而不是
Stripe::Charge.create

我联系了Stripe,他们解决了这个问题。这就是haml编写代码的方式。因此,与此相反:

=表单\标签费用\路径:id=>“付款表单”do

您应该这样做:

=表单\标签费用\路径do
#付款单


而且它会正常工作。

除了stripe.js找不到付款单外,一切正常。
error:
    message: "Cannot charge a customer that has no active card"
    type: "card_error"
    param: "card"
    code: "missing"
id: cus_7gzOPGpAB2DMYY
object: "customer"
account_balance: 0
created: 1452402410
currency: null
default_source: null
delinquent: false
description: "Thank you"
discount: null
email: null
livemode: false
metadata:
shipping: null
sources:
    object: "list"
    data:
    has_more: false
    total_count: 0
    url: "/v1/customers/cus_7gzOPGpAB2DMYY/sources"
subscriptions:
    object: "list"
    data:
    has_more: false
    total_count: 0
    url: "/v1/customers/cus_7gzOPGpAB2DMYY/subscriptions"