WalletPasses.Google.Api (wallet_passes v0.6.0)

Copy Markdown View Source

Google Wallet API client for wallet passes.

Uses the Google Wallet REST API to create, update, and manage pass objects and classes across all supported types (event tickets, boarding passes, loyalty cards, offers, and generic passes).

Summary

Functions

Builds a Google Wallet class object map from configuration.

Builds a Google Wallet pass object map from PassData and Visual.

Creates a pass object on Google's servers.

Creates or updates a pass class on Google's servers.

Ensures a class exists on Google's servers, creating it if necessary.

Gets a cached Google OAuth2 access token, refreshing if expired.

Updates an existing pass object on Google's servers.

Functions

build_class_object(class_config)

Builds a Google Wallet class object map from configuration.

Options

  • :id - Class ID suffix (required)
  • :issuer_name - Issuer name (required)
  • :event_name - Title/name for the class (required). Maps to type-specific field: eventName for event tickets, programName for loyalty, title for offers, etc.
  • :pass_type - Pass type atom (optional, defaults to :event_ticket)
  • :start_date - Start date as ISO 8601 string (optional)
  • :end_date - End date as ISO 8601 string (optional)
  • :location_name - Venue name (optional)
  • :location_address - Venue address (optional)
  • :enable_smart_tap - Enable Smart Tap / NFC for this class (optional, boolean)
  • :redemption_issuers - List of redemption issuer IDs authorized for Smart Tap (optional)
  • :latitude - Venue latitude (optional)
  • :longitude - Venue longitude (optional)
  • :logo_uri - Logo image URI (optional)

build_pass_object(pass_data, visual, opts \\ [])

Builds a Google Wallet pass object map from PassData and Visual.

The object type is determined by pass_data.pass_type.

create_object(pass_data, visual, opts \\ [])

Creates a pass object on Google's servers.

If the object already exists (409), updates it instead. The object type is determined by pass_data.pass_type. Returns {:ok, object_id} on success.

create_or_update_class(class_config, pass_type \\ :event_ticket)

Creates or updates a pass class on Google's servers.

Attempts to update first; falls back to insert on 404. Pass type defaults to :event_ticket when not specified.

ensure_class(class_config, pass_type \\ :event_ticket)

Ensures a class exists on Google's servers, creating it if necessary.

The first call within a VM lifetime calls create_or_update_class/2. Subsequent calls for the same class_id are no-ops, tracked via the TokenCache ETS table with key {:class_ensured, class_id}.

Returns :ok on success, {:error, reason} on failure.

get_access_token()

Gets a cached Google OAuth2 access token, refreshing if expired.

Emits [:wallet_passes, :google, :token_exchange, :start|:stop] events with metadata %{cached: boolean()}.

update_object(pass_data, visual, object_id, opts \\ [])

Updates an existing pass object on Google's servers.

The object type is determined by pass_data.pass_type. Returns {:ok, object_id} on success.