Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

PayPal: Find successful Express Checkout transactions

See more PayPal Examples

Filter a reporting window by T0006 (Express Checkout) and S (success). The signed amount distinguishes money received from money sent. This is one transaction class, not all merchant sales; reporting access is required.

PayPal documentation

Chilkat Dart Downloads

Dart
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);
  query.updateString('transaction_type', 'T0006');
  query.updateString('transaction_status', 'S');
  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++;
  }
}