Skip to content

สร้าง QR Code ​

สร้าง QR Code พร้อมเพย์และร้านค้าสำหรับรับชำระเงิน

Endpoint ​

http
POST /qr/generate

URL เต็ม: https://api.easyslip.com/v1/qr/generate

การยืนยันตัวตน ​

ต้องยืนยันตัวตน ดู คู่มือการยืนยันตัวตน

http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

v1 เท่านั้น

การสร้าง QR Code มีเฉพาะใน API v1

Request ​

ประเภท QR ที่รองรับ ​

  • PromptPay - QR Code พร้อมเพย์ ด้วยเบอร์โทรศัพท์ เลขบัตรประชาชน E-wallet ID หรือ Biller ID ที่ลงทะเบียนไว้ (Tag 30)
  • K-Shop - QR Code ร้านค้า Kasikorn สำหรับรหัสร้าน K SHOP (KB ตามด้วยตัวเลข 12 หลัก)
  • Mae Manee - QR Code ร้านค้า Mae Manee สำหรับรหัสร้านแม่มณี 15 หลัก
  • Tungngern - QR Code ร้านค้า Tungngern ด้วยรหัสร้าน และชื่อร้านภาษาอังกฤษ (ไม่บังคับ)
  • Bill Payment - รูปแบบเดิมที่ยังใช้ได้ สร้าง QR Code ชำระบิลด้วย Biller ID ได้ QR ตัวเดียวกับ PromptPay แบบ billerId

Type Definitions ​

typescript
// Request
type QRGenerateRequest = PromptPayRequest | KShopRequest | MaeManeeRequest | TungngernRequest | BillPaymentRequest;

interface PromptPayRequest {
  type: 'PROMPTPAY';
  // ระบุอย่างใดอย่างหนึ่งเท่านั้น: msisdn, natId, eWalletId หรือ billerId
  msisdn?: string;               // เบอร์โทรศัพท์ (0xxxxxxxxx)
  natId?: string;                // เลขบัตรประชาชน (13 หลัก)
  eWalletId?: string;            // E-wallet ID (15 หลัก)
  billerId?: string;             // Biller ID 15 หลักรวม suffix; ต้องส่งเป็น string เพื่อคงเลขศูนย์ด้านหน้า
  ref1?: string;                 // จำเป็นเมื่อใช้ billerId: ASCII ที่พิมพ์ได้ 1-20 ตัว คงตัวพิมพ์เล็ก/ใหญ่
  ref2?: string;                 // ใช้ได้เฉพาะกับ billerId: รูปแบบเดียวกับ ref1; ไม่ต้องส่งหากไม่ใช้
  terminalId?: string;           // ใช้ได้เฉพาะกับ billerId: รหัสเครื่อง (tag 62 sub 07) ASCII ที่พิมพ์ได้ 1-25 ตัว
  referenceLabel?: string;       // ใช้ได้เฉพาะกับ billerId: Reference label (tag 62 sub 05) ASCII ที่พิมพ์ได้ 1-25 ตัว
  amount?: number;               // จำนวนเงิน (ทศนิยม 2 ตำแหน่ง); กับ billerId 0.01 ถึง 9999999999.99
}

// รูปแบบเดิมที่ยังรองรับ: ได้ QR เดียวกับ PROMPTPAY แบบ billerId
interface BillPaymentRequest {
  type: 'BILL_PAYMENT';
  billerId: string;      // 15 หลักรวม suffix; ต้องส่งเป็น string เพื่อคงเลขศูนย์ด้านหน้า
  ref1: string;          // ASCII ที่พิมพ์ได้ 1-20 ตัว คงตัวพิมพ์เล็ก/ใหญ่
  ref2?: string;         // รูปแบบเดียวกับ ref1; ไม่ต้องส่งหากไม่ใช้
  terminalId?: string;   // รหัสเครื่อง (tag 62 sub 07) ASCII ที่พิมพ์ได้ 1-25 ตัว
  referenceLabel?: string; // Reference label (tag 62 sub 05) ASCII ที่พิมพ์ได้ 1-25 ตัว
  amount?: number;       // 0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 2 ตำแหน่ง
}

interface KShopRequest {
  type: 'KSHOP';
  ref1: string;                  // รหัสร้าน K SHOP: KB ตามด้วยตัวเลข 12 หลัก พิมพ์เล็กหรือใหญ่ก็ได้; ถ้ามี KPS004 นำหน้าระบบจะตัดออก
  amount?: number;               // จำนวนเงิน 0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 2 ตำแหน่ง
}

