我按照Google Pay for Payments > Android教程中的确定使用 Google Pay API 付款的准备情况步骤来确定 Google Pay 钱包的准备情况。
在我将IsReadyToPayRequest对象existingPaymentMethodRequired中的属性设置为 之前,此方法工作正常。我的目的是确定钱包是否至少有一张卡,但我总是从请求中得到。我的环境是测试环境,Android手机注册了信用卡。有谁知道为什么?truefalse
public static Optional<JSONObject> getIsReadyToPayRequest() {
try {
JSONObject isReadyToPayRequest = getBaseRequest();
isReadyToPayRequest.put(
"allowedPaymentMethods", new JSONArray().put(getBaseCardPaymentMethod())
);
isReadyToPayRequest.put("existingPaymentMethodRequired", true);
return Optional.of(isReadyToPayRequest);
} catch (JSONException e) {
return Optional.empty();
}
}
private static JSONObject getCardPaymentMethod() throws JSONException {
JSONObject cardPaymentMethod = getBaseCardPaymentMethod();
cardPaymentMethod.put(
"tokenizationSpecification", getGatewayTokenizationSpecification()
);
return cardPaymentMethod;
}
private static JSONObject getBaseCardPaymentMethod() throws JSONException {
JSONObject …Run Code Online (Sandbox Code Playgroud)