mirror of
https://github.com/google-wallet/rest-samples.git
synced 2026-04-18 03:00:10 -04:00
* Create language-specific READMEs with setup and usage instructions * Add links to each language-specific README from main README * Converted examples to use importable classes and functions * Added class- and function-level docstrings and type hinting for IDEs * Removed use of WALLET_* environment variables (now function arguments) * General formatting updates (line length, indentation, etc.) * Switched Java, .NET, and PHP to use Walletobjects libraries * Updated JWT examples to show creating a class and object at once * Fixed error with missing status parameter for certain pass types * Added batch creation example for raw HTTP requests * Removed generator scripts (doesn't work with the Wallet libraries)
3.2 KiB
3.2 KiB
Google Wallet Python samples
Overview
The files in this directory each implement a demo class for a specific Google Wallet pass type. Each class implements methods for performing tasks such as creating a pass class, updating issuer permissions, and more.
| Pass type | File |
|---|---|
| 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 |
Prerequisites
- Python 3.x
- The
pipenvlibrary - Follow the steps outlined in the Google Wallet prerequisites to create the Google Wallet issuer account and Google Cloud service account
Environment variables
The following environment variables must be set. Alternatively, you can update the code files to set the values directly. They can be found in the constructor for each class file.
| Enviroment variable | Description | Example |
|---|---|---|
GOOGLE_APPLICATION_CREDENTIALS |
Path to a Google Cloud service account key file | /path/to/key.json |
How to use the code samples
-
Create a virtual environment in your workspace
# This creates a .venv directory in the current working path python3 -m venv .venv -
Activate the virtual environment
# This must be run in the same location as the .venv directory source .venv/bin/activate -
Use
pipenvto install the dependencies in the Pipfile# This must be run from the same location as the Pipfile pipenv install -
In your Python code, import a demo class and call its method(s). An example can be found below
# Import the demo class from .demo_eventticket import DemoEventTicket # Create a demo class instance demo = DemoEventTicket() # Create the authenticated HTTP client demo.auth() # Create a pass class demo.create_event_ticket_class(issuer_id='issuer_id', class_suffix='class_suffix') # Create a pass object demo.create_event_ticket_object(issuer_id='issuer_id', class_suffix='class_suffix', user_id='user_id') # Create an Add to Google Wallet link demo.create_jwt_save_url(issuer_id='issuer_id', class_suffix='class_suffix', user_id='user_id') # Create an issuer account demo.create_issuer_account(issuer_name='issuer_name', issuer_email='issuer_email') # Create pass objects in batch demo.batch_create_event_ticket_objects(issuer_id='issuer_id', class_suffix='class_suffix')