Edit - mpxpays.php
Back
Editing:
/webhook/mpxpays.php
Save Code
<?php // New Gateway File // 1. Set Content-Type header header("Content-Type: application/json"); // 2. Require config require_once '../lib/config.php'; // 3. Read incoming webhook payload $rawPayload = file_get_contents('php://input'); $webhookData = json_decode($rawPayload, true); // 4. Immediately log incoming webhook data log_api_data("MPXPays Incoming Webhook", $webhookData ?: $rawPayload, "mpxpays_order"); if (!$webhookData) { // If not JSON, try to parse form-data just in case, though docs say JSON POST $webhookData = $_POST; log_api_data("MPXPays Incoming Webhook (Form Data fallback)", $webhookData, "mpxpays_order"); } // 5. Extract merchant order ID and payment status $merchantOrderId = $webhookData['merchant_order_no'] ?? null; $parsedStatus = $webhookData['status'] ?? null; // 'success' or 'failed' if ($merchantOrderId && $parsedStatus) { // 6. Create Next.js update payload $updatePayload = [ "action" => "update", "payload" => [ "id" => $merchantOrderId, "status" => $parsedStatus ] ]; // 7. Strictly use this URL for Next.js API $nextJsApiUrl = rtrim(UPDATE_STATUS_DOMAIN, '/') . '/admin/api/update-buy-order'; // cURL to Next.js backend $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' ]); $nextjs_response = curl_exec($ch); $nextjs_http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // 8. Log the response received from Next.js API log_api_data("MPXPays Next.js Backend Update Response (HTTP $nextjs_http_code)", $nextjs_response, "mpxpays_order"); } else { log_api_data("MPXPays Webhook Missing Data", "Missing merchant_order_no or status", "mpxpays_error"); } // 9. Output exact HTTP Status Code and JSON format expected by Gateway http_response_code(200); echo json_encode(["status" => "ok"]);