Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL nPage
LOCAL nLastPage
LOCAL oUrl
LOCAL oErrorInfo
LOCAL oResult
LOCAL nParsed
LOCAL i
LOCAL nCount
nSuccess := 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.
oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "SANDBOX_ACCESS_TOKEN"
oResp := CreateObject("Chilkat.HttpResponse")
// Request total_pages so a merchant with more than one page sees every invoice.
nPage := 1
nLastPage := 1
DO WHILE (nPage <= nLastPage)
oUrl := CreateObject("Chilkat.StringBuilder")
oUrl:Append("https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true&page_size=20&page=")
oUrl:AppendInt(nPage)
nSuccess := oHttp:HttpNoBody("GET", oUrl:GetAsString(), oResp)
IF (nSuccess != 1)
? "No HTTP response: " + oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
oUrl:destroy()
RETURN
ENDIF
IF ((oResp:StatusCode < 200) .OR. (oResp:StatusCode >= 300))
oErrorInfo := CreateObject("Chilkat.JsonObject")
oErrorInfo:Load(oResp:BodyStr)
? "HTTP " + Str(oResp:StatusCode) + " " + oErrorInfo:StringOf("name") + " " + oErrorInfo:StringOf("details[0].issue")
? "PayPal debug ID: " + oErrorInfo:StringOf("debug_id")
oHttp:destroy()
oResp:destroy()
oUrl:destroy()
oErrorInfo:destroy()
RETURN
ENDIF
oResult := CreateObject("Chilkat.JsonObject")
nParsed := oResult:Load(oResp:BodyStr)
IF (nParsed != 1)
? "Expected a JSON response; HTTP " + Str(oResp:StatusCode)
oHttp:destroy()
oResp:destroy()
oUrl:destroy()
oErrorInfo:destroy()
oResult:destroy()
RETURN
ENDIF
i := 0
nCount := oResult:SizeOfArray("items")
DO WHILE (i < nCount)
oResult:I := i
? oResult:StringOf("items[i].id") + " " + oResult:StringOf("items[i].detail.invoice_number") + " " + oResult:StringOf("items[i].status")
i := i + 1
ENDDO
nLastPage := oResult:IntOf("total_pages")
nPage := nPage + 1
ENDDO
oHttp:destroy()
oResp:destroy()
oUrl:destroy()
oErrorInfo:destroy()
oResult:destroy()