Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

PayPal: Find invoices for a recipient

See more PayPal Examples

Filter by a sandbox recipient email address in the JSON body. Pagination belongs in the URL. Read every matching invoice ID; several invoices can share the same recipient.

PayPal documentation

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loBody
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')

*  Use a JSON search body on every page; the recipient email does not belong in the
*  URL.
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("recipient_email","buyer@example.com")
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=20&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 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 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 loBody
        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 loBody
RELEASE loUrl
RELEASE loErrorInfo
RELEASE loResult