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 developer dashboard 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 (you need to provide the price info).
Store Offer structure
usingRGN.Modules.VirtualItems;usingSystem;usingSystem.Collections.Generic;namespaceRGN.Modules.Store{ [Serializable]publicclassStoreOffer { /// <summary> /// Unique id of the store offer /// </summary>publicstring id; /// <summary> /// Store offer name /// Is used also to store localization key for the name /// </summary>publicstring name; /// <summary> /// Store offer description /// Is used also to store localization key for the name /// </summary>publicstring description; /// <summary> /// List of application ids where this item is used /// </summary>publicList<string> appIds; /// <summary> /// List of tags to filter the offers /// You can place multiple store offers into one category tag /// For example in a shooter game: "guns", "rifles" /// Or you can also have one store offer for every category /// with multiple virtual items /// </summary>publicList<string> tags; /// <summary> /// Store offer image url /// </summary>publicstring imageUrl; /// <summary> /// Date and time when the store offer was created /// In milliseconds since midnight, January 1, 1970 UTC. /// This field is automatically populated by the backend /// </summary>publiclong createdAt; /// <summary> /// Date and time when the store offer data was last time updated /// In milliseconds since midnight, January 1, 1970 UTC. /// This field is automatically populated by the backend /// </summary>publiclong updatedAt; /// <summary> /// User Id who created the store offer /// This field is automatically populated by the backend /// </summary>publicstring createdBy; /// <summary> /// User Id who last time updated the store offer /// This field is automatically populated by the backend /// </summary>publicstring updatedBy; /// <summary> /// The time when the store offer is available /// This is used for limited time offers (LTO) /// </summary>publicTimeInfo time; /// <summary> /// List of store offer custom json. It is used to store /// game specific json in json format. /// For example: you can attach some json like /// "additiona_description", "in_app_products" to this offer /// </summary>publicList<Properties> properties; /// <summary> /// Virtual items ids list /// It contains the virtual items available to sell /// </summary>publicList<string> itemIds; /// <summary> /// Price information for the store offer virtual items /// It is very powerful: you can sell the same virtual item for different /// currencies and prices in the same store offer. /// You can also combine two and more {currency, price} to sell one item /// by using the group field. To "group" currencies and prices together. /// </summary>publicList<PriceInfo> prices; /// <summary> /// The Virtual Items data /// This is populated only when the /// GetWithVirtualItemsDataByAppIdsAsync method is used. /// </summary>publicList<VirtualItem> GetItems(); }}
Buy Virtual Items and Store offers:
In case the virtual item contains prices information, you can let the user purchase virtual items by using the following example:
The example above shows the purchase of a single virtual item. If you provide more than one item in the request, the purchase process will try to buy all items. In the case that the user does not have enough coins an exception will be thrown.
In case you want to sell virtual items as a pack, you can create a store offer containing those virtual item ids. Later you can use the store offer id to purchase the virtual items pack:
As you can see above the GetForCurrentAppAsync has a limit parameter. It is used to support pagination in case you have a lot of store offers and don't want to load them all at once.
The flow for pagination is following:
Make the GetForCurrentAppAsync(limit: itemsToRetrieveInt); and cache the result
Show the result in the UI
When the User scrolls down and it is time to load new items, make a second call GetForCurrentAppAsync(limit: itemsToRetrieveInt, startAfter: "last_loaded_offer_id"); but this time provide the startAfter parameter. This parameter takes the store offer id.
You can also provide an optional parameter appId to the GetByTagsAsync method call. This parameter is working in combination with the method SetTagsAsync. The SetTagsAsync method has also an optional appId parameter. When this parameter is provided, we automatically attach appId to every tag in thetagsarray and query the database. This is specifically done to let the app developers have unique tags for virtual items per app id.
Get by timestamp:
It is possible to set store offers to be available for a limited time. After you add a new store offer in the developer dashboard you can later set the TimeInfo for the store offer. The time info has the following format:
The hasStart parameter specifies if the store offer has a starting date. If it is set to true, then the start parameter should have an appropriate Unix timestamp value. The same applies to the hasEnd and end parameters.
The hasInterval parameter specifies if the store offer will be unavailable in between the start and end time. For example, a store offer can be available 2 hours every day for 2 weeks starting from now. In this case the TimeInfo values will be:
Often it is convenient to get the store offers with the virtual items data to display in the UI. By default, the store offers contain only virtual item ids and you need to query the virtual items separately by ids (VirtualItemsModule.I.GetVirtualItemsByIdsAsync())
The StoreModule has a method to retrieve the StoreOffer data with the VirtualItem data included: