File: /var/www/vhosts/sethsawariyabizmart.com/httpdocs/masterAir/masterCheckout/refund-init.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
header("Content-Type: application/json");
include('../cred-config.php');
include('../functions.php');
try {
$input = json_decode(file_get_contents('php://input'), true);
// Accept POST data
$order_id = $input['order_id'];
$airpay_id = $input['airpay_id'];
$amount = $input['amount'];
$provider_id = $input['provider_id'];
// Validate fields
if (!$order_id || !$airpay_id || !$amount || !$provider_id) {
echo json_encode([
"success" => false,
"message" => "Missing required fields: order_id, airpay_id, amount, provider_id"
], JSON_PRETTY_PRINT);
exit;
}
// Call your API function: response MUST remain stdClass
$data = refundTxn($order_id, $airpay_id, $amount, $provider_id);
// Ensure $data is an object (stdClass)
if (is_array($data)) {
$data = json_decode(json_encode($data));
}
// Final JSON response
echo json_encode([
"success" => true,
"message" => "Refund processed",
"data" => $data
], JSON_PRETTY_PRINT);
} catch (Exception $e) {
echo json_encode([
"success" => false,
"message" => $e->getMessage()
], JSON_PRETTY_PRINT);
}