Reputation: 3
I have integrated Google Pay payment option using Stripe Android SDK, but during payment I am getting an ERROR ALERT
Request Failed Unexpected Developer error, please try again later
And in log I am getting
Status: DEVELOPER_ERROR, resolution = null}
PaymentConfiguration.init(this, getResources().getString(R.string.stripe_key));
mPaymentsClient = Wallet.getPaymentsClient(this, new Wallet.WalletOptions.Builder().setEnvironment(getEnvironment()).build());
stripe = new Stripe(this, getResources().getString(R.string.stripe_key));
AutoResolveHelper.resolveTask(mPaymentsClient.loadPaymentData(createPaymentDataRequest()), this, LOAD_PAYMENT_DATA_REQUEST_CODE);
@NonNull
private IsReadyToPayRequest createIsReadyToPayRequest() throws JSONException {
final JSONArray allowedAuthMethods = new JSONArray();
allowedAuthMethods.put("PAN_ONLY");
allowedAuthMethods.put("CRYPTOGRAM_3DS");
final JSONArray allowedCardNetworks = new JSONArray();
allowedCardNetworks.put("AMEX");
allowedCardNetworks.put("DISCOVER");
allowedCardNetworks.put("MASTERCARD");
allowedCardNetworks.put("VISA");
final JSONObject cardParameters = new JSONObject();
cardParameters.put("allowedAuthMethods", allowedAuthMethods);
cardParameters.put("allowedCardNetworks", allowedCardNetworks);
final JSONObject cardPaymentMethod = new JSONObject();
cardPaymentMethod.put("type", "CARD");
cardPaymentMethod.put("parameters", cardParameters);
final JSONArray allowedPaymentMethods = new JSONArray();
allowedPaymentMethods.put(cardPaymentMethod);
final JSONObject isReadyToPayRequestJson = new JSONObject();
isReadyToPayRequestJson.put("apiVersion", 2);
isReadyToPayRequestJson.put("apiVersionMinor", 0);
isReadyToPayRequestJson.put("allowedPaymentMethods", allowedPaymentMethods);
return IsReadyToPayRequest.fromJson(isReadyToPayRequestJson.toString());
}
@NonNull
private PaymentDataRequest createPaymentDataRequest() {
JSONObject tokenizationSpec = null;
JSONObject cardPaymentMethod = null;
JSONObject paymentDataRequest = null;
try {
tokenizationSpec = new GooglePayConfig(this).getTokenizationSpecification();
cardPaymentMethod = new JSONObject()
.put("type", "CARD")
.put("parameters", new JSONObject()
.put("allowedAuthMethods", new JSONArray()
.put("PAN_ONLY")
.put("CRYPTOGRAM_3DS"))
.put("allowedCardNetworks",
new JSONArray()
.put("AMEX")
.put("DISCOVER")
.put("JCB")
.put("MASTERCARD")
.put("VISA"))
// require billing address
.put("billingAddressRequired", true)
.put("billingAddressParameters", new JSONObject()
// require full billing address
.put("format", "FULL")
// require phone number
.put("phoneNumberRequired", true)
)
)
.put("tokenizationSpecification", tokenizationSpec);
// create PaymentDataRequest
paymentDataRequest = new JSONObject()
.put("apiVersion", 2)
.put("apiVersionMinor", 0)
.put("allowedPaymentMethods",
new JSONArray().put(cardPaymentMethod))
.put("transactionInfo", new JSONObject()
.put("totalPrice", mPricingDetailsModel.getTotal_cost())
.put("totalPriceStatus", "FINAL")
.put("currencyCode", "USD"))
.put("merchantInfo", new JSONObject()
.put("merchantName", "SPARKOUT"))
// require email address
.put("emailRequired", true);
} catch(Exception e) {
Logger.Companion.log(e.getMessage());
}
return PaymentDataRequest.fromJson(String.valueOf(paymentDataRequest));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case LOAD_PAYMENT_DATA_REQUEST_CODE: {
switch(resultCode) {
case Activity.RESULT_OK: {
if (data != null) {
try {
onGooglePayResult(data);
} catch(Exception e) {
Logger.Companion.log(e.getMessage());
}
}
break;
}
case Activity.RESULT_CANCELED: {
// Canceled
break;
}
case AutoResolveHelper.RESULT_ERROR: {
// Log the status for debugging
// Generally there is no need to show an error to
// the user as the Google Payment API will do that
Status status = AutoResolveHelper.getStatusFromIntent(data);
Logger.Companion.log(String.valueOf(status.getStatus()));
Logger.Companion.log(status.zza());
Logger.Companion.log(String.valueOf(status.getStatusCode()));
break;
}
default: {
// Do nothing.
}
}
break;
}
default: {
// Handle any other startActivityForResult calls you may have made.
}
}
}
Upvotes: 0
Views: 1042
Reputation: 76799
It is outright absurd, to declare something as final
and then instantly try to change it again.
The most likely would be: remove all the final
keywords and it might actually send a request.
Upvotes: 0