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

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

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

set curl = Server.CreateObject("Chilkat.HttpCurl")
set cmd = Server.CreateObject("Chilkat.StringBuilder")
set json = Server.CreateObject("Chilkat.JsonObject")

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 <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Chilkat failure code: " & curl.FailReason) & "</pre>"
    Response.End
End If

success = curl.GetResponseJson(json)
If ((curl.StatusCode <> 200) Or (success <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Stripe HTTP " & curl.StatusCode & "  Request-Id: " & curl.GetResponseHeaderField("Request-Id")) & "</pre>"
    If (success = 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( json.StringOf("error.message")) & "</pre>"
    End If

    Response.End
End If

If (json.StringOf("collection_method") <> "send_invoice") Then
    Response.Write "<pre>" & Server.HTMLEncode( "Select an invoice intended for email collection.") & "</pre>"
    Response.End
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 <> 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Chilkat failure code: " & curl.FailReason) & "</pre>"
        Response.End
    End If

    success = curl.GetResponseJson(json)
    If ((curl.StatusCode <> 200) Or (success <> 1)) Then
        Response.Write "<pre>" & Server.HTMLEncode( "Stripe HTTP " & curl.StatusCode & "  Request-Id: " & curl.GetResponseHeaderField("Request-Id")) & "</pre>"
        If (success = 1) Then
            Response.Write "<pre>" & Server.HTMLEncode( json.StringOf("error.message")) & "</pre>"
        End If

        Response.End
    End If

End If

If (json.StringOf("status") <> "open") Then
    Response.Write "<pre>" & Server.HTMLEncode( "Invoice is not open for collection: " & json.StringOf("status")) & "</pre>"
    Response.End
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 <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Chilkat failure code: " & curl.FailReason) & "</pre>"
    Response.End
End If

success = curl.GetResponseJson(json)
If ((curl.StatusCode <> 200) Or (success <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Stripe HTTP " & curl.StatusCode & "  Request-Id: " & curl.GetResponseHeaderField("Request-Id")) & "</pre>"
    If (success = 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( json.StringOf("error.message")) & "</pre>"
    End If

    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "number = " & json.StringOf("number")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "status = " & json.StringOf("status")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "hosted_invoice_url = " & json.StringOf("hosted_invoice_url")) & "</pre>"

%>
</body>
</html>