Google Pay SDK检查用户是否已添加特定卡

时间:2020-02-05 11:11:25

标签: android kotlin google-pay

Google Pay API 是否可以检查用户是否已在 Google Pay 中添加了特定卡?我知道有一种检查用户是否可以付款的方法。

From official docs:
...调用isReadyToPay API以确定用户是否可以使用Google Pay API付款。

private void possiblyShowGooglePayButton() {
    final Optional<JSONObject> isReadyToPayJson = PaymentsUtil.getIsReadyToPayRequest();
    if (!isReadyToPayJson.isPresent()) {
      return;
    }
    IsReadyToPayRequest request = IsReadyToPayRequest.fromJson(isReadyToPayJson.get().toString());
    if (request == null) {
      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.
    Task<Boolean> task = mPaymentsClient.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());
            }
          }
        });
  }

但是??上面的代码不适合我的需求。也许有人对此有解决方案?

1 个答案:

答案 0 :(得分:0)

特定卡是什么意思?

documentation existingPaymentMethodRequired很容易错过一件事。

默认情况下,API会检查设备/应用程序是否可用于付款,但通过existingPaymentMethodRequired选项将检查用户是否具有可用于付款的现有付款方式