PureBasic 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

PureBasic Example

IncludeFile "CkRest.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://api.stripe.com/v1/tokens
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"api.stripe.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"STRIPE_SECRET_KEY","")

    CkRest::ckAddQueryParam(rest,"pii[personal_id_number]","000000000")

    strResponseBody.s = CkRest::ckFullRequestFormUrlEncoded(rest,"POST","/v1/tokens")
    If CkRest::ckLastMethodSuccess(rest) <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(jsonResponse,strResponseBody)

    id.s
    object.s
    client_ip.i
    created.i
    livemode.i
    type.s
    used.i

    id = CkJsonObject::ckStringOf(jsonResponse,"id")
    object = CkJsonObject::ckStringOf(jsonResponse,"object")
    client_ip = CkJsonObject::ckIsNullOf(jsonResponse,"client_ip")
    created = CkJsonObject::ckIntOf(jsonResponse,"created")
    livemode = CkJsonObject::ckBoolOf(jsonResponse,"livemode")
    type = CkJsonObject::ckStringOf(jsonResponse,"type")
    used = CkJsonObject::ckBoolOf(jsonResponse,"used")


    CkRest::ckDispose(rest)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

Sample JSON Response Body

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