KBank User Management
This guide explains how to create and manage KBank users through the Villa Payment API.
API Base URLs
The Villa Payment API is available in two environments:
- Development:
https://shop.villamarket.com/api/payment3devapi - Production:
https://shop.villamarket.com/api/payment3api
Replace {BASE_URL} in the examples below with the appropriate base URL for your environment.
Creating a User
To create a new KBank user:
curl -X POST {BASE_URL}/kbank/user \
-H "Authorization: YOUR_COGNITO_ID_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"phone": "+66812345678",
"first_name": "John",
"last_name": "Doe"
}'
Request Parameters
| Parameter | Type | Description |
|---|---|---|
| string | User's email address | |
| phone | string | User's phone number |
| first_name | string | User's first name |
| last_name | string | User's last name |
Response
{
"message": "User created successfully",
"user_id": "usr_1234567890"
}
Error Handling
The API uses standard HTTP status codes to indicate success or failure:
- 200: Success
- 400: Bad Request (missing required fields)
- 401: Unauthorized
- 403: Forbidden
- 500: Internal Server Error
Example error response:
{
"error": {
"code": "missing_field",
"message": "Missing required field: email"
}
}
Best Practices
- Validate user data before submission
- Handle API errors gracefully
- Implement proper error logging
- Use idempotency keys for retries
- Keep user data secure and encrypted
- Follow data protection regulations
- Implement rate limiting for user creation
Testing
For testing user management:
- Use test email addresses
- Verify phone number format
- Test address validation
- Check error responses
- Validate update operations