อาลีเพย์ (บาร์โค้ด)

หัวข้อทั้งหมดในหน้านี้

ยกระดับโปรแกรมขายหน้าร้าน (ระบบ POS) ให้สามารถสแกนคิวอาร์โค้ดและเชื่อมต่อเข้ากับระบบของโอมิเซะ เพื่อรองรับการรับชำระเงินผ่านอาลีเพย์ด้วย Barcode wallet API

การเปิดรับชำระเงิน

  • ประเทศที่รองรับ: ประเทศไทย
  • API เวอร์ชันล่าสุดที่รองรับ: 2017-11-02

ร้านค้าที่ต้องการเปิดใช้ระบบ อาลีเพย์ (บาร์โค้ด) กรุณาส่งอีเมลมาที่ support@opn.ooo ทางทีมงานโอมิเซะจะส่งข้อกำหนดและเงื่อนไขการใช้บริการให้ร้านค้าได้พิจารณาและลงลายมือชื่อก่อนเปิดใช้งานจริง

ขั้นตอนการรับชำระเงิน

ภาพประกอบด้านล่างนี้ อธิบายถึงกระบวนการทำงานของระบบสำหรับการรับชำระเงินผ่านอาลีเพย์ โดยแสดงปฏิสัมพันธ์ที่เกิดขึ้นระหว่าง ผู้ซื้อ, ร้านค้า, โอมิเซะ และอาลีเพย์

Flow

ขั้นตอนการชำระเงิน

  1. เมื่อต้องการชำระเงินผู้ซื้อจะเปิดแอปพลิเคชันอาลีเพย์
  2. เลือกที่เมนู ชำระเงิน และระบบจะสร้างบาร์โค้ด เพื่อให้ผู้ซื้อแสดงต่อแคชเชียร์
  3. แคชเชียร์จะทำการสแกนบาร์โค้ด
  4. เซิร์ฟเวอร์ของร้านค้าจะสร้างรายการรับชำระเงิน โดยส่งคำสั่งไปที่ Charge API
  5. ร้านค้าจะได้รับสถานะรายการตอบกลับ แสดงเป็น กำลังดำเนินการ
  6. ในบางกรณี ผู้ซื้ออาจต้องยืนยันการทำรายการในแอปพลิเคชัน
  7. เซิร์ฟเวอร์ของทางร้านค้าจะสามารถรับสถานะรายการล่าสุดของรายการโดยส่งคำสั่งไปยัง Charge API
  8. สถานะรายการแสดงเป็น สำเร็จ หมายถึงรายการรับชำระเงินนั้นสำเร็จแล้ว และยอดชำระถูกส่งเข้าบัญชีโอมิเซะของทางร้านค้า
  9. สถานะรายการแสดงเป็น ไม่สำเร็จ หมายถึงเกิดข้อขัดข้องอย่างใดอย่างหนึ่ง:
    1. รายการเกินเวลาที่กำหนด - หากยังคงต้องการรับชำระเงิน แจ้งผู้ซื้อให้สร้างบาร์โค้ดอีกครั้ง
    2. วงเงินไม่เพียงพอสำหรับทำรายการ - ผู้ซื้อจะต้องเพิ่มวงเงินในบัญชีอาลีเพย์ หรือเลือกชำระเงินผ่านช่องทางอื่นๆ

* ระบบจะมีการส่ง webhook (POST) ไปยังเซิร์ฟเวอร์ของร้านค้าเมื่อมีการอัพเดตสถานะรายการ (สถานะเป็น สำเร็จ หรือ ไม่สำเร็จ)

การเชื่อมต่อระบบ

สามารถสร้างรายการรับชำระเงินอาลีเพย์ (บาร์โค้ด) ด้วยการส่งคำสั่ง API ดังนี้

  1. สร้างรายการรับชำระเงิน พร้อมทั้งระบุ parameter
  2. เมื่อได้รับการแจ้งเตือนรายการสำเร็จผ่าน webhook ให้เรียกดูข้อมูลอีกครั้งเพื่อความแม่นยำ (แนะนำ)

ใช้งาน secret key ในการสร้างรายการอาลีเพย์ (บาร์โค้ด)

สร้างรายการรับชำระเงิน

เมื่อผู้ซื้อเลือกชำระเงินผ่านช่องทางนี้ ให้ร้านค้าสร้างรายการรับชำระเงิน พร้อมทั้งระบุ parameter amount, currency, source[type] (barcode_alipay), source[barcode], source[store_id], source[store_name], and source[terminal_id]

Parameter Type Description
amount integer (required) See Limits
currency string (required) THB
source[barcode] string (required) Alipay barcode number
source[type] string (required) barcode_alipay
source[store_id] string (conditionally required) Store identifier. If store identifier is already configured on your account, this parameter must not be present. Please consult our support team to check if this parameter is required.
source[store_name] string (conditionally required) Store name. If store name is already configured on your account, this parameter must not be present. Please consult our support team to check if this parameter is required.
source[terminal_id] string (optional) Terminal identifier

