希望一切都好
我感到困惑的是为什么我的本地主机上的 ruby on rails上的条带支付是c9.io帐户但是当我在Heroku中部署我的代码时,它给了我这个错误:
我感到困惑的是为什么我的本地主机上的 ruby on rails上的条带支付是c9.io帐户但是当我在Heroku中部署我的代码时,它给了我这个错误:
Cannot charge a customer that has no active card
我的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获得的样本
谁能让我知道为什么我有这么奇怪的问题?
左边一个来自heroku,右边一个来自localhost
如果需要更多信息,请将其提出.
解决方法
因此,此错误意味着
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回调中添加一些日志,以检查令牌是否已成功创建和提交.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。