Swift 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

Swift Example


func chilkatTest() {
    let rest = CkoRest()
    var success: Bool

    //  URL: https://api.stripe.com/v1/tokens
    var bTls: Bool = true
    var port: Int = 443
    var bAutoReconnect: Bool = true
    success = rest.Connect("api.stripe.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
    if success != true {
        print("ConnectFailReason: \(rest.ConnectFailReason.integerValue)")
        print("\(rest.LastErrorText)")
        return
    }

    rest.SetAuthBasic("STRIPE_SECRET_KEY", password: "")

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

    var strResponseBody: String? = rest.FullRequestFormUrlEncoded("POST", uriPath: "/v1/tokens")
    if rest.LastMethodSuccess != true {
        print("\(rest.LastErrorText)")
        return
    }

    let jsonResponse = CkoJsonObject()
    jsonResponse.Load(strResponseBody)

    var id: String?
    var object: String?
    var client_ip: Bool
    var created: Int
    var livemode: Bool
    var type: String?
    var used: Bool

    id = jsonResponse.StringOf("id")
    object = jsonResponse.StringOf("object")
    client_ip = jsonResponse.IsNullOf("client_ip")
    created = jsonResponse.IntOf("created").integerValue
    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
}