Objective-C Requires Chilkat v11.0.0+
Objective-C
PayPal: Add shipment tracking to a captured order
See more PayPal Examples
Use the order ID in the URL and the capture ID for this shipment in the body. Send the carrier and tracking number from your shipping record. Set notify_payer according to how your business sends shipping notices.
Chilkat Objective-C Downloads
#import <CkoHttp.h>
#import <CkoHttpResponse.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];
// Replace both PayPal IDs and the sample tracking number with values from the same
// shipped order.
[http SetUrlVar: @"id" value: @"ORDER_ID"];
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"capture_id" value: @"CAPTUREID"];
[body UpdateString: @"tracking_number" value: @"1Z999AA10123456784"];
[body UpdateString: @"carrier" value: @"UPS"];
[body UpdateBool: @"notify_payer" value: NO];
success = [http HttpJson: @"POST" url: @"https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}/track" json: body contentType: @"application/json" 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;
}
NSLog(@"%@%d",@"PayPal accepted tracking for this order. HTTP ",[resp.StatusCode intValue]);