> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Redemption with the Google Marketplace

> Create Google Play in-app products, map them to PlayFab Economy v2 bundles, and redeem purchases into player inventory using the redemption API.

# Set up a PlayFab bundle that can be purchased from Google Play Store

This tutorial shows you how to successfully create a PlayFab bundle, add it to your game in the Google Marketplace for players to purchase, and how to redeem the items contained in it.

## Prerequisites

1. A Title in PlayFab's [Game Manager](https://developer.playfab.com/).
2. An existing integration between the selected Title and your desired marketplace.
3. An app already created and available in [Google Play](https://play.google.com/console/developers).
   1. Make sure your app has the [Google Play Android Developer API](https://console.cloud.google.com/apis/library/androidpublisher.googleapis.com) enabled.

## Step 1: Create a bundle

In this tutorial, we start by creating the **Bundle** in the **Google Play Console**.

### Create a Bundle using the Google Play Console

1. Open your desired **App** in the [Google Play Console](https://play.google.com/console/developers).

2. On the left navbar, scroll down to the **Monetize** section and select **In-app products**.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/in-app-products-menu-option.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=92b9e2190985623fa3dde381d41ba772" alt="In-app products menu option" width="268" height="174" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/in-app-products-menu-option.png" />

3. Select **Create product** on the top right.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/create-product-button.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=b41920daf7ccfa83fa1dac7fe6c92079" alt="Create product button" width="167" height="49" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/create-product-button.png" />

4. Enter your desired **Product ID** and **Name** for the bundle. In this tutorial, use **warrior\_bundle** as the **Product ID**. Remember the **Product ID** because it will be used for linking **Game Manager**.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/create-new-product-fields.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=be23718de59d1064702dbbef9785639a" alt="Create new product fields" width="925" height="747" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/create-new-product-fields.png" />

5. Scroll down to the **Price** section and select **Set price**.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/set-price-option.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=fb05ce5fabf21d5eab166866748c66f5" alt="Set price option" width="616" height="134" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/set-price-option.png" />

6. Add whatever price you want your bundle to have, for example \$1.00, and select **Apply prices** on the bottom right.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/set-price-screen.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=5a568d7b4c64c2cd991194e08d4c917f" alt="Set price screen" width="369" height="263" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/set-price-screen.png" />

7. Select **Save** to save all the changes you just made to the bundle. Note that saving won't activate it as a product. Once saved, the activation option appears. To make the bundle active in your app in the **Google Play Console**, select the **Activate** button on the lower right.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/activate-bundle-button.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=c43485d79a2f0e4263d0bd45f8275f3a" alt="Activate bundle button" width="237" height="60" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/activate-bundle-button.png" />

### Create a Bundle using Game Manager

To create a new **Bundle** in **Game Manager** follow the next steps:

1. Go to [Game Manager](https://developer.playfab.com/) and navigate to you **Title**.

2. From the left navigation menu, choose **Engage** > **Economy**.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/economy-menu-location.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=8bf748433b2bf5b630a720f8875f54d8" alt="Economy menu location" width="146" height="29" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/economy-menu-location.png" />

3. Select the **Bundles** tab.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/bundles-tab.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=171855d0a8a8d1f179c4a0a1ff099a79" alt="Bundles tab" width="513" height="46" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/bundles-tab.png" />

4. Select **New bundle**.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/new-bundle-button.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=47c50c417bbaf9666116c4c57a6b8fc4" alt="New bundle button" width="658" height="161" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/new-bundle-button.png" />

5. Add any information you want to the **Bundle**, such as items and prices In this tutorial, use **Warrior Bundle** as the name.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/bundle-options.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=418ff8e0ea29852ceb78367fb3abda80" alt="bundle options" width="1563" height="781" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/bundle-options.png" />

6. Scroll down to the end of the page and select **Save and publish** if you want it to be published right away, or **Save as draft** if you want it saved but don't want it available yet.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/save-options.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=eeabd76a32bdcaf3b2047d248eb3d698" alt="Save option" width="302" height="42" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/save-options.png" />

### Add items to your bundle

A bundle by itself doesn't grant any items to a player, we must first link items to it and once redeemed, it grants those items to that specific player.

Before adding items to a bundle, make sure you have the items already created and published in your Catalog. We already have a sword called **Fire Sword** and a shield called **Ice Shield**. If you don't know how to create an item, refer to [this step](/services/playfab/economy-monetization/economy-v2/tutorials/craftingGame/crafting-game-game-manager#step-4---create-your-first-item).

Now to add them to your bundle! To do so, you can either add them while creating your bundle the first time, assuming that the items are already created, or you can add them later by editing the bundle item.

While in edit mode, scroll down to the **Items** section of your bundle and select the **Add** button, this displays a window in which all your items available in your catalog are shown, from here you can either filter by type (Items or User Generated Content (UGC) Items), or search for a specific item. We select the **Add** button next to each of the items we want to add and finally the blue **Add** button at the bottom of the window.

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/add-bundle-items.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=5555fac96752cb10974c4d251ab9a10d" alt="Add items to a bundle" width="1156" height="648" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/add-bundle-items.png" />

#### Enable Marketplace Mapping

To ensure that when a player purchases a bundle from your app, it gets properly purchased and assigned in Game Manager, you must configure your **Marketplace Mapping**. This can be done while creating your bundle in Game Manager or after the bundle was created by going back to the bundle in **Edit mode**.

1. Navigate to your bundle in edit mode.
2. Scroll down to the **Marketplace Mapping** section.
3. From the **Marketplace** dropdown, select your desired marketplace. (For this tutorial, it will be **GooglePlay**).
4. For your **Marketplace ID**, make sure to use the same as your **Product ID** in the Google Play Console. In this tutorial, we used **Warrior\_bundle**.
5. To finish, select the **+** at the right side of that row.

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/marketplace-mapping.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=4c95bc354ae66871f9aa1d502063351a" alt="Marketplace Mapping" width="867" height="145" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/marketplace-mapping.png" />

## Step 2: Generate a Purchase Token

<Note>
  Make sure you have **Prerequisite #3** completed before continuing, if not, there is no practical way of generating a **Purchase Token**.
</Note>

A **Purchase Token** is a token generated by Google Play's APIs on each purchase, similar to a receipt ID. According to Google's documentation, "a **Purchase Token** is a string that represents a buyer's entitlement to a product on Google Play. It indicates that a Google user has paid for a specific product."

In your implementation, you should save that token as it should be sent to PlayFab's API in order to validate the purchase with the Google Marketplace. It allows PlayFab to redeem the player's purchased items and grant them in the player's inventory.

To generate the token, you must already have an app running with an active integration with Google Play. Your app registration in Google Play must also have items (or in this case, a bundle) available for purchase. Your code implementation must use Google Play's billing system for you to get a token returned once you make a purchase.

In summary, the billing system should be used when coding your app, through that billing system you can purchase the bundle from Google's end, which will return the **Purchase Token**. The token should then be used with PlayFab's [Economy API](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-google-play-inventory-items) to redeem the purchase and add the bundle items to the player's inventory.

<Tip>
  For implementation examples of a similar project using Google's systems, see this [CodeLab](https://codelabs.developers.google.com/play-billing-codelab#0). For more information about billing, see [Google's Billing System documentation](https://developer.android.com/google/play/billing).
</Tip>

## Step 3: Redeem a bundle

Now that you have your bundle created in both **Game Manager** and in the **Google Play Console**, you can redeem your bundle for one of your players. In this example, we focus on doing so using PlayFab's API, specifically, the **RedeemGooglePlayInventoryItems** call, part of PlayFab's **Economy API**.

### Check AlternateIDs

Before making the redeem call, make sure you have the correct **AlternateId** in **Game Manager**, it should be the same as in the **Google Play Console**.

The following screenshot is from within your bundle in **Game Manager**, the **Marketplace ID** is what we call the **AlternateId**, basically it's another way of identifying your bundle.

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/marketplace-mapping.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=4c95bc354ae66871f9aa1d502063351a" alt="Marketplace Mapping" width="867" height="145" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/marketplace-mapping.png" />

From the **Google Play Console**, go into the **In-app products** screen under the **Monetize** section, from here, you see all your created products, including the **Warrior Bundle**. The **Product ID** can be seen in the second column, you should make sure it's the same as your **AlternateId** in **Game Manager**, if it isn't, then update **Game Manager**.

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/google-product-id.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=540fdae0f4ec818e566dcaff96fb82de" alt="Google Play Console Product Id" width="506" height="102" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/google-product-id.png" />

### Get the player authenticated

To redeem an item, use [RedeemGooglePlayInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-google-play-inventory-items). But before that, we must ensure that the player looking to redeem the item(s) gets properly authenticated in your app, for which you'll likely use the [LoginWithGoogleAccount](https://learn.microsoft.com/en-us/rest/api/playfab/client/authentication/login-with-google-account).

<Note>
  For a more detailed example, see [Setting up PlayFab authentication using Google Play games sign-in in Unity](/services/playfab/identity/player-identity/platform-specific-authentication/google-sign-in-unity).
</Note>

After a successful **LoginWithGoogleAccount** call, PlayFab's API returns an **EntityToken** that you have to use as part of your **RedeemGooglePlayInventoryItems** headers with a `X-EntityToken` key. Which would look like this if you're using an API platform to test.

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/header-keys.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=f0198070ec5ca0f935b5aaf5b87c4da0" alt="API platform header keys" width="684" height="111" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/header-keys.png" />

### Make the redemption call

With your player authenticated, both bundle instances created and their **Alternate IDs** checked, and your **Purchase Token**. You're ready to make the redemption call. For this, we use the **RedeemGooglePlayInventoryItems** API call.

```json theme={null}
{
    "Purchases": [
        {
            "ProductId": "warrior_bundle",
            "Token": "{Your Google Purchase Token}"
        }
    ]
}
```

The call is straightforward, you have a `Purchases` array, containing the `Product ID` (which should match the one in the **Google Play Console**), and a `Token` field that corresponds to the **Purchase Token** returned when calling the **Google Play Billing System**.

A successful response includes a `200 status code` alongside data such as a **timestamp** and a **MarketplaceTransactionId**.

After a successful redemption has been made, if you go into your player's inventory, you should now be able to see both of items linked to the bundle.

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/inventory-after-redemption.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=e86cd91ff9c2e5da81f315ae071a3072" alt="Inventory after redemption" width="843" height="197" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/inventory-after-redemption.png" />

Each redemption action will also trigger a corresponding event log in the player's transaction history that can be retrieved from the **Transaction History (V2)** tab under a specified player's overview page, and looks something like this:

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/transaction-history.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=45757726c6c89bbd6c364effc9387162" alt="Transaction history" width="1423" height="521" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/transaction-history.png" />

Alongside the record in the player's transaction history, a PlayStream event is also triggered and logged. You can access these logs for your Title by going to the **Data** page under the **Analyze** section of the left navigation bar in **Game Manager**. Here you can edit queries to search for specific records or run it with the default settings to get everything. There should be a record under the **Event name** of **items\_redeemed**, such as follows:

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/google-redemption/playstream-event-log.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=a510550be545cce753c637ea1bcdb842" alt="PlayStream event log" width="778" height="192" data-path="images/playfab/economy-monetization/economy-v2/google-redemption/playstream-event-log.png" />

You notice that there are two distinct `items_redeemed` PlayStream events logged, this is because even though we redeemed just one bundle, the bundle contained two different items.

## Step 4: Consumption

After successfully redeeming your purchase, you should then make sure it gets properly **Consumed** in the marketplace. The ways of doing this are:

* Using the **purchases.products.consume** method part of the [Google Play Developer API](https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/consume).
* Using the **BillingClient.consumeAsync** method part of [Google's Billing Client](https://developer.android.com/reference/com/android/billingclient/api/BillingClient#consumeAsync\(com.android.billingclient.api.ConsumeParams,%20com.android.billingclient.api.ConsumeResponseListener\)).
* Or by using one of the built-in plugins such as the ones available on **Unity** and **Unreal**.

Nonetheless, before making the consumption call (or in the Unity or Unreal plugins, before the client indicates it has finished processing the purchase), you need to receive a `200` response after the redemption process with 1 or more successes and **0 failures**. If you receive a `202` response or a redemption failure, you're encouraged to retry the consumption call once more after a while.

## See also

* [Getting Started with Economy v2, Unity, and Android](/services/playfab/economy-monetization/economy-v2/tutorials/getting-started-with-unity-and-android)

* [Fraud prevention quickstart](/services/playfab/economy-monetization/economy-v2/fraud-prevention/quickstart)
