-
-
Save molpe/611158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'md5' | |
class Chargify::HooksController < ApplicationController | |
protect_from_forgery :except => :dispatch | |
before_filter :verify, :only => :dispatch | |
EVENTS = %w[ test signup_success signup_failure renewal_success renewal_failure payment_success payment_failure billing_date_change subscription_state_change subscription_product_change ].freeze | |
def dispatch | |
event = params[:event] | |
render :nothing, :status => 404 unless EVENTS.include? event | |
self.send event | |
end | |
def test | |
Rails.logger.debug "Chargify Webhook test!" | |
render :nothing, :status => 200 | |
end | |
def signup_success | |
render :nothing, :status => 200 | |
end | |
def signup_failure | |
render :nothing, :status => 200 | |
end | |
def renewal_success | |
render :nothing, :status => 200 | |
end | |
def renewal_failure | |
render :nothing, :status => 200 | |
end | |
def payment_success | |
render :nothing, :status => 200 | |
end | |
def payment_failure | |
render :nothing, :status => 200 | |
end | |
def billing_date_change | |
render :nothing, :status => 200 | |
end | |
def subscription_state_change | |
render :nothing, :status => 200 | |
end | |
def subscription_product_change | |
render :nothing, :status => 200 | |
end | |
protected | |
def verify | |
if params[:signature].nil? | |
params[:signature] = request.headers["HTTP_X_CHARGIFY_WEBHOOK_SIGNATURE"] | |
end | |
unless MD5::hexdigest(CHARGIFY_CONFIG['subdomain_shared_key'] + request.raw_post) == params[:signature] | |
render :nothing, :status => :forbidden | |
end | |
end | |
end | |
# route | |
#map.chargify_hooks '/chargify/hooks', :controller => 'chargify/hooks', :action => "dispatch", :conditions => { :method => :post } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment