GooglePay
# 概述
PingPong Checkout 通过 SDK 内嵌到合作商户 APP 的方式,向商户提供基于 Android 移动设备客户端的支付能力。
本指南定义了合作商户接入 PingPong Checkout SDK(Android)的接口标准。
提示
商户APP在向用户展示收银台之前,要根据 SDK 提供的方法判断是否向用户提供 Google Pay支付方式,
从而判断是否显示 Google Pay 支付按钮。
从商户角度来看,需要做以下几步交互:
- 商户 APP 调用 SDK 接口判断是否支持 Google Pay
- 商户 APP 收到判断结果,决定是否向用户展示 Google Pay支付按钮
# 支付流程
在前序步骤中,商户能够向用户提供 Google Pay 支付能力后,用户点击 Google Pay 支付按钮,触发交易申请,系统处理中,用户等待交易结果。
在商户侧角度来看,需做以下几步交互:
- 商户 APP 向商户后台初始化订单交易
- 商户 Server 返回商户APP请求结果
- 商户 APP 调用 SDK 交易请求方法(具体参数详见下面接口说明)
- SDK 调用商户 APP 支付结果接口,返回支付交易结果
- 商户 APP 向用户展示交易结果
- 同时 PingPong 后台异步通知交易结果到商户 Server
警告
与 ApplePay 的差异点,Google Pay 存在需要用户3D认证的可能性。当 PP Checkout判断用户需要做3D认证后,调用 SDK 中的 3D 插件,弹出认证页面,用户完成认证后,PP Checkout 后端继续交易流程
# 接入说明Android 10 or higher
# 下载
步骤 1. 在你的根目录下的 build.gradle(settings.gradle)文件的 repositories 部分末尾添加 Maven 仓库
allprojects {
repositories {
//...
maven {
url 'https://cardinalcommerceprod.jfrog.io/artifactory/android'
credentials {
username 'cybersource_pingpongpay_wangyy'
password 'OOBu3#PtZwe.}mYfgc4)'
}
}
maven {
url "https://mobile-sdks.forter.com/android"
credentials {
username "forter-android-sdk"
password "HvYumAfjVQYQFyoGsmNAefGdR84Esqig"
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
步骤 2. 添加依赖项
dependencies {
implementation 'com.google.android.gms:play-services-wallet:19.1.0'
implementation 'org.jfrog.cardinalcommerce.gradle:cardinalmobilesdk:2.2.7-2'
implementation 'com.forter.mobile:fortersdk:2.4.13'
}
2
3
4
5
6
7
8
9
请将 PingPong SDK 放置在 lib 文件夹中。
同时,请确保将以下依赖项添加到您应用程序的 build.gradle 文件中。
当前版本号是最新版本(2023-01-01),因此您可以选择更高版本的依赖项来适配您的应用程序。
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'
implementation('com.squareup.retrofit2:retrofit:2.9.0') {
exclude module: 'okhttp'
exclude module: 'okio'
}
implementation('com.squareup.retrofit2:converter-gson:2.9.0') {
exclude module: 'okhttp'
exclude module: 'okio'
exclude module: 'gson'
}
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.11'
implementation 'com.google.code.gson:gson:2.10.1'
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Google Pay 静态支付按钮资源和布局文件
请将适当的按钮布局文件链接到应该显示该按钮的布局中。
例如:
<include layout="@layout/googlepay_button" />
<include layout="@layout/buy_with_googlepay_button" />
<include layout="@layout/pay_with_googlepay_button" />
2
3
4
5
6
7
8
9
Google Pay支付按钮有三种不同的样式可供选择: dark, light, and light with an outline.
# Google Pay 的标志
当您在支付流程中展示 Google Pay 作为支付选项时,请仅使用下方提供的 Google Pay 标志
android:src="@drawable/google_pay_mark_800" // .xml
android:src="@drawable/google_pay_acceptance_mark_800" // .png
2
3
# 品牌指南
要获取完整的指南和最佳实践,请参考以下资源
# 缩减资源
我们强烈建议在您的 build.gradle 文件中启用资源收缩(resource shrinking)。要了解更多信息 请访问 Android Studio 文档中的缩减资源 (opens new window)
# SDK 调用示例
# 设置环境参数
接口名:setSDKEnvironment
# 请求参数:
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
| environment | enum | M |
示例:
PPPayManager.getInstance().setSDKEnvironment(PPPayEnvironment.SANDBOX)
# Google Pay展示判断示例
接口名:canGooglePay
# 请求参数:
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
| context | Context | M | Context |
# 响应参数:
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
| code | String | M | 状态码 |
| description | String | M | 结果描述 |
| canGooglePay | Boolean | M |
示例:
private fun possiblyShowGooglePayButton() {
PPPayManager.getInstance().canGooglePay(this) {
when (it.code) {
CanGooglePayResult.SUCCESS -> {
if (it.canUseGooglePay) {
// show GooglePay button
vb.googlePayButton.root.visibility = View.VISIBLE
} else {
}
}
CanGooglePayResult.ERROR -> {
}
else -> {
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33