POST /bank-accounts
สร้างบัญชีธนาคาร ระบบจะเชื่อมโยงบัญชีกับ Branch ที่เรียกใช้ให้อัตโนมัติ Branch ของคุณจึงเห็นบัญชีได้ทันที
Endpoint
http
POST /bank-accountsURL เต็ม: https://api.easyslip.com/v2/bank-accounts
การยืนยันตัวตน
ต้องยืนยันตัวตน ดู คู่มือการยืนยันตัวตน
http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/jsonRequest
พารามิเตอร์
| พารามิเตอร์ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
bankCode | string | ใช่ | รหัสที่ถูกต้องจาก GET /banks |
bankNumber | string | ใช่ | เลขที่บัญชี |
nameTh | string | ใช่ | ชื่อเจ้าของบัญชี (ไทย) ไม่เกิน 255 ตัวอักษร |
nameEn | string | ใช่ | ชื่อเจ้าของบัญชี (อังกฤษ) ไม่เกิน 255 ตัวอักษร |
type | string | ใช่ | ประเภทบัญชี: NATURAL หรือ JURISTIC |
extraVerify | string | ไม่ | ตัวเลือกการตรวจสอบของธนาคาร ต้องเป็นค่า value ที่ธนาคารนั้นรองรับ (ดู GET /banks) |
matchMode | string | ไม่ | โหมดจับคู่สำหรับ PromptPay: NAME, NUMBER หรือ NAME_NUMBER ใช้ได้กับบัญชี PromptPay เท่านั้น ถ้าไม่ส่งจะมีผลเป็น NUMBER |
Request Body
json
{
"bankCode": "004",
"bankNumber": "123-4-56789-0",
"nameTh": "บริษัท ตัวอย่าง จำกัด",
"nameEn": "EXAMPLE CO., LTD.",
"type": "JURISTIC"
}serviceId กำหนดอัตโนมัติ
เซิร์ฟเวอร์กำหนด serviceId ให้จาก API Key ของคุณ ส่งเองใน Request ไม่ได้
Type Definitions
typescript
// Request
interface CreateBankAccountRequest {
bankCode: string; // ต้องเป็นรหัสที่ถูกต้องจาก GET /banks
bankNumber: string;
nameTh: string; // ไม่เกิน 255 ตัวอักษร
nameEn: string; // ไม่เกิน 255 ตัวอักษร
type: 'NATURAL' | 'JURISTIC';
extraVerify?: string; // ต้องเป็นค่า value ที่ธนาคารรองรับ (ดู GET /banks)
matchMode?: 'NAME' | 'NUMBER' | 'NAME_NUMBER'; // PromptPay เท่านั้น; ไม่ส่ง = มีผลเป็น NUMBER
}
// Response
interface BankAccountResponse {
success: true;
data: BankAccount;
}
interface BankAccount {
id: number;
bankCode: string;
bankNumber: string;
nameTh: string;
nameEn: string;
type: 'NATURAL' | 'JURISTIC';
extraVerify: string | null;
matchMode: 'NAME' | 'NUMBER' | 'NAME_NUMBER' | null;
createdAt: string; // ISO 8601
updatedAt: string; // ISO 8601
}
// Error Response
interface ErrorResponse {
success: false;
error: {
code: string;
message: string;
};
}ตัวอย่าง
bash
curl -X POST https://api.easyslip.com/v2/bank-accounts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"bankCode": "004",
"bankNumber": "123-4-56789-0",
"nameTh": "บริษัท ตัวอย่าง จำกัด",
"nameEn": "EXAMPLE CO., LTD.",
"type": "JURISTIC"
}'javascript
const createBankAccount = async (account) => {
const response = await fetch('https://api.easyslip.com/v2/bank-accounts', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify(account)
});
const result = await response.json();
if (!result.success) {
throw new Error(result.error.message);
}
return result.data;
};
// การใช้งาน
const account = await createBankAccount({
bankCode: '004',
bankNumber: '123-4-56789-0',
nameTh: 'บริษัท ตัวอย่าง จำกัด',
nameEn: 'EXAMPLE CO., LTD.',
type: 'JURISTIC'
});
console.log('สร้างบัญชีแล้ว:', account.id);php
function createBankAccount(array $account): array
{
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.easyslip.com/v2/bank-accounts',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode($account)
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if (!$result['success']) {
throw new Exception($result['error']['message']);
}
return $result['data'];
}
// การใช้งาน
$account = createBankAccount([
'bankCode' => '004',
'bankNumber' => '123-4-56789-0',
'nameTh' => 'บริษัท ตัวอย่าง จำกัด',
'nameEn' => 'EXAMPLE CO., LTD.',
'type' => 'JURISTIC'
]);
echo "สร้างบัญชีแล้ว: " . $account['id'];python
import requests
def create_bank_account(account: dict) -> dict:
response = requests.post(
'https://api.easyslip.com/v2/bank-accounts',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json=account
)
result = response.json()
if not result['success']:
raise Exception(result['error']['message'])
return result['data']
# การใช้งาน
account = create_bank_account({
'bankCode': '004',
'bankNumber': '123-4-56789-0',
'nameTh': 'บริษัท ตัวอย่าง จำกัด',
'nameEn': 'EXAMPLE CO., LTD.',
'type': 'JURISTIC'
})
print('สร้างบัญชีแล้ว:', account['id'])Response
สำเร็จ (201)
json
{
"success": true,
"data": {
"id": 12345,
"bankCode": "004",
"bankNumber": "123-4-56789-0",
"nameTh": "บริษัท ตัวอย่าง จำกัด",
"nameEn": "EXAMPLE CO., LTD.",
"type": "JURISTIC",
"extraVerify": null,
"matchMode": null,
"createdAt": "2024-01-15T14:30:00+07:00",
"updatedAt": "2024-01-15T14:30:00+07:00"
}
}Error Responses
Validation Error (400)
json
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "bankNumber: Too small: expected string to have >=1 characters"
}
}รหัสธนาคารไม่ถูกต้อง (400)
json
{
"success": false,
"error": {
"code": "INVALID_BANK_CODE",
"message": "The provided bankCode is not supported"
}
}extraVerify ไม่ถูกต้อง (400)
json
{
"success": false,
"error": {
"code": "INVALID_EXTRA_VERIFY",
"message": "The provided extraVerify is not a valid option for this bank"
}
}matchMode ไม่ถูกต้อง (400)
json
{
"success": false,
"error": {
"code": "INVALID_MATCH_MODE",
"message": "matchMode is supported only for PromptPay accounts"
}
}บัญชีซ้ำ (409)
json
{
"success": false,
"error": {
"code": "BANK_ACCOUNT_DUPLICATE",
"message": "An active account with the same bank code and number already exists"
}
}โหมดการจับคู่ PromptPay
matchMode บอกว่าฟิลด์ไหนของบัญชีต้องตรงกับสลิป PromptPay:
| ค่า | เงื่อนไขการจับคู่ |
|---|---|
NAME | ชื่อผู้รับในสลิปตรงกับ nameTh หรือ nameEn |
NUMBER | เลข proxy account ในสลิปตรงกับ bankNumber |
NAME_NUMBER | ทั้งชื่อผู้รับและเลข proxy account ต้องตรงกัน |
json
{
"bankCode": "PROMPTPAY",
"bankNumber": "0812345678",
"nameTh": "นาย ทดสอบ",
"nameEn": "TEST USER",
"type": "NATURAL",
"extraVerify": "MSISDN",
"matchMode": "NAME_NUMBER"
}extraVerify ยังเป็นเงื่อนไขบังคับของการจับคู่
matchMode ใช้แทน extraVerify ไม่ได้ ไม่ว่าจะใช้โหมดไหน ประเภท PromptPay proxy ในสลิปต้องตรงกับค่า extraVerify ของบัญชี (MSISDN, NATID, EWALLETID หรือ BILLERID) ก่อน แล้วระบบจึงตรวจชื่อหรือเลขตามโหมด
ไคลเอนต์เดิมไม่ต้องส่ง matchMode ก็ได้ ค่าที่เก็บไว้อาจเป็น null แต่ Response จะแสดง และการจับคู่จะใช้ค่า effective เป็น NUMBER
หมายเหตุ
- บัญชีใหม่เชื่อมโยงกับ Branch ที่เรียกใช้ให้อัตโนมัติ ใช้งานจาก Branch นี้ได้เลยโดยไม่ต้องเชื่อมโยงเพิ่ม
bankCodeต้องเป็นรหัสที่ถูกต้องจากGET /banksextraVerifyเป็นฟิลด์เสริม ถ้าส่งมาต้องเป็นvalueตัวใดตัวหนึ่งที่ธนาคารปลายทางรองรับ ไม่อย่างนั้นจะได้400 INVALID_EXTRA_VERIFYค่าที่ใช้ได้ต่างกันไปตามธนาคาร ให้เรียกGET /banksแล้วอ่านตัวเลือกextraVerifyของธนาคารนั้น- ส่ง
matchModeได้เฉพาะเมื่อbankCodeเป็นPROMPTPAYถ้าส่งกับธนาคารอื่นจะได้400 INVALID_MATCH_MODE - บัญชีซ้ำหมายถึงบัญชีที่ใช้งานอยู่ซึ่งมี
bankCode+bankNumberเดียวกันภายใน Service ของคุณ