Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
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.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
http: TChilkatHttp;
resp: TChilkatHttpResponse;
errorInfo: TChilkatJsonObject;
result: TChilkatJsonObject;
parsedResult: Integer;
canSubmit: Integer;
linkIndex: Integer;
requested: Integer;
i: Integer;
body: TChilkatJsonObject;
upload: TChilkatHttpRequest;
submitError: TChilkatJsonObject;
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);
http.SetUrlVar('id','DISPUTE_ID');
success := http.HttpNoBody('GET','https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}',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;
canSubmit := 0;
linkIndex := 0;
while (linkIndex < result.SizeOfArray('links')) do
begin
result.I := linkIndex;
if (result.StringOfEquals('links[i].rel','provide_evidence',1) = 1) then
begin
canSubmit := 1;
end;
linkIndex := linkIndex + 1;
end;
requested := 0;
i := 0;
while (i < result.SizeOfArray('evidences')) do
begin
result.I := i;
if ((result.StringOfEquals('evidences[i].evidence_type','PROOF_OF_FULFILLMENT',1) = 1) and (result.StringOfEquals('evidences[i].source','REQUESTED_FROM_SELLER',1) = 1)) then
begin
requested := 1;
end;
i := i + 1;
end;
if ((canSubmit <> 1) or (requested <> 1)) then
begin
Memo1.Lines.Add('PayPal is not requesting seller fulfillment evidence for this case.');
Exit;
end;
body := TChilkatJsonObject.Create(Self);
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 := TChilkatHttpRequest.Create(Self);
upload.HttpVerb := 'POST';
upload.ContentType := 'multipart/form-data';
success := upload.AddStringForUpload2('input','',body.Emit(),'utf-8','application/json');
if (success <> 1) then
begin
Memo1.Lines.Add(upload.LastErrorText);
Exit;
end;
success := upload.AddFileForUpload2('file1','carrier-receipt.pdf','application/pdf');
if (success <> 1) then
begin
Memo1.Lines.Add(upload.LastErrorText);
Exit;
end;
success := http.HttpReq('https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence',upload.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
submitError := TChilkatJsonObject.Create(Self);
submitError.Load(resp.BodyStr);
Memo1.Lines.Add('HTTP ' + IntToStr(resp.StatusCode) + ' ' + submitError.StringOf('name') + ' ' + submitError.StringOf('details[0].issue'));
Memo1.Lines.Add('PayPal debug ID: ' + submitError.StringOf('debug_id'));
Exit;
end;
Memo1.Lines.Add('PayPal accepted the evidence.');