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 พร้อมเพย์ส่วนบุคคล
  • 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 ที่ลงทะเบียนไว้ (Tag 30)

Type Definitions ​

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

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

interface PromptPayRequest {
  type: 'PROMPTPAY';
  msisdn?: string;               // เบอร์โทรศัพท์ (0xxxxxxxxx)
  natId?: string;                // เลขบัตรประชาชน (13 หลัก)
  eWalletId?: string;            // E-wallet ID (15 หลัก)
  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 ​

Bill Payment (Biller ID) ​

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

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

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

ฟิลด์จำเป็นรูปแบบ
billerIdใช่string ตัวเลข 15 หลัก รวม suffix ไม่ตัดเลขศูนย์ด้านหน้า
ref1ใช่ASCII ที่พิมพ์ได้ 1-20 ตัว ห้ามว่างล้วน
ref2ไม่รูปแบบเดียวกับ ref1; ไม่ต้องส่งหากไม่ใช้
amountไม่number บวก ทศนิยมไม่เกิน 2 ตำแหน่ง สูงสุด 9999999999.99 บาท

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

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

PromptPay ​

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

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

พารามิเตอร์ประเภทจำเป็นคำอธิบาย
typestringใช่"PROMPTPAY"
msisdnstringเลือก 1เบอร์โทรศัพท์ (0xxxxxxxxx)
natIdstringเลือก 1เลขบัตรประชาชน (13 หลัก)
eWalletIdstringเลือก 1E-wallet ID (15 หลัก)
amountnumberไม่จำนวนเงิน (0.01 ถึง 9999999999.99 ทศนิยมไม่เกิน 2 ตำแหน่ง)

TIP

ต้องระบุ 1 อย่างจาก msisdn, natId หรือ eWalletId

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

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

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

หมายเหตุ ​

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

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

Bank Slip Verification API for Thai Banking