对于上下文,我正在使用Ruby on Rails开发一个Web应用程序,我使用MailChimp来处理电子邮件活动.
给定名为User的ActiveRecord模型,其属性名为email,在成功创建新用户后,如何将用户的电子邮件发送到MailChimp列表?
我正在设置Stripe的webhook.基本上是因为它是一个订阅模式,我需要知道我是否会继续更新月份.我想通过'invoice.payment_succeeded'活动来做到这一点.
当我用条纹测试我的webhook网址时,我得到了这个:
host localhost:3000 resolves to illegal IP 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
我的完整终点是:
localhost:3000/hooks/receiver
Run Code Online (Sandbox Code Playgroud)
路线:
get 'hooks/receiver' => "hooks#receiver"
Run Code Online (Sandbox Code Playgroud)
钩子控制器看起来像这样:
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
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?