Developer Reference

Integration Guide & SDK

Select your backend runtime or framework to view customized installation commands, authentication setup, checkout session controllers, frontend modal triggers, and webhook verification.

Select Language & Framework Stack Python (FastAPI / Django)
1

Package Installation & Configuration

Install the official client SDK and configure your merchant API credentials.

Terminal Installation Command
npm install @qeg/pay dotenv
Environment Configuration (.env)
QEG_PAY_KEY="pk_test_LVhTRY1mxVIhC6XJUb9HjYH9N6UBc0B2" QEG_PAY_SECRET="sk_test_902bf891c9812f84091a9f1" QEG_WEBHOOK_SECRET="whsec_89dfa01bf9201e74"
2

Authentication & Client Setup

Configure the client instance with your API Key to authenticate outbound requests.

// Node.js / TypeScript Initialization import { QegPayClient } from '@qeg/pay'; export const qeg = new QegPayClient({ apiKey: process.env.QEG_PAY_SECRET || process.env.QEG_PAY_KEY, environment: 'sandbox' // or 'live' });
3

Create a Checkout Session (Backend Route)

Call the invoice API endpoint from your server to generate an authorized checkout session token.

// Next.js / Express Checkout Controller import { qeg } from '@/lib/qeg'; export async function POST(req: Request) { const body = await req.json(); const invoice = await qeg.invoices.create({ platform_invoice_id: `INV-${Date.now()}`, amount: body.amount, currency: 'USD', customer_name: body.customer_name, customer_email: body.customer_email, callback_url: 'https://yourstore.com/checkout/callback' }); return Response.json({ checkout_token: invoice.checkout_token, checkout_url: invoice.checkout_url }); }
4

Frontend Modal SDK Integration

Open the seamless checkout modal in place or redirect customers to the hosted checkout page.

<!-- 1. Include the lightweight frontend Gateway SDK --> <script src="https://www.qegpay.ae/sdk/gateway.js"></script> <!-- 2. Trigger Checkout Modal on button click --> <button type="button" onclick="launchCheckout()">Pay Now</button> <script> Gateway.init({ publicKey: 'pk_test_LVhTRY1mxVIhC6XJUb9HjYH9N6UBc0B2' }); async function launchCheckout() { // 1. Fetch token from your backend endpoint (Step 3) const res = await fetch('/api/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: 150.00, customer_name: 'Alex Morgan' }) }); const { checkout_token } = await res.json(); // 2. Open popup modal directly on current page Gateway.openPopup({ token: checkout_token, onSuccess: function(data) { console.log('Payment succeeded:', data.charge_id); window.location.href = '/order-success?ref=' + data.unique_gateway_ref; }, onError: function(err) { console.error('Payment declined:', err); } }); } </script>
5

Webhook Signature Verification & Fulfillment

Securely verify inbound payment events using HMAC-SHA256 signature verification before fulfilling orders.

// Node.js / Express Webhook Receiver import crypto from 'crypto'; export async function POST(req) { const signature = req.headers['x-pop-signature']; const rawBody = await req.text(); const secret = process.env.QEG_WEBHOOK_SECRET; const expectedSignature = crypto .createHmac('sha256', secret) .update(rawBody) .digest('hex'); if (signature !== expectedSignature) { return new Response('Invalid Signature', { status: 401 }); } const event = JSON.parse(rawBody); if (event.event === 'payment.succeeded') { // Fulfill order in database: markOrderPaid(event.invoice_id); console.log(`Payment confirmed: ${event.invoice_id} for ${event.amount} ${event.currency}`); } return new Response(JSON.stringify({ received: true }), { status: 200 }); }

Test Live in the Sandbox Simulator

Test the complete frontend popup modal SDK, postMessage telemetry, and auto-callback routing using sample merchant credentials.

Launch Store Simulator