Dart Requires Chilkat v11.0.0+
Dart
PayPal: Page through merchant transactions
See more PayPal Examples
Read yesterday-to-now account activity one page at a time. Enable Transaction Search for the REST app and obtain a token with reporting access. Data can lag by up to three hours; use order or capture lookup for a checkout in progress.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// 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.
final http = CkHttp();
http.authToken = 'SANDBOX_ACCESS_TOKEN';
final resp = CkHttpResponse();
// Use the UTC window containing the transaction (at most 31 days per request).
final dt = CkDateTime();
dt.setFromCurrentSystemTime();
final query = CkJsonObject();
query.updateString('end_date', dt.getAsTimestamp(false));
dt.addDays(-1);
query.updateString('start_date', dt.getAsTimestamp(false));
query.updateString('fields', 'transaction_info');
query.updateInt('page_size', 100);
var page = 1;
var lastPage = 1;
while (page <= lastPage) {
query.updateInt('page', page);
try {
http.httpParams('GET', 'https://api-m.sandbox.paypal.com/v1/reporting/transactions', query, resp);
} on ChilkatException catch (e) {
print('No HTTP response: ${e.lastErrorText}');
return;
}
if ((resp.statusCode < 200) || (resp.statusCode >= 300)) {
final errorInfo = CkJsonObject();
errorInfo.load(resp.bodyStr);
print('HTTP ${resp.statusCode} ${errorInfo.stringOf('name')} ${errorInfo.stringOf('details[0].issue')}');
print('PayPal debug ID: ${errorInfo.stringOf('debug_id')}');
return;
}
final result = CkJsonObject();
try {
result.load(resp.bodyStr);
} on ChilkatException {
print('Expected a JSON response; HTTP ${resp.statusCode}');
return;
}
var i = 0;
final count = result.sizeOfArray('transaction_details');
while (i < count) {
result.i = i;
print('${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')}');
print(' ${result.stringOf('transaction_details[i].transaction_info.transaction_amount.value')} ${result.stringOf('transaction_details[i].transaction_info.transaction_amount.currency_code')}');
i++;
}
lastPage = result.intOf('total_pages');
page++;
}
}