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

Swift

func chilkatTest() {
    var success: Bool = false

    //  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.
    let http = CkoHttp()!
    http.authToken = "SANDBOX_ACCESS_TOKEN"
    let resp = CkoHttpResponse()!
    let since = CkoDateTime()!
    since.setFromCurrentSystemTime()
    since.addDays(numDays: -30)
    let query = CkoJsonObject()!
    query.updateString(jsonPath: "update_time_after", value: since.get(asTimestamp: false))
    query.updateInt(jsonPath: "page_size", value: 50)
    var page: Int = 1
    var more: Bool = true
    while (more == true) {
        query.updateInt(jsonPath: "page", value: page)
        success = http.httpParams(verb: "GET", url: "https://api-m.sandbox.paypal.com/v1/customer/disputes", json: query, response: resp)
        if success != true {
            print("No HTTP response: \(http.lastErrorText!)")
            return
        }

        if (resp.statusCode.intValue < 200) || (resp.statusCode.intValue >= 300) {
            let errorInfo = CkoJsonObject()!
            errorInfo.load(json: resp.bodyStr)
            print("HTTP \(resp.statusCode.intValue) \(errorInfo.string(of: "name")!) \(errorInfo.string(of: "details[0].issue")!)")
            print("PayPal debug ID: \(errorInfo.string(of: "debug_id")!)")
            return
        }

        let result = CkoJsonObject()!
        var parsedResult: Bool = result.load(json: resp.bodyStr)
        if parsedResult != true {
            print("Expected a JSON response; HTTP \(resp.statusCode.intValue)")
            return
        }

        var i: Int = 0
        while (i < result.size(ofArray: "items").intValue) {
            result.i = i
            if result.string(ofEquals: "items[i].status", value: "WAITING_FOR_SELLER_RESPONSE", caseSensitive: true) == true {
                print("\(result.string(of: "items[i].dispute_id")!)  \(result.string(of: "items[i].reason")!)")
                if result.hasMember(jsonPath: "items[i].seller_response_due_date") == true {
                    print("Respond by \(result.string(of: "items[i].seller_response_due_date")!)")
                }

            }

            i = i + 1
        }

        var hasNext: Bool = false
        var linkIndex: Int = 0
        while (linkIndex < result.size(ofArray: "links").intValue) {
            result.i = linkIndex
            if result.string(ofEquals: "links[i].rel", value: "next", caseSensitive: true) == true {
                hasNext = true
            }

            linkIndex = linkIndex + 1
        }

        more = hasNext
        page = page + 1
    }


}