AutoIt Requires Chilkat v11.7.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Requires an unlocked Chilkat bundle. See Global Unlock Sample.
; Supply a restricted sandbox key from merchant-controlled configuration.
Local $sApiKey = "YOUR_STRIPE_TEST_KEY"
; Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
Local $sOperationId = "YOUR_SAVED_OPERATION_UUID"
$oCurl = ObjCreate("Chilkat.HttpCurl")
$oCmd = ObjCreate("Chilkat.StringBuilder")
$oJson = ObjCreate("Chilkat.JsonObject")
Local $iReplaced
Local $sInvoiceId = "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"
$oCmd.SetString("curl -X GET ""https://api.stripe.com/v1/invoices/@ID@""")
$oCmd.Append(" -u ""@KEY@:""")
$oCmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
$iReplaced = $oCmd.Replace("@ID@",$sInvoiceId)
$iReplaced = $oCmd.Replace("@KEY@",$sApiKey)
$bSuccess = $oCurl.DoYourThing($oCmd.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response. Chilkat failure code: " & $oCurl.FailReason & @CRLF)
Exit
EndIf
$bSuccess = $oCurl.GetResponseJson($oJson)
If (($oCurl.StatusCode <> 200) Or ($bSuccess <> True)) Then
ConsoleWrite("Stripe HTTP " & $oCurl.StatusCode & " Request-Id: " & $oCurl.GetResponseHeaderField("Request-Id") & @CRLF)
If ($bSuccess = True) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
If ($oJson.StringOf("collection_method") <> "send_invoice") Then
ConsoleWrite("Select an invoice intended for email collection." & @CRLF)
Exit
EndIf
If ($oJson.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"
$oCmd.SetString("curl -X POST ""https://api.stripe.com/v1/invoices/@ID@/finalize""")
$oCmd.Append(" -u ""@KEY@:""")
$oCmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
$oCmd.Append(" -H ""Idempotency-Key: @OP@-finalize""")
$oCmd.Append(" -d ""auto_advance=false""")
$iReplaced = $oCmd.Replace("@ID@",$sInvoiceId)
$iReplaced = $oCmd.Replace("@OP@",$sOperationId)
$iReplaced = $oCmd.Replace("@KEY@",$sApiKey)
$bSuccess = $oCurl.DoYourThing($oCmd.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response. Chilkat failure code: " & $oCurl.FailReason & @CRLF)
Exit
EndIf
$bSuccess = $oCurl.GetResponseJson($oJson)
If (($oCurl.StatusCode <> 200) Or ($bSuccess <> True)) Then
ConsoleWrite("Stripe HTTP " & $oCurl.StatusCode & " Request-Id: " & $oCurl.GetResponseHeaderField("Request-Id") & @CRLF)
If ($bSuccess = True) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
EndIf
If ($oJson.StringOf("status") <> "open") Then
ConsoleWrite("Invoice is not open for collection: " & $oJson.StringOf("status") & @CRLF)
Exit
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"
$oCmd.SetString("curl -X POST ""https://api.stripe.com/v1/invoices/@ID@/send""")
$oCmd.Append(" -u ""@KEY@:""")
$oCmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
$oCmd.Append(" -H ""Idempotency-Key: @OP@-send""")
$iReplaced = $oCmd.Replace("@ID@",$sInvoiceId)
$iReplaced = $oCmd.Replace("@OP@",$sOperationId)
$iReplaced = $oCmd.Replace("@KEY@",$sApiKey)
$bSuccess = $oCurl.DoYourThing($oCmd.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response. Chilkat failure code: " & $oCurl.FailReason & @CRLF)
Exit
EndIf
$bSuccess = $oCurl.GetResponseJson($oJson)
If (($oCurl.StatusCode <> 200) Or ($bSuccess <> True)) Then
ConsoleWrite("Stripe HTTP " & $oCurl.StatusCode & " Request-Id: " & $oCurl.GetResponseHeaderField("Request-Id") & @CRLF)
If ($bSuccess = True) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
ConsoleWrite("number = " & $oJson.StringOf("number") & @CRLF)
ConsoleWrite("status = " & $oJson.StringOf("status") & @CRLF)
ConsoleWrite("hosted_invoice_url = " & $oJson.StringOf("hosted_invoice_url") & @CRLF)