Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.7.0+

Stripe: Draft an invoice and attach line items

See more Stripe Examples

Create a draft for a customer and attach a priced line item to that specific invoice.

Stripe documentation and cURL example

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL lcApiKey
LOCAL lcOperationId
LOCAL loCurl
LOCAL loCmd
LOCAL loJson
LOCAL lnReplaced
LOCAL lcCustomerId
LOCAL lcPriceId
LOCAL lcInvoiceId

lnSuccess = 0

*  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
*  Supply a restricted sandbox key from merchant-controlled configuration.
lcApiKey = "YOUR_STRIPE_TEST_KEY"
*  Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
lcOperationId = "YOUR_SAVED_OPERATION_UUID"

loCurl = CreateObject('Chilkat.HttpCurl')
loCmd = CreateObject('Chilkat.StringBuilder')
loJson = CreateObject('Chilkat.JsonObject')

lcCustomerId = "cus_FROM_BILLING_ACCOUNT"

lcPriceId = "price_FROM_CATALOG"

*  curl -X POST "https://api.stripe.com/v1/invoices" \
*    -u "$STRIPE_API_KEY:" \
*    -H "Stripe-Version: 2026-10-28.endive" \
*    -H "Idempotency-Key: {operationId}-draft" \
*    -d "customer={customerId}" \
*    -d "collection_method=send_invoice" \
*    -d "days_until_due=30" \
*    -d "auto_advance=false" \
*    -d "pending_invoice_items_behavior=exclude"
loCmd.SetString('curl -X POST "https://api.stripe.com/v1/invoices"')
loCmd.Append(' -u "@KEY@:"')
loCmd.Append(' -H "Stripe-Version: 2026-10-28.endive"')
loCmd.Append(' -H "Idempotency-Key: @OP@-draft"')
loCmd.Append(' -d "customer=@CUSTOMER@"')
loCmd.Append(' -d "collection_method=send_invoice"')
loCmd.Append(' -d "days_until_due=30"')
loCmd.Append(' -d "auto_advance=false"')
loCmd.Append(' -d "pending_invoice_items_behavior=exclude"')
lnReplaced = loCmd.Replace("@CUSTOMER@",lcCustomerId)
lnReplaced = loCmd.Replace("@OP@",lcOperationId)
lnReplaced = loCmd.Replace("@KEY@",lcApiKey)
lnSuccess = loCurl.DoYourThing(loCmd.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "No HTTP response. Chilkat failure code: " + STR(loCurl.FailReason)
    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    CANCEL
ENDIF

lnSuccess = loCurl.GetResponseJson(loJson)
IF ((loCurl.StatusCode <> 200) OR (lnSuccess <> 1)) THEN
    ? "Stripe HTTP " + STR(loCurl.StatusCode) + "  Request-Id: " + loCurl.GetResponseHeaderField("Request-Id")
    IF (lnSuccess = 1) THEN
        ? loJson.StringOf("error.message")
    ENDIF

    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    CANCEL
ENDIF

lcInvoiceId = loJson.StringOf("id")
? "Save draft invoice ID: " + lcInvoiceId
*  Attach this line to the draft. Use a distinct stable key per local line on retries.

*  curl -X POST "https://api.stripe.com/v1/invoiceitems" \
*    -u "$STRIPE_API_KEY:" \
*    -H "Stripe-Version: 2026-10-28.endive" \
*    -H "Idempotency-Key: {operationId}-line-1" \
*    -d "invoice={invoiceId}" \
*    -d "customer={customerId}" \
*    -d "pricing[price]={priceId}" \
*    -d "quantity=2"
loCmd.SetString('curl -X POST "https://api.stripe.com/v1/invoiceitems"')
loCmd.Append(' -u "@KEY@:"')
loCmd.Append(' -H "Stripe-Version: 2026-10-28.endive"')
loCmd.Append(' -H "Idempotency-Key: @OP@-line-1"')
loCmd.Append(' -d "invoice=@INVOICE@"')
loCmd.Append(' -d "customer=@CUSTOMER@"')
loCmd.Append(' -d "pricing[price]=@PRICE@"')
loCmd.Append(' -d "quantity=2"')
lnReplaced = loCmd.Replace("@INVOICE@",lcInvoiceId)
lnReplaced = loCmd.Replace("@CUSTOMER@",lcCustomerId)
lnReplaced = loCmd.Replace("@PRICE@",lcPriceId)
lnReplaced = loCmd.Replace("@OP@",lcOperationId)
lnReplaced = loCmd.Replace("@KEY@",lcApiKey)
lnSuccess = loCurl.DoYourThing(loCmd.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "No HTTP response. Chilkat failure code: " + STR(loCurl.FailReason)
    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    CANCEL
ENDIF

lnSuccess = loCurl.GetResponseJson(loJson)
IF ((loCurl.StatusCode <> 200) OR (lnSuccess <> 1)) THEN
    ? "Stripe HTTP " + STR(loCurl.StatusCode) + "  Request-Id: " + loCurl.GetResponseHeaderField("Request-Id")
    IF (lnSuccess = 1) THEN
        ? loJson.StringOf("error.message")
    ENDIF

    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    CANCEL
ENDIF

? "invoice = " + loJson.StringOf("invoice")
? "id = " + loJson.StringOf("id")
? "amount = " + loJson.StringOf("amount")
? "currency = " + loJson.StringOf("currency")

RELEASE loCurl
RELEASE loCmd
RELEASE loJson