สร้างลูกค้า
สร้างโปรไฟล์ลูกค้าเพื่อบันทึกวิธีการชำระเงินสำหรับการเรียกเก็บเงินซ้ำ ลูกค้าสามารถมีบัตรที่บันทึกไว้หลายใบและทำการซื้อในอนาคตได้โดยไม่ต้องกรอกรายละเอียดบัตรอีกครั้ง
ข้อมูลยืนยันตัวตน API
พารามิเตอร์คำขอ
แนะนำ - 2 ฟิลด์พารามิเตอร์แนะนำ
`email`STRING(optional)
ที่อยู่อีเมลของลูกค้า ใช้สำหรับใบเสร็จ การแจ้งเตือนการคืนเงิน และการสนับสนุน
`description`STRING(optional)
ชื่อหรือคำอธิบายของลูกค้า ช่วยในการระบุลูกค้าในแดชบอร์ดและรายงานของคุณ
เพิ่มเติม - 2 ฟิลด์พารามิเตอร์เพิ่มเติม
การตอบกลับ
200
สร้างลูกค้าสำเร็จโปรไฟล์ลูกค้าถูกสร้างแล้ว ควรบันทึก customer ID ไว้ในฐานข้อมูลของคุณสำหรับการเรียกเก็บเงินในอนาคต
ฟิลด์ของออบเจ็กต์ Customer:
id- Customer ID (cust_*) บันทึกสิ่งนี้ไว้ในฐานข้อมูลของคุณemail- ที่อยู่อีเมลของลูกค้าdescription- คำอธิบาย/ชื่อของลูกค้าdefault_card- ID ของบัตรชำระเงินเริ่มต้น (หากมีการระบุบัตร)cards- ออบเจ็กต์รายการที่มีบัตรที่บันทึกไว้ทั้งหมดmetadata- ข้อมูลคีย์-ค่าที่กำหนดเอง
400
คำขอไม่ถูกต้องการตรวจสอบคำขอล้มเหลว ตรวจสอบข้อความแสดงข้อผิดพลาดเพื่อดูรายละเอียด
สาเหตุทั่วไป:
- ร ูปแบบอีเมลไม่ถูกต้อง
- token ID ไม่ถูกต้อง
- metadata เกิน 15,000 ตัวอักษร
401
ไม่ได้รับอนุญาตการยืนยันตัวตนล้มเหลว API key ไม่ถูกต้องหรือขาดหายไป
สาเหตุทั่วไป:
- ขาดหัวข้อ Authorization
- secret key ไม่ถูกต้อง
- ใช้ public key แทน secret key
- รูปแบบ HTTP Basic Auth ไม่ถูกต้อง
404
ไม่พบไม่พบ token หรือไม่ถูกต้อง
สาเหตุทั่วไป:
- token ID ไม่มีอยู่
- token ถูกใช้ไปแล้ว
- token หมดอายุแล้ว
ตัวอย่างโค้ด
- cURL
- Ruby
- Python
- Node.js
- PHP
- Java
- C#
- Go
curl https://api.omise.co/customers \
-u skey_test_5xuy4w91xqz7d1w9u0t: \
-d "email=john@example.com" \
-d "description=John Doe" \
-d "card=tokn_test_5xuy4w91xqz7d1w9u0t"
require 'omise'
Omise.api_key = 'skey_test_5xuy4w91xqz7d1w9u0t'
customer = Omise::Customer.create({
email: 'john@example.com',
description: 'John Doe',
card: 'tokn_test_5xuy4w91xqz7d1w9u0t'
})
import omise
omise.api_secret = 'skey_test_5xuy4w91xqz7d1w9u0t'
customer = omise.Customer.create(
email='john@example.com',
description='John Doe',
card='tokn_test_5xuy4w91xqz7d1w9u0t'
)
const omise = require('omise')({
secretKey: 'skey_test_5xuy4w91xqz7d1w9u0t'
});
const customer = await omise.customers.create({
email: 'john@example.com',
description: 'John Doe',
card: 'tokn_test_5xuy4w91xqz7d1w9u0t'
});
<?php
define('OMISE_SECRET_KEY', 'skey_test_5xuy4w91xqz7d1w9u0t');
$customer = OmiseCustomer::create([
'email' => 'john@example.com',
'description' => 'John Doe',
'card' => 'tokn_test_5xuy4w91xqz7d1w9u0t'
]);
Client client = new Client.Builder()
.secretKey("skey_test_5xuy4w91xqz7d1w9u0t")
.build();
Customer customer = client.customers().create()
.email("john@example.com")
.description("John Doe")
.card("tokn_test_5xuy4w91xqz7d1w9u0t")
.send();
var client = new Client("skey_test_5xuy4w91xqz7d1w9u0t");
var customer = await client.Customers.Create(new CreateCustomerRequest
{
Email = "john@example.com",
Description = "John Doe",
Card = "tokn_test_5xuy4w91xqz7d1w9u0t"
});
client, _ := omise.NewClient(
"pkey_test_5xuy4w91xqz7d1w9u0t",
"skey_test_5xuy4w91xqz7d1w9u0t",
)
customer, _ := client.Customers().Create(&operations.CreateCustomer{
Email: "john@example.com",
Description: "John Doe",
Card: "tokn_test_5xuy4w91xqz7d1w9u0t",
})
รหัสข้อผิดพลาดและผลลัพธ์
รหัสข้อผิดพลาดทั่วไป
| Code | Description | Resolution |
|---|---|---|
bad_request | พารามิเตอร์ขาดหายหรือไม่ถูกต้อง | ตรวจสอบรูปแบบอีเมลและขนาด metadata |
authentication_failure | API key ไม่ถูกต้อง | ตรวจสอบว่า secret key ของคุณถูกต้อง |
used_token | token ถูกใช้ไปแล้ว | สร้าง token ใหม่ |
token_not_found | token ID ไม่มีอยู่ | ตรวจสอบว่า token ID ถูกต้อง |
invalid_card | token ของบัตรไม่ถูกต้อง | ตรวจสอบว่า token ถูกสร้างสำเร็จ |
ฟิลด์ของ Customer
| Field | Description |
|---|---|
id | Customer ID (บันทึกสิ่งนี้ไว้ในฐานข้อมูลของคุณ) |
email | ที่อยู่อีเมลของลูกค้า |
description | ชื่อหรือคำอธิบายของลูกค้า |
default_card | ID ของบัตรชำระเงินเริ่มต้น |
cards | รายการของบัตรที่บันทึกไว้ทั้งหมด |
metadata | ข้อมูลคีย์-ค่าที่กำหนดเอง |
created_at | เวลาที่สร้างลูกค้า |
ลองใช้งาน
แนะนำ - 2 ฟิลด์
เพิ่มเติม - 2 ฟิลด์