Tcl 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

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.stripe.com/v1/invoices?limit=3
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "api.stripe.com" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

CkRest_SetAuthBasic $rest "STRIPE_SECRET_KEY" ""

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/v1/invoices?limit=3" $sbResponseBody]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_LoadSb $jsonResponse $sbResponseBody

set object [CkJsonObject_stringOf $jsonResponse "object"]
set url [CkJsonObject_stringOf $jsonResponse "url"]
set has_more [CkJsonObject_BoolOf $jsonResponse "has_more"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "data"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set id [CkJsonObject_stringOf $jsonResponse "data[i].id"]
    set object [CkJsonObject_stringOf $jsonResponse "data[i].object"]
    set amount_due [CkJsonObject_IntOf $jsonResponse "data[i].amount_due"]
    set application_fee [CkJsonObject_IsNullOf $jsonResponse "data[i].application_fee"]
    set attempt_count [CkJsonObject_IntOf $jsonResponse "data[i].attempt_count"]
    set attempted [CkJsonObject_BoolOf $jsonResponse "data[i].attempted"]
    set billing [CkJsonObject_stringOf $jsonResponse "data[i].billing"]
    set charge [CkJsonObject_IsNullOf $jsonResponse "data[i].charge"]
    set closed [CkJsonObject_BoolOf $jsonResponse "data[i].closed"]
    set currency [CkJsonObject_stringOf $jsonResponse "data[i].currency"]
    set customer [CkJsonObject_stringOf $jsonResponse "data[i].customer"]
    set date [CkJsonObject_IntOf $jsonResponse "data[i].date"]
    set description [CkJsonObject_IsNullOf $jsonResponse "data[i].description"]
    set discount [CkJsonObject_IsNullOf $jsonResponse "data[i].discount"]
    set due_date [CkJsonObject_IsNullOf $jsonResponse "data[i].due_date"]
    set ending_balance [CkJsonObject_IsNullOf $jsonResponse "data[i].ending_balance"]
    set forgiven [CkJsonObject_BoolOf $jsonResponse "data[i].forgiven"]
    set linesHas_more [CkJsonObject_BoolOf $jsonResponse "data[i].lines.has_more"]
    set linesObject [CkJsonObject_stringOf $jsonResponse "data[i].lines.object"]
    set linesUrl [CkJsonObject_stringOf $jsonResponse "data[i].lines.url"]
    set livemode [CkJsonObject_BoolOf $jsonResponse "data[i].livemode"]
    set next_payment_attempt [CkJsonObject_IntOf $jsonResponse "data[i].next_payment_attempt"]
    set number [CkJsonObject_stringOf $jsonResponse "data[i].number"]
    set paid [CkJsonObject_BoolOf $jsonResponse "data[i].paid"]
    set period_end [CkJsonObject_IntOf $jsonResponse "data[i].period_end"]
    set period_start [CkJsonObject_IntOf $jsonResponse "data[i].period_start"]
    set receipt_number [CkJsonObject_IsNullOf $jsonResponse "data[i].receipt_number"]
    set starting_balance [CkJsonObject_IntOf $jsonResponse "data[i].starting_balance"]
    set statement_descriptor [CkJsonObject_IsNullOf $jsonResponse "data[i].statement_descriptor"]
    set subscription [CkJsonObject_IsNullOf $jsonResponse "data[i].subscription"]
    set subtotal [CkJsonObject_IntOf $jsonResponse "data[i].subtotal"]
    set tax [CkJsonObject_IsNullOf $jsonResponse "data[i].tax"]
    set tax_percent [CkJsonObject_IsNullOf $jsonResponse "data[i].tax_percent"]
    set total [CkJsonObject_IntOf $jsonResponse "data[i].total"]
    set webhooks_delivered_at [CkJsonObject_IsNullOf $jsonResponse "data[i].webhooks_delivered_at"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jsonResponse "data[i].lines.data"]
    while {[expr $j < $count_j]} {
        CkJsonObject_put_J $jsonResponse $j
        set id [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].id"]
        set object [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].object"]
        set amount [CkJsonObject_IntOf $jsonResponse "data[i].lines.data[j].amount"]
        set currency [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].currency"]
        set description_str [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].description"]
        set discountable [CkJsonObject_BoolOf $jsonResponse "data[i].lines.data[j].discountable"]
        set livemode [CkJsonObject_BoolOf $jsonResponse "data[i].lines.data[j].livemode"]
        set periodStart [CkJsonObject_IntOf $jsonResponse "data[i].lines.data[j].period.start"]
        set periodEnd [CkJsonObject_IntOf $jsonResponse "data[i].lines.data[j].period.end"]
        set planId [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].plan.id"]
        set planObject [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].plan.object"]
        set planAmount [CkJsonObject_IntOf $jsonResponse "data[i].lines.data[j].plan.amount"]
        set planCreated [CkJsonObject_IntOf $jsonResponse "data[i].lines.data[j].plan.created"]
        set planCurrency [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].plan.currency"]
        set planInterval [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].plan.interval"]
        set planInterval_count [CkJsonObject_IntOf $jsonResponse "data[i].lines.data[j].plan.interval_count"]
        set planLivemode [CkJsonObject_BoolOf $jsonResponse "data[i].lines.data[j].plan.livemode"]
        set planName [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].plan.name"]
        set planStatement_descriptor [CkJsonObject_IsNullOf $jsonResponse "data[i].lines.data[j].plan.statement_descriptor"]
        set planTrial_period_days [CkJsonObject_IsNullOf $jsonResponse "data[i].lines.data[j].plan.trial_period_days"]
        set proration [CkJsonObject_BoolOf $jsonResponse "data[i].lines.data[j].proration"]
        set quantity [CkJsonObject_IntOf $jsonResponse "data[i].lines.data[j].quantity"]
        set subscription [CkJsonObject_IsNullOf $jsonResponse "data[i].lines.data[j].subscription"]
        set subscription_item [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].subscription_item"]
        set type [CkJsonObject_stringOf $jsonResponse "data[i].lines.data[j].type"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $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
    }
  ]
}