Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4-条带webhook 500错误_Ruby On Rails_Stripe Payments_Webhooks - Fatal编程技术网

Ruby on rails Rails 4-条带webhook 500错误

Ruby on rails Rails 4-条带webhook 500错误,ruby-on-rails,stripe-payments,webhooks,Ruby On Rails,Stripe Payments,Webhooks,我得到了200 在寻找答案之后,我迷路了 那500来自你的代码的某个地方,只有你才能知道在哪里。要么在调试器中一步一步地检查它,要么加入一些日志语句,看看在它爆炸之前您能走多远。500是从您的代码的某个地方来的,只有您才能知道在哪里。要么在调试器中一步一步地检查它,要么抛出一些日志语句,看看在它爆炸之前能走多远。您试图获取一个不存在的事件(因为它是一个id为evt\u000000000 1或其他什么的测试webhook) 注释掉这一行,它应该可以工作:data=Stripe::Event.ret

我得到了
200


在寻找答案之后,我迷路了

那500来自你的代码的某个地方,只有你才能知道在哪里。要么在调试器中一步一步地检查它,要么加入一些日志语句,看看在它爆炸之前您能走多远。

500是从您的代码的某个地方来的,只有您才能知道在哪里。要么在调试器中一步一步地检查它,要么抛出一些日志语句,看看在它爆炸之前能走多远。

您试图获取一个不存在的
事件(因为它是一个id为
evt\u000000000 1
或其他什么的测试webhook)

注释掉这一行,它应该可以工作:
data=Stripe::Event.retrieve(Event\u id)

Stripe应使此测试事件可检索,以便更好地进行测试


此外,最佳做法是在顶部设置
head:ok
您试图获取一个不存在的
事件(因为它是一个id为evt\u000000000 1
的测试webhook或其他东西)

注释掉这一行,它应该可以工作:
data=Stripe::Event.retrieve(Event\u id)

Stripe应使此测试事件可检索,以便更好地进行测试

此外,最佳做法是在顶部设置
标题:ok

 #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
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