Objective-C Requires Chilkat v11.0.0+
Objective-C
PayPal: Find invoices for a recipient
See more PayPal Examples
Filter by a sandbox recipient email address in the JSON body. Pagination belongs in the URL. Read every matching invoice ID; several invoices can share the same recipient.
Chilkat Objective-C Downloads
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.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];
// Use a JSON search body on every page; the recipient email does not belong in the
// URL.
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"recipient_email" value: @"buyer@example.com"];
int page = 1;
int lastPage = 1;
while ((page <= lastPage)) {
CkoStringBuilder *url = [[CkoStringBuilder alloc] init];
[url Append: @"https://api-m.sandbox.paypal.com/v2/invoicing/search-invoices?total_required=true&page_size=20&page="];
[url AppendInt: [NSNumber numberWithInt: page]];
success = [http HttpJson: @"POST" url: [url GetAsString] 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;
}
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;
}
int i = 0;
int count = [[result SizeOfArray: @"items"] intValue];
while ((i < count)) {
result.I = [NSNumber numberWithInt: i];
NSLog(@"%@%@%@%@%@",[result StringOf: @"items[i].id"],@" ",[result StringOf: @"items[i].detail.invoice_number"],@" ",[result StringOf: @"items[i].status"]);
i = i + 1;
}
lastPage = [[result IntOf: @"total_pages"] intValue];
page = page + 1;
}