IAP integration
- Game Development course
- Expert
- Lesson 39/47
- 4 min
Learn in-app purchase integration with Unity IAP.
What Is IAP Integration?
In-App Purchase (IAP) allows players to purchase digital products or features inside a game. Unity IAP is a Unity solution used to connect store purchasing processes to a game project. Products are commonly defined as consumables, non-consumables, or subscriptions.
Product:
ID: gems_pack
Type: ConsumablePurchases are processed through real store accounts and the rules of the relevant platform.
Defining Store Products
In IAP integration, each product has a unique product identifier. This identifier allows the game to match the product with the store item. For example, a package that grants in-game gems can be identified with an ID such as gems_pack.
Product ID: gems_pack
Product Type: Consumable
Description: 100 gemsThe product type affects whether the purchase can be repeated and how the product is delivered.
Practice Simulate a Purchase Request
Create a MonoBehaviour class named PurchaseExample. In the Start method, assign the product ID gems_pack to a variable. Then call a method named PurchaseProduct with that ID. The method should print a message indicating a purchase request. This example simulates the flow and does not perform a real store transaction.
Starter code
using UnityEngine;
public class PurchaseExample : MonoBehaviour
{
void Start()
{
// Ürün kimliğini tanımla
// PurchaseProduct metodunu çağır
}
// Satın alma metodunu tanımla
}Sample solution
using UnityEngine;
public class PurchaseExample : MonoBehaviour
{
void Start()
{
string productId = "gems_pack";
PurchaseProduct(productId);
}
void PurchaseProduct(string id)
{
Debug.Log("Purchase requested: " + id);
}
}Expected output
Purchase requested: gems_pack
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which method allows players to purchase digital products inside a game?
- IAP Correct answer
- Ads
- Premium
- F2P
Explanation: IAP means in-app purchase and allows digital products to be purchased inside a game.
2 Complete the Product Identifier
var productId = "____";
var productId = "gems_pack";
Explanation: gems_pack is the unique product identifier for the gem package defined in the store.
3 IAP Product Types
| Term | Meaning |
|---|---|
Consumable |
Can be bought again after consumption |
Non-Consumable |
Purchased once and remains available |
Subscription |
Charged at recurring intervals |
Product ID |
Uniquely identifies a store product |