File: /home/qhl5pt3kkb1d/public_html/tstp-old/web-hook.php
<?php
// Set your response content type to JSON
header('Content-Type: application/json');
// Retrieve the webhook payload (the POST data)
$payload = file_get_contents('php://input');
// Log the payload for debugging (optional)
file_put_contents('webhook_log.txt', $payload . PHP_EOL, FILE_APPEND);
// Decode the JSON payload into an associative array
$data = json_decode($payload, true);
// Process the webhook data
if ($data) {
// Perform actions based on webhook data
// For example, check if it's an event you're interested in:
if (isset($data['event']) && $data['event'] == 'order_created') {
// Handle order created event
// You can insert the data into a database, send notifications, etc.
// Example: $orderId = $data['order']['id'];
}
// Send a success response back to the webhook provider
http_response_code(200); // HTTP 200 OK
echo json_encode(['status' => 'success']);
} else {
// Handle the case where the payload is empty or invalid
http_response_code(400); // HTTP 400 Bad Request
echo json_encode(['status' => 'error', 'message' => 'Invalid payload']);
}
?>