Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

PayPal: Submit proof of fulfillment for a dispute

See more PayPal Examples

Inspect the actions and evidence requested for a selected dispute. When PayPal requests proof of fulfillment from the seller, attach the matching carrier receipt PDF with tracking details in a multipart request. Replace the file and tracking number with those for this case.

PayPal documentation

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoJsonObject.h>
#import <CkoHttpRequest.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];

[http SetUrlVar: @"id" value: @"DISPUTE_ID"];

success = [http HttpNoBody: @"GET" url: @"https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}" 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;
}

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

    linkIndex = linkIndex + 1;
}

BOOL requested = NO;
int i = 0;
while ((i < [[result SizeOfArray: @"evidences"] intValue])) {
    result.I = [NSNumber numberWithInt: i];
    if (([result StringOfEquals: @"evidences[i].evidence_type" value: @"PROOF_OF_FULFILLMENT" caseSensitive: YES] == YES) && ([result StringOfEquals: @"evidences[i].source" value: @"REQUESTED_FROM_SELLER" caseSensitive: YES] == YES)) {
        requested = YES;
    }

    i = i + 1;
}

if ((canSubmit != YES) || (requested != YES)) {
    NSLog(@"%@",@"PayPal is not requesting seller fulfillment evidence for this case.");
    return;
}

CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"evidences[0].evidence_type" value: @"PROOF_OF_FULFILLMENT"];
[body UpdateString: @"evidences[0].evidence_info.tracking_info[0].carrier_name" value: @"FEDEX"];
[body UpdateString: @"evidences[0].evidence_info.tracking_info[0].tracking_number" value: @"123456789012"];
[body UpdateString: @"evidences[0].notes" value: @"The attached carrier receipt corresponds to this shipment."];
CkoHttpRequest *upload = [[CkoHttpRequest alloc] init];
upload.HttpVerb = @"POST";
upload.ContentType = @"multipart/form-data";
success = [upload AddStringForUpload2: @"input" filename: @"" strData: [body Emit] charset: @"utf-8" contentType: @"application/json"];
if (success != YES) {
    NSLog(@"%@",upload.LastErrorText);
    return;
}

success = [upload AddFileForUpload2: @"file1" path: @"carrier-receipt.pdf" contentType: @"application/pdf"];
if (success != YES) {
    NSLog(@"%@",upload.LastErrorText);
    return;
}

success = [http HttpReq: @"https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence" request: upload response: resp];
if (success != YES) {
    NSLog(@"%@%@",@"No HTTP response: ",http.LastErrorText);
    return;
}

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

NSLog(@"%@",@"PayPal accepted the evidence.");