【问题标题】:isReadyToPayRequest returns false when I set the existingPaymentMethodRequired as true当我将 existingPaymentMethodRequired 设置为 true 时,isReadyToPayRequest 返回 false
【发布时间】:2021-03-20 19:22:02
【问题描述】:

我按照此处的说明确定 Google Pay 钱包是否准备就绪。 https://developers.google.com/pay/api/android/guides/tutorial#isreadytopay

在我将 true 设置为 existingPaymentMethodRequired 之前,这一切正常。我的目的是知道钱包是否至少有一张卡,但我总是从请求中得到false。我的环境是测试环境,安卓手机注册了信用卡。有谁知道为什么?文档在这里https://developers.google.com/pay/api/android/reference/request-objects#IsReadyToPayRequest

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 cardPaymentMethod = new JSONObject();
    cardPaymentMethod.put("type", "CARD");

    JSONObject parameters = new JSONObject();
    parameters.put("allowedAuthMethods", getAllowedCardAuthMethods());
    parameters.put("allowedCardNetworks", getAllowedCardNetworks());
    // Optionally, you can add billing address/phone number associated with a CARD payment method.
    parameters.put("billingAddressRequired", true);

    JSONObject billingAddressParameters = new JSONObject();
    billingAddressParameters.put("format", "FULL");

    parameters.put("billingAddressParameters", billingAddressParameters);

    cardPaymentMethod.put("parameters", parameters);

    return cardPaymentMethod;
  }

private static JSONArray getAllowedCardAuthMethods() {
  return new JSONArray()
      .put("PAN_ONLY")
      .put("CRYPTOGRAM_3DS");
}
private static JSONArray getAllowedCardNetworks() {
  return new JSONArray()
      .put("AMEX")
      .put("DISCOVER")
      .put("INTERAC")
      .put("JCB")
      .put("MASTERCARD")
      .put("VISA");
}
  private static JSONObject getBaseRequest() throws JSONException {
    return new JSONObject().put("apiVersion", 2).put("apiVersionMinor", 0);
  }


private void possiblyShowGooglePayButton() {

    final Optional<JSONObject> isReadyToPayJson = PaymentsUtil.getIsReadyToPayRequest();
    if (!isReadyToPayJson.isPresent()) {
      return;
    }

    // The call to isReadyToPay is asynchronous and returns a Task. We need to provide an
    // OnCompleteListener to be triggered when the result of the call is known.
    IsReadyToPayRequest request = IsReadyToPayRequest.fromJson(isReadyToPayJson.get().toString());
    Task<Boolean> task = paymentsClient.isReadyToPay(request);
    task.addOnCompleteListener(this,
        new OnCompleteListener<Boolean>() {
          @Override
          public void onComplete(@NonNull Task<Boolean> task) {
            if (task.isSuccessful()) {
              setGooglePayAvailable(task.getResult());
            } else {
              Log.w("isReadyToPay failed", task.getException());
            }
          }
        });
  }

【问题讨论】:

    标签: android google-play-services google-pay


    【解决方案1】:

    根据documentation,在TEST环境中,它应该总是返回true

    注意:在 TEST 环境中,如果您在 IsReadyToPay() 请求中将 existingPaymentMethodRequired 设置为 true,则响应始终返回 true。

    您能否确认它始终为您返回false?也就是文档不正确?

    【讨论】:

    • 是的,这很奇怪。我已经对文档和代码进行了三重检查。 API 似乎总是返回false。不确定这是否与任何手机设置有关。我正在使用 2 部全新的安卓手机。也许有用的信息——如果我不通过这个属性,我会得到true,我可以继续触发 GPay 流可以在测试环境中与 Stripe 确认交易。
    • 不确定钱包 SDK 是否有可以联系的支持。我现在有点卡住了。
    • 您应该可以通过业务控制台中的“联系支持”菜单获得支持:pay.google.com/business/console
    • 嘿!我对 isReadyToPay() 有同样的问题。你解决了吗?
    • 请注意,当环境设置为PRODUCTION时,它只会返回false。你在PRODUCTION使用这个吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    • 2021-07-02
    • 2020-06-23
    • 2011-08-12
    • 2016-11-14
    • 1970-01-01
    • 2013-01-20
    相关资源
    最近更新 更多