gpt4 book ai didi

ruby-on-rails - Stripe Payment 在 LocalHost 上有效,但在 Heroku 上无效

转载 作者:行者123 更新时间:2023-12-04 22:57:06 25 4
gpt4 key购买 nike

希望一切都好
我很困惑为什么我在 ruby​​ on rails 中的 strip 支付可以在我的本地主机上运行,​​它是 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 出来:

enter image description here

我的 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 获得的示例的条纹仪表板

enter image description here

谁能告诉我为什么我有这么奇怪的问题?
左边一个来自heroku,右边一个来自localhost
enter image description here
如果需要更多信息,请询问。

最佳答案

我认为在 Heroku 上进行测试时,您会为新客户创建费用,而该客户没有任何卡默认处于事件状态。请在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"
)

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

关于ruby-on-rails - Stripe Payment 在 LocalHost 上有效,但在 Heroku 上无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40351203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com