Documentation

​
​

Development

User Acquisition

Monetization

Industry

In-App Purchasing

IAP Client API

IAP SDK API

Webshop Admin API

Webshop Client API

In-App Purchasing

LiveOps
​
​
Get started
  • Overview
  • Introduction to IAP
  • What's new in IAP v5.4
  • Upgrade from IAP v4 to v5
  • AI skill for In-App Purchasing
Direct to Consumer (D2C) payments
  • Direct to Consumer (D2C) payment providers
    • Integrate D2C payment providers workflow
      • Create Remote Catalog
      • Initialize services to handle the start up sequence
      • Fetch Remote Catalog
      • Configure a webhook or Cloud Code module for purchase fulfillment
      • Configure your payment provider
      • Add a routing rule
      • Fulfill purchases
      • Test your integration
    • Initiate a purchase
    • Refunds and disputes for D2C payments
    • Currencies and exchange rates for D2C payments
    • Comply with Apple and Google external purchase requirements
    • Deep link Success URL example
Webshop
  • Overview
  • Get started with webshops
  • Webshop setup
  • Catalog and payments
  • Game integration for webshops
  • Troubleshooting webshops
Platform-native stores
  • Set up IAP for platform-native stores
  • Codeless IAP
Catalogs and store management
  • Create product catalogs
  • Supported stores
Purchases
  • Purchase management and fulfillment
Monitor IAP performance
  • Overview
  • IAP revenue performance
  • D2C performance
Privacy
  • Privacy and consent
  1. Unity In-App Purchasing
  2. Direct-to-Consumer (D2C) payment providers

Initialize services to handle the startup sequence

Initialize Unity Gaming Services, Authentication and In-App Purchasing (IAP) so you can integrate with a Direct-to-Consumer (D2C) payment provider.
Read time 2 minutes
Last updated 2 months ago

Create a script to initialize Unity Gaming Services (UGS) to handle the startup sequence for IAP. This startup script can do the following:
  1. Initialize Unity Gaming Services.
  2. Set up Authentication event handlers.
  3. Sign in.
  4. Initialize IAP and fetch the Remote Catalog. For more information, refer to Fetch your Remote Catalog.
Note
Set your environment before you initialize UGS.
In your initialization script, ensure you assign the
PurchaseManager
component in the Inspector. The
PurchaseManager
component is created as part of the next fetch your Remote Catalog step.

Initialize services example script

The following example script is named
ServiceOrchestrator
:
Important
The recommended best practice is to not use anonymous sign-in as your authentication method, because this wouldn't persist purchases after the session token is lost. If frictionless platform-specific providers are not viable for your app, refer to anonymous authentication and linking.
using System;using System.Threading.Tasks;using Unity.Services.Authentication;using Unity.Services.Core;using UnityEngine;// Ensure you have reference to your PurchaseManager namespace if applicablepublic class ServiceOrchestrator : MonoBehaviour{ // Assign this in the Inspector public PurchaseManager purchaseManager; async void Awake() { try { // 1. Initialize Unity Gaming Services await Unity.Services.Core.UnityServices.InitializeAsync(); // 2. Setup Auth Event Handlers SetupEvents(); // 3. Sign In await SignUpAnonymouslyAsync(); // 4. Initialize IAP and Fetch Catalog await purchaseManager.InitializeIAP(); } catch (Exception e) { Debug.LogException(e); } } // Setup authentication event handlers if desired void SetupEvents() { AuthenticationService.Instance.SignedIn += () => { // Shows how to get a playerID Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); // Shows how to get an access token Debug.Log($"Access Token: {AuthenticationService.Instance.AccessToken}"); }; AuthenticationService.Instance.SignInFailed += (err) => { Debug.LogError(err); }; AuthenticationService.Instance.SignedOut += () => { Debug.Log("Player signed out."); }; AuthenticationService.Instance.Expired += () => { Debug.Log("Player session could not be refreshed and expired."); }; } // Sign in async Task SignUpAnonymouslyAsync() { try { await AuthenticationService.Instance.SignInAnonymouslyAsync(); Debug.Log("Sign in anonymously succeeded!"); Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes Debug.LogException(ex); } }}

Next steps

This page is part of a workflow to set up D2C payment providers with IAP. To continue this workflow, choose one of the following options:
Integrate D2C payment providers
Return to the Integrate D2C payment providers with IAP workflow page.
Fetch your Remote Catalog
Proceed to the next step in the workflow to set up your D2C payment provider.

Copyright © 2026 Unity Technologies
LegalPrivacy PolicyCookiesDocumentation Terms of UseDo Not Sell or Share My Personal InformationYour Privacy Choices (Cookie Settings)

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S and elsewhere (more info here). Other names or brands are trademarks of their respective owners.

Some pages are machine-translated for convenience, and may contain inaccuracies. In the event of conflicting information, the English version is authoritative.

  • On this page
    • Initialize services example script

    • Next steps


Report a problem with this page