PowerBuilder 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

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
oleobject loo_JsonResponse
string ls_Object
string ls_Url
integer li_Has_more
integer i
integer li_Count_i
string ls_Id
integer li_Amount_due
integer li_Application_fee
integer li_Attempt_count
integer li_Attempted
string ls_Billing
integer li_Charge
integer li_Closed
string ls_Currency
string ls_Customer
integer li_Date
integer li_Description
integer li_Discount
integer li_Due_date
integer li_Ending_balance
integer li_Forgiven
integer li_LinesHas_more
string ls_LinesObject
string ls_LinesUrl
integer li_Livemode
integer li_Next_payment_attempt
string ls_Number
integer li_Paid
integer li_Period_end
integer li_Period_start
integer li_Receipt_number
integer li_Starting_balance
integer li_Statement_descriptor
integer li_Subscription
integer li_Subtotal
integer li_Tax
integer li_Tax_percent
integer li_Total
integer li_Webhooks_delivered_at
integer j
integer li_Count_j
integer li_Amount
string ls_Description_str
integer li_Discountable
integer li_PeriodStart
integer li_PeriodEnd
string ls_PlanId
string ls_PlanObject
integer li_PlanAmount
integer li_PlanCreated
string ls_PlanCurrency
string ls_PlanInterval
integer li_PlanInterval_count
integer li_PlanLivemode
string ls_PlanName
integer li_PlanStatement_descriptor
integer li_PlanTrial_period_days
integer li_Proration
integer li_Quantity
string ls_Subscription_item
string ls_Type

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  URL: https://api.stripe.com/v1/invoices?limit=3
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("api.stripe.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_Rest.SetAuthBasic("STRIPE_SECRET_KEY","")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/v1/invoices?limit=3",loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbResponseBody
    return
end if

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResponse.LoadSb(loo_SbResponseBody)

ls_Object = loo_JsonResponse.StringOf("object")
ls_Url = loo_JsonResponse.StringOf("url")
li_Has_more = loo_JsonResponse.BoolOf("has_more")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("data")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Id = loo_JsonResponse.StringOf("data[i].id")
    ls_Object = loo_JsonResponse.StringOf("data[i].object")
    li_Amount_due = loo_JsonResponse.IntOf("data[i].amount_due")
    li_Application_fee = loo_JsonResponse.IsNullOf("data[i].application_fee")
    li_Attempt_count = loo_JsonResponse.IntOf("data[i].attempt_count")
    li_Attempted = loo_JsonResponse.BoolOf("data[i].attempted")
    ls_Billing = loo_JsonResponse.StringOf("data[i].billing")
    li_Charge = loo_JsonResponse.IsNullOf("data[i].charge")
    li_Closed = loo_JsonResponse.BoolOf("data[i].closed")
    ls_Currency = loo_JsonResponse.StringOf("data[i].currency")
    ls_Customer = loo_JsonResponse.StringOf("data[i].customer")
    li_Date = loo_JsonResponse.IntOf("data[i].date")
    li_Description = loo_JsonResponse.IsNullOf("data[i].description")
    li_Discount = loo_JsonResponse.IsNullOf("data[i].discount")
    li_Due_date = loo_JsonResponse.IsNullOf("data[i].due_date")
    li_Ending_balance = loo_JsonResponse.IsNullOf("data[i].ending_balance")
    li_Forgiven = loo_JsonResponse.BoolOf("data[i].forgiven")
    li_LinesHas_more = loo_JsonResponse.BoolOf("data[i].lines.has_more")
    ls_LinesObject = loo_JsonResponse.StringOf("data[i].lines.object")
    ls_LinesUrl = loo_JsonResponse.StringOf("data[i].lines.url")
    li_Livemode = loo_JsonResponse.BoolOf("data[i].livemode")
    li_Next_payment_attempt = loo_JsonResponse.IntOf("data[i].next_payment_attempt")
    ls_Number = loo_JsonResponse.StringOf("data[i].number")
    li_Paid = loo_JsonResponse.BoolOf("data[i].paid")
    li_Period_end = loo_JsonResponse.IntOf("data[i].period_end")
    li_Period_start = loo_JsonResponse.IntOf("data[i].period_start")
    li_Receipt_number = loo_JsonResponse.IsNullOf("data[i].receipt_number")
    li_Starting_balance = loo_JsonResponse.IntOf("data[i].starting_balance")
    li_Statement_descriptor = loo_JsonResponse.IsNullOf("data[i].statement_descriptor")
    li_Subscription = loo_JsonResponse.IsNullOf("data[i].subscription")
    li_Subtotal = loo_JsonResponse.IntOf("data[i].subtotal")
    li_Tax = loo_JsonResponse.IsNullOf("data[i].tax")
    li_Tax_percent = loo_JsonResponse.IsNullOf("data[i].tax_percent")
    li_Total = loo_JsonResponse.IntOf("data[i].total")
    li_Webhooks_delivered_at = loo_JsonResponse.IsNullOf("data[i].webhooks_delivered_at")
    j = 0
    li_Count_j = loo_JsonResponse.SizeOfArray("data[i].lines.data")
    do while j < li_Count_j
        loo_JsonResponse.J = j
        ls_Id = loo_JsonResponse.StringOf("data[i].lines.data[j].id")
        ls_Object = loo_JsonResponse.StringOf("data[i].lines.data[j].object")
        li_Amount = loo_JsonResponse.IntOf("data[i].lines.data[j].amount")
        ls_Currency = loo_JsonResponse.StringOf("data[i].lines.data[j].currency")
        ls_Description_str = loo_JsonResponse.StringOf("data[i].lines.data[j].description")
        li_Discountable = loo_JsonResponse.BoolOf("data[i].lines.data[j].discountable")
        li_Livemode = loo_JsonResponse.BoolOf("data[i].lines.data[j].livemode")
        li_PeriodStart = loo_JsonResponse.IntOf("data[i].lines.data[j].period.start")
        li_PeriodEnd = loo_JsonResponse.IntOf("data[i].lines.data[j].period.end")
        ls_PlanId = loo_JsonResponse.StringOf("data[i].lines.data[j].plan.id")
        ls_PlanObject = loo_JsonResponse.StringOf("data[i].lines.data[j].plan.object")
        li_PlanAmount = loo_JsonResponse.IntOf("data[i].lines.data[j].plan.amount")
        li_PlanCreated = loo_JsonResponse.IntOf("data[i].lines.data[j].plan.created")
        ls_PlanCurrency = loo_JsonResponse.StringOf("data[i].lines.data[j].plan.currency")
        ls_PlanInterval = loo_JsonResponse.StringOf("data[i].lines.data[j].plan.interval")
        li_PlanInterval_count = loo_JsonResponse.IntOf("data[i].lines.data[j].plan.interval_count")
        li_PlanLivemode = loo_JsonResponse.BoolOf("data[i].lines.data[j].plan.livemode")
        ls_PlanName = loo_JsonResponse.StringOf("data[i].lines.data[j].plan.name")
        li_PlanStatement_descriptor = loo_JsonResponse.IsNullOf("data[i].lines.data[j].plan.statement_descriptor")
        li_PlanTrial_period_days = loo_JsonResponse.IsNullOf("data[i].lines.data[j].plan.trial_period_days")
        li_Proration = loo_JsonResponse.BoolOf("data[i].lines.data[j].proration")
        li_Quantity = loo_JsonResponse.IntOf("data[i].lines.data[j].quantity")
        li_Subscription = loo_JsonResponse.IsNullOf("data[i].lines.data[j].subscription")
        ls_Subscription_item = loo_JsonResponse.StringOf("data[i].lines.data[j].subscription_item")
        ls_Type = loo_JsonResponse.StringOf("data[i].lines.data[j].type")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_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
    }
  ]
}