您需要创建一个控制器来基本接受和处理请求。这是非常简单的,尽管最初并不是那么简单。这里是我的hooks_controller.rb的例子:
class HooksController < ApplicationController
require 'json'
Stripe.api_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def receiver
data_json = JSON.parse request.body.read
p data_json['data']['object']['customer']
if data_json[:type] == "invoice.payment_succeeded"
make_active(data_event)
end
if data_json[:type] == "invoice.payment_failed"
make_inactive(data_event)
end
end
def make_active(data_event)
@profile = Profile.find(User.find_by_stripe_customer_token(data['data']['object']['customer']).profile)
if @profile.payment_received == false
@profile.payment_received = true
@profile.save!
end
end
def make_inactive(data_event)
@profile = Profile.find(User.find_by_stripe_customer_token(data['data']['object']['customer']).profile)
if @profile.payment_received == true
@profile.payment_received = false
@profile.save!
end
end
end
的高清接收机是,你必须给网络挂接指向条纹接口的视图。视图接收的JSON和我用它来更新用户在支付失败或成功的事件概貌。
[使用条纹webhooks与Rails]可能的重复(http://stackoverflow.com/questions/9371566/using-stripe-webhooks-with-rails) – Hauleth 2012-10-29 06:50:31