Objective-C Requires Chilkat v11.0.0+
Objective-C
PayPal: Reconcile a transaction ID in a reporting window
See more PayPal Examples
Supply the reporting transaction ID and a window containing the activity. Return all matches: transaction IDs are not necessarily unique in the report. Include non-balance-affecting records when reconciling an event.
Chilkat Objective-C Downloads
#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];
// Use the UTC window containing the transaction (at most 31 days per request).
CkoDateTime *dt = [[CkoDateTime alloc] init];
[dt SetFromCurrentSystemTime];
CkoJsonObject *query = [[CkoJsonObject alloc] init];
[query UpdateString: @"end_date" value: [dt GetAsTimestamp: NO]];
[dt AddDays: [NSNumber numberWithInt: -1]];
[query UpdateString: @"start_date" value: [dt GetAsTimestamp: NO]];
[query UpdateString: @"fields" value: @"transaction_info"];
[query UpdateInt: @"page_size" value: [NSNumber numberWithInt: 100]];
[query UpdateString: @"transaction_id" value: @"REPORT_TRANSACTION_ID"];
[query UpdateString: @"balance_affecting_records_only" value: @"N"];
int page = 1;
int lastPage = 1;
while ((page <= lastPage)) {
[query UpdateInt: @"page" value: [NSNumber numberWithInt: page]];
success = [http HttpParams: @"GET" url: @"https://api-m.sandbox.paypal.com/v1/reporting/transactions" 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 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: @"transaction_details"] intValue];
while ((i < count)) {
result.I = [NSNumber numberWithInt: i];
NSLog(@"%@%@%@%@%@",[result StringOf: @"transaction_details[i].transaction_info.transaction_id"],@" ",[result StringOf: @"transaction_details[i].transaction_info.transaction_event_code"]
,@" ",[result StringOf: @"transaction_details[i].transaction_info.transaction_status"]);
NSLog(@"%@%@%@%@",@" ",[result StringOf: @"transaction_details[i].transaction_info.transaction_amount.value"],@" ",[result StringOf: @"transaction_details[i].transaction_info.transaction_amount.currency_code"]);
i = i + 1;
}
lastPage = [[result IntOf: @"total_pages"] intValue];
page = page + 1;
}