Lua Requires Chilkat v11.0.0+
Lua
PayPal: Find disputes awaiting a seller response
See more PayPal Examples
Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local 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.
local http = chilkat.Http.new()
http.auth_token = "SANDBOX_ACCESS_TOKEN"
local resp = chilkat.HttpResponse.new()
local since = chilkat.DateTime.new()
since:set_from_current_system_time()
since:add_days(-30)
local query = chilkat.JsonObject.new()
query:update_string("update_time_after", since:get_as_timestamp(false))
query:update_int("page_size", 50)
local page = 1
local more = true
while more do
query:update_int("page", page)
success = http:http_params("GET", "https://api-m.sandbox.paypal.com/v1/customer/disputes", query, 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 i = 0
while i < result:size_of_array("items") do
result.i = i
if result:string_of_equals("items[i].status", "WAITING_FOR_SELLER_RESPONSE", true) then
print(result:string_of("items[i].dispute_id") .. " " .. result:string_of("items[i].reason"))
if result:has_member("items[i].seller_response_due_date") then
print("Respond by " .. result:string_of("items[i].seller_response_due_date"))
end
end
i = i + 1
end
local hasNext = false
local linkIndex = 0
while linkIndex < result:size_of_array("links") do
result.i = linkIndex
if result:string_of_equals("links[i].rel", "next", true) then
hasNext = true
end
linkIndex = linkIndex + 1
end
more = hasNext
page = page + 1
end