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 <CkRestW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect(L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    rest.SetAuthBasic(L"STRIPE_SECRET_KEY",L"");

    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestNoBodySb(L"GET",L"/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    const wchar_t *object = 0;
    const wchar_t *url = 0;
    bool has_more;
    int i;
    int count_i;
    const wchar_t *id = 0;
    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 = 0;
    const wchar_t *country = 0;
    const wchar_t *customer = 0;
    bool cvc_check;
    bool dynamic_last4;
    int exp_month;
    int exp_year;
    const wchar_t *fingerprint = 0;
    const wchar_t *funding = 0;
    const wchar_t *last4 = 0;
    bool name;
    bool tokenization_method;

    object = jsonResponse.stringOf(L"object");
    url = jsonResponse.stringOf(L"url");
    has_more = jsonResponse.BoolOf(L"has_more");
    i = 0;
    count_i = jsonResponse.SizeOfArray(L"data");
    while (i < count_i) {
        jsonResponse.put_I(i);
        id = jsonResponse.stringOf(L"data[i].id");
        object = jsonResponse.stringOf(L"data[i].object");
        address_city = jsonResponse.IsNullOf(L"data[i].address_city");
        address_country = jsonResponse.IsNullOf(L"data[i].address_country");
        address_line1 = jsonResponse.IsNullOf(L"data[i].address_line1");
        address_line1_check = jsonResponse.IsNullOf(L"data[i].address_line1_check");
        address_line2 = jsonResponse.IsNullOf(L"data[i].address_line2");
        address_state = jsonResponse.IsNullOf(L"data[i].address_state");
        address_zip = jsonResponse.IsNullOf(L"data[i].address_zip");
        address_zip_check = jsonResponse.IsNullOf(L"data[i].address_zip_check");
        brand = jsonResponse.stringOf(L"data[i].brand");
        country = jsonResponse.stringOf(L"data[i].country");
        customer = jsonResponse.stringOf(L"data[i].customer");
        cvc_check = jsonResponse.IsNullOf(L"data[i].cvc_check");
        dynamic_last4 = jsonResponse.IsNullOf(L"data[i].dynamic_last4");
        exp_month = jsonResponse.IntOf(L"data[i].exp_month");
        exp_year = jsonResponse.IntOf(L"data[i].exp_year");
        fingerprint = jsonResponse.stringOf(L"data[i].fingerprint");
        funding = jsonResponse.stringOf(L"data[i].funding");
        last4 = jsonResponse.stringOf(L"data[i].last4");
        name = jsonResponse.IsNullOf(L"data[i].name");
        tokenization_method = jsonResponse.IsNullOf(L"data[i].tokenization_method");
        i = i + 1;
    }
    }

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