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

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.

PayPal documentation

Chilkat Ruby Downloads

Ruby
require 'chilkat'

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 = Chilkat::CkHttp.new()
http.put_AuthToken("SANDBOX_ACCESS_TOKEN")
resp = Chilkat::CkHttpResponse.new()

http.SetUrlVar("id","DISPUTE_ID")

success = http.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}",resp)
if (success != true)
    print "No HTTP response: " + http.lastErrorText() + "\n";
    exit
end

if ((resp.get_StatusCode() < 200) or (resp.get_StatusCode() >= 300))
    errorInfo = Chilkat::CkJsonObject.new()
    errorInfo.Load(resp.bodyStr())
    print "HTTP " + resp.get_StatusCode().to_s() + " " + errorInfo.stringOf("name") + " " + errorInfo.stringOf("details[0].issue") + "\n";
    print "PayPal debug ID: " + errorInfo.stringOf("debug_id") + "\n";
    exit
end

result = Chilkat::CkJsonObject.new()
parsedResult = result.Load(resp.bodyStr())
if (parsedResult != true)
    print "Expected a JSON response; HTTP " + resp.get_StatusCode().to_s() + "\n";
    exit
end

canSubmit = false
linkIndex = 0
while (linkIndex < result.SizeOfArray("links"))
    result.put_I(linkIndex)
    if (result.StringOfEquals("links[i].rel","provide_evidence",true) == true)
        canSubmit = true
    end

    linkIndex = linkIndex + 1
end
requested = false
i = 0
while (i < result.SizeOfArray("evidences"))
    result.put_I(i)
    if ((result.StringOfEquals("evidences[i].evidence_type","PROOF_OF_FULFILLMENT",true) == true) and (result.StringOfEquals("evidences[i].source","REQUESTED_FROM_SELLER",true) == true))
        requested = true
    end

    i = i + 1
end
if ((canSubmit != true) or (requested != true))
    print "PayPal is not requesting seller fulfillment evidence for this case." + "\n";
    exit
end

body = Chilkat::CkJsonObject.new()
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 = Chilkat::CkHttpRequest.new()
upload.put_HttpVerb("POST")
upload.put_ContentType("multipart/form-data")
success = upload.AddStringForUpload2("input","",body.emit(),"utf-8","application/json")
if (success != true)
    print upload.lastErrorText() + "\n";
    exit
end

success = upload.AddFileForUpload2("file1","carrier-receipt.pdf","application/pdf")
if (success != true)
    print upload.lastErrorText() + "\n";
    exit
end

success = http.HttpReq("https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence",upload,resp)
if (success != true)
    print "No HTTP response: " + http.lastErrorText() + "\n";
    exit
end

if ((resp.get_StatusCode() < 200) or (resp.get_StatusCode() >= 300))
    submitError = Chilkat::CkJsonObject.new()
    submitError.Load(resp.bodyStr())
    print "HTTP " + resp.get_StatusCode().to_s() + " " + submitError.stringOf("name") + " " + submitError.stringOf("details[0].issue") + "\n";
    print "PayPal debug ID: " + submitError.stringOf("debug_id") + "\n";
    exit
end

print "PayPal accepted the evidence." + "\n";