Skip to content

ตรวจสอบสลิปด้วยรูปภาพ

ตรวจสอบสลิปธนาคารด้วยการอัปโหลดไฟล์รูปภาพ

Endpoint

http
POST /verify

URL เต็ม: https://developer.easyslip.com/api/v1/verify

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

จำเป็น ดูคู่มือการยืนยันตัวตน

http
Authorization: Bearer YOUR_API_KEY
Content-Type: multipart/form-data

Request

พารามิเตอร์

พารามิเตอร์ประเภทจำเป็นคำอธิบาย
fileFileใช่ไฟล์รูปสลิป
checkDuplicatebooleanไม่ตรวจสอบสลิปซ้ำ

ข้อกำหนดรูปภาพ

ข้อกำหนดค่า
ขนาดสูงสุด4 MB
รูปแบบที่รองรับJPEG, PNG, GIF, WebP
QR Codeต้องมองเห็นได้ชัดเจน

Type Definitions

typescript
// Request (multipart/form-data)
interface VerifyByImageRequest {
  file: File;
  checkDuplicate?: boolean;
}

// Response
interface VerifyResponse {
  status: 200;
  data: SlipData;
}

interface SlipData {
  payload: string;
  transRef: string;
  date: string;                  // ISO 8601
  countryCode: string;
  amount: Amount;
  fee: number;
  ref1: string;
  ref2: string;
  ref3: string;
  sender: Party;
  receiver: Party;
}

interface Amount {
  amount: number;
  local: {
    amount: number;
    currency: string;
  };
}

interface Party {
  bank: {
    id: string;
    name: string;
    short: string;
  };
  account: {
    name: {
      th?: string;
      en?: string;
    };
    bank?: {
      type: 'BANKAC' | 'TOKEN' | 'DUMMY';
      account: string;
    };
    proxy?: {
      type: 'NATID' | 'MSISDN' | 'EWALLETID' | 'EMAIL' | 'BILLERID';
      account: string;
    };
  };
}

// Error Response
interface ErrorResponse {
  status: number;
  message: string;
  data?: SlipData;              // สำหรับกรณีสลิปซ้ำ
}

ตัวอย่าง

bash
curl -X POST https://developer.easyslip.com/api/v1/verify \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@/path/to/slip.jpg" \
  -F "checkDuplicate=true"
javascript
const verifyByImage = async (file, options = {}) => {
  const formData = new FormData();
  formData.append('file', file);

  if (options.checkDuplicate) {
    formData.append('checkDuplicate', 'true');
  }

  const response = await fetch('https://developer.easyslip.com/api/v1/verify', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    },
    body: formData
  });

  const result = await response.json();

  if (result.status !== 200) {
    throw new Error(result.message);
  }

  return result.data;
};

// การใช้งานกับ file input
const fileInput = document.getElementById('slipImage');
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files[0];

  try {
    const slip = await verifyByImage(file, { checkDuplicate: true });
    console.log('จำนวนเงิน:', slip.amount.amount);
  } catch (error) {
    console.error('Error:', error.message);
  }
});
php
function verifyByImage(string $filePath, bool $checkDuplicate = false): array
{
    $apiKey = getenv('EASYSLIP_API_KEY');

    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => 'https://developer.easyslip.com/api/v1/verify',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . $apiKey
        ],
        CURLOPT_POSTFIELDS => [
            'file' => new CURLFile($filePath),
            'checkDuplicate' => $checkDuplicate ? 'true' : 'false'
        ]
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    $result = json_decode($response, true);

    if ($result['status'] !== 200) {
        throw new Exception($result['message']);
    }

    return $result['data'];
}

// การใช้งาน
$slip = verifyByImage('/path/to/slip.jpg', true);
echo "จำนวนเงิน: " . $slip['amount']['amount'];
python
import requests
import os

def verify_by_image(file_path: str, check_duplicate: bool = False) -> dict:
    with open(file_path, 'rb') as f:
        files = {'file': f}
        data = {'checkDuplicate': 'true' if check_duplicate else 'false'}

        response = requests.post(
            'https://developer.easyslip.com/api/v1/verify',
            headers={
                'Authorization': f'Bearer {os.environ["EASYSLIP_API_KEY"]}'
            },
            files=files,
            data=data
        )

    result = response.json()

    if result['status'] != 200:
        raise Exception(result['message'])

    return result['data']

# การใช้งาน
slip = verify_by_image('./slip.jpg', check_duplicate=True)
print(f"จำนวนเงิน: {slip['amount']['amount']}")

Response

สำเร็จ (200)

json
{
  "status": 200,
  "data": {
    "payload": "00000000000000000000000000000000000000000000000",
    "transRef": "68370160657749I376388B35",
    "date": "2024-01-15T14:30:00+07:00",
    "amount": {
      "amount": 1500.00
    },
    "sender": {
      "bank": { "id": "004", "name": "กสิกรไทย", "short": "KBANK" },
      "account": { "name": { "th": "นาย ผู้โอน ทดสอบ" } }
    },
    "receiver": {
      "bank": { "id": "014", "name": "ไทยพาณิชย์", "short": "SCB" },
      "account": { "name": { "th": "นาย รับเงิน ทดสอบ" } }
    }
  }
}

Error Responses

รูปภาพไม่ถูกต้อง (400)

json
{
  "status": 400,
  "message": "invalid_image"
}

รูปภาพใหญ่เกินไป (400)

json
{
  "status": 400,
  "message": "image_size_too_large"
}

ไม่พบ QR Code (404)

json
{
  "status": 404,
  "message": "qrcode_not_found"
}

หมายเหตุ

  • QR Code ต้องมองเห็นได้ชัดเจนและไม่เบลอ
  • ครอปรูปให้เห็น QR Code ชัดๆ เพื่อประมวลผลเร็วขึ้น
  • บีบอัดรูปขนาดใหญ่ก่อนอัปโหลด
  • API จัดการการหมุนรูปอัตโนมัติ

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

Bank Slip Verification API for Thai Banking