Unicode 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

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/invoices?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/invoices?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;
    int amount_due;
    bool application_fee;
    int attempt_count;
    bool attempted;
    const wchar_t *billing = 0;
    bool charge;
    bool closed;
    const wchar_t *currency = 0;
    const wchar_t *customer = 0;
    int date;
    bool description;
    bool discount;
    bool due_date;
    bool ending_balance;
    bool forgiven;
    bool linesHas_more;
    const wchar_t *linesObject = 0;
    const wchar_t *linesUrl = 0;
    bool livemode;
    int next_payment_attempt;
    const wchar_t *number = 0;
    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 wchar_t *description_str = 0;
    bool discountable;
    int periodStart;
    int periodEnd;
    const wchar_t *planId = 0;
    const wchar_t *planObject = 0;
    int planAmount;
    int planCreated;
    const wchar_t *planCurrency = 0;
    const wchar_t *planInterval = 0;
    int planInterval_count;
    bool planLivemode;
    const wchar_t *planName = 0;
    bool planStatement_descriptor;
    bool planTrial_period_days;
    bool proration;
    int quantity;
    const wchar_t *subscription_item = 0;
    const wchar_t *type = 0;

    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");
        amount_due = jsonResponse.IntOf(L"data[i].amount_due");
        application_fee = jsonResponse.IsNullOf(L"data[i].application_fee");
        attempt_count = jsonResponse.IntOf(L"data[i].attempt_count");
        attempted = jsonResponse.BoolOf(L"data[i].attempted");
        billing = jsonResponse.stringOf(L"data[i].billing");
        charge = jsonResponse.IsNullOf(L"data[i].charge");
        closed = jsonResponse.BoolOf(L"data[i].closed");
        currency = jsonResponse.stringOf(L"data[i].currency");
        customer = jsonResponse.stringOf(L"data[i].customer");
        date = jsonResponse.IntOf(L"data[i].date");
        description = jsonResponse.IsNullOf(L"data[i].description");
        discount = jsonResponse.IsNullOf(L"data[i].discount");
        due_date = jsonResponse.IsNullOf(L"data[i].due_date");
        ending_balance = jsonResponse.IsNullOf(L"data[i].ending_balance");
        forgiven = jsonResponse.BoolOf(L"data[i].forgiven");
        linesHas_more = jsonResponse.BoolOf(L"data[i].lines.has_more");
        linesObject = jsonResponse.stringOf(L"data[i].lines.object");
        linesUrl = jsonResponse.stringOf(L"data[i].lines.url");
        livemode = jsonResponse.BoolOf(L"data[i].livemode");
        next_payment_attempt = jsonResponse.IntOf(L"data[i].next_payment_attempt");
        number = jsonResponse.stringOf(L"data[i].number");
        paid = jsonResponse.BoolOf(L"data[i].paid");
        period_end = jsonResponse.IntOf(L"data[i].period_end");
        period_start = jsonResponse.IntOf(L"data[i].period_start");
        receipt_number = jsonResponse.IsNullOf(L"data[i].receipt_number");
        starting_balance = jsonResponse.IntOf(L"data[i].starting_balance");
        statement_descriptor = jsonResponse.IsNullOf(L"data[i].statement_descriptor");
        subscription = jsonResponse.IsNullOf(L"data[i].subscription");
        subtotal = jsonResponse.IntOf(L"data[i].subtotal");
        tax = jsonResponse.IsNullOf(L"data[i].tax");
        tax_percent = jsonResponse.IsNullOf(L"data[i].tax_percent");
        total = jsonResponse.IntOf(L"data[i].total");
        webhooks_delivered_at = jsonResponse.IsNullOf(L"data[i].webhooks_delivered_at");
        j = 0;
        count_j = jsonResponse.SizeOfArray(L"data[i].lines.data");
        while (j < count_j) {
            jsonResponse.put_J(j);
            id = jsonResponse.stringOf(L"data[i].lines.data[j].id");
            object = jsonResponse.stringOf(L"data[i].lines.data[j].object");
            amount = jsonResponse.IntOf(L"data[i].lines.data[j].amount");
            currency = jsonResponse.stringOf(L"data[i].lines.data[j].currency");
            description_str = jsonResponse.stringOf(L"data[i].lines.data[j].description");
            discountable = jsonResponse.BoolOf(L"data[i].lines.data[j].discountable");
            livemode = jsonResponse.BoolOf(L"data[i].lines.data[j].livemode");
            periodStart = jsonResponse.IntOf(L"data[i].lines.data[j].period.start");
            periodEnd = jsonResponse.IntOf(L"data[i].lines.data[j].period.end");
            planId = jsonResponse.stringOf(L"data[i].lines.data[j].plan.id");
            planObject = jsonResponse.stringOf(L"data[i].lines.data[j].plan.object");
            planAmount = jsonResponse.IntOf(L"data[i].lines.data[j].plan.amount");
            planCreated = jsonResponse.IntOf(L"data[i].lines.data[j].plan.created");
            planCurrency = jsonResponse.stringOf(L"data[i].lines.data[j].plan.currency");
            planInterval = jsonResponse.stringOf(L"data[i].lines.data[j].plan.interval");
            planInterval_count = jsonResponse.IntOf(L"data[i].lines.data[j].plan.interval_count");
            planLivemode = jsonResponse.BoolOf(L"data[i].lines.data[j].plan.livemode");
            planName = jsonResponse.stringOf(L"data[i].lines.data[j].plan.name");
            planStatement_descriptor = jsonResponse.IsNullOf(L"data[i].lines.data[j].plan.statement_descriptor");
            planTrial_period_days = jsonResponse.IsNullOf(L"data[i].lines.data[j].plan.trial_period_days");
            proration = jsonResponse.BoolOf(L"data[i].lines.data[j].proration");
            quantity = jsonResponse.IntOf(L"data[i].lines.data[j].quantity");
            subscription = jsonResponse.IsNullOf(L"data[i].lines.data[j].subscription");
            subscription_item = jsonResponse.stringOf(L"data[i].lines.data[j].subscription_item");
            type = jsonResponse.stringOf(L"data[i].lines.data[j].type");
            j = j + 1;
        }

        i = i + 1;
    }
    }

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