API Docs & Integration Guide

Add UPI Payments to Any Website in 2 Minutes

1. Payment Integration Overview

यह गेटवे आपको किसी भी बाहरी वेबसाइट (PHP, Node.js, Python, HTML/JS) में UPI पेमेंट्स स्वीकार करने की सुविधा देता है। जब आप पेमेंट ऑर्डर बनाते हैं, तो सिस्टम एक सुरक्षित होस्टेड चेकआउट लिंक लौटाता है जहाँ ग्राहक QR कोड या मोबाइल ऐप्स द्वारा भुगतान करता है।

2. JavaScript SDK Integration (Frontend)

किसी भी HTML पेज पर यह स्क्रिप्ट जोड़ें:

<!-- 1. Include SDK -->
<script src="https://pay.viewcert.net/sdk/upi-checkout.js"></script>

<!-- 2. Trigger Checkout -->
<script>
function initiateUPIPayment() {
    const upi = new UPICheckout({
        apiKey: 'key_live_a1b2c3d4e5f6789012345678', // आपकी मर्चेंट API Key
        gatewayUrl: 'https://pay.viewcert.net/api/create_order.php',
        amount: 499.00,
        customerName: 'Amit Verma',
        customerPhone: '9876543210',
        customerEmail: 'amit@example.com',
        orderId: 'ORD_' + Date.now(),
        note: 'Pro Plan Subscription',
        redirectUrl: 'https://yourwebsite.com/payment-success.php'
    });
    upi.open();
}
</script>

<button onclick="initiateUPIPayment()">Pay ₹499 with UPI</button>

3. PHP Backend API Integration

<?php
$apiKey = 'key_live_a1b2c3d4e5f6789012345678';

$payload = [
    'amount' => 499.00,
    'customer_name' => 'Amit Verma',
    'customer_phone' => '9876543210',
    'customer_email' => 'amit@example.com',
    'order_id' => 'ORD_' . time(),
    'note' => 'Plan Upgrade',
    'redirect_url' => 'https://yourwebsite.com/callback.php'
];

$ch = curl_init('https://pay.viewcert.net/api/create_order.php');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'X-API-KEY: ' . $apiKey
    ]
]);

$response = json_decode(curl_exec($ch), true);
curl_close($ch);

if ($response['status'] === 'success') {
    // Redirect customer to hosted checkout page
    header('Location: ' . $response['payment_url']);
    exit;
} else {
    echo "Payment Error: " . $response['message'];
}
?>

4. Webhook Receiver & HMAC SHA-256 Verification

<?php
// webhook.php on your website
$secretKey = 'sec_live_99887766554433221100aabb'; // आपकी Secret Key

$rawPayload = file_get_contents('php://input');
$data = json_decode($rawPayload, true);
$receivedSignature = $_SERVER['HTTP_X_UPI_SIGNATURE'] ?? '';

// Verify Signature
$payloadData = $data['data'] ?? [];
ksort($payloadData);
$computedSignature = hash_hmac('sha256', json_encode($payloadData), $secretKey);

if (hash_equals($computedSignature, $receivedSignature)) {
    $txnId = $payloadData['txn_id'];
    $orderId = $payloadData['order_id'];
    $status = $payloadData['status']; // SUCCESS, REJECTED, CANCELLED

    if ($status === 'SUCCESS') {
        // Activate customer plan in your database
    }
    echo json_encode(['status' => 'ok']);
} else {
    http_response_code(401);
    echo json_encode(['error' => 'Invalid Signature']);
}
?>