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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vResp
    Handle hoResp
    Handle hoSince
    Variant vQuery
    Handle hoQuery
    Integer iPage
    Boolean iMore
    Handle hoErrorInfo
    Handle hoResult
    Boolean iParsedResult
    Integer i
    Boolean iHasNext
    Integer iLinkIndex
    String sTemp1
    String sTemp2
    Integer iTemp1
    Integer iTemp2
    Boolean bTemp1

    Move False To iSuccess

    //  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.
    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Set ComAuthToken Of hoHttp To "SANDBOX_ACCESS_TOKEN"
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get Create (RefClass(cComCkDateTime)) To hoSince
    If (Not(IsComObjectCreated(hoSince))) Begin
        Send CreateComObject of hoSince
    End
    Get ComSetFromCurrentSystemTime Of hoSince To iSuccess
    Get ComAddDays Of hoSince -30 To iSuccess
    Get Create (RefClass(cComChilkatJsonObject)) To hoQuery
    If (Not(IsComObjectCreated(hoQuery))) Begin
        Send CreateComObject of hoQuery
    End
    Get ComGetAsTimestamp Of hoSince False To sTemp1
    Get ComUpdateString Of hoQuery "update_time_after" sTemp1 To iSuccess
    Get ComUpdateInt Of hoQuery "page_size" 50 To iSuccess
    Move 1 To iPage
    Move True To iMore
    While (iMore = True)
        Get ComUpdateInt Of hoQuery "page" iPage To iSuccess
        Get pvComObject of hoQuery to vQuery
        Get pvComObject of hoResp to vResp
        Get ComHttpParams Of hoHttp "GET" "https://api-m.sandbox.paypal.com/v1/customer/disputes" vQuery vResp To iSuccess
        If (iSuccess <> True) Begin
            Get ComLastErrorText Of hoHttp To sTemp1
            Showln "No HTTP response: " sTemp1
            Procedure_Return
        End

        Get ComStatusCode Of hoResp To iTemp1
        Get ComStatusCode Of hoResp To iTemp2
        If ((iTemp1 < 200) Or (iTemp2 >= 300)) Begin
            Get Create (RefClass(cComChilkatJsonObject)) To hoErrorInfo
            If (Not(IsComObjectCreated(hoErrorInfo))) Begin
                Send CreateComObject of hoErrorInfo
            End
            Get ComBodyStr Of hoResp To sTemp1
            Get ComLoad Of hoErrorInfo sTemp1 To iSuccess
            Get ComStatusCode Of hoResp To iTemp1
            Get ComStringOf Of hoErrorInfo "name" To sTemp1
            Get ComStringOf Of hoErrorInfo "details[0].issue" To sTemp2
            Showln "HTTP " iTemp1 " " sTemp1 " " sTemp2
            Get ComStringOf Of hoErrorInfo "debug_id" To sTemp1
            Showln "PayPal debug ID: " sTemp1
            Procedure_Return
        End

        Get Create (RefClass(cComChilkatJsonObject)) To hoResult
        If (Not(IsComObjectCreated(hoResult))) Begin
            Send CreateComObject of hoResult
        End
        Get ComBodyStr Of hoResp To sTemp1
        Get ComLoad Of hoResult sTemp1 To iParsedResult
        If (iParsedResult <> True) Begin
            Get ComStatusCode Of hoResp To iTemp1
            Showln "Expected a JSON response; HTTP " iTemp1
            Procedure_Return
        End

        Move 0 To i
        While (i < (ComSizeOfArray(hoResult, "items")))
            Set ComI Of hoResult To i
            Get ComStringOfEquals Of hoResult "items[i].status" "WAITING_FOR_SELLER_RESPONSE" True To bTemp1
            If (bTemp1 = True) Begin
                Get ComStringOf Of hoResult "items[i].dispute_id" To sTemp1
                Get ComStringOf Of hoResult "items[i].reason" To sTemp2
                Showln sTemp1 "  " sTemp2
                Get ComHasMember Of hoResult "items[i].seller_response_due_date" To bTemp1
                If (bTemp1 = True) Begin
                    Get ComStringOf Of hoResult "items[i].seller_response_due_date" To sTemp1
                    Showln "Respond by " sTemp1
                End

            End

            Move (i + 1) To i
        Loop

        Move False To iHasNext
        Move 0 To iLinkIndex
        While (iLinkIndex < (ComSizeOfArray(hoResult, "links")))
            Set ComI Of hoResult To iLinkIndex
            Get ComStringOfEquals Of hoResult "links[i].rel" "next" True To bTemp1
            If (bTemp1 = True) Begin
                Move True To iHasNext
            End

            Move (iLinkIndex + 1) To iLinkIndex
        Loop

        Move iHasNext To iMore
        Move (iPage + 1) To iPage
    Loop



End_Procedure