đ Widget V2 - Secure Integration
Widget V2 provides an enhanced security model that protects your API credentials and adds IP whitelisting capabilities. Unlike Widget V1, your API key is never exposed in client-side code.
⨠Key Security Features
- đ API Key Protection: API keys never exposed in client-side code
- đĄī¸ IP Whitelisting: Restrict widget access to authorized IPs only
- âąī¸ Session-Based: Time-limited session keys for enhanced security
- đ¯ Reduced Attack Surface: No sensitive parameters visible in browser
Integration Overviewâ
Widget V2 uses a two-step integration process:
Create Session (Server-Side)
Call API with your parameters to get session key
Initialize Widget (Client-Side)
Use session key to render widget
Step 1: Create Session (Server-Side)â
First, call the session creation API from your backend server (never from client-side) with the widget parameters.
API Endpointâ
/v1/merchant/sessionHeadersâ
| Header | Type | Required | Description |
|---|---|---|---|
Content-Type | string | Yes | application/json |
x-api-key | string | Yes | Your API key from merchant dashboard |
Request Parametersâ
All parameters from Widget V1 are supported (except apiKey which goes in header).
Example Requestâ
- cURL
- Node.js
- Python
curl --location 'https://stg.api.onmeta.in/v1/merchant/session' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--data '{
"chainId": 137,
"walletAddress": "0x1111111111111111111111111111111111111111",
"fiatAmount": 1000,
"onRamp": true,
"offRamp": false,
"fiatType": "INR",
"successRedirectUrl": "https://merchant.example/success",
"failureRedirectUrl": "https://merchant.example/failure",
"metaData": {
"source": "test",
"userId": "u_1"
},
"tokenSymbol": "USDT",
}'
const axios = require('axios');
async function createWidgetSession() {
try {
const response = await axios.post(
'https://stg.api.onmeta.in/v1/merchant/session',
{
chainId: 137,
walletAddress: '0x1111111111111111111111111111111111111111',
fiatAmount: 1000,
onRamp: true,
offRamp: false,
fiatType: 'INR',
successRedirectUrl: 'https://merchant.example/success',
failureRedirectUrl: 'https://merchant.example/failure',
metaData: {
source: 'test',
userId: 'u_1'
},
tokenSymbol: 'USDT',
},
{
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
}
}
);
return response.data;
} catch (error) {
console.error('Error creating session:', error);
throw error;
}
}
import requests
import json
def create_widget_session():
url = "https://stg.api.onmeta.in/v1/merchant/session"
headers = {
"Content-Type": "application/json",
"x-api-key": "YOUR_API_KEY"
}
payload = {
"chainId": 137,
"walletAddress": "0x1111111111111111111111111111111111111111",
"fiatAmount": 1000,
"onRamp": True,
"offRamp": False,
"fiatType": "INR",
"successRedirectUrl": "https://merchant.example/success",
"failureRedirectUrl": "https://merchant.example/failure",
"metaData": {
"source": "test",
"userId": "u_1"
},
"tokenSymbol": "USDT",
}
try:
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as error:
print(f"Error creating session: {error}")
raise
Responseâ
{
"success": true,
"data": {
"expiresAt": 1770565300,
"sessionKey": "eyJhbGciO......."
},
"error": {}
}
Session Key Expiration
The sessionKey is time-limited for security. Check the expiresAt timestamp (Unix epoch). Generate a new session key if expired.
Step 2: Initialize Widget (Client-Side)â
Use the session key received from Step 1 to initialize the widget on your frontend.
Include SDK Scriptâ
Add the Widget V2 SDK script to your HTML:
- Staging
- Production
<script src="https://stg.platform.onmeta.in/onmeta-sdk.v2.js"></script>
<script src="https://platform.onmeta.in/onmeta-sdk.v2.js"></script>
Complete Integration Exampleâ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Onmeta Widget V2 Integration</title>
</head>
<body>
<!-- Widget container -->
<div id="onmeta"></div>
<!-- Include Widget V2 SDK -->
<script src="https://stg.platform.onmeta.in/onmeta-sdk.v2.js"></script>
<!-- Initialize Widget -->
<script>
// Initialize widget with session key from your backend
const widget = new window.onMetaWidgetV2({
sessionKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", // From Step 1
elementId: "onmeta",
environment: "staging",
widgetHeight: "54rem" // Optional
});
// Render the widget
widget.init();
</script>
</body>
</html>
Widget V2 Configurationâ
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionKey | string | Yes | Session key obtained from /v1/merchant/session API |
elementId | string | Yes | ID of HTML element where widget renders |
environment | string | Yes | "staging" or "production" |
widgetHeight | string | No | Height of widget |
Widget V1 vs Widget V2â
Troubleshootingâ
Session Key Expired
- Check the
expiresAttimestamp before using the session key - Generate a new session key from your backend
- Initialize widget with the new key
Widget Not Rendering
- Verify the
elementIdmatches your HTML element ID - Check browser console for JavaScript errors
- Ensure SDK script loaded successfully
- Confirm session key is valid and not expired