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

Objective-C
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoDateTime.h>
#import <CkoJsonObject.h>

BOOL success = NO;

//  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.
CkoHttp *http = [[CkoHttp alloc] init];
http.AuthToken = @"SANDBOX_ACCESS_TOKEN";
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
CkoDateTime *since = [[CkoDateTime alloc] init];
[since SetFromCurrentSystemTime];
[since AddDays: [NSNumber numberWithInt: -30]];
CkoJsonObject *query = [[CkoJsonObject alloc] init];
[query UpdateString: @"update_time_after" value: [since GetAsTimestamp: NO]];
[query UpdateInt: @"page_size" value: [NSNumber numberWithInt: 50]];
int page = 1;
BOOL more = YES;
while ((more == YES)) {
    [query UpdateInt: @"page" value: [NSNumber numberWithInt: page]];
    success = [http HttpParams: @"GET" url: @"https://api-m.sandbox.paypal.com/v1/customer/disputes" json: query response: resp];
    if (success != YES) {
        NSLog(@"%@%@",@"No HTTP response: ",http.LastErrorText);
        return;
    }

    if (([resp.StatusCode intValue] < 200) || ([resp.StatusCode intValue] >= 300)) {
        CkoJsonObject *errorInfo = [[CkoJsonObject alloc] init];
        [errorInfo Load: resp.BodyStr];
        NSLog(@"%@%d%@%@%@%@",@"HTTP ",[resp.StatusCode intValue],@" ",[errorInfo StringOf: @"name"],@" ",[errorInfo StringOf: @"details[0].issue"]);
        NSLog(@"%@%@",@"PayPal debug ID: ",[errorInfo StringOf: @"debug_id"]);
        return;
    }

    CkoJsonObject *result = [[CkoJsonObject alloc] init];
    BOOL parsedResult = [result Load: resp.BodyStr];
    if (parsedResult != YES) {
        NSLog(@"%@%d",@"Expected a JSON response; HTTP ",[resp.StatusCode intValue]);
        return;
    }

    int i = 0;
    while ((i < [[result SizeOfArray: @"items"] intValue])) {
        result.I = [NSNumber numberWithInt: i];
        if ([result StringOfEquals: @"items[i].status" value: @"WAITING_FOR_SELLER_RESPONSE" caseSensitive: YES] == YES) {
            NSLog(@"%@%@%@",[result StringOf: @"items[i].dispute_id"],@"  ",[result StringOf: @"items[i].reason"]);
            if ([result HasMember: @"items[i].seller_response_due_date"] == YES) {
                NSLog(@"%@%@",@"Respond by ",[result StringOf: @"items[i].seller_response_due_date"]);
            }

        }

        i = i + 1;
    }

    BOOL hasNext = NO;
    int linkIndex = 0;
    while ((linkIndex < [[result SizeOfArray: @"links"] intValue])) {
        result.I = [NSNumber numberWithInt: linkIndex];
        if ([result StringOfEquals: @"links[i].rel" value: @"next" caseSensitive: YES] == YES) {
            hasNext = YES;
        }

        linkIndex = linkIndex + 1;
    }

    more = hasNext;
    page = page + 1;
}