Java Stripe: Retrieve a Token

Back to Index

Retrieves the token with the given ID.

Documentation: https://stripe.com/docs/api/curl#retrieve_token

CURL Command

curl https://api.stripe.com/v1/tokens/tok_1BnETKGswQrCoh0XcX6WAG5q \
   -u STRIPE_SECRET_KEY:

Java Example

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://api.stripe.com/v1/tokens/tok_1BnETKGswQrCoh0XcX6WAG5q
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(rest.lastErrorText());
        return;
        }

    rest.SetAuthBasic("STRIPE_SECRET_KEY","");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/v1/tokens/tok_1BnETKGswQrCoh0XcX6WAG5q",sbResponseBody);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.LoadSb(sbResponseBody);

    String id;
    String object;
    String cardId;
    String cardObject;
    boolean cardAddress_city;
    boolean cardAddress_country;
    boolean cardAddress_line1;
    boolean cardAddress_line1_check;
    boolean cardAddress_line2;
    boolean cardAddress_state;
    boolean cardAddress_zip;
    boolean cardAddress_zip_check;
    String cardBrand;
    String cardCountry;
    boolean cardCvc_check;
    boolean cardDynamic_last4;
    int cardExp_month;
    int cardExp_year;
    String cardFingerprint;
    String cardFunding;
    String cardLast4;
    boolean cardName;
    boolean cardTokenization_method;
    boolean client_ip;
    int created;
    boolean livemode;
    String type;
    boolean used;

    id = jsonResponse.stringOf("id");
    object = jsonResponse.stringOf("object");
    cardId = jsonResponse.stringOf("card.id");
    cardObject = jsonResponse.stringOf("card.object");
    cardAddress_city = jsonResponse.IsNullOf("card.address_city");
    cardAddress_country = jsonResponse.IsNullOf("card.address_country");
    cardAddress_line1 = jsonResponse.IsNullOf("card.address_line1");
    cardAddress_line1_check = jsonResponse.IsNullOf("card.address_line1_check");
    cardAddress_line2 = jsonResponse.IsNullOf("card.address_line2");
    cardAddress_state = jsonResponse.IsNullOf("card.address_state");
    cardAddress_zip = jsonResponse.IsNullOf("card.address_zip");
    cardAddress_zip_check = jsonResponse.IsNullOf("card.address_zip_check");
    cardBrand = jsonResponse.stringOf("card.brand");
    cardCountry = jsonResponse.stringOf("card.country");
    cardCvc_check = jsonResponse.IsNullOf("card.cvc_check");
    cardDynamic_last4 = jsonResponse.IsNullOf("card.dynamic_last4");
    cardExp_month = jsonResponse.IntOf("card.exp_month");
    cardExp_year = jsonResponse.IntOf("card.exp_year");
    cardFingerprint = jsonResponse.stringOf("card.fingerprint");
    cardFunding = jsonResponse.stringOf("card.funding");
    cardLast4 = jsonResponse.stringOf("card.last4");
    cardName = jsonResponse.IsNullOf("card.name");
    cardTokenization_method = jsonResponse.IsNullOf("card.tokenization_method");
    client_ip = jsonResponse.IsNullOf("client_ip");
    created = jsonResponse.IntOf("created");
    livemode = jsonResponse.BoolOf("livemode");
    type = jsonResponse.stringOf("type");
    used = jsonResponse.BoolOf("used");
  }
}

Sample JSON Response Body

{
  "id": "tok_1BnETKGswQrCoh0XcX6WAG5q",
  "object": "token",
  "card": {
    "id": "card_1BnETKGswQrCoh0Xa7UvZihk",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Visa",
    "country": "US",
    "cvc_check": null,
    "dynamic_last4": null,
    "exp_month": 8,
    "exp_year": 2019,
    "fingerprint": "F9mANtIt1TaukpRJ",
    "funding": "credit",
    "last4": "4242",
    "metadata": {},
    "name": null,
    "tokenization_method": null
  },
  "client_ip": null,
  "created": 1516662782,
  "livemode": false,
  "type": "card",
  "used": false
}