Delphi DLL Requires Chilkat v11.0.0+
Delphi DLL
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 DLL Downloads
var
success: Boolean;
http: HCkHttp;
resp: HCkHttpResponse;
errorInfo: HCkJsonObject;
result: HCkJsonObject;
parsedResult: Boolean;
canSubmit: Boolean;
linkIndex: Integer;
requested: Boolean;
i: Integer;
body: HCkJsonObject;
upload: HCkHttpRequest;
submitError: HCkJsonObject;
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 := CkHttp_Create();
CkHttp_putAuthToken(http,'SANDBOX_ACCESS_TOKEN');
resp := CkHttpResponse_Create();
CkHttp_SetUrlVar(http,'id','DISPUTE_ID');
success := CkHttp_HttpNoBody(http,'GET','https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}',resp);
if (success <> True) then
begin
Memo1.Lines.Add('No HTTP response: ' + CkHttp__lastErrorText(http));
Exit;
end;
if ((CkHttpResponse_getStatusCode(resp) < 200) or (CkHttpResponse_getStatusCode(resp) >= 300)) then
begin
errorInfo := CkJsonObject_Create();
CkJsonObject_Load(errorInfo,CkHttpResponse__bodyStr(resp));
Memo1.Lines.Add('HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)) + ' ' + CkJsonObject__stringOf(errorInfo,'name') + ' ' + CkJsonObject__stringOf(errorInfo,'details[0].issue'));
Memo1.Lines.Add('PayPal debug ID: ' + CkJsonObject__stringOf(errorInfo,'debug_id'));
Exit;
end;
result := CkJsonObject_Create();
parsedResult := CkJsonObject_Load(result,CkHttpResponse__bodyStr(resp));
if (parsedResult <> True) then
begin
Memo1.Lines.Add('Expected a JSON response; HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
Exit;
end;
canSubmit := False;
linkIndex := 0;
while (linkIndex < CkJsonObject_SizeOfArray(result,'links')) do
begin
CkJsonObject_putI(result,linkIndex);
if (CkJsonObject_StringOfEquals(result,'links[i].rel','provide_evidence',True) = True) then
begin
canSubmit := True;
end;
linkIndex := linkIndex + 1;
end;
requested := False;
i := 0;
while (i < CkJsonObject_SizeOfArray(result,'evidences')) do
begin
CkJsonObject_putI(result,i);
if ((CkJsonObject_StringOfEquals(result,'evidences[i].evidence_type','PROOF_OF_FULFILLMENT',True) = True) and (CkJsonObject_StringOfEquals(result,'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
Memo1.Lines.Add('PayPal is not requesting seller fulfillment evidence for this case.');
Exit;
end;
body := CkJsonObject_Create();
CkJsonObject_UpdateString(body,'evidences[0].evidence_type','PROOF_OF_FULFILLMENT');
CkJsonObject_UpdateString(body,'evidences[0].evidence_info.tracking_info[0].carrier_name','FEDEX');
CkJsonObject_UpdateString(body,'evidences[0].evidence_info.tracking_info[0].tracking_number','123456789012');
CkJsonObject_UpdateString(body,'evidences[0].notes','The attached carrier receipt corresponds to this shipment.');
upload := CkHttpRequest_Create();
CkHttpRequest_putHttpVerb(upload,'POST');
CkHttpRequest_putContentType(upload,'multipart/form-data');
success := CkHttpRequest_AddStringForUpload2(upload,'input','',CkJsonObject__emit(body),'utf-8','application/json');
if (success <> True) then
begin
Memo1.Lines.Add(CkHttpRequest__lastErrorText(upload));
Exit;
end;
success := CkHttpRequest_AddFileForUpload2(upload,'file1','carrier-receipt.pdf','application/pdf');
if (success <> True) then
begin
Memo1.Lines.Add(CkHttpRequest__lastErrorText(upload));
Exit;
end;
success := CkHttp_HttpReq(http,'https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence',upload,resp);
if (success <> True) then
begin
Memo1.Lines.Add('No HTTP response: ' + CkHttp__lastErrorText(http));
Exit;
end;
if ((CkHttpResponse_getStatusCode(resp) < 200) or (CkHttpResponse_getStatusCode(resp) >= 300)) then
begin
submitError := CkJsonObject_Create();
CkJsonObject_Load(submitError,CkHttpResponse__bodyStr(resp));
Memo1.Lines.Add('HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)) + ' ' + CkJsonObject__stringOf(submitError,'name') + ' ' + CkJsonObject__stringOf(submitError,'details[0].issue'));
Memo1.Lines.Add('PayPal debug ID: ' + CkJsonObject__stringOf(submitError,'debug_id'));
Exit;
end;
Memo1.Lines.Add('PayPal accepted the evidence.');
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(errorInfo);
CkJsonObject_Dispose(result);
CkJsonObject_Dispose(body);
CkHttpRequest_Dispose(upload);
CkJsonObject_Dispose(submitError);