NAV
docs

Create Token

Android

如欲了解最新版號 SDK 以及各版號之間的差異性,請參考 Github Release Page : TapPay Android Github

Overview

  1. 專案設置 , 並使用 TPDSetup 設定環境
  2. 確認用戶設備支援 LINE Pay
  3. 建立 TPDLinePay 並給入對應intent filter 的 uri
  4. 利用 TPDLinePay 取得 Prime
  5. 利用 redirectWithUrl 開啟 LINE Application
  6. 用戶付款完成後從 onNewIntent 取得 LinePayResult

Setup Environment

在 Manifest 中您欲接收LINE Pay 付款結果的 Activity 中新增 intent filter 並設定為 single Task:

<activity android:name=".LinePayActivity" 
    android:launchMode="singleTask">            
    <intent-filter>               

        <action android:name="android.intent.action.VIEW" />                
        <category android:name="android.intent.category.DEFAULT" />                
        <category android:name="android.intent.category.BROWSABLE" />                

        <data 
            android:host="tech.cherri" 
            android:scheme="linepayexample" />                  
    </intent-filter>          
</activity>

TPDSetup

static void initInstance(Context context, int appID, String appKey, TPDServerType serverType);

名稱 類別 內容
context Context Android Context
appID int 請參考 appid
appKey String 請參考 appkey
serverType TPDServerType 使用的伺服器種類
測試時請使用 Sandbox 環境 (TPDServerType.Sandbox)
實體上線後請切換至 Production 環境 (TPDServerType.Production)
TPDSetup.initInstance(getApplicationContext(), APP_ID, "APP_KEY", TPDServerType.SANDBOX);

Check LINE Pay Availability

確認用戶設備支援 LINE Pay

boolean isLinePayAvailable = TPDLinePay.isLinePayAvailable(Context context);

Setup TPDLinePay

用 uri 初始化 TPDLinePay 物件 該 uri 為您在 Setup Environment 中設定的(格式為 “scheme:// host”)

範例如下 :

TPDLinePay tpdLinePay = new TPDLinePay(Context context, "linepayexample://tech.cherri");

Get Prime

利用 TPDLinePay 取得 prime, 並將 prime 送至您的 server 呼叫 Pay-By-Prime API

tpdLinePay.getPrime(TPDLinePayGetPrimeSuccessCallback, TPDTokenFailureCallback);

redirectWithUrl

從 TapPay Server 取得 payment_url 後, 您可以使用 redirectWithUrl(payment_url)開啟 LINE Application 或是對應的付款連結.

tpdLinePay.redirectWithUrl(payment_url);

LINE Pay Result

用戶付款完成後您將於 Activity 生命週期的 onCreate 或 onNewIntent (視您的 Activity 是否被 destroyed ) 中取得 LinePayResult, 範例如下:

tpdLinePay.parseToLinePayResult(Context context, intent.getData(), TPDLinePayResult- Listener listener);


您於 onParseSuccess 中可取得本次 LINE Pay 交易的基本資料 (TPDLinePayResult)

Name Content
status 0 代表交易成功, 924 代表使用者取消 LINE Pay 付款
recTradeId 由 TapPay 伺服器產生的交易字串
bankTransactionId 銀行端的訂單編號
orderNumber 您自定義的訂單編號,用於 TapPay 做訂單識別,可重複帶入