【发布时间】:2015-03-09 21:47:24
【问题描述】:
我正在从 Stripe 设置一个 webhook。本质上是因为它是一种订阅模式,我需要知道我是否会继续更新这个月。我想通过事件“invoice.payment_succeeded”来做到这一点。
当我在条纹中测试我的 webhook url 时,我得到了这个:
host localhost:3000 resolves to illegal IP 127.0.0.1
我的完整端点是:
localhost:3000/hooks/receiver
路线:
get 'hooks/receiver' => "hooks#receiver"
钩子控制器看起来像这样:
class HooksController < ApplicationController
require 'json'
Stripe.api_key
def receiver
data_json = JSON.parse request.body.read
p data_json['data']['object']['customer']
if data_json[:type] == 'invoice.payment_succeded'
make_active(data_event)
end
if data_json[:type] == 'invoice.payment_failed'
# something make_inactive(data_event)
end
end
def make_active(data_event)
@user = User.find_by_customer_token(data['data']['object']['customer'])
@status = @user.statuses.pluck(:list_id).presence || -1
Resque.enqueue(ScheduleTweets, @user.token, @user.id, @status)
end
def make_inactive(data_event)
end
end
有人知道如何解决这个问题吗?
【问题讨论】:
标签: ruby-on-rails stripe-payments webhooks