2016-10-01 5 views
1
#stripe_controller.rb 

class StripeController < ApplicationController 
    protect_from_forgery except: :stripe_webook 
    skip_before_action :verify_authenticity_token  

    def stripe_webook 
     data_json = JSON.parse(request.body.read) 
     event_id = data_json['id'] 
     data = Stripe::Event.retrieve(event_id) 
     handle_webhook(data) 
     head :ok 
    end 

しかし、私は答えを検索した後200Railsは4 - ストライプは、ウェブフック500エラー

を取得していますcurl

curl -i  -H "Content-Type: application/json" 
      -X POST -'{"id":"evt_0000000000000001","object":"event","api_version":"2016-03-07","created":1475273919,"data":{"object":{"id":"in_xxxxxxxxxxxxxxxxxxx","object":"invoice","amount_due":2900,"application_fee":null,"attempt_count":1,"attempted":true,"charge":"ch_xxxxxxxxxxxxxx","closed":false,"currency":"usd","customer":"cus_xxxxxxxxxxxx","date":1475270308,"description":null,"discount":null,"ending_balance":0,"forgiven":false,"lines":{"object":"list","data":[{"id":"sub_xxxxxxxxxxx","object":"line_item","amount":2900,"currency":"usd","description":null,"discountable":true,"livemode":false,"metadata":{},"period":{"start":1475270272,"end":1477862272},"plan":{"id":"tier_a_plan","object":"plan","amount":2900,"created":1475099850,"currency":"usd","interval":"month","interval_count":1,"livemode":false,"metadata":{},"name":"Startup","statement_descriptor":null,"trial_period_days":15},"proration":false,"quantity":1,"subscription":null,"type":"subscription"}],"has_more":false,"total_count":1,"url":"/v1/invoices/in_xxxxxxxxxxxxxxxx/lines"},"livemode":false,"metadata":{},"next_payment_attempt":1475360318,"paid":false,"period_end":1475270272,"period_start":1475269805,"receipt_number":null,"starting_balance":0,"statement_descriptor":null,"subscription":"sub_xxxxxxxxxxxxxxx","subtotal":2900,"tax":null,"tax_percent":null,"total":2900,"webhooks_delivered_at":1475270308}},"livemode":false,"pending_webhooks":1,"request":null,"type":"invoice.payment_failed"}'  https://myurl.com/stripe/webhook 

を使用して、ストライプのダッシュボード経由でウェブフックをテストする場合にのみ500エラーを取得 - 私は失われた

答えて

0

あなたのコードのどこかから500が来ています。どこにいるのか分かります。デバッガでステップ実行するか、いくつかのログステートメントを投げて、爆発するまでの距離を確認してください。ストライプを作るべきdata = Stripe::Event.retrieve(event_id)

0

あなたが(それはID evt_0000000001か何かでテストウェブフックだから)が存在し、このラインアウト

コメントし、それが動作するはずはありませんEventを取得しようとしていますこのテストイベントは、より良いテストのために取得可能です。

また、ベストプラクティスは、先頭にhead: okを持つことです。