ライブストライプのウェブフックを受け取りたいのですが、そのためにはイニシャライザを使用する必要があります。 Stripe_events gemを使用しています。イニシャライザには慣れていませんが、私はここで学びます!イニシャライザでハンドラメソッドを呼び出す方法は?
- 私のevent
(webhook)がhandler_methodで呼び出されるようにします。あなたが見ることができるように
マイ初期化子/ 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]
StripeEvent.configure do |events|
events.subscribe 'charge.succeeded', ReservationsController.new
events.all = AllEvents.new
end
は、私はこの1 stripe_handlerにすべてのイベントを呼び出したいevents.all = AllEvents.new
設定します。 event.typeがExであるものに基づいています。すべてのすべてでアプリ/ stripe_handlers/all_events.rb
class AllEvents
def call(event)
if event.type == 'charge.succeeded'
reservation = Reservation.find_by_transaction_id(event.object.id)
reservation.update_attributes pay_completed: true
# reservation = Reservation.find_by_transaction_id
elsif event.type == 'customer.created'
elsif event.type == 'account.application.deauthorized'
# look out for account.updated and check if the account ID is unknown
end
end
end
で'charge.succeeded'
if event.type == 'charge.succeeded'
etc........
end
、私は、各ウェブフックのためのアクションを行うことができますhandler_methodsにevents.all値を送信します。
うーん、あなたは「handle_methodへのすべての値が」と言う、あなたは様々なイベントを処理するために、個々のメソッドのような意味ですか:
は、その後のイベントを処理するクラスは次のようになりますか?そうであれば、私はあなたが個々の "handler_methods"を作るのを止めていることを理解していません。 – Rashmirathiはい!この 'def call(event)'のようにイベントを受け取ったとすると、内部では、ちょうどwebhookとして送られた特定のイベントであるイベント値を使用します –