You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Pay快速启动Demo选DIRECT令牌化无卡片列表显示咨询

关于Google Pay Demo DIRECT模式及开发者资质的问题

问题背景

我按照教程操作Google Pay快速启动Demo,当tokenizationSpecification参数选择getGatewayTokenizationSpecification()方法时功能完全正常:

private static JSONObject getGatewayTokenizationSpecification() throws JSONException {
    return new JSONObject(){{
        put("type", "PAYMENT_GATEWAY");
        put("parameters", new JSONObject(){{
            put("gateway", "example");
            put("gatewayMerchantId", "exampleGatewayMerchantId");
        }});
    }};
}

但切换到getDirectTokenizationSpecification()方法时,却无法显示卡片列表:

private static JSONObject getDirectTokenizationSpecification() throws JSONException, RuntimeException {
    if (Constants.DIRECT_TOKENIZATION_PARAMETERS.isEmpty() || Constants.DIRECT_TOKENIZATION_PUBLIC_KEY.isEmpty() || Constants.DIRECT_TOKENIZATION_PUBLIC_KEY == null || Constants.DIRECT_TOKENIZATION_PUBLIC_KEY == "REPLACE_ME") {
        throw new RuntimeException(
            "Please edit the Constants.java file to add protocol version & public key.");
    }
    JSONObject tokenizationSpecification = new JSONObject();
    tokenizationSpecification.put("type", "DIRECT");
    JSONObject parameters = new JSONObject(Constants.DIRECT_TOKENIZATION_PARAMETERS);
    tokenizationSpecification.put("parameters", parameters);
    return tokenizationSpecification;
}

注:我已经通过以下命令生成公钥并替换到Constants文件中:

# generate private key
openssl ecparam -name prime256v1 -genkey -noout -out key.pem
# generate a base64-encoded public key
openssl ec -in key.pem -pubout -text -noout 2> /dev/null | grep "pub:" -A5 | sed 1d | xxd -r -p | base64 | paste -sd "\0" -

核心疑问

运行该Demo的DIRECT模式是否必须拥有Google Pay开发者资质?


回答

是的,使用Google Pay的DIRECT tokenization模式确实需要具备Google Pay开发者资质,并且完成对应的商家注册与配置,这也是它和PAYMENT_GATEWAY模式最核心的差异之一:

  1. 两种模式的资质要求差异

    • PAYMENT_GATEWAY模式:Demo里用的example网关配置是官方提供的测试体验方案,不需要正式开发者资质就能运行——因为支付处理流程是由第三方网关承接,Google只负责把支付令牌传递给网关,无需直接验证你的商家身份。
    • DIRECT模式:这种模式是直接将支付令牌发送到你自己的服务器进行处理,Google要求你必须是经过注册验证的合规商家,且要在Google Pay Console中完成公钥上传、支付环境配置等操作,否则Google Pay会拒绝返回可用卡片列表。
  2. DIRECT模式的额外配置要求
    除了生成公钥,你还需要完成这些步骤才能让Demo正常运行:

    • 在Google Pay Console中注册你的商家ID,并将生成的公钥上传到对应配置项;
    • 确保Constants.DIRECT_TOKENIZATION_PARAMETERS里的protocolVersion和publicKey参数,和控制台中的配置完全匹配;
    • 验证你的应用签名、包名已在控制台完成绑定,否则请求会被Google Pay拦截。
  3. 测试阶段的临时方案
    如果只是想测试DIRECT模式的逻辑,你可以使用Google提供的官方测试公钥和商家配置,但这类配置只能用于模拟环境,无法处理真实支付请求。一旦要推进到生产环境,必须完成正式的开发者资质申请和全流程配置。


内容的提问来源于stack exchange,提问作者Hardy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:47:44