Delphi ActiveX Stripe: Retrieve an Invoice's Line Items

Back to Index

Retrieves the line items for a given invoice.

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

CURL Command

curl https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5 \
   -u STRIPE_SECRET_KEY:

Delphi ActiveX Example

var
rest: TChilkatRest;
success: Integer;
bTls: Integer;
port: Integer;
bAutoReconnect: Integer;
sbResponseBody: TChilkatStringBuilder;
jsonResponse: TChilkatJsonObject;
object: WideString;
url: WideString;
has_more: Integer;
i: Integer;
count_i: Integer;
id: WideString;
amount: Integer;
currency: WideString;
description: WideString;
discountable: Integer;
livemode: Integer;
periodStart: Integer;
periodEnd: Integer;
plan: Integer;
proration: Integer;
quantity: Integer;
subscription: Integer;
type: WideString;

begin
rest := TChilkatRest.Create(Self);

//  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5
bTls := 1;
port := 443;
bAutoReconnect := 1;
success := rest.Connect('api.stripe.com',port,bTls,bAutoReconnect);
if (success <> 1) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(rest.ConnectFailReason));
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

rest.SetAuthBasic('STRIPE_SECRET_KEY','');

sbResponseBody := TChilkatStringBuilder.Create(Self);
success := rest.FullRequestNoBodySb('GET','/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5',sbResponseBody.ControlInterface);
if (success <> 1) then
  begin
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

jsonResponse := TChilkatJsonObject.Create(Self);
jsonResponse.LoadSb(sbResponseBody.ControlInterface);

object := jsonResponse.StringOf('object');
url := jsonResponse.StringOf('url');
has_more := jsonResponse.BoolOf('has_more');
i := 0;
count_i := jsonResponse.SizeOfArray('data');
while i < count_i do
  begin
    jsonResponse.I := i;
    id := jsonResponse.StringOf('data[i].id');
    object := jsonResponse.StringOf('data[i].object');
    amount := jsonResponse.IntOf('data[i].amount');
    currency := jsonResponse.StringOf('data[i].currency');
    description := jsonResponse.StringOf('data[i].description');
    discountable := jsonResponse.BoolOf('data[i].discountable');
    livemode := jsonResponse.BoolOf('data[i].livemode');
    periodStart := jsonResponse.IntOf('data[i].period.start');
    periodEnd := jsonResponse.IntOf('data[i].period.end');
    plan := jsonResponse.IsNullOf('data[i].plan');
    proration := jsonResponse.BoolOf('data[i].proration');
    quantity := jsonResponse.IsNullOf('data[i].quantity');
    subscription := jsonResponse.IsNullOf('data[i].subscription');
    type := jsonResponse.StringOf('data[i].type');
    i := i + 1;
  end;

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines",
  "has_more": false,
  "data": [
    {
      "id": "ii_1BnETLGswQrCoh0XhmXYb8CY",
      "object": "line_item",
      "amount": 1000,
      "currency": "usd",
      "description": "My First Invoice Item (created for API docs)",
      "discountable": true,
      "livemode": false,
      "metadata": {},
      "period": {
        "start": 1516662783,
        "end": 1516662783
      },
      "plan": null,
      "proration": false,
      "quantity": null,
      "subscription": null,
      "type": "invoiceitem"
    }
  ]
}