Skip to content

Install the module, initialize, and log in

To use coupon features, you must install the coupon module in the Hive Axyl SDK, initialize it, and then prepare the login session. If you have not installed the Hive Axyl SDK yet, first install the Hive Axyl SDK.

1. Install the coupon module

Install the coupon module together with the common module, the authentication module, and the mailbox module.

1.1. Select common modules

The common module provides the minimum features for using Hive Axyl, so you must select it.

  • com.com2usplatform.hiveaxyl.core: SDK initialization and the basic features that other modules share

1.2. Select modules for coupon features

Coupon features additionally require the following modules.

  • com.com2usplatform.hiveaxyl.auth: Features needed to prepare the login session, such as account creation, login, and token issuance
  • com.com2usplatform.hiveaxyl.mailbox: Mailbox features, such as retrieving the grant mail sent through coupon redemption and marking it as read
  • com.com2usplatform.hiveaxyl.coupon: Features that redeem the coupon code the app user entered and send the grant mail containing the items set for the coupon

The actor that redeems coupons is the app user. Therefore, coupons work only when there is a user login session, and preparing the login session requires the authentication module. The items set for the coupon are put in the grant mail and delivered to the in-app mailbox of the user who redeemed the coupon. For the user to open the grant mail in the app and receive the items, the app must have the mailbox feature, so the mailbox module is also needed.

1.3. Install modules

Install the modules the same way as in SDK installation. Because the Hive Axyl SDK is installed only through a Scoped Registry, keep the Hive Axyl Scoped Registry you registered when you installed the SDK as it is, and add only the modules that coupon features need to dependencies.

In Packages/manifest.json, dependencies must contain com.com2usplatform.hiveaxyl.core together with com.com2usplatform.hiveaxyl.auth for preparing the login session, com.com2usplatform.hiveaxyl.mailbox for retrieving the grant mail and marking it as read, and the coupon feature module com.com2usplatform.hiveaxyl.coupon. If you already installed some modules in Build with Code or Install the mailbox module, do not remove the existing entries; add only the modules that are not there yet.

{
  "scopedRegistries": [
    {
      "name": "Hive Axyl",
      "url": "https://package.openupm.com",
      "scopes": [
        "com.com2usplatform.hiveaxyl"
      ]
    }
  ],
  "dependencies": {
    "com.com2usplatform.hiveaxyl.core": "1.0.0",
    "com.com2usplatform.hiveaxyl.auth": "1.0.0",
    "com.com2usplatform.hiveaxyl.mailbox": "1.0.0",
    "com.com2usplatform.hiveaxyl.coupon": "1.0.0"
  }
}

1.4. Verify the installation

Use the following code to check that the namespaces of the installed SDK and the authentication, mailbox, and coupon modules are recognized correctly.

using Hive.Axyl.Core;
using Hive.Axyl.Auth;
using Hive.Axyl.Mailbox;
using Hive.Axyl.Coupon;

The installation step is complete when the installed modules appear in the Installed state in Unity Package Manager.

2. Initialize the SDK

Method

Initialize

Hive Axyl SDK initialization is a preparation step that the app goes through once before it uses coupon features. When the app starts, call the initialization method and, in that call, register the coupon module together with the authentication and mailbox modules.

  1. Check the App ID you created in Create app information.
  2. Run CoreConfig.CreateBuilder with the App ID to create a CoreConfig object.
  3. Initialize with HiveBootstrap.Initialize, and register AddAuth(), AddToken(), AddMailbox(), and AddCoupon() on builder.

Call the initialization method only once while the app is running. If you already wrote initialization code in Step 4. Initialize the SDK or Install the mailbox module, do not call it again; add only the modules you have not registered yet to the builder of the existing Initialize call.

Call parameters

Field name Type Required Description
config CoreConfig Required The CoreConfig object that holds the App ID. Create it with CoreConfig.CreateBuilder.
assemble Action<IHiveBuilder> Required The builder callback that registers the feature modules to use. To use coupon features, include builder.AddAuth(), builder.AddToken(), builder.AddMailbox(), and builder.AddCoupon().

Call example

The following example registers the modules that coupon features need in the assemble callback, the second argument of Initialize. Because coupons work based on the logged-in user's session, also register AddAuth() and AddToken() in the Initialize call that registers AddCoupon(). Both methods are provided by the com.com2usplatform.hiveaxyl.auth module and are needed to prepare the login session through login and token issuance. Also register AddMailbox(), which is needed to retrieve the grant mail and mark it as read, in the same call.

using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity;   // HiveBootstrap
using Hive.Axyl.Auth;         // AddAuth, AddToken extensions
using Hive.Axyl.Mailbox;      // AddMailbox extension
using Hive.Axyl.Coupon;       // AddCoupon extension

var config = CoreConfig.CreateBuilder("{appId}").Build();

HiveBootstrap.Initialize(config, builder =>
{
    builder.AddAuth();      // Account and authentication (IAuthService)
    builder.AddToken();     // Token issuance (ITokenService)
    builder.AddMailbox();   // Mailbox (IMailboxService)
    builder.AddCoupon();    // Coupon (ICouponService)
});

After that, retrieve and use the registered modules as follows.

  • HiveCore.Resolve<IAuthService>()
  • HiveCore.Resolve<ITokenService>()
  • HiveCore.Resolve<IMailboxService>()
  • HiveCore.Resolve<ICouponService>()

Response data

No data is returned on success.

Response example

IAuthService auth = HiveCore.Resolve<IAuthService>();
ITokenService token = HiveCore.Resolve<ITokenService>();
IMailboxService mailbox = HiveCore.Resolve<IMailboxService>();
ICouponService coupon = HiveCore.Resolve<ICouponService>();

Response status

Check whether initialization and module registration are complete with the result of the HiveCore.Resolve<T>() calls. If HiveCore.Resolve<IAuthService>(), HiveCore.Resolve<ITokenService>(), HiveCore.Resolve<IMailboxService>(), and HiveCore.Resolve<ICouponService>() all return an instance without throwing an exception, they are complete. For the exception thrown when you retrieve an unregistered module with Resolve<T>() and the common principles of error handling, see Common error handling.

In the following cases, an exception is thrown during initialization. Unlike a Failure you receive as the result of a method call, these exceptions immediately fail the initialization.

  • ArgumentNullException: When you pass null to config
  • InvalidOperationException: When you call the initialization method again after initialization is already complete
  • DllNotFoundException: When the native plugins that the SDK uses cannot be loaded on Windows. For the causes and how to handle them, see Windows runtime prerequisites

3. Activate the login session

Coupons work only when there is a user login session. This is because the actor that redeems coupons is the app user, and the grant mail containing the items set for the coupon is also sent to that user's mailbox. Activate the login session first, and then call the coupon redemption method.

Next steps