Visual FoxPro Stripe: List all Customers

Back to Index

Returns a list of your customers. The customers are returned sorted by creation date, with the most recent customers appearing first.

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

CURL Command

curl https://api.stripe.com/v1/customers?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcObject
LOCAL lcUrl
LOCAL lnHas_more
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lnAccount_balance
LOCAL lnCreated
LOCAL lcCurrency
LOCAL lnDefault_source
LOCAL lnDelinquent
LOCAL lnDescription
LOCAL lnDiscount
LOCAL lnEmail
LOCAL lnLivemode
LOCAL lnShipping
LOCAL lcSourcesObject
LOCAL lnSourcesHas_more
LOCAL lnSourcesTotal_count
LOCAL lcSourcesUrl
LOCAL lcSubscriptionsObject
LOCAL lnSubscriptionsHas_more
LOCAL lnSubscriptionsTotal_count
LOCAL lcSubscriptionsUrl
LOCAL j
LOCAL lnCount_j

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/customers?limit=3
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.stripe.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("STRIPE_SECRET_KEY","")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/v1/customers?limit=3",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcObject = loJsonResponse.StringOf("object")
lcUrl = loJsonResponse.StringOf("url")
lnHas_more = loJsonResponse.BoolOf("has_more")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcId = loJsonResponse.StringOf("data[i].id")
    lcObject = loJsonResponse.StringOf("data[i].object")
    lnAccount_balance = loJsonResponse.IntOf("data[i].account_balance")
    lnCreated = loJsonResponse.IntOf("data[i].created")
    lcCurrency = loJsonResponse.StringOf("data[i].currency")
    lnDefault_source = loJsonResponse.IsNullOf("data[i].default_source")
    lnDelinquent = loJsonResponse.BoolOf("data[i].delinquent")
    lnDescription = loJsonResponse.IsNullOf("data[i].description")
    lnDiscount = loJsonResponse.IsNullOf("data[i].discount")
    lnEmail = loJsonResponse.IsNullOf("data[i].email")
    lnLivemode = loJsonResponse.BoolOf("data[i].livemode")
    lnShipping = loJsonResponse.IsNullOf("data[i].shipping")
    lcSourcesObject = loJsonResponse.StringOf("data[i].sources.object")
    lnSourcesHas_more = loJsonResponse.BoolOf("data[i].sources.has_more")
    lnSourcesTotal_count = loJsonResponse.IntOf("data[i].sources.total_count")
    lcSourcesUrl = loJsonResponse.StringOf("data[i].sources.url")
    lcSubscriptionsObject = loJsonResponse.StringOf("data[i].subscriptions.object")
    lnSubscriptionsHas_more = loJsonResponse.BoolOf("data[i].subscriptions.has_more")
    lnSubscriptionsTotal_count = loJsonResponse.IntOf("data[i].subscriptions.total_count")
    lcSubscriptionsUrl = loJsonResponse.StringOf("data[i].subscriptions.url")
    j = 0
    lnCount_j = loJsonResponse.SizeOfArray("data[i].sources.data")
    DO WHILE j < lnCount_j
        loJsonResponse.J = j
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJsonResponse.SizeOfArray("data[i].subscriptions.data")
    DO WHILE j < lnCount_j
        loJsonResponse.J = j
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/customers",
  "has_more": false,
  "data": [
    {
      "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"
      }
    }
  ]
}