Skip to content

Stratkit Unity IAP Shop

The package contains a module that manages the Unity IAP Shop logic by initializing the offers for the user received from the assigned implementation of IShopHandler.

Shop Offers

Bytro has the concept of Shop Offer, which may be a purchasable package in the store, a gift or a rewarded video. It is handled by their own Web Offers Editor. - Alpha offer web editor: has all items defined in Alpha environment, with its own database. - Beta offer web editor: has all the configurations defined in Beta, but shares the same database with Live.[1] - Live offer web editor: has all the configurations defined in Live, but shares the same database with Beta.[1]

These offers have an itemId that we get with the WebAPI in the form of a component OfferIdComponent. Please make sure that the same itemId is used across Alpha, Beta and Live.

[1] Beta and Live share the same database. This means, all items and their settings are the same for both, but the configuration available can differ. For example, a titleId can exist in Beta but not in Live. Setting such titleId in an itemId will show up in Beta but in Live it would just default to some other known titleId.

Flow for first time projects

  1. Request the creation of the project (e.g. WHS titleId 40000) and corresponding scopes (e.g. whs-android-app or whs-ios-app) in the web shops
  2. Go to the Payment Method editor (inside the same tool), look for google or istore and edit the payment method. Inside there should be a field called limitedToScope, in there, select the scopes that are related to the new project (i.e. for google activate whs-android-app, for istore activate whs-ios-app).
  3. Once the payment methods have been updated, it is advised to press on Clear Cache Namespaces on memcache and select the right namespace (sup_memcache_ns_offers).

Flow to create offers

The original flow is described in a series of videos in Google Drive. You may request access to the folder if you can't see it, but this document tries to highlight the most important steps otherwise.

1. Create offers in web editor tool

There's two ways to create new offers. - (Advanced) You can either create a SQL command to insert the new offers directly into the databases, if you have access to them. You may use this template for the SQL generation. - (Recommended) Access the web tools and create the offers one by one. There's one for Alpha, one for Live.

Here we'll assume that you do it through the web tools. - Alpha offer web editor - Live offer web editor

  1. Create the shop offers (also known as items) for your specific game. If you're creating store packages (for GooglePlay, App Store, etc.) you will need to create a single item for each store. Create the shop offers on both alpha and live.
  2. Deactivate the shop offers on live
  3. Enable on alpha

2. Create entries in the stores (if required)

If you're creating a shop offer that is meant to be purchased from a store, create them in the corresponding stores (GooglePlay, Apple App Store, etc.).

There is a very specific name pattern that must be followed: - [store_prefix]_[shop_offer_item_id] Each store has its own prefix. - GooglePlay: ps - Apple's App Store: ios

E.g. - Given an offer for GooglePlay with Id 1234, the package must be called ps_1234 - Given an offer for the App Store with Id 4321, the package must be called ios_4321

3. Add additional information in editor

In order to give more data to these offer ids, we have a PropertyCollection for ShopOffers.

In there we can add more data to each offer as needed, like their GooglePlayStore package name.

In case of need to add new stores, just create new components to extend the shop offer's data.

For convenience, you can create a ShopOfferImporter to import offers directly from Bytro's shop-offer-alpha-web-tool into the project as if they were balancing entries. This tool imports from an HTTP request into CSV and then uses a regular ContentItemImporter to parse the CSV. You can extend the CSV that gets generated by using AShopOfferToCsvExtension and adding these entries to the ShopOfferFromWebToCsv scriptable object.

4. Test on an Alpha environment

Test your packages in an alpha environment.

5. Enable for live

Once tested, activate the offers on the live shop offer web editor, when ready to release.

API Examples

How to request a purchase:

World world = // reference to the persistent world
EntityManager entityManager = world.EntityManager;
Entity purchaseEntity = entityManager.CreateEntity(typeof(ShopPurchaseRequestData));
entityManager.SetComponentData(purchaseEntity, new ShopPurchaseRequestData { ProductId = "12345" });
How to get successful purchase result:
// in OnUpdate():
Entities.WithoutBurst().WithStructuralChanges()
    .WithAll<ValidatedPurchaseTag>()
    .ForEach((Entity entity, ValidatedPurchaseTag purchaseData) => {
        // show a message to user indicating successful purchase
    }).Run();

How to get failed purchase result:

// for purchases failed before validation:
Entities.WithoutBurst().WithStructuralChanges()
    .WithAll<PurchaseFailedData>()
    .ForEach((Entity entity, PurchaseFailedData purchaseData) => {
        // show a message to user indicating failed purchase reason if it is not cancelled by user
    }).Run();
// for purchases failed at validation:
Entities.WithoutBurst().WithStructuralChanges()
    .WithAll<InvalidatedPurchaseData>()
    .ForEach((Entity entity, InvalidatedPurchaseData purchaseData) => {
        // show a message to user indicating failed validation and suggesting actions like restarting the game or contacting support
    }).Run();