Discussions

Ask a Question
Back to All

Webhook URL Not Working

Here is my code
Tested it with postman and it works.

<?php
header('HTTP/1.1 200 OK');
header('Content-Type: application/json');
$request = file_get_contents('php://input');
$header = $_SERVER['HTTP_PAYMONGO_SIGNATURE'];
$payload = json_decode($request, true);
$type = $payload['data']['attributes']['type'];

$path = "../../";
require($path . 'vendor/autoload.php');

$dotenv = Dotenv\Dotenv::createImmutable($path);
$dotenv->safeLoad();

$sql = "INSERT INTO `log`(`data`) VALUES ('" . $request . "')";

try {
    $conn = new PDO("mysql:host=" . $_ENV["DB_SERVER"] . ";dbname=" . $_ENV["DB_NAME"], $_ENV["DB_USERNAME"], $_ENV["DB_PASSWORD"]);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $conn->prepare($sql);
    $stmt->execute();
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
?>