Skip to main content

🔐 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:

1ī¸âƒŖ

Create Session (Server-Side)

Call API with your parameters to get session key

2ī¸âƒŖ

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​

Headers​

HeaderTypeRequiredDescription
Content-TypestringYesapplication/json
x-api-keystringYesYour API key from merchant dashboard

Request Parameters​

All parameters from Widget V1 are supported (except apiKey which goes in header).

📋 Widget V2 Session Parameters

ParameterTypeRequiredDescriptionExample
chainIdnumberOptional

Blockchain network ID. Example: 137 for Polygon.

137
walletAddressstringRequired

Wallet address to receive crypto tokens. Must be provided during widget initialization. Users cannot enter wallet address manually.

"0xEcc24..."
fiatAmountnumberOptional

Pre-filled amount for purchase.

1000
onRampstringOptional

Enable buy crypto functionality (on-ramp). Default: "enabled"

"enabled"
offRampstringOptional

Enable sell crypto functionality (off-ramp). Default: "disabled"

"disabled"
fiatTypestringOptional

Fiat currency to use. Supported: "inr" (Indian Rupee), "php" (Philippine Peso), "idr" (Indonesian Rupiah)

"inr"
userEmailstringOptional

User's email address. If provided, skips registration step in widget.

"user@..."
tokenAddressstringOptional

Contract address of token. Use with chainId to show specific token. Otherwise shows all tokens from chain.

"0xEcc24..."
tokenSymbolstringOptional

Token symbol (e.g., USDT, USDC). Alternative to tokenAddress for filtering tokens.

"USDT"
paymentMethodstringOptional

Pre-select Payment Method (e.g., INR_UPI, INR_IMPS).

"INR_UPI"
metaDataobjectOptional

Custom data sent with webhook events. Must be key-value pairs of strings only.

{userId: "..."}
successRedirectUrlstringOptional

URL to redirect on successful order. Must start with http:// or https://

"https://..."
failureRedirectUrlstringOptional

URL to redirect on order failure. Must start with http:// or https://

"https://..."

Example Request​

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",
}'

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:

<script src="https://stg.platform.onmeta.in/onmeta-sdk.v2.js"></script>

Complete Integration Example​

index.html
<!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​

ParameterTypeRequiredDescription
sessionKeystringYesSession key obtained from /v1/merchant/session API
elementIdstringYesID of HTML element where widget renders
environmentstringYes"staging" or "production"
widgetHeightstringNoHeight of widget

Widget V1 vs Widget V2​

FeatureWidget V1Widget V2
API Key Exposure❌ Exposed in URL✅ Hidden (server-side only)
IP Whitelisting❌ Not available✅ Supported
Session Management❌ Stateless✅ Time-limited sessions
Integration Steps1 step (client-side)2 steps (server + client)
Security Levelâš ī¸ Basic✅ Enhanced

Troubleshooting​

Session Key Expired

Solutions:
  • Check the expiresAt timestamp before using the session key
  • Generate a new session key from your backend
  • Initialize widget with the new key

Widget Not Rendering

Solutions:
  • Verify the elementId matches your HTML element ID
  • Check browser console for JavaScript errors
  • Ensure SDK script loaded successfully
  • Confirm session key is valid and not expired