C Stripe: List all Invoices

Back to Index

Attempts payment on an invoice out of the normal collection schedule.

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

CURL Command

curl https://api.stripe.com/v1/invoices?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;
    int amount_due;
    BOOL application_fee;
    int attempt_count;
    BOOL attempted;
    const char *billing;
    BOOL charge;
    BOOL closed;
    const char *currency;
    const char *customer;
    int date;
    BOOL description;
    BOOL discount;
    BOOL due_date;
    BOOL ending_balance;
    BOOL forgiven;
    BOOL linesHas_more;
    const char *linesObject;
    const char *linesUrl;
    BOOL livemode;
    int next_payment_attempt;
    const char *number;
    BOOL paid;
    int period_end;
    int period_start;
    BOOL receipt_number;
    int starting_balance;
    BOOL statement_descriptor;
    BOOL subscription;
    int subtotal;
    BOOL tax;
    BOOL tax_percent;
    int total;
    BOOL webhooks_delivered_at;
    int j;
    int count_j;
    int amount;
    const char *description_str;
    BOOL discountable;
    int periodStart;
    int periodEnd;
    const char *planId;
    const char *planObject;
    int planAmount;
    int planCreated;
    const char *planCurrency;
    const char *planInterval;
    int planInterval_count;
    BOOL planLivemode;
    const char *planName;
    BOOL planStatement_descriptor;
    BOOL planTrial_period_days;
    BOOL proration;
    int quantity;
    const char *subscription_item;
    const char *type;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/invoices?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/invoices?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");
        amount_due = CkJsonObject_IntOf(jsonResponse,"data[i].amount_due");
        application_fee = CkJsonObject_IsNullOf(jsonResponse,"data[i].application_fee");
        attempt_count = CkJsonObject_IntOf(jsonResponse,"data[i].attempt_count");
        attempted = CkJsonObject_BoolOf(jsonResponse,"data[i].attempted");
        billing = CkJsonObject_stringOf(jsonResponse,"data[i].billing");
        charge = CkJsonObject_IsNullOf(jsonResponse,"data[i].charge");
        closed = CkJsonObject_BoolOf(jsonResponse,"data[i].closed");
        currency = CkJsonObject_stringOf(jsonResponse,"data[i].currency");
        customer = CkJsonObject_stringOf(jsonResponse,"data[i].customer");
        date = CkJsonObject_IntOf(jsonResponse,"data[i].date");
        description = CkJsonObject_IsNullOf(jsonResponse,"data[i].description");
        discount = CkJsonObject_IsNullOf(jsonResponse,"data[i].discount");
        due_date = CkJsonObject_IsNullOf(jsonResponse,"data[i].due_date");
        ending_balance = CkJsonObject_IsNullOf(jsonResponse,"data[i].ending_balance");
        forgiven = CkJsonObject_BoolOf(jsonResponse,"data[i].forgiven");
        linesHas_more = CkJsonObject_BoolOf(jsonResponse,"data[i].lines.has_more");
        linesObject = CkJsonObject_stringOf(jsonResponse,"data[i].lines.object");
        linesUrl = CkJsonObject_stringOf(jsonResponse,"data[i].lines.url");
        livemode = CkJsonObject_BoolOf(jsonResponse,"data[i].livemode");
        next_payment_attempt = CkJsonObject_IntOf(jsonResponse,"data[i].next_payment_attempt");
        number = CkJsonObject_stringOf(jsonResponse,"data[i].number");
        paid = CkJsonObject_BoolOf(jsonResponse,"data[i].paid");
        period_end = CkJsonObject_IntOf(jsonResponse,"data[i].period_end");
        period_start = CkJsonObject_IntOf(jsonResponse,"data[i].period_start");
        receipt_number = CkJsonObject_IsNullOf(jsonResponse,"data[i].receipt_number");
        starting_balance = CkJsonObject_IntOf(jsonResponse,"data[i].starting_balance");
        statement_descriptor = CkJsonObject_IsNullOf(jsonResponse,"data[i].statement_descriptor");
        subscription = CkJsonObject_IsNullOf(jsonResponse,"data[i].subscription");
        subtotal = CkJsonObject_IntOf(jsonResponse,"data[i].subtotal");
        tax = CkJsonObject_IsNullOf(jsonResponse,"data[i].tax");
        tax_percent = CkJsonObject_IsNullOf(jsonResponse,"data[i].tax_percent");
        total = CkJsonObject_IntOf(jsonResponse,"data[i].total");
        webhooks_delivered_at = CkJsonObject_IsNullOf(jsonResponse,"data[i].webhooks_delivered_at");
        j = 0;
        count_j = CkJsonObject_SizeOfArray(jsonResponse,"data[i].lines.data");
        while (j < count_j) {
            CkJsonObject_putJ(jsonResponse,j);
            id = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].id");
            object = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].object");
            amount = CkJsonObject_IntOf(jsonResponse,"data[i].lines.data[j].amount");
            currency = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].currency");
            description_str = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].description");
            discountable = CkJsonObject_BoolOf(jsonResponse,"data[i].lines.data[j].discountable");
            livemode = CkJsonObject_BoolOf(jsonResponse,"data[i].lines.data[j].livemode");
            periodStart = CkJsonObject_IntOf(jsonResponse,"data[i].lines.data[j].period.start");
            periodEnd = CkJsonObject_IntOf(jsonResponse,"data[i].lines.data[j].period.end");
            planId = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].plan.id");
            planObject = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].plan.object");
            planAmount = CkJsonObject_IntOf(jsonResponse,"data[i].lines.data[j].plan.amount");
            planCreated = CkJsonObject_IntOf(jsonResponse,"data[i].lines.data[j].plan.created");
            planCurrency = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].plan.currency");
            planInterval = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].plan.interval");
            planInterval_count = CkJsonObject_IntOf(jsonResponse,"data[i].lines.data[j].plan.interval_count");
            planLivemode = CkJsonObject_BoolOf(jsonResponse,"data[i].lines.data[j].plan.livemode");
            planName = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].plan.name");
            planStatement_descriptor = CkJsonObject_IsNullOf(jsonResponse,"data[i].lines.data[j].plan.statement_descriptor");
            planTrial_period_days = CkJsonObject_IsNullOf(jsonResponse,"data[i].lines.data[j].plan.trial_period_days");
            proration = CkJsonObject_BoolOf(jsonResponse,"data[i].lines.data[j].proration");
            quantity = CkJsonObject_IntOf(jsonResponse,"data[i].lines.data[j].quantity");
            subscription = CkJsonObject_IsNullOf(jsonResponse,"data[i].lines.data[j].subscription");
            subscription_item = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].subscription_item");
            type = CkJsonObject_stringOf(jsonResponse,"data[i].lines.data[j].type");
            j = j + 1;
        }

        i = i + 1;
    }



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

    }

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/invoices",
  "has_more": false,
  "data": [
    {
      "id": "in_1BnETLGswQrCoh0X6M67Qy9c",
      "object": "invoice",
      "amount_due": 0,
      "application_fee": null,
      "attempt_count": 0,
      "attempted": false,
      "billing": "charge_automatically",
      "charge": null,
      "closed": false,
      "currency": "usd",
      "customer": "cus_CBbggkUyLoz3pe",
      "date": 1516662783,
      "description": null,
      "discount": null,
      "due_date": null,
      "ending_balance": null,
      "forgiven": false,
      "lines": {
        "data": [
          {
            "id": "sub_CBbgC3EaFZqN3Q",
            "object": "line_item",
            "amount": 999,
            "currency": "usd",
            "description": "1x Silver Express (at $9.99)",
            "discountable": true,
            "livemode": true,
            "metadata": {},
            "period": {
              "start": 1521760383,
              "end": 1524438783
            },
            "plan": {
              "id": "gold",
              "object": "plan",
              "amount": 2000,
              "created": 1516662783,
              "currency": "usd",
              "interval": "month",
              "interval_count": 1,
              "livemode": false,
              "metadata": {},
              "name": "T-shirt",
              "statement_descriptor": null,
              "trial_period_days": null
            },
            "proration": false,
            "quantity": 1,
            "subscription": null,
            "subscription_item": "si_CBbgZxCVF3Ha7P",
            "type": "subscription"
          }
        ],
        "has_more": false,
        "object": "list",
        "url": "/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines"
      },
      "livemode": false,
      "metadata": {},
      "next_payment_attempt": 1516666383,
      "number": "330a34b8d5-0001",
      "paid": false,
      "period_end": 1516662783,
      "period_start": 1516662783,
      "receipt_number": null,
      "starting_balance": 0,
      "statement_descriptor": null,
      "subscription": null,
      "subtotal": 0,
      "tax": null,
      "tax_percent": null,
      "total": 0,
      "webhooks_delivered_at": null
    }
  ]
}