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

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_due
LOCAL lnApplication_fee
LOCAL lnAttempt_count
LOCAL lnAttempted
LOCAL lcBilling
LOCAL lnCharge
LOCAL lnClosed
LOCAL lcCurrency
LOCAL lcCustomer
LOCAL lnDate
LOCAL lnDescription
LOCAL lnDiscount
LOCAL lnDue_date
LOCAL lnEnding_balance
LOCAL lnForgiven
LOCAL lnLinesHas_more
LOCAL lcLinesObject
LOCAL lcLinesUrl
LOCAL lnLivemode
LOCAL lnNext_payment_attempt
LOCAL lcNumber
LOCAL lnPaid
LOCAL lnPeriod_end
LOCAL lnPeriod_start
LOCAL lnReceipt_number
LOCAL lnStarting_balance
LOCAL lnStatement_descriptor
LOCAL lnSubscription
LOCAL lnSubtotal
LOCAL lnTax
LOCAL lnTax_percent
LOCAL lnTotal
LOCAL lnWebhooks_delivered_at
LOCAL j
LOCAL lnCount_j
LOCAL lnAmount
LOCAL lcDescription_str
LOCAL lnDiscountable
LOCAL lnPeriodStart
LOCAL lnPeriodEnd
LOCAL lcPlanId
LOCAL lcPlanObject
LOCAL lnPlanAmount
LOCAL lnPlanCreated
LOCAL lcPlanCurrency
LOCAL lcPlanInterval
LOCAL lnPlanInterval_count
LOCAL lnPlanLivemode
LOCAL lcPlanName
LOCAL lnPlanStatement_descriptor
LOCAL lnPlanTrial_period_days
LOCAL lnProration
LOCAL lnQuantity
LOCAL lcSubscription_item
LOCAL lcType

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/invoices?limit=3
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?limit=3",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_due = loJsonResponse.IntOf("data[i].amount_due")
    lnApplication_fee = loJsonResponse.IsNullOf("data[i].application_fee")
    lnAttempt_count = loJsonResponse.IntOf("data[i].attempt_count")
    lnAttempted = loJsonResponse.BoolOf("data[i].attempted")
    lcBilling = loJsonResponse.StringOf("data[i].billing")
    lnCharge = loJsonResponse.IsNullOf("data[i].charge")
    lnClosed = loJsonResponse.BoolOf("data[i].closed")
    lcCurrency = loJsonResponse.StringOf("data[i].currency")
    lcCustomer = loJsonResponse.StringOf("data[i].customer")
    lnDate = loJsonResponse.IntOf("data[i].date")
    lnDescription = loJsonResponse.IsNullOf("data[i].description")
    lnDiscount = loJsonResponse.IsNullOf("data[i].discount")
    lnDue_date = loJsonResponse.IsNullOf("data[i].due_date")
    lnEnding_balance = loJsonResponse.IsNullOf("data[i].ending_balance")
    lnForgiven = loJsonResponse.BoolOf("data[i].forgiven")
    lnLinesHas_more = loJsonResponse.BoolOf("data[i].lines.has_more")
    lcLinesObject = loJsonResponse.StringOf("data[i].lines.object")
    lcLinesUrl = loJsonResponse.StringOf("data[i].lines.url")
    lnLivemode = loJsonResponse.BoolOf("data[i].livemode")
    lnNext_payment_attempt = loJsonResponse.IntOf("data[i].next_payment_attempt")
    lcNumber = loJsonResponse.StringOf("data[i].number")
    lnPaid = loJsonResponse.BoolOf("data[i].paid")
    lnPeriod_end = loJsonResponse.IntOf("data[i].period_end")
    lnPeriod_start = loJsonResponse.IntOf("data[i].period_start")
    lnReceipt_number = loJsonResponse.IsNullOf("data[i].receipt_number")
    lnStarting_balance = loJsonResponse.IntOf("data[i].starting_balance")
    lnStatement_descriptor = loJsonResponse.IsNullOf("data[i].statement_descriptor")
    lnSubscription = loJsonResponse.IsNullOf("data[i].subscription")
    lnSubtotal = loJsonResponse.IntOf("data[i].subtotal")
    lnTax = loJsonResponse.IsNullOf("data[i].tax")
    lnTax_percent = loJsonResponse.IsNullOf("data[i].tax_percent")
    lnTotal = loJsonResponse.IntOf("data[i].total")
    lnWebhooks_delivered_at = loJsonResponse.IsNullOf("data[i].webhooks_delivered_at")
    j = 0
    lnCount_j = loJsonResponse.SizeOfArray("data[i].lines.data")
    DO WHILE j < lnCount_j
        loJsonResponse.J = j
        lcId = loJsonResponse.StringOf("data[i].lines.data[j].id")
        lcObject = loJsonResponse.StringOf("data[i].lines.data[j].object")
        lnAmount = loJsonResponse.IntOf("data[i].lines.data[j].amount")
        lcCurrency = loJsonResponse.StringOf("data[i].lines.data[j].currency")
        lcDescription_str = loJsonResponse.StringOf("data[i].lines.data[j].description")
        lnDiscountable = loJsonResponse.BoolOf("data[i].lines.data[j].discountable")
        lnLivemode = loJsonResponse.BoolOf("data[i].lines.data[j].livemode")
        lnPeriodStart = loJsonResponse.IntOf("data[i].lines.data[j].period.start")
        lnPeriodEnd = loJsonResponse.IntOf("data[i].lines.data[j].period.end")
        lcPlanId = loJsonResponse.StringOf("data[i].lines.data[j].plan.id")
        lcPlanObject = loJsonResponse.StringOf("data[i].lines.data[j].plan.object")
        lnPlanAmount = loJsonResponse.IntOf("data[i].lines.data[j].plan.amount")
        lnPlanCreated = loJsonResponse.IntOf("data[i].lines.data[j].plan.created")
        lcPlanCurrency = loJsonResponse.StringOf("data[i].lines.data[j].plan.currency")
        lcPlanInterval = loJsonResponse.StringOf("data[i].lines.data[j].plan.interval")
        lnPlanInterval_count = loJsonResponse.IntOf("data[i].lines.data[j].plan.interval_count")
        lnPlanLivemode = loJsonResponse.BoolOf("data[i].lines.data[j].plan.livemode")
        lcPlanName = loJsonResponse.StringOf("data[i].lines.data[j].plan.name")
        lnPlanStatement_descriptor = loJsonResponse.IsNullOf("data[i].lines.data[j].plan.statement_descriptor")
        lnPlanTrial_period_days = loJsonResponse.IsNullOf("data[i].lines.data[j].plan.trial_period_days")
        lnProration = loJsonResponse.BoolOf("data[i].lines.data[j].proration")
        lnQuantity = loJsonResponse.IntOf("data[i].lines.data[j].quantity")
        lnSubscription = loJsonResponse.IsNullOf("data[i].lines.data[j].subscription")
        lcSubscription_item = loJsonResponse.StringOf("data[i].lines.data[j].subscription_item")
        lcType = loJsonResponse.StringOf("data[i].lines.data[j].type")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

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