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

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.

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.HttpResponse,
  Chilkat.CkDateTime,
  Chilkat.JsonObject;

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

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  resp: THttpResponse;
  since: TCkDateTime;
  query: TJsonObject;
  page: Integer;
  more: Boolean;
  errorInfo: TJsonObject;
  result: TJsonObject;
  parsedResult: Boolean;
  i: Integer;
  hasNext: Boolean;
  linkIndex: Integer;

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;
  since := TCkDateTime.Create;
  since.SetFromCurrentSystemTime();
  since.AddDays(-30);
  query := TJsonObject.Create;
  query.UpdateString('update_time_after',since.GetAsTimestamp(False));
  query.UpdateInt('page_size',50);
  page := 1;
  more := True;
  while (more = True) do
    begin
      query.UpdateInt('page',page);
      success := http.HttpParams('GET','https://api-m.sandbox.paypal.com/v1/customer/disputes',query,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;
      i := 0;
      while (i < result.SizeOfArray('items')) do
        begin
          result.I := i;
          if (result.StringOfEquals('items[i].status','WAITING_FOR_SELLER_RESPONSE',True) = True) then
            begin
              WriteLn(result.StringOf('items[i].dispute_id') + '  ' + result.StringOf('items[i].reason'));
              if (result.HasMember('items[i].seller_response_due_date') = True) then
                begin
                  WriteLn('Respond by ' + result.StringOf('items[i].seller_response_due_date'));
                end;
            end;
          i := i + 1;
        end;

      hasNext := False;
      linkIndex := 0;
      while (linkIndex < result.SizeOfArray('links')) do
        begin
          result.I := linkIndex;
          if (result.StringOfEquals('links[i].rel','next',True) = True) then
            begin
              hasNext := True;
            end;
          linkIndex := linkIndex + 1;
        end;

      more := hasNext;
      page := page + 1;
    end;



  http.Free;
  resp.Free;
  since.Free;
  query.Free;
          errorInfo.Free;
      result.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.