Requirements
Android SDK level 21+
The app targets Android 5.0 (Lollipop) or above. It must be deployed to a device or AVD that supports Google Play services (not just Google API) because Google account sign-in is required.
Android Studio
Used to build and deploy the app to a compatible AVD or physical device.
PlayFab title
A PlayFab title configured with a virtual currency (TC) and a catalog of items.
Google Play account
A valid Google account is required to complete the sign-in and billing flows.
Due to Android signing requirements, the billing flow on a locally-deployed debug build may return
responseCode 4 from onPurchasesUpdated(). This is expected behavior for unsigned builds.Setup
Configure a compatible AVD
Create an AVD with API level 21 or higher and select a system image that includes Google Play services (look for the Play Store icon in the AVD Manager).
Using the sample
After launch, sign in with a valid Google account. The store screen shows:- Virtual items (TC price) — items purchasable immediately with the TC virtual currency. Each new player starts with a seed amount of TC.
- Real-money items — items whose price is displayed in real currency. Purchasing these triggers the Google Play billing flow to acquire more TC.
- Inventory — items the player has already purchased are listed at the bottom. Selecting an inventory item decrements its quantity.
Code structure
PlayFabAuthManager
PlayFabAuthManager
A lightweight sign-in layer that handles authenticating with PlayFab across different platforms. It abstracts the platform-specific credential flow (Google Sign-In for Android) and produces a PlayFab session.
PlayFabCommerceManager
PlayFabCommerceManager
The core commerce class. Responsibilities include:
- Fetching the item catalog from PlayFab
- Reading and updating player inventory
- Invoking Unity IAP for real-money purchase flows
- Awarding virtual currency (TC) upon successful purchase confirmation
Key PlayFab features
GetCatalogItems
Retrieves the list of items and their prices from the PlayFab catalog.
GetUserInventory
Reads the player’s current inventory and virtual currency balances.
PurchaseItem
Spends virtual currency (TC) to grant a catalog item to the player’s inventory.
ValidateGooglePlayPurchase
Validates a real-money Google Play purchase receipt on the PlayFab server before awarding virtual currency, preventing fraudulent grants.
