Eşzamansız sipariş güncellemesi

Bir müşteri yemek siparişi gönderdikten sonra değişikliği bize bildirmek için Sipariş Verme Uçtan Uca hizmetine sipariş güncelleme mesajı gönderebilirsiniz.

Sipariş güncellemeleri göndermenin yaygın nedenlerinden bazıları şunlardır:

  • Siparişin tahmini tamamlanma süresi kullanılabilir hale gelir veya değişir.
  • Siparişin durumu değiştiğinde.
  • Sipariş artık karşılanamıyor.
  • Siparişe dahil olan menü öğesinin fiyatı değişti.
  • Müşteri, siparişini yönetmek için müşteri desteği veya restoran telefon numarası gibi yeni bir yönteme sahip.
  • Siparişin makbuzu hazır olur.

Sonraki bölümlerde, sipariş güncellemeleri kullanılarak bu farklı senaryoların nasıl ele alınacağı hakkında ayrıntılar verilmektedir.

Geçiş siparişi durumları

Bir siparişte altı olası durum söz konusudur. Bu durumlar ve olası geçişleri aşağıdaki şemada özetlenmiştir:

Sipariş durumu geçişleri

Bir müşteri ilk kez sipariş gönderdiğinde, sipariş CREATED, CONFIRMED veya REJECTED durumuyla başlar. Durum geçişi geçerli olduğu sürece, bir siparişin durumunu güncellemek için sipariş güncelleme mesajı gönderebilirsiniz. CREATED durumu, iş ortağının platformu siparişi hemen onaylayamadığında veya reddedemediğinde kullanılır. Kullanım alanına örnek olarak müşterinin bir teslimat toplayıcı aracılığıyla sipariş vermesi verilebilir. Teslimat toplayıcı, teslimatı Google'dan alır ve toplayıcı, bilgileri restorana gönderir. Restoran, sipariş uygunluğunu aldıktan ve onayladıktan sonra eyalet artık CONFIRMED, aksi takdirde REJECTED olabilir.

CONFIRMED durumundaki bir sipariş daha sonra IN_PREPARATION durumuna taşınır. Siparişin teslim alma mı yoksa teslimat için mi olduğuna bağlı olarak READY_FOR_PICKUP veya IN_TRANSIT durumunu kullanın. Yemek teslim edildiğinde veya teslim alındığında sipariş FULFILLED durumuna ayarlanır.

Müşterilerin siparişleri iptal etmesine izin veriyorsanız CANCELLED durumunu kullanabilirsiniz. Sipariş CREATED, CONFIRMED, IN_PREPARATION, READY_FOR_PICKUP veya IN_TRANSIT durumunda iptal edilebilir. Sipariş Uçtan Uca hizmetiniz iptal politikanıza ve iptal anındaki ödemelerin durumuna bağlı olarak geri ödeme yapmalıdır.

Sipariş uçtan uca hizmetinizin mevcut tüm durumları ve geçişleri desteklemesi gerekmez. Ancak siparişin son durumu FULFILLED, REJECTED veya CANCELLED olmalıdır.

Tahmini sipariş karşılama süresi sağlama

Kullanıcılara, siparişlerinin teslim alınmaya (veya teslim edilmeye) hazır olacağı tahmini bir zaman aralığı sunabilirsiniz. Bir müşterinin siparişinin teslim alınmaya veya teslim edilmeye hazır olacağı tahmini zaman aralığını sağlamak için FoodOrderUpdateExtension alanındaki estimatedFulfillmentTimeIso8601 alanını kullanın.

estimatedFulfillmentTimeIso8601 hizmetini şu saatlerde gönder:

  • Tahmini süre mevcut olduğunda, ideal olarak CREATED veya CONFIRMED durumunda olmalıdır.
  • Tahmini süre değiştiğinde, örneğin sipariş IN_TRANSIT olduğunda daha doğru olmak için tahmini süreyi güncelleme.

Kullanıcı beklentilerini etkili bir şekilde yönetmek için tahminlerinizde muhafazakar olun ve sabit bir tarih ve saat yerine tarih ve zaman aralığı belirtin. Mümkün olduğunda trafik koşulları gibi varyasyonları göz önünde bulundurmalısınız. Örneğin, tahmini teslimat süresinin 13:00 olduğu bir sipariş için tahmini olarak 12:45 (alt sınır) ile 13:15 (üst sınır) arası bir saat gönderebilirsiniz.

