我在使用Ruby 2.1.5的Rails 4.0.6應用程序中使用stripe gem和stripe_event gem。直到我嘗試了stripe_event gem自述文件(https://github.com/integrallis/stripe_event#authenticating-webhooks)的'保護webhook端點'或'身份驗證webhooks'部分時,它一直運行良好。看起來這兩個問題都有類似的行爲,所以我只在這裏描述第二個問題。Rails stripe_event gem問題:未初始化的常量Stripe :: SignatureVerificationError
當我嘗試使用下面的代碼驗證我的webhook(在嘗試此操作之前工作正常),我得到一個未初始化的常量錯誤。
#config/initializers/stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
:secret_key => ENV['STRIPE_SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
#this is the line that supposedly tells stripe_event to verify the stripe signature
StripeEvent.signing_secret = ENV['STRIPE_SIGNING_SECRET']
StripeEvent.configure do |events|
events.all do |event|
if event.type == 'invoice.payment_failed'
#handled this event...removed code for clarity since works fine
end
end
end
這是錯誤:
NameError stripe_event/webhook#event
uninitialized constant Stripe::SignatureVerificationError
我從我的條紋儀表板的條紋簽名密鑰如條紋文檔描述:描述https://stripe.com/docs/webhooks#signatures
我一直在測試觸發事件在條紋文檔中:https://stripe.com/docs/recipes/sending-emails-for-failed-payments#testing
對此的任何幫助將不勝感激。
這樣做的伎倆!鑑於錯誤信息,後知後覺 – user3754940