Expired Boarding passes  |  Google for Developers (2024)

Table of Contents
Java PHP Python C# Node.js Go

In Google Wallet, there's an "Expired passes" section that contains all archived or inactive passes.

A pass is moved to the "Expired passes" section if at least one of the following conditions is true:

The following code sample demonstrates expiring a pass object using the GoogleWallet API.

Java

To start your integration in Java, refer to our complete code samples on Github.

/** * Expire an object. * * <p>Sets the object's state to Expired. If the valid time interval is already set, the pass will * expire automatically up to 24 hours after. * * @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 expireObject(String issuerId, String objectSuffix) throws IOException { // Check if the object exists try { 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); } } // Patch the object, setting the pass as expired FlightObject patchBody = new FlightObject().setState("EXPIRED"); FlightObject response = service .flightobject() .patch(String.format("%s.%s", issuerId, objectSuffix), patchBody) .execute(); System.out.println("Object expiration response"); System.out.println(response.toPrettyString()); return response.getId();}

PHP

To start your integration in PHP, refer to our complete code samples on Github.

/** * Expire an object. * * Sets the object's state to Expired. If the valid time interval is * already set, the pass will expire automatically up to 24 hours after. * * @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 expireObject(string $issuerId, string $objectSuffix){ // Check if the object exists try { $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}"; } } // Patch the object, setting the pass as expired $patchBody = new Google_Service_Walletobjects_FlightObject([ 'state' => 'EXPIRED' ]); $response = $this->service->flightobject->patch("{$issuerId}.{$objectSuffix}", $patchBody); print "Object expiration response\n"; print_r($response); return $response->id;}

Python

To start your integration in Python, refer to our complete code samples on Github.

def expire_object(self, issuer_id: str, object_suffix: str) -> str: """Expire an object. Sets the object's state to Expired. If the valid time interval is already set, the pass will expire automatically up to 24 hours after. 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 response = self.http_client.get( url=f'{self.object_url}/{issuer_id}.{object_suffix}') if response.status_code == 404: print(f'Object {issuer_id}.{object_suffix} not found!') return f'{issuer_id}.{object_suffix}' elif response.status_code != 200: # Something else went wrong... print(response.text) return f'{issuer_id}.{object_suffix}' # Patch the object, setting the pass as expired patch_body = {'state': 'EXPIRED'} response = self.http_client.patch( url=f'{self.object_url}/{issuer_id}.{object_suffix}', json=patch_body) print('Object expiration response') print(response.text) return response.json().get('id')

C#

To start your integration in C#, refer to our complete code samples on Github.

/// <summary>/// Expire an object./// <para />/// Sets the object's state to Expired. If the valid time interval is already/// set, the pass will expire automatically up to 24 hours after./// </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 ExpireObject(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}"; } } // Patch the object, setting the pass as expired FlightObject patchBody = new FlightObject { State = "EXPIRED" }; responseStream = service.Flightobject .Patch(patchBody, $"{issuerId}.{objectSuffix}") .ExecuteAsStream(); responseReader = new StreamReader(responseStream); jsonResponse = JObject.Parse(responseReader.ReadToEnd()); Console.WriteLine("Object expiration response"); Console.WriteLine(jsonResponse.ToString()); return $"{issuerId}.{objectSuffix}";}

Node.js

To start your integration in Node, refer to our complete code samples on Github.

/** * Expire an object. * * Sets the object's state to Expired. If the valid time interval is * already set, the pass will expire automatically up to 24 hours after. * * @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 expireObject(issuerId, objectSuffix) { let response; // Check if the object exists try { response = await this.httpClient.request({ url: `${this.objectUrl}/${issuerId}.${objectSuffix}`, method: 'GET' }); } 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}`; } } // Patch the object, setting the pass as expired let patchBody = { 'state': 'EXPIRED' }; response = await this.httpClient.request({ url: `${this.objectUrl}/${issuerId}.${objectSuffix}`, method: 'PATCH', data: patchBody }); console.log('Object expiration response'); console.log(response); return `${issuerId}.${objectSuffix}`;}

Go

To start your integration in Go, refer to our complete code samples on github code samples on Github.

// Expire an object.//// Sets the object's state to Expired. If the valid time interval is// already set, the pass will expire automatically up to 24 hours after.func (d *demoFlight) expireObject(issuerId, objectSuffix string) {patchBody := `{"state": "EXPIRED"}`url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))res, err := d.httpClient.Do(req)if err != nil {fmt.Println(err)} else {b, _ := io.ReadAll(res.Body)fmt.Printf("Object expiration response:\n%s\n", b)}}
Expired Boarding passes  |  Google for Developers (2024)
Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 6168

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.