Sipariş yönetimi işlemleri sağlama

Sipariş güncellemesi gönderirken, müşterilere siparişlerini yönetmelerine yardımcı olacak kaynaklar OrderManagementAction biçiminde sağlayabilirsiniz. Bir müşterinin sipariş verdikten sonra ilerlemeyi takip etmek, değişiklik yapmak veya siparişini iptal etmek için sizinle ya da siparişi yerine getiren restoranla iletişime geçmesi gerekebilir.

OrderManagementAction, müşterilerin doğrudan cihazlarından e-posta göndermesine, arayabilmesine veya bir URL'ye bağlantı oluşturmasına olanak tanır. OrderManagementAction öğesinde, kullanıcıya gönderdiğiniz e-posta sipariş onayındakiyle aynı bilgileri kullanın.

Sipariş yönetimi işlemleri aşağıdaki türleri içerir:

  • CUSTOMER_SERVICE: Müşterilere, müşteri hizmetleriyle iletişime geçmeleri için işlem sunun. Bu yönetim işlemi türü, sipariş güncellemeleri için gereklidir.
  • EMAIL: Müşterilere, belirttiğiniz e-posta adresine e-posta göndermeleri için bir işlem sunun.
  • CALL: Müşterilere, sağladıkları telefon numarasını aramaları için harekete geçin.
  • VIEW_DETAIL: Müşterilere siparişlerinin ayrıntılarını görüntülemeleri için işlem sunun.

Her sipariş güncellemesi en az bir sipariş yönetimi işlemi içermelidir. Ancak sağlanan sipariş yönetimi işlemleri, siparişin durumuna göre değişiklik gösterebilir. Örneğin, bir sipariş CONFIRMED durumundaysa CUSTOMER_SERVICE işlemi müşteri hizmetleri telefon numaranıza yönlendirebilir. Bu sipariş durumu IN_TRANSIT olarak güncellendiğinde CUSTOMER_SERVICE işlemi, sipariş karşılama restoranının telefon numarasına yönlendirebilir.

Sipariş güncellemelerini gönderme

Sipariş Güncellemeleri Uçtan Uca hizmetine sipariş güncellemesi göndermek için AsyncOrderUpdateRequestMessage mesaj türünü kullanırsınız. Google, AsyncOrderUpdateResponseMessage ile yanıt verir. Örneğin, bir müşteriye siparişinin geçerli ve kabul edilmiş olduğunu bildirmek istiyorsanız siparişin durumunu CONFIRMED olarak değiştirmek için Accepted by restaurant etiketiyle AsyncOrderUpdateRequestMessage gönderebilirsiniz.

Sipariş güncelleme şeması

Sipariş güncelleme mesajını ayarlama

Google'a AsyncOrderUpdateRequestMessage gönderirken OrderUpdate alanını kullanarak siparişin durumuyla ilgili bilgileri eklemeniz gerekir.

Aşağıdaki örneklerde her sipariş durumu için örnek bir AsyncOrderUpdateRequestMessage gösterilmektedir:

ONAYLANDI

Bu örnekte, kullanıcıya siparişin bir makbuz ve tahmini teslimat süresiyle onaylandığını bildiren bir sipariş güncelleme isteği örneği gösterilmektedir.

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

REDDEDİLDİ

Bu örnekte, kullanıcıya siparişin bir ret nedeniyle reddedildiğini bildiren örnek bir sipariş güncelleme isteği gösterilmektedir.

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

İPTAL EDİLDİ

Bu örnekte, kullanıcıya siparişin iptal edildiğini bildiren ve iptal nedeninin belirtildiği bir sipariş güncelleme isteği örneği gösterilmektedir.

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

IN_PREPARATION

Bu örnekte, kullanıcıyı yemeğin şu anda hazırlandığını bildiren bir sipariş güncelleme isteği örneği gösterilmektedir.

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

READY_FOR_PICKUP

Bu örnekte, kullanıcıyı yemeğin teslim alınmaya hazır olduğunu bildiren bir sipariş güncelleme isteği örneği gösterilmektedir.

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

IN_TRANSIT

Bu örnekte, kullanıcıyı siparişin gönderim sürecinde olduğu konusunda bilgilendiren ve tahmini teslimat süresiyle birlikte örnek bir sipariş güncelleme isteği gösterilmektedir.

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

TAMAMLANDI

Bu örnekte, kullanıcıya siparişin alındığını veya teslim edildiğini bildiren örnek bir sipariş güncelleme isteği gösterilmektedir:

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

