Sample code for 30+ languages & platforms
Lazarus Pascal 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 Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.HttpRequest,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  resp: THttpResponse;
  errorInfo: TJsonObject;
  result: TJsonObject;
  parsedResult: Boolean;
  canSubmit: Boolean;
  linkIndex: Integer;
  requested: Boolean;
  i: Integer;
  body: TJsonObject;
  upload: THttpRequest;
  submitError: TJsonObject;

begin
  success := False;

  //  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.
  http := THttp.Create;
  http.AuthToken := 'SANDBOX_ACCESS_TOKEN';
  resp := THttpResponse.Create;

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

  success := http.HttpNoBody('GET','https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}',resp);
  if (success <> True) then
    begin
      WriteLn('No HTTP response: ' + http.LastErrorText);
      Exit;
    end;
  if ((resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
    begin
      errorInfo := TJsonObject.Create;
      errorInfo.Load(resp.BodyStr);
      WriteLn('HTTP ' + resp.StatusCode + ' ' + errorInfo.StringOf('name') + ' ' + errorInfo.StringOf('details[0].issue'));
      WriteLn('PayPal debug ID: ' + errorInfo.StringOf('debug_id'));
      Exit;
    end;

  result := TJsonObject.Create;
  parsedResult := result.Load(resp.BodyStr);
  if (parsedResult <> True) then
    begin
      WriteLn('Expected a JSON response; HTTP ' + resp.StatusCode);
      Exit;
    end;
  canSubmit := False;
  linkIndex := 0;
  while (linkIndex < result.SizeOfArray('links')) do
    begin
      result.I := linkIndex;
      if (result.StringOfEquals('links[i].rel','provide_evidence',True) = True) then
        begin
          canSubmit := True;
        end;
      linkIndex := linkIndex + 1;
    end;

  requested := False;
  i := 0;
  while (i < result.SizeOfArray('evidences')) do
    begin
      result.I := i;
      if ((result.StringOfEquals('evidences[i].evidence_type','PROOF_OF_FULFILLMENT',True) = True) and (result.StringOfEquals('evidences[i].source','REQUESTED_FROM_SELLER',True) = True)) then
        begin
          requested := True;
        end;
      i := i + 1;
    end;

  if ((canSubmit <> True) or (requested <> True)) then
    begin
      WriteLn('PayPal is not requesting seller fulfillment evidence for this case.');
      Exit;
    end;
  body := TJsonObject.Create;
  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.');
  upload := THttpRequest.Create;
  upload.HttpVerb := 'POST';
  upload.ContentType := 'multipart/form-data';
  success := upload.AddStringForUpload2('input','',body.Emit(),'utf-8','application/json');
  if (success <> True) then
    begin
      WriteLn(upload.LastErrorText);
      Exit;
    end;
  success := upload.AddFileForUpload2('file1','carrier-receipt.pdf','application/pdf');
  if (success <> True) then
    begin
      WriteLn(upload.LastErrorText);
      Exit;
    end;
  success := http.HttpReq('https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence',upload,resp);
  if (success <> True) then
    begin
      WriteLn('No HTTP response: ' + http.LastErrorText);
      Exit;
    end;
  if ((resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
    begin
      submitError := TJsonObject.Create;
      submitError.Load(resp.BodyStr);
      WriteLn('HTTP ' + resp.StatusCode + ' ' + submitError.StringOf('name') + ' ' + submitError.StringOf('details[0].issue'));
      WriteLn('PayPal debug ID: ' + submitError.StringOf('debug_id'));
      Exit;
    end;
  WriteLn('PayPal accepted the evidence.');


  http.Free;
  resp.Free;
      errorInfo.Free;
  result.Free;
  body.Free;
  upload.Free;
      submitError.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.