Vòng đời của đơn đặt hàng (sau khi mua)

Sau khi hoàn tất quy trình thanh toán và đặt đơn hàng, bạn phải gửi thông tin cập nhật trạng thái cho Google bằng Webhook. Bạn phải gửi khoá API trong các tham số truy vấn hoặc tiêu đề.

1. Sự kiện Đã tạo đơn đặt hàng

  • Gửi thư: Ngay sau khi đơn đặt hàng được xác nhận (status: processing).
  • Điểm cuối: POST /webhooks/partners/{partner_id}/events/order

Tải trọng: Bạn phải gửi thực thể đơn đặt hàng đầy đủ.

{
  "ucp": { "version": "2026-01-01", "capabilities": [...] },
  "id": "order_789",
  "checkout_id": "checkout_xyz789",
  "line_items": [
    {
      "id": "line_1",
      "item":
        {
          "id": "product_12345",
          "title": "Running Shoes",
          "price": 10000
        },
      "quantity": { "total": 1, "fulfilled": 0 },
      "totals": [
        {"type": "subtotal", "amount": 10000},
        {"type": "total", "amount": 10000}
      ],
      "status": "processing"
    }
  ],
  "fulfillment": {
    "expectations": [
      {
        "id": "exp_1",
        "line_items": [{ "id": "line_1", "quantity": 1 }],
        "method_type": "shipping",
        "destination": {
          "street_address": "123 Main St",
          "address_locality": "Austin",
          "address_region": "TX",
          "address_country": "US",
          "postal_code": "78701"
        },
        "description": "Arrives in 2-3 business days",
        "fulfillable_on": "now"
      }
    ]
  },
  "permalink_url": "https://merchant.example.com/orders/789"
}

2. Thông tin cập nhật về đơn đặt hàng (Vận chuyển/Huỷ)

  • Điều kiện kích hoạt: Khi có thông tin cập nhật về trạng thái đơn đặt hàng (ví dụ: mặt hàng được vận chuyển hoặc bị huỷ).
  • Yêu cầu: Bạn phải gửi lại toàn bộ thực thể đơn đặt hàng, chứ không chỉ gửi một bản cập nhật một phần.

Ví dụ (Đã vận chuyển):

{
  "id": "order_789",
  "checkout_id": "checkout_xyz789",
  // Full line items must be included
  "line_items": [
    {
      "id": "line_1",
      "item":
        {
          "id": "product_12345",
          "title": "Running Shoes",
          "price": 10000
        },
      "quantity": { "total": 1, "fulfilled": 1 },
      "totals": [
        {"type": "subtotal", "amount": 10000},
        {"type": "total", "amount": 10000}
      ],
      "status": "fulfilled"
    }
  ],
  // Updated fulfillment details
  "fulfillment": {
    "events": [
      {
        "id": "evt_1",
        "occurred_at": "2025-01-08T10:30:00Z",
        "type": "shipped",
        "line_items": [{ "id": "line_1", "quantity": 1 }],
        "tracking_number": "123456789",
        "tracking_url": "https://fedex.com/track/123456789",
        "description": "Shipping departed from warehouse"
      }
    ]
  },
  "expectations": {"..."},
  "permalink_url": "https://merchant.example.com/orders/789"
}