Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
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 Delphi ActiveX Downloads
var
success: Integer;
http: TChilkatHttp;
resp: TChilkatHttpResponse;
since: TCkDateTime;
query: TChilkatJsonObject;
page: Integer;
more: Integer;
errorInfo: TChilkatJsonObject;
result: TChilkatJsonObject;
parsedResult: Integer;
i: Integer;
hasNext: Integer;
linkIndex: Integer;
begin
success := 0;
// 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 := TChilkatHttp.Create(Self);
http.AuthToken := 'SANDBOX_ACCESS_TOKEN';
resp := TChilkatHttpResponse.Create(Self);
since := TCkDateTime.Create(Self);
since.SetFromCurrentSystemTime();
since.AddDays(-30);
query := TChilkatJsonObject.Create(Self);
query.UpdateString('update_time_after',since.GetAsTimestamp(0));
query.UpdateInt('page_size',50);
page := 1;
more := 1;
while (more = 1) do
begin
query.UpdateInt('page',page);
success := http.HttpParams('GET','https://api-m.sandbox.paypal.com/v1/customer/disputes',query.ControlInterface,resp.ControlInterface);
if (success <> 1) then
begin
Memo1.Lines.Add('No HTTP response: ' + http.LastErrorText);
Exit;
end;
if ((resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
begin
errorInfo := TChilkatJsonObject.Create(Self);
errorInfo.Load(resp.BodyStr);
Memo1.Lines.Add('HTTP ' + IntToStr(resp.StatusCode) + ' ' + errorInfo.StringOf('name') + ' ' + errorInfo.StringOf('details[0].issue'));
Memo1.Lines.Add('PayPal debug ID: ' + errorInfo.StringOf('debug_id'));
Exit;
end;
result := TChilkatJsonObject.Create(Self);
parsedResult := result.Load(resp.BodyStr);
if (parsedResult <> 1) then
begin
Memo1.Lines.Add('Expected a JSON response; HTTP ' + IntToStr(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',1) = 1) then
begin
Memo1.Lines.Add(result.StringOf('items[i].dispute_id') + ' ' + result.StringOf('items[i].reason'));
if (result.HasMember('items[i].seller_response_due_date') = 1) then
begin
Memo1.Lines.Add('Respond by ' + result.StringOf('items[i].seller_response_due_date'));
end;
end;
i := i + 1;
end;
hasNext := 0;
linkIndex := 0;
while (linkIndex < result.SizeOfArray('links')) do
begin
result.I := linkIndex;
if (result.StringOfEquals('links[i].rel','next',1) = 1) then
begin
hasNext := 1;
end;
linkIndex := linkIndex + 1;
end;
more := hasNext;
page := page + 1;
end;