Delphi DLL Stripe: Retrieve an Invoice

Back to Index

Retrieves the invoice with the given ID.

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

CURL Command

curl https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0XR7p1RCtV \
   -u STRIPE_SECRET_KEY:

Delphi DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
sbResponseBody: HCkStringBuilder;
jsonResponse: HCkJsonObject;
id: PWideChar;
object: PWideChar;
amount_due: Integer;
application_fee: Boolean;
attempt_count: Integer;
attempted: Boolean;
billing: PWideChar;
charge: Boolean;
closed: Boolean;
currency: PWideChar;
customer: PWideChar;
date: Integer;
description: Boolean;
discount: Boolean;
due_date: Boolean;
ending_balance: Boolean;
forgiven: Boolean;
linesHas_more: Boolean;
linesObject: PWideChar;
linesUrl: PWideChar;
livemode: Boolean;
next_payment_attempt: Integer;
number: PWideChar;
paid: Boolean;
period_end: Integer;
period_start: Integer;
receipt_number: Boolean;
starting_balance: Integer;
statement_descriptor: Boolean;
subscription: Boolean;
subtotal: Integer;
tax: Boolean;
tax_percent: Boolean;
total: Integer;
webhooks_delivered_at: Boolean;
i: Integer;
count_i: Integer;
amount: Integer;
description_str: PWideChar;
discountable: Boolean;
periodStart: Integer;
periodEnd: Integer;
planId: PWideChar;
planObject: PWideChar;
planAmount: Integer;
planCreated: Integer;
planCurrency: PWideChar;
planInterval: PWideChar;
planInterval_count: Integer;
planLivemode: Boolean;
planName: PWideChar;
planStatement_descriptor: Boolean;
planTrial_period_days: Boolean;
proration: Boolean;
quantity: Integer;
subscription_item: PWideChar;
type: PWideChar;

begin
rest := CkRest_Create();

//  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0XR7p1RCtV
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_1BnETLGswQrCoh0XR7p1RCtV',sbResponseBody);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

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

id := CkJsonObject__stringOf(jsonResponse,'id');
object := CkJsonObject__stringOf(jsonResponse,'object');
amount_due := CkJsonObject_IntOf(jsonResponse,'amount_due');
application_fee := CkJsonObject_IsNullOf(jsonResponse,'application_fee');
attempt_count := CkJsonObject_IntOf(jsonResponse,'attempt_count');
attempted := CkJsonObject_BoolOf(jsonResponse,'attempted');
billing := CkJsonObject__stringOf(jsonResponse,'billing');
charge := CkJsonObject_IsNullOf(jsonResponse,'charge');
closed := CkJsonObject_BoolOf(jsonResponse,'closed');
currency := CkJsonObject__stringOf(jsonResponse,'currency');
customer := CkJsonObject__stringOf(jsonResponse,'customer');
date := CkJsonObject_IntOf(jsonResponse,'date');
description := CkJsonObject_IsNullOf(jsonResponse,'description');
discount := CkJsonObject_IsNullOf(jsonResponse,'discount');
due_date := CkJsonObject_IsNullOf(jsonResponse,'due_date');
ending_balance := CkJsonObject_IsNullOf(jsonResponse,'ending_balance');
forgiven := CkJsonObject_BoolOf(jsonResponse,'forgiven');
linesHas_more := CkJsonObject_BoolOf(jsonResponse,'lines.has_more');
linesObject := CkJsonObject__stringOf(jsonResponse,'lines.object');
linesUrl := CkJsonObject__stringOf(jsonResponse,'lines.url');
livemode := CkJsonObject_BoolOf(jsonResponse,'livemode');
next_payment_attempt := CkJsonObject_IntOf(jsonResponse,'next_payment_attempt');
number := CkJsonObject__stringOf(jsonResponse,'number');
paid := CkJsonObject_BoolOf(jsonResponse,'paid');
period_end := CkJsonObject_IntOf(jsonResponse,'period_end');
period_start := CkJsonObject_IntOf(jsonResponse,'period_start');
receipt_number := CkJsonObject_IsNullOf(jsonResponse,'receipt_number');
starting_balance := CkJsonObject_IntOf(jsonResponse,'starting_balance');
statement_descriptor := CkJsonObject_IsNullOf(jsonResponse,'statement_descriptor');
subscription := CkJsonObject_IsNullOf(jsonResponse,'subscription');
subtotal := CkJsonObject_IntOf(jsonResponse,'subtotal');
tax := CkJsonObject_IsNullOf(jsonResponse,'tax');
tax_percent := CkJsonObject_IsNullOf(jsonResponse,'tax_percent');
total := CkJsonObject_IntOf(jsonResponse,'total');
webhooks_delivered_at := CkJsonObject_IsNullOf(jsonResponse,'webhooks_delivered_at');
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'lines.data');
while i < count_i do
  begin
