【问题标题】:Stripe Live Publishable API Key IncorrectStripe Live 可发布 API 密钥不正确
【发布时间】:2015-04-08 21:32:47
【问题描述】:

我正在使用CareerFoundry's 使用 Rails 设置 Stripe Checkout 的教程。我在提交表单时收到错误,表明公共 API 不正确。我认为问题出在下面的初始化程序文件中,但也可能是其他问题。

Config/initializers/stripe.rb

if Rails.env.production?
  Rails.configuration.stripe = {
    publishable_key: ENV[ 'STRIPE_PUBLISHABLE_KEY' ],
    secret_key:      ENV[ 'STRIPE_SECRET_KEY' ]
  }
else
  Rails.configuration.stripe = {
    publishable_key: 'pk_test_UQ2EqhNNQRrDkDouuZ1xgpS5', #Both test keys are fakes in case you're wondering
    secret_key:      'sk_test_hkiYUThcriCTBfHuUSXpUP7n'
  }
end

付款控制器

class PaymentsController < ApplicationController
  def create #You want might to make actions more specific.
    token = params[:stripeToken] #The token when the form is posted includes the stripe token in the url.
    # Create the charge in stripes servers.  This is what commits the transaction.
    begin
      charge = Stripe::Charge.create(
        :amount => 200,
        :currency => "usd",
        :source => token,
        :description => params[:stripeEmail]
        )
      rescue Stripe::CardError => e 
        #The card was decline because of number/ccv error, expired error, bank decline, or zip error

        body = e.json_body
        err = body[:error]
        flash[:error] = "There was an error in processing your card: #{err[:message]}"
    end
    respond_to do |format|
      format.html { redirect_to "/confirmation" }
      #format.html { redirect_to "/purchase", notice: "Purchase was successfully completed.  We'll be in contact shortly!" }
    end
  end
end

视图/共享/_stripe_checkout_button.html.erb

<script
  src="https://checkout.stripe.com/checkout.js" class="stripe-button"
  data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
  data-image="/assets/square-image.png"
  data-name="Achieve More"
  data-description="1 Month ($800)"
  data-amount="2000">
</script>

视图/payments.html.erb

<%= form_tag "/payments" do %>
  <%= render partial: "shared/stripe_checkout_button" %>
<% end %>

【问题讨论】:

    标签: ruby-on-rails initialization stripe-payments


    【解决方案1】:

    因此,CareerFoundry 教程没有任何关于设置密钥的内容。条纹演示确实如此。这一行:

    heroku config:set PUBLISHABLE_KEY=pk_test_UQ2EqhNNQRrDkD5V0Z1xgpS5 SECRET_KEY=sk_test_hkiYUTQzHiCTBfHuUSXpUP7n
    

    设置初始化器的键。那些丢失,导致错误。

    【讨论】:

      猜你喜欢
      • 2020-05-06
      • 2014-03-19
      • 2021-06-05
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 2021-05-25
      相关资源
      最近更新 更多