市場選擇
「市場選擇(market selection)」功能可在支援多個市場(例如 App Store + Hive Store)的環境中,讓使用者選擇購買時要使用的市場。
運作方式¶
本頁說明 market selection 功能所需 API(setMarketSelection、getSelectedMarket 等),以及 API 呼叫順序與使用流程。
在 IAP v4 初始化時呼叫 marketConnect,會回傳裝置可用市場清單。若可用市場超過一個,請呼叫 setMarketSelection 選擇市場,再呼叫 getSelectedMarket,並以回傳的 market type 進行購買。
API 呼叫順序¶
flowchart TD
A(["marketConnect"])
B(["getProductInfo"])
C{"使用者是否<br/>變更付款方式<br/>(市場)?"}
D(["setMarketSelection"])
E(["getSelectedMarket"])
F(["purchase / restore"])
G{"是否以其他市場<br/>進行加購?"}
H([完成])
A -- "App 啟動時呼叫一次" --> B
B -- "每個市場首次各呼叫一次" --> C
C -- "Yes" --> D
C -- "No" --> F
D --> E --> F
F --> G
G -- "Yes" --> D
G -- "No" --> H 呼叫 getProductInfo¶
在上述流程中,getProductInfo 每個市場僅需首次呼叫一次。
- 呼叫成功後,該市場商品資訊會快取於 SDK 內。後續即使透過
setMarketSelection切換市場,也不需再次呼叫。
setMarketSelection¶
setMarketSelection API 透過傳入 IAPV4Type,設定後續購買流程要使用的市場。
setMarketSelection 呼叫時機
請在 marketConnect 之後、purchase 或 restore 之前呼叫。
* 使用者變更付款方式(市場)時呼叫。 * 變更後,purchase 與 restore 會依新市場執行。
IAPV4Type¶
IAPV4Type 是表示 IAP v4 支援市場類型的 enum。
| Value | Name | Description |
|---|---|---|
| 0 | notSelected | 未選擇 |
| 1 | appStore | Apple App Store |
| 2 | 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 |
getSelectedMarket¶
呼叫 getSelectedMarket 可取得目前已選擇的市場類型。
getSelectedMarket 呼叫時機
建議在發出購買請求前,用於確認目前已選擇市場。