Unicode C 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

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const wchar_t *strResponseBody;
    HCkJsonObjectW jsonResponse;
    const wchar_t *id;
    const wchar_t *object;
    BOOL client_ip;
    int created;
    BOOL livemode;
    const wchar_t *type;
    BOOL used;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/tokens
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"STRIPE_SECRET_KEY",L"");

    CkRestW_AddQueryParam(rest,L"pii[personal_id_number]",L"000000000");

    strResponseBody = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/v1/tokens");
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_Load(jsonResponse,strResponseBody);

    id = CkJsonObjectW_stringOf(jsonResponse,L"id");
    object = CkJsonObjectW_stringOf(jsonResponse,L"object");
    client_ip = CkJsonObjectW_IsNullOf(jsonResponse,L"client_ip");
    created = CkJsonObjectW_IntOf(jsonResponse,L"created");
    livemode = CkJsonObjectW_BoolOf(jsonResponse,L"livemode");
    type = CkJsonObjectW_stringOf(jsonResponse,L"type");
    used = CkJsonObjectW_BoolOf(jsonResponse,L"used");


    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "id": "pii_1BnETKGswQrCoh0XMUBp4DiD",
  "object": "token",
  "client_ip": null,
  "created": 1516662782,
  "livemode": false,
  "type": "pii",
  "used": false
}