หลังจากที่ลูกค้าส่งคำสั่งซื้ออาหาร คุณสามารถส่งข้อความอัปเดตคำสั่งซื้อไปยังบริการสั่งซื้อจากต้นทางถึงปลายทางเพื่อแจ้งให้เราทราบถึงการเปลี่ยนแปลงได้
ต่อไปนี้คือเหตุผลทั่วไปบางประการในการส่งการอัปเดตคำสั่งซื้อ:
- เวลาที่ดำเนินการตามคำสั่งซื้อโดยประมาณจะพร้อมใช้งานหรือมีการเปลี่ยนแปลง
- สถานะของคำสั่งซื้อจะเปลี่ยนแปลง
- ดำเนินการตามคำสั่งซื้อนี้ไม่ได้อีกต่อไป
- ราคารายการในเมนูในคำสั่งซื้อมีการเปลี่ยนแปลง
- ลูกค้ามีวิธีใหม่ในการจัดการคำสั่งซื้อ เช่น หมายเลขโทรศัพท์ของฝ่ายสนับสนุนลูกค้าหรือหมายเลขโทรศัพท์ของร้านอาหาร
- ใบเสร็จสำหรับคำสั่งซื้อจะพร้อมใช้งาน
ส่วนถัดไปจะให้รายละเอียดเกี่ยวกับวิธีจัดการกับสถานการณ์ต่างๆ เหล่านี้ โดยใช้การอัปเดตคำสั่งซื้อ
การเปลี่ยนแปลงสถานะคำสั่งซื้อ
คำสั่งซื้อมีสถานะที่เป็นไปได้ 6 สถานะ สถานะเหล่านี้และการเปลี่ยนแปลงที่เป็นไปได้ แสดงอยู่ในแผนภาพต่อไปนี้
เมื่อลูกค้าส่งคำสั่งซื้อเป็นครั้งแรก คำสั่งซื้อจะเริ่มต้นด้วยสถานะ CREATED
CONFIRMED
หรือ REJECTED
คุณสามารถส่งข้อความอัปเดตคำสั่งซื้อเพื่ออัปเดตสถานะคำสั่งซื้อได้ตราบใดที่การเปลี่ยนสถานะมีผลบังคับใช้ ระบบจะใช้สถานะ CREATED
เมื่อแพลตฟอร์มของพาร์ทเนอร์ยืนยันหรือปฏิเสธคำสั่งซื้อทันทีไม่ได้ ตัวอย่างกรณีการใช้งาน เช่น เมื่อลูกค้าสั่งซื้อผ่านผู้รวบรวมข้อมูลการจัดส่ง ผู้รวบรวมข้อมูลการจัดส่งจะได้รับการส่งอาหารจาก Google และผู้รวบรวมข้อมูลจะส่งข้อมูลไปยังร้านอาหาร เมื่อร้านอาหารได้รับและยืนยันความพร้อมให้บริการของคำสั่งซื้อแล้ว ตอนนี้สถานะจะเป็น CONFIRMED
หรือ REJECTED
คำสั่งซื้อในรัฐ CONFIRMED
จะเปลี่ยนไปเป็นสถานะ IN_PREPARATION
ต่อไปจะใช้สถานะ READY_FOR_PICKUP
หรือ IN_TRANSIT
ขึ้นอยู่กับว่าเป็นการสั่งซื้อแบบมารับที่ร้านหรือจัดส่ง เมื่อมีการจัดส่งหรือมารับอาหารแล้ว ระบบจะตั้งค่าคำสั่งซื้อเป็นรัฐ FULFILLED
หากอนุญาตให้ลูกค้ายกเลิกคำสั่งซื้อ คุณจะใช้รัฐ CANCELLED
ได้ คุณสามารถยกเลิกคำสั่งซื้อขณะอยู่ในสถานะ CREATED
, CONFIRMED
, IN_PREPARATION
, READY_FOR_PICKUP
หรือ IN_TRANSIT
บริการสั่งซื้อจากต้นทางถึงปลายทางของคุณควรมีการคืนเงินตามนโยบายการยกเลิกและสถานะการชำระเงินของคุณ ณ เวลาที่ยกเลิก
บริการสั่งซื้อแบบต้นทางถึงปลายทางไม่จำเป็นต้องสนับสนุนสถานะและการเปลี่ยนแปลงทั้งหมดที่มี แต่สถานะสุดท้ายของคำสั่งซื้อต้องเป็น FULFILLED
, REJECTED
หรือ CANCELLED
การระบุเวลาดำเนินการตามคำสั่งซื้อโดยประมาณ
คุณระบุช่วงเวลาโดยประมาณให้ผู้ใช้ได้ทราบว่าจะพร้อมให้มารับ (หรือนำส่ง) ที่สินค้าที่สั่งซื้อเมื่อใด ใช้ช่อง estimatedFulfillmentTimeIso8601
ของ FoodOrderUpdateExtension
เพื่อระบุช่วงเวลาโดยประมาณว่าคำสั่งซื้อของลูกค้าจะพร้อมสำหรับการรับสินค้าหรือจัดส่งเมื่อใด
ส่ง estimatedFulfillmentTimeIso8601
ในเวลาต่อไปนี้
- เมื่อถึงเวลาโดยประมาณ หากเป็นไปได้ ให้อยู่ในสถานะ
CREATED
หรือCONFIRMED
- เมื่อเวลาโดยประมาณมีการเปลี่ยนแปลง เช่น อัปเดตเวลาโดยประมาณให้แม่นยำมากขึ้นเมื่อคำสั่งซื้อเป็น
IN_TRANSIT
หากต้องการจัดการกับความคาดหวังของผู้ใช้อย่างมีประสิทธิภาพ ให้ใช้ค่าประมาณการอย่างระมัดระวังและระบุช่วงวันที่และเวลาแทนที่จะระบุวันที่และเวลาที่แน่นอน คุณควรคำนึงถึงรูปแบบต่างๆ เช่น สภาพการจราจร ทุกครั้งที่เป็นไปได้ เช่น เวลานำส่งโดยประมาณ 12:45 น. (ขอบเขตล่าง) ถึง 13:15 น. (บน) สำหรับคำสั่งซื้อที่เวลานำส่งโดยประมาณคือ 13:00 น.
การจัดทำการดำเนินการจัดการคำสั่งซื้อ
เมื่อส่งการอัปเดตคำสั่งซื้อ คุณจะให้ทรัพยากรแก่ลูกค้าที่ช่วยให้ลูกค้าจัดการคำสั่งซื้อในรูปแบบ OrderManagementAction
ได้ หลังจากที่สั่งซื้อแล้ว ลูกค้าอาจต้องติดต่อคุณหรือร้านอาหารเพื่อดำเนินการตามคำสั่งซื้อเพื่อติดตามความคืบหน้า เปลี่ยนแปลง หรือยกเลิกคำสั่งซื้อ
OrderManagementAction
ช่วยให้ลูกค้าส่งอีเมล โทร หรือลิงก์ไปยัง URL ได้โดยตรงจากอุปกรณ์ ใช้ข้อมูลเดียวกันกับใน OrderManagementAction
ตามการยืนยันคำสั่งซื้อที่ส่งให้ผู้ใช้ทางอีเมล
การดำเนินการจัดการคำสั่งซื้อประกอบด้วยประเภทต่อไปนี้
CUSTOMER_SERVICE
: แจ้งให้ลูกค้าทราบเกี่ยวกับ การดำเนินการติดต่อฝ่ายบริการลูกค้า ต้องระบุประเภทการดำเนินการด้านการจัดการนี้สำหรับการอัปเดตคำสั่งซื้อEMAIL
: แจ้งให้ลูกค้าทราบถึงการดำเนินการเพื่อส่งอีเมลไปยังอีเมลที่ระบุไว้CALL
: แจ้งลูกค้าให้โทรไปยังหมายเลขโทรศัพท์ที่ระบุไว้VIEW_DETAIL
: แจ้งการดำเนินการเพื่อดูรายละเอียดคำสั่งซื้อแก่ลูกค้า
การอัปเดตคำสั่งซื้อแต่ละครั้งต้องมีการดำเนินการจัดการคำสั่งซื้ออย่างน้อย 1 รายการ อย่างไรก็ตาม การดำเนินการเกี่ยวกับการจัดการคำสั่งซื้อที่มีให้อาจแตกต่างกันไปตามสถานะของคำสั่งซื้อ
เช่น เมื่อคำสั่งซื้ออยู่ในสถานะ CONFIRMED
การดำเนินการ CUSTOMER_SERVICE
อาจชี้ไปยังหมายเลขโทรศัพท์ของฝ่ายบริการลูกค้า เมื่ออัปเดตสถานะคำสั่งซื้อเป็น IN_TRANSIT
การดำเนินการ CUSTOMER_SERVICE
อาจชี้ไปยังหมายเลขโทรศัพท์ของร้านอาหารที่ดำเนินการตามคำสั่งซื้อ
กำลังส่งข้อมูลอัปเดตเกี่ยวกับคำสั่งซื้อ
คุณใช้ข้อความประเภท AsyncOrderUpdateRequestMessage
ในการส่งการอัปเดตคำสั่งซื้อไปยังบริการสั่งซื้อจากต้นทางถึงปลายทางได้ Google จะตอบกลับด้วย AsyncOrderUpdateResponseMessage
เช่น หากต้องการแจ้งลูกค้าว่าคำสั่งซื้อของลูกค้าถูกต้องและได้รับการยอมรับ คุณอาจส่ง AsyncOrderUpdateRequestMessage
เพื่อเปลี่ยนสถานะของคำสั่งซื้อเป็น CONFIRMED
ที่มีป้ายกำกับว่า Accepted by restaurant
ได้
การตั้งค่าข้อความอัปเดตคำสั่งซื้อ
เมื่อส่ง AsyncOrderUpdateRequestMessage
ไปยัง Google คุณต้องระบุข้อมูลเกี่ยวกับสถานะของคำสั่งซื้อโดยใช้ช่อง OrderUpdate
ตัวอย่างต่อไปนี้แสดงตัวอย่าง AsyncOrderUpdateRequestMessage
สำหรับแต่ละสถานะคำสั่งซื้อ
ยืนยันแล้ว
ตัวอย่างนี้แสดงตัวอย่างคำขออัปเดตคำสั่งซื้อที่แจ้งผู้ใช้ว่าคำสั่งซื้อได้รับการยืนยันด้วยใบเสร็จและเวลานำส่งโดยประมาณ
{ "isInSandbox": true, "customPushMessage": { "orderUpdate": { "actionOrderId": "sample_action_order_id", "orderState": { "state": "CONFIRMED", "label": "Provider confirmed" }, "receipt": { "userVisibleOrderId": "userVisibleId1234" }, "updateTime": "2017-07-17T12:00:00Z", "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Contact customer service", "openUrlAction": { "url": "mailto:support@example.com" } } }, { "type": "EMAIL", "button": { "title": "Email restaurant", "openUrlAction": { "url": "mailto:person@example.com" } } }, { "type": "CALL_RESTAURANT", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "CALL_DRIVER", "button": { "title": "Call driver", "openUrlAction": { "url": "tel:+16505554681" } } } ], "infoExtension": { "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderUpdateExtension", "estimatedFulfillmentTimeIso8601": "2017-07-17T13:00:00Z/2017-07-17T13:30:00Z" } } } }
ถูกปฏิเสธ
ตัวอย่างนี้แสดงตัวอย่างคำขออัปเดตคำสั่งซื้อที่แจ้งผู้ใช้ว่าคำสั่งซื้อถูกปฏิเสธพร้อมเหตุผลการปฏิเสธ
{ "isInSandbox": true, "customPushMessage": { "orderUpdate": { "actionOrderId": "sample_action_order_id", "orderState": { "state": "REJECTED", "label": "Order rejected" }, "updateTime": "2017-05-10T02:30:00.000Z", "rejectionInfo": { "type": "UNKNOWN", "reason": "Sorry, the restaurant cannot take your order right now." }, "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Contact customer service", "openUrlAction": { "url": "mailto:support@example.com" } } }, { "type": "EMAIL", "button": { "title": "Email restaurant", "openUrlAction": { "url": "mailto:person@example.com" } } }, { "type": "CALL_RESTAURANT", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "CALL_DRIVER", "button": { "title": "Call driver", "openUrlAction": { "url": "tel:+16505554681" } } } ], "infoExtension": { "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderUpdateExtension", "foodOrderErrors": [ { "error": "NO_CAPACITY", "description": "Sorry, the restaurant cannot take your order right now." } ] } } } }
ยกเลิกแล้ว
ตัวอย่างนี้แสดงตัวอย่างคำขออัปเดตคำสั่งซื้อที่แจ้งให้ผู้ใช้ทราบว่ามีการยกเลิกคำสั่งซื้อพร้อมเหตุผลการยกเลิก
{ "isInSandbox": true, "customPushMessage": { "orderUpdate": { "actionOrderId": "sample_action_order_id", "orderState": { "state": "CANCELLED", "label": "Order cancelled" }, "updateTime": "2017-05-10T02:30:00.000Z", "cancellationInfo": { "reason": "Customer requested" }, "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Contact customer service", "openUrlAction": { "url": "mailto:support@example.com" } } }, { "type": "EMAIL", "button": { "title": "Email restaurant", "openUrlAction": { "url": "mailto:person@example.com" } } }, { "type": "CALL_RESTAURANT", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "CALL_DRIVER", "button": { "title": "Call driver", "openUrlAction": { "url": "tel:+16505554681" } } } ] } } }
IN_PREPARATION
ตัวอย่างนี้แสดงตัวอย่างคำขออัปเดตคำสั่งซื้อที่แจ้งให้ผู้ใช้ทราบว่ากำลังเตรียมอาหารอยู่
{ "isInSandbox":true, "customPushMessage":{ "orderUpdate":{ "actionOrderId":"sample_action_order_id", "orderState":{ "state":"IN_PREPARATION", "label":"Order is being prepared" }, "receipt": { "userVisibleOrderId": "userVisibleId1234" }, "updateTime":"2018-04-15T11:30:00Z", "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Contact customer service", "openUrlAction": { "url": "mailto:support@example.com" } } }, { "type": "EMAIL", "button": { "title": "Email restaurant", "openUrlAction": { "url": "mailto:person@example.com" } } }, { "type": "CALL_RESTAURANT", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "CALL_DRIVER", "button": { "title": "Call driver", "openUrlAction": { "url": "tel:+16505554681" } } } ], "infoExtension":{ "@type":"type.googleapis.com/google.actions.v2.orders.FoodOrderUpdateExtension", "estimatedFulfillmentTimeIso8601":"PT20M" } } } }
READY_FOR_PICKUP
ตัวอย่างนี้แสดงตัวอย่างคำขออัปเดตคำสั่งซื้อที่แจ้งผู้ใช้ว่าอาหารพร้อมให้มารับแล้ว
{ "isInSandbox": true, "customPushMessage": { "orderUpdate": { "actionOrderId": "sample_action_order_id", "orderState": { "state": "READY_FOR_PICKUP", "label": "Order is ready for pickup" }, "receipt": { "userVisibleOrderId": "userVisibleId1234" }, "updateTime": "2018-04-15T12:00:00Z", "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Contact customer service", "openUrlAction": { "url": "mailto:support@example.com" } } }, { "type": "EMAIL", "button": { "title": "Email restaurant", "openUrlAction": { "url": "mailto:person@example.com" } } }, { "type": "CALL_RESTAURANT", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "CALL_DRIVER", "button": { "title": "Call driver", "openUrlAction": { "url": "tel:+16505554681" } } } ], "infoExtension": { "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderUpdateExtension", "estimatedFulfillmentTimeIso8601": "PT20M" } } } }
IN_TRANSIT
ตัวอย่างนี้แสดงตัวอย่างคำขออัปเดตคำสั่งซื้อที่แจ้งผู้ใช้ว่าคำสั่งซื้ออยู่ระหว่างการขนส่งด้วยเวลานำส่งโดยประมาณ
{ "isInSandbox": true, "customPushMessage": { "orderUpdate": { "actionOrderId": "sample_action_order_id", "orderState": { "state": "IN_TRANSIT", "label": "Order is on the way" }, "inTransitInfo": { "updatedTime": "2017-07-17T12:00:00Z" }, "updateTime": "2017-07-17T12:00:00Z", "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Contact customer service", "openUrlAction": { "url": "mailto:support@example.com" } } }, { "type": "EMAIL", "button": { "title": "Email restaurant", "openUrlAction": { "url": "mailto:person@example.com" } } }, { "type": "CALL_RESTAURANT", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "CALL_DRIVER", "button": { "title": "Call driver", "openUrlAction": { "url": "tel:+16505554681" } } } ], "infoExtension": { "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderUpdateExtension", "estimatedFulfillmentTimeIso8601": "PT20M" } } } }
เรียบร้อยแล้ว
ตัวอย่างนี้แสดงตัวอย่างคำขออัปเดตคำสั่งซื้อที่แจ้งผู้ใช้ว่ามีการรับสินค้าหรือนำส่งคำสั่งซื้อแล้ว
{ "isInSandbox": true, "customPushMessage": { "orderUpdate": { "actionOrderId": "sample_action_order_id", "orderState": { "state": "FULFILLED", "label": "Order delivered" }, "updateTime": "2017-05-10T02:30:00.000Z", "fulfillmentInfo": { "deliveryTime": "2017-05-10T02:30:00.000Z" }, "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Contact customer service", "openUrlAction": { "url": "mailto:support@example.com" } } }, { "type": "EMAIL", "button": { "title": "Email restaurant", "openUrlAction": { "url": "mailto:person@example.com" } } }, { "type": "CALL_RESTAURANT", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "CALL_DRIVER", "button": { "title": "Call driver", "openUrlAction": { "url": "tel:+16505554681" } } } ] } } }
ดูตัวอย่างเพิ่มเติมของคำขออัปเดตคำสั่งซื้อในกรณีการใช้งานที่แตกต่างกันได้ที่หัวข้อใช้การอัปเดตคำสั่งซื้อขั้นสูง
สร้างโทเค็นการให้สิทธิ์และส่งข้อความ
การอัปเดตคำสั่งซื้อจำเป็นต้องมีโทเค็นการให้สิทธิ์เพื่อให้บริการสั่งซื้อจากต้นทางถึงปลายทางสามารถยืนยันได้ว่าข้อความนั้นมาจากบริการเว็บสำหรับการสั่งซื้อจากต้นทางถึงปลายทาง
โปรดทำตามขั้นตอนต่อไปนี้เพื่อใช้การอัปเดตคำสั่งซื้อกับโปรเจ็กต์
- สร้างโทเค็นการให้สิทธิ์โดยทำตามขั้นตอนต่อไปนี้
- ใช้ Google Auth Library เพื่ออ่านข้อมูลเข้าสู่ระบบจากไฟล์บัญชีบริการ
- โทเค็นคำขอที่ใช้ขอบเขต API ต่อไปนี้
https://www.googleapis.com/auth/actions.fulfillment.conversation
- ใช้โทเค็นนี้เพื่อส่งคำขอ HTTP POST ที่ผ่านการตรวจสอบสิทธิ์ไปยังปลายทางต่อไปนี้
https://actions.googleapis.com/v2/conversations:send
- ตั้งค่าส่วนหัว
Content-Type
เป็นapplication/json
ตามคำขอ
ตัวอย่างต่อไปนี้แสดงวิธีการอัปเดตคำสั่งซื้อ
Node.js
โค้ดนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สำหรับ Node.js
const {auth} = require('google-auth-library') const request = require('request'); // The service account client secret file downloaded from the Google Cloud Console const serviceAccountJson = require('./service-account.json') // order-update.json is a file that contains the payload const jsonBody = require('./order-update.json') /** * Get the authorization token using a service account. */ async function getAuthToken() { let client = auth.fromJSON(serviceAccountJson) client.scopes = ['https://www.googleapis.com/auth/actions.fulfillment.conversation'] const tokens = await client.authorize() return tokens.access_token; } /** * Send an order update request */ async function sendOrderUpdate() { const token = await getAuthToken() request.post({ headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, url: 'https://actions.googleapis.com/v2/conversations:send', body: jsonBody, json: true }, (err, res, body) => { if (err) { return console.log(err); } console.log(`Response: ${JSON.stringify(res)}`) }) }
Python
โค้ดนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สำหรับ Python
from google.oauth2 import service_account from google.auth.transport.requests import AuthorizedSession import json # service-account.json is the service account client secret file downloaded from the # Google Cloud Console credentials = service_account.Credentials.from_service_account_file( 'service-account.json') scoped_credentials = credentials.with_scopes( ['https://www.googleapis.com/auth/actions.fulfillment.conversation']) authed_session = AuthorizedSession(scoped_credentials) # order-update.json is a file that contains the payload json_payload=json.load(open('order-update.json')) response = authed_session.post( 'https://actions.googleapis.com/v2/conversations:send', json=json_payload)
Java
รหัสนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สำหรับ Java
/** * Get the authorization token using a service account. */ private static String getAuthToken() { InputStream serviceAccountFile = Example.class.getClassLoader().getResourceAsStream("service-account.json"); ServiceAccountCredentials.Builder credentialsSimpleBuilder = ServiceAccountCredentials.fromStream(serviceAccountFile).toBuilder(); credentialsSimpleBuilder.setScopes(ImmutableList.of("https://www.googleapis.com/auth/actions.fulfillment.conversation")); AccessToken accessToken = credentialsSimpleBuilder.build().refreshAccessToken(); return accessToken.getTokenValue(); } /** * Send an order update request */ public void sendOrderUpdate() { String authToken = getAuthToken(); // Execute POST request executePostRequest("https://actions.googleapis.com/v2/conversations:send", authToken, "update_order_example.json",); }
เพื่อให้การอัปเดตคำสั่งซื้อเสร็จสมบูรณ์โดยไม่มีข้อผิดพลาด Google จะส่งคืนการตอบกลับ HTTP 200 ที่มีเพย์โหลดว่างเปล่า หากมีปัญหา เช่น การอัปเดตมีรูปแบบไม่ถูกต้อง Google จะส่งกลับข้อผิดพลาด