---
description: Unity integration
---

# Unity

## Introduction

The users can buy Virtual Items either individually or in packs. After a virtual item is purchased it will be added to the user's inventory. You can use the [PLAY Dev Dashboard](https://ready.gg/developer/) to create new store offers and virtual items.

Each store offer can contain one or more virtual items to sell. Price info data is also part of the store offer. It is also possible to sell virtual items without creating store offers.

<details>

<summary>StoreOffer</summary>

* **id** (string): _Unique id or the store offer._
* **name** (string): _Name of the store offer._
* **description** (string): _Description of the virtual item._
* **appIds** (List\<string>): _List of project id where your store offer can be accessed._
* **createdAt** (long): _Date and time of the store offer creation._
* **updatedAt** (long): _Date and time of the last update on the store offer._
* **createdBy** (string): _User ID of the creator of the store offer._
* **updatedBy** (string): _User ID of the last person who updated the store offer._
* **tags** (List\<string>): _List of tags to filter the store offers._
* **time** (TimeInfo): _Contains the time infos for your store offer._
* **itemIds** (List\<string>): _List of items available in your store offer_
* **prices** (List\<PriceInfo>): _List of prices defined for this store offer. Used to process transaction with the user's currencies._
* **properties** (List\<Property>): _List of properties you can store in json format to retrieve with the store offer._

</details>

### Buy Virtual Items and Store offers

In case the virtual item contains prices information

```csharp
using System.Collections.Generic;
using UnityEngine;
using RGN.Modules.Store;
using RGN.Modules.VirtualItems;
using RGN.Modules.Currency;
using RGN.Modules.Inventory;

public class StoreExamples : MonoBehaviour
{
    public async void BuyVirtualItemAsync(VirtualItem virtualItem)
    {
        List<string> itemsToPurchase = new List<string>() { virtualItem.id };
        PurchaseResult purchaseResult = await StoreModule.I.BuyVirtualItemsAsync(itemsToPurchase);
        // purchaseResult returns the purchased items and updated currencies
        List<Currency> updatedCurrencies = purchaseResult.updatedCurrencies;
        List<InventoryItemData> purchasedItems = purchaseResult.items;
    }
}
```

**Purchase from store offer**

```csharp
using System.Collections.Generic;
using UnityEngine;
using RGN.Modules.Store;
using RGN.Modules.Currency;
using RGN.Modules.Inventory;

public class StoreExamples : MonoBehaviour
{
    public async void BuyStoreOfferAsync()
    {
        PurchaseResult purchaseResult = await StoreModule.I.BuyStoreOfferAsync("storeOfferId");
        // purchaseResult Returns the purchased items and updated currencies
        List<Currency> updatedCurrencies = purchaseResult.updatedCurrencies;
        List<InventoryItemData> purchasedItems = purchaseResult.items;
    }
}
```

**Get store offer**&#x20;

```csharp
using System.Collections.Generic;
using UnityEngine;
using RGN.Modules.Store;

public class StoreExamples : MonoBehaviour
{
    public async void GetStoreOfferAsync()
    {
        // Get the first 10 offer
        List<StoreOffer> offers = await StoreModule.I.GetWithVirtualItemsDataForCurrentAppAsync(10);
        // Pick the first returned offer for log purposes
        StoreOffer firstStoreOffer = offers[0];
        Debug.Log($"Store offer id : {firstStoreOffer.id}");
        // Log the virtuals items name for this offer
        foreach (var virtualItem in firstStoreOffer.virtualItems)
        {
            Debug.Log($"Virtual item name : {virtualItem.name}");
        }
    }
}
```

### Buy Virtual Items NFT

In order to purchase NFTs, there is some additional check you will need to do to make sure the user has all the requirements. \
Here's an example:

```csharp
using System.Collections.Generic;
using UnityEngine;
using RGN;
using RGN.Modules.Wallets;
using RGN.Modules.SignIn;
using RGN.Modules.Store;

public class NFTPurchaseExamples : MonoBehaviour
{
    private async void BuyNFTVirtualItem()
    {
        bool authWithEmail = RGNCoreBuilder.I.CurrentAuthState.AuthProvider == EnumAuthProvider.Email;
        if (!authWithEmail)
        {
            EmailSignInModule.I.TryToSignIn();
            return;
        }

        bool hasBlockchainRequirement = await WalletsModule.I.IsUserHasBlockchainRequirementAsync();
        if (!hasBlockchainRequirement)
        {
            WalletsModule.I.CreateWallet();
            return;
        }

        List<string> virtualItemIds = new List<string> { "myNftVirtualItemId" };
        PurchaseResult purchaseResult = await StoreModule.I.BuyVirtualItemsAsync(virtualItemIds);
    }
}
```
