Lumberyard
User Guide (Version 1.15)

In-App Purchases Sample

The In-App Purchases sample demonstrates how to use the In-App Purchases (IAP) Gem for a Lumberyard application that runs on a mobile device. For more information about this gem, see In-App Purchases Gem.

Prerequisites

To use the In-App Purchases sample, you must have the following:

  • An understanding of how to build a Lumberyard application and deploy to a mobile device. For more information, see Creating Android and iOS Games.

  • Access to iTunes Connect to properly configure the sample for an iOS device.

  • Access to the Google Play Developer Console to properly configure the sample for an Android device.

To load the In-App Purchases sample, you must edit the autoexec.cfg file (located in the \dev\SamplesProject directory) to include the following: map Gems_InAppPurchases_Sample

You must also update the product IDs in the product_ids.json file to match the product IDs in iTunes Connect or the Google Play Developer Console. This file is located in the \dev\SamplesProject\IAP_ProductIds directory.

Testing the In-App Purchases Sample on Android

You can test the In-App Purchase samples on an Android device.

To test the In-App Purchases sample on an Android device

  1. In a command line window, build the SamplesProject application.

  2. Go to the Google Play Developer Console.

  3. In the left pane, click All Applications.

  4. In the right pane, click Create Application.

  5. Follow the steps to create a new application. The package name for your application must match the package name under android_settings in the project.json file. This file is located in the \dev\SamplesProject directory.

  6. Once the application is created, it appears on the All Applications tab in the Google Play Developer Console. Click the application. In the left pane, navigate to In-app Products.

  7. On the In-app Products page, click Add new product to add products that can be purchased through the application.

  8. In the left pane of the application page, click APK to upload the APK that you built in step 1.

  9. Create a closed beta test and add test accounts for testing.

  10. Deploy the application to your device. The in-app products that you created in the Google Play Developer Console appear when you select Available Products in the application.

You can now buy products, view purchased products, and consume purchased products in the application.

Testing the In-App Purchases Sample on iOS

You can test the In-App Purchases sample on an iOS device.

To test the In-App Purchases sample on an iOS device

  1. Go to iTunes Connect.

    You must have an admin account to create applications.

  2. Click My Apps.

  3. In the top left of the page, click + to create a new application.

    The bundle identifier must match the bundle identifier for your product in Xcode. To find the bundle identifier, select your Lumberyard project (for example, SamplesProject) in Xcode. You can also find the bundle identifier in the Info.plist file (located in the \Code\SamplesProject\Resources\IOSLauncher directory).

  4. On the My Apps page, click your newly created application.

  5. In the top pane of the application page, click Features.

  6. In the left pane of the Features page, click In-App Purchases.

  7. On the In-App Purchases page, click + to add products that can be purchased through the application.

  8. When you finish adding products for in-app purchases, go to the iTunes Connect home page.

  9. In iTunes Connect, click Users and Roles.

  10. On the Users and Roles page, click Sandbox Testers.

  11. On the Sandbox Testers page, click + to add sandbox tester accounts.

    Important

    Do not log in using this account on your device. This will deactivate the sandbox testing account and you'll need to create a new account.

  12. On your device, choose Settings, iTunes. Log out of any accounts that are logged in.

  13. Deploy and run the application from Xcode. When prompted, sign in with your sandbox tester account on the device.

You can now view available products, buy products, view purchased products, and more. When you buy a product, a note appears that indicates you are in the sandbox environment and will not be charged for the purchase.