Farklı kullanım alanlarındaki sipariş güncelleme istekleriyle ilgili daha fazla örnek için Gelişmiş sipariş güncellemelerini uygulama başlıklı makaleyi okuyun.

Yetkilendirme jetonu oluştur ve mesajı gönder

Sipariş güncellemeleri bir yetkilendirme jetonu gerektirir. Böylece Sipariş Uçtan Uca hizmeti, mesajın Sipariş Verme Uçtan Uca web hizmetinizden geldiğini doğrulayabilir.

Projenizde sipariş güncellemelerini uygulamak için şu adımları izleyin:

  1. Aşağıdaki adımları uygulayarak bir yetkilendirme jetonu oluşturun:
    1. Hizmet hesabı dosyanızdaki kimlik bilgilerini okumak için Google Kimlik Doğrulama Kitaplığı'nı kullanın.
    2. Şu API kapsamını kullanarak jeton isteyin: https://www.googleapis.com/auth/actions.fulfillment.conversation
  2. Aşağıdaki uç noktaya kimliği doğrulanmış bir HTTP POST isteği göndermek için bu jetonu kullanın: https://actions.googleapis.com/v2/conversations:send
  3. İsteğinizin bir parçası olarak Content-Type başlığını application/json olarak ayarlayın.

Aşağıdaki örneklerde, sipariş güncellemelerinin nasıl uygulanacağı gösterilmektedir:

Node.js

Bu kod, Node.js için Google kimlik doğrulama kitaplığını kullanır.

const {auth} = require('google-auth-library')
const request = require('request');
// The service account client secret file downloaded from the Google Cloud Console
const serviceAccountJson = require('./service-account.json')
// order-update.json is a file that contains the payload
const jsonBody = require('./order-update.json')

/**
 * Get the authorization token using a service account.
 */
async function getAuthToken() {
  let client = auth.fromJSON(serviceAccountJson)
  client.scopes = ['https://www.googleapis.com/auth/actions.fulfillment.conversation']
  const tokens = await client.authorize()
  return tokens.access_token;
}

/**
 * Send an order update request
 */
async function sendOrderUpdate() {
  const token = await getAuthToken()
  request.post({
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    url: 'https://actions.googleapis.com/v2/conversations:send',
    body: jsonBody,
    json: true
  },
  (err, res, body) => {
    if (err) { return console.log(err); }
    console.log(`Response: ${JSON.stringify(res)}`)
  })
}
    

Python

Bu kod, Python için Google kimlik doğrulama kitaplığını kullanır.

from google.oauth2 import service_account
from google.auth.transport.requests import AuthorizedSession
import json

# service-account.json is the service account client secret file downloaded from the
# Google Cloud Console
credentials = service_account.Credentials.from_service_account_file(
    'service-account.json')

scoped_credentials = credentials.with_scopes(
    ['https://www.googleapis.com/auth/actions.fulfillment.conversation'])

authed_session = AuthorizedSession(scoped_credentials)

# order-update.json is a file that contains the payload
json_payload=json.load(open('order-update.json'))

response = authed_session.post(
    'https://actions.googleapis.com/v2/conversations:send',
    json=json_payload)
    

Java

Bu kod, Java için Google kimlik doğrulama kitaplığını kullanır.

/**
 * Get the authorization token using a service account.
 */
private static String getAuthToken() {
  InputStream serviceAccountFile = Example.class.getClassLoader().getResourceAsStream("service-account.json");
  ServiceAccountCredentials.Builder credentialsSimpleBuilder =
      ServiceAccountCredentials.fromStream(serviceAccountFile).toBuilder();
  credentialsSimpleBuilder.setScopes(ImmutableList.of("https://www.googleapis.com/auth/actions.fulfillment.conversation"));
  AccessToken accessToken = credentialsSimpleBuilder.build().refreshAccessToken();
  return accessToken.getTokenValue();
}

/**
 * Send an order update request
 */
public void sendOrderUpdate() {
  String authToken = getAuthToken();
  // Execute POST request
  executePostRequest("https://actions.googleapis.com/v2/conversations:send",
      authToken, "update_order_example.json",);
}
    

Google, hatasız başarılı sipariş güncellemeleri için boş yük içeren bir HTTP 200 yanıtı döndürür. Güncellemenin bozuk olması gibi bir sorun varsa Google bir hata döndürür.