Home

Integrate approved In-App (IAP) Purchases in Unity

Integrate approved IAP in your Web3 game - Apple and Android

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:

Application Workflow#

Openfort In-App Purchase Advanced Sample workflow

Prerequisites#

Setup Openfort dashboard#

  • Add an NFT contract

    This sample requires an NFT contract to run. We use 0xbed6a05ce8719bc00db1cc81a814192c82be1bb1 (contract deployed in 80002 Mumbai). You can use it for this tutorial too:

    Contract Info
  • Add an ERC20 contract

    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.

  • Add a Policy

    We aim to cover gas fees for our users when they mint the NFT. Set a new gas policy for that:

    Gas Policy

    Add a rule so the NFT contract uses this policy:

    NFT Policy Rule

    Add also a rule for the ERC20 contract:

    ERC20 Policy Rule
  • Add a Treasury Developer Account

    Enter a name and choose Add account:

    Developer account

    This will automatically create a custodial wallet that we'll use to transfer the ERC20 tokens to the players. IMPORTANT: Transfer a good amount of tokens from the created ERC20 contract to this wallet to facilitate testing.

  • Add a Minting Developer Account

    Enter a name and choose Add account:

    Minting Developer account

    This will automatically create a custodial wallet that the players 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 up unity-client#

In Unity go to Edit --> Project Settings --> Services and link the unity-client to your UGS Project:

Services settings

Select your Environment:

UGS 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:

Google Play License Key

Your UGS project dashboard should look like this:

License key in UGS dashboard

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:

    Android Player settings

    Also, make sure to sign the application with a Keystore in Publishing Settings:

    Application Signing

    Then go to Build Settings, check Build App Bundle (Google Play) and choose Build:

    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:

      New release

      Upload the .aab file and then choose Next:

      Upload build

      If needed, solve pending errors and warnings and then choose Save and publish:

      Save and publish
    • Import IAP catalog

      On your Google Play Console app, go to Monetize --> Products --> In-app products and choose Import:

      Create product

      Upload the GooglePlayProductCatalog.csv file (which contains all the in-app products) and choose Import:

      Import products

      You should see all the products have been created:

      Products created
  • Testing#

    Once the internal testing release is published, you have two options to test:

    Internal testing link

iOS deployment#

  • Xcode: Build & Archive & Upload#

    In Unity go to File --> Build Settings and choose Build And Run:

    Build to Xcode

    This will automatically open Xcode. If you encounter a signing error, select your development team and enable Automatically manage signing:

    Build to Xcode: error

    Start the building process again (cmd + B) and when completed, go to Product --> Archive:

    Build to Xcode: archive

    After completing, choose Distribute App:

    Build to Xcode: Distribute app

    Select TestFlight & App Store to enable both internal and external testing and choose Distribute:

    Build to Xcode: distribute

    The app will be uploaded to App Store Connect:

    Build to Xcode: complete
  • 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:

    Build to Xcode: in-app purchases

    Remember to fill the same Product ID as you have set in your Unity IAP Catalog. Do it for all your products:

    Build to Xcode: catalog

    Go to the TestFlight section and choose Manage Missing Compliance for your build:

    Build to Xcode: catalog
  • Testing#

    Go to Internal Testers (add testers) and you should see your build ready to be tested:

    Build to Xcode: testers

    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: