Create Shopline Order
Description
Shopline 建立新訂單。
Resource
POST /v1/shopline/order
Authorization
採用 OAuth 2.0 Bearer Token,詳細使用流程請參考 Auth Login。
Request Body Parameters
| Name | Type | Description |
|---|---|---|
| resource | Resource | order/complete event 資源 |
| omni_is_resend | Boolean | 是否補建立訂單 (optional) |
Request Body Parameters - Resource
| Name | Type | Description |
|---|---|---|
| _id | string | 訂單編號 |
Request Example
{
"event": "Order",
"merchant_handle": "irishsu400",
"merchant_id": "5fd719ea92248a0018024420",
"resource": {
"_id": "64521840619562000e0f5faa",
"affiliate_data": {},
"cart_attributes": {
"affiliate_data": {},
"shop_session_id": ""
},
"channel": {},
"checkout_object_data": {
"_id": "64521840619562000e0f5fa8",
"current_total": {
"cents": 299,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 299,
"label": "NT$299"
},
"number": "C20230503081600201",
"order_ids": [
"64521840619562000e0f5faa"
]
},
"child_order_ids": [],
"confirmed_at": "2023-05-03T08:20:29.371+00:00",
"created_at": "2023-05-03T08:16:00.054Z",
"created_by": "shop",
"created_from": "shop",
"currency_iso": "TWD",
"custom_data": [
{
"field_id": "635f7a7f13b53d001c477c69",
"field_translations": {
"en": "DHC Testing Money",
"zh-hant": "DHC 測試幣"
},
"value": ""
}
],
"custom_discount_items": null,
"customer_email": "[email protected]",
"customer_id": "5fd822b5ade99b001304a7d9",
"customer_info": {},
"customer_name": "Iris",
"customer_phone": "0989536693",
"customer_phone_country_code": "886",
"delivery_address": {
"address_1": null,
"address_2": null,
"city": null,
"country": "台灣",
"country_code": "TW",
"district": null,
"key": null,
"layer1": null,
"layer2": null,
"layer3": null,
"logistic_codes": null,
"postcode": null,
"recipient_name": "Iris",
"recipient_phone": "0989536693",
"recipient_phone_country_code": "886",
"remarks": null,
"state": null
},
"delivery_data": {
"hk_sfplus_home_region": null,
"location_code": null,
"location_name": null,
"location_short_name": null,
"name_translations": null,
"scheduled_delivery_date": null,
"store_address": null,
"time_slot_key": "",
"time_slot_translations": null,
"tracking_number": "",
"url": null
},
"delivery_option_id": "60d5527bfbb7a2001db51c58",
"ga_tracked": false,
"id": "64521840619562000e0f5faa",
"invoice": {
"buyer_name": "",
"carrier_number": "",
"carrier_type": "",
"invoice_cancelled_at": null,
"invoice_date": null,
"invoice_number": "",
"invoice_status": "",
"invoice_tax_type": "",
"invoice_type": "",
"mailing_address": "",
"n_p_o_b_a_n": "",
"tax_id": ""
},
"invoices": [],
"membership_tier_data": null,
"merchant_order_number": null,
"order_comments": [],
"order_delivery": {
"arrived_at": null,
"collected_at": null,
"delivery_option_id": "60d5527bfbb7a2001db51c58",
"delivery_status": "pending",
"delivery_type": "custom",
"name_translations": {
"en": "Other",
"zh-hant": "其他"
},
"platform": "custom",
"remark": null,
"request_accepted_at": null,
"request_authorized_at": null,
"request_submitted_at": null,
"requested_fmt_at": null,
"require_expired_upload": false,
"require_storeclosed_upload": false,
"return_order_id": null,
"returned_at": null,
"shipped_at": null,
"status": "pending",
"store_closed_at": null,
"storeclosed_upload_at": null,
"total": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
}
},
"order_discount": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"order_notes": [],
"order_number": "20230503081600202",
"order_payment": {
"created_at": "2023-05-03T08:16:00.185Z",
"id": "64521840619562000e0f5fb1",
"last_four_digits": "",
"name_translations": {
"en": "Cash on Delivery",
"zh-hant": "貨到付款"
},
"paid_at": null,
"payment_data": {},
"payment_fee": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"payment_method_id": "607a596907e0710023fab3ef",
"payment_slips_setting": null,
"payment_type": "cash_on_delivery",
"ref_payment_id": null,
"status": "pending",
"total": {
"cents": 299,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 299,
"label": "NT$299"
},
"updated_at": "2023-05-03T08:16:01.296Z"
},
"order_points_to_cash": {
"cents": 1,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 1,
"label": "NT$1"
},
"order_remarks": "",
"order_source": {
"id": "6125ed4f693a9f2e6eedcb4f",
"name": null,
"source_id": null,
"type": "storefront"
},
"parent_order_id": null,
"payment_slips": [],
"promotion_items": [
{
"created_at": "2023-05-03T08:16:00.117Z",
"discountable_amount": null,
"discounted_amount": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"id": "64521840619562000e0f5fac",
"promotion": {
"_id": "630c695f5c21e00025a59801",
"addon_product_id": null,
"available_platforms": [
"ec"
],
"banner_media_ids": [],
"codes": [],
"coupon_generated_by": null,
"coupon_type": null,
"created_at": "2022-08-29T07:23:11.795Z",
"description_translations": {},
"discount_amount": null,
"discount_on": "order",
"discount_percentage": null,
"discount_type": "gift",
"discountable_category_ids": [],
"discountable_product_ids": [
"61ea5064fe2f5e0029bcae83"
],
"discountable_quantity": 1,
"discounted_point": null,
"discounted_price": null,
"drew_coupon_count": 0,
"end_at": null,
"extended_promotion_id": null,
"first_purchase_only": false,
"for_affiliate_campaign": false,
"id": "630c695f5c21e00025a59801",
"is_accumulated": false,
"max_use_count": null,
"membership_tier_id": null,
"merchant_id": "5fd719ea92248a0018024420",
"min_price_type": "after_discount",
"multiple_code": false,
"requires_membership": false,
"seo_description_translations": {},
"seo_keywords": null,
"seo_title_translations": {},
"show_coupon": false,
"start_at": "2022-08-29T07:00:00.000+00:00",
"status": "active",
"term_translations": {},
"title_translations": {
"en": "美白水",
"zh-hant": "美白水"
},
"updated_at": "2022-10-05T10:59:25.198Z",
"use_count": 29,
"user_max_use_count": 0,
"whitelisted_tag_contents": []
},
"subtotal_after": {
"cents": 300,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 300,
"label": "NT$300"
},
"updated_at": "2023-05-03T08:16:00.117Z"
}
],
"ref_customer_id": "",
"ref_order_id": "",
"return_from_order_id": null,
"seller_id": "5fd719ea92248a0018024420",
"skip_fulfillment": false,
"split_at": null,
"status": "completed",
"subtotal": {
"cents": 300,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 300,
"label": "NT$300"
},
"subtotal_items": [
{
"cost": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": "NT$0"
},
"created_by": "admin",
"discounted_price": null,
"fields_translations": {},
"id": "64521840619562000e0f5fae",
"is_preorder": false,
"item_data": {
"cart_item_id": "6452183f619562000e0f5fa5",
"parent_item_ids": [
"6452183f619562000e0f5fa4"
],
"promotion_id": "630c695f5c21e00025a59801",
"triggering_item_id": null
},
"item_id": "61ea5064fe2f5e0029bcae83",
"item_price": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"item_type": "Gift",
"item_variation_id": "",
"item_variation_key": "",
"media": {
"_id": "61ea503dc82e5f001a54e910",
"alt_translations": {},
"images": {
"favicon": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"favicon_large": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"favicon_small": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"original": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"source": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"thumb": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"transparent_large": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"transparent_thumb": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
},
"transparent_xlarge": {
"height": 819,
"url": "https://img.shoplineapp.com/media/image_clips/61ea503dc82e5f001a54e910/original.jpg?1642745917",
"width": 721
}
}
},
"object_data": {
"barcode_type": "Code 128",
"weight": 1.1
},
"order_discounted_price": null,
"price": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"price_sale": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": "NT$0"
},
"quantity": 1,
"ref_data": null,
"sku": "white11",
"title_translations": {
"zh-hant": "[保健食品] 美白水"
},
"total": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"total_points": null
},
{
"cost": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": "NT$0"
},
"created_by": "admin",
"discounted_price": null,
"fields_translations": {},
"id": "64521840619562000e0f5fad",
"is_preorder": false,
"item_data": {
"cart_item_id": "378253556",
"has_exclude_promotion_tag": false,
"member_point_ratio_amount": 1,
"member_point_redeem_to_cash_ratio_amount": {
"cents": 1,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 1,
"label": "NT$1"
},
"order_promotion_items": {},
"parent_item_ids": [],
"promotion_id": null,
"triggering_item_id": ""
},
"item_id": "6391a20a674380002e198546",
"item_price": {
"cents": 300,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 300,
"label": "NT$300"
},
"item_type": "Product",
"item_variation_id": "",
"item_variation_key": "",
"media": {
"_id": "6391a1f0724e0c002e166c8a",
"alt_translations": {},
"images": {
"favicon": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"favicon_large": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"favicon_small": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"original": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"source": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"thumb": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"transparent_large": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"transparent_thumb": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
},
"transparent_xlarge": {
"height": 3024,
"url": "https://img.shoplineapp.com/media/image_clips/6391a1f0724e0c002e166c8a/original.jpg?1670488559",
"width": 4032
}
}
},
"object_data": {
"adult": "no",
"age_group": "all_ages",
"barcode_type": "Code 128",
"condition": "new",
"gender": "unisex",
"max_order_quantity": -1,
"weight": 0
},
"order_discounted_price": null,
"price": {
"cents": 300,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 300,
"label": "NT$300"
},
"price_sale": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": "NT$0"
},
"quantity": 1,
"ref_data": null,
"sku": "SKUtest1",
"title_translations": {
"en": "抱枕",
"zh-hant": "抱枕"
},
"total": {
"cents": 300,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 300,
"label": "NT$300"
},
"total_points": null
}
],
"system_order_number": "20230503081600202",
"total": {
"cents": 299,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 299,
"label": "NT$299"
},
"total_tax_fee": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"updated_at": "2023-05-03T08:20:29.392Z",
"user_credit": {
"cents": 0,
"currency_iso": "TWD",
"currency_symbol": "NT$",
"dollars": 0,
"label": ""
},
"utm_data": {}
},
"topic": "order/complete",
"trace_id": "f2eaa9fc-f05b-4980-a13c-5cfd0dd5597e",
"ts": "1683102029413003500"
}
Response Body Parameters
| Name | Type | Description |
|---|---|---|
| id | string | 訂單編號 |
Response Success Example
{
"id": "STORE2023082301"
}
Response Not Found Example
{
"message": "查無此訂單",
}
Response 已建立訂單 Example
{
"message": "訂單[64e6b5c941aeba0017b10c6e]已建立過,全通路訂單號為[00003023082500008]"
}
Create Shopline Order API Workflow
sequenceDiagram
autonumber
participant C as Client
participant OP as OmniPlatform
participant SL as Shopline
participant DB as Database
C->>OP: [POST] /v1/shopline/order
activate OP
OP->>DB: Get Weborder00 By request.resource._id
activate DB
DB-->>OP: Return Data
deactivate DB
NOTE OVER C, OP: 避免 shopline webhook 15 秒之內沒收到回應碼,使用相同訂單編號再次呼叫 shopline 建立新訂單 API
alt if data is not empty
OP-->>C: Return Response(200, {'message: '該筆訂單已建立: {request.resource._id}'})
end
NOTE OVER OP, SL: 使用 request.resource._id
OP->>SL: [GET] /v1/orders/:id
activate SL
SL-->>OP: Return Response
deactivate SL
alt if response_data is empty
OP-->>C: Return Response(404, {'message': '查無此訂單'})
end
OP->>OP: [POST] /v1/user
alt if response_data['status_code'] != 204:
OP->>OP: Write Error Log(response_data['message'])
end
OP->>DB: Get Member Data By customer_phone
activate DB
DB-->>OP: Return Data
deactivate DB
alt if member_data is empty
OP->>OP: Write Error Log(404, {'message': '查無會員資料'})
end
OP->>OP: Handle Weborder Data
NOTE OVER OP: 將會員代碼寫入weborder00.vip_id,若 member_data 為空則寫入空值
OP->>DB: Insert Weborder Data
alt if insert failed
OP-->>C: Return Response(400, {'message': '訂單資料寫入時發錯誤'})
end
OP-->>C: Return Response(200)
deactivate OP