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

PayPal: Find disputes awaiting a seller response

See more PayPal Examples

Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.

PayPal documentation

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loSince
LOCAL loQuery
LOCAL lnPage
LOCAL lnMore
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsedResult
LOCAL i
LOCAL lnHasNext
LOCAL lnLinkIndex

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')
loSince = CreateObject('Chilkat.CkDateTime')
loSince.SetFromCurrentSystemTime()
loSince.AddDays(-30)
loQuery = CreateObject('Chilkat.JsonObject')
loQuery.UpdateString("update_time_after",loSince.GetAsTimestamp(0))
loQuery.UpdateInt("page_size",50)
lnPage = 1
lnMore = 1
DO WHILE (lnMore = 1)
    loQuery.UpdateInt("page",lnPage)
    lnSuccess = loHttp.HttpParams("GET","https://api-m.sandbox.paypal.com/v1/customer/disputes",loQuery,loResp)
    IF (lnSuccess <> 1) THEN
        ? "No HTTP response: " + loHttp.LastErrorText
        RELEASE loHttp
        RELEASE loResp
        RELEASE loSince
        RELEASE loQuery
        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 loSince
        RELEASE loQuery
        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 loSince
        RELEASE loQuery
        RELEASE loErrorInfo
        RELEASE loResult
        CANCEL
    ENDIF

    i = 0
    DO WHILE (i < loResult.SizeOfArray("items"))
        loResult.I = i
        IF (loResult.StringOfEquals("items[i].status","WAITING_FOR_SELLER_RESPONSE",1) = 1) THEN
            ? loResult.StringOf("items[i].dispute_id") + "  " + loResult.StringOf("items[i].reason")
            IF (loResult.HasMember("items[i].seller_response_due_date") = 1) THEN
                ? "Respond by " + loResult.StringOf("items[i].seller_response_due_date")
            ENDIF

        ENDIF

        i = i + 1
    ENDDO
    lnHasNext = 0
    lnLinkIndex = 0
    DO WHILE (lnLinkIndex < loResult.SizeOfArray("links"))
        loResult.I = lnLinkIndex
        IF (loResult.StringOfEquals("links[i].rel","next",1) = 1) THEN
            lnHasNext = 1
        ENDIF

        lnLinkIndex = lnLinkIndex + 1
    ENDDO
    lnMore = lnHasNext
    lnPage = lnPage + 1
ENDDO

RELEASE loHttp
RELEASE loResp
RELEASE loSince
RELEASE loQuery
RELEASE loErrorInfo
RELEASE loResult