Payment works with a strip on LocalHost, but do not work on Heroku

I hope everything is fine. I am confused why my payment in ruby ​​on rails works on my localhost, which is the c9.io account, but when I deployed my code to Heroku, it gives me this error:

You cannot charge a client that does not have an active card

my orders.coffee file:

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)

from my orders. coffee in localhost:

enter image description here

section of the application.html.erb section

<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>

section of my 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

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 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 .

my toolbar strip for the sample where I get from heroku

enter image description here

Can someone tell me why I have such a weird problem? the left one is from geroku, and the right one is from localhost. enter image description here If you need more information, please ask her.

+4
3

, 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
+3

, , (Stripe::Charge.create(...)) , .

, , , :

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

token nil, , Stripe source. , Stripe.

, , , params[:stripeToken] nil .

, , . , stripeResponseHandler CoffeeScript, Rails, , .

+3

, , Stripe , . . Stripe , Customer Create . . , Charge, :

11/03 , . - , API, , , . , , . , , Heroku. , Stripe . ENV , dev, . , , Heroku CSS jQuery, , , . RAILS_ENV=production bundle exec rake assets:precompile, , .

: https://devcenter.heroku.com/articles/rails-asset-pipeline

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

, Stripe, :

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

11/07 , , , , , javascript . "Stripe Api" : https://stripe.com/docs/stripe.js#collecting-card-details 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);
+3
source

Source: https://habr.com/ru/post/1659459/


All Articles