Skip to content

Pass sessionToken to Place Details to enable Google session billing#52

Merged
sampoyigi merged 2 commits into
tastyigniter:4.xfrom
obinnaelviso:fix/google-places-session-token
May 15, 2026
Merged

Pass sessionToken to Place Details to enable Google session billing#52
sampoyigi merged 2 commits into
tastyigniter:4.xfrom
obinnaelviso:fix/google-places-session-token

Conversation

@obinnaelviso
Copy link
Copy Markdown
Contributor

Summary

The Google Places provider sends a sessionToken on Autocomplete requests but does not send it on the subsequent Place Details call (getPlaceCoordinates). Google only bundles Autocomplete + Place Details into a single billable session when the same token is presented on both calls — so as-is, every Autocomplete keystroke is billed as a standalone request instead of as a free companion to the Details call.

Per the places.get REST reference, sessionToken is documented as a query-string parameter (URL/filename-safe base64, ≤36 ASCII chars). UUIDv4 from Str::uuid() satisfies that constraint.

This PR:

  • Appends ?sessionToken=<token> to the Place Details GET URL in GoogleProvider::getPlaceCoordinates() using the existing getPlacesSessionToken(). The existing clearPlacesSessionToken() after a successful Details call continues to end the session correctly.
  • Bumps the local session-token expiry from 3 → 5 minutes to align with Google's recommended session window, so a user pausing mid-address doesn't get their session prematurely rotated into a second billable session.

Behavior

  • Autocomplete request: unchanged — already sent sessionToken in the body.
  • Place Details request: now sends the same sessionToken as a query parameter, then clears it on success.
  • Net effect: Autocomplete keystrokes within a 5-minute window that culminate in a Details call are billed once per session by Google instead of once per keystroke.

Test plan

  • Type into the address autocomplete; confirm subsequent Place Details network call includes ?sessionToken=… matching the token used for Autocomplete.
  • Confirm a fresh token is issued after a successful Place Details call (session cleared on completion).
  • Confirm a new token is issued after 5 minutes of inactivity.
  • Verify the resolved coordinates and address selection flow still work end-to-end.

🤖 Generated with Claude Code

Google's Places API (New) bundles Autocomplete + Place Details into a
single billable session only when the same sessionToken is presented on
both calls. The Autocomplete request already sent the token, but
getPlaceCoordinates() omitted it, so every Autocomplete keystroke was
billed as a standalone request instead of as part of a free session
companion to the Details call.

Per the places.get REST reference, sessionToken is an optional query
string parameter on GET /v1/places/{PLACE_ID}. Appending it here lets
Google link the calls and apply session pricing.

Also bumps the local session-token expiry from 3 to 5 minutes to align
with Google's recommended session window, reducing premature token
rotation while a user is still typing.
Copilot AI review requested due to automatic review settings May 14, 2026 12:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Google Places session billing by sending the same sessionToken to the Place Details endpoint that was already used for Autocomplete, allowing Google to bundle them into a single billable session. The session token's local TTL is also extended from 3 to 5 minutes to better match Google's recommended session window.

Changes:

  • Append ?sessionToken=<token> (URL-encoded) to the Place Details GET URL via the existing getPlacesSessionToken() helper.
  • Extend the in-session token expiry from 3 minutes to 5 minutes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@obinnaelviso obinnaelviso requested a review from sampoyigi May 14, 2026 12:43
@sampoyigi sampoyigi merged commit 8369027 into tastyigniter:4.x May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants