Unicode 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

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jsonResponse;
    const wchar_t *object;
    const wchar_t *url;
    BOOL has_more;
    int i;
    int count_i;
    const wchar_t *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 wchar_t *brand;
    const wchar_t *country;
    const wchar_t *customer;
    BOOL cvc_check;
    BOOL dynamic_last4;
    int exp_month;
    int exp_year;
    const wchar_t *fingerprint;
    const wchar_t *funding;
    const wchar_t *last4;
    BOOL name;
    BOOL tokenization_method;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"STRIPE_SECRET_KEY",L"");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);

    object = CkJsonObjectW_stringOf(jsonResponse,L"object");
    url = CkJsonObjectW_stringOf(jsonResponse,L"url");
    has_more = CkJsonObjectW_BoolOf(jsonResponse,L"has_more");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"data");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        id = CkJsonObjectW_stringOf(jsonResponse,L"data[i].id");
        object = CkJsonObjectW_stringOf(jsonResponse,L"data[i].object");
        address_city = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_city");
        address_country = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_country");
        address_line1 = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_line1");
        address_line1_check = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_line1_check");
        address_line2 = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_line2");
        address_state = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_state");
        address_zip = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_zip");
        address_zip_check = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].address_zip_check");
        brand = CkJsonObjectW_stringOf(jsonResponse,L"data[i].brand");
        country = CkJsonObjectW_stringOf(jsonResponse,L"data[i].country");
        customer = CkJsonObjectW_stringOf(jsonResponse,L"data[i].customer");
        cvc_check = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].cvc_check");
        dynamic_last4 = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].dynamic_last4");
        exp_month = CkJsonObjectW_IntOf(jsonResponse,L"data[i].exp_month");
        exp_year = CkJsonObjectW_IntOf(jsonResponse,L"data[i].exp_year");
        fingerprint = CkJsonObjectW_stringOf(jsonResponse,L"data[i].fingerprint");
        funding = CkJsonObjectW_stringOf(jsonResponse,L"data[i].funding");
        last4 = CkJsonObjectW_stringOf(jsonResponse,L"data[i].last4");
        name = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].name");
        tokenization_method = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].tokenization_method");
        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_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
    }
  ]
}