【发布时间】:2017-03-14 01:39:03
【问题描述】:
希望一切都好 我很困惑为什么我在 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 来自本地主机:
我的 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
我的应用程序.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 如果需要更多信息,请提出来。
【问题讨论】:
-
您是否正在混合测试和生产 API 密钥?
-
我不这么认为。你能改写你的问题吗?您认为还有什么问题?
-
您可能有单独的 Stripe API 密钥用于您的测试/开发和生产环境,那么您在 Heroku 的任何地方都使用正确的密钥吗?
-
@muistooshort 是的,我检查了一切正常
-
@muistooshort 我将我的 github 帐户添加到我的个人资料中如果您想查看我的代码。 :)
标签: ruby-on-rails heroku stripe-payments