Zeeshan Shabbir Zeeshan Shabbir - 9 months ago 96
Android Question

Stripe InvalidRequestException in java

I am trying to test Stripe payment API in my android app. The Android app sends a token (token is provided by Stripe to the Android app) to the server, and then the server uses the token charge the user via the Stripe charge API. Since I am testing the process, I am using the dummy values provided by Stripe, but when I initiate a charge call I get an

on the server side. I am having hard time testing it.
For clarity's sake, I am also adding an image.

enter image description here

Here is my code.

try {
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", jsonNode.get("amount")); // amount in cents, again
chargeParams.put("currency", "USD");
chargeParams.put("source", token);
chargeParams.put("description", "charge from server");

Charge charge = Charge.create(chargeParams);
String des = charge.getDescription();
catch (CardException e) {
// The card has been declined

How can I test this process?
Please guide me into the right direction.


In the screenshot, look at the detailed error message. It tells you what's wrong: your integration is sending the string "<com.stripe.android.model.Token@..." as the token to Stripe's API.

From your Android app, you're likely sending a string representation of the token to the server. Instead, you simply need to send the token ID. The token ID is a string that starts with tok_ followed by random alphanumeric characters. You can access it by calling getId().