Google Wallet REST Samples

repository·main·Indexed 19 days ago

https://github.com/google-wallet/rest-samples

Multi-language implementation samples for the Google Wallet REST APIs to help developers integrate pass management features. Provides demo classes and implementation guides for C#, Go, Java, and Node.js, covering various pass types including event tickets, flight boarding passes, generic passes, gift cards, loyalty programs, offers, and transit passes.

Tokens
15.3K
Snippets
44
Records
57
Agent score
63%

What's inside google-wallet-rest-samples

  1. Overview of Google Wallet Java samples

    main

    The Java samples in this repository provide demo classes for specific Google Wallet pass types. Each class implements methods to perform common tasks such as creating pass classes, updating issuer permissions, and managing pass objects.

    Available pass type implementations:

    • Event tickets: com.google.developers.wallet.rest.DemoEventTicket
    • Flight boarding passes: com.google.developers.wallet.rest.DemoFlight
    • Generic passes: com.google.developers.wallet.rest.DemoGeneric
    • Gift cards: com.google.developers.wallet.rest.DemoGiftCard
    • Loyalty program membership: com.google.developers.wallet.rest.DemoLoyalty
    • Offers and promotions: com.google.developers.wallet.rest.DemoOffer
    • Transit passes: com.google.developers.wallet.rest.DemoTransit
  2. Explore Google Wallet REST API samples by language

    main

    This repository provides standalone implementation samples for the Google Wallet REST APIs across multiple programming languages. Each language directory contains specific examples for different pass types supported by the API.

    Available language samples:

    • Java: ./java/README.md
    • C#: ./dotnet/README.md
    • JavaScript (Node.js): ./nodejs/README.md
    • PHP: ./php/README.md
    • Python: ./python/README.md
    • Go: ./go/README.md
  3. Available Google Wallet Node.js demo classes

    main

    The repository provides specific demo classes for different Google Wallet pass types. Each class implements methods for managing the lifecycle of that specific pass type (e.g., creating classes, updating permissions, and managing objects).

    Pass typeFile
    Event ticketsdemo-eventticket.js
    Flight boarding passesdemo-flight.js
    Generic passesdemo-generic.js
    Gift cardsdemo-giftcard.js
    Loyalty program membershipdemo-loyalty.js
    Offers and promotionsdemo-offer.js
    Transit passesdemo-transit.js
  4. Use Google Wallet Python demo classes

    main

    The repository provides specialized demo classes for different Google Wallet pass types. Each class provides methods to manage the lifecycle of pass classes and pass objects (e.g., creating, updating, patching, and expiring).

    Available Pass Types

    • Event tickets: demo_eventticket.py
    • Flight boarding passes: demo_flight.py
    • Generic passes: demo_generic.py
    • Gift cards: demo_giftcard.py
    • Loyalty program membership: demo_loyalty.py
    • Offers and promotions: demo_offer.py
    • Transit passes: demo_transit.py
  5. Available Google Wallet C# pass type demos

    main

    The dotnet directory contains demo classes for specific Google Wallet pass types. Each class implements methods for managing the lifecycle of that pass type (e.g., creating classes, updating permissions, etc.).

    Pass typeImplementation File
    Event ticketsDemoEventTicket.cs
    Flight boarding passesDemoFlight.cs
    Generic passesDemoGeneric.cs
    Gift cardsDemoGiftCard.cs
    Loyalty program membershipDemoLoyalty.cs
    Offers and promotionsDemoOffer.cs
    Transit passesDemoTransit.cs
  6. What is covered in the Google Wallet samples

    main

    The samples in this repository are designed to demonstrate the full lifecycle of managing Google Wallet passes. Each sample typically covers the following workflows:

    • Authentication: Using a Google Cloud service account.
    • Pass Class Management: Creating, updating, patching, and adding messages to a pass class.
    • Pass Object Management: Creating, updating, patching, adding messages to, and expiring a pass object.
    • User Integration: Creating a signed JWT and generating an "Add to Google Wallet" URL.
    • Performance: Performing batch API calls to optimize throughput.
  7. How to use the Google Wallet Java code samples

    main

    Follow these steps to run the samples:

    1. Open the java project folder in your IDE.
    2. Build the project to install necessary dependencies.
    3. Import a demo class (e.g., DemoEventTicket) and call its methods to perform operations like creating classes, updating objects, or generating 'Add to Google Wallet' JWT links.
    // Create a demo class instance
    // Creates the authenticated HTTP client
    com.google.developers.wallet.rest.DemoEventTicket demo = new com.google.developers.wallet.rest.DemoEventTicket();
    
    // Create a pass class
    demo.createClass("issuer_id", "class_suffix");
    
    // Update a pass class
    demo.updateClass("issuer_id", "class_suffix");
    
    // Patch a pass class
    demo.patchClass("issuer_id", "class_suffix");
    
    // Add a message to a pass class
    demo.addClassMessage("issuer_id", "class_suffix", "header", "body");
    
    // Create a pass object
    demo.createObject("issuer_id", "class_suffix", "object_suffix");
    
    // Update a pass object
    demo.updateObject("issuer_id", "object_suffix");
    
    // Patch a pass object
    demo.patchObject("issuer_id", "object_suffix");
    
    // Add a message to a pass object
    demo.addObjectMessage("issuer_id", "object_suffix", "header", "body");
    
    // Expire a pass object
    demo.expireObject("issuer_id", "object_suffix");
    
    // Generate an Add to Google Wallet link that creates a new pass class and object
    demo.createJWTNewObjects("issuer_id", "class_suffix", "object_suffix");
    
    // Generate an Add to Google Wallet link that references existing pass object(s)
    demo.createJWTExistingObjects("issuer_id");
    
    // Create pass objects in batch
    demo.batchCreateObjects("issuer_id", "class_suffix");
  8. Set up Google Wallet PHP samples

    main

    To use the Google Wallet PHP samples, ensure you meet the following requirements and follow the installation steps.

    Prerequisites

    Installation

    Run the following command from the directory containing composer.json to install the necessary dependencies:

    composer install
  9. Set up Google Wallet C# samples

    main

    To use the Google Wallet C# samples, ensure you have the following prerequisites met:

    Set the following environment variable to authenticate your requests:

    Environment variableDescriptionExample
    GOOGLE_APPLICATION_CREDENTIALSPath to a Google Cloud service account key file/path/to/key.json

    Note: You can also hardcode these values directly in the constructor of each demo class if preferred.

  10. Use Google Wallet PHP demo classes

    main

    Each demo class in this directory implements a specific Google Wallet pass type. You can import a class and call its methods to perform tasks like creating, updating, or patching pass classes and objects.

    Available Pass Types

    Pass typeFile
    Event ticketsdemo_eventticket.php
    Flight boarding passesdemo_flight.php
    Generic passesdemo_generic.php
    Gift cardsdemo_giftcard.php
    Loyalty program membershipdemo_loyalty.php
    Offers and promotionsdemo_offer.php
    Transit passesdemo_transit.php
    // Import the demo class
    require __DIR__ . '/demo_eventticket.php';
    
    // Your Issuer account ID
    $issuerId = '3388000000000000000';
    
    // Create a demo class instance
    $demo = new DemoEventTicket();
    
    // Create a pass class
    $demo->createClass($issuerId, 'class_suffix');
    
    // Create a pass object
    $demo->createObject($issuerId, 'class_suffix', 'object_suffix');
    
    // Generate an Add to Google Wallet link that creates a new pass class and object
    $demo->createJWTNewObjects($issuerId, 'class_suffix', 'object_suffix');
  11. Run a Google Wallet Go sample

    main

    Each sample file implements a specific pass type. To run a sample, first install its dependencies and then execute the file using go run.

    # Install dependencies for the sample
    go install demo_eventticket.go
    
    # Run the sample
    go run demo_eventticket.go