持續更新票證是與消費者互動並打造良好體驗的重要方式。
有兩項資源可更新:FlightClass
和 FlightObject
。
最佳做法
以下清單提供更新登機證類別和物件時的實用資訊:
- 如要更新整個類別或物件,請傳送
update
要求。如要更新類別或物件的少量欄位,請傳送patch
要求。 - 當您發出
update
要求時,系統會更新整個物件或類別。也就是說,凡是未包含在要求中的欄位都會遭到清除。傳送update
要求之前,建議您先傳送GET
要求,確保使用最新版本,且所有需要的欄位均包含在要求中。 - 提出
patch
要求時,只有修補的欄位會更新。傳送patch
要求之前,請考慮傳送GET
要求,以比較您的變更與最新版本。 - 提出
patch
要求更新陣列時,系統會將原始陣列替換為要求主體中包含的陣列。您無法個別修改陣列中的元素。 - 在某些情況下,您可能不知道變更的時間或觸發更新的時機。請考慮為所有類別和物件定期安排
update
或patch
要求。
更新票證類別
使用 Google 錢包商家主控台
您可以直接在 Google Pay 和錢包主控台中修改票證類別 (而非物件)。
- 前往控制台
- 選取「Google Wallet API」
- 選取您想修改的課程
- 選取 [編輯]
- 更新類別屬性
- 選取 [儲存]
儲存變更後,系統會自動為所有航班持有者更新該類別。
使用 Google Wallet API
如果更新 FlightClass
,所有使用這個類別佈建登機證的使用者都會受到影響。舉例來說,如要更新登機證的標誌,您需要在下列任一端點向 Google Wallet API 提交 update
或 patch
要求。resourceId
值將是類別 ID (ISSUER_ID.CLASS_SUFFIX
)。
# Update
PUT https://walletobjects.googleapis.com/walletobjects/v1/flightclass/{resourceId}
# Patch
PATCH https://walletobjects.googleapis.com/walletobjects/v1/flightclass/{resourceId}
詳情請參閱 API 參考資料。
Java
如要開始在 Java 中整合,請參閱 GitHub 上完整的程式碼範例。
/** * Update a class. * * <p><strong>Warning:</strong> This replaces all existing class attributes! * * @param issuerId The issuer ID being used for this request. * @param classSuffix Developer-defined unique ID for this pass class. * @return The pass class ID: "{issuerId}.{classSuffix}" */ public String updateClass(String issuerId, String classSuffix) throws IOException { FlightClass updatedClass; // Check if the class exists try { updatedClass = service.flightclass().get(String.format("%s.%s", issuerId, classSuffix)).execute(); } catch (GoogleJsonResponseException ex) { if (ex.getStatusCode() == 404) { // Class does not exist System.out.printf("Class %s.%s not found!%n", issuerId, classSuffix); return String.format("%s.%s", issuerId, classSuffix); } else { // Something else went wrong... ex.printStackTrace(); return String.format("%s.%s", issuerId, classSuffix); } } // Class exists // Update the class by adding a homepage updatedClass.setHomepageUri( new Uri() .setUri("https://developers.google.com/wallet") .setDescription("Homepage description")); // Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates updatedClass.setReviewStatus("UNDER_REVIEW"); FlightClass response = service .flightclass() .update(String.format("%s.%s", issuerId, classSuffix), updatedClass) .execute(); System.out.println("Class update response"); System.out.println(response.toPrettyString()); return response.getId(); }
PHP
如要開始在 PHP 中整合,請參閱完整的 GitHub 程式碼範例。
/** * Update a class. * * **Warning:** This replaces all existing class attributes! * * @param string $issuerId The issuer ID being used for this request. * @param string $classSuffix Developer-defined unique ID for this pass class. * * @return string The pass class ID: "{$issuerId}.{$classSuffix}" */ public function updateClass(string $issuerId, string $classSuffix) { // Check if the class exists try { $updatedClass = $this->service->flightclass->get("{$issuerId}.{$classSuffix}"); } catch (Google\Service\Exception $ex) { if (!empty($ex->getErrors()) && $ex->getErrors()[0]['reason'] == 'classNotFound') { // Class does not exist print("Class {$issuerId}.{$classSuffix} not found!"); return "{$issuerId}.{$classSuffix}"; } else { // Something else went wrong... print_r($ex); return "{$issuerId}.{$classSuffix}"; } } // Update the class by adding a homepage $updatedClass->setHomepageUri(new Uri([ 'uri' => 'https://developers.google.com/wallet', 'description' => 'Homepage description' ])); // Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates $updatedClass->setReviewStatus('UNDER_REVIEW'); $response = $this->service->flightclass->update("{$issuerId}.{$classSuffix}", $updatedClass); print "Class update response\n"; print_r($response); return $response->id; }
Python
如要開始在 Python 中整合,請參閱 GitHub 上完整的程式碼範例。
def update_class(self, issuer_id: str, class_suffix: str) -> str: """Update a class. **Warning:** This replaces all existing class attributes! Args: issuer_id (str): The issuer ID being used for this request. class_suffix (str): Developer-defined unique ID for this pass class. Returns: The pass class ID: f"{issuer_id}.{class_suffix}" """ # Check if the class exists try: response = self.client.flightclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute() except HttpError as e: if e.status_code == 404: print(f'Class {issuer_id}.{class_suffix} not found!') return f'{issuer_id}.{class_suffix}' else: # Something else went wrong... print(e.error_details) return f'{issuer_id}.{class_suffix}' # Class exists updated_class = response # Update the class by adding a homepage updated_class['homepageUri'] = { 'uri': 'https://developers.google.com/wallet', 'description': 'Homepage description' } # Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates updated_class['reviewStatus'] = 'UNDER_REVIEW' response = self.client.flightclass().update( resourceId=f'{issuer_id}.{class_suffix}', body=updated_class).execute() print('Class update response') print(response) return f'{issuer_id}.{class_suffix}'
C#
如要開始在 C# 中整合,請參閱 GitHub 上完整的程式碼範例。
/// <summary> /// Update a class. /// <para /> /// <strong>Warning:</strong> This replaces all existing class attributes! /// </summary> /// <param name="issuerId">The issuer ID being used for this request.</param> /// <param name="classSuffix">Developer-defined unique ID for this pass class.</param> /// <returns>The pass class ID: "{issuerId}.{classSuffix}"</returns> public string UpdateClass(string issuerId, string classSuffix) { // Check if the class exists Stream responseStream = service.Flightclass .Get($"{issuerId}.{classSuffix}") .ExecuteAsStream(); StreamReader responseReader = new StreamReader(responseStream); JObject jsonResponse = JObject.Parse(responseReader.ReadToEnd()); if (jsonResponse.ContainsKey("error")) { if (jsonResponse["error"].Value<int>("code") == 404) { // Class does not exist Console.WriteLine($"Class {issuerId}.{classSuffix} not found!"); return $"{issuerId}.{classSuffix}"; } else { // Something else went wrong... Console.WriteLine(jsonResponse.ToString()); return $"{issuerId}.{classSuffix}"; } } // Class exists FlightClass updatedClass = JsonConvert.DeserializeObject<FlightClass>(jsonResponse.ToString()); // Update the class by adding a homepage updatedClass.HomepageUri = new Google.Apis.Walletobjects.v1.Data.Uri { UriValue = "https://developers.google.com/wallet", Description = "Homepage description" }; // Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates updatedClass.ReviewStatus = "UNDER_REVIEW"; responseStream = service.Flightclass .Update(updatedClass, $"{issuerId}.{classSuffix}") .ExecuteAsStream(); responseReader = new StreamReader(responseStream); jsonResponse = JObject.Parse(responseReader.ReadToEnd()); Console.WriteLine("Class update response"); Console.WriteLine(jsonResponse.ToString()); return $"{issuerId}.{classSuffix}"; }
Node.js
如要開始在節點中整合,請參閱完整的 GitHub 程式碼範例。
/** * Update a class. * * **Warning:** This replaces all existing class attributes! * * @param {string} issuerId The issuer ID being used for this request. * @param {string} classSuffix Developer-defined unique ID for this pass class. * * @returns {string} The pass class ID: `${issuerId}.${classSuffix}` */ async updateClass(issuerId, classSuffix) { let response; // Check if the class exists try { response = await this.client.flightclass.get({ resourceId: `${issuerId}.${classSuffix}` }); } catch (err) { if (err.response && err.response.status === 404) { console.log(`Class ${issuerId}.${classSuffix} not found!`); return `${issuerId}.${classSuffix}`; } else { // Something else went wrong... console.log(err); return `${issuerId}.${classSuffix}`; } } // Class exists let updatedClass = response.data; // Update the class by adding a homepage updatedClass['homepageUri'] = { 'uri': 'https://developers.google.com/wallet', 'description': 'Homepage description' }; // Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates updatedClass['reviewStatus'] = 'UNDER_REVIEW'; response = await this.client.flightclass.update({ resourceId: `${issuerId}.${classSuffix}`, requestBody: updatedClass }); console.log('Class update response'); console.log(response); return `${issuerId}.${classSuffix}`; }
更新票證物件
更新個別 FlightObject
只會影響已佈建該特定物件的使用者。建議您定期更新個別登機證,以反映會對客戶造成影響,並讓他們持續參與。resourceId
值是物件 ID (ISSUER_ID.OBJECT_SUFFIX
)。
# Update
PUT https://walletobjects.googleapis.com/walletobjects/v1/flightobject/{resourceId}
# Patch
PATCH https://walletobjects.googleapis.com/walletobjects/v1/flightobject/{resourceId}
詳情請參閱 API 參考資料。
Java
如要開始在 Java 中整合,請參閱 GitHub 上完整的程式碼範例。
/** * Update an object. * * <p><strong>Warning:</strong> This replaces all existing object attributes! * * @param issuerId The issuer ID being used for this request. * @param objectSuffix Developer-defined unique ID for this pass object. * @return The pass object ID: "{issuerId}.{objectSuffix}" */ public String updateObject(String issuerId, String objectSuffix) throws IOException { FlightObject updatedObject; // Check if the object exists try { updatedObject = service.flightobject().get(String.format("%s.%s", issuerId, objectSuffix)).execute(); } catch (GoogleJsonResponseException ex) { if (ex.getStatusCode() == 404) { // Object does not exist System.out.printf("Object %s.%s not found!%n", issuerId, objectSuffix); return String.format("%s.%s", issuerId, objectSuffix); } else { // Something else went wrong... ex.printStackTrace(); return String.format("%s.%s", issuerId, objectSuffix); } } // Object exists // Update the object by adding a link Uri newLink = new Uri() .setUri("https://developers.google.com/wallet") .setDescription("New link description"); if (updatedObject.getLinksModuleData() == null) { // LinksModuleData was not set on the original object updatedObject.setLinksModuleData(new LinksModuleData().setUris(List.of(newLink))); } else { updatedObject.getLinksModuleData().getUris().add(newLink); } FlightObject response = service .flightobject() .update(String.format("%s.%s", issuerId, objectSuffix), updatedObject) .execute(); System.out.println("Object update response"); System.out.println(response.toPrettyString()); return response.getId(); }
PHP
如要開始在 PHP 中整合,請參閱完整的 GitHub 程式碼範例。
/** * Update an object. * * **Warning:** This replaces all existing object attributes! * * @param string $issuerId The issuer ID being used for this request. * @param string $objectSuffix Developer-defined unique ID for this pass object. * * @return string The pass object ID: "{$issuerId}.{$objectSuffix}" */ public function updateObject(string $issuerId, string $objectSuffix) { // Check if the object exists try { $updatedObject = $this->service->flightobject->get("{$issuerId}.{$objectSuffix}"); } catch (Google\Service\Exception $ex) { if (!empty($ex->getErrors()) && $ex->getErrors()[0]['reason'] == 'resourceNotFound') { print("Object {$issuerId}.{$objectSuffix} not found!"); return "{$issuerId}.{$objectSuffix}"; } else { // Something else went wrong... print_r($ex); return "{$issuerId}.{$objectSuffix}"; } } // Update the object by adding a link $newLink = new Uri([ 'uri' => 'https://developers.google.com/wallet', 'description' => 'New link description' ]); $linksModuleData = $updatedObject->getLinksModuleData(); if (is_null($linksModuleData)) { // LinksModuleData was not set on the original object $linksModuleData = new LinksModuleData([ 'uris' => [] ]); } $uris = $linksModuleData->getUris(); array_push( $uris, $newLink ); $linksModuleData->setUris($uris); $updatedObject->setLinksModuleData($linksModuleData); $response = $this->service->flightobject->update("{$issuerId}.{$objectSuffix}", $updatedObject); print "Object update response\n"; print_r($response); return $response->id; }
Python
如要開始在 Python 中整合,請參閱 GitHub 上完整的程式碼範例。
def update_object(self, issuer_id: str, object_suffix: str) -> str: """Update an object. **Warning:** This replaces all existing object attributes! Args: issuer_id (str): The issuer ID being used for this request. object_suffix (str): Developer-defined unique ID for the pass object. Returns: The pass object ID: f"{issuer_id}.{object_suffix}" """ # Check if the object exists try: response = self.client.flightobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute() except HttpError as e: if e.status_code == 404: print(f'Object {issuer_id}.{object_suffix} not found!') return f'{issuer_id}.{object_suffix}' else: # Something else went wrong... print(e.error_details) return f'{issuer_id}.{object_suffix}' # Object exists updated_object = response # Update the object by adding a link new_link = { 'uri': 'https://developers.google.com/wallet', 'description': 'New link description' } if not updated_object.get('linksModuleData'): updated_object['linksModuleData'] = {'uris': []} updated_object['linksModuleData']['uris'].append(new_link) response = self.client.flightobject().update( resourceId=f'{issuer_id}.{object_suffix}', body=updated_object).execute() print('Object update response') print(response) return f'{issuer_id}.{object_suffix}'
C#
如要開始在 C# 中整合,請參閱 GitHub 上完整的程式碼範例。
/// <summary> /// Update an object. /// <para /> /// <strong>Warning:</strong> This replaces all existing class attributes! /// </summary> /// <param name="issuerId">The issuer ID being used for this request.</param> /// <param name="objectSuffix">Developer-defined unique ID for this pass object.</param> /// <returns>The pass object ID: "{issuerId}.{objectSuffix}"</returns> public string UpdateObject(string issuerId, string objectSuffix) { // Check if the object exists Stream responseStream = service.Flightobject .Get($"{issuerId}.{objectSuffix}") .ExecuteAsStream(); StreamReader responseReader = new StreamReader(responseStream); JObject jsonResponse = JObject.Parse(responseReader.ReadToEnd()); if (jsonResponse.ContainsKey("error")) { if (jsonResponse["error"].Value<int>("code") == 404) { // Object does not exist Console.WriteLine($"Object {issuerId}.{objectSuffix} not found!"); return $"{issuerId}.{objectSuffix}"; } else { // Something else went wrong... Console.WriteLine(jsonResponse.ToString()); return $"{issuerId}.{objectSuffix}"; } } // Object exists FlightObject updatedObject = JsonConvert.DeserializeObject<FlightObject>(jsonResponse.ToString()); // Update the object by adding a link Google.Apis.Walletobjects.v1.Data.Uri newLink = new Google.Apis.Walletobjects.v1.Data.Uri { UriValue = "https://developers.google.com/wallet", Description = "New link description" }; if (updatedObject.LinksModuleData == null) { // LinksModuleData was not set on the original object updatedObject.LinksModuleData = new LinksModuleData { Uris = new List<Google.Apis.Walletobjects.v1.Data.Uri>() }; } updatedObject.LinksModuleData.Uris.Add(newLink); responseStream = service.Flightobject .Update(updatedObject, $"{issuerId}.{objectSuffix}") .ExecuteAsStream(); responseReader = new StreamReader(responseStream); jsonResponse = JObject.Parse(responseReader.ReadToEnd()); Console.WriteLine("Object update response"); Console.WriteLine(jsonResponse.ToString()); return $"{issuerId}.{objectSuffix}"; }
Node.js
如要開始在節點中整合,請參閱完整的 GitHub 程式碼範例。
/** * Update an object. * * **Warning:** This replaces all existing object attributes! * * @param {string} issuerId The issuer ID being used for this request. * @param {string} objectSuffix Developer-defined unique ID for the pass object. * * @returns {string} The pass object ID: `${issuerId}.${objectSuffix}` */ async updateObject(issuerId, objectSuffix) { let response; // Check if the object exists try { response = await this.client.flightobject.get({ resourceId: `${issuerId}.${objectSuffix}` }); } catch (err) { if (err.response && err.response.status === 404) { console.log(`Object ${issuerId}.${objectSuffix} not found!`); return `${issuerId}.${objectSuffix}`; } else { // Something else went wrong... console.log(err); return `${issuerId}.${objectSuffix}`; } } // Object exists let updatedObject = response.data; // Update the object by adding a link let newLink = { 'uri': 'https://developers.google.com/wallet', 'description': 'New link description' } if (updatedObject['linksModuleData'] === undefined) { updatedObject['linksModuleData'] = { 'uris': [newLink] }; } else { updatedObject['linksModuleData']['uris'].push(newLink); } response = await this.client.flightobject.update({ resourceId: `${issuerId}.${objectSuffix}`, requestBody: updatedObject }); console.log('Object update response'); console.log(response); return `${issuerId}.${objectSuffix}`; }
航班更新的資料來源
不論 class.localScheduledDepartureDateTime
的時間是在過去 24 小時內,還是在接下來的 48 小時內,系統都會向使用者顯示航班狀態資訊卡。此時,Google 錢包會顯示 Google 航班/機票的資料或 Google 錢包票證中的資訊。使用哪一個來源取決於下列因素:
-
如果未提供
class.localEstimatedOrActualDepartureDateTime
,系統就會使用 Google 航班/機票。並忽略您設定的所有class.flightStatus
。舉例來說,如果航班誤點,使用者會在 Google 錢包應用程式的「首頁」分頁中看到一張卡片,其中顯示新的出發時間。同時,使用者也會在「票證」分頁中看到類似的誤點資訊卡。
- 如果您只提供
class.localEstimatedOrActualDepartureDateTime
但未提供class.flightStatus
,系統就會根據您輸入的時間判斷航班是否誤點,接著,系統會根據下列邏輯,在資訊卡中向使用者顯示航班狀態:- 如果
class.localEstimatedOrActualDepartureDateTime
晚於class.localScheduledDepartureDateTime
,使用者就會在卡片上看到該航班列為誤點。 - 如果
class.localEstimatedOrActualDepartureDateTime
沒有大於class.localScheduledDepartureDateTime
,使用者就會在卡片上看到航班資訊,但不會看到任何狀態訊息。
- 如果
如果您不想使用 Google 航班/機票做為航班資訊來源,請務必為 FlightClass
提供 flightStatus
、localScheduledDepartureDateTime
和 localEstimatedOrActualDepartureDateTime
。如此一來,資料卡上就只會使用您提供的資料。另外還有一種做法:只要將 FlightClass
的 IATA 代碼改為 ICAO 航空公司代碼,系統就不會使用 Google 航班/機票做為航班資訊來源。
如果特定欄位的資料有所改變,使用者就會收到與變更相關的推播通知。詳情請參閱接收有關航班的最新通知。