如何解决当我将 existingPaymentMethodRequired 设置为 true 时,isReadyToPayRequest 返回 false
我按照此处的说明确定 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());
}
}
});
}
解决方法
根据documentation,在TEST
环境下,应该总是返回true
:
注意:在 TEST 环境中,如果您在 IsReadyToPay() 请求中将 existingPaymentMethodRequired 设置为 true,则响应始终返回 true。
您能否确认它始终为您返回 false
?也就是说,文档不正确?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。