Reputation: 7114
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 InvalidRequestException
on the server side. I am having hard time testing it.
For clarity's sake, I am also adding an image.
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.
Upvotes: 0
Views: 1425
Reputation: 17533
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()
.
Upvotes: 3