PureBasic Stripe: Retrieve a Customer

Back to Index

Retrieves the details of an existing customer. You need only supply the unique customer identifier that was returned upon customer creation.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq \
   -u STRIPE_SECRET_KEY:

PureBasic Example

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.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/customers/cus_CBbgVLJqv487Oq
    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","")

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

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/v1/customers/cus_CBbgVLJqv487Oq",sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

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

    CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody)

    id.s
    object.s
    account_balance.i
    created.i
    currency.s
    default_source.i
    delinquent.i
    description.i
    discount.i
    email.i
    livemode.i
    shipping.i
    sourcesObject.s
    sourcesHas_more.i
    sourcesTotal_count.i
    sourcesUrl.s
    subscriptionsObject.s
    subscriptionsHas_more.i
    subscriptionsTotal_count.i
    subscriptionsUrl.s
    i.i
    count_i.i

    id = CkJsonObject::ckStringOf(jsonResponse,"id")
    object = CkJsonObject::ckStringOf(jsonResponse,"object")
    account_balance = CkJsonObject::ckIntOf(jsonResponse,"account_balance")
    created = CkJsonObject::ckIntOf(jsonResponse,"created")
    currency = CkJsonObject::ckStringOf(jsonResponse,"currency")
    default_source = CkJsonObject::ckIsNullOf(jsonResponse,"default_source")
    delinquent = CkJsonObject::ckBoolOf(jsonResponse,"delinquent")
    description = CkJsonObject::ckIsNullOf(jsonResponse,"description")
    discount = CkJsonObject::ckIsNullOf(jsonResponse,"discount")
    email = CkJsonObject::ckIsNullOf(jsonResponse,"email")
    livemode = CkJsonObject::ckBoolOf(jsonResponse,"livemode")
    shipping = CkJsonObject::ckIsNullOf(jsonResponse,"shipping")
    sourcesObject = CkJsonObject::ckStringOf(jsonResponse,"sources.object")
    sourcesHas_more = CkJsonObject::ckBoolOf(jsonResponse,"sources.has_more")
    sourcesTotal_count = CkJsonObject::ckIntOf(jsonResponse,"sources.total_count")
    sourcesUrl = CkJsonObject::ckStringOf(jsonResponse,"sources.url")
    subscriptionsObject = CkJsonObject::ckStringOf(jsonResponse,"subscriptions.object")
    subscriptionsHas_more = CkJsonObject::ckBoolOf(jsonResponse,"subscriptions.has_more")
    subscriptionsTotal_count = CkJsonObject::ckIntOf(jsonResponse,"subscriptions.total_count")
    subscriptionsUrl = CkJsonObject::ckStringOf(jsonResponse,"subscriptions.url")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"sources.data")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"subscriptions.data")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        i = i + 1
    Wend


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


    ProcedureReturn
EndProcedure

Sample JSON Response Body

{
  "id": "cus_CBbgVLJqv487Oq",
  "object": "customer",
  "account_balance": 0,
  "created": 1516662781,
  "currency": "usd",
  "default_source": null,
  "delinquent": false,
  "description": null,
  "discount": null,
  "email": null,
  "livemode": false,
  "metadata": {},
  "shipping": null,
  "sources": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/sources"
  },
  "subscriptions": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/subscriptions"
  }
}