PureBasic 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

PureBasic Example

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://api.stripe.com/v1/invoices?limit=3
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"api.stripe.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"STRIPE_SECRET_KEY","")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/v1/invoices?limit=3",sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody)

    object.s
    url.s
    has_more.i
    i.i
    count_i.i
    id.s
    amount_due.i
    application_fee.i
    attempt_count.i
    attempted.i
    billing.s
    charge.i
    closed.i
    currency.s
    customer.s
    date.i
    description.i
    discount.i
    due_date.i
    ending_balance.i
    forgiven.i
    linesHas_more.i
    linesObject.s
    linesUrl.s
    livemode.i
    next_payment_attempt.i
    number.s
    paid.i
    period_end.i
    period_start.i
    receipt_number.i
    starting_balance.i
    statement_descriptor.i
    subscription.i
    subtotal.i
    tax.i
    tax_percent.i
    total.i
    webhooks_delivered_at.i
    j.i
    count_j.i
    amount.i
    description_str.s
    discountable.i
    periodStart.i
    periodEnd.i
    planId.s
    planObject.s
    planAmount.i
    planCreated.i
    planCurrency.s
    planInterval.s
    planInterval_count.i
    planLivemode.i
    planName.s
    planStatement_descriptor.i
    planTrial_period_days.i
    proration.i
    quantity.i
    subscription_item.s
    type.s

    object = CkJsonObject::ckStringOf(jsonResponse,"object")
    url = CkJsonObject::ckStringOf(jsonResponse,"url")
    has_more = CkJsonObject::ckBoolOf(jsonResponse,"has_more")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"data")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        id = CkJsonObject::ckStringOf(jsonResponse,"data[i].id")
        object = CkJsonObject::ckStringOf(jsonResponse,"data[i].object")
        amount_due = CkJsonObject::ckIntOf(jsonResponse,"data[i].amount_due")
        application_fee = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].application_fee")
        attempt_count = CkJsonObject::ckIntOf(jsonResponse,"data[i].attempt_count")
        attempted = CkJsonObject::ckBoolOf(jsonResponse,"data[i].attempted")
        billing = CkJsonObject::ckStringOf(jsonResponse,"data[i].billing")
        charge = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].charge")
        closed = CkJsonObject::ckBoolOf(jsonResponse,"data[i].closed")
        currency = CkJsonObject::ckStringOf(jsonResponse,"data[i].currency")
        customer = CkJsonObject::ckStringOf(jsonResponse,"data[i].customer")
        date = CkJsonObject::ckIntOf(jsonResponse,"data[i].date")
        description = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].description")
        discount = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].discount")
        due_date = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].due_date")
        ending_balance = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].ending_balance")
        forgiven = CkJsonObject::ckBoolOf(jsonResponse,"data[i].forgiven")
        linesHas_more = CkJsonObject::ckBoolOf(jsonResponse,"data[i].lines.has_more")
        linesObject = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.object")
        linesUrl = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.url")
        livemode = CkJsonObject::ckBoolOf(jsonResponse,"data[i].livemode")
        next_payment_attempt = CkJsonObject::ckIntOf(jsonResponse,"data[i].next_payment_attempt")
        number = CkJsonObject::ckStringOf(jsonResponse,"data[i].number")
        paid = CkJsonObject::ckBoolOf(jsonResponse,"data[i].paid")
        period_end = CkJsonObject::ckIntOf(jsonResponse,"data[i].period_end")
        period_start = CkJsonObject::ckIntOf(jsonResponse,"data[i].period_start")
        receipt_number = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].receipt_number")
        starting_balance = CkJsonObject::ckIntOf(jsonResponse,"data[i].starting_balance")
        statement_descriptor = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].statement_descriptor")
        subscription = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].subscription")
        subtotal = CkJsonObject::ckIntOf(jsonResponse,"data[i].subtotal")
        tax = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].tax")
        tax_percent = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].tax_percent")
        total = CkJsonObject::ckIntOf(jsonResponse,"data[i].total")
        webhooks_delivered_at = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].webhooks_delivered_at")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"data[i].lines.data")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            id = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].id")
            object = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].object")
            amount = CkJsonObject::ckIntOf(jsonResponse,"data[i].lines.data[j].amount")
            currency = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].currency")
            description_str = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].description")
            discountable = CkJsonObject::ckBoolOf(jsonResponse,"data[i].lines.data[j].discountable")
            livemode = CkJsonObject::ckBoolOf(jsonResponse,"data[i].lines.data[j].livemode")
            periodStart = CkJsonObject::ckIntOf(jsonResponse,"data[i].lines.data[j].period.start")
            periodEnd = CkJsonObject::ckIntOf(jsonResponse,"data[i].lines.data[j].period.end")
            planId = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].plan.id")
            planObject = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].plan.object")
            planAmount = CkJsonObject::ckIntOf(jsonResponse,"data[i].lines.data[j].plan.amount")
            planCreated = CkJsonObject::ckIntOf(jsonResponse,"data[i].lines.data[j].plan.created")
            planCurrency = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].plan.currency")
            planInterval = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].plan.interval")
            planInterval_count = CkJsonObject::ckIntOf(jsonResponse,"data[i].lines.data[j].plan.interval_count")
            planLivemode = CkJsonObject::ckBoolOf(jsonResponse,"data[i].lines.data[j].plan.livemode")
            planName = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].plan.name")
            planStatement_descriptor = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].lines.data[j].plan.statement_descriptor")
            planTrial_period_days = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].lines.data[j].plan.trial_period_days")
            proration = CkJsonObject::ckBoolOf(jsonResponse,"data[i].lines.data[j].proration")
            quantity = CkJsonObject::ckIntOf(jsonResponse,"data[i].lines.data[j].quantity")
            subscription = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].lines.data[j].subscription")
            subscription_item = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].subscription_item")
            type = CkJsonObject::ckStringOf(jsonResponse,"data[i].lines.data[j].type")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkRest::ckDispose(rest)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

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