Skip to content

Instantly share code, notes, and snippets.

@rslhdyt
Created September 14, 2023 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rslhdyt/d132ca20ebf5377ddc0dc94445f82452 to your computer and use it in GitHub Desktop.
Save rslhdyt/d132ca20ebf5377ddc0dc94445f82452 to your computer and use it in GitHub Desktop.
Send stamping request
<?php
// Function to convert a file to base64
function fileToBase64($filePath) {
if (file_exists($filePath)) {
$fileData = file_get_contents($filePath);
if ($fileData !== false) {
return base64_encode($fileData);
} else {
return false; // Error reading file
}
} else {
return false; // File does not exist
}
}
// Define the file path
$filePath = "path/to/your/filename.pdf";
// Convert the file to base64
$base64Doc = fileToBase64($filePath);
if ($base64Doc === false) {
echo "Error converting the file to base64.";
exit;
}
// Define the parameters
$params = [
"doc" => $base64Doc,
"filename" => "filename.pdf",
"annotations" => [
[
"page" => 1,
"position_x" => 100,
"position_y" => 200,
"element_width" => 80,
"element_height" => 80,
"canvas_width" => 595,
"canvas_height" => 841,
"type_of" => "meterai"
]
],
"callback_url" => "https://webhook.site/c766dac9-5ffc-40d8-80d7-428fe6ab19e4"
];
// Convert parameters to JSON
$jsonParams = json_encode($params);
if ($jsonParams === false) {
echo "Error encoding parameters to JSON.";
exit;
}
// Prepare the HTTP request
$ch = curl_init("https://sandbox-api.mekari.com/v2/esign/v1/documents/stamp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonParams);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Send the HTTP request
$response = curl_exec($ch);
if ($response === false) {
echo "Error sending the HTTP request: " . curl_error($ch);
} else {
echo "HTTP Response: " . $response;
}
// Close the cURL session
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment