Visual FoxPro 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:

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcObject
LOCAL lcUrl
LOCAL lnHas_more
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lnAmount
LOCAL lcCurrency
LOCAL lcDescription
LOCAL lnDiscountable
LOCAL lnLivemode
LOCAL lnPeriodStart
LOCAL lnPeriodEnd
LOCAL lnPlan
LOCAL lnProration
LOCAL lnQuantity
LOCAL lnSubscription
LOCAL lcType

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.stripe.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("STRIPE_SECRET_KEY","")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcObject = loJsonResponse.StringOf("object")
lcUrl = loJsonResponse.StringOf("url")
lnHas_more = loJsonResponse.BoolOf("has_more")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcId = loJsonResponse.StringOf("data[i].id")
    lcObject = loJsonResponse.StringOf("data[i].object")
    lnAmount = loJsonResponse.IntOf("data[i].amount")
    lcCurrency = loJsonResponse.StringOf("data[i].currency")
    lcDescription = loJsonResponse.StringOf("data[i].description")
    lnDiscountable = loJsonResponse.BoolOf("data[i].discountable")
    lnLivemode = loJsonResponse.BoolOf("data[i].livemode")
    lnPeriodStart = loJsonResponse.IntOf("data[i].period.start")
    lnPeriodEnd = loJsonResponse.IntOf("data[i].period.end")
    lnPlan = loJsonResponse.IsNullOf("data[i].plan")
    lnProration = loJsonResponse.BoolOf("data[i].proration")
    lnQuantity = loJsonResponse.IsNullOf("data[i].quantity")
    lnSubscription = loJsonResponse.IsNullOf("data[i].subscription")
    lcType = loJsonResponse.StringOf("data[i].type")
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

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