订单预览时未正确计算小计

Subtotal is not calculated correctly at order preview

我想使用 Dialogflow 和 Google Assistant 以及 Google Transactions API 创建一个聊天机器人,以使用户能够订购一些商品。现在我的代理包含以下四个意图:

我正在使用 Dialogflow Json 而不是 Node.js 将我的代理与事务连接 API。我想通过最终用户通过使用 Google 操作的 actions.intent.TRANSACTION_DECISION 操作满足交易要求,为用户构建购物车和订单。出于这个原因,遵循 Google 文档,当 Int3 被触发时,我正在使用连接 Google Assistant 我的后端的 webhook,它发回以下 json (触发actions.intent.TRANSACTION_DECISION) :

  {
    "fulfillmentText": "This is your order preview:",
    "payload": {
        "google": {
            "expectUserResponse": true,
            "isSsml": false,
            "noInputPrompts": [],
            "systemIntent": {
                "data": {
                    "@type": "type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec",
                    "orderOptions": {
                        "requestDeliveryAddress": true
                    },
                    "paymentOptions": {
                        "actionProvidedOptions": {
                            "displayName": "VISA **** **** **** 3235",
                            "paymentType": "PAYMENT_CARD"
                        }
                    },
                    "proposedOrder": {
                        "cart": {
                            "lineItems": [
                                {
                                    "description": "Book",
                                    "id": "1",
                                    "name": "Book",
                                    "price": {
                                        "amount": {
                                            "currencyCode": "USD",
                                            "nanos": 0,
                                            "units": 31
                                        },
                                        "type": "ACTUAL"
                                    },
                                    "quantity": 2,
                                    "subLines": [],
                                    "type": "REGULAR"
                                }
                            ],
                            "merchant": {
                                "id": "Amazon",
                                "name": "Amazon"
                            },
                            "otherItems": []
                        },
                        "id": "<UNIQUE_ORDER_ID>",
                        "otherItems": [
                            {
                                "id": "Subtotal",
                                "name": "Subtotal",
                                "price": {
                                    "amount": {
                                        "currencyCode": "USD",
                                        "nanos": 0,
                                        "units": 62
                                    },
                                    "type": "ACTUAL"
                                },
                                "type": "SUBTOTAL"
                            },
                            {
                                "id": "Delivery fees",
                                "name": "Delivery fees",
                                "price": {
                                    "amount": {
                                        "currencyCode": "USD",
                                        "nanos": 0,
                                        "units": 10
                                    },
                                    "type": "ACTUAL"
                                },
                                "type": "FEE"
                            }
                        ],
                        "totalPrice": {
                            "amount": {
                                "currencyCode": "USD",
                                "units": 72
                            },
                            "type": "ACTUAL"
                        }
                    }
                },
                "intent": "actions.intent.TRANSACTION_DECISION"
            }
        }
    }
}

但是,我在 Google Assistant 模拟器上遇到以下错误:

MalformedResponse
expected_inputs[0].possible_intents[0].input_value_data.transaction_decision_value_spec.proposed_order: subtotal price is not sum of regular lineItems. Expected-> Sum of line item price: units: 31 nanos: 0 currency: USD Actual-> Provided total price: units: 62 nanos: 0 currency: USD.

MalformedResponse
expected_inputs[0].possible_intents[0].input_value_data.transaction_decision_value_spec.proposed_order: total price is not sum of lineItems and otherItems. Expected-> Sum of line item price: units: 42 nanos: 0 currency: USD Actual-> Provided total price: units: 72 nanos: 0 currency: USD.

为什么我会收到此错误,因为我在相应的 lineItem?

中指定了 "quantity": 2

很明显,小计应该是units: 62,因为我订购了"quantity": 2件产品,每件价格units: 31...

最终订单预览如下所示(这是从 Google 文档示例中借用的):

答案似乎在错误消息中:API 期望每个订单项的价格是该订单项中所有项目的总和,而不是数量价格(相关错误短语:"Sum of line item price").更正后的 JSON 应如下所示:

{
  "fulfillmentText": "This is your order preview:",
  "payload": {
    "google": {
      "expectUserResponse": true,
      "isSsml": false,
      "noInputPrompts": [],
      "systemIntent": {
        "data": {
          "@type": "type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec",
          "orderOptions": {
            "requestDeliveryAddress": true
          },
          "paymentOptions": {
            "actionProvidedOptions": {
              "displayName": "VISA **** **** **** 3235",
              "paymentType": "PAYMENT_CARD"
            }
          },
          "proposedOrder": {
            "cart": {
              "lineItems": [
                {
                  "description": "Book",
                  "id": "1",
                  "name": "Book",
                  "price": {
                    "amount": {
                      "currencyCode": "USD",
                      "nanos": 0,
                      "units": 62
                    },
                    "type": "ACTUAL"
                  },
                  "quantity": 2,
                  "subLines": [],
                  "type": "REGULAR"
                }
              ],
              "merchant": {
                "id": "Amazon",
                "name": "Amazon"
              },
              "otherItems": []
            },
            "id": "<UNIQUE_ORDER_ID>",
            "otherItems": [
              {
                "id": "Subtotal",
                "name": "Subtotal",
                "price": {
                  "amount": {
                    "currencyCode": "USD",
                    "nanos": 0,
                    "units": 62
                  },
                  "type": "ACTUAL"
                },
                "type": "SUBTOTAL"
              },
              {
                "id": "Delivery fees",
                "name": "Delivery fees",
                "price": {
                  "amount": {
                    "currencyCode": "USD",
                    "nanos": 0,
                    "units": 10
                  },
                  "type": "ACTUAL"
                },
                "type": "FEE"
              }
            ],
            "totalPrice": {
              "amount": {
                "currencyCode": "USD",
                "units": 72
              },
              "type": "ACTUAL"
            }
          }
        },
        "intent": "actions.intent.TRANSACTION_DECISION"
      }
    }
  }
}