PHP ActiveX Requires Chilkat v11.0.0+
PHP 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 PHP ActiveX Downloads
<?php
$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 = new COM("Chilkat.Http");
$http->AuthToken = 'SANDBOX_ACCESS_TOKEN';
$resp = new COM("Chilkat.HttpResponse");
$http->SetUrlVar('id','DISPUTE_ID');
$success = $http->HttpNoBody('GET','https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}',$resp);
if ($success != 1) {
print 'No HTTP response: ' . $http->LastErrorText . "\n";
exit;
}
if (($resp->StatusCode < 200) or ($resp->StatusCode >= 300)) {
$errorInfo = new COM("Chilkat.JsonObject");
$errorInfo->Load($resp->BodyStr);
print 'HTTP ' . $resp->StatusCode . ' ' . $errorInfo->stringOf('name') . ' ' . $errorInfo->stringOf('details[0].issue') . "\n";
print 'PayPal debug ID: ' . $errorInfo->stringOf('debug_id') . "\n";
exit;
}
$result = new COM("Chilkat.JsonObject");
$parsedResult = $result->Load($resp->BodyStr);
if ($parsedResult != 1) {
print 'Expected a JSON response; HTTP ' . $resp->StatusCode . "\n";
exit;
}
$canSubmit = 0;
$linkIndex = 0;
while (($linkIndex < $result->SizeOfArray('links'))) {
$result->I = $linkIndex;
if ($result->StringOfEquals('links[i].rel','provide_evidence',1) == 1) {
$canSubmit = 1;
}
$linkIndex = $linkIndex + 1;
}
$requested = 0;
$i = 0;
while (($i < $result->SizeOfArray('evidences'))) {
$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)) {
$requested = 1;
}
$i = $i + 1;
}
if (($canSubmit != 1) or ($requested != 1)) {
print 'PayPal is not requesting seller fulfillment evidence for this case.' . "\n";
exit;
}
$body = new COM("Chilkat.JsonObject");
$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 = new COM("Chilkat.HttpRequest");
$upload->HttpVerb = 'POST';
$upload->ContentType = 'multipart/form-data';
$success = $upload->AddStringForUpload2('input','',$body->emit(),'utf-8','application/json');
if ($success != 1) {
print $upload->LastErrorText . "\n";
exit;
}
$success = $upload->AddFileForUpload2('file1','carrier-receipt.pdf','application/pdf');
if ($success != 1) {
print $upload->LastErrorText . "\n";
exit;
}
$success = $http->HttpReq('https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence',$upload,$resp);
if ($success != 1) {
print 'No HTTP response: ' . $http->LastErrorText . "\n";
exit;
}
if (($resp->StatusCode < 200) or ($resp->StatusCode >= 300)) {
$submitError = new COM("Chilkat.JsonObject");
$submitError->Load($resp->BodyStr);
print 'HTTP ' . $resp->StatusCode . ' ' . $submitError->stringOf('name') . ' ' . $submitError->stringOf('details[0].issue') . "\n";
print 'PayPal debug ID: ' . $submitError->stringOf('debug_id') . "\n";
exit;
}
print 'PayPal accepted the evidence.' . "\n";
?>