DataFlex Stripe: Retrieve an Upcoming Invoice

Back to Index

Retrieves an upcoming invoice.

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

CURL Command

curl https://api.stripe.com/v1/invoices/upcoming?customer=cus_CBbggkUyLoz3pe \
   -u STRIPE_SECRET_KEY:

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



End_Procedure

Sample JSON Response Body

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