<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');

$input = file_get_contents('php://input');
$data = json_decode($input, true);

if ($data && isset($data['trx_id'])) {
    $filename = 'data/' . $data['trx_id'] . '.json';
    file_put_contents($filename, json_encode($data, JSON_PRETTY_PRINT));
    echo json_encode(['status' => 'success', 'message' => 'PO Saved']);
} else {
    echo json_encode(['status' => 'error', 'message' => 'Invalid Data']);
}
?>