結帳呼叫後,使用者會查看已更新的購物車,其中包含稅金、運費、折扣和您傳回的其他費用。使用者確認並提交訂單後,Google 會向你的執行端點傳送 JSON 要求,其中包含訂單資訊。您的網路服務必須接收這筆訂單、處理訂單,並回覆 Google 訂單狀態。
本節將說明 Google 傳送的訂單要求訊息格式 (稱為 SubmitOrderRequestMessage
),以及您必須提供的回應訊息格式 (稱為 SubmitOrderResponseMessage
)。如要進一步瞭解訂單執行要求生命週期,請參閱執行要求總覽。
訂單履行導入
您為配合端對端訂購服務而建構的端對端訂購服務網頁服務,必須包含用於接收 Google 訂單訊息的網址端點。在訂單處理作業中,您的網路服務會以 JSON 格式接收來自 Google 的 POST 要求 SubmitOrderRequestMessage
。這項要求包含客戶訂單,包括稅金、費用和付款資訊。收到提交訂單要求後,您的網路服務必須執行下列操作:
- 檢查交易資格,例如卡片驗證或詐欺偵測。
- 在系統中建立訂單。
- 授權付款方式,並視需要呼叫付款處理工具的收費 API。
- 回傳訂單的適當狀態:
CREATED
、CONFIRMED
或REJECTED
。
處理訂單後,你的執行程式碼必須以 SubmitOrderResponseMessage
JSON 訊息的形式,將回應傳回給 Google。
如要進一步瞭解訂購端到端執行要求的網路服務實作規定,請參閱執行要求總覽。
訂購要求訊息
當消費者在訂購端到端流程中選擇下單時,Google 會向您的網路服務傳送要求,其中包含名為 SubmitOrderRequestMessage
的 JSON 訊息,其中包含以下資料:
- 意圖:每個提交訂單要求主體的
inputs[0].intent
欄位都包含actions.intent.TRANSACTION_DECISION
字串值。 - 訂單:提交訂單要求的
inputs[0].arguments[0].transactionDecisionValue
欄位包含Order
物件,代表要提交的客戶訂單,以及付款詳細資料。 - 沙箱標記:提交訂單要求的
isInSandbox
欄位會指出交易是否使用沙箱付款。
訂購要求範例
以下是 SubmitOrderRequestMessage
範例:
{ "user": {}, "conversation": { "conversationId": "CTKbKfUlHCyDEdcz_5PBJTtf" }, "inputs": [ { "intent": "actions.intent.TRANSACTION_DECISION", "arguments": [ { "transactionDecisionValue": { "order": { "finalOrder": { "cart": { "merchant": { "id": "restaurant/Restaurant/QWERTY", "name": "Tep Tep Chicken Club" }, "lineItems": [ { "name": "Spicy Fried Chicken", "type": "REGULAR", "id": "299977679", "quantity": 2, "price": { "type": "ESTIMATE", "amount": { "currencyCode": "AUD", "units": "39", "nanos": 600000000 } }, "offerId": "MenuItemOffer/QWERTY/scheduleId/496/itemId/143", "extension": { "@type": "type.googleapis.com/google.actions.v2.orders.FoodItemExtension" } } ], "extension": { "@type": "type.googleapis.com/google.actions.v2.orders.FoodCartExtension", "fulfillmentPreference": { "fulfillmentInfo": { "delivery": { "deliveryTimeIso8601": "P0M" } } }, "location": { "coordinates": { "latitude": -33.8376441, "longitude": 151.0868736 }, "formattedAddress": "Killoola St, 1, Concord West NSW 2138", "zipCode": "2138", "city": "Concord West", "postalAddress": { "regionCode": "AU", "postalCode": "2138", "administrativeArea": "NSW", "locality": "Concord West", "addressLines": [ "Killoola St", "1" ] } }, "contact": { "displayName": "Hab Sy", "email": "hab9878.sy@gmail.com", "phoneNumber": "+61000000000", "firstName": "Hab", "lastName": "Sy" } } }, "otherItems": [ { "name": "Delivery fee", "type": "DELIVERY", "price": { "type": "ESTIMATE", "amount": { "currencyCode": "AUD", "units": "3", "nanos": 500000000 } } }, { "name": "Subtotal", "type": "SUBTOTAL", "price": { "type": "ESTIMATE", "amount": { "currencyCode": "AUD", "units": "39", "nanos": 600000000 } } } ], "totalPrice": { "type": "ESTIMATE", "amount": { "currencyCode": "AUD", "units": "43", "nanos": 100000000 } }, "extension": { "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderExtension" } }, "googleOrderId": "01412971004192156198", "orderDate": "2020-10-22T09:02:06.173Z", "paymentInfo": { "displayName": "Pay when you get your food", "paymentType": "ON_FULFILLMENT" } } } } ] } ], "directActionOnly": true, "isInSandbox": true }
訂單回應訊息
收到要求後,訂購端到端網路服務會處理要求,並傳回包含下列資料的 SubmitOrderResponseMessage
:
OrderUpdate
:物件包含訂單狀態,以及使用者可執行的任何後續訂單動作,例如聯絡支援團隊和查看訂單詳細資料,這些動作會在回應的finalResponse.richResponse.items[0].structuredResponse.orderUpdate
欄位中定義。
訂單更新欄位
當您的網路服務傳送 SubmitOrderResponseMessage
時,其中包含的 OrderUpdate
欄位會包含下列欄位:
actionOrderId
:訂單的專屬 ID,用於在系統中識別訂單,並在傳送後續訂單更新時參照。orderState
:代表訂單狀態的OrderState
物件。orderManagementActions
:使用者可執行的訂單後動作,例如聯絡客戶服務團隊和查看訂單詳細資料。totalPrice
:訂單的總價。這項設定為選用。只有在訂單提交後,訂單總價發生變化時,才傳送。
訂單可能處於下列其中一種狀態:
CREATED
:你的履行端點已成功處理訂單,但供應商尚未確認訂單。CONFIRMED
:你的履行端點已成功處理訂單,且供應商已確認訂單。REJECTED
:發生問題,你的訂單端點無法建立或確認訂單,可能包括付款問題。
如果您將訂單設為 REJECTED
狀態,請在 OrderUpdate
的 rejectionInfo
欄位中指定原因。使用 FoodOrderUpdateExtension.FoodOrderErrors
值搭配 UNKNOWN
類型的 rejectionInfo
,並提供說明。
訂單回應範例
以下是 SubmitOrderResponseMessage
範例:
{ "finalResponse": { "richResponse": { "items": [ { "structuredResponse": { "orderUpdate": { "actionOrderId": "1603357328160", "orderState": { "state": "CONFIRMED", "label": "Pending" }, "updateTime": "2020-10-22T02:02:08-07:00", "orderManagementActions": [ { "type": "CUSTOMER_SERVICE", "button": { "title": "Call customer service", "openUrlAction": { "url": "tel:+61234561000" } } }, { "type": "VIEW_DETAILS", "button": { "title": "View order details", "openUrlAction": { "url": "https://partner.com/view/orderstatus" } } } ], "receipt": { "userVisibleOrderId": "BXZ-1603357328" } } } } ] } } }
要求失敗
如果提交要求失敗,SubmitOrderResponseMessage
需要將 OrderState.state
設為 REJECTED
。回應也必須包含 RejectionInfo,其中包含 RejectionType
物件,用於說明錯誤類型。
失敗回應範例
{ "expectUserResponse": false, "finalResponse": { "richResponse": { "items": [ { "structuredResponse": { "orderUpdate": { "actionOrderId": "sample_action_order_id", "orderState": { "state": "REJECTED", "label": "Order rejected" }, "updateTime": "2017-05-10T02:30:00.000Z", "rejectionInfo": { "type": "PAYMENT_DECLINED", "reason": "Insufficient funds" }, "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", "button": { "title": "Call restaurant", "openUrlAction": { "url": "tel:+16505554679" } } }, { "type": "VIEW_DETAILS", "button": { "title": "View order", "openUrlAction": { "url": "https://orderview.partner.com?orderid=sample_action_order_id" } } } ] } } } ] } } }
提交訂單實作
實作提交訂單 API 時,應採取下列步驟。
驗證
- 執行服務、購物車和促銷活動驗證,如同設定結帳功能。
- 視需要使用下列任一類型的 RejectionInfo 進行傳回:
RejectionInfoType | 用途 |
---|---|
UNAVAILABLE_SLOT |
執行時間已失效。 |
PROMO_USER_INELIGIBLE |
請使用要求中「聯絡人」物件中的電子郵件,驗證使用者的促銷活動資格。請參閱「實作促銷活動訂單提交功能」中的範例。 |
INELIGIBLE |
|
PAYMENT_DECLINED |
系統無法處理付款。例如,這可能是因為餘額不足。 |
UNKNOWN |
如有其他驗證錯誤。 |
如果發生驗證錯誤,請將 OrderState.state
設為 REJECTED
。您可以選擇使用 FoodOrderUpdateExtension 提供特定拒絕原因。foodOrderErrors
。請參閱「提交訂單驗證」中的範例。
處理付款
- 計算
totalPrice
時,請將購物車價格、費用、折扣、稅金和小費加總。如果使用者可以修改小費金額,totalPrice
應與 CheckoutResponseMessage 中傳回的totalPrice
相同,並加上小費金額的變更。詳情請參閱「提交訂單時的價格變更」。 - 如果您傳回的回應中訂單狀態為
CREATED
或CONFIRMED
,請處理訂單和付款。 - 請按照「產生用戶端程式庫」一文的說明,使用從結構定義產生的類型,確保系統傳回有效的回應格式。
- 使用 GoogleProvidedPaymentInstrument.
instrumentToken
處理付款。如果無法處理付款,請傳回類型為PAYMENT_DECLINED
的 RejectionInfo。詳情請參閱「處理付款」。 - 在處理完訂單後,透過電子郵件和/或簡訊立即通知使用者。
傳回回應
- 如果沒有錯誤,請將 OrderState.
state
設為CREATED
或CONFIRMED
。 - 如果遇到錯誤,請將 OrderState.
state
設為REJECTED
,並加入含有對應 RejectionInfoType 的 RejectionInfo 物件。 - 設定 OrderUpdate.
orderManagementActions
。