DataFlex Stripe: List all Cards

Back to Index

List the cards belonging to a customer or recipient.

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

CURL Command

curl "https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3" \
   -u STRIPE_SECRET_KEY: \
   -G

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 sObject
    String sUrl
    Boolean iHas_more
    Integer i
    Integer iCount_i
    String sId
    Boolean iAddress_city
    Boolean iAddress_country
    Boolean iAddress_line1
    Boolean iAddress_line1_check
    Boolean iAddress_line2
    Boolean iAddress_state
    Boolean iAddress_zip
    Boolean iAddress_zip_check
    String sBrand
    String sCountry
    String sCustomer
    Boolean iCvc_check
    Boolean iDynamic_last4
    Integer iExp_month
    Integer iExp_year
    String sFingerprint
    String sFunding
    String sLast4
    Boolean iName
    Boolean iTokenization_method
    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_CBbg3iRMzWBjoe/sources?object=card&limit=3
    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_CBbg3iRMzWBjoe/sources?object=card&limit=3" 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 "object" To sObject
    Get ComStringOf Of hoJsonResponse "url" To sUrl
    Get ComBoolOf Of hoJsonResponse "has_more" To iHas_more
    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Get ComStringOf Of hoJsonResponse "data[i].id" To sId
        Get ComStringOf Of hoJsonResponse "data[i].object" To sObject
        Get ComIsNullOf Of hoJsonResponse "data[i].address_city" To iAddress_city
        Get ComIsNullOf Of hoJsonResponse "data[i].address_country" To iAddress_country
        Get ComIsNullOf Of hoJsonResponse "data[i].address_line1" To iAddress_line1
        Get ComIsNullOf Of hoJsonResponse "data[i].address_line1_check" To iAddress_line1_check
        Get ComIsNullOf Of hoJsonResponse "data[i].address_line2" To iAddress_line2
        Get ComIsNullOf Of hoJsonResponse "data[i].address_state" To iAddress_state
        Get ComIsNullOf Of hoJsonResponse "data[i].address_zip" To iAddress_zip
        Get ComIsNullOf Of hoJsonResponse "data[i].address_zip_check" To iAddress_zip_check
        Get ComStringOf Of hoJsonResponse "data[i].brand" To sBrand
        Get ComStringOf Of hoJsonResponse "data[i].country" To sCountry
        Get ComStringOf Of hoJsonResponse "data[i].customer" To sCustomer
        Get ComIsNullOf Of hoJsonResponse "data[i].cvc_check" To iCvc_check
        Get ComIsNullOf Of hoJsonResponse "data[i].dynamic_last4" To iDynamic_last4
        Get ComIntOf Of hoJsonResponse "data[i].exp_month" To iExp_month
        Get ComIntOf Of hoJsonResponse "data[i].exp_year" To iExp_year
        Get ComStringOf Of hoJsonResponse "data[i].fingerprint" To sFingerprint
        Get ComStringOf Of hoJsonResponse "data[i].funding" To sFunding
        Get ComStringOf Of hoJsonResponse "data[i].last4" To sLast4
        Get ComIsNullOf Of hoJsonResponse "data[i].name" To iName
        Get ComIsNullOf Of hoJsonResponse "data[i].tokenization_method" To iTokenization_method
        Move i + 1 To i
    Loop



End_Procedure

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/customers/cus_CBbg3iRMzWBjoe/sources",
  "has_more": false,
  "data": [
    {
      "id": "card_1BnETKGswQrCoh0Xhu1A6BfL",
      "object": "card",
      "address_city": null,
      "address_country": null,
      "address_line1": null,
      "address_line1_check": null,
      "address_line2": null,
      "address_state": null,
      "address_zip": null,
      "address_zip_check": null,
      "brand": "Visa",
      "country": "US",
      "customer": "cus_CBbg3iRMzWBjoe",
      "cvc_check": null,
      "dynamic_last4": null,
      "exp_month": 8,
      "exp_year": 2019,
      "fingerprint": "F9mANtIt1TaukpRJ",
      "funding": "credit",
      "last4": "4242",
      "metadata": {},
      "name": null,
      "tokenization_method": null
    }
  ]
}