SphereOneManager

The SphereOneManager is how you will interact with the SDK. Its a singleton MonoBehavior that can be accessed anywhere in your code, and will stay instantiated across scenes with DontDestroyOnLoad(). It should be placed in your starting scene.

Configuration

You'll need to add your api key (provided by SphereOne), and if using Popup mode add your Client Id and Redirect URL (the URL your game is deployed to or http://localhost:port for testing).

Login Mode

You will need to choose a login mode for you game. Currently we support 2 modes: Slideout and Popup.

  • Slideout Mode
    • This mode will embed the SphereOne Wallet (https://wallet.sphereone.xyz) into an iframe that slides out on top of your game. This gives your players a convenient way to quickly access their wallet without leaving the game.
  • Popup Mode
    • This mode will launch an auth popup when SphereOneManager.Instance.Login() is called. Once the player logs in, it will redirect them back to your game and load their credentials.
    • Once authenticated, the SDK will encrypt the player's credentials and store in the browser's local storage.

iOS / Android

  • A custom Redirect Scheme can be used to differentiate your app from others installed on the users device.
  • This can be configured on the SphereOneManager editor
  • Make sure to update the scheme value in the android manifest file - Assets/Plugins/Android/AndroidManifest.xml

Environments

  • Editor
    • For local testing in the editor (play mode), mock data can be used to simulate data coming from the SphereOne API. This mode uses mock data from multiple json files located in SphereOne / Scripts / MockData.
    • You must switch to production before building.
  • Production
    • This environment will connect to the production SphereOne API, and use real data.

Accessing the SDK

using SphereOne;

...

SphereOneManager.Instance

Accessing Data

TODO

Events

The SDK provides delegate events that your scrips can observe.

These events trigger when new data is fetched from the Sphere One API. This happens during the awake() method of SphereOneManager, or when you manually call to fetch new data.

void OnEnable()
{
  SphereOneManager.onUserLoaded += UserLoaded;
  SphereOneManager.onUserLogout += ClearAll;
  SphereOneManager.onUserWalletsLoaded += WalletsLoaded;
  SphereOneManager.onUserBalancesLoaded += AccountsLoaded;
  SphereOneManager.onUserNftsLoaded += NftsLoaded;
}

void OnDisable()
{
  SphereOneManager.onUserLoaded -= UserLoaded;
  SphereOneManager.onUserLogout -= ClearAll;
  SphereOneManager.onUserWalletsLoaded -= WalletsLoaded;
  SphereOneManager.onUserBalancesLoaded -= AccountsLoaded;
  SphereOneManager.onUserNftsLoaded -= NftsLoaded;
}

void UserLoaded(User user)
{
  // do work
}

void WalletsLoaded(List<Wallet> wallets)
{
  // do work
}

...

Create a charge

var chargeItems = new List<ChargeItem>
{
  new ChargeItem
  {
      name = "Your Item",
      image = "https://your-image-url.somewhere.com",
      amount = 0.9,
      quantity = 1,
   }
};

var chargeRequest = new ChargeReqBody
{
    chain = SupportedChains.SOLANA,
    symbol = "SOL",
    amount = 0.9,
    tokenAddress = "So11111111111111111111111111111111111111112",
    items = chargeItems,
    successUrl = "https://your-website.com/success",
    cancelUrl = "https://your-website.com/cancel",
};

var isTest = false;
var charge = await SphereOneManager.Instance.CreateCharge(chargeRequest, isTest);

if (charge == null) {
  // Handle the error
  return;
}

Debug.Log(charge.ToString());

Pay a charge

var payment = await SphereOneManager.Instance.PayCharge(charge.chargeId);

if (payment == null)
{
  // Handle the error
  return;
}

Debug.Log(payment.ToString());

// Payment has been submitted, it will take a few minutes to process

// At this point, your game server should listen to the webhook from sphereone (setup in the merchant dashboard)
// Sphereone will trigger the webhook when the payment completes successfully or fails