Webhooks are events we send to your pre-set endpoints via HTTP POST requests. They serve as a means of notification for when verification(s) has been completed.
Which Verifications require webhooks?
At the moment the following verifications require webhooks to be set:
Webhook signatures are a means for you to verify if a webhook originated from our servers. All webhooks events have the x-verifyme-signature HTTP header which is a hash of the body of the request and your secret key.
Sample Code
constcrypto=require('crypto')// your api secretkey ( testSecretKey or liveSecretKey)constsecretKey=process.env.SECRET_KEYconstWebhookHandler= (req , res ) =>{constsignature=crypto.createHmac('sha512', secretKey).update(JSON.stringify(res.body)).digest('hex');if(signature ===req.headers['x-verifyme-signatue']){// Source of the webhook is verified , Add logic here }}
import ("crypto/hmac""crypto/sha512""encoding/hex""io/ioutil""net/http""os")// your api secretkey ( testSecretKey or liveSecretKey)var secret = os.Getenv("SECRET_KEY")funcWebhookHandler(w http.ResponseWriter, r *http.Request) { hash := hmac.New(sha512.New, []byte(secret)) requestBody, _ := ioutil.ReadAll(r.Body) hash.Write(requestBody) sha := hex.EncodeToString(hash.Sum(nil))if sha == r.Header.Get("x-verifyme-signature") {// Source of the webhook is verified , Add logic here }}
usingSystem;usingSystem.Security.Cryptography;usingSystem.Text;usingNewtonsoft.Json.Linq;namespaceHMacExample{classProgram {staticvoidMain(string[] args) {String key ="YOUR_SECRET_KEY"; //replace with your live or test secret keyString jsonInput ="YOUR_WEBHOOK_PAYLOAD"; //JSON webhook payload gotten from your request handlerString inputString =Convert.ToString(newJValue(jsonInput));String result ="";byte[] secretkeyBytes =Encoding.UTF8.GetBytes(key);byte[] inputBytes =Encoding.UTF8.GetBytes(inputString);using (var hmac =newHMACSHA512(secretkeyBytes)) {byte[] hashValue =hmac.ComputeHash(inputBytes); result =BitConverter.ToString(hashValue).Replace("-",string.Empty);; }Console.WriteLine(result);String verifyMeSignature =""; //put in the request's value for x-verifyme-signatureif(result.ToLower().Equals(verifyMeSignature)) { // valid request from our servers // insert logic here } else { // if it gets to this block it it didnt come from verifyme servers } } }}