Dart Requires Chilkat v11.0.0+
Dart
PayPal: Find disputes awaiting a seller response
See more PayPal Examples
Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.
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();
final since = CkDateTime();
since.setFromCurrentSystemTime();
since.addDays(-30);
final query = CkJsonObject();
query.updateString('update_time_after', since.getAsTimestamp(false));
query.updateInt('page_size', 50);
var page = 1;
var more = true;
while (more) {
query.updateInt('page', page);
try {
http.httpParams('GET', 'https://api-m.sandbox.paypal.com/v1/customer/disputes', 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;
while (i < result.sizeOfArray('items')) {
result.i = i;
if (result.stringOfEquals('items[i].status', 'WAITING_FOR_SELLER_RESPONSE', true)) {
print('${result.stringOf('items[i].dispute_id')} ${result.stringOf('items[i].reason')}');
if (result.hasMember('items[i].seller_response_due_date')) {
print('Respond by ${result.stringOf('items[i].seller_response_due_date')}');
}
}
i++;
}
var hasNext = false;
var linkIndex = 0;
while (linkIndex < result.sizeOfArray('links')) {
result.i = linkIndex;
if (result.stringOfEquals('links[i].rel', 'next', true)) {
hasNext = true;
}
linkIndex++;
}
more = hasNext;
page++;
}
}