Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loBody
LOCAL loDay
LOCAL lnPage
LOCAL lnLastPage
LOCAL loUrl
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsedResult
LOCAL i
LOCAL lnCount
lnSuccess = 0
* 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.
loHttp = CreateObject('Chilkat.Http')
loHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
loResp = CreateObject('Chilkat.HttpResponse')
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("status[0]","SENT")
loBody.UpdateString("status[1]","PARTIALLY_PAID")
loBody.UpdateString("status[2]","UNPAID")
loBody.UpdateString("status[3]","SHARED")
* Yesterday is the last overdue date. Include invoices due in the past 90 days.
loDay = CreateObject('Chilkat.CkDateTime')
loDay.SetFromCurrentSystemTime()
loDay.AddDays(-1)
loBody.UpdateString("due_date_range.end",loDay.GetAsIso8601("YYYY-MM-DD",0))
loDay.AddDays(-89)
loBody.UpdateString("due_date_range.start",loDay.GetAsIso8601("YYYY-MM-DD",0))
lnPage = 1
lnLastPage = 1
DO WHILE (lnPage <= lnLastPage)
loUrl = CreateObject('Chilkat.StringBuilder')
loUrl.Append("https://api-m.sandbox.paypal.com/v2/invoicing/search-invoices?total_required=true&page_size=50&page=")
loUrl.AppendInt(lnPage)
lnSuccess = loHttp.HttpJson("POST",loUrl.GetAsString(),loBody,"application/json",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDay
RELEASE loUrl
CANCEL
ENDIF
IF ((loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
loErrorInfo = CreateObject('Chilkat.JsonObject')
loErrorInfo.Load(loResp.BodyStr)
? "HTTP " + STR(loResp.StatusCode) + " " + loErrorInfo.StringOf("name") + " " + loErrorInfo.StringOf("details[0].issue")
? "PayPal debug ID: " + loErrorInfo.StringOf("debug_id")
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDay
RELEASE loUrl
RELEASE loErrorInfo
CANCEL
ENDIF
loResult = CreateObject('Chilkat.JsonObject')
lnParsedResult = loResult.Load(loResp.BodyStr)
IF (lnParsedResult <> 1) THEN
? "Expected a JSON response; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDay
RELEASE loUrl
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
i = 0
lnCount = loResult.SizeOfArray("items")
DO WHILE (i < lnCount)
loResult.I = i
? loResult.StringOf("items[i].detail.invoice_number") + " due " + loResult.StringOf("items[i].detail.payment_term.due_date") + " " + loResult.StringOf("items[i].due_amount.value") + " " + loResult.StringOf("items[i].due_amount.currency_code")
i = i + 1
ENDDO
lnLastPage = loResult.IntOf("total_pages")
lnPage = lnPage + 1
ENDDO
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDay
RELEASE loUrl
RELEASE loErrorInfo
RELEASE loResult