实现高级订单更新

客户提交订单后,您可以通过向 Google 发送订单更新消息来通知客户订单发生了更改。然后,Google 会在订购界面中将该消息转发给客户。

发送订单更新的常见原因包括:

  • 订单的预计履单时间变为可用状态或发生变化。
  • 订单的状态会发生变化。
  • 该订单无法再履行。
  • 订单中所包含的菜单项的价格发生了变化。
  • 客户可以通过新的方式管理订单,例如客户服务或餐厅电话号码。
  • 订单收据可供使用。

例如,以下示例使用订单更新,在餐厅确认订单后,将客户订单的状态从 CREATED 更改为 CONFIRMED

使用场景 如何实现
用例 1:餐馆确认订单 系统会将状态为 CONFIRMEDOrderUpdate 发送给 Google。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsestimatedFulfillmentTime

JSON

{
  "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"
        }
      }
  }
}

如需了解为项目实现订单更新的基础知识,请阅读异步订单更新指南。

以下部分将举例说明更高级的订单更新场景。

“已拒绝”状态

以下示例展示了因各种原因而遭拒的订单的 AsyncOrderUpdateRequestMessage。拒绝原因的一些示例包括餐厅无法再履行订单,或者与订单相关联的送餐地址超出有效范围。

使用场景 如何实现
用例 1:订单被拒,因为提供商无法与餐馆联系,或餐馆无法履行订单。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfofoodOrderError(错误类型为 NO_CAPACITY)。
使用场景 2:订单因司机没空或配送地址超出范围而被拒。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfofoodOrderError(错误类型为 OUT_OF_SERVICE_AREA)。
用例 3:订单因餐厅意外停业或即将打烊而被拒。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfofoodOrderError(错误类型为 CLOSED)。
用例 4:订单因部分商品缺货而被拒。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfofoodOrderError(错误类型为 AVAILABILITY_CHANGED)。
用例 5:订单因未知或未分类原因而遭拒。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfo(错误类型为 UNKNOWN)。

JSON

{
  "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."
          }
        ]
      }
    }
  }
}

JSON

{
  "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, delivery is currently not available to your address."
      },
      "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": "OUT_OF_SERVICE_AREA",
            "description": "Sorry, delivery is currently not available to your address."
          }
        ]
      }
    }
  }
}

JSON

{
  "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 is closed unexpectedly."
      },
      "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": "CLOSED",
            "description": "Sorry, the restaurant is closed unexpectedly."
          }
        ]
      }
    }
  }
}

JSON

{
  "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, some of items are not available 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": "AVAILABILITY_CHANGED",
            "id": "sample_menu_item_id",
            "description": "Sorry, some of the items are not available right now."
          }
        ]
      }
    }
  }
}

JSON

{
  "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, your order is rejected."
      },
      "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"
            }
          }
        }
      ]
    }
  }
}

“已取消”状态

以下示例演示了客户请求取消的订单的 AsyncOrderUpdateRequestMessage

使用场景 如何实现
用例 1:订单被客户请求取消 向 Google 发送状态为 CANCELLEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionscancellationInfo

JSON

{
  "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"
            }
          }
        }
      ]
    }
  }
}

“已完成”状态

以下示例展示了已履行订单的 AsyncOrderUpdateRequestMessage

使用场景 如何实现
用例 1:履单 向 Google 发送状态为 FULFILLEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActions

JSON

{
  "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"
            }
          }
        }
      ]
    }
  }
}

运输状态

以下示例展示了正在运送给客户的送货订单的 AsyncOrderUpdateRequestMessage

使用场景 如何实现
用例 1:配送订单正在运送中。 向 Google 发送状态为 IN_TRANSITOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsestimatedFulfillmentTime

JSON

{
  "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"
      }
    }
  }
}

可随时取货状态

以下示例演示了可以由客户自提的订单的 AsyncOrderUpdateRequestMessage

使用场景 如何实现
用例 1:订单已准备好提货。 向 Google 发送状态为 READY_FOR_PICKUPOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsestimatedFulfillmentTime

JSON

{
  "isInSandbox": true,
  "customPushMessage": {
    "orderUpdate": {
      "actionOrderId": "sample_action_order_id",
      "orderState": {
        "state": "READY_FOR_PICKUP",
        "label": "Order is ready for pickup"
      },
      "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"
      }
    }
  }
}

预制食物状态

以下示例展示了餐馆正在准备的订单的 AsyncOrderUpdateRequestMessage

使用场景 如何实现
用例 1:餐馆正在准备订单。 向 Google 发送状态为 IN_PREPARATIONOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsestimatedFulfillmentTime

JSON

{
  "isInSandbox": true,
  "customPushMessage": {
    "orderUpdate": {
      "actionOrderId": "sample_action_order_id",
      "orderState": {
        "state": "IN_PREPARATION",
        "label": "Order is being prepared"
      },
      "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"
      }
    }
  }
}

订单已更改状态

以下示例演示了对客户订单进行的各种更改的 AsyncOrderUpdateRequestMessage

用例 1:预计履单时间需要更新。 向 Google 发送 OrderUpdate,其中包含订单状态、actionOrderIduserVisibleOrderIdorderManagementAction 和更新后的 estimatedFulfillmentTime
使用情形 2:需要更新订单总价。 向 Google 发送 OrderUpdate,其中包含订单状态、actionOrderIduserVisibleOrderIdorderManagementActionestimatedFulfillmentTime 和更新后的 totalPrice
用例 3:需要更新订单的订单管理操作。 向 Google 发送 OrderUpdate,其中包含订单状态、actionOrderIduserVisibleOrderIdestimatedFulfillmentTime 和更新后的 orderManagementActions

JSON

{
  "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"
        }
      }
  }
}

JSON

{
  "isInSandbox": true,
  "customPushMessage": {
    "orderUpdate": {
      "actionOrderId": "sample_action_order_id",
      "orderState": {
        "state": "CONFIRMED",
        "label": "Provider confirmed"
      },
      "receipt": {
        "userVisibleOrderId": "userVisibleId1234"
      },
      "totalPrice": {
        "type": "ESTIMATE",
        "amount": {
          "currencyCode": "USD",
          "units": "20",
          "nanos": 500000000
        }
      },
      "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"
      }
    }
  }
}

JSON

{
  "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"
        }
      }
  }
}