Delphi DLL 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 DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
sbResponseBody: HCkStringBuilder;
jsonResponse: HCkJsonObject;
object: PWideChar;
url: PWideChar;
has_more: Boolean;
i: Integer;
count_i: Integer;
id: PWideChar;
amount: Integer;
currency: PWideChar;
description: PWideChar;
discountable: Boolean;
livemode: Boolean;
periodStart: Integer;
periodEnd: Integer;
plan: Boolean;
proration: Boolean;
quantity: Boolean;
subscription: Boolean;
type: PWideChar;

begin
rest := CkRest_Create();

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

CkRest_SetAuthBasic(rest,'STRIPE_SECRET_KEY','');

sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5',sbResponseBody);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

jsonResponse := CkJsonObject_Create();
CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

object := CkJsonObject__stringOf(jsonResponse,'object');
url := CkJsonObject__stringOf(jsonResponse,'url');
has_more := CkJsonObject_BoolOf(jsonResponse,'has_more');
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'data');
while i < count_i do
  begin
CkJsonObject_putI(jsonResponse,i);
    id := CkJsonObject__stringOf(jsonResponse,'data[i].id');
    object := CkJsonObject__stringOf(jsonResponse,'data[i].object');
    amount := CkJsonObject_IntOf(jsonResponse,'data[i].amount');
    currency := CkJsonObject__stringOf(jsonResponse,'data[i].currency');
    description := CkJsonObject__stringOf(jsonResponse,'data[i].description');
    discountable := CkJsonObject_BoolOf(jsonResponse,'data[i].discountable');
    livemode := CkJsonObject_BoolOf(jsonResponse,'data[i].livemode');
    periodStart := CkJsonObject_IntOf(jsonResponse,'data[i].period.start');
    periodEnd := CkJsonObject_IntOf(jsonResponse,'data[i].period.end');
    plan := CkJsonObject_IsNullOf(jsonResponse,'data[i].plan');
    proration := CkJsonObject_BoolOf(jsonResponse,'data[i].proration');
    quantity := CkJsonObject_IsNullOf(jsonResponse,'data[i].quantity');
    subscription := CkJsonObject_IsNullOf(jsonResponse,'data[i].subscription');
    type := CkJsonObject__stringOf(jsonResponse,'data[i].type');
    i := i + 1;
  end;

CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);

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