Edit - bondpay.php
Back
Editing:
/webhook/bondpay.php
Save Code
<?php // 1. Include config file to get constants and log function require_once __DIR__ . '/../lib/config.php'; // Webhook hamesha JSON header ke sath respond karna chahiye header('Content-Type: application/json'); // 2. Read incoming JSON payload from BondPay $input = json_decode(file_get_contents('php://input'), true); // 3. Log the incoming webhook data log_api_data('BondPay Webhook Received', $input ? $input : ['error' => 'No input received'], 'bondpay_webhook'); // 4. Validate the payload if (!$input || !isset($input['merchantOrder']) || !isset($input['status'])) { http_response_code(400); echo json_encode([ 'status' => 'error', 'message' => 'Invalid callback payload' ]); exit(); } $merchantOrder = $input['merchantOrder']; $gatewayStatus = strtolower($input['status']); $updatePayload = [ "action" => "update", "payload" => [ "id" => $merchantOrder, "status" => $gatewayStatus ] ]; $nextJsApiUrl = UPDATE_STATUS_DOMAIN . '/admin/api/update-buy-order'; $ch = curl_init($nextJsApiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($updatePayload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $nodeResponse = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); // 7. Log the response from your Next.js API log_api_data('Node API Update Response', [ 'url' => $nextJsApiUrl, 'sent_payload' => $updatePayload, 'http_code' => $httpCode, 'curl_error' => $curlError, 'node_response' => json_decode($nodeResponse, true) ?? $nodeResponse ], 'bondpay_webhook'); http_response_code(200); echo json_encode([ "status" => "ok", "message" => "Callback received successfully" ]);