Client Example - Live Testing
Example of JavaScript client integration with Payment Gateway
Payment Configuration
Test Environment: This demo uses test credentials configured in the backend.
Contact PayGlobe support for your production API keys.
Client JavaScript Code
1. Payment Initialization
initiatePayment() JS
// Function to initialize payment
async function initiatePayment(amount) {
const baseUrl = window.location.origin + '/paymentgw';
const apiKey = 'pk_test_PayGlobe123456789TestPublishable';
const response = await fetch(`${baseUrl}/api/payment/initiate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify({
amount: amount
})
});
const data = await response.json();
console.log('Payment initiated:', data);
// Redirect to IGFS for PREAUTH
if (data.igfsRedirectUrl) {
window.location.href = data.igfsRedirectUrl;
}
return data;
}
Note: After PREAUTH, the user is redirected to the voucher selection page.
The system automatically processes the transaction:
- If the user enters OTP + voucher amount → processes vouchers + CAPTURE difference
- If the user doesn't enter anything → CAPTURE total amount
2. Verify Transaction Status
getTransactionStatus() JS
// Function to verify status
async function getTransactionStatus(transactionId) {
const baseUrl = window.location.origin + '/paymentgw';
const apiKey = 'pk_test_PayGlobe123456789TestPublishable';
const response = await fetch(
`${baseUrl}/api/payment/status/${transactionId}`,
{
headers: {
'Authorization': `Bearer ${apiKey}`
}
}
);
const data = await response.json();
console.log('Transaction status:', data);
return data;
}
3. Webhook with HMAC Signature (Server-to-Server)
Note: Webhooks are sent from the PayGlobe server to your backend server.
They cannot be tested directly from the browser.
handleWebhook() - Node.js Backend JS
// Backend: Verify webhook signature
async function handleWebhook(req, res) {
const signature = req.headers['x-webhook-signature'];
const { transactionId, paymentId, amount, status } = req.body;
// Create payload
const payload = `${transactionId}|${paymentId}|${amount}|${status}`;
// Verify signature with IGFS API key
const crypto = require('crypto');
const hmac = crypto.createHmac('sha256', process.env.IGFS_API_KEY);
hmac.update(payload);
const expectedSignature = hmac.digest('base64');
if (expectedSignature !== signature) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Valid webhook - process payment
console.log('✅ Webhook verified:', transactionId);
res.json({ success: true });
}
Interactive Testing
Version: v2.0.0-NO-SERIAL
Build: 2025-11-05 11:50
Serial Number retrieved automatically from VALIDA API
Step 1: Initialize Payment (PREAUTH)
Enter the total amount and perform card preauthorization