Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
Ruby on rails 条带支付在本地主机上有效,但在Heroku上不起作用_Ruby On Rails_Heroku_Stripe Payments - Fatal编程技术网

Ruby on rails 条带支付在本地主机上有效,但在Heroku上不起作用

Ruby on rails 条带支付在本地主机上有效,但在Heroku上不起作用,ruby-on-rails,heroku,stripe-payments,Ruby On Rails,Heroku,Stripe Payments,希望一切都好 为什么我在ruby on rails中的条带支付在我的本地主机(即c9.io帐户)上工作,我感到困惑,但当我在Heroku中部署代码时,它给了我以下错误: 无法向没有活动卡的客户收费 my orders.coffee文件: jQuery -> Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content')) payment.setupForm() payment = setupForm:

希望一切都好 为什么我在ruby on rails中的条带支付在我的本地主机(即c9.io帐户)上工作,我感到困惑,但当我在Heroku中部署代码时,它给了我以下错误:

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

my orders.coffee文件:

jQuery ->
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
  payment.setupForm()

payment =
  setupForm: ->
    $('#new_order').submit ->
      $('input[type=submit]').attr('disabled', true)
      obj = Stripe.card.createToken($('#new_order'), payment.handleStripeResponse)
      alert(JSON.stringify(obj));

  handleStripeResponse: (status, response) ->
    if status == 200
      $('#new_order').append($('<input type="hidden" name="stripeToken" />').val(response.id))
      $('#new_order')[0].submit()
    else
      $('#stripe_error').text(response.error.message).show()
      $('input[type=submit]').attr('disabled', false)
my application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
我从heroku获得的样本的条纹仪表板

有人能告诉我为什么我有这样一个奇怪的问题吗? 左一个来自heroku,右一个来自localhost
如果需要更多信息,请立即询问。

我认为在Heroku上进行测试时,您会向新客户收取费用,而该客户没有任何可用的默认卡。请在创建订单费用之前添加创建新卡\u controller.rb

Stripe.api_key = ENV["stripe_api_key"]
    #flash[:notice] = Stripe.api_key
    #puts "stripe api key is " + Stripe.api_key
    token = params[:stripeToken]

    begin
      customer = Stripe::Customer.create(
        :source  => token,
        :description => "Customer.create"
        )

      card = customer.sources.create({:source => token})

      charge = Stripe::Charge.create(
        :amount => (@listing.price * 100).floor,
        :description => 'charge.create',
        :currency => "usd",
        :customer => customer.id,
        :source => card.id
        )
      flash[:notice] = "Thanks for ordering!"
    rescue Stripe::CardError => e
       flash[:danger] = e.message
    end

因此,此错误意味着(
Stripe::Charge.create(…)
)失败,因为客户没有付款来源

这反过来意味着,当您:

token
必须是
nil
或空字符串,因此没有
source
参数发送到Stripe。您可以通过查看条带仪表板中客户创建请求的日志条目来检查这一点

这反过来意味着
params[:stripeToken]
本身就是
nil
或空字符串


不幸的是,我不知道为什么会这样。我建议在CoffeeScript文件的
stripeResponseHandler
回调和Rails控制器中添加一些日志,检查令牌是否已成功创建和提交。

我认为您的错误只是创建了一个条带客户帐户并将令牌传递给客户,但没有将令牌传递给实际费用。在这两种情况下都需要这样做。Stripe的许多用例可以用于创建订阅或稍后处理付款,这就是为什么客户创建时会将令牌存档。但要产生电荷,你也需要这样做。因此,我会编辑代码,将令牌包含在费用中,如下所示:

2003年11月编辑 事实上,我继续并将代码还原为您拥有的代码。通过进一步阅读API,我认为您可以使它以这种方式工作。如果你打算创建一个可以在以后再次收费的客户,那么我将考虑的方向是,它在本地有效,但在Heroku上无效。我认为这不是关于条带代码,而是关于生产的变化。查看ENV变量,看看它是否同时为dev和production设置。但不仅如此,我还会预编译您的资产,因为Heroku在CSS或jQuery方面往往有问题,至少在我从开发到生产的过程中是这样。运行
RAILS\u ENV=production bundle exec rake assets:precompile
,这样就可以完成任务,然后推送到master

