Skip to content

Market selection

'Market selection' is a feature that allows users to choose which market to use for purchases in a service environment where multiple markets are available, such as App Store + Hive Store.

How it works

This section describes the APIs required for the 'market selection' feature (setMarketSelection, getSelectedMarket, and so on), as well as the API call order and usage.

First, when the marketConnect API is called during IAP v4 initialization, it returns a list of markets available on the user's device. If multiple markets are available, call the setMarketSelection API to select a market. Then call the getSelectedMarket API and proceed with the purchase using the returned market type.

The following is the recommended API call sequence for implementing the 'market selection' feature.

flowchart TD
    A(["marketConnect"])
    B(["getProductInfo"])
    C{"Does the user<br/>change the payment method<br/>(market)?"}
    D(["setMarketSelection"])
    E(["getSelectedMarket"])
    F(["purchase / restore"])
    G{"Make an additional purchase<br/>with another market?"}
    H([Done])

    A -- "Once when the app launches" --> B
    B -- "Once per market on first use" --> C
    C -- "Yes" --> D
    C -- "No" --> F
    D --> E --> F
    F --> G
    G -- "Yes" --> D
    G -- "No" --> H

Calling getProductInfo

In the API call sequence above, call the getProductInfo API only once per market, on first use.

  • Product information for a market is cached inside the SDK after a successful call. Therefore, even if the market is changed later with setMarketSelection, you do not need to call getProductInfo again for that market.
    • For example, in an app that supports both App Store and Hive Store, if getProductInfo is called once for each market, subsequent market switching only requires calls in the order of setMarketSelectionpurchase.


setMarketSelection

The setMarketSelection API sets the market to be used in the subsequent purchase flow by receiving an IAPV4Type value. Call the setMarketSelection API to select the market to use in the purchase flow, and pass an IAPV4Type value when calling it.

When to call the setMarketSelection API

Call this API after calling the marketConnect API and before calling the purchase API or restore API.

  • Call it when the user changes the payment method (market) in the in-game shop.
  • After the market is changed, purchase and restore operate based on the newly selected market.

IAPV4Type

IAPV4Type is an enum that represents the market types supported in IAP v4.

Value Name Description
0 notSelected Not selected
1 appStore Apple App Store
2 google Google Play Store
3 lebi Lebi Market
4 oneStore ONE Store
5 amazon Amazon Appstore
6 samsung Samsung Galaxy Store
7 huawei Huawei AppGallery
8 funtap Funtap
9 oppoAppMarket OPPO App Market
10 vivoAppStore vivo App Store
11 tencentMyapp Tencent Myapp
12 xiaomiAppStore Xiaomi App Store
13 huaweiAppGalleryChina Huawei AppGallery China
14 facebookCloudGame Facebook Cloud Game
15 hiveStore Hive Store
16 steam Steam
17 nowgg now.gg

Example code

The following example code shows how to use the setMarketSelection API.

using hive;
IAPV4.setMarketSelection(IAPV4Type.HIVESTORE);
#include "HiveIAPV4.h"

FHiveIAPV4::SetMarketSelection(EHiveIAPV4Type::HIVESTORE);
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;
IAPV4::setMarketSelection(IAPV4Type::HIVESTORE);
import com.hive.IAPV4
IAPV4.setMarketSelection(IAPV4.IAPV4Type.HIVESTORE)
import com.hive.IAPV4;
IAPV4.INSTANCE.setMarketSelection(IAPV4.IAPV4Type.HIVESTORE);
import HIVEService
IAPV4Interface.setMarketSelection(.HIVESTORE)
#import <HIVEService/HIVEService-Swift.h>
[HIVEIAPV4 setMarketSelection:HIVEIAPV4TypeHIVESTORE];


getSelectedMarket

Call the getSelectedMarket API to get the currently selected market type. After the call, you can proceed with the purchase using the returned market type.

When to call getSelectedMarket

Use the getSelectedMarket API to check the currently selected market before making a purchase request. Use it after calling the setMarketSelection API to verify that the market has been changed to the intended one.

Example code

The following example code shows how to use the getSelectedMarket API.

using hive;
IAPV4Type marketType = IAPV4.getSelectedMarket();
#include "HiveIAPV4.h"

EHiveIAPV4Type MarketType = FHiveIAPV4::GetSelectedMarket();
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;
IAPV4Type marketType = IAPV4::getSelectedMarket();
import com.hive.IAPV4
val marketType: IAPV4.IAPV4Type = IAPV4.getSelectedMarket()
import com.hive.IAPV4;
IAPV4.IAPV4Type marketType = IAPV4.INSTANCE.getSelectedMarket();
import HIVEService
let marketType = HIVEIAPV4.getSelectedMarket()
#import <HIVEService/HIVEService-Swift.h>
HIVEIAPV4Type marketType = [HIVEIAPV4 getSelectedMarket];