API เวอร์ชัน 1.0

PayGate API

สร้างระบบชำระเงินที่ทรงพลังด้วย API ที่เรียบง่าย ปลอดภัย และใช้งานง่าย สำหรับ PromptPay QR

ดูบน GitHub
โฮสต์ Production หลัก (canonical)Production

ใช้ host นี้ทุกที่ (NEXT_PUBLIC_API_URL, mobile app, SDK) เพื่อหลีกเลี่ยงความสับสนข้าม environment

Production Host

https://paygate-production-f1e9.up.railway.app

Public API (/api/v1)

https://paygate-production-f1e9.up.railway.app/api/v1

Dashboard/Admin API (/api)

https://paygate-production-f1e9.up.railway.app/api
Base URL ที่กำลังใช้ในหน้านี้ (NEXT_PUBLIC_API_URL):https://api.hyperpay.pro

เชื่อมต่อง่าย

เริ่มต้นใช้งานได้ในไม่กี่นาทีด้วย REST API และ SDK ที่มีเอกสารครบถ้วน

ปลอดภัยตั้งแต่ต้น

ความปลอดภัยระดับธนาคารด้วย API Key และ Webhook Signature

แจ้งเตือนทันที

รับการแจ้งเตือนทันทีเมื่อมีการชำระเงินสำเร็จ

API Endpoints

Base URL: https://paygate-production-f1e9.up.railway.app/api/v1
POST
https://paygate-production-f1e9.up.railway.app/api/v1/payment/create

สร้างลิงก์ชำระเงินใหม่

GET
https://paygate-production-f1e9.up.railway.app/api/v1/payment/:id

ตรวจสอบสถานะการชำระเงิน

GET
https://paygate-production-f1e9.up.railway.app/api/v1/payment/order/:orderId

ค้นหาจาก Order ID / Lookup by Order ID

GET
https://paygate-production-f1e9.up.railway.app/api/v1/transactions

ดูรายการธุรกรรมทั้งหมด

POST
https://paygate-production-f1e9.up.railway.app/api/v1/payment/:id/cancel

Cancel payment

POST
https://paygate-production-f1e9.up.railway.app/api/payment/create-link

Dashboard API (JWT) - create payment link

เริ่มต้นอย่างรวดเร็ว

5 นาที

โหมดการรับเงินตามแพลน

แพลน Free
  • QR Code ชี้ไปที่บัญชีกลาง PayGate
  • ต้องขอถอนเงินหลังได้รับชำระ
  • ค่าธรรมเนียม 3% ต่อรายการ
แพลน Basic/Pro/Enterprise
  • QR Code ชี้ไปที่ PromptPay ของคุณ
  • เงินเข้าบัญชีคุณโดยตรง ทันที
  • ค่าธรรมเนียมลดเหลือ 1.5-2.5%
1

สร้างบัญชี

สมัครบัญชีร้านค้า PayGate และรอการอนุมัติ

สร้างบัญชี
2

รับ API Key

สร้าง API Key จากหน้า Dashboard ของคุณ

API Key ของคุณ
text
sk_live_xxxxxxxxxxxxxxxxxxxx
3

สร้าง Payment แรก

เรียก API เพื่อสร้างลิงก์ชำระเงินแรกของคุณ

create-payment.js
javascript
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});
13
14const 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

HTTP Header
text
X-API-Key: sk_xxxxxxxxxxxxxxxxxxxx
# or (supported fallback)
Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxx

Public API (/api/v1): ส่ง API Key ผ่าน X-API-Key หรือ Bearer <API Key>

Dashboard/Admin: ใช้ JWT Bearer token จาก /api/auth/login หรือ /api/auth/admin/login

ตัวอย่าง Request

terminal
bash
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"

สร้างลิงก์ชำระเงิน

POSThttps://paygate-production-f1e9.up.railway.app/api/v1/payment/create

Request Body

พารามิเตอร์ประเภทจำเป็นคำอธิบาย
amountnumber จำเป็นจำนวนเงิน (บาท)
orderIdstringไม่บังคับรหัสคำสั่งซื้อของร้านค้า
descriptionstringไม่บังคับรายละเอียดที่แสดงให้ลูกค้า
metadataobjectไม่บังคับข้อมูล metadata (JSON) จะถูกส่งกลับใน webhook

