function webhookCallback() { global $connectHost, $requestHeaders; if ($_SERVER['REQUEST_METHOD'] == 'POST') { # Get the JSON body and HMAC-SHA1 signature of the incoming POST request $callbackBody = file_get_contents('php://input'); $callbackSignature = getallheaders()['X-Square-Signature']; # Validate the signature if (!isValidCallback($callbackBody, $callbackSignature)) { # Fail if the signature is invalid error_log("Webhook event with invalid signature detected!"); return; } # Load the JSON body into an associative array $callbackBodyJson = json_decode($callbackBody); # If the notification indicates a PAYMENT_UPDATED event... if (property_exists($callbackBodyJson, 'event_type') and $callbackBodyJson->event_type == 'PAYMENT_UPDATED') { # Get the ID of the updated payment $paymentId = $callbackBodyJson->entity_id; # Send a request to the Retrieve Payment endpoint to get the updated payment's full details $response = Unirest\Request::get($connectHost . '/v1/me/payments/' . $paymentId, $requestHeaders); # Perform an action based on the returned payment (in this case, simply log it) error_log(json_encode($response->body, JSON_PRETTY_PRINT)); } } else { error_log("Received a non-POST request"); } }
function renderError($msg) { global $callback; $out = json_encode(['ia' => $item_id, 'q' => $q, 'indexed' => true, 'matches' => [], 'error' => $msg]); if (isValidCallback($callback)) { $out = $callback . '(' . $out . ')'; } echo $out; exit(0); }
exit(0); } } $filename = "{$path}/{$doc}_abbyy.gz"; if (file_exists($filename)) { checkPrivs($filename); } else { $filename = "{$path}/{$doc}_abbyy.zip"; if (file_exists($filename)) { checkPrivs($filename); } } $contentType = 'application/json'; // default if ($callback) { if (!isValidCallback($callback)) { throw new Exception("Invalid callback"); } $contentType = 'text/javascript'; // JSONP is not JSON } header('Content-type: ' . $contentType . ';charset=UTF-8'); header('Access-Control-Allow-Origin: *'); // allow cross-origin requests $item_id = escapeshellarg($item_id); $doc = escapeshellarg($doc); $path = escapeshellarg($path); $q = escapeshellarg($q); set_time_limit(120); passthru("python inside.py {$item_id} {$doc} {$path} {$q} {$callback} 2>&1"); ?>