Getting Started
Get started with One2Pays in minutes. This guide will walk you through the basics of integrating One2Pays into your application.
Prerequisites
Before you begin, make sure you have:
- A One2Pays merchant account
- API credentials (API key and secret)
- Basic knowledge of HTTP requests and JSON
Authentication
One2Pays uses HMAC-based authentication for all API requests. You'll need to:
- Get your API credentials from your merchant dashboard
- Generate HMAC signatures for each request
- Include authentication headers in your requests
See the Authentication Guide for detailed information.
Your First Payment
Create your first payment using the REST API:
import crypto from 'crypto';
const API_KEY = process.env.PAYMENT_API_KEY!;
const API_SECRET = process.env.PAYMENT_API_SECRET!;
async function createPayment() {
const method = 'POST';
const path = '/api/v1/payments';
const body = JSON.stringify({
amount: '1000.00',
currency: 'THB',
referenceId: `order-${Date.now()}`,
paymentMethod: 'promptpay',
customerBankAccountName: 'John Doe',
customerBankAccountNumber: '1234567890',
customerBankCode: '004',
description: 'Test payment',
});
const timestamp = Date.now().toString();
// Create HMAC signature: HMAC-SHA256(timestamp + "." + rawBody, secretKey)
const message = `${timestamp}.${body}`;
const signature = crypto.createHmac('sha256', API_SECRET).update(message).digest('hex');
const response = await fetch('https://api.example.com/api/v1/payments', {
method,
headers: {
'X-API-Key': API_KEY,
'X-Timestamp': timestamp,
'X-Signature': `sha256=${signature}`,
'Content-Type': 'application/json',
},
body,
});
const result = await response.json();
if (result.success) {
console.log('Payment created:', result.data.id);
return result.data;
} else {
throw new Error(result.error.message);
}
}Next Steps
- Learn about Payment Methods
- Set up Webhooks
- Explore the API Reference
Questions? Check out our FAQ or contact support.