ตัวอย่างนี้ แสดงวิธีการสร้างรายการด้วย curl แทน $OMISE_SECRET_KEYด้วย test secret key ของร้านค้า สามารถไปคัดลอกจากแดชบอร์ด

curl https://api.omise.co/charges \
  -u $OMISE_SECRET_KEY: \
  -d "amount=400000" \
  -d "currency=THB" \
  -d "source[type]=barcode_alipay" \
  -d "source[barcode]=1234567890" \
  -d "source[store_id]=BJ_ZZ_001" \
  -d "source[store_name]=Some Store" \
  -d "source[terminal_id]=T80001"
{
  "object": "charge",
  "id": "chrg_test_5y81yhipv3vrds1vt8z",
  "location": "/charges/chrg_test_5y81yhipv3vrds1vt8z",
  "amount": 400000,
  "acquirer_reference_number": null,
  "net": 392938,
  "fee": 6600,
  "fee_vat": 462,
  "interest": 0,
  "interest_vat": 0,
  "funding_amount": 400000,
  "refunded_amount": 0,
  "transaction_fees": {
    "fee_flat": "0.0",
    "fee_rate": "1.65",
    "vat_rate": "7.0"
  },
  "platform_fee": {
    "fixed": null,
    "amount": null,
    "percentage": null
  },
  "currency": "THB",
  "funding_currency": "THB",
  "ip": null,
  "refunds": {
    "object": "list",
    "data": [],
    "limit": 20,
    "offset": 0,
    "total": 0,
    "location": "/charges/chrg_test_5y81yhipv3vrds1vt8z/refunds",
    "order": "chronological",
    "from": "1970-01-01T00:00:00Z",
    "to": "2023-12-26T06:16:17Z"
  },
  "link": null,
  "description": null,
  "metadata": {},
  "card": null,
  "source": {
    "object": "source",
    "id": "src_test_5y81yhi0yjx5ksqlt4e",
    "livemode": false,
    "location": "/sources/src_test_5y81yhi0yjx5ksqlt4e",
    "amount": 400000,
    "barcode": "1234567890",
    "bank": null,
    "created_at": "2023-12-26T06:16:16Z",
    "currency": "THB",
    "email": null,
    "flow": "offline",
    "installment_term": null,
    "ip": null,
    "absorption_type": null,
    "name": null,
    "mobile_number": null,
    "phone_number": null,
    "platform_type": null,
    "scannable_code": null,
    "billing": null,
    "shipping": null,
    "items": [],
    "references": {
      "expires_at": "2023-12-27T06:16:16Z",
      "device_id": null,
      "customer_amount": null,
      "customer_currency": null,
      "customer_exchange_rate": null,
      "omise_tax_id": null,
      "reference_number_1": null,
      "reference_number_2": null,
      "barcode": null,
      "payment_code": null,
      "va_code": null
    },
    "provider_references": null,
    "store_id": "BJ_ZZ_001",
    "store_name": "Some Store",
    "terminal_id": "T80001",
    "type": "barcode_alipay",
    "zero_interest_installments": null,
    "charge_status": "pending",
    "receipt_amount": null,
    "discounts": []
  },
  "schedule": null,
  "customer": null,
  "dispute": null,
  "transaction": null,
  "failure_code": null,
  "failure_message": null,
  "status": "pending",
  "authorize_uri": null,
  "return_uri": null,
  "created_at": "2023-12-26T06:16:16Z",
  "paid_at": null,
  "expires_at": "2023-12-27T06:16:16Z",
  "expired_at": null,
  "reversed_at": null,
  "zero_interest_installments": false,
  "branch": null,
  "terminal": null,
  "device": null,
  "authorized": false,
  "capturable": false,
  "capture": true,
  "disputable": false,
  "livemode": false,
  "refundable": false,
  "partially_refundable": false,
  "reversed": false,
  "reversible": false,
  "voided": false,
  "paid": false,
  "expired": false
}

Setting the charge to expire

Alipay In-Store charges that have not yet been authorized (status=pending) can be set to expire.

curl https://api.omise.co/charges/$CHARGE_ID/expire \
  -X POST \
  -u $OMISE_SECRET_KEY:

สร้างรายการสำเร็จ

เมื่อร้านค้าสร้างรายการรับชำระเงินขึ้นมาแล้ว จะพบว่าสถานะของรายการแสดงเป็น pending หรือ status==pending โดยสถานะของรายการรับชำระเงินสามารถเป็นได้ทั้ง successful, failed และ expired

