API Documentation

Everything you need to integrate PayBridge into your application

Quick Start

1. Base URL

All API requests should be made to:

https://your-domain.com/api/

2. Configure a Gateway

Before accepting payments, add your payment gateway credentials in the dashboard.

3. Create Your First Payment

Make a POST request to create a payment:

// Create a payment order const response = await fetch('/api/payments.php?action=create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: 999, // Amount in base currency currency: 'INR', // Currency code gateway: 'razorpay', // Payment gateway customer_name: 'John Doe', customer_email: 'john@example.com', customer_phone: '9876543210', gst_rate: 18, // Optional: GST percentage description: 'Order #123', metadata: { // Optional: Custom data product_id: 'prod_123', user_id: 'user_456' } }) }); const data = await response.json(); // Response: // { // order_id: "order_abc123...", // amount: 999, // gst_amount: 179.82, // total_amount: 1178.82, // razorpay_order_id: "order_XYZ...", // For Razorpay // razorpay_key: "rzp_test_...", // status: "pending" // }

Razorpay Integration

PayBridge uses Razorpay's checkout.js for seamless payment collection.

<!-- Include Razorpay Script --> <script src="https://checkout.razorpay.com/v1/checkout.js"></script> <script> async function initiatePayment() { // 1. Create order on backend const response = await fetch('/api/payments.php?action=create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: 1000, currency: 'INR', gateway: 'razorpay', customer_name: 'Customer Name', customer_email: 'customer@email.com', gst_rate: 18 }) }); const orderData = await response.json(); // 2. Open Razorpay Checkout const options = { key: orderData.razorpay_key, amount: orderData.total_amount * 100, currency: orderData.currency, order_id: orderData.razorpay_order_id, name: 'Your Company', description: 'Payment Description', handler: async function(response) { // 3. Verify payment on backend const verifyRes = await fetch('/api/payments.php?action=verify', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ order_id: orderData.order_id, gateway: 'razorpay', payment_id: response.razorpay_payment_id, razorpay_order_id: response.razorpay_order_id, signature: response.razorpay_signature }) }); const result = await verifyRes.json(); if (result.verified) { alert('Payment successful!'); } }, prefill: { name: 'Customer Name', email: 'customer@email.com' }, theme: { color: '#3B82F6' } }; new Razorpay(options).open(); } </script>

API Endpoints

Authentication

POST /api/auth.php?action=register

Create a new admin account

POST /api/auth.php?action=login

Login with email and password

POST /api/auth.php?action=magic-link

Request OTP for passwordless login

Payments

POST /api/payments.php?action=create

Create a new payment order (public)

POST /api/payments.php?action=verify

Verify payment after completion (public)

GET /api/payments.php?action=status&order_id={id}

Get payment status by order ID (public)

Gateways (Auth Required)

GET /api/gateways.php

List all payment gateways

POST /api/gateways.php

Create a new gateway

PUT /api/gateways.php?id={gateway_id}

Update gateway settings

DELETE /api/gateways.php?id={gateway_id}

Delete a gateway

Webhooks

Configure these webhook URLs in your payment gateway dashboards to receive real-time payment updates:

Razorpay: /api/webhook/razorpay.php
Stripe: /api/webhook/stripe.php
Cashfree: /api/webhook/cashfree.php
Paytm: /api/webhook/paytm.php
All webhook events are logged in the database for debugging. Configure Telegram integration to receive instant notifications.

Adding New Payment Gateways

To add a new payment gateway to PayBridge:

  1. Backend: Add gateway handler in api/payments.php
  2. Create webhook endpoint: api/webhook/{gateway_name}.php
  3. Add to provider options: Update the gateway form in gateways.html
  4. Test: Use test/sandbox credentials before going live
Each gateway requires its own SDK/API integration. Refer to the gateway's official documentation for specific implementation details.

Database Structure

PayBridge auto-creates the following tables with _pcv suffix:

Tables are automatically created when you first access the API. Just configure your MySQL credentials in config.php.