美文网首页
Google Pay 支付接入

Google Pay 支付接入

作者: 千夜零一 | 来源:发表于2023-09-16 15:37 被阅读0次

文档地址:

  1. 准备文档
  2. 集成文档
  3. 官网example

准备工作:

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

  2. Google Play 服务框架套件
    Github: Google Play 三件套
    套件安装: Google Play套件装机
    我的是华为荣耀3.0系统,选择:华古套件
    测试了下,Google配件版本都可以,但无法正常启动。。。
    遂,借到测试机-sumsung:密码 1111,可用。

  3. 创建产品:创建应用内商品/订阅产品

  4. 官网代码: 封装实现

  5. 掘金经验贴宏观:Google Play 应用上架从0到1

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

  7. 应用迁移到其他开发者账号

  1. App 出海实践:Google Play 结算系统

Google Play迁移应用至新开发者账号下:

登陆旧开发者账号进入App tansfer:https://play.google.com/console/u/0/developers/4850394672493643989/app-transfer
依次输入相关信息:
● 输入当前账号的全名:xxx
● 输入新账号的邮箱地址:xxx
● 输入新账号的交易ID:需查询到订单号,并且按照指定规则输入。
形如:token.xxxxxxxx
registration-xxxxx-xxx-xxx-xxxx-xxxxx
登录新的Google账号,登录Google payment:https://pay.google.com/gp/w/home/activity?sctid=6026630207844823
● 迁移的原因:下拉可选择具体的原因;
● 选择需要迁移的App。
tips:完成上述步骤后申请迁移,会进入Google审核,审核时间预计2个工作日,通过后会以邮件的形式给您回复。

设计

  • 时序图


    google_pay_shixu.png
  • 流程图


    google_pay_liucheng.png
  • 代码结构

tips:涉及双界面,考虑Service。
双界面包含:个人中心界面UI,权益订阅界面UI
主要类:PayActivity:权益订阅界面。
PayViewModel:权益数据处理界面
PayService:建立连接Google Pay,全局维护订阅权益。
PayClient:操纵Google SDK,与Google 支付服务建立连接。

项目Code梳理:

遇到case:
产生原因: Google Play服务框架等未安装,或机型不适配。
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分支,无法登陆。

主要通过操纵client对象进行各类操作。

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

全局监听支付调起后的状态,如:用户取消等。
tips: 跟billingClient关系:1对1

PurchasesUpdatedListener

进行同服务端的连接,连接到 Google Play

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

ProductType 可以是:
ProductType.INAPP(针对一次性商品),
也可以是 ProductType.SUBS(针对订阅)。

服务端?
如何获取所有商品?
https://github.com/android/play-billing-samples/issues/565
通过google api ?
https://developers.google.com/android-publisher/api-ref/rest/v3/inappproducts/list

尝试在线调用下api,结果如下:

{
"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"
    }
  ]
}
}

相关文章

网友评论

      本文标题:Google Pay 支付接入

      本文链接:https://www.haomeiwen.com/subject/sxqivdtx.html