Working code with new tpid in the reply_url
Added custom error to handle unauthorized