<?php
error_reporting(E_ALL);
ini_set('display_errors', 0);

header('Content-Type: application/json; charset=UTF-8');

require_once __DIR__ . '/config/koneksi.php';
require_once __DIR__ . '/services/google_play_subscription_service.php';

try {
    $mysqli = gps_get_db_connection();
    gps_require_rtdn_secret();

    $requestData = gps_parse_rtdn_request();
    $result = gps_process_rtdn_notification($mysqli, $requestData);

    gps_json_response(true, 'RTDN berhasil diproses', $result);
} catch (Exception $e) {
    gps_log('rtdn fatal error', ['error' => $e->getMessage()]);
    gps_json_response(false, 'Terjadi kesalahan saat memproses RTDN', null, 500);
}
