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

Stripe: Finalize and email a reviewed invoice

See more Stripe Examples

Finalize a reviewed draft and send the open invoice by email. Stripe test mode returns the API result without delivering an email.

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 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')

lcInvoiceId = "in_FROM_BILLING_RECORD"

*  curl -X GET "https://api.stripe.com/v1/invoices/{invoiceId}" \
*    -u "$STRIPE_API_KEY:" \
*    -H "Stripe-Version: 2026-10-28.endive"
loCmd.SetString('curl -X GET "https://api.stripe.com/v1/invoices/@ID@"')
loCmd.Append(' -u "@KEY@:"')
loCmd.Append(' -H "Stripe-Version: 2026-10-28.endive"')
lnReplaced = loCmd.Replace("@ID@",lcInvoiceId)
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

IF (loJson.StringOf("collection_method") <> "send_invoice") THEN
    ? "Select an invoice intended for email collection."
    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    CANCEL
ENDIF

IF (loJson.StringOf("status") = "draft") THEN
    *  curl -X POST "https://api.stripe.com/v1/invoices/{invoiceId}/finalize" \
    *    -u "$STRIPE_API_KEY:" \
    *    -H "Stripe-Version: 2026-10-28.endive" \
    *    -H "Idempotency-Key: {operationId}-finalize" \
    *    -d "auto_advance=false"
    loCmd.SetString('curl -X POST "https://api.stripe.com/v1/invoices/@ID@/finalize"')
    loCmd.Append(' -u "@KEY@:"')
    loCmd.Append(' -H "Stripe-Version: 2026-10-28.endive"')
    loCmd.Append(' -H "Idempotency-Key: @OP@-finalize"')
    loCmd.Append(' -d "auto_advance=false"')
    lnReplaced = loCmd.Replace("@ID@",lcInvoiceId)
    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

ENDIF

IF (loJson.StringOf("status") <> "open") THEN
    ? "Invoice is not open for collection: " + loJson.StringOf("status")
    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    CANCEL
ENDIF

*  Retry a send using the same saved operation UUID. Test mode sends no email.

*  curl -X POST "https://api.stripe.com/v1/invoices/{invoiceId}/send" \
*    -u "$STRIPE_API_KEY:" \
*    -H "Stripe-Version: 2026-10-28.endive" \
*    -H "Idempotency-Key: {operationId}-send"
loCmd.SetString('curl -X POST "https://api.stripe.com/v1/invoices/@ID@/send"')
loCmd.Append(' -u "@KEY@:"')
loCmd.Append(' -H "Stripe-Version: 2026-10-28.endive"')
loCmd.Append(' -H "Idempotency-Key: @OP@-send"')
lnReplaced = loCmd.Replace("@ID@",lcInvoiceId)
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

? "number = " + loJson.StringOf("number")
? "status = " + loJson.StringOf("status")
? "hosted_invoice_url = " + loJson.StringOf("hosted_invoice_url")

RELEASE loCurl
RELEASE loCmd
RELEASE loJson