# ONE store In-App支付概要

### **ONE store In-App支付是什么？** <a href="#onestoreinapp-zhi-fu-gai-yao-onestoreinapp-zhi-fu-shi-shen-me" id="onestoreinapp-zhi-fu-gai-yao-onestoreinapp-zhi-fu-shi-shen-me"></a>

One store的In-App支付(In-App Purchase, IAP)是一种利用One store認證和支付系统，向用户銷售android應用程式內商品，並向開發者付費的服务。

In-App商品支付需要与One store服务(ONE store service, OSS) 應用軟件進行聯動，One store服務應用軟件與One store支付服務器聯合執行In-App商品的支付。

為了使用One store的In-App支付， 需要套用"One store IAP SDK(In-App Purchase Software Development Kit)"。&#x20;

### **In-App商品的類型** <a href="#onestoreinapp-zhi-fu-gai-yao-inapp-shang-pin-de-lei-xing" id="onestoreinapp-zhi-fu-gai-yao-inapp-shang-pin-de-lei-xing"></a>

One store In-App支付API V7（SDK V21）提供管理型商品和訂閱型商品兩種類型的In-App商品。 首先，請您確認每個類型都具有那些特性，然後嘗試構建符合您所提供的App商品的In-App商品目錄。\
&#x20;

| 區分                 | 内容                                                                                                                                                                |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 管理型商品              | <p>在購買後使用(consume)之前不会再購買的App商品。要想重新購買該App商品，需要先使用(consume)已購買商品。<br>利用管理型商品的特性，可提供消耗性/永久性/期間制類型的In-App商品。</p>                                                    |
| 包月型商品 (Deprecated) | <p>一旦加入，每月自動支付一定金額的App商品，自動支付更新（再支付）由One store處理。<br>套用SDK V21 (API V7)後，無法創建新的包月型商品。(現有包月型商品可繼續使用。) <br>可使用訂閱型商品提供定期支付商品。 </p>                                   |
| 訂閱型商品              | <p>從SDK V21(API V7)開始提供的定期支付商品類型。<br>按照規定的周期在One store進行定期支付，為吸引新客户提供促銷功能及變更支付手段等用戶便利功能。<br>訂閱型商品的詳細内容請參考<a href="/pages/wsqOpVE4GpwZEAmLQuZp">適用定期支付</a>的頁面。</p> |

### **支付流程** <a href="#onestoreinapp-zhi-fu-gai-yao-zhi-fu-liu-cheng" id="onestoreinapp-zhi-fu-gai-yao-zhi-fu-liu-cheng"></a>

One store In-App支付大致由以下四个流程组成。&#x20;

#### One store會員登錄 <a href="#onestoreinapp-zhi-fu-gai-yao-onestore-hui-yuan-deng-lu" id="onestoreinapp-zhi-fu-gai-yao-onestore-hui-yuan-deng-lu"></a>

欲使用One store In-App支付服务，必須註冊成為One store會員並處於登錄中的狀態。\
如果收到與登錄失敗相關的錯誤代碼(RESULT\_NEED\_LOGIN)，請調用登錄過程以便登錄到One store，或者引導客戶運行One store應用軟件登錄。

* **引導用戶運行One store應用軟件登錄**

利用dialog等，將"您需要登錄One store會員"傳遞給用戶。該方法為用戶提供簡單的指南，並引到用戶直接運行One store應用軟件。

* **使用launchLoginFlowAsync調用登錄流程**

開發公司將使用launchLoginFlowAsync API來調用登錄畫面。\
用户完成登錄後，可以通過IapResultLIstener（在調用API時將其放入parameter中）傳遞結果值。\
如果在驗證結果代碼值後確認為成功，之後就可以使用One store  In-App支付SDK的API。\
下圖顯示了開發公司應用軟件和One store之間的登錄流程。&#x20;

\
&#x20;

<figure><img src="/files/QhxLGZVkL5CgZlyFDm3g" alt=""><figcaption></figcaption></figure>

