2016-10-01 35 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 

只得到一個500錯誤通過條紋儀表盤測試網絡掛接時,但是使用curl軌道4 - 條紋網絡掛接500錯誤

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 

我越來越200

尋找問題的答案後 - 我丟失。

回答

0

那500是來自你的代碼的地方,只有你可以找出在哪裏。可以在調試器中逐步瀏覽它,或者輸入一些日誌語句以查看它在爆炸之前得到了多少。

0

你試圖獲取一個Event不存在(因爲它是一個測試網絡掛接ID爲evt_0000000001或東西)

評論了這條線,它應該工作:data = Stripe::Event.retrieve(event_id)

條紋應這個測試事件可以更好地進行測試。

此外,最佳做法是讓head: ok在頂部