Unicode C Stripe: List all Charges

Back to Index

Returns a list of charges you’ve previously created. The charges are returned in sorted order, with the most recent charges appearing first.

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

CURL Command

curl https://api.stripe.com/v1/charges?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;
    int amount;
    int amount_refunded;
    BOOL application;
    BOOL application_fee;
    const wchar_t *balance_transaction;
    BOOL captured;
    int created;
    const wchar_t *currency;
    BOOL customer;
    const wchar_t *description;
    BOOL destination;
    BOOL dispute;
    BOOL failure_code;
    BOOL failure_message;
    BOOL invoice;
    BOOL livemode;
    BOOL on_behalf_of;
    BOOL order;
    BOOL outcome;
    BOOL paid;
    BOOL receipt_email;
    BOOL receipt_number;
    BOOL refunded;
    const wchar_t *refundsObject;
    BOOL refundsHas_more;
    int refundsTotal_count;
    const wchar_t *refundsUrl;
    BOOL review;
    BOOL shipping;
    const wchar_t *sourceId;
    const wchar_t *sourceObject;
    BOOL sourceAddress_city;
    BOOL sourceAddress_country;
    BOOL sourceAddress_line1;
    BOOL sourceAddress_line1_check;
    BOOL sourceAddress_line2;
    BOOL sourceAddress_state;
    BOOL sourceAddress_zip;
    BOOL sourceAddress_zip_check;
    const wchar_t *sourceBrand;
    const wchar_t *sourceCountry;
    BOOL sourceCustomer;
    BOOL sourceCvc_check;
    BOOL sourceDynamic_last4;
    int sourceExp_month;
    int sourceExp_year;
    const wchar_t *sourceFingerprint;
    const wchar_t *sourceFunding;
    const wchar_t *sourceLast4;
    BOOL sourceName;
    BOOL sourceTokenization_method;
    BOOL source_transfer;
    BOOL statement_descriptor;
    const wchar_t *status;
    BOOL transfer_group;
    int j;
    int count_j;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/charges?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/charges?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");
        amount = CkJsonObjectW_IntOf(jsonResponse,L"data[i].amount");
        amount_refunded = CkJsonObjectW_IntOf(jsonResponse,L"data[i].amount_refunded");
        application = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].application");
        application_fee = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].application_fee");
        balance_transaction = CkJsonObjectW_stringOf(jsonResponse,L"data[i].balance_transaction");
        captured = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].captured");
        created = CkJsonObjectW_IntOf(jsonResponse,L"data[i].created");
        currency = CkJsonObjectW_stringOf(jsonResponse,L"data[i].currency");
        customer = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].customer");
        description = CkJsonObjectW_stringOf(jsonResponse,L"data[i].description");
        destination = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].destination");
        dispute = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].dispute");
        failure_code = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].failure_code");
        failure_message = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].failure_message");
        invoice = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].invoice");
        livemode = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].livemode");
        on_behalf_of = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].on_behalf_of");
        order = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].order");
        outcome = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].outcome");
        paid = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].paid");
        receipt_email = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].receipt_email");
        receipt_number = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].receipt_number");
        refunded = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].refunded");
        refundsObject = CkJsonObjectW_stringOf(jsonResponse,L"data[i].refunds.object");
        refundsHas_more = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].refunds.has_more");
        refundsTotal_count = CkJsonObjectW_IntOf(jsonResponse,L"data[i].refunds.total_count");
        refundsUrl = CkJsonObjectW_stringOf(jsonResponse,L"data[i].refunds.url");
        review = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].review");
        shipping = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].shipping");
        sourceId = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source.id");
        sourceObject = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source.object");
        sourceAddress_city = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_city");
        sourceAddress_country = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_country");
        sourceAddress_line1 = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_line1");
        sourceAddress_line1_check = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_line1_check");
        sourceAddress_line2 = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_line2");
        sourceAddress_state = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_state");
        sourceAddress_zip = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_zip");
        sourceAddress_zip_check = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.address_zip_check");
        sourceBrand = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source.brand");
        sourceCountry = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source.country");
        sourceCustomer = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.customer");
        sourceCvc_check = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.cvc_check");
        sourceDynamic_last4 = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.dynamic_last4");
        sourceExp_month = CkJsonObjectW_IntOf(jsonResponse,L"data[i].source.exp_month");
        sourceExp_year = CkJsonObjectW_IntOf(jsonResponse,L"data[i].source.exp_year");
        sourceFingerprint = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source.fingerprint");
        sourceFunding = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source.funding");
        sourceLast4 = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source.last4");
        sourceName = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.name");
        sourceTokenization_method = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source.tokenization_method");
        source_transfer = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].source_transfer");
        statement_descriptor = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].statement_descriptor");
        status = CkJsonObjectW_stringOf(jsonResponse,L"data[i].status");
        transfer_group = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].transfer_group");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"data[i].refunds.data");
        while (j < count_j) {
            CkJsonObjectW_putJ(jsonResponse,j);
            j = j + 1;
        }

        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/charges",
  "has_more": false,
  "data": [
    {
      "id": "ch_1BnETJGswQrCoh0XTs0EERBj",
      "object": "charge",
      "amount": 100,
      "amount_refunded": 0,
      "application": null,
      "application_fee": null,
      "balance_transaction": "txn_1BnETJGswQrCoh0XxO2tGYr7",
      "captured": false,
      "created": 1516662781,
      "currency": "usd",
      "customer": null,
      "description": "My First Test Charge (created for API docs)",
      "destination": null,
      "dispute": null,
      "failure_code": null,
      "failure_message": null,
      "fraud_details": {},
      "invoice": null,
      "livemode": false,
      "metadata": {},
      "on_behalf_of": null,
      "order": null,
      "outcome": null,
      "paid": true,
      "receipt_email": null,
      "receipt_number": null,
      "refunded": false,
      "refunds": {
        "object": "list",
        "data": [
        ],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/refunds"
      },
      "review": null,
      "shipping": null,
      "source": {
        "id": "card_18ropuGswQrCoh0XjCJ5Zvma",
        "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": null,
        "cvc_check": null,
        "dynamic_last4": null,
        "exp_month": 8,
        "exp_year": 2017,
        "fingerprint": "F9mANtIt1TaukpRJ",
        "funding": "credit",
        "last4": "4242",
        "metadata": {},
        "name": null,
        "tokenization_method": null
      },
      "source_transfer": null,
      "statement_descriptor": null,
      "status": "succeeded",
      "transfer_group": null
    }
  ]
}