ruby-on-rails – 条带支付在LocalHost上有效但在Heroku上不起作
希望一切都好
我感到困惑的是为什么我的本地主机上的 ruby on rails上的条带支付是c9.io帐户但是当我在Heroku中部署我的代码时,它给了我这个错误:
我的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) 来自我的orders.coffee in localhost: 我的application.html.erb标题部分 <head> <title>Estydemo</title> <%= stylesheet_link_tag 'application',media: 'all'%> <%= javascript_include_tag 'https://js.stripe.com/v2/',type: 'text/javascript' %> <%= javascript_include_tag 'application' %> <%= csrf_meta_tags %> <%= tag :meta,:name=> 'stripe-key',:content => STRIPE_PUBLIC_KEY %> </head> 我的orders_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" ) 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 我的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获得的样本 谁能让我知道为什么我有这么奇怪的问题? 如果需要更多信息,请将其提出. 解决方法
因此,此错误意味着
charge creation request(Stripe :: Charge.create(…))失败,因为客户没有付款来源.
这反过来意味着当你created the customer: customer = Stripe::Customer.create( :source => token,:description => "Customer.create" ) token必须是nil或空字符串,因此没有源参数发送到Stripe.您可以通过查看Stripe仪表板中客户创建请求的日志条目来检查此问题. 这反过来意味着params [:stripeToken]本身是nil或空字符串. 不幸的是,我不确定为什么会这样.我建议在CoffeeScript文件和Rails控制器中的stripeResponseHandler回调中添加一些日志,以检查令牌是否已成功创建和提交. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |