PayGate API
สร้างระบบชำระเงินที่ทรงพลังด้วย API ที่เรียบง่าย ปลอดภัย และใช้งานง่าย สำหรับ PromptPay QR
ใช้ host นี้ทุกที่ (NEXT_PUBLIC_API_URL, mobile app, SDK) เพื่อหลีกเลี่ยงความสับสนข้าม environment
Production Host
https://paygate-production-f1e9.up.railway.appPublic API (/api/v1)
https://paygate-production-f1e9.up.railway.app/api/v1Dashboard/Admin API (/api)
https://paygate-production-f1e9.up.railway.app/apihttps://api.hyperpay.proเชื่อมต่อง่าย
เริ่มต้นใช้งานได้ในไม่กี่นาทีด้วย REST API และ SDK ที่มีเอกสารครบถ้วน
ปลอดภัยตั้งแต่ต้น
ความปลอดภัยระดับธนาคารด้วย API Key และ Webhook Signature
แจ้งเตือนทันที
รับการแจ้งเตือนทันทีเมื่อมีการชำระเงินสำเร็จ
API Endpoints
Base URL:https://paygate-production-f1e9.up.railway.app/api/v1https://paygate-production-f1e9.up.railway.app/api/v1/payment/createสร้างลิงก์ชำระเงินใหม่
https://paygate-production-f1e9.up.railway.app/api/v1/payment/:idตรวจสอบสถานะการชำระเงิน
https://paygate-production-f1e9.up.railway.app/api/v1/payment/order/:orderIdค้นหาจาก Order ID / Lookup by Order ID
https://paygate-production-f1e9.up.railway.app/api/v1/transactionsดูรายการธุรกรรมทั้งหมด
https://paygate-production-f1e9.up.railway.app/api/v1/payment/:id/cancelCancel payment
https://paygate-production-f1e9.up.railway.app/api/payment/create-linkDashboard API (JWT) - create payment link
เริ่มต้นอย่างรวดเร็ว
5 นาทีโหมดการรับเงินตามแพลน
แพลน Free
- • QR Code ชี้ไปที่บัญชีกลาง PayGate
- • ต้องขอถอนเงินหลังได้รับชำระ
- • ค่าธรรมเนียม 3% ต่อรายการ
แพลน Basic/Pro/Enterprise
- • QR Code ชี้ไปที่ PromptPay ของคุณ
- • เงินเข้าบัญชีคุณโดยตรง ทันที
- • ค่าธรรมเนียมลดเหลือ 1.5-2.5%
รับ API Key
สร้าง API Key จากหน้า Dashboard ของคุณ
sk_live_xxxxxxxxxxxxxxxxxxxxสร้าง Payment แรก
เรียก API เพื่อสร้างลิงก์ชำระเงินแรกของคุณ
1const response = await fetch('https://paygate-production-f1e9.up.railway.app/api/v1/payment/create', {2 method: 'POST',3 headers: {4 'X-API-Key': 'sk_live_xxxxxxxxxxxx',5 'Content-Type': 'application/json'6 },7 body: JSON.stringify({8 amount: 150.00,9 orderId: 'ORDER-12345',10 description: 'Premium Subscription'11 })12});1314const data = await response.json();15console.log('Transaction ID:', data.transaction.id);16console.log('QR Code:', data.transaction.qrCode);17console.log('Checkout URL:', 'https://paygate-gules.vercel.app/pay/' + data.transaction.id);การยืนยันตัวตน
ยืนยันตัวตน API requests ด้วย API Key ผ่าน header X-API-Key (รองรับ Bearer <API Key> ด้วย)
เก็บ API Key ไว้เป็นความลับ
อย่าเปิดเผย API Key ใน client-side code หรือ public repositories
รูปแบบ Header
X-API-Key: sk_xxxxxxxxxxxxxxxxxxxx
# or (supported fallback)
Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxxPublic API (/api/v1): ส่ง API Key ผ่าน X-API-Key หรือ Bearer <API Key>
Dashboard/Admin: ใช้ JWT Bearer token จาก /api/auth/login หรือ /api/auth/admin/login
ตัวอย่าง Request
curl -X GET "https://paygate-production-f1e9.up.railway.app/api/v1/payment/<transaction_id>" \
-H "X-API-Key: sk_xxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json"สร้างลิงก์ชำระเงิน
https://paygate-production-f1e9.up.railway.app/api/v1/payment/createRequest Body
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
amount | number | จำเป็น | จำนวนเงิน (บาท) |
orderId | string | ไม่บังคับ | รหัสคำสั่งซื้อของร้านค้า |
description | string | ไม่บังคับ | รายละเอียดที่แสดงให้ลูกค้า |
metadata | object | ไม่บังคับ | ข้อมูล metadata (JSON) จะถูกส่งกลับใน webhook |
ตัวอย่าง Request
1const response = await fetch('https://paygate-production-f1e9.up.railway.app/api/v1/payment/create', {2 method: 'POST',3 headers: {4 'X-API-Key': 'sk_xxxxxxxxxxxx',5 'Content-Type': 'application/json'6 },7 body: JSON.stringify({8 amount: 150.00,9 orderId: 'ORDER-12345',10 description: 'Premium Subscription',11 metadata: { customerId: 'CUST-01' }12 })13});1415const data = await response.json();16console.log('QR data URL:', data.transaction.qrCode);17console.log('Checkout URL:', 'https://paygate-gules.vercel.app/pay/' + data.transaction.id);Response
{
"success": true,
"transaction": {
"id": "abc123-uuid",
"orderId": "ORDER-12345",
"amount": 150.00,
"fee": 3.00,
"netAmount": 147.00,
"status": "PENDING",
"paymentMethod": "PROMPTPAY",
"qrCode": "data:image/png;base64,...",
"qrExpiry": "2025-12-09T10:45:00Z",
"createdAt": "2025-12-09T10:30:00Z"
}
}ตรวจสอบสถานะ
https://paygate-production-f1e9.up.railway.app/api/v1/payment/:idค่าสถานะ
PENDINGรอชำระเงิน (PENDING)
PAIDชำระเงินแล้ว (PAID)
CANCELLEDยกเลิก (CANCELLED)
EXPIREDหมดอายุ (EXPIRED)
ตัวอย่าง Response
{
"transaction": {
"id": "d5c0c8b0-xxxx-xxxx-xxxx-4c1a0f26cb25",
"orderId": "ORDER-12345",
"amount": 150.00,
"fee": 3.00,
"netAmount": 147.00,
"status": "PAID",
"paymentMethod": "PROMPTPAY",
"paidAt": "2025-12-09T10:32:15Z",
"createdAt": "2025-12-09T10:30:00Z"
}
}Webhooks
รับการแจ้งเตือนแบบ real-time เมื่อมีเหตุการณ์เกี่ยวกับการชำระเงินเกิดขึ้น
Events ที่มี
payment.createdสร้างรายการชำระเงิน
payment.successชำระเงินสำเร็จ (PAID)
payment.failedชำระเงินล้มเหลว
payment.expiredQR หมดอายุ
settlement.createdสร้างคำขอถอนเงิน
settlement.completedโอนเงินให้ร้านค้าเรียบร้อย
X-Webhook-Signature (HMAC SHA256) และ X-Webhook-Event จะถูกส่งมาพร้อม payloadWebhook Payload
{
"event": "payment.success",
"timestamp": "2025-12-09T10:32:15Z",
"webhookId": "wh_123456",
"data": {
"transactionId": "d5c0c8b0-xxxx-xxxx-xxxx-4c1a0f26cb25",
"orderId": "ORDER-12345",
"amount": 150.00,
"fee": 3.00,
"netAmount": 147.00,
"status": "PAID",
"paidAt": "2025-12-09T10:32:15Z"
}
}ตรวจสอบ Webhook Signature
1const crypto = require('crypto');23function verifyWebhookSignature(payload, signature, secret) {4 const expectedSignature = crypto5 .createHmac('sha256', secret)6 .update(JSON.stringify(payload))7 .digest('hex');8 9 return signature === expectedSignature;10}1112// Express.js example13app.post('/webhook', (req, res) => {14 const signature = req.headers['x-webhook-signature'];15 const isValid = verifyWebhookSignature(req.body, signature, process.env.WEBHOOK_SECRET);16 17 if (!isValid) {18 return res.status(401).json({ error: 'Invalid signature' });19 }20 21 console.log('Received:', req.body.event);22 res.json({ received: true });23});Dashboard API (JWT)
เส้นนี้ใช้สำหรับ Merchant Dashboard / หลังบ้าน (JWT) ไม่ใช่ Public API Key
ใช้เมื่อคุณล็อกอิน merchant แล้ว และต้องการสร้าง payment link สำเร็จรูปจากระบบหลังบ้าน
https://paygate-production-f1e9.up.railway.app/api/payment/create-link1const response = await fetch('https://paygate-production-f1e9.up.railway.app/api/payment/create-link', {2 method: 'POST',3 headers: {4 'Authorization': 'Bearer <merchant_jwt_token>',5 'Content-Type': 'application/json'6 },7 body: JSON.stringify({8 amount: 40,9 orderId: 'LINK0AFC13B6',10 description: 'Bet payment',11 expiryMinutes: 6012 })13});1415const data = await response.json();16console.log('Payment Link:', data.paymentLink);17console.log('Transaction ID:', data.transaction.id);Response
{
"success": true,
"paymentLink": "https://paygate-gules.vercel.app/pay/3f302545-a46f-4f7d-8722-784b9ba26528",
"transaction": {
"id": "3f302545-a46f-4f7d-8722-784b9ba26528",
"orderId": "LINK0AFC13B6",
"amount": "40",
"expiresAt": "2026-02-11T13:24:57.588Z"
}
}Widget Script (ตัวเลือก)
<!-- Use Public Key (pk_) on browser widgets. Keep sk_ on server only -->
<script src="https://paygate-gules.vercel.app/paygate-widget.js"></script>
<div id="paygate-button-container"></div>
<script>
PayGate.renderButton({
elementId: 'paygate-button-container',
apiKey: 'pk_live_xxxxxxxxxxxxxxxxxxxx',
amount: 150.00,
orderId: 'ORDER-12345',
description: 'Payment via widget',
checkoutBaseUrl: 'https://paygate-gules.vercel.app',
apiBaseUrl: 'https://paygate-production-f1e9.up.railway.app/api/v1'
});
</script>การจัดการ Error
HTTP Status Codes
| รหัส | Error | คำอธิบาย |
|---|---|---|
400 | INVALID_REQUEST | ข้อมูล Request ไม่ถูกต้อง |
401 | UNAUTHORIZED | API Key ไม่ถูกต้องหรือไม่มี |
403 | FORBIDDEN | ไม่มีสิทธิ์เข้าถึง |
404 | NOT_FOUND | ไม่พบ Resource |
500 | SERVER_ERROR | เกิดข้อผิดพลาดภายในเซิร์ฟเวอร์ |
รูปแบบ Error Response
{
"error": "Unauthorized",
"message": "API key is required. Send it via X-API-Key header."
}SDKs & Libraries
ใช้ SDK อย่างเป็นทางการเพื่อเชื่อมต่อได้ง่ายขึ้น
Node.js
JavaScript / TypeScript
PHP
Native / Laravel / WP
Python
Django / Flask
ตัวอย่างการใช้งาน (Node.js)
1const PayGate = require('./paygate-node.js'); // Point to the downloaded file23const paygate = new PayGate('sk_live_xxxxxxxxxxxxxxxxxxxx');45async function createOrder() {6 try {7 const payment = await paygate.createPayment({8 amount: 150.00,9 orderId: 'ORDER-12345',10 description: 'Premium Subscription'11 });1213 const txId = payment.transaction.id;14 console.log('Transaction ID:', txId);15 console.log('Checkout URL:', 'https://paygate-gules.vercel.app/pay/' + txId);16 } catch (error) {17 console.error('Error:', error.message);18 }19}2021createOrder();ตัวอย่างการใช้งาน (PHP)
1<?php2require_once 'PayGate.php'; // Include the downloaded file34$paygate = new PayGate('sk_live_xxxxxxxxxxxxxxxxxxxx');56try {7 $payment = $paygate->createPayment(150.00, 'ORDER-12345', 'Premium Subscription');89 // Redirect user to payment page10 $txId = $payment['transaction']['id'];11 header('Location: https://paygate-gules.vercel.app/pay/' . $txId);12 exit;13} catch (Exception $e) {14 echo 'Error: ' . $e->getMessage();15}16?>ตัวอย่างการใช้งาน (Python)
1from PayGate import PayGate23paygate = PayGate('sk_live_xxxxxxxxxxxxxxxxxxxx')45try:6 payment = paygate.create_payment(7 amount=150.00, 8 order_id='ORDER-12345', 9 description='Premium Subscription'10 )11 tx_id = payment['transaction']['id']12 print(f"Transaction ID: {tx_id}")13 print(f"Checkout URL: https://paygate-gules.vercel.app/pay/{tx_id}")14except Exception as e:15 print(f"Error: {e}")