DataFlex 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:

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJsonResponse
    String sId
    String sObject
    Integer iAccount_balance
    Integer iCreated
    String sCurrency
    Boolean iDefault_source
    Boolean iDelinquent
    Boolean iDescription
    Boolean iDiscount
    Boolean iEmail
    Boolean iLivemode
    Boolean iShipping
    String sSourcesObject
    Boolean iSourcesHas_more
    Integer iSourcesTotal_count
    String sSourcesUrl
    String sSubscriptionsObject
    Boolean iSubscriptionsHas_more
    Integer iSubscriptionsTotal_count
    String sSubscriptionsUrl
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //  URL: https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.stripe.com" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSetAuthBasic Of hoRest "STRIPE_SECRET_KEY" "" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestNoBodySb Of hoRest "GET" "/v1/customers/cus_CBbgVLJqv487Oq" vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess

    Get ComStringOf Of hoJsonResponse "id" To sId
    Get ComStringOf Of hoJsonResponse "object" To sObject
    Get ComIntOf Of hoJsonResponse "account_balance" To iAccount_balance
    Get ComIntOf Of hoJsonResponse "created" To iCreated
    Get ComStringOf Of hoJsonResponse "currency" To sCurrency
    Get ComIsNullOf Of hoJsonResponse "default_source" To iDefault_source
    Get ComBoolOf Of hoJsonResponse "delinquent" To iDelinquent
    Get ComIsNullOf Of hoJsonResponse "description" To iDescription
    Get ComIsNullOf Of hoJsonResponse "discount" To iDiscount
    Get ComIsNullOf Of hoJsonResponse "email" To iEmail
    Get ComBoolOf Of hoJsonResponse "livemode" To iLivemode
    Get ComIsNullOf Of hoJsonResponse "shipping" To iShipping
    Get ComStringOf Of hoJsonResponse "sources.object" To sSourcesObject
    Get ComBoolOf Of hoJsonResponse "sources.has_more" To iSourcesHas_more
    Get ComIntOf Of hoJsonResponse "sources.total_count" To iSourcesTotal_count
    Get ComStringOf Of hoJsonResponse "sources.url" To sSourcesUrl
    Get ComStringOf Of hoJsonResponse "subscriptions.object" To sSubscriptionsObject
    Get ComBoolOf Of hoJsonResponse "subscriptions.has_more" To iSubscriptionsHas_more
    Get ComIntOf Of hoJsonResponse "subscriptions.total_count" To iSubscriptionsTotal_count
    Get ComStringOf Of hoJsonResponse "subscriptions.url" To sSubscriptionsUrl
    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "sources.data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Move i + 1 To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "subscriptions.data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Move i + 1 To i
    Loop



End_Procedure

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"
  }
}