interface MaeManeeRequest {
  type: 'MAE_MANEE';
  ref1: string;                  // รหัสร้านแม่มณี: ตัวเลข 15 หลัก
  amount?: number;               // จำนวนเงิน 0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 2 ตำแหน่ง
}

interface TungngernRequest {
  type: 'TUNGNGERN';
  ref1: string;                  // รหัสร้านถุงเงิน (ตัวอักษรอังกฤษและตัวเลข 1-20 ตัว, ตัวพิมพ์ใหญ่)
  merchantName?: string;         // ไม่บังคับ: ชื่อร้านภาษาอังกฤษตามแอปถุงเงิน เก็บเฉพาะ A-Z0-9 ไม่เกิน 20 ตัว ถ้าไม่ส่งจะใช้ ref1
  amount?: number;               // จำนวนเงิน 0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 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;
  details?: string | Array<{ field: string; message: string }>;
}

ตัวอย่าง Request ​

PromptPay (Biller ID) ​

ส่ง type เป็น PROMPTPAY พร้อม Biller ID 15 หลักที่ลงทะเบียนกับธนาคารหรือผู้ให้บริการไว้แล้ว Endpoint นี้สร้างแค่ QR สำหรับรับชำระเงิน ไม่ได้ออกหรือลงทะเบียน Biller ID ใหม่ และไม่ได้เช็กว่า ID นั้นยังเปิดใช้งานอยู่

json
{
  "type": "PROMPTPAY",
  "billerId": "010555123456701",
  "ref1": "INV20261014001",
  "ref2": "CUSTOMER001",
  "amount": 125.50
}

ID ในตัวอย่างใช้ประกอบเอกสารเท่านั้น ให้เปลี่ยนเป็น Biller ID ของคุณ

ฟิลด์จำเป็นรูปแบบ
typeใช่"PROMPTPAY"
billerIdใช่string ตัวเลข 15 หลัก รวม suffix ไม่ตัดเลขศูนย์ด้านหน้า
ref1ใช่ASCII ที่พิมพ์ได้ 1-20 ตัว ห้ามว่างล้วน
ref2ไม่รูปแบบเดียวกับ ref1; ไม่ต้องส่งหากไม่ใช้
terminalIdไม่ASCII ที่พิมพ์ได้ 1-25 ตัว ห้ามเป็นช่องว่างล้วน ดู ร้านที่มีเครื่องรับเงิน
referenceLabelไม่ASCII ที่พิมพ์ได้ 1-25 ตัว ห้ามเป็นช่องว่างล้วน ส่งคู่กับ terminalId เมื่อ QR เดิมของร้านมี
amountไม่number บวก ทศนิยมไม่เกิน 2 ตำแหน่ง 0.01 ถึง 9999999999.99 บาท

ห้ามส่ง msisdn, natId หรือ eWalletId มาพร้อมกับ billerId (จะได้ 400) ระบบใช้ค่าอ้างอิงตามที่ส่งมาทุกตัวอักษร ไม่เปลี่ยนเป็นตัวพิมพ์ใหญ่และไม่ตัดช่องว่าง จึงต้องส่งตามรูปแบบอ้างอิงที่ธนาคารกำหนดให้ Biller ID ของคุณ ถ้าไม่ส่ง amount ผู้จ่ายจะกรอกจำนวนเงินเองได้ รูปแบบ response (image, mime, payload) เหมือน QR ประเภทเดิม

รูปแบบข้อมูลอ้างอิง มาตรฐาน Thai QR Code ของ ธปท. หน้า 15

ร้านที่มีเครื่องรับเงิน ​

ร้านที่มีเครื่องรับเงิน QR เดิมของร้านจะมีข้อมูลเพิ่ม (tag 62) คือ Reference label (sub tag 05) และรหัสเครื่อง (sub tag 07) หากสร้าง QR โดยไม่ใส่ อาจจ่ายไม่ผ่านในแอปธนาคาร ("ร้านค้าไม่สามารถทำรายการรับชำระ") ให้คัดลอกสองค่านี้จาก QR เดิมของร้านแล้วส่งเป็น referenceLabel และ terminalId ทั้งสองไม่บังคับ ใช้ได้กับ PROMPTPAY แบบ billerId และ BILL_PAYMENT เท่านั้น หากไม่ส่ง payload เหมือนเดิมทุกตัวอักษร

