Gateway Manager
Gateway Manager
Copy AI Prompt
Order API
Webhooks
Files in /order
Create
Filename
Actions
bondpay.php
mpxpays.php
Act as an expert PHP Backend Developer. I have a custom PHP routing architecture and I need to integrate a new Payment Gateway. I will provide the API documentation for the gateway's "Create Order" and "Webhook/Callback". Based on the documentation, you need to generate TWO PHP files: 1. `order/[gatewayname].php` (To create the payment link) 2. `webhook/[gatewayname].php` (To handle callbacks and update my Next.js backend) ### 📌 System Context & Available Config: I have a `lib/config.php` file that contains: - `DOMAIN` (e.g., 'http://localhost/MyApps/p2pxgetway') - `UPDATE_STATUS_DOMAIN` (e.g., 'http://localhost:3000') - A logging function: `log_api_data($title, $data, $filename)` ### 🛠️ File 1: `order/[gatewayname].php` Requirements: 1. Add strict CORS headers allowing POST requests from all origins (`*`). 2. Read JSON input `php://input` expecting `order_id` and `amount`. 3. Require `../lib/config.php`. 4. Apply the exact Signature/Hash generation logic as mentioned in the gateway documentation. 5. Send the `callback_url` as: `DOMAIN . '/webhook/[gatewayname].php'`. 6. Use cURL to POST the data to the Gateway's Create Order endpoint. 7. **Logging:** Use `log_api_data()` to log the Request Payload, cURL errors, Gateway Rejection Errors, API Down Errors, and the Gateway Success Response. Save logs in `[gatewayname]_order` and `[gatewayname]_error`. 8. Return a JSON response for the frontend in this exact format on success: `{"payment_url": "https://..."}`. ### 🛠️ File 2: `webhook/[gatewayname].php` Requirements: 1. Set `Content-Type: application/json` header. 2. Require `../lib/config.php`. 3. Read the incoming webhook payload (JSON or form-data based on docs). 4. **Logging:** Immediately log the incoming webhook data using `log_api_data()`. 5. Extract the merchant order ID and the payment status (`success`, `failed`, etc.) from the payload as per the gateway's response structure. 6. Create an update payload: `{"action": "update", "payload": {"id": merchantOrderId, "status": parsedStatus}}` 7. Use cURL to POST this update payload to my Next.js API. **Strictly use this URL:** `$nextJsApiUrl = UPDATE_STATUS_DOMAIN . '/admin/api/update-buy-order';` 8. Log the response received from the Next.js API. 9. Output the exact HTTP Status Code and JSON format expected by the Payment Gateway's callback documentation (e.g., `{"status": "ok"}` with a `200 OK` header). Here is the Gateway Documentation: --- CREATE ORDER API DOCS --- [PASTE CREATE ORDER DOCS HERE] --- WEBHOOK / CALLBACK DOCS --- [PASTE WEBHOOK DOCS HERE] Please generate the complete, production-ready PHP code for both files.