Google Pay 支付接入

文檔地址:

  1. 準(zhǔn)備文檔
  2. 集成文檔
  3. 官網(wǎng)example

準(zhǔn)備工作:

  1. 掃盲:如何使用Play管理中心?

  2. Google Play 服務(wù)框架套件
    Github: Google Play 三件套
    套件安裝: Google Play套件裝機(jī)
    我的是華為榮耀3.0系統(tǒng),選擇:華古套件
    測(cè)試了下,Google配件版本都可以,但無(wú)法正常啟動(dòng)。。。
    遂,借到測(cè)試機(jī)-sumsung:密碼 1111,可用。

  3. 創(chuàng)建產(chǎn)品:創(chuàng)建應(yīng)用內(nèi)商品/訂閱產(chǎn)品

  4. 官網(wǎng)代碼: 封裝實(shí)現(xiàn)

  5. 掘金經(jīng)驗(yàn)貼宏觀:Google Play 應(yīng)用上架從0到1

  6. 防踩坑:Google Pay踩坑日記

  7. 應(yīng)用遷移到其他開(kāi)發(fā)者賬號(hào)

  1. App 出海實(shí)踐:Google Play 結(jié)算系統(tǒng)

Google Play遷移應(yīng)用至新開(kāi)發(fā)者賬號(hào)下:

登陸舊開(kāi)發(fā)者賬號(hào)進(jìn)入App tansfer:https://play.google.com/console/u/0/developers/4850394672493643989/app-transfer
依次輸入相關(guān)信息:
● 輸入當(dāng)前賬號(hào)的全名:xxx
● 輸入新賬號(hào)的郵箱地址:xxx
● 輸入新賬號(hào)的交易ID:需查詢到訂單號(hào),并且按照指定規(guī)則輸入。
形如:token.xxxxxxxx
registration-xxxxx-xxx-xxx-xxxx-xxxxx
登錄新的Google賬號(hào),登錄Google payment:https://pay.google.com/gp/w/home/activity?sctid=6026630207844823
● 遷移的原因:下拉可選擇具體的原因;
● 選擇需要遷移的App。
tips:完成上述步驟后申請(qǐng)遷移,會(huì)進(jìn)入Google審核,審核時(shí)間預(yù)計(jì)2個(gè)工作日,通過(guò)后會(huì)以郵件的形式給您回復(fù)。

設(shè)計(jì)

  • 時(shí)序圖


    google_pay_shixu.png
  • 流程圖


    google_pay_liucheng.png
  • 代碼結(jié)構(gòu)

tips:涉及雙界面,考慮Service。
雙界面包含:個(gè)人中心界面UI,權(quán)益訂閱界面UI
主要類:PayActivity:權(quán)益訂閱界面。
PayViewModel:權(quán)益數(shù)據(jù)處理界面
PayService:建立連接Google Pay,全局維護(hù)訂閱權(quán)益。
PayClient:操縱Google SDK,與Google 支付服務(wù)建立連接。

項(xiàng)目Code梳理:

遇到case:
產(chǎn)生原因: Google Play服務(wù)框架等未安裝,或機(jī)型不適配。
2023-09-06 20:50:33.062 14131-14131/com.qianfan.aihomework E/PayClient: [, , 0]:startConnection.onBillingSetupFinished: Response Code: BILLING_UNAVAILABLE, Debug Message: Billing service unavailable on device.

feature分支,無(wú)法登陸。

主要通過(guò)操縱client對(duì)象進(jìn)行各類操作。

private val billingClient by lazy {
        BillingClient.newBuilder(AppContext)
            .setListener(purchasesUpdatedListener)
            .enablePendingPurchases()
            .build()
    }

全局監(jiān)聽(tīng)支付調(diào)起后的狀態(tài),如:用戶取消等。
tips: 跟billingClient關(guān)系:1對(duì)1

PurchasesUpdatedListener

進(jìn)行同服務(wù)端的連接,連接到 Google Play

billingClient.startConnection(object :BillingClientStateListener {
    override fun onBillingSetupFinished(billingResult: BillingResult) {}
    override fun onBillingServiceDisconnected() {}
}

ProductType 可以是:
ProductType.INAPP(針對(duì)一次性商品),
也可以是 ProductType.SUBS(針對(duì)訂閱)。

服務(wù)端?
如何獲取所有商品?
https://github.com/android/play-billing-samples/issues/565
通過(guò)google api ?
https://developers.google.com/android-publisher/api-ref/rest/v3/inappproducts/list

嘗試在線調(diào)用下api,結(jié)果如下:

{
"error": {
  "code": 403,
  "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.",
  "errors": [
    {
      "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.",
      "domain": "androidpublisher",
      "reason": "projectNotLinked"
    }
  ]
}
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容