Java Stripe: Create a PII Token

Back to Index

Creates a single use token that wraps the details of personally identifiable information (PII). This token can be used in place of a personal_id_number in the Account Update API method. These tokens can only be used once.

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

CURL Command

curl https://api.stripe.com/v1/tokens \
   -u STRIPE_SECRET_KEY: \
   -d pii[personal_id_number]=000000000 \
   -X POST

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
    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","");

    rest.AddQueryParam("pii[personal_id_number]","000000000");

    String strResponseBody = rest.fullRequestFormUrlEncoded("POST","/v1/tokens");
    if (rest.get_LastMethodSuccess() != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.Load(strResponseBody);

    String id;
    String object;
    boolean client_ip;
    int created;
    boolean livemode;
    String type;
    boolean used;

    id = jsonResponse.stringOf("id");
    object = jsonResponse.stringOf("object");
    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": "pii_1BnETKGswQrCoh0XMUBp4DiD",
  "object": "token",
  "client_ip": null,
  "created": 1516662782,
  "livemode": false,
  "type": "pii",
  "used": false
}