ตัวอย่าง Request

create-payment.js
javascript
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});
14
15const 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

response.json
json
{
  "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"
  }
}

ตรวจสอบสถานะ

GEThttps://paygate-production-f1e9.up.railway.app/api/v1/payment/:id

ค่าสถานะ

PENDING

รอชำระเงิน (PENDING)

PAID

ชำระเงินแล้ว (PAID)

CANCELLED

ยกเลิก (CANCELLED)

EXPIRED

หมดอายุ (EXPIRED)

ตัวอย่าง Response

response.json
json
{
  "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.expired

QR หมดอายุ

settlement.created

สร้างคำขอถอนเงิน

settlement.completed

โอนเงินให้ร้านค้าเรียบร้อย

Headers: X-Webhook-Signature (HMAC SHA256) และ X-Webhook-Event จะถูกส่งมาพร้อม payload

Webhook Payload

webhook-payload.json
json
{
  "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

verify-webhook.js
javascript
1const crypto = require('crypto');
2
3function verifyWebhookSignature(payload, signature, secret) {
4 const expectedSignature = crypto
5 .createHmac('sha256', secret)
6 .update(JSON.stringify(payload))
7 .digest('hex');
8
9 return signature === expectedSignature;
10}
11
12// Express.js example
13app.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 สำเร็จรูปจากระบบหลังบ้าน

POSThttps://paygate-production-f1e9.up.railway.app/api/payment/create-link
create-link.js
javascript
1const 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: 60
12 })
13});
14
15const data = await response.json();
16console.log('Payment Link:', data.paymentLink);
17console.log('Transaction ID:', data.transaction.id);

Response

response.json
json
{
  "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 (ตัวเลือก)

index.html
html
<!-- 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คำอธิบาย
400INVALID_REQUESTข้อมูล Request ไม่ถูกต้อง
401UNAUTHORIZEDAPI Key ไม่ถูกต้องหรือไม่มี
403FORBIDDENไม่มีสิทธิ์เข้าถึง
404NOT_FOUNDไม่พบ Resource
500SERVER_ERRORเกิดข้อผิดพลาดภายในเซิร์ฟเวอร์

รูปแบบ Error Response

error-response.json
json
{
  "error": "Unauthorized",
  "message": "API key is required. Send it via X-API-Key header."
}

SDKs & Libraries

ใช้ SDK อย่างเป็นทางการเพื่อเชื่อมต่อได้ง่ายขึ้น

Node.js

JavaScript / TypeScript

ดาวน์โหลด
paygate-node.js

PHP

Native / Laravel / WP

ดาวน์โหลด
PayGate.php

Python

Django / Flask

ดาวน์โหลด
PayGate.py

ตัวอย่างการใช้งาน (Node.js)

app.js
javascript
1const PayGate = require('./paygate-node.js'); // Point to the downloaded file
2
3const paygate = new PayGate('sk_live_xxxxxxxxxxxxxxxxxxxx');
4
5async function createOrder() {
6 try {
7 const payment = await paygate.createPayment({
8 amount: 150.00,
9 orderId: 'ORDER-12345',
10 description: 'Premium Subscription'
11 });
12
13 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}
20
21createOrder();

ตัวอย่างการใช้งาน (PHP)

checkout.php
php
1<?php
2require_once 'PayGate.php'; // Include the downloaded file
3
4$paygate = new PayGate('sk_live_xxxxxxxxxxxxxxxxxxxx');
5
6try {
7 $payment = $paygate->createPayment(150.00, 'ORDER-12345', 'Premium Subscription');
8
9 // Redirect user to payment page
10 $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)

app.py
python
1from PayGate import PayGate
2
3paygate = PayGate('sk_live_xxxxxxxxxxxxxxxxxxxx')
4
5try:
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}")

พร้อมเริ่มต้นแล้วหรือยัง?

สร้างบัญชีร้านค้าและเริ่มรับชำระเงินได้ในไม่กี่นาที