请参见:

如果您只是想向他们收费,但不想保留信息,您可以使用:

token = params[:stripeToken]

begin
  charge = Stripe::Charge.create(
    :amount => (@listing.price * 100).floor,
    :currency => "usd",
    :source => token,
    :description => "Example charge"
  )
  flash[:notice] = "Thanks for ordering!"
rescue Stripe::CardError => e
   flash[:danger] = e.message
end
编辑2007年11月 好的,在查看实际的回购协议时,我认为您遇到了一个问题,因为您没有必要的javascript调用来首先创建令牌。我想在这里引用Stripe Api: 并将其插入orders.js文件中,但这取决于以创建订单的形式使用这些类命名的各种输入字段。我希望这能帮你找到正确的方向。就我所知,其他一切看起来都应该是好的

Stripe.card.createToken({
  number: $('.card-number').val(),
  cvc: $('.card-cvc').val(),
  exp_month: $('.card-expiry-month').val(),
  exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);


我试过了,但是我得到了这个错误,我不能使用source twicedo您还有其他建议吗?如何与youTry聊天以删除:source=>创建客户时的令牌我将我的github帐户添加到我的配置文件中,如果您想检查我的代码:你是对的。由于某种原因,在heroku中,我没有为params[:stripeToken]获取任何值?你认为heroku对咖啡剧本有意见吗?我不知道为什么会这样。在添加隐藏的
stripeToken
字段后但在提交表单之前,能否在
stripeResponseHandler
回调中添加警报,以确保
stripeToken
确实包含令牌?如果您想检查我的代码,我已将我的github帐户添加到我的个人资料中。:)您是否在混合测试和生产API键?我不这么认为。你能把你的问题改一下吗?您认为eelse会有什么问题?您的测试/开发和生产环境可能有单独的条带API密钥,所以您在Heroku的任何地方都使用了正确的密钥吗?@muistooshort是的,我检查了所有的问题ok@muistooshort如果您想查看我的代码,我已将我的github帐户添加到我的个人资料中。:)当我闪烁[:alert]令牌的值时,我没有得到任何东西。除非token=params[:stripeToken]flash[:alert]=“您没有正确提交表单”结束我知道您没有正确提交表单警报我按照您所说的做了,我收到了此错误客户CUU x没有ID为tok_y的链接源。很抱歉,我的响应太晚了。首先,我遇到了这个问题,Gem::LoadError:为数据库适配器指定了“postgresql”,但没有加载Gem。将
gem'pg'
添加到您的gem文件中(并确保其版本为ActiveRecord要求的最低版本)。我把gem'pg'放在global中,没有错误,但我不确定。我按照你的建议运行了资产管道,但我仍然有这个问题。如果您想解决此问题,我愿意共享我的github。如果您想查看我的代码,我已将我的github帐户添加到我的个人资料中。:)看看你的订单表。我看到您在那里反复列出了nil,从我可以看出,这可能是问题的一部分,因为它没有获取表单中输入的数据,而是将其传递为nil。具体查看卡号、卡号,选择月份和年份。文本字段中列出了nil。看起来这是一个表单错误。
customer = Stripe::Customer.create(
  :source  => token,
  :description => "Customer.create"
)
token = params[:stripeToken]

begin
  customer = Stripe::Customer.create(
    :source  => token,
    :description => "Customer.create"
    )
  charge = Stripe::Charge.create(
    :amount => (@listing.price * 100).floor,
    :description => 'charge.create',
    :currency => "usd",
    :customer    => customer.id
    )
  flash[:notice] = "Thanks for ordering!"
rescue Stripe::CardError => e
   flash[:danger] = e.message
end
token = params[:stripeToken]

begin
  charge = Stripe::Charge.create(
    :amount => (@listing.price * 100).floor,
    :currency => "usd",
    :source => token,
    :description => "Example charge"
  )
  flash[:notice] = "Thanks for ordering!"
rescue Stripe::CardError => e
   flash[:danger] = e.message
end
Stripe.card.createToken({
  number: $('.card-number').val(),
  cvc: $('.card-cvc').val(),
  exp_month: $('.card-expiry-month').val(),
  exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);