Sample code for 30+ languages & platforms
Xojo Plugin 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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

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

Dim curl As New Chilkat.HttpCurl
Dim cmd As New Chilkat.StringBuilder
Dim json As New Chilkat.JsonObject

Dim replaced As Int32

Dim invoiceId As String
invoiceId = "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"
success = cmd.SetString("curl -X GET ""https://api.stripe.com/v1/invoices/@ID@""")
success = cmd.Append(" -u ""@KEY@:""")
success = cmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
replaced = cmd.Replace("@ID@",invoiceId)
replaced = cmd.Replace("@KEY@",apiKey)
success = curl.DoYourThing(cmd.GetAsString())
If (success <> True) Then
    System.DebugLog("No HTTP response. Chilkat failure code: " + Str(curl.FailReason))
    Return
End If

success = curl.GetResponseJson(json)
If ((curl.StatusCode <> 200) Or (success <> True)) Then
    System.DebugLog("Stripe HTTP " + Str(curl.StatusCode) + "  Request-Id: " + curl.GetResponseHeaderField("Request-Id"))
    If (success = True) Then
        System.DebugLog(json.StringOf("error.message"))
    End If

    Return
End If

If (json.StringOf("collection_method") <> "send_invoice") Then
    System.DebugLog("Select an invoice intended for email collection.")
    Return
End If

If (json.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"
    success = cmd.SetString("curl -X POST ""https://api.stripe.com/v1/invoices/@ID@/finalize""")
    success = cmd.Append(" -u ""@KEY@:""")
    success = cmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
    success = cmd.Append(" -H ""Idempotency-Key: @OP@-finalize""")
    success = cmd.Append(" -d ""auto_advance=false""")
    replaced = cmd.Replace("@ID@",invoiceId)
    replaced = cmd.Replace("@OP@",operationId)
    replaced = cmd.Replace("@KEY@",apiKey)
    success = curl.DoYourThing(cmd.GetAsString())
    If (success <> True) Then
        System.DebugLog("No HTTP response. Chilkat failure code: " + Str(curl.FailReason))
        Return
    End If

    success = curl.GetResponseJson(json)
    If ((curl.StatusCode <> 200) Or (success <> True)) Then
        System.DebugLog("Stripe HTTP " + Str(curl.StatusCode) + "  Request-Id: " + curl.GetResponseHeaderField("Request-Id"))
        If (success = True) Then
            System.DebugLog(json.StringOf("error.message"))
        End If

        Return
    End If

End If

If (json.StringOf("status") <> "open") Then
    System.DebugLog("Invoice is not open for collection: " + json.StringOf("status"))
    Return
End If

//  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"
success = cmd.SetString("curl -X POST ""https://api.stripe.com/v1/invoices/@ID@/send""")
success = cmd.Append(" -u ""@KEY@:""")
success = cmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
success = cmd.Append(" -H ""Idempotency-Key: @OP@-send""")
replaced = cmd.Replace("@ID@",invoiceId)
replaced = cmd.Replace("@OP@",operationId)
replaced = cmd.Replace("@KEY@",apiKey)
success = curl.DoYourThing(cmd.GetAsString())
If (success <> True) Then
    System.DebugLog("No HTTP response. Chilkat failure code: " + Str(curl.FailReason))
    Return
End If

success = curl.GetResponseJson(json)
If ((curl.StatusCode <> 200) Or (success <> True)) Then
    System.DebugLog("Stripe HTTP " + Str(curl.StatusCode) + "  Request-Id: " + curl.GetResponseHeaderField("Request-Id"))
    If (success = True) Then
        System.DebugLog(json.StringOf("error.message"))
    End If

    Return
End If

System.DebugLog("number = " + json.StringOf("number"))
System.DebugLog("status = " + json.StringOf("status"))
System.DebugLog("hosted_invoice_url = " + json.StringOf("hosted_invoice_url"))