Sample code for 30+ languages & platforms
PowerBuilder 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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Since
oleobject loo_Query
long li_Page
long li_More
oleobject loo_ErrorInfo
oleobject loo_Result
long li_ParsedResult
long i
long li_HasNext
long li_LinkIndex

li_Success = 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.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Http.AuthToken = "SANDBOX_ACCESS_TOKEN"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

loo_Since = create oleobject
li_rc = loo_Since.ConnectToNewObject("Chilkat.CkDateTime")

loo_Since.SetFromCurrentSystemTime()
loo_Since.AddDays(-30)
loo_Query = create oleobject
li_rc = loo_Query.ConnectToNewObject("Chilkat.JsonObject")

loo_Query.UpdateString("update_time_after",loo_Since.GetAsTimestamp(0))
loo_Query.UpdateInt("page_size",50)
li_Page = 1
li_More = 1
do while (li_More = 1)
    loo_Query.UpdateInt("page",li_Page)
    li_Success = loo_Http.HttpParams("GET","https://api-m.sandbox.paypal.com/v1/customer/disputes",loo_Query,loo_Resp)
    if li_Success <> 1 then
        Write-Debug "No HTTP response: " + loo_Http.LastErrorText
        destroy loo_Http
        destroy loo_Resp
        destroy loo_Since
        destroy loo_Query
        return
    end if

    if (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
        loo_ErrorInfo = create oleobject
        li_rc = loo_ErrorInfo.ConnectToNewObject("Chilkat.JsonObject")

        loo_ErrorInfo.Load(loo_Resp.BodyStr)
        Write-Debug "HTTP " + string(loo_Resp.StatusCode) + " " + loo_ErrorInfo.StringOf("name") + " " + loo_ErrorInfo.StringOf("details[0].issue")
        Write-Debug "PayPal debug ID: " + loo_ErrorInfo.StringOf("debug_id")
        destroy loo_Http
        destroy loo_Resp
        destroy loo_Since
        destroy loo_Query
        destroy loo_ErrorInfo
        return
    end if

    loo_Result = create oleobject
    li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject")

    li_ParsedResult = loo_Result.Load(loo_Resp.BodyStr)
    if li_ParsedResult <> 1 then
        Write-Debug "Expected a JSON response; HTTP " + string(loo_Resp.StatusCode)
        destroy loo_Http
        destroy loo_Resp
        destroy loo_Since
        destroy loo_Query
        destroy loo_ErrorInfo
        destroy loo_Result
        return
    end if

    i = 0
    do while (i < loo_Result.SizeOfArray("items"))
        loo_Result.I = i
        if loo_Result.StringOfEquals("items[i].status","WAITING_FOR_SELLER_RESPONSE",1) = 1 then
            Write-Debug loo_Result.StringOf("items[i].dispute_id") + "  " + loo_Result.StringOf("items[i].reason")
            if loo_Result.HasMember("items[i].seller_response_due_date") = 1 then
                Write-Debug "Respond by " + loo_Result.StringOf("items[i].seller_response_due_date")
            end if

        end if

        i = i + 1
    loop
    li_HasNext = 0
    li_LinkIndex = 0
    do while (li_LinkIndex < loo_Result.SizeOfArray("links"))
        loo_Result.I = li_LinkIndex
        if loo_Result.StringOfEquals("links[i].rel","next",1) = 1 then
            li_HasNext = 1
        end if

        li_LinkIndex = li_LinkIndex + 1
    loop
    li_More = li_HasNext
    li_Page = li_Page + 1
loop


destroy loo_Http
destroy loo_Resp
destroy loo_Since
destroy loo_Query
destroy loo_ErrorInfo
destroy loo_Result