实现高级订单更新

客户提交订单后,您可以向 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。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfo 和错误类型 NO_CAPACITYfoodOrderError
用例 2:订单被拒,因为司机不可用或送货地址超出范围。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfo 和错误类型 OUT_OF_SERVICE_AREAfoodOrderError
用例 3:订单因餐厅意外停业或停业而被拒。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfo 和错误类型 CLOSEDfoodOrderError
用例 4:订单遭拒,因为部分商品缺货。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActionsrejectionInfo 和错误类型 AVAILABILITY_CHANGEDfoodOrderError
用例 5:订单因未知或未分类原因遭拒。 向 Google 发送状态为 REJECTEDOrderUpdate。它必须具有 actionOrderIduserVisibleOrderIdorderManagementActions 以及 rejectionInfo 作为错误类型 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"
        }
      }
  }
}