【发布时间】:2020-07-04 01:08:21
【问题描述】:
我已按照 Google 的官方文档进行 GPay 集成,即使我的 Google ID 中没有添加有效的支付卡,IsReadyToPayRequest 是否显示“TRUE”。我如何检查是否没有卡添加到 Google ID。请在下面找到我的代码:
IsReadyToPayRequest request = IsReadyToPayRequest.fromJson(isReadyToPayJson.get().toString());
Task<Boolean> task = paymentsClient.isReadyToPay(request);
task.addOnCompleteListener((Activity) getContext(),
new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
showGooglePayButton(task.getResult());
} else {
Log.w("isReadyToPay failed", task.getException());
}
}
});
【问题讨论】:
-
请分享您的
getIsReadyToPayRequest()功能。来自 PaymentUtils。 -
public static Optional
getIsReadyToPayRequest() { try { JSONObject isReadyToPayRequest = getBaseRequest( ); isReadyToPayRequest.put("allowedPaymentMethods", new JSONArray().put(getBaseCardPaymentMethod())); isReadyToPayRequest.put("existingPaymentMethodRequired",true);返回 Optional.of(isReadyToPayRequest); } catch (JSONException e) { return Optional.empty( ); } }
标签: android api google-pay