json
{
  "type": "PROMPTPAY",
  "billerId": "040556800491515",
  "ref1": "DEHENG",
  "amount": 1,
  "terminalId": "23035360",
  "referenceLabel": "23035360"
}

ได้ payload นี้ (tag 62 อยู่หลัง tag 58 โดย sub tag 05 มาก่อน sub tag 07)

00020101021230490016A00000067701011201150405568004915150206DEHENG530376454041.005802TH62240508230353600708230353606304E955

Bill Payment (รูปแบบเดิม) ​

BILL_PAYMENT ยังใช้ได้ด้วยฟิลด์เดียวกัน (billerId, ref1, ref2, amount, terminalId, referenceLabel) และเงื่อนไขเดียวกัน ถ้าส่งข้อมูลชุดเดียวกันจะได้ QR และ payload ตรงกับ PROMPTPAY แบบ billerId ทุกตัวอักษร ระบบที่เพิ่งเริ่มเชื่อมต่อควรใช้ PROMPTPAY

json
{
  "type": "BILL_PAYMENT",
  "billerId": "010555123456701",
  "ref1": "INV20261014001",
  "ref2": "CUSTOMER001",
  "amount": 125.50
}

PromptPay ​

json
{
  "type": "PROMPTPAY",
  "msisdn": "0812345678",
  "amount": 100.00
}

พารามิเตอร์:

พารามิเตอร์ประเภทจำเป็นคำอธิบาย
typestringใช่"PROMPTPAY"
msisdnstringเลือก 1เบอร์โทรศัพท์ (0xxxxxxxxx)
natIdstringเลือก 1เลขบัตรประชาชน (13 หลัก)
eWalletIdstringเลือก 1E-wallet ID (15 หลัก)
billerIdstringเลือก 1Biller ID (15 หลักรวม suffix ไม่ตัดเลขศูนย์ด้านหน้า)
ref1stringเมื่อใช้ billerIdReference 1 (ASCII ที่พิมพ์ได้ 1-20 ตัว คงตัวพิมพ์เล็ก/ใหญ่) จำเป็นเมื่อใช้ billerId
ref2stringไม่Reference 2 ใช้ได้เฉพาะกับ billerId (รูปแบบเดียวกับ ref1)
terminalIdstringไม่รหัสเครื่อง (tag 62 sub 07) ใช้ได้เฉพาะกับ billerId ASCII ที่พิมพ์ได้ 1-25 ตัว
referenceLabelstringไม่Reference label (tag 62 sub 05) ใช้ได้เฉพาะกับ billerId ASCII ที่พิมพ์ได้ 1-25 ตัว
amountnumberไม่จำนวนเงิน (ทศนิยม 2 ตำแหน่ง; กับ billerId 0.01 ถึง 9999999999.99)

TIP

ต้องระบุ 1 อย่างจาก msisdn, natId, eWalletId หรือ billerId ส่วน ref1 และ ref2 ใช้ได้กับ billerId เท่านั้น ถ้าส่งคู่กับตัวระบุอื่นจะได้ 400

K-Shop ​

json
{
  "type": "KSHOP",
  "ref1": "KB000001234567",
  "amount": 250.00
}

ref1 คือรหัสร้าน K SHOP ของคุณ: KB ตามด้วยตัวเลข 12 หลัก พิมพ์เล็กหรือใหญ่ก็ได้ ถ้ามี KPS004 นำหน้า (เช่น KPS004KB000001234567) ระบบจะตัดออกให้ รูปแบบอื่นจะได้ 400

พารามิเตอร์:

พารามิเตอร์ประเภทจำเป็นคำอธิบาย
typestringใช่"KSHOP"
ref1stringใช่รหัสร้าน K SHOP: KB ตามด้วยตัวเลข 12 หลัก พิมพ์เล็กหรือใหญ่ก็ได้; ตัด KPS004 ที่นำหน้าออกให้
amountnumberไม่จำนวนเงิน (0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 2 ตำแหน่ง)

Mae Manee ​

json
{
  "type": "MAE_MANEE",
  "ref1": "014000123456789",
  "amount": 500.00
}

ref1 คือรหัสร้านแม่มณี 15 หลักของคุณ QR มีแค่ tag 30 ไม่มี tag 31 ของ KBank

พารามิเตอร์:

พารามิเตอร์ประเภทจำเป็นคำอธิบาย
typestringใช่"MAE_MANEE"
ref1stringใช่รหัสร้านแม่มณี: ตัวเลข 15 หลัก
amountnumberไม่จำนวนเงิน (0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 2 ตำแหน่ง)

