This website uses cookies to improve our services and deliver relevant ads.
By interacting with this site, you agree to this use. For more information, see our Cookies Policy
In-app purchases (IAP) allow users to purchase items without leaving your app.
There are two types of items that you can offer in your game, consumable and durable.
Before you begin integrating the IAP methods in your experience, you’ll need to define the items that you will be offering for purchase. The in-app purchase list can be updated or modified at any time.
At the moment there is no support for selling a single item with multiple currencies. A separate SKU will need to be created for each item and currency combination.
To define your IAP list open your preferred spreadsheet or text editor and create a tab-separated (.tsv) file in the following format.
| SKU | NAME | Description | Currency | Amount | Item Type |
|---|---|---|---|---|---|
| unlock_level_2 | Level 2 Unlock | Purchase this item to unlock the 2nd level in the game. | USD | 9.99 | durable |
| 100_coins | 100 Coins | 100 coins to spend as in-game currency. | USD | 2.99 | consumable |
The values for the items in the table above are:
An IAP item template is available for download from the IAP section of the Developer Center.
Once you’ve created your file, you can upload your IAP items to your selected experience in the IAP section of the Developer Center and selecting ‘Upload TSV’ and following the on-screen prompts.
Once you’ve finished defining the items that you would like to offer as purchases, you can start building them as purchasable items into your app.
The following SDK methods can be called from your client app.
Retrieve the user's purchased items:
Native - ovr_IAP_GetViewerPurchases()
Unity - Platform.IAP.GetViewerPurchases()
Review the ovr_IAP_GetViewerPurchases page for information about the parameters and return data structure.
Retrieve a list of available items and prices by SKU:
Native - ovr_IAP_GetProductsBySKU()
Unity - Platform.IAP.GetProductsBySKU()
Review the ovr_IAP_GetProductsBySKU page for information about the parameters and return data structure.
Launch the checkout flow for a SKU (Purchase an item):
Native - ovr_IAP_LaunchCheckoutFlow()
Unity - Platform.IAP.LaunchCheckoutFlow()
Review the ovr_IAP_LaunchCheckoutFlow page for information about the parameters and return data structure.
Consume a purchased item:
Native - ovr_IAP_ConsumePurchase()
Unity - Platform.IAP.ConsumePurchase()
Review the ovr_IAP_ConsumePurchase page for information about the parameters and return data structure.
The following Unity example demonstrates the end-to-end flow of retrieving information for an IAP item, displaying that information to the user, consuming any outstanding purchases, and initiating the checkout flow when a user indicates that they would like to make a purchase. The following example is taken from the VRBoardGame sample app. Please see the Sample Apps page for more information about the apps that are available.
using UnityEngine;
using Oculus.Platform;
using Oculus.Platform.Models;
using UnityEngine.UI;
// This class coordinates In-App-Purchases (IAP) for the application. Follow the
// instructions in the Readme for setting up IAP on the Oculus Dashboard. Only
// one consumable IAP item is used is the demo: the Power-Ball!
public class IAPManager : MonoBehaviour
{
// the game controller to notify when the user purchase more powerballs
[SerializeField] private GameController m_gameController;
// where to record to display the current price for the IAP item
[SerializeField] private Text m_priceText;
// purchasable IAP products we've configured on the Oculus Dashboard
private const string CONSUMABLE_1 = "PowerballPack1";
void Start()
{
FetchProductPrices();
FetchPurchasedProducts();
}
// get the current price for the configured IAP item
public void FetchProductPrices()
{
string[] skus = { CONSUMABLE_1 };
IAP.GetProductsBySKU(skus).OnComplete(GetProductsBySKUCallback);
}
void GetProductsBySKUCallback(Message<ProductList> msg)
{
if (msg.IsError)
{
PlatformManager.TerminateWithError(msg);
return;
}
foreach (Product p in msg.GetProductList())
{
Debug.LogFormat("Product: sku:{0} name:{1} price:{2}", p.Sku, p.Name, p.FormattedPrice);
if (p.Sku == CONSUMABLE_1)
{
m_priceText.text = p.FormattedPrice;
}
}
}
// fetches the Durable purchased IAP items. should return none unless you are expanding the
// to sample to include them.
public void FetchPurchasedProducts()
{
IAP.GetViewerPurchases().OnComplete(GetViewerPurchasesCallback);
}
void GetViewerPurchasesCallback(Message<PurchaseList> msg)
{
if (msg.IsError)
{
PlatformManager.TerminateWithError(msg);
return;
}
foreach (Purchase p in msg.GetPurchaseList())
{
Debug.LogFormat("Purchased: sku:{0} granttime:{1} id:{2}", p.Sku, p.GrantTime, p.ID);
}
}
public void BuyPowerBallsPressed()
{
#if UNITY_EDITOR
m_gameController.AddPowerballs(1);
#else
IAP.LaunchCheckoutFlow(CONSUMABLE_1).OnComplete(LaunchCheckoutFlowCallback);
#endif
}
private void LaunchCheckoutFlowCallback(Message<Purchase> msg)
{
if (msg.IsError)
{
PlatformManager.TerminateWithError(msg);
return;
}
Purchase p = msg.GetPurchase();
Debug.Log("purchased " + p.Sku);
m_gameController.AddPowerballs(3);
}
} Certain actions require to you to interact directly with our server. See the Server-to-Server API Basics page for information about interacting with our APIs.
| Parameter | Required | Description | Type | Example |
|---|---|---|---|---|
| sku | Y | The sku for the item, defined when created on the Developer Center. | string | "50_gems" |
Verify Item Ownership
Verify that a user owns an item.
Example Request
$ curl -d "access_token=$USER_ACCESSTOKEN" -d "user_id=$USERID"
https://graph.oculus.com/$APPID/verify_entitlementExample Response
{"success":true}Consume an IAP Item
Consume an IAP item that a user has purchased.
Example Request
$ curl -d "access_token=$USER_ACCESSTOKEN" -d "sku=$SKU"
https://graph.oculus.com/$APPID/consume_entitlementExample Response
{"success":true}Retrieve Items Owned
Retrieve a list of items that the user owns.
Example Request
$ curl -G -d "access_token=$USER_ACCESSTOKEN" -d "sku=$SKU" -d 'fields'='item{skus},id'
https://graph.oculus.com/$APPID/viewer_purchasesExample Response
{
"data": [
{
"id": "963119010431337",
"item": {
"sku": "EXAMPLE1"
}
}
]
}You can test your IAP integration by creating test users for your organization. These test users have permission to purchase IAP items in your app, including the Alpha, Beta, and Release Candidate apps, without using actual money. These users will work with all applications in your organization and can be deleted at any time.
Create a test user by navigating to your Org's publishing page on the Developer Center and selecting the 'Test Users' tab. On this page select ‘+ Add Test User’ and enter a password and pin on the modal that opens. Click ‘Submit’ to create the user. This user will be assigned the name of the person who’s account created the test user, a random Oculus Id, and an email address based on the account creators email address. This user inherits permissions to all apps and channels for the Org that you created the user in.
Once the test user has been created, log in to that account and add a payment method for the user. Since this user will be testing the IAP checkout flow, add the following credit card numbers to test different IAP flows.
These cards only work with test users and can only be used within your organization. When using these cards, you can enter any valid address and expiration date.