Intermediate10 min read
Simple Integration (Public Key Mode)
Create orders directly from the browser using Public Key, no backend required. Perfect for frontend developers.
Public Key vs API Key
PonponPay provides two authentication methods for different scenarios:
| API Key | Public Key |
|---|---|
| API Key is a server-side secret that must be stored securely on your backend server, with full API access. | Public Key is a frontend key that can be safely exposed in browser code, only supports creating and querying orders. |
| ✅ Full API access | ⚠️ Create/query orders only |
| 🔒 Must be kept secret | 🌐 Can be public |
| 🖥️ Server-side only | 🌍 Browser-side |
Get Your Public Key
- Log in to PonponPay merchant dashboard
- Go to "Frontend Integration" page
- Enable frontend integration
- Copy the displayed Public Key
Domain Whitelist
For security, Public Key can only be used on configured domains. Add your website domain in the merchant dashboard.
You can add localhost for development testing.
Rate Limits
Public Key mode has the following limits:
- Maximum 60 requests per minute
- Maximum 1000 requests per day
- Maximum 10 requests per minute per IP
Usage Example
Here is a complete example of creating an order with Public Key:
import { PonponPayClient } from '@ponponpay/sdk';
// 初始化客户端(使用 Public Key)
const client = new PonponPayClient({
publicKey: 'pub_your_public_key',
// Token 会自动获取和刷新
});
// 创建订单
async function createOrder() {
try {
const order = await client.createOrder({
amount: 100,
currency: 'USDT',
network: 'tron',
description: 'Product purchase'
});
console.log('Order created:', order.tradeId);
console.log('Payment URL:', order.paymentUrl);
// 跳转到支付页面
window.location.href = order.paymentUrl;
} catch (error) {
console.error('Failed to create order:', error);
}
}