C 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

C Example

#include <C_CkRest.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jsonResponse;
    const char *object;
    const char *url;
    BOOL has_more;
    int i;
    int count_i;
    const char *id;
    BOOL address_city;
    BOOL address_country;
    BOOL address_line1;
    BOOL address_line1_check;
    BOOL address_line2;
    BOOL address_state;
    BOOL address_zip;
    BOOL address_zip_check;
    const char *brand;
    const char *country;
    const char *customer;
    BOOL cvc_check;
    BOOL dynamic_last4;
    int exp_month;
    int exp_year;
    const char *fingerprint;
    const char *funding;
    const char *last4;
    BOOL name;
    BOOL tokenization_method;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");

    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3",sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

    object = CkJsonObject_stringOf(jsonResponse,"object");
    url = CkJsonObject_stringOf(jsonResponse,"url");
    has_more = CkJsonObject_BoolOf(jsonResponse,"has_more");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"data");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        id = CkJsonObject_stringOf(jsonResponse,"data[i].id");
        object = CkJsonObject_stringOf(jsonResponse,"data[i].object");
        address_city = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_city");
        address_country = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_country");
        address_line1 = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_line1");
        address_line1_check = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_line1_check");
        address_line2 = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_line2");
        address_state = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_state");
        address_zip = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_zip");
        address_zip_check = CkJsonObject_IsNullOf(jsonResponse,"data[i].address_zip_check");
        brand = CkJsonObject_stringOf(jsonResponse,"data[i].brand");
        country = CkJsonObject_stringOf(jsonResponse,"data[i].country");
        customer = CkJsonObject_stringOf(jsonResponse,"data[i].customer");
        cvc_check = CkJsonObject_IsNullOf(jsonResponse,"data[i].cvc_check");
        dynamic_last4 = CkJsonObject_IsNullOf(jsonResponse,"data[i].dynamic_last4");
        exp_month = CkJsonObject_IntOf(jsonResponse,"data[i].exp_month");
        exp_year = CkJsonObject_IntOf(jsonResponse,"data[i].exp_year");
        fingerprint = CkJsonObject_stringOf(jsonResponse,"data[i].fingerprint");
        funding = CkJsonObject_stringOf(jsonResponse,"data[i].funding");
        last4 = CkJsonObject_stringOf(jsonResponse,"data[i].last4");
        name = CkJsonObject_IsNullOf(jsonResponse,"data[i].name");
        tokenization_method = CkJsonObject_IsNullOf(jsonResponse,"data[i].tokenization_method");
        i = i + 1;
    }



    CkRest_Dispose(rest);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

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