Mobile In-App Purchases (IAP) in Unity
Overview
Disclaimer: Openfort is not responible of such integration to be approved by Apple and/or Google
This sample project showcases the Openfort advanced & compliant integration with In-App Purchasing in Unity. The objective of this integration sample is to implement and showcase a crypto In-App Purchasing system compliant with the rules/guidelines companies like Apple have set for this type of purchases in mobile apps.
Specifications
The sample includes:
-
A .NET Core project with Cloud Code C# modules that implement Openfort C# SDK methods. Needs to be hosted in Unity Gaming Services.
-
A Unity sample game that connects to
ugs-backend
through Cloud Code. It uses Openfort Unity SDK to have full compatibility withugs-backend
responses.
Application Workflow

Prerequisites
- Get started with Openfort
- Get started with UGS
- Get started with Google Play Console
-
Get started with Apple Developer Account
- Set up everything needed for Apple development
- Make sure to sign the Paid Apps agreement and fill tax and banking details as it's needed for testing IAP.
Setup Openfort dashboard
-
This sample requires an NFT contract to run. We use 0xbed6a05ce8719bc00db1cc81a814192c82be1bb1 (contract deployed in 80002 Amoy). You can use it for this tutorial too:
-
This sample also requires an ERC20 contract to run. You can deploy a standard one and then add it to the Openfort dashboard following the same logic as above.
-
We aim to cover gas fees for our users when they mint the NFT. Set a new gas policy for that:
Add a rule so the NFT contract uses this policy:
Add also a rule for the ERC20 contract:
-
- Enter a name (treasure account) and click Add account. This will automatically create a custodial wallet that we'll use to transfer the ERC20 tokens to the users. IMPORTANT: Transfer a good amount of tokens from the created ERC20 contract to this wallet to facilitate testing.
- Enter a name (minting account) and click Add account. This will automatically create a custodial wallet that the users will transfer the NFTs to when they choose the sell them. They'll get rewarded from the Treasury Dev Account afterwards.
Set up ugs-backend
-
Set Openfort dashboard variables
Open the solution with your preferred IDE, open
SingletonModule.cs
and fill in these variables:OfApiKey
: Retrieve the Openfort secret keyOfNftContract
: Retrieve the NFT contract API IDOfGoldContract
: Retrieve the ERC20 contract API IDOfSponsorPolicy
: Retrieve the Policy API IDOfDevTreasuryAccount
: Retrieve the Treasury Developer Account API IDOfDevMintingAccount
: Retrieve the Minting Developer Account API ID
-
Package Code
Follow the official documentation steps.
-
Deploy to UGS
Follow the official documentation steps.
-
Add a currency to UGS project
Follow the official documentation steps to add a currency to your game:
Set up unity-client
In Unity go to Edit --> Project Settings --> Services and link the unity-client
to your UGS Project:

Select your Environment:

Now make sure In-App Purchasing is enabled and Current Targeted Store is set to Google Play. Then follow the instructions to set the Google Play License Key to your UGS project:

Your UGS project dashboard should look like this:

Apple AppStore doesn't need this license key configuration so if you're targeting iOS you're good to go.
Android deployment
-
Build App Bundle
In Unity go to Android Player settings and make sure Other Settings looks like this:
Also, make sure to sign the application with a Keystore in Publishing Settings:
Then go to Build Settings, check Build App Bundle (Google Play) and choose Build:
-
Set up Google Play Console
-
Create internal release
On your Google Play Console app, go to Release --> Testing --> Internal testing --> Testers and select or create an email list with the emails that will test your app. Then choose Create new release:
Upload the
.aab
file and then choose Next:If needed, solve pending errors and warnings and then choose Save and publish:
-
Import IAP catalog
On your Google Play Console app, go to Monetize --> Products --> In-app products and choose Import:
Upload the
GooglePlayProductCatalog.csv
file (which contains all the in-app products) and choose Import:You should see all the products have been created:
-
-
Testing
Once the internal testing release is published, you have two options to test:
- Build and run the .apk directly to your device (if the version number is the same as in the internal release).
- Download the app from Google Play through the internal testing link:
iOS deployment
-
Xcode: Build & Archive & Upload
In Unity go to File --> Build Settings and choose Build And Run:
This will automatically open Xcode. If you encounter a
signing error
, select your development team and enable Automatically manage signing:Start the building process again (cmd + B) and when completed, go to Product --> Archive:
After completing, choose Distribute App:
Select TestFlight & App Store to enable both internal and external testing and choose Distribute:
The app will be uploaded to App Store Connect:
-
Set up App Store Connect app
Go to App Store Connect Apps, choose your newly uploaded app and under Distribution --> In-App Purchases add the purchases:
Remember to fill the same Product ID as you have set in your Unity IAP Catalog. Do it for all your products:
Go to the TestFlight section and choose Manage Missing Compliance for your build:
-
Testing
Go to Internal Testers (add testers) and you should see your build ready to be tested:
Open the TestFlight in the iOS device where your tester Apple ID is configured and test the app!
Conclusion
Upon completing the above steps, your Unity game will be fully integrated with Openfort and Unity In-App Purchasing service. Always remember to test every feature before deploying to guarantee a flawless player experience.
For a deeper understanding of the underlying processes, check out the tutorial video.
Get support
If you found a bug or want to suggest a new [feature/use case/sample], please file an issue.
If you have questions, or comments, or need help with code, we're here to help:
- on Twitter at https://twitter.com/openfortxyz
- on Discord: https://discord.com/invite/t7x7hwkJF4
- by email: support+youtube@openfort.io