Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Chargify Webhook Reflector. Sinatra app I use in dev to get warm fuzzies as the webhooks fly by. Since Chargify will only post to ports 80 or 443 in production, you'll need to run this on a web accessible box on one of those ports. http://docs.chargify.com/webhooks
require 'sinatra'
require 'openssl'
require 'json'
post '/' do
body = request.body.read
puts "Time : #{Time.now}"
puts "Actual Signature : #{request.env['HTTP_X_CHARGIFY_WEBHOOK_SIGNATURE_HMAC_SHA_256']}"
puts "Computed Signature: #{signature(body)}"
puts "Raw Body"
puts "--------"
puts body
puts "-----------------------------------------------------------------------------"
puts ""
puts "JSON"
puts "----"
puts JSON.pretty_generate(params)
puts "-----------------------------------------------------------------------------"
puts ""
200
end
def shared_key
"your Site shared key"
end
def signature(body)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), shared_key, body)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.