Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
PayPal: List merchant invoices across pages
See more PayPal Examples
List invoices for the authenticated merchant. Request totals, iterate every page, and keep the PayPal ID alongside the human-readable number and current status.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL lnPage
LOCAL lnLastPage
LOCAL loUrl
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsed
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')
* Request total_pages so a merchant with more than one page sees every invoice.
lnPage = 1
lnLastPage = 1
DO WHILE (lnPage <= lnLastPage)
loUrl = CreateObject('Chilkat.StringBuilder')
loUrl.Append("https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true&page_size=20&page=")
loUrl.AppendInt(lnPage)
lnSuccess = loHttp.HttpNoBody("GET",loUrl.GetAsString(),loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
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 loUrl
RELEASE loErrorInfo
CANCEL
ENDIF
loResult = CreateObject('Chilkat.JsonObject')
lnParsed = loResult.Load(loResp.BodyStr)
IF (lnParsed <> 1) THEN
? "Expected a JSON response; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
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].id") + " " + loResult.StringOf("items[i].detail.invoice_number") + " " + loResult.StringOf("items[i].status")
i = i + 1
ENDDO
lnLastPage = loResult.IntOf("total_pages")
lnPage = lnPage + 1
ENDDO
RELEASE loHttp
RELEASE loResp
RELEASE loUrl
RELEASE loErrorInfo
RELEASE loResult