Delphi ActiveX 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

Delphi ActiveX Example

var
rest: TChilkatRest;
success: Integer;
bTls: Integer;
port: Integer;
bAutoReconnect: Integer;
strResponseBody: WideString;
jsonResponse: TChilkatJsonObject;
id: WideString;
object: WideString;
client_ip: Integer;
created: Integer;
livemode: Integer;
type: WideString;
used: Integer;

begin
rest := TChilkatRest.Create(Self);

//  URL: https://api.stripe.com/v1/tokens
bTls := 1;
port := 443;
bAutoReconnect := 1;
success := rest.Connect('api.stripe.com',port,bTls,bAutoReconnect);
if (success <> 1) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(rest.ConnectFailReason));
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

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

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

strResponseBody := rest.FullRequestFormUrlEncoded('POST','/v1/tokens');
if (rest.LastMethodSuccess <> 1) then
  begin
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

jsonResponse := TChilkatJsonObject.Create(Self);
jsonResponse.Load(strResponseBody);

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
}