> ## 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.

# Redeem Apple App Store In-App Purchases

> Create an Apple App Store IAP, map it to a PlayFab catalog bundle, and guide players through redemption using the Economy v2 redemption APIs.

# Set up an In-App Purchase using PlayFab and the Apple App Store

This tutorial provides step-by-step instructions on how to create an Apple App Store In-App Purchase (IAP) item, add it to your Catalog in Game Manager, and guide players through the redemption process.

## Prerequisites

1. A Title in PlayFab [Game Manager](https://developer.playfab.com/).
2. An existing [integration between the selected Title in PlayFab and the Apple App Store](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-integrations/apple).
3. Access to [App Store Connect](https://appstoreconnect.apple.com/).
4. An app already [created](https://developer.apple.com/help/app-store-connect/create-an-app-record/add-a-new-app) in the **App Store Connect**.
5. An [In-App Purchase](https://developer.apple.com/help/app-store-connect/manage-in-app-purchases/create-consumable-or-non-consumable-in-app-purchases/) created within your **App** in the **App Store Connect**. Your **In-App Purchase** should include [Pricing](https://developer.apple.com/help/app-store-connect/manage-in-app-purchases/set-a-price-for-an-in-app-purchase) and [Localization](https://developer.apple.com/documentation/appstoreconnectapi/app_store/in-app_purchase/in-app_purchase_localizations).
6. A [Payment Queue](https://developer.apple.com/documentation/storekit/skpaymentqueue) with its corresponding [Transaction Observer](https://developer.apple.com/documentation/storekit/in-app_purchase/original_api_for_in-app_purchase/setting_up_the_transaction_observer_for_the_payment_queue) already part of your app.

## Step 1: Create test users

In order for you to properly test a purchase without incurring in real-money payments, start by creating a test user for your app.

1. Navigate to the [App Store Connect](https://appstoreconnect.apple.com/) > **Users and Access**.

2. Select **Sandbox**.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/apple-redemption/sandbox-tab-option.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=3d00d1425e1b9adbaa9e7eefa6773510" alt="Sandbox tab option" width="804" height="76" data-path="images/playfab/economy-monetization/economy-v2/apple-redemption/sandbox-tab-option.png" />

3. Select the plus sign (**+**) button next to **Test Accounts**.

4. Fill the form and select **Create**.

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/apple-redemption/new-test-user-form.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=d8a84e3ec992c3a706d09bcb7c9221cb" alt="New test user form" width="465" height="354" data-path="images/playfab/economy-monetization/economy-v2/apple-redemption/new-test-user-form.png" />

## Step 2: Create a Bundle in Game Manager

<Note>
  Before creating a bundle in **Game Manager**, ensure that you have already created and published the items you want to add to the bundle in your Catalog. In this tutorial, we assume that you have already created a sword called **Super Awesome Sword**. If you need guidance on how to create an item, please refer to [this step](/services/playfab/economy-monetization/economy-v2/tutorials/craftingGame/crafting-game-game-manager#step-4---create-your-first-item).
</Note>

To enable a marketplace mapping between **Game Manager** and the **App Store Connect**, you need to create a **Bundle** in Game Manager. A bundle can contain multiple items with different quantities, and PlayFab will add them to the player's inventory once redeemed. Follow these steps to create a new **Bundle** in **Game Manager**:

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

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

3. Select the **Bundles** tab.

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

4. Select **New bundle**.

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

   <img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/apple-redemption/bundle-fields.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=186122634a38f2bb84d8eb1e59c8275f" alt="Bundle options" width="1270" height="662" data-path="images/playfab/economy-monetization/economy-v2/apple-redemption/bundle-fields.png" />

6. Scroll down to the end of the page and select **Save and publish** if you want it to be redeemable by players right away. Select "Save as draft" if you want to publish it at a later date.

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

### Add an item 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.

To add items to your bundle, follow these steps:

1. Go to the **Items** section in edit mode.
2. Select **Add**. A window appears showing all your catalog items.
3. You can filter by type or search for a specific item.
4. Find our **Super Awesome Sword** and select **Add** next to it.
5. Finally, select the **Add** button at the bottom.

This adds the item to your bundle.

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

## Step 3: 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 the **Marketplace Mapping**. This can be done while creating your bundle in Game Manager or by going back to the bundle in **Edit mode** after it has been created.

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's **AppleAppStore**).
4. For your **Marketplace ID**, make sure to use the same as your **Product ID** in the **App Store Connect**. In this tutorial, we used **pf.commerce.ios.sas1**.
5. To finish, select the **+** at the right side of that row and **Save** your changes.

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

## Step 4: Make a purchase

<Tip>
  To find out more about this topic, see [In-App Purchases](https://developer.apple.com/design/human-interface-guidelines/in-app-purchase). For an overview on how to configure In-App Purchases, see [Apple's Developer Documentation](https://developer.apple.com/help/app-store-connect/configure-in-app-purchase-settings/overview-for-configuring-in-app-purchases/).
</Tip>

Now you have your **IAP** created in the **App Store Connect**, your **Bundle** configured with **Item**(s) in **Game Manager**, and the **Marketplace Mapping** of your **Bundle** set up. Let's move on to purchasing the IAP from your **App**.

After you have your IAP item exposed and purchasable from your app, you can use the **Test User** we created in [Step 1](#step-1-create-test-users) to purchase your IAP on your app. Once this is complete, Apple's API should return a **receipt** which you have to then use with PlayFab's redemption API to validate the purchase and grant the item(s) in the **Bundle** to the player.

## Step 5: Redeem your In-App Purchase

Once your get your **receipt** from Apple's API, you must use PlayFab's **RedeemAppleAppStoreInventoryItems** API call to successfully redeem your IAP. In this case, it should grant our **Super Awesome Sword** to the authenticated player.

### Check both IDs are matching

Before making your redemption call, you must ensure that both the **Alternate ID** you used in **Game Manager** for your marketplace mapping, matches the **Product ID** in the **App Store Connect**.

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/apple-redemption/marketplace-mapping.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=df47a8ad762edebe9ad4815f8fc60d14" alt="Marketplace mapping" width="1270" height="199" data-path="images/playfab/economy-monetization/economy-v2/apple-redemption/marketplace-mapping.png" />

From the [App Store Connect](https://appstoreconnect.apple.com/), go to **My Apps**, select your desired app, then navigate to **Features** > **In-App Purchases** from the left navigation menu, finally, select your IAP, and from the IAP metadata you see the **Product ID**.

<img src="https://mintcdn.com/microsoft-4404708b/68AB2fedpk3M7e-n/images/playfab/economy-monetization/economy-v2/apple-redemption/app-store-connect-product-id.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=975ebfa25d33ee63a869c1d0c485d18f" alt="App Store Connect Product ID" width="383" height="178" data-path="images/playfab/economy-monetization/economy-v2/apple-redemption/app-store-connect-product-id.png" />

### Get the player authenticated

To redeem an item, use [RedeemAppleAppStoreInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-apple-app-store-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 use the [LoginWithApple](https://learn.microsoft.com/en-us/rest/api/playfab/client/authentication/login-with-apple).

After a successful **LoginWithApple** call, PlayFab's API returns an **EntityToken** that you have to use as part of your **RedeemAppleAppStoreInventoryItems** 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/apple-redemption/header-keys.png?fit=max&auto=format&n=68AB2fedpk3M7e-n&q=85&s=7f4e1dc7fe1f3af28ea2a945fd5614b0" alt="API platform header keys" width="684" height="111" data-path="images/playfab/economy-monetization/economy-v2/apple-redemption/header-keys.png" />

### Make the redemption call

With your player authenticated, both your IDs checked and matching, and your **receipt** from the app purchase made by your player. You're ready to make the redemption call. For this, use the **RedeemAppleAppStoreInventoryItems** API call.

```json theme={null}
{
    "Receipt": "{Your receipt}"
}
```

The redemption call has only a single value and that's the **receipt** returned by Apple after a successful purchase of your IAP.

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

After a successful redemption call is executed, you should be able to see a **Super Awesome Sword** in your authenticated player's inventory. This triggers a corresponding event in the player's transaction history. This can be retrieved from the **Transaction History (V2)** tab under the player's overview page in [Game Manager](https://developer.playfab.com/).

Alongside a new log entry in the player's transaction history, an `items_redeemed` **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](https://developer.playfab.com/). 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**.

## Step 6: Finishing the transaction

After successfully redeeming your purchased items, you have to make sure to properly finish your transaction to prevent it from remaining in the purchase queue indefinitely. It's important to note that you should finish your transaction regardless if it succeeded or failed.

To properly finish your transaction, you must use **Apple's** [`finishTransaction(_:)`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1506003-finishtransaction) method.

<Note>
  You can find more info on `finishTransaction(_:)` by going through **Apple's** [documentation](https://developer.apple.com/documentation/storekit/in-app_purchase/original_api_for_in-app_purchase/finishing_a_transaction/).
</Note>

## See also

* [How to successfully integrate an Apple app into Game Manager](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-integrations/apple)
* [How to successfully integrate a Google app into Game Manager](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-integrations/google)
* [Set up a PlayFab bundle that can be purchased from Google Play Store](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-redemption/google)


## Related topics

- [PFInventoryRedeemAppleAppStoreInventoryItemsAsync](/services/playfab/api-references/c/pfinventory/functions/pfinventoryredeemappleappstoreinventoryitemsasync.md)
- [PFInventoryRedeemAppleAppStoreInventoryItemsRequest](/services/playfab/api-references/c/pfinventorytypes/structs/pfinventoryredeemappleappstoreinventoryitemsrequest.md)
- [PFInventoryRedeemAppleAppStoreInventoryItemsResponse](/services/playfab/api-references/c/pfinventorytypes/structs/pfinventoryredeemappleappstoreinventoryitemsresponse.md)
- [PFInventoryRedeemAppleAppStoreInventoryItemsGetResult](/services/playfab/api-references/c/pfinventory/functions/pfinventoryredeemappleappstoreinventoryitemsgetresult.md)
- [PFInventoryRedeemAppleAppStoreInventoryItemsGetResultSize](/services/playfab/api-references/c/pfinventory/functions/pfinventoryredeemappleappstoreinventoryitemsgetresultsize.md)
