Create Deposit
API สำหรับสร้างรายการฝากเงินและ QR Code
API นี้รองรับการสร้างรายการฝากเงินและการสร้าง QR Code เพื่อการชำระเงิน
ภาพรวมการทำงาน
ลูกค้า: ส่งข้อมูลที่จำเป็นมายังระบบเพื่อใช้ตรวจสอบการชำระเงิน
ระบบ: ตรวจสอบและจับคู่ธุรกรรมที่เกิดขึ้นกับรายการที่มีในระบบ
สถานะรายการ: ส่งผลการตรวจสอบ (สถานะ) กลับไปยัง URL callback ที่ลูกค้ากำหนดไว้
API for Deposit Transactions and QR Code
This API supports creating deposit transactions and generating QR codes for payments.
Workflow Overview
Client: Sends the necessary data to the system for payment verification.
System: Matches the detected transaction with the corresponding record in the system.
Transaction Status: Sends the verification result (status) back to the callback URL specified by the client.
รายละเอียด Endpoint
POST /api/v1/client/create_deposit
Headers
Authorization
Bearer YOUR_SECRET_TOKEN
x-api-key
YOUR_API_KEY
x-signature
YOUR_BASE64_ENCODED_SIGNATURE
Body
{
"order_id": "",
"amount": 0,
"ref_account": "",
"ref_bank_code": "",
"ref_name_th": "",
"ref_name_en": "",
"ref_user_id": "",
"ref1": "",
"ref2": "",
"callback_url": ""
}order_id
string
Required
หมายเลขออเดอร์หรือเลขอ้างอิงคำสั่งฝากในระบบของคุณ ต้องไม่ซ้ำ กับที่เคยส่งมาแล้ว ใช้สำหรับอ้างอิงรายการในระบบของคุณเอง
amount
number
Required
จำนวนเงินที่ต้องการฝาก มีรูปแบบเป็นตัวเลขพร้อมทศนิยม 2 ตำแหน่ง (ไม่มี comma) เช่น 1000.00 หมายเหตุ: ในบางกรณีระบบอาจปรับค่าเล็กน้อยเพื่อใช้จับคู่กับ QR Code
ref_account
string
Required
ข้อมูลอ้างอิงบัญชีลูกค้า เช่น เลขบัญชีลูกค้า หรือข้อมูลเฉพาะ เพื่อช่วยในการตรวจสอบและระบุแหล่งที่มาของเงิน
ref_bank_code
string
Required
รหัสธนาคารของผู้ฝาก ใช้เพื่อระบุธนาคารต้นทาง
ref_name_th
string
Required
ชื่อลูกค้า (ภาษาไทย) ที่จะโอนเงินมา ช่วยในการตรวจสอบรายการ
ref_name_en
string
Optional
ชื่อลูกค้า (ภาษาอังกฤษ) ที่จะโอนเงินมา ช่วยในกรณีที่จำเป็นต้องใช้งานชื่อภาษาอังกฤษ
ref_user_id
string
Required
รหัสลูกค้าในระบบภายในของคุณเอง ใช้เพื่อเชื่อมโยงคำสั่งฝากกับบัญชีผู้ใช้
ref1
string
Optional
ข้อมูลอ้างอิงเพิ่มเติม (เช่น เลขที่ใบเสร็จ หรือข้อมูลภายในองค์กร)
ref2
string
Optional
ข้อมูลอ้างอิงเพิ่มเติมอีกส่วนหนึ่ง เพื่อใช้ตามความต้องการของระบบภายในของคุณ
callback_url
string
Optional
URL สำหรับรับ Callback หากต้องการเปลี่ยนเฉพาะคำสั่งนี้ หากไม่ระบุ ระบบจะใช้ค่าเริ่มต้นที่ตั้งไว้ในหน้า Profile ของร้านค้า
ตัวอย่างการเรียกใช้งาน (Request Example)
curl -X POST https://baseUrl/api/v1/client/create_deposit \
-H "Authorization: Bearer YOUR_SECRET_TOKEN" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-signature: YOUR_BASE64_ENCODED_SIGNATURE" \
-H "Content-Type: application/json" \
-d '{
"order_id": "123456",
"amount": 1000,
"ref_account": "9876543210",
"ref_bank_code": "014",
"ref_name_th": "จอห์น โด",
"ref_name_en": "John Doe",
"ref_user_id": "user123",
"ref1": "reference1",
"ref2": "reference2"
"callback_url": "xxx"
}'การตอบกลับจาก API (Response Example)
{
"status": "string",
"ref_id": "string",
"dest_bank_code": "string",
"dest_bank_acc_no": "string",
"dest_bank_acc_name": "string",
"order_id": "string",
"amount": 0,
"qr_image": "string",
"qr_image_link": "string",
"create_time": "string",
"expire_time": "string"
}{
"detail": "Deposit are not available at this time"
}{
"detail": [
{
"loc": [
"string",
0
],
"msg": "string",
"type": "string"
}
]
}กรณีสำเร็จ (HTTP 200)
• status: สถานะการสร้างคำสั่ง เช่น “CREATED”
• ref_id: เลขอ้างอิงภายในระบบผู้ให้บริการ
• dest_bank_code, dest_bank_acc_no, dest_bank_acc_name: ข้อมูลธนาคารปลายทางเพื่อใช้ทำรายการฝาก
• qr_image: ข้อมูล QR Code แบบ Base64 (ถ้ามี)
• qr_image_link: ลิงก์ดาวน์โหลด QR Code (ถ้ามี)
• create_time, expire_time: เวลาที่สร้างรายการและเวลาหมดอายุของรายการ กรณีไม่พบหรือไม่สามารถทำรายการได้ (HTTP 404) • detail จะระบุข้อความแจ้งข้อผิดพลาด เช่น “Deposit are not available at this time”
กรณีเกิดข้อผิดพลาดในการตรวจสอบข้อมูล (HTTP 422)
msg จะระบุข้อความแจ้งข้อผิดพลาด เช่น “field required” หรือ “invalid format”
Callback Response
เมื่อทำการเรียก API เพื่อสร้างการฝากเงิน/client/create_depositระบบจะส่งข้อมูลการฝากกลับไปที่ URL callback ที่คุณได้ตั้งค่าไว้ในระบบ
เมื่อการทำรายการสำเร็จ ระบบจะส่ง callback กลับไปที่ URL ที่ได้ตั้งค่าไว้ในระบบ โดยมีโครงสร้างข้อมูลดังนี้
{
"type": "DEPOSIT",
"status": "", //AUTO_SUCCESS ,SUCCESS ,FAILED
"status_desc": "",
"amount": 0,
"mdr_amount": 0,
"stm_desc": "",
"stm_ref_id": "",
"stm_bank_code": "",
"stm_bank_acc_no": "",
"stm_bank_acc_name": "",
"stm_timestamp": "",
"txn_ref_id": "",
"txn_ref_user_id": "",
"txn_ref1": "",
"txn_ref2": "",
"txn_ref_order_id": "",
"txn_ref_bank_code": "",
"txn_ref_bank_acc_no": "",
"txn_ref_bank_acc_name_en": "",
"txn_ref_bank_acc_name_th": "",
"txn_timestamp": "",
} PROCESSING
กำลังดำเนินการ
AUTO_SUCCESS หรือ SUCCESS
ฝากสำเร็จ
FAILED
ฝากล้มเหลว
Callback สำหรับรายการสำเร็จและไม่สำเร็จมีข้อมูลเหมือนกัน ต่างกันที่ Status เท่านั้น
Sample Code
const axios = require('axios')
try {
const { data } = await axios.post(
`${baseUrl}/api/v1/client/create_deposit`, // URL ของ API ที่จะส่งคำขอไป
{
order_id: '123e4567-426614174000', // รหัสคำสั่งฝากเงินที่ไม่ซ้ำ
amount: 1000, // จำนวนเงินที่ต้องการฝาก (ในหน่วยที่ระบบรองรับ เช่น บาท)
ref_account: '1234567890', // หมายเลขบัญชีที่ฝากเงินเข้ามา
ref_bank_code: '004', // รหัสธนาคารที่ฝากเงินเข้ามา (รหัสธนาคาร)
ref_name_th: "จอห์น โด", // ชื่อผู้โอนในภาษาไทย
ref_name_en: "John Doe", // ชื่อผู้โอนในภาษาอังกฤษ
ref_user_id: '', // รหัสผู้ใช้
ref1: '', // ค่าตัวแปรเพิ่มเติม (ถ้ามี หรือปล่อยว่างถ้าไม่จำเป็น)
ref2: '', // ค่าตัวแปรเพิ่มเติม (ถ้ามี หรือปล่อยว่างถ้าไม่จำเป็น)
},
{
headers: { // Headers สำหรับการร้องขอ API
Authorization: 'Bearer YOUR_ACCESS_TOKEN', // ใช้ Bearer Token สำหรับการยืนยันตัวตน
'x-api-key': 'YOUR_API_KEY', // กุญแจ API สำหรับการยืนยันการเข้าถึง
'x-signature': 'YOUR_BASE64_ENCODED_SIGNATURE', // ลายเซ็นที่เข้ารหัสสำหรับความปลอดภัย
},
},
)
// ถ้าคำขอสำเร็จ จะได้ข้อมูลในตัวแปร data
} catch (error) {
// ถ้ามีข้อผิดพลาดเกิดขึ้น จะไปที่บล็อกนี้
console.error('Error', error) // แสดงข้อผิดพลาดในคอนโซล
}<?php
// URL ของ API
$baseUrl = 'https://your-api-url.com'; // แก้ไข URL ตามที่ต้องการ
$ref_account = '1234567890'; // หมายเลขบัญชีที่ฝากเงินเข้ามา
$ref_bank_code = '004'; // รหัสธนาคารที่ฝากเงินเข้ามา
$ref_name_th = 'จอห์น โด'; // ชื่อผู้โอนในภาษาไทย
$ref_name_en = 'John Doe'; // ชื่อผู้โอนในภาษาอังกฤษ
$order_id = '123e4567-426614174000'; // รหัสคำสั่งฝากเงินที่ไม่ซ้ำ
$amount = 1000; // จำนวนเงินที่ต้องการฝาก
$ref_user_id = ''; // รหัสผู้ใช้
$ref1 = ''; // ค่าตัวแปรเพิ่มเติม (ถ้ามี หรือปล่อยว่างถ้าไม่จำเป็น)
$ref2 = ''; // ค่าตัวแปรเพิ่มเติม (ถ้ามี หรือปล่อยว่างถ้าไม่จำเป็น)
// ข้อมูลที่ส่งใน request body
$data = [
'order_id' => $order_id,
'amount' => $amount,
'ref_account' => $ref_account,
'ref_bank_code' => $ref_bank_code,
'ref_name_th' => $ref_name_th,
'ref_name_en' => $ref_name_en,
'ref_user_id' => $ref_user_id,
'ref1' => $ref1,
'ref2' => $ref2,
];
// Headers สำหรับการร้องขอ API
$headers = [
'Authorization: Bearer YOUR_ACCESS_TOKEN', // การให้สิทธิ์ด้วย Bearer token
'x-api-key: YOUR_API_KEY', // กุญแจ API
'x-signature: YOUR_BASE64_ENCODED_SIGNATURE', // ลายเซ็นที่เข้ารหัส
];
// ใช้ cURL ในการส่ง POST request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/api/v1/client/create_deposit'); // URL ของ API
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // ให้ cURL คืนค่าผลลัพธ์
curl_setopt($ch, CURLOPT_POST, true); // ใช้ POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // ข้อมูลที่ส่งใน request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // เพิ่ม headers ที่จำเป็น
// รับผลลัพธ์จากการส่งคำขอ
$response = curl_exec($ch);
// ตรวจสอบข้อผิดพลาดในการเชื่อมต่อ
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
// ปิดการเชื่อมต่อ
curl_close($ch);
// แสดงผลลัพธ์จาก API (อาจจะเป็น JSON หรือข้อความอื่นๆ)
echo $response;
?>เคสไหนที่มีการปรับมือที่ร้านค้าไปก่อนให้สำเร็จ หากระบบมีการยิง callback กลับมาให้ดักไว้เพื่อป้องกันการรับ Callback ซ้ำ
Last updated