DataFlex 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

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJsonResponse
    String sObject
    String sUrl
    Boolean iHas_more
    Integer i
    Integer iCount_i
    String sId
    Integer iAmount_due
    Boolean iApplication_fee
    Integer iAttempt_count
    Boolean iAttempted
    String sBilling
    Boolean iCharge
    Boolean iClosed
    String sCurrency
    String sCustomer
    Integer iDate
    Boolean iDescription
    Boolean iDiscount
    Boolean iDue_date
    Boolean iEnding_balance
    Boolean iForgiven
    Boolean iLinesHas_more
    String sLinesObject
    String sLinesUrl
    Boolean iLivemode
    Integer iNext_payment_attempt
    String sNumber
    Boolean iPaid
    Integer iPeriod_end
    Integer iPeriod_start
    Boolean iReceipt_number
    Integer iStarting_balance
    Boolean iStatement_descriptor
    Boolean iSubscription
    Integer iSubtotal
    Boolean iTax
    Boolean iTax_percent
    Integer iTotal
    Boolean iWebhooks_delivered_at
    Integer j
    Integer iCount_j
    Integer iAmount
    String sDescription_str
    Boolean iDiscountable
    Integer iPeriodStart
    Integer iPeriodEnd
    String sPlanId
    String sPlanObject
    Integer iPlanAmount
    Integer iPlanCreated
    String sPlanCurrency
    String sPlanInterval
    Integer iPlanInterval_count
    Boolean iPlanLivemode
    String sPlanName
    Boolean iPlanStatement_descriptor
    Boolean iPlanTrial_period_days
    Boolean iProration
    Integer iQuantity
    String sSubscription_item
    String sType
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //  URL: https://api.stripe.com/v1/invoices?limit=3
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.stripe.com" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSetAuthBasic Of hoRest "STRIPE_SECRET_KEY" "" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestNoBodySb Of hoRest "GET" "/v1/invoices?limit=3" vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess

    Get ComStringOf Of hoJsonResponse "object" To sObject
    Get ComStringOf Of hoJsonResponse "url" To sUrl
    Get ComBoolOf Of hoJsonResponse "has_more" To iHas_more
    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Get ComStringOf Of hoJsonResponse "data[i].id" To sId
        Get ComStringOf Of hoJsonResponse "data[i].object" To sObject
        Get ComIntOf Of hoJsonResponse "data[i].amount_due" To iAmount_due
        Get ComIsNullOf Of hoJsonResponse "data[i].application_fee" To iApplication_fee
        Get ComIntOf Of hoJsonResponse "data[i].attempt_count" To iAttempt_count
        Get ComBoolOf Of hoJsonResponse "data[i].attempted" To iAttempted
        Get ComStringOf Of hoJsonResponse "data[i].billing" To sBilling
        Get ComIsNullOf Of hoJsonResponse "data[i].charge" To iCharge
        Get ComBoolOf Of hoJsonResponse "data[i].closed" To iClosed
        Get ComStringOf Of hoJsonResponse "data[i].currency" To sCurrency
        Get ComStringOf Of hoJsonResponse "data[i].customer" To sCustomer
        Get ComIntOf Of hoJsonResponse "data[i].date" To iDate
        Get ComIsNullOf Of hoJsonResponse "data[i].description" To iDescription
        Get ComIsNullOf Of hoJsonResponse "data[i].discount" To iDiscount
        Get ComIsNullOf Of hoJsonResponse "data[i].due_date" To iDue_date
        Get ComIsNullOf Of hoJsonResponse "data[i].ending_balance" To iEnding_balance
        Get ComBoolOf Of hoJsonResponse "data[i].forgiven" To iForgiven
        Get ComBoolOf Of hoJsonResponse "data[i].lines.has_more" To iLinesHas_more
        Get ComStringOf Of hoJsonResponse "data[i].lines.object" To sLinesObject
        Get ComStringOf Of hoJsonResponse "data[i].lines.url" To sLinesUrl
        Get ComBoolOf Of hoJsonResponse "data[i].livemode" To iLivemode
        Get ComIntOf Of hoJsonResponse "data[i].next_payment_attempt" To iNext_payment_attempt
        Get ComStringOf Of hoJsonResponse "data[i].number" To sNumber
        Get ComBoolOf Of hoJsonResponse "data[i].paid" To iPaid
        Get ComIntOf Of hoJsonResponse "data[i].period_end" To iPeriod_end
        Get ComIntOf Of hoJsonResponse "data[i].period_start" To iPeriod_start
        Get ComIsNullOf Of hoJsonResponse "data[i].receipt_number" To iReceipt_number
        Get ComIntOf Of hoJsonResponse "data[i].starting_balance" To iStarting_balance
        Get ComIsNullOf Of hoJsonResponse "data[i].statement_descriptor" To iStatement_descriptor
        Get ComIsNullOf Of hoJsonResponse "data[i].subscription" To iSubscription
        Get ComIntOf Of hoJsonResponse "data[i].subtotal" To iSubtotal
        Get ComIsNullOf Of hoJsonResponse "data[i].tax" To iTax
        Get ComIsNullOf Of hoJsonResponse "data[i].tax_percent" To iTax_percent
        Get ComIntOf Of hoJsonResponse "data[i].total" To iTotal
        Get ComIsNullOf Of hoJsonResponse "data[i].webhooks_delivered_at" To iWebhooks_delivered_at
        Move 0 To j
        Get ComSizeOfArray Of hoJsonResponse "data[i].lines.data" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJsonResponse To j
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].id" To sId
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].object" To sObject
            Get ComIntOf Of hoJsonResponse "data[i].lines.data[j].amount" To iAmount
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].currency" To sCurrency
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].description" To sDescription_str
            Get ComBoolOf Of hoJsonResponse "data[i].lines.data[j].discountable" To iDiscountable
            Get ComBoolOf Of hoJsonResponse "data[i].lines.data[j].livemode" To iLivemode
            Get ComIntOf Of hoJsonResponse "data[i].lines.data[j].period.start" To iPeriodStart
            Get ComIntOf Of hoJsonResponse "data[i].lines.data[j].period.end" To iPeriodEnd
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].plan.id" To sPlanId
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].plan.object" To sPlanObject
            Get ComIntOf Of hoJsonResponse "data[i].lines.data[j].plan.amount" To iPlanAmount
            Get ComIntOf Of hoJsonResponse "data[i].lines.data[j].plan.created" To iPlanCreated
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].plan.currency" To sPlanCurrency
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].plan.interval" To sPlanInterval
            Get ComIntOf Of hoJsonResponse "data[i].lines.data[j].plan.interval_count" To iPlanInterval_count
            Get ComBoolOf Of hoJsonResponse "data[i].lines.data[j].plan.livemode" To iPlanLivemode
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].plan.name" To sPlanName
            Get ComIsNullOf Of hoJsonResponse "data[i].lines.data[j].plan.statement_descriptor" To iPlanStatement_descriptor
            Get ComIsNullOf Of hoJsonResponse "data[i].lines.data[j].plan.trial_period_days" To iPlanTrial_period_days
            Get ComBoolOf Of hoJsonResponse "data[i].lines.data[j].proration" To iProration
            Get ComIntOf Of hoJsonResponse "data[i].lines.data[j].quantity" To iQuantity
            Get ComIsNullOf Of hoJsonResponse "data[i].lines.data[j].subscription" To iSubscription
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].subscription_item" To sSubscription_item
            Get ComStringOf Of hoJsonResponse "data[i].lines.data[j].type" To sType
            Move j + 1 To j
        Loop

        Move i + 1 To i
    Loop



End_Procedure

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