San pham
Quan ly danh muc san pham voi thong tin gia ban va gia mua.
Tham chieu nhanh
| Endpoint | Method | Mo ta |
|---|---|---|
/api/v1/products | POST | Tao san pham moi |
/api/v1/products | GET | Lay danh sach tat ca san pham |
/api/v1/products/:id | GET | Lay thong tin san pham cu the |
/api/v1/products/:id | PUT | Cap nhat san pham |
/api/v1/products/:id | DELETE | Xoa san pham |
Cac endpoint API
Tao san pham
Tao san pham moi voi thong tin gia ban va gia mua.
POST /api/v1/products
- cURL
- Go
curl -X POST 'https://api.finan.one/open/api/v1/products' \
-H 'Content-Type: application/json' \
-H 'x-client-id: YOUR_CLIENT_ID' \
-H 'x-signature: YOUR_SIGNATURE' \
-H 'x-timestamp: 1699999999' \
-d '{
"general_info": {
"item_name": "Example Product",
"sku_code": "SKU12345",
"unit": "pcs",
"description": "This is a sample product."
},
"sale_info": {
"sale_price": 100000,
"sale_category_code": "C1001",
"sale_tax_code": "TAX_CODE_10"
},
"purchase_info": {
"purchase_price": 80000,
"purchase_category_code": "D1001",
"purchase_tax_code": "TAX_CODE_8"
}
}'
package main
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"time"
)
type GeneralInfo struct {
ItemName string `json:"item_name"`
SKUCode string `json:"sku_code"`
Unit string `json:"unit,omitempty"`
Description string `json:"description,omitempty"`
}
type SaleInfo struct {
SalePrice int64 `json:"sale_price"`
SaleCategoryCode string `json:"sale_category_code"`
SaleTaxCode string `json:"sale_tax_code,omitempty"`
}
type PurchaseInfo struct {
PurchasePrice int64 `json:"purchase_price"`
PurchaseCategoryCode string `json:"purchase_category_code"`
PurchaseTaxCode string `json:"purchase_tax_code,omitempty"`
}
type CreateProductRequest struct {
GeneralInfo GeneralInfo `json:"general_info"`
SaleInfo SaleInfo `json:"sale_info"`
PurchaseInfo PurchaseInfo `json:"purchase_info"`
}
func generateSignature(secretKey, method, path, payload, timestamp string) string {
message := secretKey + "_" + method + "_" + path + "_" + payload + "_" + timestamp
hash := sha256.Sum256([]byte(message))
return hex.EncodeToString(hash[:])
}
func main() {
clientID := "YOUR_CLIENT_ID"
secretKey := "YOUR_SECRET_KEY"
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
reqBody := CreateProductRequest{
GeneralInfo: GeneralInfo{
ItemName: "Example Product",
SKUCode: "SKU12345",
Unit: "pcs",
Description: "This is a sample product.",
},
SaleInfo: SaleInfo{
SalePrice: 100000,
SaleCategoryCode: "C1001",
SaleTaxCode: "TAX_CODE_10",
},
PurchaseInfo: PurchaseInfo{
PurchasePrice: 80000,
PurchaseCategoryCode: "D1001",
PurchaseTaxCode: "TAX_CODE_8",
},
}
jsonBody, _ := json.Marshal(reqBody)
signature := generateSignature(secretKey, "POST", "/api/v1/products", string(jsonBody), timestamp)
req, _ := http.NewRequest("POST", "https://api.finan.one/open/api/v1/products", bytes.NewBuffer(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-client-id", clientID)
req.Header.Set("x-signature", signature)
req.Header.Set("x-timestamp", timestamp)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
Noi dung request
general_info (bat buoc)
| Truong | Kieu | Bat buoc | Mo ta |
|---|---|---|---|
item_name | string | ✅ | Ten san pham |
sku_code | string | ✅ | Ma SKU duy nhat |
unit | string | Don vi tinh (vi du: pcs, kg) | |
description | string | Mo ta san pham |
sale_info (bat buoc)
| Truong | Kieu | Bat buoc | Mo ta |
|---|---|---|---|
sale_price | integer | ✅ | Gia ban truoc thue (don vi tien te nho nhat) |
sale_category_code | string | ✅ | Ma danh muc thu nhap. Xem Tai lieu tham chieu ma |
sale_tax_code | string | Ma thue (vi du: TAX_CODE_10). Xem Tai lieu tham chieu ma |
purchase_info (bat buoc)
| Truong | Kieu | Bat buoc | Mo ta |
|---|---|---|---|
purchase_price | integer | ✅ | Gia mua truoc thue |
purchase_category_code | string | ✅ | Ma danh muc chi phi. Xem Tai lieu tham chieu ma |
purchase_tax_code | string | Ma thue. Xem Tai lieu tham chieu ma |
Phan hoi
- ✅ Success (200)
- ❌ Error
{
"message": { "content": "Thực thi API thành công" },
"code": 102001,
"request_id": "abc123...",
"data": {
"product_id": "PROD-550e8400-e29b-41d4-a716-446655440000",
"general_info": {
"item_name": "Example Product",
"sku_code": "SKU12345",
"unit": "pcs",
"description": "This is a sample product."
},
"sale_info": {
"sale_price": 100000,
"sale_category_code": "C1001",
"sale_tax_code": "TAX_CODE_10"
},
"purchase_info": {
"purchase_price": 80000,
"purchase_category_code": "D1001",
"purchase_tax_code": "TAX_CODE_8"
},
"created_at": "2024-01-20T14:00:00Z"
}
}
| Code | Message | Mo ta |
|---|---|---|
| 400 | Bad Request | Noi dung request khong hop le |
| 401 | Unauthorized | Xac thuc khong hop le |
| 409 | Conflict | Ma SKU da ton tai |
| 422 | Unprocessable Entity | Xac thuc du lieu that bai |
{
"message": {
"content": "Yêu cầu không hợp lệ",
"error": "SKU code SKU12345 already exists"
},
"code": 104000,
"request_id": "abc123..."
}
Lay danh sach san pham
Truy xuat tat ca san pham.
GET /api/v1/products
- cURL
- Go
curl -X GET 'https://api.finan.one/open/api/v1/products' \
-H 'Content-Type: application/json' \
-H 'x-client-id: YOUR_CLIENT_ID' \
-H 'x-signature: YOUR_SIGNATURE' \
-H 'x-timestamp: 1699999999'
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/http"
"strconv"
"time"
)
func generateSignature(secretKey, method, path, payload, timestamp string) string {
message := secretKey + "_" + method + "_" + path + "_" + payload + "_" + timestamp
hash := sha256.Sum256([]byte(message))
return hex.EncodeToString(hash[:])
}
func main() {
clientID := "YOUR_CLIENT_ID"
secretKey := "YOUR_SECRET_KEY"
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
signature := generateSignature(secretKey, "GET", "/api/v1/products", "", timestamp)
req, _ := http.NewRequest("GET", "https://api.finan.one/open/api/v1/products", nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-client-id", clientID)
req.Header.Set("x-signature", signature)
req.Header.Set("x-timestamp", timestamp)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
Phan hoi
- ✅ Success (200)
- ❌ Error
{
"message": { "content": "Thực thi API thành công" },
"code": 102000,
"request_id": "abc123...",
"data": [
{
"product_id": "PROD-550e8400-e29b-41d4-a716-446655440000",
"general_info": {
"item_name": "Example Product",
"sku_code": "SKU12345",
"unit": "pcs"
},
"sale_info": {
"sale_price": 100000
},
"purchase_info": {
"purchase_price": 80000
},
"created_at": "2024-01-20T14:00:00Z"
}
]
}
| Code | Message | Mo ta |
|---|---|---|
| 401 | Unauthorized | Xac thuc khong hop le |
Lay mot san pham
GET /api/v1/products/:product_id
Cap nhat san pham
Thay the du lieu cua san pham hien tai. Day la thao tac thay the toan bo -- tat ca cac phan (general_info, sale_info, purchase_info) va cac truong bat buoc cua chung phai duoc bao gom.
PUT /api/v1/products/:product_id
Thay the toan bo
Tat ca cac truong bao gom sale_tax_code va purchase_tax_code deu bat buoc khi cap nhat. Cac truong bi bo qua se bi xoa.
- cURL
- Go
curl -X PUT 'https://api.finan.one/open/api/v1/products/PRODUCT_ID' \
-H 'Content-Type: application/json' \
-H 'x-client-id: YOUR_CLIENT_ID' \
-H 'x-signature: YOUR_SIGNATURE' \
-H 'x-timestamp: 1699999999' \
-d '{
"general_info": {
"item_name": "Updated Product Name",
"sku_code": "SKU67890",
"unit": "kg",
"description": "Updated description for the product."
},
"sale_info": {
"sale_price": 120000,
"sale_category_code": "C1001",
"sale_tax_code": "TAX_CODE_10"
},
"purchase_info": {
"purchase_price": 100000,
"purchase_category_code": "D1001",
"purchase_tax_code": "TAX_CODE_10"
}
}'
package main
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"time"
)
func generateSignature(secretKey, method, path, payload, timestamp string) string {
message := secretKey + "_" + method + "_" + path + "_" + payload + "_" + timestamp
hash := sha256.Sum256([]byte(message))
return hex.EncodeToString(hash[:])
}
func main() {
clientID := "YOUR_CLIENT_ID"
secretKey := "YOUR_SECRET_KEY"
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
productID := "YOUR_PRODUCT_ID"
reqBody := CreateProductRequest{
GeneralInfo: GeneralInfo{
ItemName: "Updated Product Name",
SKUCode: "SKU67890",
Unit: "kg",
Description: "Updated description for the product.",
},
SaleInfo: SaleInfo{
SalePrice: 120000,
SaleCategoryCode: "C1001",
SaleTaxCode: "TAX_CODE_10",
},
PurchaseInfo: PurchaseInfo{
PurchasePrice: 100000,
PurchaseCategoryCode: "D1001",
PurchaseTaxCode: "TAX_CODE_10",
},
}
jsonBody, _ := json.Marshal(reqBody)
path := "/api/v1/products/" + productID
signature := generateSignature(secretKey, "PUT", path, string(jsonBody), timestamp)
url := "https://api.finan.one/open" + path
req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-client-id", clientID)
req.Header.Set("x-signature", signature)
req.Header.Set("x-timestamp", timestamp)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
Phan hoi
- ✅ Success (200)
- ❌ Error
{
"message": { "content": "Thực thi API thành công" },
"code": 102001,
"request_id": "abc123...",
"data": {
"product_id": "e5f85e53-d5db-4e4a-8383-61b4cc67398a",
"general_info": {
"item_name": "Updated Product Name",
"sku_code": "SKU67890",
"unit": "kg",
"description": "Updated description for the product."
},
"sale_info": {
"sale_price": 120000,
"sale_category_code": "C1001",
"sale_tax_code": "TAX_CODE_10"
},
"purchase_info": {
"purchase_price": 100000,
"purchase_category_code": "D1001",
"purchase_tax_code": "TAX_CODE_10"
}
}
}
| Code | Message | Mo ta |
|---|---|---|
| 400 | Bad Request | Thieu cac truong bat buoc |
| 401 | Unauthorized | Xac thuc khong hop le |
| 404 | Not Found | Khong tim thay san pham |
Xoa san pham
Xoa san pham khoi danh muc.
DELETE /api/v1/products/:product_id
- cURL
- Go
curl -X DELETE 'https://api.finan.one/open/api/v1/products/PROD-550e8400-e29b-41d4-a716-446655440000' \
-H 'Content-Type: application/json' \
-H 'x-client-id: YOUR_CLIENT_ID' \
-H 'x-signature: YOUR_SIGNATURE' \
-H 'x-timestamp: 1699999999'
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/http"
"strconv"
"time"
)
func generateSignature(secretKey, method, path, payload, timestamp string) string {
message := secretKey + "_" + method + "_" + path + "_" + payload + "_" + timestamp
hash := sha256.Sum256([]byte(message))
return hex.EncodeToString(hash[:])
}
func main() {
clientID := "YOUR_CLIENT_ID"
secretKey := "YOUR_SECRET_KEY"
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
productID := "PROD-550e8400-e29b-41d4-a716-446655440000"
path := "/api/v1/products/" + productID
signature := generateSignature(secretKey, "DELETE", path, "", timestamp)
url := "https://api.finan.one/open/api/v1/products/" + productID
req, _ := http.NewRequest("DELETE", url, nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-client-id", clientID)
req.Header.Set("x-signature", signature)
req.Header.Set("x-timestamp", timestamp)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
Phan hoi
- ✅ Success (200)
- ❌ Error
{
"message": { "content": "Thực thi API thành công" },
"code": 102001,
"request_id": "abc123...",
"data": "success"
}
| Code | Message | Mo ta |
|---|---|---|
| 401 | Unauthorized | Xac thuc khong hop le |
| 404 | Not Found | Khong tim thay san pham |
Buoc tiep theo
- Hoa don - Tao hoa don voi san pham
- Khach hang - Quan ly khach hang
- Tai lieu tham chieu ma - Ma danh muc va ma thue