สร้าง QR Code
สร้าง QR Code พร้อมเพย์และร้านค้าสำหรับรับชำระเงิน
Endpoint
http
POST /qr/generateURL เต็ม: https://developer.easyslip.com/api/v1/qr/generate
การยืนยันตัวตน
จำเป็น ดูคู่มือการยืนยันตัวตน
http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/jsonv1 เท่านั้น
การสร้าง QR Code มีเฉพาะใน API v1
Request
ประเภท QR ที่รองรับ
- PromptPay - QR Code พร้อมเพย์ส่วนบุคคล
- K-Shop - QR Code ร้านค้า Kasikorn
- Mae Manee - QR Code ร้านค้า Mae Manee
- Tungngern - QR Code ร้านค้า Tungngern
Type Definitions
typescript
// Request
type QRGenerateRequest = PromptPayRequest | KShopRequest | MaeManeeRequest | TungngernRequest;
interface PromptPayRequest {
type: 'PROMPTPAY';
msisdn?: string; // เบอร์โทรศัพท์ (0xxxxxxxxx)
natId?: string; // เลขบัตรประชาชน (13 หลัก)
eWalletId?: string; // E-wallet ID (15 หลัก)
amount?: number; // จำนวนเงิน (ทศนิยม 2 ตำแหน่ง)
}
interface KShopRequest {
type: 'KSHOP';
ref1: string; // Reference 1 (1-20 ตัวอักษร, ตัวพิมพ์ใหญ่)
amount?: number; // จำนวนเงิน (ทศนิยม 2 ตำแหน่ง)
}
interface MaeManeeRequest {
type: 'MAE_MANEE';
ref1: string; // Reference 1 (1-20 ตัวอักษร, ตัวพิมพ์ใหญ่)
amount?: number; // จำนวนเงิน (ทศนิยม 2 ตำแหน่ง)
}
interface TungngernRequest {
type: 'TUNGNGERN';
ref1: string; // Reference 1 (1-20 ตัวอักษร, ตัวพิมพ์ใหญ่)
merchantName?: string; // ชื่อร้านค้า (1-25 ตัวอักษร)
amount?: number; // จำนวนเงิน (ทศนิยม 2 ตำแหน่ง)
}
// Response
interface QRGenerateResponse {
status: 200;
data: QRData;
}
interface QRData {
image: string; // รูป PNG ที่เข้ารหัส Base64
mime: string; // MIME type (image/png)
payload: string; // ข้อมูล QR Code Payload
}
// Error Response
interface ErrorResponse {
status: number;
message: string;
data?: {
errors: Array<{
field: string;
message: string;
}>;
};
}ตัวอย่าง Request
PromptPay
json
{
"type": "PROMPTPAY",
"msisdn": "0812345678",
"amount": 100.00
}พารามิเตอร์:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
type | string | ใช่ | "PROMPTPAY" |
msisdn | string | เลือก 1 | เบอร์โทรศัพท์ (0xxxxxxxxx) |
natId | string | เลือก 1 | เลขบัตรประชาชน (13 หลัก) |
eWalletId | string | เลือก 1 | E-wallet ID (15 หลัก) |
amount | number | ไม่ | จำนวนเงิน (ทศนิยม 2 ตำแหน่ง) |
TIP
ต้องระบุ 1 อย่างจาก: msisdn, natId หรือ eWalletId
K-Shop
json
{
"type": "KSHOP",
"ref1": "ORDER12345",
"amount": 250.00
}พารามิเตอร์:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
type | string | ใช่ | "KSHOP" |
ref1 | string | ใช่ | Reference 1 (1-20 ตัวอักษร, ตัวพิมพ์ใหญ่) |
amount | number | ไม่ | จำนวนเงิน (ทศนิยม 2 ตำแหน่ง) |
Mae Manee
json
{
"type": "MAE_MANEE",
"ref1": "ORDER12345",
"amount": 500.00
}พารามิเตอร์:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
type | string | ใช่ | "MAE_MANEE" |
ref1 | string | ใช่ | Reference 1 (1-20 ตัวอักษร, ตัวพิมพ์ใหญ่) |
amount | number | ไม่ | จำนวนเงิน (ทศนิยม 2 ตำแหน่ง) |
Tungngern
json
{
"type": "TUNGNGERN",
"ref1": "ORDER12345",
"merchantName": "ร้านของฉัน",
"amount": 750.00
}พารามิเตอร์:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
type | string | ใช่ | "TUNGNGERN" |
ref1 | string | ใช่ | Reference 1 (1-20 ตัวอักษร, ตัวพิมพ์ใหญ่) |
merchantName | string | ไม่ | ชื่อร้านค้า (1-25 ตัวอักษร) |
amount | number | ไม่ | จำนวนเงิน (ทศนิยม 2 ตำแหน่ง) |
ตัวอย่าง
bash
curl -X POST https://developer.easyslip.com/api/v1/qr/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "PROMPTPAY",
"msisdn": "0812345678",
"amount": 100.00
}'javascript
const generateQR = async (config) => {
const response = await fetch('https://developer.easyslip.com/api/v1/qr/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify(config)
});
const result = await response.json();
if (result.status !== 200) {
throw new Error(result.message);
}
return result.data;
};
// สร้าง PromptPay QR
const promptPayQR = await generateQR({
type: 'PROMPTPAY',
msisdn: '0812345678',
amount: 100.00
});
// แสดง QR Code
const img = document.createElement('img');
img.src = `data:${promptPayQR.mime};base64,${promptPayQR.image}`;
document.body.appendChild(img);
// สร้าง K-Shop QR
const kshopQR = await generateQR({
type: 'KSHOP',
ref1: 'ORDER12345',
amount: 250.00
});php
function generateQR(array $config): array
{
$apiKey = getenv('EASYSLIP_API_KEY');
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://developer.easyslip.com/api/v1/qr/generate',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode($config)
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['status'] !== 200) {
throw new Exception($result['message']);
}
return $result['data'];
}
// สร้าง PromptPay QR
$qr = generateQR([
'type' => 'PROMPTPAY',
'msisdn' => '0812345678',
'amount' => 100.00
]);
// บันทึกเป็นไฟล์
$imageData = base64_decode($qr['image']);
file_put_contents('qr-code.png', $imageData);
// หรือแสดงในหน้าเว็บ
echo '<img src="data:' . $qr['mime'] . ';base64,' . $qr['image'] . '">';python
import requests
import base64
import os
def generate_qr(config: dict) -> dict:
response = requests.post(
'https://developer.easyslip.com/api/v1/qr/generate',
headers={
'Authorization': f'Bearer {os.environ["EASYSLIP_API_KEY"]}',
'Content-Type': 'application/json'
},
json=config
)
result = response.json()
if result['status'] != 200:
raise Exception(result['message'])
return result['data']
# สร้าง PromptPay QR
qr = generate_qr({
'type': 'PROMPTPAY',
'msisdn': '0812345678',
'amount': 100.00
})
# บันทึกเป็นไฟล์
image_data = base64.b64decode(qr['image'])
with open('qr-code.png', 'wb') as f:
f.write(image_data)
print(f"Payload: {qr['payload']}")Response
สำเร็จ (200)
json
{
"status": 200,
"data": {
"image": "iVBORw0KGgoAAAANSUhEUgAA...",
"mime": "image/png",
"payload": "00020101021230..."
}
}ฟิลด์ใน Response
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
image | string | รูป PNG ที่เข้ารหัส Base64 |
mime | string | MIME type (image/png) |
payload | string | ข้อมูล QR Code Payload |
Error Responses
Request ไม่ถูกต้อง (400)
json
{
"status": 400,
"message": "invalid_request",
"data": {
"errors": [
{ "field": "ref1", "message": "Required" }
]
}
}ไม่ได้รับอนุญาต (401)
json
{
"status": 401,
"message": "unauthorized"
}หมายเหตุ
- การสร้าง QR Code ไม่หักโควต้าการตรวจสอบ
- QR Code ที่สร้างใช้ได้ตลอดไป
- จำนวนเงินเป็น Optional - ลูกค้าสามารถกรอกจำนวนเงินเองเมื่อจ่าย
- Reference fields ต้องเป็นตัวอักษรและตัวเลข และเป็นตัวพิมพ์ใหญ่