請求購買In-App商品

如果想要購買App商品，請先調用商品詳細資訊(queryProductDetailAsync) API，然後拿著收集到的商品資訊，通過launchPurchaseFlow API調用購買頁面。\
支付完成後，您可以通過在初始化PurchaseClient對象時輸入的PurchasesUpdatedListener獲得購買資訊。\
驗證結果代碼值後，如果確認成功，之後進行發放相當於In-App商品的item的流程。 下圖是購買開發公司應用軟件和One store之間In-App商品的流程。  &#x20;

<figure><img src="/files/AgTNV3Wp3sUMiujMRhNq" alt=""><figcaption></figcaption></figure>

#### 確認購買In-App商品  <a href="#onestoreinapp-zhi-fu-gai-yao-que-ren-gou-mai-inapp-shang-pin" id="onestoreinapp-zhi-fu-gai-yao-que-ren-gou-mai-inapp-shang-pin"></a>

使用One store IAP library V6以上版本，需要3天内確認購買。如果沒有確認購買，購買金額將退還给客戶。\
使用以下兩種方法可以確認購買。&#x20;

* **消費 (consume)**&#x20;
  * 管理型商品的特徵是，在購買後使用（consume）前不能再購買。 因此，提供管理型商品中可重複購買的消費性商品时，必須使用PurchaseClient.consumeAsync（）進行使用處理後，客戶才能重新購買該商品。&#x20;
  * 安裝啟動消費性類型的商品時，需要在購買流程完成後立即使用到購買的商品，並在消費完成後發放item。&#x20;
  * 建議用戶在運行應用軟件（遊戲）時或登錄應用軟件（遊戲）時調用上述API，事先確認是否存在未支付的App商品，並添加支付App商品的流程。<br>

    <figure><img src="/files/rvJDZnmfVje2T9ALbqWL" alt=""><figcaption></figcaption></figure>
* **確認購買商品 (acknowledge)**
  * 不是消費性商品時，請使用PurchaseClient.acknowledgeAsync（）。可以不進行使用處理，僅通過購買確認的方式實現永久性商品。
  * 安裝啟動永久性類型商品時，需進行確認購買（acknowledge）而不是使用。
  * 訂閱類商品也需要確認購買，僅需對首次支付進行確認購買即可。 <br>

    <figure><img src="/files/MH8nTqI0UdWhOfpYs29l" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
因網絡中斷或App突發非正常終止關閉等原因，有可能發生客戶已完成支付，但傳遞給開發公司的支付資訊發生傳遞遺漏，導致無法支付In-App商品的情况。 建議使用購買資訊導入（queryPurchases）及使用（consume）功能確認是否有購買完成卻未發放的商品，對於未發放的商品需要按照流程進行。
{% endhint %}

#### 訂閱型商品管理 <a href="#onestoreinapp-zhi-fu-gai-yao-ding-yue-xing-shang-pin-guan-li" id="onestoreinapp-zhi-fu-gai-yao-ding-yue-xing-shang-pin-guan-li"></a>

訂閱型商品(subscription)在首次購買後，根據商品支付周期定期更新支付。\
One store為用戶提供定期支付商品管理畫面，具有暫停支付、解除訂閱、變更支付手段等多種功能。   \
可以調用launchManageSubscription API或deep link，提供定期支付管理選單。&#x20;

### 推薦開發環境 <a href="#onestoreinapp-zhi-fu-gai-yao-tui-jian-kai-fa-huan-jing" id="onestoreinapp-zhi-fu-gai-yao-tui-jian-kai-fa-huan-jing"></a>

為了應用One store IAP SDK，需要以下開發環境。

* Android 6.0以上版本(API版本23以上)
* [Java SDK 11版本](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
* [Android studio 2.0以上版本](https://developer.android.com/studio/index.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://onestore-dev.gitbook.io/dev/cht/tools/billing/v21/ov.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