ในส่วนต่อไปเราจะอธิบายวิธีอนุมัติรายการ, การรับ event แจ้งเตือนเมื่อรายการเสร็จสิ้นผ่าน webhook และการตรวจสอบสถานะรายการ

ภาพด้านล่างนี้แสดงให้เห็นถึงขั้นตอนทั้งหมดในการรับชำระเงินแต่ละรายการ

sequenceDiagram participant customer participant merchant participant api.omise.co participant payment provider customer->>merchant: Present payment code for scanning merchant->>api.omise.co: Create charge using payment code api.omise.co-->>merchant: Return charge api.omise.co-xmerchant: Send "charge.create" webhook customer->>payment provider: Provide charge authorization payment provider-->>customer: Return payment result payment provider-->>api.omise.co: Return payment result api.omise.co-xmerchant: Send "charge.complete" webhook

การอนุมัติรายการ

ในบางกรณี ผู้ซื้ออาจต้องเข้าแอปอาลีเพย์เพื่อยืนยันรายการชำระเงินด้วยตนเอง

การรับ event แจ้งเตือนรายการสำเร็จ

ร้านค้าสามารถรับการแจ้งเตือนเมื่อมีการทำรายการเสร็จสิ้นโดยใช้งาน webhook events

ในการติดตั้งให้ร้านค้ากำหนดตำแหน่งบนเซิร์ฟเวอร์เพื่อรับ webhook events และเพิ่มตำแหน่งเดียวกันนี้เป็น webhook endpoint บนแดชบอร์ด

เมื่อมีรายการเสร็จสิ้น ระบบจะส่ง POST request ไปยัง endpoint นี้ พร้อมทั้งแนบสถานะการตอบกลับของรายการนั้นๆ ไปด้วย

ตัวแปรหลักหรือ key สำหรับ event object ประกอบไปด้วย charge.complete และตัวแปร data ที่มี charge object

อ่านเพิ่มเติมได้ที่ Events API

การตรวจสอบสถานะรายการ

เมื่อได้รับ event ของรายการที่เสร็จสิ้นแล้ว ร้านค้าสามารถตรวจสอบสถานะรายการหรือ status โดยใช้ Charge API

หากค่าของ charge.status เป็น successful หมายถึงว่ารายการรับชำระเงินสำเร็จ หากค่าของ charge.status เป็น failed รายการรับชำระเงินนั้นไม่สำเร็จ ร้านค้าสามารถตรวจสอบ failure_code และ failure_message ได้ใน charge object เพื่ออ่านคำอธิบายเพิ่มเติม

สาเหตุขัดข้องที่อาจเกิดขึ้นได้มีดังนี้

รหัสข้อขัดข้อง รายละเอียด
payment_cancelled ผู้ซื้อยกเลิกการชำระเงิน
failed_processing ระบบทำรายการไม่สำเร็จ
insufficient_balance วงเงินคงเหลือไม่เพียงพอหรือวงเงินเต็ม
payment_rejected รายการถูกปฏิเสธโดยธนาคารผู้ออกบัตร
payment_expired รายการชำระเงินหมดอายุ

การคืนเงิน

การคืนเงินสามารถทำได้ภายใน 12 เดือนนับจากวันทำรายการ โดยสามารถเลือกคืนเงินเต็มจำนวน หรือคืนเพียงบางส่วน

curl https://api.omise.co/charges/$REFUNDABLE_CHARGE_ID/refunds \
  -u $OMISE_SECRET_KEY: \
  -d "amount=400000"
{
  "object": "refund",
  "id": "rfnd_test_5y81yhye1onvah12wea",
  "location": "/charges/chrg_test_5y81yhbt1jtfc1vg4of/refunds/rfnd_test_5y81yhye1onvah12wea",
  "livemode": false,
  "voided": true,
  "currency": "THB",
  "amount": 400000,
  "metadata": {},
  "charge": "chrg_test_5y81yhbt1jtfc1vg4of",
  "terminal": null,
  "transaction": "trxn_test_5y81yhynmt9r3u4zrak",
  "status": "closed",
  "funding_amount": 400000,
  "funding_currency": "THB",
  "created_at": "2023-12-26T06:16:18Z",
  "acquirer_reference_number": null
}

ข้อจำกัด

  • จำนวนรับชำระขั้นต่ำ: 2000 (THB20.00)
  • จำนวนรับชำระสูงสุด: 15000000 (THB150,000.00)

ขั้นตอนต่อไป

เว็ปไซต์นี้มีการใช้คุกกี้เพื่อวิเคราะห์การใช้และปรับการใช้งานให้เหมาะกับท่าน เมื่อกดยอมรับหรือยังคงเข้าชมเว็บไซต์ต่อ เราถือว่าท่านยินยอมในการใช้งานคุกกี้ของเว็บไซต์ อ่านนโยบายความเป็นส่วนตัว