# Ginsberg+Chan
###### tags: `GAC` `API` `Laravel`
> [TOC]
## Data Structure
#### Categorization
```javascript=
{Category}: halo-products, champagne, fine-wines, mature-vintage-wines
{Product Name}: eg Chateau La Mission Haut Brion Imperial 2000
```
#### Product Properties
```javascript=
{Quantity}: 1-pcs, 3-pcs, 6-pcs, 12-pcs
```
#### Product
```javascript=
{product_name - year}: eg Chateau La Mission Haut Brion Imperial 2000
-attach taxonomy: {category}, {product_name}
-attach properties: {quantity}
```
- Each product has its own images
## Auth
#### ==Get Token== ####
:::info
Get api token for auth
:::
###### Request
```javascript
{
"open_id": "obY6_v02z-wEoRS_3MlFkSEnutuA"
}
```
###### Response
```javascript
{
"token": "orXrKCUWUpqRGO2o5jjez9gVOJt9S2SKhfZMnhKSTZf7n4y5PPw7ZTTu6fEN"
}
```
#### ==All api need auth== ####
:::info
**request**
Add api_token in all request
:::
###### Request
```javascript
{
"api_token": "orXrKCUWUpqRGO2o5jjez9gVOJt9S2SKhfZMnhKSTZf7n4y5PPw7ZTTu6fEN"
}
```
## Product
#### ==Product List== ####
`GET /products?category={cat}`
:::info
cat: halo-products, champagne, fine-wines, mature-vintage-wines
**params**
{cat}: category filter
**response**
count: total number of record
image: first image of the first product,
type: red, white, sparkling, sweet
:::
###### Get all products
###### Response
```javascript
{
"count": 24,
"products": [
{
"id": 1,
"cat": "halo-products",
"title": "Chateau La Mission Haut Brion 1949",
"image": "url",
"type": "red",
"original": 38000
"price": 37000
},
...
]
}
```
#### ==Product== ####
`GET /products/{id}`
:::info
**params**
{id}: product id
**response**
image: concat all image of product of that color
color: red, white, sparkling, sweet
:::
###### Get specific product
###### Response
```javascript
{
"id": 1,
"cat": "halo-products",
"title": "Chateau La Mission Haut Brion 1949",
"sku": "A1909053",
"type": "red",
"region": "Italy",
"size": 750,
"rating": "WA100"
"desc": `<p class='package'>Sold as loose bottle, the price is per bottle</p>
<ul><li>Region: Bordeaux</li><li>Item: A1801228</li><li>Vintage: 1982</li><li>Color: Red</li><li>Size: 750ml</li><li>Rating: WA97+</li></ul>`,
"item": [
{
"attr": {
"key": "3",
"value": "3-pcs"
}
"images": ["url", "url"],
"id": 1,
"original": 38000
"price": 37000,
"stock": 6
}
]
}
```
## User
#### ==User Info== ####
`GET /user`
:::info
:::
###### Get user info
###### Response
```javascript
{
"id": 1,
"name": "Nicholas Barker",
"email": "abc@gmail.com",
"tel": "+852 1234 5678"
}
```
#### ==Update User Info== ####
`POST /user`
:::info
**request**
send up whole user obejct with all fields. would replace the whole object
:::
###### Edit user info
###### Request
```javascript
{
"name": "Nicholas Barker",
"email": "abc@gmail.com",
"tel": "+852 1234 5678"
}
```
###### Response
```javascript
{
"id": 1,
"name": "Nicholas Barker",
"email": "abc@gmail.com",
"tel": "+852 1234 5678"
}
```
## Cart
#### ==Update cart== ####
`PATCH /cart/{id}`
###### update cart item #####
###### Request
```javascript
{
"quantity":3
}
```
###### Response
```javascript
{
"cart_item_id":14,
"quantity":3
}
```
#### ==Add to cart== ####
`POST /cart`
:::info
:::
###### Add item to cart
###### Request
```javascript
{
"product_id":1,
"quantity":1
}
```
###### Response
```javascript
{
"cart_item_id": 1
}
```
#### ==Remove cart== ####
`DELETE /cart/{id}`
:::info
:::
###### Response
```javascript
{
"success": true
}
```
###### Fail Response
```javascript
403
message:Cart item does not belongs to user
```
```javascript
422
message:Cart item not exist
```
#### ==Cart List== ####
`GET /carts`
:::info
**response**
count: total number of record
color, size: optional depends on if the property is valid for item
:::
###### Get all cart items
###### Response
```javascript
{
"count": 12,
"products": [
{
"cart_item_id":1,
"product_id": 1,
"taxon_id": 1,
"title": "Chateau La Mission Haut Brion 1949",
"image": "url",
"quantity": 1,
"price": 37000
},
...
]
}
```
## Order
#### ==Submit Order== ####
`POST /submit-order`
:::info
Get cart from backend directly
Deduct stock quantity
:::
###### Create order
###### Request
```javascript
{
"name": "Nicholas Barker",
"email": "abc@gmail.com",
"tel": "+852 1234 5678",
"delivery_method": "pickup"
}
```
###### Response
```javascript
{
"order_number": "4958275923047"
}
```
#### ==Cancel Order Transaction== ####
###### Request
`POST /cancel-order`
:::info
:::
```javascript
{
"order_number": "4958275923047",
}
```
###### Response (Success)
```javascript
{
"success": true,
"order_id": 5,
"order_number": "4958275923047"
}
```
###### Fail Response
```javascript
403
message:Order does not belongs to user
```
```javascript
422
message:Order not exist
```
```javascript
428
message:Order cannot be cancelled
```
#### ==Order List== ####
`GET /orders?status={status}`
:::info
**response**
status: completed(completed, refunded), incompleted (cancelled)
count: total number of record,
:::
###### Get all orders
###### Response (Complete)
```javascript
{
"count": 24,
"orders": [
{
"order_number": "958275923047",
"order_id":1,
"status": "completed",
"delivery_method": "pickup",
"created_date": "2019-08-28 20:00",
"total": 920,
"items": [
{
"product_id": 1,
"taxon_id": 1,
"title": "Chateau La Mission Haut Brion 1949",
"image": "url",
"quantity": 1,
"price": 920
},
]
}
],
...
}
```
## Pay
#### ==Pay== ####
`POST /pay`
:::info
Use vts mp payment
:::
###### Pay via VTS
###### Request
```javascript
{
"order_number": "4958275923047",
"redirect_url": "url"
}
```
###### Response
```javascript
{
"payment_url": "url"
}
```
###### Response (Failed)
```javascript
422
message:Order cannot be paid
```
#### ==Get Payment Result== ####
`GET /payment-result`
:::info
status: pending, cancelled, completed
if cancelled, add back the stock
:::
###### Request
```javascript
{
"order_number": "4958275923047"
}
```
###### Response
```javascript
{
"order_id":1,
"order_number":"4958275923047",
"status": "completed",
"order_at":"date string with timezone",
"total": 838,
"payment_method":"wechat",
"name":"Nicholas Barker",
"email" : "abc@gmail.com"
"tel" : "+852 13231123",
"delivery_method" : "pickup"
}
```
###### Response (Failed)
```javascript
422
message:Order not exist
```