Get card token from Stripe on android

Viewed 1933

I'm using the set of instructions from https://stripe.com/docs/mobile/android/standard in my Android/Kotlin app, and on the final onPaymentSessionDataChanged() callback, I get a PaymentMethod with an id that starts with pm_. But what I want is a card token id that starts with card_, which is what my server requires to continue payment.

Is there a way to translate this to get the card token, or should I be using a different methodology?

If it helps, I can put some code here.

Thanks.

1 Answers

Here you go:

Token token = null;

final Card card = new Card(cardNumber, month, year, cvc);

final Stripe stripe = new Stripe(getApplicationContext());
try {

    token = stripe.createTokenSynchronous(card, "YOUR-API-KEY");

} catch (StripeException stripeEx) {

    errorMessage = stripeEx.getLocalizedMessage();
}
Related