[{"data":1,"prerenderedAt":779},["ShallowReactive",2],{"navigation_docs":3,"-webhooks-verifying-signatures":23,"-webhooks-verifying-signatures-surround":776},[4,14],{"title":5,"path":6,"stem":7,"children":8,"page":13},"Getting Started","\u002Fgetting-started","1.getting-started",[9],{"title":10,"path":11,"stem":12},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F1.introduction",false,{"title":15,"path":16,"stem":17,"children":18,"page":13},"Webhooks","\u002Fwebhooks","2.webhooks",[19],{"title":20,"path":21,"stem":22},"Verifying webhook signatures","\u002Fwebhooks\u002Fverifying-signatures","2.webhooks\u002F1.verifying-signatures",{"id":24,"title":20,"body":25,"description":770,"extension":771,"links":772,"meta":773,"navigation":182,"path":21,"seo":774,"stem":22,"__hash__":775},"docs\u002F2.webhooks\u002F1.verifying-signatures.md",{"type":26,"value":27,"toc":765},"minimark",[28,37,51,56,106,116,120,703,707,761],[29,30,31,32,36],"p",{},"FlazzPay signs every webhook with your business's webhook secret (",[33,34,35],"code",{},"whsec_…","), created in the dashboard under Developers › Webhooks. Verify the signature before you trust the body.",[38,39,40,41,46,47,50],"note",{},"Every event is described, with its body and headers, in the ",[42,43,45],"a",{"href":44},"\u002Fapi-reference","API reference"," under ",[48,49,15],"strong",{},".",[52,53,55],"h2",{"id":54},"steps","Steps",[57,58,59,67,78,81,96,99],"ol",{},[60,61,62,63,66],"li",{},"Read the ",[48,64,65],{},"raw body"," before you parse it. Do not re-serialize the JSON: the signature covers the exact bytes.",[60,68,69,70,73,74,77],{},"Read ",[33,71,72],{},"X-FlazzPay-Timestamp"," and ",[33,75,76],{},"X-FlazzPay-Signature"," (header names are case-insensitive).",[60,79,80],{},"Reject the request if the timestamp is more than five minutes from your clock.",[60,82,83,84,87,88,91,92,95],{},"Compute ",[33,85,86],{},"hex(HMAC_SHA256(secret, timestamp + \"\\n\" + \"POST\" + \"\\n\" + path_with_query + \"\\n\" + hex(SHA256(raw_body))))",". ",[33,89,90],{},"path_with_query"," is the path and query of the URL you registered, for example ",[33,93,94],{},"\u002Fhooks\u002Fflazzpay",", without the host.",[60,97,98],{},"Compare it with the signature in constant time.",[60,100,101,102,105],{},"Answer with a ",[33,103,104],{},"2xx"," within 10 seconds. Anything else is retried.",[29,107,108,109,73,112,115],{},"Only the timestamp, method, path and body are signed. The ",[33,110,111],{},"X-FlazzPay-Event-Id",[33,113,114],{},"X-FlazzPay-Event-Type"," headers are not: trust the body.",[52,117,119],{"id":118},"examples","Examples",[121,122,123,196,636],"code-group",{},[124,125,131],"pre",{"className":126,"code":127,"filename":128,"language":129,"meta":130,"style":130},"language-php shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F Laravel: $request->getContent() and $request->header('X-FlazzPay-Timestamp')\nfunction flazzpay_verify(string $secret, string $pathWithQuery, string $rawBody, string $timestamp, string $signature, int $toleranceSeconds = 300): bool\n{\n    if (! ctype_digit($timestamp) || abs(time() - (int) $timestamp) > $toleranceSeconds) {\n        return false;\n    }\n    $signed = $timestamp.\"\\n\".\"POST\".\"\\n\".$pathWithQuery.\"\\n\".hash('sha256', $rawBody);\n\n    return hash_equals(hash_hmac('sha256', $signed, $secret), strtolower($signature));\n}\n","PHP","php","",[33,132,133,141,147,153,159,165,171,177,184,190],{"__ignoreMap":130},[134,135,138],"span",{"class":136,"line":137},"line",1,[134,139,140],{},"\u002F\u002F Laravel: $request->getContent() and $request->header('X-FlazzPay-Timestamp')\n",[134,142,144],{"class":136,"line":143},2,[134,145,146],{},"function flazzpay_verify(string $secret, string $pathWithQuery, string $rawBody, string $timestamp, string $signature, int $toleranceSeconds = 300): bool\n",[134,148,150],{"class":136,"line":149},3,[134,151,152],{},"{\n",[134,154,156],{"class":136,"line":155},4,[134,157,158],{},"    if (! ctype_digit($timestamp) || abs(time() - (int) $timestamp) > $toleranceSeconds) {\n",[134,160,162],{"class":136,"line":161},5,[134,163,164],{},"        return false;\n",[134,166,168],{"class":136,"line":167},6,[134,169,170],{},"    }\n",[134,172,174],{"class":136,"line":173},7,[134,175,176],{},"    $signed = $timestamp.\"\\n\".\"POST\".\"\\n\".$pathWithQuery.\"\\n\".hash('sha256', $rawBody);\n",[134,178,180],{"class":136,"line":179},8,[134,181,183],{"emptyLinePlaceholder":182},true,"\n",[134,185,187],{"class":136,"line":186},9,[134,188,189],{},"    return hash_equals(hash_hmac('sha256', $signed, $secret), strtolower($signature));\n",[134,191,193],{"class":136,"line":192},10,[134,194,195],{},"}\n",[124,197,202],{"className":198,"code":199,"filename":200,"language":201,"meta":130,"style":130},"language-js shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F Express: app.post('\u002Fhooks\u002Fflazzpay', express.raw({ type: 'application\u002Fjson' }), ...)\n\u002F\u002F req.body is a Buffer and req.get('X-FlazzPay-Signature') is the signature.\nconst crypto = require('node:crypto')\n\nfunction verifyFlazzPay(secret, pathWithQuery, rawBody, timestamp, signature, toleranceSeconds = 300) {\n  if (!\u002F^\\d+$\u002F.test(timestamp) || Math.abs(Date.now() \u002F 1000 - Number(timestamp)) > toleranceSeconds) return false\n  const bodyHash = crypto.createHash('sha256').update(rawBody).digest('hex')\n  const expected = crypto.createHmac('sha256', secret).update(`${timestamp}\\nPOST\\n${pathWithQuery}\\n${bodyHash}`).digest()\n  const received = Buffer.from(String(signature).toLowerCase(), 'hex')\n  return received.length === expected.length && crypto.timingSafeEqual(received, expected)\n}\n","Node","js",[33,203,204,210,215,248,252,305,404,461,541,589,631],{"__ignoreMap":130},[134,205,206],{"class":136,"line":137},[134,207,209],{"class":208},"sHwdD","\u002F\u002F Express: app.post('\u002Fhooks\u002Fflazzpay', express.raw({ type: 'application\u002Fjson' }), ...)\n",[134,211,212],{"class":136,"line":143},[134,213,214],{"class":208},"\u002F\u002F req.body is a Buffer and req.get('X-FlazzPay-Signature') is the signature.\n",[134,216,217,221,225,229,233,236,239,243,245],{"class":136,"line":149},[134,218,220],{"class":219},"spNyl","const",[134,222,224],{"class":223},"sTEyZ"," crypto ",[134,226,228],{"class":227},"sMK4o","=",[134,230,232],{"class":231},"s2Zo4"," require",[134,234,235],{"class":223},"(",[134,237,238],{"class":227},"'",[134,240,242],{"class":241},"sfazB","node:crypto",[134,244,238],{"class":227},[134,246,247],{"class":223},")\n",[134,249,250],{"class":136,"line":155},[134,251,183],{"emptyLinePlaceholder":182},[134,253,254,257,260,262,266,269,272,274,277,279,282,284,287,289,292,295,299,302],{"class":136,"line":161},[134,255,256],{"class":219},"function",[134,258,259],{"class":231}," verifyFlazzPay",[134,261,235],{"class":227},[134,263,265],{"class":264},"sHdIc","secret",[134,267,268],{"class":227},",",[134,270,271],{"class":264}," pathWithQuery",[134,273,268],{"class":227},[134,275,276],{"class":264}," rawBody",[134,278,268],{"class":227},[134,280,281],{"class":264}," timestamp",[134,283,268],{"class":227},[134,285,286],{"class":264}," signature",[134,288,268],{"class":227},[134,290,291],{"class":264}," toleranceSeconds",[134,293,294],{"class":227}," =",[134,296,298],{"class":297},"sbssI"," 300",[134,300,301],{"class":227},")",[134,303,304],{"class":227}," {\n",[134,306,307,311,315,318,321,324,327,330,333,335,337,340,342,345,348,351,354,356,359,361,364,366,369,372,374,377,380,383,385,387,390,393,395,397,400],{"class":136,"line":167},[134,308,310],{"class":309},"s7zQu","  if",[134,312,314],{"class":313},"swJcz"," (",[134,316,317],{"class":227},"!",[134,319,320],{"class":227},"\u002F",[134,322,323],{"class":309},"^",[134,325,326],{"class":241},"\\d",[134,328,329],{"class":227},"+",[134,331,332],{"class":309},"$",[134,334,320],{"class":227},[134,336,50],{"class":227},[134,338,339],{"class":231},"test",[134,341,235],{"class":313},[134,343,344],{"class":223},"timestamp",[134,346,347],{"class":313},") ",[134,349,350],{"class":227},"||",[134,352,353],{"class":223}," Math",[134,355,50],{"class":227},[134,357,358],{"class":231},"abs",[134,360,235],{"class":313},[134,362,363],{"class":223},"Date",[134,365,50],{"class":227},[134,367,368],{"class":231},"now",[134,370,371],{"class":313},"() ",[134,373,320],{"class":227},[134,375,376],{"class":297}," 1000",[134,378,379],{"class":227}," -",[134,381,382],{"class":231}," Number",[134,384,235],{"class":313},[134,386,344],{"class":223},[134,388,389],{"class":313},")) ",[134,391,392],{"class":227},">",[134,394,291],{"class":223},[134,396,347],{"class":313},[134,398,399],{"class":309},"return",[134,401,403],{"class":402},"sfNiH"," false\n",[134,405,406,409,412,414,417,419,422,424,426,429,431,433,435,438,440,443,445,447,450,452,454,457,459],{"class":136,"line":173},[134,407,408],{"class":219},"  const",[134,410,411],{"class":223}," bodyHash",[134,413,294],{"class":227},[134,415,416],{"class":223}," crypto",[134,418,50],{"class":227},[134,420,421],{"class":231},"createHash",[134,423,235],{"class":313},[134,425,238],{"class":227},[134,427,428],{"class":241},"sha256",[134,430,238],{"class":227},[134,432,301],{"class":313},[134,434,50],{"class":227},[134,436,437],{"class":231},"update",[134,439,235],{"class":313},[134,441,442],{"class":223},"rawBody",[134,444,301],{"class":313},[134,446,50],{"class":227},[134,448,449],{"class":231},"digest",[134,451,235],{"class":313},[134,453,238],{"class":227},[134,455,456],{"class":241},"hex",[134,458,238],{"class":227},[134,460,247],{"class":313},[134,462,463,465,468,470,472,474,477,479,481,483,485,487,490,492,494,496,498,501,503,506,509,512,514,517,520,522,524,526,529,532,534,536,538],{"class":136,"line":179},[134,464,408],{"class":219},[134,466,467],{"class":223}," expected",[134,469,294],{"class":227},[134,471,416],{"class":223},[134,473,50],{"class":227},[134,475,476],{"class":231},"createHmac",[134,478,235],{"class":313},[134,480,238],{"class":227},[134,482,428],{"class":241},[134,484,238],{"class":227},[134,486,268],{"class":227},[134,488,489],{"class":223}," secret",[134,491,301],{"class":313},[134,493,50],{"class":227},[134,495,437],{"class":231},[134,497,235],{"class":313},[134,499,500],{"class":227},"`${",[134,502,344],{"class":223},[134,504,505],{"class":227},"}",[134,507,508],{"class":223},"\\n",[134,510,511],{"class":241},"POST",[134,513,508],{"class":223},[134,515,516],{"class":227},"${",[134,518,519],{"class":223},"pathWithQuery",[134,521,505],{"class":227},[134,523,508],{"class":223},[134,525,516],{"class":227},[134,527,528],{"class":223},"bodyHash",[134,530,531],{"class":227},"}`",[134,533,301],{"class":313},[134,535,50],{"class":227},[134,537,449],{"class":231},[134,539,540],{"class":313},"()\n",[134,542,543,545,548,550,553,555,558,560,563,565,568,570,572,575,578,580,583,585,587],{"class":136,"line":186},[134,544,408],{"class":219},[134,546,547],{"class":223}," received",[134,549,294],{"class":227},[134,551,552],{"class":223}," Buffer",[134,554,50],{"class":227},[134,556,557],{"class":231},"from",[134,559,235],{"class":313},[134,561,562],{"class":231},"String",[134,564,235],{"class":313},[134,566,567],{"class":223},"signature",[134,569,301],{"class":313},[134,571,50],{"class":227},[134,573,574],{"class":231},"toLowerCase",[134,576,577],{"class":313},"()",[134,579,268],{"class":227},[134,581,582],{"class":227}," '",[134,584,456],{"class":241},[134,586,238],{"class":227},[134,588,247],{"class":313},[134,590,591,594,596,598,601,604,606,608,610,613,615,617,620,622,625,627,629],{"class":136,"line":192},[134,592,593],{"class":309},"  return",[134,595,547],{"class":223},[134,597,50],{"class":227},[134,599,600],{"class":223},"length",[134,602,603],{"class":227}," ===",[134,605,467],{"class":223},[134,607,50],{"class":227},[134,609,600],{"class":223},[134,611,612],{"class":227}," &&",[134,614,416],{"class":223},[134,616,50],{"class":227},[134,618,619],{"class":231},"timingSafeEqual",[134,621,235],{"class":313},[134,623,624],{"class":223},"received",[134,626,268],{"class":227},[134,628,467],{"class":223},[134,630,247],{"class":313},[134,632,634],{"class":136,"line":633},11,[134,635,195],{"class":227},[124,637,642],{"className":638,"code":639,"filename":640,"language":641,"meta":130,"style":130},"language-go shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F body, _ := io.ReadAll(r.Body); r.Header.Get(\"X-FlazzPay-Signature\")\nfunc VerifyFlazzPay(secret, pathWithQuery string, rawBody []byte, timestamp, signature string, tolerance time.Duration) bool {\n    ts, err := strconv.ParseInt(timestamp, 10, 64)\n    if err != nil || time.Since(time.Unix(ts, 0)).Abs() > tolerance {\n        return false\n    }\n    bodyHash := sha256.Sum256(rawBody)\n    mac := hmac.New(sha256.New, []byte(secret))\n    mac.Write([]byte(timestamp + \"\\nPOST\\n\" + pathWithQuery + \"\\n\" + hex.EncodeToString(bodyHash[:])))\n    received, err := hex.DecodeString(strings.ToLower(signature))\n    return err == nil && hmac.Equal(mac.Sum(nil), received)\n}\n","Go","go",[33,643,644,649,654,659,664,669,673,678,683,688,693,698],{"__ignoreMap":130},[134,645,646],{"class":136,"line":137},[134,647,648],{},"\u002F\u002F body, _ := io.ReadAll(r.Body); r.Header.Get(\"X-FlazzPay-Signature\")\n",[134,650,651],{"class":136,"line":143},[134,652,653],{},"func VerifyFlazzPay(secret, pathWithQuery string, rawBody []byte, timestamp, signature string, tolerance time.Duration) bool {\n",[134,655,656],{"class":136,"line":149},[134,657,658],{},"    ts, err := strconv.ParseInt(timestamp, 10, 64)\n",[134,660,661],{"class":136,"line":155},[134,662,663],{},"    if err != nil || time.Since(time.Unix(ts, 0)).Abs() > tolerance {\n",[134,665,666],{"class":136,"line":161},[134,667,668],{},"        return false\n",[134,670,671],{"class":136,"line":167},[134,672,170],{},[134,674,675],{"class":136,"line":173},[134,676,677],{},"    bodyHash := sha256.Sum256(rawBody)\n",[134,679,680],{"class":136,"line":179},[134,681,682],{},"    mac := hmac.New(sha256.New, []byte(secret))\n",[134,684,685],{"class":136,"line":186},[134,686,687],{},"    mac.Write([]byte(timestamp + \"\\nPOST\\n\" + pathWithQuery + \"\\n\" + hex.EncodeToString(bodyHash[:])))\n",[134,689,690],{"class":136,"line":192},[134,691,692],{},"    received, err := hex.DecodeString(strings.ToLower(signature))\n",[134,694,695],{"class":136,"line":633},[134,696,697],{},"    return err == nil && hmac.Equal(mac.Sum(nil), received)\n",[134,699,701],{"class":136,"line":700},12,[134,702,195],{},[52,704,706],{"id":705},"handling-events","Handling events",[708,709,710,719,732,745,751],"ul",{},[60,711,712,718],{},[48,713,714,715,50],{},"Deduplicate on ",[33,716,717],{},"event_id"," Delivery is at least once, so the same event can arrive twice.",[60,720,721,724,725,728,729,50],{},[48,722,723],{},"Do not rely on order."," Use ",[33,726,727],{},"created_at"," and the status inside ",[33,730,731],{},"data",[60,733,734,737,738,740,741,744],{},[48,735,736],{},"Confirm before you act on money."," ",[33,739,731],{}," is the resource as the matching ",[33,742,743],{},"GET"," returns it; you can fetch it again to be sure.",[60,746,747,750],{},[48,748,749],{},"Retries."," A failed delivery is retried 6 times in all, after 30 seconds, 1, 2, 5 and 10 minutes.",[60,752,753,756,757,760],{},[48,754,755],{},"Test it."," Press \"Send test event\" on an endpoint in the dashboard: you receive a ",[33,758,759],{},"webhook.test"," event signed the same way.",[762,763,764],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}",{"title":130,"searchDepth":143,"depth":143,"links":766},[767,768,769],{"id":54,"depth":143,"text":55},{"id":118,"depth":143,"text":119},{"id":705,"depth":143,"text":706},"Check that a webhook really comes from FlazzPay, with PHP, Node and Go examples.","md",null,{},{"title":20,"description":770},"WtBoVDX4O7tz_6PUXhXX1h-GdaZ-q31Lw5AU45b2_a8",[777,772],{"title":10,"path":11,"stem":12,"description":778,"children":-1},"Environments, API keys and request signing.",1795233028829]