Objective-C Requires Chilkat v11.0.0+
Objective-C
PayPal: Look up a checkout order
See more PayPal Examples
Read intent, order status and the amount requested for each purchase unit. A completed checkout order can contain payment resources with their own statuses; use their IDs to inspect individual captures or authorizations.
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];
// Look up the order itself; its ID does not identify an individual capture.
[http SetUrlVar: @"id" value: @"ORDER_ID"];
success = [http HttpNoBody: @"GET" url: @"https://api-m.sandbox.paypal.com/v2/checkout/orders/{$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 parsed = [result Load: resp.BodyStr];
if (parsed != YES) {
NSLog(@"%@%d",@"Expected a JSON response; HTTP ",[resp.StatusCode intValue]);
return;
}
NSLog(@"%@%@",@"ID: ",[result StringOf: @"id"]);
NSLog(@"%@%@",@"Status: ",[result StringOf: @"status"]);
NSLog(@"%@%@",@"Intent: ",[result StringOf: @"intent"]);
int i = 0;
while ((i < [[result SizeOfArray: @"purchase_units"] intValue])) {
result.I = [NSNumber numberWithInt: i];
NSLog(@"%@%@%@%@%@",[result StringOf: @"purchase_units[i].reference_id"],@": ",[result StringOf: @"purchase_units[i].amount.value"],@" ",[result StringOf: @"purchase_units[i].amount.currency_code"]);
i = i + 1;
}