AutoIt Requires Chilkat v11.0.0+
AutoIt
PayPal: Build a worklist of overdue invoices
See more PayPal Examples
Find open invoices due in the past 90 days, including partial payments. Walk all result pages and display the invoice number, due date, and remaining balance for the collections team.
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")
$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateString("status[0]","SENT")
$oBody.UpdateString("status[1]","PARTIALLY_PAID")
$oBody.UpdateString("status[2]","UNPAID")
$oBody.UpdateString("status[3]","SHARED")
; Yesterday is the last overdue date. Include invoices due in the past 90 days.
$oDay = ObjCreate("Chilkat.CkDateTime")
$oDay.SetFromCurrentSystemTime()
$oDay.AddDays(-1)
$oBody.UpdateString("due_date_range.end",$oDay.GetAsIso8601("YYYY-MM-DD",False))
$oDay.AddDays(-89)
$oBody.UpdateString("due_date_range.start",$oDay.GetAsIso8601("YYYY-MM-DD",False))
Local $iPage = 1
Local $iLastPage = 1
While ($iPage <= $iLastPage)
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://api-m.sandbox.paypal.com/v2/invoicing/search-invoices?total_required=true&page_size=50&page=")
$oUrl.AppendInt($iPage)
$bSuccess = $oHttp.HttpJson("POST",$oUrl.GetAsString(),$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
$oResult = ObjCreate("Chilkat.JsonObject")
Local $bParsedResult = $oResult.Load($oResp.BodyStr)
If ($bParsedResult <> True) Then
ConsoleWrite("Expected a JSON response; HTTP " & $oResp.StatusCode & @CRLF)
Exit
EndIf
Local $i = 0
Local $iCount = $oResult.SizeOfArray("items")
While ($i < $iCount)
$oResult.I = $i
ConsoleWrite($oResult.StringOf("items[i].detail.invoice_number") & " due " & $oResult.StringOf("items[i].detail.payment_term.due_date") & " " & $oResult.StringOf("items[i].due_amount.value") _
& " " & $oResult.StringOf("items[i].due_amount.currency_code") & @CRLF)
$i = $i + 1
Wend
$iLastPage = $oResult.IntOf("total_pages")
$iPage = $iPage + 1
Wend