0

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.

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.

chewpoclypse
  • 500
  • 5
  • 20
Zeeshan Shabbir
  • 6,704
  • 4
  • 38
  • 74

1 Answers1

3

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().

Ywain
  • 16,854
  • 4
  • 51
  • 67
  • Oh thank you. I guess they should mention it clearly in their documentation. This quote is from their documentation ```Your app will receive the token back, and can then send the token to an endpoint on your server, where it can be used to process a payment, establish recurring billing, or merely saved for later use.``` – Zeeshan Shabbir Aug 09 '16 at 09:35
  • Can you please look into this SO http://stackoverflow.com/questions/38850331/what-is-connected-stripe-account-id-how-to-get-it-from-android-platform – Zeeshan Shabbir Aug 09 '16 at 12:48