AutoIt Requires Chilkat v11.0.0+
AutoIt
PayPal: Send a draft invoice
See more PayPal Examples
Send a draft to its sandbox recipient. PayPal can accept delivery for later when the issue date is in the future. After an uncertain response, look up the invoice before trying again.
Chilkat AutoIt Downloads
Local $bSuccess = False
; See Unlock Chilkat before making requests.
; For the merchant's internal backoffice application. Load the sandbox token
; from the merchant's credential store. Keep it out of publicly distributed apps.
; See Get a PayPal access token.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
$oResp = ObjCreate("Chilkat.HttpResponse")
; The invoice already exists as a draft. Sending is the separate step that notifies
; the recipient.
$oHttp.SetUrlVar("id","INVOICE_ID")
$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateBool("send_to_recipient",True)
$oBody.UpdateBool("send_to_invoicer",False)
$bSuccess = $oHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/send",$oBody,"application/json",$oResp)
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
Exit
EndIf
If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
$oErrorInfo = ObjCreate("Chilkat.JsonObject")
$oErrorInfo.Load($oResp.BodyStr)
ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oErrorInfo.StringOf("name") & " " & $oErrorInfo.StringOf("details[0].issue") & @CRLF)
ConsoleWrite("PayPal debug ID: " & $oErrorInfo.StringOf("debug_id") & @CRLF)
Exit
EndIf
ConsoleWrite("Send request accepted; HTTP " & $oResp.StatusCode & @CRLF)