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

PayPal: Submit proof of fulfillment for a dispute

See more PayPal Examples

Inspect the actions and evidence requested for a selected dispute. When PayPal requests proof of fulfillment from the seller, attach the matching carrier receipt PDF with tracking details in a multipart request. Replace the file and tracking number with those for this case.

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();

  http.setUrlVar('id', 'DISPUTE_ID');

  try {
    http.httpNoBody('GET', 'https://api-m.sandbox.paypal.com/v1/customer/disputes/{\$id}', 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 canSubmit = false;
  var linkIndex = 0;
  while (linkIndex < result.sizeOfArray('links')) {
    result.i = linkIndex;
    if (result.stringOfEquals('links[i].rel', 'provide_evidence', true)) {
      canSubmit = true;
    }

    linkIndex++;
  }

  var requested = false;
  var i = 0;
  while (i < result.sizeOfArray('evidences')) {
    result.i = i;
    if ((result.stringOfEquals('evidences[i].evidence_type', 'PROOF_OF_FULFILLMENT', true)) && (result.stringOfEquals('evidences[i].source', 'REQUESTED_FROM_SELLER', true))) {
      requested = true;
    }

    i++;
  }

  if ((!canSubmit) || (!requested)) {
    print('PayPal is not requesting seller fulfillment evidence for this case.');
    return;
  }

  final body = CkJsonObject();
  body.updateString('evidences[0].evidence_type', 'PROOF_OF_FULFILLMENT');
  body.updateString('evidences[0].evidence_info.tracking_info[0].carrier_name', 'FEDEX');
  body.updateString('evidences[0].evidence_info.tracking_info[0].tracking_number', '123456789012');
  body.updateString('evidences[0].notes', 'The attached carrier receipt corresponds to this shipment.');
  final upload = CkHttpRequest();
  upload.httpVerb = 'POST';
  upload.contentType = 'multipart/form-data';
  try {
    upload.addStringForUpload2('input', '', body.emit(), 'utf-8', 'application/json');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    upload.addFileForUpload2('file1', 'carrier-receipt.pdf', 'application/pdf');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    http.httpReq('https://api-m.sandbox.paypal.com/v1/customer/disputes/{\$id}/provide-evidence', upload, resp);
  } on ChilkatException catch (e) {
    print('No HTTP response: ${e.lastErrorText}');
    return;
  }

  if ((resp.statusCode < 200) || (resp.statusCode >= 300)) {
    final submitError = CkJsonObject();
    submitError.load(resp.bodyStr);
    print('HTTP ${resp.statusCode} ${submitError.stringOf('name')} ${submitError.stringOf('details[0].issue')}');
    print('PayPal debug ID: ${submitError.stringOf('debug_id')}');
    return;
  }

  print('PayPal accepted the evidence.');
}