CkJsonObject_putI(jsonResponse,i);
    id := CkJsonObject__stringOf(jsonResponse,'lines.data[i].id');
    object := CkJsonObject__stringOf(jsonResponse,'lines.data[i].object');
    amount := CkJsonObject_IntOf(jsonResponse,'lines.data[i].amount');
    currency := CkJsonObject__stringOf(jsonResponse,'lines.data[i].currency');
    description_str := CkJsonObject__stringOf(jsonResponse,'lines.data[i].description');
    discountable := CkJsonObject_BoolOf(jsonResponse,'lines.data[i].discountable');
    livemode := CkJsonObject_BoolOf(jsonResponse,'lines.data[i].livemode');
    periodStart := CkJsonObject_IntOf(jsonResponse,'lines.data[i].period.start');
    periodEnd := CkJsonObject_IntOf(jsonResponse,'lines.data[i].period.end');
    planId := CkJsonObject__stringOf(jsonResponse,'lines.data[i].plan.id');
    planObject := CkJsonObject__stringOf(jsonResponse,'lines.data[i].plan.object');
    planAmount := CkJsonObject_IntOf(jsonResponse,'lines.data[i].plan.amount');
    planCreated := CkJsonObject_IntOf(jsonResponse,'lines.data[i].plan.created');
    planCurrency := CkJsonObject__stringOf(jsonResponse,'lines.data[i].plan.currency');
    planInterval := CkJsonObject__stringOf(jsonResponse,'lines.data[i].plan.interval');
    planInterval_count := CkJsonObject_IntOf(jsonResponse,'lines.data[i].plan.interval_count');
    planLivemode := CkJsonObject_BoolOf(jsonResponse,'lines.data[i].plan.livemode');
    planName := CkJsonObject__stringOf(jsonResponse,'lines.data[i].plan.name');
    planStatement_descriptor := CkJsonObject_IsNullOf(jsonResponse,'lines.data[i].plan.statement_descriptor');
    planTrial_period_days := CkJsonObject_IsNullOf(jsonResponse,'lines.data[i].plan.trial_period_days');
    proration := CkJsonObject_BoolOf(jsonResponse,'lines.data[i].proration');
    quantity := CkJsonObject_IntOf(jsonResponse,'lines.data[i].quantity');
    subscription := CkJsonObject_IsNullOf(jsonResponse,'lines.data[i].subscription');
    subscription_item := CkJsonObject__stringOf(jsonResponse,'lines.data[i].subscription_item');
    type := CkJsonObject__stringOf(jsonResponse,'lines.data[i].type');
    i := i + 1;
  end;

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

Sample JSON Response Body

{
  "id": "in_1BnETLGswQrCoh0XR7p1RCtV",
  "object": "invoice",
  "amount_due": 0,
  "application_fee": null,
  "attempt_count": 0,
  "attempted": false,
  "billing": "charge_automatically",
  "charge": null,
  "closed": false,
  "currency": "usd",
  "customer": "cus_CBbg9PmQ9sLbmo",
  "date": 1516662783,
  "description": null,
  "discount": null,
  "due_date": null,
  "ending_balance": null,
  "forgiven": false,
  "lines": {
    "data": [
      {
        "id": "sub_CBbgnZGMJwa9ta",
        "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_CBbgiJ7hAAGzMF",
        "type": "subscription"
      }
    ],
    "has_more": false,
    "object": "list",
    "url": "/v1/invoices/in_1BnETLGswQrCoh0XR7p1RCtV/lines"
  },
  "livemode": false,
  "metadata": {},
  "next_payment_attempt": 1516666383,
  "number": "36eba31eaa-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
}