Tungngern ​

json
{
  "type": "TUNGNGERN",
  "ref1": "ORDER12345",
  "merchantName": "MY STORE",
  "amount": 750.00
}

merchantName ไม่บังคับ ถ้ามีชื่อร้านภาษาอังกฤษที่แสดงในแอปถุงเงินให้ส่งมา ใช้ได้เฉพาะตัวอักษรอังกฤษและตัวเลข ระบบจะเปลี่ยนเป็นตัวพิมพ์ใหญ่ ตัดทุกอย่างที่ไม่ใช่ A-Z และ 0-9 ออก แล้วตัดให้เหลือไม่เกิน 20 ตัว เช่น MY STORE จะอยู่ใน QR เป็น MYSTORE ถ้าไม่ส่ง หรือไม่เหลืออะไรหลังตัด (เช่น ชื่อภาษาไทยล้วน) QR จะใช้ ref1 เป็นชื่อร้านแทน QR จะมี tag 62 ที่ sub-tag 07 เป็น 0000 ด้วย

พารามิเตอร์:

พารามิเตอร์ประเภทจำเป็นคำอธิบาย
typestringใช่"TUNGNGERN"
ref1stringใช่รหัสร้านถุงเงิน (ตัวอักษรอังกฤษและตัวเลข 1-20 ตัว, ตัวพิมพ์ใหญ่)
merchantNamestringไม่ชื่อร้านภาษาอังกฤษตามแอปถุงเงิน ใช้ได้เฉพาะตัวอักษรอังกฤษและตัวเลข (ระบบเปลี่ยนเป็น A-Z0-9 ตัวพิมพ์ใหญ่ ไม่เกิน 20 ตัว) ถ้าไม่ส่งหรือว่างจะใช้ ref1 แทน
amountnumberไม่จำนวนเงิน (0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 2 ตำแหน่ง)

ตัวอย่าง ​

bash
curl -X POST https://api.easyslip.com/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://api.easyslip.com/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: 'KB000001234567',
  amount: 250.00
});
php
function generateQR(array $config): array
{
    $apiKey = getenv('EASYSLIP_API_KEY');

    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => 'https://api.easyslip.com/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://api.easyslip.com/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 ​

ฟิลด์ประเภทคำอธิบาย
imagestringรูป PNG ที่เข้ารหัส Base64
mimestringMIME type (image/png)
payloadstringข้อมูล QR Code Payload

Error Responses ​

Request ไม่ถูกต้อง (400) ​

json
{
  "status": 400,
  "message": "invalid_request",
  "details": [
    { "field": "ref1", "message": "ref1 must be KB followed by 12 digits" }
  ]
}
กรณีfieldmessage
ref1 ของ KSHOP ไม่ใช่ KB + ตัวเลข 12 หลักref1ref1 must be KB followed by 12 digits
ref1 ของ MAE_MANEE ไม่ใช่ตัวเลข 15 หลักref1ref1 must be the 15-digit Mae Manee shop id
merchantName ของ TUNGNGERN ไม่ใช่ stringmerchantNamemerchantName: use the English shop name shown in the Tung Ngern app

PROMPTPAY ที่ใช้ msisdn, natId หรือ eWalletId จะได้ details เป็นข้อความเดียว:

json
{
  "status": 400,
  "message": "invalid_request",
  "details": "ref1 and ref2 are only allowed with billerId"
}

ไม่ได้รับอนุญาต (401) ​

json
{
  "status": 401,
  "message": "unauthorized"
}

หมายเหตุ ​

  • การสร้าง QR Code ไม่หักโควต้าการตรวจสอบ
  • QR Code ที่สร้างไม่มีวันหมดอายุ
  • ไม่ใส่จำนวนเงินก็ได้ ลูกค้าจะกรอกเองตอนจ่าย
  • ref1 ของ KSHOP คือรหัสร้าน K SHOP (KB + ตัวเลข 12 หลัก) และ ref1 ของ MAE_MANEE คือรหัสร้าน 15 หลัก ส่วน ref1 ของ TUNGNGERN รับตัวอักษรและตัวเลข ระบบจะเปลี่ยนเป็นตัวพิมพ์ใหญ่ให้ ส่วนค่าอ้างอิงของ Biller ID (PROMPTPAY แบบ billerId และ BILL_PAYMENT) คงตัวพิมพ์เล็ก/ใหญ่และรับ ASCII ที่พิมพ์ได้

ที่เกี่ยวข้อง ​

Bank Slip Verification API for Thai Banking