Lua Requires Chilkat v11.0.0+
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- 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.
local http = chilkat.Http.new()
http.auth_token = "SANDBOX_ACCESS_TOKEN"
local resp = chilkat.HttpResponse.new()
http:set_url_var("id", "DISPUTE_ID")
local success = http:http_no_body("GET", "https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}", resp)
if not success then
print("No HTTP response: " .. http.last_error_text)
return
end
if (resp.status_code < 200) or (resp.status_code >= 300) then
local errorInfo = chilkat.JsonObject.new()
errorInfo:load(resp.body_str)
print("HTTP " .. resp.status_code .. " " .. errorInfo:string_of("name") .. " " .. errorInfo:string_of("details[0].issue"))
print("PayPal debug ID: " .. errorInfo:string_of("debug_id"))
return
end
local result = chilkat.JsonObject.new()
local parsedResult = result:load(resp.body_str)
if not parsedResult then
print("Expected a JSON response; HTTP " .. resp.status_code)
return
end
local canSubmit = false
local linkIndex = 0
while linkIndex < result:size_of_array("links") do
result.i = linkIndex
if result:string_of_equals("links[i].rel", "provide_evidence", true) then
canSubmit = true
end
linkIndex = linkIndex + 1
end
local requested = false
local i = 0
while i < result:size_of_array("evidences") do
result.i = i
if (result:string_of_equals("evidences[i].evidence_type", "PROOF_OF_FULFILLMENT", true)) and (result:string_of_equals("evidences[i].source", "REQUESTED_FROM_SELLER", true)) then
requested = true
end
i = i + 1
end
if (not canSubmit) or (not requested) then
print("PayPal is not requesting seller fulfillment evidence for this case.")
return
end
local body = chilkat.JsonObject.new()
body:update_string("evidences[0].evidence_type", "PROOF_OF_FULFILLMENT")
body:update_string("evidences[0].evidence_info.tracking_info[0].carrier_name", "FEDEX")
body:update_string("evidences[0].evidence_info.tracking_info[0].tracking_number", "123456789012")
body:update_string("evidences[0].notes", "The attached carrier receipt corresponds to this shipment.")
local upload = chilkat.HttpRequest.new()
upload.http_verb = "POST"
upload.content_type = "multipart/form-data"
success = upload:add_string_for_upload2("input", "", body:emit(), "utf-8", "application/json")
if not success then
print(upload.last_error_text)
return
end
success = upload:add_file_for_upload2("file1", "carrier-receipt.pdf", "application/pdf")
if not success then
print(upload.last_error_text)
return
end
success = http:http_req("https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence", upload, resp)
if not success then
print("No HTTP response: " .. http.last_error_text)
return
end
if (resp.status_code < 200) or (resp.status_code >= 300) then
local submitError = chilkat.JsonObject.new()
submitError:load(resp.body_str)
print("HTTP " .. resp.status_code .. " " .. submitError:string_of("name") .. " " .. submitError:string_of("details[0].issue"))
print("PayPal debug ID: " .. submitError:string_of("debug_id"))
return
end
print("PayPal accepted the evidence.")