Skip to main content

Receiving Notifications

Code Sample

require 'sinatra'
require 'json'

post '/callback' do
request.body.rewind
raw_body = request.body.read
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), ENV['NOTIFICATION_SECRET_KEY'], raw_body)
if Rack::Utils.secure_compare(signature, request.env['X-Go-Signature'])
notif = JSON.parse(raw_body)
"I got some JSON: #{notif.inspect}"
else
halt 400, "Signatures didn't match!"
end
end

GoBiz uses Signature Key mechanism to help you ensure that the notifications you receive are sent by GoBiz. Every request received from GoBiz should have the HTTP header X-Go-Signature, which is computed using HMAC (sha256, notification_secret_key, request_body). If the Signature Key in the request header does not match the Signature Key computed by you, ignore the notification.

The logic of the Signature Key and the sample code to generate the Signature Key are given on the side, in the code section.